src/HOL/Fields.thy
author wenzelm
Mon Mar 22 20:58:52 2010 +0100 (2010-03-22)
changeset 35898 c890a3835d15
parent 35828 46cfc4b8112e
child 36301 72f4d079ebf8
permissions -rw-r--r--
recovered header;
     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, no_atp]:
    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, no_atp]:
    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 [no_atp] = 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, no_atp]:
   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, no_atp]:
   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, no_atp]:
   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, no_atp]:
   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, no_atp]:
   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, no_atp]:
   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, no_atp]: "(-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[no_atp] = 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
   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
   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
   293 done
   294 
   295 lemma divide_divide_eq_right [simp,no_atp]:
   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,no_atp]:
   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,no_atp]:
   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, no_atp]:
   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])
   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,no_atp]:
   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,no_atp]:
   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,no_atp]:
   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,no_atp]:
   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)
   528 
   529 lemma inverse_less_1_iff:
   530   "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{linordered_field,division_by_zero}))"
   531 by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
   532 
   533 lemma inverse_le_1_iff:
   534   "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{linordered_field,division_by_zero}))"
   535 by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
   536 
   537 
   538 subsection{*Simplification of Inequalities Involving Literal Divisors*}
   539 
   540 lemma pos_le_divide_eq: "0 < (c::'a::linordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
   541 proof -
   542   assume less: "0<c"
   543   hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
   544     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   545   also have "... = (a*c \<le> b)"
   546     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   547   finally show ?thesis .
   548 qed
   549 
   550 lemma neg_le_divide_eq: "c < (0::'a::linordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
   551 proof -
   552   assume less: "c<0"
   553   hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
   554     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   555   also have "... = (b \<le> a*c)"
   556     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   557   finally show ?thesis .
   558 qed
   559 
   560 lemma le_divide_eq:
   561   "(a \<le> b/c) = 
   562    (if 0 < c then a*c \<le> b
   563              else if c < 0 then b \<le> a*c
   564              else  a \<le> (0::'a::{linordered_field,division_by_zero}))"
   565 apply (cases "c=0", simp) 
   566 apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
   567 done
   568 
   569 lemma pos_divide_le_eq: "0 < (c::'a::linordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
   570 proof -
   571   assume less: "0<c"
   572   hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
   573     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   574   also have "... = (b \<le> a*c)"
   575     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   576   finally show ?thesis .
   577 qed
   578 
   579 lemma neg_divide_le_eq: "c < (0::'a::linordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
   580 proof -
   581   assume less: "c<0"
   582   hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
   583     by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   584   also have "... = (a*c \<le> b)"
   585     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   586   finally show ?thesis .
   587 qed
   588 
   589 lemma divide_le_eq:
   590   "(b/c \<le> a) = 
   591    (if 0 < c then b \<le> a*c
   592              else if c < 0 then a*c \<le> b
   593              else 0 \<le> (a::'a::{linordered_field,division_by_zero}))"
   594 apply (cases "c=0", simp) 
   595 apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
   596 done
   597 
   598 lemma pos_less_divide_eq:
   599      "0 < (c::'a::linordered_field) ==> (a < b/c) = (a*c < b)"
   600 proof -
   601   assume less: "0<c"
   602   hence "(a < b/c) = (a*c < (b/c)*c)"
   603     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   604   also have "... = (a*c < b)"
   605     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   606   finally show ?thesis .
   607 qed
   608 
   609 lemma neg_less_divide_eq:
   610  "c < (0::'a::linordered_field) ==> (a < b/c) = (b < a*c)"
   611 proof -
   612   assume less: "c<0"
   613   hence "(a < b/c) = ((b/c)*c < a*c)"
   614     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   615   also have "... = (b < a*c)"
   616     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   617   finally show ?thesis .
   618 qed
   619 
   620 lemma less_divide_eq:
   621   "(a < b/c) = 
   622    (if 0 < c then a*c < b
   623              else if c < 0 then b < a*c
   624              else  a < (0::'a::{linordered_field,division_by_zero}))"
   625 apply (cases "c=0", simp) 
   626 apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
   627 done
   628 
   629 lemma pos_divide_less_eq:
   630      "0 < (c::'a::linordered_field) ==> (b/c < a) = (b < a*c)"
   631 proof -
   632   assume less: "0<c"
   633   hence "(b/c < a) = ((b/c)*c < a*c)"
   634     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   635   also have "... = (b < a*c)"
   636     by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   637   finally show ?thesis .
   638 qed
   639 
   640 lemma neg_divide_less_eq:
   641  "c < (0::'a::linordered_field) ==> (b/c < a) = (a*c < b)"
   642 proof -
   643   assume less: "c<0"
   644   hence "(b/c < a) = (a*c < (b/c)*c)"
   645     by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   646   also have "... = (a*c < b)"
   647     by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   648   finally show ?thesis .
   649 qed
   650 
   651 lemma divide_less_eq:
   652   "(b/c < a) = 
   653    (if 0 < c then b < a*c
   654              else if c < 0 then a*c < b
   655              else 0 < (a::'a::{linordered_field,division_by_zero}))"
   656 apply (cases "c=0", simp) 
   657 apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
   658 done
   659 
   660 
   661 subsection{*Field simplification*}
   662 
   663 text{* Lemmas @{text field_simps} multiply with denominators in in(equations)
   664 if they can be proved to be non-zero (for equations) or positive/negative
   665 (for inequations). Can be too aggressive and is therefore separate from the
   666 more benign @{text algebra_simps}. *}
   667 
   668 lemmas field_simps[no_atp] = field_eq_simps
   669   (* multiply ineqn *)
   670   pos_divide_less_eq neg_divide_less_eq
   671   pos_less_divide_eq neg_less_divide_eq
   672   pos_divide_le_eq neg_divide_le_eq
   673   pos_le_divide_eq neg_le_divide_eq
   674 
   675 text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
   676 of positivity/negativity needed for @{text field_simps}. Have not added @{text
   677 sign_simps} to @{text field_simps} because the former can lead to case
   678 explosions. *}
   679 
   680 lemmas sign_simps[no_atp] = group_simps
   681   zero_less_mult_iff  mult_less_0_iff
   682 
   683 (* Only works once linear arithmetic is installed:
   684 text{*An example:*}
   685 lemma fixes a b c d e f :: "'a::linordered_field"
   686 shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
   687  ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
   688  ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
   689 apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
   690  prefer 2 apply(simp add:sign_simps)
   691 apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
   692  prefer 2 apply(simp add:sign_simps)
   693 apply(simp add:field_simps)
   694 done
   695 *)
   696 
   697 
   698 subsection{*Division and Signs*}
   699 
   700 lemma zero_less_divide_iff:
   701      "((0::'a::{linordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
   702 by (simp add: divide_inverse zero_less_mult_iff)
   703 
   704 lemma divide_less_0_iff:
   705      "(a/b < (0::'a::{linordered_field,division_by_zero})) = 
   706       (0 < a & b < 0 | a < 0 & 0 < b)"
   707 by (simp add: divide_inverse mult_less_0_iff)
   708 
   709 lemma zero_le_divide_iff:
   710      "((0::'a::{linordered_field,division_by_zero}) \<le> a/b) =
   711       (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
   712 by (simp add: divide_inverse zero_le_mult_iff)
   713 
   714 lemma divide_le_0_iff:
   715      "(a/b \<le> (0::'a::{linordered_field,division_by_zero})) =
   716       (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
   717 by (simp add: divide_inverse mult_le_0_iff)
   718 
   719 lemma divide_eq_0_iff [simp,no_atp]:
   720      "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
   721 by (simp add: divide_inverse)
   722 
   723 lemma divide_pos_pos:
   724   "0 < (x::'a::linordered_field) ==> 0 < y ==> 0 < x / y"
   725 by(simp add:field_simps)
   726 
   727 
   728 lemma divide_nonneg_pos:
   729   "0 <= (x::'a::linordered_field) ==> 0 < y ==> 0 <= x / y"
   730 by(simp add:field_simps)
   731 
   732 lemma divide_neg_pos:
   733   "(x::'a::linordered_field) < 0 ==> 0 < y ==> x / y < 0"
   734 by(simp add:field_simps)
   735 
   736 lemma divide_nonpos_pos:
   737   "(x::'a::linordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
   738 by(simp add:field_simps)
   739 
   740 lemma divide_pos_neg:
   741   "0 < (x::'a::linordered_field) ==> y < 0 ==> x / y < 0"
   742 by(simp add:field_simps)
   743 
   744 lemma divide_nonneg_neg:
   745   "0 <= (x::'a::linordered_field) ==> y < 0 ==> x / y <= 0" 
   746 by(simp add:field_simps)
   747 
   748 lemma divide_neg_neg:
   749   "(x::'a::linordered_field) < 0 ==> y < 0 ==> 0 < x / y"
   750 by(simp add:field_simps)
   751 
   752 lemma divide_nonpos_neg:
   753   "(x::'a::linordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
   754 by(simp add:field_simps)
   755 
   756 
   757 subsection{*Cancellation Laws for Division*}
   758 
   759 lemma divide_cancel_right [simp,no_atp]:
   760      "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
   761 apply (cases "c=0", simp)
   762 apply (simp add: divide_inverse)
   763 done
   764 
   765 lemma divide_cancel_left [simp,no_atp]:
   766      "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
   767 apply (cases "c=0", simp)
   768 apply (simp add: divide_inverse)
   769 done
   770 
   771 
   772 subsection {* Division and the Number One *}
   773 
   774 text{*Simplify expressions equated with 1*}
   775 lemma divide_eq_1_iff [simp,no_atp]:
   776      "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
   777 apply (cases "b=0", simp)
   778 apply (simp add: right_inverse_eq)
   779 done
   780 
   781 lemma one_eq_divide_iff [simp,no_atp]:
   782      "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
   783 by (simp add: eq_commute [of 1])
   784 
   785 lemma zero_eq_1_divide_iff [simp,no_atp]:
   786      "((0::'a::{linordered_field,division_by_zero}) = 1/a) = (a = 0)"
   787 apply (cases "a=0", simp)
   788 apply (auto simp add: nonzero_eq_divide_eq)
   789 done
   790 
   791 lemma one_divide_eq_0_iff [simp,no_atp]:
   792      "(1/a = (0::'a::{linordered_field,division_by_zero})) = (a = 0)"
   793 apply (cases "a=0", simp)
   794 apply (insert zero_neq_one [THEN not_sym])
   795 apply (auto simp add: nonzero_divide_eq_eq)
   796 done
   797 
   798 text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
   799 lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
   800 lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
   801 lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
   802 lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
   803 
   804 declare zero_less_divide_1_iff [simp,no_atp]
   805 declare divide_less_0_1_iff [simp,no_atp]
   806 declare zero_le_divide_1_iff [simp,no_atp]
   807 declare divide_le_0_1_iff [simp,no_atp]
   808 
   809 
   810 subsection {* Ordering Rules for Division *}
   811 
   812 lemma divide_strict_right_mono:
   813      "[|a < b; 0 < c|] ==> a / c < b / (c::'a::linordered_field)"
   814 by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
   815               positive_imp_inverse_positive)
   816 
   817 lemma divide_right_mono:
   818      "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{linordered_field,division_by_zero})"
   819 by (force simp add: divide_strict_right_mono order_le_less)
   820 
   821 lemma divide_right_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
   822     ==> c <= 0 ==> b / c <= a / c"
   823 apply (drule divide_right_mono [of _ _ "- c"])
   824 apply auto
   825 done
   826 
   827 lemma divide_strict_right_mono_neg:
   828      "[|b < a; c < 0|] ==> a / c < b / (c::'a::linordered_field)"
   829 apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
   830 apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
   831 done
   832 
   833 text{*The last premise ensures that @{term a} and @{term b} 
   834       have the same sign*}
   835 lemma divide_strict_left_mono:
   836   "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
   837 by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
   838 
   839 lemma divide_left_mono:
   840   "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::linordered_field)"
   841 by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
   842 
   843 lemma divide_left_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
   844     ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
   845   apply (drule divide_left_mono [of _ _ "- c"])
   846   apply (auto simp add: mult_commute)
   847 done
   848 
   849 lemma divide_strict_left_mono_neg:
   850   "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
   851 by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
   852 
   853 
   854 text{*Simplify quotients that are compared with the value 1.*}
   855 
   856 lemma le_divide_eq_1 [no_atp]:
   857   fixes a :: "'a :: {linordered_field,division_by_zero}"
   858   shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
   859 by (auto simp add: le_divide_eq)
   860 
   861 lemma divide_le_eq_1 [no_atp]:
   862   fixes a :: "'a :: {linordered_field,division_by_zero}"
   863   shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
   864 by (auto simp add: divide_le_eq)
   865 
   866 lemma less_divide_eq_1 [no_atp]:
   867   fixes a :: "'a :: {linordered_field,division_by_zero}"
   868   shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
   869 by (auto simp add: less_divide_eq)
   870 
   871 lemma divide_less_eq_1 [no_atp]:
   872   fixes a :: "'a :: {linordered_field,division_by_zero}"
   873   shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
   874 by (auto simp add: divide_less_eq)
   875 
   876 
   877 subsection{*Conditional Simplification Rules: No Case Splits*}
   878 
   879 lemma le_divide_eq_1_pos [simp,no_atp]:
   880   fixes a :: "'a :: {linordered_field,division_by_zero}"
   881   shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
   882 by (auto simp add: le_divide_eq)
   883 
   884 lemma le_divide_eq_1_neg [simp,no_atp]:
   885   fixes a :: "'a :: {linordered_field,division_by_zero}"
   886   shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
   887 by (auto simp add: le_divide_eq)
   888 
   889 lemma divide_le_eq_1_pos [simp,no_atp]:
   890   fixes a :: "'a :: {linordered_field,division_by_zero}"
   891   shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
   892 by (auto simp add: divide_le_eq)
   893 
   894 lemma divide_le_eq_1_neg [simp,no_atp]:
   895   fixes a :: "'a :: {linordered_field,division_by_zero}"
   896   shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
   897 by (auto simp add: divide_le_eq)
   898 
   899 lemma less_divide_eq_1_pos [simp,no_atp]:
   900   fixes a :: "'a :: {linordered_field,division_by_zero}"
   901   shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
   902 by (auto simp add: less_divide_eq)
   903 
   904 lemma less_divide_eq_1_neg [simp,no_atp]:
   905   fixes a :: "'a :: {linordered_field,division_by_zero}"
   906   shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
   907 by (auto simp add: less_divide_eq)
   908 
   909 lemma divide_less_eq_1_pos [simp,no_atp]:
   910   fixes a :: "'a :: {linordered_field,division_by_zero}"
   911   shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
   912 by (auto simp add: divide_less_eq)
   913 
   914 lemma divide_less_eq_1_neg [simp,no_atp]:
   915   fixes a :: "'a :: {linordered_field,division_by_zero}"
   916   shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
   917 by (auto simp add: divide_less_eq)
   918 
   919 lemma eq_divide_eq_1 [simp,no_atp]:
   920   fixes a :: "'a :: {linordered_field,division_by_zero}"
   921   shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
   922 by (auto simp add: eq_divide_eq)
   923 
   924 lemma divide_eq_eq_1 [simp,no_atp]:
   925   fixes a :: "'a :: {linordered_field,division_by_zero}"
   926   shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
   927 by (auto simp add: divide_eq_eq)
   928 
   929 
   930 subsection {* Reasoning about inequalities with division *}
   931 
   932 lemma mult_imp_div_pos_le: "0 < (y::'a::linordered_field) ==> x <= z * y ==>
   933     x / y <= z"
   934 by (subst pos_divide_le_eq, assumption+)
   935 
   936 lemma mult_imp_le_div_pos: "0 < (y::'a::linordered_field) ==> z * y <= x ==>
   937     z <= x / y"
   938 by(simp add:field_simps)
   939 
   940 lemma mult_imp_div_pos_less: "0 < (y::'a::linordered_field) ==> x < z * y ==>
   941     x / y < z"
   942 by(simp add:field_simps)
   943 
   944 lemma mult_imp_less_div_pos: "0 < (y::'a::linordered_field) ==> z * y < x ==>
   945     z < x / y"
   946 by(simp add:field_simps)
   947 
   948 lemma frac_le: "(0::'a::linordered_field) <= x ==> 
   949     x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
   950   apply (rule mult_imp_div_pos_le)
   951   apply simp
   952   apply (subst times_divide_eq_left)
   953   apply (rule mult_imp_le_div_pos, assumption)
   954   apply (rule mult_mono)
   955   apply simp_all
   956 done
   957 
   958 lemma frac_less: "(0::'a::linordered_field) <= x ==> 
   959     x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
   960   apply (rule mult_imp_div_pos_less)
   961   apply simp
   962   apply (subst times_divide_eq_left)
   963   apply (rule mult_imp_less_div_pos, assumption)
   964   apply (erule mult_less_le_imp_less)
   965   apply simp_all
   966 done
   967 
   968 lemma frac_less2: "(0::'a::linordered_field) < x ==> 
   969     x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
   970   apply (rule mult_imp_div_pos_less)
   971   apply simp_all
   972   apply (subst times_divide_eq_left)
   973   apply (rule mult_imp_less_div_pos, assumption)
   974   apply (erule mult_le_less_imp_less)
   975   apply simp_all
   976 done
   977 
   978 text{*It's not obvious whether these should be simprules or not. 
   979   Their effect is to gather terms into one big fraction, like
   980   a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
   981   seem to need them.*}
   982 
   983 declare times_divide_eq [simp]
   984 
   985 
   986 subsection {* Ordered Fields are Dense *}
   987 
   988 lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::linordered_field)"
   989 by (simp add: field_simps zero_less_two)
   990 
   991 lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::linordered_field) < b"
   992 by (simp add: field_simps zero_less_two)
   993 
   994 instance linordered_field < dense_linorder
   995 proof
   996   fix x y :: 'a
   997   have "x < x + 1" by simp
   998   then show "\<exists>y. x < y" .. 
   999   have "x - 1 < x" by simp
  1000   then show "\<exists>y. y < x" ..
  1001   show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
  1002 qed
  1003 
  1004 
  1005 subsection {* Absolute Value *}
  1006 
  1007 lemma nonzero_abs_inverse:
  1008      "a \<noteq> 0 ==> abs (inverse (a::'a::linordered_field)) = inverse (abs a)"
  1009 apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
  1010                       negative_imp_inverse_negative)
  1011 apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
  1012 done
  1013 
  1014 lemma abs_inverse [simp]:
  1015      "abs (inverse (a::'a::{linordered_field,division_by_zero})) = 
  1016       inverse (abs a)"
  1017 apply (cases "a=0", simp) 
  1018 apply (simp add: nonzero_abs_inverse) 
  1019 done
  1020 
  1021 lemma nonzero_abs_divide:
  1022      "b \<noteq> 0 ==> abs (a / (b::'a::linordered_field)) = abs a / abs b"
  1023 by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
  1024 
  1025 lemma abs_divide [simp]:
  1026      "abs (a / (b::'a::{linordered_field,division_by_zero})) = abs a / abs b"
  1027 apply (cases "b=0", simp) 
  1028 apply (simp add: nonzero_abs_divide) 
  1029 done
  1030 
  1031 lemma abs_div_pos: "(0::'a::{division_by_zero,linordered_field}) < y ==> 
  1032     abs x / y = abs (x / y)"
  1033   apply (subst abs_divide)
  1034   apply (simp add: order_less_imp_le)
  1035 done
  1036 
  1037 lemma field_le_epsilon:
  1038   fixes x y :: "'a\<Colon>linordered_field"
  1039   assumes e: "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
  1040   shows "x \<le> y"
  1041 proof (rule dense_le)
  1042   fix t assume "t < x"
  1043   hence "0 < x - t" by (simp add: less_diff_eq)
  1044   from e[OF this]
  1045   show "t \<le> y" by (simp add: field_simps)
  1046 qed
  1047 
  1048 lemma field_le_mult_one_interval:
  1049   fixes x :: "'a\<Colon>{linordered_field,division_by_zero}"
  1050   assumes *: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
  1051   shows "x \<le> y"
  1052 proof (cases "0 < x")
  1053   assume "0 < x"
  1054   thus ?thesis
  1055     using dense_le_bounded[of 0 1 "y/x"] *
  1056     unfolding le_divide_eq if_P[OF `0 < x`] by simp
  1057 next
  1058   assume "\<not>0 < x" hence "x \<le> 0" by simp
  1059   obtain s::'a where s: "0 < s" "s < 1" using dense[of 0 "1\<Colon>'a"] by auto
  1060   hence "x \<le> s * x" using mult_le_cancel_right[of 1 x s] `x \<le> 0` by auto
  1061   also note *[OF s]
  1062   finally show ?thesis .
  1063 qed
  1064 
  1065 code_modulename SML
  1066   Fields Arith
  1067 
  1068 code_modulename OCaml
  1069   Fields Arith
  1070 
  1071 code_modulename Haskell
  1072   Fields Arith
  1073 
  1074 end