src/HOL/Fields.thy
author haftmann
Sun Sep 21 16:56:11 2014 +0200 (2014-09-21)
changeset 58410 6d46ad54a2ab
parent 57950 59c17b0b870d
child 58512 dc4d76dfa8f0
permissions -rw-r--r--
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
     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 end
   379 
   380 class field_inverse_zero = field +
   381   assumes field_inverse_zero: "inverse 0 = 0"
   382 begin
   383 
   384 subclass division_ring_inverse_zero proof
   385 qed (fact field_inverse_zero)
   386 
   387 text{*This version builds in division by zero while also re-orienting
   388       the right-hand side.*}
   389 lemma inverse_mult_distrib [simp]:
   390   "inverse (a * b) = inverse a * inverse b"
   391 proof cases
   392   assume "a \<noteq> 0 & b \<noteq> 0" 
   393   thus ?thesis by (simp add: nonzero_inverse_mult_distrib ac_simps)
   394 next
   395   assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
   396   thus ?thesis by force
   397 qed
   398 
   399 lemma inverse_divide [simp]:
   400   "inverse (a / b) = b / a"
   401   by (simp add: divide_inverse mult.commute)
   402 
   403 
   404 text {* Calculations with fractions *}
   405 
   406 text{* There is a whole bunch of simp-rules just for class @{text
   407 field} but none for class @{text field} and @{text nonzero_divides}
   408 because the latter are covered by a simproc. *}
   409 
   410 lemma mult_divide_mult_cancel_left:
   411   "c \<noteq> 0 \<Longrightarrow> (c * a) / (c * b) = a / b"
   412 apply (cases "b = 0")
   413 apply simp_all
   414 done
   415 
   416 lemma mult_divide_mult_cancel_right:
   417   "c \<noteq> 0 \<Longrightarrow> (a * c) / (b * c) = a / b"
   418 apply (cases "b = 0")
   419 apply simp_all
   420 done
   421 
   422 lemma divide_divide_eq_right [simp]:
   423   "a / (b / c) = (a * c) / b"
   424   by (simp add: divide_inverse ac_simps)
   425 
   426 lemma divide_divide_eq_left [simp]:
   427   "(a / b) / c = a / (b * c)"
   428   by (simp add: divide_inverse mult.assoc)
   429 
   430 lemma divide_divide_times_eq:
   431   "(x / y) / (z / w) = (x * w) / (y * z)"
   432   by simp
   433 
   434 text {*Special Cancellation Simprules for Division*}
   435 
   436 lemma mult_divide_mult_cancel_left_if [simp]:
   437   shows "(c * a) / (c * b) = (if c = 0 then 0 else a / b)"
   438   by (simp add: mult_divide_mult_cancel_left)
   439 
   440 
   441 text {* Division and Unary Minus *}
   442 
   443 lemma minus_divide_right:
   444   "- (a / b) = a / - b"
   445   by (simp add: divide_inverse)
   446 
   447 lemma divide_minus_right [simp]:
   448   "a / - b = - (a / b)"
   449   by (simp add: divide_inverse)
   450 
   451 lemma minus_divide_divide:
   452   "(- a) / (- b) = a / b"
   453 apply (cases "b=0", simp) 
   454 apply (simp add: nonzero_minus_divide_divide) 
   455 done
   456 
   457 lemma inverse_eq_1_iff [simp]:
   458   "inverse x = 1 \<longleftrightarrow> x = 1"
   459   by (insert inverse_eq_iff_eq [of x 1], simp) 
   460 
   461 lemma divide_eq_0_iff [simp]:
   462   "a / b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
   463   by (simp add: divide_inverse)
   464 
   465 lemma divide_cancel_right [simp]:
   466   "a / c = b / c \<longleftrightarrow> c = 0 \<or> a = b"
   467   apply (cases "c=0", simp)
   468   apply (simp add: divide_inverse)
   469   done
   470 
   471 lemma divide_cancel_left [simp]:
   472   "c / a = c / b \<longleftrightarrow> c = 0 \<or> a = b" 
   473   apply (cases "c=0", simp)
   474   apply (simp add: divide_inverse)
   475   done
   476 
   477 lemma divide_eq_1_iff [simp]:
   478   "a / b = 1 \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
   479   apply (cases "b=0", simp)
   480   apply (simp add: right_inverse_eq)
   481   done
   482 
   483 lemma one_eq_divide_iff [simp]:
   484   "1 = a / b \<longleftrightarrow> b \<noteq> 0 \<and> a = b"
   485   by (simp add: eq_commute [of 1])
   486 
   487 lemma times_divide_times_eq:
   488   "(x / y) * (z / w) = (x * z) / (y * w)"
   489   by simp
   490 
   491 lemma add_frac_num:
   492   "y \<noteq> 0 \<Longrightarrow> x / y + z = (x + z * y) / y"
   493   by (simp add: add_divide_distrib)
   494 
   495 lemma add_num_frac:
   496   "y \<noteq> 0 \<Longrightarrow> z + x / y = (x + z * y) / y"
   497   by (simp add: add_divide_distrib add.commute)
   498 
   499 end
   500 
   501 
   502 subsection {* Ordered fields *}
   503 
   504 class linordered_field = field + linordered_idom
   505 begin
   506 
   507 lemma positive_imp_inverse_positive: 
   508   assumes a_gt_0: "0 < a" 
   509   shows "0 < inverse a"
   510 proof -
   511   have "0 < a * inverse a" 
   512     by (simp add: a_gt_0 [THEN less_imp_not_eq2])
   513   thus "0 < inverse a" 
   514     by (simp add: a_gt_0 [THEN less_not_sym] zero_less_mult_iff)
   515 qed
   516 
   517 lemma negative_imp_inverse_negative:
   518   "a < 0 \<Longrightarrow> inverse a < 0"
   519   by (insert positive_imp_inverse_positive [of "-a"], 
   520     simp add: nonzero_inverse_minus_eq less_imp_not_eq)
   521 
   522 lemma inverse_le_imp_le:
   523   assumes invle: "inverse a \<le> inverse b" and apos: "0 < a"
   524   shows "b \<le> a"
   525 proof (rule classical)
   526   assume "~ b \<le> a"
   527   hence "a < b"  by (simp add: linorder_not_le)
   528   hence bpos: "0 < b"  by (blast intro: apos less_trans)
   529   hence "a * inverse a \<le> a * inverse b"
   530     by (simp add: apos invle less_imp_le mult_left_mono)
   531   hence "(a * inverse a) * b \<le> (a * inverse b) * b"
   532     by (simp add: bpos less_imp_le mult_right_mono)
   533   thus "b \<le> a"  by (simp add: mult.assoc apos bpos less_imp_not_eq2)
   534 qed
   535 
   536 lemma inverse_positive_imp_positive:
   537   assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
   538   shows "0 < a"
   539 proof -
   540   have "0 < inverse (inverse a)"
   541     using inv_gt_0 by (rule positive_imp_inverse_positive)
   542   thus "0 < a"
   543     using nz by (simp add: nonzero_inverse_inverse_eq)
   544 qed
   545 
   546 lemma inverse_negative_imp_negative:
   547   assumes inv_less_0: "inverse a < 0" and nz: "a \<noteq> 0"
   548   shows "a < 0"
   549 proof -
   550   have "inverse (inverse a) < 0"
   551     using inv_less_0 by (rule negative_imp_inverse_negative)
   552   thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
   553 qed
   554 
   555 lemma linordered_field_no_lb:
   556   "\<forall>x. \<exists>y. y < x"
   557 proof
   558   fix x::'a
   559   have m1: "- (1::'a) < 0" by simp
   560   from add_strict_right_mono[OF m1, where c=x] 
   561   have "(- 1) + x < x" by simp
   562   thus "\<exists>y. y < x" by blast
   563 qed
   564 
   565 lemma linordered_field_no_ub:
   566   "\<forall> x. \<exists>y. y > x"
   567 proof
   568   fix x::'a
   569   have m1: " (1::'a) > 0" by simp
   570   from add_strict_right_mono[OF m1, where c=x] 
   571   have "1 + x > x" by simp
   572   thus "\<exists>y. y > x" by blast
   573 qed
   574 
   575 lemma less_imp_inverse_less:
   576   assumes less: "a < b" and apos:  "0 < a"
   577   shows "inverse b < inverse a"
   578 proof (rule ccontr)
   579   assume "~ inverse b < inverse a"
   580   hence "inverse a \<le> inverse b" by simp
   581   hence "~ (a < b)"
   582     by (simp add: not_less inverse_le_imp_le [OF _ apos])
   583   thus False by (rule notE [OF _ less])
   584 qed
   585 
   586 lemma inverse_less_imp_less:
   587   "inverse a < inverse b \<Longrightarrow> 0 < a \<Longrightarrow> b < a"
   588 apply (simp add: less_le [of "inverse a"] less_le [of "b"])
   589 apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
   590 done
   591 
   592 text{*Both premises are essential. Consider -1 and 1.*}
   593 lemma inverse_less_iff_less [simp]:
   594   "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
   595   by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
   596 
   597 lemma le_imp_inverse_le:
   598   "a \<le> b \<Longrightarrow> 0 < a \<Longrightarrow> inverse b \<le> inverse a"
   599   by (force simp add: le_less less_imp_inverse_less)
   600 
   601 lemma inverse_le_iff_le [simp]:
   602   "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
   603   by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
   604 
   605 
   606 text{*These results refer to both operands being negative.  The opposite-sign
   607 case is trivial, since inverse preserves signs.*}
   608 lemma inverse_le_imp_le_neg:
   609   "inverse a \<le> inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b \<le> a"
   610 apply (rule classical) 
   611 apply (subgoal_tac "a < 0") 
   612  prefer 2 apply force
   613 apply (insert inverse_le_imp_le [of "-b" "-a"])
   614 apply (simp add: nonzero_inverse_minus_eq) 
   615 done
   616 
   617 lemma less_imp_inverse_less_neg:
   618    "a < b \<Longrightarrow> b < 0 \<Longrightarrow> inverse b < inverse a"
   619 apply (subgoal_tac "a < 0") 
   620  prefer 2 apply (blast intro: less_trans) 
   621 apply (insert less_imp_inverse_less [of "-b" "-a"])
   622 apply (simp add: nonzero_inverse_minus_eq) 
   623 done
   624 
   625 lemma inverse_less_imp_less_neg:
   626    "inverse a < inverse b \<Longrightarrow> b < 0 \<Longrightarrow> b < a"
   627 apply (rule classical) 
   628 apply (subgoal_tac "a < 0") 
   629  prefer 2
   630  apply force
   631 apply (insert inverse_less_imp_less [of "-b" "-a"])
   632 apply (simp add: nonzero_inverse_minus_eq) 
   633 done
   634 
   635 lemma inverse_less_iff_less_neg [simp]:
   636   "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a < inverse b \<longleftrightarrow> b < a"
   637 apply (insert inverse_less_iff_less [of "-b" "-a"])
   638 apply (simp del: inverse_less_iff_less 
   639             add: nonzero_inverse_minus_eq)
   640 done
   641 
   642 lemma le_imp_inverse_le_neg:
   643   "a \<le> b \<Longrightarrow> b < 0 ==> inverse b \<le> inverse a"
   644   by (force simp add: le_less less_imp_inverse_less_neg)
   645 
   646 lemma inverse_le_iff_le_neg [simp]:
   647   "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> inverse a \<le> inverse b \<longleftrightarrow> b \<le> a"
   648   by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
   649 
   650 lemma one_less_inverse:
   651   "0 < a \<Longrightarrow> a < 1 \<Longrightarrow> 1 < inverse a"
   652   using less_imp_inverse_less [of a 1, unfolded inverse_1] .
   653 
   654 lemma one_le_inverse:
   655   "0 < a \<Longrightarrow> a \<le> 1 \<Longrightarrow> 1 \<le> inverse a"
   656   using le_imp_inverse_le [of a 1, unfolded inverse_1] .
   657 
   658 lemma pos_le_divide_eq [field_simps]: "0 < c \<Longrightarrow> a \<le> b / c \<longleftrightarrow> a * c \<le> b"
   659 proof -
   660   assume less: "0<c"
   661   hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
   662     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   663   also have "... = (a*c \<le> b)"
   664     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   665   finally show ?thesis .
   666 qed
   667 
   668 lemma neg_le_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a \<le> b / c \<longleftrightarrow> b \<le> a * c"
   669 proof -
   670   assume less: "c<0"
   671   hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
   672     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   673   also have "... = (b \<le> a*c)"
   674     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   675   finally show ?thesis .
   676 qed
   677 
   678 lemma pos_less_divide_eq [field_simps]: "0 < c \<Longrightarrow> a < b / c \<longleftrightarrow> a * c < b"
   679 proof -
   680   assume less: "0<c"
   681   hence "(a < b/c) = (a*c < (b/c)*c)"
   682     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   683   also have "... = (a*c < b)"
   684     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   685   finally show ?thesis .
   686 qed
   687 
   688 lemma neg_less_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a < b / c \<longleftrightarrow> b < a * c"
   689 proof -
   690   assume less: "c<0"
   691   hence "(a < b/c) = ((b/c)*c < a*c)"
   692     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   693   also have "... = (b < a*c)"
   694     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   695   finally show ?thesis .
   696 qed
   697 
   698 lemma pos_divide_less_eq [field_simps]: "0 < c \<Longrightarrow> b / c < a \<longleftrightarrow> b < a * c"
   699 proof -
   700   assume less: "0<c"
   701   hence "(b/c < a) = ((b/c)*c < a*c)"
   702     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   703   also have "... = (b < a*c)"
   704     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   705   finally show ?thesis .
   706 qed
   707 
   708 lemma neg_divide_less_eq [field_simps]: "c < 0 \<Longrightarrow> b / c < a \<longleftrightarrow> a * c < b"
   709 proof -
   710   assume less: "c<0"
   711   hence "(b/c < a) = (a*c < (b/c)*c)"
   712     by (simp add: mult_less_cancel_right_disj less_not_sym [OF less] del: times_divide_eq)
   713   also have "... = (a*c < b)"
   714     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   715   finally show ?thesis .
   716 qed
   717 
   718 lemma pos_divide_le_eq [field_simps]: "0 < c \<Longrightarrow> b / c \<le> a \<longleftrightarrow> b \<le> a * c"
   719 proof -
   720   assume less: "0<c"
   721   hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
   722     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   723   also have "... = (b \<le> a*c)"
   724     by (simp add: less_imp_not_eq2 [OF less] divide_inverse mult.assoc) 
   725   finally show ?thesis .
   726 qed
   727 
   728 lemma neg_divide_le_eq [field_simps]: "c < 0 \<Longrightarrow> b / c \<le> a \<longleftrightarrow> a * c \<le> b"
   729 proof -
   730   assume less: "c<0"
   731   hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
   732     by (simp add: mult_le_cancel_right less_not_sym [OF less] del: times_divide_eq)
   733   also have "... = (a*c \<le> b)"
   734     by (simp add: less_imp_not_eq [OF less] divide_inverse mult.assoc) 
   735   finally show ?thesis .
   736 qed
   737 
   738 text{* The following @{text field_simps} rules are necessary, as minus is always moved atop of
   739 division but we want to get rid of division. *}
   740 
   741 lemma pos_le_minus_divide_eq [field_simps]: "0 < c \<Longrightarrow> a \<le> - (b / c) \<longleftrightarrow> a * c \<le> - b"
   742   unfolding minus_divide_left by (rule pos_le_divide_eq)
   743 
   744 lemma neg_le_minus_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a \<le> - (b / c) \<longleftrightarrow> - b \<le> a * c"
   745   unfolding minus_divide_left by (rule neg_le_divide_eq)
   746 
   747 lemma pos_less_minus_divide_eq [field_simps]: "0 < c \<Longrightarrow> a < - (b / c) \<longleftrightarrow> a * c < - b"
   748   unfolding minus_divide_left by (rule pos_less_divide_eq)
   749 
   750 lemma neg_less_minus_divide_eq [field_simps]: "c < 0 \<Longrightarrow> a < - (b / c) \<longleftrightarrow> - b < a * c"
   751   unfolding minus_divide_left by (rule neg_less_divide_eq)
   752 
   753 lemma pos_minus_divide_less_eq [field_simps]: "0 < c \<Longrightarrow> - (b / c) < a \<longleftrightarrow> - b < a * c"
   754   unfolding minus_divide_left by (rule pos_divide_less_eq)
   755 
   756 lemma neg_minus_divide_less_eq [field_simps]: "c < 0 \<Longrightarrow> - (b / c) < a \<longleftrightarrow> a * c < - b"
   757   unfolding minus_divide_left by (rule neg_divide_less_eq)
   758 
   759 lemma pos_minus_divide_le_eq [field_simps]: "0 < c \<Longrightarrow> - (b / c) \<le> a \<longleftrightarrow> - b \<le> a * c"
   760   unfolding minus_divide_left by (rule pos_divide_le_eq)
   761 
   762 lemma neg_minus_divide_le_eq [field_simps]: "c < 0 \<Longrightarrow> - (b / c) \<le> a \<longleftrightarrow> a * c \<le> - b"
   763   unfolding minus_divide_left by (rule neg_divide_le_eq)
   764 
   765 lemma frac_less_eq:
   766   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y < w / z \<longleftrightarrow> (x * z - w * y) / (y * z) < 0"
   767   by (subst less_iff_diff_less_0) (simp add: diff_frac_eq )
   768 
   769 lemma frac_le_eq:
   770   "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y \<le> w / z \<longleftrightarrow> (x * z - w * y) / (y * z) \<le> 0"
   771   by (subst le_iff_diff_le_0) (simp add: diff_frac_eq )
   772 
   773 text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
   774 of positivity/negativity needed for @{text field_simps}. Have not added @{text
   775 sign_simps} to @{text field_simps} because the former can lead to case
   776 explosions. *}
   777 
   778 lemmas sign_simps = algebra_simps zero_less_mult_iff mult_less_0_iff
   779 
   780 lemmas (in -) sign_simps = algebra_simps zero_less_mult_iff mult_less_0_iff
   781 
   782 (* Only works once linear arithmetic is installed:
   783 text{*An example:*}
   784 lemma fixes a b c d e f :: "'a::linordered_field"
   785 shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
   786  ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
   787  ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
   788 apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
   789  prefer 2 apply(simp add:sign_simps)
   790 apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
   791  prefer 2 apply(simp add:sign_simps)
   792 apply(simp add:field_simps)
   793 done
   794 *)
   795 
   796 lemma divide_pos_pos[simp]:
   797   "0 < x ==> 0 < y ==> 0 < x / y"
   798 by(simp add:field_simps)
   799 
   800 lemma divide_nonneg_pos:
   801   "0 <= x ==> 0 < y ==> 0 <= x / y"
   802 by(simp add:field_simps)
   803 
   804 lemma divide_neg_pos:
   805   "x < 0 ==> 0 < y ==> x / y < 0"
   806 by(simp add:field_simps)
   807 
   808 lemma divide_nonpos_pos:
   809   "x <= 0 ==> 0 < y ==> x / y <= 0"
   810 by(simp add:field_simps)
   811 
   812 lemma divide_pos_neg:
   813   "0 < x ==> y < 0 ==> x / y < 0"
   814 by(simp add:field_simps)
   815 
   816 lemma divide_nonneg_neg:
   817   "0 <= x ==> y < 0 ==> x / y <= 0" 
   818 by(simp add:field_simps)
   819 
   820 lemma divide_neg_neg:
   821   "x < 0 ==> y < 0 ==> 0 < x / y"
   822 by(simp add:field_simps)
   823 
   824 lemma divide_nonpos_neg:
   825   "x <= 0 ==> y < 0 ==> 0 <= x / y"
   826 by(simp add:field_simps)
   827 
   828 lemma divide_strict_right_mono:
   829      "[|a < b; 0 < c|] ==> a / c < b / c"
   830 by (simp add: less_imp_not_eq2 divide_inverse mult_strict_right_mono 
   831               positive_imp_inverse_positive)
   832 
   833 
   834 lemma divide_strict_right_mono_neg:
   835      "[|b < a; c < 0|] ==> a / c < b / c"
   836 apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
   837 apply (simp add: less_imp_not_eq nonzero_minus_divide_right [symmetric])
   838 done
   839 
   840 text{*The last premise ensures that @{term a} and @{term b} 
   841       have the same sign*}
   842 lemma divide_strict_left_mono:
   843   "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / b"
   844   by (auto simp: field_simps zero_less_mult_iff mult_strict_right_mono)
   845 
   846 lemma divide_left_mono:
   847   "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / b"
   848   by (auto simp: field_simps zero_less_mult_iff mult_right_mono)
   849 
   850 lemma divide_strict_left_mono_neg:
   851   "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / b"
   852   by (auto simp: field_simps zero_less_mult_iff mult_strict_right_mono_neg)
   853 
   854 lemma mult_imp_div_pos_le: "0 < y ==> x <= z * y ==>
   855     x / y <= z"
   856 by (subst pos_divide_le_eq, assumption+)
   857 
   858 lemma mult_imp_le_div_pos: "0 < y ==> z * y <= x ==>
   859     z <= x / y"
   860 by(simp add:field_simps)
   861 
   862 lemma mult_imp_div_pos_less: "0 < y ==> x < z * y ==>
   863     x / y < z"
   864 by(simp add:field_simps)
   865 
   866 lemma mult_imp_less_div_pos: "0 < y ==> z * y < x ==>
   867     z < x / y"
   868 by(simp add:field_simps)
   869 
   870 lemma frac_le: "0 <= x ==> 
   871     x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
   872   apply (rule mult_imp_div_pos_le)
   873   apply simp
   874   apply (subst times_divide_eq_left)
   875   apply (rule mult_imp_le_div_pos, assumption)
   876   apply (rule mult_mono)
   877   apply simp_all
   878 done
   879 
   880 lemma frac_less: "0 <= x ==> 
   881     x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
   882   apply (rule mult_imp_div_pos_less)
   883   apply simp
   884   apply (subst times_divide_eq_left)
   885   apply (rule mult_imp_less_div_pos, assumption)
   886   apply (erule mult_less_le_imp_less)
   887   apply simp_all
   888 done
   889 
   890 lemma frac_less2: "0 < x ==> 
   891     x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
   892   apply (rule mult_imp_div_pos_less)
   893   apply simp_all
   894   apply (rule mult_imp_less_div_pos, assumption)
   895   apply (erule mult_le_less_imp_less)
   896   apply simp_all
   897 done
   898 
   899 lemma less_half_sum: "a < b ==> a < (a+b) / (1+1)"
   900 by (simp add: field_simps zero_less_two)
   901 
   902 lemma gt_half_sum: "a < b ==> (a+b)/(1+1) < b"
   903 by (simp add: field_simps zero_less_two)
   904 
   905 subclass unbounded_dense_linorder
   906 proof
   907   fix x y :: 'a
   908   from less_add_one show "\<exists>y. x < y" .. 
   909   from less_add_one have "x + (- 1) < (x + 1) + (- 1)" by (rule add_strict_right_mono)
   910   then have "x - 1 < x + 1 - 1" by simp
   911   then have "x - 1 < x" by (simp add: algebra_simps)
   912   then show "\<exists>y. y < x" ..
   913   show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
   914 qed
   915 
   916 lemma nonzero_abs_inverse:
   917      "a \<noteq> 0 ==> \<bar>inverse a\<bar> = inverse \<bar>a\<bar>"
   918 apply (auto simp add: neq_iff abs_if nonzero_inverse_minus_eq 
   919                       negative_imp_inverse_negative)
   920 apply (blast intro: positive_imp_inverse_positive elim: less_asym) 
   921 done
   922 
   923 lemma nonzero_abs_divide:
   924      "b \<noteq> 0 ==> \<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
   925   by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
   926 
   927 lemma field_le_epsilon:
   928   assumes e: "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
   929   shows "x \<le> y"
   930 proof (rule dense_le)
   931   fix t assume "t < x"
   932   hence "0 < x - t" by (simp add: less_diff_eq)
   933   from e [OF this] have "x + 0 \<le> x + (y - t)" by (simp add: algebra_simps)
   934   then have "0 \<le> y - t" by (simp only: add_le_cancel_left)
   935   then show "t \<le> y" by (simp add: algebra_simps)
   936 qed
   937 
   938 end
   939 
   940 class linordered_field_inverse_zero = linordered_field + field_inverse_zero
   941 begin
   942 
   943 lemma inverse_positive_iff_positive [simp]:
   944   "(0 < inverse a) = (0 < a)"
   945 apply (cases "a = 0", simp)
   946 apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
   947 done
   948 
   949 lemma inverse_negative_iff_negative [simp]:
   950   "(inverse a < 0) = (a < 0)"
   951 apply (cases "a = 0", simp)
   952 apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
   953 done
   954 
   955 lemma inverse_nonnegative_iff_nonnegative [simp]:
   956   "0 \<le> inverse a \<longleftrightarrow> 0 \<le> a"
   957   by (simp add: not_less [symmetric])
   958 
   959 lemma inverse_nonpositive_iff_nonpositive [simp]:
   960   "inverse a \<le> 0 \<longleftrightarrow> a \<le> 0"
   961   by (simp add: not_less [symmetric])
   962 
   963 lemma one_less_inverse_iff: "1 < inverse x \<longleftrightarrow> 0 < x \<and> x < 1"
   964   using less_trans[of 1 x 0 for x]
   965   by (cases x 0 rule: linorder_cases) (auto simp add: field_simps)
   966 
   967 lemma one_le_inverse_iff: "1 \<le> inverse x \<longleftrightarrow> 0 < x \<and> x \<le> 1"
   968 proof (cases "x = 1")
   969   case True then show ?thesis by simp
   970 next
   971   case False then have "inverse x \<noteq> 1" by simp
   972   then have "1 \<noteq> inverse x" by blast
   973   then have "1 \<le> inverse x \<longleftrightarrow> 1 < inverse x" by (simp add: le_less)
   974   with False show ?thesis by (auto simp add: one_less_inverse_iff)
   975 qed
   976 
   977 lemma inverse_less_1_iff: "inverse x < 1 \<longleftrightarrow> x \<le> 0 \<or> 1 < x"
   978   by (simp add: not_le [symmetric] one_le_inverse_iff) 
   979 
   980 lemma inverse_le_1_iff: "inverse x \<le> 1 \<longleftrightarrow> x \<le> 0 \<or> 1 \<le> x"
   981   by (simp add: not_less [symmetric] one_less_inverse_iff) 
   982 
   983 lemma [divide_simps]:
   984   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)"
   985     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)"
   986     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)"
   987     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)"
   988     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)"
   989     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)"
   990     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)"
   991     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)"
   992   by (auto simp: field_simps not_less dest: antisym)
   993 
   994 text {*Division and Signs*}
   995 
   996 lemma
   997   shows zero_less_divide_iff: "0 < a / b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
   998     and divide_less_0_iff: "a / b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
   999     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"
  1000     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"
  1001   by (auto simp add: divide_simps)
  1002 
  1003 text {* Division and the Number One *}
  1004 
  1005 text{*Simplify expressions equated with 1*}
  1006 
  1007 lemma zero_eq_1_divide_iff [simp]: "0 = 1 / a \<longleftrightarrow> a = 0"
  1008   by (cases "a = 0") (auto simp: field_simps)
  1009 
  1010 lemma one_divide_eq_0_iff [simp]: "1 / a = 0 \<longleftrightarrow> a = 0"
  1011   using zero_eq_1_divide_iff[of a] by simp
  1012 
  1013 text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
  1014 
  1015 lemma zero_le_divide_1_iff [simp]:
  1016   "0 \<le> 1 / a \<longleftrightarrow> 0 \<le> a"
  1017   by (simp add: zero_le_divide_iff)
  1018 
  1019 lemma zero_less_divide_1_iff [simp]:
  1020   "0 < 1 / a \<longleftrightarrow> 0 < a"
  1021   by (simp add: zero_less_divide_iff)
  1022 
  1023 lemma divide_le_0_1_iff [simp]:
  1024   "1 / a \<le> 0 \<longleftrightarrow> a \<le> 0"
  1025   by (simp add: divide_le_0_iff)
  1026 
  1027 lemma divide_less_0_1_iff [simp]:
  1028   "1 / a < 0 \<longleftrightarrow> a < 0"
  1029   by (simp add: divide_less_0_iff)
  1030 
  1031 lemma divide_right_mono:
  1032      "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/c"
  1033 by (force simp add: divide_strict_right_mono le_less)
  1034 
  1035 lemma divide_right_mono_neg: "a <= b 
  1036     ==> c <= 0 ==> b / c <= a / c"
  1037 apply (drule divide_right_mono [of _ _ "- c"])
  1038 apply auto
  1039 done
  1040 
  1041 lemma divide_left_mono_neg: "a <= b 
  1042     ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
  1043   apply (drule divide_left_mono [of _ _ "- c"])
  1044   apply (auto simp add: mult.commute)
  1045 done
  1046 
  1047 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)"
  1048   by (cases a 0 b 0 rule: linorder_cases[case_product linorder_cases])
  1049      (auto simp add: field_simps zero_less_mult_iff mult_le_0_iff)
  1050 
  1051 lemma inverse_less_iff: "inverse a < inverse b \<longleftrightarrow> (0 < a * b \<longrightarrow> b < a) \<and> (a * b \<le> 0 \<longrightarrow> a < b)"
  1052   by (subst less_le) (auto simp: inverse_le_iff)
  1053 
  1054 lemma divide_le_cancel: "a / c \<le> b / c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
  1055   by (simp add: divide_inverse mult_le_cancel_right)
  1056 
  1057 lemma divide_less_cancel: "a / c < b / c \<longleftrightarrow> (0 < c \<longrightarrow> a < b) \<and> (c < 0 \<longrightarrow> b < a) \<and> c \<noteq> 0"
  1058   by (auto simp add: divide_inverse mult_less_cancel_right)
  1059 
  1060 text{*Simplify quotients that are compared with the value 1.*}
  1061 
  1062 lemma le_divide_eq_1:
  1063   "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
  1064 by (auto simp add: le_divide_eq)
  1065 
  1066 lemma divide_le_eq_1:
  1067   "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
  1068 by (auto simp add: divide_le_eq)
  1069 
  1070 lemma less_divide_eq_1:
  1071   "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
  1072 by (auto simp add: less_divide_eq)
  1073 
  1074 lemma divide_less_eq_1:
  1075   "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
  1076 by (auto simp add: divide_less_eq)
  1077 
  1078 lemma divide_nonneg_nonneg [simp]:
  1079   "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x / y"
  1080   by (auto simp add: divide_simps)
  1081 
  1082 lemma divide_nonpos_nonpos:
  1083   "x \<le> 0 \<Longrightarrow> y \<le> 0 \<Longrightarrow> 0 \<le> x / y"
  1084   by (auto simp add: divide_simps)
  1085 
  1086 lemma divide_nonneg_nonpos:
  1087   "0 \<le> x \<Longrightarrow> y \<le> 0 \<Longrightarrow> x / y \<le> 0"
  1088   by (auto simp add: divide_simps)
  1089 
  1090 lemma divide_nonpos_nonneg:
  1091   "x \<le> 0 \<Longrightarrow> 0 \<le> y \<Longrightarrow> x / y \<le> 0"
  1092   by (auto simp add: divide_simps)
  1093 
  1094 text {*Conditional Simplification Rules: No Case Splits*}
  1095 
  1096 lemma le_divide_eq_1_pos [simp]:
  1097   "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
  1098 by (auto simp add: le_divide_eq)
  1099 
  1100 lemma le_divide_eq_1_neg [simp]:
  1101   "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
  1102 by (auto simp add: le_divide_eq)
  1103 
  1104 lemma divide_le_eq_1_pos [simp]:
  1105   "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
  1106 by (auto simp add: divide_le_eq)
  1107 
  1108 lemma divide_le_eq_1_neg [simp]:
  1109   "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
  1110 by (auto simp add: divide_le_eq)
  1111 
  1112 lemma less_divide_eq_1_pos [simp]:
  1113   "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
  1114 by (auto simp add: less_divide_eq)
  1115 
  1116 lemma less_divide_eq_1_neg [simp]:
  1117   "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
  1118 by (auto simp add: less_divide_eq)
  1119 
  1120 lemma divide_less_eq_1_pos [simp]:
  1121   "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
  1122 by (auto simp add: divide_less_eq)
  1123 
  1124 lemma divide_less_eq_1_neg [simp]:
  1125   "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
  1126 by (auto simp add: divide_less_eq)
  1127 
  1128 lemma eq_divide_eq_1 [simp]:
  1129   "(1 = b/a) = ((a \<noteq> 0 & a = b))"
  1130 by (auto simp add: eq_divide_eq)
  1131 
  1132 lemma divide_eq_eq_1 [simp]:
  1133   "(b/a = 1) = ((a \<noteq> 0 & a = b))"
  1134 by (auto simp add: divide_eq_eq)
  1135 
  1136 lemma abs_inverse [simp]:
  1137      "\<bar>inverse a\<bar> = 
  1138       inverse \<bar>a\<bar>"
  1139 apply (cases "a=0", simp) 
  1140 apply (simp add: nonzero_abs_inverse) 
  1141 done
  1142 
  1143 lemma abs_divide [simp]:
  1144      "\<bar>a / b\<bar> = \<bar>a\<bar> / \<bar>b\<bar>"
  1145 apply (cases "b=0", simp) 
  1146 apply (simp add: nonzero_abs_divide) 
  1147 done
  1148 
  1149 lemma abs_div_pos: "0 < y ==> 
  1150     \<bar>x\<bar> / y = \<bar>x / y\<bar>"
  1151   apply (subst abs_divide)
  1152   apply (simp add: order_less_imp_le)
  1153 done
  1154 
  1155 lemma zero_le_divide_abs_iff [simp]: "(0 \<le> a / abs b) = (0 \<le> a | b = 0)" 
  1156 by (auto simp: zero_le_divide_iff)
  1157 
  1158 lemma divide_le_0_abs_iff [simp]: "(a / abs b \<le> 0) = (a \<le> 0 | b = 0)" 
  1159 by (auto simp: divide_le_0_iff)
  1160 
  1161 lemma field_le_mult_one_interval:
  1162   assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
  1163   shows "x \<le> y"
  1164 proof (cases "0 < x")
  1165   assume "0 < x"
  1166   thus ?thesis
  1167     using dense_le_bounded[of 0 1 "y/x"] *
  1168     unfolding le_divide_eq if_P[OF `0 < x`] by simp
  1169 next
  1170   assume "\<not>0 < x" hence "x \<le> 0" by simp
  1171   obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1\<Colon>'a"] by auto
  1172   hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] `x \<le> 0` by auto
  1173   also note *[OF s]
  1174   finally show ?thesis .
  1175 qed
  1176 
  1177 end
  1178 
  1179 code_identifier
  1180   code_module Fields \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
  1181 
  1182 end