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