src/HOL/Fields.thy
author haftmann
Sat Jul 05 11:01:53 2014 +0200 (2014-07-05)
changeset 57514 bdc2c6b40bf2
parent 57512 cc97b347b301
child 57950 59c17b0b870d
permissions -rw-r--r--
prefer ac_simps collections over separate name bindings for add and mult
     1 (*  Title:      HOL/Fields.thy
     2     Author:     Gertrud Bauer
     3     Author:     Steven Obua
     4     Author:     Tobias Nipkow
     5     Author:     Lawrence C Paulson
     6     Author:     Markus Wenzel
     7     Author:     Jeremy Avigad
     8 *)
     9 
    10 header {* Fields *}
    11 
    12 theory Fields
    13 imports Rings
    14 begin
    15 
    16 subsection {* Division rings *}
    17 
    18 text {*
    19   A division ring is like a field, but without the commutativity requirement.
    20 *}
    21 
    22 class inverse =
    23   fixes inverse :: "'a \<Rightarrow> 'a"
    24     and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
    25 
    26 text{* Lemmas @{text divide_simps} move division to the outside and eliminates them on (in)equalities. *}
    27 
    28 ML {*
    29 structure Divide_Simps = Named_Thms
    30 (
    31   val name = @{binding divide_simps}
    32   val description = "rewrite rules to eliminate divisions"
    33 )
    34 *}
    35 
    36 setup Divide_Simps.setup
    37 
    38 
    39 class division_ring = ring_1 + inverse +
    40   assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
    41   assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
    42   assumes divide_inverse: "a / b = a * inverse b"
    43 begin
    44 
    45 subclass ring_1_no_zero_divisors
    46 proof
    47   fix a b :: 'a
    48   assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
    49   show "a * b \<noteq> 0"
    50   proof
    51     assume ab: "a * b = 0"
    52     hence "0 = inverse a * (a * b) * inverse b" by simp
    53     also have "\<dots> = (inverse a * a) * (b * inverse b)"
    54       by (simp only: mult.assoc)
    55     also have "\<dots> = 1" using a b by simp
    56     finally show False by simp
    57   qed
    58 qed
    59 
    60 lemma nonzero_imp_inverse_nonzero:
    61   "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
    62 proof
    63   assume ianz: "inverse a = 0"
    64   assume "a \<noteq> 0"
    65   hence "1 = a * inverse a" by simp
    66   also have "... = 0" by (simp add: ianz)
    67   finally have "1 = 0" .
    68   thus False by (simp add: eq_commute)
    69 qed
    70 
    71 lemma inverse_zero_imp_zero:
    72   "inverse a = 0 \<Longrightarrow> a = 0"
    73 apply (rule classical)
    74 apply (drule nonzero_imp_inverse_nonzero)
    75 apply auto
    76 done
    77 
    78 lemma inverse_unique: 
    79   assumes ab: "a * b = 1"
    80   shows "inverse a = b"
    81 proof -
    82   have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
    83   moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
    84   ultimately show ?thesis by (simp add: mult.assoc [symmetric])
    85 qed
    86 
    87 lemma nonzero_inverse_minus_eq:
    88   "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
    89 by (rule inverse_unique) simp
    90 
    91 lemma nonzero_inverse_inverse_eq:
    92   "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
    93 by (rule inverse_unique) simp
    94 
    95 lemma nonzero_inverse_eq_imp_eq:
    96   assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
    97   shows "a = b"
    98 proof -
    99   from `inverse a = inverse b`
   100   have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
   101   with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
   102     by (simp add: nonzero_inverse_inverse_eq)
   103 qed
   104 
   105 lemma inverse_1 [simp]: "inverse 1 = 1"
   106 by (rule inverse_unique) simp
   107 
   108 lemma nonzero_inverse_mult_distrib: 
   109   assumes "a \<noteq> 0" and "b \<noteq> 0"
   110   shows "inverse (a * b) = inverse b * inverse a"
   111 proof -
   112   have "a * (b * inverse b) * inverse a = 1" using assms by simp
   113   hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult.assoc)
   114   thus ?thesis by (rule inverse_unique)
   115 qed
   116 
   117 lemma division_ring_inverse_add:
   118   "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
   119 by (simp add: algebra_simps)
   120 
   121 lemma division_ring_inverse_diff:
   122   "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
   123 by (simp add: algebra_simps)
   124 
   125 lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
   126 proof
   127   assume neq: "b \<noteq> 0"
   128   {
   129     hence "a = (a / b) * b" by (simp add: divide_inverse mult.assoc)
   130     also assume "a / b = 1"
   131     finally show "a = b" by simp
   132   next
   133     assume "a = b"
   134     with neq show "a / b = 1" by (simp add: divide_inverse)
   135   }
   136 qed
   137 
   138 lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
   139 by (simp add: divide_inverse)
   140 
   141 lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
   142 by (simp add: divide_inverse)
   143 
   144 lemma divide_zero_left [simp]: "0 / a = 0"
   145 by (simp add: divide_inverse)
   146 
   147 lemma inverse_eq_divide [field_simps, divide_simps]: "inverse a = 1 / a"
   148 by (simp add: divide_inverse)
   149 
   150 lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
   151 by (simp add: divide_inverse algebra_simps)
   152 
   153 lemma divide_1 [simp]: "a / 1 = a"
   154   by (simp add: divide_inverse)
   155 
   156 lemma times_divide_eq_right [simp]: "a * (b / c) = (a * b) / c"
   157   by (simp add: divide_inverse mult.assoc)
   158 
   159 lemma minus_divide_left: "- (a / b) = (-a) / b"
   160   by (simp add: divide_inverse)
   161 
   162 lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
   163   by (simp add: divide_inverse nonzero_inverse_minus_eq)
   164 
   165 lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
   166   by (simp add: divide_inverse nonzero_inverse_minus_eq)
   167 
   168 lemma divide_minus_left [simp]: "(-a) / b = - (a / b)"
   169   by (simp add: divide_inverse)
   170 
   171 lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
   172   using add_divide_distrib [of a "- b" c] by simp
   173 
   174 lemma nonzero_eq_divide_eq [field_simps]: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
   175 proof -
   176   assume [simp]: "c \<noteq> 0"
   177   have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
   178   also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult.assoc)
   179   finally show ?thesis .
   180 qed
   181 
   182 lemma nonzero_divide_eq_eq [field_simps]: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
   183 proof -
   184   assume [simp]: "c \<noteq> 0"
   185   have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
   186   also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult.assoc) 
   187   finally show ?thesis .
   188 qed
   189 
   190 lemma nonzero_neg_divide_eq_eq [field_simps]: "b \<noteq> 0 \<Longrightarrow> - (a / b) = c \<longleftrightarrow> - a = c * b"
   191   using nonzero_divide_eq_eq[of b "-a" c] by (simp add: divide_minus_left)
   192 
   193 lemma nonzero_neg_divide_eq_eq2 [field_simps]: "b \<noteq> 0 \<Longrightarrow> c = - (a / b) \<longleftrightarrow> c * b = - a"
   194   using nonzero_neg_divide_eq_eq[of b a c] by auto
   195 
   196 lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
   197   by (simp add: divide_inverse mult.assoc)
   198 
   199 lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
   200   by (drule sym) (simp add: divide_inverse mult.assoc)
   201 
   202 lemma add_divide_eq_iff [field_simps]:
   203   "z \<noteq> 0 \<Longrightarrow> x + y / z = (x * z + y) / z"
   204   by (simp add: add_divide_distrib nonzero_eq_divide_eq)
   205 
   206 lemma divide_add_eq_iff [field_simps]:
   207   "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + y * z) / z"
   208   by (simp add: add_divide_distrib nonzero_eq_divide_eq)
   209 
   210 lemma diff_divide_eq_iff [field_simps]:
   211   "z \<noteq> 0 \<Longrightarrow> x - y / z = (x * z - y) / z"
   212   by (simp add: diff_divide_distrib nonzero_eq_divide_eq eq_diff_eq)
   213 
   214 lemma minus_divide_add_eq_iff [field_simps]:
   215   "z \<noteq> 0 \<Longrightarrow> - (x / z) + y = (- x + y * z) / z"
   216   by (simp add: add_divide_distrib diff_divide_eq_iff divide_minus_left)
   217 
   218 lemma divide_diff_eq_iff [field_simps]:
   219   "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - y * z) / z"
   220   by (simp add: field_simps)
   221 
   222 lemma minus_divide_diff_eq_iff [field_simps]:
   223   "z \<noteq> 0 \<Longrightarrow> - (x / z) - y = (- x - y * z) / z"
   224   by (simp add: divide_diff_eq_iff[symmetric] divide_minus_left)
   225 
   226 end
   227 
   228 class division_ring_inverse_zero = division_ring +
   229   assumes inverse_zero [simp]: "inverse 0 = 0"
   230 begin
   231 
   232 lemma divide_zero [simp]:
   233   "a / 0 = 0"
   234   by (simp add: divide_inverse)
   235 
   236 lemma divide_self_if [simp]:
   237   "a / a = (if a = 0 then 0 else 1)"
   238   by simp
   239 
   240 lemma inverse_nonzero_iff_nonzero [simp]:
   241   "inverse a = 0 \<longleftrightarrow> a = 0"
   242   by rule (fact inverse_zero_imp_zero, simp)
   243 
   244 lemma inverse_minus_eq [simp]:
   245   "inverse (- a) = - inverse a"
   246 proof cases
   247   assume "a=0" thus ?thesis by simp
   248 next
   249   assume "a\<noteq>0" 
   250   thus ?thesis by (simp add: nonzero_inverse_minus_eq)
   251 qed
   252 
   253 lemma inverse_inverse_eq [simp]:
   254   "inverse (inverse a) = a"
   255 proof cases
   256   assume "a=0" thus ?thesis by simp
   257 next
   258   assume "a\<noteq>0" 
   259   thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
   260 qed
   261 
   262 lemma inverse_eq_imp_eq:
   263   "inverse a = inverse b \<Longrightarrow> a = b"
   264   by (drule arg_cong [where f="inverse"], simp)
   265 
   266 lemma inverse_eq_iff_eq [simp]:
   267   "inverse a = inverse b \<longleftrightarrow> a = b"
   268   by (force dest!: inverse_eq_imp_eq)
   269 
   270 lemma add_divide_eq_if_simps [divide_simps]:
   271     "a + b / z = (if z = 0 then a else (a * z + b) / z)"
   272     "a / z + b = (if z = 0 then b else (a + b * z) / z)"
   273     "- (a / z) + b = (if z = 0 then b else (-a + b * z) / z)"
   274     "a - b / z = (if z = 0 then a else (a * z - b) / z)"
   275     "a / z - b = (if z = 0 then -b else (a - b * z) / z)"
   276     "- (a / z) - b = (if z = 0 then -b else (- a - b * z) / z)"
   277   by (simp_all add: add_divide_eq_iff divide_add_eq_iff diff_divide_eq_iff divide_diff_eq_iff
   278       minus_divide_diff_eq_iff)
   279 
   280 lemma [divide_simps]:
   281   shows divide_eq_eq: "b / c = a \<longleftrightarrow> (if c \<noteq> 0 then b = a * c else a = 0)"
   282     and eq_divide_eq: "a = b / c \<longleftrightarrow> (if c \<noteq> 0 then a * c = b else a = 0)"
   283     and minus_divide_eq_eq: "- (b / c) = a \<longleftrightarrow> (if c \<noteq> 0 then - b = a * c else a = 0)"
   284     and eq_minus_divide_eq: "a = - (b / c) \<longleftrightarrow> (if c \<noteq> 0 then a * c = - b else a = 0)"
   285   by (auto simp add:  field_simps)
   286 
   287 end
   288 
   289 subsection {* Fields *}
   290 
   291 class field = comm_ring_1 + inverse +
   292   assumes field_inverse: "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
   293   assumes field_divide_inverse: "a / b = a * inverse b"
   294 begin
   295 
   296 subclass division_ring
   297 proof
   298   fix a :: 'a
   299   assume "a \<noteq> 0"
   300   thus "inverse a * a = 1" by (rule field_inverse)
   301   thus "a * inverse a = 1" by (simp only: mult.commute)
   302 next
   303   fix a b :: 'a
   304   show "a / b = a * inverse b" by (rule field_divide_inverse)
   305 qed
   306 
   307 subclass idom ..
   308 
   309 text{*There is no slick version using division by zero.*}
   310 lemma inverse_add:
   311   "[| a \<noteq> 0;  b \<noteq> 0 |]
   312    ==> inverse a + inverse b = (a + b) * inverse a * inverse b"
   313 by (simp add: division_ring_inverse_add ac_simps)
   314 
   315 lemma nonzero_mult_divide_mult_cancel_left [simp]:
   316 assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/b"
   317 proof -
   318   have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
   319     by (simp add: divide_inverse nonzero_inverse_mult_distrib)
   320   also have "... =  a * inverse b * (inverse c * c)"
   321     by (simp only: ac_simps)
   322   also have "... =  a * inverse b" by simp
   323     finally show ?thesis by (simp add: divide_inverse)
   324 qed
   325 
   326 lemma nonzero_mult_divide_mult_cancel_right [simp]:
   327   "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (b * c) = a / b"
   328 by (simp add: mult.commute [of _ c])
   329 
   330 lemma times_divide_eq_left [simp]: "(b / c) * a = (b * a) / c"
   331   by (simp add: divide_inverse ac_simps)
   332 
   333 text{*It's not obvious whether @{text times_divide_eq} should be
   334   simprules or not. Their effect is to gather terms into one big
   335   fraction, like a*b*c / x*y*z. The rationale for that is unclear, but
   336   many proofs seem to need them.*}
   337 
   338 lemmas times_divide_eq = times_divide_eq_right times_divide_eq_left
   339 
   340 lemma add_frac_eq:
   341   assumes "y \<noteq> 0" and "z \<noteq> 0"
   342   shows "x / y + w / z = (x * z + w * y) / (y * z)"
   343 proof -
   344   have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
   345     using assms by simp
   346   also have "\<dots> = (x * z + y * w) / (y * z)"
   347     by (simp only: add_divide_distrib)
   348   finally show ?thesis
   349     by (simp only: mult.commute)
   350 qed
   351 
   352 text{*Special Cancellation Simprules for Division*}
   353 
   354 lemma nonzero_mult_divide_cancel_right [simp]:
   355   "b \<noteq> 0 \<Longrightarrow> a * b / b = a"
   356   using nonzero_mult_divide_mult_cancel_right [of 1 b a] by simp
   357 
   358 lemma nonzero_mult_divide_cancel_left [simp]:
   359   "a \<noteq> 0 \<Longrightarrow> a * b / a = b"
   360 using nonzero_mult_divide_mult_cancel_left [of 1 a b] by simp
   361 
   362 lemma nonzero_divide_mult_cancel_right [simp]:
   363   "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> b / (a * b) = 1 / a"
   364 using nonzero_mult_divide_mult_cancel_right [of a b 1] by simp
   365 
   366 lemma nonzero_divide_mult_cancel_left [simp]:
   367   "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / (a * b) = 1 / b"
   368 using nonzero_mult_divide_mult_cancel_left [of b a 1] by simp
   369 
   370 lemma nonzero_mult_divide_mult_cancel_left2 [simp]:
   371   "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (c * a) / (b * c) = a / b"
   372 using nonzero_mult_divide_mult_cancel_left [of b c a] by (simp add: ac_simps)
   373 
   374 lemma nonzero_mult_divide_mult_cancel_right2 [simp]:
   375   "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (c * b) = a / b"
   376 using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: ac_simps)
   377 
   378 lemma diff_frac_eq:
   379   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
   380   by (simp add: field_simps)
   381 
   382 lemma frac_eq_eq:
   383   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
   384   by (simp add: field_simps)
   385 
   386 end
   387 
   388 class field_inverse_zero = field +
   389   assumes field_inverse_zero: "inverse 0 = 0"
   390 begin
   391 
   392 subclass division_ring_inverse_zero proof
   393 qed (fact field_inverse_zero)
   394 
   395 text{*This version builds in division by zero while also re-orienting
   396       the right-hand side.*}
   397 lemma inverse_mult_distrib [simp]:
   398   "inverse (a * b) = inverse a * inverse b"
   399 proof cases
   400   assume "a \<noteq> 0 & b \<noteq> 0" 
   401   thus ?thesis by (simp add: nonzero_inverse_mult_distrib ac_simps)
   402 next
   403   assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
   404   thus ?thesis by force
   405 qed
   406 
   407 lemma inverse_divide [simp]:
   408   "inverse (a / b) = b / a"
   409   by (simp add: divide_inverse mult.commute)
   410 
   411 
   412 text {* Calculations with fractions *}
   413 
   414 text{* There is a whole bunch of simp-rules just for class @{text
   415 field} but none for class @{text field} and @{text nonzero_divides}
   416 because the latter are covered by a simproc. *}
   417 
   418 lemma mult_divide_mult_cancel_left:
   419   "c \<noteq> 0 \<Longrightarrow> (c * a) / (c * b) = a / b"
   420 apply (cases "b = 0")
   421 apply simp_all
   422 done
   423 
   424 lemma mult_divide_mult_cancel_right:
   425   "c \<noteq> 0 \<Longrightarrow> (a * c) / (b * c) = a / b"
   426 apply (cases "b = 0")
   427 apply simp_all
   428 done
   429 
   430 lemma divide_divide_eq_right [simp]:
   431   "a / (b / c) = (a * c) / b"
   432   by (simp add: divide_inverse ac_simps)
   433 
   434 lemma divide_divide_eq_left [simp]:
   435   "(a / b) / c = a / (b * c)"
   436   by (simp add: divide_inverse mult.assoc)
   437 
   438 lemma divide_divide_times_eq:
   439   "(x / y) / (z / w) = (x * w) / (y * z)"
   440   by simp
   441 
   442 text {*Special Cancellation Simprules for Division*}
   443 
   444 lemma mult_divide_mult_cancel_left_if [simp]:
   445   shows "(c * a) / (c * b) = (if c = 0 then 0 else a / b)"
   446   by (simp add: mult_divide_mult_cancel_left)
   447 
   448 
   449 text {* Division and Unary Minus *}
   450 
   451 lemma minus_divide_right:
   452   "- (a / b) = a / - b"
   453   by (simp add: divide_inverse)
   454 
   455 lemma divide_minus_right [simp]:
   456   "a / - b = - (a / b)"
   457   by (simp add: divide_inverse)
   458 
   459 lemma minus_divide_divide:
   460   "(- a) / (- b) = a / b"
   461 apply (cases "b=0", simp) 
   462 apply (simp add: nonzero_minus_divide_divide) 
   463 done
   464 
   465 lemma inverse_eq_1_iff [simp]:
   466   "inverse x = 1 \<longleftrightarrow> x = 1"
   467   by (insert inverse_eq_iff_eq [of x 1], simp) 
   468 
   469 lemma divide_eq_0_iff [simp]:
   470   "a / b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
   471   by (simp add: divide_inverse)
   472 
   473 lemma divide_cancel_right [simp]:
   474   "a / c = b / c \<longleftrightarrow> c = 0 \<or> a = b"
   475   apply (cases "c=0", simp)
   476   apply (simp add: divide_inverse)
   477   done
   478 
   479 lemma divide_cancel_left [simp]:
   480   "c / a = c / b \<longleftrightarrow> c = 0 \<or> a = b" 
   481   apply (cases "c=0", simp)
   482   apply (simp add: divide_inverse)
   483   done
   484 
   485 lemma divide_eq_1_iff [simp]:
   486   "a / b = 1 \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
   487   apply (cases "b=0", simp)
   488   apply (simp add: right_inverse_eq)
   489   done
   490 
   491 lemma one_eq_divide_iff [simp]:
   492   "1 = a / b \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
   493   by (simp add: eq_commute [of 1])
   494 
   495 lemma times_divide_times_eq:
   496   "(x / y) * (z / w) = (x * z) / (y * w)"
   497   by simp
   498 
   499 lemma add_frac_num:
   500   "y \<noteq> 0 \<Longrightarrow> x / y + z = (x + z * y) / y"
   501   by (simp add: add_divide_distrib)
   502 
   503 lemma add_num_frac:
   504   "y \<noteq> 0 \<Longrightarrow> z + x / y = (x + z * y) / y"
   505   by (simp add: add_divide_distrib add.commute)
   506 
   507 end
   508 
   509 
   510 subsection {* Ordered fields *}
   511 
   512 class linordered_field = field + linordered_idom
   513 begin
   514 
   515 lemma positive_imp_inverse_positive: 
   516   assumes a_gt_0: "0 < a" 
   517   shows "0 < inverse a"
   518 proof -
   519   have "0 < a * inverse a" 
   520     by (simp add: a_gt_0 [THEN less_imp_not_eq2])
   521   thus "0 < inverse a" 
   522     by (simp add: a_gt_0 [THEN less_not_sym] zero_less_mult_iff)
   523 qed
   524 
   525 lemma negative_imp_inverse_negative:
   526   "a < 0 \<Longrightarrow> inverse a < 0"
   527   by (insert positive_imp_inverse_positive [of "-a"], 
   528     simp add: nonzero_inverse_minus_eq less_imp_not_eq)
   529 
   530 lemma inverse_le_imp_le:
   531   assumes invle: "inverse a \<le> inverse b" and apos: "0 < a"
   532   shows "b \<le> a"
   533 proof (rule classical)
   534   assume "~ b \<le> a"
   535   hence "a < b"  by (simp add: linorder_not_le)
   536   hence bpos: "0 < b"  by (blast intro: apos less_trans)
   537   hence "a * inverse a \<le> a * inverse b"
   538     by (simp add: apos invle less_imp_le mult_left_mono)
   539   hence "(a * inverse a) * b \<le> (a * inverse b) * b"
   540     by (simp add: bpos less_imp_le mult_right_mono)
   541   thus "b \<le> a"  by (simp add: mult.assoc apos bpos less_imp_not_eq2)
   542 qed
   543 
   544 lemma inverse_positive_imp_positive:
   545   assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
   546   shows "0 < a"
   547 proof -
   548   have "0 < inverse (inverse a)"
   549     using inv_gt_0 by (rule positive_imp_inverse_positive)
   550   thus "0 < a"
   551     using nz by (simp add: nonzero_inverse_inverse_eq)
   552 qed
   553 
   554 lemma inverse_negative_imp_negative:
   555   assumes inv_less_0: "inverse a < 0" and nz: "a \<noteq> 0"
   556   shows "a < 0"
   557 proof -
   558   have "inverse (inverse a) < 0"
   559     using inv_less_0 by (rule negative_imp_inverse_negative)
   560   thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
   561 qed
   562 
   563 lemma linordered_field_no_lb:
   564   "\<forall>x. \<exists>y. y < x"
   565 proof
   566   fix x::'a
   567   have m1: "- (1::'a) < 0" by simp
   568   from add_strict_right_mono[OF m1, where c=x] 
   569   have "(- 1) + x < x" by simp
   570   thus "\<exists>y. y < x" by blast
   571 qed
   572 
   573 lemma linordered_field_no_ub:
   574   "\<forall> x. \<exists>y. y > x"
   575 proof
   576   fix x::'a
   577   have m1: " (1::'a) > 0" by simp
   578   from add_strict_right_mono[OF m1, where c=x] 
   579   have "1 + x > x" by simp
   580   thus "\<exists>y. y > x" by blast
   581 qed
   582 
   583 lemma less_imp_inverse_less:
   584   assumes less: "a < b" and apos:  "0 < a"
   585   shows "inverse b < inverse a"
   586 proof (rule ccontr)
   587   assume "~ inverse b < inverse a"
   588   hence "inverse a \<le> inverse b" by simp
   589   hence "~ (a < b)"
   590     by (simp add: not_less inverse_le_imp_le [OF _ apos])
   591   thus False by (rule notE [OF _ less])
   592 qed
   593 
   594 lemma inverse_less_imp_less:
   595   "inverse a < inverse b \<Longrightarrow> 0 < a \<Longrightarrow> b < a"
   596 apply (simp add: less_le [of "inverse a"] less_le [of "b"])
   597 apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
   598 done
   599 
   600 text{*Both premises are essential. Consider -1 and 1.*}
   601 lemma inverse_less_iff_less [simp]:
   602   "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
   603   by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
   604 
   605 lemma le_imp_inverse_le:
   606   "a \<le> b \<Longrightarrow> 0 < a \<Longrightarrow> inverse b \<le> inverse a"
   607   by (force simp add: le_less less_imp_inverse_less)
   608 
   609 lemma inverse_le_iff_le [simp]:
   610   "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
   611   by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
   612 
   613 
   614 text{*These results refer to both operands being negative.  The opposite-sign
   615 case is trivial, since inverse preserves signs.*}
   616 lemma inverse_le_imp_le_neg:
   617   "inverse a \<le> inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b \<le> a"
   618 apply (rule classical) 
   619 apply (subgoal_tac "a < 0") 
   620  prefer 2 apply force
   621 apply (insert inverse_le_imp_le [of "-b" "-a"])
   622 apply (simp add: nonzero_inverse_minus_eq) 
   623 done
   624 
   625 lemma less_imp_inverse_less_neg:
   626    "a < b \<Longrightarrow> b < 0 \<Longrightarrow> inverse b < inverse a"
   627 apply (subgoal_tac "a < 0") 
   628  prefer 2 apply (blast intro: less_trans) 
   629 apply (insert less_imp_inverse_less [of "-b" "-a"])
   630 apply (simp add: nonzero_inverse_minus_eq) 
   631 done
   632 
   633 lemma inverse_less_imp_less_neg:
   634    "inverse a < inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b < a"
   635 apply (rule classical) 
   636 apply (subgoal_tac "a < 0") 
   637  prefer 2
   638  apply force
   639 apply (insert inverse_less_imp_less [of "-b" "-a"])
   640 apply (simp add: nonzero_inverse_minus_eq) 
   641 done
   642 
   643 lemma inverse_less_iff_less_neg [simp]:
   644   "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
   645 apply (insert inverse_less_iff_less [of "-b" "-a"])
   646 apply (simp del: inverse_less_iff_less 
   647             add: nonzero_inverse_minus_eq)
   648 done
   649 
   650 lemma le_imp_inverse_le_neg:
   651   "a \<le> b \<Longrightarrow> b < 0 ==> inverse b \<le> inverse a"
   652   by (force simp add: le_less less_imp_inverse_less_neg)
   653 
   654 lemma inverse_le_iff_le_neg [simp]:
   655   "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
   656   by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
   657 
   658 lemma one_less_inverse:
   659   "0 < a \<Longrightarrow> a < 1 \<Longrightarrow> 1 < inverse a"
   660   using less_imp_inverse_less [of a 1, unfolded inverse_1] .
   661 
   662 lemma one_le_inverse:
   663   "0 < a \<Longrightarrow> a \<le> 1 \<Longrightarrow> 1 \<le> inverse a"
   664   using le_imp_inverse_le [of a 1, unfolded inverse_1] .
   665 
   666 lemma pos_le_divide_eq [field_simps]: "0 < c \<Longrightarrow> a \<le> b / c \<longleftrightarrow> a * c \<le> b"
   667 proof -
   668   assume less: "0<c"
   669   hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
   670     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   671   also have "... = (a*c \<le> b)"
   672     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   673   finally show ?thesis .
   674 qed
   675 
   676 lemma neg_le_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a \<le> b / c \<longleftrightarrow> b \<le> a * c"
   677 proof -
   678   assume less: "c<0"
   679   hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
   680     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   681   also have "... = (b \<le> a*c)"
   682     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   683   finally show ?thesis .
   684 qed
   685 
   686 lemma pos_less_divide_eq [field_simps]: "0 < c \<Longrightarrow> a < b / c \<longleftrightarrow> a * c < b"
   687 proof -
   688   assume less: "0<c"
   689   hence "(a < b/c) = (a*c < (b/c)*c)"
   690     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   691   also have "... = (a*c < b)"
   692     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   693   finally show ?thesis .
   694 qed
   695 
   696 lemma neg_less_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a < b / c \<longleftrightarrow> b < a * c"
   697 proof -
   698   assume less: "c<0"
   699   hence "(a < b/c) = ((b/c)*c < a*c)"
   700     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   701   also have "... = (b < a*c)"
   702     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   703   finally show ?thesis .
   704 qed
   705 
   706 lemma pos_divide_less_eq [field_simps]: "0 < c \<Longrightarrow> b / c < a \<longleftrightarrow> b < a * c"
   707 proof -
   708   assume less: "0<c"
   709   hence "(b/c < a) = ((b/c)*c < a*c)"
   710     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   711   also have "... = (b < a*c)"
   712     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   713   finally show ?thesis .
   714 qed
   715 
   716 lemma neg_divide_less_eq [field_simps]: "c < 0 \<Longrightarrow> b / c < a \<longleftrightarrow> a * c < b"
   717 proof -
   718   assume less: "c<0"
   719   hence "(b/c < a) = (a*c < (b/c)*c)"
   720     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   721   also have "... = (a*c < b)"
   722     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   723   finally show ?thesis .
   724 qed
   725 
   726 lemma pos_divide_le_eq [field_simps]: "0 < c \<Longrightarrow> b / c \<le> a \<longleftrightarrow> b \<le> a * c"
   727 proof -
   728   assume less: "0<c"
   729   hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
   730     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   731   also have "... = (b \<le> a*c)"
   732     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   733   finally show ?thesis .
   734 qed
   735 
   736 lemma neg_divide_le_eq [field_simps]: "c < 0 \<Longrightarrow> b / c \<le> a \<longleftrightarrow> a * c \<le> b"
   737 proof -
   738   assume less: "c<0"
   739   hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
   740     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   741   also have "... = (a*c \<le> b)"
   742     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   743   finally show ?thesis .
   744 qed
   745 
   746 text{* The following @{text field_simps} rules are necessary, as minus is always moved atop of
   747 division but we want to get rid of division. *}
   748 
   749 lemma pos_le_minus_divide_eq [field_simps]: "0 < c \<Longrightarrow> a \<le> - (b / c) \<longleftrightarrow> a * c \<le> - b"
   750   unfolding minus_divide_left by (rule pos_le_divide_eq)
   751 
   752 lemma neg_le_minus_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a \<le> - (b / c) \<longleftrightarrow> - b \<le> a * c"
   753   unfolding minus_divide_left by (rule neg_le_divide_eq)
   754 
   755 lemma pos_less_minus_divide_eq [field_simps]: "0 < c \<Longrightarrow> a < - (b / c) \<longleftrightarrow> a * c < - b"
   756   unfolding minus_divide_left by (rule pos_less_divide_eq)
   757 
   758 lemma neg_less_minus_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a < - (b / c) \<longleftrightarrow> - b < a * c"
   759   unfolding minus_divide_left by (rule neg_less_divide_eq)
   760 
   761 lemma pos_minus_divide_less_eq [field_simps]: "0 < c \<Longrightarrow> - (b / c) < a \<longleftrightarrow> - b < a * c"
   762   unfolding minus_divide_left by (rule pos_divide_less_eq)
   763 
   764 lemma neg_minus_divide_less_eq [field_simps]: "c < 0 \<Longrightarrow> - (b / c) < a \<longleftrightarrow> a * c < - b"
   765   unfolding minus_divide_left by (rule neg_divide_less_eq)
   766 
   767 lemma pos_minus_divide_le_eq [field_simps]: "0 < c \<Longrightarrow> - (b / c) \<le> a \<longleftrightarrow> - b \<le> a * c"
   768   unfolding minus_divide_left by (rule pos_divide_le_eq)
   769 
   770 lemma neg_minus_divide_le_eq [field_simps]: "c < 0 \<Longrightarrow> - (b / c) \<le> a \<longleftrightarrow> a * c \<le> - b"
   771   unfolding minus_divide_left by (rule neg_divide_le_eq)
   772 
   773 lemma frac_less_eq:
   774   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y < w / z \<longleftrightarrow> (x * z - w * y) / (y * z) < 0"
   775   by (subst less_iff_diff_less_0) (simp add: diff_frac_eq )
   776 
   777 lemma frac_le_eq:
   778   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y \<le> w / z \<longleftrightarrow> (x * z - w * y) / (y * z) \<le> 0"
   779   by (subst le_iff_diff_le_0) (simp add: diff_frac_eq )
   780 
   781 text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
   782 of positivity/negativity needed for @{text field_simps}. Have not added @{text
   783 sign_simps} to @{text field_simps} because the former can lead to case
   784 explosions. *}
   785 
   786 lemmas sign_simps = algebra_simps zero_less_mult_iff mult_less_0_iff
   787 
   788 lemmas (in -) sign_simps = algebra_simps zero_less_mult_iff mult_less_0_iff
   789 
   790 (* Only works once linear arithmetic is installed:
   791 text{*An example:*}
   792 lemma fixes a b c d e f :: "'a::linordered_field"
   793 shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
   794  ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
   795  ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
   796 apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
   797  prefer 2 apply(simp add:sign_simps)
   798 apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
   799  prefer 2 apply(simp add:sign_simps)
   800 apply(simp add:field_simps)
   801 done
   802 *)
   803 
   804 lemma divide_pos_pos[simp]:
   805   "0 < x ==> 0 < y ==> 0 < x / y"
   806 by(simp add:field_simps)
   807 
   808 lemma divide_nonneg_pos:
   809   "0 <= x ==> 0 < y ==> 0 <= x / y"
   810 by(simp add:field_simps)
   811 
   812 lemma divide_neg_pos:
   813   "x < 0 ==> 0 < y ==> x / y < 0"
   814 by(simp add:field_simps)
   815 
   816 lemma divide_nonpos_pos:
   817   "x <= 0 ==> 0 < y ==> x / y <= 0"
   818 by(simp add:field_simps)
   819 
   820 lemma divide_pos_neg:
   821   "0 < x ==> y < 0 ==> x / y < 0"
   822 by(simp add:field_simps)
   823 
   824 lemma divide_nonneg_neg:
   825   "0 <= x ==> y < 0 ==> x / y <= 0" 
   826 by(simp add:field_simps)
   827 
   828 lemma divide_neg_neg:
   829   "x < 0 ==> y < 0 ==> 0 < x / y"
   830 by(simp add:field_simps)
   831 
   832 lemma divide_nonpos_neg:
   833   "x <= 0 ==> y < 0 ==> 0 <= x / y"
   834 by(simp add:field_simps)
   835 
   836 lemma divide_strict_right_mono:
   837      "[|a < b; 0 < c|] ==> a / c < b / c"
   838 by (simp add: less_imp_not_eq2 divide_inverse mult_strict_right_mono 
   839               positive_imp_inverse_positive)
   840 
   841 
   842 lemma divide_strict_right_mono_neg:
   843      "[|b < a; c < 0|] ==> a / c < b / c"
   844 apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
   845 apply (simp add: less_imp_not_eq nonzero_minus_divide_right [symmetric])
   846 done
   847 
   848 text{*The last premise ensures that @{term a} and @{term b} 
   849       have the same sign*}
   850 lemma divide_strict_left_mono:
   851   "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / b"
   852   by (auto simp: field_simps zero_less_mult_iff mult_strict_right_mono)
   853 
   854 lemma divide_left_mono:
   855   "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / b"
   856   by (auto simp: field_simps zero_less_mult_iff mult_right_mono)
   857 
   858 lemma divide_strict_left_mono_neg:
   859   "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / b"
   860   by (auto simp: field_simps zero_less_mult_iff mult_strict_right_mono_neg)
   861 
   862 lemma mult_imp_div_pos_le: "0 < y ==> x <= z * y ==>
   863     x / y <= z"
   864 by (subst pos_divide_le_eq, assumption+)
   865 
   866 lemma mult_imp_le_div_pos: "0 < y ==> z * y <= x ==>
   867     z <= x / y"
   868 by(simp add:field_simps)
   869 
   870 lemma mult_imp_div_pos_less: "0 < y ==> x < z * y ==>
   871     x / y < z"
   872 by(simp add:field_simps)
   873 
   874 lemma mult_imp_less_div_pos: "0 < y ==> z * y < x ==>
   875     z < x / y"
   876 by(simp add:field_simps)
   877 
   878 lemma frac_le: "0 <= x ==> 
   879     x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
   880   apply (rule mult_imp_div_pos_le)
   881   apply simp
   882   apply (subst times_divide_eq_left)
   883   apply (rule mult_imp_le_div_pos, assumption)
   884   apply (rule mult_mono)
   885   apply simp_all
   886 done
   887 
   888 lemma frac_less: "0 <= x ==> 
   889     x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
   890   apply (rule mult_imp_div_pos_less)
   891   apply simp
   892   apply (subst times_divide_eq_left)
   893   apply (rule mult_imp_less_div_pos, assumption)
   894   apply (erule mult_less_le_imp_less)
   895   apply simp_all
   896 done
   897 
   898 lemma frac_less2: "0 < x ==> 
   899     x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
   900   apply (rule mult_imp_div_pos_less)
   901   apply simp_all
   902   apply (rule mult_imp_less_div_pos, assumption)
   903   apply (erule mult_le_less_imp_less)
   904   apply simp_all
   905 done
   906 
   907 lemma less_half_sum: "a < b ==> a < (a+b) / (1+1)"
   908 by (simp add: field_simps zero_less_two)
   909 
   910 lemma gt_half_sum: "a < b ==> (a+b)/(1+1) < b"
   911 by (simp add: field_simps zero_less_two)
   912 
   913 subclass unbounded_dense_linorder
   914 proof
   915   fix x y :: 'a
   916   from less_add_one show "\<exists>y. x < y" .. 
   917   from less_add_one have "x + (- 1) < (x + 1) + (- 1)" by (rule add_strict_right_mono)
   918   then have "x - 1 < x + 1 - 1" by simp
   919   then have "x - 1 < x" by (simp add: algebra_simps)
   920   then show "\<exists>y. y < x" ..
   921   show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
   922 qed
   923 
   924 lemma nonzero_abs_inverse:
   925      "a \<noteq> 0 ==> \<bar>inverse a\<bar> = inverse \<bar>a\<bar>"
   926 apply (auto simp add: neq_iff abs_if nonzero_inverse_minus_eq 
   927                       negative_imp_inverse_negative)
   928 apply (blast intro: positive_imp_inverse_positive elim: less_asym) 
   929 done
   930 
   931 lemma nonzero_abs_divide:
   932      "b \<noteq> 0 ==> \<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
   933   by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
   934 
   935 lemma field_le_epsilon:
   936   assumes e: "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
   937   shows "x \<le> y"
   938 proof (rule dense_le)
   939   fix t assume "t < x"
   940   hence "0 < x - t" by (simp add: less_diff_eq)
   941   from e [OF this] have "x + 0 \<le> x + (y - t)" by (simp add: algebra_simps)
   942   then have "0 \<le> y - t" by (simp only: add_le_cancel_left)
   943   then show "t \<le> y" by (simp add: algebra_simps)
   944 qed
   945 
   946 end
   947 
   948 class linordered_field_inverse_zero = linordered_field + field_inverse_zero
   949 begin
   950 
   951 lemma inverse_positive_iff_positive [simp]:
   952   "(0 < inverse a) = (0 < a)"
   953 apply (cases "a = 0", simp)
   954 apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
   955 done
   956 
   957 lemma inverse_negative_iff_negative [simp]:
   958   "(inverse a < 0) = (a < 0)"
   959 apply (cases "a = 0", simp)
   960 apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
   961 done
   962 
   963 lemma inverse_nonnegative_iff_nonnegative [simp]:
   964   "0 \<le> inverse a \<longleftrightarrow> 0 \<le> a"
   965   by (simp add: not_less [symmetric])
   966 
   967 lemma inverse_nonpositive_iff_nonpositive [simp]:
   968   "inverse a \<le> 0 \<longleftrightarrow> a \<le> 0"
   969   by (simp add: not_less [symmetric])
   970 
   971 lemma one_less_inverse_iff: "1 < inverse x \<longleftrightarrow> 0 < x \<and> x < 1"
   972   using less_trans[of 1 x 0 for x]
   973   by (cases x 0 rule: linorder_cases) (auto simp add: field_simps)
   974 
   975 lemma one_le_inverse_iff: "1 \<le> inverse x \<longleftrightarrow> 0 < x \<and> x \<le> 1"
   976 proof (cases "x = 1")
   977   case True then show ?thesis by simp
   978 next
   979   case False then have "inverse x \<noteq> 1" by simp
   980   then have "1 \<noteq> inverse x" by blast
   981   then have "1 \<le> inverse x \<longleftrightarrow> 1 < inverse x" by (simp add: le_less)
   982   with False show ?thesis by (auto simp add: one_less_inverse_iff)
   983 qed
   984 
   985 lemma inverse_less_1_iff: "inverse x < 1 \<longleftrightarrow> x \<le> 0 \<or> 1 < x"
   986   by (simp add: not_le [symmetric] one_le_inverse_iff) 
   987 
   988 lemma inverse_le_1_iff: "inverse x \<le> 1 \<longleftrightarrow> x \<le> 0 \<or> 1 \<le> x"
   989   by (simp add: not_less [symmetric] one_less_inverse_iff) 
   990 
   991 lemma [divide_simps]:
   992   shows le_divide_eq: "a \<le> b / c \<longleftrightarrow> (if 0 < c then a * c \<le> b else if c < 0 then b \<le> a * c else a \<le> 0)"
   993     and divide_le_eq: "b / c \<le> a \<longleftrightarrow> (if 0 < c then b \<le> a * c else if c < 0 then a * c \<le> b else 0 \<le> a)"
   994     and less_divide_eq: "a < b / c \<longleftrightarrow> (if 0 < c then a * c < b else if c < 0 then b < a * c else a < 0)"
   995     and divide_less_eq: "b / c < a \<longleftrightarrow> (if 0 < c then b < a * c else if c < 0 then a * c < b else 0 < a)"
   996     and le_minus_divide_eq: "a \<le> - (b / c) \<longleftrightarrow> (if 0 < c then a * c \<le> - b else if c < 0 then - b \<le> a * c else a \<le> 0)"
   997     and minus_divide_le_eq: "- (b / c) \<le> a \<longleftrightarrow> (if 0 < c then - b \<le> a * c else if c < 0 then a * c \<le> - b else 0 \<le> a)"
   998     and less_minus_divide_eq: "a < - (b / c) \<longleftrightarrow> (if 0 < c then a * c < - b else if c < 0 then - b < a * c else  a < 0)"
   999     and minus_divide_less_eq: "- (b / c) < a \<longleftrightarrow> (if 0 < c then - b < a * c else if c < 0 then a * c < - b else 0 < a)"
  1000   by (auto simp: field_simps not_less dest: antisym)
  1001 
  1002 text {*Division and Signs*}
  1003 
  1004 lemma
  1005   shows zero_less_divide_iff: "0 < a / b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
  1006     and divide_less_0_iff: "a / b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
  1007     and zero_le_divide_iff: "0 \<le> a / b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
  1008     and divide_le_0_iff: "a / b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
  1009   by (auto simp add: divide_simps)
  1010 
  1011 text {* Division and the Number One *}
  1012 
  1013 text{*Simplify expressions equated with 1*}
  1014 
  1015 lemma zero_eq_1_divide_iff [simp]: "0 = 1 / a \<longleftrightarrow> a = 0"
  1016   by (cases "a = 0") (auto simp: field_simps)
  1017 
  1018 lemma one_divide_eq_0_iff [simp]: "1 / a = 0 \<longleftrightarrow> a = 0"
  1019   using zero_eq_1_divide_iff[of a] by simp
  1020 
  1021 text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
  1022 
  1023 lemma zero_le_divide_1_iff [simp]:
  1024   "0 \<le> 1 / a \<longleftrightarrow> 0 \<le> a"
  1025   by (simp add: zero_le_divide_iff)
  1026 
  1027 lemma zero_less_divide_1_iff [simp]:
  1028   "0 < 1 / a \<longleftrightarrow> 0 < a"
  1029   by (simp add: zero_less_divide_iff)
  1030 
  1031 lemma divide_le_0_1_iff [simp]:
  1032   "1 / a \<le> 0 \<longleftrightarrow> a \<le> 0"
  1033   by (simp add: divide_le_0_iff)
  1034 
  1035 lemma divide_less_0_1_iff [simp]:
  1036   "1 / a < 0 \<longleftrightarrow> a < 0"
  1037   by (simp add: divide_less_0_iff)
  1038 
  1039 lemma divide_right_mono:
  1040      "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/c"
  1041 by (force simp add: divide_strict_right_mono le_less)
  1042 
  1043 lemma divide_right_mono_neg: "a <= b 
  1044     ==> c <= 0 ==> b / c <= a / c"
  1045 apply (drule divide_right_mono [of _ _ "- c"])
  1046 apply auto
  1047 done
  1048 
  1049 lemma divide_left_mono_neg: "a <= b 
  1050     ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
  1051   apply (drule divide_left_mono [of _ _ "- c"])
  1052   apply (auto simp add: mult.commute)
  1053 done
  1054 
  1055 lemma inverse_le_iff: "inverse a \<le> inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b \<le> a) \<and> (a * b \<le> 0 \<longrightarrow> a \<le> b)"
  1056   by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
  1057      (auto simp add: field_simps zero_less_mult_iff mult_le_0_iff)
  1058 
  1059 lemma inverse_less_iff: "inverse a < inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b < a) \<and> (a * b \<le> 0 \<longrightarrow> a < b)"
  1060   by (subst less_le) (auto simp: inverse_le_iff)
  1061 
  1062 lemma divide_le_cancel: "a / c \<le> b / c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
  1063   by (simp add: divide_inverse mult_le_cancel_right)
  1064 
  1065 lemma divide_less_cancel: "a / c < b / c \<longleftrightarrow> (0 < c \<longrightarrow> a < b) \<and> (c < 0 \<longrightarrow> b < a) \<and> c \<noteq> 0"
  1066   by (auto simp add: divide_inverse mult_less_cancel_right)
  1067 
  1068 text{*Simplify quotients that are compared with the value 1.*}
  1069 
  1070 lemma le_divide_eq_1:
  1071   "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
  1072 by (auto simp add: le_divide_eq)
  1073 
  1074 lemma divide_le_eq_1:
  1075   "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
  1076 by (auto simp add: divide_le_eq)
  1077 
  1078 lemma less_divide_eq_1:
  1079   "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
  1080 by (auto simp add: less_divide_eq)
  1081 
  1082 lemma divide_less_eq_1:
  1083   "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
  1084 by (auto simp add: divide_less_eq)
  1085 
  1086 lemma divide_nonneg_nonneg [simp]:
  1087   "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x / y"
  1088   by (auto simp add: divide_simps)
  1089 
  1090 lemma divide_nonpos_nonpos:
  1091   "x \<le> 0 \<Longrightarrow> y \<le> 0 \<Longrightarrow> 0 \<le> x / y"
  1092   by (auto simp add: divide_simps)
  1093 
  1094 lemma divide_nonneg_nonpos:
  1095   "0 \<le> x \<Longrightarrow> y \<le> 0 \<Longrightarrow> x / y \<le> 0"
  1096   by (auto simp add: divide_simps)
  1097 
  1098 lemma divide_nonpos_nonneg:
  1099   "x \<le> 0 \<Longrightarrow> 0 \<le> y \<Longrightarrow> x / y \<le> 0"
  1100   by (auto simp add: divide_simps)
  1101 
  1102 text {*Conditional Simplification Rules: No Case Splits*}
  1103 
  1104 lemma le_divide_eq_1_pos [simp]:
  1105   "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
  1106 by (auto simp add: le_divide_eq)
  1107 
  1108 lemma le_divide_eq_1_neg [simp]:
  1109   "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
  1110 by (auto simp add: le_divide_eq)
  1111 
  1112 lemma divide_le_eq_1_pos [simp]:
  1113   "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
  1114 by (auto simp add: divide_le_eq)
  1115 
  1116 lemma divide_le_eq_1_neg [simp]:
  1117   "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
  1118 by (auto simp add: divide_le_eq)
  1119 
  1120 lemma less_divide_eq_1_pos [simp]:
  1121   "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
  1122 by (auto simp add: less_divide_eq)
  1123 
  1124 lemma less_divide_eq_1_neg [simp]:
  1125   "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
  1126 by (auto simp add: less_divide_eq)
  1127 
  1128 lemma divide_less_eq_1_pos [simp]:
  1129   "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
  1130 by (auto simp add: divide_less_eq)
  1131 
  1132 lemma divide_less_eq_1_neg [simp]:
  1133   "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
  1134 by (auto simp add: divide_less_eq)
  1135 
  1136 lemma eq_divide_eq_1 [simp]:
  1137   "(1 = b/a) = ((a \<noteq> 0 & a = b))"
  1138 by (auto simp add: eq_divide_eq)
  1139 
  1140 lemma divide_eq_eq_1 [simp]:
  1141   "(b/a = 1) = ((a \<noteq> 0 & a = b))"
  1142 by (auto simp add: divide_eq_eq)
  1143 
  1144 lemma abs_inverse [simp]:
  1145      "\<bar>inverse a\<bar> = 
  1146       inverse \<bar>a\<bar>"
  1147 apply (cases "a=0", simp) 
  1148 apply (simp add: nonzero_abs_inverse) 
  1149 done
  1150 
  1151 lemma abs_divide [simp]:
  1152      "\<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
  1153 apply (cases "b=0", simp) 
  1154 apply (simp add: nonzero_abs_divide) 
  1155 done
  1156 
  1157 lemma abs_div_pos: "0 < y ==> 
  1158     \<bar>x\<bar> / y = \<bar>x / y\<bar>"
  1159   apply (subst abs_divide)
  1160   apply (simp add: order_less_imp_le)
  1161 done
  1162 
  1163 lemma zero_le_divide_abs_iff [simp]: "(0 \<le> a / abs b) = (0 \<le> a | b = 0)" 
  1164 by (auto simp: zero_le_divide_iff)
  1165 
  1166 lemma divide_le_0_abs_iff [simp]: "(a / abs b \<le> 0) = (a \<le> 0 | b = 0)" 
  1167 by (auto simp: divide_le_0_iff)
  1168 
  1169 lemma field_le_mult_one_interval:
  1170   assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
  1171   shows "x \<le> y"
  1172 proof (cases "0 < x")
  1173   assume "0 < x"
  1174   thus ?thesis
  1175     using dense_le_bounded[of 0 1 "y/x"] *
  1176     unfolding le_divide_eq if_P[OF `0 < x`] by simp
  1177 next
  1178   assume "\<not>0 < x" hence "x \<le> 0" by simp
  1179   obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1\<Colon>'a"] by auto
  1180   hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] `x \<le> 0` by auto
  1181   also note *[OF s]
  1182   finally show ?thesis .
  1183 qed
  1184 
  1185 end
  1186 
  1187 code_identifier
  1188   code_module Fields \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
  1189 
  1190 end