renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
authorhaftmann
Mon Feb 08 17:12:38 2010 +0100 (2010-02-08)
changeset 350509f841f20dca6
parent 35049 00f311c32444
child 35051 648e492abc43
renamed OrderedGroup to Groups; split theory Ring_and_Field into Rings Fields
NEWS
src/HOL/Algebra/poly/UnivPoly2.thy
src/HOL/Decision_Procs/mir_tac.ML
src/HOL/Divides.thy
src/HOL/Fields.thy
src/HOL/Groebner_Basis.thy
src/HOL/Groups.thy
src/HOL/Import/HOL/arithmetic.imp
src/HOL/Import/HOL/divides.imp
src/HOL/Import/HOL/prob_extra.imp
src/HOL/Import/HOL/real.imp
src/HOL/Import/HOL/realax.imp
src/HOL/Int.thy
src/HOL/IsaMakefile
src/HOL/Library/Poly_Deriv.thy
src/HOL/Metis_Examples/BigO.thy
src/HOL/NSA/HyperDef.thy
src/HOL/NSA/NSComplex.thy
src/HOL/NSA/StarDef.thy
src/HOL/OrderedGroup.thy
src/HOL/PReal.thy
src/HOL/Presburger.thy
src/HOL/Probability/Borel.thy
src/HOL/RealDef.thy
src/HOL/Ring_and_Field.thy
src/HOL/Rings.thy
src/HOL/Tools/Qelim/cooper.ML
src/HOL/Tools/lin_arith.ML
src/HOL/Tools/nat_numeral_simprocs.ML
src/HOL/Tools/numeral_simprocs.ML
     1.1 --- a/NEWS	Mon Feb 08 17:12:32 2010 +0100
     1.2 +++ b/NEWS	Mon Feb 08 17:12:38 2010 +0100
     1.3 @@ -15,6 +15,11 @@
     1.4  * New set of rules "ac_simps" provides combined assoc / commute rewrites
     1.5  for all interpretations of the appropriate generic locales.
     1.6  
     1.7 +* Renamed theory "OrderedGroup" to "Groups" and split theory "Ring_and_Field"
     1.8 +into theories "Rings" and "Fields";  for more appropriate and more
     1.9 +consistent names suitable for name prefixes within the HOL theories.
    1.10 +INCOMPATIBILITY.
    1.11 +
    1.12  * More consistent naming of type classes involving orderings (and lattices):
    1.13  
    1.14      lower_semilattice                   ~> semilattice_inf
     2.1 --- a/src/HOL/Algebra/poly/UnivPoly2.thy	Mon Feb 08 17:12:32 2010 +0100
     2.2 +++ b/src/HOL/Algebra/poly/UnivPoly2.thy	Mon Feb 08 17:12:38 2010 +0100
     2.3 @@ -139,7 +139,7 @@
     2.4  
     2.5  end
     2.6  
     2.7 -instance up :: ("{times, comm_monoid_add}") Ring_and_Field.dvd ..
     2.8 +instance up :: ("{times, comm_monoid_add}") Rings.dvd ..
     2.9  
    2.10  instantiation up :: ("{times, one, comm_monoid_add, uminus, minus}") inverse
    2.11  begin
     3.1 --- a/src/HOL/Decision_Procs/mir_tac.ML	Mon Feb 08 17:12:32 2010 +0100
     3.2 +++ b/src/HOL/Decision_Procs/mir_tac.ML	Mon Feb 08 17:12:38 2010 +0100
     3.3 @@ -33,7 +33,7 @@
     3.4               @{thm "real_of_nat_number_of"},
     3.5               @{thm "real_of_nat_Suc"}, @{thm "real_of_nat_one"}, @{thm "real_of_one"},
     3.6               @{thm "real_of_int_zero"}, @{thm "real_of_nat_zero"},
     3.7 -             @{thm "Ring_and_Field.divide_zero"}, 
     3.8 +             @{thm "Fields.divide_zero"}, 
     3.9               @{thm "divide_divide_eq_left"}, @{thm "times_divide_eq_right"}, 
    3.10               @{thm "times_divide_eq_left"}, @{thm "divide_divide_eq_right"},
    3.11               @{thm "diff_def"}, @{thm "minus_divide_left"}]
     4.1 --- a/src/HOL/Divides.thy	Mon Feb 08 17:12:32 2010 +0100
     4.2 +++ b/src/HOL/Divides.thy	Mon Feb 08 17:12:38 2010 +0100
     4.3 @@ -657,7 +657,7 @@
     4.4    val trans = trans;
     4.5  
     4.6    val prove_eq_sums = Arith_Data.prove_conv2 all_tac (Arith_Data.simp_all_tac
     4.7 -    (@{thm monoid_add_class.add_0_left} :: @{thm monoid_add_class.add_0_right} :: @{thms add_ac}))
     4.8 +    (@{thm add_0_left} :: @{thm add_0_right} :: @{thms add_ac}))
     4.9  
    4.10  end)
    4.11  
    4.12 @@ -1655,8 +1655,8 @@
    4.13  lemmas arithmetic_simps =
    4.14    arith_simps
    4.15    add_special
    4.16 -  OrderedGroup.add_0_left
    4.17 -  OrderedGroup.add_0_right
    4.18 +  add_0_left
    4.19 +  add_0_right
    4.20    mult_zero_left
    4.21    mult_zero_right
    4.22    mult_1_left
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/HOL/Fields.thy	Mon Feb 08 17:12:38 2010 +0100
     5.3 @@ -0,0 +1,1044 @@
     5.4 +(*  Title:      HOL/Fields.thy
     5.5 +    Author:     Gertrud Bauer
     5.6 +    Author:     Steven Obua
     5.7 +    Author:     Tobias Nipkow
     5.8 +    Author:     Lawrence C Paulson
     5.9 +    Author:     Markus Wenzel
    5.10 +    Author:     Jeremy Avigad
    5.11 +*)
    5.12 +
    5.13 +header {* Fields *}
    5.14 +
    5.15 +theory Fields
    5.16 +imports Rings
    5.17 +begin
    5.18 +
    5.19 +class field = comm_ring_1 + inverse +
    5.20 +  assumes field_inverse:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
    5.21 +  assumes divide_inverse: "a / b = a * inverse b"
    5.22 +begin
    5.23 +
    5.24 +subclass division_ring
    5.25 +proof
    5.26 +  fix a :: 'a
    5.27 +  assume "a \<noteq> 0"
    5.28 +  thus "inverse a * a = 1" by (rule field_inverse)
    5.29 +  thus "a * inverse a = 1" by (simp only: mult_commute)
    5.30 +qed
    5.31 +
    5.32 +subclass idom ..
    5.33 +
    5.34 +lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
    5.35 +proof
    5.36 +  assume neq: "b \<noteq> 0"
    5.37 +  {
    5.38 +    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
    5.39 +    also assume "a / b = 1"
    5.40 +    finally show "a = b" by simp
    5.41 +  next
    5.42 +    assume "a = b"
    5.43 +    with neq show "a / b = 1" by (simp add: divide_inverse)
    5.44 +  }
    5.45 +qed
    5.46 +
    5.47 +lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
    5.48 +by (simp add: divide_inverse)
    5.49 +
    5.50 +lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
    5.51 +by (simp add: divide_inverse)
    5.52 +
    5.53 +lemma divide_zero_left [simp]: "0 / a = 0"
    5.54 +by (simp add: divide_inverse)
    5.55 +
    5.56 +lemma inverse_eq_divide: "inverse a = 1 / a"
    5.57 +by (simp add: divide_inverse)
    5.58 +
    5.59 +lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
    5.60 +by (simp add: divide_inverse algebra_simps)
    5.61 +
    5.62 +text{*There is no slick version using division by zero.*}
    5.63 +lemma inverse_add:
    5.64 +  "[| a \<noteq> 0;  b \<noteq> 0 |]
    5.65 +   ==> inverse a + inverse b = (a + b) * inverse a * inverse b"
    5.66 +by (simp add: division_ring_inverse_add mult_ac)
    5.67 +
    5.68 +lemma nonzero_mult_divide_mult_cancel_left [simp, noatp]:
    5.69 +assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/b"
    5.70 +proof -
    5.71 +  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
    5.72 +    by (simp add: divide_inverse nonzero_inverse_mult_distrib)
    5.73 +  also have "... =  a * inverse b * (inverse c * c)"
    5.74 +    by (simp only: mult_ac)
    5.75 +  also have "... =  a * inverse b" by simp
    5.76 +    finally show ?thesis by (simp add: divide_inverse)
    5.77 +qed
    5.78 +
    5.79 +lemma nonzero_mult_divide_mult_cancel_right [simp, noatp]:
    5.80 +  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (b * c) = a / b"
    5.81 +by (simp add: mult_commute [of _ c])
    5.82 +
    5.83 +lemma divide_1 [simp]: "a / 1 = a"
    5.84 +by (simp add: divide_inverse)
    5.85 +
    5.86 +lemma times_divide_eq_right: "a * (b / c) = (a * b) / c"
    5.87 +by (simp add: divide_inverse mult_assoc)
    5.88 +
    5.89 +lemma times_divide_eq_left: "(b / c) * a = (b * a) / c"
    5.90 +by (simp add: divide_inverse mult_ac)
    5.91 +
    5.92 +text {* These are later declared as simp rules. *}
    5.93 +lemmas times_divide_eq [noatp] = times_divide_eq_right times_divide_eq_left
    5.94 +
    5.95 +lemma add_frac_eq:
    5.96 +  assumes "y \<noteq> 0" and "z \<noteq> 0"
    5.97 +  shows "x / y + w / z = (x * z + w * y) / (y * z)"
    5.98 +proof -
    5.99 +  have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
   5.100 +    using assms by simp
   5.101 +  also have "\<dots> = (x * z + y * w) / (y * z)"
   5.102 +    by (simp only: add_divide_distrib)
   5.103 +  finally show ?thesis
   5.104 +    by (simp only: mult_commute)
   5.105 +qed
   5.106 +
   5.107 +text{*Special Cancellation Simprules for Division*}
   5.108 +
   5.109 +lemma nonzero_mult_divide_cancel_right [simp, noatp]:
   5.110 +  "b \<noteq> 0 \<Longrightarrow> a * b / b = a"
   5.111 +using nonzero_mult_divide_mult_cancel_right [of 1 b a] by simp
   5.112 +
   5.113 +lemma nonzero_mult_divide_cancel_left [simp, noatp]:
   5.114 +  "a \<noteq> 0 \<Longrightarrow> a * b / a = b"
   5.115 +using nonzero_mult_divide_mult_cancel_left [of 1 a b] by simp
   5.116 +
   5.117 +lemma nonzero_divide_mult_cancel_right [simp, noatp]:
   5.118 +  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> b / (a * b) = 1 / a"
   5.119 +using nonzero_mult_divide_mult_cancel_right [of a b 1] by simp
   5.120 +
   5.121 +lemma nonzero_divide_mult_cancel_left [simp, noatp]:
   5.122 +  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / (a * b) = 1 / b"
   5.123 +using nonzero_mult_divide_mult_cancel_left [of b a 1] by simp
   5.124 +
   5.125 +lemma nonzero_mult_divide_mult_cancel_left2 [simp, noatp]:
   5.126 +  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (c * a) / (b * c) = a / b"
   5.127 +using nonzero_mult_divide_mult_cancel_left [of b c a] by (simp add: mult_ac)
   5.128 +
   5.129 +lemma nonzero_mult_divide_mult_cancel_right2 [simp, noatp]:
   5.130 +  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (c * b) = a / b"
   5.131 +using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: mult_ac)
   5.132 +
   5.133 +lemma minus_divide_left: "- (a / b) = (-a) / b"
   5.134 +by (simp add: divide_inverse)
   5.135 +
   5.136 +lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
   5.137 +by (simp add: divide_inverse nonzero_inverse_minus_eq)
   5.138 +
   5.139 +lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
   5.140 +by (simp add: divide_inverse nonzero_inverse_minus_eq)
   5.141 +
   5.142 +lemma divide_minus_left [simp, noatp]: "(-a) / b = - (a / b)"
   5.143 +by (simp add: divide_inverse)
   5.144 +
   5.145 +lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
   5.146 +by (simp add: diff_minus add_divide_distrib)
   5.147 +
   5.148 +lemma add_divide_eq_iff:
   5.149 +  "z \<noteq> 0 \<Longrightarrow> x + y / z = (z * x + y) / z"
   5.150 +by (simp add: add_divide_distrib)
   5.151 +
   5.152 +lemma divide_add_eq_iff:
   5.153 +  "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + z * y) / z"
   5.154 +by (simp add: add_divide_distrib)
   5.155 +
   5.156 +lemma diff_divide_eq_iff:
   5.157 +  "z \<noteq> 0 \<Longrightarrow> x - y / z = (z * x - y) / z"
   5.158 +by (simp add: diff_divide_distrib)
   5.159 +
   5.160 +lemma divide_diff_eq_iff:
   5.161 +  "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - z * y) / z"
   5.162 +by (simp add: diff_divide_distrib)
   5.163 +
   5.164 +lemma nonzero_eq_divide_eq: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
   5.165 +proof -
   5.166 +  assume [simp]: "c \<noteq> 0"
   5.167 +  have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
   5.168 +  also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult_assoc)
   5.169 +  finally show ?thesis .
   5.170 +qed
   5.171 +
   5.172 +lemma nonzero_divide_eq_eq: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
   5.173 +proof -
   5.174 +  assume [simp]: "c \<noteq> 0"
   5.175 +  have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
   5.176 +  also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult_assoc) 
   5.177 +  finally show ?thesis .
   5.178 +qed
   5.179 +
   5.180 +lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
   5.181 +by simp
   5.182 +
   5.183 +lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
   5.184 +by (erule subst, simp)
   5.185 +
   5.186 +lemmas field_eq_simps[noatp] = algebra_simps
   5.187 +  (* pull / out*)
   5.188 +  add_divide_eq_iff divide_add_eq_iff
   5.189 +  diff_divide_eq_iff divide_diff_eq_iff
   5.190 +  (* multiply eqn *)
   5.191 +  nonzero_eq_divide_eq nonzero_divide_eq_eq
   5.192 +(* is added later:
   5.193 +  times_divide_eq_left times_divide_eq_right
   5.194 +*)
   5.195 +
   5.196 +text{*An example:*}
   5.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"
   5.198 +apply(subgoal_tac "(c-d)*(e-f)*(a-b) \<noteq> 0")
   5.199 + apply(simp add:field_eq_simps)
   5.200 +apply(simp)
   5.201 +done
   5.202 +
   5.203 +lemma diff_frac_eq:
   5.204 +  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
   5.205 +by (simp add: field_eq_simps times_divide_eq)
   5.206 +
   5.207 +lemma frac_eq_eq:
   5.208 +  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
   5.209 +by (simp add: field_eq_simps times_divide_eq)
   5.210 +
   5.211 +end
   5.212 +
   5.213 +class division_by_zero = zero + inverse +
   5.214 +  assumes inverse_zero [simp]: "inverse 0 = 0"
   5.215 +
   5.216 +lemma divide_zero [simp]:
   5.217 +  "a / 0 = (0::'a::{field,division_by_zero})"
   5.218 +by (simp add: divide_inverse)
   5.219 +
   5.220 +lemma divide_self_if [simp]:
   5.221 +  "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
   5.222 +by simp
   5.223 +
   5.224 +class linordered_field = field + linordered_idom
   5.225 +
   5.226 +lemma inverse_nonzero_iff_nonzero [simp]:
   5.227 +   "(inverse a = 0) = (a = (0::'a::{division_ring,division_by_zero}))"
   5.228 +by (force dest: inverse_zero_imp_zero) 
   5.229 +
   5.230 +lemma inverse_minus_eq [simp]:
   5.231 +   "inverse(-a) = -inverse(a::'a::{division_ring,division_by_zero})"
   5.232 +proof cases
   5.233 +  assume "a=0" thus ?thesis by (simp add: inverse_zero)
   5.234 +next
   5.235 +  assume "a\<noteq>0" 
   5.236 +  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
   5.237 +qed
   5.238 +
   5.239 +lemma inverse_eq_imp_eq:
   5.240 +  "inverse a = inverse b ==> a = (b::'a::{division_ring,division_by_zero})"
   5.241 +apply (cases "a=0 | b=0") 
   5.242 + apply (force dest!: inverse_zero_imp_zero
   5.243 +              simp add: eq_commute [of "0::'a"])
   5.244 +apply (force dest!: nonzero_inverse_eq_imp_eq) 
   5.245 +done
   5.246 +
   5.247 +lemma inverse_eq_iff_eq [simp]:
   5.248 +  "(inverse a = inverse b) = (a = (b::'a::{division_ring,division_by_zero}))"
   5.249 +by (force dest!: inverse_eq_imp_eq)
   5.250 +
   5.251 +lemma inverse_inverse_eq [simp]:
   5.252 +     "inverse(inverse (a::'a::{division_ring,division_by_zero})) = a"
   5.253 +  proof cases
   5.254 +    assume "a=0" thus ?thesis by simp
   5.255 +  next
   5.256 +    assume "a\<noteq>0" 
   5.257 +    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
   5.258 +  qed
   5.259 +
   5.260 +text{*This version builds in division by zero while also re-orienting
   5.261 +      the right-hand side.*}
   5.262 +lemma inverse_mult_distrib [simp]:
   5.263 +     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
   5.264 +  proof cases
   5.265 +    assume "a \<noteq> 0 & b \<noteq> 0" 
   5.266 +    thus ?thesis by (simp add: nonzero_inverse_mult_distrib mult_commute)
   5.267 +  next
   5.268 +    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
   5.269 +    thus ?thesis by force
   5.270 +  qed
   5.271 +
   5.272 +lemma inverse_divide [simp]:
   5.273 +  "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
   5.274 +by (simp add: divide_inverse mult_commute)
   5.275 +
   5.276 +
   5.277 +subsection {* Calculations with fractions *}
   5.278 +
   5.279 +text{* There is a whole bunch of simp-rules just for class @{text
   5.280 +field} but none for class @{text field} and @{text nonzero_divides}
   5.281 +because the latter are covered by a simproc. *}
   5.282 +
   5.283 +lemma mult_divide_mult_cancel_left:
   5.284 +  "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
   5.285 +apply (cases "b = 0")
   5.286 +apply (simp_all add: nonzero_mult_divide_mult_cancel_left)
   5.287 +done
   5.288 +
   5.289 +lemma mult_divide_mult_cancel_right:
   5.290 +  "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
   5.291 +apply (cases "b = 0")
   5.292 +apply (simp_all add: nonzero_mult_divide_mult_cancel_right)
   5.293 +done
   5.294 +
   5.295 +lemma divide_divide_eq_right [simp,noatp]:
   5.296 +  "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
   5.297 +by (simp add: divide_inverse mult_ac)
   5.298 +
   5.299 +lemma divide_divide_eq_left [simp,noatp]:
   5.300 +  "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
   5.301 +by (simp add: divide_inverse mult_assoc)
   5.302 +
   5.303 +
   5.304 +subsubsection{*Special Cancellation Simprules for Division*}
   5.305 +
   5.306 +lemma mult_divide_mult_cancel_left_if[simp,noatp]:
   5.307 +fixes c :: "'a :: {field,division_by_zero}"
   5.308 +shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
   5.309 +by (simp add: mult_divide_mult_cancel_left)
   5.310 +
   5.311 +
   5.312 +subsection {* Division and Unary Minus *}
   5.313 +
   5.314 +lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
   5.315 +by (simp add: divide_inverse)
   5.316 +
   5.317 +lemma divide_minus_right [simp, noatp]:
   5.318 +  "a / -(b::'a::{field,division_by_zero}) = -(a / b)"
   5.319 +by (simp add: divide_inverse)
   5.320 +
   5.321 +lemma minus_divide_divide:
   5.322 +  "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
   5.323 +apply (cases "b=0", simp) 
   5.324 +apply (simp add: nonzero_minus_divide_divide) 
   5.325 +done
   5.326 +
   5.327 +lemma eq_divide_eq:
   5.328 +  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
   5.329 +by (simp add: nonzero_eq_divide_eq)
   5.330 +
   5.331 +lemma divide_eq_eq:
   5.332 +  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
   5.333 +by (force simp add: nonzero_divide_eq_eq)
   5.334 +
   5.335 +
   5.336 +subsection {* Ordered Fields *}
   5.337 +
   5.338 +lemma positive_imp_inverse_positive: 
   5.339 +assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::linordered_field)"
   5.340 +proof -
   5.341 +  have "0 < a * inverse a" 
   5.342 +    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
   5.343 +  thus "0 < inverse a" 
   5.344 +    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
   5.345 +qed
   5.346 +
   5.347 +lemma negative_imp_inverse_negative:
   5.348 +  "a < 0 ==> inverse a < (0::'a::linordered_field)"
   5.349 +by (insert positive_imp_inverse_positive [of "-a"], 
   5.350 +    simp add: nonzero_inverse_minus_eq order_less_imp_not_eq)
   5.351 +
   5.352 +lemma inverse_le_imp_le:
   5.353 +assumes invle: "inverse a \<le> inverse b" and apos:  "0 < a"
   5.354 +shows "b \<le> (a::'a::linordered_field)"
   5.355 +proof (rule classical)
   5.356 +  assume "~ b \<le> a"
   5.357 +  hence "a < b"  by (simp add: linorder_not_le)
   5.358 +  hence bpos: "0 < b"  by (blast intro: apos order_less_trans)
   5.359 +  hence "a * inverse a \<le> a * inverse b"
   5.360 +    by (simp add: apos invle order_less_imp_le mult_left_mono)
   5.361 +  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
   5.362 +    by (simp add: bpos order_less_imp_le mult_right_mono)
   5.363 +  thus "b \<le> a"  by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
   5.364 +qed
   5.365 +
   5.366 +lemma inverse_positive_imp_positive:
   5.367 +assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
   5.368 +shows "0 < (a::'a::linordered_field)"
   5.369 +proof -
   5.370 +  have "0 < inverse (inverse a)"
   5.371 +    using inv_gt_0 by (rule positive_imp_inverse_positive)
   5.372 +  thus "0 < a"
   5.373 +    using nz by (simp add: nonzero_inverse_inverse_eq)
   5.374 +qed
   5.375 +
   5.376 +lemma inverse_positive_iff_positive [simp]:
   5.377 +  "(0 < inverse a) = (0 < (a::'a::{linordered_field,division_by_zero}))"
   5.378 +apply (cases "a = 0", simp)
   5.379 +apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
   5.380 +done
   5.381 +
   5.382 +lemma inverse_negative_imp_negative:
   5.383 +assumes inv_less_0: "inverse a < 0" and nz:  "a \<noteq> 0"
   5.384 +shows "a < (0::'a::linordered_field)"
   5.385 +proof -
   5.386 +  have "inverse (inverse a) < 0"
   5.387 +    using inv_less_0 by (rule negative_imp_inverse_negative)
   5.388 +  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
   5.389 +qed
   5.390 +
   5.391 +lemma inverse_negative_iff_negative [simp]:
   5.392 +  "(inverse a < 0) = (a < (0::'a::{linordered_field,division_by_zero}))"
   5.393 +apply (cases "a = 0", simp)
   5.394 +apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
   5.395 +done
   5.396 +
   5.397 +lemma inverse_nonnegative_iff_nonnegative [simp]:
   5.398 +  "(0 \<le> inverse a) = (0 \<le> (a::'a::{linordered_field,division_by_zero}))"
   5.399 +by (simp add: linorder_not_less [symmetric])
   5.400 +
   5.401 +lemma inverse_nonpositive_iff_nonpositive [simp]:
   5.402 +  "(inverse a \<le> 0) = (a \<le> (0::'a::{linordered_field,division_by_zero}))"
   5.403 +by (simp add: linorder_not_less [symmetric])
   5.404 +
   5.405 +lemma linordered_field_no_lb: "\<forall> x. \<exists>y. y < (x::'a::linordered_field)"
   5.406 +proof
   5.407 +  fix x::'a
   5.408 +  have m1: "- (1::'a) < 0" by simp
   5.409 +  from add_strict_right_mono[OF m1, where c=x] 
   5.410 +  have "(- 1) + x < x" by simp
   5.411 +  thus "\<exists>y. y < x" by blast
   5.412 +qed
   5.413 +
   5.414 +lemma linordered_field_no_ub: "\<forall> x. \<exists>y. y > (x::'a::linordered_field)"
   5.415 +proof
   5.416 +  fix x::'a
   5.417 +  have m1: " (1::'a) > 0" by simp
   5.418 +  from add_strict_right_mono[OF m1, where c=x] 
   5.419 +  have "1 + x > x" by simp
   5.420 +  thus "\<exists>y. y > x" by blast
   5.421 +qed
   5.422 +
   5.423 +subsection{*Anti-Monotonicity of @{term inverse}*}
   5.424 +
   5.425 +lemma less_imp_inverse_less:
   5.426 +assumes less: "a < b" and apos:  "0 < a"
   5.427 +shows "inverse b < inverse (a::'a::linordered_field)"
   5.428 +proof (rule ccontr)
   5.429 +  assume "~ inverse b < inverse a"
   5.430 +  hence "inverse a \<le> inverse b" by (simp add: linorder_not_less)
   5.431 +  hence "~ (a < b)"
   5.432 +    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
   5.433 +  thus False by (rule notE [OF _ less])
   5.434 +qed
   5.435 +
   5.436 +lemma inverse_less_imp_less:
   5.437 +  "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::linordered_field)"
   5.438 +apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
   5.439 +apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
   5.440 +done
   5.441 +
   5.442 +text{*Both premises are essential. Consider -1 and 1.*}
   5.443 +lemma inverse_less_iff_less [simp,noatp]:
   5.444 +  "[|0 < a; 0 < b|] ==> (inverse a < inverse b) = (b < (a::'a::linordered_field))"
   5.445 +by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
   5.446 +
   5.447 +lemma le_imp_inverse_le:
   5.448 +  "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::linordered_field)"
   5.449 +by (force simp add: order_le_less less_imp_inverse_less)
   5.450 +
   5.451 +lemma inverse_le_iff_le [simp,noatp]:
   5.452 + "[|0 < a; 0 < b|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::linordered_field))"
   5.453 +by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
   5.454 +
   5.455 +
   5.456 +text{*These results refer to both operands being negative.  The opposite-sign
   5.457 +case is trivial, since inverse preserves signs.*}
   5.458 +lemma inverse_le_imp_le_neg:
   5.459 +  "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::linordered_field)"
   5.460 +apply (rule classical) 
   5.461 +apply (subgoal_tac "a < 0") 
   5.462 + prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
   5.463 +apply (insert inverse_le_imp_le [of "-b" "-a"])
   5.464 +apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
   5.465 +done
   5.466 +
   5.467 +lemma less_imp_inverse_less_neg:
   5.468 +   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::linordered_field)"
   5.469 +apply (subgoal_tac "a < 0") 
   5.470 + prefer 2 apply (blast intro: order_less_trans) 
   5.471 +apply (insert less_imp_inverse_less [of "-b" "-a"])
   5.472 +apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
   5.473 +done
   5.474 +
   5.475 +lemma inverse_less_imp_less_neg:
   5.476 +   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::linordered_field)"
   5.477 +apply (rule classical) 
   5.478 +apply (subgoal_tac "a < 0") 
   5.479 + prefer 2
   5.480 + apply (force simp add: linorder_not_less intro: order_le_less_trans) 
   5.481 +apply (insert inverse_less_imp_less [of "-b" "-a"])
   5.482 +apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
   5.483 +done
   5.484 +
   5.485 +lemma inverse_less_iff_less_neg [simp,noatp]:
   5.486 +  "[|a < 0; b < 0|] ==> (inverse a < inverse b) = (b < (a::'a::linordered_field))"
   5.487 +apply (insert inverse_less_iff_less [of "-b" "-a"])
   5.488 +apply (simp del: inverse_less_iff_less 
   5.489 +            add: order_less_imp_not_eq nonzero_inverse_minus_eq)
   5.490 +done
   5.491 +
   5.492 +lemma le_imp_inverse_le_neg:
   5.493 +  "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::linordered_field)"
   5.494 +by (force simp add: order_le_less less_imp_inverse_less_neg)
   5.495 +
   5.496 +lemma inverse_le_iff_le_neg [simp,noatp]:
   5.497 + "[|a < 0; b < 0|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::linordered_field))"
   5.498 +by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
   5.499 +
   5.500 +
   5.501 +subsection{*Inverses and the Number One*}
   5.502 +
   5.503 +lemma one_less_inverse_iff:
   5.504 +  "(1 < inverse x) = (0 < x & x < (1::'a::{linordered_field,division_by_zero}))"
   5.505 +proof cases
   5.506 +  assume "0 < x"
   5.507 +    with inverse_less_iff_less [OF zero_less_one, of x]
   5.508 +    show ?thesis by simp
   5.509 +next
   5.510 +  assume notless: "~ (0 < x)"
   5.511 +  have "~ (1 < inverse x)"
   5.512 +  proof
   5.513 +    assume "1 < inverse x"
   5.514 +    also with notless have "... \<le> 0" by (simp add: linorder_not_less)
   5.515 +    also have "... < 1" by (rule zero_less_one) 
   5.516 +    finally show False by auto
   5.517 +  qed
   5.518 +  with notless show ?thesis by simp
   5.519 +qed
   5.520 +
   5.521 +lemma inverse_eq_1_iff [simp]:
   5.522 +  "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
   5.523 +by (insert inverse_eq_iff_eq [of x 1], simp) 
   5.524 +
   5.525 +lemma one_le_inverse_iff:
   5.526 +  "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{linordered_field,division_by_zero}))"
   5.527 +by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
   5.528 +                    eq_commute [of 1]) 
   5.529 +
   5.530 +lemma inverse_less_1_iff:
   5.531 +  "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{linordered_field,division_by_zero}))"
   5.532 +by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
   5.533 +
   5.534 +lemma inverse_le_1_iff:
   5.535 +  "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{linordered_field,division_by_zero}))"
   5.536 +by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
   5.537 +
   5.538 +
   5.539 +subsection{*Simplification of Inequalities Involving Literal Divisors*}
   5.540 +
   5.541 +lemma pos_le_divide_eq: "0 < (c::'a::linordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
   5.542 +proof -
   5.543 +  assume less: "0<c"
   5.544 +  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
   5.545 +    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   5.546 +  also have "... = (a*c \<le> b)"
   5.547 +    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   5.548 +  finally show ?thesis .
   5.549 +qed
   5.550 +
   5.551 +lemma neg_le_divide_eq: "c < (0::'a::linordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
   5.552 +proof -
   5.553 +  assume less: "c<0"
   5.554 +  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
   5.555 +    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   5.556 +  also have "... = (b \<le> a*c)"
   5.557 +    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   5.558 +  finally show ?thesis .
   5.559 +qed
   5.560 +
   5.561 +lemma le_divide_eq:
   5.562 +  "(a \<le> b/c) = 
   5.563 +   (if 0 < c then a*c \<le> b
   5.564 +             else if c < 0 then b \<le> a*c
   5.565 +             else  a \<le> (0::'a::{linordered_field,division_by_zero}))"
   5.566 +apply (cases "c=0", simp) 
   5.567 +apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
   5.568 +done
   5.569 +
   5.570 +lemma pos_divide_le_eq: "0 < (c::'a::linordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
   5.571 +proof -
   5.572 +  assume less: "0<c"
   5.573 +  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
   5.574 +    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   5.575 +  also have "... = (b \<le> a*c)"
   5.576 +    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   5.577 +  finally show ?thesis .
   5.578 +qed
   5.579 +
   5.580 +lemma neg_divide_le_eq: "c < (0::'a::linordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
   5.581 +proof -
   5.582 +  assume less: "c<0"
   5.583 +  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
   5.584 +    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
   5.585 +  also have "... = (a*c \<le> b)"
   5.586 +    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   5.587 +  finally show ?thesis .
   5.588 +qed
   5.589 +
   5.590 +lemma divide_le_eq:
   5.591 +  "(b/c \<le> a) = 
   5.592 +   (if 0 < c then b \<le> a*c
   5.593 +             else if c < 0 then a*c \<le> b
   5.594 +             else 0 \<le> (a::'a::{linordered_field,division_by_zero}))"
   5.595 +apply (cases "c=0", simp) 
   5.596 +apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
   5.597 +done
   5.598 +
   5.599 +lemma pos_less_divide_eq:
   5.600 +     "0 < (c::'a::linordered_field) ==> (a < b/c) = (a*c < b)"
   5.601 +proof -
   5.602 +  assume less: "0<c"
   5.603 +  hence "(a < b/c) = (a*c < (b/c)*c)"
   5.604 +    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   5.605 +  also have "... = (a*c < b)"
   5.606 +    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   5.607 +  finally show ?thesis .
   5.608 +qed
   5.609 +
   5.610 +lemma neg_less_divide_eq:
   5.611 + "c < (0::'a::linordered_field) ==> (a < b/c) = (b < a*c)"
   5.612 +proof -
   5.613 +  assume less: "c<0"
   5.614 +  hence "(a < b/c) = ((b/c)*c < a*c)"
   5.615 +    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   5.616 +  also have "... = (b < a*c)"
   5.617 +    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   5.618 +  finally show ?thesis .
   5.619 +qed
   5.620 +
   5.621 +lemma less_divide_eq:
   5.622 +  "(a < b/c) = 
   5.623 +   (if 0 < c then a*c < b
   5.624 +             else if c < 0 then b < a*c
   5.625 +             else  a < (0::'a::{linordered_field,division_by_zero}))"
   5.626 +apply (cases "c=0", simp) 
   5.627 +apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
   5.628 +done
   5.629 +
   5.630 +lemma pos_divide_less_eq:
   5.631 +     "0 < (c::'a::linordered_field) ==> (b/c < a) = (b < a*c)"
   5.632 +proof -
   5.633 +  assume less: "0<c"
   5.634 +  hence "(b/c < a) = ((b/c)*c < a*c)"
   5.635 +    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   5.636 +  also have "... = (b < a*c)"
   5.637 +    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
   5.638 +  finally show ?thesis .
   5.639 +qed
   5.640 +
   5.641 +lemma neg_divide_less_eq:
   5.642 + "c < (0::'a::linordered_field) ==> (b/c < a) = (a*c < b)"
   5.643 +proof -
   5.644 +  assume less: "c<0"
   5.645 +  hence "(b/c < a) = (a*c < (b/c)*c)"
   5.646 +    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
   5.647 +  also have "... = (a*c < b)"
   5.648 +    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
   5.649 +  finally show ?thesis .
   5.650 +qed
   5.651 +
   5.652 +lemma divide_less_eq:
   5.653 +  "(b/c < a) = 
   5.654 +   (if 0 < c then b < a*c
   5.655 +             else if c < 0 then a*c < b
   5.656 +             else 0 < (a::'a::{linordered_field,division_by_zero}))"
   5.657 +apply (cases "c=0", simp) 
   5.658 +apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
   5.659 +done
   5.660 +
   5.661 +
   5.662 +subsection{*Field simplification*}
   5.663 +
   5.664 +text{* Lemmas @{text field_simps} multiply with denominators in in(equations)
   5.665 +if they can be proved to be non-zero (for equations) or positive/negative
   5.666 +(for inequations). Can be too aggressive and is therefore separate from the
   5.667 +more benign @{text algebra_simps}. *}
   5.668 +
   5.669 +lemmas field_simps[noatp] = field_eq_simps
   5.670 +  (* multiply ineqn *)
   5.671 +  pos_divide_less_eq neg_divide_less_eq
   5.672 +  pos_less_divide_eq neg_less_divide_eq
   5.673 +  pos_divide_le_eq neg_divide_le_eq
   5.674 +  pos_le_divide_eq neg_le_divide_eq
   5.675 +
   5.676 +text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
   5.677 +of positivity/negativity needed for @{text field_simps}. Have not added @{text
   5.678 +sign_simps} to @{text field_simps} because the former can lead to case
   5.679 +explosions. *}
   5.680 +
   5.681 +lemmas sign_simps[noatp] = group_simps
   5.682 +  zero_less_mult_iff  mult_less_0_iff
   5.683 +
   5.684 +(* Only works once linear arithmetic is installed:
   5.685 +text{*An example:*}
   5.686 +lemma fixes a b c d e f :: "'a::linordered_field"
   5.687 +shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
   5.688 + ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
   5.689 + ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
   5.690 +apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
   5.691 + prefer 2 apply(simp add:sign_simps)
   5.692 +apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
   5.693 + prefer 2 apply(simp add:sign_simps)
   5.694 +apply(simp add:field_simps)
   5.695 +done
   5.696 +*)
   5.697 +
   5.698 +
   5.699 +subsection{*Division and Signs*}
   5.700 +
   5.701 +lemma zero_less_divide_iff:
   5.702 +     "((0::'a::{linordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
   5.703 +by (simp add: divide_inverse zero_less_mult_iff)
   5.704 +
   5.705 +lemma divide_less_0_iff:
   5.706 +     "(a/b < (0::'a::{linordered_field,division_by_zero})) = 
   5.707 +      (0 < a & b < 0 | a < 0 & 0 < b)"
   5.708 +by (simp add: divide_inverse mult_less_0_iff)
   5.709 +
   5.710 +lemma zero_le_divide_iff:
   5.711 +     "((0::'a::{linordered_field,division_by_zero}) \<le> a/b) =
   5.712 +      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
   5.713 +by (simp add: divide_inverse zero_le_mult_iff)
   5.714 +
   5.715 +lemma divide_le_0_iff:
   5.716 +     "(a/b \<le> (0::'a::{linordered_field,division_by_zero})) =
   5.717 +      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
   5.718 +by (simp add: divide_inverse mult_le_0_iff)
   5.719 +
   5.720 +lemma divide_eq_0_iff [simp,noatp]:
   5.721 +     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
   5.722 +by (simp add: divide_inverse)
   5.723 +
   5.724 +lemma divide_pos_pos:
   5.725 +  "0 < (x::'a::linordered_field) ==> 0 < y ==> 0 < x / y"
   5.726 +by(simp add:field_simps)
   5.727 +
   5.728 +
   5.729 +lemma divide_nonneg_pos:
   5.730 +  "0 <= (x::'a::linordered_field) ==> 0 < y ==> 0 <= x / y"
   5.731 +by(simp add:field_simps)
   5.732 +
   5.733 +lemma divide_neg_pos:
   5.734 +  "(x::'a::linordered_field) < 0 ==> 0 < y ==> x / y < 0"
   5.735 +by(simp add:field_simps)
   5.736 +
   5.737 +lemma divide_nonpos_pos:
   5.738 +  "(x::'a::linordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
   5.739 +by(simp add:field_simps)
   5.740 +
   5.741 +lemma divide_pos_neg:
   5.742 +  "0 < (x::'a::linordered_field) ==> y < 0 ==> x / y < 0"
   5.743 +by(simp add:field_simps)
   5.744 +
   5.745 +lemma divide_nonneg_neg:
   5.746 +  "0 <= (x::'a::linordered_field) ==> y < 0 ==> x / y <= 0" 
   5.747 +by(simp add:field_simps)
   5.748 +
   5.749 +lemma divide_neg_neg:
   5.750 +  "(x::'a::linordered_field) < 0 ==> y < 0 ==> 0 < x / y"
   5.751 +by(simp add:field_simps)
   5.752 +
   5.753 +lemma divide_nonpos_neg:
   5.754 +  "(x::'a::linordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
   5.755 +by(simp add:field_simps)
   5.756 +
   5.757 +
   5.758 +subsection{*Cancellation Laws for Division*}
   5.759 +
   5.760 +lemma divide_cancel_right [simp,noatp]:
   5.761 +     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
   5.762 +apply (cases "c=0", simp)
   5.763 +apply (simp add: divide_inverse)
   5.764 +done
   5.765 +
   5.766 +lemma divide_cancel_left [simp,noatp]:
   5.767 +     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
   5.768 +apply (cases "c=0", simp)
   5.769 +apply (simp add: divide_inverse)
   5.770 +done
   5.771 +
   5.772 +
   5.773 +subsection {* Division and the Number One *}
   5.774 +
   5.775 +text{*Simplify expressions equated with 1*}
   5.776 +lemma divide_eq_1_iff [simp,noatp]:
   5.777 +     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
   5.778 +apply (cases "b=0", simp)
   5.779 +apply (simp add: right_inverse_eq)
   5.780 +done
   5.781 +
   5.782 +lemma one_eq_divide_iff [simp,noatp]:
   5.783 +     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
   5.784 +by (simp add: eq_commute [of 1])
   5.785 +
   5.786 +lemma zero_eq_1_divide_iff [simp,noatp]:
   5.787 +     "((0::'a::{linordered_field,division_by_zero}) = 1/a) = (a = 0)"
   5.788 +apply (cases "a=0", simp)
   5.789 +apply (auto simp add: nonzero_eq_divide_eq)
   5.790 +done
   5.791 +
   5.792 +lemma one_divide_eq_0_iff [simp,noatp]:
   5.793 +     "(1/a = (0::'a::{linordered_field,division_by_zero})) = (a = 0)"
   5.794 +apply (cases "a=0", simp)
   5.795 +apply (insert zero_neq_one [THEN not_sym])
   5.796 +apply (auto simp add: nonzero_divide_eq_eq)
   5.797 +done
   5.798 +
   5.799 +text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
   5.800 +lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
   5.801 +lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
   5.802 +lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
   5.803 +lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
   5.804 +
   5.805 +declare zero_less_divide_1_iff [simp,noatp]
   5.806 +declare divide_less_0_1_iff [simp,noatp]
   5.807 +declare zero_le_divide_1_iff [simp,noatp]
   5.808 +declare divide_le_0_1_iff [simp,noatp]
   5.809 +
   5.810 +
   5.811 +subsection {* Ordering Rules for Division *}
   5.812 +
   5.813 +lemma divide_strict_right_mono:
   5.814 +     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::linordered_field)"
   5.815 +by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
   5.816 +              positive_imp_inverse_positive)
   5.817 +
   5.818 +lemma divide_right_mono:
   5.819 +     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{linordered_field,division_by_zero})"
   5.820 +by (force simp add: divide_strict_right_mono order_le_less)
   5.821 +
   5.822 +lemma divide_right_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
   5.823 +    ==> c <= 0 ==> b / c <= a / c"
   5.824 +apply (drule divide_right_mono [of _ _ "- c"])
   5.825 +apply auto
   5.826 +done
   5.827 +
   5.828 +lemma divide_strict_right_mono_neg:
   5.829 +     "[|b < a; c < 0|] ==> a / c < b / (c::'a::linordered_field)"
   5.830 +apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
   5.831 +apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
   5.832 +done
   5.833 +
   5.834 +text{*The last premise ensures that @{term a} and @{term b} 
   5.835 +      have the same sign*}
   5.836 +lemma divide_strict_left_mono:
   5.837 +  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
   5.838 +by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
   5.839 +
   5.840 +lemma divide_left_mono:
   5.841 +  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::linordered_field)"
   5.842 +by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
   5.843 +
   5.844 +lemma divide_left_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
   5.845 +    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
   5.846 +  apply (drule divide_left_mono [of _ _ "- c"])
   5.847 +  apply (auto simp add: mult_commute)
   5.848 +done
   5.849 +
   5.850 +lemma divide_strict_left_mono_neg:
   5.851 +  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
   5.852 +by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
   5.853 +
   5.854 +
   5.855 +text{*Simplify quotients that are compared with the value 1.*}
   5.856 +
   5.857 +lemma le_divide_eq_1 [noatp]:
   5.858 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.859 +  shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
   5.860 +by (auto simp add: le_divide_eq)
   5.861 +
   5.862 +lemma divide_le_eq_1 [noatp]:
   5.863 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.864 +  shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
   5.865 +by (auto simp add: divide_le_eq)
   5.866 +
   5.867 +lemma less_divide_eq_1 [noatp]:
   5.868 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.869 +  shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
   5.870 +by (auto simp add: less_divide_eq)
   5.871 +
   5.872 +lemma divide_less_eq_1 [noatp]:
   5.873 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.874 +  shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
   5.875 +by (auto simp add: divide_less_eq)
   5.876 +
   5.877 +
   5.878 +subsection{*Conditional Simplification Rules: No Case Splits*}
   5.879 +
   5.880 +lemma le_divide_eq_1_pos [simp,noatp]:
   5.881 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.882 +  shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
   5.883 +by (auto simp add: le_divide_eq)
   5.884 +
   5.885 +lemma le_divide_eq_1_neg [simp,noatp]:
   5.886 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.887 +  shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
   5.888 +by (auto simp add: le_divide_eq)
   5.889 +
   5.890 +lemma divide_le_eq_1_pos [simp,noatp]:
   5.891 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.892 +  shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
   5.893 +by (auto simp add: divide_le_eq)
   5.894 +
   5.895 +lemma divide_le_eq_1_neg [simp,noatp]:
   5.896 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.897 +  shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
   5.898 +by (auto simp add: divide_le_eq)
   5.899 +
   5.900 +lemma less_divide_eq_1_pos [simp,noatp]:
   5.901 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.902 +  shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
   5.903 +by (auto simp add: less_divide_eq)
   5.904 +
   5.905 +lemma less_divide_eq_1_neg [simp,noatp]:
   5.906 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.907 +  shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
   5.908 +by (auto simp add: less_divide_eq)
   5.909 +
   5.910 +lemma divide_less_eq_1_pos [simp,noatp]:
   5.911 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.912 +  shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
   5.913 +by (auto simp add: divide_less_eq)
   5.914 +
   5.915 +lemma divide_less_eq_1_neg [simp,noatp]:
   5.916 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.917 +  shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
   5.918 +by (auto simp add: divide_less_eq)
   5.919 +
   5.920 +lemma eq_divide_eq_1 [simp,noatp]:
   5.921 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.922 +  shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
   5.923 +by (auto simp add: eq_divide_eq)
   5.924 +
   5.925 +lemma divide_eq_eq_1 [simp,noatp]:
   5.926 +  fixes a :: "'a :: {linordered_field,division_by_zero}"
   5.927 +  shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
   5.928 +by (auto simp add: divide_eq_eq)
   5.929 +
   5.930 +
   5.931 +subsection {* Reasoning about inequalities with division *}
   5.932 +
   5.933 +lemma mult_imp_div_pos_le: "0 < (y::'a::linordered_field) ==> x <= z * y ==>
   5.934 +    x / y <= z"
   5.935 +by (subst pos_divide_le_eq, assumption+)
   5.936 +
   5.937 +lemma mult_imp_le_div_pos: "0 < (y::'a::linordered_field) ==> z * y <= x ==>
   5.938 +    z <= x / y"
   5.939 +by(simp add:field_simps)
   5.940 +
   5.941 +lemma mult_imp_div_pos_less: "0 < (y::'a::linordered_field) ==> x < z * y ==>
   5.942 +    x / y < z"
   5.943 +by(simp add:field_simps)
   5.944 +
   5.945 +lemma mult_imp_less_div_pos: "0 < (y::'a::linordered_field) ==> z * y < x ==>
   5.946 +    z < x / y"
   5.947 +by(simp add:field_simps)
   5.948 +
   5.949 +lemma frac_le: "(0::'a::linordered_field) <= x ==> 
   5.950 +    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
   5.951 +  apply (rule mult_imp_div_pos_le)
   5.952 +  apply simp
   5.953 +  apply (subst times_divide_eq_left)
   5.954 +  apply (rule mult_imp_le_div_pos, assumption)
   5.955 +  apply (rule mult_mono)
   5.956 +  apply simp_all
   5.957 +done
   5.958 +
   5.959 +lemma frac_less: "(0::'a::linordered_field) <= x ==> 
   5.960 +    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
   5.961 +  apply (rule mult_imp_div_pos_less)
   5.962 +  apply simp
   5.963 +  apply (subst times_divide_eq_left)
   5.964 +  apply (rule mult_imp_less_div_pos, assumption)
   5.965 +  apply (erule mult_less_le_imp_less)
   5.966 +  apply simp_all
   5.967 +done
   5.968 +
   5.969 +lemma frac_less2: "(0::'a::linordered_field) < x ==> 
   5.970 +    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
   5.971 +  apply (rule mult_imp_div_pos_less)
   5.972 +  apply simp_all
   5.973 +  apply (subst times_divide_eq_left)
   5.974 +  apply (rule mult_imp_less_div_pos, assumption)
   5.975 +  apply (erule mult_le_less_imp_less)
   5.976 +  apply simp_all
   5.977 +done
   5.978 +
   5.979 +text{*It's not obvious whether these should be simprules or not. 
   5.980 +  Their effect is to gather terms into one big fraction, like
   5.981 +  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
   5.982 +  seem to need them.*}
   5.983 +
   5.984 +declare times_divide_eq [simp]
   5.985 +
   5.986 +
   5.987 +subsection {* Ordered Fields are Dense *}
   5.988 +
   5.989 +lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::linordered_field)"
   5.990 +by (simp add: field_simps zero_less_two)
   5.991 +
   5.992 +lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::linordered_field) < b"
   5.993 +by (simp add: field_simps zero_less_two)
   5.994 +
   5.995 +instance linordered_field < dense_linorder
   5.996 +proof
   5.997 +  fix x y :: 'a
   5.998 +  have "x < x + 1" by simp
   5.999 +  then show "\<exists>y. x < y" .. 
  5.1000 +  have "x - 1 < x" by simp
  5.1001 +  then show "\<exists>y. y < x" ..
  5.1002 +  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
  5.1003 +qed
  5.1004 +
  5.1005 +
  5.1006 +subsection {* Absolute Value *}
  5.1007 +
  5.1008 +lemma nonzero_abs_inverse:
  5.1009 +     "a \<noteq> 0 ==> abs (inverse (a::'a::linordered_field)) = inverse (abs a)"
  5.1010 +apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
  5.1011 +                      negative_imp_inverse_negative)
  5.1012 +apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
  5.1013 +done
  5.1014 +
  5.1015 +lemma abs_inverse [simp]:
  5.1016 +     "abs (inverse (a::'a::{linordered_field,division_by_zero})) = 
  5.1017 +      inverse (abs a)"
  5.1018 +apply (cases "a=0", simp) 
  5.1019 +apply (simp add: nonzero_abs_inverse) 
  5.1020 +done
  5.1021 +
  5.1022 +lemma nonzero_abs_divide:
  5.1023 +     "b \<noteq> 0 ==> abs (a / (b::'a::linordered_field)) = abs a / abs b"
  5.1024 +by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
  5.1025 +
  5.1026 +lemma abs_divide [simp]:
  5.1027 +     "abs (a / (b::'a::{linordered_field,division_by_zero})) = abs a / abs b"
  5.1028 +apply (cases "b=0", simp) 
  5.1029 +apply (simp add: nonzero_abs_divide) 
  5.1030 +done
  5.1031 +
  5.1032 +lemma abs_div_pos: "(0::'a::{division_by_zero,linordered_field}) < y ==> 
  5.1033 +    abs x / y = abs (x / y)"
  5.1034 +  apply (subst abs_divide)
  5.1035 +  apply (simp add: order_less_imp_le)
  5.1036 +done
  5.1037 +
  5.1038 +code_modulename SML
  5.1039 +  Fields Arith
  5.1040 +
  5.1041 +code_modulename OCaml
  5.1042 +  Fields Arith
  5.1043 +
  5.1044 +code_modulename Haskell
  5.1045 +  Fields Arith
  5.1046 +
  5.1047 +end
     6.1 --- a/src/HOL/Groebner_Basis.thy	Mon Feb 08 17:12:32 2010 +0100
     6.2 +++ b/src/HOL/Groebner_Basis.thy	Mon Feb 08 17:12:38 2010 +0100
     6.3 @@ -621,7 +621,7 @@
     6.4  
     6.5  val ths = [@{thm "mult_numeral_1"}, @{thm "mult_numeral_1_right"},
     6.6             @{thm "divide_Numeral1"},
     6.7 -           @{thm "Ring_and_Field.divide_zero"}, @{thm "divide_Numeral0"},
     6.8 +           @{thm "Fields.divide_zero"}, @{thm "divide_Numeral0"},
     6.9             @{thm "divide_divide_eq_left"}, @{thm "mult_frac_frac"},
    6.10             @{thm "mult_num_frac"}, @{thm "mult_frac_num"},
    6.11             @{thm "mult_frac_frac"}, @{thm "times_divide_eq_right"},
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/HOL/Groups.thy	Mon Feb 08 17:12:38 2010 +0100
     7.3 @@ -0,0 +1,1159 @@
     7.4 +(*  Title:   HOL/Groups.thy
     7.5 +    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, Markus Wenzel, Jeremy Avigad
     7.6 +*)
     7.7 +
     7.8 +header {* Groups, also combined with orderings *}
     7.9 +
    7.10 +theory Groups
    7.11 +imports Lattices
    7.12 +uses "~~/src/Provers/Arith/abel_cancel.ML"
    7.13 +begin
    7.14 +
    7.15 +text {*
    7.16 +  The theory of partially ordered groups is taken from the books:
    7.17 +  \begin{itemize}
    7.18 +  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
    7.19 +  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
    7.20 +  \end{itemize}
    7.21 +  Most of the used notions can also be looked up in 
    7.22 +  \begin{itemize}
    7.23 +  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
    7.24 +  \item \emph{Algebra I} by van der Waerden, Springer.
    7.25 +  \end{itemize}
    7.26 +*}
    7.27 +
    7.28 +ML {*
    7.29 +structure Algebra_Simps = Named_Thms(
    7.30 +  val name = "algebra_simps"
    7.31 +  val description = "algebra simplification rules"
    7.32 +)
    7.33 +*}
    7.34 +
    7.35 +setup Algebra_Simps.setup
    7.36 +
    7.37 +text{* The rewrites accumulated in @{text algebra_simps} deal with the
    7.38 +classical algebraic structures of groups, rings and family. They simplify
    7.39 +terms by multiplying everything out (in case of a ring) and bringing sums and
    7.40 +products into a canonical form (by ordered rewriting). As a result it decides
    7.41 +group and ring equalities but also helps with inequalities.
    7.42 +
    7.43 +Of course it also works for fields, but it knows nothing about multiplicative
    7.44 +inverses or division. This is catered for by @{text field_simps}. *}
    7.45 +
    7.46 +subsection {* Semigroups and Monoids *}
    7.47 +
    7.48 +class semigroup_add = plus +
    7.49 +  assumes add_assoc [algebra_simps]: "(a + b) + c = a + (b + c)"
    7.50 +
    7.51 +sublocale semigroup_add < plus!: semigroup plus proof
    7.52 +qed (fact add_assoc)
    7.53 +
    7.54 +class ab_semigroup_add = semigroup_add +
    7.55 +  assumes add_commute [algebra_simps]: "a + b = b + a"
    7.56 +
    7.57 +sublocale ab_semigroup_add < plus!: abel_semigroup plus proof
    7.58 +qed (fact add_commute)
    7.59 +
    7.60 +context ab_semigroup_add
    7.61 +begin
    7.62 +
    7.63 +lemmas add_left_commute [algebra_simps] = plus.left_commute
    7.64 +
    7.65 +theorems add_ac = add_assoc add_commute add_left_commute
    7.66 +
    7.67 +end
    7.68 +
    7.69 +theorems add_ac = add_assoc add_commute add_left_commute
    7.70 +
    7.71 +class semigroup_mult = times +
    7.72 +  assumes mult_assoc [algebra_simps]: "(a * b) * c = a * (b * c)"
    7.73 +
    7.74 +sublocale semigroup_mult < times!: semigroup times proof
    7.75 +qed (fact mult_assoc)
    7.76 +
    7.77 +class ab_semigroup_mult = semigroup_mult +
    7.78 +  assumes mult_commute [algebra_simps]: "a * b = b * a"
    7.79 +
    7.80 +sublocale ab_semigroup_mult < times!: abel_semigroup times proof
    7.81 +qed (fact mult_commute)
    7.82 +
    7.83 +context ab_semigroup_mult
    7.84 +begin
    7.85 +
    7.86 +lemmas mult_left_commute [algebra_simps] = times.left_commute
    7.87 +
    7.88 +theorems mult_ac = mult_assoc mult_commute mult_left_commute
    7.89 +
    7.90 +end
    7.91 +
    7.92 +theorems mult_ac = mult_assoc mult_commute mult_left_commute
    7.93 +
    7.94 +class ab_semigroup_idem_mult = ab_semigroup_mult +
    7.95 +  assumes mult_idem: "x * x = x"
    7.96 +
    7.97 +sublocale ab_semigroup_idem_mult < times!: semilattice times proof
    7.98 +qed (fact mult_idem)
    7.99 +
   7.100 +context ab_semigroup_idem_mult
   7.101 +begin
   7.102 +
   7.103 +lemmas mult_left_idem = times.left_idem
   7.104 +
   7.105 +end
   7.106 +
   7.107 +class monoid_add = zero + semigroup_add +
   7.108 +  assumes add_0_left [simp]: "0 + a = a"
   7.109 +    and add_0_right [simp]: "a + 0 = a"
   7.110 +
   7.111 +lemma zero_reorient: "0 = x \<longleftrightarrow> x = 0"
   7.112 +by (rule eq_commute)
   7.113 +
   7.114 +class comm_monoid_add = zero + ab_semigroup_add +
   7.115 +  assumes add_0: "0 + a = a"
   7.116 +begin
   7.117 +
   7.118 +subclass monoid_add
   7.119 +  proof qed (insert add_0, simp_all add: add_commute)
   7.120 +
   7.121 +end
   7.122 +
   7.123 +class monoid_mult = one + semigroup_mult +
   7.124 +  assumes mult_1_left [simp]: "1 * a  = a"
   7.125 +  assumes mult_1_right [simp]: "a * 1 = a"
   7.126 +
   7.127 +lemma one_reorient: "1 = x \<longleftrightarrow> x = 1"
   7.128 +by (rule eq_commute)
   7.129 +
   7.130 +class comm_monoid_mult = one + ab_semigroup_mult +
   7.131 +  assumes mult_1: "1 * a = a"
   7.132 +begin
   7.133 +
   7.134 +subclass monoid_mult
   7.135 +  proof qed (insert mult_1, simp_all add: mult_commute)
   7.136 +
   7.137 +end
   7.138 +
   7.139 +class cancel_semigroup_add = semigroup_add +
   7.140 +  assumes add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
   7.141 +  assumes add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
   7.142 +begin
   7.143 +
   7.144 +lemma add_left_cancel [simp]:
   7.145 +  "a + b = a + c \<longleftrightarrow> b = c"
   7.146 +by (blast dest: add_left_imp_eq)
   7.147 +
   7.148 +lemma add_right_cancel [simp]:
   7.149 +  "b + a = c + a \<longleftrightarrow> b = c"
   7.150 +by (blast dest: add_right_imp_eq)
   7.151 +
   7.152 +end
   7.153 +
   7.154 +class cancel_ab_semigroup_add = ab_semigroup_add +
   7.155 +  assumes add_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
   7.156 +begin
   7.157 +
   7.158 +subclass cancel_semigroup_add
   7.159 +proof
   7.160 +  fix a b c :: 'a
   7.161 +  assume "a + b = a + c" 
   7.162 +  then show "b = c" by (rule add_imp_eq)
   7.163 +next
   7.164 +  fix a b c :: 'a
   7.165 +  assume "b + a = c + a"
   7.166 +  then have "a + b = a + c" by (simp only: add_commute)
   7.167 +  then show "b = c" by (rule add_imp_eq)
   7.168 +qed
   7.169 +
   7.170 +end
   7.171 +
   7.172 +class cancel_comm_monoid_add = cancel_ab_semigroup_add + comm_monoid_add
   7.173 +
   7.174 +
   7.175 +subsection {* Groups *}
   7.176 +
   7.177 +class group_add = minus + uminus + monoid_add +
   7.178 +  assumes left_minus [simp]: "- a + a = 0"
   7.179 +  assumes diff_minus: "a - b = a + (- b)"
   7.180 +begin
   7.181 +
   7.182 +lemma minus_unique:
   7.183 +  assumes "a + b = 0" shows "- a = b"
   7.184 +proof -
   7.185 +  have "- a = - a + (a + b)" using assms by simp
   7.186 +  also have "\<dots> = b" by (simp add: add_assoc [symmetric])
   7.187 +  finally show ?thesis .
   7.188 +qed
   7.189 +
   7.190 +lemmas equals_zero_I = minus_unique (* legacy name *)
   7.191 +
   7.192 +lemma minus_zero [simp]: "- 0 = 0"
   7.193 +proof -
   7.194 +  have "0 + 0 = 0" by (rule add_0_right)
   7.195 +  thus "- 0 = 0" by (rule minus_unique)
   7.196 +qed
   7.197 +
   7.198 +lemma minus_minus [simp]: "- (- a) = a"
   7.199 +proof -
   7.200 +  have "- a + a = 0" by (rule left_minus)
   7.201 +  thus "- (- a) = a" by (rule minus_unique)
   7.202 +qed
   7.203 +
   7.204 +lemma right_minus [simp]: "a + - a = 0"
   7.205 +proof -
   7.206 +  have "a + - a = - (- a) + - a" by simp
   7.207 +  also have "\<dots> = 0" by (rule left_minus)
   7.208 +  finally show ?thesis .
   7.209 +qed
   7.210 +
   7.211 +lemma minus_add_cancel: "- a + (a + b) = b"
   7.212 +by (simp add: add_assoc [symmetric])
   7.213 +
   7.214 +lemma add_minus_cancel: "a + (- a + b) = b"
   7.215 +by (simp add: add_assoc [symmetric])
   7.216 +
   7.217 +lemma minus_add: "- (a + b) = - b + - a"
   7.218 +proof -
   7.219 +  have "(a + b) + (- b + - a) = 0"
   7.220 +    by (simp add: add_assoc add_minus_cancel)
   7.221 +  thus "- (a + b) = - b + - a"
   7.222 +    by (rule minus_unique)
   7.223 +qed
   7.224 +
   7.225 +lemma right_minus_eq: "a - b = 0 \<longleftrightarrow> a = b"
   7.226 +proof
   7.227 +  assume "a - b = 0"
   7.228 +  have "a = (a - b) + b" by (simp add:diff_minus add_assoc)
   7.229 +  also have "\<dots> = b" using `a - b = 0` by simp
   7.230 +  finally show "a = b" .
   7.231 +next
   7.232 +  assume "a = b" thus "a - b = 0" by (simp add: diff_minus)
   7.233 +qed
   7.234 +
   7.235 +lemma diff_self [simp]: "a - a = 0"
   7.236 +by (simp add: diff_minus)
   7.237 +
   7.238 +lemma diff_0 [simp]: "0 - a = - a"
   7.239 +by (simp add: diff_minus)
   7.240 +
   7.241 +lemma diff_0_right [simp]: "a - 0 = a" 
   7.242 +by (simp add: diff_minus)
   7.243 +
   7.244 +lemma diff_minus_eq_add [simp]: "a - - b = a + b"
   7.245 +by (simp add: diff_minus)
   7.246 +
   7.247 +lemma neg_equal_iff_equal [simp]:
   7.248 +  "- a = - b \<longleftrightarrow> a = b" 
   7.249 +proof 
   7.250 +  assume "- a = - b"
   7.251 +  hence "- (- a) = - (- b)" by simp
   7.252 +  thus "a = b" by simp
   7.253 +next
   7.254 +  assume "a = b"
   7.255 +  thus "- a = - b" by simp
   7.256 +qed
   7.257 +
   7.258 +lemma neg_equal_0_iff_equal [simp]:
   7.259 +  "- a = 0 \<longleftrightarrow> a = 0"
   7.260 +by (subst neg_equal_iff_equal [symmetric], simp)
   7.261 +
   7.262 +lemma neg_0_equal_iff_equal [simp]:
   7.263 +  "0 = - a \<longleftrightarrow> 0 = a"
   7.264 +by (subst neg_equal_iff_equal [symmetric], simp)
   7.265 +
   7.266 +text{*The next two equations can make the simplifier loop!*}
   7.267 +
   7.268 +lemma equation_minus_iff:
   7.269 +  "a = - b \<longleftrightarrow> b = - a"
   7.270 +proof -
   7.271 +  have "- (- a) = - b \<longleftrightarrow> - a = b" by (rule neg_equal_iff_equal)
   7.272 +  thus ?thesis by (simp add: eq_commute)
   7.273 +qed
   7.274 +
   7.275 +lemma minus_equation_iff:
   7.276 +  "- a = b \<longleftrightarrow> - b = a"
   7.277 +proof -
   7.278 +  have "- a = - (- b) \<longleftrightarrow> a = -b" by (rule neg_equal_iff_equal)
   7.279 +  thus ?thesis by (simp add: eq_commute)
   7.280 +qed
   7.281 +
   7.282 +lemma diff_add_cancel: "a - b + b = a"
   7.283 +by (simp add: diff_minus add_assoc)
   7.284 +
   7.285 +lemma add_diff_cancel: "a + b - b = a"
   7.286 +by (simp add: diff_minus add_assoc)
   7.287 +
   7.288 +declare diff_minus[symmetric, algebra_simps]
   7.289 +
   7.290 +lemma eq_neg_iff_add_eq_0: "a = - b \<longleftrightarrow> a + b = 0"
   7.291 +proof
   7.292 +  assume "a = - b" then show "a + b = 0" by simp
   7.293 +next
   7.294 +  assume "a + b = 0"
   7.295 +  moreover have "a + (b + - b) = (a + b) + - b"
   7.296 +    by (simp only: add_assoc)
   7.297 +  ultimately show "a = - b" by simp
   7.298 +qed
   7.299 +
   7.300 +end
   7.301 +
   7.302 +class ab_group_add = minus + uminus + comm_monoid_add +
   7.303 +  assumes ab_left_minus: "- a + a = 0"
   7.304 +  assumes ab_diff_minus: "a - b = a + (- b)"
   7.305 +begin
   7.306 +
   7.307 +subclass group_add
   7.308 +  proof qed (simp_all add: ab_left_minus ab_diff_minus)
   7.309 +
   7.310 +subclass cancel_comm_monoid_add
   7.311 +proof
   7.312 +  fix a b c :: 'a
   7.313 +  assume "a + b = a + c"
   7.314 +  then have "- a + a + b = - a + a + c"
   7.315 +    unfolding add_assoc by simp
   7.316 +  then show "b = c" by simp
   7.317 +qed
   7.318 +
   7.319 +lemma uminus_add_conv_diff[algebra_simps]:
   7.320 +  "- a + b = b - a"
   7.321 +by (simp add:diff_minus add_commute)
   7.322 +
   7.323 +lemma minus_add_distrib [simp]:
   7.324 +  "- (a + b) = - a + - b"
   7.325 +by (rule minus_unique) (simp add: add_ac)
   7.326 +
   7.327 +lemma minus_diff_eq [simp]:
   7.328 +  "- (a - b) = b - a"
   7.329 +by (simp add: diff_minus add_commute)
   7.330 +
   7.331 +lemma add_diff_eq[algebra_simps]: "a + (b - c) = (a + b) - c"
   7.332 +by (simp add: diff_minus add_ac)
   7.333 +
   7.334 +lemma diff_add_eq[algebra_simps]: "(a - b) + c = (a + c) - b"
   7.335 +by (simp add: diff_minus add_ac)
   7.336 +
   7.337 +lemma diff_eq_eq[algebra_simps]: "a - b = c \<longleftrightarrow> a = c + b"
   7.338 +by (auto simp add: diff_minus add_assoc)
   7.339 +
   7.340 +lemma eq_diff_eq[algebra_simps]: "a = c - b \<longleftrightarrow> a + b = c"
   7.341 +by (auto simp add: diff_minus add_assoc)
   7.342 +
   7.343 +lemma diff_diff_eq[algebra_simps]: "(a - b) - c = a - (b + c)"
   7.344 +by (simp add: diff_minus add_ac)
   7.345 +
   7.346 +lemma diff_diff_eq2[algebra_simps]: "a - (b - c) = (a + c) - b"
   7.347 +by (simp add: diff_minus add_ac)
   7.348 +
   7.349 +lemma eq_iff_diff_eq_0: "a = b \<longleftrightarrow> a - b = 0"
   7.350 +by (simp add: algebra_simps)
   7.351 +
   7.352 +lemma diff_eq_0_iff_eq [simp, noatp]: "a - b = 0 \<longleftrightarrow> a = b"
   7.353 +by (simp add: algebra_simps)
   7.354 +
   7.355 +end
   7.356 +
   7.357 +subsection {* (Partially) Ordered Groups *} 
   7.358 +
   7.359 +class ordered_ab_semigroup_add = order + ab_semigroup_add +
   7.360 +  assumes add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
   7.361 +begin
   7.362 +
   7.363 +lemma add_right_mono:
   7.364 +  "a \<le> b \<Longrightarrow> a + c \<le> b + c"
   7.365 +by (simp add: add_commute [of _ c] add_left_mono)
   7.366 +
   7.367 +text {* non-strict, in both arguments *}
   7.368 +lemma add_mono:
   7.369 +  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c \<le> b + d"
   7.370 +  apply (erule add_right_mono [THEN order_trans])
   7.371 +  apply (simp add: add_commute add_left_mono)
   7.372 +  done
   7.373 +
   7.374 +end
   7.375 +
   7.376 +class ordered_cancel_ab_semigroup_add =
   7.377 +  ordered_ab_semigroup_add + cancel_ab_semigroup_add
   7.378 +begin
   7.379 +
   7.380 +lemma add_strict_left_mono:
   7.381 +  "a < b \<Longrightarrow> c + a < c + b"
   7.382 +by (auto simp add: less_le add_left_mono)
   7.383 +
   7.384 +lemma add_strict_right_mono:
   7.385 +  "a < b \<Longrightarrow> a + c < b + c"
   7.386 +by (simp add: add_commute [of _ c] add_strict_left_mono)
   7.387 +
   7.388 +text{*Strict monotonicity in both arguments*}
   7.389 +lemma add_strict_mono:
   7.390 +  "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
   7.391 +apply (erule add_strict_right_mono [THEN less_trans])
   7.392 +apply (erule add_strict_left_mono)
   7.393 +done
   7.394 +
   7.395 +lemma add_less_le_mono:
   7.396 +  "a < b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c < b + d"
   7.397 +apply (erule add_strict_right_mono [THEN less_le_trans])
   7.398 +apply (erule add_left_mono)
   7.399 +done
   7.400 +
   7.401 +lemma add_le_less_mono:
   7.402 +  "a \<le> b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
   7.403 +apply (erule add_right_mono [THEN le_less_trans])
   7.404 +apply (erule add_strict_left_mono) 
   7.405 +done
   7.406 +
   7.407 +end
   7.408 +
   7.409 +class ordered_ab_semigroup_add_imp_le =
   7.410 +  ordered_cancel_ab_semigroup_add +
   7.411 +  assumes add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
   7.412 +begin
   7.413 +
   7.414 +lemma add_less_imp_less_left:
   7.415 +  assumes less: "c + a < c + b" shows "a < b"
   7.416 +proof -
   7.417 +  from less have le: "c + a <= c + b" by (simp add: order_le_less)
   7.418 +  have "a <= b" 
   7.419 +    apply (insert le)
   7.420 +    apply (drule add_le_imp_le_left)
   7.421 +    by (insert le, drule add_le_imp_le_left, assumption)
   7.422 +  moreover have "a \<noteq> b"
   7.423 +  proof (rule ccontr)
   7.424 +    assume "~(a \<noteq> b)"
   7.425 +    then have "a = b" by simp
   7.426 +    then have "c + a = c + b" by simp
   7.427 +    with less show "False"by simp
   7.428 +  qed
   7.429 +  ultimately show "a < b" by (simp add: order_le_less)
   7.430 +qed
   7.431 +
   7.432 +lemma add_less_imp_less_right:
   7.433 +  "a + c < b + c \<Longrightarrow> a < b"
   7.434 +apply (rule add_less_imp_less_left [of c])
   7.435 +apply (simp add: add_commute)  
   7.436 +done
   7.437 +
   7.438 +lemma add_less_cancel_left [simp]:
   7.439 +  "c + a < c + b \<longleftrightarrow> a < b"
   7.440 +by (blast intro: add_less_imp_less_left add_strict_left_mono) 
   7.441 +
   7.442 +lemma add_less_cancel_right [simp]:
   7.443 +  "a + c < b + c \<longleftrightarrow> a < b"
   7.444 +by (blast intro: add_less_imp_less_right add_strict_right_mono)
   7.445 +
   7.446 +lemma add_le_cancel_left [simp]:
   7.447 +  "c + a \<le> c + b \<longleftrightarrow> a \<le> b"
   7.448 +by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
   7.449 +
   7.450 +lemma add_le_cancel_right [simp]:
   7.451 +  "a + c \<le> b + c \<longleftrightarrow> a \<le> b"
   7.452 +by (simp add: add_commute [of a c] add_commute [of b c])
   7.453 +
   7.454 +lemma add_le_imp_le_right:
   7.455 +  "a + c \<le> b + c \<Longrightarrow> a \<le> b"
   7.456 +by simp
   7.457 +
   7.458 +lemma max_add_distrib_left:
   7.459 +  "max x y + z = max (x + z) (y + z)"
   7.460 +  unfolding max_def by auto
   7.461 +
   7.462 +lemma min_add_distrib_left:
   7.463 +  "min x y + z = min (x + z) (y + z)"
   7.464 +  unfolding min_def by auto
   7.465 +
   7.466 +end
   7.467 +
   7.468 +subsection {* Support for reasoning about signs *}
   7.469 +
   7.470 +class ordered_comm_monoid_add =
   7.471 +  ordered_cancel_ab_semigroup_add + comm_monoid_add
   7.472 +begin
   7.473 +
   7.474 +lemma add_pos_nonneg:
   7.475 +  assumes "0 < a" and "0 \<le> b" shows "0 < a + b"
   7.476 +proof -
   7.477 +  have "0 + 0 < a + b" 
   7.478 +    using assms by (rule add_less_le_mono)
   7.479 +  then show ?thesis by simp
   7.480 +qed
   7.481 +
   7.482 +lemma add_pos_pos:
   7.483 +  assumes "0 < a" and "0 < b" shows "0 < a + b"
   7.484 +by (rule add_pos_nonneg) (insert assms, auto)
   7.485 +
   7.486 +lemma add_nonneg_pos:
   7.487 +  assumes "0 \<le> a" and "0 < b" shows "0 < a + b"
   7.488 +proof -
   7.489 +  have "0 + 0 < a + b" 
   7.490 +    using assms by (rule add_le_less_mono)
   7.491 +  then show ?thesis by simp
   7.492 +qed
   7.493 +
   7.494 +lemma add_nonneg_nonneg:
   7.495 +  assumes "0 \<le> a" and "0 \<le> b" shows "0 \<le> a + b"
   7.496 +proof -
   7.497 +  have "0 + 0 \<le> a + b" 
   7.498 +    using assms by (rule add_mono)
   7.499 +  then show ?thesis by simp
   7.500 +qed
   7.501 +
   7.502 +lemma add_neg_nonpos:
   7.503 +  assumes "a < 0" and "b \<le> 0" shows "a + b < 0"
   7.504 +proof -
   7.505 +  have "a + b < 0 + 0"
   7.506 +    using assms by (rule add_less_le_mono)
   7.507 +  then show ?thesis by simp
   7.508 +qed
   7.509 +
   7.510 +lemma add_neg_neg: 
   7.511 +  assumes "a < 0" and "b < 0" shows "a + b < 0"
   7.512 +by (rule add_neg_nonpos) (insert assms, auto)
   7.513 +
   7.514 +lemma add_nonpos_neg:
   7.515 +  assumes "a \<le> 0" and "b < 0" shows "a + b < 0"
   7.516 +proof -
   7.517 +  have "a + b < 0 + 0"
   7.518 +    using assms by (rule add_le_less_mono)
   7.519 +  then show ?thesis by simp
   7.520 +qed
   7.521 +
   7.522 +lemma add_nonpos_nonpos:
   7.523 +  assumes "a \<le> 0" and "b \<le> 0" shows "a + b \<le> 0"
   7.524 +proof -
   7.525 +  have "a + b \<le> 0 + 0"
   7.526 +    using assms by (rule add_mono)
   7.527 +  then show ?thesis by simp
   7.528 +qed
   7.529 +
   7.530 +lemmas add_sign_intros =
   7.531 +  add_pos_nonneg add_pos_pos add_nonneg_pos add_nonneg_nonneg
   7.532 +  add_neg_nonpos add_neg_neg add_nonpos_neg add_nonpos_nonpos
   7.533 +
   7.534 +lemma add_nonneg_eq_0_iff:
   7.535 +  assumes x: "0 \<le> x" and y: "0 \<le> y"
   7.536 +  shows "x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   7.537 +proof (intro iffI conjI)
   7.538 +  have "x = x + 0" by simp
   7.539 +  also have "x + 0 \<le> x + y" using y by (rule add_left_mono)
   7.540 +  also assume "x + y = 0"
   7.541 +  also have "0 \<le> x" using x .
   7.542 +  finally show "x = 0" .
   7.543 +next
   7.544 +  have "y = 0 + y" by simp
   7.545 +  also have "0 + y \<le> x + y" using x by (rule add_right_mono)
   7.546 +  also assume "x + y = 0"
   7.547 +  also have "0 \<le> y" using y .
   7.548 +  finally show "y = 0" .
   7.549 +next
   7.550 +  assume "x = 0 \<and> y = 0"
   7.551 +  then show "x + y = 0" by simp
   7.552 +qed
   7.553 +
   7.554 +end
   7.555 +
   7.556 +class ordered_ab_group_add =
   7.557 +  ab_group_add + ordered_ab_semigroup_add
   7.558 +begin
   7.559 +
   7.560 +subclass ordered_cancel_ab_semigroup_add ..
   7.561 +
   7.562 +subclass ordered_ab_semigroup_add_imp_le
   7.563 +proof
   7.564 +  fix a b c :: 'a
   7.565 +  assume "c + a \<le> c + b"
   7.566 +  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
   7.567 +  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
   7.568 +  thus "a \<le> b" by simp
   7.569 +qed
   7.570 +
   7.571 +subclass ordered_comm_monoid_add ..
   7.572 +
   7.573 +lemma max_diff_distrib_left:
   7.574 +  shows "max x y - z = max (x - z) (y - z)"
   7.575 +by (simp add: diff_minus, rule max_add_distrib_left) 
   7.576 +
   7.577 +lemma min_diff_distrib_left:
   7.578 +  shows "min x y - z = min (x - z) (y - z)"
   7.579 +by (simp add: diff_minus, rule min_add_distrib_left) 
   7.580 +
   7.581 +lemma le_imp_neg_le:
   7.582 +  assumes "a \<le> b" shows "-b \<le> -a"
   7.583 +proof -
   7.584 +  have "-a+a \<le> -a+b" using `a \<le> b` by (rule add_left_mono) 
   7.585 +  hence "0 \<le> -a+b" by simp
   7.586 +  hence "0 + (-b) \<le> (-a + b) + (-b)" by (rule add_right_mono) 
   7.587 +  thus ?thesis by (simp add: add_assoc)
   7.588 +qed
   7.589 +
   7.590 +lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
   7.591 +proof 
   7.592 +  assume "- b \<le> - a"
   7.593 +  hence "- (- a) \<le> - (- b)" by (rule le_imp_neg_le)
   7.594 +  thus "a\<le>b" by simp
   7.595 +next
   7.596 +  assume "a\<le>b"
   7.597 +  thus "-b \<le> -a" by (rule le_imp_neg_le)
   7.598 +qed
   7.599 +
   7.600 +lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
   7.601 +by (subst neg_le_iff_le [symmetric], simp)
   7.602 +
   7.603 +lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
   7.604 +by (subst neg_le_iff_le [symmetric], simp)
   7.605 +
   7.606 +lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
   7.607 +by (force simp add: less_le) 
   7.608 +
   7.609 +lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
   7.610 +by (subst neg_less_iff_less [symmetric], simp)
   7.611 +
   7.612 +lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
   7.613 +by (subst neg_less_iff_less [symmetric], simp)
   7.614 +
   7.615 +text{*The next several equations can make the simplifier loop!*}
   7.616 +
   7.617 +lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
   7.618 +proof -
   7.619 +  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
   7.620 +  thus ?thesis by simp
   7.621 +qed
   7.622 +
   7.623 +lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
   7.624 +proof -
   7.625 +  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
   7.626 +  thus ?thesis by simp
   7.627 +qed
   7.628 +
   7.629 +lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
   7.630 +proof -
   7.631 +  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
   7.632 +  have "(- (- a) <= -b) = (b <= - a)" 
   7.633 +    apply (auto simp only: le_less)
   7.634 +    apply (drule mm)
   7.635 +    apply (simp_all)
   7.636 +    apply (drule mm[simplified], assumption)
   7.637 +    done
   7.638 +  then show ?thesis by simp
   7.639 +qed
   7.640 +
   7.641 +lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
   7.642 +by (auto simp add: le_less minus_less_iff)
   7.643 +
   7.644 +lemma less_iff_diff_less_0: "a < b \<longleftrightarrow> a - b < 0"
   7.645 +proof -
   7.646 +  have  "(a < b) = (a + (- b) < b + (-b))"  
   7.647 +    by (simp only: add_less_cancel_right)
   7.648 +  also have "... =  (a - b < 0)" by (simp add: diff_minus)
   7.649 +  finally show ?thesis .
   7.650 +qed
   7.651 +
   7.652 +lemma diff_less_eq[algebra_simps]: "a - b < c \<longleftrightarrow> a < c + b"
   7.653 +apply (subst less_iff_diff_less_0 [of a])
   7.654 +apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
   7.655 +apply (simp add: diff_minus add_ac)
   7.656 +done
   7.657 +
   7.658 +lemma less_diff_eq[algebra_simps]: "a < c - b \<longleftrightarrow> a + b < c"
   7.659 +apply (subst less_iff_diff_less_0 [of "plus a b"])
   7.660 +apply (subst less_iff_diff_less_0 [of a])
   7.661 +apply (simp add: diff_minus add_ac)
   7.662 +done
   7.663 +
   7.664 +lemma diff_le_eq[algebra_simps]: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
   7.665 +by (auto simp add: le_less diff_less_eq diff_add_cancel add_diff_cancel)
   7.666 +
   7.667 +lemma le_diff_eq[algebra_simps]: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
   7.668 +by (auto simp add: le_less less_diff_eq diff_add_cancel add_diff_cancel)
   7.669 +
   7.670 +lemma le_iff_diff_le_0: "a \<le> b \<longleftrightarrow> a - b \<le> 0"
   7.671 +by (simp add: algebra_simps)
   7.672 +
   7.673 +text{*Legacy - use @{text algebra_simps} *}
   7.674 +lemmas group_simps[noatp] = algebra_simps
   7.675 +
   7.676 +end
   7.677 +
   7.678 +text{*Legacy - use @{text algebra_simps} *}
   7.679 +lemmas group_simps[noatp] = algebra_simps
   7.680 +
   7.681 +class linordered_ab_semigroup_add =
   7.682 +  linorder + ordered_ab_semigroup_add
   7.683 +
   7.684 +class linordered_cancel_ab_semigroup_add =
   7.685 +  linorder + ordered_cancel_ab_semigroup_add
   7.686 +begin
   7.687 +
   7.688 +subclass linordered_ab_semigroup_add ..
   7.689 +
   7.690 +subclass ordered_ab_semigroup_add_imp_le
   7.691 +proof
   7.692 +  fix a b c :: 'a
   7.693 +  assume le: "c + a <= c + b"  
   7.694 +  show "a <= b"
   7.695 +  proof (rule ccontr)
   7.696 +    assume w: "~ a \<le> b"
   7.697 +    hence "b <= a" by (simp add: linorder_not_le)
   7.698 +    hence le2: "c + b <= c + a" by (rule add_left_mono)
   7.699 +    have "a = b" 
   7.700 +      apply (insert le)
   7.701 +      apply (insert le2)
   7.702 +      apply (drule antisym, simp_all)
   7.703 +      done
   7.704 +    with w show False 
   7.705 +      by (simp add: linorder_not_le [symmetric])
   7.706 +  qed
   7.707 +qed
   7.708 +
   7.709 +end
   7.710 +
   7.711 +class linordered_ab_group_add = linorder + ordered_ab_group_add
   7.712 +begin
   7.713 +
   7.714 +subclass linordered_cancel_ab_semigroup_add ..
   7.715 +
   7.716 +lemma neg_less_eq_nonneg [simp]:
   7.717 +  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
   7.718 +proof
   7.719 +  assume A: "- a \<le> a" show "0 \<le> a"
   7.720 +  proof (rule classical)
   7.721 +    assume "\<not> 0 \<le> a"
   7.722 +    then have "a < 0" by auto
   7.723 +    with A have "- a < 0" by (rule le_less_trans)
   7.724 +    then show ?thesis by auto
   7.725 +  qed
   7.726 +next
   7.727 +  assume A: "0 \<le> a" show "- a \<le> a"
   7.728 +  proof (rule order_trans)
   7.729 +    show "- a \<le> 0" using A by (simp add: minus_le_iff)
   7.730 +  next
   7.731 +    show "0 \<le> a" using A .
   7.732 +  qed
   7.733 +qed
   7.734 +
   7.735 +lemma neg_less_nonneg [simp]:
   7.736 +  "- a < a \<longleftrightarrow> 0 < a"
   7.737 +proof
   7.738 +  assume A: "- a < a" show "0 < a"
   7.739 +  proof (rule classical)
   7.740 +    assume "\<not> 0 < a"
   7.741 +    then have "a \<le> 0" by auto
   7.742 +    with A have "- a < 0" by (rule less_le_trans)
   7.743 +    then show ?thesis by auto
   7.744 +  qed
   7.745 +next
   7.746 +  assume A: "0 < a" show "- a < a"
   7.747 +  proof (rule less_trans)
   7.748 +    show "- a < 0" using A by (simp add: minus_le_iff)
   7.749 +  next
   7.750 +    show "0 < a" using A .
   7.751 +  qed
   7.752 +qed
   7.753 +
   7.754 +lemma less_eq_neg_nonpos [simp]:
   7.755 +  "a \<le> - a \<longleftrightarrow> a \<le> 0"
   7.756 +proof
   7.757 +  assume A: "a \<le> - a" show "a \<le> 0"
   7.758 +  proof (rule classical)
   7.759 +    assume "\<not> a \<le> 0"
   7.760 +    then have "0 < a" by auto
   7.761 +    then have "0 < - a" using A by (rule less_le_trans)
   7.762 +    then show ?thesis by auto
   7.763 +  qed
   7.764 +next
   7.765 +  assume A: "a \<le> 0" show "a \<le> - a"
   7.766 +  proof (rule order_trans)
   7.767 +    show "0 \<le> - a" using A by (simp add: minus_le_iff)
   7.768 +  next
   7.769 +    show "a \<le> 0" using A .
   7.770 +  qed
   7.771 +qed
   7.772 +
   7.773 +lemma equal_neg_zero [simp]:
   7.774 +  "a = - a \<longleftrightarrow> a = 0"
   7.775 +proof
   7.776 +  assume "a = 0" then show "a = - a" by simp
   7.777 +next
   7.778 +  assume A: "a = - a" show "a = 0"
   7.779 +  proof (cases "0 \<le> a")
   7.780 +    case True with A have "0 \<le> - a" by auto
   7.781 +    with le_minus_iff have "a \<le> 0" by simp
   7.782 +    with True show ?thesis by (auto intro: order_trans)
   7.783 +  next
   7.784 +    case False then have B: "a \<le> 0" by auto
   7.785 +    with A have "- a \<le> 0" by auto
   7.786 +    with B show ?thesis by (auto intro: order_trans)
   7.787 +  qed
   7.788 +qed
   7.789 +
   7.790 +lemma neg_equal_zero [simp]:
   7.791 +  "- a = a \<longleftrightarrow> a = 0"
   7.792 +  by (auto dest: sym)
   7.793 +
   7.794 +lemma double_zero [simp]:
   7.795 +  "a + a = 0 \<longleftrightarrow> a = 0"
   7.796 +proof
   7.797 +  assume assm: "a + a = 0"
   7.798 +  then have a: "- a = a" by (rule minus_unique)
   7.799 +  then show "a = 0" by (simp add: neg_equal_zero)
   7.800 +qed simp
   7.801 +
   7.802 +lemma double_zero_sym [simp]:
   7.803 +  "0 = a + a \<longleftrightarrow> a = 0"
   7.804 +  by (rule, drule sym) simp_all
   7.805 +
   7.806 +lemma zero_less_double_add_iff_zero_less_single_add [simp]:
   7.807 +  "0 < a + a \<longleftrightarrow> 0 < a"
   7.808 +proof
   7.809 +  assume "0 < a + a"
   7.810 +  then have "0 - a < a" by (simp only: diff_less_eq)
   7.811 +  then have "- a < a" by simp
   7.812 +  then show "0 < a" by (simp add: neg_less_nonneg)
   7.813 +next
   7.814 +  assume "0 < a"
   7.815 +  with this have "0 + 0 < a + a"
   7.816 +    by (rule add_strict_mono)
   7.817 +  then show "0 < a + a" by simp
   7.818 +qed
   7.819 +
   7.820 +lemma zero_le_double_add_iff_zero_le_single_add [simp]:
   7.821 +  "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
   7.822 +  by (auto simp add: le_less)
   7.823 +
   7.824 +lemma double_add_less_zero_iff_single_add_less_zero [simp]:
   7.825 +  "a + a < 0 \<longleftrightarrow> a < 0"
   7.826 +proof -
   7.827 +  have "\<not> a + a < 0 \<longleftrightarrow> \<not> a < 0"
   7.828 +    by (simp add: not_less)
   7.829 +  then show ?thesis by simp
   7.830 +qed
   7.831 +
   7.832 +lemma double_add_le_zero_iff_single_add_le_zero [simp]:
   7.833 +  "a + a \<le> 0 \<longleftrightarrow> a \<le> 0" 
   7.834 +proof -
   7.835 +  have "\<not> a + a \<le> 0 \<longleftrightarrow> \<not> a \<le> 0"
   7.836 +    by (simp add: not_le)
   7.837 +  then show ?thesis by simp
   7.838 +qed
   7.839 +
   7.840 +lemma le_minus_self_iff:
   7.841 +  "a \<le> - a \<longleftrightarrow> a \<le> 0"
   7.842 +proof -
   7.843 +  from add_le_cancel_left [of "- a" "a + a" 0]
   7.844 +  have "a \<le> - a \<longleftrightarrow> a + a \<le> 0" 
   7.845 +    by (simp add: add_assoc [symmetric])
   7.846 +  thus ?thesis by simp
   7.847 +qed
   7.848 +
   7.849 +lemma minus_le_self_iff:
   7.850 +  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
   7.851 +proof -
   7.852 +  from add_le_cancel_left [of "- a" 0 "a + a"]
   7.853 +  have "- a \<le> a \<longleftrightarrow> 0 \<le> a + a" 
   7.854 +    by (simp add: add_assoc [symmetric])
   7.855 +  thus ?thesis by simp
   7.856 +qed
   7.857 +
   7.858 +lemma minus_max_eq_min:
   7.859 +  "- max x y = min (-x) (-y)"
   7.860 +  by (auto simp add: max_def min_def)
   7.861 +
   7.862 +lemma minus_min_eq_max:
   7.863 +  "- min x y = max (-x) (-y)"
   7.864 +  by (auto simp add: max_def min_def)
   7.865 +
   7.866 +end
   7.867 +
   7.868 +-- {* FIXME localize the following *}
   7.869 +
   7.870 +lemma add_increasing:
   7.871 +  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   7.872 +  shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
   7.873 +by (insert add_mono [of 0 a b c], simp)
   7.874 +
   7.875 +lemma add_increasing2:
   7.876 +  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   7.877 +  shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
   7.878 +by (simp add:add_increasing add_commute[of a])
   7.879 +
   7.880 +lemma add_strict_increasing:
   7.881 +  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   7.882 +  shows "[|0<a; b\<le>c|] ==> b < a + c"
   7.883 +by (insert add_less_le_mono [of 0 a b c], simp)
   7.884 +
   7.885 +lemma add_strict_increasing2:
   7.886 +  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
   7.887 +  shows "[|0\<le>a; b<c|] ==> b < a + c"
   7.888 +by (insert add_le_less_mono [of 0 a b c], simp)
   7.889 +
   7.890 +
   7.891 +class ordered_ab_group_add_abs = ordered_ab_group_add + abs +
   7.892 +  assumes abs_ge_zero [simp]: "\<bar>a\<bar> \<ge> 0"
   7.893 +    and abs_ge_self: "a \<le> \<bar>a\<bar>"
   7.894 +    and abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
   7.895 +    and abs_minus_cancel [simp]: "\<bar>-a\<bar> = \<bar>a\<bar>"
   7.896 +    and abs_triangle_ineq: "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
   7.897 +begin
   7.898 +
   7.899 +lemma abs_minus_le_zero: "- \<bar>a\<bar> \<le> 0"
   7.900 +  unfolding neg_le_0_iff_le by simp
   7.901 +
   7.902 +lemma abs_of_nonneg [simp]:
   7.903 +  assumes nonneg: "0 \<le> a" shows "\<bar>a\<bar> = a"
   7.904 +proof (rule antisym)
   7.905 +  from nonneg le_imp_neg_le have "- a \<le> 0" by simp
   7.906 +  from this nonneg have "- a \<le> a" by (rule order_trans)
   7.907 +  then show "\<bar>a\<bar> \<le> a" by (auto intro: abs_leI)
   7.908 +qed (rule abs_ge_self)
   7.909 +
   7.910 +lemma abs_idempotent [simp]: "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
   7.911 +by (rule antisym)
   7.912 +   (auto intro!: abs_ge_self abs_leI order_trans [of "uminus (abs a)" zero "abs a"])
   7.913 +
   7.914 +lemma abs_eq_0 [simp]: "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
   7.915 +proof -
   7.916 +  have "\<bar>a\<bar> = 0 \<Longrightarrow> a = 0"
   7.917 +  proof (rule antisym)
   7.918 +    assume zero: "\<bar>a\<bar> = 0"
   7.919 +    with abs_ge_self show "a \<le> 0" by auto
   7.920 +    from zero have "\<bar>-a\<bar> = 0" by simp
   7.921 +    with abs_ge_self [of "uminus a"] have "- a \<le> 0" by auto
   7.922 +    with neg_le_0_iff_le show "0 \<le> a" by auto
   7.923 +  qed
   7.924 +  then show ?thesis by auto
   7.925 +qed
   7.926 +
   7.927 +lemma abs_zero [simp]: "\<bar>0\<bar> = 0"
   7.928 +by simp
   7.929 +
   7.930 +lemma abs_0_eq [simp, noatp]: "0 = \<bar>a\<bar> \<longleftrightarrow> a = 0"
   7.931 +proof -
   7.932 +  have "0 = \<bar>a\<bar> \<longleftrightarrow> \<bar>a\<bar> = 0" by (simp only: eq_ac)
   7.933 +  thus ?thesis by simp
   7.934 +qed
   7.935 +
   7.936 +lemma abs_le_zero_iff [simp]: "\<bar>a\<bar> \<le> 0 \<longleftrightarrow> a = 0" 
   7.937 +proof
   7.938 +  assume "\<bar>a\<bar> \<le> 0"
   7.939 +  then have "\<bar>a\<bar> = 0" by (rule antisym) simp
   7.940 +  thus "a = 0" by simp
   7.941 +next
   7.942 +  assume "a = 0"
   7.943 +  thus "\<bar>a\<bar> \<le> 0" by simp
   7.944 +qed
   7.945 +
   7.946 +lemma zero_less_abs_iff [simp]: "0 < \<bar>a\<bar> \<longleftrightarrow> a \<noteq> 0"
   7.947 +by (simp add: less_le)
   7.948 +
   7.949 +lemma abs_not_less_zero [simp]: "\<not> \<bar>a\<bar> < 0"
   7.950 +proof -
   7.951 +  have a: "\<And>x y. x \<le> y \<Longrightarrow> \<not> y < x" by auto
   7.952 +  show ?thesis by (simp add: a)
   7.953 +qed
   7.954 +
   7.955 +lemma abs_ge_minus_self: "- a \<le> \<bar>a\<bar>"
   7.956 +proof -
   7.957 +  have "- a \<le> \<bar>-a\<bar>" by (rule abs_ge_self)
   7.958 +  then show ?thesis by simp
   7.959 +qed
   7.960 +
   7.961 +lemma abs_minus_commute: 
   7.962 +  "\<bar>a - b\<bar> = \<bar>b - a\<bar>"
   7.963 +proof -
   7.964 +  have "\<bar>a - b\<bar> = \<bar>- (a - b)\<bar>" by (simp only: abs_minus_cancel)
   7.965 +  also have "... = \<bar>b - a\<bar>" by simp
   7.966 +  finally show ?thesis .
   7.967 +qed
   7.968 +
   7.969 +lemma abs_of_pos: "0 < a \<Longrightarrow> \<bar>a\<bar> = a"
   7.970 +by (rule abs_of_nonneg, rule less_imp_le)
   7.971 +
   7.972 +lemma abs_of_nonpos [simp]:
   7.973 +  assumes "a \<le> 0" shows "\<bar>a\<bar> = - a"
   7.974 +proof -
   7.975 +  let ?b = "- a"
   7.976 +  have "- ?b \<le> 0 \<Longrightarrow> \<bar>- ?b\<bar> = - (- ?b)"
   7.977 +  unfolding abs_minus_cancel [of "?b"]
   7.978 +  unfolding neg_le_0_iff_le [of "?b"]
   7.979 +  unfolding minus_minus by (erule abs_of_nonneg)
   7.980 +  then show ?thesis using assms by auto
   7.981 +qed
   7.982 +  
   7.983 +lemma abs_of_neg: "a < 0 \<Longrightarrow> \<bar>a\<bar> = - a"
   7.984 +by (rule abs_of_nonpos, rule less_imp_le)
   7.985 +
   7.986 +lemma abs_le_D1: "\<bar>a\<bar> \<le> b \<Longrightarrow> a \<le> b"
   7.987 +by (insert abs_ge_self, blast intro: order_trans)
   7.988 +
   7.989 +lemma abs_le_D2: "\<bar>a\<bar> \<le> b \<Longrightarrow> - a \<le> b"
   7.990 +by (insert abs_le_D1 [of "uminus a"], simp)
   7.991 +
   7.992 +lemma abs_le_iff: "\<bar>a\<bar> \<le> b \<longleftrightarrow> a \<le> b \<and> - a \<le> b"
   7.993 +by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
   7.994 +
   7.995 +lemma abs_triangle_ineq2: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>a - b\<bar>"
   7.996 +  apply (simp add: algebra_simps)
   7.997 +  apply (subgoal_tac "abs a = abs (plus b (minus a b))")
   7.998 +  apply (erule ssubst)
   7.999 +  apply (rule abs_triangle_ineq)
  7.1000 +  apply (rule arg_cong[of _ _ abs])
  7.1001 +  apply (simp add: algebra_simps)
  7.1002 +done
  7.1003 +
  7.1004 +lemma abs_triangle_ineq3: "\<bar>\<bar>a\<bar> - \<bar>b\<bar>\<bar> \<le> \<bar>a - b\<bar>"
  7.1005 +  apply (subst abs_le_iff)
  7.1006 +  apply auto
  7.1007 +  apply (rule abs_triangle_ineq2)
  7.1008 +  apply (subst abs_minus_commute)
  7.1009 +  apply (rule abs_triangle_ineq2)
  7.1010 +done
  7.1011 +
  7.1012 +lemma abs_triangle_ineq4: "\<bar>a - b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
  7.1013 +proof -
  7.1014 +  have "abs(a - b) = abs(a + - b)" by (subst diff_minus, rule refl)
  7.1015 +  also have "... <= abs a + abs (- b)" by (rule abs_triangle_ineq)
  7.1016 +  finally show ?thesis by simp
  7.1017 +qed
  7.1018 +
  7.1019 +lemma abs_diff_triangle_ineq: "\<bar>a + b - (c + d)\<bar> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
  7.1020 +proof -
  7.1021 +  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
  7.1022 +  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
  7.1023 +  finally show ?thesis .
  7.1024 +qed
  7.1025 +
  7.1026 +lemma abs_add_abs [simp]:
  7.1027 +  "\<bar>\<bar>a\<bar> + \<bar>b\<bar>\<bar> = \<bar>a\<bar> + \<bar>b\<bar>" (is "?L = ?R")
  7.1028 +proof (rule antisym)
  7.1029 +  show "?L \<ge> ?R" by(rule abs_ge_self)
  7.1030 +next
  7.1031 +  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
  7.1032 +  also have "\<dots> = ?R" by simp
  7.1033 +  finally show "?L \<le> ?R" .
  7.1034 +qed
  7.1035 +
  7.1036 +end
  7.1037 +
  7.1038 +text {* Needed for abelian cancellation simprocs: *}
  7.1039 +
  7.1040 +lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
  7.1041 +apply (subst add_left_commute)
  7.1042 +apply (subst add_left_cancel)
  7.1043 +apply simp
  7.1044 +done
  7.1045 +
  7.1046 +lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
  7.1047 +apply (subst add_cancel_21[of _ _ _ 0, simplified])
  7.1048 +apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
  7.1049 +done
  7.1050 +
  7.1051 +lemma less_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
  7.1052 +by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
  7.1053 +
  7.1054 +lemma le_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
  7.1055 +apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
  7.1056 +apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
  7.1057 +done
  7.1058 +
  7.1059 +lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
  7.1060 +by (simp only: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
  7.1061 +
  7.1062 +lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
  7.1063 +by (simp add: diff_minus)
  7.1064 +
  7.1065 +lemma le_add_right_mono: 
  7.1066 +  assumes 
  7.1067 +  "a <= b + (c::'a::ordered_ab_group_add)"
  7.1068 +  "c <= d"    
  7.1069 +  shows "a <= b + d"
  7.1070 +  apply (rule_tac order_trans[where y = "b+c"])
  7.1071 +  apply (simp_all add: prems)
  7.1072 +  done
  7.1073 +
  7.1074 +
  7.1075 +subsection {* Tools setup *}
  7.1076 +
  7.1077 +lemma add_mono_thms_linordered_semiring [noatp]:
  7.1078 +  fixes i j k :: "'a\<Colon>ordered_ab_semigroup_add"
  7.1079 +  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
  7.1080 +    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
  7.1081 +    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
  7.1082 +    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
  7.1083 +by (rule add_mono, clarify+)+
  7.1084 +
  7.1085 +lemma add_mono_thms_linordered_field [noatp]:
  7.1086 +  fixes i j k :: "'a\<Colon>ordered_cancel_ab_semigroup_add"
  7.1087 +  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
  7.1088 +    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
  7.1089 +    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
  7.1090 +    and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
  7.1091 +    and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
  7.1092 +by (auto intro: add_strict_right_mono add_strict_left_mono
  7.1093 +  add_less_le_mono add_le_less_mono add_strict_mono)
  7.1094 +
  7.1095 +text{*Simplification of @{term "x-y < 0"}, etc.*}
  7.1096 +lemmas diff_less_0_iff_less [simp, noatp] = less_iff_diff_less_0 [symmetric]
  7.1097 +lemmas diff_le_0_iff_le [simp, noatp] = le_iff_diff_le_0 [symmetric]
  7.1098 +
  7.1099 +ML {*
  7.1100 +structure ab_group_add_cancel = Abel_Cancel
  7.1101 +(
  7.1102 +
  7.1103 +(* term order for abelian groups *)
  7.1104 +
  7.1105 +fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a')
  7.1106 +      [@{const_name Algebras.zero}, @{const_name Algebras.plus},
  7.1107 +        @{const_name Algebras.uminus}, @{const_name Algebras.minus}]
  7.1108 +  | agrp_ord _ = ~1;
  7.1109 +
  7.1110 +fun termless_agrp (a, b) = (TermOrd.term_lpo agrp_ord (a, b) = LESS);
  7.1111 +
  7.1112 +local
  7.1113 +  val ac1 = mk_meta_eq @{thm add_assoc};
  7.1114 +  val ac2 = mk_meta_eq @{thm add_commute};
  7.1115 +  val ac3 = mk_meta_eq @{thm add_left_commute};
  7.1116 +  fun solve_add_ac thy _ (_ $ (Const (@{const_name Algebras.plus},_) $ _ $ _) $ _) =
  7.1117 +        SOME ac1
  7.1118 +    | solve_add_ac thy _ (_ $ x $ (Const (@{const_name Algebras.plus},_) $ y $ z)) =
  7.1119 +        if termless_agrp (y, x) then SOME ac3 else NONE
  7.1120 +    | solve_add_ac thy _ (_ $ x $ y) =
  7.1121 +        if termless_agrp (y, x) then SOME ac2 else NONE
  7.1122 +    | solve_add_ac thy _ _ = NONE
  7.1123 +in
  7.1124 +  val add_ac_proc = Simplifier.simproc @{theory}
  7.1125 +    "add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac;
  7.1126 +end;
  7.1127 +
  7.1128 +val eq_reflection = @{thm eq_reflection};
  7.1129 +  
  7.1130 +val T = @{typ "'a::ab_group_add"};
  7.1131 +
  7.1132 +val cancel_ss = HOL_basic_ss settermless termless_agrp
  7.1133 +  addsimprocs [add_ac_proc] addsimps
  7.1134 +  [@{thm add_0_left}, @{thm add_0_right}, @{thm diff_def},
  7.1135 +   @{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero},
  7.1136 +   @{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel},
  7.1137 +   @{thm minus_add_cancel}];
  7.1138 +
  7.1139 +val sum_pats = [@{cterm "x + y::'a::ab_group_add"}, @{cterm "x - y::'a::ab_group_add"}];
  7.1140 +  
  7.1141 +val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}];
  7.1142 +
  7.1143 +val dest_eqI = 
  7.1144 +  fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of;
  7.1145 +
  7.1146 +);
  7.1147 +*}
  7.1148 +
  7.1149 +ML {*
  7.1150 +  Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv];
  7.1151 +*}
  7.1152 +
  7.1153 +code_modulename SML
  7.1154 +  Groups Arith
  7.1155 +
  7.1156 +code_modulename OCaml
  7.1157 +  Groups Arith
  7.1158 +
  7.1159 +code_modulename Haskell
  7.1160 +  Groups Arith
  7.1161 +
  7.1162 +end
     8.1 --- a/src/HOL/Import/HOL/arithmetic.imp	Mon Feb 08 17:12:32 2010 +0100
     8.2 +++ b/src/HOL/Import/HOL/arithmetic.imp	Mon Feb 08 17:12:38 2010 +0100
     8.3 @@ -162,12 +162,12 @@
     8.4    "LESS_OR" > "Nat.Suc_leI"
     8.5    "LESS_NOT_SUC" > "HOL4Base.arithmetic.LESS_NOT_SUC"
     8.6    "LESS_MULT_MONO" > "Nat.Suc_mult_less_cancel1"
     8.7 -  "LESS_MULT2" > "Ring_and_Field.mult_pos_pos"
     8.8 +  "LESS_MULT2" > "Rings.mult_pos_pos"
     8.9    "LESS_MONO_REV" > "Nat.Suc_less_SucD"
    8.10    "LESS_MONO_MULT" > "Nat.mult_le_mono1"
    8.11    "LESS_MONO_EQ" > "Nat.Suc_less_eq"
    8.12 -  "LESS_MONO_ADD_INV" > "OrderedGroup.add_less_imp_less_right"
    8.13 -  "LESS_MONO_ADD_EQ" > "OrderedGroup.add_less_cancel_right"
    8.14 +  "LESS_MONO_ADD_INV" > "Groups.add_less_imp_less_right"
    8.15 +  "LESS_MONO_ADD_EQ" > "Groups.add_less_cancel_right"
    8.16    "LESS_MONO_ADD" > "Nat.add_less_mono1"
    8.17    "LESS_MOD" > "Divides.mod_less"
    8.18    "LESS_LESS_SUC" > "HOL4Base.arithmetic.LESS_LESS_SUC"
    8.19 @@ -180,7 +180,7 @@
    8.20    "LESS_EQ_SUC_REFL" > "HOL4Base.arithmetic.LESS_EQ_SUC_REFL"
    8.21    "LESS_EQ_SUB_LESS" > "HOL4Base.arithmetic.LESS_EQ_SUB_LESS"
    8.22    "LESS_EQ_REFL" > "Finite_Set.max.f_below.below_refl"
    8.23 -  "LESS_EQ_MONO_ADD_EQ" > "OrderedGroup.add_le_cancel_right"
    8.24 +  "LESS_EQ_MONO_ADD_EQ" > "Groups.add_le_cancel_right"
    8.25    "LESS_EQ_MONO" > "Nat.Suc_le_mono"
    8.26    "LESS_EQ_LESS_TRANS" > "Nat.le_less_trans"
    8.27    "LESS_EQ_LESS_EQ_MONO" > "Nat.add_le_mono"
     9.1 --- a/src/HOL/Import/HOL/divides.imp	Mon Feb 08 17:12:32 2010 +0100
     9.2 +++ b/src/HOL/Import/HOL/divides.imp	Mon Feb 08 17:12:38 2010 +0100
     9.3 @@ -9,16 +9,16 @@
     9.4    "divides_def" > "HOL4Compat.divides_def"
     9.5    "ONE_DIVIDES_ALL" > "HOL4Base.divides.ONE_DIVIDES_ALL"
     9.6    "NOT_LT_DIV" > "NatSimprocs.nat_dvd_not_less"
     9.7 -  "DIVIDES_TRANS" > "Ring_and_Field.dvd_trans"
     9.8 -  "DIVIDES_SUB" > "Ring_and_Field.dvd_diff"
     9.9 -  "DIVIDES_REFL" > "Ring_and_Field.dvd_refl"
    9.10 +  "DIVIDES_TRANS" > "Rings.dvd_trans"
    9.11 +  "DIVIDES_SUB" > "Rings.dvd_diff"
    9.12 +  "DIVIDES_REFL" > "Rings.dvd_refl"
    9.13    "DIVIDES_MULT_LEFT" > "HOL4Base.divides.DIVIDES_MULT_LEFT"
    9.14    "DIVIDES_MULT" > "Divides.dvd_mult2"
    9.15    "DIVIDES_LE" > "Divides.dvd_imp_le"
    9.16    "DIVIDES_FACT" > "HOL4Base.divides.DIVIDES_FACT"
    9.17    "DIVIDES_ANTISYM" > "Divides.dvd_antisym"
    9.18    "DIVIDES_ADD_2" > "HOL4Base.divides.DIVIDES_ADD_2"
    9.19 -  "DIVIDES_ADD_1" > "Ring_and_Field.dvd_add"
    9.20 +  "DIVIDES_ADD_1" > "Rings.dvd_add"
    9.21    "ALL_DIVIDES_0" > "Divides.dvd_0_right"
    9.22  
    9.23  end
    10.1 --- a/src/HOL/Import/HOL/prob_extra.imp	Mon Feb 08 17:12:32 2010 +0100
    10.2 +++ b/src/HOL/Import/HOL/prob_extra.imp	Mon Feb 08 17:12:38 2010 +0100
    10.3 @@ -23,9 +23,9 @@
    10.4    "REAL_SUP_LE_X" > "HOL4Prob.prob_extra.REAL_SUP_LE_X"
    10.5    "REAL_SUP_EXISTS_UNIQUE" > "HOL4Prob.prob_extra.REAL_SUP_EXISTS_UNIQUE"
    10.6    "REAL_POW" > "RealPow.realpow_real_of_nat"
    10.7 -  "REAL_LE_INV_LE" > "Ring_and_Field.le_imp_inverse_le"
    10.8 +  "REAL_LE_INV_LE" > "Rings.le_imp_inverse_le"
    10.9    "REAL_LE_EQ" > "Set.basic_trans_rules_26"
   10.10 -  "REAL_INVINV_ALL" > "Ring_and_Field.inverse_inverse_eq"
   10.11 +  "REAL_INVINV_ALL" > "Rings.inverse_inverse_eq"
   10.12    "REAL_INF_MIN" > "HOL4Prob.prob_extra.REAL_INF_MIN"
   10.13    "RAND_THM" > "HOL.arg_cong"
   10.14    "POW_HALF_TWICE" > "HOL4Prob.prob_extra.POW_HALF_TWICE"
    11.1 --- a/src/HOL/Import/HOL/real.imp	Mon Feb 08 17:12:32 2010 +0100
    11.2 +++ b/src/HOL/Import/HOL/real.imp	Mon Feb 08 17:12:38 2010 +0100
    11.3 @@ -25,13 +25,13 @@
    11.4    "sumc" > "HOL4Real.real.sumc"
    11.5    "sum_def" > "HOL4Real.real.sum_def"
    11.6    "sum" > "HOL4Real.real.sum"
    11.7 -  "real_sub" > "OrderedGroup.diff_def"
    11.8 +  "real_sub" > "Groups.diff_def"
    11.9    "real_of_num" > "HOL4Compat.real_of_num"
   11.10    "real_lte" > "HOL4Compat.real_lte"
   11.11    "real_lt" > "Orderings.linorder_not_le"
   11.12    "real_gt" > "HOL4Compat.real_gt"
   11.13    "real_ge" > "HOL4Compat.real_ge"
   11.14 -  "real_div" > "Ring_and_Field.field_class.divide_inverse"
   11.15 +  "real_div" > "Rings.field_class.divide_inverse"
   11.16    "pow" > "HOL4Compat.pow"
   11.17    "abs" > "HOL4Compat.abs"
   11.18    "SUP_LEMMA3" > "HOL4Real.real.SUP_LEMMA3"
   11.19 @@ -74,24 +74,24 @@
   11.20    "REAL_SUB_TRIANGLE" > "HOL4Real.real.REAL_SUB_TRIANGLE"
   11.21    "REAL_SUB_SUB2" > "HOL4Real.real.REAL_SUB_SUB2"
   11.22    "REAL_SUB_SUB" > "HOL4Real.real.REAL_SUB_SUB"
   11.23 -  "REAL_SUB_RZERO" > "OrderedGroup.diff_0_right"
   11.24 -  "REAL_SUB_RNEG" > "OrderedGroup.diff_minus_eq_add"
   11.25 -  "REAL_SUB_REFL" > "OrderedGroup.diff_self"
   11.26 -  "REAL_SUB_RDISTRIB" > "Ring_and_Field.ring_eq_simps_3"
   11.27 +  "REAL_SUB_RZERO" > "Groups.diff_0_right"
   11.28 +  "REAL_SUB_RNEG" > "Groups.diff_minus_eq_add"
   11.29 +  "REAL_SUB_REFL" > "Groups.diff_self"
   11.30 +  "REAL_SUB_RDISTRIB" > "Rings.ring_eq_simps_3"
   11.31    "REAL_SUB_NEG2" > "HOL4Real.real.REAL_SUB_NEG2"
   11.32 -  "REAL_SUB_LZERO" > "OrderedGroup.diff_0"
   11.33 +  "REAL_SUB_LZERO" > "Groups.diff_0"
   11.34    "REAL_SUB_LT" > "HOL4Real.real.REAL_SUB_LT"
   11.35    "REAL_SUB_LNEG" > "HOL4Real.real.REAL_SUB_LNEG"
   11.36    "REAL_SUB_LE" > "HOL4Real.real.REAL_SUB_LE"
   11.37 -  "REAL_SUB_LDISTRIB" > "Ring_and_Field.ring_eq_simps_4"
   11.38 +  "REAL_SUB_LDISTRIB" > "Rings.ring_eq_simps_4"
   11.39    "REAL_SUB_INV2" > "HOL4Real.real.REAL_SUB_INV2"
   11.40    "REAL_SUB_ADD2" > "HOL4Real.real.REAL_SUB_ADD2"
   11.41 -  "REAL_SUB_ADD" > "OrderedGroup.diff_add_cancel"
   11.42 -  "REAL_SUB_ABS" > "OrderedGroup.abs_triangle_ineq2"
   11.43 -  "REAL_SUB_0" > "OrderedGroup.diff_eq_0_iff_eq"
   11.44 +  "REAL_SUB_ADD" > "Groups.diff_add_cancel"
   11.45 +  "REAL_SUB_ABS" > "Groups.abs_triangle_ineq2"
   11.46 +  "REAL_SUB_0" > "Groups.diff_eq_0_iff_eq"
   11.47    "REAL_RNEG_UNIQ" > "RealDef.real_add_eq_0_iff"
   11.48 -  "REAL_RINV_UNIQ" > "Ring_and_Field.inverse_unique"
   11.49 -  "REAL_RDISTRIB" > "Ring_and_Field.ring_eq_simps_1"
   11.50 +  "REAL_RINV_UNIQ" > "Rings.inverse_unique"
   11.51 +  "REAL_RDISTRIB" > "Rings.ring_eq_simps_1"
   11.52    "REAL_POW_POW" > "Power.power_mult"
   11.53    "REAL_POW_MONO_LT" > "HOL4Real.real.REAL_POW_MONO_LT"
   11.54    "REAL_POW_LT2" > "HOL4Real.real.REAL_POW_LT2"
   11.55 @@ -103,7 +103,7 @@
   11.56    "REAL_POS_NZ" > "HOL4Real.real.REAL_POS_NZ"
   11.57    "REAL_POS" > "RealDef.real_of_nat_ge_zero"
   11.58    "REAL_POASQ" > "HOL4Real.real.REAL_POASQ"
   11.59 -  "REAL_OVER1" > "Ring_and_Field.divide_1"
   11.60 +  "REAL_OVER1" > "Rings.divide_1"
   11.61    "REAL_OF_NUM_SUC" > "RealDef.real_of_nat_Suc"
   11.62    "REAL_OF_NUM_POW" > "RealPow.realpow_real_of_nat"
   11.63    "REAL_OF_NUM_MUL" > "RealDef.real_of_nat_mult"
   11.64 @@ -113,172 +113,172 @@
   11.65    "REAL_NZ_IMP_LT" > "HOL4Real.real.REAL_NZ_IMP_LT"
   11.66    "REAL_NOT_LT" > "HOL4Compat.real_lte"
   11.67    "REAL_NOT_LE" > "Orderings.linorder_not_le"
   11.68 -  "REAL_NEG_SUB" > "OrderedGroup.minus_diff_eq"
   11.69 -  "REAL_NEG_RMUL" > "Ring_and_Field.mult_minus_right"
   11.70 -  "REAL_NEG_NEG" > "OrderedGroup.minus_minus"
   11.71 -  "REAL_NEG_MUL2" > "Ring_and_Field.minus_mult_minus"
   11.72 +  "REAL_NEG_SUB" > "Groups.minus_diff_eq"
   11.73 +  "REAL_NEG_RMUL" > "Rings.mult_minus_right"
   11.74 +  "REAL_NEG_NEG" > "Groups.minus_minus"
   11.75 +  "REAL_NEG_MUL2" > "Rings.minus_mult_minus"
   11.76    "REAL_NEG_MINUS1" > "HOL4Real.real.REAL_NEG_MINUS1"
   11.77 -  "REAL_NEG_LT0" > "OrderedGroup.neg_less_0_iff_less"
   11.78 -  "REAL_NEG_LMUL" > "Ring_and_Field.mult_minus_left"
   11.79 -  "REAL_NEG_LE0" > "OrderedGroup.neg_le_0_iff_le"
   11.80 -  "REAL_NEG_INV" > "Ring_and_Field.nonzero_inverse_minus_eq"
   11.81 -  "REAL_NEG_GT0" > "OrderedGroup.neg_0_less_iff_less"
   11.82 -  "REAL_NEG_GE0" > "OrderedGroup.neg_0_le_iff_le"
   11.83 -  "REAL_NEG_EQ0" > "OrderedGroup.neg_equal_0_iff_equal"
   11.84 +  "REAL_NEG_LT0" > "Groups.neg_less_0_iff_less"
   11.85 +  "REAL_NEG_LMUL" > "Rings.mult_minus_left"
   11.86 +  "REAL_NEG_LE0" > "Groups.neg_le_0_iff_le"
   11.87 +  "REAL_NEG_INV" > "Rings.nonzero_inverse_minus_eq"
   11.88 +  "REAL_NEG_GT0" > "Groups.neg_0_less_iff_less"
   11.89 +  "REAL_NEG_GE0" > "Groups.neg_0_le_iff_le"
   11.90 +  "REAL_NEG_EQ0" > "Groups.neg_equal_0_iff_equal"
   11.91    "REAL_NEG_EQ" > "HOL4Real.real.REAL_NEG_EQ"
   11.92 -  "REAL_NEG_ADD" > "OrderedGroup.minus_add_distrib"
   11.93 -  "REAL_NEG_0" > "OrderedGroup.minus_zero"
   11.94 -  "REAL_NEGNEG" > "OrderedGroup.minus_minus"
   11.95 +  "REAL_NEG_ADD" > "Groups.minus_add_distrib"
   11.96 +  "REAL_NEG_0" > "Groups.minus_zero"
   11.97 +  "REAL_NEGNEG" > "Groups.minus_minus"
   11.98    "REAL_MUL_SYM" > "Int.zmult_ac_2"
   11.99 -  "REAL_MUL_RZERO" > "Ring_and_Field.mult_zero_right"
  11.100 -  "REAL_MUL_RNEG" > "Ring_and_Field.mult_minus_right"
  11.101 -  "REAL_MUL_RINV" > "Ring_and_Field.right_inverse"
  11.102 +  "REAL_MUL_RZERO" > "Rings.mult_zero_right"
  11.103 +  "REAL_MUL_RNEG" > "Rings.mult_minus_right"
  11.104 +  "REAL_MUL_RINV" > "Rings.right_inverse"
  11.105    "REAL_MUL_RID" > "Finite_Set.AC_mult.f_e.ident"
  11.106 -  "REAL_MUL_LZERO" > "Ring_and_Field.mult_zero_left"
  11.107 -  "REAL_MUL_LNEG" > "Ring_and_Field.mult_minus_left"
  11.108 +  "REAL_MUL_LZERO" > "Rings.mult_zero_left"
  11.109 +  "REAL_MUL_LNEG" > "Rings.mult_minus_left"
  11.110    "REAL_MUL_LINV" > "HOL4Compat.REAL_MUL_LINV"
  11.111    "REAL_MUL_LID" > "Finite_Set.AC_mult.f_e.left_ident"
  11.112    "REAL_MUL_ASSOC" > "HOL4Compat.REAL_MUL_ASSOC"
  11.113    "REAL_MUL" > "RealDef.real_of_nat_mult"
  11.114    "REAL_MIDDLE2" > "HOL4Real.real.REAL_MIDDLE2"
  11.115    "REAL_MIDDLE1" > "HOL4Real.real.REAL_MIDDLE1"
  11.116 -  "REAL_MEAN" > "Ring_and_Field.dense"
  11.117 +  "REAL_MEAN" > "Rings.dense"
  11.118    "REAL_LT_TRANS" > "Set.basic_trans_rules_21"
  11.119    "REAL_LT_TOTAL" > "HOL4Compat.REAL_LT_TOTAL"
  11.120 -  "REAL_LT_SUB_RADD" > "OrderedGroup.compare_rls_6"
  11.121 -  "REAL_LT_SUB_LADD" > "OrderedGroup.compare_rls_7"
  11.122 -  "REAL_LT_RMUL_IMP" > "Ring_and_Field.mult_strict_right_mono"
  11.123 +  "REAL_LT_SUB_RADD" > "Groups.compare_rls_6"
  11.124 +  "REAL_LT_SUB_LADD" > "Groups.compare_rls_7"
  11.125 +  "REAL_LT_RMUL_IMP" > "Rings.mult_strict_right_mono"
  11.126    "REAL_LT_RMUL_0" > "HOL4Real.real.REAL_LT_RMUL_0"
  11.127    "REAL_LT_RMUL" > "RealDef.real_mult_less_iff1"
  11.128    "REAL_LT_REFL" > "Orderings.order_less_irrefl"
  11.129 -  "REAL_LT_RDIV_EQ" > "Ring_and_Field.pos_less_divide_eq"
  11.130 +  "REAL_LT_RDIV_EQ" > "Rings.pos_less_divide_eq"
  11.131    "REAL_LT_RDIV_0" > "HOL4Real.real.REAL_LT_RDIV_0"
  11.132    "REAL_LT_RDIV" > "HOL4Real.real.REAL_LT_RDIV"
  11.133 -  "REAL_LT_RADD" > "OrderedGroup.add_less_cancel_right"
  11.134 +  "REAL_LT_RADD" > "Groups.add_less_cancel_right"
  11.135    "REAL_LT_NZ" > "HOL4Real.real.REAL_LT_NZ"
  11.136    "REAL_LT_NEGTOTAL" > "HOL4Real.real.REAL_LT_NEGTOTAL"
  11.137 -  "REAL_LT_NEG" > "OrderedGroup.neg_less_iff_less"
  11.138 +  "REAL_LT_NEG" > "Groups.neg_less_iff_less"
  11.139    "REAL_LT_MULTIPLE" > "HOL4Real.real.REAL_LT_MULTIPLE"
  11.140 -  "REAL_LT_MUL2" > "Ring_and_Field.mult_strict_mono'"
  11.141 -  "REAL_LT_MUL" > "Ring_and_Field.mult_pos_pos"
  11.142 -  "REAL_LT_LMUL_IMP" > "Ring_and_Field.linordered_comm_semiring_strict_class.mult_strict_mono"
  11.143 +  "REAL_LT_MUL2" > "Rings.mult_strict_mono'"
  11.144 +  "REAL_LT_MUL" > "Rings.mult_pos_pos"
  11.145 +  "REAL_LT_LMUL_IMP" > "Rings.linordered_comm_semiring_strict_class.mult_strict_mono"
  11.146    "REAL_LT_LMUL_0" > "HOL4Real.real.REAL_LT_LMUL_0"
  11.147    "REAL_LT_LMUL" > "HOL4Real.real.REAL_LT_LMUL"
  11.148    "REAL_LT_LE" > "Orderings.order_class.order_less_le"
  11.149 -  "REAL_LT_LDIV_EQ" > "Ring_and_Field.pos_divide_less_eq"
  11.150 -  "REAL_LT_LADD" > "OrderedGroup.add_less_cancel_left"
  11.151 -  "REAL_LT_INV_EQ" > "Ring_and_Field.inverse_positive_iff_positive"
  11.152 -  "REAL_LT_INV" > "Ring_and_Field.less_imp_inverse_less"
  11.153 +  "REAL_LT_LDIV_EQ" > "Rings.pos_divide_less_eq"
  11.154 +  "REAL_LT_LADD" > "Groups.add_less_cancel_left"
  11.155 +  "REAL_LT_INV_EQ" > "Rings.inverse_positive_iff_positive"
  11.156 +  "REAL_LT_INV" > "Rings.less_imp_inverse_less"
  11.157    "REAL_LT_IMP_NE" > "Orderings.less_imp_neq"
  11.158    "REAL_LT_IMP_LE" > "Orderings.order_less_imp_le"
  11.159 -  "REAL_LT_IADD" > "OrderedGroup.add_strict_left_mono"
  11.160 +  "REAL_LT_IADD" > "Groups.add_strict_left_mono"
  11.161    "REAL_LT_HALF2" > "HOL4Real.real.REAL_LT_HALF2"
  11.162    "REAL_LT_HALF1" > "NatSimprocs.half_gt_zero_iff"
  11.163    "REAL_LT_GT" > "Orderings.order_less_not_sym"
  11.164    "REAL_LT_FRACTION_0" > "HOL4Real.real.REAL_LT_FRACTION_0"
  11.165    "REAL_LT_FRACTION" > "HOL4Real.real.REAL_LT_FRACTION"
  11.166 -  "REAL_LT_DIV" > "Ring_and_Field.divide_pos_pos"
  11.167 +  "REAL_LT_DIV" > "Rings.divide_pos_pos"
  11.168    "REAL_LT_ANTISYM" > "HOL4Real.real.REAL_LT_ANTISYM"
  11.169 -  "REAL_LT_ADD_SUB" > "OrderedGroup.compare_rls_7"
  11.170 +  "REAL_LT_ADD_SUB" > "Groups.compare_rls_7"
  11.171    "REAL_LT_ADDR" > "HOL4Real.real.REAL_LT_ADDR"
  11.172    "REAL_LT_ADDNEG2" > "HOL4Real.real.REAL_LT_ADDNEG2"
  11.173    "REAL_LT_ADDNEG" > "HOL4Real.real.REAL_LT_ADDNEG"
  11.174    "REAL_LT_ADDL" > "HOL4Real.real.REAL_LT_ADDL"
  11.175 -  "REAL_LT_ADD2" > "OrderedGroup.add_strict_mono"
  11.176 +  "REAL_LT_ADD2" > "Groups.add_strict_mono"
  11.177    "REAL_LT_ADD1" > "HOL4Real.real.REAL_LT_ADD1"
  11.178 -  "REAL_LT_ADD" > "OrderedGroup.add_pos_pos"
  11.179 +  "REAL_LT_ADD" > "Groups.add_pos_pos"
  11.180    "REAL_LT_1" > "HOL4Real.real.REAL_LT_1"
  11.181 -  "REAL_LT_01" > "Ring_and_Field.zero_less_one"
  11.182 +  "REAL_LT_01" > "Rings.zero_less_one"
  11.183    "REAL_LTE_TRANS" > "Set.basic_trans_rules_24"
  11.184    "REAL_LTE_TOTAL" > "HOL4Real.real.REAL_LTE_TOTAL"
  11.185    "REAL_LTE_ANTSYM" > "HOL4Real.real.REAL_LTE_ANTSYM"
  11.186 -  "REAL_LTE_ADD2" > "OrderedGroup.add_less_le_mono"
  11.187 -  "REAL_LTE_ADD" > "OrderedGroup.add_pos_nonneg"
  11.188 +  "REAL_LTE_ADD2" > "Groups.add_less_le_mono"
  11.189 +  "REAL_LTE_ADD" > "Groups.add_pos_nonneg"
  11.190    "REAL_LT1_POW2" > "HOL4Real.real.REAL_LT1_POW2"
  11.191    "REAL_LT" > "RealDef.real_of_nat_less_iff"
  11.192    "REAL_LNEG_UNIQ" > "HOL4Real.real.REAL_LNEG_UNIQ"
  11.193    "REAL_LINV_UNIQ" > "HOL4Real.real.REAL_LINV_UNIQ"
  11.194    "REAL_LE_TRANS" > "Set.basic_trans_rules_25"
  11.195    "REAL_LE_TOTAL" > "Orderings.linorder_class.linorder_linear"
  11.196 -  "REAL_LE_SUB_RADD" > "OrderedGroup.compare_rls_8"
  11.197 -  "REAL_LE_SUB_LADD" > "OrderedGroup.compare_rls_9"
  11.198 -  "REAL_LE_SQUARE" > "Ring_and_Field.zero_le_square"
  11.199 -  "REAL_LE_RNEG" > "OrderedGroup.le_eq_neg"
  11.200 -  "REAL_LE_RMUL_IMP" > "Ring_and_Field.mult_right_mono"
  11.201 +  "REAL_LE_SUB_RADD" > "Groups.compare_rls_8"
  11.202 +  "REAL_LE_SUB_LADD" > "Groups.compare_rls_9"
  11.203 +  "REAL_LE_SQUARE" > "Rings.zero_le_square"
  11.204 +  "REAL_LE_RNEG" > "Groups.le_eq_neg"
  11.205 +  "REAL_LE_RMUL_IMP" > "Rings.mult_right_mono"
  11.206    "REAL_LE_RMUL" > "RealDef.real_mult_le_cancel_iff1"
  11.207    "REAL_LE_REFL" > "Finite_Set.max.f_below.below_refl"
  11.208 -  "REAL_LE_RDIV_EQ" > "Ring_and_Field.pos_le_divide_eq"
  11.209 -  "REAL_LE_RDIV" > "Ring_and_Field.mult_imp_le_div_pos"
  11.210 -  "REAL_LE_RADD" > "OrderedGroup.add_le_cancel_right"
  11.211 +  "REAL_LE_RDIV_EQ" > "Rings.pos_le_divide_eq"
  11.212 +  "REAL_LE_RDIV" > "Rings.mult_imp_le_div_pos"
  11.213 +  "REAL_LE_RADD" > "Groups.add_le_cancel_right"
  11.214    "REAL_LE_POW2" > "Nat_Numeral.zero_compare_simps_12"
  11.215    "REAL_LE_NEGTOTAL" > "HOL4Real.real.REAL_LE_NEGTOTAL"
  11.216 -  "REAL_LE_NEGR" > "OrderedGroup.le_minus_self_iff"
  11.217 -  "REAL_LE_NEGL" > "OrderedGroup.minus_le_self_iff"
  11.218 -  "REAL_LE_NEG2" > "OrderedGroup.neg_le_iff_le"
  11.219 -  "REAL_LE_NEG" > "OrderedGroup.neg_le_iff_le"
  11.220 +  "REAL_LE_NEGR" > "Groups.le_minus_self_iff"
  11.221 +  "REAL_LE_NEGL" > "Groups.minus_le_self_iff"
  11.222 +  "REAL_LE_NEG2" > "Groups.neg_le_iff_le"
  11.223 +  "REAL_LE_NEG" > "Groups.neg_le_iff_le"
  11.224    "REAL_LE_MUL2" > "HOL4Real.real.REAL_LE_MUL2"
  11.225 -  "REAL_LE_MUL" > "Ring_and_Field.mult_nonneg_nonneg"
  11.226 +  "REAL_LE_MUL" > "Rings.mult_nonneg_nonneg"
  11.227    "REAL_LE_LT" > "Orderings.order_le_less"
  11.228    "REAL_LE_LNEG" > "RealDef.real_0_le_add_iff"
  11.229 -  "REAL_LE_LMUL_IMP" > "Ring_and_Field.mult_mono"
  11.230 +  "REAL_LE_LMUL_IMP" > "Rings.mult_mono"
  11.231    "REAL_LE_LMUL" > "RealDef.real_mult_le_cancel_iff2"
  11.232 -  "REAL_LE_LDIV_EQ" > "Ring_and_Field.pos_divide_le_eq"
  11.233 -  "REAL_LE_LDIV" > "Ring_and_Field.mult_imp_div_pos_le"
  11.234 -  "REAL_LE_LADD_IMP" > "OrderedGroup.add_left_mono"
  11.235 -  "REAL_LE_LADD" > "OrderedGroup.add_le_cancel_left"
  11.236 -  "REAL_LE_INV_EQ" > "Ring_and_Field.inverse_nonnegative_iff_nonnegative"
  11.237 +  "REAL_LE_LDIV_EQ" > "Rings.pos_divide_le_eq"
  11.238 +  "REAL_LE_LDIV" > "Rings.mult_imp_div_pos_le"
  11.239 +  "REAL_LE_LADD_IMP" > "Groups.add_left_mono"
  11.240 +  "REAL_LE_LADD" > "Groups.add_le_cancel_left"
  11.241 +  "REAL_LE_INV_EQ" > "Rings.inverse_nonnegative_iff_nonnegative"
  11.242    "REAL_LE_INV" > "HOL4Real.real.REAL_LE_INV"
  11.243 -  "REAL_LE_DOUBLE" > "OrderedGroup.zero_le_double_add_iff_zero_le_single_add"
  11.244 +  "REAL_LE_DOUBLE" > "Groups.zero_le_double_add_iff_zero_le_single_add"
  11.245    "REAL_LE_DIV" > "HOL4Real.real.REAL_LE_DIV"
  11.246    "REAL_LE_ANTISYM" > "Orderings.order_eq_iff"
  11.247    "REAL_LE_ADDR" > "HOL4Real.real.REAL_LE_ADDR"
  11.248    "REAL_LE_ADDL" > "HOL4Real.real.REAL_LE_ADDL"
  11.249 -  "REAL_LE_ADD2" > "OrderedGroup.add_mono"
  11.250 -  "REAL_LE_ADD" > "OrderedGroup.add_nonneg_nonneg"
  11.251 -  "REAL_LE_01" > "Ring_and_Field.zero_le_one"
  11.252 +  "REAL_LE_ADD2" > "Groups.add_mono"
  11.253 +  "REAL_LE_ADD" > "Groups.add_nonneg_nonneg"
  11.254 +  "REAL_LE_01" > "Rings.zero_le_one"
  11.255    "REAL_LET_TRANS" > "Set.basic_trans_rules_23"
  11.256    "REAL_LET_TOTAL" > "Orderings.linorder_le_less_linear"
  11.257    "REAL_LET_ANTISYM" > "HOL4Real.real.REAL_LET_ANTISYM"
  11.258 -  "REAL_LET_ADD2" > "OrderedGroup.add_le_less_mono"
  11.259 -  "REAL_LET_ADD" > "OrderedGroup.add_nonneg_pos"
  11.260 +  "REAL_LET_ADD2" > "Groups.add_le_less_mono"
  11.261 +  "REAL_LET_ADD" > "Groups.add_nonneg_pos"
  11.262    "REAL_LE1_POW2" > "HOL4Real.real.REAL_LE1_POW2"
  11.263    "REAL_LE" > "RealDef.real_of_nat_le_iff"
  11.264 -  "REAL_LDISTRIB" > "Ring_and_Field.ring_eq_simps_2"
  11.265 -  "REAL_INV_POS" > "Ring_and_Field.positive_imp_inverse_positive"
  11.266 -  "REAL_INV_NZ" > "Ring_and_Field.nonzero_imp_inverse_nonzero"
  11.267 +  "REAL_LDISTRIB" > "Rings.ring_eq_simps_2"
  11.268 +  "REAL_INV_POS" > "Rings.positive_imp_inverse_positive"
  11.269 +  "REAL_INV_NZ" > "Rings.nonzero_imp_inverse_nonzero"
  11.270    "REAL_INV_MUL" > "HOL4Real.real.REAL_INV_MUL"
  11.271    "REAL_INV_LT1" > "RealDef.real_inverse_gt_one"
  11.272 -  "REAL_INV_INV" > "Ring_and_Field.inverse_inverse_eq"
  11.273 -  "REAL_INV_EQ_0" > "Ring_and_Field.inverse_nonzero_iff_nonzero"
  11.274 -  "REAL_INV_1OVER" > "Ring_and_Field.inverse_eq_divide"
  11.275 -  "REAL_INV_0" > "Ring_and_Field.division_by_zero_class.inverse_zero"
  11.276 -  "REAL_INVINV" > "Ring_and_Field.nonzero_inverse_inverse_eq"
  11.277 -  "REAL_INV1" > "Ring_and_Field.inverse_1"
  11.278 +  "REAL_INV_INV" > "Rings.inverse_inverse_eq"
  11.279 +  "REAL_INV_EQ_0" > "Rings.inverse_nonzero_iff_nonzero"
  11.280 +  "REAL_INV_1OVER" > "Rings.inverse_eq_divide"
  11.281 +  "REAL_INV_0" > "Rings.division_by_zero_class.inverse_zero"
  11.282 +  "REAL_INVINV" > "Rings.nonzero_inverse_inverse_eq"
  11.283 +  "REAL_INV1" > "Rings.inverse_1"
  11.284    "REAL_INJ" > "RealDef.real_of_nat_inject"
  11.285    "REAL_HALF_DOUBLE" > "RComplete.real_sum_of_halves"
  11.286    "REAL_FACT_NZ" > "HOL4Real.real.REAL_FACT_NZ"
  11.287 -  "REAL_EQ_SUB_RADD" > "Ring_and_Field.ring_eq_simps_15"
  11.288 -  "REAL_EQ_SUB_LADD" > "Ring_and_Field.ring_eq_simps_16"
  11.289 -  "REAL_EQ_RMUL_IMP" > "Ring_and_Field.field_mult_cancel_right_lemma"
  11.290 -  "REAL_EQ_RMUL" > "Ring_and_Field.field_mult_cancel_right"
  11.291 +  "REAL_EQ_SUB_RADD" > "Rings.ring_eq_simps_15"
  11.292 +  "REAL_EQ_SUB_LADD" > "Rings.ring_eq_simps_16"
  11.293 +  "REAL_EQ_RMUL_IMP" > "Rings.field_mult_cancel_right_lemma"
  11.294 +  "REAL_EQ_RMUL" > "Rings.field_mult_cancel_right"
  11.295    "REAL_EQ_RDIV_EQ" > "HOL4Real.real.REAL_EQ_RDIV_EQ"
  11.296 -  "REAL_EQ_RADD" > "OrderedGroup.add_right_cancel"
  11.297 -  "REAL_EQ_NEG" > "OrderedGroup.neg_equal_iff_equal"
  11.298 -  "REAL_EQ_MUL_LCANCEL" > "Ring_and_Field.field_mult_cancel_left"
  11.299 +  "REAL_EQ_RADD" > "Groups.add_right_cancel"
  11.300 +  "REAL_EQ_NEG" > "Groups.neg_equal_iff_equal"
  11.301 +  "REAL_EQ_MUL_LCANCEL" > "Rings.field_mult_cancel_left"
  11.302    "REAL_EQ_LMUL_IMP" > "HOL4Real.real.REAL_EQ_LMUL_IMP"
  11.303    "REAL_EQ_LMUL2" > "RealDef.real_mult_left_cancel"
  11.304 -  "REAL_EQ_LMUL" > "Ring_and_Field.field_mult_cancel_left"
  11.305 +  "REAL_EQ_LMUL" > "Rings.field_mult_cancel_left"
  11.306    "REAL_EQ_LDIV_EQ" > "HOL4Real.real.REAL_EQ_LDIV_EQ"
  11.307 -  "REAL_EQ_LADD" > "OrderedGroup.add_left_cancel"
  11.308 +  "REAL_EQ_LADD" > "Groups.add_left_cancel"
  11.309    "REAL_EQ_IMP_LE" > "Orderings.order_eq_refl"
  11.310 -  "REAL_ENTIRE" > "Ring_and_Field.field_mult_eq_0_iff"
  11.311 +  "REAL_ENTIRE" > "Rings.field_mult_eq_0_iff"
  11.312    "REAL_DOWN2" > "RealDef.real_lbound_gt_zero"
  11.313    "REAL_DOWN" > "HOL4Real.real.REAL_DOWN"
  11.314    "REAL_DOUBLE" > "Int.mult_2"
  11.315    "REAL_DIV_RMUL" > "HOL4Real.real.REAL_DIV_RMUL"
  11.316 -  "REAL_DIV_REFL" > "Ring_and_Field.divide_self"
  11.317 +  "REAL_DIV_REFL" > "Rings.divide_self"
  11.318    "REAL_DIV_MUL2" > "HOL4Real.real.REAL_DIV_MUL2"
  11.319 -  "REAL_DIV_LZERO" > "Ring_and_Field.divide_zero_left"
  11.320 +  "REAL_DIV_LZERO" > "Rings.divide_zero_left"
  11.321    "REAL_DIV_LMUL" > "HOL4Real.real.REAL_DIV_LMUL"
  11.322    "REAL_DIFFSQ" > "HOL4Real.real.REAL_DIFFSQ"
  11.323    "REAL_ARCH_LEAST" > "HOL4Real.real.REAL_ARCH_LEAST"
  11.324 @@ -286,20 +286,20 @@
  11.325    "REAL_ADD_SYM" > "Finite_Set.AC_add.f.AC_2"
  11.326    "REAL_ADD_SUB2" > "HOL4Real.real.REAL_ADD_SUB2"
  11.327    "REAL_ADD_SUB" > "HOL4Real.real.REAL_ADD_SUB"
  11.328 -  "REAL_ADD_RINV" > "OrderedGroup.right_minus"
  11.329 +  "REAL_ADD_RINV" > "Groups.right_minus"
  11.330    "REAL_ADD_RID_UNIQ" > "HOL4Real.real.REAL_ADD_RID_UNIQ"
  11.331    "REAL_ADD_RID" > "Finite_Set.AC_add.f_e.ident"
  11.332 -  "REAL_ADD_RDISTRIB" > "Ring_and_Field.ring_eq_simps_1"
  11.333 +  "REAL_ADD_RDISTRIB" > "Rings.ring_eq_simps_1"
  11.334    "REAL_ADD_LINV" > "HOL4Compat.REAL_ADD_LINV"
  11.335    "REAL_ADD_LID_UNIQ" > "HOL4Real.real.REAL_ADD_LID_UNIQ"
  11.336    "REAL_ADD_LID" > "Finite_Set.AC_add.f_e.left_ident"
  11.337 -  "REAL_ADD_LDISTRIB" > "Ring_and_Field.ring_eq_simps_2"
  11.338 +  "REAL_ADD_LDISTRIB" > "Rings.ring_eq_simps_2"
  11.339    "REAL_ADD_ASSOC" > "HOL4Compat.REAL_ADD_ASSOC"
  11.340    "REAL_ADD2_SUB2" > "HOL4Real.real.REAL_ADD2_SUB2"
  11.341    "REAL_ADD" > "RealDef.real_of_nat_add"
  11.342 -  "REAL_ABS_TRIANGLE" > "OrderedGroup.abs_triangle_ineq"
  11.343 -  "REAL_ABS_POS" > "OrderedGroup.abs_ge_zero"
  11.344 -  "REAL_ABS_MUL" > "Ring_and_Field.abs_mult"
  11.345 +  "REAL_ABS_TRIANGLE" > "Groups.abs_triangle_ineq"
  11.346 +  "REAL_ABS_POS" > "Groups.abs_ge_zero"
  11.347 +  "REAL_ABS_MUL" > "Rings.abs_mult"
  11.348    "REAL_ABS_0" > "Int.bin_arith_simps_28"
  11.349    "REAL_10" > "HOL4Compat.REAL_10"
  11.350    "REAL_1" > "HOL4Real.real.REAL_1"
  11.351 @@ -326,25 +326,25 @@
  11.352    "POW_2" > "Nat_Numeral.power2_eq_square"
  11.353    "POW_1" > "Power.power_one_right"
  11.354    "POW_0" > "Power.power_0_Suc"
  11.355 -  "ABS_ZERO" > "OrderedGroup.abs_eq_0"
  11.356 -  "ABS_TRIANGLE" > "OrderedGroup.abs_triangle_ineq"
  11.357 +  "ABS_ZERO" > "Groups.abs_eq_0"
  11.358 +  "ABS_TRIANGLE" > "Groups.abs_triangle_ineq"
  11.359    "ABS_SUM" > "HOL4Real.real.ABS_SUM"
  11.360 -  "ABS_SUB_ABS" > "OrderedGroup.abs_triangle_ineq3"
  11.361 -  "ABS_SUB" > "OrderedGroup.abs_minus_commute"
  11.362 +  "ABS_SUB_ABS" > "Groups.abs_triangle_ineq3"
  11.363 +  "ABS_SUB" > "Groups.abs_minus_commute"
  11.364    "ABS_STILLNZ" > "HOL4Real.real.ABS_STILLNZ"
  11.365    "ABS_SIGN2" > "HOL4Real.real.ABS_SIGN2"
  11.366    "ABS_SIGN" > "HOL4Real.real.ABS_SIGN"
  11.367    "ABS_REFL" > "HOL4Real.real.ABS_REFL"
  11.368    "ABS_POW2" > "Nat_Numeral.abs_power2"
  11.369 -  "ABS_POS" > "OrderedGroup.abs_ge_zero"
  11.370 -  "ABS_NZ" > "OrderedGroup.zero_less_abs_iff"
  11.371 -  "ABS_NEG" > "OrderedGroup.abs_minus_cancel"
  11.372 +  "ABS_POS" > "Groups.abs_ge_zero"
  11.373 +  "ABS_NZ" > "Groups.zero_less_abs_iff"
  11.374 +  "ABS_NEG" > "Groups.abs_minus_cancel"
  11.375    "ABS_N" > "RealDef.abs_real_of_nat_cancel"
  11.376 -  "ABS_MUL" > "Ring_and_Field.abs_mult"
  11.377 +  "ABS_MUL" > "Rings.abs_mult"
  11.378    "ABS_LT_MUL2" > "HOL4Real.real.ABS_LT_MUL2"
  11.379 -  "ABS_LE" > "OrderedGroup.abs_ge_self"
  11.380 -  "ABS_INV" > "Ring_and_Field.nonzero_abs_inverse"
  11.381 -  "ABS_DIV" > "Ring_and_Field.nonzero_abs_divide"
  11.382 +  "ABS_LE" > "Groups.abs_ge_self"
  11.383 +  "ABS_INV" > "Rings.nonzero_abs_inverse"
  11.384 +  "ABS_DIV" > "Rings.nonzero_abs_divide"
  11.385    "ABS_CIRCLE" > "HOL4Real.real.ABS_CIRCLE"
  11.386    "ABS_CASES" > "HOL4Real.real.ABS_CASES"
  11.387    "ABS_BOUNDS" > "RealDef.abs_le_interval_iff"
  11.388 @@ -352,7 +352,7 @@
  11.389    "ABS_BETWEEN2" > "HOL4Real.real.ABS_BETWEEN2"
  11.390    "ABS_BETWEEN1" > "HOL4Real.real.ABS_BETWEEN1"
  11.391    "ABS_BETWEEN" > "HOL4Real.real.ABS_BETWEEN"
  11.392 -  "ABS_ABS" > "OrderedGroup.abs_idempotent"
  11.393 +  "ABS_ABS" > "Groups.abs_idempotent"
  11.394    "ABS_1" > "Int.bin_arith_simps_29"
  11.395    "ABS_0" > "Int.bin_arith_simps_28"
  11.396  
    12.1 --- a/src/HOL/Import/HOL/realax.imp	Mon Feb 08 17:12:32 2010 +0100
    12.2 +++ b/src/HOL/Import/HOL/realax.imp	Mon Feb 08 17:12:38 2010 +0100
    12.3 @@ -98,10 +98,10 @@
    12.4    "REAL_LT_TRANS" > "Set.basic_trans_rules_21"
    12.5    "REAL_LT_TOTAL" > "HOL4Compat.REAL_LT_TOTAL"
    12.6    "REAL_LT_REFL" > "Orderings.order_less_irrefl"
    12.7 -  "REAL_LT_MUL" > "Ring_and_Field.mult_pos_pos"
    12.8 -  "REAL_LT_IADD" > "OrderedGroup.add_strict_left_mono"
    12.9 -  "REAL_LDISTRIB" > "Ring_and_Field.ring_eq_simps_2"
   12.10 -  "REAL_INV_0" > "Ring_and_Field.division_by_zero_class.inverse_zero"
   12.11 +  "REAL_LT_MUL" > "Rings.mult_pos_pos"
   12.12 +  "REAL_LT_IADD" > "Groups.add_strict_left_mono"
   12.13 +  "REAL_LDISTRIB" > "Rings.ring_eq_simps_2"
   12.14 +  "REAL_INV_0" > "Rings.division_by_zero_class.inverse_zero"
   12.15    "REAL_ADD_SYM" > "Finite_Set.AC_add.f.AC_2"
   12.16    "REAL_ADD_LINV" > "HOL4Compat.REAL_ADD_LINV"
   12.17    "REAL_ADD_LID" > "Finite_Set.AC_add.f_e.left_ident"
    13.1 --- a/src/HOL/Int.thy	Mon Feb 08 17:12:32 2010 +0100
    13.2 +++ b/src/HOL/Int.thy	Mon Feb 08 17:12:38 2010 +0100
    13.3 @@ -307,7 +307,7 @@
    13.4  by (cases z, simp add: algebra_simps of_int minus)
    13.5  
    13.6  lemma of_int_diff [simp]: "of_int (w - z) = of_int w - of_int z"
    13.7 -by (simp add: OrderedGroup.diff_minus diff_minus)
    13.8 +by (simp add: diff_minus Groups.diff_minus)
    13.9  
   13.10  lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z"
   13.11  apply (cases w, cases z)
   13.12 @@ -519,7 +519,7 @@
   13.13  
   13.14  text{*This version is proved for all ordered rings, not just integers!
   13.15        It is proved here because attribute @{text arith_split} is not available
   13.16 -      in theory @{text Ring_and_Field}.
   13.17 +      in theory @{text Rings}.
   13.18        But is it really better than just rewriting with @{text abs_if}?*}
   13.19  lemma abs_split [arith_split,noatp]:
   13.20       "P(abs(a::'a::linordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))"
   13.21 @@ -2317,9 +2317,9 @@
   13.22  lemmas zadd_assoc = add_assoc [of "z1::int" "z2" "z3", standard]
   13.23  lemmas zadd_left_commute = add_left_commute [of "x::int" "y" "z", standard]
   13.24  lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute
   13.25 -lemmas zmult_ac = OrderedGroup.mult_ac
   13.26 -lemmas zadd_0 = OrderedGroup.add_0_left [of "z::int", standard]
   13.27 -lemmas zadd_0_right = OrderedGroup.add_0_left [of "z::int", standard]
   13.28 +lemmas zmult_ac = mult_ac
   13.29 +lemmas zadd_0 = add_0_left [of "z::int", standard]
   13.30 +lemmas zadd_0_right = add_0_right [of "z::int", standard]
   13.31  lemmas zadd_zminus_inverse2 = left_minus [of "z::int", standard]
   13.32  lemmas zmult_zminus = mult_minus_left [of "z::int" "w", standard]
   13.33  lemmas zmult_commute = mult_commute [of "z::int" "w", standard]
    14.1 --- a/src/HOL/IsaMakefile	Mon Feb 08 17:12:32 2010 +0100
    14.2 +++ b/src/HOL/IsaMakefile	Mon Feb 08 17:12:38 2010 +0100
    14.3 @@ -145,15 +145,16 @@
    14.4    Complete_Lattice.thy \
    14.5    Datatype.thy \
    14.6    Extraction.thy \
    14.7 +  Fields.thy \
    14.8    Finite_Set.thy \
    14.9    Fun.thy \
   14.10    FunDef.thy \
   14.11 +  Groups.thy \
   14.12    Inductive.thy \
   14.13    Lattices.thy \
   14.14    Nat.thy \
   14.15    Nitpick.thy \
   14.16    Option.thy \
   14.17 -  OrderedGroup.thy \
   14.18    Orderings.thy \
   14.19    Plain.thy \
   14.20    Power.thy \
   14.21 @@ -162,7 +163,7 @@
   14.22    Record.thy \
   14.23    Refute.thy \
   14.24    Relation.thy \
   14.25 -  Ring_and_Field.thy \
   14.26 +  Rings.thy \
   14.27    SAT.thy \
   14.28    Set.thy \
   14.29    Sum_Type.thy \
    15.1 --- a/src/HOL/Library/Poly_Deriv.thy	Mon Feb 08 17:12:32 2010 +0100
    15.2 +++ b/src/HOL/Library/Poly_Deriv.thy	Mon Feb 08 17:12:38 2010 +0100
    15.3 @@ -139,7 +139,7 @@
    15.4  lemma dvd_add_cancel1:
    15.5    fixes a b c :: "'a::comm_ring_1"
    15.6    shows "a dvd b + c \<Longrightarrow> a dvd b \<Longrightarrow> a dvd c"
    15.7 -  by (drule (1) Ring_and_Field.dvd_diff, simp)
    15.8 +  by (drule (1) Rings.dvd_diff, simp)
    15.9  
   15.10  lemma lemma_order_pderiv [rule_format]:
   15.11       "\<forall>p q a. 0 < n &
    16.1 --- a/src/HOL/Metis_Examples/BigO.thy	Mon Feb 08 17:12:32 2010 +0100
    16.2 +++ b/src/HOL/Metis_Examples/BigO.thy	Mon Feb 08 17:12:38 2010 +0100
    16.3 @@ -368,7 +368,7 @@
    16.4      f : O(g)" 
    16.5    apply (auto simp add: bigo_def)
    16.6  (*Version 1: one-shot proof*)
    16.7 -  apply (metis OrderedGroup.abs_le_D1 linorder_class.not_less  order_less_le  Orderings.xt1(12)  Ring_and_Field.abs_mult)
    16.8 +  apply (metis abs_le_D1 linorder_class.not_less  order_less_le  Orderings.xt1(12)  abs_mult)
    16.9    done
   16.10  
   16.11  lemma (*bigo_bounded_alt:*) "ALL x. 0 <= f x ==> ALL x. f x <= c * g x ==> 
   16.12 @@ -595,8 +595,8 @@
   16.13  using [[ atp_problem_prefix = "BigO__bigo_mult_simpler" ]]
   16.14  prefer 2 
   16.15  apply (metis mult_assoc mult_left_commute
   16.16 -  OrderedGroup.abs_of_pos OrderedGroup.mult_left_commute
   16.17 -  Ring_and_Field.abs_mult Ring_and_Field.mult_pos_pos)
   16.18 +  abs_of_pos mult_left_commute
   16.19 +  abs_mult mult_pos_pos)
   16.20    apply (erule ssubst) 
   16.21    apply (subst abs_mult)
   16.22  (*not qute BigO__bigo_mult_simpler_1 (a hard problem!) as abs_mult has
   16.23 @@ -613,32 +613,32 @@
   16.24    \<le> (c\<Colon>'b\<Colon>linordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar> *
   16.25      ((ca\<Colon>'b\<Colon>linordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar>)"
   16.26  have 4: "\<bar>c\<Colon>'b\<Colon>linordered_idom\<bar> = c"
   16.27 -  by (metis OrderedGroup.abs_of_pos 0)
   16.28 +  by (metis abs_of_pos 0)
   16.29  have 5: "\<And>X1\<Colon>'b\<Colon>linordered_idom. (c\<Colon>'b\<Colon>linordered_idom) * \<bar>X1\<bar> = \<bar>c * X1\<bar>"
   16.30 -  by (metis Ring_and_Field.abs_mult 4)
   16.31 +  by (metis abs_mult 4)
   16.32  have 6: "(0\<Colon>'b\<Colon>linordered_idom) = (1\<Colon>'b\<Colon>linordered_idom) \<or>
   16.33  (0\<Colon>'b\<Colon>linordered_idom) < (1\<Colon>'b\<Colon>linordered_idom)"
   16.34 -  by (metis OrderedGroup.abs_not_less_zero Ring_and_Field.abs_one Ring_and_Field.linorder_neqE_linordered_idom)
   16.35 +  by (metis abs_not_less_zero abs_one linorder_neqE_linordered_idom)
   16.36  have 7: "(0\<Colon>'b\<Colon>linordered_idom) < (1\<Colon>'b\<Colon>linordered_idom)"
   16.37 -  by (metis 6 Ring_and_Field.one_neq_zero)
   16.38 +  by (metis 6 one_neq_zero)
   16.39  have 8: "\<bar>1\<Colon>'b\<Colon>linordered_idom\<bar> = (1\<Colon>'b\<Colon>linordered_idom)"
   16.40 -  by (metis OrderedGroup.abs_of_pos 7)
   16.41 +  by (metis abs_of_pos 7)
   16.42  have 9: "\<And>X1\<Colon>'b\<Colon>linordered_idom. (0\<Colon>'b\<Colon>linordered_idom) \<le> (c\<Colon>'b\<Colon>linordered_idom) * \<bar>X1\<bar>"
   16.43 -  by (metis OrderedGroup.abs_ge_zero 5)
   16.44 +  by (metis abs_ge_zero 5)
   16.45  have 10: "\<And>X1\<Colon>'b\<Colon>linordered_idom. X1 * (1\<Colon>'b\<Colon>linordered_idom) = X1"
   16.46 -  by (metis Ring_and_Field.mult_cancel_right2 mult_commute)
   16.47 +  by (metis mult_cancel_right2 mult_commute)
   16.48  have 11: "\<And>X1\<Colon>'b\<Colon>linordered_idom. \<bar>\<bar>X1\<bar>\<bar> = \<bar>X1\<bar> * \<bar>1\<Colon>'b\<Colon>linordered_idom\<bar>"
   16.49 -  by (metis Ring_and_Field.abs_mult OrderedGroup.abs_idempotent 10)
   16.50 +  by (metis abs_mult abs_idempotent 10)
   16.51  have 12: "\<And>X1\<Colon>'b\<Colon>linordered_idom. \<bar>\<bar>X1\<bar>\<bar> = \<bar>X1\<bar>"
   16.52    by (metis 11 8 10)
   16.53  have 13: "\<And>X1\<Colon>'b\<Colon>linordered_idom. (0\<Colon>'b\<Colon>linordered_idom) \<le> \<bar>X1\<bar>"
   16.54 -  by (metis OrderedGroup.abs_ge_zero 12)
   16.55 +  by (metis abs_ge_zero 12)
   16.56  have 14: "\<not> (0\<Colon>'b\<Colon>linordered_idom)
   16.57    \<le> (c\<Colon>'b\<Colon>linordered_idom) * \<bar>(f\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) (x\<Colon>'a)\<bar> \<or>
   16.58  \<not> (0\<Colon>'b\<Colon>linordered_idom) \<le> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar> \<or>
   16.59  \<not> \<bar>b x\<bar> \<le> (ca\<Colon>'b\<Colon>linordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar> \<or>
   16.60  \<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar> \<le> c * \<bar>f x\<bar>"
   16.61 -  by (metis 3 Ring_and_Field.mult_mono)
   16.62 +  by (metis 3 mult_mono)
   16.63  have 15: "\<not> (0\<Colon>'b\<Colon>linordered_idom) \<le> \<bar>(b\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) (x\<Colon>'a)\<bar> \<or>
   16.64  \<not> \<bar>b x\<bar> \<le> (ca\<Colon>'b\<Colon>linordered_idom) * \<bar>(g\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar> \<or>
   16.65  \<not> \<bar>(a\<Colon>'a \<Rightarrow> 'b\<Colon>linordered_idom) x\<bar>
   16.66 @@ -1078,7 +1078,7 @@
   16.67    apply (rule_tac x = c in exI)
   16.68    apply safe
   16.69    apply (case_tac "x = 0")
   16.70 -apply (metis OrderedGroup.abs_ge_zero  OrderedGroup.abs_zero  order_less_le  Ring_and_Field.split_mult_pos_le) 
   16.71 +apply (metis abs_ge_zero  abs_zero  order_less_le  split_mult_pos_le) 
   16.72    apply (subgoal_tac "x = Suc (x - 1)")
   16.73    apply metis
   16.74    apply simp
    17.1 --- a/src/HOL/NSA/HyperDef.thy	Mon Feb 08 17:12:32 2010 +0100
    17.2 +++ b/src/HOL/NSA/HyperDef.thy	Mon Feb 08 17:12:38 2010 +0100
    17.3 @@ -394,7 +394,7 @@
    17.4  by (simp only: hypreal_three_squares_add_zero_iff hrealpow_two)
    17.5  
    17.6  (*FIXME: This and RealPow.abs_realpow_two should be replaced by an abstract
    17.7 -  result proved in Ring_and_Field*)
    17.8 +  result proved in Rings or Fields*)
    17.9  lemma hrabs_hrealpow_two [simp]:
   17.10       "abs(x ^ Suc (Suc 0)) = (x::hypreal) ^ Suc (Suc 0)"
   17.11  by (simp add: abs_mult)
   17.12 @@ -516,7 +516,7 @@
   17.13  text{*The precondition could be weakened to @{term "0\<le>x"}*}
   17.14  lemma hypreal_mult_less_mono:
   17.15       "[| u<v;  x<y;  (0::hypreal) < v;  0 < x |] ==> u*x < v* y"
   17.16 - by (simp add: Ring_and_Field.mult_strict_mono order_less_imp_le)
   17.17 + by (simp add: mult_strict_mono order_less_imp_le)
   17.18  
   17.19  lemma hyperpow_two_gt_one:
   17.20    "\<And>r::'a::{linordered_semidom} star. 1 < r \<Longrightarrow> 1 < r pow (1 + 1)"
    18.1 --- a/src/HOL/NSA/NSComplex.thy	Mon Feb 08 17:12:32 2010 +0100
    18.2 +++ b/src/HOL/NSA/NSComplex.thy	Mon Feb 08 17:12:38 2010 +0100
    18.3 @@ -1,5 +1,4 @@
    18.4  (*  Title:       NSComplex.thy
    18.5 -    ID:      $Id$
    18.6      Author:      Jacques D. Fleuriot
    18.7      Copyright:   2001  University of Edinburgh
    18.8      Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
    18.9 @@ -161,7 +160,7 @@
   18.10  
   18.11  lemma hcomplex_add_minus_eq_minus:
   18.12        "x + y = (0::hcomplex) ==> x = -y"
   18.13 -apply (drule OrderedGroup.minus_unique)
   18.14 +apply (drule minus_unique)
   18.15  apply (simp add: minus_equation_iff [of x y])
   18.16  done
   18.17  
   18.18 @@ -196,7 +195,7 @@
   18.19  
   18.20  lemma hcomplex_diff_eq_eq [simp]: "((x::hcomplex) - y = z) = (x = z + y)"
   18.21  (* TODO: delete *)
   18.22 -by (rule OrderedGroup.diff_eq_eq)
   18.23 +by (rule diff_eq_eq)
   18.24  
   18.25  
   18.26  subsection{*Embedding Properties for @{term hcomplex_of_hypreal} Map*}
    19.1 --- a/src/HOL/NSA/StarDef.thy	Mon Feb 08 17:12:32 2010 +0100
    19.2 +++ b/src/HOL/NSA/StarDef.thy	Mon Feb 08 17:12:38 2010 +0100
    19.3 @@ -530,7 +530,7 @@
    19.4  
    19.5  end
    19.6  
    19.7 -instance star :: (Ring_and_Field.dvd) Ring_and_Field.dvd ..
    19.8 +instance star :: (Rings.dvd) Rings.dvd ..
    19.9  
   19.10  instantiation star :: (Divides.div) Divides.div
   19.11  begin
    20.1 --- a/src/HOL/OrderedGroup.thy	Mon Feb 08 17:12:32 2010 +0100
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,1159 +0,0 @@
    20.4 -(*  Title:   HOL/OrderedGroup.thy
    20.5 -    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson, Markus Wenzel, Jeremy Avigad
    20.6 -*)
    20.7 -
    20.8 -header {* Ordered Groups *}
    20.9 -
   20.10 -theory OrderedGroup
   20.11 -imports Lattices
   20.12 -uses "~~/src/Provers/Arith/abel_cancel.ML"
   20.13 -begin
   20.14 -
   20.15 -text {*
   20.16 -  The theory of partially ordered groups is taken from the books:
   20.17 -  \begin{itemize}
   20.18 -  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
   20.19 -  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
   20.20 -  \end{itemize}
   20.21 -  Most of the used notions can also be looked up in 
   20.22 -  \begin{itemize}
   20.23 -  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
   20.24 -  \item \emph{Algebra I} by van der Waerden, Springer.
   20.25 -  \end{itemize}
   20.26 -*}
   20.27 -
   20.28 -ML {*
   20.29 -structure Algebra_Simps = Named_Thms(
   20.30 -  val name = "algebra_simps"
   20.31 -  val description = "algebra simplification rules"
   20.32 -)
   20.33 -*}
   20.34 -
   20.35 -setup Algebra_Simps.setup
   20.36 -
   20.37 -text{* The rewrites accumulated in @{text algebra_simps} deal with the
   20.38 -classical algebraic structures of groups, rings and family. They simplify
   20.39 -terms by multiplying everything out (in case of a ring) and bringing sums and
   20.40 -products into a canonical form (by ordered rewriting). As a result it decides
   20.41 -group and ring equalities but also helps with inequalities.
   20.42 -
   20.43 -Of course it also works for fields, but it knows nothing about multiplicative
   20.44 -inverses or division. This is catered for by @{text field_simps}. *}
   20.45 -
   20.46 -subsection {* Semigroups and Monoids *}
   20.47 -
   20.48 -class semigroup_add = plus +
   20.49 -  assumes add_assoc [algebra_simps]: "(a + b) + c = a + (b + c)"
   20.50 -
   20.51 -sublocale semigroup_add < plus!: semigroup plus proof
   20.52 -qed (fact add_assoc)
   20.53 -
   20.54 -class ab_semigroup_add = semigroup_add +
   20.55 -  assumes add_commute [algebra_simps]: "a + b = b + a"
   20.56 -
   20.57 -sublocale ab_semigroup_add < plus!: abel_semigroup plus proof
   20.58 -qed (fact add_commute)
   20.59 -
   20.60 -context ab_semigroup_add
   20.61 -begin
   20.62 -
   20.63 -lemmas add_left_commute [algebra_simps] = plus.left_commute
   20.64 -
   20.65 -theorems add_ac = add_assoc add_commute add_left_commute
   20.66 -
   20.67 -end
   20.68 -
   20.69 -theorems add_ac = add_assoc add_commute add_left_commute
   20.70 -
   20.71 -class semigroup_mult = times +
   20.72 -  assumes mult_assoc [algebra_simps]: "(a * b) * c = a * (b * c)"
   20.73 -
   20.74 -sublocale semigroup_mult < times!: semigroup times proof
   20.75 -qed (fact mult_assoc)
   20.76 -
   20.77 -class ab_semigroup_mult = semigroup_mult +
   20.78 -  assumes mult_commute [algebra_simps]: "a * b = b * a"
   20.79 -
   20.80 -sublocale ab_semigroup_mult < times!: abel_semigroup times proof
   20.81 -qed (fact mult_commute)
   20.82 -
   20.83 -context ab_semigroup_mult
   20.84 -begin
   20.85 -
   20.86 -lemmas mult_left_commute [algebra_simps] = times.left_commute
   20.87 -
   20.88 -theorems mult_ac = mult_assoc mult_commute mult_left_commute
   20.89 -
   20.90 -end
   20.91 -
   20.92 -theorems mult_ac = mult_assoc mult_commute mult_left_commute
   20.93 -
   20.94 -class ab_semigroup_idem_mult = ab_semigroup_mult +
   20.95 -  assumes mult_idem: "x * x = x"
   20.96 -
   20.97 -sublocale ab_semigroup_idem_mult < times!: semilattice times proof
   20.98 -qed (fact mult_idem)
   20.99 -
  20.100 -context ab_semigroup_idem_mult
  20.101 -begin
  20.102 -
  20.103 -lemmas mult_left_idem = times.left_idem
  20.104 -
  20.105 -end
  20.106 -
  20.107 -class monoid_add = zero + semigroup_add +
  20.108 -  assumes add_0_left [simp]: "0 + a = a"
  20.109 -    and add_0_right [simp]: "a + 0 = a"
  20.110 -
  20.111 -lemma zero_reorient: "0 = x \<longleftrightarrow> x = 0"
  20.112 -by (rule eq_commute)
  20.113 -
  20.114 -class comm_monoid_add = zero + ab_semigroup_add +
  20.115 -  assumes add_0: "0 + a = a"
  20.116 -begin
  20.117 -
  20.118 -subclass monoid_add
  20.119 -  proof qed (insert add_0, simp_all add: add_commute)
  20.120 -
  20.121 -end
  20.122 -
  20.123 -class monoid_mult = one + semigroup_mult +
  20.124 -  assumes mult_1_left [simp]: "1 * a  = a"
  20.125 -  assumes mult_1_right [simp]: "a * 1 = a"
  20.126 -
  20.127 -lemma one_reorient: "1 = x \<longleftrightarrow> x = 1"
  20.128 -by (rule eq_commute)
  20.129 -
  20.130 -class comm_monoid_mult = one + ab_semigroup_mult +
  20.131 -  assumes mult_1: "1 * a = a"
  20.132 -begin
  20.133 -
  20.134 -subclass monoid_mult
  20.135 -  proof qed (insert mult_1, simp_all add: mult_commute)
  20.136 -
  20.137 -end
  20.138 -
  20.139 -class cancel_semigroup_add = semigroup_add +
  20.140 -  assumes add_left_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
  20.141 -  assumes add_right_imp_eq: "b + a = c + a \<Longrightarrow> b = c"
  20.142 -begin
  20.143 -
  20.144 -lemma add_left_cancel [simp]:
  20.145 -  "a + b = a + c \<longleftrightarrow> b = c"
  20.146 -by (blast dest: add_left_imp_eq)
  20.147 -
  20.148 -lemma add_right_cancel [simp]:
  20.149 -  "b + a = c + a \<longleftrightarrow> b = c"
  20.150 -by (blast dest: add_right_imp_eq)
  20.151 -
  20.152 -end
  20.153 -
  20.154 -class cancel_ab_semigroup_add = ab_semigroup_add +
  20.155 -  assumes add_imp_eq: "a + b = a + c \<Longrightarrow> b = c"
  20.156 -begin
  20.157 -
  20.158 -subclass cancel_semigroup_add
  20.159 -proof
  20.160 -  fix a b c :: 'a
  20.161 -  assume "a + b = a + c" 
  20.162 -  then show "b = c" by (rule add_imp_eq)
  20.163 -next
  20.164 -  fix a b c :: 'a
  20.165 -  assume "b + a = c + a"
  20.166 -  then have "a + b = a + c" by (simp only: add_commute)
  20.167 -  then show "b = c" by (rule add_imp_eq)
  20.168 -qed
  20.169 -
  20.170 -end
  20.171 -
  20.172 -class cancel_comm_monoid_add = cancel_ab_semigroup_add + comm_monoid_add
  20.173 -
  20.174 -
  20.175 -subsection {* Groups *}
  20.176 -
  20.177 -class group_add = minus + uminus + monoid_add +
  20.178 -  assumes left_minus [simp]: "- a + a = 0"
  20.179 -  assumes diff_minus: "a - b = a + (- b)"
  20.180 -begin
  20.181 -
  20.182 -lemma minus_unique:
  20.183 -  assumes "a + b = 0" shows "- a = b"
  20.184 -proof -
  20.185 -  have "- a = - a + (a + b)" using assms by simp
  20.186 -  also have "\<dots> = b" by (simp add: add_assoc [symmetric])
  20.187 -  finally show ?thesis .
  20.188 -qed
  20.189 -
  20.190 -lemmas equals_zero_I = minus_unique (* legacy name *)
  20.191 -
  20.192 -lemma minus_zero [simp]: "- 0 = 0"
  20.193 -proof -
  20.194 -  have "0 + 0 = 0" by (rule add_0_right)
  20.195 -  thus "- 0 = 0" by (rule minus_unique)
  20.196 -qed
  20.197 -
  20.198 -lemma minus_minus [simp]: "- (- a) = a"
  20.199 -proof -
  20.200 -  have "- a + a = 0" by (rule left_minus)
  20.201 -  thus "- (- a) = a" by (rule minus_unique)
  20.202 -qed
  20.203 -
  20.204 -lemma right_minus [simp]: "a + - a = 0"
  20.205 -proof -
  20.206 -  have "a + - a = - (- a) + - a" by simp
  20.207 -  also have "\<dots> = 0" by (rule left_minus)
  20.208 -  finally show ?thesis .
  20.209 -qed
  20.210 -
  20.211 -lemma minus_add_cancel: "- a + (a + b) = b"
  20.212 -by (simp add: add_assoc [symmetric])
  20.213 -
  20.214 -lemma add_minus_cancel: "a + (- a + b) = b"
  20.215 -by (simp add: add_assoc [symmetric])
  20.216 -
  20.217 -lemma minus_add: "- (a + b) = - b + - a"
  20.218 -proof -
  20.219 -  have "(a + b) + (- b + - a) = 0"
  20.220 -    by (simp add: add_assoc add_minus_cancel)
  20.221 -  thus "- (a + b) = - b + - a"
  20.222 -    by (rule minus_unique)
  20.223 -qed
  20.224 -
  20.225 -lemma right_minus_eq: "a - b = 0 \<longleftrightarrow> a = b"
  20.226 -proof
  20.227 -  assume "a - b = 0"
  20.228 -  have "a = (a - b) + b" by (simp add:diff_minus add_assoc)
  20.229 -  also have "\<dots> = b" using `a - b = 0` by simp
  20.230 -  finally show "a = b" .
  20.231 -next
  20.232 -  assume "a = b" thus "a - b = 0" by (simp add: diff_minus)
  20.233 -qed
  20.234 -
  20.235 -lemma diff_self [simp]: "a - a = 0"
  20.236 -by (simp add: diff_minus)
  20.237 -
  20.238 -lemma diff_0 [simp]: "0 - a = - a"
  20.239 -by (simp add: diff_minus)
  20.240 -
  20.241 -lemma diff_0_right [simp]: "a - 0 = a" 
  20.242 -by (simp add: diff_minus)
  20.243 -
  20.244 -lemma diff_minus_eq_add [simp]: "a - - b = a + b"
  20.245 -by (simp add: diff_minus)
  20.246 -
  20.247 -lemma neg_equal_iff_equal [simp]:
  20.248 -  "- a = - b \<longleftrightarrow> a = b" 
  20.249 -proof 
  20.250 -  assume "- a = - b"
  20.251 -  hence "- (- a) = - (- b)" by simp
  20.252 -  thus "a = b" by simp
  20.253 -next
  20.254 -  assume "a = b"
  20.255 -  thus "- a = - b" by simp
  20.256 -qed
  20.257 -
  20.258 -lemma neg_equal_0_iff_equal [simp]:
  20.259 -  "- a = 0 \<longleftrightarrow> a = 0"
  20.260 -by (subst neg_equal_iff_equal [symmetric], simp)
  20.261 -
  20.262 -lemma neg_0_equal_iff_equal [simp]:
  20.263 -  "0 = - a \<longleftrightarrow> 0 = a"
  20.264 -by (subst neg_equal_iff_equal [symmetric], simp)
  20.265 -
  20.266 -text{*The next two equations can make the simplifier loop!*}
  20.267 -
  20.268 -lemma equation_minus_iff:
  20.269 -  "a = - b \<longleftrightarrow> b = - a"
  20.270 -proof -
  20.271 -  have "- (- a) = - b \<longleftrightarrow> - a = b" by (rule neg_equal_iff_equal)
  20.272 -  thus ?thesis by (simp add: eq_commute)
  20.273 -qed
  20.274 -
  20.275 -lemma minus_equation_iff:
  20.276 -  "- a = b \<longleftrightarrow> - b = a"
  20.277 -proof -
  20.278 -  have "- a = - (- b) \<longleftrightarrow> a = -b" by (rule neg_equal_iff_equal)
  20.279 -  thus ?thesis by (simp add: eq_commute)
  20.280 -qed
  20.281 -
  20.282 -lemma diff_add_cancel: "a - b + b = a"
  20.283 -by (simp add: diff_minus add_assoc)
  20.284 -
  20.285 -lemma add_diff_cancel: "a + b - b = a"
  20.286 -by (simp add: diff_minus add_assoc)
  20.287 -
  20.288 -declare diff_minus[symmetric, algebra_simps]
  20.289 -
  20.290 -lemma eq_neg_iff_add_eq_0: "a = - b \<longleftrightarrow> a + b = 0"
  20.291 -proof
  20.292 -  assume "a = - b" then show "a + b = 0" by simp
  20.293 -next
  20.294 -  assume "a + b = 0"
  20.295 -  moreover have "a + (b + - b) = (a + b) + - b"
  20.296 -    by (simp only: add_assoc)
  20.297 -  ultimately show "a = - b" by simp
  20.298 -qed
  20.299 -
  20.300 -end
  20.301 -
  20.302 -class ab_group_add = minus + uminus + comm_monoid_add +
  20.303 -  assumes ab_left_minus: "- a + a = 0"
  20.304 -  assumes ab_diff_minus: "a - b = a + (- b)"
  20.305 -begin
  20.306 -
  20.307 -subclass group_add
  20.308 -  proof qed (simp_all add: ab_left_minus ab_diff_minus)
  20.309 -
  20.310 -subclass cancel_comm_monoid_add
  20.311 -proof
  20.312 -  fix a b c :: 'a
  20.313 -  assume "a + b = a + c"
  20.314 -  then have "- a + a + b = - a + a + c"
  20.315 -    unfolding add_assoc by simp
  20.316 -  then show "b = c" by simp
  20.317 -qed
  20.318 -
  20.319 -lemma uminus_add_conv_diff[algebra_simps]:
  20.320 -  "- a + b = b - a"
  20.321 -by (simp add:diff_minus add_commute)
  20.322 -
  20.323 -lemma minus_add_distrib [simp]:
  20.324 -  "- (a + b) = - a + - b"
  20.325 -by (rule minus_unique) (simp add: add_ac)
  20.326 -
  20.327 -lemma minus_diff_eq [simp]:
  20.328 -  "- (a - b) = b - a"
  20.329 -by (simp add: diff_minus add_commute)
  20.330 -
  20.331 -lemma add_diff_eq[algebra_simps]: "a + (b - c) = (a + b) - c"
  20.332 -by (simp add: diff_minus add_ac)
  20.333 -
  20.334 -lemma diff_add_eq[algebra_simps]: "(a - b) + c = (a + c) - b"
  20.335 -by (simp add: diff_minus add_ac)
  20.336 -
  20.337 -lemma diff_eq_eq[algebra_simps]: "a - b = c \<longleftrightarrow> a = c + b"
  20.338 -by (auto simp add: diff_minus add_assoc)
  20.339 -
  20.340 -lemma eq_diff_eq[algebra_simps]: "a = c - b \<longleftrightarrow> a + b = c"
  20.341 -by (auto simp add: diff_minus add_assoc)
  20.342 -
  20.343 -lemma diff_diff_eq[algebra_simps]: "(a - b) - c = a - (b + c)"
  20.344 -by (simp add: diff_minus add_ac)
  20.345 -
  20.346 -lemma diff_diff_eq2[algebra_simps]: "a - (b - c) = (a + c) - b"
  20.347 -by (simp add: diff_minus add_ac)
  20.348 -
  20.349 -lemma eq_iff_diff_eq_0: "a = b \<longleftrightarrow> a - b = 0"
  20.350 -by (simp add: algebra_simps)
  20.351 -
  20.352 -lemma diff_eq_0_iff_eq [simp, noatp]: "a - b = 0 \<longleftrightarrow> a = b"
  20.353 -by (simp add: algebra_simps)
  20.354 -
  20.355 -end
  20.356 -
  20.357 -subsection {* (Partially) Ordered Groups *} 
  20.358 -
  20.359 -class ordered_ab_semigroup_add = order + ab_semigroup_add +
  20.360 -  assumes add_left_mono: "a \<le> b \<Longrightarrow> c + a \<le> c + b"
  20.361 -begin
  20.362 -
  20.363 -lemma add_right_mono:
  20.364 -  "a \<le> b \<Longrightarrow> a + c \<le> b + c"
  20.365 -by (simp add: add_commute [of _ c] add_left_mono)
  20.366 -
  20.367 -text {* non-strict, in both arguments *}
  20.368 -lemma add_mono:
  20.369 -  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c \<le> b + d"
  20.370 -  apply (erule add_right_mono [THEN order_trans])
  20.371 -  apply (simp add: add_commute add_left_mono)
  20.372 -  done
  20.373 -
  20.374 -end
  20.375 -
  20.376 -class ordered_cancel_ab_semigroup_add =
  20.377 -  ordered_ab_semigroup_add + cancel_ab_semigroup_add
  20.378 -begin
  20.379 -
  20.380 -lemma add_strict_left_mono:
  20.381 -  "a < b \<Longrightarrow> c + a < c + b"
  20.382 -by (auto simp add: less_le add_left_mono)
  20.383 -
  20.384 -lemma add_strict_right_mono:
  20.385 -  "a < b \<Longrightarrow> a + c < b + c"
  20.386 -by (simp add: add_commute [of _ c] add_strict_left_mono)
  20.387 -
  20.388 -text{*Strict monotonicity in both arguments*}
  20.389 -lemma add_strict_mono:
  20.390 -  "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
  20.391 -apply (erule add_strict_right_mono [THEN less_trans])
  20.392 -apply (erule add_strict_left_mono)
  20.393 -done
  20.394 -
  20.395 -lemma add_less_le_mono:
  20.396 -  "a < b \<Longrightarrow> c \<le> d \<Longrightarrow> a + c < b + d"
  20.397 -apply (erule add_strict_right_mono [THEN less_le_trans])
  20.398 -apply (erule add_left_mono)
  20.399 -done
  20.400 -
  20.401 -lemma add_le_less_mono:
  20.402 -  "a \<le> b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
  20.403 -apply (erule add_right_mono [THEN le_less_trans])
  20.404 -apply (erule add_strict_left_mono) 
  20.405 -done
  20.406 -
  20.407 -end
  20.408 -
  20.409 -class ordered_ab_semigroup_add_imp_le =
  20.410 -  ordered_cancel_ab_semigroup_add +
  20.411 -  assumes add_le_imp_le_left: "c + a \<le> c + b \<Longrightarrow> a \<le> b"
  20.412 -begin
  20.413 -
  20.414 -lemma add_less_imp_less_left:
  20.415 -  assumes less: "c + a < c + b" shows "a < b"
  20.416 -proof -
  20.417 -  from less have le: "c + a <= c + b" by (simp add: order_le_less)
  20.418 -  have "a <= b" 
  20.419 -    apply (insert le)
  20.420 -    apply (drule add_le_imp_le_left)
  20.421 -    by (insert le, drule add_le_imp_le_left, assumption)
  20.422 -  moreover have "a \<noteq> b"
  20.423 -  proof (rule ccontr)
  20.424 -    assume "~(a \<noteq> b)"
  20.425 -    then have "a = b" by simp
  20.426 -    then have "c + a = c + b" by simp
  20.427 -    with less show "False"by simp
  20.428 -  qed
  20.429 -  ultimately show "a < b" by (simp add: order_le_less)
  20.430 -qed
  20.431 -
  20.432 -lemma add_less_imp_less_right:
  20.433 -  "a + c < b + c \<Longrightarrow> a < b"
  20.434 -apply (rule add_less_imp_less_left [of c])
  20.435 -apply (simp add: add_commute)  
  20.436 -done
  20.437 -
  20.438 -lemma add_less_cancel_left [simp]:
  20.439 -  "c + a < c + b \<longleftrightarrow> a < b"
  20.440 -by (blast intro: add_less_imp_less_left add_strict_left_mono) 
  20.441 -
  20.442 -lemma add_less_cancel_right [simp]:
  20.443 -  "a + c < b + c \<longleftrightarrow> a < b"
  20.444 -by (blast intro: add_less_imp_less_right add_strict_right_mono)
  20.445 -
  20.446 -lemma add_le_cancel_left [simp]:
  20.447 -  "c + a \<le> c + b \<longleftrightarrow> a \<le> b"
  20.448 -by (auto, drule add_le_imp_le_left, simp_all add: add_left_mono) 
  20.449 -
  20.450 -lemma add_le_cancel_right [simp]:
  20.451 -  "a + c \<le> b + c \<longleftrightarrow> a \<le> b"
  20.452 -by (simp add: add_commute [of a c] add_commute [of b c])
  20.453 -
  20.454 -lemma add_le_imp_le_right:
  20.455 -  "a + c \<le> b + c \<Longrightarrow> a \<le> b"
  20.456 -by simp
  20.457 -
  20.458 -lemma max_add_distrib_left:
  20.459 -  "max x y + z = max (x + z) (y + z)"
  20.460 -  unfolding max_def by auto
  20.461 -
  20.462 -lemma min_add_distrib_left:
  20.463 -  "min x y + z = min (x + z) (y + z)"
  20.464 -  unfolding min_def by auto
  20.465 -
  20.466 -end
  20.467 -
  20.468 -subsection {* Support for reasoning about signs *}
  20.469 -
  20.470 -class ordered_comm_monoid_add =
  20.471 -  ordered_cancel_ab_semigroup_add + comm_monoid_add
  20.472 -begin
  20.473 -
  20.474 -lemma add_pos_nonneg:
  20.475 -  assumes "0 < a" and "0 \<le> b" shows "0 < a + b"
  20.476 -proof -
  20.477 -  have "0 + 0 < a + b" 
  20.478 -    using assms by (rule add_less_le_mono)
  20.479 -  then show ?thesis by simp
  20.480 -qed
  20.481 -
  20.482 -lemma add_pos_pos:
  20.483 -  assumes "0 < a" and "0 < b" shows "0 < a + b"
  20.484 -by (rule add_pos_nonneg) (insert assms, auto)
  20.485 -
  20.486 -lemma add_nonneg_pos:
  20.487 -  assumes "0 \<le> a" and "0 < b" shows "0 < a + b"
  20.488 -proof -
  20.489 -  have "0 + 0 < a + b" 
  20.490 -    using assms by (rule add_le_less_mono)
  20.491 -  then show ?thesis by simp
  20.492 -qed
  20.493 -
  20.494 -lemma add_nonneg_nonneg:
  20.495 -  assumes "0 \<le> a" and "0 \<le> b" shows "0 \<le> a + b"
  20.496 -proof -
  20.497 -  have "0 + 0 \<le> a + b" 
  20.498 -    using assms by (rule add_mono)
  20.499 -  then show ?thesis by simp
  20.500 -qed
  20.501 -
  20.502 -lemma add_neg_nonpos:
  20.503 -  assumes "a < 0" and "b \<le> 0" shows "a + b < 0"
  20.504 -proof -
  20.505 -  have "a + b < 0 + 0"
  20.506 -    using assms by (rule add_less_le_mono)
  20.507 -  then show ?thesis by simp
  20.508 -qed
  20.509 -
  20.510 -lemma add_neg_neg: 
  20.511 -  assumes "a < 0" and "b < 0" shows "a + b < 0"
  20.512 -by (rule add_neg_nonpos) (insert assms, auto)
  20.513 -
  20.514 -lemma add_nonpos_neg:
  20.515 -  assumes "a \<le> 0" and "b < 0" shows "a + b < 0"
  20.516 -proof -
  20.517 -  have "a + b < 0 + 0"
  20.518 -    using assms by (rule add_le_less_mono)
  20.519 -  then show ?thesis by simp
  20.520 -qed
  20.521 -
  20.522 -lemma add_nonpos_nonpos:
  20.523 -  assumes "a \<le> 0" and "b \<le> 0" shows "a + b \<le> 0"
  20.524 -proof -
  20.525 -  have "a + b \<le> 0 + 0"
  20.526 -    using assms by (rule add_mono)
  20.527 -  then show ?thesis by simp
  20.528 -qed
  20.529 -
  20.530 -lemmas add_sign_intros =
  20.531 -  add_pos_nonneg add_pos_pos add_nonneg_pos add_nonneg_nonneg
  20.532 -  add_neg_nonpos add_neg_neg add_nonpos_neg add_nonpos_nonpos
  20.533 -
  20.534 -lemma add_nonneg_eq_0_iff:
  20.535 -  assumes x: "0 \<le> x" and y: "0 \<le> y"
  20.536 -  shows "x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
  20.537 -proof (intro iffI conjI)
  20.538 -  have "x = x + 0" by simp
  20.539 -  also have "x + 0 \<le> x + y" using y by (rule add_left_mono)
  20.540 -  also assume "x + y = 0"
  20.541 -  also have "0 \<le> x" using x .
  20.542 -  finally show "x = 0" .
  20.543 -next
  20.544 -  have "y = 0 + y" by simp
  20.545 -  also have "0 + y \<le> x + y" using x by (rule add_right_mono)
  20.546 -  also assume "x + y = 0"
  20.547 -  also have "0 \<le> y" using y .
  20.548 -  finally show "y = 0" .
  20.549 -next
  20.550 -  assume "x = 0 \<and> y = 0"
  20.551 -  then show "x + y = 0" by simp
  20.552 -qed
  20.553 -
  20.554 -end
  20.555 -
  20.556 -class ordered_ab_group_add =
  20.557 -  ab_group_add + ordered_ab_semigroup_add
  20.558 -begin
  20.559 -
  20.560 -subclass ordered_cancel_ab_semigroup_add ..
  20.561 -
  20.562 -subclass ordered_ab_semigroup_add_imp_le
  20.563 -proof
  20.564 -  fix a b c :: 'a
  20.565 -  assume "c + a \<le> c + b"
  20.566 -  hence "(-c) + (c + a) \<le> (-c) + (c + b)" by (rule add_left_mono)
  20.567 -  hence "((-c) + c) + a \<le> ((-c) + c) + b" by (simp only: add_assoc)
  20.568 -  thus "a \<le> b" by simp
  20.569 -qed
  20.570 -
  20.571 -subclass ordered_comm_monoid_add ..
  20.572 -
  20.573 -lemma max_diff_distrib_left:
  20.574 -  shows "max x y - z = max (x - z) (y - z)"
  20.575 -by (simp add: diff_minus, rule max_add_distrib_left) 
  20.576 -
  20.577 -lemma min_diff_distrib_left:
  20.578 -  shows "min x y - z = min (x - z) (y - z)"
  20.579 -by (simp add: diff_minus, rule min_add_distrib_left) 
  20.580 -
  20.581 -lemma le_imp_neg_le:
  20.582 -  assumes "a \<le> b" shows "-b \<le> -a"
  20.583 -proof -
  20.584 -  have "-a+a \<le> -a+b" using `a \<le> b` by (rule add_left_mono) 
  20.585 -  hence "0 \<le> -a+b" by simp
  20.586 -  hence "0 + (-b) \<le> (-a + b) + (-b)" by (rule add_right_mono) 
  20.587 -  thus ?thesis by (simp add: add_assoc)
  20.588 -qed
  20.589 -
  20.590 -lemma neg_le_iff_le [simp]: "- b \<le> - a \<longleftrightarrow> a \<le> b"
  20.591 -proof 
  20.592 -  assume "- b \<le> - a"
  20.593 -  hence "- (- a) \<le> - (- b)" by (rule le_imp_neg_le)
  20.594 -  thus "a\<le>b" by simp
  20.595 -next
  20.596 -  assume "a\<le>b"
  20.597 -  thus "-b \<le> -a" by (rule le_imp_neg_le)
  20.598 -qed
  20.599 -
  20.600 -lemma neg_le_0_iff_le [simp]: "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
  20.601 -by (subst neg_le_iff_le [symmetric], simp)
  20.602 -
  20.603 -lemma neg_0_le_iff_le [simp]: "0 \<le> - a \<longleftrightarrow> a \<le> 0"
  20.604 -by (subst neg_le_iff_le [symmetric], simp)
  20.605 -
  20.606 -lemma neg_less_iff_less [simp]: "- b < - a \<longleftrightarrow> a < b"
  20.607 -by (force simp add: less_le) 
  20.608 -
  20.609 -lemma neg_less_0_iff_less [simp]: "- a < 0 \<longleftrightarrow> 0 < a"
  20.610 -by (subst neg_less_iff_less [symmetric], simp)
  20.611 -
  20.612 -lemma neg_0_less_iff_less [simp]: "0 < - a \<longleftrightarrow> a < 0"
  20.613 -by (subst neg_less_iff_less [symmetric], simp)
  20.614 -
  20.615 -text{*The next several equations can make the simplifier loop!*}
  20.616 -
  20.617 -lemma less_minus_iff: "a < - b \<longleftrightarrow> b < - a"
  20.618 -proof -
  20.619 -  have "(- (-a) < - b) = (b < - a)" by (rule neg_less_iff_less)
  20.620 -  thus ?thesis by simp
  20.621 -qed
  20.622 -
  20.623 -lemma minus_less_iff: "- a < b \<longleftrightarrow> - b < a"
  20.624 -proof -
  20.625 -  have "(- a < - (-b)) = (- b < a)" by (rule neg_less_iff_less)
  20.626 -  thus ?thesis by simp
  20.627 -qed
  20.628 -
  20.629 -lemma le_minus_iff: "a \<le> - b \<longleftrightarrow> b \<le> - a"
  20.630 -proof -
  20.631 -  have mm: "!! a (b::'a). (-(-a)) < -b \<Longrightarrow> -(-b) < -a" by (simp only: minus_less_iff)
  20.632 -  have "(- (- a) <= -b) = (b <= - a)" 
  20.633 -    apply (auto simp only: le_less)
  20.634 -    apply (drule mm)
  20.635 -    apply (simp_all)
  20.636 -    apply (drule mm[simplified], assumption)
  20.637 -    done
  20.638 -  then show ?thesis by simp
  20.639 -qed
  20.640 -
  20.641 -lemma minus_le_iff: "- a \<le> b \<longleftrightarrow> - b \<le> a"
  20.642 -by (auto simp add: le_less minus_less_iff)
  20.643 -
  20.644 -lemma less_iff_diff_less_0: "a < b \<longleftrightarrow> a - b < 0"
  20.645 -proof -
  20.646 -  have  "(a < b) = (a + (- b) < b + (-b))"  
  20.647 -    by (simp only: add_less_cancel_right)
  20.648 -  also have "... =  (a - b < 0)" by (simp add: diff_minus)
  20.649 -  finally show ?thesis .
  20.650 -qed
  20.651 -
  20.652 -lemma diff_less_eq[algebra_simps]: "a - b < c \<longleftrightarrow> a < c + b"
  20.653 -apply (subst less_iff_diff_less_0 [of a])
  20.654 -apply (rule less_iff_diff_less_0 [of _ c, THEN ssubst])
  20.655 -apply (simp add: diff_minus add_ac)
  20.656 -done
  20.657 -
  20.658 -lemma less_diff_eq[algebra_simps]: "a < c - b \<longleftrightarrow> a + b < c"
  20.659 -apply (subst less_iff_diff_less_0 [of "plus a b"])
  20.660 -apply (subst less_iff_diff_less_0 [of a])
  20.661 -apply (simp add: diff_minus add_ac)
  20.662 -done
  20.663 -
  20.664 -lemma diff_le_eq[algebra_simps]: "a - b \<le> c \<longleftrightarrow> a \<le> c + b"
  20.665 -by (auto simp add: le_less diff_less_eq diff_add_cancel add_diff_cancel)
  20.666 -
  20.667 -lemma le_diff_eq[algebra_simps]: "a \<le> c - b \<longleftrightarrow> a + b \<le> c"
  20.668 -by (auto simp add: le_less less_diff_eq diff_add_cancel add_diff_cancel)
  20.669 -
  20.670 -lemma le_iff_diff_le_0: "a \<le> b \<longleftrightarrow> a - b \<le> 0"
  20.671 -by (simp add: algebra_simps)
  20.672 -
  20.673 -text{*Legacy - use @{text algebra_simps} *}
  20.674 -lemmas group_simps[noatp] = algebra_simps
  20.675 -
  20.676 -end
  20.677 -
  20.678 -text{*Legacy - use @{text algebra_simps} *}
  20.679 -lemmas group_simps[noatp] = algebra_simps
  20.680 -
  20.681 -class linordered_ab_semigroup_add =
  20.682 -  linorder + ordered_ab_semigroup_add
  20.683 -
  20.684 -class linordered_cancel_ab_semigroup_add =
  20.685 -  linorder + ordered_cancel_ab_semigroup_add
  20.686 -begin
  20.687 -
  20.688 -subclass linordered_ab_semigroup_add ..
  20.689 -
  20.690 -subclass ordered_ab_semigroup_add_imp_le
  20.691 -proof
  20.692 -  fix a b c :: 'a
  20.693 -  assume le: "c + a <= c + b"  
  20.694 -  show "a <= b"
  20.695 -  proof (rule ccontr)
  20.696 -    assume w: "~ a \<le> b"
  20.697 -    hence "b <= a" by (simp add: linorder_not_le)
  20.698 -    hence le2: "c + b <= c + a" by (rule add_left_mono)
  20.699 -    have "a = b" 
  20.700 -      apply (insert le)
  20.701 -      apply (insert le2)
  20.702 -      apply (drule antisym, simp_all)
  20.703 -      done
  20.704 -    with w show False 
  20.705 -      by (simp add: linorder_not_le [symmetric])
  20.706 -  qed
  20.707 -qed
  20.708 -
  20.709 -end
  20.710 -
  20.711 -class linordered_ab_group_add = linorder + ordered_ab_group_add
  20.712 -begin
  20.713 -
  20.714 -subclass linordered_cancel_ab_semigroup_add ..
  20.715 -
  20.716 -lemma neg_less_eq_nonneg [simp]:
  20.717 -  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
  20.718 -proof
  20.719 -  assume A: "- a \<le> a" show "0 \<le> a"
  20.720 -  proof (rule classical)
  20.721 -    assume "\<not> 0 \<le> a"
  20.722 -    then have "a < 0" by auto
  20.723 -    with A have "- a < 0" by (rule le_less_trans)
  20.724 -    then show ?thesis by auto
  20.725 -  qed
  20.726 -next
  20.727 -  assume A: "0 \<le> a" show "- a \<le> a"
  20.728 -  proof (rule order_trans)
  20.729 -    show "- a \<le> 0" using A by (simp add: minus_le_iff)
  20.730 -  next
  20.731 -    show "0 \<le> a" using A .
  20.732 -  qed
  20.733 -qed
  20.734 -
  20.735 -lemma neg_less_nonneg [simp]:
  20.736 -  "- a < a \<longleftrightarrow> 0 < a"
  20.737 -proof
  20.738 -  assume A: "- a < a" show "0 < a"
  20.739 -  proof (rule classical)
  20.740 -    assume "\<not> 0 < a"
  20.741 -    then have "a \<le> 0" by auto
  20.742 -    with A have "- a < 0" by (rule less_le_trans)
  20.743 -    then show ?thesis by auto
  20.744 -  qed
  20.745 -next
  20.746 -  assume A: "0 < a" show "- a < a"
  20.747 -  proof (rule less_trans)
  20.748 -    show "- a < 0" using A by (simp add: minus_le_iff)
  20.749 -  next
  20.750 -    show "0 < a" using A .
  20.751 -  qed
  20.752 -qed
  20.753 -
  20.754 -lemma less_eq_neg_nonpos [simp]:
  20.755 -  "a \<le> - a \<longleftrightarrow> a \<le> 0"
  20.756 -proof
  20.757 -  assume A: "a \<le> - a" show "a \<le> 0"
  20.758 -  proof (rule classical)
  20.759 -    assume "\<not> a \<le> 0"
  20.760 -    then have "0 < a" by auto
  20.761 -    then have "0 < - a" using A by (rule less_le_trans)
  20.762 -    then show ?thesis by auto
  20.763 -  qed
  20.764 -next
  20.765 -  assume A: "a \<le> 0" show "a \<le> - a"
  20.766 -  proof (rule order_trans)
  20.767 -    show "0 \<le> - a" using A by (simp add: minus_le_iff)
  20.768 -  next
  20.769 -    show "a \<le> 0" using A .
  20.770 -  qed
  20.771 -qed
  20.772 -
  20.773 -lemma equal_neg_zero [simp]:
  20.774 -  "a = - a \<longleftrightarrow> a = 0"
  20.775 -proof
  20.776 -  assume "a = 0" then show "a = - a" by simp
  20.777 -next
  20.778 -  assume A: "a = - a" show "a = 0"
  20.779 -  proof (cases "0 \<le> a")
  20.780 -    case True with A have "0 \<le> - a" by auto
  20.781 -    with le_minus_iff have "a \<le> 0" by simp
  20.782 -    with True show ?thesis by (auto intro: order_trans)
  20.783 -  next
  20.784 -    case False then have B: "a \<le> 0" by auto
  20.785 -    with A have "- a \<le> 0" by auto
  20.786 -    with B show ?thesis by (auto intro: order_trans)
  20.787 -  qed
  20.788 -qed
  20.789 -
  20.790 -lemma neg_equal_zero [simp]:
  20.791 -  "- a = a \<longleftrightarrow> a = 0"
  20.792 -  by (auto dest: sym)
  20.793 -
  20.794 -lemma double_zero [simp]:
  20.795 -  "a + a = 0 \<longleftrightarrow> a = 0"
  20.796 -proof
  20.797 -  assume assm: "a + a = 0"
  20.798 -  then have a: "- a = a" by (rule minus_unique)
  20.799 -  then show "a = 0" by (simp add: neg_equal_zero)
  20.800 -qed simp
  20.801 -
  20.802 -lemma double_zero_sym [simp]:
  20.803 -  "0 = a + a \<longleftrightarrow> a = 0"
  20.804 -  by (rule, drule sym) simp_all
  20.805 -
  20.806 -lemma zero_less_double_add_iff_zero_less_single_add [simp]:
  20.807 -  "0 < a + a \<longleftrightarrow> 0 < a"
  20.808 -proof
  20.809 -  assume "0 < a + a"
  20.810 -  then have "0 - a < a" by (simp only: diff_less_eq)
  20.811 -  then have "- a < a" by simp
  20.812 -  then show "0 < a" by (simp add: neg_less_nonneg)
  20.813 -next
  20.814 -  assume "0 < a"
  20.815 -  with this have "0 + 0 < a + a"
  20.816 -    by (rule add_strict_mono)
  20.817 -  then show "0 < a + a" by simp
  20.818 -qed
  20.819 -
  20.820 -lemma zero_le_double_add_iff_zero_le_single_add [simp]:
  20.821 -  "0 \<le> a + a \<longleftrightarrow> 0 \<le> a"
  20.822 -  by (auto simp add: le_less)
  20.823 -
  20.824 -lemma double_add_less_zero_iff_single_add_less_zero [simp]:
  20.825 -  "a + a < 0 \<longleftrightarrow> a < 0"
  20.826 -proof -
  20.827 -  have "\<not> a + a < 0 \<longleftrightarrow> \<not> a < 0"
  20.828 -    by (simp add: not_less)
  20.829 -  then show ?thesis by simp
  20.830 -qed
  20.831 -
  20.832 -lemma double_add_le_zero_iff_single_add_le_zero [simp]:
  20.833 -  "a + a \<le> 0 \<longleftrightarrow> a \<le> 0" 
  20.834 -proof -
  20.835 -  have "\<not> a + a \<le> 0 \<longleftrightarrow> \<not> a \<le> 0"
  20.836 -    by (simp add: not_le)
  20.837 -  then show ?thesis by simp
  20.838 -qed
  20.839 -
  20.840 -lemma le_minus_self_iff:
  20.841 -  "a \<le> - a \<longleftrightarrow> a \<le> 0"
  20.842 -proof -
  20.843 -  from add_le_cancel_left [of "- a" "a + a" 0]
  20.844 -  have "a \<le> - a \<longleftrightarrow> a + a \<le> 0" 
  20.845 -    by (simp add: add_assoc [symmetric])
  20.846 -  thus ?thesis by simp
  20.847 -qed
  20.848 -
  20.849 -lemma minus_le_self_iff:
  20.850 -  "- a \<le> a \<longleftrightarrow> 0 \<le> a"
  20.851 -proof -
  20.852 -  from add_le_cancel_left [of "- a" 0 "a + a"]
  20.853 -  have "- a \<le> a \<longleftrightarrow> 0 \<le> a + a" 
  20.854 -    by (simp add: add_assoc [symmetric])
  20.855 -  thus ?thesis by simp
  20.856 -qed
  20.857 -
  20.858 -lemma minus_max_eq_min:
  20.859 -  "- max x y = min (-x) (-y)"
  20.860 -  by (auto simp add: max_def min_def)
  20.861 -
  20.862 -lemma minus_min_eq_max:
  20.863 -  "- min x y = max (-x) (-y)"
  20.864 -  by (auto simp add: max_def min_def)
  20.865 -
  20.866 -end
  20.867 -
  20.868 --- {* FIXME localize the following *}
  20.869 -
  20.870 -lemma add_increasing:
  20.871 -  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
  20.872 -  shows  "[|0\<le>a; b\<le>c|] ==> b \<le> a + c"
  20.873 -by (insert add_mono [of 0 a b c], simp)
  20.874 -
  20.875 -lemma add_increasing2:
  20.876 -  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
  20.877 -  shows  "[|0\<le>c; b\<le>a|] ==> b \<le> a + c"
  20.878 -by (simp add:add_increasing add_commute[of a])
  20.879 -
  20.880 -lemma add_strict_increasing:
  20.881 -  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
  20.882 -  shows "[|0<a; b\<le>c|] ==> b < a + c"
  20.883 -by (insert add_less_le_mono [of 0 a b c], simp)
  20.884 -
  20.885 -lemma add_strict_increasing2:
  20.886 -  fixes c :: "'a::{ordered_ab_semigroup_add_imp_le, comm_monoid_add}"
  20.887 -  shows "[|0\<le>a; b<c|] ==> b < a + c"
  20.888 -by (insert add_le_less_mono [of 0 a b c], simp)
  20.889 -
  20.890 -
  20.891 -class ordered_ab_group_add_abs = ordered_ab_group_add + abs +
  20.892 -  assumes abs_ge_zero [simp]: "\<bar>a\<bar> \<ge> 0"
  20.893 -    and abs_ge_self: "a \<le> \<bar>a\<bar>"
  20.894 -    and abs_leI: "a \<le> b \<Longrightarrow> - a \<le> b \<Longrightarrow> \<bar>a\<bar> \<le> b"
  20.895 -    and abs_minus_cancel [simp]: "\<bar>-a\<bar> = \<bar>a\<bar>"
  20.896 -    and abs_triangle_ineq: "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
  20.897 -begin
  20.898 -
  20.899 -lemma abs_minus_le_zero: "- \<bar>a\<bar> \<le> 0"
  20.900 -  unfolding neg_le_0_iff_le by simp
  20.901 -
  20.902 -lemma abs_of_nonneg [simp]:
  20.903 -  assumes nonneg: "0 \<le> a" shows "\<bar>a\<bar> = a"
  20.904 -proof (rule antisym)
  20.905 -  from nonneg le_imp_neg_le have "- a \<le> 0" by simp
  20.906 -  from this nonneg have "- a \<le> a" by (rule order_trans)
  20.907 -  then show "\<bar>a\<bar> \<le> a" by (auto intro: abs_leI)
  20.908 -qed (rule abs_ge_self)
  20.909 -
  20.910 -lemma abs_idempotent [simp]: "\<bar>\<bar>a\<bar>\<bar> = \<bar>a\<bar>"
  20.911 -by (rule antisym)
  20.912 -   (auto intro!: abs_ge_self abs_leI order_trans [of "uminus (abs a)" zero "abs a"])
  20.913 -
  20.914 -lemma abs_eq_0 [simp]: "\<bar>a\<bar> = 0 \<longleftrightarrow> a = 0"
  20.915 -proof -
  20.916 -  have "\<bar>a\<bar> = 0 \<Longrightarrow> a = 0"
  20.917 -  proof (rule antisym)
  20.918 -    assume zero: "\<bar>a\<bar> = 0"
  20.919 -    with abs_ge_self show "a \<le> 0" by auto
  20.920 -    from zero have "\<bar>-a\<bar> = 0" by simp
  20.921 -    with abs_ge_self [of "uminus a"] have "- a \<le> 0" by auto
  20.922 -    with neg_le_0_iff_le show "0 \<le> a" by auto
  20.923 -  qed
  20.924 -  then show ?thesis by auto
  20.925 -qed
  20.926 -
  20.927 -lemma abs_zero [simp]: "\<bar>0\<bar> = 0"
  20.928 -by simp
  20.929 -
  20.930 -lemma abs_0_eq [simp, noatp]: "0 = \<bar>a\<bar> \<longleftrightarrow> a = 0"
  20.931 -proof -
  20.932 -  have "0 = \<bar>a\<bar> \<longleftrightarrow> \<bar>a\<bar> = 0" by (simp only: eq_ac)
  20.933 -  thus ?thesis by simp
  20.934 -qed
  20.935 -
  20.936 -lemma abs_le_zero_iff [simp]: "\<bar>a\<bar> \<le> 0 \<longleftrightarrow> a = 0" 
  20.937 -proof
  20.938 -  assume "\<bar>a\<bar> \<le> 0"
  20.939 -  then have "\<bar>a\<bar> = 0" by (rule antisym) simp
  20.940 -  thus "a = 0" by simp
  20.941 -next
  20.942 -  assume "a = 0"
  20.943 -  thus "\<bar>a\<bar> \<le> 0" by simp
  20.944 -qed
  20.945 -
  20.946 -lemma zero_less_abs_iff [simp]: "0 < \<bar>a\<bar> \<longleftrightarrow> a \<noteq> 0"
  20.947 -by (simp add: less_le)
  20.948 -
  20.949 -lemma abs_not_less_zero [simp]: "\<not> \<bar>a\<bar> < 0"
  20.950 -proof -
  20.951 -  have a: "\<And>x y. x \<le> y \<Longrightarrow> \<not> y < x" by auto
  20.952 -  show ?thesis by (simp add: a)
  20.953 -qed
  20.954 -
  20.955 -lemma abs_ge_minus_self: "- a \<le> \<bar>a\<bar>"
  20.956 -proof -
  20.957 -  have "- a \<le> \<bar>-a\<bar>" by (rule abs_ge_self)
  20.958 -  then show ?thesis by simp
  20.959 -qed
  20.960 -
  20.961 -lemma abs_minus_commute: 
  20.962 -  "\<bar>a - b\<bar> = \<bar>b - a\<bar>"
  20.963 -proof -
  20.964 -  have "\<bar>a - b\<bar> = \<bar>- (a - b)\<bar>" by (simp only: abs_minus_cancel)
  20.965 -  also have "... = \<bar>b - a\<bar>" by simp
  20.966 -  finally show ?thesis .
  20.967 -qed
  20.968 -
  20.969 -lemma abs_of_pos: "0 < a \<Longrightarrow> \<bar>a\<bar> = a"
  20.970 -by (rule abs_of_nonneg, rule less_imp_le)
  20.971 -
  20.972 -lemma abs_of_nonpos [simp]:
  20.973 -  assumes "a \<le> 0" shows "\<bar>a\<bar> = - a"
  20.974 -proof -
  20.975 -  let ?b = "- a"
  20.976 -  have "- ?b \<le> 0 \<Longrightarrow> \<bar>- ?b\<bar> = - (- ?b)"
  20.977 -  unfolding abs_minus_cancel [of "?b"]
  20.978 -  unfolding neg_le_0_iff_le [of "?b"]
  20.979 -  unfolding minus_minus by (erule abs_of_nonneg)
  20.980 -  then show ?thesis using assms by auto
  20.981 -qed
  20.982 -  
  20.983 -lemma abs_of_neg: "a < 0 \<Longrightarrow> \<bar>a\<bar> = - a"
  20.984 -by (rule abs_of_nonpos, rule less_imp_le)
  20.985 -
  20.986 -lemma abs_le_D1: "\<bar>a\<bar> \<le> b \<Longrightarrow> a \<le> b"
  20.987 -by (insert abs_ge_self, blast intro: order_trans)
  20.988 -
  20.989 -lemma abs_le_D2: "\<bar>a\<bar> \<le> b \<Longrightarrow> - a \<le> b"
  20.990 -by (insert abs_le_D1 [of "uminus a"], simp)
  20.991 -
  20.992 -lemma abs_le_iff: "\<bar>a\<bar> \<le> b \<longleftrightarrow> a \<le> b \<and> - a \<le> b"
  20.993 -by (blast intro: abs_leI dest: abs_le_D1 abs_le_D2)
  20.994 -
  20.995 -lemma abs_triangle_ineq2: "\<bar>a\<bar> - \<bar>b\<bar> \<le> \<bar>a - b\<bar>"
  20.996 -  apply (simp add: algebra_simps)
  20.997 -  apply (subgoal_tac "abs a = abs (plus b (minus a b))")
  20.998 -  apply (erule ssubst)
  20.999 -  apply (rule abs_triangle_ineq)
 20.1000 -  apply (rule arg_cong[of _ _ abs])
 20.1001 -  apply (simp add: algebra_simps)
 20.1002 -done
 20.1003 -
 20.1004 -lemma abs_triangle_ineq3: "\<bar>\<bar>a\<bar> - \<bar>b\<bar>\<bar> \<le> \<bar>a - b\<bar>"
 20.1005 -  apply (subst abs_le_iff)
 20.1006 -  apply auto
 20.1007 -  apply (rule abs_triangle_ineq2)
 20.1008 -  apply (subst abs_minus_commute)
 20.1009 -  apply (rule abs_triangle_ineq2)
 20.1010 -done
 20.1011 -
 20.1012 -lemma abs_triangle_ineq4: "\<bar>a - b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
 20.1013 -proof -
 20.1014 -  have "abs(a - b) = abs(a + - b)" by (subst diff_minus, rule refl)
 20.1015 -  also have "... <= abs a + abs (- b)" by (rule abs_triangle_ineq)
 20.1016 -  finally show ?thesis by simp
 20.1017 -qed
 20.1018 -
 20.1019 -lemma abs_diff_triangle_ineq: "\<bar>a + b - (c + d)\<bar> \<le> \<bar>a - c\<bar> + \<bar>b - d\<bar>"
 20.1020 -proof -
 20.1021 -  have "\<bar>a + b - (c+d)\<bar> = \<bar>(a-c) + (b-d)\<bar>" by (simp add: diff_minus add_ac)
 20.1022 -  also have "... \<le> \<bar>a-c\<bar> + \<bar>b-d\<bar>" by (rule abs_triangle_ineq)
 20.1023 -  finally show ?thesis .
 20.1024 -qed
 20.1025 -
 20.1026 -lemma abs_add_abs [simp]:
 20.1027 -  "\<bar>\<bar>a\<bar> + \<bar>b\<bar>\<bar> = \<bar>a\<bar> + \<bar>b\<bar>" (is "?L = ?R")
 20.1028 -proof (rule antisym)
 20.1029 -  show "?L \<ge> ?R" by(rule abs_ge_self)
 20.1030 -next
 20.1031 -  have "?L \<le> \<bar>\<bar>a\<bar>\<bar> + \<bar>\<bar>b\<bar>\<bar>" by(rule abs_triangle_ineq)
 20.1032 -  also have "\<dots> = ?R" by simp
 20.1033 -  finally show "?L \<le> ?R" .
 20.1034 -qed
 20.1035 -
 20.1036 -end
 20.1037 -
 20.1038 -text {* Needed for abelian cancellation simprocs: *}
 20.1039 -
 20.1040 -lemma add_cancel_21: "((x::'a::ab_group_add) + (y + z) = y + u) = (x + z = u)"
 20.1041 -apply (subst add_left_commute)
 20.1042 -apply (subst add_left_cancel)
 20.1043 -apply simp
 20.1044 -done
 20.1045 -
 20.1046 -lemma add_cancel_end: "(x + (y + z) = y) = (x = - (z::'a::ab_group_add))"
 20.1047 -apply (subst add_cancel_21[of _ _ _ 0, simplified])
 20.1048 -apply (simp add: add_right_cancel[symmetric, of "x" "-z" "z", simplified])
 20.1049 -done
 20.1050 -
 20.1051 -lemma less_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (x < y) = (x' < y')"
 20.1052 -by (simp add: less_iff_diff_less_0[of x y] less_iff_diff_less_0[of x' y'])
 20.1053 -
 20.1054 -lemma le_eqI: "(x::'a::ordered_ab_group_add) - y = x' - y' \<Longrightarrow> (y <= x) = (y' <= x')"
 20.1055 -apply (simp add: le_iff_diff_le_0[of y x] le_iff_diff_le_0[of  y' x'])
 20.1056 -apply (simp add: neg_le_iff_le[symmetric, of "y-x" 0] neg_le_iff_le[symmetric, of "y'-x'" 0])
 20.1057 -done
 20.1058 -
 20.1059 -lemma eq_eqI: "(x::'a::ab_group_add) - y = x' - y' \<Longrightarrow> (x = y) = (x' = y')"
 20.1060 -by (simp only: eq_iff_diff_eq_0[of x y] eq_iff_diff_eq_0[of x' y'])
 20.1061 -
 20.1062 -lemma diff_def: "(x::'a::ab_group_add) - y == x + (-y)"
 20.1063 -by (simp add: diff_minus)
 20.1064 -
 20.1065 -lemma le_add_right_mono: 
 20.1066 -  assumes 
 20.1067 -  "a <= b + (c::'a::ordered_ab_group_add)"
 20.1068 -  "c <= d"    
 20.1069 -  shows "a <= b + d"
 20.1070 -  apply (rule_tac order_trans[where y = "b+c"])
 20.1071 -  apply (simp_all add: prems)
 20.1072 -  done
 20.1073 -
 20.1074 -
 20.1075 -subsection {* Tools setup *}
 20.1076 -
 20.1077 -lemma add_mono_thms_linordered_semiring [noatp]:
 20.1078 -  fixes i j k :: "'a\<Colon>ordered_ab_semigroup_add"
 20.1079 -  shows "i \<le> j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
 20.1080 -    and "i = j \<and> k \<le> l \<Longrightarrow> i + k \<le> j + l"
 20.1081 -    and "i \<le> j \<and> k = l \<Longrightarrow> i + k \<le> j + l"
 20.1082 -    and "i = j \<and> k = l \<Longrightarrow> i + k = j + l"
 20.1083 -by (rule add_mono, clarify+)+
 20.1084 -
 20.1085 -lemma add_mono_thms_linordered_field [noatp]:
 20.1086 -  fixes i j k :: "'a\<Colon>ordered_cancel_ab_semigroup_add"
 20.1087 -  shows "i < j \<and> k = l \<Longrightarrow> i + k < j + l"
 20.1088 -    and "i = j \<and> k < l \<Longrightarrow> i + k < j + l"
 20.1089 -    and "i < j \<and> k \<le> l \<Longrightarrow> i + k < j + l"
 20.1090 -    and "i \<le> j \<and> k < l \<Longrightarrow> i + k < j + l"
 20.1091 -    and "i < j \<and> k < l \<Longrightarrow> i + k < j + l"
 20.1092 -by (auto intro: add_strict_right_mono add_strict_left_mono
 20.1093 -  add_less_le_mono add_le_less_mono add_strict_mono)
 20.1094 -
 20.1095 -text{*Simplification of @{term "x-y < 0"}, etc.*}
 20.1096 -lemmas diff_less_0_iff_less [simp, noatp] = less_iff_diff_less_0 [symmetric]
 20.1097 -lemmas diff_le_0_iff_le [simp, noatp] = le_iff_diff_le_0 [symmetric]
 20.1098 -
 20.1099 -ML {*
 20.1100 -structure ab_group_add_cancel = Abel_Cancel
 20.1101 -(
 20.1102 -
 20.1103 -(* term order for abelian groups *)
 20.1104 -
 20.1105 -fun agrp_ord (Const (a, _)) = find_index (fn a' => a = a')
 20.1106 -      [@{const_name Algebras.zero}, @{const_name Algebras.plus},
 20.1107 -        @{const_name Algebras.uminus}, @{const_name Algebras.minus}]
 20.1108 -  | agrp_ord _ = ~1;
 20.1109 -
 20.1110 -fun termless_agrp (a, b) = (TermOrd.term_lpo agrp_ord (a, b) = LESS);
 20.1111 -
 20.1112 -local
 20.1113 -  val ac1 = mk_meta_eq @{thm add_assoc};
 20.1114 -  val ac2 = mk_meta_eq @{thm add_commute};
 20.1115 -  val ac3 = mk_meta_eq @{thm add_left_commute};
 20.1116 -  fun solve_add_ac thy _ (_ $ (Const (@{const_name Algebras.plus},_) $ _ $ _) $ _) =
 20.1117 -        SOME ac1
 20.1118 -    | solve_add_ac thy _ (_ $ x $ (Const (@{const_name Algebras.plus},_) $ y $ z)) =
 20.1119 -        if termless_agrp (y, x) then SOME ac3 else NONE
 20.1120 -    | solve_add_ac thy _ (_ $ x $ y) =
 20.1121 -        if termless_agrp (y, x) then SOME ac2 else NONE
 20.1122 -    | solve_add_ac thy _ _ = NONE
 20.1123 -in
 20.1124 -  val add_ac_proc = Simplifier.simproc @{theory}
 20.1125 -    "add_ac_proc" ["x + y::'a::ab_semigroup_add"] solve_add_ac;
 20.1126 -end;
 20.1127 -
 20.1128 -val eq_reflection = @{thm eq_reflection};
 20.1129 -  
 20.1130 -val T = @{typ "'a::ab_group_add"};
 20.1131 -
 20.1132 -val cancel_ss = HOL_basic_ss settermless termless_agrp
 20.1133 -  addsimprocs [add_ac_proc] addsimps
 20.1134 -  [@{thm add_0_left}, @{thm add_0_right}, @{thm diff_def},
 20.1135 -   @{thm minus_add_distrib}, @{thm minus_minus}, @{thm minus_zero},
 20.1136 -   @{thm right_minus}, @{thm left_minus}, @{thm add_minus_cancel},
 20.1137 -   @{thm minus_add_cancel}];
 20.1138 -
 20.1139 -val sum_pats = [@{cterm "x + y::'a::ab_group_add"}, @{cterm "x - y::'a::ab_group_add"}];
 20.1140 -  
 20.1141 -val eqI_rules = [@{thm less_eqI}, @{thm le_eqI}, @{thm eq_eqI}];
 20.1142 -
 20.1143 -val dest_eqI = 
 20.1144 -  fst o HOLogic.dest_bin "op =" HOLogic.boolT o HOLogic.dest_Trueprop o concl_of;
 20.1145 -
 20.1146 -);
 20.1147 -*}
 20.1148 -
 20.1149 -ML {*
 20.1150 -  Addsimprocs [ab_group_add_cancel.sum_conv, ab_group_add_cancel.rel_conv];
 20.1151 -*}
 20.1152 -
 20.1153 -code_modulename SML
 20.1154 -  OrderedGroup Arith
 20.1155 -
 20.1156 -code_modulename OCaml
 20.1157 -  OrderedGroup Arith
 20.1158 -
 20.1159 -code_modulename Haskell
 20.1160 -  OrderedGroup Arith
 20.1161 -
 20.1162 -end
    21.1 --- a/src/HOL/PReal.thy	Mon Feb 08 17:12:32 2010 +0100
    21.2 +++ b/src/HOL/PReal.thy	Mon Feb 08 17:12:38 2010 +0100
    21.3 @@ -12,7 +12,7 @@
    21.4  imports Rational 
    21.5  begin
    21.6  
    21.7 -text{*Could be generalized and moved to @{text Ring_and_Field}*}
    21.8 +text{*Could be generalized and moved to @{text Groups}*}
    21.9  lemma add_eq_exists: "\<exists>x. a+x = (b::rat)"
   21.10  by (rule_tac x="b-a" in exI, simp)
   21.11  
    22.1 --- a/src/HOL/Presburger.thy	Mon Feb 08 17:12:32 2010 +0100
    22.2 +++ b/src/HOL/Presburger.thy	Mon Feb 08 17:12:38 2010 +0100
    22.3 @@ -30,8 +30,8 @@
    22.4    "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<le> t) = True"
    22.5    "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x > t) = False"
    22.6    "\<exists>(z ::'a::{linorder}).\<forall>x<z.(x \<ge> t) = False"
    22.7 -  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})<z. (d dvd x + s) = (d dvd x + s)"
    22.8 -  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})<z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
    22.9 +  "\<exists>z.\<forall>(x::'a::{linorder,plus,Rings.dvd})<z. (d dvd x + s) = (d dvd x + s)"
   22.10 +  "\<exists>z.\<forall>(x::'a::{linorder,plus,Rings.dvd})<z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
   22.11    "\<exists>z.\<forall>x<z. F = F"
   22.12    by ((erule exE, erule exE,rule_tac x="min z za" in exI,simp)+, (rule_tac x="t" in exI,fastsimp)+) simp_all
   22.13  
   22.14 @@ -46,8 +46,8 @@
   22.15    "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<le> t) = False"
   22.16    "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x > t) = True"
   22.17    "\<exists>(z ::'a::{linorder}).\<forall>x>z.(x \<ge> t) = True"
   22.18 -  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})>z. (d dvd x + s) = (d dvd x + s)"
   22.19 -  "\<exists>z.\<forall>(x::'a::{linorder,plus,Ring_and_Field.dvd})>z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
   22.20 +  "\<exists>z.\<forall>(x::'a::{linorder,plus,Rings.dvd})>z. (d dvd x + s) = (d dvd x + s)"
   22.21 +  "\<exists>z.\<forall>(x::'a::{linorder,plus,Rings.dvd})>z. (\<not> d dvd x + s) = (\<not> d dvd x + s)"
   22.22    "\<exists>z.\<forall>x>z. F = F"
   22.23    by ((erule exE, erule exE,rule_tac x="max z za" in exI,simp)+,(rule_tac x="t" in exI,fastsimp)+) simp_all
   22.24  
   22.25 @@ -56,8 +56,8 @@
   22.26      \<Longrightarrow> \<forall>x k. (P x \<and> Q x) = (P (x - k*D) \<and> Q (x - k*D))"
   22.27    "\<lbrakk>\<forall>x k. P x = P (x - k*D); \<forall>x k. Q x = Q (x - k*D)\<rbrakk> 
   22.28      \<Longrightarrow> \<forall>x k. (P x \<or> Q x) = (P (x - k*D) \<or> Q (x - k*D))"
   22.29 -  "(d::'a::{comm_ring,Ring_and_Field.dvd}) dvd D \<Longrightarrow> \<forall>x k. (d dvd x + t) = (d dvd (x - k*D) + t)"
   22.30 -  "(d::'a::{comm_ring,Ring_and_Field.dvd}) dvd D \<Longrightarrow> \<forall>x k. (\<not>d dvd x + t) = (\<not>d dvd (x - k*D) + t)"
   22.31 +  "(d::'a::{comm_ring,Rings.dvd}) dvd D \<Longrightarrow> \<forall>x k. (d dvd x + t) = (d dvd (x - k*D) + t)"
   22.32 +  "(d::'a::{comm_ring,Rings.dvd}) dvd D \<Longrightarrow> \<forall>x k. (\<not>d dvd x + t) = (\<not>d dvd (x - k*D) + t)"
   22.33    "\<forall>x k. F = F"
   22.34  apply (auto elim!: dvdE simp add: algebra_simps)
   22.35  unfolding mult_assoc [symmetric] left_distrib [symmetric] left_diff_distrib [symmetric]
   22.36 @@ -243,7 +243,7 @@
   22.37    {fix x
   22.38      have "P x \<longrightarrow> P (x - i * d)" using step.hyps by blast
   22.39      also have "\<dots> \<longrightarrow> P(x - (i + 1) * d)" using minus[THEN spec, of "x - i * d"]
   22.40 -      by (simp add:int_distrib OrderedGroup.diff_diff_eq[symmetric])
   22.41 +      by (simp add: algebra_simps)
   22.42      ultimately have "P x \<longrightarrow> P(x - (i + 1) * d)" by blast}
   22.43    thus ?case ..
   22.44  qed
   22.45 @@ -360,7 +360,7 @@
   22.46  apply(fastsimp)
   22.47  done
   22.48  
   22.49 -theorem unity_coeff_ex: "(\<exists>(x::'a::{semiring_0,Ring_and_Field.dvd}). P (l * x)) \<equiv> (\<exists>x. l dvd (x + 0) \<and> P x)"
   22.50 +theorem unity_coeff_ex: "(\<exists>(x::'a::{semiring_0,Rings.dvd}). P (l * x)) \<equiv> (\<exists>x. l dvd (x + 0) \<and> P x)"
   22.51    apply (rule eq_reflection [symmetric])
   22.52    apply (rule iffI)
   22.53    defer
    23.1 --- a/src/HOL/Probability/Borel.thy	Mon Feb 08 17:12:32 2010 +0100
    23.2 +++ b/src/HOL/Probability/Borel.thy	Mon Feb 08 17:12:38 2010 +0100
    23.3 @@ -355,7 +355,7 @@
    23.4                      borel_measurable_add_borel_measurable f g) 
    23.5    have "(\<lambda>x. -((f x + -g x) ^ 2 * inverse 4)) = 
    23.6          (\<lambda>x. 0 + ((f x + -g x) ^ 2 * inverse -4))"
    23.7 -    by (simp add: Ring_and_Field.minus_divide_right) 
    23.8 +    by (simp add: minus_divide_right) 
    23.9    also have "... \<in> borel_measurable M" 
   23.10      by (fast intro: affine_borel_measurable borel_measurable_square 
   23.11                      borel_measurable_add_borel_measurable 
    24.1 --- a/src/HOL/RealDef.thy	Mon Feb 08 17:12:32 2010 +0100
    24.2 +++ b/src/HOL/RealDef.thy	Mon Feb 08 17:12:38 2010 +0100
    24.3 @@ -521,7 +521,7 @@
    24.4  
    24.5  lemma real_mult_less_iff1 [simp]: "(0::real) < z ==> (x*z < y*z) = (x < y)"
    24.6    by (force elim: order_less_asym
    24.7 -            simp add: Ring_and_Field.mult_less_cancel_right)
    24.8 +            simp add: mult_less_cancel_right)
    24.9  
   24.10  lemma real_mult_le_cancel_iff1 [simp]: "(0::real) < z ==> (x*z \<le> y*z) = (x\<le>y)"
   24.11  apply (simp add: mult_le_cancel_right)
   24.12 @@ -1015,7 +1015,7 @@
   24.13  done
   24.14  
   24.15  
   24.16 -text{*Similar results are proved in @{text Ring_and_Field}*}
   24.17 +text{*Similar results are proved in @{text Fields}*}
   24.18  lemma real_less_half_sum: "x < y ==> x < (x+y) / (2::real)"
   24.19    by auto
   24.20  
   24.21 @@ -1030,7 +1030,7 @@
   24.22  
   24.23  (* FIXME: redundant, but used by Integration/RealRandVar.thy in AFP *)
   24.24  lemma abs_le_interval_iff: "(abs x \<le> r) = (-r\<le>x & x\<le>(r::real))"
   24.25 -by (force simp add: OrderedGroup.abs_le_iff)
   24.26 +by (force simp add: abs_le_iff)
   24.27  
   24.28  lemma abs_add_one_gt_zero [simp]: "(0::real) < 1 + abs(x)"
   24.29  by (simp add: abs_if)
    25.1 --- a/src/HOL/Ring_and_Field.thy	Mon Feb 08 17:12:32 2010 +0100
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,2226 +0,0 @@
    25.4 -(*  Title:      HOL/Ring_and_Field.thy
    25.5 -    Author:     Gertrud Bauer
    25.6 -    Author:     Steven Obua
    25.7 -    Author:     Tobias Nipkow
    25.8 -    Author:     Lawrence C Paulson
    25.9 -    Author:     Markus Wenzel
   25.10 -    Author:     Jeremy Avigad
   25.11 -*)
   25.12 -
   25.13 -header {* (Ordered) Rings and Fields *}
   25.14 -
   25.15 -theory Ring_and_Field
   25.16 -imports OrderedGroup
   25.17 -begin
   25.18 -
   25.19 -text {*
   25.20 -  The theory of partially ordered rings is taken from the books:
   25.21 -  \begin{itemize}
   25.22 -  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
   25.23 -  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
   25.24 -  \end{itemize}
   25.25 -  Most of the used notions can also be looked up in 
   25.26 -  \begin{itemize}
   25.27 -  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
   25.28 -  \item \emph{Algebra I} by van der Waerden, Springer.
   25.29 -  \end{itemize}
   25.30 -*}
   25.31 -
   25.32 -class semiring = ab_semigroup_add + semigroup_mult +
   25.33 -  assumes left_distrib[algebra_simps]: "(a + b) * c = a * c + b * c"
   25.34 -  assumes right_distrib[algebra_simps]: "a * (b + c) = a * b + a * c"
   25.35 -begin
   25.36 -
   25.37 -text{*For the @{text combine_numerals} simproc*}
   25.38 -lemma combine_common_factor:
   25.39 -  "a * e + (b * e + c) = (a + b) * e + c"
   25.40 -by (simp add: left_distrib add_ac)
   25.41 -
   25.42 -end
   25.43 -
   25.44 -class mult_zero = times + zero +
   25.45 -  assumes mult_zero_left [simp]: "0 * a = 0"
   25.46 -  assumes mult_zero_right [simp]: "a * 0 = 0"
   25.47 -
   25.48 -class semiring_0 = semiring + comm_monoid_add + mult_zero
   25.49 -
   25.50 -class semiring_0_cancel = semiring + cancel_comm_monoid_add
   25.51 -begin
   25.52 -
   25.53 -subclass semiring_0
   25.54 -proof
   25.55 -  fix a :: 'a
   25.56 -  have "0 * a + 0 * a = 0 * a + 0" by (simp add: left_distrib [symmetric])
   25.57 -  thus "0 * a = 0" by (simp only: add_left_cancel)
   25.58 -next
   25.59 -  fix a :: 'a
   25.60 -  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: right_distrib [symmetric])
   25.61 -  thus "a * 0 = 0" by (simp only: add_left_cancel)
   25.62 -qed
   25.63 -
   25.64 -end
   25.65 -
   25.66 -class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
   25.67 -  assumes distrib: "(a + b) * c = a * c + b * c"
   25.68 -begin
   25.69 -
   25.70 -subclass semiring
   25.71 -proof
   25.72 -  fix a b c :: 'a
   25.73 -  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
   25.74 -  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
   25.75 -  also have "... = b * a + c * a" by (simp only: distrib)
   25.76 -  also have "... = a * b + a * c" by (simp add: mult_ac)
   25.77 -  finally show "a * (b + c) = a * b + a * c" by blast
   25.78 -qed
   25.79 -
   25.80 -end
   25.81 -
   25.82 -class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
   25.83 -begin
   25.84 -
   25.85 -subclass semiring_0 ..
   25.86 -
   25.87 -end
   25.88 -
   25.89 -class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
   25.90 -begin
   25.91 -
   25.92 -subclass semiring_0_cancel ..
   25.93 -
   25.94 -subclass comm_semiring_0 ..
   25.95 -
   25.96 -end
   25.97 -
   25.98 -class zero_neq_one = zero + one +
   25.99 -  assumes zero_neq_one [simp]: "0 \<noteq> 1"
  25.100 -begin
  25.101 -
  25.102 -lemma one_neq_zero [simp]: "1 \<noteq> 0"
  25.103 -by (rule not_sym) (rule zero_neq_one)
  25.104 -
  25.105 -end
  25.106 -
  25.107 -class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
  25.108 -
  25.109 -text {* Abstract divisibility *}
  25.110 -
  25.111 -class dvd = times
  25.112 -begin
  25.113 -
  25.114 -definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "dvd" 50) where
  25.115 -  [code del]: "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
  25.116 -
  25.117 -lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
  25.118 -  unfolding dvd_def ..
  25.119 -
  25.120 -lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
  25.121 -  unfolding dvd_def by blast 
  25.122 -
  25.123 -end
  25.124 -
  25.125 -class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
  25.126 -  (*previously almost_semiring*)
  25.127 -begin
  25.128 -
  25.129 -subclass semiring_1 ..
  25.130 -
  25.131 -lemma dvd_refl[simp]: "a dvd a"
  25.132 -proof
  25.133 -  show "a = a * 1" by simp
  25.134 -qed
  25.135 -
  25.136 -lemma dvd_trans:
  25.137 -  assumes "a dvd b" and "b dvd c"
  25.138 -  shows "a dvd c"
  25.139 -proof -
  25.140 -  from assms obtain v where "b = a * v" by (auto elim!: dvdE)
  25.141 -  moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
  25.142 -  ultimately have "c = a * (v * w)" by (simp add: mult_assoc)
  25.143 -  then show ?thesis ..
  25.144 -qed
  25.145 -
  25.146 -lemma dvd_0_left_iff [noatp, simp]: "0 dvd a \<longleftrightarrow> a = 0"
  25.147 -by (auto intro: dvd_refl elim!: dvdE)
  25.148 -
  25.149 -lemma dvd_0_right [iff]: "a dvd 0"
  25.150 -proof
  25.151 -  show "0 = a * 0" by simp
  25.152 -qed
  25.153 -
  25.154 -lemma one_dvd [simp]: "1 dvd a"
  25.155 -by (auto intro!: dvdI)
  25.156 -
  25.157 -lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
  25.158 -by (auto intro!: mult_left_commute dvdI elim!: dvdE)
  25.159 -
  25.160 -lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
  25.161 -  apply (subst mult_commute)
  25.162 -  apply (erule dvd_mult)
  25.163 -  done
  25.164 -
  25.165 -lemma dvd_triv_right [simp]: "a dvd b * a"
  25.166 -by (rule dvd_mult) (rule dvd_refl)
  25.167 -
  25.168 -lemma dvd_triv_left [simp]: "a dvd a * b"
  25.169 -by (rule dvd_mult2) (rule dvd_refl)
  25.170 -
  25.171 -lemma mult_dvd_mono:
  25.172 -  assumes "a dvd b"
  25.173 -    and "c dvd d"
  25.174 -  shows "a * c dvd b * d"
  25.175 -proof -
  25.176 -  from `a dvd b` obtain b' where "b = a * b'" ..
  25.177 -  moreover from `c dvd d` obtain d' where "d = c * d'" ..
  25.178 -  ultimately have "b * d = (a * c) * (b' * d')" by (simp add: mult_ac)
  25.179 -  then show ?thesis ..
  25.180 -qed
  25.181 -
  25.182 -lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
  25.183 -by (simp add: dvd_def mult_assoc, blast)
  25.184 -
  25.185 -lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
  25.186 -  unfolding mult_ac [of a] by (rule dvd_mult_left)
  25.187 -
  25.188 -lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
  25.189 -by simp
  25.190 -
  25.191 -lemma dvd_add[simp]:
  25.192 -  assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
  25.193 -proof -
  25.194 -  from `a dvd b` obtain b' where "b = a * b'" ..
  25.195 -  moreover from `a dvd c` obtain c' where "c = a * c'" ..
  25.196 -  ultimately have "b + c = a * (b' + c')" by (simp add: right_distrib)
  25.197 -  then show ?thesis ..
  25.198 -qed
  25.199 -
  25.200 -end
  25.201 -
  25.202 -
  25.203 -class no_zero_divisors = zero + times +
  25.204 -  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
  25.205 -
  25.206 -class semiring_1_cancel = semiring + cancel_comm_monoid_add
  25.207 -  + zero_neq_one + monoid_mult
  25.208 -begin
  25.209 -
  25.210 -subclass semiring_0_cancel ..
  25.211 -
  25.212 -subclass semiring_1 ..
  25.213 -
  25.214 -end
  25.215 -
  25.216 -class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
  25.217 -  + zero_neq_one + comm_monoid_mult
  25.218 -begin
  25.219 -
  25.220 -subclass semiring_1_cancel ..
  25.221 -subclass comm_semiring_0_cancel ..
  25.222 -subclass comm_semiring_1 ..
  25.223 -
  25.224 -end
  25.225 -
  25.226 -class ring = semiring + ab_group_add
  25.227 -begin
  25.228 -
  25.229 -subclass semiring_0_cancel ..
  25.230 -
  25.231 -text {* Distribution rules *}
  25.232 -
  25.233 -lemma minus_mult_left: "- (a * b) = - a * b"
  25.234 -by (rule minus_unique) (simp add: left_distrib [symmetric]) 
  25.235 -
  25.236 -lemma minus_mult_right: "- (a * b) = a * - b"
  25.237 -by (rule minus_unique) (simp add: right_distrib [symmetric]) 
  25.238 -
  25.239 -text{*Extract signs from products*}
  25.240 -lemmas mult_minus_left [simp, noatp] = minus_mult_left [symmetric]
  25.241 -lemmas mult_minus_right [simp,noatp] = minus_mult_right [symmetric]
  25.242 -
  25.243 -lemma minus_mult_minus [simp]: "- a * - b = a * b"
  25.244 -by simp
  25.245 -
  25.246 -lemma minus_mult_commute: "- a * b = a * - b"
  25.247 -by simp
  25.248 -
  25.249 -lemma right_diff_distrib[algebra_simps]: "a * (b - c) = a * b - a * c"
  25.250 -by (simp add: right_distrib diff_minus)
  25.251 -
  25.252 -lemma left_diff_distrib[algebra_simps]: "(a - b) * c = a * c - b * c"
  25.253 -by (simp add: left_distrib diff_minus)
  25.254 -
  25.255 -lemmas ring_distribs[noatp] =
  25.256 -  right_distrib left_distrib left_diff_distrib right_diff_distrib
  25.257 -
  25.258 -text{*Legacy - use @{text algebra_simps} *}
  25.259 -lemmas ring_simps[noatp] = algebra_simps
  25.260 -
  25.261 -lemma eq_add_iff1:
  25.262 -  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
  25.263 -by (simp add: algebra_simps)
  25.264 -
  25.265 -lemma eq_add_iff2:
  25.266 -  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
  25.267 -by (simp add: algebra_simps)
  25.268 -
  25.269 -end
  25.270 -
  25.271 -lemmas ring_distribs[noatp] =
  25.272 -  right_distrib left_distrib left_diff_distrib right_diff_distrib
  25.273 -
  25.274 -class comm_ring = comm_semiring + ab_group_add
  25.275 -begin
  25.276 -
  25.277 -subclass ring ..
  25.278 -subclass comm_semiring_0_cancel ..
  25.279 -
  25.280 -end
  25.281 -
  25.282 -class ring_1 = ring + zero_neq_one + monoid_mult
  25.283 -begin
  25.284 -
  25.285 -subclass semiring_1_cancel ..
  25.286 -
  25.287 -end
  25.288 -
  25.289 -class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
  25.290 -  (*previously ring*)
  25.291 -begin
  25.292 -
  25.293 -subclass ring_1 ..
  25.294 -subclass comm_semiring_1_cancel ..
  25.295 -
  25.296 -lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
  25.297 -proof
  25.298 -  assume "x dvd - y"
  25.299 -  then have "x dvd - 1 * - y" by (rule dvd_mult)
  25.300 -  then show "x dvd y" by simp
  25.301 -next
  25.302 -  assume "x dvd y"
  25.303 -  then have "x dvd - 1 * y" by (rule dvd_mult)
  25.304 -  then show "x dvd - y" by simp
  25.305 -qed
  25.306 -
  25.307 -lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
  25.308 -proof
  25.309 -  assume "- x dvd y"
  25.310 -  then obtain k where "y = - x * k" ..
  25.311 -  then have "y = x * - k" by simp
  25.312 -  then show "x dvd y" ..
  25.313 -next
  25.314 -  assume "x dvd y"
  25.315 -  then obtain k where "y = x * k" ..
  25.316 -  then have "y = - x * - k" by simp
  25.317 -  then show "- x dvd y" ..
  25.318 -qed
  25.319 -
  25.320 -lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
  25.321 -by (simp add: diff_minus dvd_minus_iff)
  25.322 -
  25.323 -end
  25.324 -
  25.325 -class ring_no_zero_divisors = ring + no_zero_divisors
  25.326 -begin
  25.327 -
  25.328 -lemma mult_eq_0_iff [simp]:
  25.329 -  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
  25.330 -proof (cases "a = 0 \<or> b = 0")
  25.331 -  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
  25.332 -    then show ?thesis using no_zero_divisors by simp
  25.333 -next
  25.334 -  case True then show ?thesis by auto
  25.335 -qed
  25.336 -
  25.337 -text{*Cancellation of equalities with a common factor*}
  25.338 -lemma mult_cancel_right [simp, noatp]:
  25.339 -  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
  25.340 -proof -
  25.341 -  have "(a * c = b * c) = ((a - b) * c = 0)"
  25.342 -    by (simp add: algebra_simps right_minus_eq)
  25.343 -  thus ?thesis by (simp add: disj_commute right_minus_eq)
  25.344 -qed
  25.345 -
  25.346 -lemma mult_cancel_left [simp, noatp]:
  25.347 -  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
  25.348 -proof -
  25.349 -  have "(c * a = c * b) = (c * (a - b) = 0)"
  25.350 -    by (simp add: algebra_simps right_minus_eq)
  25.351 -  thus ?thesis by (simp add: right_minus_eq)
  25.352 -qed
  25.353 -
  25.354 -end
  25.355 -
  25.356 -class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
  25.357 -begin
  25.358 -
  25.359 -lemma mult_cancel_right1 [simp]:
  25.360 -  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
  25.361 -by (insert mult_cancel_right [of 1 c b], force)
  25.362 -
  25.363 -lemma mult_cancel_right2 [simp]:
  25.364 -  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
  25.365 -by (insert mult_cancel_right [of a c 1], simp)
  25.366 - 
  25.367 -lemma mult_cancel_left1 [simp]:
  25.368 -  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
  25.369 -by (insert mult_cancel_left [of c 1 b], force)
  25.370 -
  25.371 -lemma mult_cancel_left2 [simp]:
  25.372 -  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
  25.373 -by (insert mult_cancel_left [of c a 1], simp)
  25.374 -
  25.375 -end
  25.376 -
  25.377 -class idom = comm_ring_1 + no_zero_divisors
  25.378 -begin
  25.379 -
  25.380 -subclass ring_1_no_zero_divisors ..
  25.381 -
  25.382 -lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
  25.383 -proof
  25.384 -  assume "a * a = b * b"
  25.385 -  then have "(a - b) * (a + b) = 0"
  25.386 -    by (simp add: algebra_simps)
  25.387 -  then show "a = b \<or> a = - b"
  25.388 -    by (simp add: right_minus_eq eq_neg_iff_add_eq_0)
  25.389 -next
  25.390 -  assume "a = b \<or> a = - b"
  25.391 -  then show "a * a = b * b" by auto
  25.392 -qed
  25.393 -
  25.394 -lemma dvd_mult_cancel_right [simp]:
  25.395 -  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
  25.396 -proof -
  25.397 -  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
  25.398 -    unfolding dvd_def by (simp add: mult_ac)
  25.399 -  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
  25.400 -    unfolding dvd_def by simp
  25.401 -  finally show ?thesis .
  25.402 -qed
  25.403 -
  25.404 -lemma dvd_mult_cancel_left [simp]:
  25.405 -  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
  25.406 -proof -
  25.407 -  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
  25.408 -    unfolding dvd_def by (simp add: mult_ac)
  25.409 -  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
  25.410 -    unfolding dvd_def by simp
  25.411 -  finally show ?thesis .
  25.412 -qed
  25.413 -
  25.414 -end
  25.415 -
  25.416 -class division_ring = ring_1 + inverse +
  25.417 -  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
  25.418 -  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
  25.419 -begin
  25.420 -
  25.421 -subclass ring_1_no_zero_divisors
  25.422 -proof
  25.423 -  fix a b :: 'a
  25.424 -  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
  25.425 -  show "a * b \<noteq> 0"
  25.426 -  proof
  25.427 -    assume ab: "a * b = 0"
  25.428 -    hence "0 = inverse a * (a * b) * inverse b" by simp
  25.429 -    also have "\<dots> = (inverse a * a) * (b * inverse b)"
  25.430 -      by (simp only: mult_assoc)
  25.431 -    also have "\<dots> = 1" using a b by simp
  25.432 -    finally show False by simp
  25.433 -  qed
  25.434 -qed
  25.435 -
  25.436 -lemma nonzero_imp_inverse_nonzero:
  25.437 -  "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
  25.438 -proof
  25.439 -  assume ianz: "inverse a = 0"
  25.440 -  assume "a \<noteq> 0"
  25.441 -  hence "1 = a * inverse a" by simp
  25.442 -  also have "... = 0" by (simp add: ianz)
  25.443 -  finally have "1 = 0" .
  25.444 -  thus False by (simp add: eq_commute)
  25.445 -qed
  25.446 -
  25.447 -lemma inverse_zero_imp_zero:
  25.448 -  "inverse a = 0 \<Longrightarrow> a = 0"
  25.449 -apply (rule classical)
  25.450 -apply (drule nonzero_imp_inverse_nonzero)
  25.451 -apply auto
  25.452 -done
  25.453 -
  25.454 -lemma inverse_unique: 
  25.455 -  assumes ab: "a * b = 1"
  25.456 -  shows "inverse a = b"
  25.457 -proof -
  25.458 -  have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
  25.459 -  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
  25.460 -  ultimately show ?thesis by (simp add: mult_assoc [symmetric])
  25.461 -qed
  25.462 -
  25.463 -lemma nonzero_inverse_minus_eq:
  25.464 -  "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
  25.465 -by (rule inverse_unique) simp
  25.466 -
  25.467 -lemma nonzero_inverse_inverse_eq:
  25.468 -  "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
  25.469 -by (rule inverse_unique) simp
  25.470 -
  25.471 -lemma nonzero_inverse_eq_imp_eq:
  25.472 -  assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
  25.473 -  shows "a = b"
  25.474 -proof -
  25.475 -  from `inverse a = inverse b`
  25.476 -  have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
  25.477 -  with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
  25.478 -    by (simp add: nonzero_inverse_inverse_eq)
  25.479 -qed
  25.480 -
  25.481 -lemma inverse_1 [simp]: "inverse 1 = 1"
  25.482 -by (rule inverse_unique) simp
  25.483 -
  25.484 -lemma nonzero_inverse_mult_distrib: 
  25.485 -  assumes "a \<noteq> 0" and "b \<noteq> 0"
  25.486 -  shows "inverse (a * b) = inverse b * inverse a"
  25.487 -proof -
  25.488 -  have "a * (b * inverse b) * inverse a = 1" using assms by simp
  25.489 -  hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult_assoc)
  25.490 -  thus ?thesis by (rule inverse_unique)
  25.491 -qed
  25.492 -
  25.493 -lemma division_ring_inverse_add:
  25.494 -  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
  25.495 -by (simp add: algebra_simps)
  25.496 -
  25.497 -lemma division_ring_inverse_diff:
  25.498 -  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
  25.499 -by (simp add: algebra_simps)
  25.500 -
  25.501 -end
  25.502 -
  25.503 -class field = comm_ring_1 + inverse +
  25.504 -  assumes field_inverse:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
  25.505 -  assumes divide_inverse: "a / b = a * inverse b"
  25.506 -begin
  25.507 -
  25.508 -subclass division_ring
  25.509 -proof
  25.510 -  fix a :: 'a
  25.511 -  assume "a \<noteq> 0"
  25.512 -  thus "inverse a * a = 1" by (rule field_inverse)
  25.513 -  thus "a * inverse a = 1" by (simp only: mult_commute)
  25.514 -qed
  25.515 -
  25.516 -subclass idom ..
  25.517 -
  25.518 -lemma right_inverse_eq: "b \<noteq> 0 \<Longrightarrow> a / b = 1 \<longleftrightarrow> a = b"
  25.519 -proof
  25.520 -  assume neq: "b \<noteq> 0"
  25.521 -  {
  25.522 -    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
  25.523 -    also assume "a / b = 1"
  25.524 -    finally show "a = b" by simp
  25.525 -  next
  25.526 -    assume "a = b"
  25.527 -    with neq show "a / b = 1" by (simp add: divide_inverse)
  25.528 -  }
  25.529 -qed
  25.530 -
  25.531 -lemma nonzero_inverse_eq_divide: "a \<noteq> 0 \<Longrightarrow> inverse a = 1 / a"
  25.532 -by (simp add: divide_inverse)
  25.533 -
  25.534 -lemma divide_self [simp]: "a \<noteq> 0 \<Longrightarrow> a / a = 1"
  25.535 -by (simp add: divide_inverse)
  25.536 -
  25.537 -lemma divide_zero_left [simp]: "0 / a = 0"
  25.538 -by (simp add: divide_inverse)
  25.539 -
  25.540 -lemma inverse_eq_divide: "inverse a = 1 / a"
  25.541 -by (simp add: divide_inverse)
  25.542 -
  25.543 -lemma add_divide_distrib: "(a+b) / c = a/c + b/c"
  25.544 -by (simp add: divide_inverse algebra_simps)
  25.545 -
  25.546 -text{*There is no slick version using division by zero.*}
  25.547 -lemma inverse_add:
  25.548 -  "[| a \<noteq> 0;  b \<noteq> 0 |]
  25.549 -   ==> inverse a + inverse b = (a + b) * inverse a * inverse b"
  25.550 -by (simp add: division_ring_inverse_add mult_ac)
  25.551 -
  25.552 -lemma nonzero_mult_divide_mult_cancel_left [simp, noatp]:
  25.553 -assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" shows "(c*a)/(c*b) = a/b"
  25.554 -proof -
  25.555 -  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
  25.556 -    by (simp add: divide_inverse nonzero_inverse_mult_distrib)
  25.557 -  also have "... =  a * inverse b * (inverse c * c)"
  25.558 -    by (simp only: mult_ac)
  25.559 -  also have "... =  a * inverse b" by simp
  25.560 -    finally show ?thesis by (simp add: divide_inverse)
  25.561 -qed
  25.562 -
  25.563 -lemma nonzero_mult_divide_mult_cancel_right [simp, noatp]:
  25.564 -  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (b * c) = a / b"
  25.565 -by (simp add: mult_commute [of _ c])
  25.566 -
  25.567 -lemma divide_1 [simp]: "a / 1 = a"
  25.568 -by (simp add: divide_inverse)
  25.569 -
  25.570 -lemma times_divide_eq_right: "a * (b / c) = (a * b) / c"
  25.571 -by (simp add: divide_inverse mult_assoc)
  25.572 -
  25.573 -lemma times_divide_eq_left: "(b / c) * a = (b * a) / c"
  25.574 -by (simp add: divide_inverse mult_ac)
  25.575 -
  25.576 -text {* These are later declared as simp rules. *}
  25.577 -lemmas times_divide_eq [noatp] = times_divide_eq_right times_divide_eq_left
  25.578 -
  25.579 -lemma add_frac_eq:
  25.580 -  assumes "y \<noteq> 0" and "z \<noteq> 0"
  25.581 -  shows "x / y + w / z = (x * z + w * y) / (y * z)"
  25.582 -proof -
  25.583 -  have "x / y + w / z = (x * z) / (y * z) + (y * w) / (y * z)"
  25.584 -    using assms by simp
  25.585 -  also have "\<dots> = (x * z + y * w) / (y * z)"
  25.586 -    by (simp only: add_divide_distrib)
  25.587 -  finally show ?thesis
  25.588 -    by (simp only: mult_commute)
  25.589 -qed
  25.590 -
  25.591 -text{*Special Cancellation Simprules for Division*}
  25.592 -
  25.593 -lemma nonzero_mult_divide_cancel_right [simp, noatp]:
  25.594 -  "b \<noteq> 0 \<Longrightarrow> a * b / b = a"
  25.595 -using nonzero_mult_divide_mult_cancel_right [of 1 b a] by simp
  25.596 -
  25.597 -lemma nonzero_mult_divide_cancel_left [simp, noatp]:
  25.598 -  "a \<noteq> 0 \<Longrightarrow> a * b / a = b"
  25.599 -using nonzero_mult_divide_mult_cancel_left [of 1 a b] by simp
  25.600 -
  25.601 -lemma nonzero_divide_mult_cancel_right [simp, noatp]:
  25.602 -  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> b / (a * b) = 1 / a"
  25.603 -using nonzero_mult_divide_mult_cancel_right [of a b 1] by simp
  25.604 -
  25.605 -lemma nonzero_divide_mult_cancel_left [simp, noatp]:
  25.606 -  "\<lbrakk>a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> a / (a * b) = 1 / b"
  25.607 -using nonzero_mult_divide_mult_cancel_left [of b a 1] by simp
  25.608 -
  25.609 -lemma nonzero_mult_divide_mult_cancel_left2 [simp, noatp]:
  25.610 -  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (c * a) / (b * c) = a / b"
  25.611 -using nonzero_mult_divide_mult_cancel_left [of b c a] by (simp add: mult_ac)
  25.612 -
  25.613 -lemma nonzero_mult_divide_mult_cancel_right2 [simp, noatp]:
  25.614 -  "\<lbrakk>b \<noteq> 0; c \<noteq> 0\<rbrakk> \<Longrightarrow> (a * c) / (c * b) = a / b"
  25.615 -using nonzero_mult_divide_mult_cancel_right [of b c a] by (simp add: mult_ac)
  25.616 -
  25.617 -lemma minus_divide_left: "- (a / b) = (-a) / b"
  25.618 -by (simp add: divide_inverse)
  25.619 -
  25.620 -lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a / b) = a / (- b)"
  25.621 -by (simp add: divide_inverse nonzero_inverse_minus_eq)
  25.622 -
  25.623 -lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a) / (-b) = a / b"
  25.624 -by (simp add: divide_inverse nonzero_inverse_minus_eq)
  25.625 -
  25.626 -lemma divide_minus_left [simp, noatp]: "(-a) / b = - (a / b)"
  25.627 -by (simp add: divide_inverse)
  25.628 -
  25.629 -lemma diff_divide_distrib: "(a - b) / c = a / c - b / c"
  25.630 -by (simp add: diff_minus add_divide_distrib)
  25.631 -
  25.632 -lemma add_divide_eq_iff:
  25.633 -  "z \<noteq> 0 \<Longrightarrow> x + y / z = (z * x + y) / z"
  25.634 -by (simp add: add_divide_distrib)
  25.635 -
  25.636 -lemma divide_add_eq_iff:
  25.637 -  "z \<noteq> 0 \<Longrightarrow> x / z + y = (x + z * y) / z"
  25.638 -by (simp add: add_divide_distrib)
  25.639 -
  25.640 -lemma diff_divide_eq_iff:
  25.641 -  "z \<noteq> 0 \<Longrightarrow> x - y / z = (z * x - y) / z"
  25.642 -by (simp add: diff_divide_distrib)
  25.643 -
  25.644 -lemma divide_diff_eq_iff:
  25.645 -  "z \<noteq> 0 \<Longrightarrow> x / z - y = (x - z * y) / z"
  25.646 -by (simp add: diff_divide_distrib)
  25.647 -
  25.648 -lemma nonzero_eq_divide_eq: "c \<noteq> 0 \<Longrightarrow> a = b / c \<longleftrightarrow> a * c = b"
  25.649 -proof -
  25.650 -  assume [simp]: "c \<noteq> 0"
  25.651 -  have "a = b / c \<longleftrightarrow> a * c = (b / c) * c" by simp
  25.652 -  also have "... \<longleftrightarrow> a * c = b" by (simp add: divide_inverse mult_assoc)
  25.653 -  finally show ?thesis .
  25.654 -qed
  25.655 -
  25.656 -lemma nonzero_divide_eq_eq: "c \<noteq> 0 \<Longrightarrow> b / c = a \<longleftrightarrow> b = a * c"
  25.657 -proof -
  25.658 -  assume [simp]: "c \<noteq> 0"
  25.659 -  have "b / c = a \<longleftrightarrow> (b / c) * c = a * c" by simp
  25.660 -  also have "... \<longleftrightarrow> b = a * c" by (simp add: divide_inverse mult_assoc) 
  25.661 -  finally show ?thesis .
  25.662 -qed
  25.663 -
  25.664 -lemma divide_eq_imp: "c \<noteq> 0 \<Longrightarrow> b = a * c \<Longrightarrow> b / c = a"
  25.665 -by simp
  25.666 -
  25.667 -lemma eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c"
  25.668 -by (erule subst, simp)
  25.669 -
  25.670 -lemmas field_eq_simps[noatp] = algebra_simps
  25.671 -  (* pull / out*)
  25.672 -  add_divide_eq_iff divide_add_eq_iff
  25.673 -  diff_divide_eq_iff divide_diff_eq_iff
  25.674 -  (* multiply eqn *)
  25.675 -  nonzero_eq_divide_eq nonzero_divide_eq_eq
  25.676 -(* is added later:
  25.677 -  times_divide_eq_left times_divide_eq_right
  25.678 -*)
  25.679 -
  25.680 -text{*An example:*}
  25.681 -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"
  25.682 -apply(subgoal_tac "(c-d)*(e-f)*(a-b) \<noteq> 0")
  25.683 - apply(simp add:field_eq_simps)
  25.684 -apply(simp)
  25.685 -done
  25.686 -
  25.687 -lemma diff_frac_eq:
  25.688 -  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> x / y - w / z = (x * z - w * y) / (y * z)"
  25.689 -by (simp add: field_eq_simps times_divide_eq)
  25.690 -
  25.691 -lemma frac_eq_eq:
  25.692 -  "y \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (x / y = w / z) = (x * z = w * y)"
  25.693 -by (simp add: field_eq_simps times_divide_eq)
  25.694 -
  25.695 -end
  25.696 -
  25.697 -class division_by_zero = zero + inverse +
  25.698 -  assumes inverse_zero [simp]: "inverse 0 = 0"
  25.699 -
  25.700 -lemma divide_zero [simp]:
  25.701 -  "a / 0 = (0::'a::{field,division_by_zero})"
  25.702 -by (simp add: divide_inverse)
  25.703 -
  25.704 -lemma divide_self_if [simp]:
  25.705 -  "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
  25.706 -by simp
  25.707 -
  25.708 -class mult_mono = times + zero + ord +
  25.709 -  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
  25.710 -  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
  25.711 -
  25.712 -class ordered_semiring = mult_mono + semiring_0 + ordered_ab_semigroup_add 
  25.713 -begin
  25.714 -
  25.715 -lemma mult_mono:
  25.716 -  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c
  25.717 -     \<Longrightarrow> a * c \<le> b * d"
  25.718 -apply (erule mult_right_mono [THEN order_trans], assumption)
  25.719 -apply (erule mult_left_mono, assumption)
  25.720 -done
  25.721 -
  25.722 -lemma mult_mono':
  25.723 -  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c
  25.724 -     \<Longrightarrow> a * c \<le> b * d"
  25.725 -apply (rule mult_mono)
  25.726 -apply (fast intro: order_trans)+
  25.727 -done
  25.728 -
  25.729 -end
  25.730 -
  25.731 -class ordered_cancel_semiring = mult_mono + ordered_ab_semigroup_add
  25.732 -  + semiring + cancel_comm_monoid_add
  25.733 -begin
  25.734 -
  25.735 -subclass semiring_0_cancel ..
  25.736 -subclass ordered_semiring ..
  25.737 -
  25.738 -lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
  25.739 -using mult_left_mono [of zero b a] by simp
  25.740 -
  25.741 -lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
  25.742 -using mult_left_mono [of b zero a] by simp
  25.743 -
  25.744 -lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
  25.745 -using mult_right_mono [of a zero b] by simp
  25.746 -
  25.747 -text {* Legacy - use @{text mult_nonpos_nonneg} *}
  25.748 -lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
  25.749 -by (drule mult_right_mono [of b zero], auto)
  25.750 -
  25.751 -lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
  25.752 -by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
  25.753 -
  25.754 -end
  25.755 -
  25.756 -class linordered_semiring = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add + mult_mono
  25.757 -begin
  25.758 -
  25.759 -subclass ordered_cancel_semiring ..
  25.760 -
  25.761 -subclass ordered_comm_monoid_add ..
  25.762 -
  25.763 -lemma mult_left_less_imp_less:
  25.764 -  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
  25.765 -by (force simp add: mult_left_mono not_le [symmetric])
  25.766 - 
  25.767 -lemma mult_right_less_imp_less:
  25.768 -  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
  25.769 -by (force simp add: mult_right_mono not_le [symmetric])
  25.770 -
  25.771 -end
  25.772 -
  25.773 -class linordered_semiring_1 = linordered_semiring + semiring_1
  25.774 -
  25.775 -class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
  25.776 -  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
  25.777 -  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
  25.778 -begin
  25.779 -
  25.780 -subclass semiring_0_cancel ..
  25.781 -
  25.782 -subclass linordered_semiring
  25.783 -proof
  25.784 -  fix a b c :: 'a
  25.785 -  assume A: "a \<le> b" "0 \<le> c"
  25.786 -  from A show "c * a \<le> c * b"
  25.787 -    unfolding le_less
  25.788 -    using mult_strict_left_mono by (cases "c = 0") auto
  25.789 -  from A show "a * c \<le> b * c"
  25.790 -    unfolding le_less
  25.791 -    using mult_strict_right_mono by (cases "c = 0") auto
  25.792 -qed
  25.793 -
  25.794 -lemma mult_left_le_imp_le:
  25.795 -  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
  25.796 -by (force simp add: mult_strict_left_mono _not_less [symmetric])
  25.797 - 
  25.798 -lemma mult_right_le_imp_le:
  25.799 -  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
  25.800 -by (force simp add: mult_strict_right_mono not_less [symmetric])
  25.801 -
  25.802 -lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
  25.803 -using mult_strict_left_mono [of zero b a] by simp
  25.804 -
  25.805 -lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
  25.806 -using mult_strict_left_mono [of b zero a] by simp
  25.807 -
  25.808 -lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
  25.809 -using mult_strict_right_mono [of a zero b] by simp
  25.810 -
  25.811 -text {* Legacy - use @{text mult_neg_pos} *}
  25.812 -lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
  25.813 -by (drule mult_strict_right_mono [of b zero], auto)
  25.814 -
  25.815 -lemma zero_less_mult_pos:
  25.816 -  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
  25.817 -apply (cases "b\<le>0")
  25.818 - apply (auto simp add: le_less not_less)
  25.819 -apply (drule_tac mult_pos_neg [of a b])
  25.820 - apply (auto dest: less_not_sym)
  25.821 -done
  25.822 -
  25.823 -lemma zero_less_mult_pos2:
  25.824 -  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
  25.825 -apply (cases "b\<le>0")
  25.826 - apply (auto simp add: le_less not_less)
  25.827 -apply (drule_tac mult_pos_neg2 [of a b])
  25.828 - apply (auto dest: less_not_sym)
  25.829 -done
  25.830 -
  25.831 -text{*Strict monotonicity in both arguments*}
  25.832 -lemma mult_strict_mono:
  25.833 -  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
  25.834 -  shows "a * c < b * d"
  25.835 -  using assms apply (cases "c=0")
  25.836 -  apply (simp add: mult_pos_pos)
  25.837 -  apply (erule mult_strict_right_mono [THEN less_trans])
  25.838 -  apply (force simp add: le_less)
  25.839 -  apply (erule mult_strict_left_mono, assumption)
  25.840 -  done
  25.841 -
  25.842 -text{*This weaker variant has more natural premises*}
  25.843 -lemma mult_strict_mono':
  25.844 -  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
  25.845 -  shows "a * c < b * d"
  25.846 -by (rule mult_strict_mono) (insert assms, auto)
  25.847 -
  25.848 -lemma mult_less_le_imp_less:
  25.849 -  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
  25.850 -  shows "a * c < b * d"
  25.851 -  using assms apply (subgoal_tac "a * c < b * c")
  25.852 -  apply (erule less_le_trans)
  25.853 -  apply (erule mult_left_mono)
  25.854 -  apply simp
  25.855 -  apply (erule mult_strict_right_mono)
  25.856 -  apply assumption
  25.857 -  done
  25.858 -
  25.859 -lemma mult_le_less_imp_less:
  25.860 -  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
  25.861 -  shows "a * c < b * d"
  25.862 -  using assms apply (subgoal_tac "a * c \<le> b * c")
  25.863 -  apply (erule le_less_trans)
  25.864 -  apply (erule mult_strict_left_mono)
  25.865 -  apply simp
  25.866 -  apply (erule mult_right_mono)
  25.867 -  apply simp
  25.868 -  done
  25.869 -
  25.870 -lemma mult_less_imp_less_left:
  25.871 -  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
  25.872 -  shows "a < b"
  25.873 -proof (rule ccontr)
  25.874 -  assume "\<not>  a < b"
  25.875 -  hence "b \<le> a" by (simp add: linorder_not_less)
  25.876 -  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
  25.877 -  with this and less show False by (simp add: not_less [symmetric])
  25.878 -qed
  25.879 -
  25.880 -lemma mult_less_imp_less_right:
  25.881 -  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
  25.882 -  shows "a < b"
  25.883 -proof (rule ccontr)
  25.884 -  assume "\<not> a < b"
  25.885 -  hence "b \<le> a" by (simp add: linorder_not_less)
  25.886 -  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
  25.887 -  with this and less show False by (simp add: not_less [symmetric])
  25.888 -qed  
  25.889 -
  25.890 -end
  25.891 -
  25.892 -class linlinordered_semiring_1_strict = linordered_semiring_strict + semiring_1
  25.893 -
  25.894 -class mult_mono1 = times + zero + ord +
  25.895 -  assumes mult_mono1: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
  25.896 -
  25.897 -class ordered_comm_semiring = comm_semiring_0
  25.898 -  + ordered_ab_semigroup_add + mult_mono1
  25.899 -begin
  25.900 -
  25.901 -subclass ordered_semiring
  25.902 -proof
  25.903 -  fix a b c :: 'a
  25.904 -  assume "a \<le> b" "0 \<le> c"
  25.905 -  thus "c * a \<le> c * b" by (rule mult_mono1)
  25.906 -  thus "a * c \<le> b * c" by (simp only: mult_commute)
  25.907 -qed
  25.908 -
  25.909 -end
  25.910 -
  25.911 -class ordered_cancel_comm_semiring = comm_semiring_0_cancel
  25.912 -  + ordered_ab_semigroup_add + mult_mono1
  25.913 -begin
  25.914 -
  25.915 -subclass ordered_comm_semiring ..
  25.916 -subclass ordered_cancel_semiring ..
  25.917 -
  25.918 -end
  25.919 -
  25.920 -class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
  25.921 -  assumes mult_strict_left_mono_comm: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
  25.922 -begin
  25.923 -
  25.924 -subclass linordered_semiring_strict
  25.925 -proof
  25.926 -  fix a b c :: 'a
  25.927 -  assume "a < b" "0 < c"
  25.928 -  thus "c * a < c * b" by (rule mult_strict_left_mono_comm)
  25.929 -  thus "a * c < b * c" by (simp only: mult_commute)
  25.930 -qed
  25.931 -
  25.932 -subclass ordered_cancel_comm_semiring
  25.933 -proof
  25.934 -  fix a b c :: 'a
  25.935 -  assume "a \<le> b" "0 \<le> c"
  25.936 -  thus "c * a \<le> c * b"
  25.937 -    unfolding le_less
  25.938 -    using mult_strict_left_mono by (cases "c = 0") auto
  25.939 -qed
  25.940 -
  25.941 -end
  25.942 -
  25.943 -class ordered_ring = ring + ordered_cancel_semiring 
  25.944 -begin
  25.945 -
  25.946 -subclass ordered_ab_group_add ..
  25.947 -
  25.948 -text{*Legacy - use @{text algebra_simps} *}
  25.949 -lemmas ring_simps[noatp] = algebra_simps
  25.950 -
  25.951 -lemma less_add_iff1:
  25.952 -  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
  25.953 -by (simp add: algebra_simps)
  25.954 -
  25.955 -lemma less_add_iff2:
  25.956 -  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
  25.957 -by (simp add: algebra_simps)
  25.958 -
  25.959 -lemma le_add_iff1:
  25.960 -  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
  25.961 -by (simp add: algebra_simps)
  25.962 -
  25.963 -lemma le_add_iff2:
  25.964 -  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
  25.965 -by (simp add: algebra_simps)
  25.966 -
  25.967 -lemma mult_left_mono_neg:
  25.968 -  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
  25.969 -  apply (drule mult_left_mono [of _ _ "uminus c"])
  25.970 -  apply (simp_all add: minus_mult_left [symmetric]) 
  25.971 -  done
  25.972 -
  25.973 -lemma mult_right_mono_neg:
  25.974 -  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
  25.975 -  apply (drule mult_right_mono [of _ _ "uminus c"])
  25.976 -  apply (simp_all add: minus_mult_right [symmetric]) 
  25.977 -  done
  25.978 -
  25.979 -lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
  25.980 -using mult_right_mono_neg [of a zero b] by simp
  25.981 -
  25.982 -lemma split_mult_pos_le:
  25.983 -  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
  25.984 -by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
  25.985 -
  25.986 -end
  25.987 -
  25.988 -class abs_if = minus + uminus + ord + zero + abs +
  25.989 -  assumes abs_if: "\<bar>a\<bar> = (if a < 0 then - a else a)"
  25.990 -
  25.991 -class sgn_if = minus + uminus + zero + one + ord + sgn +
  25.992 -  assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
  25.993 -
  25.994 -lemma (in sgn_if) sgn0[simp]: "sgn 0 = 0"
  25.995 -by(simp add:sgn_if)
  25.996 -
  25.997 -class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
  25.998 -begin
  25.999 -
 25.1000 -subclass ordered_ring ..
 25.1001 -
 25.1002 -subclass ordered_ab_group_add_abs
 25.1003 -proof
 25.1004 -  fix a b
 25.1005 -  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
 25.1006 -    by (auto simp add: abs_if not_less neg_less_eq_nonneg less_eq_neg_nonpos)
 25.1007 -    (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric]
 25.1008 -     neg_less_eq_nonneg less_eq_neg_nonpos, auto intro: add_nonneg_nonneg,
 25.1009 -      auto intro!: less_imp_le add_neg_neg)
 25.1010 -qed (auto simp add: abs_if less_eq_neg_nonpos neg_equal_zero)
 25.1011 -
 25.1012 -end
 25.1013 -
 25.1014 -(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
 25.1015 -   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
 25.1016 - *)
 25.1017 -class linordered_ring_strict = ring + linordered_semiring_strict
 25.1018 -  + ordered_ab_group_add + abs_if
 25.1019 -begin
 25.1020 -
 25.1021 -subclass linordered_ring ..
 25.1022 -
 25.1023 -lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
 25.1024 -using mult_strict_left_mono [of b a "- c"] by simp
 25.1025 -
 25.1026 -lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
 25.1027 -using mult_strict_right_mono [of b a "- c"] by simp
 25.1028 -
 25.1029 -lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
 25.1030 -using mult_strict_right_mono_neg [of a zero b] by simp
 25.1031 -
 25.1032 -subclass ring_no_zero_divisors
 25.1033 -proof
 25.1034 -  fix a b
 25.1035 -  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
 25.1036 -  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
 25.1037 -  have "a * b < 0 \<or> 0 < a * b"
 25.1038 -  proof (cases "a < 0")
 25.1039 -    case True note A' = this
 25.1040 -    show ?thesis proof (cases "b < 0")
 25.1041 -      case True with A'
 25.1042 -      show ?thesis by (auto dest: mult_neg_neg)
 25.1043 -    next
 25.1044 -      case False with B have "0 < b" by auto
 25.1045 -      with A' show ?thesis by (auto dest: mult_strict_right_mono)
 25.1046 -    qed
 25.1047 -  next
 25.1048 -    case False with A have A': "0 < a" by auto
 25.1049 -    show ?thesis proof (cases "b < 0")
 25.1050 -      case True with A'
 25.1051 -      show ?thesis by (auto dest: mult_strict_right_mono_neg)
 25.1052 -    next
 25.1053 -      case False with B have "0 < b" by auto
 25.1054 -      with A' show ?thesis by (auto dest: mult_pos_pos)
 25.1055 -    qed
 25.1056 -  qed
 25.1057 -  then show "a * b \<noteq> 0" by (simp add: neq_iff)
 25.1058 -qed
 25.1059 -
 25.1060 -lemma zero_less_mult_iff:
 25.1061 -  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
 25.1062 -  apply (auto simp add: mult_pos_pos mult_neg_neg)
 25.1063 -  apply (simp_all add: not_less le_less)
 25.1064 -  apply (erule disjE) apply assumption defer
 25.1065 -  apply (erule disjE) defer apply (drule sym) apply simp
 25.1066 -  apply (erule disjE) defer apply (drule sym) apply simp
 25.1067 -  apply (erule disjE) apply assumption apply (drule sym) apply simp
 25.1068 -  apply (drule sym) apply simp
 25.1069 -  apply (blast dest: zero_less_mult_pos)
 25.1070 -  apply (blast dest: zero_less_mult_pos2)
 25.1071 -  done
 25.1072 -
 25.1073 -lemma zero_le_mult_iff:
 25.1074 -  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
 25.1075 -by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
 25.1076 -
 25.1077 -lemma mult_less_0_iff:
 25.1078 -  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
 25.1079 -  apply (insert zero_less_mult_iff [of "-a" b]) 
 25.1080 -  apply (force simp add: minus_mult_left[symmetric]) 
 25.1081 -  done
 25.1082 -
 25.1083 -lemma mult_le_0_iff:
 25.1084 -  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
 25.1085 -  apply (insert zero_le_mult_iff [of "-a" b]) 
 25.1086 -  apply (force simp add: minus_mult_left[symmetric]) 
 25.1087 -  done
 25.1088 -
 25.1089 -lemma zero_le_square [simp]: "0 \<le> a * a"
 25.1090 -by (simp add: zero_le_mult_iff linear)
 25.1091 -
 25.1092 -lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
 25.1093 -by (simp add: not_less)
 25.1094 -
 25.1095 -text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
 25.1096 -   also with the relations @{text "\<le>"} and equality.*}
 25.1097 -
 25.1098 -text{*These ``disjunction'' versions produce two cases when the comparison is
 25.1099 - an assumption, but effectively four when the comparison is a goal.*}
 25.1100 -
 25.1101 -lemma mult_less_cancel_right_disj:
 25.1102 -  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
 25.1103 -  apply (cases "c = 0")
 25.1104 -  apply (auto simp add: neq_iff mult_strict_right_mono 
 25.1105 -                      mult_strict_right_mono_neg)
 25.1106 -  apply (auto simp add: not_less 
 25.1107 -                      not_le [symmetric, of "a*c"]
 25.1108 -                      not_le [symmetric, of a])
 25.1109 -  apply (erule_tac [!] notE)
 25.1110 -  apply (auto simp add: less_imp_le mult_right_mono 
 25.1111 -                      mult_right_mono_neg)
 25.1112 -  done
 25.1113 -
 25.1114 -lemma mult_less_cancel_left_disj:
 25.1115 -  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
 25.1116 -  apply (cases "c = 0")
 25.1117 -  apply (auto simp add: neq_iff mult_strict_left_mono 
 25.1118 -                      mult_strict_left_mono_neg)
 25.1119 -  apply (auto simp add: not_less 
 25.1120 -                      not_le [symmetric, of "c*a"]
 25.1121 -                      not_le [symmetric, of a])
 25.1122 -  apply (erule_tac [!] notE)
 25.1123 -  apply (auto simp add: less_imp_le mult_left_mono 
 25.1124 -                      mult_left_mono_neg)
 25.1125 -  done
 25.1126 -
 25.1127 -text{*The ``conjunction of implication'' lemmas produce two cases when the
 25.1128 -comparison is a goal, but give four when the comparison is an assumption.*}
 25.1129 -
 25.1130 -lemma mult_less_cancel_right:
 25.1131 -  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
 25.1132 -  using mult_less_cancel_right_disj [of a c b] by auto
 25.1133 -
 25.1134 -lemma mult_less_cancel_left:
 25.1135 -  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
 25.1136 -  using mult_less_cancel_left_disj [of c a b] by auto
 25.1137 -
 25.1138 -lemma mult_le_cancel_right:
 25.1139 -   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
 25.1140 -by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
 25.1141 -
 25.1142 -lemma mult_le_cancel_left:
 25.1143 -  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
 25.1144 -by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
 25.1145 -
 25.1146 -lemma mult_le_cancel_left_pos:
 25.1147 -  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
 25.1148 -by (auto simp: mult_le_cancel_left)
 25.1149 -
 25.1150 -lemma mult_le_cancel_left_neg:
 25.1151 -  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
 25.1152 -by (auto simp: mult_le_cancel_left)
 25.1153 -
 25.1154 -lemma mult_less_cancel_left_pos:
 25.1155 -  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
 25.1156 -by (auto simp: mult_less_cancel_left)
 25.1157 -
 25.1158 -lemma mult_less_cancel_left_neg:
 25.1159 -  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
 25.1160 -by (auto simp: mult_less_cancel_left)
 25.1161 -
 25.1162 -end
 25.1163 -
 25.1164 -text{*Legacy - use @{text algebra_simps} *}
 25.1165 -lemmas ring_simps[noatp] = algebra_simps
 25.1166 -
 25.1167 -lemmas mult_sign_intros =
 25.1168 -  mult_nonneg_nonneg mult_nonneg_nonpos
 25.1169 -  mult_nonpos_nonneg mult_nonpos_nonpos
 25.1170 -  mult_pos_pos mult_pos_neg
 25.1171 -  mult_neg_pos mult_neg_neg
 25.1172 -
 25.1173 -class ordered_comm_ring = comm_ring + ordered_comm_semiring
 25.1174 -begin
 25.1175 -
 25.1176 -subclass ordered_ring ..
 25.1177 -subclass ordered_cancel_comm_semiring ..
 25.1178 -
 25.1179 -end
 25.1180 -
 25.1181 -class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
 25.1182 -  (*previously linordered_semiring*)
 25.1183 -  assumes zero_less_one [simp]: "0 < 1"
 25.1184 -begin
 25.1185 -
 25.1186 -lemma pos_add_strict:
 25.1187 -  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
 25.1188 -  using add_strict_mono [of zero a b c] by simp
 25.1189 -
 25.1190 -lemma zero_le_one [simp]: "0 \<le> 1"
 25.1191 -by (rule zero_less_one [THEN less_imp_le]) 
 25.1192 -
 25.1193 -lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
 25.1194 -by (simp add: not_le) 
 25.1195 -
 25.1196 -lemma not_one_less_zero [simp]: "\<not> 1 < 0"
 25.1197 -by (simp add: not_less) 
 25.1198 -
 25.1199 -lemma less_1_mult:
 25.1200 -  assumes "1 < m" and "1 < n"
 25.1201 -  shows "1 < m * n"
 25.1202 -  using assms mult_strict_mono [of 1 m 1 n]
 25.1203 -    by (simp add:  less_trans [OF zero_less_one]) 
 25.1204 -
 25.1205 -end
 25.1206 -
 25.1207 -class linordered_idom = comm_ring_1 +
 25.1208 -  linordered_comm_semiring_strict + ordered_ab_group_add +
 25.1209 -  abs_if + sgn_if
 25.1210 -  (*previously linordered_ring*)
 25.1211 -begin
 25.1212 -
 25.1213 -subclass linordered_ring_strict ..
 25.1214 -subclass ordered_comm_ring ..
 25.1215 -subclass idom ..
 25.1216 -
 25.1217 -subclass linordered_semidom
 25.1218 -proof
 25.1219 -  have "0 \<le> 1 * 1" by (rule zero_le_square)
 25.1220 -  thus "0 < 1" by (simp add: le_less)
 25.1221 -qed 
 25.1222 -
 25.1223 -lemma linorder_neqE_linordered_idom:
 25.1224 -  assumes "x \<noteq> y" obtains "x < y" | "y < x"
 25.1225 -  using assms by (rule neqE)
 25.1226 -
 25.1227 -text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
 25.1228 -
 25.1229 -lemma mult_le_cancel_right1:
 25.1230 -  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
 25.1231 -by (insert mult_le_cancel_right [of 1 c b], simp)
 25.1232 -
 25.1233 -lemma mult_le_cancel_right2:
 25.1234 -  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
 25.1235 -by (insert mult_le_cancel_right [of a c 1], simp)
 25.1236 -
 25.1237 -lemma mult_le_cancel_left1:
 25.1238 -  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
 25.1239 -by (insert mult_le_cancel_left [of c 1 b], simp)
 25.1240 -
 25.1241 -lemma mult_le_cancel_left2:
 25.1242 -  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
 25.1243 -by (insert mult_le_cancel_left [of c a 1], simp)
 25.1244 -
 25.1245 -lemma mult_less_cancel_right1:
 25.1246 -  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
 25.1247 -by (insert mult_less_cancel_right [of 1 c b], simp)
 25.1248 -
 25.1249 -lemma mult_less_cancel_right2:
 25.1250 -  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
 25.1251 -by (insert mult_less_cancel_right [of a c 1], simp)
 25.1252 -
 25.1253 -lemma mult_less_cancel_left1:
 25.1254 -  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
 25.1255 -by (insert mult_less_cancel_left [of c 1 b], simp)
 25.1256 -
 25.1257 -lemma mult_less_cancel_left2:
 25.1258 -  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
 25.1259 -by (insert mult_less_cancel_left [of c a 1], simp)
 25.1260 -
 25.1261 -lemma sgn_sgn [simp]:
 25.1262 -  "sgn (sgn a) = sgn a"
 25.1263 -unfolding sgn_if by simp
 25.1264 -
 25.1265 -lemma sgn_0_0:
 25.1266 -  "sgn a = 0 \<longleftrightarrow> a = 0"
 25.1267 -unfolding sgn_if by simp
 25.1268 -
 25.1269 -lemma sgn_1_pos:
 25.1270 -  "sgn a = 1 \<longleftrightarrow> a > 0"
 25.1271 -unfolding sgn_if by (simp add: neg_equal_zero)
 25.1272 -
 25.1273 -lemma sgn_1_neg:
 25.1274 -  "sgn a = - 1 \<longleftrightarrow> a < 0"
 25.1275 -unfolding sgn_if by (auto simp add: equal_neg_zero)
 25.1276 -
 25.1277 -lemma sgn_pos [simp]:
 25.1278 -  "0 < a \<Longrightarrow> sgn a = 1"
 25.1279 -unfolding sgn_1_pos .
 25.1280 -
 25.1281 -lemma sgn_neg [simp]:
 25.1282 -  "a < 0 \<Longrightarrow> sgn a = - 1"
 25.1283 -unfolding sgn_1_neg .
 25.1284 -
 25.1285 -lemma sgn_times:
 25.1286 -  "sgn (a * b) = sgn a * sgn b"
 25.1287 -by (auto simp add: sgn_if zero_less_mult_iff)
 25.1288 -
 25.1289 -lemma abs_sgn: "abs k = k * sgn k"
 25.1290 -unfolding sgn_if abs_if by auto
 25.1291 -
 25.1292 -lemma sgn_greater [simp]:
 25.1293 -  "0 < sgn a \<longleftrightarrow> 0 < a"
 25.1294 -  unfolding sgn_if by auto
 25.1295 -
 25.1296 -lemma sgn_less [simp]:
 25.1297 -  "sgn a < 0 \<longleftrightarrow> a < 0"
 25.1298 -  unfolding sgn_if by auto
 25.1299 -
 25.1300 -lemma abs_dvd_iff [simp]: "(abs m) dvd k \<longleftrightarrow> m dvd k"
 25.1301 -  by (simp add: abs_if)
 25.1302 -
 25.1303 -lemma dvd_abs_iff [simp]: "m dvd (abs k) \<longleftrightarrow> m dvd k"
 25.1304 -  by (simp add: abs_if)
 25.1305 -
 25.1306 -lemma dvd_if_abs_eq:
 25.1307 -  "abs l = abs (k) \<Longrightarrow> l dvd k"
 25.1308 -by(subst abs_dvd_iff[symmetric]) simp
 25.1309 -
 25.1310 -end
 25.1311 -
 25.1312 -class linordered_field = field + linordered_idom
 25.1313 -
 25.1314 -text {* Simprules for comparisons where common factors can be cancelled. *}
 25.1315 -
 25.1316 -lemmas mult_compare_simps[noatp] =
 25.1317 -    mult_le_cancel_right mult_le_cancel_left
 25.1318 -    mult_le_cancel_right1 mult_le_cancel_right2
 25.1319 -    mult_le_cancel_left1 mult_le_cancel_left2
 25.1320 -    mult_less_cancel_right mult_less_cancel_left
 25.1321 -    mult_less_cancel_right1 mult_less_cancel_right2
 25.1322 -    mult_less_cancel_left1 mult_less_cancel_left2
 25.1323 -    mult_cancel_right mult_cancel_left
 25.1324 -    mult_cancel_right1 mult_cancel_right2
 25.1325 -    mult_cancel_left1 mult_cancel_left2
 25.1326 -
 25.1327 --- {* FIXME continue localization here *}
 25.1328 -
 25.1329 -lemma inverse_nonzero_iff_nonzero [simp]:
 25.1330 -   "(inverse a = 0) = (a = (0::'a::{division_ring,division_by_zero}))"
 25.1331 -by (force dest: inverse_zero_imp_zero) 
 25.1332 -
 25.1333 -lemma inverse_minus_eq [simp]:
 25.1334 -   "inverse(-a) = -inverse(a::'a::{division_ring,division_by_zero})"
 25.1335 -proof cases
 25.1336 -  assume "a=0" thus ?thesis by (simp add: inverse_zero)
 25.1337 -next
 25.1338 -  assume "a\<noteq>0" 
 25.1339 -  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
 25.1340 -qed
 25.1341 -
 25.1342 -lemma inverse_eq_imp_eq:
 25.1343 -  "inverse a = inverse b ==> a = (b::'a::{division_ring,division_by_zero})"
 25.1344 -apply (cases "a=0 | b=0") 
 25.1345 - apply (force dest!: inverse_zero_imp_zero
 25.1346 -              simp add: eq_commute [of "0::'a"])
 25.1347 -apply (force dest!: nonzero_inverse_eq_imp_eq) 
 25.1348 -done
 25.1349 -
 25.1350 -lemma inverse_eq_iff_eq [simp]:
 25.1351 -  "(inverse a = inverse b) = (a = (b::'a::{division_ring,division_by_zero}))"
 25.1352 -by (force dest!: inverse_eq_imp_eq)
 25.1353 -
 25.1354 -lemma inverse_inverse_eq [simp]:
 25.1355 -     "inverse(inverse (a::'a::{division_ring,division_by_zero})) = a"
 25.1356 -  proof cases
 25.1357 -    assume "a=0" thus ?thesis by simp
 25.1358 -  next
 25.1359 -    assume "a\<noteq>0" 
 25.1360 -    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
 25.1361 -  qed
 25.1362 -
 25.1363 -text{*This version builds in division by zero while also re-orienting
 25.1364 -      the right-hand side.*}
 25.1365 -lemma inverse_mult_distrib [simp]:
 25.1366 -     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
 25.1367 -  proof cases
 25.1368 -    assume "a \<noteq> 0 & b \<noteq> 0" 
 25.1369 -    thus ?thesis by (simp add: nonzero_inverse_mult_distrib mult_commute)
 25.1370 -  next
 25.1371 -    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
 25.1372 -    thus ?thesis by force
 25.1373 -  qed
 25.1374 -
 25.1375 -lemma inverse_divide [simp]:
 25.1376 -  "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
 25.1377 -by (simp add: divide_inverse mult_commute)
 25.1378 -
 25.1379 -
 25.1380 -subsection {* Calculations with fractions *}
 25.1381 -
 25.1382 -text{* There is a whole bunch of simp-rules just for class @{text
 25.1383 -field} but none for class @{text field} and @{text nonzero_divides}
 25.1384 -because the latter are covered by a simproc. *}
 25.1385 -
 25.1386 -lemma mult_divide_mult_cancel_left:
 25.1387 -  "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
 25.1388 -apply (cases "b = 0")
 25.1389 -apply (simp_all add: nonzero_mult_divide_mult_cancel_left)
 25.1390 -done
 25.1391 -
 25.1392 -lemma mult_divide_mult_cancel_right:
 25.1393 -  "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
 25.1394 -apply (cases "b = 0")
 25.1395 -apply (simp_all add: nonzero_mult_divide_mult_cancel_right)
 25.1396 -done
 25.1397 -
 25.1398 -lemma divide_divide_eq_right [simp,noatp]:
 25.1399 -  "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
 25.1400 -by (simp add: divide_inverse mult_ac)
 25.1401 -
 25.1402 -lemma divide_divide_eq_left [simp,noatp]:
 25.1403 -  "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
 25.1404 -by (simp add: divide_inverse mult_assoc)
 25.1405 -
 25.1406 -
 25.1407 -subsubsection{*Special Cancellation Simprules for Division*}
 25.1408 -
 25.1409 -lemma mult_divide_mult_cancel_left_if[simp,noatp]:
 25.1410 -fixes c :: "'a :: {field,division_by_zero}"
 25.1411 -shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
 25.1412 -by (simp add: mult_divide_mult_cancel_left)
 25.1413 -
 25.1414 -
 25.1415 -subsection {* Division and Unary Minus *}
 25.1416 -
 25.1417 -lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
 25.1418 -by (simp add: divide_inverse)
 25.1419 -
 25.1420 -lemma divide_minus_right [simp, noatp]:
 25.1421 -  "a / -(b::'a::{field,division_by_zero}) = -(a / b)"
 25.1422 -by (simp add: divide_inverse)
 25.1423 -
 25.1424 -lemma minus_divide_divide:
 25.1425 -  "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
 25.1426 -apply (cases "b=0", simp) 
 25.1427 -apply (simp add: nonzero_minus_divide_divide) 
 25.1428 -done
 25.1429 -
 25.1430 -lemma eq_divide_eq:
 25.1431 -  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
 25.1432 -by (simp add: nonzero_eq_divide_eq)
 25.1433 -
 25.1434 -lemma divide_eq_eq:
 25.1435 -  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
 25.1436 -by (force simp add: nonzero_divide_eq_eq)
 25.1437 -
 25.1438 -
 25.1439 -subsection {* Ordered Fields *}
 25.1440 -
 25.1441 -lemma positive_imp_inverse_positive: 
 25.1442 -assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::linordered_field)"
 25.1443 -proof -
 25.1444 -  have "0 < a * inverse a" 
 25.1445 -    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
 25.1446 -  thus "0 < inverse a" 
 25.1447 -    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
 25.1448 -qed
 25.1449 -
 25.1450 -lemma negative_imp_inverse_negative:
 25.1451 -  "a < 0 ==> inverse a < (0::'a::linordered_field)"
 25.1452 -by (insert positive_imp_inverse_positive [of "-a"], 
 25.1453 -    simp add: nonzero_inverse_minus_eq order_less_imp_not_eq)
 25.1454 -
 25.1455 -lemma inverse_le_imp_le:
 25.1456 -assumes invle: "inverse a \<le> inverse b" and apos:  "0 < a"
 25.1457 -shows "b \<le> (a::'a::linordered_field)"
 25.1458 -proof (rule classical)
 25.1459 -  assume "~ b \<le> a"
 25.1460 -  hence "a < b"  by (simp add: linorder_not_le)
 25.1461 -  hence bpos: "0 < b"  by (blast intro: apos order_less_trans)
 25.1462 -  hence "a * inverse a \<le> a * inverse b"
 25.1463 -    by (simp add: apos invle order_less_imp_le mult_left_mono)
 25.1464 -  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
 25.1465 -    by (simp add: bpos order_less_imp_le mult_right_mono)
 25.1466 -  thus "b \<le> a"  by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
 25.1467 -qed
 25.1468 -
 25.1469 -lemma inverse_positive_imp_positive:
 25.1470 -assumes inv_gt_0: "0 < inverse a" and nz: "a \<noteq> 0"
 25.1471 -shows "0 < (a::'a::linordered_field)"
 25.1472 -proof -
 25.1473 -  have "0 < inverse (inverse a)"
 25.1474 -    using inv_gt_0 by (rule positive_imp_inverse_positive)
 25.1475 -  thus "0 < a"
 25.1476 -    using nz by (simp add: nonzero_inverse_inverse_eq)
 25.1477 -qed
 25.1478 -
 25.1479 -lemma inverse_positive_iff_positive [simp]:
 25.1480 -  "(0 < inverse a) = (0 < (a::'a::{linordered_field,division_by_zero}))"
 25.1481 -apply (cases "a = 0", simp)
 25.1482 -apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
 25.1483 -done
 25.1484 -
 25.1485 -lemma inverse_negative_imp_negative:
 25.1486 -assumes inv_less_0: "inverse a < 0" and nz:  "a \<noteq> 0"
 25.1487 -shows "a < (0::'a::linordered_field)"
 25.1488 -proof -
 25.1489 -  have "inverse (inverse a) < 0"
 25.1490 -    using inv_less_0 by (rule negative_imp_inverse_negative)
 25.1491 -  thus "a < 0" using nz by (simp add: nonzero_inverse_inverse_eq)
 25.1492 -qed
 25.1493 -
 25.1494 -lemma inverse_negative_iff_negative [simp]:
 25.1495 -  "(inverse a < 0) = (a < (0::'a::{linordered_field,division_by_zero}))"
 25.1496 -apply (cases "a = 0", simp)
 25.1497 -apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
 25.1498 -done
 25.1499 -
 25.1500 -lemma inverse_nonnegative_iff_nonnegative [simp]:
 25.1501 -  "(0 \<le> inverse a) = (0 \<le> (a::'a::{linordered_field,division_by_zero}))"
 25.1502 -by (simp add: linorder_not_less [symmetric])
 25.1503 -
 25.1504 -lemma inverse_nonpositive_iff_nonpositive [simp]:
 25.1505 -  "(inverse a \<le> 0) = (a \<le> (0::'a::{linordered_field,division_by_zero}))"
 25.1506 -by (simp add: linorder_not_less [symmetric])
 25.1507 -
 25.1508 -lemma linordered_field_no_lb: "\<forall> x. \<exists>y. y < (x::'a::linordered_field)"
 25.1509 -proof
 25.1510 -  fix x::'a
 25.1511 -  have m1: "- (1::'a) < 0" by simp
 25.1512 -  from add_strict_right_mono[OF m1, where c=x] 
 25.1513 -  have "(- 1) + x < x" by simp
 25.1514 -  thus "\<exists>y. y < x" by blast
 25.1515 -qed
 25.1516 -
 25.1517 -lemma linordered_field_no_ub: "\<forall> x. \<exists>y. y > (x::'a::linordered_field)"
 25.1518 -proof
 25.1519 -  fix x::'a
 25.1520 -  have m1: " (1::'a) > 0" by simp
 25.1521 -  from add_strict_right_mono[OF m1, where c=x] 
 25.1522 -  have "1 + x > x" by simp
 25.1523 -  thus "\<exists>y. y > x" by blast
 25.1524 -qed
 25.1525 -
 25.1526 -subsection{*Anti-Monotonicity of @{term inverse}*}
 25.1527 -
 25.1528 -lemma less_imp_inverse_less:
 25.1529 -assumes less: "a < b" and apos:  "0 < a"
 25.1530 -shows "inverse b < inverse (a::'a::linordered_field)"
 25.1531 -proof (rule ccontr)
 25.1532 -  assume "~ inverse b < inverse a"
 25.1533 -  hence "inverse a \<le> inverse b" by (simp add: linorder_not_less)
 25.1534 -  hence "~ (a < b)"
 25.1535 -    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
 25.1536 -  thus False by (rule notE [OF _ less])
 25.1537 -qed
 25.1538 -
 25.1539 -lemma inverse_less_imp_less:
 25.1540 -  "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::linordered_field)"
 25.1541 -apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
 25.1542 -apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
 25.1543 -done
 25.1544 -
 25.1545 -text{*Both premises are essential. Consider -1 and 1.*}
 25.1546 -lemma inverse_less_iff_less [simp,noatp]:
 25.1547 -  "[|0 < a; 0 < b|] ==> (inverse a < inverse b) = (b < (a::'a::linordered_field))"
 25.1548 -by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
 25.1549 -
 25.1550 -lemma le_imp_inverse_le:
 25.1551 -  "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::linordered_field)"
 25.1552 -by (force simp add: order_le_less less_imp_inverse_less)
 25.1553 -
 25.1554 -lemma inverse_le_iff_le [simp,noatp]:
 25.1555 - "[|0 < a; 0 < b|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::linordered_field))"
 25.1556 -by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
 25.1557 -
 25.1558 -
 25.1559 -text{*These results refer to both operands being negative.  The opposite-sign
 25.1560 -case is trivial, since inverse preserves signs.*}
 25.1561 -lemma inverse_le_imp_le_neg:
 25.1562 -  "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::linordered_field)"
 25.1563 -apply (rule classical) 
 25.1564 -apply (subgoal_tac "a < 0") 
 25.1565 - prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
 25.1566 -apply (insert inverse_le_imp_le [of "-b" "-a"])
 25.1567 -apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
 25.1568 -done
 25.1569 -
 25.1570 -lemma less_imp_inverse_less_neg:
 25.1571 -   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::linordered_field)"
 25.1572 -apply (subgoal_tac "a < 0") 
 25.1573 - prefer 2 apply (blast intro: order_less_trans) 
 25.1574 -apply (insert less_imp_inverse_less [of "-b" "-a"])
 25.1575 -apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
 25.1576 -done
 25.1577 -
 25.1578 -lemma inverse_less_imp_less_neg:
 25.1579 -   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::linordered_field)"
 25.1580 -apply (rule classical) 
 25.1581 -apply (subgoal_tac "a < 0") 
 25.1582 - prefer 2
 25.1583 - apply (force simp add: linorder_not_less intro: order_le_less_trans) 
 25.1584 -apply (insert inverse_less_imp_less [of "-b" "-a"])
 25.1585 -apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
 25.1586 -done
 25.1587 -
 25.1588 -lemma inverse_less_iff_less_neg [simp,noatp]:
 25.1589 -  "[|a < 0; b < 0|] ==> (inverse a < inverse b) = (b < (a::'a::linordered_field))"
 25.1590 -apply (insert inverse_less_iff_less [of "-b" "-a"])
 25.1591 -apply (simp del: inverse_less_iff_less 
 25.1592 -            add: order_less_imp_not_eq nonzero_inverse_minus_eq)
 25.1593 -done
 25.1594 -
 25.1595 -lemma le_imp_inverse_le_neg:
 25.1596 -  "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::linordered_field)"
 25.1597 -by (force simp add: order_le_less less_imp_inverse_less_neg)
 25.1598 -
 25.1599 -lemma inverse_le_iff_le_neg [simp,noatp]:
 25.1600 - "[|a < 0; b < 0|] ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::linordered_field))"
 25.1601 -by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
 25.1602 -
 25.1603 -
 25.1604 -subsection{*Inverses and the Number One*}
 25.1605 -
 25.1606 -lemma one_less_inverse_iff:
 25.1607 -  "(1 < inverse x) = (0 < x & x < (1::'a::{linordered_field,division_by_zero}))"
 25.1608 -proof cases
 25.1609 -  assume "0 < x"
 25.1610 -    with inverse_less_iff_less [OF zero_less_one, of x]
 25.1611 -    show ?thesis by simp
 25.1612 -next
 25.1613 -  assume notless: "~ (0 < x)"
 25.1614 -  have "~ (1 < inverse x)"
 25.1615 -  proof
 25.1616 -    assume "1 < inverse x"
 25.1617 -    also with notless have "... \<le> 0" by (simp add: linorder_not_less)
 25.1618 -    also have "... < 1" by (rule zero_less_one) 
 25.1619 -    finally show False by auto
 25.1620 -  qed
 25.1621 -  with notless show ?thesis by simp
 25.1622 -qed
 25.1623 -
 25.1624 -lemma inverse_eq_1_iff [simp]:
 25.1625 -  "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
 25.1626 -by (insert inverse_eq_iff_eq [of x 1], simp) 
 25.1627 -
 25.1628 -lemma one_le_inverse_iff:
 25.1629 -  "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{linordered_field,division_by_zero}))"
 25.1630 -by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
 25.1631 -                    eq_commute [of 1]) 
 25.1632 -
 25.1633 -lemma inverse_less_1_iff:
 25.1634 -  "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{linordered_field,division_by_zero}))"
 25.1635 -by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
 25.1636 -
 25.1637 -lemma inverse_le_1_iff:
 25.1638 -  "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{linordered_field,division_by_zero}))"
 25.1639 -by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
 25.1640 -
 25.1641 -
 25.1642 -subsection{*Simplification of Inequalities Involving Literal Divisors*}
 25.1643 -
 25.1644 -lemma pos_le_divide_eq: "0 < (c::'a::linordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
 25.1645 -proof -
 25.1646 -  assume less: "0<c"
 25.1647 -  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
 25.1648 -    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
 25.1649 -  also have "... = (a*c \<le> b)"
 25.1650 -    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
 25.1651 -  finally show ?thesis .
 25.1652 -qed
 25.1653 -
 25.1654 -lemma neg_le_divide_eq: "c < (0::'a::linordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
 25.1655 -proof -
 25.1656 -  assume less: "c<0"
 25.1657 -  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
 25.1658 -    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
 25.1659 -  also have "... = (b \<le> a*c)"
 25.1660 -    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
 25.1661 -  finally show ?thesis .
 25.1662 -qed
 25.1663 -
 25.1664 -lemma le_divide_eq:
 25.1665 -  "(a \<le> b/c) = 
 25.1666 -   (if 0 < c then a*c \<le> b
 25.1667 -             else if c < 0 then b \<le> a*c
 25.1668 -             else  a \<le> (0::'a::{linordered_field,division_by_zero}))"
 25.1669 -apply (cases "c=0", simp) 
 25.1670 -apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
 25.1671 -done
 25.1672 -
 25.1673 -lemma pos_divide_le_eq: "0 < (c::'a::linordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
 25.1674 -proof -
 25.1675 -  assume less: "0<c"
 25.1676 -  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
 25.1677 -    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
 25.1678 -  also have "... = (b \<le> a*c)"
 25.1679 -    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
 25.1680 -  finally show ?thesis .
 25.1681 -qed
 25.1682 -
 25.1683 -lemma neg_divide_le_eq: "c < (0::'a::linordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
 25.1684 -proof -
 25.1685 -  assume less: "c<0"
 25.1686 -  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
 25.1687 -    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
 25.1688 -  also have "... = (a*c \<le> b)"
 25.1689 -    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
 25.1690 -  finally show ?thesis .
 25.1691 -qed
 25.1692 -
 25.1693 -lemma divide_le_eq:
 25.1694 -  "(b/c \<le> a) = 
 25.1695 -   (if 0 < c then b \<le> a*c
 25.1696 -             else if c < 0 then a*c \<le> b
 25.1697 -             else 0 \<le> (a::'a::{linordered_field,division_by_zero}))"
 25.1698 -apply (cases "c=0", simp) 
 25.1699 -apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
 25.1700 -done
 25.1701 -
 25.1702 -lemma pos_less_divide_eq:
 25.1703 -     "0 < (c::'a::linordered_field) ==> (a < b/c) = (a*c < b)"
 25.1704 -proof -
 25.1705 -  assume less: "0<c"
 25.1706 -  hence "(a < b/c) = (a*c < (b/c)*c)"
 25.1707 -    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
 25.1708 -  also have "... = (a*c < b)"
 25.1709 -    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
 25.1710 -  finally show ?thesis .
 25.1711 -qed
 25.1712 -
 25.1713 -lemma neg_less_divide_eq:
 25.1714 - "c < (0::'a::linordered_field) ==> (a < b/c) = (b < a*c)"
 25.1715 -proof -
 25.1716 -  assume less: "c<0"
 25.1717 -  hence "(a < b/c) = ((b/c)*c < a*c)"
 25.1718 -    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
 25.1719 -  also have "... = (b < a*c)"
 25.1720 -    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
 25.1721 -  finally show ?thesis .
 25.1722 -qed
 25.1723 -
 25.1724 -lemma less_divide_eq:
 25.1725 -  "(a < b/c) = 
 25.1726 -   (if 0 < c then a*c < b
 25.1727 -             else if c < 0 then b < a*c
 25.1728 -             else  a < (0::'a::{linordered_field,division_by_zero}))"
 25.1729 -apply (cases "c=0", simp) 
 25.1730 -apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
 25.1731 -done
 25.1732 -
 25.1733 -lemma pos_divide_less_eq:
 25.1734 -     "0 < (c::'a::linordered_field) ==> (b/c < a) = (b < a*c)"
 25.1735 -proof -
 25.1736 -  assume less: "0<c"
 25.1737 -  hence "(b/c < a) = ((b/c)*c < a*c)"
 25.1738 -    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
 25.1739 -  also have "... = (b < a*c)"
 25.1740 -    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
 25.1741 -  finally show ?thesis .
 25.1742 -qed
 25.1743 -
 25.1744 -lemma neg_divide_less_eq:
 25.1745 - "c < (0::'a::linordered_field) ==> (b/c < a) = (a*c < b)"
 25.1746 -proof -
 25.1747 -  assume less: "c<0"
 25.1748 -  hence "(b/c < a) = (a*c < (b/c)*c)"
 25.1749 -    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
 25.1750 -  also have "... = (a*c < b)"
 25.1751 -    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
 25.1752 -  finally show ?thesis .
 25.1753 -qed
 25.1754 -
 25.1755 -lemma divide_less_eq:
 25.1756 -  "(b/c < a) = 
 25.1757 -   (if 0 < c then b < a*c
 25.1758 -             else if c < 0 then a*c < b
 25.1759 -             else 0 < (a::'a::{linordered_field,division_by_zero}))"
 25.1760 -apply (cases "c=0", simp) 
 25.1761 -apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
 25.1762 -done
 25.1763 -
 25.1764 -
 25.1765 -subsection{*Field simplification*}
 25.1766 -
 25.1767 -text{* Lemmas @{text field_simps} multiply with denominators in in(equations)
 25.1768 -if they can be proved to be non-zero (for equations) or positive/negative
 25.1769 -(for inequations). Can be too aggressive and is therefore separate from the
 25.1770 -more benign @{text algebra_simps}. *}
 25.1771 -
 25.1772 -lemmas field_simps[noatp] = field_eq_simps
 25.1773 -  (* multiply ineqn *)
 25.1774 -  pos_divide_less_eq neg_divide_less_eq
 25.1775 -  pos_less_divide_eq neg_less_divide_eq
 25.1776 -  pos_divide_le_eq neg_divide_le_eq
 25.1777 -  pos_le_divide_eq neg_le_divide_eq
 25.1778 -
 25.1779 -text{* Lemmas @{text sign_simps} is a first attempt to automate proofs
 25.1780 -of positivity/negativity needed for @{text field_simps}. Have not added @{text
 25.1781 -sign_simps} to @{text field_simps} because the former can lead to case
 25.1782 -explosions. *}
 25.1783 -
 25.1784 -lemmas sign_simps[noatp] = group_simps
 25.1785 -  zero_less_mult_iff  mult_less_0_iff
 25.1786 -
 25.1787 -(* Only works once linear arithmetic is installed:
 25.1788 -text{*An example:*}
 25.1789 -lemma fixes a b c d e f :: "'a::linordered_field"
 25.1790 -shows "\<lbrakk>a>b; c<d; e<f; 0 < u \<rbrakk> \<Longrightarrow>
 25.1791 - ((a-b)*(c-d)*(e-f))/((c-d)*(e-f)*(a-b)) <
 25.1792 - ((e-f)*(a-b)*(c-d))/((e-f)*(a-b)*(c-d)) + u"
 25.1793 -apply(subgoal_tac "(c-d)*(e-f)*(a-b) > 0")
 25.1794 - prefer 2 apply(simp add:sign_simps)
 25.1795 -apply(subgoal_tac "(c-d)*(e-f)*(a-b)*u > 0")
 25.1796 - prefer 2 apply(simp add:sign_simps)
 25.1797 -apply(simp add:field_simps)
 25.1798 -done
 25.1799 -*)
 25.1800 -
 25.1801 -
 25.1802 -subsection{*Division and Signs*}
 25.1803 -
 25.1804 -lemma zero_less_divide_iff:
 25.1805 -     "((0::'a::{linordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
 25.1806 -by (simp add: divide_inverse zero_less_mult_iff)
 25.1807 -
 25.1808 -lemma divide_less_0_iff:
 25.1809 -     "(a/b < (0::'a::{linordered_field,division_by_zero})) = 
 25.1810 -      (0 < a & b < 0 | a < 0 & 0 < b)"
 25.1811 -by (simp add: divide_inverse mult_less_0_iff)
 25.1812 -
 25.1813 -lemma zero_le_divide_iff:
 25.1814 -     "((0::'a::{linordered_field,division_by_zero}) \<le> a/b) =
 25.1815 -      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
 25.1816 -by (simp add: divide_inverse zero_le_mult_iff)
 25.1817 -
 25.1818 -lemma divide_le_0_iff:
 25.1819 -     "(a/b \<le> (0::'a::{linordered_field,division_by_zero})) =
 25.1820 -      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
 25.1821 -by (simp add: divide_inverse mult_le_0_iff)
 25.1822 -
 25.1823 -lemma divide_eq_0_iff [simp,noatp]:
 25.1824 -     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
 25.1825 -by (simp add: divide_inverse)
 25.1826 -
 25.1827 -lemma divide_pos_pos:
 25.1828 -  "0 < (x::'a::linordered_field) ==> 0 < y ==> 0 < x / y"
 25.1829 -by(simp add:field_simps)
 25.1830 -
 25.1831 -
 25.1832 -lemma divide_nonneg_pos:
 25.1833 -  "0 <= (x::'a::linordered_field) ==> 0 < y ==> 0 <= x / y"
 25.1834 -by(simp add:field_simps)
 25.1835 -
 25.1836 -lemma divide_neg_pos:
 25.1837 -  "(x::'a::linordered_field) < 0 ==> 0 < y ==> x / y < 0"
 25.1838 -by(simp add:field_simps)
 25.1839 -
 25.1840 -lemma divide_nonpos_pos:
 25.1841 -  "(x::'a::linordered_field) <= 0 ==> 0 < y ==> x / y <= 0"
 25.1842 -by(simp add:field_simps)
 25.1843 -
 25.1844 -lemma divide_pos_neg:
 25.1845 -  "0 < (x::'a::linordered_field) ==> y < 0 ==> x / y < 0"
 25.1846 -by(simp add:field_simps)
 25.1847 -
 25.1848 -lemma divide_nonneg_neg:
 25.1849 -  "0 <= (x::'a::linordered_field) ==> y < 0 ==> x / y <= 0" 
 25.1850 -by(simp add:field_simps)
 25.1851 -
 25.1852 -lemma divide_neg_neg:
 25.1853 -  "(x::'a::linordered_field) < 0 ==> y < 0 ==> 0 < x / y"
 25.1854 -by(simp add:field_simps)
 25.1855 -
 25.1856 -lemma divide_nonpos_neg:
 25.1857 -  "(x::'a::linordered_field) <= 0 ==> y < 0 ==> 0 <= x / y"
 25.1858 -by(simp add:field_simps)
 25.1859 -
 25.1860 -
 25.1861 -subsection{*Cancellation Laws for Division*}
 25.1862 -
 25.1863 -lemma divide_cancel_right [simp,noatp]:
 25.1864 -     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
 25.1865 -apply (cases "c=0", simp)
 25.1866 -apply (simp add: divide_inverse)
 25.1867 -done
 25.1868 -
 25.1869 -lemma divide_cancel_left [simp,noatp]:
 25.1870 -     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
 25.1871 -apply (cases "c=0", simp)
 25.1872 -apply (simp add: divide_inverse)
 25.1873 -done
 25.1874 -
 25.1875 -
 25.1876 -subsection {* Division and the Number One *}
 25.1877 -
 25.1878 -text{*Simplify expressions equated with 1*}
 25.1879 -lemma divide_eq_1_iff [simp,noatp]:
 25.1880 -     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
 25.1881 -apply (cases "b=0", simp)
 25.1882 -apply (simp add: right_inverse_eq)
 25.1883 -done
 25.1884 -
 25.1885 -lemma one_eq_divide_iff [simp,noatp]:
 25.1886 -     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
 25.1887 -by (simp add: eq_commute [of 1])
 25.1888 -
 25.1889 -lemma zero_eq_1_divide_iff [simp,noatp]:
 25.1890 -     "((0::'a::{linordered_field,division_by_zero}) = 1/a) = (a = 0)"
 25.1891 -apply (cases "a=0", simp)
 25.1892 -apply (auto simp add: nonzero_eq_divide_eq)
 25.1893 -done
 25.1894 -
 25.1895 -lemma one_divide_eq_0_iff [simp,noatp]:
 25.1896 -     "(1/a = (0::'a::{linordered_field,division_by_zero})) = (a = 0)"
 25.1897 -apply (cases "a=0", simp)
 25.1898 -apply (insert zero_neq_one [THEN not_sym])
 25.1899 -apply (auto simp add: nonzero_divide_eq_eq)
 25.1900 -done
 25.1901 -
 25.1902 -text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
 25.1903 -lemmas zero_less_divide_1_iff = zero_less_divide_iff [of 1, simplified]
 25.1904 -lemmas divide_less_0_1_iff = divide_less_0_iff [of 1, simplified]
 25.1905 -lemmas zero_le_divide_1_iff = zero_le_divide_iff [of 1, simplified]
 25.1906 -lemmas divide_le_0_1_iff = divide_le_0_iff [of 1, simplified]
 25.1907 -
 25.1908 -declare zero_less_divide_1_iff [simp,noatp]
 25.1909 -declare divide_less_0_1_iff [simp,noatp]
 25.1910 -declare zero_le_divide_1_iff [simp,noatp]
 25.1911 -declare divide_le_0_1_iff [simp,noatp]
 25.1912 -
 25.1913 -
 25.1914 -subsection {* Ordering Rules for Division *}
 25.1915 -
 25.1916 -lemma divide_strict_right_mono:
 25.1917 -     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::linordered_field)"
 25.1918 -by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
 25.1919 -              positive_imp_inverse_positive)
 25.1920 -
 25.1921 -lemma divide_right_mono:
 25.1922 -     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{linordered_field,division_by_zero})"
 25.1923 -by (force simp add: divide_strict_right_mono order_le_less)
 25.1924 -
 25.1925 -lemma divide_right_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
 25.1926 -    ==> c <= 0 ==> b / c <= a / c"
 25.1927 -apply (drule divide_right_mono [of _ _ "- c"])
 25.1928 -apply auto
 25.1929 -done
 25.1930 -
 25.1931 -lemma divide_strict_right_mono_neg:
 25.1932 -     "[|b < a; c < 0|] ==> a / c < b / (c::'a::linordered_field)"
 25.1933 -apply (drule divide_strict_right_mono [of _ _ "-c"], simp)
 25.1934 -apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric])
 25.1935 -done
 25.1936 -
 25.1937 -text{*The last premise ensures that @{term a} and @{term b} 
 25.1938 -      have the same sign*}
 25.1939 -lemma divide_strict_left_mono:
 25.1940 -  "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
 25.1941 -by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono)
 25.1942 -
 25.1943 -lemma divide_left_mono:
 25.1944 -  "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::linordered_field)"
 25.1945 -by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_right_mono)
 25.1946 -
 25.1947 -lemma divide_left_mono_neg: "(a::'a::{division_by_zero,linordered_field}) <= b 
 25.1948 -    ==> c <= 0 ==> 0 < a * b ==> c / a <= c / b"
 25.1949 -  apply (drule divide_left_mono [of _ _ "- c"])
 25.1950 -  apply (auto simp add: mult_commute)
 25.1951 -done
 25.1952 -
 25.1953 -lemma divide_strict_left_mono_neg:
 25.1954 -  "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::linordered_field)"
 25.1955 -by(auto simp: field_simps times_divide_eq zero_less_mult_iff mult_strict_right_mono_neg)
 25.1956 -
 25.1957 -
 25.1958 -text{*Simplify quotients that are compared with the value 1.*}
 25.1959 -
 25.1960 -lemma le_divide_eq_1 [noatp]:
 25.1961 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1962 -  shows "(1 \<le> b / a) = ((0 < a & a \<le> b) | (a < 0 & b \<le> a))"
 25.1963 -by (auto simp add: le_divide_eq)
 25.1964 -
 25.1965 -lemma divide_le_eq_1 [noatp]:
 25.1966 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1967 -  shows "(b / a \<le> 1) = ((0 < a & b \<le> a) | (a < 0 & a \<le> b) | a=0)"
 25.1968 -by (auto simp add: divide_le_eq)
 25.1969 -
 25.1970 -lemma less_divide_eq_1 [noatp]:
 25.1971 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1972 -  shows "(1 < b / a) = ((0 < a & a < b) | (a < 0 & b < a))"
 25.1973 -by (auto simp add: less_divide_eq)
 25.1974 -
 25.1975 -lemma divide_less_eq_1 [noatp]:
 25.1976 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1977 -  shows "(b / a < 1) = ((0 < a & b < a) | (a < 0 & a < b) | a=0)"
 25.1978 -by (auto simp add: divide_less_eq)
 25.1979 -
 25.1980 -
 25.1981 -subsection{*Conditional Simplification Rules: No Case Splits*}
 25.1982 -
 25.1983 -lemma le_divide_eq_1_pos [simp,noatp]:
 25.1984 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1985 -  shows "0 < a \<Longrightarrow> (1 \<le> b/a) = (a \<le> b)"
 25.1986 -by (auto simp add: le_divide_eq)
 25.1987 -
 25.1988 -lemma le_divide_eq_1_neg [simp,noatp]:
 25.1989 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1990 -  shows "a < 0 \<Longrightarrow> (1 \<le> b/a) = (b \<le> a)"
 25.1991 -by (auto simp add: le_divide_eq)
 25.1992 -
 25.1993 -lemma divide_le_eq_1_pos [simp,noatp]:
 25.1994 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.1995 -  shows "0 < a \<Longrightarrow> (b/a \<le> 1) = (b \<le> a)"
 25.1996 -by (auto simp add: divide_le_eq)
 25.1997 -
 25.1998 -lemma divide_le_eq_1_neg [simp,noatp]:
 25.1999 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2000 -  shows "a < 0 \<Longrightarrow> (b/a \<le> 1) = (a \<le> b)"
 25.2001 -by (auto simp add: divide_le_eq)
 25.2002 -
 25.2003 -lemma less_divide_eq_1_pos [simp,noatp]:
 25.2004 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2005 -  shows "0 < a \<Longrightarrow> (1 < b/a) = (a < b)"
 25.2006 -by (auto simp add: less_divide_eq)
 25.2007 -
 25.2008 -lemma less_divide_eq_1_neg [simp,noatp]:
 25.2009 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2010 -  shows "a < 0 \<Longrightarrow> (1 < b/a) = (b < a)"
 25.2011 -by (auto simp add: less_divide_eq)
 25.2012 -
 25.2013 -lemma divide_less_eq_1_pos [simp,noatp]:
 25.2014 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2015 -  shows "0 < a \<Longrightarrow> (b/a < 1) = (b < a)"
 25.2016 -by (auto simp add: divide_less_eq)
 25.2017 -
 25.2018 -lemma divide_less_eq_1_neg [simp,noatp]:
 25.2019 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2020 -  shows "a < 0 \<Longrightarrow> b/a < 1 <-> a < b"
 25.2021 -by (auto simp add: divide_less_eq)
 25.2022 -
 25.2023 -lemma eq_divide_eq_1 [simp,noatp]:
 25.2024 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2025 -  shows "(1 = b/a) = ((a \<noteq> 0 & a = b))"
 25.2026 -by (auto simp add: eq_divide_eq)
 25.2027 -
 25.2028 -lemma divide_eq_eq_1 [simp,noatp]:
 25.2029 -  fixes a :: "'a :: {linordered_field,division_by_zero}"
 25.2030 -  shows "(b/a = 1) = ((a \<noteq> 0 & a = b))"
 25.2031 -by (auto simp add: divide_eq_eq)
 25.2032 -
 25.2033 -
 25.2034 -subsection {* Reasoning about inequalities with division *}
 25.2035 -
 25.2036 -lemma mult_right_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
 25.2037 -    ==> x * y <= x"
 25.2038 -by (auto simp add: mult_compare_simps)
 25.2039 -
 25.2040 -lemma mult_left_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
 25.2041 -    ==> y * x <= x"
 25.2042 -by (auto simp add: mult_compare_simps)
 25.2043 -
 25.2044 -lemma mult_imp_div_pos_le: "0 < (y::'a::linordered_field) ==> x <= z * y ==>
 25.2045 -    x / y <= z"
 25.2046 -by (subst pos_divide_le_eq, assumption+)
 25.2047 -
 25.2048 -lemma mult_imp_le_div_pos: "0 < (y::'a::linordered_field) ==> z * y <= x ==>
 25.2049 -    z <= x / y"
 25.2050 -by(simp add:field_simps)
 25.2051 -
 25.2052 -lemma mult_imp_div_pos_less: "0 < (y::'a::linordered_field) ==> x < z * y ==>
 25.2053 -    x / y < z"
 25.2054 -by(simp add:field_simps)
 25.2055 -
 25.2056 -lemma mult_imp_less_div_pos: "0 < (y::'a::linordered_field) ==> z * y < x ==>
 25.2057 -    z < x / y"
 25.2058 -by(simp add:field_simps)
 25.2059 -
 25.2060 -lemma frac_le: "(0::'a::linordered_field) <= x ==> 
 25.2061 -    x <= y ==> 0 < w ==> w <= z  ==> x / z <= y / w"
 25.2062 -  apply (rule mult_imp_div_pos_le)
 25.2063 -  apply simp
 25.2064 -  apply (subst times_divide_eq_left)
 25.2065 -  apply (rule mult_imp_le_div_pos, assumption)
 25.2066 -  apply (rule mult_mono)
 25.2067 -  apply simp_all
 25.2068 -done
 25.2069 -
 25.2070 -lemma frac_less: "(0::'a::linordered_field) <= x ==> 
 25.2071 -    x < y ==> 0 < w ==> w <= z  ==> x / z < y / w"
 25.2072 -  apply (rule mult_imp_div_pos_less)
 25.2073 -  apply simp
 25.2074 -  apply (subst times_divide_eq_left)
 25.2075 -  apply (rule mult_imp_less_div_pos, assumption)
 25.2076 -  apply (erule mult_less_le_imp_less)
 25.2077 -  apply simp_all
 25.2078 -done
 25.2079 -
 25.2080 -lemma frac_less2: "(0::'a::linordered_field) < x ==> 
 25.2081 -    x <= y ==> 0 < w ==> w < z  ==> x / z < y / w"
 25.2082 -  apply (rule mult_imp_div_pos_less)
 25.2083 -  apply simp_all
 25.2084 -  apply (subst times_divide_eq_left)
 25.2085 -  apply (rule mult_imp_less_div_pos, assumption)
 25.2086 -  apply (erule mult_le_less_imp_less)
 25.2087 -  apply simp_all
 25.2088 -done
 25.2089 -
 25.2090 -text{*It's not obvious whether these should be simprules or not. 
 25.2091 -  Their effect is to gather terms into one big fraction, like
 25.2092 -  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
 25.2093 -  seem to need them.*}
 25.2094 -
 25.2095 -declare times_divide_eq [simp]
 25.2096 -
 25.2097 -
 25.2098 -subsection {* Ordered Fields are Dense *}
 25.2099 -
 25.2100 -context linordered_semidom
 25.2101 -begin
 25.2102 -
 25.2103 -lemma less_add_one: "a < a + 1"
 25.2104 -proof -
 25.2105 -  have "a + 0 < a + 1"
 25.2106 -    by (blast intro: zero_less_one add_strict_left_mono)
 25.2107 -  thus ?thesis by simp
 25.2108 -qed
 25.2109 -
 25.2110 -lemma zero_less_two: "0 < 1 + 1"
 25.2111 -by (blast intro: less_trans zero_less_one less_add_one)
 25.2112 -
 25.2113 -end
 25.2114 -
 25.2115 -lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::linordered_field)"
 25.2116 -by (simp add: field_simps zero_less_two)
 25.2117 -
 25.2118 -lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::linordered_field) < b"
 25.2119 -by (simp add: field_simps zero_less_two)
 25.2120 -
 25.2121 -instance linordered_field < dense_linorder
 25.2122 -proof
 25.2123 -  fix x y :: 'a
 25.2124 -  have "x < x + 1" by simp
 25.2125 -  then show "\<exists>y. x < y" .. 
 25.2126 -  have "x - 1 < x" by simp
 25.2127 -  then show "\<exists>y. y < x" ..
 25.2128 -  show "x < y \<Longrightarrow> \<exists>z>x. z < y" by (blast intro!: less_half_sum gt_half_sum)
 25.2129 -qed
 25.2130 -
 25.2131 -
 25.2132 -subsection {* Absolute Value *}
 25.2133 -
 25.2134 -context linordered_idom
 25.2135 -begin
 25.2136 -
 25.2137 -lemma mult_sgn_abs: "sgn x * abs x = x"
 25.2138 -  unfolding abs_if sgn_if by auto
 25.2139 -
 25.2140 -end
 25.2141 -
 25.2142 -lemma abs_one [simp]: "abs 1 = (1::'a::linordered_idom)"
 25.2143 -by (simp add: abs_if zero_less_one [THEN order_less_not_sym])
 25.2144 -
 25.2145 -class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
 25.2146 -  assumes abs_eq_mult:
 25.2147 -    "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
 25.2148 -
 25.2149 -context linordered_idom
 25.2150 -begin
 25.2151 -
 25.2152 -subclass ordered_ring_abs proof
 25.2153 -qed (auto simp add: abs_if not_less equal_neg_zero neg_equal_zero mult_less_0_iff)
 25.2154 -
 25.2155 -lemma abs_mult:
 25.2156 -  "abs (a * b) = abs a * abs b" 
 25.2157 -  by (rule abs_eq_mult) auto
 25.2158 -
 25.2159 -lemma abs_mult_self:
 25.2160 -  "abs a * abs a = a * a"
 25.2161 -  by (simp add: abs_if) 
 25.2162 -
 25.2163 -end
 25.2164 -
 25.2165 -lemma nonzero_abs_inverse:
 25.2166 -     "a \<noteq> 0 ==> abs (inverse (a::'a::linordered_field)) = inverse (abs a)"
 25.2167 -apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
 25.2168 -                      negative_imp_inverse_negative)
 25.2169 -apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
 25.2170 -done
 25.2171 -
 25.2172 -lemma abs_inverse [simp]:
 25.2173 -     "abs (inverse (a::'a::{linordered_field,division_by_zero})) = 
 25.2174 -      inverse (abs a)"
 25.2175 -apply (cases "a=0", simp) 
 25.2176 -apply (simp add: nonzero_abs_inverse) 
 25.2177 -done
 25.2178 -
 25.2179 -lemma nonzero_abs_divide:
 25.2180 -     "b \<noteq> 0 ==> abs (a / (b::'a::linordered_field)) = abs a / abs b"
 25.2181 -by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
 25.2182 -
 25.2183 -lemma abs_divide [simp]:
 25.2184 -     "abs (a / (b::'a::{linordered_field,division_by_zero})) = abs a / abs b"
 25.2185 -apply (cases "b=0", simp) 
 25.2186 -apply (simp add: nonzero_abs_divide) 
 25.2187 -done
 25.2188 -
 25.2189 -lemma abs_mult_less:
 25.2190 -     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::linordered_idom)"
 25.2191 -proof -
 25.2192 -  assume ac: "abs a < c"
 25.2193 -  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
 25.2194 -  assume "abs b < d"
 25.2195 -  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
 25.2196 -qed
 25.2197 -
 25.2198 -lemmas eq_minus_self_iff[noatp] = equal_neg_zero
 25.2199 -
 25.2200 -lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::linordered_idom))"
 25.2201 -  unfolding order_less_le less_eq_neg_nonpos equal_neg_zero ..
 25.2202 -
 25.2203 -lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::linordered_idom))" 
 25.2204 -apply (simp add: order_less_le abs_le_iff)  
 25.2205 -apply (auto simp add: abs_if neg_less_eq_nonneg less_eq_neg_nonpos)
 25.2206 -done
 25.2207 -
 25.2208 -lemma abs_mult_pos: "(0::'a::linordered_idom) <= x ==> 
 25.2209 -    (abs y) * x = abs (y * x)"
 25.2210 -  apply (subst abs_mult)
 25.2211 -  apply simp
 25.2212 -done
 25.2213 -
 25.2214 -lemma abs_div_pos: "(0::'a::{division_by_zero,linordered_field}) < y ==> 
 25.2215 -    abs x / y = abs (x / y)"
 25.2216 -  apply (subst abs_divide)
 25.2217 -  apply (simp add: order_less_imp_le)
 25.2218 -done
 25.2219 -
 25.2220 -code_modulename SML
 25.2221 -  Ring_and_Field Arith
 25.2222 -
 25.2223 -code_modulename OCaml
 25.2224 -  Ring_and_Field Arith
 25.2225 -
 25.2226 -code_modulename Haskell
 25.2227 -  Ring_and_Field Arith
 25.2228 -
 25.2229 -end
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/HOL/Rings.thy	Mon Feb 08 17:12:38 2010 +0100
    26.3 @@ -0,0 +1,1212 @@
    26.4 +(*  Title:      HOL/Rings.thy
    26.5 +    Author:     Gertrud Bauer
    26.6 +    Author:     Steven Obua
    26.7 +    Author:     Tobias Nipkow
    26.8 +    Author:     Lawrence C Paulson
    26.9 +    Author:     Markus Wenzel
   26.10 +    Author:     Jeremy Avigad
   26.11 +*)
   26.12 +
   26.13 +header {* Rings *}
   26.14 +
   26.15 +theory Rings
   26.16 +imports Groups
   26.17 +begin
   26.18 +
   26.19 +text {*
   26.20 +  The theory of partially ordered rings is taken from the books:
   26.21 +  \begin{itemize}
   26.22 +  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
   26.23 +  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
   26.24 +  \end{itemize}
   26.25 +  Most of the used notions can also be looked up in 
   26.26 +  \begin{itemize}
   26.27 +  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
   26.28 +  \item \emph{Algebra I} by van der Waerden, Springer.
   26.29 +  \end{itemize}
   26.30 +*}
   26.31 +
   26.32 +class semiring = ab_semigroup_add + semigroup_mult +
   26.33 +  assumes left_distrib[algebra_simps]: "(a + b) * c = a * c + b * c"
   26.34 +  assumes right_distrib[algebra_simps]: "a * (b + c) = a * b + a * c"
   26.35 +begin
   26.36 +
   26.37 +text{*For the @{text combine_numerals} simproc*}
   26.38 +lemma combine_common_factor:
   26.39 +  "a * e + (b * e + c) = (a + b) * e + c"
   26.40 +by (simp add: left_distrib add_ac)
   26.41 +
   26.42 +end
   26.43 +
   26.44 +class mult_zero = times + zero +
   26.45 +  assumes mult_zero_left [simp]: "0 * a = 0"
   26.46 +  assumes mult_zero_right [simp]: "a * 0 = 0"
   26.47 +
   26.48 +class semiring_0 = semiring + comm_monoid_add + mult_zero
   26.49 +
   26.50 +class semiring_0_cancel = semiring + cancel_comm_monoid_add
   26.51 +begin
   26.52 +
   26.53 +subclass semiring_0
   26.54 +proof
   26.55 +  fix a :: 'a
   26.56 +  have "0 * a + 0 * a = 0 * a + 0" by (simp add: left_distrib [symmetric])
   26.57 +  thus "0 * a = 0" by (simp only: add_left_cancel)
   26.58 +next
   26.59 +  fix a :: 'a
   26.60 +  have "a * 0 + a * 0 = a * 0 + 0" by (simp add: right_distrib [symmetric])
   26.61 +  thus "a * 0 = 0" by (simp only: add_left_cancel)
   26.62 +qed
   26.63 +
   26.64 +end
   26.65 +
   26.66 +class comm_semiring = ab_semigroup_add + ab_semigroup_mult +
   26.67 +  assumes distrib: "(a + b) * c = a * c + b * c"
   26.68 +begin
   26.69 +
   26.70 +subclass semiring
   26.71 +proof
   26.72 +  fix a b c :: 'a
   26.73 +  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
   26.74 +  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
   26.75 +  also have "... = b * a + c * a" by (simp only: distrib)
   26.76 +  also have "... = a * b + a * c" by (simp add: mult_ac)
   26.77 +  finally show "a * (b + c) = a * b + a * c" by blast
   26.78 +qed
   26.79 +
   26.80 +end
   26.81 +
   26.82 +class comm_semiring_0 = comm_semiring + comm_monoid_add + mult_zero
   26.83 +begin
   26.84 +
   26.85 +subclass semiring_0 ..
   26.86 +
   26.87 +end
   26.88 +
   26.89 +class comm_semiring_0_cancel = comm_semiring + cancel_comm_monoid_add
   26.90 +begin
   26.91 +
   26.92 +subclass semiring_0_cancel ..
   26.93 +
   26.94 +subclass comm_semiring_0 ..
   26.95 +
   26.96 +end
   26.97 +
   26.98 +class zero_neq_one = zero + one +
   26.99 +  assumes zero_neq_one [simp]: "0 \<noteq> 1"
  26.100 +begin
  26.101 +
  26.102 +lemma one_neq_zero [simp]: "1 \<noteq> 0"
  26.103 +by (rule not_sym) (rule zero_neq_one)
  26.104 +
  26.105 +end
  26.106 +
  26.107 +class semiring_1 = zero_neq_one + semiring_0 + monoid_mult
  26.108 +
  26.109 +text {* Abstract divisibility *}
  26.110 +
  26.111 +class dvd = times
  26.112 +begin
  26.113 +
  26.114 +definition dvd :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "dvd" 50) where
  26.115 +  [code del]: "b dvd a \<longleftrightarrow> (\<exists>k. a = b * k)"
  26.116 +
  26.117 +lemma dvdI [intro?]: "a = b * k \<Longrightarrow> b dvd a"
  26.118 +  unfolding dvd_def ..
  26.119 +
  26.120 +lemma dvdE [elim?]: "b dvd a \<Longrightarrow> (\<And>k. a = b * k \<Longrightarrow> P) \<Longrightarrow> P"
  26.121 +  unfolding dvd_def by blast 
  26.122 +
  26.123 +end
  26.124 +
  26.125 +class comm_semiring_1 = zero_neq_one + comm_semiring_0 + comm_monoid_mult + dvd
  26.126 +  (*previously almost_semiring*)
  26.127 +begin
  26.128 +
  26.129 +subclass semiring_1 ..
  26.130 +
  26.131 +lemma dvd_refl[simp]: "a dvd a"
  26.132 +proof
  26.133 +  show "a = a * 1" by simp
  26.134 +qed
  26.135 +
  26.136 +lemma dvd_trans:
  26.137 +  assumes "a dvd b" and "b dvd c"
  26.138 +  shows "a dvd c"
  26.139 +proof -
  26.140 +  from assms obtain v where "b = a * v" by (auto elim!: dvdE)
  26.141 +  moreover from assms obtain w where "c = b * w" by (auto elim!: dvdE)
  26.142 +  ultimately have "c = a * (v * w)" by (simp add: mult_assoc)
  26.143 +  then show ?thesis ..
  26.144 +qed
  26.145 +
  26.146 +lemma dvd_0_left_iff [noatp, simp]: "0 dvd a \<longleftrightarrow> a = 0"
  26.147 +by (auto intro: dvd_refl elim!: dvdE)
  26.148 +
  26.149 +lemma dvd_0_right [iff]: "a dvd 0"
  26.150 +proof
  26.151 +  show "0 = a * 0" by simp
  26.152 +qed
  26.153 +
  26.154 +lemma one_dvd [simp]: "1 dvd a"
  26.155 +by (auto intro!: dvdI)
  26.156 +
  26.157 +lemma dvd_mult[simp]: "a dvd c \<Longrightarrow> a dvd (b * c)"
  26.158 +by (auto intro!: mult_left_commute dvdI elim!: dvdE)
  26.159 +
  26.160 +lemma dvd_mult2[simp]: "a dvd b \<Longrightarrow> a dvd (b * c)"
  26.161 +  apply (subst mult_commute)
  26.162 +  apply (erule dvd_mult)
  26.163 +  done
  26.164 +
  26.165 +lemma dvd_triv_right [simp]: "a dvd b * a"
  26.166 +by (rule dvd_mult) (rule dvd_refl)
  26.167 +
  26.168 +lemma dvd_triv_left [simp]: "a dvd a * b"
  26.169 +by (rule dvd_mult2) (rule dvd_refl)
  26.170 +
  26.171 +lemma mult_dvd_mono:
  26.172 +  assumes "a dvd b"
  26.173 +    and "c dvd d"
  26.174 +  shows "a * c dvd b * d"
  26.175 +proof -
  26.176 +  from `a dvd b` obtain b' where "b = a * b'" ..
  26.177 +  moreover from `c dvd d` obtain d' where "d = c * d'" ..
  26.178 +  ultimately have "b * d = (a * c) * (b' * d')" by (simp add: mult_ac)
  26.179 +  then show ?thesis ..
  26.180 +qed
  26.181 +
  26.182 +lemma dvd_mult_left: "a * b dvd c \<Longrightarrow> a dvd c"
  26.183 +by (simp add: dvd_def mult_assoc, blast)
  26.184 +
  26.185 +lemma dvd_mult_right: "a * b dvd c \<Longrightarrow> b dvd c"
  26.186 +  unfolding mult_ac [of a] by (rule dvd_mult_left)
  26.187 +
  26.188 +lemma dvd_0_left: "0 dvd a \<Longrightarrow> a = 0"
  26.189 +by simp
  26.190 +
  26.191 +lemma dvd_add[simp]:
  26.192 +  assumes "a dvd b" and "a dvd c" shows "a dvd (b + c)"
  26.193 +proof -
  26.194 +  from `a dvd b` obtain b' where "b = a * b'" ..
  26.195 +  moreover from `a dvd c` obtain c' where "c = a * c'" ..
  26.196 +  ultimately have "b + c = a * (b' + c')" by (simp add: right_distrib)
  26.197 +  then show ?thesis ..
  26.198 +qed
  26.199 +
  26.200 +end
  26.201 +
  26.202 +
  26.203 +class no_zero_divisors = zero + times +
  26.204 +  assumes no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
  26.205 +
  26.206 +class semiring_1_cancel = semiring + cancel_comm_monoid_add
  26.207 +  + zero_neq_one + monoid_mult
  26.208 +begin
  26.209 +
  26.210 +subclass semiring_0_cancel ..
  26.211 +
  26.212 +subclass semiring_1 ..
  26.213 +
  26.214 +end
  26.215 +
  26.216 +class comm_semiring_1_cancel = comm_semiring + cancel_comm_monoid_add
  26.217 +  + zero_neq_one + comm_monoid_mult
  26.218 +begin
  26.219 +
  26.220 +subclass semiring_1_cancel ..
  26.221 +subclass comm_semiring_0_cancel ..
  26.222 +subclass comm_semiring_1 ..
  26.223 +
  26.224 +end
  26.225 +
  26.226 +class ring = semiring + ab_group_add
  26.227 +begin
  26.228 +
  26.229 +subclass semiring_0_cancel ..
  26.230 +
  26.231 +text {* Distribution rules *}
  26.232 +
  26.233 +lemma minus_mult_left: "- (a * b) = - a * b"
  26.234 +by (rule minus_unique) (simp add: left_distrib [symmetric]) 
  26.235 +
  26.236 +lemma minus_mult_right: "- (a * b) = a * - b"
  26.237 +by (rule minus_unique) (simp add: right_distrib [symmetric]) 
  26.238 +
  26.239 +text{*Extract signs from products*}
  26.240 +lemmas mult_minus_left [simp, noatp] = minus_mult_left [symmetric]
  26.241 +lemmas mult_minus_right [simp,noatp] = minus_mult_right [symmetric]
  26.242 +
  26.243 +lemma minus_mult_minus [simp]: "- a * - b = a * b"
  26.244 +by simp
  26.245 +
  26.246 +lemma minus_mult_commute: "- a * b = a * - b"
  26.247 +by simp
  26.248 +
  26.249 +lemma right_diff_distrib[algebra_simps]: "a * (b - c) = a * b - a * c"
  26.250 +by (simp add: right_distrib diff_minus)
  26.251 +
  26.252 +lemma left_diff_distrib[algebra_simps]: "(a - b) * c = a * c - b * c"
  26.253 +by (simp add: left_distrib diff_minus)
  26.254 +
  26.255 +lemmas ring_distribs[noatp] =
  26.256 +  right_distrib left_distrib left_diff_distrib right_diff_distrib
  26.257 +
  26.258 +text{*Legacy - use @{text algebra_simps} *}
  26.259 +lemmas ring_simps[noatp] = algebra_simps
  26.260 +
  26.261 +lemma eq_add_iff1:
  26.262 +  "a * e + c = b * e + d \<longleftrightarrow> (a - b) * e + c = d"
  26.263 +by (simp add: algebra_simps)
  26.264 +
  26.265 +lemma eq_add_iff2:
  26.266 +  "a * e + c = b * e + d \<longleftrightarrow> c = (b - a) * e + d"
  26.267 +by (simp add: algebra_simps)
  26.268 +
  26.269 +end
  26.270 +
  26.271 +lemmas ring_distribs[noatp] =
  26.272 +  right_distrib left_distrib left_diff_distrib right_diff_distrib
  26.273 +
  26.274 +class comm_ring = comm_semiring + ab_group_add
  26.275 +begin
  26.276 +
  26.277 +subclass ring ..
  26.278 +subclass comm_semiring_0_cancel ..
  26.279 +
  26.280 +end
  26.281 +
  26.282 +class ring_1 = ring + zero_neq_one + monoid_mult
  26.283 +begin
  26.284 +
  26.285 +subclass semiring_1_cancel ..
  26.286 +
  26.287 +end
  26.288 +
  26.289 +class comm_ring_1 = comm_ring + zero_neq_one + comm_monoid_mult
  26.290 +  (*previously ring*)
  26.291 +begin
  26.292 +
  26.293 +subclass ring_1 ..
  26.294 +subclass comm_semiring_1_cancel ..
  26.295 +
  26.296 +lemma dvd_minus_iff [simp]: "x dvd - y \<longleftrightarrow> x dvd y"
  26.297 +proof
  26.298 +  assume "x dvd - y"
  26.299 +  then have "x dvd - 1 * - y" by (rule dvd_mult)
  26.300 +  then show "x dvd y" by simp
  26.301 +next
  26.302 +  assume "x dvd y"
  26.303 +  then have "x dvd - 1 * y" by (rule dvd_mult)
  26.304 +  then show "x dvd - y" by simp
  26.305 +qed
  26.306 +
  26.307 +lemma minus_dvd_iff [simp]: "- x dvd y \<longleftrightarrow> x dvd y"
  26.308 +proof
  26.309 +  assume "- x dvd y"
  26.310 +  then obtain k where "y = - x * k" ..
  26.311 +  then have "y = x * - k" by simp
  26.312 +  then show "x dvd y" ..
  26.313 +next
  26.314 +  assume "x dvd y"
  26.315 +  then obtain k where "y = x * k" ..
  26.316 +  then have "y = - x * - k" by simp
  26.317 +  then show "- x dvd y" ..
  26.318 +qed
  26.319 +
  26.320 +lemma dvd_diff[simp]: "x dvd y \<Longrightarrow> x dvd z \<Longrightarrow> x dvd (y - z)"
  26.321 +by (simp add: diff_minus dvd_minus_iff)
  26.322 +
  26.323 +end
  26.324 +
  26.325 +class ring_no_zero_divisors = ring + no_zero_divisors
  26.326 +begin
  26.327 +
  26.328 +lemma mult_eq_0_iff [simp]:
  26.329 +  shows "a * b = 0 \<longleftrightarrow> (a = 0 \<or> b = 0)"
  26.330 +proof (cases "a = 0 \<or> b = 0")
  26.331 +  case False then have "a \<noteq> 0" and "b \<noteq> 0" by auto
  26.332 +    then show ?thesis using no_zero_divisors by simp
  26.333 +next
  26.334 +  case True then show ?thesis by auto
  26.335 +qed
  26.336 +
  26.337 +text{*Cancellation of equalities with a common factor*}
  26.338 +lemma mult_cancel_right [simp, noatp]:
  26.339 +  "a * c = b * c \<longleftrightarrow> c = 0 \<or> a = b"
  26.340 +proof -
  26.341 +  have "(a * c = b * c) = ((a - b) * c = 0)"
  26.342 +    by (simp add: algebra_simps right_minus_eq)
  26.343 +  thus ?thesis by (simp add: disj_commute right_minus_eq)
  26.344 +qed
  26.345 +
  26.346 +lemma mult_cancel_left [simp, noatp]:
  26.347 +  "c * a = c * b \<longleftrightarrow> c = 0 \<or> a = b"
  26.348 +proof -
  26.349 +  have "(c * a = c * b) = (c * (a - b) = 0)"
  26.350 +    by (simp add: algebra_simps right_minus_eq)
  26.351 +  thus ?thesis by (simp add: right_minus_eq)
  26.352 +qed
  26.353 +
  26.354 +end
  26.355 +
  26.356 +class ring_1_no_zero_divisors = ring_1 + ring_no_zero_divisors
  26.357 +begin
  26.358 +
  26.359 +lemma mult_cancel_right1 [simp]:
  26.360 +  "c = b * c \<longleftrightarrow> c = 0 \<or> b = 1"
  26.361 +by (insert mult_cancel_right [of 1 c b], force)
  26.362 +
  26.363 +lemma mult_cancel_right2 [simp]:
  26.364 +  "a * c = c \<longleftrightarrow> c = 0 \<or> a = 1"
  26.365 +by (insert mult_cancel_right [of a c 1], simp)
  26.366 + 
  26.367 +lemma mult_cancel_left1 [simp]:
  26.368 +  "c = c * b \<longleftrightarrow> c = 0 \<or> b = 1"
  26.369 +by (insert mult_cancel_left [of c 1 b], force)
  26.370 +
  26.371 +lemma mult_cancel_left2 [simp]:
  26.372 +  "c * a = c \<longleftrightarrow> c = 0 \<or> a = 1"
  26.373 +by (insert mult_cancel_left [of c a 1], simp)
  26.374 +
  26.375 +end
  26.376 +
  26.377 +class idom = comm_ring_1 + no_zero_divisors
  26.378 +begin
  26.379 +
  26.380 +subclass ring_1_no_zero_divisors ..
  26.381 +
  26.382 +lemma square_eq_iff: "a * a = b * b \<longleftrightarrow> (a = b \<or> a = - b)"
  26.383 +proof
  26.384 +  assume "a * a = b * b"
  26.385 +  then have "(a - b) * (a + b) = 0"
  26.386 +    by (simp add: algebra_simps)
  26.387 +  then show "a = b \<or> a = - b"
  26.388 +    by (simp add: right_minus_eq eq_neg_iff_add_eq_0)
  26.389 +next
  26.390 +  assume "a = b \<or> a = - b"
  26.391 +  then show "a * a = b * b" by auto
  26.392 +qed
  26.393 +
  26.394 +lemma dvd_mult_cancel_right [simp]:
  26.395 +  "a * c dvd b * c \<longleftrightarrow> c = 0 \<or> a dvd b"
  26.396 +proof -
  26.397 +  have "a * c dvd b * c \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
  26.398 +    unfolding dvd_def by (simp add: mult_ac)
  26.399 +  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
  26.400 +    unfolding dvd_def by simp
  26.401 +  finally show ?thesis .
  26.402 +qed
  26.403 +
  26.404 +lemma dvd_mult_cancel_left [simp]:
  26.405 +  "c * a dvd c * b \<longleftrightarrow> c = 0 \<or> a dvd b"
  26.406 +proof -
  26.407 +  have "c * a dvd c * b \<longleftrightarrow> (\<exists>k. b * c = (a * k) * c)"
  26.408 +    unfolding dvd_def by (simp add: mult_ac)
  26.409 +  also have "(\<exists>k. b * c = (a * k) * c) \<longleftrightarrow> c = 0 \<or> a dvd b"
  26.410 +    unfolding dvd_def by simp
  26.411 +  finally show ?thesis .
  26.412 +qed
  26.413 +
  26.414 +end
  26.415 +
  26.416 +class division_ring = ring_1 + inverse +
  26.417 +  assumes left_inverse [simp]:  "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
  26.418 +  assumes right_inverse [simp]: "a \<noteq> 0 \<Longrightarrow> a * inverse a = 1"
  26.419 +begin
  26.420 +
  26.421 +subclass ring_1_no_zero_divisors
  26.422 +proof
  26.423 +  fix a b :: 'a
  26.424 +  assume a: "a \<noteq> 0" and b: "b \<noteq> 0"
  26.425 +  show "a * b \<noteq> 0"
  26.426 +  proof
  26.427 +    assume ab: "a * b = 0"
  26.428 +    hence "0 = inverse a * (a * b) * inverse b" by simp
  26.429 +    also have "\<dots> = (inverse a * a) * (b * inverse b)"
  26.430 +      by (simp only: mult_assoc)
  26.431 +    also have "\<dots> = 1" using a b by simp
  26.432 +    finally show False by simp
  26.433 +  qed
  26.434 +qed
  26.435 +
  26.436 +lemma nonzero_imp_inverse_nonzero:
  26.437 +  "a \<noteq> 0 \<Longrightarrow> inverse a \<noteq> 0"
  26.438 +proof
  26.439 +  assume ianz: "inverse a = 0"
  26.440 +  assume "a \<noteq> 0"
  26.441 +  hence "1 = a * inverse a" by simp
  26.442 +  also have "... = 0" by (simp add: ianz)
  26.443 +  finally have "1 = 0" .
  26.444 +  thus False by (simp add: eq_commute)
  26.445 +qed
  26.446 +
  26.447 +lemma inverse_zero_imp_zero:
  26.448 +  "inverse a = 0 \<Longrightarrow> a = 0"
  26.449 +apply (rule classical)
  26.450 +apply (drule nonzero_imp_inverse_nonzero)
  26.451 +apply auto
  26.452 +done
  26.453 +
  26.454 +lemma inverse_unique: 
  26.455 +  assumes ab: "a * b = 1"
  26.456 +  shows "inverse a = b"
  26.457 +proof -
  26.458 +  have "a \<noteq> 0" using ab by (cases "a = 0") simp_all
  26.459 +  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab)
  26.460 +  ultimately show ?thesis by (simp add: mult_assoc [symmetric])
  26.461 +qed
  26.462 +
  26.463 +lemma nonzero_inverse_minus_eq:
  26.464 +  "a \<noteq> 0 \<Longrightarrow> inverse (- a) = - inverse a"
  26.465 +by (rule inverse_unique) simp
  26.466 +
  26.467 +lemma nonzero_inverse_inverse_eq:
  26.468 +  "a \<noteq> 0 \<Longrightarrow> inverse (inverse a) = a"
  26.469 +by (rule inverse_unique) simp
  26.470 +
  26.471 +lemma nonzero_inverse_eq_imp_eq:
  26.472 +  assumes "inverse a = inverse b" and "a \<noteq> 0" and "b \<noteq> 0"
  26.473 +  shows "a = b"
  26.474 +proof -
  26.475 +  from `inverse a = inverse b`
  26.476 +  have "inverse (inverse a) = inverse (inverse b)" by (rule arg_cong)
  26.477 +  with `a \<noteq> 0` and `b \<noteq> 0` show "a = b"
  26.478 +    by (simp add: nonzero_inverse_inverse_eq)
  26.479 +qed
  26.480 +
  26.481 +lemma inverse_1 [simp]: "inverse 1 = 1"
  26.482 +by (rule inverse_unique) simp
  26.483 +
  26.484 +lemma nonzero_inverse_mult_distrib: 
  26.485 +  assumes "a \<noteq> 0" and "b \<noteq> 0"
  26.486 +  shows "inverse (a * b) = inverse b * inverse a"
  26.487 +proof -
  26.488 +  have "a * (b * inverse b) * inverse a = 1" using assms by simp
  26.489 +  hence "a * b * (inverse b * inverse a) = 1" by (simp only: mult_assoc)
  26.490 +  thus ?thesis by (rule inverse_unique)
  26.491 +qed
  26.492 +
  26.493 +lemma division_ring_inverse_add:
  26.494 +  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a + inverse b = inverse a * (a + b) * inverse b"
  26.495 +by (simp add: algebra_simps)
  26.496 +
  26.497 +lemma division_ring_inverse_diff:
  26.498 +  "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> inverse a - inverse b = inverse a * (b - a) * inverse b"
  26.499 +by (simp add: algebra_simps)
  26.500 +
  26.501 +end
  26.502 +
  26.503 +class mult_mono = times + zero + ord +
  26.504 +  assumes mult_left_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
  26.505 +  assumes mult_right_mono: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
  26.506 +
  26.507 +class ordered_semiring = mult_mono + semiring_0 + ordered_ab_semigroup_add 
  26.508 +begin
  26.509 +
  26.510 +lemma mult_mono:
  26.511 +  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> c
  26.512 +     \<Longrightarrow> a * c \<le> b * d"
  26.513 +apply (erule mult_right_mono [THEN order_trans], assumption)
  26.514 +apply (erule mult_left_mono, assumption)
  26.515 +done
  26.516 +
  26.517 +lemma mult_mono':
  26.518 +  "a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> c
  26.519 +     \<Longrightarrow> a * c \<le> b * d"
  26.520 +apply (rule mult_mono)
  26.521 +apply (fast intro: order_trans)+
  26.522 +done
  26.523 +
  26.524 +end
  26.525 +
  26.526 +class ordered_cancel_semiring = mult_mono + ordered_ab_semigroup_add
  26.527 +  + semiring + cancel_comm_monoid_add
  26.528 +begin
  26.529 +
  26.530 +subclass semiring_0_cancel ..
  26.531 +subclass ordered_semiring ..
  26.532 +
  26.533 +lemma mult_nonneg_nonneg: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * b"
  26.534 +using mult_left_mono [of zero b a] by simp
  26.535 +
  26.536 +lemma mult_nonneg_nonpos: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> a * b \<le> 0"
  26.537 +using mult_left_mono [of b zero a] by simp
  26.538 +
  26.539 +lemma mult_nonpos_nonneg: "a \<le> 0 \<Longrightarrow> 0 \<le> b \<Longrightarrow> a * b \<le> 0"
  26.540 +using mult_right_mono [of a zero b] by simp
  26.541 +
  26.542 +text {* Legacy - use @{text mult_nonpos_nonneg} *}
  26.543 +lemma mult_nonneg_nonpos2: "0 \<le> a \<Longrightarrow> b \<le> 0 \<Longrightarrow> b * a \<le> 0" 
  26.544 +by (drule mult_right_mono [of b zero], auto)
  26.545 +
  26.546 +lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> 0" 
  26.547 +by (auto simp add: mult_nonneg_nonpos mult_nonneg_nonpos2)
  26.548 +
  26.549 +end
  26.550 +
  26.551 +class linordered_semiring = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add + mult_mono
  26.552 +begin
  26.553 +
  26.554 +subclass ordered_cancel_semiring ..
  26.555 +
  26.556 +subclass ordered_comm_monoid_add ..
  26.557 +
  26.558 +lemma mult_left_less_imp_less:
  26.559 +  "c * a < c * b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
  26.560 +by (force simp add: mult_left_mono not_le [symmetric])
  26.561 + 
  26.562 +lemma mult_right_less_imp_less:
  26.563 +  "a * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> a < b"
  26.564 +by (force simp add: mult_right_mono not_le [symmetric])
  26.565 +
  26.566 +end
  26.567 +
  26.568 +class linordered_semiring_1 = linordered_semiring + semiring_1
  26.569 +
  26.570 +class linordered_semiring_strict = semiring + comm_monoid_add + linordered_cancel_ab_semigroup_add +
  26.571 +  assumes mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
  26.572 +  assumes mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
  26.573 +begin
  26.574 +
  26.575 +subclass semiring_0_cancel ..
  26.576 +
  26.577 +subclass linordered_semiring
  26.578 +proof
  26.579 +  fix a b c :: 'a
  26.580 +  assume A: "a \<le> b" "0 \<le> c"
  26.581 +  from A show "c * a \<le> c * b"
  26.582 +    unfolding le_less
  26.583 +    using mult_strict_left_mono by (cases "c = 0") auto
  26.584 +  from A show "a * c \<le> b * c"
  26.585 +    unfolding le_less
  26.586 +    using mult_strict_right_mono by (cases "c = 0") auto
  26.587 +qed
  26.588 +
  26.589 +lemma mult_left_le_imp_le:
  26.590 +  "c * a \<le> c * b \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
  26.591 +by (force simp add: mult_strict_left_mono _not_less [symmetric])
  26.592 + 
  26.593 +lemma mult_right_le_imp_le:
  26.594 +  "a * c \<le> b * c \<Longrightarrow> 0 < c \<Longrightarrow> a \<le> b"
  26.595 +by (force simp add: mult_strict_right_mono not_less [symmetric])
  26.596 +
  26.597 +lemma mult_pos_pos: "0 < a \<Longrightarrow> 0 < b \<Longrightarrow> 0 < a * b"
  26.598 +using mult_strict_left_mono [of zero b a] by simp
  26.599 +
  26.600 +lemma mult_pos_neg: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> a * b < 0"
  26.601 +using mult_strict_left_mono [of b zero a] by simp
  26.602 +
  26.603 +lemma mult_neg_pos: "a < 0 \<Longrightarrow> 0 < b \<Longrightarrow> a * b < 0"
  26.604 +using mult_strict_right_mono [of a zero b] by simp
  26.605 +
  26.606 +text {* Legacy - use @{text mult_neg_pos} *}
  26.607 +lemma mult_pos_neg2: "0 < a \<Longrightarrow> b < 0 \<Longrightarrow> b * a < 0" 
  26.608 +by (drule mult_strict_right_mono [of b zero], auto)
  26.609 +
  26.610 +lemma zero_less_mult_pos:
  26.611 +  "0 < a * b \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
  26.612 +apply (cases "b\<le>0")
  26.613 + apply (auto simp add: le_less not_less)
  26.614 +apply (drule_tac mult_pos_neg [of a b])
  26.615 + apply (auto dest: less_not_sym)
  26.616 +done
  26.617 +
  26.618 +lemma zero_less_mult_pos2:
  26.619 +  "0 < b * a \<Longrightarrow> 0 < a \<Longrightarrow> 0 < b"
  26.620 +apply (cases "b\<le>0")
  26.621 + apply (auto simp add: le_less not_less)
  26.622 +apply (drule_tac mult_pos_neg2 [of a b])
  26.623 + apply (auto dest: less_not_sym)
  26.624 +done
  26.625 +
  26.626 +text{*Strict monotonicity in both arguments*}
  26.627 +lemma mult_strict_mono:
  26.628 +  assumes "a < b" and "c < d" and "0 < b" and "0 \<le> c"
  26.629 +  shows "a * c < b * d"
  26.630 +  using assms apply (cases "c=0")
  26.631 +  apply (simp add: mult_pos_pos)
  26.632 +  apply (erule mult_strict_right_mono [THEN less_trans])
  26.633 +  apply (force simp add: le_less)
  26.634 +  apply (erule mult_strict_left_mono, assumption)
  26.635 +  done
  26.636 +
  26.637 +text{*This weaker variant has more natural premises*}
  26.638 +lemma mult_strict_mono':
  26.639 +  assumes "a < b" and "c < d" and "0 \<le> a" and "0 \<le> c"
  26.640 +  shows "a * c < b * d"
  26.641 +by (rule mult_strict_mono) (insert assms, auto)
  26.642 +
  26.643 +lemma mult_less_le_imp_less:
  26.644 +  assumes "a < b" and "c \<le> d" and "0 \<le> a" and "0 < c"
  26.645 +  shows "a * c < b * d"
  26.646 +  using assms apply (subgoal_tac "a * c < b * c")
  26.647 +  apply (erule less_le_trans)
  26.648 +  apply (erule mult_left_mono)
  26.649 +  apply simp
  26.650 +  apply (erule mult_strict_right_mono)
  26.651 +  apply assumption
  26.652 +  done
  26.653 +
  26.654 +lemma mult_le_less_imp_less:
  26.655 +  assumes "a \<le> b" and "c < d" and "0 < a" and "0 \<le> c"
  26.656 +  shows "a * c < b * d"
  26.657 +  using assms apply (subgoal_tac "a * c \<le> b * c")
  26.658 +  apply (erule le_less_trans)
  26.659 +  apply (erule mult_strict_left_mono)
  26.660 +  apply simp
  26.661 +  apply (erule mult_right_mono)
  26.662 +  apply simp
  26.663 +  done
  26.664 +
  26.665 +lemma mult_less_imp_less_left:
  26.666 +  assumes less: "c * a < c * b" and nonneg: "0 \<le> c"
  26.667 +  shows "a < b"
  26.668 +proof (rule ccontr)
  26.669 +  assume "\<not>  a < b"
  26.670 +  hence "b \<le> a" by (simp add: linorder_not_less)
  26.671 +  hence "c * b \<le> c * a" using nonneg by (rule mult_left_mono)
  26.672 +  with this and less show False by (simp add: not_less [symmetric])
  26.673 +qed
  26.674 +
  26.675 +lemma mult_less_imp_less_right:
  26.676 +  assumes less: "a * c < b * c" and nonneg: "0 \<le> c"
  26.677 +  shows "a < b"
  26.678 +proof (rule ccontr)
  26.679 +  assume "\<not> a < b"
  26.680 +  hence "b \<le> a" by (simp add: linorder_not_less)
  26.681 +  hence "b * c \<le> a * c" using nonneg by (rule mult_right_mono)
  26.682 +  with this and less show False by (simp add: not_less [symmetric])
  26.683 +qed  
  26.684 +
  26.685 +end
  26.686 +
  26.687 +class linlinordered_semiring_1_strict = linordered_semiring_strict + semiring_1
  26.688 +
  26.689 +class mult_mono1 = times + zero + ord +
  26.690 +  assumes mult_mono1: "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
  26.691 +
  26.692 +class ordered_comm_semiring = comm_semiring_0
  26.693 +  + ordered_ab_semigroup_add + mult_mono1
  26.694 +begin
  26.695 +
  26.696 +subclass ordered_semiring
  26.697 +proof
  26.698 +  fix a b c :: 'a
  26.699 +  assume "a \<le> b" "0 \<le> c"
  26.700 +  thus "c * a \<le> c * b" by (rule mult_mono1)
  26.701 +  thus "a * c \<le> b * c" by (simp only: mult_commute)
  26.702 +qed
  26.703 +
  26.704 +end
  26.705 +
  26.706 +class ordered_cancel_comm_semiring = comm_semiring_0_cancel
  26.707 +  + ordered_ab_semigroup_add + mult_mono1
  26.708 +begin
  26.709 +
  26.710 +subclass ordered_comm_semiring ..
  26.711 +subclass ordered_cancel_semiring ..
  26.712 +
  26.713 +end
  26.714 +
  26.715 +class linordered_comm_semiring_strict = comm_semiring_0 + linordered_cancel_ab_semigroup_add +
  26.716 +  assumes mult_strict_left_mono_comm: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
  26.717 +begin
  26.718 +
  26.719 +subclass linordered_semiring_strict
  26.720 +proof
  26.721 +  fix a b c :: 'a
  26.722 +  assume "a < b" "0 < c"
  26.723 +  thus "c * a < c * b" by (rule mult_strict_left_mono_comm)
  26.724 +  thus "a * c < b * c" by (simp only: mult_commute)
  26.725 +qed
  26.726 +
  26.727 +subclass ordered_cancel_comm_semiring
  26.728 +proof
  26.729 +  fix a b c :: 'a
  26.730 +  assume "a \<le> b" "0 \<le> c"
  26.731 +  thus "c * a \<le> c * b"
  26.732 +    unfolding le_less
  26.733 +    using mult_strict_left_mono by (cases "c = 0") auto
  26.734 +qed
  26.735 +
  26.736 +end
  26.737 +
  26.738 +class ordered_ring = ring + ordered_cancel_semiring 
  26.739 +begin
  26.740 +
  26.741 +subclass ordered_ab_group_add ..
  26.742 +
  26.743 +text{*Legacy - use @{text algebra_simps} *}
  26.744 +lemmas ring_simps[noatp] = algebra_simps
  26.745 +
  26.746 +lemma less_add_iff1:
  26.747 +  "a * e + c < b * e + d \<longleftrightarrow> (a - b) * e + c < d"
  26.748 +by (simp add: algebra_simps)
  26.749 +
  26.750 +lemma less_add_iff2:
  26.751 +  "a * e + c < b * e + d \<longleftrightarrow> c < (b - a) * e + d"
  26.752 +by (simp add: algebra_simps)
  26.753 +
  26.754 +lemma le_add_iff1:
  26.755 +  "a * e + c \<le> b * e + d \<longleftrightarrow> (a - b) * e + c \<le> d"
  26.756 +by (simp add: algebra_simps)
  26.757 +
  26.758 +lemma le_add_iff2:
  26.759 +  "a * e + c \<le> b * e + d \<longleftrightarrow> c \<le> (b - a) * e + d"
  26.760 +by (simp add: algebra_simps)
  26.761 +
  26.762 +lemma mult_left_mono_neg:
  26.763 +  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> c * a \<le> c * b"
  26.764 +  apply (drule mult_left_mono [of _ _ "uminus c"])
  26.765 +  apply (simp_all add: minus_mult_left [symmetric]) 
  26.766 +  done
  26.767 +
  26.768 +lemma mult_right_mono_neg:
  26.769 +  "b \<le> a \<Longrightarrow> c \<le> 0 \<Longrightarrow> a * c \<le> b * c"
  26.770 +  apply (drule mult_right_mono [of _ _ "uminus c"])
  26.771 +  apply (simp_all add: minus_mult_right [symmetric]) 
  26.772 +  done
  26.773 +
  26.774 +lemma mult_nonpos_nonpos: "a \<le> 0 \<Longrightarrow> b \<le> 0 \<Longrightarrow> 0 \<le> a * b"
  26.775 +using mult_right_mono_neg [of a zero b] by simp
  26.776 +
  26.777 +lemma split_mult_pos_le:
  26.778 +  "(0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0) \<Longrightarrow> 0 \<le> a * b"
  26.779 +by (auto simp add: mult_nonneg_nonneg mult_nonpos_nonpos)
  26.780 +
  26.781 +end
  26.782 +
  26.783 +class abs_if = minus + uminus + ord + zero + abs +
  26.784 +  assumes abs_if: "\<bar>a\<bar> = (if a < 0 then - a else a)"
  26.785 +
  26.786 +class sgn_if = minus + uminus + zero + one + ord + sgn +
  26.787 +  assumes sgn_if: "sgn x = (if x = 0 then 0 else if 0 < x then 1 else - 1)"
  26.788 +
  26.789 +lemma (in sgn_if) sgn0[simp]: "sgn 0 = 0"
  26.790 +by(simp add:sgn_if)
  26.791 +
  26.792 +class linordered_ring = ring + linordered_semiring + linordered_ab_group_add + abs_if
  26.793 +begin
  26.794 +
  26.795 +subclass ordered_ring ..
  26.796 +
  26.797 +subclass ordered_ab_group_add_abs
  26.798 +proof
  26.799 +  fix a b
  26.800 +  show "\<bar>a + b\<bar> \<le> \<bar>a\<bar> + \<bar>b\<bar>"
  26.801 +    by (auto simp add: abs_if not_less neg_less_eq_nonneg less_eq_neg_nonpos)
  26.802 +    (auto simp del: minus_add_distrib simp add: minus_add_distrib [symmetric]
  26.803 +     neg_less_eq_nonneg less_eq_neg_nonpos, auto intro: add_nonneg_nonneg,
  26.804 +      auto intro!: less_imp_le add_neg_neg)
  26.805 +qed (auto simp add: abs_if less_eq_neg_nonpos neg_equal_zero)
  26.806 +
  26.807 +end
  26.808 +
  26.809 +(* The "strict" suffix can be seen as describing the combination of linordered_ring and no_zero_divisors.
  26.810 +   Basically, linordered_ring + no_zero_divisors = linordered_ring_strict.
  26.811 + *)
  26.812 +class linordered_ring_strict = ring + linordered_semiring_strict
  26.813 +  + ordered_ab_group_add + abs_if
  26.814 +begin
  26.815 +
  26.816 +subclass linordered_ring ..
  26.817 +
  26.818 +lemma mult_strict_left_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> c * a < c * b"
  26.819 +using mult_strict_left_mono [of b a "- c"] by simp
  26.820 +
  26.821 +lemma mult_strict_right_mono_neg: "b < a \<Longrightarrow> c < 0 \<Longrightarrow> a * c < b * c"
  26.822 +using mult_strict_right_mono [of b a "- c"] by simp
  26.823 +
  26.824 +lemma mult_neg_neg: "a < 0 \<Longrightarrow> b < 0 \<Longrightarrow> 0 < a * b"
  26.825 +using mult_strict_right_mono_neg [of a zero b] by simp
  26.826 +
  26.827 +subclass ring_no_zero_divisors
  26.828 +proof
  26.829 +  fix a b
  26.830 +  assume "a \<noteq> 0" then have A: "a < 0 \<or> 0 < a" by (simp add: neq_iff)
  26.831 +  assume "b \<noteq> 0" then have B: "b < 0 \<or> 0 < b" by (simp add: neq_iff)
  26.832 +  have "a * b < 0 \<or> 0 < a * b"
  26.833 +  proof (cases "a < 0")
  26.834 +    case True note A' = this
  26.835 +    show ?thesis proof (cases "b < 0")
  26.836 +      case True with A'
  26.837 +      show ?thesis by (auto dest: mult_neg_neg)
  26.838 +    next
  26.839 +      case False with B have "0 < b" by auto
  26.840 +      with A' show ?thesis by (auto dest: mult_strict_right_mono)
  26.841 +    qed
  26.842 +  next
  26.843 +    case False with A have A': "0 < a" by auto
  26.844 +    show ?thesis proof (cases "b < 0")
  26.845 +      case True with A'
  26.846 +      show ?thesis by (auto dest: mult_strict_right_mono_neg)
  26.847 +    next
  26.848 +      case False with B have "0 < b" by auto
  26.849 +      with A' show ?thesis by (auto dest: mult_pos_pos)
  26.850 +    qed
  26.851 +  qed
  26.852 +  then show "a * b \<noteq> 0" by (simp add: neq_iff)
  26.853 +qed
  26.854 +
  26.855 +lemma zero_less_mult_iff:
  26.856 +  "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < b \<or> a < 0 \<and> b < 0"
  26.857 +  apply (auto simp add: mult_pos_pos mult_neg_neg)
  26.858 +  apply (simp_all add: not_less le_less)
  26.859 +  apply (erule disjE) apply assumption defer
  26.860 +  apply (erule disjE) defer apply (drule sym) apply simp
  26.861 +  apply (erule disjE) defer apply (drule sym) apply simp
  26.862 +  apply (erule disjE) apply assumption apply (drule sym) apply simp
  26.863 +  apply (drule sym) apply simp
  26.864 +  apply (blast dest: zero_less_mult_pos)
  26.865 +  apply (blast dest: zero_less_mult_pos2)
  26.866 +  done
  26.867 +
  26.868 +lemma zero_le_mult_iff:
  26.869 +  "0 \<le> a * b \<longleftrightarrow> 0 \<le> a \<and> 0 \<le> b \<or> a \<le> 0 \<and> b \<le> 0"
  26.870 +by (auto simp add: eq_commute [of 0] le_less not_less zero_less_mult_iff)
  26.871 +
  26.872 +lemma mult_less_0_iff:
  26.873 +  "a * b < 0 \<longleftrightarrow> 0 < a \<and> b < 0 \<or> a < 0 \<and> 0 < b"
  26.874 +  apply (insert zero_less_mult_iff [of "-a" b]) 
  26.875 +  apply (force simp add: minus_mult_left[symmetric]) 
  26.876 +  done
  26.877 +
  26.878 +lemma mult_le_0_iff:
  26.879 +  "a * b \<le> 0 \<longleftrightarrow> 0 \<le> a \<and> b \<le> 0 \<or> a \<le> 0 \<and> 0 \<le> b"
  26.880 +  apply (insert zero_le_mult_iff [of "-a" b]) 
  26.881 +  apply (force simp add: minus_mult_left[symmetric]) 
  26.882 +  done
  26.883 +
  26.884 +lemma zero_le_square [simp]: "0 \<le> a * a"
  26.885 +by (simp add: zero_le_mult_iff linear)
  26.886 +
  26.887 +lemma not_square_less_zero [simp]: "\<not> (a * a < 0)"
  26.888 +by (simp add: not_less)
  26.889 +
  26.890 +text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
  26.891 +   also with the relations @{text "\<le>"} and equality.*}
  26.892 +
  26.893 +text{*These ``disjunction'' versions produce two cases when the comparison is
  26.894 + an assumption, but effectively four when the comparison is a goal.*}
  26.895 +
  26.896 +lemma mult_less_cancel_right_disj:
  26.897 +  "a * c < b * c \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
  26.898 +  apply (cases "c = 0")
  26.899 +  apply (auto simp add: neq_iff mult_strict_right_mono 
  26.900 +                      mult_strict_right_mono_neg)
  26.901 +  apply (auto simp add: not_less 
  26.902 +                      not_le [symmetric, of "a*c"]
  26.903 +                      not_le [symmetric, of a])
  26.904 +  apply (erule_tac [!] notE)
  26.905 +  apply (auto simp add: less_imp_le mult_right_mono 
  26.906 +                      mult_right_mono_neg)
  26.907 +  done
  26.908 +
  26.909 +lemma mult_less_cancel_left_disj:
  26.910 +  "c * a < c * b \<longleftrightarrow> 0 < c \<and> a < b \<or> c < 0 \<and>  b < a"
  26.911 +  apply (cases "c = 0")
  26.912 +  apply (auto simp add: neq_iff mult_strict_left_mono 
  26.913 +                      mult_strict_left_mono_neg)
  26.914 +  apply (auto simp add: not_less 
  26.915 +                      not_le [symmetric, of "c*a"]
  26.916 +                      not_le [symmetric, of a])
  26.917 +  apply (erule_tac [!] notE)
  26.918 +  apply (auto simp add: less_imp_le mult_left_mono 
  26.919 +                      mult_left_mono_neg)
  26.920 +  done
  26.921 +
  26.922 +text{*The ``conjunction of implication'' lemmas produce two cases when the
  26.923 +comparison is a goal, but give four when the comparison is an assumption.*}
  26.924 +
  26.925 +lemma mult_less_cancel_right:
  26.926 +  "a * c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
  26.927 +  using mult_less_cancel_right_disj [of a c b] by auto
  26.928 +
  26.929 +lemma mult_less_cancel_left:
  26.930 +  "c * a < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < b) \<and> (c \<le> 0 \<longrightarrow> b < a)"
  26.931 +  using mult_less_cancel_left_disj [of c a b] by auto
  26.932 +
  26.933 +lemma mult_le_cancel_right:
  26.934 +   "a * c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
  26.935 +by (simp add: not_less [symmetric] mult_less_cancel_right_disj)
  26.936 +
  26.937 +lemma mult_le_cancel_left:
  26.938 +  "c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
  26.939 +by (simp add: not_less [symmetric] mult_less_cancel_left_disj)
  26.940 +
  26.941 +lemma mult_le_cancel_left_pos:
  26.942 +  "0 < c \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> a \<le> b"
  26.943 +by (auto simp: mult_le_cancel_left)
  26.944 +
  26.945 +lemma mult_le_cancel_left_neg:
  26.946 +  "c < 0 \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> b \<le> a"
  26.947 +by (auto simp: mult_le_cancel_left)
  26.948 +
  26.949 +lemma mult_less_cancel_left_pos:
  26.950 +  "0 < c \<Longrightarrow> c * a < c * b \<longleftrightarrow> a < b"
  26.951 +by (auto simp: mult_less_cancel_left)
  26.952 +
  26.953 +lemma mult_less_cancel_left_neg:
  26.954 +  "c < 0 \<Longrightarrow> c * a < c * b \<longleftrightarrow> b < a"
  26.955 +by (auto simp: mult_less_cancel_left)
  26.956 +
  26.957 +end
  26.958 +
  26.959 +text{*Legacy - use @{text algebra_simps} *}
  26.960 +lemmas ring_simps[noatp] = algebra_simps
  26.961 +
  26.962 +lemmas mult_sign_intros =
  26.963 +  mult_nonneg_nonneg mult_nonneg_nonpos
  26.964 +  mult_nonpos_nonneg mult_nonpos_nonpos
  26.965 +  mult_pos_pos mult_pos_neg
  26.966 +  mult_neg_pos mult_neg_neg
  26.967 +
  26.968 +class ordered_comm_ring = comm_ring + ordered_comm_semiring
  26.969 +begin
  26.970 +
  26.971 +subclass ordered_ring ..
  26.972 +subclass ordered_cancel_comm_semiring ..
  26.973 +
  26.974 +end
  26.975 +
  26.976 +class linordered_semidom = comm_semiring_1_cancel + linordered_comm_semiring_strict +
  26.977 +  (*previously linordered_semiring*)
  26.978 +  assumes zero_less_one [simp]: "0 < 1"
  26.979 +begin
  26.980 +
  26.981 +lemma pos_add_strict:
  26.982 +  shows "0 < a \<Longrightarrow> b < c \<Longrightarrow> b < a + c"
  26.983 +  using add_strict_mono [of zero a b c] by simp
  26.984 +
  26.985 +lemma zero_le_one [simp]: "0 \<le> 1"
  26.986 +by (rule zero_less_one [THEN less_imp_le]) 
  26.987 +
  26.988 +lemma not_one_le_zero [simp]: "\<not> 1 \<le> 0"
  26.989 +by (simp add: not_le) 
  26.990 +
  26.991 +lemma not_one_less_zero [simp]: "\<not> 1 < 0"
  26.992 +by (simp add: not_less) 
  26.993 +
  26.994 +lemma less_1_mult:
  26.995 +  assumes "1 < m" and "1 < n"
  26.996 +  shows "1 < m * n"
  26.997 +  using assms mult_strict_mono [of 1 m 1 n]
  26.998 +    by (simp add:  less_trans [OF zero_less_one]) 
  26.999 +
 26.1000 +end
 26.1001 +
 26.1002 +class linordered_idom = comm_ring_1 +
 26.1003 +  linordered_comm_semiring_strict + ordered_ab_group_add +
 26.1004 +  abs_if + sgn_if
 26.1005 +  (*previously linordered_ring*)
 26.1006 +begin
 26.1007 +
 26.1008 +subclass linordered_ring_strict ..
 26.1009 +subclass ordered_comm_ring ..
 26.1010 +subclass idom ..
 26.1011 +
 26.1012 +subclass linordered_semidom
 26.1013 +proof
 26.1014 +  have "0 \<le> 1 * 1" by (rule zero_le_square)
 26.1015 +  thus "0 < 1" by (simp add: le_less)
 26.1016 +qed 
 26.1017 +
 26.1018 +lemma linorder_neqE_linordered_idom:
 26.1019 +  assumes "x \<noteq> y" obtains "x < y" | "y < x"
 26.1020 +  using assms by (rule neqE)
 26.1021 +
 26.1022 +text {* These cancellation simprules also produce two cases when the comparison is a goal. *}
 26.1023 +
 26.1024 +lemma mult_le_cancel_right1:
 26.1025 +  "c \<le> b * c \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
 26.1026 +by (insert mult_le_cancel_right [of 1 c b], simp)
 26.1027 +
 26.1028 +lemma mult_le_cancel_right2:
 26.1029 +  "a * c \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
 26.1030 +by (insert mult_le_cancel_right [of a c 1], simp)
 26.1031 +
 26.1032 +lemma mult_le_cancel_left1:
 26.1033 +  "c \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> 1 \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> 1)"
 26.1034 +by (insert mult_le_cancel_left [of c 1 b], simp)
 26.1035 +
 26.1036 +lemma mult_le_cancel_left2:
 26.1037 +  "c * a \<le> c \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> 1) \<and> (c < 0 \<longrightarrow> 1 \<le> a)"
 26.1038 +by (insert mult_le_cancel_left [of c a 1], simp)
 26.1039 +
 26.1040 +lemma mult_less_cancel_right1:
 26.1041 +  "c < b * c \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
 26.1042 +by (insert mult_less_cancel_right [of 1 c b], simp)
 26.1043 +
 26.1044 +lemma mult_less_cancel_right2:
 26.1045 +  "a * c < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
 26.1046 +by (insert mult_less_cancel_right [of a c 1], simp)
 26.1047 +
 26.1048 +lemma mult_less_cancel_left1:
 26.1049 +  "c < c * b \<longleftrightarrow> (0 \<le> c \<longrightarrow> 1 < b) \<and> (c \<le> 0 \<longrightarrow> b < 1)"
 26.1050 +by (insert mult_less_cancel_left [of c 1 b], simp)
 26.1051 +
 26.1052 +lemma mult_less_cancel_left2:
 26.1053 +  "c * a < c \<longleftrightarrow> (0 \<le> c \<longrightarrow> a < 1) \<and> (c \<le> 0 \<longrightarrow> 1 < a)"
 26.1054 +by (insert mult_less_cancel_left [of c a 1], simp)
 26.1055 +
 26.1056 +lemma sgn_sgn [simp]:
 26.1057 +  "sgn (sgn a) = sgn a"
 26.1058 +unfolding sgn_if by simp
 26.1059 +
 26.1060 +lemma sgn_0_0:
 26.1061 +  "sgn a = 0 \<longleftrightarrow> a = 0"
 26.1062 +unfolding sgn_if by simp
 26.1063 +
 26.1064 +lemma sgn_1_pos:
 26.1065 +  "sgn a = 1 \<longleftrightarrow> a > 0"
 26.1066 +unfolding sgn_if by (simp add: neg_equal_zero)
 26.1067 +
 26.1068 +lemma sgn_1_neg:
 26.1069 +  "sgn a = - 1 \<longleftrightarrow> a < 0"
 26.1070 +unfolding sgn_if by (auto simp add: equal_neg_zero)
 26.1071 +
 26.1072 +lemma sgn_pos [simp]:
 26.1073 +  "0 < a \<Longrightarrow> sgn a = 1"
 26.1074 +unfolding sgn_1_pos .
 26.1075 +
 26.1076 +lemma sgn_neg [simp]:
 26.1077 +  "a < 0 \<Longrightarrow> sgn a = - 1"
 26.1078 +unfolding sgn_1_neg .
 26.1079 +
 26.1080 +lemma sgn_times:
 26.1081 +  "sgn (a * b) = sgn a * sgn b"
 26.1082 +by (auto simp add: sgn_if zero_less_mult_iff)
 26.1083 +
 26.1084 +lemma abs_sgn: "abs k = k * sgn k"
 26.1085 +unfolding sgn_if abs_if by auto
 26.1086 +
 26.1087 +lemma sgn_greater [simp]:
 26.1088 +  "0 < sgn a \<longleftrightarrow> 0 < a"
 26.1089 +  unfolding sgn_if by auto
 26.1090 +
 26.1091 +lemma sgn_less [simp]:
 26.1092 +  "sgn a < 0 \<longleftrightarrow> a < 0"
 26.1093 +  unfolding sgn_if by auto
 26.1094 +
 26.1095 +lemma abs_dvd_iff [simp]: "(abs m) dvd k \<longleftrightarrow> m dvd k"
 26.1096 +  by (simp add: abs_if)
 26.1097 +
 26.1098 +lemma dvd_abs_iff [simp]: "m dvd (abs k) \<longleftrightarrow> m dvd k"
 26.1099 +  by (simp add: abs_if)
 26.1100 +
 26.1101 +lemma dvd_if_abs_eq:
 26.1102 +  "abs l = abs (k) \<Longrightarrow> l dvd k"
 26.1103 +by(subst abs_dvd_iff[symmetric]) simp
 26.1104 +
 26.1105 +end
 26.1106 +
 26.1107 +text {* Simprules for comparisons where common factors can be cancelled. *}
 26.1108 +
 26.1109 +lemmas mult_compare_simps[noatp] =
 26.1110 +    mult_le_cancel_right mult_le_cancel_left
 26.1111 +    mult_le_cancel_right1 mult_le_cancel_right2
 26.1112 +    mult_le_cancel_left1 mult_le_cancel_left2
 26.1113 +    mult_less_cancel_right mult_less_cancel_left
 26.1114 +    mult_less_cancel_right1 mult_less_cancel_right2
 26.1115 +    mult_less_cancel_left1 mult_less_cancel_left2
 26.1116 +    mult_cancel_right mult_cancel_left
 26.1117 +    mult_cancel_right1 mult_cancel_right2
 26.1118 +    mult_cancel_left1 mult_cancel_left2
 26.1119 +
 26.1120 +-- {* FIXME continue localization here *}
 26.1121 +
 26.1122 +subsection {* Reasoning about inequalities with division *}
 26.1123 +
 26.1124 +lemma mult_right_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
 26.1125 +    ==> x * y <= x"
 26.1126 +by (auto simp add: mult_compare_simps)
 26.1127 +
 26.1128 +lemma mult_left_le_one_le: "0 <= (x::'a::linordered_idom) ==> 0 <= y ==> y <= 1
 26.1129 +    ==> y * x <= x"
 26.1130 +by (auto simp add: mult_compare_simps)
 26.1131 +
 26.1132 +context linordered_semidom
 26.1133 +begin
 26.1134 +
 26.1135 +lemma less_add_one: "a < a + 1"
 26.1136 +proof -
 26.1137 +  have "a + 0 < a + 1"
 26.1138 +    by (blast intro: zero_less_one add_strict_left_mono)
 26.1139 +  thus ?thesis by simp
 26.1140 +qed
 26.1141 +
 26.1142 +lemma zero_less_two: "0 < 1 + 1"
 26.1143 +by (blast intro: less_trans zero_less_one less_add_one)
 26.1144 +
 26.1145 +end
 26.1146 +
 26.1147 +
 26.1148 +subsection {* Absolute Value *}
 26.1149 +
 26.1150 +context linordered_idom
 26.1151 +begin
 26.1152 +
 26.1153 +lemma mult_sgn_abs: "sgn x * abs x = x"
 26.1154 +  unfolding abs_if sgn_if by auto
 26.1155 +
 26.1156 +end
 26.1157 +
 26.1158 +lemma abs_one [simp]: "abs 1 = (1::'a::linordered_idom)"
 26.1159 +by (simp add: abs_if zero_less_one [THEN order_less_not_sym])
 26.1160 +
 26.1161 +class ordered_ring_abs = ordered_ring + ordered_ab_group_add_abs +
 26.1162 +  assumes abs_eq_mult:
 26.1163 +    "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0) \<Longrightarrow> \<bar>a * b\<bar> = \<bar>a\<bar> * \<bar>b\<bar>"
 26.1164 +
 26.1165 +context linordered_idom
 26.1166 +begin
 26.1167 +
 26.1168 +subclass ordered_ring_abs proof
 26.1169 +qed (auto simp add: abs_if not_less equal_neg_zero neg_equal_zero mult_less_0_iff)
 26.1170 +
 26.1171 +lemma abs_mult:
 26.1172 +  "abs (a * b) = abs a * abs b" 
 26.1173 +  by (rule abs_eq_mult) auto
 26.1174 +
 26.1175 +lemma abs_mult_self:
 26.1176 +  "abs a * abs a = a * a"
 26.1177 +  by (simp add: abs_if) 
 26.1178 +
 26.1179 +end
 26.1180 +
 26.1181 +lemma abs_mult_less:
 26.1182 +     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::linordered_idom)"
 26.1183 +proof -
 26.1184 +  assume ac: "abs a < c"
 26.1185 +  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
 26.1186 +  assume "abs b < d"
 26.1187 +  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
 26.1188 +qed
 26.1189 +
 26.1190 +lemmas eq_minus_self_iff[noatp] = equal_neg_zero
 26.1191 +
 26.1192 +lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::linordered_idom))"