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