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