src/HOL/Hyperreal/HyperDef.thy
changeset 14329 ff3210fe968f
parent 14305 f17ca9f6dc8c
child 14331 8dbbb7cf3637
     1.1 --- a/src/HOL/Hyperreal/HyperDef.thy	Wed Dec 24 08:54:30 2003 +0100
     1.2 +++ b/src/HOL/Hyperreal/HyperDef.thy	Thu Dec 25 22:48:32 2003 +0100
     1.3 @@ -84,12 +84,14 @@
     1.4    hypreal_le_def:
     1.5    "P <= (Q::hypreal) == ~(Q < P)"
     1.6  
     1.7 -(*------------------------------------------------------------------------
     1.8 -             Proof that the set of naturals is not finite
     1.9 - ------------------------------------------------------------------------*)
    1.10 +  hrabs_def:  "abs (r::hypreal) == (if 0 \<le> r then r else -r)"
    1.11 +
    1.12 +
    1.13 +subsection{*The Set of Naturals is not Finite*}
    1.14  
    1.15  (*** based on James' proof that the set of naturals is not finite ***)
    1.16 -lemma finite_exhausts [rule_format (no_asm)]: "finite (A::nat set) --> (\<exists>n. \<forall>m. Suc (n + m) \<notin> A)"
    1.17 +lemma finite_exhausts [rule_format]:
    1.18 +     "finite (A::nat set) --> (\<exists>n. \<forall>m. Suc (n + m) \<notin> A)"
    1.19  apply (rule impI)
    1.20  apply (erule_tac F = A in finite_induct)
    1.21  apply (blast, erule exE)
    1.22 @@ -98,16 +100,18 @@
    1.23  apply (auto simp add: add_ac)
    1.24  done
    1.25  
    1.26 -lemma finite_not_covers [rule_format (no_asm)]: "finite (A :: nat set) --> (\<exists>n. n \<notin>A)"
    1.27 +lemma finite_not_covers [rule_format (no_asm)]:
    1.28 +     "finite (A :: nat set) --> (\<exists>n. n \<notin>A)"
    1.29  by (rule impI, drule finite_exhausts, blast)
    1.30  
    1.31  lemma not_finite_nat: "~ finite(UNIV:: nat set)"
    1.32  by (fast dest!: finite_exhausts)
    1.33  
    1.34 -(*------------------------------------------------------------------------
    1.35 -   Existence of free ultrafilter over the naturals and proof of various 
    1.36 -   properties of the FreeUltrafilterNat- an arbitrary free ultrafilter
    1.37 - ------------------------------------------------------------------------*)
    1.38 +
    1.39 +subsection{*Existence of Free Ultrafilter over the Naturals*}
    1.40 +
    1.41 +text{*Also, proof of various properties of @{term FreeUltrafilterNat}: 
    1.42 +an arbitrary free ultrafilter*}
    1.43  
    1.44  lemma FreeUltrafilterNat_Ex: "\<exists>U. U: FreeUltrafilter (UNIV::nat set)"
    1.45  by (rule not_finite_nat [THEN FreeUltrafilter_Ex])
    1.46 @@ -137,33 +141,39 @@
    1.47                     Filter_empty_not_mem)
    1.48  done
    1.49  
    1.50 -lemma FreeUltrafilterNat_Int: "[| X: FreeUltrafilterNat;  Y: FreeUltrafilterNat |]   
    1.51 +lemma FreeUltrafilterNat_Int:
    1.52 +     "[| X: FreeUltrafilterNat;  Y: FreeUltrafilterNat |]   
    1.53        ==> X Int Y \<in> FreeUltrafilterNat"
    1.54  apply (cut_tac FreeUltrafilterNat_mem)
    1.55  apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter mem_FiltersetD1)
    1.56  done
    1.57  
    1.58 -lemma FreeUltrafilterNat_subset: "[| X: FreeUltrafilterNat;  X <= Y |]  
    1.59 +lemma FreeUltrafilterNat_subset:
    1.60 +     "[| X: FreeUltrafilterNat;  X <= Y |]  
    1.61        ==> Y \<in> FreeUltrafilterNat"
    1.62  apply (cut_tac FreeUltrafilterNat_mem)
    1.63  apply (blast dest: FreeUltrafilter_Ultrafilter Ultrafilter_Filter mem_FiltersetD2)
    1.64  done
    1.65  
    1.66 -lemma FreeUltrafilterNat_Compl: "X: FreeUltrafilterNat ==> -X \<notin> FreeUltrafilterNat"
    1.67 +lemma FreeUltrafilterNat_Compl:
    1.68 +     "X: FreeUltrafilterNat ==> -X \<notin> FreeUltrafilterNat"
    1.69  apply safe
    1.70  apply (drule FreeUltrafilterNat_Int, assumption, auto)
    1.71  done
    1.72  
    1.73 -lemma FreeUltrafilterNat_Compl_mem: "X\<notin> FreeUltrafilterNat ==> -X \<in> FreeUltrafilterNat"
    1.74 +lemma FreeUltrafilterNat_Compl_mem:
    1.75 +     "X\<notin> FreeUltrafilterNat ==> -X \<in> FreeUltrafilterNat"
    1.76  apply (cut_tac FreeUltrafilterNat_mem [THEN FreeUltrafilter_iff [THEN iffD1]])
    1.77  apply (safe, drule_tac x = X in bspec)
    1.78  apply (auto simp add: UNIV_diff_Compl)
    1.79  done
    1.80  
    1.81 -lemma FreeUltrafilterNat_Compl_iff1: "(X \<notin> FreeUltrafilterNat) = (-X: FreeUltrafilterNat)"
    1.82 +lemma FreeUltrafilterNat_Compl_iff1:
    1.83 +     "(X \<notin> FreeUltrafilterNat) = (-X: FreeUltrafilterNat)"
    1.84  by (blast dest: FreeUltrafilterNat_Compl FreeUltrafilterNat_Compl_mem)
    1.85  
    1.86 -lemma FreeUltrafilterNat_Compl_iff2: "(X: FreeUltrafilterNat) = (-X \<notin> FreeUltrafilterNat)"
    1.87 +lemma FreeUltrafilterNat_Compl_iff2:
    1.88 +     "(X: FreeUltrafilterNat) = (-X \<notin> FreeUltrafilterNat)"
    1.89  by (auto simp add: FreeUltrafilterNat_Compl_iff1 [symmetric])
    1.90  
    1.91  lemma FreeUltrafilterNat_UNIV [simp]: "(UNIV::nat set) \<in> FreeUltrafilterNat"
    1.92 @@ -172,7 +182,8 @@
    1.93  lemma FreeUltrafilterNat_Nat_set [simp]: "UNIV \<in> FreeUltrafilterNat"
    1.94  by auto
    1.95  
    1.96 -lemma FreeUltrafilterNat_Nat_set_refl [intro]: "{n. P(n) = P(n)} \<in> FreeUltrafilterNat"
    1.97 +lemma FreeUltrafilterNat_Nat_set_refl [intro]:
    1.98 +     "{n. P(n) = P(n)} \<in> FreeUltrafilterNat"
    1.99  by simp
   1.100  
   1.101  lemma FreeUltrafilterNat_P: "{n::nat. P} \<in> FreeUltrafilterNat ==> P"
   1.102 @@ -184,9 +195,8 @@
   1.103  lemma FreeUltrafilterNat_all: "\<forall>n. P(n) ==> {n. P(n)} \<in> FreeUltrafilterNat"
   1.104  by (auto intro: FreeUltrafilterNat_Nat_set)
   1.105  
   1.106 -(*-------------------------------------------------------
   1.107 -     Define and use Ultrafilter tactics
   1.108 - -------------------------------------------------------*)
   1.109 +
   1.110 +text{*Define and use Ultrafilter tactics*}
   1.111  use "fuf.ML"
   1.112  
   1.113  method_setup fuf = {*
   1.114 @@ -204,21 +214,18 @@
   1.115      "ultrafilter tactic"
   1.116  
   1.117  
   1.118 -(*-------------------------------------------------------
   1.119 -  Now prove one further property of our free ultrafilter
   1.120 - -------------------------------------------------------*)
   1.121 -lemma FreeUltrafilterNat_Un: "X Un Y: FreeUltrafilterNat  
   1.122 +text{*One further property of our free ultrafilter*}
   1.123 +lemma FreeUltrafilterNat_Un:
   1.124 +     "X Un Y: FreeUltrafilterNat  
   1.125        ==> X: FreeUltrafilterNat | Y: FreeUltrafilterNat"
   1.126  apply auto
   1.127  apply ultra
   1.128  done
   1.129  
   1.130 -(*-------------------------------------------------------
   1.131 -   Properties of hyprel
   1.132 - -------------------------------------------------------*)
   1.133  
   1.134 -(** Proving that hyprel is an equivalence relation **)
   1.135 -(** Natural deduction for hyprel **)
   1.136 +subsection{*Properties of @{term hyprel}*}
   1.137 +
   1.138 +text{*Proving that @{term hyprel} is an equivalence relation*}
   1.139  
   1.140  lemma hyprel_iff: "((X,Y): hyprel) = ({n. X n = Y n}: FreeUltrafilterNat)"
   1.141  by (unfold hyprel_def, fast)
   1.142 @@ -281,9 +288,8 @@
   1.143  by (cut_tac x = x in Rep_hypreal, auto)
   1.144  
   1.145  
   1.146 -(*------------------------------------------------------------------------
   1.147 -   hypreal_of_real: the injection from real to hypreal
   1.148 - ------------------------------------------------------------------------*)
   1.149 +subsection{*@{term hypreal_of_real}: 
   1.150 +            the Injection from @{typ real} to @{typ hypreal}*}
   1.151  
   1.152  lemma inj_hypreal_of_real: "inj(hypreal_of_real)"
   1.153  apply (rule inj_onI)
   1.154 @@ -302,7 +308,61 @@
   1.155  apply (force simp add: Rep_hypreal_inverse)
   1.156  done
   1.157  
   1.158 -(**** hypreal_minus: additive inverse on hypreal ****)
   1.159 +
   1.160 +subsection{*Hyperreal Addition*}
   1.161 +
   1.162 +lemma hypreal_add_congruent2: 
   1.163 +    "congruent2 hyprel (%X Y. hyprel``{%n. X n + Y n})"
   1.164 +apply (unfold congruent2_def, auto, ultra)
   1.165 +done
   1.166 +
   1.167 +lemma hypreal_add: 
   1.168 +  "Abs_hypreal(hyprel``{%n. X n}) + Abs_hypreal(hyprel``{%n. Y n}) =  
   1.169 +   Abs_hypreal(hyprel``{%n. X n + Y n})"
   1.170 +apply (unfold hypreal_add_def)
   1.171 +apply (simp add: UN_equiv_class2 [OF equiv_hyprel hypreal_add_congruent2])
   1.172 +done
   1.173 +
   1.174 +lemma hypreal_add_commute: "(z::hypreal) + w = w + z"
   1.175 +apply (rule_tac z = z in eq_Abs_hypreal)
   1.176 +apply (rule_tac z = w in eq_Abs_hypreal)
   1.177 +apply (simp add: real_add_ac hypreal_add)
   1.178 +done
   1.179 +
   1.180 +lemma hypreal_add_assoc: "((z1::hypreal) + z2) + z3 = z1 + (z2 + z3)"
   1.181 +apply (rule_tac z = z1 in eq_Abs_hypreal)
   1.182 +apply (rule_tac z = z2 in eq_Abs_hypreal)
   1.183 +apply (rule_tac z = z3 in eq_Abs_hypreal)
   1.184 +apply (simp add: hypreal_add real_add_assoc)
   1.185 +done
   1.186 +
   1.187 +(*For AC rewriting*)
   1.188 +lemma hypreal_add_left_commute: "(x::hypreal)+(y+z)=y+(x+z)"
   1.189 +  apply (rule mk_left_commute [of "op +"])
   1.190 +  apply (rule hypreal_add_assoc)
   1.191 +  apply (rule hypreal_add_commute)
   1.192 +  done
   1.193 +
   1.194 +(* hypreal addition is an AC operator *)
   1.195 +lemmas hypreal_add_ac =
   1.196 +       hypreal_add_assoc hypreal_add_commute hypreal_add_left_commute
   1.197 +
   1.198 +lemma hypreal_add_zero_left [simp]: "(0::hypreal) + z = z"
   1.199 +apply (unfold hypreal_zero_def)
   1.200 +apply (rule_tac z = z in eq_Abs_hypreal)
   1.201 +apply (simp add: hypreal_add)
   1.202 +done
   1.203 +
   1.204 +instance hypreal :: plus_ac0
   1.205 +  by (intro_classes,
   1.206 +      (assumption | 
   1.207 +       rule hypreal_add_commute hypreal_add_assoc hypreal_add_zero_left)+)
   1.208 +
   1.209 +lemma hypreal_add_zero_right [simp]: "z + (0::hypreal) = z"
   1.210 +by (simp add: hypreal_add_zero_left hypreal_add_commute)
   1.211 +
   1.212 +
   1.213 +subsection{*Additive inverse on @{typ hypreal}*}
   1.214  
   1.215  lemma hypreal_minus_congruent: 
   1.216    "congruent hyprel (%X. hyprel``{%n. - (X n)})"
   1.217 @@ -337,59 +397,12 @@
   1.218  apply (auto simp add: hypreal_zero_def hypreal_minus)
   1.219  done
   1.220  
   1.221 -
   1.222 -(**** hyperreal addition: hypreal_add  ****)
   1.223 -
   1.224 -lemma hypreal_add_congruent2: 
   1.225 -    "congruent2 hyprel (%X Y. hyprel``{%n. X n + Y n})"
   1.226 -apply (unfold congruent2_def, auto, ultra)
   1.227 -done
   1.228 -
   1.229 -lemma hypreal_add: 
   1.230 -  "Abs_hypreal(hyprel``{%n. X n}) + Abs_hypreal(hyprel``{%n. Y n}) =  
   1.231 -   Abs_hypreal(hyprel``{%n. X n + Y n})"
   1.232 -apply (unfold hypreal_add_def)
   1.233 -apply (simp add: UN_equiv_class2 [OF equiv_hyprel hypreal_add_congruent2])
   1.234 -done
   1.235 -
   1.236 -lemma hypreal_diff: "Abs_hypreal(hyprel``{%n. X n}) - Abs_hypreal(hyprel``{%n. Y n}) =  
   1.237 +lemma hypreal_diff:
   1.238 +     "Abs_hypreal(hyprel``{%n. X n}) - Abs_hypreal(hyprel``{%n. Y n}) =  
   1.239        Abs_hypreal(hyprel``{%n. X n - Y n})"
   1.240  apply (simp add: hypreal_diff_def hypreal_minus hypreal_add)
   1.241  done
   1.242  
   1.243 -lemma hypreal_add_commute: "(z::hypreal) + w = w + z"
   1.244 -apply (rule_tac z = z in eq_Abs_hypreal)
   1.245 -apply (rule_tac z = w in eq_Abs_hypreal)
   1.246 -apply (simp add: real_add_ac hypreal_add)
   1.247 -done
   1.248 -
   1.249 -lemma hypreal_add_assoc: "((z1::hypreal) + z2) + z3 = z1 + (z2 + z3)"
   1.250 -apply (rule_tac z = z1 in eq_Abs_hypreal)
   1.251 -apply (rule_tac z = z2 in eq_Abs_hypreal)
   1.252 -apply (rule_tac z = z3 in eq_Abs_hypreal)
   1.253 -apply (simp add: hypreal_add real_add_assoc)
   1.254 -done
   1.255 -
   1.256 -(*For AC rewriting*)
   1.257 -lemma hypreal_add_left_commute: "(x::hypreal)+(y+z)=y+(x+z)"
   1.258 -  apply (rule mk_left_commute [of "op +"])
   1.259 -  apply (rule hypreal_add_assoc)
   1.260 -  apply (rule hypreal_add_commute)
   1.261 -  done
   1.262 -
   1.263 -(* hypreal addition is an AC operator *)
   1.264 -lemmas hypreal_add_ac =
   1.265 -       hypreal_add_assoc hypreal_add_commute hypreal_add_left_commute
   1.266 -
   1.267 -lemma hypreal_add_zero_left [simp]: "(0::hypreal) + z = z"
   1.268 -apply (unfold hypreal_zero_def)
   1.269 -apply (rule_tac z = z in eq_Abs_hypreal)
   1.270 -apply (simp add: hypreal_add)
   1.271 -done
   1.272 -
   1.273 -lemma hypreal_add_zero_right [simp]: "z + (0::hypreal) = z"
   1.274 -by (simp add: hypreal_add_zero_left hypreal_add_commute)
   1.275 -
   1.276  lemma hypreal_add_minus [simp]: "z + -z = (0::hypreal)"
   1.277  apply (unfold hypreal_zero_def)
   1.278  apply (rule_tac z = z in eq_Abs_hypreal)
   1.279 @@ -399,42 +412,6 @@
   1.280  lemma hypreal_add_minus_left [simp]: "-z + z = (0::hypreal)"
   1.281  by (simp add: hypreal_add_commute hypreal_add_minus)
   1.282  
   1.283 -lemma hypreal_minus_ex: "\<exists>y. (x::hypreal) + y = 0"
   1.284 -by (fast intro: hypreal_add_minus)
   1.285 -
   1.286 -lemma hypreal_minus_ex1: "EX! y. (x::hypreal) + y = 0"
   1.287 -apply (auto intro: hypreal_add_minus)
   1.288 -apply (drule_tac f = "%x. ya+x" in arg_cong)
   1.289 -apply (simp add: hypreal_add_assoc [symmetric])
   1.290 -apply (simp add: hypreal_add_commute)
   1.291 -done
   1.292 -
   1.293 -lemma hypreal_minus_left_ex1: "EX! y. y + (x::hypreal) = 0"
   1.294 -apply (auto intro: hypreal_add_minus_left)
   1.295 -apply (drule_tac f = "%x. x+ya" in arg_cong)
   1.296 -apply (simp add: hypreal_add_assoc)
   1.297 -apply (simp add: hypreal_add_commute)
   1.298 -done
   1.299 -
   1.300 -lemma hypreal_add_minus_eq_minus: "x + y = (0::hypreal) ==> x = -y"
   1.301 -apply (cut_tac z = y in hypreal_add_minus_left)
   1.302 -apply (rule_tac x1 = y in hypreal_minus_left_ex1 [THEN ex1E], blast)
   1.303 -done
   1.304 -
   1.305 -lemma hypreal_as_add_inverse_ex: "\<exists>y::hypreal. x = -y"
   1.306 -apply (cut_tac x = x in hypreal_minus_ex)
   1.307 -apply (erule exE, drule hypreal_add_minus_eq_minus, fast)
   1.308 -done
   1.309 -
   1.310 -lemma hypreal_minus_add_distrib [simp]: "-(x + (y::hypreal)) = -x + -y"
   1.311 -apply (rule_tac z = x in eq_Abs_hypreal)
   1.312 -apply (rule_tac z = y in eq_Abs_hypreal)
   1.313 -apply (auto simp add: hypreal_minus hypreal_add real_minus_add_distrib)
   1.314 -done
   1.315 -
   1.316 -lemma hypreal_minus_distrib1: "-(y + -(x::hypreal)) = x + -y"
   1.317 -by (simp add: hypreal_add_commute)
   1.318 -
   1.319  lemma hypreal_add_left_cancel: "((x::hypreal) + y = x + z) = (y = z)"
   1.320  apply safe
   1.321  apply (drule_tac f = "%t.-x + t" in arg_cong)
   1.322 @@ -450,7 +427,8 @@
   1.323  lemma hypreal_minus_add_cancelA [simp]: "(-z) + (z + w) = (w::hypreal)"
   1.324  by (simp add: hypreal_add_assoc [symmetric])
   1.325  
   1.326 -(**** hyperreal multiplication: hypreal_mult  ****)
   1.327 +
   1.328 +subsection{*Hyperreal Multiplication*}
   1.329  
   1.330  lemma hypreal_mult_congruent2: 
   1.331      "congruent2 hyprel (%X Y. hyprel``{%n. X n * Y n})"
   1.332 @@ -530,30 +508,30 @@
   1.333  lemma hypreal_minus_mult_commute: "(-x) * y = (x::hypreal) * -y"
   1.334  by auto
   1.335  
   1.336 -(*-----------------------------------------------------------------------------
   1.337 -    A few more theorems
   1.338 - ----------------------------------------------------------------------------*)
   1.339 -lemma hypreal_add_assoc_cong: "(z::hypreal) + v = z' + v' ==> z + (v + w) = z' + (v' + w)"
   1.340 -by (simp add: hypreal_add_assoc [symmetric])
   1.341 +subsection{*A few more theorems *}
   1.342  
   1.343 -lemma hypreal_add_mult_distrib: "((z1::hypreal) + z2) * w = (z1 * w) + (z2 * w)"
   1.344 +lemma hypreal_add_mult_distrib:
   1.345 +     "((z1::hypreal) + z2) * w = (z1 * w) + (z2 * w)"
   1.346  apply (rule_tac z = z1 in eq_Abs_hypreal)
   1.347  apply (rule_tac z = z2 in eq_Abs_hypreal)
   1.348  apply (rule_tac z = w in eq_Abs_hypreal)
   1.349  apply (simp add: hypreal_mult hypreal_add real_add_mult_distrib)
   1.350  done
   1.351  
   1.352 -lemma hypreal_add_mult_distrib2: "(w::hypreal) * (z1 + z2) = (w * z1) + (w * z2)"
   1.353 +lemma hypreal_add_mult_distrib2:
   1.354 +     "(w::hypreal) * (z1 + z2) = (w * z1) + (w * z2)"
   1.355  by (simp add: hypreal_mult_commute [of w] hypreal_add_mult_distrib)
   1.356  
   1.357  
   1.358 -lemma hypreal_diff_mult_distrib: "((z1::hypreal) - z2) * w = (z1 * w) - (z2 * w)"
   1.359 +lemma hypreal_diff_mult_distrib:
   1.360 +     "((z1::hypreal) - z2) * w = (z1 * w) - (z2 * w)"
   1.361  
   1.362  apply (unfold hypreal_diff_def)
   1.363  apply (simp add: hypreal_add_mult_distrib)
   1.364  done
   1.365  
   1.366 -lemma hypreal_diff_mult_distrib2: "(w::hypreal) * (z1 - z2) = (w * z1) - (w * z2)"
   1.367 +lemma hypreal_diff_mult_distrib2:
   1.368 +     "(w::hypreal) * (z1 - z2) = (w * z1) - (w * z2)"
   1.369  by (simp add: hypreal_mult_commute [of w] hypreal_diff_mult_distrib)
   1.370  
   1.371  (*** one and zero are distinct ***)
   1.372 @@ -563,7 +541,7 @@
   1.373  done
   1.374  
   1.375  
   1.376 -(**** multiplicative inverse on hypreal ****)
   1.377 +subsection{*Multiplicative Inverse on @{typ hypreal} *}
   1.378  
   1.379  lemma hypreal_inverse_congruent: 
   1.380    "congruent hyprel (%X. hyprel``{%n. if X n = 0 then 0 else inverse(X n)})"
   1.381 @@ -586,19 +564,15 @@
   1.382  lemma HYPREAL_DIVISION_BY_ZERO: "a / (0::hypreal) = 0"
   1.383  by (simp add: hypreal_divide_def HYPREAL_INVERSE_ZERO)
   1.384  
   1.385 -lemma hypreal_inverse_inverse [simp]: "inverse (inverse (z::hypreal)) = z"
   1.386 -apply (case_tac "z=0", simp add: HYPREAL_INVERSE_ZERO)
   1.387 -apply (rule_tac z = z in eq_Abs_hypreal)
   1.388 -apply (simp add: hypreal_inverse hypreal_zero_def)
   1.389 -done
   1.390 -
   1.391 -lemma hypreal_inverse_1 [simp]: "inverse((1::hypreal)) = (1::hypreal)"
   1.392 -apply (unfold hypreal_one_def)
   1.393 -apply (simp add: hypreal_inverse real_zero_not_eq_one [THEN not_sym])
   1.394 -done
   1.395 +instance hypreal :: division_by_zero
   1.396 +proof
   1.397 +  fix x :: hypreal
   1.398 +  show "inverse 0 = (0::hypreal)" by (rule HYPREAL_INVERSE_ZERO)
   1.399 +  show "x/0 = 0" by (rule HYPREAL_DIVISION_BY_ZERO) 
   1.400 +qed
   1.401  
   1.402  
   1.403 -(*** existence of inverse ***)
   1.404 +subsection{*Existence of Inverse*}
   1.405  
   1.406  lemma hypreal_mult_inverse [simp]: 
   1.407       "x \<noteq> 0 ==> x*inverse(x) = (1::hypreal)"
   1.408 @@ -609,99 +583,33 @@
   1.409  apply (blast intro!: real_mult_inv_right FreeUltrafilterNat_subset)
   1.410  done
   1.411  
   1.412 -lemma hypreal_mult_inverse_left [simp]: "x \<noteq> 0 ==> inverse(x)*x = (1::hypreal)"
   1.413 +lemma hypreal_mult_inverse_left [simp]:
   1.414 +     "x \<noteq> 0 ==> inverse(x)*x = (1::hypreal)"
   1.415  by (simp add: hypreal_mult_inverse hypreal_mult_commute)
   1.416  
   1.417 -lemma hypreal_mult_left_cancel: "(c::hypreal) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
   1.418 -apply auto
   1.419 -apply (drule_tac f = "%x. x*inverse c" in arg_cong)
   1.420 -apply (simp add: hypreal_mult_inverse hypreal_mult_ac)
   1.421 -done
   1.422 -    
   1.423 -lemma hypreal_mult_right_cancel: "(c::hypreal) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
   1.424 -apply safe
   1.425 -apply (drule_tac f = "%x. x*inverse c" in arg_cong)
   1.426 -apply (simp add: hypreal_mult_inverse hypreal_mult_ac)
   1.427 -done
   1.428 +
   1.429 +subsection{*Theorems for Ordering*}
   1.430 +
   1.431 +text{*TODO: define @{text "\<le>"} as the primitive concept and quickly 
   1.432 +establish membership in class @{text linorder}. Then proofs could be
   1.433 +simplified, since properties of @{text "<"} would be generic.*}
   1.434  
   1.435 -lemma hypreal_inverse_not_zero: "x \<noteq> 0 ==> inverse (x::hypreal) \<noteq> 0"
   1.436 -apply (unfold hypreal_zero_def)
   1.437 -apply (rule_tac z = x in eq_Abs_hypreal)
   1.438 -apply (simp add: hypreal_inverse hypreal_mult)
   1.439 -done
   1.440 -
   1.441 -
   1.442 -lemma hypreal_mult_not_0: "[| x \<noteq> 0; y \<noteq> 0 |] ==> x * y \<noteq> (0::hypreal)"
   1.443 -apply safe
   1.444 -apply (drule_tac f = "%z. inverse x*z" in arg_cong)
   1.445 -apply (simp add: hypreal_mult_assoc [symmetric])
   1.446 -done
   1.447 -
   1.448 -lemma hypreal_mult_zero_disj: "x*y = (0::hypreal) ==> x = 0 | y = 0"
   1.449 -by (auto intro: ccontr dest: hypreal_mult_not_0)
   1.450 -
   1.451 -lemma hypreal_minus_inverse: "inverse(-x) = -inverse(x::hypreal)"
   1.452 -apply (case_tac "x=0", simp add: HYPREAL_INVERSE_ZERO)
   1.453 -apply (rule hypreal_mult_right_cancel [of "-x", THEN iffD1], simp) 
   1.454 -apply (subst hypreal_mult_inverse_left, auto)
   1.455 +text{*TODO: The following theorem should be used througout the proofs
   1.456 +  as it probably makes many of them more straightforward.*}
   1.457 +lemma hypreal_less: 
   1.458 +      "(Abs_hypreal(hyprel``{%n. X n}) < Abs_hypreal(hyprel``{%n. Y n})) =  
   1.459 +       ({n. X n < Y n} \<in> FreeUltrafilterNat)"
   1.460 +apply (unfold hypreal_less_def)
   1.461 +apply (auto intro!: lemma_hyprel_refl, ultra)
   1.462  done
   1.463  
   1.464 -lemma hypreal_inverse_distrib: "inverse(x*y) = inverse(x)*inverse(y::hypreal)"
   1.465 -apply (case_tac "x=0", simp add: HYPREAL_INVERSE_ZERO)
   1.466 -apply (case_tac "y=0", simp add: HYPREAL_INVERSE_ZERO)
   1.467 -apply (frule_tac y = y in hypreal_mult_not_0, assumption)
   1.468 -apply (rule_tac c1 = x in hypreal_mult_left_cancel [THEN iffD1])
   1.469 -apply (auto simp add: hypreal_mult_assoc [symmetric])
   1.470 -apply (rule_tac c1 = y in hypreal_mult_left_cancel [THEN iffD1])
   1.471 -apply (auto simp add: hypreal_mult_left_commute)
   1.472 -apply (simp add: hypreal_mult_assoc [symmetric])
   1.473 -done
   1.474 -
   1.475 -(*------------------------------------------------------------------
   1.476 -                   Theorems for ordering 
   1.477 - ------------------------------------------------------------------*)
   1.478 -
   1.479  (* prove introduction and elimination rules for hypreal_less *)
   1.480  
   1.481 -lemma hypreal_less_iff: 
   1.482 - "(P < (Q::hypreal)) = (\<exists>X Y. X \<in> Rep_hypreal(P) &  
   1.483 -                              Y \<in> Rep_hypreal(Q) &  
   1.484 -                              {n. X n < Y n} \<in> FreeUltrafilterNat)"
   1.485 -
   1.486 -apply (unfold hypreal_less_def, fast)
   1.487 -done
   1.488 -
   1.489 -lemma hypreal_lessI: 
   1.490 - "[| {n. X n < Y n} \<in> FreeUltrafilterNat;  
   1.491 -          X \<in> Rep_hypreal(P);  
   1.492 -          Y \<in> Rep_hypreal(Q) |] ==> P < (Q::hypreal)"
   1.493 -apply (unfold hypreal_less_def, fast)
   1.494 -done
   1.495 -
   1.496 -
   1.497 -lemma hypreal_lessE: 
   1.498 -     "!! R1. [| R1 < (R2::hypreal);  
   1.499 -          !!X Y. {n. X n < Y n} \<in> FreeUltrafilterNat ==> P;  
   1.500 -          !!X. X \<in> Rep_hypreal(R1) ==> P;   
   1.501 -          !!Y. Y \<in> Rep_hypreal(R2) ==> P |]  
   1.502 -      ==> P"
   1.503 -
   1.504 -apply (unfold hypreal_less_def, auto)
   1.505 -done
   1.506 -
   1.507 -lemma hypreal_lessD: 
   1.508 - "R1 < (R2::hypreal) ==> (\<exists>X Y. {n. X n < Y n} \<in> FreeUltrafilterNat &  
   1.509 -                                   X \<in> Rep_hypreal(R1) &  
   1.510 -                                   Y \<in> Rep_hypreal(R2))"
   1.511 -apply (unfold hypreal_less_def, fast)
   1.512 -done
   1.513 -
   1.514  lemma hypreal_less_not_refl: "~ (R::hypreal) < R"
   1.515  apply (rule_tac z = R in eq_Abs_hypreal)
   1.516  apply (auto simp add: hypreal_less_def, ultra)
   1.517  done
   1.518  
   1.519 -(*** y < y ==> P ***)
   1.520  lemmas hypreal_less_irrefl = hypreal_less_not_refl [THEN notE, standard]
   1.521  declare hypreal_less_irrefl [elim!]
   1.522  
   1.523 @@ -720,25 +628,10 @@
   1.524  apply (simp add: hypreal_less_not_refl)
   1.525  done
   1.526  
   1.527 -(*-------------------------------------------------------
   1.528 -  TODO: The following theorem should have been proved 
   1.529 -  first and then used througout the proofs as it probably 
   1.530 -  makes many of them more straightforward. 
   1.531 - -------------------------------------------------------*)
   1.532 -lemma hypreal_less: 
   1.533 -      "(Abs_hypreal(hyprel``{%n. X n}) <  
   1.534 -            Abs_hypreal(hyprel``{%n. Y n})) =  
   1.535 -       ({n. X n < Y n} \<in> FreeUltrafilterNat)"
   1.536 -apply (unfold hypreal_less_def)
   1.537 -apply (auto intro!: lemma_hyprel_refl, ultra)
   1.538 -done
   1.539  
   1.540 -(*----------------------------------------------------------------------------
   1.541 -		 Trichotomy: the hyperreals are linearly ordered
   1.542 -  ---------------------------------------------------------------------------*)
   1.543 +subsection{*Trichotomy: the hyperreals are Linearly Ordered*}
   1.544  
   1.545  lemma lemma_hyprel_0_mem: "\<exists>x. x: hyprel `` {%n. 0}"
   1.546 -
   1.547  apply (unfold hyprel_def)
   1.548  apply (rule_tac x = "%n. 0" in exI, safe)
   1.549  apply (auto intro!: FreeUltrafilterNat_Nat_set)
   1.550 @@ -763,9 +656,7 @@
   1.551  apply (insert hypreal_trichotomy [of x], blast) 
   1.552  done
   1.553  
   1.554 -(*----------------------------------------------------------------------------
   1.555 -            More properties of <
   1.556 - ----------------------------------------------------------------------------*)
   1.557 +subsection{*More properties of Less Than*}
   1.558  
   1.559  lemma hypreal_less_minus_iff: "((x::hypreal) < y) = (0 < y + -x)"
   1.560  apply (rule_tac z = x in eq_Abs_hypreal)
   1.561 @@ -789,24 +680,8 @@
   1.562  apply (rule_tac x1 = "-x" in hypreal_add_right_cancel [THEN iffD1], auto)
   1.563  done
   1.564  
   1.565 -(* 07/00 *)
   1.566 -lemma hypreal_diff_zero [simp]: "(0::hypreal) - x = -x"
   1.567 -by (simp add: hypreal_diff_def)
   1.568  
   1.569 -lemma hypreal_diff_zero_right [simp]: "x - (0::hypreal) = x"
   1.570 -by (simp add: hypreal_diff_def)
   1.571 -
   1.572 -lemma hypreal_diff_self [simp]: "x - x = (0::hypreal)"
   1.573 -by (simp add: hypreal_diff_def)
   1.574 -
   1.575 -lemma hypreal_eq_minus_iff3: "(x = y + z) = (x + -z = (y::hypreal))"
   1.576 -by (auto simp add: hypreal_add_assoc)
   1.577 -
   1.578 -lemma hypreal_not_eq_minus_iff: "(x \<noteq> a) = (x + -a \<noteq> (0::hypreal))"
   1.579 -by (auto dest: hypreal_eq_minus_iff [THEN iffD2])
   1.580 -
   1.581 -
   1.582 -(*** linearity ***)
   1.583 +subsection{*Linearity*}
   1.584  
   1.585  lemma hypreal_linear: "(x::hypreal) < y | x = y | y < x"
   1.586  apply (subst hypreal_eq_minus_iff2)
   1.587 @@ -823,10 +698,8 @@
   1.588  apply (cut_tac x = x and y = y in hypreal_linear, auto)
   1.589  done
   1.590  
   1.591 -(*------------------------------------------------------------------------------
   1.592 -                            Properties of <=
   1.593 - ------------------------------------------------------------------------------*)
   1.594 -(*------ hypreal le iff reals le a.e ------*)
   1.595 +
   1.596 +subsection{*Properties of The @{text "\<le>"} Relation*}
   1.597  
   1.598  lemma hypreal_le: 
   1.599        "(Abs_hypreal(hyprel``{%n. X n}) <=  
   1.600 @@ -837,8 +710,6 @@
   1.601  apply (ultra+)
   1.602  done
   1.603  
   1.604 -(*---------------------------------------------------------*)
   1.605 -(*---------------------------------------------------------*)
   1.606  lemma hypreal_leI: 
   1.607       "~(w < z) ==> z <= (w::hypreal)"
   1.608  apply (unfold hypreal_le_def, assumption)
   1.609 @@ -894,17 +765,21 @@
   1.610  apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   1.611  done
   1.612  
   1.613 -lemma not_less_not_eq_hypreal_less: "[| ~ y < x; y \<noteq> x |] ==> x < (y::hypreal)"
   1.614 -apply (rule not_hypreal_leE)
   1.615 -apply (fast dest: hypreal_le_imp_less_or_eq)
   1.616 -done
   1.617 -
   1.618  (* Axiom 'order_less_le' of class 'order': *)
   1.619  lemma hypreal_less_le: "((w::hypreal) < z) = (w <= z & w \<noteq> z)"
   1.620  apply (simp add: hypreal_le_def hypreal_neq_iff)
   1.621  apply (blast intro: hypreal_less_asym)
   1.622  done
   1.623  
   1.624 +instance hypreal :: order
   1.625 +  by (intro_classes,
   1.626 +      (assumption | 
   1.627 +       rule hypreal_le_refl hypreal_le_trans hypreal_le_anti_sym
   1.628 +            hypreal_less_le)+)
   1.629 +
   1.630 +instance hypreal :: linorder 
   1.631 +  by (intro_classes, rule hypreal_le_linear)
   1.632 +
   1.633  lemma hypreal_minus_zero_less_iff [simp]: "(0 < -R) = (R < (0::hypreal))"
   1.634  apply (rule_tac z = R in eq_Abs_hypreal)
   1.635  apply (auto simp add: hypreal_zero_def hypreal_less hypreal_minus)
   1.636 @@ -925,9 +800,141 @@
   1.637  apply (simp add: hypreal_minus_zero_less_iff2)
   1.638  done
   1.639  
   1.640 -(*----------------------------------------------------------
   1.641 -  hypreal_of_real preserves field and order properties
   1.642 - -----------------------------------------------------------*)
   1.643 +
   1.644 +lemma hypreal_self_eq_minus_self_zero: "x = -x ==> x = (0::hypreal)"
   1.645 +apply (rule_tac z = x in eq_Abs_hypreal)
   1.646 +apply (auto simp add: hypreal_minus hypreal_zero_def, ultra)
   1.647 +done
   1.648 +
   1.649 +lemma hypreal_add_self_zero_cancel [simp]: "(x + x = 0) = (x = (0::hypreal))"
   1.650 +apply (rule_tac z = x in eq_Abs_hypreal)
   1.651 +apply (auto simp add: hypreal_add hypreal_zero_def)
   1.652 +done
   1.653 +
   1.654 +lemma hypreal_add_self_zero_cancel2 [simp]:
   1.655 +     "(x + x + y = y) = (x = (0::hypreal))"
   1.656 +apply auto
   1.657 +apply (drule hypreal_eq_minus_iff [THEN iffD1])
   1.658 +apply (auto simp add: hypreal_add_assoc hypreal_self_eq_minus_self_zero)
   1.659 +done
   1.660 +
   1.661 +lemma hypreal_minus_eq_swap: "(b = -a) = (-b = (a::hypreal))"
   1.662 +by auto
   1.663 +
   1.664 +lemma hypreal_minus_eq_cancel [simp]: "(-b = -a) = (b = (a::hypreal))"
   1.665 +by (simp add: hypreal_minus_eq_swap)
   1.666 +
   1.667 +lemma hypreal_add_less_mono1: "(A::hypreal) < B ==> A + C < B + C"
   1.668 +apply (rule_tac z = A in eq_Abs_hypreal)
   1.669 +apply (rule_tac z = B in eq_Abs_hypreal)
   1.670 +apply (rule_tac z = C in eq_Abs_hypreal)
   1.671 +apply (auto intro!: exI simp add: hypreal_less_def hypreal_add, ultra)
   1.672 +done
   1.673 +
   1.674 +lemma hypreal_mult_order: "[| 0 < x; 0 < y |] ==> (0::hypreal) < x * y"
   1.675 +apply (unfold hypreal_zero_def)
   1.676 +apply (rule_tac z = x in eq_Abs_hypreal)
   1.677 +apply (rule_tac z = y in eq_Abs_hypreal)
   1.678 +apply (auto intro!: exI simp add: hypreal_less_def hypreal_mult, ultra)
   1.679 +apply (auto intro: real_mult_order)
   1.680 +done
   1.681 +
   1.682 +lemma hypreal_add_left_le_mono1: "(q1::hypreal) \<le> q2  ==> x + q1 \<le> x + q2"
   1.683 +apply (drule order_le_imp_less_or_eq)
   1.684 +apply (auto intro: order_less_imp_le hypreal_add_less_mono1 simp add: hypreal_add_commute)
   1.685 +done
   1.686 +
   1.687 +lemma hypreal_mult_less_mono1: "[| (0::hypreal) < z; x < y |] ==> x*z < y*z"
   1.688 +apply (rotate_tac 1)
   1.689 +apply (drule hypreal_less_minus_iff [THEN iffD1])
   1.690 +apply (rule hypreal_less_minus_iff [THEN iffD2])
   1.691 +apply (drule hypreal_mult_order, assumption)
   1.692 +apply (simp add: hypreal_add_mult_distrib2 hypreal_mult_commute)
   1.693 +done
   1.694 +
   1.695 +lemma hypreal_mult_less_mono2: "[| (0::hypreal)<z; x<y |] ==> z*x<z*y"
   1.696 +apply (simp (no_asm_simp) add: hypreal_mult_commute hypreal_mult_less_mono1)
   1.697 +done
   1.698 +
   1.699 +subsection{*The Hyperreals Form an Ordered Field*}
   1.700 +
   1.701 +instance hypreal :: inverse ..
   1.702 +
   1.703 +instance hypreal :: ordered_field
   1.704 +proof
   1.705 +  fix x y z :: hypreal
   1.706 +  show "(x + y) + z = x + (y + z)" by (rule hypreal_add_assoc)
   1.707 +  show "x + y = y + x" by (rule hypreal_add_commute)
   1.708 +  show "0 + x = x" by simp
   1.709 +  show "- x + x = 0" by simp
   1.710 +  show "x - y = x + (-y)" by (simp add: hypreal_diff_def)
   1.711 +  show "(x * y) * z = x * (y * z)" by (rule hypreal_mult_assoc)
   1.712 +  show "x * y = y * x" by (rule hypreal_mult_commute)
   1.713 +  show "1 * x = x" by simp
   1.714 +  show "(x + y) * z = x * z + y * z" by (simp add: hypreal_add_mult_distrib)
   1.715 +  show "0 \<noteq> (1::hypreal)" by (rule hypreal_zero_not_eq_one)
   1.716 +  show "x \<le> y ==> z + x \<le> z + y" by (rule hypreal_add_left_le_mono1)
   1.717 +  show "x < y ==> 0 < z ==> z * x < z * y" by (simp add: hypreal_mult_less_mono2)
   1.718 +  show "\<bar>x\<bar> = (if x < 0 then -x else x)"
   1.719 +    by (auto dest: order_le_less_trans simp add: hrabs_def linorder_not_le)
   1.720 +  show "x \<noteq> 0 ==> inverse x * x = 1" by simp
   1.721 +  show "y \<noteq> 0 ==> x / y = x * inverse y" by (simp add: hypreal_divide_def)
   1.722 +qed
   1.723 +
   1.724 +lemma hypreal_minus_add_distrib [simp]: "-(x + (y::hypreal)) = -x + -y"
   1.725 +  by (rule Ring_and_Field.minus_add_distrib)
   1.726 +
   1.727 +(*Used ONCE: in NSA.ML*)
   1.728 +lemma hypreal_minus_distrib1: "-(y + -(x::hypreal)) = x + -y"
   1.729 +by (simp add: hypreal_add_commute)
   1.730 +
   1.731 +(*Used ONCE: in Lim.ML*)
   1.732 +lemma hypreal_eq_minus_iff3: "(x = y + z) = (x + -z = (y::hypreal))"
   1.733 +by (auto simp add: hypreal_add_assoc)
   1.734 +
   1.735 +lemma hypreal_not_eq_minus_iff: "(x \<noteq> a) = (x + -a \<noteq> (0::hypreal))"
   1.736 +by (auto dest: hypreal_eq_minus_iff [THEN iffD2])
   1.737 +
   1.738 +lemma hypreal_mult_left_cancel: "(c::hypreal) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
   1.739 +apply auto
   1.740 +done
   1.741 +    
   1.742 +lemma hypreal_mult_right_cancel: "(c::hypreal) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
   1.743 +apply auto
   1.744 +done
   1.745 +
   1.746 +lemma hypreal_inverse_not_zero: "x \<noteq> 0 ==> inverse (x::hypreal) \<noteq> 0"
   1.747 +  by (rule Ring_and_Field.nonzero_imp_inverse_nonzero)
   1.748 +
   1.749 +lemma hypreal_mult_not_0: "[| x \<noteq> 0; y \<noteq> 0 |] ==> x * y \<noteq> (0::hypreal)"
   1.750 +by simp
   1.751 +
   1.752 +lemma hypreal_minus_inverse: "inverse(-x) = -inverse(x::hypreal)"
   1.753 +  by (rule Ring_and_Field.inverse_minus_eq)
   1.754 +
   1.755 +lemma hypreal_inverse_distrib: "inverse(x*y) = inverse(x)*inverse(y::hypreal)"
   1.756 +  by (rule Ring_and_Field.inverse_mult_distrib)
   1.757 +
   1.758 +
   1.759 +subsection{* Division lemmas *}
   1.760 +
   1.761 +lemma hypreal_divide_one: "x/(1::hypreal) = x"
   1.762 +by (simp add: hypreal_divide_def)
   1.763 +
   1.764 +
   1.765 +(** As with multiplication, pull minus signs OUT of the / operator **)
   1.766 +
   1.767 +lemma hypreal_add_divide_distrib: "(x+y)/(z::hypreal) = x/z + y/z"
   1.768 +  by (rule Ring_and_Field.add_divide_distrib)
   1.769 +
   1.770 +lemma hypreal_inverse_add:
   1.771 +     "[|(x::hypreal) \<noteq> 0;  y \<noteq> 0 |]   
   1.772 +      ==> inverse(x) + inverse(y) = (x + y)*inverse(x*y)"
   1.773 +by (simp add: Ring_and_Field.inverse_add mult_assoc)
   1.774 +
   1.775 +
   1.776 +subsection{*@{term hypreal_of_real} Preserves Field and Order Properties*}
   1.777 +
   1.778  lemma hypreal_of_real_add [simp]: 
   1.779       "hypreal_of_real (z1 + z2) = hypreal_of_real z1 + hypreal_of_real z2"
   1.780  apply (unfold hypreal_of_real_def)
   1.781 @@ -953,10 +960,12 @@
   1.782  apply (unfold hypreal_le_def real_le_def, auto)
   1.783  done
   1.784  
   1.785 -lemma hypreal_of_real_eq_iff [simp]: "(hypreal_of_real z1 = hypreal_of_real z2) = (z1 = z2)"
   1.786 +lemma hypreal_of_real_eq_iff [simp]:
   1.787 +     "(hypreal_of_real z1 = hypreal_of_real z2) = (z1 = z2)"
   1.788  by (force intro: order_antisym hypreal_of_real_le_iff [THEN iffD1])
   1.789  
   1.790 -lemma hypreal_of_real_minus [simp]: "hypreal_of_real (-r) = - hypreal_of_real  r"
   1.791 +lemma hypreal_of_real_minus [simp]:
   1.792 +     "hypreal_of_real (-r) = - hypreal_of_real  r"
   1.793  apply (unfold hypreal_of_real_def)
   1.794  apply (auto simp add: hypreal_minus)
   1.795  done
   1.796 @@ -970,146 +979,20 @@
   1.797  lemma hypreal_of_real_zero_iff: "(hypreal_of_real r = 0) = (r = 0)"
   1.798  by (auto intro: FreeUltrafilterNat_P simp add: hypreal_of_real_def hypreal_zero_def FreeUltrafilterNat_Nat_set)
   1.799  
   1.800 -lemma hypreal_of_real_inverse [simp]: "hypreal_of_real (inverse r) = inverse (hypreal_of_real r)"
   1.801 +lemma hypreal_of_real_inverse [simp]:
   1.802 +     "hypreal_of_real (inverse r) = inverse (hypreal_of_real r)"
   1.803  apply (case_tac "r=0")
   1.804  apply (simp add: DIVISION_BY_ZERO INVERSE_ZERO HYPREAL_INVERSE_ZERO)
   1.805  apply (rule_tac c1 = "hypreal_of_real r" in hypreal_mult_left_cancel [THEN iffD1])
   1.806  apply (auto simp add: hypreal_of_real_zero_iff hypreal_of_real_mult [symmetric])
   1.807  done
   1.808  
   1.809 -lemma hypreal_of_real_divide [simp]: "hypreal_of_real (z1 / z2) = hypreal_of_real z1 / hypreal_of_real z2"
   1.810 +lemma hypreal_of_real_divide [simp]:
   1.811 +     "hypreal_of_real (z1 / z2) = hypreal_of_real z1 / hypreal_of_real z2"
   1.812  by (simp add: hypreal_divide_def real_divide_def)
   1.813  
   1.814  
   1.815 -(*** Division lemmas ***)
   1.816 -
   1.817 -lemma hypreal_zero_divide: "(0::hypreal)/x = 0"
   1.818 -by (simp add: hypreal_divide_def)
   1.819 -
   1.820 -lemma hypreal_divide_one: "x/(1::hypreal) = x"
   1.821 -by (simp add: hypreal_divide_def)
   1.822 -declare hypreal_zero_divide [simp] hypreal_divide_one [simp]
   1.823 -
   1.824 -lemma hypreal_divide_divide1_eq [simp]: "(x::hypreal) / (y/z) = (x*z)/y"
   1.825 -by (simp add: hypreal_divide_def hypreal_inverse_distrib hypreal_mult_ac)
   1.826 -
   1.827 -lemma hypreal_divide_divide2_eq [simp]: "((x::hypreal) / y) / z = x/(y*z)"
   1.828 -by (simp add: hypreal_divide_def hypreal_inverse_distrib hypreal_mult_assoc)
   1.829 -
   1.830 -
   1.831 -(** As with multiplication, pull minus signs OUT of the / operator **)
   1.832 -
   1.833 -lemma hypreal_minus_divide_eq [simp]: "(-x) / (y::hypreal) = - (x/y)"
   1.834 -by (simp add: hypreal_divide_def)
   1.835 -
   1.836 -lemma hypreal_divide_minus_eq [simp]: "(x / -(y::hypreal)) = - (x/y)"
   1.837 -by (simp add: hypreal_divide_def hypreal_minus_inverse)
   1.838 -
   1.839 -lemma hypreal_add_divide_distrib: "(x+y)/(z::hypreal) = x/z + y/z"
   1.840 -by (simp add: hypreal_divide_def hypreal_add_mult_distrib)
   1.841 -
   1.842 -lemma hypreal_inverse_add: "[|(x::hypreal) \<noteq> 0;  y \<noteq> 0 |]   
   1.843 -      ==> inverse(x) + inverse(y) = (x + y)*inverse(x*y)"
   1.844 -apply (simp add: hypreal_inverse_distrib hypreal_add_mult_distrib hypreal_mult_assoc [symmetric])
   1.845 -apply (subst hypreal_mult_assoc)
   1.846 -apply (rule hypreal_mult_left_commute [THEN subst])
   1.847 -apply (simp add: hypreal_add_commute)
   1.848 -done
   1.849 -
   1.850 -lemma hypreal_self_eq_minus_self_zero: "x = -x ==> x = (0::hypreal)"
   1.851 -apply (rule_tac z = x in eq_Abs_hypreal)
   1.852 -apply (auto simp add: hypreal_minus hypreal_zero_def, ultra)
   1.853 -done
   1.854 -
   1.855 -lemma hypreal_add_self_zero_cancel [simp]: "(x + x = 0) = (x = (0::hypreal))"
   1.856 -apply (rule_tac z = x in eq_Abs_hypreal)
   1.857 -apply (auto simp add: hypreal_add hypreal_zero_def)
   1.858 -done
   1.859 -
   1.860 -lemma hypreal_add_self_zero_cancel2 [simp]: "(x + x + y = y) = (x = (0::hypreal))"
   1.861 -apply auto
   1.862 -apply (drule hypreal_eq_minus_iff [THEN iffD1])
   1.863 -apply (auto simp add: hypreal_add_assoc hypreal_self_eq_minus_self_zero)
   1.864 -done
   1.865 -
   1.866 -lemma hypreal_add_self_zero_cancel2a [simp]: "(x + (x + y) = y) = (x = (0::hypreal))"
   1.867 -by (simp add: hypreal_add_assoc [symmetric])
   1.868 -
   1.869 -lemma hypreal_minus_eq_swap: "(b = -a) = (-b = (a::hypreal))"
   1.870 -by auto
   1.871 -
   1.872 -lemma hypreal_minus_eq_cancel [simp]: "(-b = -a) = (b = (a::hypreal))"
   1.873 -by (simp add: hypreal_minus_eq_swap)
   1.874 -
   1.875 -lemma hypreal_less_eq_diff: "(x<y) = (x-y < (0::hypreal))"
   1.876 -apply (unfold hypreal_diff_def)
   1.877 -apply (rule hypreal_less_minus_iff2)
   1.878 -done
   1.879 -
   1.880 -(*** Subtraction laws ***)
   1.881 -
   1.882 -lemma hypreal_add_diff_eq: "x + (y - z) = (x + y) - (z::hypreal)"
   1.883 -by (simp add: hypreal_diff_def hypreal_add_ac)
   1.884 -
   1.885 -lemma hypreal_diff_add_eq: "(x - y) + z = (x + z) - (y::hypreal)"
   1.886 -by (simp add: hypreal_diff_def hypreal_add_ac)
   1.887 -
   1.888 -lemma hypreal_diff_diff_eq: "(x - y) - z = x - (y + (z::hypreal))"
   1.889 -by (simp add: hypreal_diff_def hypreal_add_ac)
   1.890 -
   1.891 -lemma hypreal_diff_diff_eq2: "x - (y - z) = (x + z) - (y::hypreal)"
   1.892 -by (simp add: hypreal_diff_def hypreal_add_ac)
   1.893 -
   1.894 -lemma hypreal_diff_less_eq: "(x-y < z) = (x < z + (y::hypreal))"
   1.895 -apply (subst hypreal_less_eq_diff)
   1.896 -apply (rule_tac y1 = z in hypreal_less_eq_diff [THEN ssubst])
   1.897 -apply (simp add: hypreal_diff_def hypreal_add_ac)
   1.898 -done
   1.899 -
   1.900 -lemma hypreal_less_diff_eq: "(x < z-y) = (x + (y::hypreal) < z)"
   1.901 -apply (subst hypreal_less_eq_diff)
   1.902 -apply (rule_tac y1 = "z-y" in hypreal_less_eq_diff [THEN ssubst])
   1.903 -apply (simp add: hypreal_diff_def hypreal_add_ac)
   1.904 -done
   1.905 -
   1.906 -lemma hypreal_diff_le_eq: "(x-y <= z) = (x <= z + (y::hypreal))"
   1.907 -apply (unfold hypreal_le_def)
   1.908 -apply (simp add: hypreal_less_diff_eq)
   1.909 -done
   1.910 -
   1.911 -lemma hypreal_le_diff_eq: "(x <= z-y) = (x + (y::hypreal) <= z)"
   1.912 -apply (unfold hypreal_le_def)
   1.913 -apply (simp add: hypreal_diff_less_eq)
   1.914 -done
   1.915 -
   1.916 -lemma hypreal_diff_eq_eq: "(x-y = z) = (x = z + (y::hypreal))"
   1.917 -apply (unfold hypreal_diff_def)
   1.918 -apply (auto simp add: hypreal_add_assoc)
   1.919 -done
   1.920 -
   1.921 -lemma hypreal_eq_diff_eq: "(x = z-y) = (x + (y::hypreal) = z)"
   1.922 -apply (unfold hypreal_diff_def)
   1.923 -apply (auto simp add: hypreal_add_assoc)
   1.924 -done
   1.925 -
   1.926 -
   1.927 -(** For the cancellation simproc.
   1.928 -    The idea is to cancel like terms on opposite sides by subtraction **)
   1.929 -
   1.930 -lemma hypreal_less_eqI: "(x::hypreal) - y = x' - y' ==> (x<y) = (x'<y')"
   1.931 -apply (subst hypreal_less_eq_diff)
   1.932 -apply (rule_tac y1 = y in hypreal_less_eq_diff [THEN ssubst], simp)
   1.933 -done
   1.934 -
   1.935 -lemma hypreal_le_eqI: "(x::hypreal) - y = x' - y' ==> (y<=x) = (y'<=x')"
   1.936 -apply (drule hypreal_less_eqI)
   1.937 -apply (simp add: hypreal_le_def)
   1.938 -done
   1.939 -
   1.940 -lemma hypreal_eq_eqI: "(x::hypreal) - y = x' - y' ==> (x=y) = (x'=y')"
   1.941 -apply safe
   1.942 -apply (simp_all add: hypreal_eq_diff_eq hypreal_diff_eq_eq)
   1.943 -done
   1.944 +subsection{*Misc Others*}
   1.945  
   1.946  lemma hypreal_zero_num: "0 = Abs_hypreal (hyprel `` {%n. 0})"
   1.947  by (simp add: hypreal_zero_def [THEN meta_eq_to_obj_eq, symmetric])
   1.948 @@ -1122,8 +1005,19 @@
   1.949  apply (auto simp add: hypreal_less hypreal_zero_num)
   1.950  done
   1.951  
   1.952 +
   1.953 +lemma hypreal_hrabs:
   1.954 +     "abs (Abs_hypreal (hyprel `` {X})) = 
   1.955 +      Abs_hypreal(hyprel `` {%n. abs (X n)})"
   1.956 +apply (auto simp add: hrabs_def hypreal_zero_def hypreal_le hypreal_minus)
   1.957 +apply (ultra, arith)+
   1.958 +done
   1.959 +
   1.960  ML
   1.961  {*
   1.962 +val hrabs_def = thm "hrabs_def";
   1.963 +val hypreal_hrabs = thm "hypreal_hrabs";
   1.964 +
   1.965  val hypreal_zero_def = thm "hypreal_zero_def";
   1.966  val hypreal_one_def = thm "hypreal_one_def";
   1.967  val hypreal_minus_def = thm "hypreal_minus_def";
   1.968 @@ -1189,11 +1083,6 @@
   1.969  val hypreal_add_zero_right = thm "hypreal_add_zero_right";
   1.970  val hypreal_add_minus = thm "hypreal_add_minus";
   1.971  val hypreal_add_minus_left = thm "hypreal_add_minus_left";
   1.972 -val hypreal_minus_ex = thm "hypreal_minus_ex";
   1.973 -val hypreal_minus_ex1 = thm "hypreal_minus_ex1";
   1.974 -val hypreal_minus_left_ex1 = thm "hypreal_minus_left_ex1";
   1.975 -val hypreal_add_minus_eq_minus = thm "hypreal_add_minus_eq_minus";
   1.976 -val hypreal_as_add_inverse_ex = thm "hypreal_as_add_inverse_ex";
   1.977  val hypreal_minus_add_distrib = thm "hypreal_minus_add_distrib";
   1.978  val hypreal_minus_distrib1 = thm "hypreal_minus_distrib1";
   1.979  val hypreal_add_left_cancel = thm "hypreal_add_left_cancel";
   1.980 @@ -1214,7 +1103,6 @@
   1.981  val hypreal_mult_minus_1 = thm "hypreal_mult_minus_1";
   1.982  val hypreal_mult_minus_1_right = thm "hypreal_mult_minus_1_right";
   1.983  val hypreal_minus_mult_commute = thm "hypreal_minus_mult_commute";
   1.984 -val hypreal_add_assoc_cong = thm "hypreal_add_assoc_cong";
   1.985  val hypreal_add_mult_distrib = thm "hypreal_add_mult_distrib";
   1.986  val hypreal_add_mult_distrib2 = thm "hypreal_add_mult_distrib2";
   1.987  val hypreal_diff_mult_distrib = thm "hypreal_diff_mult_distrib";
   1.988 @@ -1224,35 +1112,24 @@
   1.989  val hypreal_inverse = thm "hypreal_inverse";
   1.990  val HYPREAL_INVERSE_ZERO = thm "HYPREAL_INVERSE_ZERO";
   1.991  val HYPREAL_DIVISION_BY_ZERO = thm "HYPREAL_DIVISION_BY_ZERO";
   1.992 -val hypreal_inverse_inverse = thm "hypreal_inverse_inverse";
   1.993 -val hypreal_inverse_1 = thm "hypreal_inverse_1";
   1.994  val hypreal_mult_inverse = thm "hypreal_mult_inverse";
   1.995  val hypreal_mult_inverse_left = thm "hypreal_mult_inverse_left";
   1.996  val hypreal_mult_left_cancel = thm "hypreal_mult_left_cancel";
   1.997  val hypreal_mult_right_cancel = thm "hypreal_mult_right_cancel";
   1.998  val hypreal_inverse_not_zero = thm "hypreal_inverse_not_zero";
   1.999  val hypreal_mult_not_0 = thm "hypreal_mult_not_0";
  1.1000 -val hypreal_mult_zero_disj = thm "hypreal_mult_zero_disj";
  1.1001  val hypreal_minus_inverse = thm "hypreal_minus_inverse";
  1.1002  val hypreal_inverse_distrib = thm "hypreal_inverse_distrib";
  1.1003 -val hypreal_less_iff = thm "hypreal_less_iff";
  1.1004 -val hypreal_lessI = thm "hypreal_lessI";
  1.1005 -val hypreal_lessE = thm "hypreal_lessE";
  1.1006 -val hypreal_lessD = thm "hypreal_lessD";
  1.1007  val hypreal_less_not_refl = thm "hypreal_less_not_refl";
  1.1008  val hypreal_not_refl2 = thm "hypreal_not_refl2";
  1.1009  val hypreal_less_trans = thm "hypreal_less_trans";
  1.1010  val hypreal_less_asym = thm "hypreal_less_asym";
  1.1011  val hypreal_less = thm "hypreal_less";
  1.1012  val hypreal_trichotomy = thm "hypreal_trichotomy";
  1.1013 -val hypreal_trichotomyE = thm "hypreal_trichotomyE";
  1.1014  val hypreal_less_minus_iff = thm "hypreal_less_minus_iff";
  1.1015  val hypreal_less_minus_iff2 = thm "hypreal_less_minus_iff2";
  1.1016  val hypreal_eq_minus_iff = thm "hypreal_eq_minus_iff";
  1.1017  val hypreal_eq_minus_iff2 = thm "hypreal_eq_minus_iff2";
  1.1018 -val hypreal_diff_zero = thm "hypreal_diff_zero";
  1.1019 -val hypreal_diff_zero_right = thm "hypreal_diff_zero_right";
  1.1020 -val hypreal_diff_self = thm "hypreal_diff_self";
  1.1021  val hypreal_eq_minus_iff3 = thm "hypreal_eq_minus_iff3";
  1.1022  val hypreal_not_eq_minus_iff = thm "hypreal_not_eq_minus_iff";
  1.1023  val hypreal_linear = thm "hypreal_linear";
  1.1024 @@ -1270,7 +1147,6 @@
  1.1025  val hypreal_le_linear = thm "hypreal_le_linear";
  1.1026  val hypreal_le_trans = thm "hypreal_le_trans";
  1.1027  val hypreal_le_anti_sym = thm "hypreal_le_anti_sym";
  1.1028 -val not_less_not_eq_hypreal_less = thm "not_less_not_eq_hypreal_less";
  1.1029  val hypreal_less_le = thm "hypreal_less_le";
  1.1030  val hypreal_minus_zero_less_iff = thm "hypreal_minus_zero_less_iff";
  1.1031  val hypreal_minus_zero_less_iff2 = thm "hypreal_minus_zero_less_iff2";
  1.1032 @@ -1287,34 +1163,14 @@
  1.1033  val hypreal_of_real_zero_iff = thm "hypreal_of_real_zero_iff";
  1.1034  val hypreal_of_real_inverse = thm "hypreal_of_real_inverse";
  1.1035  val hypreal_of_real_divide = thm "hypreal_of_real_divide";
  1.1036 -val hypreal_zero_divide = thm "hypreal_zero_divide";
  1.1037  val hypreal_divide_one = thm "hypreal_divide_one";
  1.1038 -val hypreal_divide_divide1_eq = thm "hypreal_divide_divide1_eq";
  1.1039 -val hypreal_divide_divide2_eq = thm "hypreal_divide_divide2_eq";
  1.1040 -val hypreal_minus_divide_eq = thm "hypreal_minus_divide_eq";
  1.1041 -val hypreal_divide_minus_eq = thm "hypreal_divide_minus_eq";
  1.1042  val hypreal_add_divide_distrib = thm "hypreal_add_divide_distrib";
  1.1043  val hypreal_inverse_add = thm "hypreal_inverse_add";
  1.1044  val hypreal_self_eq_minus_self_zero = thm "hypreal_self_eq_minus_self_zero";
  1.1045  val hypreal_add_self_zero_cancel = thm "hypreal_add_self_zero_cancel";
  1.1046  val hypreal_add_self_zero_cancel2 = thm "hypreal_add_self_zero_cancel2";
  1.1047 -val hypreal_add_self_zero_cancel2a = thm "hypreal_add_self_zero_cancel2a";
  1.1048  val hypreal_minus_eq_swap = thm "hypreal_minus_eq_swap";
  1.1049  val hypreal_minus_eq_cancel = thm "hypreal_minus_eq_cancel";
  1.1050 -val hypreal_less_eq_diff = thm "hypreal_less_eq_diff";
  1.1051 -val hypreal_add_diff_eq = thm "hypreal_add_diff_eq";
  1.1052 -val hypreal_diff_add_eq = thm "hypreal_diff_add_eq";
  1.1053 -val hypreal_diff_diff_eq = thm "hypreal_diff_diff_eq";
  1.1054 -val hypreal_diff_diff_eq2 = thm "hypreal_diff_diff_eq2";
  1.1055 -val hypreal_diff_less_eq = thm "hypreal_diff_less_eq";
  1.1056 -val hypreal_less_diff_eq = thm "hypreal_less_diff_eq";
  1.1057 -val hypreal_diff_le_eq = thm "hypreal_diff_le_eq";
  1.1058 -val hypreal_le_diff_eq = thm "hypreal_le_diff_eq";
  1.1059 -val hypreal_diff_eq_eq = thm "hypreal_diff_eq_eq";
  1.1060 -val hypreal_eq_diff_eq = thm "hypreal_eq_diff_eq";
  1.1061 -val hypreal_less_eqI = thm "hypreal_less_eqI";
  1.1062 -val hypreal_le_eqI = thm "hypreal_le_eqI";
  1.1063 -val hypreal_eq_eqI = thm "hypreal_eq_eqI";
  1.1064  val hypreal_zero_num = thm "hypreal_zero_num";
  1.1065  val hypreal_one_num = thm "hypreal_one_num";
  1.1066  val hypreal_omega_gt_zero = thm "hypreal_omega_gt_zero";