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