simplifications in the hyperreals
authorpaulson
Thu Jan 29 16:51:17 2004 +0100 (2004-01-29)
changeset 14370b0064703967b
parent 14369 c50188fe6366
child 14371 c78c7da09519
simplifications in the hyperreals
src/HOL/Complex/CStar.ML
src/HOL/Complex/NSComplex.thy
src/HOL/Hyperreal/HLog.ML
src/HOL/Hyperreal/HRealAbs.thy
src/HOL/Hyperreal/HTranscendental.ML
src/HOL/Hyperreal/HyperArith.thy
src/HOL/Hyperreal/HyperDef.thy
src/HOL/Hyperreal/HyperNat.ML
src/HOL/Hyperreal/HyperOrd.thy
src/HOL/Hyperreal/NSA.ML
src/HOL/Hyperreal/NSA.thy
src/HOL/Hyperreal/Star.ML
src/HOL/Hyperreal/Star.thy
src/HOL/Hyperreal/Transcendental.ML
src/HOL/Hyperreal/hypreal_arith.ML
src/HOL/IsaMakefile
src/HOL/Ring_and_Field.thy
     1.1 --- a/src/HOL/Complex/CStar.ML	Wed Jan 28 17:01:01 2004 +0100
     1.2 +++ b/src/HOL/Complex/CStar.ML	Thu Jan 29 16:51:17 2004 +0100
     1.3 @@ -95,7 +95,7 @@
     1.4  
     1.5  Goal "*sc* (A - B) = *sc* A - *sc* B";
     1.6  by (auto_tac (claset(),simpset() addsimps 
     1.7 -         [set_diff_iff2,STARC_Int,STARC_Compl]));
     1.8 +         [Diff_eq,STARC_Int,STARC_Compl]));
     1.9  qed "STARC_diff";
    1.10  
    1.11  Goalw [starsetC_n_def] 
     2.1 --- a/src/HOL/Complex/NSComplex.thy	Wed Jan 28 17:01:01 2004 +0100
     2.2 +++ b/src/HOL/Complex/NSComplex.thy	Thu Jan 29 16:51:17 2004 +0100
     2.3 @@ -6,17 +6,15 @@
     2.4  
     2.5  theory NSComplex = NSInduct:
     2.6  
     2.7 -(* Move to one of the hyperreal theories *)
     2.8 +(* ???MOVE to one of the hyperreal theories: HRealAbs??? *)
     2.9  lemma hypreal_of_nat: "hypreal_of_nat m = Abs_hypreal(hyprel `` {%n. real m})"
    2.10  apply (induct_tac "m")
    2.11  apply (auto simp add: hypreal_zero_def hypreal_of_nat_Suc hypreal_zero_num hypreal_one_num hypreal_add real_of_nat_Suc)
    2.12  done
    2.13  
    2.14 -(* not proved already? strange! *)
    2.15  lemma hypreal_of_nat_le_iff:
    2.16        "(hypreal_of_nat n \<le> hypreal_of_nat m) = (n \<le> m)"
    2.17 -apply (unfold hypreal_le_def)
    2.18 -apply auto
    2.19 +apply (auto simp add: linorder_not_less [symmetric])
    2.20  done
    2.21  declare hypreal_of_nat_le_iff [simp]
    2.22  
    2.23 @@ -1365,7 +1363,7 @@
    2.24  
    2.25  lemma cos_harg_i_mult_zero [simp]:
    2.26       "y \<noteq> 0 ==> ( *f* cos) (harg(iii * hcomplex_of_hypreal y)) = 0"
    2.27 -apply (cut_tac x = "y" and y = "0" in hypreal_linear)
    2.28 +apply (cut_tac x = "y" and y = "0" in linorder_less_linear)
    2.29  apply (auto simp add: cos_harg_i_mult_zero_pos cos_harg_i_mult_zero_neg)
    2.30  done
    2.31  
     3.1 --- a/src/HOL/Hyperreal/HLog.ML	Wed Jan 28 17:01:01 2004 +0100
     3.2 +++ b/src/HOL/Hyperreal/HLog.ML	Thu Jan 29 16:51:17 2004 +0100
     3.3 @@ -114,7 +114,7 @@
     3.4  Addsimps [powhr_less_cancel_iff];
     3.5  
     3.6  Goal "1 < x ==> (x powhr a <= x powhr b) = (a <= b)";
     3.7 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_def]));
     3.8 +by (auto_tac (claset(),simpset() addsimps [linorder_not_less RS sym]));
     3.9  qed "powhr_le_cancel_iff";
    3.10  Addsimps [powhr_le_cancel_iff];
    3.11  
    3.12 @@ -246,7 +246,7 @@
    3.13  Addsimps [hlog_less_cancel_iff];
    3.14  
    3.15  Goal "[| 1 < a; 0 < x; 0 < y |] ==> (hlog a x <= hlog a y) = (x <= y)";
    3.16 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_def]));
    3.17 +by (auto_tac (claset(),simpset() addsimps [linorder_not_less RS sym]));
    3.18  qed "hlog_le_cancel_iff";
    3.19  Addsimps [hlog_le_cancel_iff];
    3.20  
     4.1 --- a/src/HOL/Hyperreal/HRealAbs.thy	Wed Jan 28 17:01:01 2004 +0100
     4.2 +++ b/src/HOL/Hyperreal/HRealAbs.thy	Thu Jan 29 16:51:17 2004 +0100
     4.3 @@ -31,7 +31,7 @@
     4.4  by (simp add: order_less_imp_le hrabs_eqI1)
     4.5  
     4.6  lemma hrabs_minus_eqI2: "x<(0::hypreal) ==> abs x = -x"
     4.7 -by (simp add: hypreal_le_def hrabs_def)
     4.8 +by (simp add: linorder_not_less [symmetric] hrabs_def)
     4.9  
    4.10  lemma hrabs_minus_eqI1: "x<=(0::hypreal) ==> abs x = -x"
    4.11  by (auto dest: order_antisym simp add: hrabs_def)
     5.1 --- a/src/HOL/Hyperreal/HTranscendental.ML	Wed Jan 28 17:01:01 2004 +0100
     5.2 +++ b/src/HOL/Hyperreal/HTranscendental.ML	Thu Jan 29 16:51:17 2004 +0100
     5.3 @@ -63,7 +63,7 @@
     5.4  Goal "[|0<=x; 0<=y |] ==> \
     5.5  \    ( *f* sqrt)(x*y) =  ( *f* sqrt)(x) * ( *f* sqrt)(y)";
     5.6  by (auto_tac (claset() addIs [hypreal_sqrt_mult_distrib],
     5.7 -    simpset() addsimps [hypreal_le_eq_less_or_eq]));
     5.8 +    simpset() addsimps [order_le_less]));
     5.9  qed "hypreal_sqrt_mult_distrib2";
    5.10  
    5.11  Goal "0 < x ==> (( *f* sqrt)(x) @= 0) = (x @= 0)";
    5.12 @@ -102,7 +102,7 @@
    5.13  
    5.14  Goal "0 <= x ==> 0 <= ( *f* sqrt)(x)";
    5.15  by (auto_tac (claset() addIs [hypreal_sqrt_gt_zero],
    5.16 -    simpset() addsimps [hypreal_le_eq_less_or_eq ]));
    5.17 +    simpset() addsimps [order_le_less ]));
    5.18  qed "hypreal_sqrt_ge_zero";
    5.19  
    5.20  Goal "( *f* sqrt)(x ^ 2) = abs(x)";
    5.21 @@ -148,14 +148,14 @@
    5.22  Addsimps [hypreal_sqrt_sum_squares_ge1];
    5.23  
    5.24  Goal "[| 0 <= x; x : HFinite |] ==> ( *f* sqrt) x : HFinite";
    5.25 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_eq_less_or_eq]));
    5.26 +by (auto_tac (claset(),simpset() addsimps [order_le_less]));
    5.27  by (rtac (HFinite_square_iff RS iffD1) 1);
    5.28  by (dtac hypreal_sqrt_gt_zero_pow2 1);
    5.29  by (auto_tac (claset(),simpset() addsimps [numeral_2_eq_2]));
    5.30  qed "HFinite_hypreal_sqrt";
    5.31  
    5.32  Goal "[| 0 <= x; ( *f* sqrt) x : HFinite |] ==> x : HFinite";
    5.33 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_eq_less_or_eq]));
    5.34 +by (auto_tac (claset(),simpset() addsimps [order_le_less]));
    5.35  by (dtac (HFinite_square_iff RS iffD2) 1);
    5.36  by (dtac hypreal_sqrt_gt_zero_pow2 1);
    5.37  by (auto_tac (claset(),simpset() addsimps [numeral_2_eq_2] delsimps [HFinite_square_iff]));
    5.38 @@ -175,14 +175,14 @@
    5.39  Addsimps [HFinite_sqrt_sum_squares];
    5.40  
    5.41  Goal "[| 0 <= x; x : Infinitesimal |] ==> ( *f* sqrt) x : Infinitesimal";
    5.42 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_eq_less_or_eq]));
    5.43 +by (auto_tac (claset(),simpset() addsimps [order_le_less]));
    5.44  by (rtac (Infinitesimal_square_iff RS iffD2) 1);
    5.45  by (dtac hypreal_sqrt_gt_zero_pow2 1);
    5.46  by (auto_tac (claset(),simpset() addsimps [numeral_2_eq_2]));
    5.47  qed "Infinitesimal_hypreal_sqrt";
    5.48  
    5.49  Goal "[| 0 <= x; ( *f* sqrt) x : Infinitesimal |] ==> x : Infinitesimal";
    5.50 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_eq_less_or_eq]));
    5.51 +by (auto_tac (claset(),simpset() addsimps [order_le_less]));
    5.52  by (dtac (Infinitesimal_square_iff RS iffD1) 1);
    5.53  by (dtac hypreal_sqrt_gt_zero_pow2 1);
    5.54  by (auto_tac (claset(),simpset() addsimps [numeral_2_eq_2] 
    5.55 @@ -203,14 +203,14 @@
    5.56  Addsimps [Infinitesimal_sqrt_sum_squares];
    5.57  
    5.58  Goal "[| 0 <= x; x : HInfinite |] ==> ( *f* sqrt) x : HInfinite";
    5.59 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_eq_less_or_eq]));
    5.60 +by (auto_tac (claset(),simpset() addsimps [order_le_less]));
    5.61  by (rtac (HInfinite_square_iff RS iffD1) 1);
    5.62  by (dtac hypreal_sqrt_gt_zero_pow2 1);
    5.63  by (auto_tac (claset(),simpset() addsimps [numeral_2_eq_2]));
    5.64  qed "HInfinite_hypreal_sqrt";
    5.65  
    5.66  Goal "[| 0 <= x; ( *f* sqrt) x : HInfinite |] ==> x : HInfinite";
    5.67 -by (auto_tac (claset(),simpset() addsimps [hypreal_le_eq_less_or_eq]));
    5.68 +by (auto_tac (claset(),simpset() addsimps [order_le_less]));
    5.69  by (dtac (HInfinite_square_iff RS iffD2) 1);
    5.70  by (dtac hypreal_sqrt_gt_zero_pow2 1);
    5.71  by (auto_tac (claset(),simpset() addsimps [numeral_2_eq_2] 
     6.1 --- a/src/HOL/Hyperreal/HyperArith.thy	Wed Jan 28 17:01:01 2004 +0100
     6.2 +++ b/src/HOL/Hyperreal/HyperArith.thy	Thu Jan 29 16:51:17 2004 +0100
     6.3 @@ -143,6 +143,9 @@
     6.4  lemma hypreal_add_minus_eq_minus: "x + y = (0::hypreal) ==> x = -y"
     6.5  by arith
     6.6  
     6.7 +lemma hypreal_le_add_order: "[| 0 \<le> x; 0 \<le> y |] ==> (0::hypreal) \<le> x + y"
     6.8 +by arith
     6.9 +
    6.10  
    6.11  subsubsection{*Division By @{term 1} and @{term "-1"}*}
    6.12  
    6.13 @@ -197,6 +200,7 @@
    6.14  ML
    6.15  {*
    6.16  val hypreal_add_minus_eq_minus = thm "hypreal_add_minus_eq_minus";
    6.17 +val hypreal_le_add_order = thm"hypreal_le_add_order";
    6.18  *}
    6.19  
    6.20  end
     7.1 --- a/src/HOL/Hyperreal/HyperDef.thy	Wed Jan 28 17:01:01 2004 +0100
     7.2 +++ b/src/HOL/Hyperreal/HyperDef.thy	Thu Jan 29 16:51:17 2004 +0100
     7.3 @@ -67,7 +67,7 @@
     7.4    epsilon :: hypreal   ("\<epsilon>")
     7.5  
     7.6  
     7.7 -defs
     7.8 +defs (overloaded)
     7.9  
    7.10    hypreal_add_def:
    7.11    "P + Q == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). \<Union>Y \<in> Rep_hypreal(Q).
    7.12 @@ -77,12 +77,12 @@
    7.13    "P * Q == Abs_hypreal(\<Union>X \<in> Rep_hypreal(P). \<Union>Y \<in> Rep_hypreal(Q).
    7.14                  hyprel``{%n::nat. X n * Y n})"
    7.15  
    7.16 -  hypreal_less_def:
    7.17 -  "P < (Q::hypreal) == \<exists>X Y. X \<in> Rep_hypreal(P) &
    7.18 +  hypreal_le_def:
    7.19 +  "P \<le> (Q::hypreal) == \<exists>X Y. X \<in> Rep_hypreal(P) &
    7.20                                 Y \<in> Rep_hypreal(Q) &
    7.21 -                               {n::nat. X n < Y n} \<in> FreeUltrafilterNat"
    7.22 -  hypreal_le_def:
    7.23 -  "P \<le> (Q::hypreal) == ~(Q < P)"
    7.24 +                               {n::nat. X n \<le> Y n} \<in> FreeUltrafilterNat"
    7.25 +
    7.26 +  hypreal_less_def: "(x < (y::hypreal)) == (x \<le> y & x \<noteq> y)"
    7.27  
    7.28    hrabs_def:  "abs (r::hypreal) == (if 0 \<le> r then r else -r)"
    7.29  
    7.30 @@ -494,205 +494,88 @@
    7.31  qed
    7.32  
    7.33  
    7.34 -subsection{*Theorems for Ordering*}
    7.35 -
    7.36 -text{*TODO: define @{text "\<le>"} as the primitive concept and quickly 
    7.37 -establish membership in class @{text linorder}. Then proofs could be
    7.38 -simplified, since properties of @{text "<"} would be generic.*}
    7.39 -
    7.40 -text{*TODO: The following theorem should be used througout the proofs
    7.41 -  as it probably makes many of them more straightforward.*}
    7.42 -lemma hypreal_less: 
    7.43 -      "(Abs_hypreal(hyprel``{%n. X n}) < Abs_hypreal(hyprel``{%n. Y n})) =  
    7.44 -       ({n. X n < Y n} \<in> FreeUltrafilterNat)"
    7.45 -apply (unfold hypreal_less_def)
    7.46 -apply (auto intro!: lemma_hyprel_refl, ultra)
    7.47 -done
    7.48 -
    7.49 -lemma hypreal_less_not_refl: "~ (R::hypreal) < R"
    7.50 -apply (rule_tac z = R in eq_Abs_hypreal)
    7.51 -apply (auto simp add: hypreal_less_def, ultra)
    7.52 -done
    7.53 -
    7.54 -lemmas hypreal_less_irrefl = hypreal_less_not_refl [THEN notE, standard]
    7.55 -declare hypreal_less_irrefl [elim!]
    7.56 -
    7.57 -lemma hypreal_not_refl2: "!!(x::hypreal). x < y ==> x \<noteq> y"
    7.58 -by (auto simp add: hypreal_less_not_refl)
    7.59 -
    7.60 -lemma hypreal_less_trans: "!!(R1::hypreal). [| R1 < R2; R2 < R3 |] ==> R1 < R3"
    7.61 -apply (rule_tac z = R1 in eq_Abs_hypreal)
    7.62 -apply (rule_tac z = R2 in eq_Abs_hypreal)
    7.63 -apply (rule_tac z = R3 in eq_Abs_hypreal)
    7.64 -apply (auto intro!: exI simp add: hypreal_less_def, ultra)
    7.65 -done
    7.66 -
    7.67 -lemma hypreal_less_asym: "!! (R1::hypreal). [| R1 < R2; R2 < R1 |] ==> P"
    7.68 -apply (drule hypreal_less_trans, assumption)
    7.69 -apply (simp add: hypreal_less_not_refl)
    7.70 -done
    7.71 -
    7.72 -
    7.73 -subsection{*Trichotomy: the hyperreals are Linearly Ordered*}
    7.74 -
    7.75 -lemma lemma_hyprel_0_mem: "\<exists>x. x \<in> hyprel `` {%n. 0}"
    7.76 -apply (unfold hyprel_def)
    7.77 -apply (rule_tac x = "%n. 0" in exI, safe)
    7.78 -apply (auto intro!: FreeUltrafilterNat_Nat_set)
    7.79 -done
    7.80 -
    7.81 -lemma hypreal_trichotomy: "0 <  x | x = 0 | x < (0::hypreal)"
    7.82 -apply (unfold hypreal_zero_def)
    7.83 -apply (rule_tac z = x in eq_Abs_hypreal)
    7.84 -apply (auto simp add: hypreal_less_def)
    7.85 -apply (cut_tac lemma_hyprel_0_mem, erule exE)
    7.86 -apply (drule_tac x = xa in spec)
    7.87 -apply (drule_tac x = x in spec)
    7.88 -apply (cut_tac x = x in lemma_hyprel_refl, auto)
    7.89 -apply (drule_tac x = x in spec)
    7.90 -apply (drule_tac x = xa in spec, auto, ultra)
    7.91 -done
    7.92 -
    7.93 -lemma hypreal_trichotomyE:
    7.94 -     "[| (0::hypreal) < x ==> P;  
    7.95 -         x = 0 ==> P;  
    7.96 -         x < 0 ==> P |] ==> P"
    7.97 -apply (insert hypreal_trichotomy [of x], blast) 
    7.98 -done
    7.99 -
   7.100 -lemma hypreal_less_minus_iff: "((x::hypreal) < y) = (0 < y + -x)"
   7.101 -apply (rule_tac z = x in eq_Abs_hypreal)
   7.102 -apply (rule_tac z = y in eq_Abs_hypreal)
   7.103 -apply (auto simp add: hypreal_add hypreal_zero_def hypreal_minus hypreal_less)
   7.104 -done
   7.105 -
   7.106 -lemma hypreal_less_minus_iff2: "((x::hypreal) < y) = (x + -y < 0)"
   7.107 -apply (rule_tac z = x in eq_Abs_hypreal)
   7.108 -apply (rule_tac z = y in eq_Abs_hypreal)
   7.109 -apply (auto simp add: hypreal_add hypreal_zero_def hypreal_minus hypreal_less)
   7.110 -done
   7.111 -
   7.112 -lemma hypreal_eq_minus_iff2: "((x::hypreal) = y) = (0 = y + - x)"
   7.113 -apply auto
   7.114 -apply (rule Ring_and_Field.add_right_cancel [of _ "-x", THEN iffD1], auto)
   7.115 -done
   7.116 -
   7.117 -lemma hypreal_linear: "(x::hypreal) < y | x = y | y < x"
   7.118 -apply (subst hypreal_eq_minus_iff2)
   7.119 -apply (rule_tac x1 = x in hypreal_less_minus_iff [THEN ssubst])
   7.120 -apply (rule_tac x1 = y in hypreal_less_minus_iff2 [THEN ssubst])
   7.121 -apply (rule hypreal_trichotomyE, auto)
   7.122 -done
   7.123 -
   7.124 -lemma hypreal_neq_iff: "((w::hypreal) \<noteq> z) = (w<z | z<w)"
   7.125 -by (cut_tac hypreal_linear, blast)
   7.126 -
   7.127 -
   7.128  subsection{*Properties of The @{text "\<le>"} Relation*}
   7.129  
   7.130  lemma hypreal_le: 
   7.131        "(Abs_hypreal(hyprel``{%n. X n}) \<le> Abs_hypreal(hyprel``{%n. Y n})) =  
   7.132         ({n. X n \<le> Y n} \<in> FreeUltrafilterNat)"
   7.133 -apply (auto simp add: hypreal_less hypreal_le_def linorder_not_less[symmetric])
   7.134 -apply (ultra+)
   7.135 -done
   7.136 -
   7.137 -lemma hypreal_le_imp_less_or_eq: "!!(x::hypreal). x \<le> y ==> x < y | x = y"
   7.138  apply (unfold hypreal_le_def)
   7.139 -apply (cut_tac hypreal_linear)
   7.140 -apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   7.141 +apply (auto intro!: lemma_hyprel_refl)
   7.142 +apply (ultra)
   7.143  done
   7.144  
   7.145 -lemma hypreal_less_or_eq_imp_le: "z<w | z=w ==> z \<le>(w::hypreal)"
   7.146 -apply (unfold hypreal_le_def)
   7.147 -apply (cut_tac hypreal_linear)
   7.148 -apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   7.149 -done
   7.150 -
   7.151 -lemma hypreal_le_eq_less_or_eq: "(x \<le> (y::hypreal)) = (x < y | x=y)"
   7.152 -by (blast intro!: hypreal_less_or_eq_imp_le dest: hypreal_le_imp_less_or_eq) 
   7.153 -
   7.154 -lemmas hypreal_le_less = hypreal_le_eq_less_or_eq
   7.155 -
   7.156  lemma hypreal_le_refl: "w \<le> (w::hypreal)"
   7.157 -by (simp add: hypreal_le_eq_less_or_eq)
   7.158 -
   7.159 -(* Axiom 'linorder_linear' of class 'linorder': *)
   7.160 -lemma hypreal_le_linear: "(z::hypreal) \<le> w | w \<le> z"
   7.161 -apply (simp add: hypreal_le_less)
   7.162 -apply (cut_tac hypreal_linear, blast)
   7.163 +apply (rule eq_Abs_hypreal [of w])
   7.164 +apply (simp add: hypreal_le) 
   7.165  done
   7.166  
   7.167  lemma hypreal_le_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::hypreal)"
   7.168 -apply (drule hypreal_le_imp_less_or_eq) 
   7.169 -apply (drule hypreal_le_imp_less_or_eq) 
   7.170 -apply (rule hypreal_less_or_eq_imp_le) 
   7.171 -apply (blast intro: hypreal_less_trans) 
   7.172 +apply (rule eq_Abs_hypreal [of i])
   7.173 +apply (rule eq_Abs_hypreal [of j])
   7.174 +apply (rule eq_Abs_hypreal [of k])
   7.175 +apply (simp add: hypreal_le) 
   7.176 +apply ultra
   7.177  done
   7.178  
   7.179  lemma hypreal_le_anti_sym: "[| z \<le> w; w \<le> z |] ==> z = (w::hypreal)"
   7.180 -apply (drule hypreal_le_imp_less_or_eq) 
   7.181 -apply (drule hypreal_le_imp_less_or_eq) 
   7.182 -apply (fast elim: hypreal_less_irrefl hypreal_less_asym)
   7.183 +apply (rule eq_Abs_hypreal [of z])
   7.184 +apply (rule eq_Abs_hypreal [of w])
   7.185 +apply (simp add: hypreal_le) 
   7.186 +apply ultra
   7.187  done
   7.188  
   7.189  (* Axiom 'order_less_le' of class 'order': *)
   7.190  lemma hypreal_less_le: "((w::hypreal) < z) = (w \<le> z & w \<noteq> z)"
   7.191 -apply (simp add: hypreal_le_def hypreal_neq_iff)
   7.192 -apply (blast intro: hypreal_less_asym)
   7.193 +apply (simp add: hypreal_less_def)
   7.194  done
   7.195  
   7.196  instance hypreal :: order
   7.197 -  by (intro_classes,
   7.198 -      (assumption | 
   7.199 -       rule hypreal_le_refl hypreal_le_trans hypreal_le_anti_sym
   7.200 -            hypreal_less_le)+)
   7.201 +proof qed
   7.202 + (assumption |
   7.203 +  rule hypreal_le_refl hypreal_le_trans hypreal_le_anti_sym hypreal_less_le)+
   7.204 +
   7.205 +
   7.206 +(* Axiom 'linorder_linear' of class 'linorder': *)
   7.207 +lemma hypreal_le_linear: "(z::hypreal) \<le> w | w \<le> z"
   7.208 +apply (rule eq_Abs_hypreal [of z])
   7.209 +apply (rule eq_Abs_hypreal [of w])
   7.210 +apply (auto simp add: hypreal_le) 
   7.211 +apply ultra
   7.212 +done
   7.213  
   7.214  instance hypreal :: linorder 
   7.215    by (intro_classes, rule hypreal_le_linear)
   7.216  
   7.217 -
   7.218 -lemma hypreal_add_less_mono1: "(A::hypreal) < B ==> A + C < B + C"
   7.219 -apply (rule_tac z = A in eq_Abs_hypreal)
   7.220 -apply (rule_tac z = B in eq_Abs_hypreal)
   7.221 -apply (rule_tac z = C in eq_Abs_hypreal)
   7.222 -apply (auto intro!: exI simp add: hypreal_less_def hypreal_add, ultra)
   7.223 -done
   7.224 +lemma hypreal_not_refl2: "!!(x::hypreal). x < y ==> x \<noteq> y"
   7.225 +by (auto simp add: order_less_irrefl)
   7.226  
   7.227 -lemma hypreal_mult_order: "[| 0 < x; 0 < y |] ==> (0::hypreal) < x * y"
   7.228 -apply (unfold hypreal_zero_def)
   7.229 -apply (rule_tac z = x in eq_Abs_hypreal)
   7.230 -apply (rule_tac z = y in eq_Abs_hypreal)
   7.231 -apply (auto intro!: exI simp add: hypreal_less_def hypreal_mult, ultra)
   7.232 -apply (auto intro: real_mult_order)
   7.233 -done
   7.234 -
   7.235 -lemma hypreal_add_left_le_mono1: "(q1::hypreal) \<le> q2  ==> x + q1 \<le> x + q2"
   7.236 -apply (drule order_le_imp_less_or_eq)
   7.237 -apply (auto intro: order_less_imp_le hypreal_add_less_mono1 simp add: hypreal_add_commute)
   7.238 -done
   7.239 -
   7.240 -lemma hypreal_mult_less_mono1: "[| (0::hypreal) < z; x < y |] ==> x*z < y*z"
   7.241 -apply (rotate_tac 1)
   7.242 -apply (drule hypreal_less_minus_iff [THEN iffD1])
   7.243 -apply (rule hypreal_less_minus_iff [THEN iffD2])
   7.244 -apply (drule hypreal_mult_order, assumption)
   7.245 -apply (simp add: right_distrib hypreal_mult_commute)
   7.246 +lemma hypreal_add_left_mono: "x \<le> y ==> z + x \<le> z + (y::hypreal)"
   7.247 +apply (rule eq_Abs_hypreal [of x])
   7.248 +apply (rule eq_Abs_hypreal [of y])
   7.249 +apply (rule eq_Abs_hypreal [of z])
   7.250 +apply (auto simp add: hypreal_le hypreal_add) 
   7.251  done
   7.252  
   7.253  lemma hypreal_mult_less_mono2: "[| (0::hypreal)<z; x<y |] ==> z*x<z*y"
   7.254 -apply (simp (no_asm_simp) add: hypreal_mult_commute hypreal_mult_less_mono1)
   7.255 +apply (rule eq_Abs_hypreal [of x])
   7.256 +apply (rule eq_Abs_hypreal [of y])
   7.257 +apply (rule eq_Abs_hypreal [of z])
   7.258 +apply (auto simp add: hypreal_zero_def hypreal_le hypreal_mult 
   7.259 +                      linorder_not_le [symmetric])
   7.260 +apply ultra 
   7.261  done
   7.262  
   7.263 +
   7.264  subsection{*The Hyperreals Form an Ordered Field*}
   7.265  
   7.266  instance hypreal :: ordered_field
   7.267  proof
   7.268    fix x y z :: hypreal
   7.269    show "0 < (1::hypreal)" 
   7.270 -    by (unfold hypreal_one_def hypreal_zero_def hypreal_less_def, force)
   7.271 +    by (simp add: hypreal_zero_def hypreal_one_def linorder_not_le [symmetric],
   7.272 +        simp add: hypreal_le)
   7.273    show "x \<le> y ==> z + x \<le> z + y" 
   7.274 -    by (rule hypreal_add_left_le_mono1)
   7.275 +    by (rule hypreal_add_left_mono)
   7.276    show "x < y ==> 0 < z ==> z * x < z * y" 
   7.277      by (simp add: hypreal_mult_less_mono2)
   7.278    show "\<bar>x\<bar> = (if x < 0 then -x else x)"
   7.279 @@ -783,17 +666,17 @@
   7.280  lemma hypreal_of_real_zero [simp]: "hypreal_of_real 0 = 0"
   7.281  by (unfold hypreal_of_real_def hypreal_zero_def, simp)
   7.282  
   7.283 -lemma hypreal_of_real_less_iff [simp]: 
   7.284 -     "(hypreal_of_real w <  hypreal_of_real z) = (w < z)"
   7.285 -apply (unfold hypreal_less_def hypreal_of_real_def, auto)
   7.286 +lemma hypreal_of_real_le_iff [simp]: 
   7.287 +     "(hypreal_of_real w \<le> hypreal_of_real z) = (w \<le> z)"
   7.288 +apply (unfold hypreal_le_def hypreal_of_real_def, auto)
   7.289  apply (rule_tac [2] x = "%n. w" in exI, safe)
   7.290  apply (rule_tac [3] x = "%n. z" in exI, auto)
   7.291  apply (rule FreeUltrafilterNat_P, ultra)
   7.292  done
   7.293  
   7.294 -lemma hypreal_of_real_le_iff [simp]: 
   7.295 -     "(hypreal_of_real w \<le> hypreal_of_real z) = (w \<le> z)"
   7.296 -by (force simp add: hypreal_less hypreal_le_def linorder_not_less[symmetric])
   7.297 +lemma hypreal_of_real_less_iff [simp]: 
   7.298 +     "(hypreal_of_real w < hypreal_of_real z) = (w < z)"
   7.299 +by (simp add: linorder_not_le [symmetric]) 
   7.300  
   7.301  lemma hypreal_of_real_eq_iff [simp]:
   7.302       "(hypreal_of_real w = hypreal_of_real z) = (w = z)"
   7.303 @@ -821,14 +704,11 @@
   7.304  
   7.305  lemma hypreal_of_real_minus [simp]:
   7.306       "hypreal_of_real (-r) = - hypreal_of_real  r"
   7.307 -apply (unfold hypreal_of_real_def)
   7.308 -apply (auto simp add: hypreal_minus)
   7.309 -done
   7.310 +by (auto simp add: hypreal_of_real_def hypreal_minus)
   7.311  
   7.312  lemma hypreal_of_real_inverse [simp]:
   7.313       "hypreal_of_real (inverse r) = inverse (hypreal_of_real r)"
   7.314 -apply (case_tac "r=0")
   7.315 -apply (simp add: DIVISION_BY_ZERO INVERSE_ZERO HYPREAL_INVERSE_ZERO)
   7.316 +apply (case_tac "r=0", simp)
   7.317  apply (rule_tac c1 = "hypreal_of_real r" in hypreal_mult_left_cancel [THEN iffD1])
   7.318  apply (auto simp add: hypreal_of_real_mult [symmetric])
   7.319  done
   7.320 @@ -840,6 +720,13 @@
   7.321  
   7.322  subsection{*Misc Others*}
   7.323  
   7.324 +lemma hypreal_less: 
   7.325 +      "(Abs_hypreal(hyprel``{%n. X n}) < Abs_hypreal(hyprel``{%n. Y n})) =  
   7.326 +       ({n. X n < Y n} \<in> FreeUltrafilterNat)"
   7.327 +apply (auto simp add: hypreal_le linorder_not_le [symmetric]) 
   7.328 +apply ultra+
   7.329 +done
   7.330 +
   7.331  lemma hypreal_zero_num: "0 = Abs_hypreal (hyprel `` {%n. 0})"
   7.332  by (simp add: hypreal_zero_def [THEN meta_eq_to_obj_eq, symmetric])
   7.333  
   7.334 @@ -851,7 +738,6 @@
   7.335  apply (auto simp add: hypreal_less hypreal_zero_num)
   7.336  done
   7.337  
   7.338 -
   7.339  lemma hypreal_hrabs:
   7.340       "abs (Abs_hypreal (hyprel `` {X})) = 
   7.341        Abs_hypreal(hyprel `` {%n. abs (X n)})"
   7.342 @@ -859,6 +745,74 @@
   7.343  apply (ultra, arith)+
   7.344  done
   7.345  
   7.346 +
   7.347 +
   7.348 +lemma hypreal_add_zero_less_le_mono: "[|r < x; (0::hypreal) \<le> y|] ==> r < x+y"
   7.349 +by (auto dest: add_less_le_mono)
   7.350 +
   7.351 +text{*The precondition could be weakened to @{term "0\<le>x"}*}
   7.352 +lemma hypreal_mult_less_mono:
   7.353 +     "[| u<v;  x<y;  (0::hypreal) < v;  0 < x |] ==> u*x < v* y"
   7.354 + by (simp add: Ring_and_Field.mult_strict_mono order_less_imp_le)
   7.355 +
   7.356 +
   7.357 +subsection{*Existence of Infinite Hyperreal Number*}
   7.358 +
   7.359 +lemma Rep_hypreal_omega: "Rep_hypreal(omega) \<in> hypreal"
   7.360 +apply (unfold omega_def)
   7.361 +apply (rule Rep_hypreal)
   7.362 +done
   7.363 +
   7.364 +text{*Existence of infinite number not corresponding to any real number.
   7.365 +Use assumption that member @{term FreeUltrafilterNat} is not finite.*}
   7.366 +
   7.367 +
   7.368 +text{*A few lemmas first*}
   7.369 +
   7.370 +lemma lemma_omega_empty_singleton_disj: "{n::nat. x = real n} = {} |  
   7.371 +      (\<exists>y. {n::nat. x = real n} = {y})"
   7.372 +by (force dest: inj_real_of_nat [THEN injD])
   7.373 +
   7.374 +lemma lemma_finite_omega_set: "finite {n::nat. x = real n}"
   7.375 +by (cut_tac x = x in lemma_omega_empty_singleton_disj, auto)
   7.376 +
   7.377 +lemma not_ex_hypreal_of_real_eq_omega: 
   7.378 +      "~ (\<exists>x. hypreal_of_real x = omega)"
   7.379 +apply (unfold omega_def hypreal_of_real_def)
   7.380 +apply (auto simp add: real_of_nat_Suc diff_eq_eq [symmetric] 
   7.381 +            lemma_finite_omega_set [THEN FreeUltrafilterNat_finite])
   7.382 +done
   7.383 +
   7.384 +lemma hypreal_of_real_not_eq_omega: "hypreal_of_real x \<noteq> omega"
   7.385 +by (cut_tac not_ex_hypreal_of_real_eq_omega, auto)
   7.386 +
   7.387 +text{*Existence of infinitesimal number also not corresponding to any
   7.388 + real number*}
   7.389 +
   7.390 +lemma lemma_epsilon_empty_singleton_disj:
   7.391 +     "{n::nat. x = inverse(real(Suc n))} = {} |  
   7.392 +      (\<exists>y. {n::nat. x = inverse(real(Suc n))} = {y})"
   7.393 +by (auto simp add: inj_real_of_nat [THEN inj_eq])
   7.394 +
   7.395 +lemma lemma_finite_epsilon_set: "finite {n. x = inverse(real(Suc n))}"
   7.396 +by (cut_tac x = x in lemma_epsilon_empty_singleton_disj, auto)
   7.397 +
   7.398 +lemma not_ex_hypreal_of_real_eq_epsilon: 
   7.399 +      "~ (\<exists>x. hypreal_of_real x = epsilon)"
   7.400 +apply (unfold epsilon_def hypreal_of_real_def)
   7.401 +apply (auto simp add: lemma_finite_epsilon_set [THEN FreeUltrafilterNat_finite])
   7.402 +done
   7.403 +
   7.404 +lemma hypreal_of_real_not_eq_epsilon: "hypreal_of_real x \<noteq> epsilon"
   7.405 +by (cut_tac not_ex_hypreal_of_real_eq_epsilon, auto)
   7.406 +
   7.407 +lemma hypreal_epsilon_not_zero: "epsilon \<noteq> 0"
   7.408 +by (unfold epsilon_def hypreal_zero_def, auto)
   7.409 +
   7.410 +lemma hypreal_epsilon_inverse_omega: "epsilon = inverse(omega)"
   7.411 +by (simp add: hypreal_inverse omega_def epsilon_def)
   7.412 +
   7.413 +
   7.414  ML
   7.415  {*
   7.416  val hrabs_def = thm "hrabs_def";
   7.417 @@ -946,23 +900,12 @@
   7.418  val hypreal_mult_not_0 = thm "hypreal_mult_not_0";
   7.419  val hypreal_minus_inverse = thm "hypreal_minus_inverse";
   7.420  val hypreal_inverse_distrib = thm "hypreal_inverse_distrib";
   7.421 -val hypreal_less_not_refl = thm "hypreal_less_not_refl";
   7.422 -val hypreal_less_irrefl = thm"hypreal_less_irrefl";
   7.423  val hypreal_not_refl2 = thm "hypreal_not_refl2";
   7.424 -val hypreal_less_trans = thm "hypreal_less_trans";
   7.425 -val hypreal_less_asym = thm "hypreal_less_asym";
   7.426  val hypreal_less = thm "hypreal_less";
   7.427 -val hypreal_trichotomy = thm "hypreal_trichotomy";
   7.428 -val hypreal_less_minus_iff = thm "hypreal_less_minus_iff";
   7.429 -val hypreal_less_minus_iff2 = thm "hypreal_less_minus_iff2";
   7.430  val hypreal_eq_minus_iff = thm "hypreal_eq_minus_iff";
   7.431 -val hypreal_eq_minus_iff2 = thm "hypreal_eq_minus_iff2";
   7.432  val hypreal_eq_minus_iff3 = thm "hypreal_eq_minus_iff3";
   7.433  val hypreal_not_eq_minus_iff = thm "hypreal_not_eq_minus_iff";
   7.434 -val hypreal_linear = thm "hypreal_linear";
   7.435  val hypreal_le = thm "hypreal_le";
   7.436 -val hypreal_le_imp_less_or_eq = thm "hypreal_le_imp_less_or_eq";
   7.437 -val hypreal_le_eq_less_or_eq = thm "hypreal_le_eq_less_or_eq";
   7.438  val hypreal_le_refl = thm "hypreal_le_refl";
   7.439  val hypreal_le_linear = thm "hypreal_le_linear";
   7.440  val hypreal_le_trans = thm "hypreal_le_trans";
   7.441 @@ -984,6 +927,17 @@
   7.442  val hypreal_zero_num = thm "hypreal_zero_num";
   7.443  val hypreal_one_num = thm "hypreal_one_num";
   7.444  val hypreal_omega_gt_zero = thm "hypreal_omega_gt_zero";
   7.445 +
   7.446 +val hypreal_add_zero_less_le_mono = thm"hypreal_add_zero_less_le_mono";
   7.447 +val Rep_hypreal_omega = thm"Rep_hypreal_omega";
   7.448 +val lemma_omega_empty_singleton_disj = thm"lemma_omega_empty_singleton_disj";
   7.449 +val lemma_finite_omega_set = thm"lemma_finite_omega_set";
   7.450 +val not_ex_hypreal_of_real_eq_omega = thm"not_ex_hypreal_of_real_eq_omega";
   7.451 +val hypreal_of_real_not_eq_omega = thm"hypreal_of_real_not_eq_omega";
   7.452 +val not_ex_hypreal_of_real_eq_epsilon = thm"not_ex_hypreal_of_real_eq_epsilon";
   7.453 +val hypreal_of_real_not_eq_epsilon = thm"hypreal_of_real_not_eq_epsilon";
   7.454 +val hypreal_epsilon_not_zero = thm"hypreal_epsilon_not_zero";
   7.455 +val hypreal_epsilon_inverse_omega = thm"hypreal_epsilon_inverse_omega";
   7.456  *}
   7.457  
   7.458  end
     8.1 --- a/src/HOL/Hyperreal/HyperNat.ML	Wed Jan 28 17:01:01 2004 +0100
     8.2 +++ b/src/HOL/Hyperreal/HyperNat.ML	Thu Jan 29 16:51:17 2004 +0100
     8.3 @@ -5,6 +5,12 @@
     8.4                    ultrafilters
     8.5  *) 
     8.6  
     8.7 +fun CLAIM_SIMP str thms =
     8.8 +               prove_goal (the_context()) str
     8.9 +               (fn prems => [cut_facts_tac prems 1,
    8.10 +                   auto_tac (claset(),simpset() addsimps thms)]);
    8.11 +fun CLAIM str = CLAIM_SIMP str [];
    8.12 +
    8.13  (* blast confuses different versions of < *)
    8.14  DelIffs [order_less_irrefl];
    8.15  Addsimps [order_less_irrefl];
     9.1 --- a/src/HOL/Hyperreal/HyperOrd.thy	Wed Jan 28 17:01:01 2004 +0100
     9.2 +++ b/src/HOL/Hyperreal/HyperOrd.thy	Thu Jan 29 16:51:17 2004 +0100
     9.3 @@ -1,124 +1,9 @@
     9.4 -(*  Title:	 Real/Hyperreal/HyperOrd.thy
     9.5 -    Author:      Jacques D. Fleuriot
     9.6 -    Copyright:   2000 University of Edinburgh
     9.7 -    Description: Type "hypreal" is a linear order and also 
     9.8 -                 satisfies plus_ac0: + is an AC-operator with zero
     9.9 -*)
    9.10 -
    9.11  theory HyperOrd = HyperDef:
    9.12  
    9.13  
    9.14 -(*** Monotonicity results ***)
    9.15 -
    9.16 -lemma hypreal_add_less_le_mono: "[|(i::hypreal)<j;  k\<le>l |] ==> i + k < j + l"
    9.17 -by (auto dest!: order_le_imp_less_or_eq intro: hypreal_add_less_mono1 add_strict_mono)
    9.18 -
    9.19 -lemma hypreal_add_less_mono2: "!!(A::hypreal). A < B ==> C + A < C + B"
    9.20 -by (auto intro: hypreal_add_less_mono1 simp add: hypreal_add_commute)
    9.21 -
    9.22 -lemma hypreal_add_le_less_mono: "[|(i::hypreal)\<le>j;  k<l |] ==> i + k < j + l"
    9.23 -apply (erule add_right_mono [THEN order_le_less_trans])
    9.24 -apply (erule add_strict_left_mono) 
    9.25 -done
    9.26 -
    9.27 -lemma hypreal_add_zero_less_le_mono: "[|r < x; (0::hypreal) \<le> y|] ==> r < x + y"
    9.28 -by (auto dest: hypreal_add_less_le_mono)
    9.29 -
    9.30 -lemma hypreal_add_order: "[| 0 < x; 0 < y |] ==> (0::hypreal) < x + y"
    9.31 -apply (erule order_less_trans)
    9.32 -apply (drule hypreal_add_less_mono2, simp)
    9.33 -done
    9.34 -
    9.35 -lemma hypreal_le_add_order: "[| 0 \<le> x; 0 \<le> y |] ==> (0::hypreal) \<le> x + y"
    9.36 -apply (drule order_le_imp_less_or_eq)+
    9.37 -apply (auto intro: hypreal_add_order order_less_imp_le)
    9.38 -done
    9.39 -
    9.40 -text{*The precondition could be weakened to @{term "0\<le>x"}*}
    9.41 -lemma hypreal_mult_less_mono:
    9.42 -     "[| u<v;  x<y;  (0::hypreal) < v;  0 < x |] ==> u*x < v* y"
    9.43 - by (simp add: Ring_and_Field.mult_strict_mono order_less_imp_le)
    9.44 -
    9.45 -
    9.46 -subsection{*Existence of Infinite Hyperreal Number*}
    9.47 -
    9.48 -lemma Rep_hypreal_omega: "Rep_hypreal(omega) \<in> hypreal"
    9.49 -apply (unfold omega_def)
    9.50 -apply (rule Rep_hypreal)
    9.51 -done
    9.52 -
    9.53 -text{*Existence of infinite number not corresponding to any real number.
    9.54 -Use assumption that member @{term FreeUltrafilterNat} is not finite.*}
    9.55 -
    9.56 -
    9.57 -text{*A few lemmas first*}
    9.58 -
    9.59 -lemma lemma_omega_empty_singleton_disj: "{n::nat. x = real n} = {} |  
    9.60 -      (\<exists>y. {n::nat. x = real n} = {y})"
    9.61 -by (force dest: inj_real_of_nat [THEN injD])
    9.62 -
    9.63 -lemma lemma_finite_omega_set: "finite {n::nat. x = real n}"
    9.64 -by (cut_tac x = x in lemma_omega_empty_singleton_disj, auto)
    9.65 -
    9.66 -lemma not_ex_hypreal_of_real_eq_omega: 
    9.67 -      "~ (\<exists>x. hypreal_of_real x = omega)"
    9.68 -apply (unfold omega_def hypreal_of_real_def)
    9.69 -apply (auto simp add: real_of_nat_Suc diff_eq_eq [symmetric] 
    9.70 -            lemma_finite_omega_set [THEN FreeUltrafilterNat_finite])
    9.71 -done
    9.72 -
    9.73 -lemma hypreal_of_real_not_eq_omega: "hypreal_of_real x \<noteq> omega"
    9.74 -by (cut_tac not_ex_hypreal_of_real_eq_omega, auto)
    9.75 -
    9.76 -text{*Existence of infinitesimal number also not corresponding to any
    9.77 - real number*}
    9.78 -
    9.79 -lemma lemma_epsilon_empty_singleton_disj:
    9.80 -     "{n::nat. x = inverse(real(Suc n))} = {} |  
    9.81 -      (\<exists>y. {n::nat. x = inverse(real(Suc n))} = {y})"
    9.82 -apply (auto simp add: inj_real_of_nat [THEN inj_eq])
    9.83 -done
    9.84 -
    9.85 -lemma lemma_finite_epsilon_set: "finite {n. x = inverse(real(Suc n))}"
    9.86 -by (cut_tac x = x in lemma_epsilon_empty_singleton_disj, auto)
    9.87 -
    9.88 -lemma not_ex_hypreal_of_real_eq_epsilon: 
    9.89 -      "~ (\<exists>x. hypreal_of_real x = epsilon)"
    9.90 -apply (unfold epsilon_def hypreal_of_real_def)
    9.91 -apply (auto simp add: lemma_finite_epsilon_set [THEN FreeUltrafilterNat_finite])
    9.92 -done
    9.93 -
    9.94 -lemma hypreal_of_real_not_eq_epsilon: "hypreal_of_real x \<noteq> epsilon"
    9.95 -by (cut_tac not_ex_hypreal_of_real_eq_epsilon, auto)
    9.96 -
    9.97 -lemma hypreal_epsilon_not_zero: "epsilon \<noteq> 0"
    9.98 -by (unfold epsilon_def hypreal_zero_def, auto)
    9.99 -
   9.100 -lemma hypreal_epsilon_inverse_omega: "epsilon = inverse(omega)"
   9.101 -by (simp add: hypreal_inverse omega_def epsilon_def)
   9.102 -
   9.103  
   9.104  ML
   9.105  {*
   9.106 -val hypreal_add_less_mono1 = thm"hypreal_add_less_mono1";
   9.107 -val hypreal_mult_order = thm"hypreal_mult_order";
   9.108 -val hypreal_le_add_order = thm"hypreal_le_add_order";
   9.109 -val hypreal_add_left_le_mono1 = thm"hypreal_add_left_le_mono1";
   9.110 -val hypreal_add_less_le_mono = thm"hypreal_add_less_le_mono";
   9.111 -val hypreal_add_le_less_mono = thm"hypreal_add_le_less_mono";
   9.112 -val hypreal_add_zero_less_le_mono = thm"hypreal_add_zero_less_le_mono";
   9.113 -val hypreal_mult_less_mono1 = thm"hypreal_mult_less_mono1";
   9.114 -val hypreal_mult_less_mono2 = thm"hypreal_mult_less_mono2";
   9.115 -val hypreal_mult_less_mono = thm"hypreal_mult_less_mono";
   9.116 -val Rep_hypreal_omega = thm"Rep_hypreal_omega";
   9.117 -val lemma_omega_empty_singleton_disj = thm"lemma_omega_empty_singleton_disj";
   9.118 -val lemma_finite_omega_set = thm"lemma_finite_omega_set";
   9.119 -val not_ex_hypreal_of_real_eq_omega = thm"not_ex_hypreal_of_real_eq_omega";
   9.120 -val hypreal_of_real_not_eq_omega = thm"hypreal_of_real_not_eq_omega";
   9.121 -val not_ex_hypreal_of_real_eq_epsilon = thm"not_ex_hypreal_of_real_eq_epsilon";
   9.122 -val hypreal_of_real_not_eq_epsilon = thm"hypreal_of_real_not_eq_epsilon";
   9.123 -val hypreal_epsilon_not_zero = thm"hypreal_epsilon_not_zero";
   9.124 -val hypreal_epsilon_inverse_omega = thm"hypreal_epsilon_inverse_omega";
   9.125  *}
   9.126  
   9.127  end
    10.1 --- a/src/HOL/Hyperreal/NSA.ML	Wed Jan 28 17:01:01 2004 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,2384 +0,0 @@
    10.4 -(*  Title       : NSA.ML
    10.5 -    Author      : Jacques D. Fleuriot
    10.6 -    Copyright   : 1998  University of Cambridge
    10.7 -    Description : Infinite numbers, Infinitesimals,
    10.8 -                  infinitely close relation  etc.
    10.9 -*)
   10.10 -
   10.11 -fun CLAIM_SIMP str thms =
   10.12 -               prove_goal (the_context()) str
   10.13 -               (fn prems => [cut_facts_tac prems 1,
   10.14 -                   auto_tac (claset(),simpset() addsimps thms)]);
   10.15 -fun CLAIM str = CLAIM_SIMP str [];
   10.16 -
   10.17 -(*--------------------------------------------------------------------
   10.18 -     Closure laws for members of (embedded) set standard real Reals
   10.19 - --------------------------------------------------------------------*)
   10.20 -
   10.21 -Goalw [SReal_def] "[| (x::hypreal): Reals; y: Reals |] ==> x + y: Reals";
   10.22 -by (Step_tac 1);
   10.23 -by (res_inst_tac [("x","r + ra")] exI 1);
   10.24 -by (Simp_tac 1);
   10.25 -qed "SReal_add";
   10.26 -
   10.27 -Goalw [SReal_def] "[| (x::hypreal): Reals; y: Reals |] ==> x * y: Reals";
   10.28 -by (Step_tac 1);
   10.29 -by (res_inst_tac [("x","r * ra")] exI 1);
   10.30 -by (simp_tac (simpset() addsimps [hypreal_of_real_mult]) 1);
   10.31 -qed "SReal_mult";
   10.32 -
   10.33 -Goalw [SReal_def] "(x::hypreal): Reals ==> inverse x : Reals";
   10.34 -by (blast_tac (claset() addIs [hypreal_of_real_inverse RS sym]) 1);
   10.35 -qed "SReal_inverse";
   10.36 -
   10.37 -Goal "[| (x::hypreal): Reals;  y: Reals |] ==> x/y: Reals";
   10.38 -by (asm_simp_tac (simpset() addsimps [SReal_mult,SReal_inverse,
   10.39 -                                      hypreal_divide_def]) 1);
   10.40 -qed "SReal_divide";
   10.41 -
   10.42 -Goalw [SReal_def] "(x::hypreal): Reals ==> -x : Reals";
   10.43 -by (blast_tac (claset() addIs [hypreal_of_real_minus RS sym]) 1);
   10.44 -qed "SReal_minus";
   10.45 -
   10.46 -Goal "(-x : Reals) = ((x::hypreal): Reals)";
   10.47 -by Auto_tac;
   10.48 -by (etac SReal_minus 2);
   10.49 -by (dtac SReal_minus 1);
   10.50 -by Auto_tac;
   10.51 -qed "SReal_minus_iff";
   10.52 -Addsimps [SReal_minus_iff];
   10.53 -
   10.54 -Goal "[| (x::hypreal) + y : Reals; y: Reals |] ==> x: Reals";
   10.55 -by (dres_inst_tac [("x","y")] SReal_minus 1);
   10.56 -by (dtac SReal_add 1);
   10.57 -by (assume_tac 1);
   10.58 -by Auto_tac;
   10.59 -qed "SReal_add_cancel";
   10.60 -
   10.61 -Goalw [SReal_def] "(x::hypreal): Reals ==> abs x : Reals";
   10.62 -by (auto_tac (claset(), simpset() addsimps [hypreal_of_real_hrabs]));
   10.63 -qed "SReal_hrabs";
   10.64 -
   10.65 -Goalw [SReal_def] "hypreal_of_real x: Reals";
   10.66 -by (Blast_tac 1);
   10.67 -qed "SReal_hypreal_of_real";
   10.68 -Addsimps [SReal_hypreal_of_real];
   10.69 -
   10.70 -Goalw [hypreal_number_of_def] "(number_of w ::hypreal) : Reals";
   10.71 -by (rtac SReal_hypreal_of_real 1);
   10.72 -qed "SReal_number_of";
   10.73 -Addsimps [SReal_number_of];
   10.74 -
   10.75 -(** As always with numerals, 0 and 1 are special cases **)
   10.76 -
   10.77 -Goal "(0::hypreal) : Reals";
   10.78 -by (stac (hypreal_numeral_0_eq_0 RS sym) 1);
   10.79 -by (rtac SReal_number_of 1);
   10.80 -qed "Reals_0";
   10.81 -Addsimps [Reals_0];
   10.82 -
   10.83 -Goal "(1::hypreal) : Reals";
   10.84 -by (stac (hypreal_numeral_1_eq_1 RS sym) 1);
   10.85 -by (rtac SReal_number_of 1);
   10.86 -qed "Reals_1";
   10.87 -Addsimps [Reals_1];
   10.88 -
   10.89 -Goalw [hypreal_divide_def] "r : Reals ==> r/(number_of w::hypreal) : Reals";
   10.90 -by (blast_tac (claset() addSIs [SReal_number_of, SReal_mult,
   10.91 -                                SReal_inverse]) 1);
   10.92 -qed "SReal_divide_number_of";
   10.93 -
   10.94 -(* Infinitesimal epsilon not in Reals *)
   10.95 -
   10.96 -Goalw [SReal_def] "epsilon ~: Reals";
   10.97 -by (auto_tac (claset(),
   10.98 -              simpset() addsimps [hypreal_of_real_not_eq_epsilon RS not_sym]));
   10.99 -qed "SReal_epsilon_not_mem";
  10.100 -
  10.101 -Goalw [SReal_def] "omega ~: Reals";
  10.102 -by (auto_tac (claset(),
  10.103 -              simpset() addsimps [hypreal_of_real_not_eq_omega RS not_sym]));
  10.104 -qed "SReal_omega_not_mem";
  10.105 -
  10.106 -Goalw [SReal_def] "{x. hypreal_of_real x : Reals} = (UNIV::real set)";
  10.107 -by Auto_tac;
  10.108 -qed "SReal_UNIV_real";
  10.109 -
  10.110 -Goalw [SReal_def] "(x: Reals) = (EX y. x = hypreal_of_real y)";
  10.111 -by Auto_tac;
  10.112 -qed "SReal_iff";
  10.113 -
  10.114 -Goalw [SReal_def] "hypreal_of_real `(UNIV::real set) = Reals";
  10.115 -by Auto_tac;
  10.116 -qed "hypreal_of_real_image";
  10.117 -
  10.118 -Goalw [SReal_def] "inv hypreal_of_real `Reals = (UNIV::real set)";
  10.119 -by Auto_tac;
  10.120 -by (rtac (inj_hypreal_of_real RS inv_f_f RS subst) 1);
  10.121 -by (Blast_tac 1);
  10.122 -qed "inv_hypreal_of_real_image";
  10.123 -
  10.124 -Goalw [SReal_def]
  10.125 -      "[| EX x. x: P; P <= Reals |] ==> EX Q. P = hypreal_of_real ` Q";
  10.126 -by (Best_tac 1);
  10.127 -qed "SReal_hypreal_of_real_image";
  10.128 -
  10.129 -Goal "[| (x::hypreal): Reals; y: Reals;  x<y |] ==> EX r: Reals. x<r & r<y";
  10.130 -by (auto_tac (claset(), simpset() addsimps [SReal_iff]));
  10.131 -by (dtac real_dense 1 THEN Step_tac 1);
  10.132 -by (res_inst_tac [("x","hypreal_of_real r")] bexI 1);
  10.133 -by Auto_tac;
  10.134 -qed "SReal_dense";
  10.135 -
  10.136 -(*------------------------------------------------------------------
  10.137 -                   Completeness of Reals
  10.138 - ------------------------------------------------------------------*)
  10.139 -Goal "P <= Reals ==> ((EX x:P. y < x) = \
  10.140 -\     (EX X. hypreal_of_real X : P & y < hypreal_of_real X))";
  10.141 -by (blast_tac (claset() addSDs [SReal_iff RS iffD1]) 1);
  10.142 -by (flexflex_tac );
  10.143 -qed "SReal_sup_lemma";
  10.144 -
  10.145 -Goal "[| P <= Reals; EX x. x: P; EX y : Reals. ALL x: P. x < y |] \
  10.146 -\     ==> (EX X. X: {w. hypreal_of_real w : P}) & \
  10.147 -\         (EX Y. ALL X: {w. hypreal_of_real w : P}. X < Y)";
  10.148 -by (rtac conjI 1);
  10.149 -by (fast_tac (claset() addSDs [SReal_iff RS iffD1]) 1);
  10.150 -by (Auto_tac THEN ftac subsetD 1 THEN assume_tac 1);
  10.151 -by (dtac (SReal_iff RS iffD1) 1);
  10.152 -by (Auto_tac THEN res_inst_tac [("x","ya")] exI 1);
  10.153 -by Auto_tac;
  10.154 -qed "SReal_sup_lemma2";
  10.155 -
  10.156 -(*------------------------------------------------------
  10.157 -    lifting of ub and property of lub
  10.158 - -------------------------------------------------------*)
  10.159 -Goalw [isUb_def,setle_def]
  10.160 -      "(isUb (Reals) (hypreal_of_real ` Q) (hypreal_of_real Y)) = \
  10.161 -\      (isUb (UNIV :: real set) Q Y)";
  10.162 -by Auto_tac;
  10.163 -qed "hypreal_of_real_isUb_iff";
  10.164 -
  10.165 -Goalw [isLub_def,leastP_def]
  10.166 -     "isLub Reals (hypreal_of_real ` Q) (hypreal_of_real Y) \
  10.167 -\     ==> isLub (UNIV :: real set) Q Y";
  10.168 -by (auto_tac (claset() addIs [hypreal_of_real_isUb_iff RS iffD2],
  10.169 -              simpset() addsimps [hypreal_of_real_isUb_iff, setge_def]));
  10.170 -qed "hypreal_of_real_isLub1";
  10.171 -
  10.172 -Goalw [isLub_def,leastP_def]
  10.173 -      "isLub (UNIV :: real set) Q Y \
  10.174 -\      ==> isLub Reals (hypreal_of_real ` Q) (hypreal_of_real Y)";
  10.175 -by (auto_tac (claset(),
  10.176 -              simpset() addsimps [hypreal_of_real_isUb_iff, setge_def]));
  10.177 -by (forw_inst_tac [("x2","x")] (isUbD2a RS (SReal_iff RS iffD1) RS exE) 1);
  10.178 -by (assume_tac 2);
  10.179 -by (dres_inst_tac [("x","xa")] spec 1);
  10.180 -by (auto_tac (claset(), simpset() addsimps [hypreal_of_real_isUb_iff]));
  10.181 -qed "hypreal_of_real_isLub2";
  10.182 -
  10.183 -Goal "(isLub Reals (hypreal_of_real ` Q) (hypreal_of_real Y)) = \
  10.184 -\     (isLub (UNIV :: real set) Q Y)";
  10.185 -by (blast_tac (claset() addIs [hypreal_of_real_isLub1,
  10.186 -                               hypreal_of_real_isLub2]) 1);
  10.187 -qed "hypreal_of_real_isLub_iff";
  10.188 -
  10.189 -(* lemmas *)
  10.190 -Goalw [isUb_def]
  10.191 -     "isUb Reals P Y ==> EX Yo. isUb Reals P (hypreal_of_real Yo)";
  10.192 -by (auto_tac (claset(), simpset() addsimps [SReal_iff]));
  10.193 -qed "lemma_isUb_hypreal_of_real";
  10.194 -
  10.195 -Goalw [isLub_def,leastP_def,isUb_def]
  10.196 -     "isLub Reals P Y ==> EX Yo. isLub Reals P (hypreal_of_real Yo)";
  10.197 -by (auto_tac (claset(), simpset() addsimps [SReal_iff]));
  10.198 -qed "lemma_isLub_hypreal_of_real";
  10.199 -
  10.200 -Goalw [isLub_def,leastP_def,isUb_def]
  10.201 -     "EX Yo. isLub Reals P (hypreal_of_real Yo) ==> EX Y. isLub Reals P Y";
  10.202 -by Auto_tac;
  10.203 -qed "lemma_isLub_hypreal_of_real2";
  10.204 -
  10.205 -Goal "[| P <= Reals;  EX x. x: P;  EX Y. isUb Reals P Y |] \
  10.206 -\     ==> EX t::hypreal. isLub Reals P t";
  10.207 -by (ftac SReal_hypreal_of_real_image 1);
  10.208 -by (Auto_tac THEN dtac lemma_isUb_hypreal_of_real 1);
  10.209 -by (auto_tac (claset() addSIs [reals_complete, lemma_isLub_hypreal_of_real2],
  10.210 -     simpset() addsimps [hypreal_of_real_isLub_iff,hypreal_of_real_isUb_iff]));
  10.211 -qed "SReal_complete";
  10.212 -
  10.213 -(*--------------------------------------------------------------------
  10.214 -        Set of finite elements is a subring of the extended reals
  10.215 - --------------------------------------------------------------------*)
  10.216 -Goalw [HFinite_def] "[|x : HFinite; y : HFinite|] ==> (x+y) : HFinite";
  10.217 -by (blast_tac (claset() addSIs [SReal_add,hrabs_add_less]) 1);
  10.218 -qed "HFinite_add";
  10.219 -
  10.220 -Goalw [HFinite_def] "[|x : HFinite; y : HFinite|] ==> x*y : HFinite";
  10.221 -by (Asm_full_simp_tac 1);
  10.222 -by (blast_tac (claset() addSIs [SReal_mult,abs_mult_less]) 1);
  10.223 -qed "HFinite_mult";
  10.224 -
  10.225 -Goalw [HFinite_def] "(-x : HFinite) = (x : HFinite)";
  10.226 -by (Simp_tac 1);
  10.227 -qed "HFinite_minus_iff";
  10.228 -
  10.229 -Goalw [SReal_def,HFinite_def] "Reals <= HFinite";
  10.230 -by Auto_tac;
  10.231 -by (res_inst_tac [("x","1 + abs(hypreal_of_real r)")] exI 1);
  10.232 -by (auto_tac (claset(), simpset() addsimps [hypreal_of_real_hrabs]));
  10.233 -by (res_inst_tac [("x","1 + abs r")] exI 1);
  10.234 -by (Simp_tac 1);
  10.235 -qed "SReal_subset_HFinite";
  10.236 -
  10.237 -Goal "hypreal_of_real x : HFinite";
  10.238 -by (auto_tac (claset() addIs [(SReal_subset_HFinite RS subsetD)],
  10.239 -              simpset()));
  10.240 -qed "HFinite_hypreal_of_real";
  10.241 -
  10.242 -Addsimps [HFinite_hypreal_of_real];
  10.243 -
  10.244 -Goalw [HFinite_def] "x : HFinite ==> EX t: Reals. abs x < t";
  10.245 -by Auto_tac;
  10.246 -qed "HFiniteD";
  10.247 -
  10.248 -Goalw [HFinite_def] "(abs x : HFinite) = (x : HFinite)";
  10.249 -by Auto_tac;
  10.250 -qed "HFinite_hrabs_iff";
  10.251 -AddIffs [HFinite_hrabs_iff];
  10.252 -
  10.253 -Goal "number_of w : HFinite";
  10.254 -by (rtac (SReal_number_of RS (SReal_subset_HFinite RS subsetD)) 1);
  10.255 -qed "HFinite_number_of";
  10.256 -Addsimps [HFinite_number_of];
  10.257 -
  10.258 -(** As always with numerals, 0 and 1 are special cases **)
  10.259 -
  10.260 -Goal "0 : HFinite";
  10.261 -by (stac (hypreal_numeral_0_eq_0 RS sym) 1);
  10.262 -by (rtac HFinite_number_of 1);
  10.263 -qed "HFinite_0";
  10.264 -Addsimps [HFinite_0];
  10.265 -
  10.266 -Goal "1 : HFinite";
  10.267 -by (stac (hypreal_numeral_1_eq_1 RS sym) 1);
  10.268 -by (rtac HFinite_number_of 1);
  10.269 -qed "HFinite_1";
  10.270 -Addsimps [HFinite_1];
  10.271 -
  10.272 -Goal "[|x : HFinite; y <= x; 0 <= y |] ==> y: HFinite";
  10.273 -by (case_tac "x <= 0" 1);
  10.274 -by (dres_inst_tac [("y","x")] order_trans 1);
  10.275 -by (dtac hypreal_le_anti_sym 2);
  10.276 -by (auto_tac (claset(), simpset() addsimps [linorder_not_le]));
  10.277 -by (auto_tac (claset() addSIs [bexI] addIs [order_le_less_trans],
  10.278 -     simpset() addsimps [hrabs_eqI1,hrabs_eqI2,hrabs_minus_eqI1,HFinite_def]));
  10.279 -qed "HFinite_bounded";
  10.280 -
  10.281 -(*------------------------------------------------------------------
  10.282 -       Set of infinitesimals is a subring of the hyperreals
  10.283 - ------------------------------------------------------------------*)
  10.284 -Goalw [Infinitesimal_def]
  10.285 -      "x : Infinitesimal ==> ALL r: Reals. 0 < r --> abs x < r";
  10.286 -by Auto_tac;
  10.287 -qed "InfinitesimalD";
  10.288 -
  10.289 -Goalw [Infinitesimal_def] "0 : Infinitesimal";
  10.290 -by (Simp_tac 1);
  10.291 -qed "Infinitesimal_zero";
  10.292 -AddIffs [Infinitesimal_zero];
  10.293 -
  10.294 -Goal "x/(2::hypreal) + x/(2::hypreal) = x";
  10.295 -by Auto_tac;
  10.296 -qed "hypreal_sum_of_halves";
  10.297 -
  10.298 -Goal "0 < r ==> 0 < r/(2::hypreal)";
  10.299 -by Auto_tac;
  10.300 -qed "hypreal_half_gt_zero";
  10.301 -
  10.302 -Goalw [Infinitesimal_def]
  10.303 -     "[| x : Infinitesimal; y : Infinitesimal |] ==> (x+y) : Infinitesimal";
  10.304 -by Auto_tac;
  10.305 -by (rtac (hypreal_sum_of_halves RS subst) 1);
  10.306 -by (dtac hypreal_half_gt_zero 1);
  10.307 -by (blast_tac (claset() addIs [hrabs_add_less, hrabs_add_less,
  10.308 -                               SReal_divide_number_of]) 1);
  10.309 -qed "Infinitesimal_add";
  10.310 -
  10.311 -Goalw [Infinitesimal_def] "(-x:Infinitesimal) = (x:Infinitesimal)";
  10.312 -by (Full_simp_tac 1);
  10.313 -qed "Infinitesimal_minus_iff";
  10.314 -Addsimps [Infinitesimal_minus_iff];
  10.315 -
  10.316 -Goal "[| x : Infinitesimal;  y : Infinitesimal |] ==> x-y : Infinitesimal";
  10.317 -by (asm_simp_tac
  10.318 -    (simpset() addsimps [hypreal_diff_def, Infinitesimal_add]) 1);
  10.319 -qed "Infinitesimal_diff";
  10.320 -
  10.321 -Goalw [Infinitesimal_def]
  10.322 -     "[| x : Infinitesimal; y : Infinitesimal |] ==> (x * y) : Infinitesimal";
  10.323 -by Auto_tac;
  10.324 -by (case_tac "y=0" 1);
  10.325 -by (cut_inst_tac [("u","abs x"),("v","1"),("x","abs y"),("y","r")]
  10.326 -    hypreal_mult_less_mono 2);
  10.327 -by Auto_tac;
  10.328 -qed "Infinitesimal_mult";
  10.329 -
  10.330 -Goal "[| x : Infinitesimal; y : HFinite |] ==> (x * y) : Infinitesimal";
  10.331 -by (auto_tac (claset() addSDs [HFiniteD],
  10.332 -              simpset() addsimps [Infinitesimal_def]));
  10.333 -by (ftac hrabs_less_gt_zero 1);
  10.334 -by (dres_inst_tac [("x","r/t")] bspec 1);
  10.335 -by (blast_tac (claset() addIs [SReal_divide]) 1);
  10.336 -by (asm_full_simp_tac (simpset() addsimps [thm"Ring_and_Field.zero_less_divide_iff"]) 1);
  10.337 -by (case_tac "x=0 | y=0" 1);
  10.338 -by (cut_inst_tac [("u","abs x"),("v","r/t"),("x","abs y")]
  10.339 -    hypreal_mult_less_mono 2);
  10.340 -by (auto_tac (claset(), simpset() addsimps [thm"Ring_and_Field.zero_less_divide_iff"]));
  10.341 -qed "Infinitesimal_HFinite_mult";
  10.342 -
  10.343 -Goal "[| x : Infinitesimal; y : HFinite |] ==> (y * x) : Infinitesimal";
  10.344 -by (auto_tac (claset() addDs [Infinitesimal_HFinite_mult],
  10.345 -              simpset() addsimps [hypreal_mult_commute]));
  10.346 -qed "Infinitesimal_HFinite_mult2";
  10.347 -
  10.348 -(*** rather long proof ***)
  10.349 -Goalw [HInfinite_def,Infinitesimal_def]
  10.350 -     "x: HInfinite ==> inverse x: Infinitesimal";
  10.351 -by Auto_tac;
  10.352 -by (eres_inst_tac [("x","inverse r")] ballE 1);
  10.353 -by (forw_inst_tac [("a1","r"),("z","abs x")]
  10.354 -    (positive_imp_inverse_positive RS order_less_trans) 1);
  10.355 -by (assume_tac 1);
  10.356 -by (dtac ((inverse_inverse_eq RS sym) RS subst) 1);
  10.357 -by (rtac (inverse_less_iff_less RS iffD1) 1);
  10.358 -by (auto_tac (claset(), simpset() addsimps [SReal_inverse]));
  10.359 -qed "HInfinite_inverse_Infinitesimal";
  10.360 -
  10.361 -
  10.362 -
  10.363 -Goalw [HInfinite_def] "[|x: HInfinite;y: HInfinite|] ==> (x*y): HInfinite";
  10.364 -by Auto_tac;
  10.365 -by (eres_inst_tac [("x","1")] ballE 1);
  10.366 -by (eres_inst_tac [("x","r")] ballE 1);
  10.367 -by (case_tac "y=0" 1);
  10.368 -by (cut_inst_tac [("x","1"),("y","abs x"),
  10.369 -                  ("u","r"),("v","abs y")] hypreal_mult_less_mono 2);
  10.370 -by (auto_tac (claset(), simpset() addsimps mult_ac));
  10.371 -qed "HInfinite_mult";
  10.372 -
  10.373 -Goalw [HInfinite_def]
  10.374 -      "[|x: HInfinite; 0 <= y; 0 <= x|] ==> (x + y): HInfinite";
  10.375 -by (auto_tac (claset() addSIs [hypreal_add_zero_less_le_mono],
  10.376 -              simpset() addsimps [hrabs_eqI1, hypreal_add_commute,
  10.377 -                                  hypreal_le_add_order]));
  10.378 -qed "HInfinite_add_ge_zero";
  10.379 -
  10.380 -Goal "[|x: HInfinite; 0 <= y; 0 <= x|] ==> (y + x): HInfinite";
  10.381 -by (auto_tac (claset() addSIs [HInfinite_add_ge_zero],
  10.382 -              simpset() addsimps [hypreal_add_commute]));
  10.383 -qed "HInfinite_add_ge_zero2";
  10.384 -
  10.385 -Goal "[|x: HInfinite; 0 < y; 0 < x|] ==> (x + y): HInfinite";
  10.386 -by (blast_tac (claset() addIs [HInfinite_add_ge_zero,
  10.387 -                    order_less_imp_le]) 1);
  10.388 -qed "HInfinite_add_gt_zero";
  10.389 -
  10.390 -Goalw [HInfinite_def] "(-x: HInfinite) = (x: HInfinite)";
  10.391 -by Auto_tac;
  10.392 -qed "HInfinite_minus_iff";
  10.393 -
  10.394 -Goal "[|x: HInfinite; y <= 0; x <= 0|] ==> (x + y): HInfinite";
  10.395 -by (dtac (HInfinite_minus_iff RS iffD2) 1);
  10.396 -by (rtac (HInfinite_minus_iff RS iffD1) 1);
  10.397 -by (auto_tac (claset() addIs [HInfinite_add_ge_zero],
  10.398 -              simpset()));
  10.399 -qed "HInfinite_add_le_zero";
  10.400 -
  10.401 -Goal "[|x: HInfinite; y < 0; x < 0|] ==> (x + y): HInfinite";
  10.402 -by (blast_tac (claset() addIs [HInfinite_add_le_zero,
  10.403 -                               order_less_imp_le]) 1);
  10.404 -qed "HInfinite_add_lt_zero";
  10.405 -
  10.406 -Goal "[|a: HFinite; b: HFinite; c: HFinite|] \
  10.407 -\     ==> a*a + b*b + c*c : HFinite";
  10.408 -by (auto_tac (claset() addIs [HFinite_mult,HFinite_add], simpset()));
  10.409 -qed "HFinite_sum_squares";
  10.410 -
  10.411 -Goal "x ~: Infinitesimal ==> x ~= 0";
  10.412 -by Auto_tac;
  10.413 -qed "not_Infinitesimal_not_zero";
  10.414 -
  10.415 -Goal "x: HFinite - Infinitesimal ==> x ~= 0";
  10.416 -by Auto_tac;
  10.417 -qed "not_Infinitesimal_not_zero2";
  10.418 -
  10.419 -Goal "(abs x : Infinitesimal) = (x : Infinitesimal)";
  10.420 -by (auto_tac (claset(), simpset() addsimps [hrabs_def]));
  10.421 -qed "Infinitesimal_hrabs_iff";
  10.422 -AddIffs [Infinitesimal_hrabs_iff];
  10.423 -
  10.424 -Goal "x : HFinite - Infinitesimal ==> abs x : HFinite - Infinitesimal";
  10.425 -by (Blast_tac 1);
  10.426 -qed "HFinite_diff_Infinitesimal_hrabs";
  10.427 -
  10.428 -Goalw [Infinitesimal_def]
  10.429 -      "[| e : Infinitesimal; abs x < e |] ==> x : Infinitesimal";
  10.430 -by (auto_tac (claset(), simpset() addsimps [abs_less_iff]));
  10.431 -qed "hrabs_less_Infinitesimal";
  10.432 -
  10.433 -Goal "[| e : Infinitesimal; abs x <= e |] ==> x : Infinitesimal";
  10.434 -by (blast_tac (claset() addDs [order_le_imp_less_or_eq]
  10.435 -                        addIs [hrabs_less_Infinitesimal]) 1);
  10.436 -qed "hrabs_le_Infinitesimal";
  10.437 -
  10.438 -Goalw [Infinitesimal_def]
  10.439 -      "[| e : Infinitesimal; \
  10.440 -\         e' : Infinitesimal; \
  10.441 -\         e' < x ; x < e |] ==> x : Infinitesimal";
  10.442 -by (auto_tac (claset(), simpset() addsimps [abs_less_iff]));
  10.443 -qed "Infinitesimal_interval";
  10.444 -
  10.445 -Goal "[| e : Infinitesimal; e' : Infinitesimal; \
  10.446 -\        e' <= x ; x <= e |] ==> x : Infinitesimal";
  10.447 -by (auto_tac (claset() addIs [Infinitesimal_interval],
  10.448 -    simpset() addsimps [hypreal_le_eq_less_or_eq]));
  10.449 -qed "Infinitesimal_interval2";
  10.450 -
  10.451 -Goalw [Infinitesimal_def]
  10.452 -     "[| x ~: Infinitesimal;  y ~: Infinitesimal|] ==> (x*y) ~:Infinitesimal";
  10.453 -by (Clarify_tac 1);
  10.454 -by (asm_full_simp_tac (simpset() addsimps [linorder_not_less]) 1);
  10.455 -by (eres_inst_tac [("x","r*ra")] ballE 1);
  10.456 -by (fast_tac (claset() addIs [SReal_mult]) 2);
  10.457 -by (auto_tac (claset(), simpset() addsimps [zero_less_mult_iff]));
  10.458 -by (cut_inst_tac [("c","ra"),("d","abs y"),
  10.459 -                  ("a","r"),("b","abs x")] mult_mono 1);
  10.460 -by Auto_tac;
  10.461 -qed "not_Infinitesimal_mult";
  10.462 -
  10.463 -Goal "x*y : Infinitesimal ==> x : Infinitesimal | y : Infinitesimal";
  10.464 -by (rtac ccontr 1);
  10.465 -by (dtac (de_Morgan_disj RS iffD1) 1);
  10.466 -by (fast_tac (claset() addDs [not_Infinitesimal_mult]) 1);
  10.467 -qed "Infinitesimal_mult_disj";
  10.468 -
  10.469 -Goal "x: HFinite-Infinitesimal ==> x ~= 0";
  10.470 -by (Blast_tac 1);
  10.471 -qed "HFinite_Infinitesimal_not_zero";
  10.472 -
  10.473 -Goal "[| x : HFinite - Infinitesimal; \
  10.474 -\                  y : HFinite - Infinitesimal \
  10.475 -\               |] ==> (x*y) : HFinite - Infinitesimal";
  10.476 -by (Clarify_tac 1);
  10.477 -by (blast_tac (claset() addDs [HFinite_mult,not_Infinitesimal_mult]) 1);
  10.478 -qed "HFinite_Infinitesimal_diff_mult";
  10.479 -
  10.480 -Goalw [Infinitesimal_def,HFinite_def]
  10.481 -      "Infinitesimal <= HFinite";
  10.482 -by Auto_tac;
  10.483 -by (res_inst_tac [("x","1")] bexI 1);
  10.484 -by Auto_tac;
  10.485 -qed "Infinitesimal_subset_HFinite";
  10.486 -
  10.487 -Goal "x: Infinitesimal ==> x * hypreal_of_real r : Infinitesimal";
  10.488 -by (etac (HFinite_hypreal_of_real RSN
  10.489 -          (2,Infinitesimal_HFinite_mult)) 1);
  10.490 -qed "Infinitesimal_hypreal_of_real_mult";
  10.491 -
  10.492 -Goal "x: Infinitesimal ==> hypreal_of_real r * x: Infinitesimal";
  10.493 -by (etac (HFinite_hypreal_of_real RSN
  10.494 -          (2,Infinitesimal_HFinite_mult2)) 1);
  10.495 -qed "Infinitesimal_hypreal_of_real_mult2";
  10.496 -
  10.497 -(*----------------------------------------------------------------------
  10.498 -                   Infinitely close relation @=
  10.499 - ----------------------------------------------------------------------*)
  10.500 -
  10.501 -Goalw [Infinitesimal_def,approx_def]
  10.502 -        "(x:Infinitesimal) = (x @= 0)";
  10.503 -by (Simp_tac 1);
  10.504 -qed "mem_infmal_iff";
  10.505 -
  10.506 -Goalw [approx_def]" (x @= y) = (x + -y @= 0)";
  10.507 -by (Simp_tac 1);
  10.508 -qed "approx_minus_iff";
  10.509 -
  10.510 -Goalw [approx_def]" (x @= y) = (-y + x @= 0)";
  10.511 -by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  10.512 -qed "approx_minus_iff2";
  10.513 -
  10.514 -Goalw [approx_def,Infinitesimal_def]  "x @= x";
  10.515 -by (Simp_tac 1);
  10.516 -qed "approx_refl";
  10.517 -AddIffs [approx_refl];
  10.518 -
  10.519 -Goalw [approx_def]  "x @= y ==> y @= x";
  10.520 -by (rtac (hypreal_minus_distrib1 RS subst) 1);
  10.521 -by (etac (Infinitesimal_minus_iff RS iffD2) 1);
  10.522 -qed "approx_sym";
  10.523 -
  10.524 -Goalw [approx_def]  "[| x @= y; y @= z |] ==> x @= z";
  10.525 -by (dtac Infinitesimal_add 1);
  10.526 -by (assume_tac 1);
  10.527 -by Auto_tac;
  10.528 -qed "approx_trans";
  10.529 -
  10.530 -Goal "[| r @= x; s @= x |] ==> r @= s";
  10.531 -by (blast_tac (claset() addIs [approx_sym, approx_trans]) 1);
  10.532 -qed "approx_trans2";
  10.533 -
  10.534 -Goal "[| x @= r; x @= s|] ==> r @= s";
  10.535 -by (blast_tac (claset() addIs [approx_sym, approx_trans]) 1);
  10.536 -qed "approx_trans3";
  10.537 -
  10.538 -Goal "(number_of w @= x) = (x @= number_of w)";
  10.539 -by (blast_tac (claset() addIs [approx_sym]) 1);
  10.540 -qed "number_of_approx_reorient";
  10.541 -
  10.542 -Goal "(0 @= x) = (x @= 0)";
  10.543 -by (blast_tac (claset() addIs [approx_sym]) 1);
  10.544 -qed "zero_approx_reorient";
  10.545 -
  10.546 -Goal "(1 @= x) = (x @= 1)";
  10.547 -by (blast_tac (claset() addIs [approx_sym]) 1);
  10.548 -qed "one_approx_reorient";
  10.549 -
  10.550 -
  10.551 -(*** re-orientation, following HOL/Integ/Bin.ML
  10.552 -     We re-orient x @=y where x is 0, 1 or a numeral, unless y is as well!
  10.553 - ***)
  10.554 -
  10.555 -(*reorientation simprules using ==, for the following simproc*)
  10.556 -val meta_zero_approx_reorient = zero_approx_reorient RS eq_reflection;
  10.557 -val meta_one_approx_reorient = one_approx_reorient RS eq_reflection;
  10.558 -val meta_number_of_approx_reorient = number_of_approx_reorient RS eq_reflection;
  10.559 -
  10.560 -(*reorientation simplification procedure: reorients (polymorphic)
  10.561 -  0 = x, 1 = x, nnn = x provided x isn't 0, 1 or a numeral.*)
  10.562 -fun reorient_proc sg _ (_ $ t $ u) =
  10.563 -  case u of
  10.564 -      Const("0", _) => None
  10.565 -    | Const("1", _) => None
  10.566 -    | Const("Numeral.number_of", _) $ _ => None
  10.567 -    | _ => Some (case t of
  10.568 -                Const("0", _) => meta_zero_approx_reorient
  10.569 -              | Const("1", _) => meta_one_approx_reorient
  10.570 -              | Const("Numeral.number_of", _) $ _ =>
  10.571 -                                 meta_number_of_approx_reorient);
  10.572 -
  10.573 -val approx_reorient_simproc =
  10.574 -  Bin_Simprocs.prep_simproc
  10.575 -    ("reorient_simproc", ["0@=x", "1@=x", "number_of w @= x"], reorient_proc);
  10.576 -
  10.577 -Addsimprocs [approx_reorient_simproc];
  10.578 -
  10.579 -
  10.580 -Goal "(x-y : Infinitesimal) = (x @= y)";
  10.581 -by (auto_tac (claset(),
  10.582 -              simpset() addsimps [hypreal_diff_def, approx_minus_iff RS sym,
  10.583 -                                  mem_infmal_iff]));
  10.584 -qed "Infinitesimal_approx_minus";
  10.585 -
  10.586 -Goalw [monad_def] "(x @= y) = (monad(x)=monad(y))";
  10.587 -by (auto_tac (claset() addDs [approx_sym]
  10.588 -                       addSEs [approx_trans,equalityCE],
  10.589 -              simpset()));
  10.590 -qed "approx_monad_iff";
  10.591 -
  10.592 -Goal "[| x: Infinitesimal; y: Infinitesimal |] ==> x @= y";
  10.593 -by (asm_full_simp_tac (simpset() addsimps [mem_infmal_iff]) 1);
  10.594 -by (blast_tac (claset() addIs [approx_trans, approx_sym]) 1);
  10.595 -qed "Infinitesimal_approx";
  10.596 -
  10.597 -val prem1::prem2::rest =
  10.598 -goalw thy [approx_def] "[| a @= b; c @= d |] ==> a+c @= b+d";
  10.599 -by (stac minus_add_distrib 1);
  10.600 -by (stac hypreal_add_assoc 1);
  10.601 -by (res_inst_tac [("b1","c")] (add_left_commute RS subst) 1);
  10.602 -by (rtac (hypreal_add_assoc RS subst) 1);
  10.603 -by (rtac ([prem1,prem2] MRS Infinitesimal_add) 1);
  10.604 -qed "approx_add";
  10.605 -
  10.606 -Goal "a @= b ==> -a @= -b";
  10.607 -by (rtac ((approx_minus_iff RS iffD2) RS approx_sym) 1);
  10.608 -by (dtac (approx_minus_iff RS iffD1) 1);
  10.609 -by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  10.610 -qed "approx_minus";
  10.611 -
  10.612 -Goal "-a @= -b ==> a @= b";
  10.613 -by (auto_tac (claset() addDs [approx_minus], simpset()));
  10.614 -qed "approx_minus2";
  10.615 -
  10.616 -Goal "(-a @= -b) = (a @= b)";
  10.617 -by (blast_tac (claset() addIs [approx_minus,approx_minus2]) 1);
  10.618 -qed "approx_minus_cancel";
  10.619 -
  10.620 -Addsimps [approx_minus_cancel];
  10.621 -
  10.622 -Goal "[| a @= b; c @= d |] ==> a + -c @= b + -d";
  10.623 -by (blast_tac (claset() addSIs [approx_add,approx_minus]) 1);
  10.624 -qed "approx_add_minus";
  10.625 -
  10.626 -Goalw [approx_def] "[| a @= b; c: HFinite|] ==> a*c @= b*c";
  10.627 -by (asm_full_simp_tac (simpset() addsimps [Infinitesimal_HFinite_mult,
  10.628 -    minus_mult_left,left_distrib RS sym]
  10.629 -    delsimps [minus_mult_left RS sym]) 1);
  10.630 -qed "approx_mult1";
  10.631 -
  10.632 -Goal "[|a @= b; c: HFinite|] ==> c*a @= c*b";
  10.633 -by (asm_simp_tac (simpset() addsimps [approx_mult1,hypreal_mult_commute]) 1);
  10.634 -qed "approx_mult2";
  10.635 -
  10.636 -Goal "[|u @= v*x; x @= y; v: HFinite|] ==> u @= v*y";
  10.637 -by (fast_tac (claset() addIs [approx_mult2,approx_trans]) 1);
  10.638 -qed "approx_mult_subst";
  10.639 -
  10.640 -Goal "[| u @= x*v; x @= y; v: HFinite |] ==> u @= y*v";
  10.641 -by (fast_tac (claset() addIs [approx_mult1,approx_trans]) 1);
  10.642 -qed "approx_mult_subst2";
  10.643 -
  10.644 -Goal "[| u @= x*hypreal_of_real v; x @= y |] ==> u @= y*hypreal_of_real v";
  10.645 -by (auto_tac (claset() addIs [approx_mult_subst2], simpset()));
  10.646 -qed "approx_mult_subst_SReal";
  10.647 -
  10.648 -Goalw [approx_def]  "a = b ==> a @= b";
  10.649 -by (Asm_simp_tac 1);
  10.650 -qed "approx_eq_imp";
  10.651 -
  10.652 -Goal "x: Infinitesimal ==> -x @= x";
  10.653 -by (fast_tac (HOL_cs addIs [Infinitesimal_minus_iff RS iffD2,
  10.654 -    mem_infmal_iff RS iffD1,approx_trans2]) 1);
  10.655 -qed "Infinitesimal_minus_approx";
  10.656 -
  10.657 -Goalw [approx_def]  "(EX y: Infinitesimal. x + -z = y) = (x @= z)";
  10.658 -by (Blast_tac 1);
  10.659 -qed "bex_Infinitesimal_iff";
  10.660 -
  10.661 -Goal "(EX y: Infinitesimal. x = z + y) = (x @= z)";
  10.662 -by (asm_full_simp_tac (simpset() addsimps [bex_Infinitesimal_iff RS sym]) 1);
  10.663 -by (Force_tac 1);
  10.664 -qed "bex_Infinitesimal_iff2";
  10.665 -
  10.666 -Goal "[| y: Infinitesimal; x + y = z |] ==> x @= z";
  10.667 -by (rtac (bex_Infinitesimal_iff RS iffD1) 1);
  10.668 -by (dtac (Infinitesimal_minus_iff RS iffD2) 1);
  10.669 -by (auto_tac (claset(), simpset() addsimps [minus_add_distrib,
  10.670 -    hypreal_add_assoc RS sym]));
  10.671 -qed "Infinitesimal_add_approx";
  10.672 -
  10.673 -Goal "y: Infinitesimal ==> x @= x + y";
  10.674 -by (rtac (bex_Infinitesimal_iff RS iffD1) 1);
  10.675 -by (dtac (Infinitesimal_minus_iff RS iffD2) 1);
  10.676 -by (auto_tac (claset(), simpset() addsimps [minus_add_distrib,
  10.677 -    hypreal_add_assoc RS sym]));
  10.678 -qed "Infinitesimal_add_approx_self";
  10.679 -
  10.680 -Goal "y: Infinitesimal ==> x @= y + x";
  10.681 -by (auto_tac (claset() addDs [Infinitesimal_add_approx_self],
  10.682 -    simpset() addsimps [hypreal_add_commute]));
  10.683 -qed "Infinitesimal_add_approx_self2";
  10.684 -
  10.685 -Goal "y: Infinitesimal ==> x @= x + -y";
  10.686 -by (blast_tac (claset() addSIs [Infinitesimal_add_approx_self,
  10.687 -                                Infinitesimal_minus_iff RS iffD2]) 1);
  10.688 -qed "Infinitesimal_add_minus_approx_self";
  10.689 -
  10.690 -Goal "[| y: Infinitesimal; x+y @= z|] ==> x @= z";
  10.691 -by (dres_inst_tac [("x","x")] (Infinitesimal_add_approx_self RS approx_sym) 1);
  10.692 -by (etac (approx_trans3 RS approx_sym) 1);
  10.693 -by (assume_tac 1);
  10.694 -qed "Infinitesimal_add_cancel";
  10.695 -
  10.696 -Goal "[| y: Infinitesimal; x @= z + y|] ==> x @= z";
  10.697 -by (dres_inst_tac [("x","z")] (Infinitesimal_add_approx_self2  RS approx_sym) 1);
  10.698 -by (etac (approx_trans3 RS approx_sym) 1);
  10.699 -by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  10.700 -by (etac approx_sym 1);
  10.701 -qed "Infinitesimal_add_right_cancel";
  10.702 -
  10.703 -Goal "d + b  @= d + c ==> b @= c";
  10.704 -by (dtac (approx_minus_iff RS iffD1) 1);
  10.705 -by (asm_full_simp_tac (simpset() addsimps
  10.706 -    [minus_add_distrib,approx_minus_iff RS sym]
  10.707 -    @ add_ac) 1);
  10.708 -qed "approx_add_left_cancel";
  10.709 -
  10.710 -Goal "b + d @= c + d ==> b @= c";
  10.711 -by (rtac approx_add_left_cancel 1);
  10.712 -by (asm_full_simp_tac (simpset() addsimps
  10.713 -    [hypreal_add_commute]) 1);
  10.714 -qed "approx_add_right_cancel";
  10.715 -
  10.716 -Goal "b @= c ==> d + b @= d + c";
  10.717 -by (rtac (approx_minus_iff RS iffD2) 1);
  10.718 -by (asm_full_simp_tac (simpset() addsimps
  10.719 -    [minus_add_distrib,approx_minus_iff RS sym]
  10.720 -    @ add_ac) 1);
  10.721 -qed "approx_add_mono1";
  10.722 -
  10.723 -Goal "b @= c ==> b + a @= c + a";
  10.724 -by (asm_simp_tac (simpset() addsimps
  10.725 -    [hypreal_add_commute,approx_add_mono1]) 1);
  10.726 -qed "approx_add_mono2";
  10.727 -
  10.728 -Goal "(a + b @= a + c) = (b @= c)";
  10.729 -by (fast_tac (claset() addEs [approx_add_left_cancel,
  10.730 -    approx_add_mono1]) 1);
  10.731 -qed "approx_add_left_iff";
  10.732 -
  10.733 -Addsimps [approx_add_left_iff];
  10.734 -
  10.735 -Goal "(b + a @= c + a) = (b @= c)";
  10.736 -by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  10.737 -qed "approx_add_right_iff";
  10.738 -
  10.739 -Addsimps [approx_add_right_iff];
  10.740 -
  10.741 -Goal "[| x: HFinite; x @= y |] ==> y: HFinite";
  10.742 -by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1);
  10.743 -by (Step_tac 1);
  10.744 -by (dtac (Infinitesimal_subset_HFinite RS subsetD
  10.745 -          RS (HFinite_minus_iff RS iffD2)) 1);
  10.746 -by (dtac HFinite_add 1);
  10.747 -by (auto_tac (claset(), simpset() addsimps [hypreal_add_assoc]));
  10.748 -qed "approx_HFinite";
  10.749 -
  10.750 -Goal "x @= hypreal_of_real D ==> x: HFinite";
  10.751 -by (rtac (approx_sym RSN (2,approx_HFinite)) 1);
  10.752 -by Auto_tac;
  10.753 -qed "approx_hypreal_of_real_HFinite";
  10.754 -
  10.755 -Goal "[|a @= b; c @= d; b: HFinite; d: HFinite|] ==> a*c @= b*d";
  10.756 -by (rtac approx_trans 1);
  10.757 -by (rtac approx_mult2 2);
  10.758 -by (rtac approx_mult1 1);
  10.759 -by (blast_tac (claset() addIs [approx_HFinite, approx_sym]) 2);
  10.760 -by Auto_tac;
  10.761 -qed "approx_mult_HFinite";
  10.762 -
  10.763 -Goal "[|a @= hypreal_of_real b; c @= hypreal_of_real d |] \
  10.764 -\     ==> a*c @= hypreal_of_real b*hypreal_of_real d";
  10.765 -by (blast_tac (claset() addSIs [approx_mult_HFinite,
  10.766 -            approx_hypreal_of_real_HFinite,HFinite_hypreal_of_real]) 1);
  10.767 -qed "approx_mult_hypreal_of_real";
  10.768 -
  10.769 -Goal "[| a: Reals; a ~= 0; a*x @= 0 |] ==> x @= 0";
  10.770 -by (dtac (SReal_inverse RS (SReal_subset_HFinite RS subsetD)) 1);
  10.771 -by (auto_tac (claset() addDs [approx_mult2],
  10.772 -    simpset() addsimps [hypreal_mult_assoc RS sym]));
  10.773 -qed "approx_SReal_mult_cancel_zero";
  10.774 -
  10.775 -(* REM comments: newly added *)
  10.776 -Goal "[| a: Reals; x @= 0 |] ==> x*a @= 0";
  10.777 -by (auto_tac (claset() addDs [(SReal_subset_HFinite RS subsetD),
  10.778 -              approx_mult1], simpset()));
  10.779 -qed "approx_mult_SReal1";
  10.780 -
  10.781 -Goal "[| a: Reals; x @= 0 |] ==> a*x @= 0";
  10.782 -by (auto_tac (claset() addDs [(SReal_subset_HFinite RS subsetD),
  10.783 -              approx_mult2], simpset()));
  10.784 -qed "approx_mult_SReal2";
  10.785 -
  10.786 -Goal "[|a : Reals; a ~= 0 |] ==> (a*x @= 0) = (x @= 0)";
  10.787 -by (blast_tac (claset() addIs [approx_SReal_mult_cancel_zero,
  10.788 -    approx_mult_SReal2]) 1);
  10.789 -qed "approx_mult_SReal_zero_cancel_iff";
  10.790 -Addsimps [approx_mult_SReal_zero_cancel_iff];
  10.791 -
  10.792 -Goal "[| a: Reals; a ~= 0; a* w @= a*z |] ==> w @= z";
  10.793 -by (dtac (SReal_inverse RS (SReal_subset_HFinite RS subsetD)) 1);
  10.794 -by (auto_tac (claset() addDs [approx_mult2],
  10.795 -    simpset() addsimps [hypreal_mult_assoc RS sym]));
  10.796 -qed "approx_SReal_mult_cancel";
  10.797 -
  10.798 -Goal "[| a: Reals; a ~= 0|] ==> (a* w @= a*z) = (w @= z)";
  10.799 -by (auto_tac (claset() addSIs [approx_mult2,SReal_subset_HFinite RS subsetD]
  10.800 -    addIs [approx_SReal_mult_cancel], simpset()));
  10.801 -qed "approx_SReal_mult_cancel_iff1";
  10.802 -Addsimps [approx_SReal_mult_cancel_iff1];
  10.803 -
  10.804 -Goal "[| z <= f; f @= g; g <= z |] ==> f @= z";
  10.805 -by (asm_full_simp_tac (simpset() addsimps [bex_Infinitesimal_iff2 RS sym]) 1);
  10.806 -by Auto_tac;
  10.807 -by (res_inst_tac [("x","g+y-z")] bexI 1);
  10.808 -by (Simp_tac 1);
  10.809 -by (rtac Infinitesimal_interval2 1);
  10.810 -by (rtac Infinitesimal_zero 2);
  10.811 -by Auto_tac;
  10.812 -qed "approx_le_bound";
  10.813 -
  10.814 -(*-----------------------------------------------------------------
  10.815 -    Zero is the only infinitesimal that is also a real
  10.816 - -----------------------------------------------------------------*)
  10.817 -
  10.818 -Goalw [Infinitesimal_def]
  10.819 -     "[| x: Reals; y: Infinitesimal; 0 < x |] ==> y < x";
  10.820 -by (rtac (abs_ge_self RS order_le_less_trans) 1);
  10.821 -by Auto_tac;
  10.822 -qed "Infinitesimal_less_SReal";
  10.823 -
  10.824 -Goal "y: Infinitesimal ==> ALL r: Reals. 0 < r --> y < r";
  10.825 -by (blast_tac (claset() addIs [Infinitesimal_less_SReal]) 1);
  10.826 -qed "Infinitesimal_less_SReal2";
  10.827 -
  10.828 -Goalw [Infinitesimal_def]
  10.829 -     "[| 0 < y;  y: Reals|] ==> y ~: Infinitesimal";
  10.830 -by (auto_tac (claset(), simpset() addsimps [hrabs_def]));
  10.831 -qed "SReal_not_Infinitesimal";
  10.832 -
  10.833 -Goal "[| y < 0;  y : Reals |] ==> y ~: Infinitesimal";
  10.834 -by (stac (Infinitesimal_minus_iff RS sym) 1);
  10.835 -by (rtac SReal_not_Infinitesimal 1);
  10.836 -by Auto_tac;
  10.837 -qed "SReal_minus_not_Infinitesimal";
  10.838 -
  10.839 -Goal "Reals Int Infinitesimal = {0}";
  10.840 -by Auto_tac;
  10.841 -by (cut_inst_tac [("x","x"),("y","0")] hypreal_linear 1);
  10.842 -by (blast_tac (claset() addDs [SReal_not_Infinitesimal,
  10.843 -                               SReal_minus_not_Infinitesimal]) 1);
  10.844 -qed "SReal_Int_Infinitesimal_zero";
  10.845 -
  10.846 -Goal "[| x: Reals; x: Infinitesimal|] ==> x = 0";
  10.847 -by (cut_facts_tac [SReal_Int_Infinitesimal_zero] 1);
  10.848 -by (Blast_tac 1);
  10.849 -qed "SReal_Infinitesimal_zero";
  10.850 -
  10.851 -Goal "[| x : Reals; x ~= 0 |] ==> x : HFinite - Infinitesimal";
  10.852 -by (auto_tac (claset() addDs [SReal_Infinitesimal_zero,
  10.853 -                              SReal_subset_HFinite RS subsetD],
  10.854 -              simpset()));
  10.855 -qed "SReal_HFinite_diff_Infinitesimal";
  10.856 -
  10.857 -Goal "hypreal_of_real x ~= 0 ==> hypreal_of_real x : HFinite - Infinitesimal";
  10.858 -by (rtac SReal_HFinite_diff_Infinitesimal 1);
  10.859 -by Auto_tac;
  10.860 -qed "hypreal_of_real_HFinite_diff_Infinitesimal";
  10.861 -
  10.862 -Goal "(hypreal_of_real x : Infinitesimal) = (x=0)";
  10.863 -by Auto_tac;
  10.864 -by (rtac ccontr 1);
  10.865 -by (rtac (hypreal_of_real_HFinite_diff_Infinitesimal RS DiffD2) 1);
  10.866 -by Auto_tac;
  10.867 -qed "hypreal_of_real_Infinitesimal_iff_0";
  10.868 -AddIffs [hypreal_of_real_Infinitesimal_iff_0];
  10.869 -
  10.870 -Goal "number_of w ~= (0::hypreal) ==> number_of w ~: Infinitesimal";
  10.871 -by (fast_tac (claset() addDs [SReal_number_of RS SReal_Infinitesimal_zero]) 1);
  10.872 -qed "number_of_not_Infinitesimal";
  10.873 -Addsimps [number_of_not_Infinitesimal];
  10.874 -
  10.875 -(*again: 1 is a special case, but not 0 this time*)
  10.876 -Goal "1 ~: Infinitesimal";
  10.877 -by (stac (hypreal_numeral_1_eq_1 RS sym) 1);
  10.878 -by (rtac number_of_not_Infinitesimal 1);
  10.879 -by (Simp_tac 1);
  10.880 -qed "one_not_Infinitesimal";
  10.881 -Addsimps [one_not_Infinitesimal];
  10.882 -
  10.883 -Goal "[| y: Reals; x @= y; y~= 0 |] ==> x ~= 0";
  10.884 -by (cut_inst_tac [("x","y")] hypreal_trichotomy 1);
  10.885 -by (Asm_full_simp_tac 1);
  10.886 -by (blast_tac (claset() addDs
  10.887 -                [approx_sym RS (mem_infmal_iff RS iffD2),
  10.888 -                 SReal_not_Infinitesimal, SReal_minus_not_Infinitesimal]) 1);
  10.889 -qed "approx_SReal_not_zero";
  10.890 -
  10.891 -Goal "[| x @= y; y : HFinite - Infinitesimal |] \
  10.892 -\     ==> x : HFinite - Infinitesimal";
  10.893 -by (auto_tac (claset() addIs [approx_sym RSN (2,approx_HFinite)],
  10.894 -              simpset() addsimps [mem_infmal_iff]));
  10.895 -by (dtac approx_trans3 1 THEN assume_tac 1);
  10.896 -by (blast_tac (claset() addDs [approx_sym]) 1);
  10.897 -qed "HFinite_diff_Infinitesimal_approx";
  10.898 -
  10.899 -(*The premise y~=0 is essential; otherwise x/y =0 and we lose the
  10.900 -  HFinite premise.*)
  10.901 -Goal "[| y ~= 0;  y: Infinitesimal;  x/y : HFinite |] ==> x : Infinitesimal";
  10.902 -by (dtac Infinitesimal_HFinite_mult2 1);
  10.903 -by (assume_tac 1);
  10.904 -by (asm_full_simp_tac
  10.905 -    (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 1);
  10.906 -qed "Infinitesimal_ratio";
  10.907 -
  10.908 -(*------------------------------------------------------------------
  10.909 -       Standard Part Theorem: Every finite x: R* is infinitely
  10.910 -       close to a unique real number (i.e a member of Reals)
  10.911 - ------------------------------------------------------------------*)
  10.912 -(*------------------------------------------------------------------
  10.913 -         Uniqueness: Two infinitely close reals are equal
  10.914 - ------------------------------------------------------------------*)
  10.915 -
  10.916 -Goal "[|x: Reals; y: Reals|] ==> (x @= y) = (x = y)";
  10.917 -by Auto_tac;
  10.918 -by (rewtac approx_def);
  10.919 -by (dres_inst_tac [("x","y")] SReal_minus 1);
  10.920 -by (dtac SReal_add 1 THEN assume_tac 1);
  10.921 -by (dtac SReal_Infinitesimal_zero 1 THEN assume_tac 1);
  10.922 -by (dtac sym 1);
  10.923 -by (asm_full_simp_tac (simpset() addsimps [hypreal_eq_minus_iff RS sym]) 1);
  10.924 -qed "SReal_approx_iff";
  10.925 -
  10.926 -Goal "(number_of v @= number_of w) = (number_of v = (number_of w :: hypreal))";
  10.927 -by (rtac SReal_approx_iff 1);
  10.928 -by Auto_tac;
  10.929 -qed "number_of_approx_iff";
  10.930 -Addsimps [number_of_approx_iff];
  10.931 -
  10.932 -(*And also for 0 @= #nn and 1 @= #nn, #nn @= 0 and #nn @= 1.*)
  10.933 -Addsimps
  10.934 - (map (simplify (simpset()))
  10.935 -      [inst "v" "bin.Pls" number_of_approx_iff,
  10.936 -       inst "v" "bin.Pls BIT True" number_of_approx_iff,
  10.937 -       inst "w" "bin.Pls" number_of_approx_iff,
  10.938 -       inst "w" "bin.Pls BIT True" number_of_approx_iff]);
  10.939 -
  10.940 -
  10.941 -Goal "~ (0 @= 1)";
  10.942 -by (stac SReal_approx_iff 1);
  10.943 -by Auto_tac;
  10.944 -qed "not_0_approx_1";
  10.945 -Addsimps [not_0_approx_1];
  10.946 -
  10.947 -Goal "~ (1 @= 0)";
  10.948 -by (stac SReal_approx_iff 1);
  10.949 -by Auto_tac;
  10.950 -qed "not_1_approx_0";
  10.951 -Addsimps [not_1_approx_0];
  10.952 -
  10.953 -Goal "(hypreal_of_real k @= hypreal_of_real m) = (k = m)";
  10.954 -by Auto_tac;
  10.955 -by (rtac (inj_hypreal_of_real RS injD) 1);
  10.956 -by (rtac (SReal_approx_iff RS iffD1) 1);
  10.957 -by Auto_tac;
  10.958 -qed "hypreal_of_real_approx_iff";
  10.959 -Addsimps [hypreal_of_real_approx_iff];
  10.960 -
  10.961 -Goal "(hypreal_of_real k @= number_of w) = (k = number_of w)";
  10.962 -by (stac (hypreal_of_real_approx_iff RS sym) 1);
  10.963 -by Auto_tac;
  10.964 -qed "hypreal_of_real_approx_number_of_iff";
  10.965 -Addsimps [hypreal_of_real_approx_number_of_iff];
  10.966 -
  10.967 -(*And also for 0 and 1.*)
  10.968 -Addsimps
  10.969 - (map (simplify (simpset()))
  10.970 -      [inst "w" "bin.Pls" hypreal_of_real_approx_number_of_iff,
  10.971 -       inst "w" "bin.Pls BIT True" hypreal_of_real_approx_number_of_iff]);
  10.972 -
  10.973 -Goal "[| r: Reals; s: Reals; r @= x; s @= x|] ==> r = s";
  10.974 -by (blast_tac (claset() addIs [(SReal_approx_iff RS iffD1),
  10.975 -               approx_trans2]) 1);
  10.976 -qed "approx_unique_real";
  10.977 -
  10.978 -(*------------------------------------------------------------------
  10.979 -       Existence of unique real infinitely close
  10.980 - ------------------------------------------------------------------*)
  10.981 -(* lemma about lubs *)
  10.982 -Goal "!!(x::hypreal). [| isLub R S x; isLub R S y |] ==> x = y";
  10.983 -by (ftac isLub_isUb 1);
  10.984 -by (forw_inst_tac [("x","y")] isLub_isUb 1);
  10.985 -by (blast_tac (claset() addSIs [hypreal_le_anti_sym]
  10.986 -                addSDs [isLub_le_isUb]) 1);
  10.987 -qed "hypreal_isLub_unique";
  10.988 -
  10.989 -Goal "x: HFinite ==> EX u. isUb Reals {s. s: Reals & s < x} u";
  10.990 -by (dtac HFiniteD 1 THEN Step_tac 1);
  10.991 -by (rtac exI 1 THEN rtac isUbI 1 THEN assume_tac 2);
  10.992 -by (auto_tac (claset() addIs [setleI,isUbI], simpset() addsimps [abs_less_iff]));
  10.993 -qed "lemma_st_part_ub";
  10.994 -
  10.995 -Goal "x: HFinite ==> EX y. y: {s. s: Reals & s < x}";
  10.996 -by (dtac HFiniteD 1 THEN Step_tac 1);
  10.997 -by (dtac SReal_minus 1);
  10.998 -by (res_inst_tac [("x","-t")] exI 1);
  10.999 -by (auto_tac (claset(), simpset() addsimps [abs_less_iff]));
 10.1000 -qed "lemma_st_part_nonempty";
 10.1001 -
 10.1002 -Goal "{s. s: Reals & s < x} <= Reals";
 10.1003 -by Auto_tac;
 10.1004 -qed "lemma_st_part_subset";
 10.1005 -
 10.1006 -Goal "x: HFinite ==> EX t. isLub Reals {s. s: Reals & s < x} t";
 10.1007 -by (blast_tac (claset() addSIs [SReal_complete,lemma_st_part_ub,
 10.1008 -    lemma_st_part_nonempty, lemma_st_part_subset]) 1);
 10.1009 -qed "lemma_st_part_lub";
 10.1010 -
 10.1011 -Goal "((t::hypreal) + r <= t) = (r <= 0)";
 10.1012 -by (Step_tac 1);
 10.1013 -by (dres_inst_tac [("x","-t")] hypreal_add_left_le_mono1 1);
 10.1014 -by (dres_inst_tac [("x","t")] hypreal_add_left_le_mono1 2);
 10.1015 -by (auto_tac (claset(), simpset() addsimps [hypreal_add_assoc RS sym]));
 10.1016 -qed "lemma_hypreal_le_left_cancel";
 10.1017 -
 10.1018 -Goal "[| x: HFinite;  isLub Reals {s. s: Reals & s < x} t; \
 10.1019 -\        r: Reals;  0 < r |] ==> x <= t + r";
 10.1020 -by (ftac isLubD1a 1);
 10.1021 -by (rtac ccontr 1 THEN dtac (linorder_not_le RS iffD2) 1);
 10.1022 -by (dres_inst_tac [("x","t")] SReal_add 1 THEN assume_tac 1);
 10.1023 -by (dres_inst_tac [("y","t + r")] (isLubD1 RS setleD) 1);
 10.1024 -by Auto_tac;
 10.1025 -qed "lemma_st_part_le1";
 10.1026 -
 10.1027 -Goalw [setle_def] "!!x::hypreal. [| S *<= x; x < y |] ==> S *<= y";
 10.1028 -by (auto_tac (claset() addSDs [bspec,order_le_less_trans]
 10.1029 -                       addIs [order_less_imp_le],
 10.1030 -              simpset()));
 10.1031 -qed "hypreal_setle_less_trans";
 10.1032 -
 10.1033 -Goalw [isUb_def]
 10.1034 -     "!!x::hypreal. [| isUb R S x; x < y; y: R |] ==> isUb R S y";
 10.1035 -by (blast_tac (claset() addIs [hypreal_setle_less_trans]) 1);
 10.1036 -qed "hypreal_gt_isUb";
 10.1037 -
 10.1038 -Goal "[| x: HFinite; x < y; y: Reals |] \
 10.1039 -\              ==> isUb Reals {s. s: Reals & s < x} y";
 10.1040 -by (auto_tac (claset() addDs [order_less_trans]
 10.1041 -    addIs [order_less_imp_le] addSIs [isUbI,setleI], simpset()));
 10.1042 -qed "lemma_st_part_gt_ub";
 10.1043 -
 10.1044 -Goal "t <= t + -r ==> r <= (0::hypreal)";
 10.1045 -by (dres_inst_tac [("x","-t")] hypreal_add_left_le_mono1 1);
 10.1046 -by (auto_tac (claset(), simpset() addsimps [hypreal_add_assoc RS sym]));
 10.1047 -qed "lemma_minus_le_zero";
 10.1048 -
 10.1049 -Goal "[| x: HFinite; \
 10.1050 -\        isLub Reals {s. s: Reals & s < x} t; \
 10.1051 -\        r: Reals; 0 < r |] \
 10.1052 -\     ==> t + -r <= x";
 10.1053 -by (ftac isLubD1a 1);
 10.1054 -by (rtac ccontr 1 THEN dtac (linorder_not_le RS iffD1) 1);
 10.1055 -by (dtac SReal_minus 1 THEN dres_inst_tac [("x","t")]
 10.1056 -    SReal_add 1 THEN assume_tac 1);
 10.1057 -by (dtac lemma_st_part_gt_ub 1 THEN REPEAT(assume_tac 1));
 10.1058 -by (dtac isLub_le_isUb 1 THEN assume_tac 1);
 10.1059 -by (dtac lemma_minus_le_zero 1);
 10.1060 -by (auto_tac (claset() addDs [order_less_le_trans],  simpset()));
 10.1061 -qed "lemma_st_part_le2";
 10.1062 -
 10.1063 -Goal "((x::hypreal) <= t + r) = (x + -t <= r)";
 10.1064 -by Auto_tac;
 10.1065 -qed "lemma_hypreal_le_swap";
 10.1066 -
 10.1067 -Goal "[| x: HFinite; \
 10.1068 -\        isLub Reals {s. s: Reals & s < x} t; \
 10.1069 -\        r: Reals; 0 < r |] \
 10.1070 -\     ==> x + -t <= r";
 10.1071 -by (blast_tac (claset() addSIs [lemma_hypreal_le_swap RS iffD1,
 10.1072 -                                lemma_st_part_le1]) 1);
 10.1073 -qed "lemma_st_part1a";
 10.1074 -
 10.1075 -Goal "(t + -r <= x) = (-(x + -t) <= (r::hypreal))";
 10.1076 -by Auto_tac;
 10.1077 -qed "lemma_hypreal_le_swap2";
 10.1078 -
 10.1079 -Goal "[| x: HFinite; \
 10.1080 -\        isLub Reals {s. s: Reals & s < x} t; \
 10.1081 -\        r: Reals;  0 < r |] \
 10.1082 -\     ==> -(x + -t) <= r";
 10.1083 -by (blast_tac (claset() addSIs [lemma_hypreal_le_swap2 RS iffD1,
 10.1084 -                                lemma_st_part_le2]) 1);
 10.1085 -qed "lemma_st_part2a";
 10.1086 -
 10.1087 -Goal "(x::hypreal): Reals ==> isUb Reals {s. s: Reals & s < x} x";
 10.1088 -by (auto_tac (claset() addIs [isUbI, setleI,order_less_imp_le], simpset()));
 10.1089 -qed "lemma_SReal_ub";
 10.1090 -
 10.1091 -Goal "(x::hypreal): Reals ==> isLub Reals {s. s: Reals & s < x} x";
 10.1092 -by (auto_tac (claset() addSIs [isLubI2,lemma_SReal_ub,setgeI], simpset()));
 10.1093 -by (ftac isUbD2a 1);
 10.1094 -by (res_inst_tac [("x","x"),("y","y")] linorder_cases 1);
 10.1095 -by (auto_tac (claset() addSIs [order_less_imp_le], simpset()));
 10.1096 -by (EVERY1[dtac SReal_dense, assume_tac, assume_tac, Step_tac]);
 10.1097 -by (dres_inst_tac [("y","r")] isUbD 1);
 10.1098 -by (auto_tac (claset() addDs [order_less_le_trans], simpset()));
 10.1099 -qed "lemma_SReal_lub";
 10.1100 -
 10.1101 -Goal "[| x: HFinite; \
 10.1102 -\        isLub Reals {s. s: Reals & s < x} t; \
 10.1103 -\        r: Reals; 0 < r |] \
 10.1104 -\     ==> x + -t ~= r";
 10.1105 -by Auto_tac;
 10.1106 -by (forward_tac [isLubD1a RS SReal_minus] 1);
 10.1107 -by (dtac SReal_add_cancel 1 THEN assume_tac 1);
 10.1108 -by (dres_inst_tac [("x","x")] lemma_SReal_lub 1);
 10.1109 -by (dtac hypreal_isLub_unique 1 THEN assume_tac 1);
 10.1110 -by Auto_tac;
 10.1111 -qed "lemma_st_part_not_eq1";
 10.1112 -
 10.1113 -Goal "[| x: HFinite; \
 10.1114 -\        isLub Reals {s. s: Reals & s < x} t; \
 10.1115 -\        r: Reals; 0 < r |] \
 10.1116 -\     ==> -(x + -t) ~= r";
 10.1117 -by (auto_tac (claset(), simpset() addsimps [minus_add_distrib]));
 10.1118 -by (ftac isLubD1a 1);
 10.1119 -by (dtac SReal_add_cancel 1 THEN assume_tac 1);
 10.1120 -by (dres_inst_tac [("x","-x")] SReal_minus 1);
 10.1121 -by (Asm_full_simp_tac 1);
 10.1122 -by (dres_inst_tac [("x","x")] lemma_SReal_lub 1);
 10.1123 -by (dtac hypreal_isLub_unique 1 THEN assume_tac 1);
 10.1124 -by Auto_tac;
 10.1125 -qed "lemma_st_part_not_eq2";
 10.1126 -
 10.1127 -Goal "[| x: HFinite; \
 10.1128 -\        isLub Reals {s. s: Reals & s < x} t; \
 10.1129 -\        r: Reals; 0 < r |] \
 10.1130 -\     ==> abs (x + -t) < r";
 10.1131 -by (ftac lemma_st_part1a 1);
 10.1132 -by (ftac lemma_st_part2a 4);
 10.1133 -by Auto_tac;
 10.1134 -by (REPEAT(dtac order_le_imp_less_or_eq 1));
 10.1135 -by (auto_tac (claset() addDs [lemma_st_part_not_eq1, lemma_st_part_not_eq2],
 10.1136 -         simpset() addsimps [abs_less_iff]));
 10.1137 -qed "lemma_st_part_major";
 10.1138 -
 10.1139 -Goal "[| x: HFinite; \
 10.1140 -\        isLub Reals {s. s: Reals & s < x} t |] \
 10.1141 -\     ==> ALL r: Reals. 0 < r --> abs (x + -t) < r";
 10.1142 -by (blast_tac (claset() addSDs [lemma_st_part_major]) 1);
 10.1143 -qed "lemma_st_part_major2";
 10.1144 -
 10.1145 -(*----------------------------------------------
 10.1146 -  Existence of real and Standard Part Theorem
 10.1147 - ----------------------------------------------*)
 10.1148 -Goal "x: HFinite ==> \
 10.1149 -\     EX t: Reals. ALL r: Reals. 0 < r --> abs (x + -t) < r";
 10.1150 -by (ftac lemma_st_part_lub 1 THEN Step_tac 1);
 10.1151 -by (ftac isLubD1a 1);
 10.1152 -by (blast_tac (claset() addDs [lemma_st_part_major2]) 1);
 10.1153 -qed "lemma_st_part_Ex";
 10.1154 -
 10.1155 -Goalw [approx_def,Infinitesimal_def]
 10.1156 -     "x:HFinite ==> EX t: Reals. x @= t";
 10.1157 -by (dtac lemma_st_part_Ex 1);
 10.1158 -by Auto_tac;
 10.1159 -qed "st_part_Ex";
 10.1160 -
 10.1161 -(*--------------------------------
 10.1162 -  Unique real infinitely close
 10.1163 - -------------------------------*)
 10.1164 -Goal "x:HFinite ==> EX! t. t: Reals & x @= t";
 10.1165 -by (dtac st_part_Ex 1 THEN Step_tac 1);
 10.1166 -by (dtac approx_sym 2 THEN dtac approx_sym 2
 10.1167 -    THEN dtac approx_sym 2);
 10.1168 -by (auto_tac (claset() addSIs [approx_unique_real], simpset()));
 10.1169 -qed "st_part_Ex1";
 10.1170 -
 10.1171 -(*------------------------------------------------------------------
 10.1172 -       Finite and Infinite --- more theorems
 10.1173 - ------------------------------------------------------------------*)
 10.1174 -
 10.1175 -Goalw [HFinite_def,HInfinite_def] "HFinite Int HInfinite = {}";
 10.1176 -by (auto_tac (claset() addIs [hypreal_less_irrefl] addDs [order_less_trans],
 10.1177 -              simpset()));
 10.1178 -qed "HFinite_Int_HInfinite_empty";
 10.1179 -Addsimps [HFinite_Int_HInfinite_empty];
 10.1180 -
 10.1181 -Goal "x: HFinite ==> x ~: HInfinite";
 10.1182 -by (EVERY1[Step_tac, dtac IntI, assume_tac]);
 10.1183 -by Auto_tac;
 10.1184 -qed "HFinite_not_HInfinite";
 10.1185 -
 10.1186 -Goalw [HInfinite_def, HFinite_def] "x~: HFinite ==> x: HInfinite";
 10.1187 -by Auto_tac;
 10.1188 -by (dres_inst_tac [("x","r + 1")] bspec 1);
 10.1189 -by (auto_tac (claset(), simpset() addsimps [SReal_add]));
 10.1190 -qed "not_HFinite_HInfinite";
 10.1191 -
 10.1192 -Goal "x : HInfinite | x : HFinite";
 10.1193 -by (blast_tac (claset() addIs [not_HFinite_HInfinite]) 1);
 10.1194 -qed "HInfinite_HFinite_disj";
 10.1195 -
 10.1196 -Goal "(x : HInfinite) = (x ~: HFinite)";
 10.1197 -by (blast_tac (claset() addDs [HFinite_not_HInfinite,
 10.1198 -               not_HFinite_HInfinite]) 1);
 10.1199 -qed "HInfinite_HFinite_iff";
 10.1200 -
 10.1201 -Goal "(x : HFinite) = (x ~: HInfinite)";
 10.1202 -by (simp_tac (simpset() addsimps [HInfinite_HFinite_iff]) 1);
 10.1203 -qed "HFinite_HInfinite_iff";
 10.1204 -
 10.1205 -(*------------------------------------------------------------------
 10.1206 -       Finite, Infinite and Infinitesimal --- more theorems
 10.1207 - ------------------------------------------------------------------*)
 10.1208 -
 10.1209 -Goal "x ~: Infinitesimal ==> x : HInfinite | x : HFinite - Infinitesimal";
 10.1210 -by (fast_tac (claset() addIs [not_HFinite_HInfinite]) 1);
 10.1211 -qed "HInfinite_diff_HFinite_Infinitesimal_disj";
 10.1212 -
 10.1213 -Goal "[| x : HFinite; x ~: Infinitesimal |] ==> inverse x : HFinite";
 10.1214 -by (cut_inst_tac [("x","inverse x")] HInfinite_HFinite_disj 1);
 10.1215 -by (auto_tac (claset() addSDs [HInfinite_inverse_Infinitesimal], simpset()));
 10.1216 -qed "HFinite_inverse";
 10.1217 -
 10.1218 -Goal "x : HFinite - Infinitesimal ==> inverse x : HFinite";
 10.1219 -by (blast_tac (claset() addIs [HFinite_inverse]) 1);
 10.1220 -qed "HFinite_inverse2";
 10.1221 -
 10.1222 -(* stronger statement possible in fact *)
 10.1223 -Goal "x ~: Infinitesimal ==> inverse(x) : HFinite";
 10.1224 -by (dtac HInfinite_diff_HFinite_Infinitesimal_disj 1);
 10.1225 -by (blast_tac (claset() addIs [HFinite_inverse,
 10.1226 -                 HInfinite_inverse_Infinitesimal,
 10.1227 -                 Infinitesimal_subset_HFinite RS subsetD]) 1);
 10.1228 -qed "Infinitesimal_inverse_HFinite";
 10.1229 -
 10.1230 -Goal "x : HFinite - Infinitesimal ==> inverse x : HFinite - Infinitesimal";
 10.1231 -by (auto_tac (claset() addIs [Infinitesimal_inverse_HFinite], simpset()));
 10.1232 -by (dtac Infinitesimal_HFinite_mult2 1);
 10.1233 -by (assume_tac 1);
 10.1234 -by (asm_full_simp_tac
 10.1235 -   (simpset() addsimps [not_Infinitesimal_not_zero, hypreal_mult_inverse]) 1);
 10.1236 -qed "HFinite_not_Infinitesimal_inverse";
 10.1237 -
 10.1238 -Goal "[| x @= y; y :  HFinite - Infinitesimal |] \
 10.1239 -\     ==> inverse x @= inverse y";
 10.1240 -by (ftac HFinite_diff_Infinitesimal_approx 1);
 10.1241 -by (assume_tac 1);
 10.1242 -by (ftac not_Infinitesimal_not_zero2 1);
 10.1243 -by (forw_inst_tac [("x","x")] not_Infinitesimal_not_zero2 1);
 10.1244 -by (REPEAT(dtac HFinite_inverse2 1));
 10.1245 -by (dtac approx_mult2 1 THEN assume_tac 1);
 10.1246 -by Auto_tac;
 10.1247 -by (dres_inst_tac [("c","inverse x")] approx_mult1 1
 10.1248 -    THEN assume_tac 1);
 10.1249 -by (auto_tac (claset() addIs [approx_sym],
 10.1250 -    simpset() addsimps [hypreal_mult_assoc]));
 10.1251 -qed "approx_inverse";
 10.1252 -
 10.1253 -(*Used for NSLIM_inverse, NSLIMSEQ_inverse*)
 10.1254 -bind_thm ("hypreal_of_real_approx_inverse",
 10.1255 -       hypreal_of_real_HFinite_diff_Infinitesimal RSN (2, approx_inverse));
 10.1256 -
 10.1257 -Goal "[| x: HFinite - Infinitesimal; \
 10.1258 -\        h : Infinitesimal |] ==> inverse(x + h) @= inverse x";
 10.1259 -by (auto_tac (claset() addIs [approx_inverse, approx_sym,
 10.1260 -                              Infinitesimal_add_approx_self],
 10.1261 -              simpset()));
 10.1262 -qed "inverse_add_Infinitesimal_approx";
 10.1263 -
 10.1264 -Goal "[| x: HFinite - Infinitesimal; \
 10.1265 -\        h : Infinitesimal |] ==> inverse(h + x) @= inverse x";
 10.1266 -by (rtac (hypreal_add_commute RS subst) 1);
 10.1267 -by (blast_tac (claset() addIs [inverse_add_Infinitesimal_approx]) 1);
 10.1268 -qed "inverse_add_Infinitesimal_approx2";
 10.1269 -
 10.1270 -Goal "[| x : HFinite - Infinitesimal; \
 10.1271 -\        h : Infinitesimal |] ==> inverse(x + h) + -inverse x @= h";
 10.1272 -by (rtac approx_trans2 1);
 10.1273 -by (auto_tac (claset() addIs [inverse_add_Infinitesimal_approx],
 10.1274 -              simpset() addsimps [mem_infmal_iff,
 10.1275 -                                  approx_minus_iff RS sym]));
 10.1276 -qed "inverse_add_Infinitesimal_approx_Infinitesimal";
 10.1277 -
 10.1278 -Goal "(x : Infinitesimal) = (x*x : Infinitesimal)";
 10.1279 -by (auto_tac (claset() addIs [Infinitesimal_mult], simpset()));
 10.1280 -by (rtac ccontr 1 THEN ftac Infinitesimal_inverse_HFinite 1);
 10.1281 -by (ftac not_Infinitesimal_not_zero 1);
 10.1282 -by (auto_tac (claset() addDs [Infinitesimal_HFinite_mult],
 10.1283 -    simpset() addsimps [hypreal_mult_assoc]));
 10.1284 -qed "Infinitesimal_square_iff";
 10.1285 -Addsimps [Infinitesimal_square_iff RS sym];
 10.1286 -
 10.1287 -Goal "(x*x : HFinite) = (x : HFinite)";
 10.1288 -by (auto_tac (claset() addIs [HFinite_mult], simpset()));
 10.1289 -by (auto_tac (claset() addDs [HInfinite_mult],
 10.1290 -    simpset() addsimps [HFinite_HInfinite_iff]));
 10.1291 -qed "HFinite_square_iff";
 10.1292 -Addsimps [HFinite_square_iff];
 10.1293 -
 10.1294 -Goal "(x*x : HInfinite) = (x : HInfinite)";
 10.1295 -by (auto_tac (claset(), simpset() addsimps
 10.1296 -    [HInfinite_HFinite_iff]));
 10.1297 -qed "HInfinite_square_iff";
 10.1298 -Addsimps [HInfinite_square_iff];
 10.1299 -
 10.1300 -Goal "[| a: HFinite-Infinitesimal; a* w @= a*z |] ==> w @= z";
 10.1301 -by (Step_tac 1);
 10.1302 -by (ftac HFinite_inverse 1 THEN assume_tac 1);
 10.1303 -by (dtac not_Infinitesimal_not_zero 1);
 10.1304 -by (auto_tac (claset() addDs [approx_mult2],
 10.1305 -    simpset() addsimps [hypreal_mult_assoc RS sym]));
 10.1306 -qed "approx_HFinite_mult_cancel";
 10.1307 -
 10.1308 -Goal "a: HFinite-Infinitesimal ==> (a * w @= a * z) = (w @= z)";
 10.1309 -by (auto_tac (claset() addIs [approx_mult2,
 10.1310 -    approx_HFinite_mult_cancel], simpset()));
 10.1311 -qed "approx_HFinite_mult_cancel_iff1";
 10.1312 -
 10.1313 -(*------------------------------------------------------------------
 10.1314 -                  more about absolute value (hrabs)
 10.1315 - ------------------------------------------------------------------*)
 10.1316 -
 10.1317 -Goal "abs x @= x | abs x @= -x";
 10.1318 -by (cut_inst_tac [("x","x")] hrabs_disj 1);
 10.1319 -by Auto_tac;
 10.1320 -qed "approx_hrabs_disj";
 10.1321 -
 10.1322 -(*------------------------------------------------------------------
 10.1323 -                  Theorems about monads
 10.1324 - ------------------------------------------------------------------*)
 10.1325 -
 10.1326 -Goal "monad (abs x) <= monad(x) Un monad(-x)";
 10.1327 -by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
 10.1328 -by Auto_tac;
 10.1329 -qed "monad_hrabs_Un_subset";
 10.1330 -
 10.1331 -Goal "e : Infinitesimal ==> monad (x+e) = monad x";
 10.1332 -by (fast_tac (claset() addSIs [Infinitesimal_add_approx_self RS approx_sym,
 10.1333 -    approx_monad_iff RS iffD1]) 1);
 10.1334 -qed "Infinitesimal_monad_eq";
 10.1335 -
 10.1336 -Goalw [monad_def] "(u:monad x) = (-u:monad (-x))";
 10.1337 -by Auto_tac;
 10.1338 -qed "mem_monad_iff";
 10.1339 -
 10.1340 -Goalw [monad_def] "(x:Infinitesimal) = (x:monad 0)";
 10.1341 -by (auto_tac (claset() addIs [approx_sym],
 10.1342 -    simpset() addsimps [mem_infmal_iff]));
 10.1343 -qed "Infinitesimal_monad_zero_iff";
 10.1344 -
 10.1345 -Goal "(x:monad 0) = (-x:monad 0)";
 10.1346 -by (simp_tac (simpset() addsimps [Infinitesimal_monad_zero_iff RS sym]) 1);
 10.1347 -qed "monad_zero_minus_iff";
 10.1348 -
 10.1349 -Goal "(x:monad 0) = (abs x:monad 0)";
 10.1350 -by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
 10.1351 -by (auto_tac (claset(), simpset() addsimps [monad_zero_minus_iff RS sym]));
 10.1352 -qed "monad_zero_hrabs_iff";
 10.1353 -
 10.1354 -Goalw [monad_def] "x:monad x";
 10.1355 -by (Simp_tac 1);
 10.1356 -qed "mem_monad_self";
 10.1357 -Addsimps [mem_monad_self];
 10.1358 -
 10.1359 -(*------------------------------------------------------------------
 10.1360 -         Proof that x @= y ==> abs x @= abs y
 10.1361 - ------------------------------------------------------------------*)
 10.1362 -Goal "x @= y ==> {x,y}<=monad x";
 10.1363 -by (Simp_tac 1);
 10.1364 -by (asm_full_simp_tac (simpset() addsimps
 10.1365 -    [approx_monad_iff]) 1);
 10.1366 -qed "approx_subset_monad";
 10.1367 -
 10.1368 -Goal "x @= y ==> {x,y}<=monad y";
 10.1369 -by (dtac approx_sym 1);
 10.1370 -by (fast_tac (claset() addDs [approx_subset_monad]) 1);
 10.1371 -qed "approx_subset_monad2";
 10.1372 -
 10.1373 -Goalw [monad_def] "u:monad x ==> x @= u";
 10.1374 -by (Fast_tac 1);
 10.1375 -qed "mem_monad_approx";
 10.1376 -
 10.1377 -Goalw [monad_def] "x @= u ==> u:monad x";
 10.1378 -by (Fast_tac 1);
 10.1379 -qed "approx_mem_monad";
 10.1380 -
 10.1381 -Goalw [monad_def] "x @= u ==> x:monad u";
 10.1382 -by (blast_tac (claset() addSIs [approx_sym]) 1);
 10.1383 -qed "approx_mem_monad2";
 10.1384 -
 10.1385 -Goal "[| x @= y;x:monad 0 |] ==> y:monad 0";
 10.1386 -by (dtac mem_monad_approx 1);
 10.1387 -by (fast_tac (claset() addIs [approx_mem_monad,approx_trans]) 1);
 10.1388 -qed "approx_mem_monad_zero";
 10.1389 -
 10.1390 -Goal "[| x @= y; x: Infinitesimal |] ==> abs x @= abs y";
 10.1391 -by (dtac (Infinitesimal_monad_zero_iff RS iffD1) 1);
 10.1392 -by (blast_tac (claset() addIs [approx_mem_monad_zero,
 10.1393 -     monad_zero_hrabs_iff RS iffD1, mem_monad_approx, approx_trans3]) 1);
 10.1394 -qed "Infinitesimal_approx_hrabs";
 10.1395 -
 10.1396 -Goal "[| 0 < x;  x ~:Infinitesimal;  e :Infinitesimal |] ==> e < x";
 10.1397 -by (rtac ccontr 1);
 10.1398 -by (auto_tac (claset()
 10.1399 -               addIs [Infinitesimal_zero RSN (2, Infinitesimal_interval)]
 10.1400 -               addSDs [order_le_imp_less_or_eq],
 10.1401 -              simpset() addsimps [linorder_not_less]));
 10.1402 -qed "less_Infinitesimal_less";
 10.1403 -
 10.1404 -Goal "[| 0 < x;  x ~: Infinitesimal; u: monad x |] ==> 0 < u";
 10.1405 -by (dtac (mem_monad_approx RS approx_sym) 1);
 10.1406 -by (etac (bex_Infinitesimal_iff2 RS iffD2 RS bexE) 1);
 10.1407 -by (dres_inst_tac [("e","-xa")] less_Infinitesimal_less 1);
 10.1408 -by Auto_tac;
 10.1409 -qed "Ball_mem_monad_gt_zero";
 10.1410 -
 10.1411 -Goal "[| x < 0; x ~: Infinitesimal; u: monad x |] ==> u < 0";
 10.1412 -by (dtac (mem_monad_approx RS approx_sym) 1);
 10.1413 -by (etac (bex_Infinitesimal_iff RS iffD2 RS bexE) 1);
 10.1414 -by (cut_inst_tac [("x","-x"),("e","xa")] less_Infinitesimal_less 1);
 10.1415 -by Auto_tac;
 10.1416 -qed "Ball_mem_monad_less_zero";
 10.1417 -
 10.1418 -Goal "[|0 < x; x ~: Infinitesimal; x @= y|] ==> 0 < y";
 10.1419 -by (blast_tac (claset() addDs [Ball_mem_monad_gt_zero,
 10.1420 -                               approx_subset_monad]) 1);
 10.1421 -qed "lemma_approx_gt_zero";
 10.1422 -
 10.1423 -Goal "[|x < 0; x ~: Infinitesimal; x @= y|] ==> y < 0";
 10.1424 -by (blast_tac (claset() addDs [Ball_mem_monad_less_zero,
 10.1425 -    approx_subset_monad]) 1);
 10.1426 -qed "lemma_approx_less_zero";
 10.1427 -
 10.1428 -Goal "[| x @= y; x < 0; x ~: Infinitesimal |] ==> abs x @= abs y";
 10.1429 -by (ftac lemma_approx_less_zero 1);
 10.1430 -by (REPEAT(assume_tac 1));
 10.1431 -by (REPEAT(dtac hrabs_minus_eqI2 1));
 10.1432 -by Auto_tac;
 10.1433 -qed "approx_hrabs1";
 10.1434 -
 10.1435 -Goal "[| x @= y; 0 < x; x ~: Infinitesimal |] ==> abs x @= abs y";
 10.1436 -by (ftac lemma_approx_gt_zero 1);
 10.1437 -by (REPEAT(assume_tac 1));
 10.1438 -by (REPEAT(dtac hrabs_eqI2 1));
 10.1439 -by Auto_tac;
 10.1440 -qed "approx_hrabs2";
 10.1441 -
 10.1442 -Goal "x @= y ==> abs x @= abs y";
 10.1443 -by (res_inst_tac [("Q","x:Infinitesimal")] (excluded_middle RS disjE) 1);
 10.1444 -by (res_inst_tac [("x1","x"),("y1","0")] (hypreal_linear RS disjE) 1);
 10.1445 -by (auto_tac (claset() addIs [approx_hrabs1,approx_hrabs2,
 10.1446 -    Infinitesimal_approx_hrabs], simpset()));
 10.1447 -qed "approx_hrabs";
 10.1448 -
 10.1449 -Goal "abs(x) @= 0 ==> x @= 0";
 10.1450 -by (cut_inst_tac [("x","x")] hrabs_disj 1);
 10.1451 -by (auto_tac (claset() addDs [approx_minus], simpset()));
 10.1452 -qed "approx_hrabs_zero_cancel";
 10.1453 -
 10.1454 -Goal "e: Infinitesimal ==> abs x @= abs(x+e)";
 10.1455 -by (fast_tac (claset() addIs [approx_hrabs,
 10.1456 -       Infinitesimal_add_approx_self]) 1);
 10.1457 -qed "approx_hrabs_add_Infinitesimal";
 10.1458 -
 10.1459 -Goal "e: Infinitesimal ==> abs x @= abs(x + -e)";
 10.1460 -by (fast_tac (claset() addIs [approx_hrabs,
 10.1461 -    Infinitesimal_add_minus_approx_self]) 1);
 10.1462 -qed "approx_hrabs_add_minus_Infinitesimal";
 10.1463 -
 10.1464 -Goal "[| e: Infinitesimal; e': Infinitesimal; \
 10.1465 -\        abs(x+e) = abs(y+e')|] ==> abs x @= abs y";
 10.1466 -by (dres_inst_tac [("x","x")] approx_hrabs_add_Infinitesimal 1);
 10.1467 -by (dres_inst_tac [("x","y")] approx_hrabs_add_Infinitesimal 1);
 10.1468 -by (auto_tac (claset() addIs [approx_trans2], simpset()));
 10.1469 -qed "hrabs_add_Infinitesimal_cancel";
 10.1470 -
 10.1471 -Goal "[| e: Infinitesimal; e': Infinitesimal; \
 10.1472 -\        abs(x + -e) = abs(y + -e')|] ==> abs x @= abs y";
 10.1473 -by (dres_inst_tac [("x","x")] approx_hrabs_add_minus_Infinitesimal 1);
 10.1474 -by (dres_inst_tac [("x","y")] approx_hrabs_add_minus_Infinitesimal 1);
 10.1475 -by (auto_tac (claset() addIs [approx_trans2], simpset()));
 10.1476 -qed "hrabs_add_minus_Infinitesimal_cancel";
 10.1477 -
 10.1478 -(* interesting slightly counterintuitive theorem: necessary
 10.1479 -   for proving that an open interval is an NS open set
 10.1480 -*)
 10.1481 -Goalw [Infinitesimal_def]
 10.1482 -     "[| x < y;  u: Infinitesimal |] \
 10.1483 -\     ==> hypreal_of_real x + u < hypreal_of_real y";
 10.1484 -by (dtac (hypreal_of_real_less_iff RS iffD2) 1);
 10.1485 -by (dtac (hypreal_less_minus_iff RS iffD1) 1 THEN Step_tac 1);
 10.1486 -by (rtac (hypreal_less_minus_iff RS iffD2) 1);
 10.1487 -by (dres_inst_tac [("x","hypreal_of_real y + -hypreal_of_real x")] bspec 1);
 10.1488 -by (auto_tac (claset(),
 10.1489 -              simpset() addsimps [hypreal_add_commute,
 10.1490 -                                  abs_less_iff,
 10.1491 -                                  SReal_add, SReal_minus]));
 10.1492 -qed "Infinitesimal_add_hypreal_of_real_less";
 10.1493 -
 10.1494 -Goal "[| x: Infinitesimal; abs(hypreal_of_real r) < hypreal_of_real y |] \
 10.1495 -\     ==> abs (hypreal_of_real r + x) < hypreal_of_real y";
 10.1496 -by (dres_inst_tac [("x","hypreal_of_real r")]
 10.1497 -    approx_hrabs_add_Infinitesimal 1);
 10.1498 -by (dtac (approx_sym RS (bex_Infinitesimal_iff2 RS iffD2)) 1);
 10.1499 -by (auto_tac (claset() addSIs [Infinitesimal_add_hypreal_of_real_less],
 10.1500 -              simpset() addsimps [hypreal_of_real_hrabs]));
 10.1501 -qed "Infinitesimal_add_hrabs_hypreal_of_real_less";
 10.1502 -
 10.1503 -Goal "[| x: Infinitesimal;  abs(hypreal_of_real r) < hypreal_of_real y |] \
 10.1504 -\     ==> abs (x + hypreal_of_real r) < hypreal_of_real y";
 10.1505 -by (rtac (hypreal_add_commute RS subst) 1);
 10.1506 -by (etac Infinitesimal_add_hrabs_hypreal_of_real_less 1);
 10.1507 -by (assume_tac 1);
 10.1508 -qed "Infinitesimal_add_hrabs_hypreal_of_real_less2";
 10.1509 -
 10.1510 -Goalw [hypreal_le_def]
 10.1511 -     "[| u: Infinitesimal; hypreal_of_real x + u <= hypreal_of_real y |] \
 10.1512 -\     ==> hypreal_of_real x <= hypreal_of_real y";
 10.1513 -by (EVERY1 [rtac notI, rtac contrapos_np, assume_tac]);
 10.1514 -by (res_inst_tac [("c1","-u")] (add_less_cancel_right RS iffD1) 1);
 10.1515 -by (Asm_full_simp_tac 1);
 10.1516 -by (dtac (Infinitesimal_minus_iff RS iffD2) 1);
 10.1517 -by (dtac Infinitesimal_add_hypreal_of_real_less 1);
 10.1518 -by (assume_tac 1);
 10.1519 -by Auto_tac;
 10.1520 -qed "Infinitesimal_add_cancel_hypreal_of_real_le";
 10.1521 -
 10.1522 -Goal "[| u: Infinitesimal;  hypreal_of_real x + u <= hypreal_of_real y |] \
 10.1523 -\     ==> x <= y";
 10.1524 -by (blast_tac (claset() addSIs [hypreal_of_real_le_iff RS iffD1,
 10.1525 -               Infinitesimal_add_cancel_hypreal_of_real_le]) 1);
 10.1526 -qed "Infinitesimal_add_cancel_real_le";
 10.1527 -
 10.1528 -Goal "[| u: Infinitesimal; v: Infinitesimal; \
 10.1529 -\        hypreal_of_real x + u <= hypreal_of_real y + v |] \
 10.1530 -\     ==> hypreal_of_real x <= hypreal_of_real y";
 10.1531 -by (asm_full_simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1);
 10.1532 -by Auto_tac;
 10.1533 -by (dres_inst_tac [("u","v-u")] Infinitesimal_add_hypreal_of_real_less 1);
 10.1534 -by (auto_tac (claset(), simpset() addsimps [Infinitesimal_diff]));
 10.1535 -qed "hypreal_of_real_le_add_Infininitesimal_cancel";
 10.1536 -
 10.1537 -Goal "[| u: Infinitesimal; v: Infinitesimal; \
 10.1538 -\        hypreal_of_real x + u <= hypreal_of_real y + v |] \
 10.1539 -\     ==> x <= y";
 10.1540 -by (blast_tac (claset() addSIs [hypreal_of_real_le_iff RS iffD1,
 10.1541 -                          hypreal_of_real_le_add_Infininitesimal_cancel]) 1);
 10.1542 -qed "hypreal_of_real_le_add_Infininitesimal_cancel2";
 10.1543 -
 10.1544 -Goal "[| hypreal_of_real x < e; e: Infinitesimal |] ==> hypreal_of_real x <= 0";
 10.1545 -by (rtac (linorder_not_less RS iffD1) 1 THEN Safe_tac);
 10.1546 -by (dtac Infinitesimal_interval 1);
 10.1547 -by (dtac (SReal_hypreal_of_real RS SReal_Infinitesimal_zero) 4);
 10.1548 -by Auto_tac;
 10.1549 -qed "hypreal_of_real_less_Infinitesimal_le_zero";
 10.1550 -
 10.1551 -(*used once, in Lim/NSDERIV_inverse*)
 10.1552 -Goal "[| h: Infinitesimal; x ~= 0 |] ==> hypreal_of_real x + h ~= 0";
 10.1553 -by Auto_tac;
 10.1554 -by (subgoal_tac "h = - hypreal_of_real x" 1);
 10.1555 -by Auto_tac;
 10.1556 -qed "Infinitesimal_add_not_zero";
 10.1557 -
 10.1558 -Goal "x*x + y*y : Infinitesimal ==> x*x : Infinitesimal";
 10.1559 -by (rtac Infinitesimal_interval2 1);
 10.1560 -by (rtac zero_le_square 3);
 10.1561 -by (assume_tac 1);
 10.1562 -by (auto_tac (claset(), simpset() addsimps [zero_le_square]));
 10.1563 -qed "Infinitesimal_square_cancel";
 10.1564 -Addsimps [Infinitesimal_square_cancel];
 10.1565 -
 10.1566 -Goal "x*x + y*y : HFinite ==> x*x : HFinite";
 10.1567 -by (rtac HFinite_bounded 1);
 10.1568 -by (assume_tac 1);
 10.1569 -by (auto_tac (claset(), simpset() addsimps [zero_le_square]));
 10.1570 -qed "HFinite_square_cancel";
 10.1571 -Addsimps [HFinite_square_cancel];
 10.1572 -
 10.1573 -Goal "x*x + y*y : Infinitesimal ==> y*y : Infinitesimal";
 10.1574 -by (rtac Infinitesimal_square_cancel 1);
 10.1575 -by (rtac (hypreal_add_commute RS subst) 1);
 10.1576 -by (Simp_tac 1);
 10.1577 -qed "Infinitesimal_square_cancel2";
 10.1578 -Addsimps [Infinitesimal_square_cancel2];
 10.1579 -
 10.1580 -Goal "x*x + y*y : HFinite ==> y*y : HFinite";
 10.1581 -by (rtac HFinite_square_cancel 1);
 10.1582 -by (rtac (hypreal_add_commute RS subst) 1);
 10.1583 -by (Simp_tac 1);
 10.1584 -qed "HFinite_square_cancel2";
 10.1585 -Addsimps [HFinite_square_cancel2];
 10.1586 -
 10.1587 -Goal "x*x + y*y + z*z : Infinitesimal ==> x*x : Infinitesimal";
 10.1588 -by (rtac Infinitesimal_interval2 1);
 10.1589 -by (assume_tac 1);
 10.1590 -by (rtac zero_le_square 2);
 10.1591 -by (Asm_full_simp_tac 1);
 10.1592 -by (cut_inst_tac [("a","y")] (thm"zero_le_square") 1);
 10.1593 -by (cut_inst_tac [("a","z")] (thm"zero_le_square") 1);
 10.1594 -by (asm_simp_tac (simpset() addsimps []) 1); 
 10.1595 -qed "Infinitesimal_sum_square_cancel";
 10.1596 -Addsimps [Infinitesimal_sum_square_cancel];
 10.1597 -
 10.1598 -Goal "x*x + y*y + z*z : HFinite ==> x*x : HFinite";
 10.1599 -by (rtac HFinite_bounded 1);
 10.1600 -by (assume_tac 1);
 10.1601 -by (rtac zero_le_square 2);
 10.1602 -by (cut_inst_tac [("a","y")] (thm"zero_le_square") 1);
 10.1603 -by (cut_inst_tac [("a","z")] (thm"zero_le_square") 1);
 10.1604 -by (asm_simp_tac (simpset() addsimps []) 1); 
 10.1605 -qed "HFinite_sum_square_cancel";
 10.1606 -Addsimps [HFinite_sum_square_cancel];
 10.1607 -
 10.1608 -Goal "y*y + x*x + z*z : Infinitesimal ==> x*x : Infinitesimal";
 10.1609 -by (rtac Infinitesimal_sum_square_cancel 1);
 10.1610 -by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
 10.1611 -qed "Infinitesimal_sum_square_cancel2";
 10.1612 -Addsimps [Infinitesimal_sum_square_cancel2];
 10.1613 -
 10.1614 -Goal "y*y + x*x + z*z : HFinite ==> x*x : HFinite";
 10.1615 -by (rtac HFinite_sum_square_cancel 1);
 10.1616 -by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
 10.1617 -qed "HFinite_sum_square_cancel2";
 10.1618 -Addsimps [HFinite_sum_square_cancel2];
 10.1619 -
 10.1620 -Goal "z*z + y*y + x*x : Infinitesimal ==> x*x : Infinitesimal";
 10.1621 -by (rtac Infinitesimal_sum_square_cancel 1);
 10.1622 -by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
 10.1623 -qed "Infinitesimal_sum_square_cancel3";
 10.1624 -Addsimps [Infinitesimal_sum_square_cancel3];
 10.1625 -
 10.1626 -Goal "z*z + y*y + x*x : HFinite ==> x*x : HFinite";
 10.1627 -by (rtac HFinite_sum_square_cancel 1);
 10.1628 -by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
 10.1629 -qed "HFinite_sum_square_cancel3";
 10.1630 -Addsimps [HFinite_sum_square_cancel3];
 10.1631 -
 10.1632 -Goal "[| y: monad x; 0 < hypreal_of_real e |] \
 10.1633 -\     ==> abs (y + -x) < hypreal_of_real e";
 10.1634 -by (dtac (mem_monad_approx RS approx_sym) 1);
 10.1635 -by (dtac (bex_Infinitesimal_iff RS iffD2) 1);
 10.1636 -by (auto_tac (claset() addSDs [InfinitesimalD], simpset()));
 10.1637 -qed "monad_hrabs_less";
 10.1638 -
 10.1639 -Goal "x: monad (hypreal_of_real  a) ==> x: HFinite";
 10.1640 -by (dtac (mem_monad_approx RS approx_sym) 1);
 10.1641 -by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1);
 10.1642 -by (step_tac (claset() addSDs
 10.1643 -       [Infinitesimal_subset_HFinite RS subsetD]) 1);
 10.1644 -by (etac (SReal_hypreal_of_real RS (SReal_subset_HFinite
 10.1645 -         RS subsetD) RS HFinite_add) 1);
 10.1646 -qed "mem_monad_SReal_HFinite";
 10.1647 -
 10.1648 -(*------------------------------------------------------------------
 10.1649 -              Theorems about standard part
 10.1650 - ------------------------------------------------------------------*)
 10.1651 -
 10.1652 -Goalw [st_def] "x: HFinite ==> st x @= x";
 10.1653 -by (ftac st_part_Ex 1 THEN Step_tac 1);
 10.1654 -by (rtac someI2 1);
 10.1655 -by (auto_tac (claset() addIs [approx_sym], simpset()));
 10.1656 -qed "st_approx_self";
 10.1657 -
 10.1658 -Goalw [st_def] "x: HFinite ==> st x: Reals";
 10.1659 -by (ftac st_part_Ex 1 THEN Step_tac 1);
 10.1660 -by (rtac someI2 1);
 10.1661 -by (auto_tac (claset() addIs [approx_sym], simpset()));
 10.1662 -qed "st_SReal";
 10.1663 -
 10.1664 -Goal "x: HFinite ==> st x: HFinite";
 10.1665 -by (etac (st_SReal RS (SReal_subset_HFinite RS subsetD)) 1);
 10.1666 -qed "st_HFinite";
 10.1667 -
 10.1668 -Goalw [st_def] "x: Reals ==> st x = x";
 10.1669 -by (rtac some_equality 1);
 10.1670 -by (fast_tac (claset() addIs [(SReal_subset_HFinite RS subsetD)]) 1);
 10.1671 -by (blast_tac (claset() addDs [SReal_approx_iff RS iffD1]) 1);
 10.1672 -qed "st_SReal_eq";
 10.1673 -
 10.1674 -(* should be added to simpset *)
 10.1675 -Goal "st (hypreal_of_real x) = hypreal_of_real x";
 10.1676 -by (rtac (SReal_hypreal_of_real RS st_SReal_eq) 1);
 10.1677 -qed "st_hypreal_of_real";
 10.1678 -
 10.1679 -Goal "[| x: HFinite; y: HFinite; st x = st y |] ==> x @= y";
 10.1680 -by (auto_tac (claset() addSDs [st_approx_self]
 10.1681 -              addSEs [approx_trans3], simpset()));
 10.1682 -qed "st_eq_approx";
 10.1683 -
 10.1684 -Goal "[| x: HFinite; y: HFinite; x @= y |] ==> st x = st y";
 10.1685 -by (EVERY1 [ftac st_approx_self ,
 10.1686 -    forw_inst_tac [("x","y")] st_approx_self,
 10.1687 -    dtac st_SReal,dtac st_SReal]);
 10.1688 -by (fast_tac (claset() addEs [approx_trans,
 10.1689 -    approx_trans2,SReal_approx_iff RS iffD1]) 1);
 10.1690 -qed "approx_st_eq";
 10.1691 -
 10.1692 -Goal "[| x: HFinite; y: HFinite|] \
 10.1693 -\                  ==> (x @= y) = (st x = st y)";
 10.1694 -by (blast_tac (claset() addIs [approx_st_eq,
 10.1695 -               st_eq_approx]) 1);
 10.1696 -qed "st_eq_approx_iff";
 10.1697 -
 10.1698 -Goal "[| x: Reals; e: Infinitesimal |] ==> st(x + e) = x";
 10.1699 -by (forward_tac [st_SReal_eq RS subst] 1);
 10.1700 -by (assume_tac 2);
 10.1701 -by (forward_tac [SReal_subset_HFinite RS subsetD] 1);
 10.1702 -by (forward_tac [Infinitesimal_subset_HFinite RS subsetD] 1);
 10.1703 -by (dtac st_SReal_eq 1);
 10.1704 -by (rtac approx_st_eq 1);
 10.1705 -by (auto_tac (claset() addIs  [HFinite_add],
 10.1706 -    simpset() addsimps [Infinitesimal_add_approx_self
 10.1707 -    RS approx_sym]));
 10.1708 -qed "st_Infinitesimal_add_SReal";
 10.1709 -
 10.1710 -Goal "[| x: Reals; e: Infinitesimal |] \
 10.1711 -\     ==> st(e + x) = x";
 10.1712 -by (rtac (hypreal_add_commute RS subst) 1);
 10.1713 -by (blast_tac (claset() addSIs [st_Infinitesimal_add_SReal]) 1);
 10.1714 -qed "st_Infinitesimal_add_SReal2";
 10.1715 -
 10.1716 -Goal "x: HFinite ==> \
 10.1717 -\     EX e: Infinitesimal. x = st(x) + e";
 10.1718 -by (blast_tac (claset() addSDs [(st_approx_self RS
 10.1719 -    approx_sym),bex_Infinitesimal_iff2 RS iffD2]) 1);
 10.1720 -qed "HFinite_st_Infinitesimal_add";
 10.1721 -
 10.1722 -Goal "[| x: HFinite; y: HFinite |] ==> st (x + y) = st(x) + st(y)";
 10.1723 -by (ftac HFinite_st_Infinitesimal_add 1);
 10.1724 -by (forw_inst_tac [("x","y")] HFinite_st_Infinitesimal_add 1);
 10.1725 -by (Step_tac 1);
 10.1726 -by (subgoal_tac "st (x + y) = st ((st x + e) + (st y + ea))" 1);
 10.1727 -by (dtac sym 2 THEN dtac sym 2);
 10.1728 -by (Asm_full_simp_tac 2);
 10.1729 -by (asm_simp_tac (simpset() addsimps add_ac) 1);
 10.1730 -by (REPEAT(dtac st_SReal 1));
 10.1731 -by (dtac SReal_add 1 THEN assume_tac 1);
 10.1732 -by (dtac Infinitesimal_add 1 THEN assume_tac 1);
 10.1733 -by (rtac (hypreal_add_assoc RS subst) 1);
 10.1734 -by (blast_tac (claset() addSIs [st_Infinitesimal_add_SReal2]) 1);
 10.1735 -qed "st_add";
 10.1736 -
 10.1737 -Goal "st (number_of w) = number_of w";
 10.1738 -by (rtac (SReal_number_of RS st_SReal_eq) 1);
 10.1739 -qed "st_number_of";
 10.1740 -Addsimps [st_number_of];
 10.1741 -
 10.1742 -(*the theorem above for the special cases of zero and one*)
 10.1743 -Addsimps
 10.1744 -  (map (simplify (simpset()))
 10.1745 -   [inst "w" "bin.Pls" st_number_of, inst "w" "bin.Pls BIT True" st_number_of]);
 10.1746 -
 10.1747 -Goal "y: HFinite ==> st(-y) = -st(y)";
 10.1748 -by (forward_tac [HFinite_minus_iff RS iffD2] 1);
 10.1749 -by (rtac hypreal_add_minus_eq_minus 1);
 10.1750 -by (dtac (st_add RS sym) 1 THEN assume_tac 1);
 10.1751 -by Auto_tac;
 10.1752 -qed "st_minus";
 10.1753 -
 10.1754 -Goalw [hypreal_diff_def]
 10.1755 -     "[| x: HFinite; y: HFinite |] ==> st (x-y) = st(x) - st(y)";
 10.1756 -by (forw_inst_tac [("y1","y")] (st_minus RS sym) 1);
 10.1757 -by (dres_inst_tac [("x1","y")] (HFinite_minus_iff RS iffD2) 1);
 10.1758 -by (asm_simp_tac (simpset() addsimps [st_add]) 1);
 10.1759 -qed "st_diff";
 10.1760 -
 10.1761 -(* lemma *)
 10.1762 -Goal "[| x: HFinite; y: HFinite; \
 10.1763 -\        e: Infinitesimal;       \
 10.1764 -\        ea : Infinitesimal |]   \
 10.1765 -\      ==> e*y + x*ea + e*ea: Infinitesimal";
 10.1766 -by (forw_inst_tac [("x","e"),("y","y")] Infinitesimal_HFinite_mult 1);
 10.1767 -by (forw_inst_tac [("x","ea"),("y","x")] Infinitesimal_HFinite_mult 2);
 10.1768 -by (dtac Infinitesimal_mult 3);
 10.1769 -by (auto_tac (claset() addIs [Infinitesimal_add],
 10.1770 -              simpset() addsimps add_ac @ mult_ac));
 10.1771 -qed "lemma_st_mult";
 10.1772 -
 10.1773 -Goal "[| x: HFinite; y: HFinite |] \
 10.1774 -\              ==> st (x * y) = st(x) * st(y)";
 10.1775 -by (ftac HFinite_st_Infinitesimal_add 1);
 10.1776 -by (forw_inst_tac [("x","y")] HFinite_st_Infinitesimal_add 1);
 10.1777 -by (Step_tac 1);
 10.1778 -by (subgoal_tac "st (x * y) = st ((st x + e) * (st y + ea))" 1);
 10.1779 -by (dtac sym 2 THEN dtac sym 2);
 10.1780 -by (Asm_full_simp_tac 2);
 10.1781 -by (thin_tac "x = st x + e" 1);
 10.1782 -by (thin_tac "y = st y + ea" 1);
 10.1783 -by (asm_full_simp_tac (simpset() addsimps [left_distrib,right_distrib]) 1);
 10.1784 -by (REPEAT(dtac st_SReal 1));
 10.1785 -by (full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
 10.1786 -by (rtac st_Infinitesimal_add_SReal 1);
 10.1787 -by (blast_tac (claset() addSIs [SReal_mult]) 1);
 10.1788 -by (REPEAT(dtac (SReal_subset_HFinite RS subsetD) 1));
 10.1789 -by (rtac (hypreal_add_assoc RS subst) 1);
 10.1790 -by (blast_tac (claset() addSIs [lemma_st_mult]) 1);
 10.1791 -qed "st_mult";
 10.1792 -
 10.1793 -Goal "x: Infinitesimal ==> st x = 0";
 10.1794 -by (stac (hypreal_numeral_0_eq_0 RS sym) 1);
 10.1795 -by (rtac (st_number_of RS subst) 1);
 10.1796 -by (rtac approx_st_eq 1);
 10.1797 -by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
 10.1798 -              simpset() addsimps [mem_infmal_iff RS sym]));
 10.1799 -qed "st_Infinitesimal";
 10.1800 -
 10.1801 -Goal "st(x) ~= 0 ==> x ~: Infinitesimal";
 10.1802 -by (fast_tac (claset() addIs [st_Infinitesimal]) 1);
 10.1803 -qed "st_not_Infinitesimal";
 10.1804 -
 10.1805 -Goal "[| x: HFinite; st x ~= 0 |] \
 10.1806 -\     ==> st(inverse x) = inverse (st x)";
 10.1807 -by (res_inst_tac [("c1","st x")] (hypreal_mult_left_cancel RS iffD1) 1);
 10.1808 -by (auto_tac (claset(),
 10.1809 -       simpset() addsimps [st_mult RS sym, st_not_Infinitesimal,
 10.1810 -                           HFinite_inverse]));
 10.1811 -by (stac hypreal_mult_inverse 1);
 10.1812 -by Auto_tac;
 10.1813 -qed "st_inverse";
 10.1814 -
 10.1815 -Goal "[| x: HFinite; y: HFinite; st y ~= 0 |] \
 10.1816 -\     ==> st(x/y) = (st x) / (st y)";
 10.1817 -by (auto_tac (claset(),
 10.1818 -      simpset() addsimps [hypreal_divide_def, st_mult, st_not_Infinitesimal,
 10.1819 -                          HFinite_inverse, st_inverse]));
 10.1820 -qed "st_divide";
 10.1821 -Addsimps [st_divide];
 10.1822 -
 10.1823 -Goal "x: HFinite ==> st(st(x)) = st(x)";
 10.1824 -by (blast_tac (claset() addIs [st_HFinite, st_approx_self,
 10.1825 -                               approx_st_eq]) 1);
 10.1826 -qed "st_idempotent";
 10.1827 -Addsimps [st_idempotent];
 10.1828 -
 10.1829 -(*** lemmas ***)
 10.1830 -Goal "[| x: HFinite; y: HFinite; \
 10.1831 -\        u: Infinitesimal; st x < st y \
 10.1832 -\     |] ==> st x + u < st y";
 10.1833 -by (REPEAT(dtac st_SReal 1));
 10.1834 -by (auto_tac (claset() addSIs [Infinitesimal_add_hypreal_of_real_less],
 10.1835 -              simpset() addsimps [SReal_iff]));
 10.1836 -qed "Infinitesimal_add_st_less";
 10.1837 -
 10.1838 -Goalw [hypreal_le_def]
 10.1839 -     "[| x: HFinite; y: HFinite; \
 10.1840 -\        u: Infinitesimal; st x <= st y + u\
 10.1841 -\     |] ==> st x <= st y";
 10.1842 -by (auto_tac (claset() addDs [Infinitesimal_add_st_less],
 10.1843 -              simpset()));
 10.1844 -qed "Infinitesimal_add_st_le_cancel";
 10.1845 -
 10.1846 -Goal "[| x: HFinite; y: HFinite; x <= y |] ==> st(x) <= st(y)";
 10.1847 -by (ftac HFinite_st_Infinitesimal_add 1);
 10.1848 -by (rotate_tac 1 1);
 10.1849 -by (ftac HFinite_st_Infinitesimal_add 1);
 10.1850 -by (Step_tac 1);
 10.1851 -by (rtac Infinitesimal_add_st_le_cancel 1);
 10.1852 -by (res_inst_tac [("x","ea"),("y","e")]
 10.1853 -             Infinitesimal_diff 3);
 10.1854 -by (auto_tac (claset(), simpset() addsimps [hypreal_add_assoc RS sym]));
 10.1855 -qed "st_le";
 10.1856 -
 10.1857 -Goal "[| 0 <= x;  x: HFinite |] ==> 0 <= st x";
 10.1858 -by (stac (hypreal_numeral_0_eq_0 RS sym) 1);
 10.1859 -by (rtac (st_number_of RS subst) 1);
 10.1860 -by (rtac st_le 1);
 10.1861 -by Auto_tac;
 10.1862 -qed "st_zero_le";
 10.1863 -
 10.1864 -Goal "[| x <= 0;  x: HFinite |] ==> st x <= 0";
 10.1865 -by (stac (hypreal_numeral_0_eq_0 RS sym) 1);
 10.1866 -by (rtac (st_number_of RS subst) 1);
 10.1867 -by (rtac st_le 1);
 10.1868 -by Auto_tac;
 10.1869 -qed "st_zero_ge";
 10.1870 -
 10.1871 -Goal "x: HFinite ==> abs(st x) = st(abs x)";
 10.1872 -by (case_tac "0 <= x" 1);
 10.1873 -by (auto_tac (claset() addSDs [order_less_imp_le],
 10.1874 -              simpset() addsimps [linorder_not_le,st_zero_le,hrabs_eqI1, hrabs_minus_eqI1,
 10.1875 -                                  st_zero_ge,st_minus]));
 10.1876 -qed "st_hrabs";
 10.1877 -
 10.1878 -(*--------------------------------------------------------------------
 10.1879 -   Alternative definitions for HFinite using Free ultrafilter
 10.1880 - --------------------------------------------------------------------*)
 10.1881 -
 10.1882 -Goal "[| X: Rep_hypreal x; Y: Rep_hypreal x |] \
 10.1883 -\     ==> {n. X n = Y n} : FreeUltrafilterNat";
 10.1884 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
 10.1885 -by Auto_tac;
 10.1886 -by (Ultra_tac 1);
 10.1887 -qed "FreeUltrafilterNat_Rep_hypreal";
 10.1888 -
 10.1889 -Goal "{n. Yb n < Y n} Int {n. -y = Yb n} <= {n. -y < Y n}";
 10.1890 -by Auto_tac;
 10.1891 -qed "lemma_free1";
 10.1892 -
 10.1893 -Goal "{n. Xa n < Yc n} Int {n. y = Yc n} <= {n. Xa n < y}";
 10.1894 -by Auto_tac;
 10.1895 -qed "lemma_free2";
 10.1896 -
 10.1897 -Goalw [HFinite_def]
 10.1898 -    "x : HFinite ==> EX X: Rep_hypreal x. \
 10.1899 -\    EX u. {n. abs (X n) < u}:  FreeUltrafilterNat";
 10.1900 -by (auto_tac (claset(), simpset() addsimps [abs_less_iff, inst "a" "x" minus_less_iff]));
 10.1901 -by (auto_tac (claset(), simpset() addsimps
 10.1902 -    [hypreal_less_def,SReal_iff,hypreal_minus,
 10.1903 -     hypreal_of_real_def]));
 10.1904 -by (dtac FreeUltrafilterNat_Rep_hypreal 1 THEN assume_tac 1);
 10.1905 -by (rename_tac "Z" 1);
 10.1906 -by (res_inst_tac [("x","Z")] bexI 1 THEN assume_tac 2);
 10.1907 -by (res_inst_tac [("x","y")] exI 1);
 10.1908 -by (Ultra_tac 1);
 10.1909 -qed "HFinite_FreeUltrafilterNat";
 10.1910 -
 10.1911 -Goalw [HFinite_def]
 10.1912 -     "EX X: Rep_hypreal x. \
 10.1913 -\      EX u. {n. abs (X n) < u}: FreeUltrafilterNat\
 10.1914 -\      ==>  x : HFinite";
 10.1915 -by (auto_tac (claset(), simpset() addsimps [abs_less_iff, inst "a" "x" minus_less_iff]));
 10.1916 -by (res_inst_tac [("x","hypreal_of_real u")] bexI 1);
 10.1917 -by (auto_tac (claset() addSIs [exI], 
 10.1918 -   simpset() addsimps
 10.1919 -    [hypreal_less_def,SReal_iff,hypreal_minus, hypreal_of_real_def]));
 10.1920 -by (ALLGOALS Ultra_tac);
 10.1921 -qed "FreeUltrafilterNat_HFinite";
 10.1922 -
 10.1923 -Goal "(x : HFinite) = (EX X: Rep_hypreal x. \
 10.1924 -\          EX u. {n. abs (X n) < u}:  FreeUltrafilterNat)";
 10.1925 -by (blast_tac (claset() addSIs [HFinite_FreeUltrafilterNat,
 10.1926 -               FreeUltrafilterNat_HFinite]) 1);
 10.1927 -qed "HFinite_FreeUltrafilterNat_iff";
 10.1928 -
 10.1929 -(*--------------------------------------------------------------------
 10.1930 -   Alternative definitions for HInfinite using Free ultrafilter
 10.1931 - --------------------------------------------------------------------*)
 10.1932 -Goal "- {n. (u::real) < abs (xa n)} = {n. abs (xa n) <= u}";
 10.1933 -by Auto_tac;
 10.1934 -qed "lemma_Compl_eq";
 10.1935 -
 10.1936 -Goal "- {n. abs (xa n) < (u::real)} = {n. u <= abs (xa n)}";
 10.1937 -by Auto_tac;
 10.1938 -qed "lemma_Compl_eq2";
 10.1939 -
 10.1940 -Goal "{n. abs (xa n) <= (u::real)} Int {n. u <= abs (xa n)} \
 10.1941 -\         = {n. abs(xa n) = u}";
 10.1942 -by Auto_tac;
 10.1943 -qed "lemma_Int_eq1";
 10.1944 -
 10.1945 -Goal "{n. abs (xa n) = u} <= {n. abs (xa n) < u + (1::real)}";
 10.1946 -by Auto_tac;
 10.1947 -qed "lemma_FreeUltrafilterNat_one";
 10.1948 -
 10.1949 -(*-------------------------------------
 10.1950 -  Exclude this type of sets from free
 10.1951 -  ultrafilter for Infinite numbers!
 10.1952 - -------------------------------------*)
 10.1953 -Goal "[| xa: Rep_hypreal x; \
 10.1954 -\                 {n. abs (xa n) = u} : FreeUltrafilterNat \
 10.1955 -\              |] ==> x: HFinite";
 10.1956 -by (rtac FreeUltrafilterNat_HFinite 1);
 10.1957 -by (res_inst_tac [("x","xa")] bexI 1);
 10.1958 -by (res_inst_tac [("x","u + 1")] exI 1);
 10.1959 -by (Ultra_tac 1 THEN assume_tac 1);
 10.1960 -qed "FreeUltrafilterNat_const_Finite";
 10.1961 -
 10.1962 -val [prem] = goal thy "x : HInfinite ==> EX X: Rep_hypreal x. \
 10.1963 -\          ALL u. {n. u < abs (X n)}:  FreeUltrafilterNat";
 10.1964 -by (cut_facts_tac [(prem RS (HInfinite_HFinite_iff RS iffD1))] 1);
 10.1965 -by (cut_inst_tac [("x","x")] Rep_hypreal_nonempty 1);
 10.1966 -by (auto_tac (claset(), simpset() delsimps [Rep_hypreal_nonempty]
 10.1967 -    addsimps [HFinite_FreeUltrafilterNat_iff,Bex_def]));
 10.1968 -by (REPEAT(dtac spec 1));
 10.1969 -by Auto_tac;
 10.1970 -by (dres_inst_tac [("x","u")] spec 1 THEN
 10.1971 -    REPEAT(dtac FreeUltrafilterNat_Compl_mem 1));
 10.1972 -by (dtac FreeUltrafilterNat_Int 1 THEN assume_tac 1);
 10.1973 -by (asm_full_simp_tac (simpset() addsimps [lemma_Compl_eq,
 10.1974 -    lemma_Compl_eq2,lemma_Int_eq1]) 1);
 10.1975 -by (auto_tac (claset() addDs [FreeUltrafilterNat_const_Finite],
 10.1976 -    simpset() addsimps [(prem RS (HInfinite_HFinite_iff RS iffD1))]));
 10.1977 -qed "HInfinite_FreeUltrafilterNat";
 10.1978 -
 10.1979 -(* yet more lemmas! *)
 10.1980 -Goal "{n. abs (Xa n) < u} Int {n. X n = Xa n} \
 10.1981 -\         <= {n. abs (X n) < (u::real)}";
 10.1982 -by Auto_tac;
 10.1983 -qed "lemma_Int_HI";
 10.1984 -
 10.1985 -Goal "{n. u < abs (X n)} Int {n. abs (X n) < (u::real)} = {}";
 10.1986 -by (auto_tac (claset() addIs [order_less_asym], simpset()));
 10.1987 -qed "lemma_Int_HIa";
 10.1988 -
 10.1989 -Goal "EX X: Rep_hypreal x. ALL u. \
 10.1990 -\              {n. u < abs (X n)}: FreeUltrafilterNat\
 10.1991 -\              ==>  x : HInfinite";
 10.1992 -by (rtac (HInfinite_HFinite_iff RS iffD2) 1);
 10.1993 -by (Step_tac 1 THEN dtac HFinite_FreeUltrafilterNat 1);
 10.1994 -by Auto_tac;
 10.1995 -by (dres_inst_tac [("x","u")] spec 1);
 10.1996 -by (dtac FreeUltrafilterNat_Rep_hypreal 1 THEN assume_tac 1);
 10.1997 -by (dres_inst_tac [("Y","{n. X n = Xa n}")] FreeUltrafilterNat_Int 1);
 10.1998 -by (dtac (lemma_Int_HI RSN (2,FreeUltrafilterNat_subset)) 2);
 10.1999 -by (dres_inst_tac [("Y","{n. abs (X n) < u}")] FreeUltrafilterNat_Int 2);
 10.2000 -by (auto_tac (claset(), simpset() addsimps [lemma_Int_HIa,
 10.2001 -              FreeUltrafilterNat_empty]));
 10.2002 -qed "FreeUltrafilterNat_HInfinite";
 10.2003 -
 10.2004 -Goal "(x : HInfinite) = (EX X: Rep_hypreal x. \
 10.2005 -\          ALL u. {n. u < abs (X n)}:  FreeUltrafilterNat)";
 10.2006 -by (blast_tac (claset() addSIs [HInfinite_FreeUltrafilterNat,
 10.2007 -               FreeUltrafilterNat_HInfinite]) 1);
 10.2008 -qed "HInfinite_FreeUltrafilterNat_iff";
 10.2009 -
 10.2010 -(*--------------------------------------------------------------------
 10.2011 -   Alternative definitions for Infinitesimal using Free ultrafilter
 10.2012 - --------------------------------------------------------------------*)
 10.2013 -
 10.2014 -Goal "{n. - u < Yd n} Int {n. xa n = Yd n} <= {n. -u < xa n}";
 10.2015 -by Auto_tac;
 10.2016 -qed "lemma_free4";
 10.2017 -
 10.2018 -Goal "{n. Yb n < u} Int {n. xa n = Yb n} <= {n. xa n < u}";
 10.2019 -by Auto_tac;
 10.2020 -qed "lemma_free5";
 10.2021 -
 10.2022 -Goalw [Infinitesimal_def]
 10.2023 -          "x : Infinitesimal ==> EX X: Rep_hypreal x. \
 10.2024 -\          ALL u. 0 < u --> {n. abs (X n) < u}:  FreeUltrafilterNat";
 10.2025 -by (auto_tac (claset(), simpset() addsimps [abs_less_iff, inst "a" "x" minus_less_iff]));
 10.2026 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
 10.2027 -by (EVERY[Auto_tac, rtac bexI 1, rtac lemma_hyprel_refl 2, Step_tac 1]);
 10.2028 -by (dtac (hypreal_of_real_less_iff RS iffD2) 1);
 10.2029 -by (dres_inst_tac [("x","hypreal_of_real u")] bspec 1);
 10.2030 -by Auto_tac;
 10.2031 -by (auto_tac (claset(),
 10.2032 -              simpset() addsimps [hypreal_less_def, hypreal_minus,
 10.2033 -                                  hypreal_of_real_def]));
 10.2034 -by (Ultra_tac 1);
 10.2035 -qed "Infinitesimal_FreeUltrafilterNat";
 10.2036 -
 10.2037 -Goalw [Infinitesimal_def]
 10.2038 -     "EX X: Rep_hypreal x. \
 10.2039 -\           ALL u. 0 < u --> {n. abs (X n) < u} : FreeUltrafilterNat \
 10.2040 -\     ==> x : Infinitesimal";
 10.2041 -by (auto_tac (claset(),
 10.2042 -              simpset() addsimps [abs_less_iff,abs_interval_iff, inst "a" "x" minus_less_iff]));
 10.2043 -by (auto_tac (claset(),
 10.2044 -              simpset() addsimps [SReal_iff]));
 10.2045 -by (auto_tac (claset() addSIs [exI]
 10.2046 -                               addIs [FreeUltrafilterNat_subset],
 10.2047 -    simpset() addsimps [hypreal_less_def, hypreal_minus,hypreal_of_real_def]));
 10.2048 -qed "FreeUltrafilterNat_Infinitesimal";
 10.2049 -
 10.2050 -Goal "(x : Infinitesimal) = (EX X: Rep_hypreal x. \
 10.2051 -\          ALL u. 0 < u --> {n. abs (X n) < u}:  FreeUltrafilterNat)";
 10.2052 -by (blast_tac (claset() addSIs [Infinitesimal_FreeUltrafilterNat,
 10.2053 -               FreeUltrafilterNat_Infinitesimal]) 1);
 10.2054 -qed "Infinitesimal_FreeUltrafilterNat_iff";
 10.2055 -
 10.2056 -(*------------------------------------------------------------------------
 10.2057 -         Infinitesimals as smaller than 1/n for all n::nat (> 0)
 10.2058 - ------------------------------------------------------------------------*)
 10.2059 -
 10.2060 -Goal "(ALL r. 0 < r --> x < r) = (ALL n. x < inverse(real (Suc n)))";
 10.2061 -by (auto_tac (claset(), simpset() addsimps [real_of_nat_Suc_gt_zero]));
 10.2062 -by (blast_tac (claset() addSDs [reals_Archimedean]
 10.2063 -                        addIs [order_less_trans]) 1);
 10.2064 -qed "lemma_Infinitesimal";
 10.2065 -
 10.2066 -Goal "(ALL r: Reals. 0 < r --> x < r) = \
 10.2067 -\     (ALL n. x < inverse(hypreal_of_nat (Suc n)))";
 10.2068 -by (Step_tac 1);
 10.2069 -by (dres_inst_tac [("x","inverse (hypreal_of_real(real (Suc n)))")]
 10.2070 -    bspec 1);
 10.2071 -by (full_simp_tac (simpset() addsimps [SReal_inverse]) 1);
 10.2072 -by (rtac (real_of_nat_Suc_gt_zero RS positive_imp_inverse_positive RS
 10.2073 -          (hypreal_of_real_less_iff RS iffD2) RSN(2,impE)) 1);
 10.2074 -by (assume_tac 2);
 10.2075 -by (asm_full_simp_tac (simpset() addsimps
 10.2076 -       [real_of_nat_Suc_gt_zero, hypreal_of_nat_def]) 1);
 10.2077 -by (auto_tac (claset() addSDs [reals_Archimedean],
 10.2078 -              simpset() addsimps [SReal_iff]));
 10.2079 -by (dtac (hypreal_of_real_less_iff RS iffD2) 1);
 10.2080 -by (asm_full_simp_tac (simpset() addsimps
 10.2081 -         [real_of_nat_Suc_gt_zero, hypreal_of_nat_def])1);
 10.2082 -by (blast_tac (claset() addIs [order_less_trans]) 1);
 10.2083 -qed "lemma_Infinitesimal2";
 10.2084 -
 10.2085 -Goalw [Infinitesimal_def]
 10.2086 -     "Infinitesimal = {x. ALL n. abs x < inverse (hypreal_of_nat (Suc n))}";
 10.2087 -by (auto_tac (claset(), simpset() addsimps [lemma_Infinitesimal2]));
 10.2088 -qed "Infinitesimal_hypreal_of_nat_iff";
 10.2089 -
 10.2090 -
 10.2091 -(*-------------------------------------------------------------------------
 10.2092 -       Proof that omega is an infinite number and
 10.2093 -       hence that epsilon is an infinitesimal number.
 10.2094 - -------------------------------------------------------------------------*)
 10.2095 -Goal "{n. n < Suc m} = {n. n < m} Un {n. n = m}";
 10.2096 -by (auto_tac (claset(), simpset() addsimps [less_Suc_eq]));
 10.2097 -qed "Suc_Un_eq";
 10.2098 -
 10.2099 -(*-------------------------------------------
 10.2100 -  Prove that any segment is finite and
 10.2101 -  hence cannot belong to FreeUltrafilterNat
 10.2102 - -------------------------------------------*)
 10.2103 -Goal "finite {n::nat. n < m}";
 10.2104 -by (induct_tac "m" 1);
 10.2105 -by (auto_tac (claset(), simpset() addsimps [Suc_Un_eq]));
 10.2106 -qed "finite_nat_segment";
 10.2107 -
 10.2108 -Goal "finite {n::nat. real n < real (m::nat)}";
 10.2109 -by (auto_tac (claset() addIs [finite_nat_segment], simpset()));
 10.2110 -qed "finite_real_of_nat_segment";
 10.2111 -
 10.2112 -Goal "finite {n::nat. real n < u}";
 10.2113 -by (cut_inst_tac [("x","u")] reals_Archimedean2 1);
 10.2114 -by (Step_tac 1);
 10.2115 -by (rtac (finite_real_of_nat_segment RSN (2,finite_subset)) 1);
 10.2116 -by (auto_tac (claset() addDs [order_less_trans], simpset()));
 10.2117 -qed "finite_real_of_nat_less_real";
 10.2118 -
 10.2119 -Goal "{n. f n <= u} = {n. f n < u} Un {n. u = (f n :: real)}";
 10.2120 -by (auto_tac (claset() addDs [order_le_imp_less_or_eq],
 10.2121 -              simpset() addsimps [order_less_imp_le]));
 10.2122 -qed "lemma_real_le_Un_eq";
 10.2123 -
 10.2124 -Goal "finite {n::nat. real n <= u}";
 10.2125 -by (auto_tac (claset(),
 10.2126 -              simpset() addsimps [lemma_real_le_Un_eq,lemma_finite_omega_set,
 10.2127 -                                  finite_real_of_nat_less_real]));
 10.2128 -qed "finite_real_of_nat_le_real";
 10.2129 -
 10.2130 -Goal "finite {n::nat. abs(real n) <= u}";
 10.2131 -by (simp_tac (simpset() addsimps [real_of_nat_Suc_gt_zero,
 10.2132 -                                  finite_real_of_nat_le_real]) 1);
 10.2133 -qed "finite_rabs_real_of_nat_le_real";
 10.2134 -
 10.2135 -Goal "{n. abs(real n) <= u} ~: FreeUltrafilterNat";
 10.2136 -by (blast_tac (claset() addSIs [FreeUltrafilterNat_finite,
 10.2137 -                                finite_rabs_real_of_nat_le_real]) 1);
 10.2138 -qed "rabs_real_of_nat_le_real_FreeUltrafilterNat";
 10.2139 -
 10.2140 -Goal "{n. u < real n} : FreeUltrafilterNat";
 10.2141 -by (rtac ccontr 1 THEN dtac FreeUltrafilterNat_Compl_mem 1);
 10.2142 -by (subgoal_tac "- {n::nat. u < real n} = {n. real n <= u}" 1);
 10.2143 -by (Force_tac 2);
 10.2144 -by (asm_full_simp_tac (simpset() addsimps
 10.2145 -        [finite_real_of_nat_le_real RS FreeUltrafilterNat_finite]) 1);
 10.2146 -qed "FreeUltrafilterNat_nat_gt_real";
 10.2147 -
 10.2148 -(*--------------------------------------------------------------
 10.2149 - The complement of {n. abs(real n) <= u} =
 10.2150 - {n. u < abs (real n)} is in FreeUltrafilterNat
 10.2151 - by property of (free) ultrafilters
 10.2152 - --------------------------------------------------------------*)
 10.2153 -Goal "- {n::nat. real n <= u} = {n. u < real n}";
 10.2154 -by (auto_tac (claset() addSDs [order_le_less_trans],
 10.2155 -              simpset() addsimps [linorder_not_le]));
 10.2156 -val lemma = result();
 10.2157 -
 10.2158 -(*-----------------------------------------------
 10.2159 -       Omega is a member of HInfinite
 10.2160 - -----------------------------------------------*)
 10.2161 -
 10.2162 -Goal "hyprel``{%n::nat. real (Suc n)} : hypreal";
 10.2163 -by Auto_tac;
 10.2164 -qed "hypreal_omega";
 10.2165 -
 10.2166 -Goal "{n. u < real n} : FreeUltrafilterNat";
 10.2167 -by (cut_inst_tac [("u","u")] rabs_real_of_nat_le_real_FreeUltrafilterNat 1);
 10.2168 -by (auto_tac (claset() addDs [FreeUltrafilterNat_Compl_mem],
 10.2169 -              simpset() addsimps [lemma]));
 10.2170 -qed "FreeUltrafilterNat_omega";
 10.2171 -
 10.2172 -Goalw [omega_def] "omega: HInfinite";
 10.2173 -by (auto_tac (claset() addSIs [FreeUltrafilterNat_HInfinite],
 10.2174 -              simpset()));
 10.2175 -by (rtac bexI 1);
 10.2176 -by (rtac lemma_hyprel_refl 2);
 10.2177 -by Auto_tac;
 10.2178 -by (simp_tac (simpset() addsimps [real_of_nat_Suc, diff_less_eq RS sym,
 10.2179 -                                  FreeUltrafilterNat_omega]) 1);
 10.2180 -qed "HInfinite_omega";
 10.2181 -Addsimps [HInfinite_omega];
 10.2182 -
 10.2183 -(*-----------------------------------------------
 10.2184 -       Epsilon is a member of Infinitesimal
 10.2185 - -----------------------------------------------*)
 10.2186 -
 10.2187 -Goal "epsilon : Infinitesimal";
 10.2188 -by (auto_tac (claset() addSIs [HInfinite_inverse_Infinitesimal,HInfinite_omega],
 10.2189 -    simpset() addsimps [hypreal_epsilon_inverse_omega]));
 10.2190 -qed "Infinitesimal_epsilon";
 10.2191 -Addsimps [Infinitesimal_epsilon];
 10.2192 -
 10.2193 -Goal "epsilon : HFinite";
 10.2194 -by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
 10.2195 -    simpset()));
 10.2196 -qed "HFinite_epsilon";
 10.2197 -Addsimps [HFinite_epsilon];
 10.2198 -
 10.2199 -Goal "epsilon @= 0";
 10.2200 -by (simp_tac (simpset() addsimps [mem_infmal_iff RS sym]) 1);
 10.2201 -qed "epsilon_approx_zero";
 10.2202 -Addsimps [epsilon_approx_zero];
 10.2203 -
 10.2204 -(*------------------------------------------------------------------------
 10.2205 -  Needed for proof that we define a hyperreal [<X(n)] @= hypreal_of_real a given
 10.2206 -  that ALL n. |X n - a| < 1/n. Used in proof of NSLIM => LIM.
 10.2207 - -----------------------------------------------------------------------*)
 10.2208 -
 10.2209 -Goal "0 < u  ==> \
 10.2210 -\     (u < inverse (real(Suc n))) = (real(Suc n) < inverse u)";
 10.2211 -by (asm_full_simp_tac (simpset() addsimps [inverse_eq_divide]) 1);
 10.2212 -by (stac pos_less_divide_eq 1);
 10.2213 -by (assume_tac 1);
 10.2214 -by (stac pos_less_divide_eq 1);
 10.2215 -by (simp_tac (simpset() addsimps [real_mult_commute]) 2);
 10.2216 -by (simp_tac (simpset() addsimps [real_of_nat_Suc_gt_zero]) 1);
 10.2217 -qed "real_of_nat_less_inverse_iff";
 10.2218 -
 10.2219 -Goal "0 < u ==> finite {n. u < inverse(real(Suc n))}";
 10.2220 -by (asm_simp_tac (simpset() addsimps [real_of_nat_less_inverse_iff]) 1);
 10.2221 -by (asm_simp_tac (simpset() addsimps [real_of_nat_Suc,
 10.2222 -                         less_diff_eq RS sym]) 1);
 10.2223 -by (rtac finite_real_of_nat_less_real 1);
 10.2224 -qed "finite_inverse_real_of_posnat_gt_real";
 10.2225 -
 10.2226 -Goal "{n. u <= inverse(real(Suc n))} = \
 10.2227 -\    {n. u < inverse(real(Suc n))} Un {n. u = inverse(real(Suc n))}";
 10.2228 -by (auto_tac (claset() addDs [order_le_imp_less_or_eq],
 10.2229 -              simpset() addsimps [order_less_imp_le]));
 10.2230 -qed "lemma_real_le_Un_eq2";
 10.2231 -
 10.2232 -Goal "(inverse (real(Suc n)) <= r) = (1 <= r * real(Suc n))";
 10.2233 -by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1);
 10.2234 -by (simp_tac (simpset() addsimps [inverse_eq_divide]) 1);
 10.2235 -by (stac pos_less_divide_eq 1);
 10.2236 -by (simp_tac (simpset() addsimps [real_of_nat_Suc_gt_zero]) 1);
 10.2237 -by (simp_tac (simpset() addsimps [real_mult_commute]) 1);
 10.2238 -qed "real_of_nat_inverse_le_iff";
 10.2239 -
 10.2240 -Goal "(u = inverse (real(Suc n))) = (real(Suc n) = inverse u)";
 10.2241 -by (auto_tac (claset(),
 10.2242 -      simpset() addsimps [inverse_inverse_eq, real_of_nat_Suc_gt_zero,
 10.2243 -                          real_not_refl2 RS not_sym]));
 10.2244 -qed "real_of_nat_inverse_eq_iff";
 10.2245 -
 10.2246 -Goal "finite {n::nat. u = inverse(real(Suc n))}";
 10.2247 -by (asm_simp_tac (simpset() addsimps [real_of_nat_inverse_eq_iff]) 1);
 10.2248 -by (cut_inst_tac [("x","inverse u - 1")] lemma_finite_omega_set 1);
 10.2249 -by (asm_full_simp_tac (simpset() addsimps [real_of_nat_Suc,
 10.2250 -                         diff_eq_eq RS sym, eq_commute]) 1);
 10.2251 -qed "lemma_finite_omega_set2";
 10.2252 -
 10.2253 -Goal "0 < u ==> finite {n. u <= inverse(real(Suc n))}";
 10.2254 -by (auto_tac (claset(),
 10.2255 -      simpset() addsimps [lemma_real_le_Un_eq2,lemma_finite_omega_set2,
 10.2256 -                          finite_inverse_real_of_posnat_gt_real]));
 10.2257 -qed "finite_inverse_real_of_posnat_ge_real";
 10.2258 -
 10.2259 -Goal "0 < u ==> \
 10.2260 -\      {n. u <= inverse(real(Suc n))} ~: FreeUltrafilterNat";
 10.2261 -by (blast_tac (claset() addSIs [FreeUltrafilterNat_finite,
 10.2262 -                                finite_inverse_real_of_posnat_ge_real]) 1);
 10.2263 -qed "inverse_real_of_posnat_ge_real_FreeUltrafilterNat";
 10.2264 -
 10.2265 -(*--------------------------------------------------------------
 10.2266 -    The complement of  {n. u <= inverse(real(Suc n))} =
 10.2267 -    {n. inverse(real(Suc n)) < u} is in FreeUltrafilterNat
 10.2268 -    by property of (free) ultrafilters
 10.2269 - --------------------------------------------------------------*)
 10.2270 -Goal "- {n. u <= inverse(real(Suc n))} = \
 10.2271 -\     {n. inverse(real(Suc n)) < u}";
 10.2272 -by (auto_tac (claset() addSDs [order_le_less_trans],
 10.2273 -              simpset() addsimps [linorder_not_le]));
 10.2274 -val lemma = result();
 10.2275 -
 10.2276 -Goal "0 < u ==> \
 10.2277 -\     {n. inverse(real(Suc n)) < u} : FreeUltrafilterNat";
 10.2278 -by (cut_inst_tac [("u","u")]  inverse_real_of_posnat_ge_real_FreeUltrafilterNat 1);
 10.2279 -by (auto_tac (claset() addDs [FreeUltrafilterNat_Compl_mem],
 10.2280 -    simpset() addsimps [lemma]));
 10.2281 -qed "FreeUltrafilterNat_inverse_real_of_posnat";
 10.2282 -
 10.2283 -(*--------------------------------------------------------------
 10.2284 -      Example where we get a hyperreal from a real sequence
 10.2285 -      for which a particular property holds. The theorem is
 10.2286 -      used in proofs about equivalence of nonstandard and
 10.2287 -      standard neighbourhoods. Also used for equivalence of
 10.2288 -      nonstandard ans standard definitions of pointwise
 10.2289 -      limit (the theorem was previously in REALTOPOS.thy).
 10.2290 - -------------------------------------------------------------*)
 10.2291 -(*-----------------------------------------------------
 10.2292 -    |X(n) - x| < 1/n ==> [<X n>] - hypreal_of_real x|: Infinitesimal
 10.2293 - -----------------------------------------------------*)
 10.2294 -Goal "ALL n. abs(X n + -x) < inverse(real(Suc n)) \
 10.2295 -\    ==> Abs_hypreal(hyprel``{X}) + -hypreal_of_real x : Infinitesimal";
 10.2296 -by (auto_tac (claset() addSIs [bexI]
 10.2297 -           addDs [FreeUltrafilterNat_inverse_real_of_posnat,
 10.2298 -                  FreeUltrafilterNat_all,FreeUltrafilterNat_Int]
 10.2299 -           addIs [order_less_trans, FreeUltrafilterNat_subset],
 10.2300 -      simpset() addsimps [hypreal_minus,
 10.2301 -                          hypreal_of_real_def,hypreal_add,
 10.2302 -                      Infinitesimal_FreeUltrafilterNat_iff,hypreal_inverse]));
 10.2303 -qed "real_seq_to_hypreal_Infinitesimal";
 10.2304 -
 10.2305 -Goal "ALL n. abs(X n + -x) < inverse(real(Suc n)) \
 10.2306 -\     ==> Abs_hypreal(hyprel``{X}) @= hypreal_of_real x";
 10.2307 -by (stac approx_minus_iff 1);
 10.2308 -by (rtac (mem_infmal_iff RS subst) 1);
 10.2309 -by (etac real_seq_to_hypreal_Infinitesimal 1);
 10.2310 -qed "real_seq_to_hypreal_approx";
 10.2311 -
 10.2312 -Goal "ALL n. abs(x + -X n) < inverse(real(Suc n)) \
 10.2313 -\              ==> Abs_hypreal(hyprel``{X}) @= hypreal_of_real x";
 10.2314 -by (asm_full_simp_tac (simpset() addsimps [abs_minus_add_cancel,
 10.2315 -        real_seq_to_hypreal_approx]) 1);
 10.2316 -qed "real_seq_to_hypreal_approx2";
 10.2317 -
 10.2318 -Goal "ALL n. abs(X n + -Y n) < inverse(real(Suc n)) \
 10.2319 -\     ==> Abs_hypreal(hyprel``{X}) + \
 10.2320 -\         -Abs_hypreal(hyprel``{Y}) : Infinitesimal";
 10.2321 -by (auto_tac (claset() addSIs [bexI]
 10.2322 -                  addDs [FreeUltrafilterNat_inverse_real_of_posnat,
 10.2323 -                         FreeUltrafilterNat_all,FreeUltrafilterNat_Int]
 10.2324 -        addIs [order_less_trans, FreeUltrafilterNat_subset],
 10.2325 -     simpset() addsimps
 10.2326 -            [Infinitesimal_FreeUltrafilterNat_iff,hypreal_minus,hypreal_add,
 10.2327 -             hypreal_inverse]));
 10.2328 -qed "real_seq_to_hypreal_Infinitesimal2";
 10.2329 -
 10.2330 -
 10.2331 -
 10.2332 -
 10.2333 -
 10.2334 -(*MOVE UP*)
 10.2335 -Goal "[| x + y : HInfinite; y: HFinite |] ==> x : HInfinite";
 10.2336 -by (rtac ccontr 1);
 10.2337 -by (dtac (HFinite_HInfinite_iff RS iffD2) 1);
 10.2338 -by (auto_tac (claset() addDs [HFinite_add],simpset() 
 10.2339 -    addsimps [HInfinite_HFinite_iff]));
 10.2340 -qed "HInfinite_HFinite_add_cancel";
 10.2341 -
 10.2342 -Goal "[| x : HInfinite; y : HFinite |] ==> x + y : HInfinite";
 10.2343 -by (res_inst_tac [("y","-y")] HInfinite_HFinite_add_cancel 1);
 10.2344 -by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc,
 10.2345 -    HFinite_minus_iff]));
 10.2346 -qed "HInfinite_HFinite_add";
 10.2347 -
 10.2348 -Goal "[| x : HInfinite; x <= y; 0 <= x |] ==> y : HInfinite";
 10.2349 -by (auto_tac (claset() addIs [HFinite_bounded],simpset() 
 10.2350 -    addsimps [HInfinite_HFinite_iff]));
 10.2351 -qed "HInfinite_ge_HInfinite";
 10.2352 -
 10.2353 -Goal "[| x : Infinitesimal; x ~= 0 |] ==> inverse x : HInfinite";
 10.2354 -by (rtac ccontr 1 THEN dtac (HFinite_HInfinite_iff RS iffD2) 1);
 10.2355 -by (auto_tac (claset() addDs [Infinitesimal_HFinite_mult2],simpset()));
 10.2356 -qed "Infinitesimal_inverse_HInfinite";
 10.2357 -
 10.2358 -Goal "[| x : HInfinite; y : HFinite - Infinitesimal |] \
 10.2359 -\     ==> x * y : HInfinite";
 10.2360 -by (rtac ccontr 1 THEN dtac (HFinite_HInfinite_iff RS iffD2) 1); 
 10.2361 -by (ftac HFinite_Infinitesimal_not_zero 1);
 10.2362 -by (dtac HFinite_not_Infinitesimal_inverse 1);
 10.2363 -by (Step_tac 1 THEN dtac HFinite_mult 1);
 10.2364 -by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc,
 10.2365 -    HFinite_HInfinite_iff]));
 10.2366 -qed "HInfinite_HFinite_not_Infinitesimal_mult";
 10.2367 -
 10.2368 -Goal "[| x : HInfinite; y : HFinite - Infinitesimal |] \
 10.2369 -\     ==> y * x : HInfinite";
 10.2370 -by (auto_tac (claset(),simpset() addsimps [hypreal_mult_commute,
 10.2371 -    HInfinite_HFinite_not_Infinitesimal_mult]));
 10.2372 -qed "HInfinite_HFinite_not_Infinitesimal_mult2";
 10.2373 -
 10.2374 -Goal "[| x : HInfinite; 0 < x; y : Reals |] ==> y < x";
 10.2375 -by (auto_tac (claset() addSDs [bspec],simpset() addsimps 
 10.2376 -    [HInfinite_def,hrabs_def,order_less_imp_le]));
 10.2377 -qed "HInfinite_gt_SReal";
 10.2378 -
 10.2379 -Goal "[| x : HInfinite; 0 < x |] ==> 1 < x";
 10.2380 -by (auto_tac (claset() addIs [HInfinite_gt_SReal],simpset()));
 10.2381 -qed "HInfinite_gt_zero_gt_one";
 10.2382 -
 10.2383 -
 10.2384 -Goal "1 ~: HInfinite";
 10.2385 -by (simp_tac (simpset() addsimps [HInfinite_HFinite_iff]) 1);
 10.2386 -qed "not_HInfinite_one";
 10.2387 -Addsimps [not_HInfinite_one];
    11.1 --- a/src/HOL/Hyperreal/NSA.thy	Wed Jan 28 17:01:01 2004 +0100
    11.2 +++ b/src/HOL/Hyperreal/NSA.thy	Thu Jan 29 16:51:17 2004 +0100
    11.3 @@ -1,46 +1,2346 @@
    11.4  (*  Title       : NSA.thy
    11.5      Author      : Jacques D. Fleuriot
    11.6      Copyright   : 1998  University of Cambridge
    11.7 -    Description : Infinite numbers, Infinitesimals,
    11.8 -                  infinitely close relation etc.
    11.9 -*) 
   11.10 +*)
   11.11  
   11.12 -NSA = HRealAbs + RComplete +
   11.13 +header{*Infinite Numbers, Infinitesimals, Infinitely Close Relation*}
   11.14 +
   11.15 +theory NSA = HRealAbs + RComplete:
   11.16  
   11.17  constdefs
   11.18  
   11.19    Infinitesimal  :: "hypreal set"
   11.20 -   "Infinitesimal == {x. ALL r: Reals. 0 < r --> abs x < r}"
   11.21 +   "Infinitesimal == {x. \<forall>r \<in> Reals. 0 < r --> abs x < r}"
   11.22  
   11.23    HFinite :: "hypreal set"
   11.24 -   "HFinite == {x. EX r: Reals. abs x < r}"
   11.25 +   "HFinite == {x. \<exists>r \<in> Reals. abs x < r}"
   11.26  
   11.27    HInfinite :: "hypreal set"
   11.28 -   "HInfinite == {x. ALL r: Reals. r < abs x}"
   11.29 +   "HInfinite == {x. \<forall>r \<in> Reals. r < abs x}"
   11.30  
   11.31    (* standard part map *)
   11.32 -  st        :: hypreal => hypreal
   11.33 -   "st           == (%x. @r. x : HFinite & r:Reals & r @= x)"
   11.34 +  st        :: "hypreal => hypreal"
   11.35 +   "st           == (%x. @r. x \<in> HFinite & r \<in> Reals & r @= x)"
   11.36  
   11.37 -  monad     :: hypreal => hypreal set
   11.38 +  monad     :: "hypreal => hypreal set"
   11.39     "monad x      == {y. x @= y}"
   11.40  
   11.41 -  galaxy    :: hypreal => hypreal set
   11.42 -   "galaxy x     == {y. (x + -y) : HFinite}"
   11.43 - 
   11.44 +  galaxy    :: "hypreal => hypreal set"
   11.45 +   "galaxy x     == {y. (x + -y) \<in> HFinite}"
   11.46 +
   11.47    (* infinitely close *)
   11.48    approx :: "[hypreal, hypreal] => bool"    (infixl "@=" 50)
   11.49 -   "x @= y       == (x + -y) : Infinitesimal"     
   11.50 +   "x @= y       == (x + -y) \<in> Infinitesimal"
   11.51 +
   11.52 +
   11.53 +defs
   11.54 +
   11.55 +   (*standard real numbers as a subset of the hyperreals*)
   11.56 +   SReal_def:      "Reals == {x. \<exists>r. x = hypreal_of_real r}"
   11.57 +
   11.58 +syntax (xsymbols)
   11.59 +    approx :: "[hypreal, hypreal] => bool"    (infixl "\<approx>" 50)
   11.60 +
   11.61 +
   11.62 +
   11.63 +(*--------------------------------------------------------------------
   11.64 +     Closure laws for members of (embedded) set standard real Reals
   11.65 + --------------------------------------------------------------------*)
   11.66 +
   11.67 +lemma SReal_add: "[| (x::hypreal) \<in> Reals; y \<in> Reals |] ==> x + y \<in> Reals"
   11.68 +apply (auto simp add: SReal_def)
   11.69 +apply (rule_tac x = "r + ra" in exI, simp)
   11.70 +done
   11.71 +
   11.72 +lemma SReal_mult: "[| (x::hypreal) \<in> Reals; y \<in> Reals |] ==> x * y \<in> Reals"
   11.73 +apply (simp add: SReal_def, safe)
   11.74 +apply (rule_tac x = "r * ra" in exI)
   11.75 +apply (simp (no_asm) add: hypreal_of_real_mult)
   11.76 +done
   11.77 +
   11.78 +lemma SReal_inverse: "(x::hypreal) \<in> Reals ==> inverse x \<in> Reals"
   11.79 +apply (simp add: SReal_def)
   11.80 +apply (blast intro: hypreal_of_real_inverse [symmetric])
   11.81 +done
   11.82 +
   11.83 +lemma SReal_divide: "[| (x::hypreal) \<in> Reals;  y \<in> Reals |] ==> x/y \<in> Reals"
   11.84 +apply (simp (no_asm_simp) add: SReal_mult SReal_inverse hypreal_divide_def)
   11.85 +done
   11.86 +
   11.87 +lemma SReal_minus: "(x::hypreal) \<in> Reals ==> -x \<in> Reals"
   11.88 +apply (simp add: SReal_def)
   11.89 +apply (blast intro: hypreal_of_real_minus [symmetric])
   11.90 +done
   11.91 +
   11.92 +lemma SReal_minus_iff: "(-x \<in> Reals) = ((x::hypreal) \<in> Reals)"
   11.93 +apply auto
   11.94 +apply (erule_tac [2] SReal_minus)
   11.95 +apply (drule SReal_minus, auto)
   11.96 +done
   11.97 +declare SReal_minus_iff [simp]
   11.98 +
   11.99 +lemma SReal_add_cancel: "[| (x::hypreal) + y \<in> Reals; y \<in> Reals |] ==> x \<in> Reals"
  11.100 +apply (drule_tac x = y in SReal_minus)
  11.101 +apply (drule SReal_add, assumption, auto)
  11.102 +done
  11.103 +
  11.104 +lemma SReal_hrabs: "(x::hypreal) \<in> Reals ==> abs x \<in> Reals"
  11.105 +apply (simp add: SReal_def)
  11.106 +apply (auto simp add: hypreal_of_real_hrabs)
  11.107 +done
  11.108 +
  11.109 +lemma SReal_hypreal_of_real: "hypreal_of_real x \<in> Reals"
  11.110 +by (simp add: SReal_def)
  11.111 +declare SReal_hypreal_of_real [simp]
  11.112 +
  11.113 +lemma SReal_number_of: "(number_of w ::hypreal) \<in> Reals"
  11.114 +apply (unfold hypreal_number_of_def)
  11.115 +apply (rule SReal_hypreal_of_real)
  11.116 +done
  11.117 +declare SReal_number_of [simp]
  11.118 +
  11.119 +(** As always with numerals, 0 and 1 are special cases **)
  11.120 +
  11.121 +lemma Reals_0: "(0::hypreal) \<in> Reals"
  11.122 +apply (subst hypreal_numeral_0_eq_0 [symmetric])
  11.123 +apply (rule SReal_number_of)
  11.124 +done
  11.125 +declare Reals_0 [simp]
  11.126 +
  11.127 +lemma Reals_1: "(1::hypreal) \<in> Reals"
  11.128 +apply (subst hypreal_numeral_1_eq_1 [symmetric])
  11.129 +apply (rule SReal_number_of)
  11.130 +done
  11.131 +declare Reals_1 [simp]
  11.132 +
  11.133 +lemma SReal_divide_number_of: "r \<in> Reals ==> r/(number_of w::hypreal) \<in> Reals"
  11.134 +apply (unfold hypreal_divide_def)
  11.135 +apply (blast intro!: SReal_number_of SReal_mult SReal_inverse)
  11.136 +done
  11.137 +
  11.138 +(* Infinitesimal epsilon not in Reals *)
  11.139 +
  11.140 +lemma SReal_epsilon_not_mem: "epsilon \<notin> Reals"
  11.141 +apply (simp add: SReal_def)
  11.142 +apply (auto simp add: hypreal_of_real_not_eq_epsilon [THEN not_sym])
  11.143 +done
  11.144 +
  11.145 +lemma SReal_omega_not_mem: "omega \<notin> Reals"
  11.146 +apply (simp add: SReal_def)
  11.147 +apply (auto simp add: hypreal_of_real_not_eq_omega [THEN not_sym])
  11.148 +done
  11.149 +
  11.150 +lemma SReal_UNIV_real: "{x. hypreal_of_real x \<in> Reals} = (UNIV::real set)"
  11.151 +by (simp add: SReal_def)
  11.152 +
  11.153 +lemma SReal_iff: "(x \<in> Reals) = (\<exists>y. x = hypreal_of_real y)"
  11.154 +by (simp add: SReal_def)
  11.155 +
  11.156 +lemma hypreal_of_real_image: "hypreal_of_real `(UNIV::real set) = Reals"
  11.157 +by (auto simp add: SReal_def)
  11.158 +
  11.159 +lemma inv_hypreal_of_real_image: "inv hypreal_of_real ` Reals = UNIV"
  11.160 +apply (auto simp add: SReal_def)
  11.161 +apply (rule inj_hypreal_of_real [THEN inv_f_f, THEN subst], blast)
  11.162 +done
  11.163 +
  11.164 +lemma SReal_hypreal_of_real_image:
  11.165 +      "[| \<exists>x. x: P; P <= Reals |] ==> \<exists>Q. P = hypreal_of_real ` Q"
  11.166 +apply (simp add: SReal_def, blast)
  11.167 +done
  11.168 +
  11.169 +lemma SReal_dense: "[| (x::hypreal) \<in> Reals; y \<in> Reals;  x<y |] ==> \<exists>r \<in> Reals. x<r & r<y"
  11.170 +apply (auto simp add: SReal_iff)
  11.171 +apply (drule real_dense, safe)
  11.172 +apply (rule_tac x = "hypreal_of_real r" in bexI, auto)
  11.173 +done
  11.174 +
  11.175 +(*------------------------------------------------------------------
  11.176 +                   Completeness of Reals
  11.177 + ------------------------------------------------------------------*)
  11.178 +lemma SReal_sup_lemma: "P <= Reals ==> ((\<exists>x \<in> P. y < x) =
  11.179 +      (\<exists>X. hypreal_of_real X \<in> P & y < hypreal_of_real X))"
  11.180 +by (blast dest!: SReal_iff [THEN iffD1])
  11.181 +
  11.182 +lemma SReal_sup_lemma2:
  11.183 +     "[| P <= Reals; \<exists>x. x \<in> P; \<exists>y \<in> Reals. \<forall>x \<in> P. x < y |]
  11.184 +      ==> (\<exists>X. X \<in> {w. hypreal_of_real w \<in> P}) &
  11.185 +          (\<exists>Y. \<forall>X \<in> {w. hypreal_of_real w \<in> P}. X < Y)"
  11.186 +apply (rule conjI)
  11.187 +apply (fast dest!: SReal_iff [THEN iffD1])
  11.188 +apply (auto, frule subsetD, assumption)
  11.189 +apply (drule SReal_iff [THEN iffD1])
  11.190 +apply (auto, rule_tac x = ya in exI, auto)
  11.191 +done
  11.192 +
  11.193 +(*------------------------------------------------------
  11.194 +    lifting of ub and property of lub
  11.195 + -------------------------------------------------------*)
  11.196 +lemma hypreal_of_real_isUb_iff:
  11.197 +      "(isUb (Reals) (hypreal_of_real ` Q) (hypreal_of_real Y)) =
  11.198 +       (isUb (UNIV :: real set) Q Y)"
  11.199 +apply (simp add: isUb_def setle_def)
  11.200 +done
  11.201 +
  11.202 +lemma hypreal_of_real_isLub1:
  11.203 +     "isLub Reals (hypreal_of_real ` Q) (hypreal_of_real Y)
  11.204 +      ==> isLub (UNIV :: real set) Q Y"
  11.205 +apply (simp add: isLub_def leastP_def)
  11.206 +apply (auto intro: hypreal_of_real_isUb_iff [THEN iffD2]
  11.207 +            simp add: hypreal_of_real_isUb_iff setge_def)
  11.208 +done
  11.209 +
  11.210 +lemma hypreal_of_real_isLub2:
  11.211 +      "isLub (UNIV :: real set) Q Y
  11.212 +       ==> isLub Reals (hypreal_of_real ` Q) (hypreal_of_real Y)"
  11.213 +apply (simp add: isLub_def leastP_def)
  11.214 +apply (auto simp add: hypreal_of_real_isUb_iff setge_def)
  11.215 +apply (frule_tac x2 = x in isUbD2a [THEN SReal_iff [THEN iffD1], THEN exE])
  11.216 + prefer 2 apply assumption
  11.217 +apply (drule_tac x = xa in spec)
  11.218 +apply (auto simp add: hypreal_of_real_isUb_iff)
  11.219 +done
  11.220 +
  11.221 +lemma hypreal_of_real_isLub_iff: "(isLub Reals (hypreal_of_real ` Q) (hypreal_of_real Y)) =
  11.222 +      (isLub (UNIV :: real set) Q Y)"
  11.223 +apply (blast intro: hypreal_of_real_isLub1 hypreal_of_real_isLub2)
  11.224 +done
  11.225 +
  11.226 +(* lemmas *)
  11.227 +lemma lemma_isUb_hypreal_of_real:
  11.228 +     "isUb Reals P Y ==> \<exists>Yo. isUb Reals P (hypreal_of_real Yo)"
  11.229 +by (auto simp add: SReal_iff isUb_def)
  11.230 +
  11.231 +lemma lemma_isLub_hypreal_of_real:
  11.232 +     "isLub Reals P Y ==> \<exists>Yo. isLub Reals P (hypreal_of_real Yo)"
  11.233 +by (auto simp add: isLub_def leastP_def isUb_def SReal_iff)
  11.234 +
  11.235 +lemma lemma_isLub_hypreal_of_real2:
  11.236 +     "\<exists>Yo. isLub Reals P (hypreal_of_real Yo) ==> \<exists>Y. isLub Reals P Y"
  11.237 +by (auto simp add: isLub_def leastP_def isUb_def)
  11.238 +
  11.239 +lemma SReal_complete: "[| P <= Reals;  \<exists>x. x \<in> P;  \<exists>Y. isUb Reals P Y |]
  11.240 +      ==> \<exists>t::hypreal. isLub Reals P t"
  11.241 +apply (frule SReal_hypreal_of_real_image)
  11.242 +apply (auto, drule lemma_isUb_hypreal_of_real)
  11.243 +apply (auto intro!: reals_complete lemma_isLub_hypreal_of_real2 simp add: hypreal_of_real_isLub_iff hypreal_of_real_isUb_iff)
  11.244 +done
  11.245 +
  11.246 +(*--------------------------------------------------------------------
  11.247 +        Set of finite elements is a subring of the extended reals
  11.248 + --------------------------------------------------------------------*)
  11.249 +lemma HFinite_add: "[|x \<in> HFinite; y \<in> HFinite|] ==> (x+y) \<in> HFinite"
  11.250 +apply (simp add: HFinite_def)
  11.251 +apply (blast intro!: SReal_add hrabs_add_less)
  11.252 +done
  11.253 +
  11.254 +lemma HFinite_mult: "[|x \<in> HFinite; y \<in> HFinite|] ==> x*y \<in> HFinite"
  11.255 +apply (simp add: HFinite_def)
  11.256 +apply (blast intro!: SReal_mult abs_mult_less)
  11.257 +done
  11.258 +
  11.259 +lemma HFinite_minus_iff: "(-x \<in> HFinite) = (x \<in> HFinite)"
  11.260 +by (simp add: HFinite_def)
  11.261 +
  11.262 +lemma SReal_subset_HFinite: "Reals <= HFinite"
  11.263 +apply (auto simp add: SReal_def HFinite_def)
  11.264 +apply (rule_tac x = "1 + abs (hypreal_of_real r) " in exI)
  11.265 +apply (auto simp add: hypreal_of_real_hrabs)
  11.266 +apply (rule_tac x = "1 + abs r" in exI, simp)
  11.267 +done
  11.268 +
  11.269 +lemma HFinite_hypreal_of_real [simp]: "hypreal_of_real x \<in> HFinite"
  11.270 +by (auto intro: SReal_subset_HFinite [THEN subsetD])
  11.271 +
  11.272 +lemma HFiniteD: "x \<in> HFinite ==> \<exists>t \<in> Reals. abs x < t"
  11.273 +by (simp add: HFinite_def)
  11.274 +
  11.275 +lemma HFinite_hrabs_iff: "(abs x \<in> HFinite) = (x \<in> HFinite)"
  11.276 +by (simp add: HFinite_def)
  11.277 +declare HFinite_hrabs_iff [iff]
  11.278 +
  11.279 +lemma HFinite_number_of: "number_of w \<in> HFinite"
  11.280 +by (rule SReal_number_of [THEN SReal_subset_HFinite [THEN subsetD]])
  11.281 +declare HFinite_number_of [simp]
  11.282 +
  11.283 +(** As always with numerals, 0 and 1 are special cases **)
  11.284 +
  11.285 +lemma HFinite_0: "0 \<in> HFinite"
  11.286 +apply (subst hypreal_numeral_0_eq_0 [symmetric])
  11.287 +apply (rule HFinite_number_of)
  11.288 +done
  11.289 +declare HFinite_0 [simp]
  11.290 +
  11.291 +lemma HFinite_1: "1 \<in> HFinite"
  11.292 +apply (subst hypreal_numeral_1_eq_1 [symmetric])
  11.293 +apply (rule HFinite_number_of)
  11.294 +done
  11.295 +declare HFinite_1 [simp]
  11.296 +
  11.297 +lemma HFinite_bounded: "[|x \<in> HFinite; y <= x; 0 <= y |] ==> y \<in> HFinite"
  11.298 +apply (case_tac "x <= 0")
  11.299 +apply (drule_tac y = x in order_trans)
  11.300 +apply (drule_tac [2] hypreal_le_anti_sym)
  11.301 +apply (auto simp add: linorder_not_le)
  11.302 +apply (auto intro: order_le_less_trans simp add: abs_if HFinite_def)
  11.303 +done
  11.304 +
  11.305 +(*------------------------------------------------------------------
  11.306 +       Set of infinitesimals is a subring of the hyperreals
  11.307 + ------------------------------------------------------------------*)
  11.308 +lemma InfinitesimalD:
  11.309 +      "x \<in> Infinitesimal ==> \<forall>r \<in> Reals. 0 < r --> abs x < r"
  11.310 +apply (simp add: Infinitesimal_def)
  11.311 +done
  11.312 +
  11.313 +lemma Infinitesimal_zero: "0 \<in> Infinitesimal"
  11.314 +by (simp add: Infinitesimal_def)
  11.315 +declare Infinitesimal_zero [iff]
  11.316 +
  11.317 +lemma hypreal_sum_of_halves: "x/(2::hypreal) + x/(2::hypreal) = x"
  11.318 +by auto
  11.319 +
  11.320 +lemma hypreal_half_gt_zero: "0 < r ==> 0 < r/(2::hypreal)"
  11.321 +by auto
  11.322 +
  11.323 +lemma Infinitesimal_add:
  11.324 +     "[| x \<in> Infinitesimal; y \<in> Infinitesimal |] ==> (x+y) \<in> Infinitesimal"
  11.325 +apply (auto simp add: Infinitesimal_def)
  11.326 +apply (rule hypreal_sum_of_halves [THEN subst])
  11.327 +apply (drule hypreal_half_gt_zero)
  11.328 +apply (blast intro: hrabs_add_less hrabs_add_less SReal_divide_number_of)
  11.329 +done
  11.330 +
  11.331 +lemma Infinitesimal_minus_iff: "(-x:Infinitesimal) = (x:Infinitesimal)"
  11.332 +by (simp add: Infinitesimal_def)
  11.333 +declare Infinitesimal_minus_iff [simp]
  11.334 +
  11.335 +lemma Infinitesimal_diff: "[| x \<in> Infinitesimal;  y \<in> Infinitesimal |] ==> x-y \<in> Infinitesimal"
  11.336 +by (simp add: hypreal_diff_def Infinitesimal_add)
  11.337 +
  11.338 +lemma Infinitesimal_mult:
  11.339 +     "[| x \<in> Infinitesimal; y \<in> Infinitesimal |] ==> (x * y) \<in> Infinitesimal"
  11.340 +apply (auto simp add: Infinitesimal_def)
  11.341 +apply (case_tac "y=0")
  11.342 +apply (cut_tac [2] a = "abs x" and b = 1 and c = "abs y" and d = r in mult_strict_mono, auto)
  11.343 +done
  11.344 +
  11.345 +lemma Infinitesimal_HFinite_mult: "[| x \<in> Infinitesimal; y \<in> HFinite |] ==> (x * y) \<in> Infinitesimal"
  11.346 +apply (auto dest!: HFiniteD simp add: Infinitesimal_def)
  11.347 +apply (frule hrabs_less_gt_zero)
  11.348 +apply (drule_tac x = "r/t" in bspec)
  11.349 +apply (blast intro: SReal_divide)
  11.350 +apply (simp add: zero_less_divide_iff)
  11.351 +apply (case_tac "x=0 | y=0")
  11.352 +apply (cut_tac [2] a = "abs x" and b = "r/t" and c = "abs y" in mult_strict_mono)
  11.353 +apply (auto simp add: zero_less_divide_iff)
  11.354 +done
  11.355 +
  11.356 +lemma Infinitesimal_HFinite_mult2: "[| x \<in> Infinitesimal; y \<in> HFinite |] ==> (y * x) \<in> Infinitesimal"
  11.357 +by (auto dest: Infinitesimal_HFinite_mult simp add: hypreal_mult_commute)
  11.358 +
  11.359 +(*** rather long proof ***)
  11.360 +lemma HInfinite_inverse_Infinitesimal:
  11.361 +     "x \<in> HInfinite ==> inverse x: Infinitesimal"
  11.362 +apply (auto simp add: HInfinite_def Infinitesimal_def)
  11.363 +apply (erule_tac x = "inverse r" in ballE)
  11.364 +apply (frule_tac a1 = r and z = "abs x" in positive_imp_inverse_positive [THEN order_less_trans], assumption)
  11.365 +apply (drule inverse_inverse_eq [symmetric, THEN subst])
  11.366 +apply (rule inverse_less_iff_less [THEN iffD1])
  11.367 +apply (auto simp add: SReal_inverse)
  11.368 +done
  11.369 +
  11.370 +
  11.371 +
  11.372 +lemma HInfinite_mult: "[|x \<in> HInfinite;y \<in> HInfinite|] ==> (x*y) \<in> HInfinite"
  11.373 +apply (simp add: HInfinite_def, auto)
  11.374 +apply (erule_tac x = 1 in ballE)
  11.375 +apply (erule_tac x = r in ballE)
  11.376 +apply (case_tac "y=0")
  11.377 +apply (cut_tac [2] c = 1 and d = "abs x" and a = r and b = "abs y" in mult_strict_mono)
  11.378 +apply (auto simp add: mult_ac)
  11.379 +done
  11.380 +
  11.381 +lemma HInfinite_add_ge_zero:
  11.382 +      "[|x \<in> HInfinite; 0 <= y; 0 <= x|] ==> (x + y): HInfinite"
  11.383 +by (auto intro!: hypreal_add_zero_less_le_mono 
  11.384 +       simp add: abs_if hypreal_add_commute hypreal_le_add_order HInfinite_def)
  11.385 +
  11.386 +lemma HInfinite_add_ge_zero2: "[|x \<in> HInfinite; 0 <= y; 0 <= x|] ==> (y + x): HInfinite"
  11.387 +by (auto intro!: HInfinite_add_ge_zero simp add: hypreal_add_commute)
  11.388 +
  11.389 +lemma HInfinite_add_gt_zero: "[|x \<in> HInfinite; 0 < y; 0 < x|] ==> (x + y): HInfinite"
  11.390 +by (blast intro: HInfinite_add_ge_zero order_less_imp_le)
  11.391 +
  11.392 +lemma HInfinite_minus_iff: "(-x \<in> HInfinite) = (x \<in> HInfinite)"
  11.393 +by (simp add: HInfinite_def)
  11.394 +
  11.395 +lemma HInfinite_add_le_zero: "[|x \<in> HInfinite; y <= 0; x <= 0|] ==> (x + y): HInfinite"
  11.396 +apply (drule HInfinite_minus_iff [THEN iffD2])
  11.397 +apply (rule HInfinite_minus_iff [THEN iffD1])
  11.398 +apply (auto intro: HInfinite_add_ge_zero)
  11.399 +done
  11.400 +
  11.401 +lemma HInfinite_add_lt_zero: "[|x \<in> HInfinite; y < 0; x < 0|] ==> (x + y): HInfinite"
  11.402 +by (blast intro: HInfinite_add_le_zero order_less_imp_le)
  11.403 +
  11.404 +lemma HFinite_sum_squares: "[|a: HFinite; b: HFinite; c: HFinite|]
  11.405 +      ==> a*a + b*b + c*c \<in> HFinite"
  11.406 +apply (auto intro: HFinite_mult HFinite_add)
  11.407 +done
  11.408 +
  11.409 +lemma not_Infinitesimal_not_zero: "x \<notin> Infinitesimal ==> x \<noteq> 0"
  11.410 +by auto
  11.411 +
  11.412 +lemma not_Infinitesimal_not_zero2: "x \<in> HFinite - Infinitesimal ==> x \<noteq> 0"
  11.413 +by auto
  11.414 +
  11.415 +lemma Infinitesimal_hrabs_iff: "(abs x \<in> Infinitesimal) = (x \<in> Infinitesimal)"
  11.416 +by (auto simp add: hrabs_def)
  11.417 +declare Infinitesimal_hrabs_iff [iff]
  11.418 +
  11.419 +lemma HFinite_diff_Infinitesimal_hrabs: "x \<in> HFinite - Infinitesimal ==> abs x \<in> HFinite - Infinitesimal"
  11.420 +by blast
  11.421 +
  11.422 +lemma hrabs_less_Infinitesimal:
  11.423 +      "[| e \<in> Infinitesimal; abs x < e |] ==> x \<in> Infinitesimal"
  11.424 +apply (auto simp add: Infinitesimal_def abs_less_iff)
  11.425 +done
  11.426 +
  11.427 +lemma hrabs_le_Infinitesimal: "[| e \<in> Infinitesimal; abs x <= e |] ==> x \<in> Infinitesimal"
  11.428 +by (blast dest: order_le_imp_less_or_eq intro: hrabs_less_Infinitesimal)
  11.429 +
  11.430 +lemma Infinitesimal_interval:
  11.431 +      "[| e \<in> Infinitesimal; e' \<in> Infinitesimal; e' < x ; x < e |] 
  11.432 +       ==> x \<in> Infinitesimal"
  11.433 +apply (auto simp add: Infinitesimal_def abs_less_iff)
  11.434 +done
  11.435 +
  11.436 +lemma Infinitesimal_interval2: "[| e \<in> Infinitesimal; e' \<in> Infinitesimal;
  11.437 +         e' <= x ; x <= e |] ==> x \<in> Infinitesimal"
  11.438 +apply (auto intro: Infinitesimal_interval simp add: order_le_less)
  11.439 +done
  11.440 +
  11.441 +lemma not_Infinitesimal_mult:
  11.442 +     "[| x \<notin> Infinitesimal;  y \<notin> Infinitesimal|] ==> (x*y) \<notin>Infinitesimal"
  11.443 +apply (unfold Infinitesimal_def, clarify)
  11.444 +apply (simp add: linorder_not_less)
  11.445 +apply (erule_tac x = "r*ra" in ballE)
  11.446 +prefer 2 apply (fast intro: SReal_mult)
  11.447 +apply (auto simp add: zero_less_mult_iff)
  11.448 +apply (cut_tac c = ra and d = "abs y" and a = r and b = "abs x" in mult_mono, auto)
  11.449 +done
  11.450 +
  11.451 +lemma Infinitesimal_mult_disj: "x*y \<in> Infinitesimal ==> x \<in> Infinitesimal | y \<in> Infinitesimal"
  11.452 +apply (rule ccontr)
  11.453 +apply (drule de_Morgan_disj [THEN iffD1])
  11.454 +apply (fast dest: not_Infinitesimal_mult)
  11.455 +done
  11.456 +
  11.457 +lemma HFinite_Infinitesimal_not_zero: "x \<in> HFinite-Infinitesimal ==> x \<noteq> 0"
  11.458 +by blast
  11.459 +
  11.460 +lemma HFinite_Infinitesimal_diff_mult: "[| x \<in> HFinite - Infinitesimal;
  11.461 +                   y \<in> HFinite - Infinitesimal
  11.462 +                |] ==> (x*y) \<in> HFinite - Infinitesimal"
  11.463 +apply clarify
  11.464 +apply (blast dest: HFinite_mult not_Infinitesimal_mult)
  11.465 +done
  11.466 +
  11.467 +lemma Infinitesimal_subset_HFinite:
  11.468 +      "Infinitesimal <= HFinite"
  11.469 +apply (simp add: Infinitesimal_def HFinite_def, auto)
  11.470 +apply (rule_tac x = 1 in bexI, auto)
  11.471 +done
  11.472 +
  11.473 +lemma Infinitesimal_hypreal_of_real_mult: "x \<in> Infinitesimal ==> x * hypreal_of_real r \<in> Infinitesimal"
  11.474 +by (erule HFinite_hypreal_of_real [THEN [2] Infinitesimal_HFinite_mult])
  11.475 +
  11.476 +lemma Infinitesimal_hypreal_of_real_mult2: "x \<in> Infinitesimal ==> hypreal_of_real r * x \<in> Infinitesimal"
  11.477 +by (erule HFinite_hypreal_of_real [THEN [2] Infinitesimal_HFinite_mult2])
  11.478 +
  11.479 +(*----------------------------------------------------------------------
  11.480 +                   Infinitely close relation @=
  11.481 + ----------------------------------------------------------------------*)
  11.482 +
  11.483 +lemma mem_infmal_iff: "(x \<in> Infinitesimal) = (x @= 0)"
  11.484 +by (simp add: Infinitesimal_def approx_def)
  11.485 +
  11.486 +lemma approx_minus_iff: " (x @= y) = (x + -y @= 0)"
  11.487 +by (simp add: approx_def)
  11.488 +
  11.489 +lemma approx_minus_iff2: " (x @= y) = (-y + x @= 0)"
  11.490 +by (simp add: approx_def hypreal_add_commute)
  11.491 +
  11.492 +lemma approx_refl: "x @= x"
  11.493 +by (simp add: approx_def Infinitesimal_def)
  11.494 +declare approx_refl [iff]
  11.495 +
  11.496 +lemma approx_sym: "x @= y ==> y @= x"
  11.497 +apply (simp add: approx_def)
  11.498 +apply (rule hypreal_minus_distrib1 [THEN subst])
  11.499 +apply (erule Infinitesimal_minus_iff [THEN iffD2])
  11.500 +done
  11.501 +
  11.502 +lemma approx_trans: "[| x @= y; y @= z |] ==> x @= z"
  11.503 +apply (simp add: approx_def)
  11.504 +apply (drule Infinitesimal_add, assumption, auto)
  11.505 +done
  11.506 +
  11.507 +lemma approx_trans2: "[| r @= x; s @= x |] ==> r @= s"
  11.508 +by (blast intro: approx_sym approx_trans)
  11.509 +
  11.510 +lemma approx_trans3: "[| x @= r; x @= s|] ==> r @= s"
  11.511 +by (blast intro: approx_sym approx_trans)
  11.512 +
  11.513 +lemma number_of_approx_reorient: "(number_of w @= x) = (x @= number_of w)"
  11.514 +by (blast intro: approx_sym)
  11.515 +
  11.516 +lemma zero_approx_reorient: "(0 @= x) = (x @= 0)"
  11.517 +by (blast intro: approx_sym)
  11.518 +
  11.519 +lemma one_approx_reorient: "(1 @= x) = (x @= 1)"
  11.520 +by (blast intro: approx_sym)
  11.521  
  11.522  
  11.523 -defs  
  11.524 +ML
  11.525 +{*
  11.526 +val SReal_add = thm "SReal_add";
  11.527 +val SReal_mult = thm "SReal_mult";
  11.528 +val SReal_inverse = thm "SReal_inverse";
  11.529 +val SReal_divide = thm "SReal_divide";
  11.530 +val SReal_minus = thm "SReal_minus";
  11.531 +val SReal_minus_iff = thm "SReal_minus_iff";
  11.532 +val SReal_add_cancel = thm "SReal_add_cancel";
  11.533 +val SReal_hrabs = thm "SReal_hrabs";
  11.534 +val SReal_hypreal_of_real = thm "SReal_hypreal_of_real";
  11.535 +val SReal_number_of = thm "SReal_number_of";
  11.536 +val Reals_0 = thm "Reals_0";
  11.537 +val Reals_1 = thm "Reals_1";
  11.538 +val SReal_divide_number_of = thm "SReal_divide_number_of";
  11.539 +val SReal_epsilon_not_mem = thm "SReal_epsilon_not_mem";
  11.540 +val SReal_omega_not_mem = thm "SReal_omega_not_mem";
  11.541 +val SReal_UNIV_real = thm "SReal_UNIV_real";
  11.542 +val SReal_iff = thm "SReal_iff";
  11.543 +val hypreal_of_real_image = thm "hypreal_of_real_image";
  11.544 +val inv_hypreal_of_real_image = thm "inv_hypreal_of_real_image";
  11.545 +val SReal_hypreal_of_real_image = thm "SReal_hypreal_of_real_image";
  11.546 +val SReal_dense = thm "SReal_dense";
  11.547 +val SReal_sup_lemma = thm "SReal_sup_lemma";
  11.548 +val SReal_sup_lemma2 = thm "SReal_sup_lemma2";
  11.549 +val hypreal_of_real_isUb_iff = thm "hypreal_of_real_isUb_iff";
  11.550 +val hypreal_of_real_isLub1 = thm "hypreal_of_real_isLub1";
  11.551 +val hypreal_of_real_isLub2 = thm "hypreal_of_real_isLub2";
  11.552 +val hypreal_of_real_isLub_iff = thm "hypreal_of_real_isLub_iff";
  11.553 +val lemma_isUb_hypreal_of_real = thm "lemma_isUb_hypreal_of_real";
  11.554 +val lemma_isLub_hypreal_of_real = thm "lemma_isLub_hypreal_of_real";
  11.555 +val lemma_isLub_hypreal_of_real2 = thm "lemma_isLub_hypreal_of_real2";
  11.556 +val SReal_complete = thm "SReal_complete";
  11.557 +val HFinite_add = thm "HFinite_add";
  11.558 +val HFinite_mult = thm "HFinite_mult";
  11.559 +val HFinite_minus_iff = thm "HFinite_minus_iff";
  11.560 +val SReal_subset_HFinite = thm "SReal_subset_HFinite";
  11.561 +val HFinite_hypreal_of_real = thm "HFinite_hypreal_of_real";
  11.562 +val HFiniteD = thm "HFiniteD";
  11.563 +val HFinite_hrabs_iff = thm "HFinite_hrabs_iff";
  11.564 +val HFinite_number_of = thm "HFinite_number_of";
  11.565 +val HFinite_0 = thm "HFinite_0";
  11.566 +val HFinite_1 = thm "HFinite_1";
  11.567 +val HFinite_bounded = thm "HFinite_bounded";
  11.568 +val InfinitesimalD = thm "InfinitesimalD";
  11.569 +val Infinitesimal_zero = thm "Infinitesimal_zero";
  11.570 +val hypreal_sum_of_halves = thm "hypreal_sum_of_halves";
  11.571 +val hypreal_half_gt_zero = thm "hypreal_half_gt_zero";
  11.572 +val Infinitesimal_add = thm "Infinitesimal_add";
  11.573 +val Infinitesimal_minus_iff = thm "Infinitesimal_minus_iff";
  11.574 +val Infinitesimal_diff = thm "Infinitesimal_diff";
  11.575 +val Infinitesimal_mult = thm "Infinitesimal_mult";
  11.576 +val Infinitesimal_HFinite_mult = thm "Infinitesimal_HFinite_mult";
  11.577 +val Infinitesimal_HFinite_mult2 = thm "Infinitesimal_HFinite_mult2";
  11.578 +val HInfinite_inverse_Infinitesimal = thm "HInfinite_inverse_Infinitesimal";
  11.579 +val HInfinite_mult = thm "HInfinite_mult";
  11.580 +val HInfinite_add_ge_zero = thm "HInfinite_add_ge_zero";
  11.581 +val HInfinite_add_ge_zero2 = thm "HInfinite_add_ge_zero2";
  11.582 +val HInfinite_add_gt_zero = thm "HInfinite_add_gt_zero";
  11.583 +val HInfinite_minus_iff = thm "HInfinite_minus_iff";
  11.584 +val HInfinite_add_le_zero = thm "HInfinite_add_le_zero";
  11.585 +val HInfinite_add_lt_zero = thm "HInfinite_add_lt_zero";
  11.586 +val HFinite_sum_squares = thm "HFinite_sum_squares";
  11.587 +val not_Infinitesimal_not_zero = thm "not_Infinitesimal_not_zero";
  11.588 +val not_Infinitesimal_not_zero2 = thm "not_Infinitesimal_not_zero2";
  11.589 +val Infinitesimal_hrabs_iff = thm "Infinitesimal_hrabs_iff";
  11.590 +val HFinite_diff_Infinitesimal_hrabs = thm "HFinite_diff_Infinitesimal_hrabs";
  11.591 +val hrabs_less_Infinitesimal = thm "hrabs_less_Infinitesimal";
  11.592 +val hrabs_le_Infinitesimal = thm "hrabs_le_Infinitesimal";
  11.593 +val Infinitesimal_interval = thm "Infinitesimal_interval";
  11.594 +val Infinitesimal_interval2 = thm "Infinitesimal_interval2";
  11.595 +val not_Infinitesimal_mult = thm "not_Infinitesimal_mult";
  11.596 +val Infinitesimal_mult_disj = thm "Infinitesimal_mult_disj";
  11.597 +val HFinite_Infinitesimal_not_zero = thm "HFinite_Infinitesimal_not_zero";
  11.598 +val HFinite_Infinitesimal_diff_mult = thm "HFinite_Infinitesimal_diff_mult";
  11.599 +val Infinitesimal_subset_HFinite = thm "Infinitesimal_subset_HFinite";
  11.600 +val Infinitesimal_hypreal_of_real_mult = thm "Infinitesimal_hypreal_of_real_mult";
  11.601 +val Infinitesimal_hypreal_of_real_mult2 = thm "Infinitesimal_hypreal_of_real_mult2";
  11.602 +val mem_infmal_iff = thm "mem_infmal_iff";
  11.603 +val approx_minus_iff = thm "approx_minus_iff";
  11.604 +val approx_minus_iff2 = thm "approx_minus_iff2";
  11.605 +val approx_refl = thm "approx_refl";
  11.606 +val approx_sym = thm "approx_sym";
  11.607 +val approx_trans = thm "approx_trans";
  11.608 +val approx_trans2 = thm "approx_trans2";
  11.609 +val approx_trans3 = thm "approx_trans3";
  11.610 +val number_of_approx_reorient = thm "number_of_approx_reorient";
  11.611 +val zero_approx_reorient = thm "zero_approx_reorient";
  11.612 +val one_approx_reorient = thm "one_approx_reorient";
  11.613 +
  11.614 +(*** re-orientation, following HOL/Integ/Bin.ML
  11.615 +     We re-orient x @=y where x is 0, 1 or a numeral, unless y is as well!
  11.616 + ***)
  11.617 +
  11.618 +(*reorientation simprules using ==, for the following simproc*)
  11.619 +val meta_zero_approx_reorient = zero_approx_reorient RS eq_reflection;
  11.620 +val meta_one_approx_reorient = one_approx_reorient RS eq_reflection;
  11.621 +val meta_number_of_approx_reorient = number_of_approx_reorient RS eq_reflection
  11.622 +
  11.623 +(*reorientation simplification procedure: reorients (polymorphic)
  11.624 +  0 = x, 1 = x, nnn = x provided x isn't 0, 1 or a numeral.*)
  11.625 +fun reorient_proc sg _ (_ $ t $ u) =
  11.626 +  case u of
  11.627 +      Const("0", _) => None
  11.628 +    | Const("1", _) => None
  11.629 +    | Const("Numeral.number_of", _) $ _ => None
  11.630 +    | _ => Some (case t of
  11.631 +                Const("0", _) => meta_zero_approx_reorient
  11.632 +              | Const("1", _) => meta_one_approx_reorient
  11.633 +              | Const("Numeral.number_of", _) $ _ =>
  11.634 +                                 meta_number_of_approx_reorient);
  11.635 +
  11.636 +val approx_reorient_simproc =
  11.637 +  Bin_Simprocs.prep_simproc
  11.638 +    ("reorient_simproc", ["0@=x", "1@=x", "number_of w @= x"], reorient_proc);
  11.639 +
  11.640 +Addsimprocs [approx_reorient_simproc];
  11.641 +*}
  11.642 +
  11.643 +lemma Infinitesimal_approx_minus: "(x-y \<in> Infinitesimal) = (x @= y)"
  11.644 +by (auto simp add: hypreal_diff_def approx_minus_iff [symmetric] mem_infmal_iff)
  11.645 +
  11.646 +lemma approx_monad_iff: "(x @= y) = (monad(x)=monad(y))"
  11.647 +apply (simp add: monad_def)
  11.648 +apply (auto dest: approx_sym elim!: approx_trans equalityCE)
  11.649 +done
  11.650 +
  11.651 +lemma Infinitesimal_approx: "[| x \<in> Infinitesimal; y \<in> Infinitesimal |] ==> x @= y"
  11.652 +apply (simp add: mem_infmal_iff)
  11.653 +apply (blast intro: approx_trans approx_sym)
  11.654 +done
  11.655 +
  11.656 +lemma approx_add: "[| a @= b; c @= d |] ==> a+c @= b+d"
  11.657 +proof (unfold approx_def)
  11.658 +  assume inf: "a + - b \<in> Infinitesimal" "c + - d \<in> Infinitesimal"
  11.659 +  have "a + c + - (b + d) = (a + - b) + (c + - d)" by arith
  11.660 +  also have "... \<in> Infinitesimal" using inf by (rule Infinitesimal_add)
  11.661 +  finally show "a + c + - (b + d) \<in> Infinitesimal" .
  11.662 +qed
  11.663 +
  11.664 +lemma approx_minus: "a @= b ==> -a @= -b"
  11.665 +apply (rule approx_minus_iff [THEN iffD2, THEN approx_sym])
  11.666 +apply (drule approx_minus_iff [THEN iffD1])
  11.667 +apply (simp (no_asm) add: hypreal_add_commute)
  11.668 +done
  11.669 +
  11.670 +lemma approx_minus2: "-a @= -b ==> a @= b"
  11.671 +by (auto dest: approx_minus)
  11.672 +
  11.673 +lemma approx_minus_cancel: "(-a @= -b) = (a @= b)"
  11.674 +by (blast intro: approx_minus approx_minus2)
  11.675 +
  11.676 +declare approx_minus_cancel [simp]
  11.677 +
  11.678 +lemma approx_add_minus: "[| a @= b; c @= d |] ==> a + -c @= b + -d"
  11.679 +by (blast intro!: approx_add approx_minus)
  11.680 +
  11.681 +lemma approx_mult1: "[| a @= b; c: HFinite|] ==> a*c @= b*c"
  11.682 +by (simp add: approx_def Infinitesimal_HFinite_mult minus_mult_left 
  11.683 +              left_distrib [symmetric] 
  11.684 +         del: minus_mult_left [symmetric])
  11.685 +
  11.686 +lemma approx_mult2: "[|a @= b; c: HFinite|] ==> c*a @= c*b"
  11.687 +apply (simp (no_asm_simp) add: approx_mult1 hypreal_mult_commute)
  11.688 +done
  11.689 +
  11.690 +lemma approx_mult_subst: "[|u @= v*x; x @= y; v \<in> HFinite|] ==> u @= v*y"
  11.691 +by (blast intro: approx_mult2 approx_trans)
  11.692 +
  11.693 +lemma approx_mult_subst2: "[| u @= x*v; x @= y; v \<in> HFinite |] ==> u @= y*v"
  11.694 +by (blast intro: approx_mult1 approx_trans)
  11.695 +
  11.696 +lemma approx_mult_subst_SReal: "[| u @= x*hypreal_of_real v; x @= y |] ==> u @= y*hypreal_of_real v"
  11.697 +by (auto intro: approx_mult_subst2)
  11.698 +
  11.699 +lemma approx_eq_imp: "a = b ==> a @= b"
  11.700 +by (simp add: approx_def)
  11.701 +
  11.702 +lemma Infinitesimal_minus_approx: "x \<in> Infinitesimal ==> -x @= x"
  11.703 +by (blast intro: Infinitesimal_minus_iff [THEN iffD2] 
  11.704 +                    mem_infmal_iff [THEN iffD1] approx_trans2)
  11.705 +
  11.706 +lemma bex_Infinitesimal_iff: "(\<exists>y \<in> Infinitesimal. x + -z = y) = (x @= z)"
  11.707 +by (simp add: approx_def)
  11.708 +
  11.709 +lemma bex_Infinitesimal_iff2: "(\<exists>y \<in> Infinitesimal. x = z + y) = (x @= z)"
  11.710 +by (force simp add: bex_Infinitesimal_iff [symmetric])
  11.711 +
  11.712 +lemma Infinitesimal_add_approx: "[| y \<in> Infinitesimal; x + y = z |] ==> x @= z"
  11.713 +apply (rule bex_Infinitesimal_iff [THEN iffD1])
  11.714 +apply (drule Infinitesimal_minus_iff [THEN iffD2])
  11.715 +apply (auto simp add: minus_add_distrib hypreal_add_assoc [symmetric])
  11.716 +done
  11.717 +
  11.718 +lemma Infinitesimal_add_approx_self: "y \<in> Infinitesimal ==> x @= x + y"
  11.719 +apply (rule bex_Infinitesimal_iff [THEN iffD1])
  11.720 +apply (drule Infinitesimal_minus_iff [THEN iffD2])
  11.721 +apply (auto simp add: minus_add_distrib hypreal_add_assoc [symmetric])
  11.722 +done
  11.723 +
  11.724 +lemma Infinitesimal_add_approx_self2: "y \<in> Infinitesimal ==> x @= y + x"
  11.725 +by (auto dest: Infinitesimal_add_approx_self simp add: hypreal_add_commute)
  11.726 +
  11.727 +lemma Infinitesimal_add_minus_approx_self: "y \<in> Infinitesimal ==> x @= x + -y"
  11.728 +by (blast intro!: Infinitesimal_add_approx_self Infinitesimal_minus_iff [THEN iffD2])
  11.729 +
  11.730 +lemma Infinitesimal_add_cancel: "[| y \<in> Infinitesimal; x+y @= z|] ==> x @= z"
  11.731 +apply (drule_tac x = x in Infinitesimal_add_approx_self [THEN approx_sym])
  11.732 +apply (erule approx_trans3 [THEN approx_sym], assumption)
  11.733 +done
  11.734 +
  11.735 +lemma Infinitesimal_add_right_cancel: "[| y \<in> Infinitesimal; x @= z + y|] ==> x @= z"
  11.736 +apply (drule_tac x = z in Infinitesimal_add_approx_self2 [THEN approx_sym])
  11.737 +apply (erule approx_trans3 [THEN approx_sym])
  11.738 +apply (simp add: hypreal_add_commute)
  11.739 +apply (erule approx_sym)
  11.740 +done
  11.741 +
  11.742 +lemma approx_add_left_cancel: "d + b  @= d + c ==> b @= c"
  11.743 +apply (drule approx_minus_iff [THEN iffD1])
  11.744 +apply (simp add: minus_add_distrib approx_minus_iff [symmetric] add_ac)
  11.745 +done
  11.746 +
  11.747 +lemma approx_add_right_cancel: "b + d @= c + d ==> b @= c"
  11.748 +apply (rule approx_add_left_cancel)
  11.749 +apply (simp add: hypreal_add_commute)
  11.750 +done
  11.751 +
  11.752 +lemma approx_add_mono1: "b @= c ==> d + b @= d + c"
  11.753 +apply (rule approx_minus_iff [THEN iffD2])
  11.754 +apply (simp add: minus_add_distrib approx_minus_iff [symmetric] add_ac)
  11.755 +done
  11.756 +
  11.757 +lemma approx_add_mono2: "b @= c ==> b + a @= c + a"
  11.758 +apply (simp (no_asm_simp) add: hypreal_add_commute approx_add_mono1)
  11.759 +done
  11.760 +
  11.761 +lemma approx_add_left_iff: "(a + b @= a + c) = (b @= c)"
  11.762 +by (fast elim: approx_add_left_cancel approx_add_mono1)
  11.763 +
  11.764 +declare approx_add_left_iff [simp]
  11.765 +
  11.766 +lemma approx_add_right_iff: "(b + a @= c + a) = (b @= c)"
  11.767 +apply (simp (no_asm) add: hypreal_add_commute)
  11.768 +done
  11.769 +
  11.770 +declare approx_add_right_iff [simp]
  11.771 +
  11.772 +lemma approx_HFinite: "[| x \<in> HFinite; x @= y |] ==> y \<in> HFinite"
  11.773 +apply (drule bex_Infinitesimal_iff2 [THEN iffD2], safe)
  11.774 +apply (drule Infinitesimal_subset_HFinite [THEN subsetD, THEN HFinite_minus_iff [THEN iffD2]])
  11.775 +apply (drule HFinite_add)
  11.776 +apply (auto simp add: hypreal_add_assoc)
  11.777 +done
  11.778 +
  11.779 +lemma approx_hypreal_of_real_HFinite: "x @= hypreal_of_real D ==> x \<in> HFinite"
  11.780 +by (rule approx_sym [THEN [2] approx_HFinite], auto)
  11.781 +
  11.782 +lemma approx_mult_HFinite: "[|a @= b; c @= d; b: HFinite; d: HFinite|] ==> a*c @= b*d"
  11.783 +apply (rule approx_trans)
  11.784 +apply (rule_tac [2] approx_mult2)
  11.785 +apply (rule approx_mult1)
  11.786 +prefer 2 apply (blast intro: approx_HFinite approx_sym, auto)
  11.787 +done
  11.788 +
  11.789 +lemma approx_mult_hypreal_of_real: "[|a @= hypreal_of_real b; c @= hypreal_of_real d |]
  11.790 +      ==> a*c @= hypreal_of_real b*hypreal_of_real d"
  11.791 +apply (blast intro!: approx_mult_HFinite approx_hypreal_of_real_HFinite HFinite_hypreal_of_real)
  11.792 +done
  11.793 +
  11.794 +lemma approx_SReal_mult_cancel_zero: "[| a \<in> Reals; a \<noteq> 0; a*x @= 0 |] ==> x @= 0"
  11.795 +apply (drule SReal_inverse [THEN SReal_subset_HFinite [THEN subsetD]])
  11.796 +apply (auto dest: approx_mult2 simp add: hypreal_mult_assoc [symmetric])
  11.797 +done
  11.798 +
  11.799 +(* REM comments: newly added *)
  11.800 +lemma approx_mult_SReal1: "[| a \<in> Reals; x @= 0 |] ==> x*a @= 0"
  11.801 +by (auto dest: SReal_subset_HFinite [THEN subsetD] approx_mult1)
  11.802 +
  11.803 +lemma approx_mult_SReal2: "[| a \<in> Reals; x @= 0 |] ==> a*x @= 0"
  11.804 +by (auto dest: SReal_subset_HFinite [THEN subsetD] approx_mult2)
  11.805 +
  11.806 +lemma approx_mult_SReal_zero_cancel_iff: "[|a \<in> Reals; a \<noteq> 0 |] ==> (a*x @= 0) = (x @= 0)"
  11.807 +by (blast intro: approx_SReal_mult_cancel_zero approx_mult_SReal2)
  11.808 +declare approx_mult_SReal_zero_cancel_iff [simp]
  11.809 +
  11.810 +lemma approx_SReal_mult_cancel: "[| a \<in> Reals; a \<noteq> 0; a* w @= a*z |] ==> w @= z"
  11.811 +apply (drule SReal_inverse [THEN SReal_subset_HFinite [THEN subsetD]])
  11.812 +apply (auto dest: approx_mult2 simp add: hypreal_mult_assoc [symmetric])
  11.813 +done
  11.814 +
  11.815 +lemma approx_SReal_mult_cancel_iff1: "[| a \<in> Reals; a \<noteq> 0|] ==> (a* w @= a*z) = (w @= z)"
  11.816 +by (auto intro!: approx_mult2 SReal_subset_HFinite [THEN subsetD] intro: approx_SReal_mult_cancel)
  11.817 +declare approx_SReal_mult_cancel_iff1 [simp]
  11.818 +
  11.819 +lemma approx_le_bound: "[| z <= f; f @= g; g <= z |] ==> f @= z"
  11.820 +apply (simp add: bex_Infinitesimal_iff2 [symmetric], auto)
  11.821 +apply (rule_tac x = "g+y-z" in bexI)
  11.822 +apply (simp (no_asm))
  11.823 +apply (rule Infinitesimal_interval2)
  11.824 +apply (rule_tac [2] Infinitesimal_zero, auto)
  11.825 +done
  11.826 +
  11.827 +(*-----------------------------------------------------------------
  11.828 +    Zero is the only infinitesimal that is also a real
  11.829 + -----------------------------------------------------------------*)
  11.830 +
  11.831 +lemma Infinitesimal_less_SReal:
  11.832 +     "[| x \<in> Reals; y \<in> Infinitesimal; 0 < x |] ==> y < x"
  11.833 +apply (simp add: Infinitesimal_def)
  11.834 +apply (rule abs_ge_self [THEN order_le_less_trans], auto)
  11.835 +done
  11.836 +
  11.837 +lemma Infinitesimal_less_SReal2: "y \<in> Infinitesimal ==> \<forall>r \<in> Reals. 0 < r --> y < r"
  11.838 +by (blast intro: Infinitesimal_less_SReal)
  11.839 +
  11.840 +lemma SReal_not_Infinitesimal:
  11.841 +     "[| 0 < y;  y \<in> Reals|] ==> y \<notin> Infinitesimal"
  11.842 +apply (simp add: Infinitesimal_def)
  11.843 +apply (auto simp add: hrabs_def)
  11.844 +done
  11.845 +
  11.846 +lemma SReal_minus_not_Infinitesimal: "[| y < 0;  y \<in> Reals |] ==> y \<notin> Infinitesimal"
  11.847 +apply (subst Infinitesimal_minus_iff [symmetric])
  11.848 +apply (rule SReal_not_Infinitesimal, auto)
  11.849 +done
  11.850 +
  11.851 +lemma SReal_Int_Infinitesimal_zero: "Reals Int Infinitesimal = {0}"
  11.852 +apply auto
  11.853 +apply (cut_tac x = x and y = 0 in linorder_less_linear)
  11.854 +apply (blast dest: SReal_not_Infinitesimal SReal_minus_not_Infinitesimal)
  11.855 +done
  11.856 +
  11.857 +lemma SReal_Infinitesimal_zero: "[| x \<in> Reals; x \<in> Infinitesimal|] ==> x = 0"
  11.858 +by (cut_tac SReal_Int_Infinitesimal_zero, blast)
  11.859 +
  11.860 +lemma SReal_HFinite_diff_Infinitesimal: "[| x \<in> Reals; x \<noteq> 0 |] ==> x \<in> HFinite - Infinitesimal"
  11.861 +by (auto dest: SReal_Infinitesimal_zero SReal_subset_HFinite [THEN subsetD])
  11.862 +
  11.863 +lemma hypreal_of_real_HFinite_diff_Infinitesimal: "hypreal_of_real x \<noteq> 0 ==> hypreal_of_real x \<in> HFinite - Infinitesimal"
  11.864 +by (rule SReal_HFinite_diff_Infinitesimal, auto)
  11.865 +
  11.866 +lemma hypreal_of_real_Infinitesimal_iff_0: "(hypreal_of_real x \<in> Infinitesimal) = (x=0)"
  11.867 +apply auto
  11.868 +apply (rule ccontr)
  11.869 +apply (rule hypreal_of_real_HFinite_diff_Infinitesimal [THEN DiffD2], auto)
  11.870 +done
  11.871 +declare hypreal_of_real_Infinitesimal_iff_0 [iff]
  11.872 +
  11.873 +lemma number_of_not_Infinitesimal: "number_of w \<noteq> (0::hypreal) ==> number_of w \<notin> Infinitesimal"
  11.874 +by (fast dest: SReal_number_of [THEN SReal_Infinitesimal_zero])
  11.875 +declare number_of_not_Infinitesimal [simp]
  11.876 +
  11.877 +(*again: 1 is a special case, but not 0 this time*)
  11.878 +lemma one_not_Infinitesimal: "1 \<notin> Infinitesimal"
  11.879 +apply (subst hypreal_numeral_1_eq_1 [symmetric])
  11.880 +apply (rule number_of_not_Infinitesimal)
  11.881 +apply (simp (no_asm))
  11.882 +done
  11.883 +declare one_not_Infinitesimal [simp]
  11.884 +
  11.885 +lemma approx_SReal_not_zero: "[| y \<in> Reals; x @= y; y\<noteq> 0 |] ==> x \<noteq> 0"
  11.886 +apply (cut_tac x = 0 and y = y in linorder_less_linear, simp)
  11.887 +apply (blast dest: approx_sym [THEN mem_infmal_iff [THEN iffD2]] SReal_not_Infinitesimal SReal_minus_not_Infinitesimal)
  11.888 +done
  11.889 +
  11.890 +lemma HFinite_diff_Infinitesimal_approx: "[| x @= y; y \<in> HFinite - Infinitesimal |]
  11.891 +      ==> x \<in> HFinite - Infinitesimal"
  11.892 +apply (auto intro: approx_sym [THEN [2] approx_HFinite]
  11.893 +            simp add: mem_infmal_iff)
  11.894 +apply (drule approx_trans3, assumption)
  11.895 +apply (blast dest: approx_sym)
  11.896 +done
  11.897 +
  11.898 +(*The premise y\<noteq>0 is essential; otherwise x/y =0 and we lose the
  11.899 +  HFinite premise.*)
  11.900 +lemma Infinitesimal_ratio: "[| y \<noteq> 0;  y \<in> Infinitesimal;  x/y \<in> HFinite |] ==> x \<in> Infinitesimal"
  11.901 +apply (drule Infinitesimal_HFinite_mult2, assumption)
  11.902 +apply (simp add: hypreal_divide_def hypreal_mult_assoc)
  11.903 +done
  11.904 +
  11.905 +(*------------------------------------------------------------------
  11.906 +       Standard Part Theorem: Every finite x: R* is infinitely
  11.907 +       close to a unique real number (i.e a member of Reals)
  11.908 + ------------------------------------------------------------------*)
  11.909 +(*------------------------------------------------------------------
  11.910 +         Uniqueness: Two infinitely close reals are equal
  11.911 + ------------------------------------------------------------------*)
  11.912 +
  11.913 +lemma SReal_approx_iff: "[|x \<in> Reals; y \<in> Reals|] ==> (x @= y) = (x = y)"
  11.914 +apply auto
  11.915 +apply (simp add: approx_def)
  11.916 +apply (drule_tac x = y in SReal_minus)
  11.917 +apply (drule SReal_add, assumption)
  11.918 +apply (drule SReal_Infinitesimal_zero, assumption)
  11.919 +apply (drule sym)
  11.920 +apply (simp add: hypreal_eq_minus_iff [symmetric])
  11.921 +done
  11.922 +
  11.923 +lemma number_of_approx_iff: "(number_of v @= number_of w) = (number_of v = (number_of w :: hypreal))"
  11.924 +by (auto simp add: SReal_approx_iff)
  11.925 +declare number_of_approx_iff [simp]
  11.926 +
  11.927 +(*And also for 0 @= #nn and 1 @= #nn, #nn @= 0 and #nn @= 1.*)
  11.928 +lemma [simp]: "(0 @= number_of w) = ((number_of w :: hypreal) = 0)"
  11.929 +              "(number_of w @= 0) = ((number_of w :: hypreal) = 0)"
  11.930 +              "(1 @= number_of w) = ((number_of w :: hypreal) = 1)"
  11.931 +              "(number_of w @= 1) = ((number_of w :: hypreal) = 1)"
  11.932 +              "~ (0 @= 1)" "~ (1 @= 0)"
  11.933 +by (auto simp only: SReal_number_of SReal_approx_iff Reals_0 Reals_1)
  11.934 +
  11.935 +lemma hypreal_of_real_approx_iff: "(hypreal_of_real k @= hypreal_of_real m) = (k = m)"
  11.936 +apply auto
  11.937 +apply (rule inj_hypreal_of_real [THEN injD])
  11.938 +apply (rule SReal_approx_iff [THEN iffD1], auto)
  11.939 +done
  11.940 +declare hypreal_of_real_approx_iff [simp]
  11.941 +
  11.942 +lemma hypreal_of_real_approx_number_of_iff: "(hypreal_of_real k @= number_of w) = (k = number_of w)"
  11.943 +by (subst hypreal_of_real_approx_iff [symmetric], auto)
  11.944 +declare hypreal_of_real_approx_number_of_iff [simp]
  11.945 +
  11.946 +(*And also for 0 and 1.*)
  11.947 +(*And also for 0 @= #nn and 1 @= #nn, #nn @= 0 and #nn @= 1.*)
  11.948 +lemma [simp]: "(hypreal_of_real k @= 0) = (k = 0)"
  11.949 +              "(hypreal_of_real k @= 1) = (k = 1)"
  11.950 +  by (simp_all add:  hypreal_of_real_approx_iff [symmetric])
  11.951 +
  11.952 +lemma approx_unique_real: "[| r \<in> Reals; s \<in> Reals; r @= x; s @= x|] ==> r = s"
  11.953 +by (blast intro: SReal_approx_iff [THEN iffD1] approx_trans2)
  11.954 +
  11.955 +(*------------------------------------------------------------------
  11.956 +       Existence of unique real infinitely close
  11.957 + ------------------------------------------------------------------*)
  11.958 +(* lemma about lubs *)
  11.959 +lemma hypreal_isLub_unique:
  11.960 +     "[| isLub R S x; isLub R S y |] ==> x = (y::hypreal)"
  11.961 +apply (frule isLub_isUb)
  11.962 +apply (frule_tac x = y in isLub_isUb)
  11.963 +apply (blast intro!: hypreal_le_anti_sym dest!: isLub_le_isUb)
  11.964 +done
  11.965 +
  11.966 +lemma lemma_st_part_ub: "x \<in> HFinite ==> \<exists>u. isUb Reals {s. s \<in> Reals & s < x} u"
  11.967 +apply (drule HFiniteD, safe)
  11.968 +apply (rule exI, rule isUbI)
  11.969 +apply (auto intro: setleI isUbI simp add: abs_less_iff)
  11.970 +done
  11.971 +
  11.972 +lemma lemma_st_part_nonempty: "x \<in> HFinite ==> \<exists>y. y \<in> {s. s \<in> Reals & s < x}"
  11.973 +apply (drule HFiniteD, safe)
  11.974 +apply (drule SReal_minus)
  11.975 +apply (rule_tac x = "-t" in exI)
  11.976 +apply (auto simp add: abs_less_iff)
  11.977 +done
  11.978 +
  11.979 +lemma lemma_st_part_subset: "{s. s \<in> Reals & s < x} <= Reals"
  11.980 +by auto
  11.981 +
  11.982 +lemma lemma_st_part_lub: "x \<in> HFinite ==> \<exists>t. isLub Reals {s. s \<in> Reals & s < x} t"
  11.983 +by (blast intro!: SReal_complete lemma_st_part_ub lemma_st_part_nonempty lemma_st_part_subset)
  11.984 +
  11.985 +lemma lemma_hypreal_le_left_cancel: "((t::hypreal) + r <= t) = (r <= 0)"
  11.986 +apply safe
  11.987 +apply (drule_tac c = "-t" in add_left_mono)
  11.988 +apply (drule_tac [2] c = t in add_left_mono)
  11.989 +apply (auto simp add: hypreal_add_assoc [symmetric])
  11.990 +done
  11.991 +
  11.992 +lemma lemma_st_part_le1: "[| x \<in> HFinite;  isLub Reals {s. s \<in> Reals & s < x} t;
  11.993 +         r \<in> Reals;  0 < r |] ==> x <= t + r"
  11.994 +apply (frule isLubD1a)
  11.995 +apply (rule ccontr, drule linorder_not_le [THEN iffD2])
  11.996 +apply (drule_tac x = t in SReal_add, assumption)
  11.997 +apply (drule_tac y = "t + r" in isLubD1 [THEN setleD], auto)
  11.998 +done
  11.999 +
 11.1000 +lemma hypreal_setle_less_trans: "!!x::hypreal. [| S *<= x; x < y |] ==> S *<= y"
 11.1001 +apply (simp add: setle_def)
 11.1002 +apply (auto dest!: bspec order_le_less_trans intro: order_less_imp_le)
 11.1003 +done
 11.1004 +
 11.1005 +lemma hypreal_gt_isUb:
 11.1006 +     "!!x::hypreal. [| isUb R S x; x < y; y \<in> R |] ==> isUb R S y"
 11.1007 +apply (simp add: isUb_def)
 11.1008 +apply (blast intro: hypreal_setle_less_trans)
 11.1009 +done
 11.1010 +
 11.1011 +lemma lemma_st_part_gt_ub: "[| x \<in> HFinite; x < y; y \<in> Reals |]
 11.1012 +               ==> isUb Reals {s. s \<in> Reals & s < x} y"
 11.1013 +apply (auto dest: order_less_trans intro: order_less_imp_le intro!: isUbI setleI)
 11.1014 +done
 11.1015 +
 11.1016 +lemma lemma_minus_le_zero: "t <= t + -r ==> r <= (0::hypreal)"
 11.1017 +apply (drule_tac c = "-t" in add_left_mono)
 11.1018 +apply (auto simp add: hypreal_add_assoc [symmetric])
 11.1019 +done
 11.1020 +
 11.1021 +lemma lemma_st_part_le2: "[| x \<in> HFinite;
 11.1022 +         isLub Reals {s. s \<in> Reals & s < x} t;
 11.1023 +         r \<in> Reals; 0 < r |]
 11.1024 +      ==> t + -r <= x"
 11.1025 +apply (frule isLubD1a)
 11.1026 +apply (rule ccontr, drule linorder_not_le [THEN iffD1])
 11.1027 +apply (drule SReal_minus, drule_tac x = t in SReal_add, assumption)
 11.1028 +apply (drule lemma_st_part_gt_ub, assumption+)
 11.1029 +apply (drule isLub_le_isUb, assumption)
 11.1030 +apply (drule lemma_minus_le_zero)
 11.1031 +apply (auto dest: order_less_le_trans)
 11.1032 +done
 11.1033 +
 11.1034 +lemma lemma_hypreal_le_swap: "((x::hypreal) <= t + r) = (x + -t <= r)"
 11.1035 +by auto
 11.1036 +
 11.1037 +lemma lemma_st_part1a: "[| x \<in> HFinite;
 11.1038 +         isLub Reals {s. s \<in> Reals & s < x} t;
 11.1039 +         r \<in> Reals; 0 < r |]
 11.1040 +      ==> x + -t <= r"
 11.1041 +apply (blast intro!: lemma_hypreal_le_swap [THEN iffD1] lemma_st_part_le1)
 11.1042 +done
 11.1043 +
 11.1044 +lemma lemma_hypreal_le_swap2: "(t + -r <= x) = (-(x + -t) <= (r::hypreal))"
 11.1045 +by auto
 11.1046 +
 11.1047 +lemma lemma_st_part2a: "[| x \<in> HFinite;
 11.1048 +         isLub Reals {s. s \<in> Reals & s < x} t;
 11.1049 +         r \<in> Reals;  0 < r |]
 11.1050 +      ==> -(x + -t) <= r"
 11.1051 +apply (blast intro!: lemma_hypreal_le_swap2 [THEN iffD1] lemma_st_part_le2)
 11.1052 +done
 11.1053 +
 11.1054 +lemma lemma_SReal_ub: "(x::hypreal) \<in> Reals ==> isUb Reals {s. s \<in> Reals & s < x} x"
 11.1055 +by (auto intro: isUbI setleI order_less_imp_le)
 11.1056 +
 11.1057 +lemma lemma_SReal_lub: "(x::hypreal) \<in> Reals ==> isLub Reals {s. s \<in> Reals & s < x} x"
 11.1058 +apply (auto intro!: isLubI2 lemma_SReal_ub setgeI)
 11.1059 +apply (frule isUbD2a)
 11.1060 +apply (rule_tac x = x and y = y in linorder_cases)
 11.1061 +apply (auto intro!: order_less_imp_le)
 11.1062 +apply (drule SReal_dense, assumption, assumption, safe)
 11.1063 +apply (drule_tac y = r in isUbD)
 11.1064 +apply (auto dest: order_less_le_trans)
 11.1065 +done
 11.1066 +
 11.1067 +lemma lemma_st_part_not_eq1: "[| x \<in> HFinite;
 11.1068 +         isLub Reals {s. s \<in> Reals & s < x} t;
 11.1069 +         r \<in> Reals; 0 < r |]
 11.1070 +      ==> x + -t \<noteq> r"
 11.1071 +apply auto
 11.1072 +apply (frule isLubD1a [THEN SReal_minus])
 11.1073 +apply (drule SReal_add_cancel, assumption)
 11.1074 +apply (drule_tac x = x in lemma_SReal_lub)
 11.1075 +apply (drule hypreal_isLub_unique, assumption, auto)
 11.1076 +done
 11.1077 +
 11.1078 +lemma lemma_st_part_not_eq2: "[| x \<in> HFinite;
 11.1079 +         isLub Reals {s. s \<in> Reals & s < x} t;
 11.1080 +         r \<in> Reals; 0 < r |]
 11.1081 +      ==> -(x + -t) \<noteq> r"
 11.1082 +apply (auto simp add: minus_add_distrib)
 11.1083 +apply (frule isLubD1a)
 11.1084 +apply (drule SReal_add_cancel, assumption)
 11.1085 +apply (drule_tac x = "-x" in SReal_minus, simp)
 11.1086 +apply (drule_tac x = x in lemma_SReal_lub)
 11.1087 +apply (drule hypreal_isLub_unique, assumption, auto)
 11.1088 +done
 11.1089 +
 11.1090 +lemma lemma_st_part_major: "[| x \<in> HFinite;
 11.1091 +         isLub Reals {s. s \<in> Reals & s < x} t;
 11.1092 +         r \<in> Reals; 0 < r |]
 11.1093 +      ==> abs (x + -t) < r"
 11.1094 +apply (frule lemma_st_part1a)
 11.1095 +apply (frule_tac [4] lemma_st_part2a, auto)
 11.1096 +apply (drule order_le_imp_less_or_eq)+
 11.1097 +apply (auto dest: lemma_st_part_not_eq1 lemma_st_part_not_eq2 simp add: abs_less_iff)
 11.1098 +done
 11.1099 +
 11.1100 +lemma lemma_st_part_major2: "[| x \<in> HFinite;
 11.1101 +         isLub Reals {s. s \<in> Reals & s < x} t |]
 11.1102 +      ==> \<forall>r \<in> Reals. 0 < r --> abs (x + -t) < r"
 11.1103 +apply (blast dest!: lemma_st_part_major)
 11.1104 +done
 11.1105 +
 11.1106 +(*----------------------------------------------
 11.1107 +  Existence of real and Standard Part Theorem
 11.1108 + ----------------------------------------------*)
 11.1109 +lemma lemma_st_part_Ex: "x \<in> HFinite ==>
 11.1110 +      \<exists>t \<in> Reals. \<forall>r \<in> Reals. 0 < r --> abs (x + -t) < r"
 11.1111 +apply (frule lemma_st_part_lub, safe)
 11.1112 +apply (frule isLubD1a)
 11.1113 +apply (blast dest: lemma_st_part_major2)
 11.1114 +done
 11.1115 +
 11.1116 +lemma st_part_Ex:
 11.1117 +     "x \<in> HFinite ==> \<exists>t \<in> Reals. x @= t"
 11.1118 +apply (simp add: approx_def Infinitesimal_def)
 11.1119 +apply (drule lemma_st_part_Ex, auto)
 11.1120 +done
 11.1121 +
 11.1122 +(*--------------------------------
 11.1123 +  Unique real infinitely close
 11.1124 + -------------------------------*)
 11.1125 +lemma st_part_Ex1: "x \<in> HFinite ==> EX! t. t \<in> Reals & x @= t"
 11.1126 +apply (drule st_part_Ex, safe)
 11.1127 +apply (drule_tac [2] approx_sym, drule_tac [2] approx_sym, drule_tac [2] approx_sym)
 11.1128 +apply (auto intro!: approx_unique_real)
 11.1129 +done
 11.1130 +
 11.1131 +(*------------------------------------------------------------------
 11.1132 +       Finite and Infinite --- more theorems
 11.1133 + ------------------------------------------------------------------*)
 11.1134 +
 11.1135 +lemma HFinite_Int_HInfinite_empty: "HFinite Int HInfinite = {}"
 11.1136 +
 11.1137 +apply (simp add: HFinite_def HInfinite_def)
 11.1138 +apply (auto dest: order_less_trans)
 11.1139 +done
 11.1140 +declare HFinite_Int_HInfinite_empty [simp]
 11.1141 +
 11.1142 +lemma HFinite_not_HInfinite: 
 11.1143 +  assumes x: "x \<in> HFinite" shows "x \<notin> HInfinite"
 11.1144 +proof
 11.1145 +  assume x': "x \<in> HInfinite"
 11.1146 +  with x have "x \<in> HFinite \<inter> HInfinite" by blast
 11.1147 +  thus False by auto
 11.1148 +qed
 11.1149 +
 11.1150 +lemma not_HFinite_HInfinite: "x\<notin> HFinite ==> x \<in> HInfinite"
 11.1151 +apply (simp add: HInfinite_def HFinite_def, auto)
 11.1152 +apply (drule_tac x = "r + 1" in bspec)
 11.1153 +apply (auto simp add: SReal_add)
 11.1154 +done
 11.1155 +
 11.1156 +lemma HInfinite_HFinite_disj: "x \<in> HInfinite | x \<in> HFinite"
 11.1157 +by (blast intro: not_HFinite_HInfinite)
 11.1158 +
 11.1159 +lemma HInfinite_HFinite_iff: "(x \<in> HInfinite) = (x \<notin> HFinite)"
 11.1160 +by (blast dest: HFinite_not_HInfinite not_HFinite_HInfinite)
 11.1161 +
 11.1162 +lemma HFinite_HInfinite_iff: "(x \<in> HFinite) = (x \<notin> HInfinite)"
 11.1163 +apply (simp (no_asm) add: HInfinite_HFinite_iff)
 11.1164 +done
 11.1165 +
 11.1166 +(*------------------------------------------------------------------
 11.1167 +       Finite, Infinite and Infinitesimal --- more theorems
 11.1168 + ------------------------------------------------------------------*)
 11.1169 +
 11.1170 +lemma HInfinite_diff_HFinite_Infinitesimal_disj: "x \<notin> Infinitesimal ==> x \<in> HInfinite | x \<in> HFinite - Infinitesimal"
 11.1171 +by (fast intro: not_HFinite_HInfinite)
 11.1172 +
 11.1173 +lemma HFinite_inverse: "[| x \<in> HFinite; x \<notin> Infinitesimal |] ==> inverse x \<in> HFinite"
 11.1174 +apply (cut_tac x = "inverse x" in HInfinite_HFinite_disj)
 11.1175 +apply (auto dest!: HInfinite_inverse_Infinitesimal)
 11.1176 +done
 11.1177 +
 11.1178 +lemma HFinite_inverse2: "x \<in> HFinite - Infinitesimal ==> inverse x \<in> HFinite"
 11.1179 +by (blast intro: HFinite_inverse)
 11.1180 +
 11.1181 +(* stronger statement possible in fact *)
 11.1182 +lemma Infinitesimal_inverse_HFinite: "x \<notin> Infinitesimal ==> inverse(x) \<in> HFinite"
 11.1183 +apply (drule HInfinite_diff_HFinite_Infinitesimal_disj)
 11.1184 +apply (blast intro: HFinite_inverse HInfinite_inverse_Infinitesimal Infinitesimal_subset_HFinite [THEN subsetD])
 11.1185 +done
 11.1186 +
 11.1187 +lemma HFinite_not_Infinitesimal_inverse: "x \<in> HFinite - Infinitesimal ==> inverse x \<in> HFinite - Infinitesimal"
 11.1188 +apply (auto intro: Infinitesimal_inverse_HFinite)
 11.1189 +apply (drule Infinitesimal_HFinite_mult2, assumption)
 11.1190 +apply (simp add: not_Infinitesimal_not_zero hypreal_mult_inverse)
 11.1191 +done
 11.1192 +
 11.1193 +lemma approx_inverse: "[| x @= y; y \<in>  HFinite - Infinitesimal |]
 11.1194 +      ==> inverse x @= inverse y"
 11.1195 +apply (frule HFinite_diff_Infinitesimal_approx, assumption)
 11.1196 +apply (frule not_Infinitesimal_not_zero2)
 11.1197 +apply (frule_tac x = x in not_Infinitesimal_not_zero2)
 11.1198 +apply (drule HFinite_inverse2)+
 11.1199 +apply (drule approx_mult2, assumption, auto)
 11.1200 +apply (drule_tac c = "inverse x" in approx_mult1, assumption)
 11.1201 +apply (auto intro: approx_sym simp add: hypreal_mult_assoc)
 11.1202 +done
 11.1203 +
 11.1204 +(*Used for NSLIM_inverse, NSLIMSEQ_inverse*)
 11.1205 +lemmas hypreal_of_real_approx_inverse =  hypreal_of_real_HFinite_diff_Infinitesimal [THEN [2] approx_inverse]
 11.1206 +
 11.1207 +lemma inverse_add_Infinitesimal_approx: "[| x \<in> HFinite - Infinitesimal;
 11.1208 +         h \<in> Infinitesimal |] ==> inverse(x + h) @= inverse x"
 11.1209 +apply (auto intro: approx_inverse approx_sym Infinitesimal_add_approx_self)
 11.1210 +done
 11.1211 +
 11.1212 +lemma inverse_add_Infinitesimal_approx2: "[| x \<in> HFinite - Infinitesimal;
 11.1213 +         h \<in> Infinitesimal |] ==> inverse(h + x) @= inverse x"
 11.1214 +apply (rule hypreal_add_commute [THEN subst])
 11.1215 +apply (blast intro: inverse_add_Infinitesimal_approx)
 11.1216 +done
 11.1217 +
 11.1218 +lemma inverse_add_Infinitesimal_approx_Infinitesimal: "[| x \<in> HFinite - Infinitesimal;
 11.1219 +         h \<in> Infinitesimal |] ==> inverse(x + h) + -inverse x @= h"
 11.1220 +apply (rule approx_trans2)
 11.1221 +apply (auto intro: inverse_add_Infinitesimal_approx simp add: mem_infmal_iff approx_minus_iff [symmetric])
 11.1222 +done
 11.1223 +
 11.1224 +lemma Infinitesimal_square_iff: "(x \<in> Infinitesimal) = (x*x \<in> Infinitesimal)"
 11.1225 +apply (auto intro: Infinitesimal_mult)
 11.1226 +apply (rule ccontr, frule Infinitesimal_inverse_HFinite)
 11.1227 +apply (frule not_Infinitesimal_not_zero)
 11.1228 +apply (auto dest: Infinitesimal_HFinite_mult simp add: hypreal_mult_assoc)
 11.1229 +done
 11.1230 +declare Infinitesimal_square_iff [symmetric, simp]
 11.1231 +
 11.1232 +lemma HFinite_square_iff: "(x*x \<in> HFinite) = (x \<in> HFinite)"
 11.1233 +apply (auto intro: HFinite_mult)
 11.1234 +apply (auto dest: HInfinite_mult simp add: HFinite_HInfinite_iff)
 11.1235 +done
 11.1236 +declare HFinite_square_iff [simp]
 11.1237 +
 11.1238 +lemma HInfinite_square_iff: "(x*x \<in> HInfinite) = (x \<in> HInfinite)"
 11.1239 +by (auto simp add: HInfinite_HFinite_iff)
 11.1240 +declare HInfinite_square_iff [simp]
 11.1241 +
 11.1242 +lemma approx_HFinite_mult_cancel: "[| a: HFinite-Infinitesimal; a* w @= a*z |] ==> w @= z"
 11.1243 +apply safe
 11.1244 +apply (frule HFinite_inverse, assumption)
 11.1245 +apply (drule not_Infinitesimal_not_zero)
 11.1246 +apply (auto dest: approx_mult2 simp add: hypreal_mult_assoc [symmetric])
 11.1247 +done
 11.1248 +
 11.1249 +lemma approx_HFinite_mult_cancel_iff1: "a: HFinite-Infinitesimal ==> (a * w @= a * z) = (w @= z)"
 11.1250 +by (auto intro: approx_mult2 approx_HFinite_mult_cancel)
 11.1251 +
 11.1252 +lemma HInfinite_HFinite_add_cancel: "[| x + y \<in> HInfinite; y \<in> HFinite |] ==> x \<in> HInfinite"
 11.1253 +apply (rule ccontr)
 11.1254 +apply (drule HFinite_HInfinite_iff [THEN iffD2])
 11.1255 +apply (auto dest: HFinite_add simp add: HInfinite_HFinite_iff)
 11.1256 +done
 11.1257 +
 11.1258 +lemma HInfinite_HFinite_add: "[| x \<in> HInfinite; y \<in> HFinite |] ==> x + y \<in> HInfinite"
 11.1259 +apply (rule_tac y = "-y" in HInfinite_HFinite_add_cancel)
 11.1260 +apply (auto simp add: hypreal_add_assoc HFinite_minus_iff)
 11.1261 +done
 11.1262 +
 11.1263 +lemma HInfinite_ge_HInfinite: "[| x \<in> HInfinite; x <= y; 0 <= x |] ==> y \<in> HInfinite"
 11.1264 +by (auto intro: HFinite_bounded simp add: HInfinite_HFinite_iff)
 11.1265 +
 11.1266 +lemma Infinitesimal_inverse_HInfinite: "[| x \<in> Infinitesimal; x \<noteq> 0 |] ==> inverse x \<in> HInfinite"
 11.1267 +apply (rule ccontr, drule HFinite_HInfinite_iff [THEN iffD2])
 11.1268 +apply (auto dest: Infinitesimal_HFinite_mult2)
 11.1269 +done
 11.1270 +
 11.1271 +lemma HInfinite_HFinite_not_Infinitesimal_mult: "[| x \<in> HInfinite; y \<in> HFinite - Infinitesimal |]
 11.1272 +      ==> x * y \<in> HInfinite"
 11.1273 +apply (rule ccontr, drule HFinite_HInfinite_iff [THEN iffD2])
 11.1274 +apply (frule HFinite_Infinitesimal_not_zero)
 11.1275 +apply (drule HFinite_not_Infinitesimal_inverse)
 11.1276 +apply (safe, drule HFinite_mult)
 11.1277 +apply (auto simp add: hypreal_mult_assoc HFinite_HInfinite_iff)
 11.1278 +done
 11.1279 +
 11.1280 +lemma HInfinite_HFinite_not_Infinitesimal_mult2: "[| x \<in> HInfinite; y \<in> HFinite - Infinitesimal |]
 11.1281 +      ==> y * x \<in> HInfinite"
 11.1282 +apply (auto simp add: hypreal_mult_commute HInfinite_HFinite_not_Infinitesimal_mult)
 11.1283 +done
 11.1284 +
 11.1285 +lemma HInfinite_gt_SReal: "[| x \<in> HInfinite; 0 < x; y \<in> Reals |] ==> y < x"
 11.1286 +by (auto dest!: bspec simp add: HInfinite_def hrabs_def order_less_imp_le)
 11.1287 +
 11.1288 +lemma HInfinite_gt_zero_gt_one: "[| x \<in> HInfinite; 0 < x |] ==> 1 < x"
 11.1289 +by (auto intro: HInfinite_gt_SReal)
 11.1290 +
 11.1291 +
 11.1292 +lemma not_HInfinite_one: "1 \<notin> HInfinite"
 11.1293 +apply (simp (no_asm) add: HInfinite_HFinite_iff)
 11.1294 +done
 11.1295 +declare not_HInfinite_one [simp]
 11.1296 +
 11.1297 +(*------------------------------------------------------------------
 11.1298 +                  more about absolute value (hrabs)
 11.1299 + ------------------------------------------------------------------*)
 11.1300 +
 11.1301 +lemma approx_hrabs_disj: "abs x @= x | abs x @= -x"
 11.1302 +by (cut_tac x = x in hrabs_disj, auto)
 11.1303 +
 11.1304 +(*------------------------------------------------------------------
 11.1305 +                  Theorems about monads
 11.1306 + ------------------------------------------------------------------*)
 11.1307 +
 11.1308 +lemma monad_hrabs_Un_subset: "monad (abs x) <= monad(x) Un monad(-x)"
 11.1309 +by (rule_tac x1 = x in hrabs_disj [THEN disjE], auto)
 11.1310 +
 11.1311 +lemma Infinitesimal_monad_eq: "e \<in> Infinitesimal ==> monad (x+e) = monad x"
 11.1312 +by (fast intro!: Infinitesimal_add_approx_self [THEN approx_sym] approx_monad_iff [THEN iffD1])
 11.1313 +
 11.1314 +lemma mem_monad_iff: "(u \<in> monad x) = (-u \<in> monad (-x))"
 11.1315 +by (simp add: monad_def)
 11.1316 +
 11.1317 +lemma Infinitesimal_monad_zero_iff: "(x \<in> Infinitesimal) = (x \<in> monad 0)"
 11.1318 +by (auto intro: approx_sym simp add: monad_def mem_infmal_iff)
 11.1319 +
 11.1320 +lemma monad_zero_minus_iff: "(x \<in> monad 0) = (-x \<in> monad 0)"
 11.1321 +apply (simp (no_asm) add: Infinitesimal_monad_zero_iff [symmetric])
 11.1322 +done
 11.1323 +
 11.1324 +lemma monad_zero_hrabs_iff: "(x \<in> monad 0) = (abs x \<in> monad 0)"
 11.1325 +apply (rule_tac x1 = x in hrabs_disj [THEN disjE])
 11.1326 +apply (auto simp add: monad_zero_minus_iff [symmetric])
 11.1327 +done
 11.1328 +
 11.1329 +lemma mem_monad_self: "x \<in> monad x"
 11.1330 +by (simp add: monad_def)
 11.1331 +declare mem_monad_self [simp]
 11.1332 +
 11.1333 +(*------------------------------------------------------------------
 11.1334 +         Proof that x @= y ==> abs x @= abs y
 11.1335 + ------------------------------------------------------------------*)
 11.1336 +lemma approx_subset_monad: "x @= y ==> {x,y}<=monad x"
 11.1337 +apply (simp (no_asm))
 11.1338 +apply (simp add: approx_monad_iff)
 11.1339 +done
 11.1340 +
 11.1341 +lemma approx_subset_monad2: "x @= y ==> {x,y}<=monad y"
 11.1342 +apply (drule approx_sym)
 11.1343 +apply (fast dest: approx_subset_monad)
 11.1344 +done
 11.1345 +
 11.1346 +lemma mem_monad_approx: "u \<in> monad x ==> x @= u"
 11.1347 +by (simp add: monad_def)
 11.1348 +
 11.1349 +lemma approx_mem_monad: "x @= u ==> u \<in> monad x"
 11.1350 +by (simp add: monad_def)
 11.1351 +
 11.1352 +lemma approx_mem_monad2: "x @= u ==> x \<in> monad u"
 11.1353 +apply (simp add: monad_def)
 11.1354 +apply (blast intro!: approx_sym)
 11.1355 +done
 11.1356 +
 11.1357 +lemma approx_mem_monad_zero: "[| x @= y;x \<in> monad 0 |] ==> y \<in> monad 0"
 11.1358 +apply (drule mem_monad_approx)
 11.1359 +apply (fast intro: approx_mem_monad approx_trans)
 11.1360 +done
 11.1361 +
 11.1362 +lemma Infinitesimal_approx_hrabs: "[| x @= y; x \<in> Infinitesimal |] ==> abs x @= abs y"
 11.1363 +apply (drule Infinitesimal_monad_zero_iff [THEN iffD1])
 11.1364 +apply (blast intro: approx_mem_monad_zero monad_zero_hrabs_iff [THEN iffD1] mem_monad_approx approx_trans3)
 11.1365 +done
 11.1366 +
 11.1367 +lemma less_Infinitesimal_less: "[| 0 < x;  x \<notin>Infinitesimal;  e :Infinitesimal |] ==> e < x"
 11.1368 +apply (rule ccontr)
 11.1369 +apply (auto intro: Infinitesimal_zero [THEN [2] Infinitesimal_interval] 
 11.1370 +            dest!: order_le_imp_less_or_eq simp add: linorder_not_less)
 11.1371 +done
 11.1372 +
 11.1373 +lemma Ball_mem_monad_gt_zero: "[| 0 < x;  x \<notin> Infinitesimal; u \<in> monad x |] ==> 0 < u"
 11.1374 +apply (drule mem_monad_approx [THEN approx_sym])
 11.1375 +apply (erule bex_Infinitesimal_iff2 [THEN iffD2, THEN bexE])
 11.1376 +apply (drule_tac e = "-xa" in less_Infinitesimal_less, auto)
 11.1377 +done
 11.1378 +
 11.1379 +lemma Ball_mem_monad_less_zero: "[| x < 0; x \<notin> Infinitesimal; u \<in> monad x |] ==> u < 0"
 11.1380 +apply (drule mem_monad_approx [THEN approx_sym])
 11.1381 +apply (erule bex_Infinitesimal_iff [THEN iffD2, THEN bexE])
 11.1382 +apply (cut_tac x = "-x" and e = xa in less_Infinitesimal_less, auto)
 11.1383 +done
 11.1384 +
 11.1385 +lemma lemma_approx_gt_zero: "[|0 < x; x \<notin> Infinitesimal; x @= y|] ==> 0 < y"
 11.1386 +by (blast dest: Ball_mem_monad_gt_zero approx_subset_monad)
 11.1387 +
 11.1388 +lemma lemma_approx_less_zero: "[|x < 0; x \<notin> Infinitesimal; x @= y|] ==> y < 0"
 11.1389 +by (blast dest: Ball_mem_monad_less_zero approx_subset_monad)
 11.1390 +
 11.1391 +lemma approx_hrabs1: "[| x @= y; x < 0; x \<notin> Infinitesimal |] ==> abs x @= abs y"
 11.1392 +apply (frule lemma_approx_less_zero)
 11.1393 +apply (assumption+)
 11.1394 +apply (simp add: abs_if) 
 11.1395 +done
 11.1396 +
 11.1397 +lemma approx_hrabs2: "[| x @= y; 0 < x; x \<notin> Infinitesimal |] ==> abs x @= abs y"
 11.1398 +apply (frule lemma_approx_gt_zero)
 11.1399 +apply (assumption+)
 11.1400 +apply (simp add: abs_if) 
 11.1401 +done
 11.1402 +
 11.1403 +lemma approx_hrabs: "x @= y ==> abs x @= abs y"
 11.1404 +apply (rule_tac Q = "x \<in> Infinitesimal" in excluded_middle [THEN disjE])
 11.1405 +apply (rule_tac x1 = x and y1 = 0 in linorder_less_linear [THEN disjE])
 11.1406 +apply (auto intro: approx_hrabs1 approx_hrabs2 Infinitesimal_approx_hrabs)
 11.1407 +done
 11.1408 +
 11.1409 +lemma approx_hrabs_zero_cancel: "abs(x) @= 0 ==> x @= 0"
 11.1410 +apply (cut_tac x = x in hrabs_disj)
 11.1411 +apply (auto dest: approx_minus)
 11.1412 +done
 11.1413 +
 11.1414 +lemma approx_hrabs_add_Infinitesimal: "e \<in> Infinitesimal ==> abs x @= abs(x+e)"
 11.1415 +by (fast intro: approx_hrabs Infinitesimal_add_approx_self)
 11.1416 +
 11.1417 +lemma approx_hrabs_add_minus_Infinitesimal: "e \<in> Infinitesimal ==> abs x @= abs(x + -e)"
 11.1418 +by (fast intro: approx_hrabs Infinitesimal_add_minus_approx_self)
 11.1419 +
 11.1420 +lemma hrabs_add_Infinitesimal_cancel: "[| e \<in> Infinitesimal; e' \<in> Infinitesimal;
 11.1421 +         abs(x+e) = abs(y+e')|] ==> abs x @= abs y"
 11.1422 +apply (drule_tac x = x in approx_hrabs_add_Infinitesimal)
 11.1423 +apply (drule_tac x = y in approx_hrabs_add_Infinitesimal)
 11.1424 +apply (auto intro: approx_trans2)
 11.1425 +done
 11.1426 +
 11.1427 +lemma hrabs_add_minus_Infinitesimal_cancel: "[| e \<in> Infinitesimal; e' \<in> Infinitesimal;
 11.1428 +         abs(x + -e) = abs(y + -e')|] ==> abs x @= abs y"
 11.1429 +apply (drule_tac x = x in approx_hrabs_add_minus_Infinitesimal)
 11.1430 +apply (drule_tac x = y in approx_hrabs_add_minus_Infinitesimal)
 11.1431 +apply (auto intro: approx_trans2)
 11.1432 +done
 11.1433 +
 11.1434 +lemma hypreal_less_minus_iff: "((x::hypreal) < y) = (0 < y + -x)"
 11.1435 +by arith
 11.1436  
 11.1437 -   (*standard real numbers as a subset of the hyperreals*)
 11.1438 -   SReal_def      "Reals == {x. EX r. x = hypreal_of_real r}"
 11.1439 +(* interesting slightly counterintuitive theorem: necessary
 11.1440 +   for proving that an open interval is an NS open set
 11.1441 +*)
 11.1442 +lemma Infinitesimal_add_hypreal_of_real_less:
 11.1443 +     "[| x < y;  u \<in> Infinitesimal |]
 11.1444 +      ==> hypreal_of_real x + u < hypreal_of_real y"
 11.1445 +apply (simp add: Infinitesimal_def)
 11.1446 +apply (drule hypreal_of_real_less_iff [THEN iffD2])
 11.1447 +apply (drule_tac x = "hypreal_of_real y + -hypreal_of_real x" in bspec)
 11.1448 +apply (auto simp add: hypreal_add_commute abs_less_iff SReal_add SReal_minus)
 11.1449 +done
 11.1450 +
 11.1451 +lemma Infinitesimal_add_hrabs_hypreal_of_real_less: "[| x \<in> Infinitesimal; abs(hypreal_of_real r) < hypreal_of_real y |]
 11.1452 +      ==> abs (hypreal_of_real r + x) < hypreal_of_real y"
 11.1453 +apply (drule_tac x = "hypreal_of_real r" in approx_hrabs_add_Infinitesimal)
 11.1454 +apply (drule approx_sym [THEN bex_Infinitesimal_iff2 [THEN iffD2]])
 11.1455 +apply (auto intro!: Infinitesimal_add_hypreal_of_real_less simp add: hypreal_of_real_hrabs)
 11.1456 +done
 11.1457 +
 11.1458 +lemma Infinitesimal_add_hrabs_hypreal_of_real_less2: "[| x \<in> Infinitesimal;  abs(hypreal_of_real r) < hypreal_of_real y |]
 11.1459 +      ==> abs (x + hypreal_of_real r) < hypreal_of_real y"
 11.1460 +apply (rule hypreal_add_commute [THEN subst])
 11.1461 +apply (erule Infinitesimal_add_hrabs_hypreal_of_real_less, assumption)
 11.1462 +done
 11.1463 +
 11.1464 +lemma hypreal_of_real_le_add_Infininitesimal_cancel: "[| u \<in> Infinitesimal; v \<in> Infinitesimal;
 11.1465 +         hypreal_of_real x + u <= hypreal_of_real y + v |]
 11.1466 +      ==> hypreal_of_real x <= hypreal_of_real y"
 11.1467 +apply (simp add: linorder_not_less [symmetric], auto)
 11.1468 +apply (drule_tac u = "v-u" in Infinitesimal_add_hypreal_of_real_less)
 11.1469 +apply (auto simp add: Infinitesimal_diff)
 11.1470 +done
 11.1471 +
 11.1472 +lemma hypreal_of_real_le_add_Infininitesimal_cancel2: "[| u \<in> Infinitesimal; v \<in> Infinitesimal;
 11.1473 +         hypreal_of_real x + u <= hypreal_of_real y + v |]
 11.1474 +      ==> x <= y"
 11.1475 +apply (blast intro!: hypreal_of_real_le_iff [THEN iffD1] hypreal_of_real_le_add_Infininitesimal_cancel)
 11.1476 +done
 11.1477 +
 11.1478 +lemma hypreal_of_real_less_Infinitesimal_le_zero: "[| hypreal_of_real x < e; e \<in> Infinitesimal |] ==> hypreal_of_real x <= 0"
 11.1479 +apply (rule linorder_not_less [THEN iffD1], safe)
 11.1480 +apply (drule Infinitesimal_interval)
 11.1481 +apply (drule_tac [4] SReal_hypreal_of_real [THEN SReal_Infinitesimal_zero], auto)
 11.1482 +done
 11.1483 +
 11.1484 +(*used once, in Lim/NSDERIV_inverse*)
 11.1485 +lemma Infinitesimal_add_not_zero: "[| h \<in> Infinitesimal; x \<noteq> 0 |] ==> hypreal_of_real x + h \<noteq> 0"
 11.1486 +apply auto
 11.1487 +apply (subgoal_tac "h = - hypreal_of_real x", auto)
 11.1488 +done
 11.1489 +
 11.1490 +lemma Infinitesimal_square_cancel: "x*x + y*y \<in> Infinitesimal ==> x*x \<in> Infinitesimal"
 11.1491 +apply (rule Infinitesimal_interval2)
 11.1492 +apply (rule_tac [3] zero_le_square, assumption)
 11.1493 +apply (auto simp add: zero_le_square)
 11.1494 +done
 11.1495 +declare Infinitesimal_square_cancel [simp]
 11.1496 +
 11.1497 +lemma HFinite_square_cancel: "x*x + y*y \<in> HFinite ==> x*x \<in> HFinite"
 11.1498 +apply (rule HFinite_bounded, assumption)
 11.1499 +apply (auto simp add: zero_le_square)
 11.1500 +done
 11.1501 +declare HFinite_square_cancel [simp]
 11.1502 +
 11.1503 +lemma Infinitesimal_square_cancel2: "x*x + y*y \<in> Infinitesimal ==> y*y \<in> Infinitesimal"
 11.1504 +apply (rule Infinitesimal_square_cancel)
 11.1505 +apply (rule hypreal_add_commute [THEN subst])
 11.1506 +apply (simp (no_asm))
 11.1507 +done
 11.1508 +declare Infinitesimal_square_cancel2 [simp]
 11.1509 +
 11.1510 +lemma HFinite_square_cancel2: "x*x + y*y \<in> HFinite ==> y*y \<in> HFinite"
 11.1511 +apply (rule HFinite_square_cancel)
 11.1512 +apply (rule hypreal_add_commute [THEN subst])
 11.1513 +apply (simp (no_asm))
 11.1514 +done
 11.1515 +declare HFinite_square_cancel2 [simp]
 11.1516 +
 11.1517 +lemma Infinitesimal_sum_square_cancel: "x*x + y*y + z*z \<in> Infinitesimal ==> x*x \<in> Infinitesimal"
 11.1518 +apply (rule Infinitesimal_interval2, assumption)
 11.1519 +apply (rule_tac [2] zero_le_square, simp)
 11.1520 +apply (insert zero_le_square [of y]) 
 11.1521 +apply (insert zero_le_square [of z], simp)
 11.1522 +done
 11.1523 +declare Infinitesimal_sum_square_cancel [simp]
 11.1524 +
 11.1525 +lemma HFinite_sum_square_cancel: "x*x + y*y + z*z \<in> HFinite ==> x*x \<in> HFinite"
 11.1526 +apply (rule HFinite_bounded, assumption)
 11.1527 +apply (rule_tac [2] zero_le_square)
 11.1528 +apply (insert zero_le_square [of y]) 
 11.1529 +apply (insert zero_le_square [of z], simp)
 11.1530 +done
 11.1531 +declare HFinite_sum_square_cancel [simp]
 11.1532 +
 11.1533 +lemma Infinitesimal_sum_square_cancel2: "y*y + x*x + z*z \<in> Infinitesimal ==> x*x \<in> Infinitesimal"
 11.1534 +apply (rule Infinitesimal_sum_square_cancel)
 11.1535 +apply (simp add: add_ac)
 11.1536 +done
 11.1537 +declare Infinitesimal_sum_square_cancel2 [simp]
 11.1538 +
 11.1539 +lemma HFinite_sum_square_cancel2: "y*y + x*x + z*z \<in> HFinite ==> x*x \<in> HFinite"
 11.1540 +apply (rule HFinite_sum_square_cancel)
 11.1541 +apply (simp add: add_ac)
 11.1542 +done
 11.1543 +declare HFinite_sum_square_cancel2 [simp]
 11.1544 +
 11.1545 +lemma Infinitesimal_sum_square_cancel3: "z*z + y*y + x*x \<in> Infinitesimal ==> x*x \<in> Infinitesimal"
 11.1546 +apply (rule Infinitesimal_sum_square_cancel)
 11.1547 +apply (simp add: add_ac)
 11.1548 +done
 11.1549 +declare Infinitesimal_sum_square_cancel3 [simp]
 11.1550 +
 11.1551 +lemma HFinite_sum_square_cancel3: "z*z + y*y + x*x \<in> HFinite ==> x*x \<in> HFinite"
 11.1552 +apply (rule HFinite_sum_square_cancel)
 11.1553 +apply (simp add: add_ac)
 11.1554 +done
 11.1555 +declare HFinite_sum_square_cancel3 [simp]
 11.1556 +
 11.1557 +lemma monad_hrabs_less: "[| y \<in> monad x; 0 < hypreal_of_real e |]
 11.1558 +      ==> abs (y + -x) < hypreal_of_real e"
 11.1559 +apply (drule mem_monad_approx [THEN approx_sym])
 11.1560 +apply (drule bex_Infinitesimal_iff [THEN iffD2])
 11.1561 +apply (auto dest!: InfinitesimalD)
 11.1562 +done
 11.1563 +
 11.1564 +lemma mem_monad_SReal_HFinite: "x \<in> monad (hypreal_of_real  a) ==> x \<in> HFinite"
 11.1565 +apply (drule mem_monad_approx [THEN approx_sym])
 11.1566 +apply (drule bex_Infinitesimal_iff2 [THEN iffD2])
 11.1567 +apply (safe dest!: Infinitesimal_subset_HFinite [THEN subsetD])
 11.1568 +apply (erule SReal_hypreal_of_real [THEN SReal_subset_HFinite [THEN subsetD], THEN HFinite_add])
 11.1569 +done
 11.1570 +
 11.1571 +(*------------------------------------------------------------------
 11.1572 +              Theorems about standard part
 11.1573 + ------------------------------------------------------------------*)
 11.1574 +
 11.1575 +lemma st_approx_self: "x \<in> HFinite ==> st x @= x"
 11.1576 +apply (simp add: st_def)
 11.1577 +apply (frule st_part_Ex, safe)
 11.1578 +apply (rule someI2)
 11.1579 +apply (auto intro: approx_sym)
 11.1580 +done
 11.1581 +
 11.1582 +lemma st_SReal: "x \<in> HFinite ==> st x \<in> Reals"
 11.1583 +apply (simp add: st_def)
 11.1584 +apply (frule st_part_Ex, safe)
 11.1585 +apply (rule someI2)
 11.1586 +apply (auto intro: approx_sym)
 11.1587 +done
 11.1588 +
 11.1589 +lemma st_HFinite: "x \<in> HFinite ==> st x \<in> HFinite"
 11.1590 +by (erule st_SReal [THEN SReal_subset_HFinite [THEN subsetD]])
 11.1591 +
 11.1592 +lemma st_SReal_eq: "x \<in> Reals ==> st x = x"
 11.1593 +apply (simp add: st_def)
 11.1594 +apply (rule some_equality)
 11.1595 +apply (fast intro: SReal_subset_HFinite [THEN subsetD])
 11.1596 +apply (blast dest: SReal_approx_iff [THEN iffD1])
 11.1597 +done
 11.1598 +
 11.1599 +(* ???should be added to simpset *)
 11.1600 +lemma st_hypreal_of_real: "st (hypreal_of_real x) = hypreal_of_real x"
 11.1601 +by (rule SReal_hypreal_of_real [THEN st_SReal_eq])
 11.1602 +
 11.1603 +lemma st_eq_approx: "[| x \<in> HFinite; y \<in> HFinite; st x = st y |] ==> x @= y"
 11.1604 +by (auto dest!: st_approx_self elim!: approx_trans3)
 11.1605 +
 11.1606 +lemma approx_st_eq: 
 11.1607 +  assumes "x \<in> HFinite" and "y \<in> HFinite" and "x @= y" 
 11.1608 +  shows "st x = st y"
 11.1609 +proof -
 11.1610 +  have "st x @= x" "st y @= y" "st x \<in> Reals" "st y \<in> Reals"
 11.1611 +    by (simp_all add: st_approx_self st_SReal prems) 
 11.1612 +  with prems show ?thesis 
 11.1613 +    by (fast elim: approx_trans approx_trans2 SReal_approx_iff [THEN iffD1])
 11.1614 +qed
 11.1615 +
 11.1616 +lemma st_eq_approx_iff: "[| x \<in> HFinite; y \<in> HFinite|]
 11.1617 +                   ==> (x @= y) = (st x = st y)"
 11.1618 +by (blast intro: approx_st_eq st_eq_approx)
 11.1619 +
 11.1620 +lemma st_Infinitesimal_add_SReal: "[| x \<in> Reals; e \<in> Infinitesimal |] ==> st(x + e) = x"
 11.1621 +apply (frule st_SReal_eq [THEN subst])
 11.1622 +prefer 2 apply assumption
 11.1623 +apply (frule SReal_subset_HFinite [THEN subsetD])
 11.1624 +apply (frule Infinitesimal_subset_HFinite [THEN subsetD])
 11.1625 +apply (drule st_SReal_eq)
 11.1626 +apply (rule approx_st_eq)
 11.1627 +apply (auto intro: HFinite_add simp add: Infinitesimal_add_approx_self [THEN approx_sym])
 11.1628 +done
 11.1629 +
 11.1630 +lemma st_Infinitesimal_add_SReal2: "[| x \<in> Reals; e \<in> Infinitesimal |]
 11.1631 +      ==> st(e + x) = x"
 11.1632 +apply (rule hypreal_add_commute [THEN subst])
 11.1633 +apply (blast intro!: st_Infinitesimal_add_SReal)
 11.1634 +done
 11.1635 +
 11.1636 +lemma HFinite_st_Infinitesimal_add: "x \<in> HFinite ==>
 11.1637 +      \<exists>e \<in> Infinitesimal. x = st(x) + e"
 11.1638 +apply (blast dest!: st_approx_self [THEN approx_sym] bex_Infinitesimal_iff2 [THEN iffD2])
 11.1639 +done
 11.1640 +
 11.1641 +lemma st_add: 
 11.1642 +  assumes x: "x \<in> HFinite" and y: "y \<in> HFinite"
 11.1643 +  shows "st (x + y) = st(x) + st(y)"
 11.1644 +proof -
 11.1645 +  from HFinite_st_Infinitesimal_add [OF x]
 11.1646 +  obtain ex where ex: "ex \<in> Infinitesimal" "st x + ex = x" 
 11.1647 +    by (blast intro: sym)
 11.1648 +  from HFinite_st_Infinitesimal_add [OF y]
 11.1649 +  obtain ey where ey: "ey \<in> Infinitesimal" "st y + ey = y" 
 11.1650 +    by (blast intro: sym)
 11.1651 +  have "st (x + y) = st ((st x + ex) + (st y + ey))"
 11.1652 +    by (simp add: ex ey) 
 11.1653 +  also have "... = st ((ex + ey) + (st x + st y))" by (simp add: add_ac)
 11.1654 +  also have "... = st x + st y" 
 11.1655 +    by (simp add: prems st_SReal SReal_add Infinitesimal_add 
 11.1656 +                  st_Infinitesimal_add_SReal2) 
 11.1657 +  finally show ?thesis .
 11.1658 +qed
 11.1659 +
 11.1660 +lemma st_number_of: "st (number_of w) = number_of w"
 11.1661 +by (rule SReal_number_of [THEN st_SReal_eq])
 11.1662 +declare st_number_of [simp]
 11.1663 +
 11.1664 +(*the theorem above for the special cases of zero and one*)
 11.1665 +lemma [simp]: "st 0 = 0" "st 1 = 1"
 11.1666 +by (simp_all add: st_SReal_eq)
 11.1667 +
 11.1668 +lemma st_minus: assumes "y \<in> HFinite" shows "st(-y) = -st(y)"
 11.1669 +proof -
 11.1670 +  have "st (- y) + st y = 0"
 11.1671 +   by (simp add: prems st_add [symmetric] HFinite_minus_iff) 
 11.1672 +  thus ?thesis by arith
 11.1673 +qed
 11.1674 +
 11.1675 +lemma st_diff:
 11.1676 +     "[| x \<in> HFinite; y \<in> HFinite |] ==> st (x-y) = st(x) - st(y)"
 11.1677 +apply (simp add: hypreal_diff_def)
 11.1678 +apply (frule_tac y1 = y in st_minus [symmetric])
 11.1679 +apply (drule_tac x1 = y in HFinite_minus_iff [THEN iffD2])
 11.1680 +apply (simp (no_asm_simp) add: st_add)
 11.1681 +done
 11.1682 +
 11.1683 +(* lemma *)
 11.1684 +lemma lemma_st_mult: "[| x \<in> HFinite; y \<in> HFinite;
 11.1685 +         e \<in> Infinitesimal;
 11.1686 +         ea \<in> Infinitesimal |]
 11.1687 +       ==> e*y + x*ea + e*ea \<in> Infinitesimal"
 11.1688 +apply (frule_tac x = e and y = y in Infinitesimal_HFinite_mult)
 11.1689 +apply (frule_tac [2] x = ea and y = x in Infinitesimal_HFinite_mult)
 11.1690 +apply (drule_tac [3] Infinitesimal_mult)
 11.1691 +apply (auto intro: Infinitesimal_add simp add: add_ac mult_ac)
 11.1692 +done
 11.1693 +
 11.1694 +lemma st_mult: "[| x \<in> HFinite; y \<in> HFinite |]
 11.1695 +               ==> st (x * y) = st(x) * st(y)"
 11.1696 +apply (frule HFinite_st_Infinitesimal_add)
 11.1697 +apply (frule_tac x = y in HFinite_st_Infinitesimal_add, safe)
 11.1698 +apply (subgoal_tac "st (x * y) = st ((st x + e) * (st y + ea))")
 11.1699 +apply (drule_tac [2] sym, drule_tac [2] sym)
 11.1700 + prefer 2 apply simp 
 11.1701 +apply (erule_tac V = "x = st x + e" in thin_rl)
 11.1702 +apply (erule_tac V = "y = st y + ea" in thin_rl)
 11.1703 +apply (simp add: left_distrib right_distrib)
 11.1704 +apply (drule st_SReal)+
 11.1705 +apply (simp (no_asm_use) add: hypreal_add_assoc)
 11.1706 +apply (rule st_Infinitesimal_add_SReal)
 11.1707 +apply (blast intro!: SReal_mult)
 11.1708 +apply (drule SReal_subset_HFinite [THEN subsetD])+
 11.1709 +apply (rule hypreal_add_assoc [THEN subst])
 11.1710 +apply (blast intro!: lemma_st_mult)
 11.1711 +done
 11.1712 +
 11.1713 +lemma st_Infinitesimal: "x \<in> Infinitesimal ==> st x = 0"
 11.1714 +apply (subst hypreal_numeral_0_eq_0 [symmetric])
 11.1715 +apply (rule st_number_of [THEN subst])
 11.1716 +apply (rule approx_st_eq)
 11.1717 +apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD] simp add: mem_infmal_iff [symmetric])
 11.1718 +done
 11.1719 +
 11.1720 +lemma st_not_Infinitesimal: "st(x) \<noteq> 0 ==> x \<notin> Infinitesimal"
 11.1721 +by (fast intro: st_Infinitesimal)
 11.1722 +
 11.1723 +lemma st_inverse: "[| x \<in> HFinite; st x \<noteq> 0 |]
 11.1724 +      ==> st(inverse x) = inverse (st x)"
 11.1725 +apply (rule_tac c1 = "st x" in hypreal_mult_left_cancel [THEN iffD1])
 11.1726 +apply (auto simp add: st_mult [symmetric] st_not_Infinitesimal HFinite_inverse)
 11.1727 +apply (subst hypreal_mult_inverse, auto)
 11.1728 +done
 11.1729 +
 11.1730 +lemma st_divide: "[| x \<in> HFinite; y \<in> HFinite; st y \<noteq> 0 |]
 11.1731 +      ==> st(x/y) = (st x) / (st y)"
 11.1732 +apply (auto simp add: hypreal_divide_def st_mult st_not_Infinitesimal HFinite_inverse st_inverse)
 11.1733 +done
 11.1734 +declare st_divide [simp]
 11.1735 +
 11.1736 +lemma st_idempotent: "x \<in> HFinite ==> st(st(x)) = st(x)"
 11.1737 +by (blast intro: st_HFinite st_approx_self approx_st_eq)
 11.1738 +declare st_idempotent [simp]
 11.1739 +
 11.1740 +(*** lemmas ***)
 11.1741 +lemma Infinitesimal_add_st_less: "[| x \<in> HFinite; y \<in> HFinite;
 11.1742 +         u \<in> Infinitesimal; st x < st y
 11.1743 +      |] ==> st x + u < st y"
 11.1744 +apply (drule st_SReal)+
 11.1745 +apply (auto intro!: Infinitesimal_add_hypreal_of_real_less simp add: SReal_iff)
 11.1746 +done
 11.1747 +
 11.1748 +lemma Infinitesimal_add_st_le_cancel: "[| x \<in> HFinite; y \<in> HFinite;
 11.1749 +         u \<in> Infinitesimal; st x <= st y + u
 11.1750 +      |] ==> st x <= st y"
 11.1751 +apply (simp add: linorder_not_less [symmetric])
 11.1752 +apply (auto dest: Infinitesimal_add_st_less)
 11.1753 +done
 11.1754 +
 11.1755 +lemma st_le: "[| x \<in> HFinite; y \<in> HFinite; x <= y |] ==> st(x) <= st(y)"
 11.1756 +apply (frule HFinite_st_Infinitesimal_add)
 11.1757 +apply (rotate_tac 1)
 11.1758 +apply (frule HFinite_st_Infinitesimal_add, safe)
 11.1759 +apply (rule Infinitesimal_add_st_le_cancel)
 11.1760 +apply (rule_tac [3] x = ea and y = e in Infinitesimal_diff)
 11.1761 +apply (auto simp add: hypreal_add_assoc [symmetric])
 11.1762 +done
 11.1763 +
 11.1764 +lemma st_zero_le: "[| 0 <= x;  x \<in> HFinite |] ==> 0 <= st x"
 11.1765 +apply (subst hypreal_numeral_0_eq_0 [symmetric])
 11.1766 +apply (rule st_number_of [THEN subst])
 11.1767 +apply (rule st_le, auto)
 11.1768 +done
 11.1769 +
 11.1770 +lemma st_zero_ge: "[| x <= 0;  x \<in> HFinite |] ==> st x <= 0"
 11.1771 +apply (subst hypreal_numeral_0_eq_0 [symmetric])
 11.1772 +apply (rule st_number_of [THEN subst])
 11.1773 +apply (rule st_le, auto)
 11.1774 +done
 11.1775 +
 11.1776 +lemma st_hrabs: "x \<in> HFinite ==> abs(st x) = st(abs x)"
 11.1777 +apply (simp add: linorder_not_le st_zero_le abs_if st_minus
 11.1778 +   linorder_not_less)
 11.1779 +apply (auto dest!: st_zero_ge [OF order_less_imp_le]) 
 11.1780 +done
 11.1781 +
 11.1782 +
 11.1783 +
 11.1784 +(*--------------------------------------------------------------------
 11.1785 +   Alternative definitions for HFinite using Free ultrafilter
 11.1786 + --------------------------------------------------------------------*)
 11.1787 +
 11.1788 +lemma FreeUltrafilterNat_Rep_hypreal: "[| X \<in> Rep_hypreal x; Y \<in> Rep_hypreal x |]
 11.1789 +      ==> {n. X n = Y n} \<in> FreeUltrafilterNat"
 11.1790 +apply (rule_tac z = x in eq_Abs_hypreal, auto, ultra)
 11.1791 +done
 11.1792 +
 11.1793 +lemma HFinite_FreeUltrafilterNat:
 11.1794 +    "x \<in> HFinite 
 11.1795 +     ==> \<exists>X \<in> Rep_hypreal x. \<exists>u. {n. abs (X n) < u} \<in> FreeUltrafilterNat"
 11.1796 +apply (rule eq_Abs_hypreal [of x])
 11.1797 +apply (auto simp add: HFinite_def abs_less_iff minus_less_iff [of x] 
 11.1798 +              hypreal_less SReal_iff hypreal_minus hypreal_of_real_def)
 11.1799 +apply (rule_tac x=x in bexI) 
 11.1800 +apply (rule_tac x=y in exI, auto, ultra)
 11.1801 +done
 11.1802 +
 11.1803 +lemma FreeUltrafilterNat_HFinite:
 11.1804 +     "\<exists>X \<in> Rep_hypreal x.
 11.1805 +       \<exists>u. {n. abs (X n) < u} \<in> FreeUltrafilterNat
 11.1806 +       ==>  x \<in> HFinite"
 11.1807 +apply (rule eq_Abs_hypreal [of x])
 11.1808 +apply (auto simp add: HFinite_def abs_less_iff minus_less_iff [of x])
 11.1809 +apply (rule_tac x = "hypreal_of_real u" in bexI)
 11.1810 +apply (auto simp add: hypreal_less SReal_iff hypreal_minus hypreal_of_real_def, ultra+)
 11.1811 +done
 11.1812 +
 11.1813 +lemma HFinite_FreeUltrafilterNat_iff: "(x \<in> HFinite) = (\<exists>X \<in> Rep_hypreal x.
 11.1814 +           \<exists>u. {n. abs (X n) < u} \<in> FreeUltrafilterNat)"
 11.1815 +apply (blast intro!: HFinite_FreeUltrafilterNat FreeUltrafilterNat_HFinite)
 11.1816 +done
 11.1817 +
 11.1818 +(*--------------------------------------------------------------------
 11.1819 +   Alternative definitions for HInfinite using Free ultrafilter
 11.1820 + --------------------------------------------------------------------*)
 11.1821 +lemma lemma_Compl_eq: "- {n. (u::real) < abs (xa n)} = {n. abs (xa n) <= u}"
 11.1822 +by auto
 11.1823 +
 11.1824 +lemma lemma_Compl_eq2: "- {n. abs (xa n) < (u::real)} = {n. u <= abs (xa n)}"
 11.1825 +by auto
 11.1826 +
 11.1827 +lemma lemma_Int_eq1: "{n. abs (xa n) <= (u::real)} Int {n. u <= abs (xa n)}
 11.1828 +          = {n. abs(xa n) = u}"
 11.1829 +apply auto
 11.1830 +done
 11.1831 +
 11.1832 +lemma lemma_FreeUltrafilterNat_one: "{n. abs (xa n) = u} <= {n. abs (xa n) < u + (1::real)}"
 11.1833 +by auto
 11.1834 +
 11.1835 +(*-------------------------------------
 11.1836 +  Exclude this type of sets from free
 11.1837 +  ultrafilter for Infinite numbers!
 11.1838 + -------------------------------------*)
 11.1839 +lemma FreeUltrafilterNat_const_Finite: "[| xa: Rep_hypreal x;
 11.1840 +                  {n. abs (xa n) = u} \<in> FreeUltrafilterNat
 11.1841 +               |] ==> x \<in> HFinite"
 11.1842 +apply (rule FreeUltrafilterNat_HFinite)
 11.1843 +apply (rule_tac x = xa in bexI)
 11.1844 +apply (rule_tac x = "u + 1" in exI)
 11.1845 +apply (ultra, assumption)
 11.1846 +done
 11.1847 +
 11.1848 +lemma HInfinite_FreeUltrafilterNat:
 11.1849 +     "x \<in> HInfinite ==> \<exists>X \<in> Rep_hypreal x.
 11.1850 +           \<forall>u. {n. u < abs (X n)} \<in> FreeUltrafilterNat"
 11.1851 +apply (frule HInfinite_HFinite_iff [THEN iffD1])
 11.1852 +apply (cut_tac x = x in Rep_hypreal_nonempty)
 11.1853 +apply (auto simp del: Rep_hypreal_nonempty simp add: HFinite_FreeUltrafilterNat_iff Bex_def)
 11.1854 +apply (drule spec)+
 11.1855 +apply auto
 11.1856 +apply (drule_tac x = u in spec)
 11.1857 +apply (drule FreeUltrafilterNat_Compl_mem)+
 11.1858 +apply (drule FreeUltrafilterNat_Int, assumption)
 11.1859 +apply (simp add: lemma_Compl_eq lemma_Compl_eq2 lemma_Int_eq1)
 11.1860 +apply (auto dest: FreeUltrafilterNat_const_Finite simp
 11.1861 +      add: HInfinite_HFinite_iff [THEN iffD1])
 11.1862 +done
 11.1863 +
 11.1864 +(* yet more lemmas! *)
 11.1865 +lemma lemma_Int_HI: "{n. abs (Xa n) < u} Int {n. X n = Xa n}
 11.1866 +          <= {n. abs (X n) < (u::real)}"
 11.1867 +apply auto
 11.1868 +done
 11.1869 +
 11.1870 +lemma lemma_Int_HIa: "{n. u < abs (X n)} Int {n. abs (X n) < (u::real)} = {}"
 11.1871 +by (auto intro: order_less_asym)
 11.1872 +
 11.1873 +lemma FreeUltrafilterNat_HInfinite: "\<exists>X \<in> Rep_hypreal x. \<forall>u.
 11.1874 +               {n. u < abs (X n)} \<in> FreeUltrafilterNat
 11.1875 +               ==>  x \<in> HInfinite"
 11.1876 +apply (rule HInfinite_HFinite_iff [THEN iffD2])
 11.1877 +apply (safe, drule HFinite_FreeUltrafilterNat, auto)
 11.1878 +apply (drule_tac x = u in spec)
 11.1879 +apply (drule FreeUltrafilterNat_Rep_hypreal, assumption)
 11.1880 +apply (drule_tac Y = "{n. X n = Xa n}" in FreeUltrafilterNat_Int, simp) 
 11.1881 +apply (drule lemma_Int_HI [THEN [2] FreeUltrafilterNat_subset])
 11.1882 +apply (drule_tac Y = "{n. abs (X n) < u}" in FreeUltrafilterNat_Int)
 11.1883 +apply (auto simp add: lemma_Int_HIa FreeUltrafilterNat_empty)
 11.1884 +done
 11.1885 +
 11.1886 +lemma HInfinite_FreeUltrafilterNat_iff: "(x \<in> HInfinite) = (\<exists>X \<in> Rep_hypreal x.
 11.1887 +           \<forall>u. {n. u < abs (X n)} \<in> FreeUltrafilterNat)"
 11.1888 +apply (blast intro!: HInfinite_FreeUltrafilterNat FreeUltrafilterNat_HInfinite)
 11.1889 +done
 11.1890 +
 11.1891 +(*--------------------------------------------------------------------
 11.1892 +   Alternative definitions for Infinitesimal using Free ultrafilter
 11.1893 + --------------------------------------------------------------------*)
 11.1894 +
 11.1895  
 11.1896 -syntax (xsymbols)
 11.1897 -    approx :: "[hypreal, hypreal] => bool"    (infixl "\\<approx>" 50)
 11.1898 -  
 11.1899 +lemma Infinitesimal_FreeUltrafilterNat:
 11.1900 +          "x \<in> Infinitesimal ==> \<exists>X \<in> Rep_hypreal x.
 11.1901 +           \<forall>u. 0 < u --> {n. abs (X n) < u} \<in> FreeUltrafilterNat"
 11.1902 +apply (simp add: Infinitesimal_def)
 11.1903 +apply (auto simp add: abs_less_iff minus_less_iff [of x])
 11.1904 +apply (rule eq_Abs_hypreal [of x])
 11.1905 +apply (auto, rule bexI [OF _ lemma_hyprel_refl], safe)
 11.1906 +apply (drule hypreal_of_real_less_iff [THEN iffD2])
 11.1907 +apply (drule_tac x = "hypreal_of_real u" in bspec, auto)
 11.1908 +apply (auto simp add: hypreal_less hypreal_minus hypreal_of_real_def, ultra)
 11.1909 +done
 11.1910 +
 11.1911 +lemma FreeUltrafilterNat_Infinitesimal:
 11.1912 +     "\<exists>X \<in> Rep_hypreal x.
 11.1913 +            \<forall>u. 0 < u --> {n. abs (X n) < u} \<in> FreeUltrafilterNat
 11.1914 +      ==> x \<in> Infinitesimal"
 11.1915 +apply (simp add: Infinitesimal_def)
 11.1916 +apply (rule eq_Abs_hypreal [of x])
 11.1917 +apply (auto simp add: abs_less_iff abs_interval_iff minus_less_iff [of x])
 11.1918 +apply (auto simp add: SReal_iff)
 11.1919 +apply (drule_tac [!] x=y in spec) 
 11.1920 +apply (auto simp add: hypreal_less hypreal_minus hypreal_of_real_def, ultra+)
 11.1921 +done
 11.1922 +
 11.1923 +lemma Infinitesimal_FreeUltrafilterNat_iff: "(x \<in> Infinitesimal) = (\<exists>X \<in> Rep_hypreal x.
 11.1924 +           \<forall>u. 0 < u --> {n. abs (X n) < u} \<in> FreeUltrafilterNat)"
 11.1925 +apply (blast intro!: Infinitesimal_FreeUltrafilterNat FreeUltrafilterNat_Infinitesimal)
 11.1926 +done
 11.1927 +
 11.1928 +(*------------------------------------------------------------------------
 11.1929 +         Infinitesimals as smaller than 1/n for all n::nat (> 0)
 11.1930 + ------------------------------------------------------------------------*)
 11.1931 +
 11.1932 +lemma lemma_Infinitesimal: "(\<forall>r. 0 < r --> x < r) = (\<forall>n. x < inverse(real (Suc n)))"
 11.1933 +apply (auto simp add: real_of_nat_Suc_gt_zero)
 11.1934 +apply (blast dest!: reals_Archimedean intro: order_less_trans)
 11.1935 +done
 11.1936 +
 11.1937 +lemma lemma_Infinitesimal2: "(\<forall>r \<in> Reals. 0 < r --> x < r) =
 11.1938 +      (\<forall>n. x < inverse(hypreal_of_nat (Suc n)))"
 11.1939 +apply safe
 11.1940 +apply (drule_tac x = "inverse (hypreal_of_real (real (Suc n))) " in bspec)
 11.1941 +apply (simp (no_asm_use) add: SReal_inverse)
 11.1942 +apply (rule real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive, THEN hypreal_of_real_less_iff [THEN iffD2], THEN [2] impE])
 11.1943 +prefer 2 apply assumption
 11.1944 +apply (simp add: real_of_nat_Suc_gt_zero hypreal_of_nat_def)
 11.1945 +apply (auto dest!: reals_Archimedean simp add: SReal_iff)
 11.1946 +apply (drule hypreal_of_real_less_iff [THEN iffD2])
 11.1947 +apply (simp add: real_of_nat_Suc_gt_zero hypreal_of_nat_def)
 11.1948 +apply (blast intro: order_less_trans)
 11.1949 +done
 11.1950 +
 11.1951 +lemma Infinitesimal_hypreal_of_nat_iff:
 11.1952 +     "Infinitesimal = {x. \<forall>n. abs x < inverse (hypreal_of_nat (Suc n))}"
 11.1953 +apply (simp add: Infinitesimal_def)
 11.1954 +apply (auto simp add: lemma_Infinitesimal2)
 11.1955 +done
 11.1956 +
 11.1957 +
 11.1958 +(*-------------------------------------------------------------------------
 11.1959 +       Proof that omega is an infinite number and
 11.1960 +       hence that epsilon is an infinitesimal number.
 11.1961 + -------------------------------------------------------------------------*)
 11.1962 +lemma Suc_Un_eq: "{n. n < Suc m} = {n. n < m} Un {n. n = m}"
 11.1963 +by (auto simp add: less_Suc_eq)
 11.1964 +
 11.1965 +(*-------------------------------------------
 11.1966 +  Prove that any segment is finite and
 11.1967 +  hence cannot belong to FreeUltrafilterNat
 11.1968 + -------------------------------------------*)
 11.1969 +lemma finite_nat_segment: "finite {n::nat. n < m}"
 11.1970 +apply (induct_tac "m")
 11.1971 +apply (auto simp add: Suc_Un_eq)
 11.1972 +done
 11.1973 +
 11.1974 +lemma finite_real_of_nat_segment: "finite {n::nat. real n < real (m::nat)}"
 11.1975 +by (auto intro: finite_nat_segment)
 11.1976 +
 11.1977 +lemma finite_real_of_nat_less_real: "finite {n::nat. real n < u}"
 11.1978 +apply (cut_tac x = u in reals_Archimedean2, safe)
 11.1979 +apply (rule finite_real_of_nat_segment [THEN [2] finite_subset])
 11.1980 +apply (auto dest: order_less_trans)
 11.1981 +done
 11.1982 +
 11.1983 +lemma lemma_real_le_Un_eq: "{n. f n <= u} = {n. f n < u} Un {n. u = (f n :: real)}"
 11.1984 +by (auto dest: order_le_imp_less_or_eq simp add: order_less_imp_le)
 11.1985 +
 11.1986 +lemma finite_real_of_nat_le_real: "finite {n::nat. real n <= u}"
 11.1987 +by (auto simp add: lemma_real_le_Un_eq lemma_finite_omega_set finite_real_of_nat_less_real)
 11.1988 +
 11.1989 +lemma finite_rabs_real_of_nat_le_real: "finite {n::nat. abs(real n) <= u}"
 11.1990 +apply (simp (no_asm) add: real_of_nat_Suc_gt_zero finite_real_of_nat_le_real)
 11.1991 +done
 11.1992 +
 11.1993 +lemma rabs_real_of_nat_le_real_FreeUltrafilterNat: "{n. abs(real n) <= u} \<notin> FreeUltrafilterNat"
 11.1994 +by (blast intro!: FreeUltrafilterNat_finite finite_rabs_real_of_nat_le_real)
 11.1995 +
 11.1996 +lemma FreeUltrafilterNat_nat_gt_real: "{n. u < real n} \<in> FreeUltrafilterNat"
 11.1997 +apply (rule ccontr, drule FreeUltrafilterNat_Compl_mem)
 11.1998 +apply (subgoal_tac "- {n::nat. u < real n} = {n. real n <= u}")
 11.1999 +prefer 2 apply force
 11.2000 +apply (simp add: finite_real_of_nat_le_real [THEN FreeUltrafilterNat_finite])
 11.2001 +done
 11.2002 +
 11.2003 +(*--------------------------------------------------------------
 11.2004 + The complement of {n. abs(real n) <= u} =
 11.2005 + {n. u < abs (real n)} is in FreeUltrafilterNat
 11.2006 + by property of (free) ultrafilters
 11.2007 + --------------------------------------------------------------*)
 11.2008 +
 11.2009 +lemma Compl_real_le_eq: "- {n::nat. real n <= u} = {n. u < real n}"
 11.2010 +by (auto dest!: order_le_less_trans simp add: linorder_not_le)
 11.2011 +
 11.2012 +(*-----------------------------------------------
 11.2013 +       Omega is a member of HInfinite
 11.2014 + -----------------------------------------------*)
 11.2015 +
 11.2016 +lemma hypreal_omega: "hyprel``{%n::nat. real (Suc n)} \<in> hypreal"
 11.2017 +by auto
 11.2018 +
 11.2019 +lemma FreeUltrafilterNat_omega: "{n. u < real n} \<in> FreeUltrafilterNat"
 11.2020 +apply (cut_tac u = u in rabs_real_of_nat_le_real_FreeUltrafilterNat)
 11.2021 +apply (auto dest: FreeUltrafilterNat_Compl_mem simp add: Compl_real_le_eq)
 11.2022 +done
 11.2023 +
 11.2024 +lemma HInfinite_omega: "omega: HInfinite"
 11.2025 +apply (simp add: omega_def)
 11.2026 +apply (auto intro!: FreeUltrafilterNat_HInfinite)
 11.2027 +apply (rule bexI)
 11.2028 +apply (rule_tac [2] lemma_hyprel_refl, auto)
 11.2029 +apply (simp (no_asm) add: real_of_nat_Suc diff_less_eq [symmetric] FreeUltrafilterNat_omega)
 11.2030 +done
 11.2031 +declare HInfinite_omega [simp]
 11.2032 +
 11.2033 +(*-----------------------------------------------
 11.2034 +       Epsilon is a member of Infinitesimal
 11.2035 + -----------------------------------------------*)
 11.2036 +
 11.2037 +lemma Infinitesimal_epsilon: "epsilon \<in> Infinitesimal"
 11.2038 +by (auto intro!: HInfinite_inverse_Infinitesimal HInfinite_omega simp add: hypreal_epsilon_inverse_omega)
 11.2039 +declare Infinitesimal_epsilon [simp]
 11.2040 +
 11.2041 +lemma HFinite_epsilon: "epsilon \<in> HFinite"
 11.2042 +by (auto intro: Infinitesimal_subset_HFinite [THEN subsetD])
 11.2043 +declare HFinite_epsilon [simp]
 11.2044 +
 11.2045 +lemma epsilon_approx_zero: "epsilon @= 0"
 11.2046 +apply (simp (no_asm) add: mem_infmal_iff [symmetric])
 11.2047 +done
 11.2048 +declare epsilon_approx_zero [simp]
 11.2049 +
 11.2050 +(*------------------------------------------------------------------------
 11.2051 +  Needed for proof that we define a hyperreal [<X(n)] @= hypreal_of_real a given
 11.2052 +  that \<forall>n. |X n - a| < 1/n. Used in proof of NSLIM => LIM.
 11.2053 + -----------------------------------------------------------------------*)
 11.2054 +
 11.2055 +lemma real_of_nat_less_inverse_iff: "0 < u  ==>
 11.2056 +      (u < inverse (real(Suc n))) = (real(Suc n) < inverse u)"
 11.2057 +apply (simp add: inverse_eq_divide)
 11.2058 +apply (subst pos_less_divide_eq, assumption)
 11.2059 +apply (subst pos_less_divide_eq)
 11.2060 + apply (simp add: real_of_nat_Suc_gt_zero)
 11.2061 +apply (simp add: real_mult_commute)
 11.2062 +done
 11.2063 +
 11.2064 +lemma finite_inverse_real_of_posnat_gt_real: "0 < u ==> finite {n. u < inverse(real(Suc n))}"
 11.2065 +apply (simp (no_asm_simp) add: real_of_nat_less_inverse_iff)
 11.2066 +apply (simp (no_asm_simp) add: real_of_nat_Suc less_diff_eq [symmetric])
 11.2067 +apply (rule finite_real_of_nat_less_real)
 11.2068 +done
 11.2069 +
 11.2070 +lemma lemma_real_le_Un_eq2: "{n. u <= inverse(real(Suc n))} =
 11.2071 +     {n. u < inverse(real(Suc n))} Un {n. u = inverse(real(Suc n))}"
 11.2072 +apply (auto dest: order_le_imp_less_or_eq simp add: order_less_imp_le)
 11.2073 +done
 11.2074 +
 11.2075 +lemma real_of_nat_inverse_le_iff: "(inverse (real(Suc n)) <= r) = (1 <= r * real(Suc n))"
 11.2076 +apply (simp (no_asm) add: linorder_not_less [symmetric])
 11.2077 +apply (simp (no_asm) add: inverse_eq_divide)
 11.2078 +apply (subst pos_less_divide_eq)
 11.2079 +apply (simp (no_asm) add: real_of_nat_Suc_gt_zero)
 11.2080 +apply (simp (no_asm) add: real_mult_commute)
 11.2081 +done
 11.2082 +
 11.2083 +lemma real_of_nat_inverse_eq_iff: "(u = inverse (real(Suc n))) = (real(Suc n) = inverse u)"
 11.2084 +by (auto simp add: inverse_inverse_eq real_of_nat_Suc_gt_zero real_not_refl2 [THEN not_sym])
 11.2085 +
 11.2086 +lemma lemma_finite_omega_set2: "finite {n::nat. u = inverse(real(Suc n))}"
 11.2087 +apply (simp (no_asm_simp) add: real_of_nat_inverse_eq_iff)
 11.2088 +apply (cut_tac x = "inverse u - 1" in lemma_finite_omega_set)
 11.2089 +apply (simp add: real_of_nat_Suc diff_eq_eq [symmetric] eq_commute)
 11.2090 +done
 11.2091 +
 11.2092 +lemma finite_inverse_real_of_posnat_ge_real: "0 < u ==> finite {n. u <= inverse(real(Suc n))}"
 11.2093 +by (auto simp add: lemma_real_le_Un_eq2 lemma_finite_omega_set2 finite_inverse_real_of_posnat_gt_real)
 11.2094 +
 11.2095 +lemma inverse_real_of_posnat_ge_real_FreeUltrafilterNat: "0 < u ==>
 11.2096 +       {n. u <= inverse(real(Suc n))} \<notin> FreeUltrafilterNat"
 11.2097 +apply (blast intro!: FreeUltrafilterNat_finite finite_inverse_real_of_posnat_ge_real)
 11.2098 +done
 11.2099 +
 11.2100 +(*--------------------------------------------------------------
 11.2101 +    The complement of  {n. u <= inverse(real(Suc n))} =
 11.2102 +    {n. inverse(real(Suc n)) < u} is in FreeUltrafilterNat
 11.2103 +    by property of (free) ultrafilters
 11.2104 + --------------------------------------------------------------*)
 11.2105 +lemma Compl_le_inverse_eq: "- {n. u <= inverse(real(Suc n))} =
 11.2106 +      {n. inverse(real(Suc n)) < u}"
 11.2107 +apply (auto dest!: order_le_less_trans simp add: linorder_not_le)
 11.2108 +done
 11.2109 +
 11.2110 +lemma FreeUltrafilterNat_inverse_real_of_posnat: "0 < u ==>
 11.2111 +      {n. inverse(real(Suc n)) < u} \<in> FreeUltrafilterNat"
 11.2112 +apply (cut_tac u = u in inverse_real_of_posnat_ge_real_FreeUltrafilterNat)
 11.2113 +apply (auto dest: FreeUltrafilterNat_Compl_mem simp add: Compl_le_inverse_eq)
 11.2114 +done
 11.2115 +
 11.2116 +(*--------------------------------------------------------------
 11.2117 +      Example where we get a hyperreal from a real sequence
 11.2118 +      for which a particular property holds. The theorem is
 11.2119 +      used in proofs about equivalence of nonstandard and
 11.2120 +      standard neighbourhoods. Also used for equivalence of
 11.2121 +      nonstandard ans standard definitions of pointwise
 11.2122 +      limit (the theorem was previously in REALTOPOS.thy).
 11.2123 + -------------------------------------------------------------*)
 11.2124 +(*-----------------------------------------------------
 11.2125 +    |X(n) - x| < 1/n ==> [<X n>] - hypreal_of_real x| \<in> Infinitesimal
 11.2126 + -----------------------------------------------------*)
 11.2127 +lemma real_seq_to_hypreal_Infinitesimal: "\<forall>n. abs(X n + -x) < inverse(real(Suc n))
 11.2128 +     ==> Abs_hypreal(hyprel``{X}) + -hypreal_of_real x \<in> Infinitesimal"
 11.2129 +apply (auto intro!: bexI dest: FreeUltrafilterNat_inverse_real_of_posnat FreeUltrafilterNat_all FreeUltrafilterNat_Int intro: order_less_trans FreeUltrafilterNat_subset simp add: hypreal_minus hypreal_of_real_def hypreal_add Infinitesimal_FreeUltrafilterNat_iff hypreal_inverse)
 11.2130 +done
 11.2131 +
 11.2132 +lemma real_seq_to_hypreal_approx: "\<forall>n. abs(X n + -x) < inverse(real(Suc n))
 11.2133 +      ==> Abs_hypreal(hyprel``{X}) @= hypreal_of_real x"
 11.2134 +apply (subst approx_minus_iff)
 11.2135 +apply (rule mem_infmal_iff [THEN subst])
 11.2136 +apply (erule real_seq_to_hypreal_Infinitesimal)
 11.2137 +done
 11.2138 +
 11.2139 +lemma real_seq_to_hypreal_approx2: "\<forall>n. abs(x + -X n) < inverse(real(Suc n))
 11.2140 +               ==> Abs_hypreal(hyprel``{X}) @= hypreal_of_real x"
 11.2141 +apply (simp add: abs_minus_add_cancel real_seq_to_hypreal_approx)
 11.2142 +done
 11.2143 +
 11.2144 +lemma real_seq_to_hypreal_Infinitesimal2: "\<forall>n. abs(X n + -Y n) < inverse(real(Suc n))
 11.2145 +      ==> Abs_hypreal(hyprel``{X}) +
 11.2146 +          -Abs_hypreal(hyprel``{Y}) \<in> Infinitesimal"
 11.2147 +by (auto intro!: bexI
 11.2148 +	 dest: FreeUltrafilterNat_inverse_real_of_posnat 
 11.2149 +	       FreeUltrafilterNat_all FreeUltrafilterNat_Int
 11.2150 +	 intro: order_less_trans FreeUltrafilterNat_subset 
 11.2151 +	 simp add: Infinitesimal_FreeUltrafilterNat_iff hypreal_minus 
 11.2152 +                   hypreal_add hypreal_inverse)
 11.2153 +
 11.2154 +
 11.2155 +ML
 11.2156 +{*
 11.2157 +val Infinitesimal_def = thm"Infinitesimal_def";
 11.2158 +val HFinite_def = thm"HFinite_def";
 11.2159 +val HInfinite_def = thm"HInfinite_def";
 11.2160 +val st_def = thm"st_def";
 11.2161 +val monad_def = thm"monad_def";
 11.2162 +val galaxy_def = thm"galaxy_def";
 11.2163 +val approx_def = thm"approx_def";
 11.2164 +val SReal_def = thm"SReal_def";
 11.2165 +
 11.2166 +val Infinitesimal_approx_minus = thm "Infinitesimal_approx_minus";
 11.2167 +val approx_monad_iff = thm "approx_monad_iff";
 11.2168 +val Infinitesimal_approx = thm "Infinitesimal_approx";
 11.2169 +val approx_add = thm "approx_add";
 11.2170 +val approx_minus = thm "approx_minus";
 11.2171 +val approx_minus2 = thm "approx_minus2";
 11.2172 +val approx_minus_cancel = thm "approx_minus_cancel";
 11.2173 +val approx_add_minus = thm "approx_add_minus";
 11.2174 +val approx_mult1 = thm "approx_mult1";
 11.2175 +val approx_mult2 = thm "approx_mult2";
 11.2176 +val approx_mult_subst = thm "approx_mult_subst";
 11.2177 +val approx_mult_subst2 = thm "approx_mult_subst2";
 11.2178 +val approx_mult_subst_SReal = thm "approx_mult_subst_SReal";
 11.2179 +val approx_eq_imp = thm "approx_eq_imp";
 11.2180 +val Infinitesimal_minus_approx = thm "Infinitesimal_minus_approx";
 11.2181 +val bex_Infinitesimal_iff = thm "bex_Infinitesimal_iff";
 11.2182 +val bex_Infinitesimal_iff2 = thm "bex_Infinitesimal_iff2";
 11.2183 +val Infinitesimal_add_approx = thm "Infinitesimal_add_approx";
 11.2184 +val Infinitesimal_add_approx_self = thm "Infinitesimal_add_approx_self";
 11.2185 +val Infinitesimal_add_approx_self2 = thm "Infinitesimal_add_approx_self2";
 11.2186 +val Infinitesimal_add_minus_approx_self = thm "Infinitesimal_add_minus_approx_self";
 11.2187 +val Infinitesimal_add_cancel = thm "Infinitesimal_add_cancel";
 11.2188 +val Infinitesimal_add_right_cancel = thm "Infinitesimal_add_right_cancel";
 11.2189 +val approx_add_left_cancel = thm "approx_add_left_cancel";
 11.2190 +val approx_add_right_cancel = thm "approx_add_right_cancel";
 11.2191 +val approx_add_mono1 = thm "approx_add_mono1";
 11.2192 +val approx_add_mono2 = thm "approx_add_mono2";
 11.2193 +val approx_add_left_iff = thm "approx_add_left_iff";
 11.2194 +val approx_add_right_iff = thm "approx_add_right_iff";
 11.2195 +val approx_HFinite = thm "approx_HFinite";
 11.2196 +val approx_hypreal_of_real_HFinite = thm "approx_hypreal_of_real_HFinite";
 11.2197 +val approx_mult_HFinite = thm "approx_mult_HFinite";
 11.2198 +val approx_mult_hypreal_of_real = thm "approx_mult_hypreal_of_real";
 11.2199 +val approx_SReal_mult_cancel_zero = thm "approx_SReal_mult_cancel_zero";
 11.2200 +val approx_mult_SReal1 = thm "approx_mult_SReal1";
 11.2201 +val approx_mult_SReal2 = thm "approx_mult_SReal2";
 11.2202 +val approx_mult_SReal_zero_cancel_iff = thm "approx_mult_SReal_zero_cancel_iff";
 11.2203 +val approx_SReal_mult_cancel = thm "approx_SReal_mult_cancel";
 11.2204 +val approx_SReal_mult_cancel_iff1 = thm "approx_SReal_mult_cancel_iff1";
 11.2205 +val approx_le_bound = thm "approx_le_bound";
 11.2206 +val Infinitesimal_less_SReal = thm "Infinitesimal_less_SReal";
 11.2207 +val Infinitesimal_less_SReal2 = thm "Infinitesimal_less_SReal2";
 11.2208 +val SReal_not_Infinitesimal = thm "SReal_not_Infinitesimal";
 11.2209 +val SReal_minus_not_Infinitesimal = thm "SReal_minus_not_Infinitesimal";
 11.2210 +val SReal_Int_Infinitesimal_zero = thm "SReal_Int_Infinitesimal_zero";
 11.2211 +val SReal_Infinitesimal_zero = thm "SReal_Infinitesimal_zero";
 11.2212 +val SReal_HFinite_diff_Infinitesimal = thm "SReal_HFinite_diff_Infinitesimal";
 11.2213 +val hypreal_of_real_HFinite_diff_Infinitesimal = thm "hypreal_of_real_HFinite_diff_Infinitesimal";
 11.2214 +val hypreal_of_real_Infinitesimal_iff_0 = thm "hypreal_of_real_Infinitesimal_iff_0";
 11.2215 +val number_of_not_Infinitesimal = thm "number_of_not_Infinitesimal";
 11.2216 +val one_not_Infinitesimal = thm "one_not_Infinitesimal";
 11.2217 +val approx_SReal_not_zero = thm "approx_SReal_not_zero";
 11.2218 +val HFinite_diff_Infinitesimal_approx = thm "HFinite_diff_Infinitesimal_approx";
 11.2219 +val Infinitesimal_ratio = thm "Infinitesimal_ratio";
 11.2220 +val SReal_approx_iff = thm "SReal_approx_iff";
 11.2221 +val number_of_approx_iff = thm "number_of_approx_iff";
 11.2222 +val hypreal_of_real_approx_iff = thm "hypreal_of_real_approx_iff";
 11.2223 +val hypreal_of_real_approx_number_of_iff = thm "hypreal_of_real_approx_number_of_iff";
 11.2224 +val approx_unique_real = thm "approx_unique_real";
 11.2225 +val hypreal_isLub_unique = thm "hypreal_isLub_unique";
 11.2226 +val hypreal_setle_less_trans = thm "hypreal_setle_less_trans";
 11.2227 +val hypreal_gt_isUb = thm "hypreal_gt_isUb";
 11.2228 +val st_part_Ex = thm "st_part_Ex";
 11.2229 +val st_part_Ex1 = thm "st_part_Ex1";
 11.2230 +val HFinite_Int_HInfinite_empty = thm "HFinite_Int_HInfinite_empty";
 11.2231 +val HFinite_not_HInfinite = thm "HFinite_not_HInfinite";
 11.2232 +val not_HFinite_HInfinite = thm "not_HFinite_HInfinite";
 11.2233 +val HInfinite_HFinite_disj = thm "HInfinite_HFinite_disj";
 11.2234 +val HInfinite_HFinite_iff = thm "HInfinite_HFinite_iff";
 11.2235 +val HFinite_HInfinite_iff = thm "HFinite_HInfinite_iff";
 11.2236 +val HInfinite_diff_HFinite_Infinitesimal_disj = thm "HInfinite_diff_HFinite_Infinitesimal_disj";
 11.2237 +val HFinite_inverse = thm "HFinite_inverse";
 11.2238 +val HFinite_inverse2 = thm "HFinite_inverse2";
 11.2239 +val Infinitesimal_inverse_HFinite = thm "Infinitesimal_inverse_HFinite";
 11.2240 +val HFinite_not_Infinitesimal_inverse = thm "HFinite_not_Infinitesimal_inverse";
 11.2241 +val approx_inverse = thm "approx_inverse";
 11.2242 +val hypreal_of_real_approx_inverse = thm "hypreal_of_real_approx_inverse";
 11.2243 +val inverse_add_Infinitesimal_approx = thm "inverse_add_Infinitesimal_approx";
 11.2244 +val inverse_add_Infinitesimal_approx2 = thm "inverse_add_Infinitesimal_approx2";
 11.2245 +val inverse_add_Infinitesimal_approx_Infinitesimal = thm "inverse_add_Infinitesimal_approx_Infinitesimal";
 11.2246 +val Infinitesimal_square_iff = thm "Infinitesimal_square_iff";
 11.2247 +val HFinite_square_iff = thm "HFinite_square_iff";
 11.2248 +val HInfinite_square_iff = thm "HInfinite_square_iff";
 11.2249 +val approx_HFinite_mult_cancel = thm "approx_HFinite_mult_cancel";
 11.2250 +val approx_HFinite_mult_cancel_iff1 = thm "approx_HFinite_mult_cancel_iff1";
 11.2251 +val approx_hrabs_disj = thm "approx_hrabs_disj";
 11.2252 +val monad_hrabs_Un_subset = thm "monad_hrabs_Un_subset";
 11.2253 +val Infinitesimal_monad_eq = thm "Infinitesimal_monad_eq";
 11.2254 +val mem_monad_iff = thm "mem_monad_iff";
 11.2255 +val Infinitesimal_monad_zero_iff = thm "Infinitesimal_monad_zero_iff";
 11.2256 +val monad_zero_minus_iff = thm "monad_zero_minus_iff";
 11.2257 +val monad_zero_hrabs_iff = thm "monad_zero_hrabs_iff";
 11.2258 +val mem_monad_self = thm "mem_monad_self";
 11.2259 +val approx_subset_monad = thm "approx_subset_monad";
 11.2260 +val approx_subset_monad2 = thm "approx_subset_monad2";
 11.2261 +val mem_monad_approx = thm "mem_monad_approx";
 11.2262 +val approx_mem_monad = thm "approx_mem_monad";
 11.2263 +val approx_mem_monad2 = thm "approx_mem_monad2";
 11.2264 +val approx_mem_monad_zero = thm "approx_mem_monad_zero";
 11.2265 +val Infinitesimal_approx_hrabs = thm "Infinitesimal_approx_hrabs";
 11.2266 +val less_Infinitesimal_less = thm "less_Infinitesimal_less";
 11.2267 +val Ball_mem_monad_gt_zero = thm "Ball_mem_monad_gt_zero";
 11.2268 +val Ball_mem_monad_less_zero = thm "Ball_mem_monad_less_zero";
 11.2269 +val approx_hrabs1 = thm "approx_hrabs1";
 11.2270 +val approx_hrabs2 = thm "approx_hrabs2";
 11.2271 +val approx_hrabs = thm "approx_hrabs";
 11.2272 +val approx_hrabs_zero_cancel = thm "approx_hrabs_zero_cancel";
 11.2273 +val approx_hrabs_add_Infinitesimal = thm "approx_hrabs_add_Infinitesimal";
 11.2274 +val approx_hrabs_add_minus_Infinitesimal = thm "approx_hrabs_add_minus_Infinitesimal";
 11.2275 +val hrabs_add_Infinitesimal_cancel = thm "hrabs_add_Infinitesimal_cancel";
 11.2276 +val hrabs_add_minus_Infinitesimal_cancel = thm "hrabs_add_minus_Infinitesimal_cancel";
 11.2277 +val hypreal_less_minus_iff = thm "hypreal_less_minus_iff";
 11.2278 +val Infinitesimal_add_hypreal_of_real_less = thm "Infinitesimal_add_hypreal_of_real_less";
 11.2279 +val Infinitesimal_add_hrabs_hypreal_of_real_less = thm "Infinitesimal_add_hrabs_hypreal_of_real_less";
 11.2280 +val Infinitesimal_add_hrabs_hypreal_of_real_less2 = thm "Infinitesimal_add_hrabs_hypreal_of_real_less2";
 11.2281 +val hypreal_of_real_le_add_Infininitesimal_cancel2 = thm"hypreal_of_real_le_add_Infininitesimal_cancel2";
 11.2282 +val hypreal_of_real_less_Infinitesimal_le_zero = thm "hypreal_of_real_less_Infinitesimal_le_zero";
 11.2283 +val Infinitesimal_add_not_zero = thm "Infinitesimal_add_not_zero";
 11.2284 +val Infinitesimal_square_cancel = thm "Infinitesimal_square_cancel";
 11.2285 +val HFinite_square_cancel = thm "HFinite_square_cancel";
 11.2286 +val Infinitesimal_square_cancel2 = thm "Infinitesimal_square_cancel2";
 11.2287 +val HFinite_square_cancel2 = thm "HFinite_square_cancel2";
 11.2288 +val Infinitesimal_sum_square_cancel = thm "Infinitesimal_sum_square_cancel";
 11.2289 +val HFinite_sum_square_cancel = thm "HFinite_sum_square_cancel";
 11.2290 +val Infinitesimal_sum_square_cancel2 = thm "Infinitesimal_sum_square_cancel2";
 11.2291 +val HFinite_sum_square_cancel2 = thm "HFinite_sum_square_cancel2";
 11.2292 +val Infinitesimal_sum_square_cancel3 = thm "Infinitesimal_sum_square_cancel3";
 11.2293 +val HFinite_sum_square_cancel3 = thm "HFinite_sum_square_cancel3";
 11.2294 +val monad_hrabs_less = thm "monad_hrabs_less";
 11.2295 +val mem_monad_SReal_HFinite = thm "mem_monad_SReal_HFinite";
 11.2296 +val st_approx_self = thm "st_approx_self";
 11.2297 +val st_SReal = thm "st_SReal";
 11.2298 +val st_HFinite = thm "st_HFinite";
 11.2299 +val st_SReal_eq = thm "st_SReal_eq";
 11.2300 +val st_hypreal_of_real = thm "st_hypreal_of_real";
 11.2301 +val st_eq_approx = thm "st_eq_approx";
 11.2302 +val approx_st_eq = thm "approx_st_eq";
 11.2303 +val st_eq_approx_iff = thm "st_eq_approx_iff";
 11.2304 +val st_Infinitesimal_add_SReal = thm "st_Infinitesimal_add_SReal";
 11.2305 +val st_Infinitesimal_add_SReal2 = thm "st_Infinitesimal_add_SReal2";
 11.2306 +val HFinite_st_Infinitesimal_add = thm "HFinite_st_Infinitesimal_add";
 11.2307 +val st_add = thm "st_add";
 11.2308 +val st_number_of = thm "st_number_of";
 11.2309 +val st_minus = thm "st_minus";
 11.2310 +val st_diff = thm "st_diff";
 11.2311 +val st_mult = thm "st_mult";
 11.2312 +val st_Infinitesimal = thm "st_Infinitesimal";
 11.2313 +val st_not_Infinitesimal = thm "st_not_Infinitesimal";
 11.2314 +val st_inverse = thm "st_inverse";
 11.2315 +val st_divide = thm "st_divide";
 11.2316 +val st_idempotent = thm "st_idempotent";
 11.2317 +val Infinitesimal_add_st_less = thm "Infinitesimal_add_st_less";
 11.2318 +val Infinitesimal_add_st_le_cancel = thm "Infinitesimal_add_st_le_cancel";
 11.2319 +val st_le = thm "st_le";
 11.2320 +val st_zero_le = thm "st_zero_le";
 11.2321 +val st_zero_ge = thm "st_zero_ge";
 11.2322 +val st_hrabs = thm "st_hrabs";
 11.2323 +val FreeUltrafilterNat_HFinite = thm "FreeUltrafilterNat_HFinite";
 11.2324 +val HFinite_FreeUltrafilterNat_iff = thm "HFinite_FreeUltrafilterNat_iff";
 11.2325 +val FreeUltrafilterNat_const_Finite = thm "FreeUltrafilterNat_const_Finite";
 11.2326 +val FreeUltrafilterNat_HInfinite = thm "FreeUltrafilterNat_HInfinite";
 11.2327 +val HInfinite_FreeUltrafilterNat_iff = thm "HInfinite_FreeUltrafilterNat_iff";
 11.2328 +val Infinitesimal_FreeUltrafilterNat = thm "Infinitesimal_FreeUltrafilterNat";
 11.2329 +val FreeUltrafilterNat_Infinitesimal = thm "FreeUltrafilterNat_Infinitesimal";
 11.2330 +val Infinitesimal_FreeUltrafilterNat_iff = thm "Infinitesimal_FreeUltrafilterNat_iff";
 11.2331 +val Infinitesimal_hypreal_of_nat_iff = thm "Infinitesimal_hypreal_of_nat_iff";
 11.2332 +val Suc_Un_eq = thm "Suc_Un_eq";
 11.2333 +val finite_nat_segment = thm "finite_nat_segment";
 11.2334 +val finite_real_of_nat_segment = thm "finite_real_of_nat_segment";
 11.2335 +val finite_real_of_nat_less_real = thm "finite_real_of_nat_less_real";
 11.2336 +val finite_real_of_nat_le_real = thm "finite_real_of_nat_le_real";
 11.2337 +val finite_rabs_real_of_nat_le_real = thm "finite_rabs_real_of_nat_le_real";
 11.2338 +val rabs_real_of_nat_le_real_FreeUltrafilterNat = thm "rabs_real_of_nat_le_real_FreeUltrafilterNat";
 11.2339 +val FreeUltrafilterNat_nat_gt_real = thm "FreeUltrafilterNat_nat_gt_real";
 11.2340 +val hypreal_omega = thm "hypreal_omega";
 11.2341 +val FreeUltrafilterNat_omega = thm "FreeUltrafilterNat_omega";
 11.2342 +val HInfinite_omega = thm "HInfinite_omega";
 11.2343 +val Infinitesimal_epsilon = thm "Infinitesimal_epsilon";
 11.2344 +val HFinite_epsilon = thm "HFinite_epsilon";
 11.2345 +val epsilon_approx_zero = thm "epsilon_approx_zero";
 11.2346 +val real_of_nat_less_inverse_iff = thm "real_of_nat_less_inverse_iff";
 11.2347 +val finite_inverse_real_of_posnat_gt_real = thm "finite_inverse_real_of_posnat_gt_real";
 11.2348 +val real_of_nat_inverse_le_iff = thm "real_of_nat_inverse_le_iff";
 11.2349 +val real_of_nat_inverse_eq_iff = thm "real_of_nat_inverse_eq_iff";
 11.2350 +val finite_inverse_real_of_posnat_ge_real = thm "finite_inverse_real_of_posnat_ge_real";
 11.2351 +val inverse_real_of_posnat_ge_real_FreeUltrafilterNat = thm "inverse_real_of_posnat_ge_real_FreeUltrafilterNat";
 11.2352 +val FreeUltrafilterNat_inverse_real_of_posnat = thm "FreeUltrafilterNat_inverse_real_of_posnat";
 11.2353 +val real_seq_to_hypreal_Infinitesimal = thm "real_seq_to_hypreal_Infinitesimal";
 11.2354 +val real_seq_to_hypreal_approx = thm "real_seq_to_hypreal_approx";
 11.2355 +val real_seq_to_hypreal_approx2 = thm "real_seq_to_hypreal_approx2";
 11.2356 +val real_seq_to_hypreal_Infinitesimal2 = thm "real_seq_to_hypreal_Infinitesimal2";
 11.2357 +val HInfinite_HFinite_add = thm "HInfinite_HFinite_add";
 11.2358 +val HInfinite_ge_HInfinite = thm "HInfinite_ge_HInfinite";
 11.2359 +val Infinitesimal_inverse_HInfinite = thm "Infinitesimal_inverse_HInfinite";
 11.2360 +val HInfinite_HFinite_not_Infinitesimal_mult = thm "HInfinite_HFinite_not_Infinitesimal_mult";
 11.2361 +val HInfinite_HFinite_not_Infinitesimal_mult2 = thm "HInfinite_HFinite_not_Infinitesimal_mult2";
 11.2362 +val HInfinite_gt_SReal = thm "HInfinite_gt_SReal";
 11.2363 +val HInfinite_gt_zero_gt_one = thm "HInfinite_gt_zero_gt_one";
 11.2364 +val not_HInfinite_one = thm "not_HInfinite_one";
 11.2365 +*}
 11.2366 +
 11.2367  end
 11.2368  
 11.2369  
    12.1 --- a/src/HOL/Hyperreal/Star.ML	Wed Jan 28 17:01:01 2004 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,490 +0,0 @@
    12.4 -(*  Title       : STAR.ML
    12.5 -    Author      : Jacques D. Fleuriot
    12.6 -    Copyright   : 1998  University of Cambridge
    12.7 -    Description : *-transforms
    12.8 -*) 
    12.9 -
   12.10 -(*--------------------------------------------------------
   12.11 -   Preamble - Pulling "EX" over "ALL"
   12.12 - ---------------------------------------------------------*)
   12.13 - 
   12.14 -(* This proof does not need AC and was suggested by the 
   12.15 -   referee for the JCM Paper: let f(x) be least y such 
   12.16 -   that  Q(x,y) 
   12.17 -*)
   12.18 -Goal "ALL x. EX y. Q x y ==> EX (f :: nat => nat). ALL x. Q x (f x)";
   12.19 -by (res_inst_tac [("x","%x. LEAST y. Q x y")] exI 1);
   12.20 -by (blast_tac (claset() addIs [LeastI]) 1);
   12.21 -qed "no_choice";
   12.22 -
   12.23 -(*------------------------------------------------------------
   12.24 -    Properties of the *-transform applied to sets of reals
   12.25 - ------------------------------------------------------------*)
   12.26 -
   12.27 -Goalw [starset_def] "*s*(UNIV::real set) = (UNIV::hypreal set)";
   12.28 -by (Auto_tac);
   12.29 -qed "STAR_real_set";
   12.30 -Addsimps [STAR_real_set];
   12.31 -
   12.32 -Goalw [starset_def] "*s* {} = {}";
   12.33 -by (Step_tac 1);
   12.34 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   12.35 -by (dres_inst_tac [("x","%n. xa n")] bspec 1);
   12.36 -by (Auto_tac);
   12.37 -qed "STAR_empty_set";
   12.38 -Addsimps [STAR_empty_set];
   12.39 -
   12.40 -Goalw [starset_def] "*s* (A Un B) = *s* A Un *s* B";
   12.41 -by (Auto_tac);
   12.42 -by (REPEAT(blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 2));
   12.43 -by (dtac FreeUltrafilterNat_Compl_mem 1);
   12.44 -by (dtac bspec 1 THEN assume_tac 1);
   12.45 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   12.46 -by (Auto_tac);
   12.47 -by (Fuf_tac 1);
   12.48 -qed "STAR_Un";
   12.49 -
   12.50 -Goalw [starset_def] "*s* (A Int B) = *s* A Int *s* B";
   12.51 -by (Auto_tac);
   12.52 -by (blast_tac (claset() addIs [FreeUltrafilterNat_Int,
   12.53 -               FreeUltrafilterNat_subset]) 3);
   12.54 -by (REPEAT(blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 1));
   12.55 -qed "STAR_Int";
   12.56 -
   12.57 -Goalw [starset_def] "*s* -A = -( *s* A)";
   12.58 -by (Auto_tac);
   12.59 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   12.60 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 2);
   12.61 -by (REPEAT(Step_tac 1) THEN Auto_tac);
   12.62 -by (Fuf_empty_tac 1);
   12.63 -by (dtac FreeUltrafilterNat_Compl_mem 1);
   12.64 -by (Fuf_tac 1);
   12.65 -qed "STAR_Compl";
   12.66 -
   12.67 -goal Set.thy "(A - B) = (A Int (- B))";
   12.68 -by (Step_tac 1);
   12.69 -qed "set_diff_iff2";
   12.70 -
   12.71 -Goal "x ~: *s* F ==> x : *s* (- F)";
   12.72 -by (auto_tac (claset(),simpset() addsimps [STAR_Compl]));
   12.73 -qed "STAR_mem_Compl";
   12.74 -
   12.75 -Goal "*s* (A - B) = *s* A - *s* B";
   12.76 -by (auto_tac (claset(),simpset() addsimps 
   12.77 -         [set_diff_iff2,STAR_Int,STAR_Compl]));
   12.78 -qed "STAR_diff";
   12.79 -
   12.80 -Goalw [starset_def] "A <= B ==> *s* A <= *s* B";
   12.81 -by (REPEAT(blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 1));
   12.82 -qed "STAR_subset";
   12.83 -
   12.84 -Goalw [starset_def,hypreal_of_real_def] 
   12.85 -          "a : A ==> hypreal_of_real a : *s* A";
   12.86 -by (auto_tac (claset() addIs [FreeUltrafilterNat_subset],simpset()));
   12.87 -qed "STAR_mem";
   12.88 -
   12.89 -Goalw [starset_def] "hypreal_of_real ` A <= *s* A";
   12.90 -by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_def]));
   12.91 -by (blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 1);
   12.92 -qed "STAR_hypreal_of_real_image_subset";
   12.93 -
   12.94 -Goalw [starset_def] "*s* X Int Reals = hypreal_of_real ` X";
   12.95 -by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_def,SReal_def]));
   12.96 -by (fold_tac [hypreal_of_real_def]);
   12.97 -by (rtac imageI 1 THEN rtac ccontr 1);
   12.98 -by (dtac bspec 1);
   12.99 -by (rtac lemma_hyprel_refl 1);
  12.100 -by (blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 2);
  12.101 -by (Auto_tac);
  12.102 -qed "STAR_hypreal_of_real_Int";
  12.103 -
  12.104 -Goal "x ~: hypreal_of_real ` A ==> ALL y: A. x ~= hypreal_of_real y";
  12.105 -by (Auto_tac);
  12.106 -qed "lemma_not_hyprealA";
  12.107 -
  12.108 -Goal "- {n. X n = xa} = {n. X n ~= xa}";
  12.109 -by (Auto_tac);
  12.110 -qed "lemma_Compl_eq";
  12.111 -
  12.112 -Goalw [starset_def]
  12.113 -    "ALL n. (X n) ~: M \
  12.114 -\         ==> Abs_hypreal(hyprel``{X}) ~: *s* M";
  12.115 -by (Auto_tac THEN rtac bexI 1 THEN rtac lemma_hyprel_refl 2);
  12.116 -by (Auto_tac);
  12.117 -qed "STAR_real_seq_to_hypreal";
  12.118 -
  12.119 -Goalw [starset_def] "*s* {x} = {hypreal_of_real x}";
  12.120 -by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_def]));
  12.121 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  12.122 -by (auto_tac (claset() addIs [FreeUltrafilterNat_subset],simpset()));
  12.123 -qed "STAR_singleton";
  12.124 -Addsimps [STAR_singleton];
  12.125 -
  12.126 -Goal "x ~: F ==> hypreal_of_real x ~: *s* F";
  12.127 -by (auto_tac (claset(),simpset() addsimps
  12.128 -    [starset_def,hypreal_of_real_def]));
  12.129 -by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2);
  12.130 -by (Auto_tac);
  12.131 -qed "STAR_not_mem";
  12.132 -
  12.133 -Goal "[| x : *s* A; A <= B |] ==> x : *s* B";
  12.134 -by (blast_tac (claset() addDs [STAR_subset]) 1);
  12.135 -qed "STAR_subset_closed";
  12.136 -
  12.137 -(*------------------------------------------------------------------ 
  12.138 -   Nonstandard extension of a set (defined using a constant 
  12.139 -   sequence) as a special case of an internal set
  12.140 - -----------------------------------------------------------------*)
  12.141 -
  12.142 -Goalw [starset_n_def,starset_def] 
  12.143 -     "ALL n. (As n = A) ==> *sn* As = *s* A";
  12.144 -by (Auto_tac);
  12.145 -qed "starset_n_starset";
  12.146 -
  12.147 -
  12.148 -(*----------------------------------------------------------------*)
  12.149 -(* Theorems about nonstandard extensions of functions             *)
  12.150 -(*----------------------------------------------------------------*)
  12.151 -
  12.152 -(*----------------------------------------------------------------*) 
  12.153 -(* Nonstandard extension of a function (defined using a           *)
  12.154 -(* constant sequence) as a special case of an internal function   *)
  12.155 -(*----------------------------------------------------------------*)
  12.156 -
  12.157 -Goalw [starfun_n_def,starfun_def] 
  12.158 -     "ALL n. (F n = f) ==> *fn* F = *f* f";
  12.159 -by (Auto_tac);
  12.160 -qed "starfun_n_starfun";
  12.161 -
  12.162 -
  12.163 -(* 
  12.164 -   Prove that hrabs is a nonstandard extension of rabs without
  12.165 -   use of congruence property (proved after this for general
  12.166 -   nonstandard extensions of real valued functions). This makes 
  12.167 -   proof much longer- see comments at end of HREALABS.thy where
  12.168 -   we proved a congruence theorem for hrabs. 
  12.169 -
  12.170 -   NEW!!! No need to prove all the lemmas anymore. Use the ultrafilter
  12.171 -   tactic! 
  12.172 -*)
  12.173 -  
  12.174 -Goalw [is_starext_def] "is_starext abs abs";
  12.175 -by (Step_tac 1);
  12.176 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.177 -by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  12.178 -by Auto_tac;
  12.179 -by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2);
  12.180 -by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2);
  12.181 -by (auto_tac (claset() addSDs [spec],
  12.182 -              simpset() addsimps [hypreal_minus,hrabs_def, hypreal_zero_def,
  12.183 -                hypreal_le_def, hypreal_less_def]));
  12.184 -by (TRYALL(Ultra_tac));
  12.185 -by (TRYALL(arith_tac));
  12.186 -qed "hrabs_is_starext_rabs";
  12.187 -
  12.188 -Goal "[| X: Rep_hypreal z; Y: Rep_hypreal z |] \
  12.189 -\     ==> {n. X n = Y n} : FreeUltrafilterNat";
  12.190 -by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
  12.191 -by (Auto_tac THEN Fuf_tac 1);
  12.192 -qed "Rep_hypreal_FreeUltrafilterNat";
  12.193 -
  12.194 -(*-----------------------------------------------------------------------
  12.195 -    Nonstandard extension of functions- congruence 
  12.196 - -----------------------------------------------------------------------*) 
  12.197 -
  12.198 -Goalw [congruent_def] "congruent hyprel (%X. hyprel``{%n. f (X n)})";
  12.199 -by Auto_tac;
  12.200 -by (ALLGOALS(Fuf_tac));
  12.201 -qed "starfun_congruent";
  12.202 -
  12.203 -Goalw [starfun_def]
  12.204 -      "( *f* f) (Abs_hypreal(hyprel``{%n. X n})) = \
  12.205 -\      Abs_hypreal(hyprel `` {%n. f (X n)})";
  12.206 -by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
  12.207 -by (simp_tac (simpset() addsimps 
  12.208 -   [hyprel_in_hypreal RS Abs_hypreal_inverse,[equiv_hyprel,
  12.209 -   starfun_congruent] MRS UN_equiv_class]) 1);
  12.210 -qed "starfun";
  12.211 -
  12.212 -(*-------------------------------------------
  12.213 -  multiplication: ( *f ) x ( *g ) = *(f x g)  
  12.214 - ------------------------------------------*)
  12.215 -Goal "( *f* f) xa * ( *f* g) xa = ( *f* (%x. f x * g x)) xa";
  12.216 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  12.217 -by (auto_tac (claset(),simpset() addsimps [starfun,hypreal_mult]));
  12.218 -qed "starfun_mult";
  12.219 -Addsimps [starfun_mult RS sym];
  12.220 -
  12.221 -(*---------------------------------------
  12.222 -  addition: ( *f ) + ( *g ) = *(f + g)  
  12.223 - ---------------------------------------*)
  12.224 -Goal "( *f* f) xa + ( *f* g) xa = ( *f* (%x. f x + g x)) xa";
  12.225 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  12.226 -by (auto_tac (claset(),simpset() addsimps [starfun,hypreal_add]));
  12.227 -qed "starfun_add";
  12.228 -Addsimps [starfun_add RS sym];
  12.229 -
  12.230 -(*--------------------------------------------
  12.231 -  subtraction: ( *f ) + -( *g ) = *(f + -g)  
  12.232 - -------------------------------------------*)
  12.233 -
  12.234 -Goal "- ( *f* f) x = ( *f* (%x. - f x)) x";
  12.235 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.236 -by (auto_tac (claset(),simpset() addsimps [starfun, hypreal_minus]));
  12.237 -qed "starfun_minus";
  12.238 -Addsimps [starfun_minus RS sym];
  12.239 -
  12.240 -(*FIXME: delete*)
  12.241 -Goal "( *f* f) xa + -( *f* g) xa = ( *f* (%x. f x + -g x)) xa";
  12.242 -by (Simp_tac 1);
  12.243 -qed "starfun_add_minus";
  12.244 -Addsimps [starfun_add_minus RS sym];
  12.245 -
  12.246 -Goalw [hypreal_diff_def,real_diff_def]
  12.247 -  "( *f* f) xa  - ( *f* g) xa = ( *f* (%x. f x - g x)) xa";
  12.248 -by (rtac starfun_add_minus 1);
  12.249 -qed "starfun_diff";
  12.250 -Addsimps [starfun_diff RS sym];
  12.251 -
  12.252 -(*--------------------------------------
  12.253 -  composition: ( *f ) o ( *g ) = *(f o g)  
  12.254 - ---------------------------------------*)
  12.255 -
  12.256 -Goal "(%x. ( *f* f) (( *f* g) x)) = *f* (%x. f (g x))"; 
  12.257 -by (rtac ext 1);
  12.258 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.259 -by (auto_tac (claset(),simpset() addsimps [starfun]));
  12.260 -qed "starfun_o2";
  12.261 -
  12.262 -Goalw [o_def] "( *f* f) o ( *f* g) = ( *f* (f o g))";
  12.263 -by (simp_tac (simpset() addsimps [starfun_o2]) 1);
  12.264 -qed "starfun_o";
  12.265 -
  12.266 -(*--------------------------------------
  12.267 -  NS extension of constant function
  12.268 - --------------------------------------*)
  12.269 -Goal "( *f* (%x. k)) xa = hypreal_of_real  k";
  12.270 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  12.271 -by (auto_tac (claset(),simpset() addsimps [starfun,
  12.272 -    hypreal_of_real_def]));
  12.273 -qed "starfun_const_fun";
  12.274 -
  12.275 -Addsimps [starfun_const_fun];
  12.276 -
  12.277 -(*----------------------------------------------------
  12.278 -   the NS extension of the identity function
  12.279 - ----------------------------------------------------*)
  12.280 -
  12.281 -Goal "x @= hypreal_of_real a ==> ( *f* (%x. x)) x @= hypreal_of_real  a";
  12.282 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.283 -by (auto_tac (claset(),simpset() addsimps [starfun]));
  12.284 -qed "starfun_Idfun_approx";
  12.285 -
  12.286 -Goal "( *f* (%x. x)) x = x";
  12.287 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.288 -by (auto_tac (claset(),simpset() addsimps [starfun]));
  12.289 -qed "starfun_Id";
  12.290 -Addsimps [starfun_Id];  
  12.291 -
  12.292 -(*----------------------------------------------------------------------
  12.293 -      the *-function is a (nonstandard) extension of the function
  12.294 - ----------------------------------------------------------------------*)
  12.295 -
  12.296 -Goalw [is_starext_def] "is_starext ( *f* f) f";
  12.297 -by (Auto_tac);
  12.298 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.299 -by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  12.300 -by (auto_tac (claset() addSIs [bexI] ,simpset() addsimps [starfun]));
  12.301 -qed "is_starext_starfun";
  12.302 -
  12.303 -(*----------------------------------------------------------------------
  12.304 -     Any nonstandard extension is in fact the *-function
  12.305 - ----------------------------------------------------------------------*)
  12.306 -
  12.307 -Goalw [is_starext_def] "is_starext F f ==> F = *f* f";
  12.308 -by (rtac ext 1);
  12.309 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.310 -by (dres_inst_tac [("x","x")] spec 1);
  12.311 -by (dres_inst_tac [("x","( *f* f) x")] spec 1);
  12.312 -by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
  12.313 -    simpset() addsimps [starfun]));
  12.314 -by (Fuf_empty_tac 1);
  12.315 -qed "is_starfun_starext";
  12.316 -
  12.317 -Goal "(is_starext F f) = (F = *f* f)";
  12.318 -by (blast_tac (claset() addIs [is_starfun_starext,is_starext_starfun]) 1);
  12.319 -qed "is_starext_starfun_iff";
  12.320 -
  12.321 -(*--------------------------------------------------------
  12.322 -   extented function has same solution as its standard
  12.323 -   version for real arguments. i.e they are the same
  12.324 -   for all real arguments
  12.325 - -------------------------------------------------------*)
  12.326 -Goal "( *f* f) (hypreal_of_real a) = hypreal_of_real (f a)";
  12.327 -by (auto_tac (claset(),simpset() addsimps 
  12.328 -     [starfun,hypreal_of_real_def]));
  12.329 -qed "starfun_eq";
  12.330 -
  12.331 -Addsimps [starfun_eq];
  12.332 -
  12.333 -Goal "( *f* f) (hypreal_of_real a) @= hypreal_of_real (f a)";
  12.334 -by (Auto_tac);
  12.335 -qed "starfun_approx";
  12.336 -
  12.337 -(* useful for NS definition of derivatives *)
  12.338 -Goal "( *f* (%h. f (x + h))) xa  = ( *f* f) (hypreal_of_real  x + xa)";
  12.339 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  12.340 -by (auto_tac (claset(),simpset() addsimps [starfun,
  12.341 -    hypreal_of_real_def,hypreal_add]));
  12.342 -qed "starfun_lambda_cancel";
  12.343 -
  12.344 -Goal "( *f* (%h. f(g(x + h)))) xa = ( *f* (f o g)) (hypreal_of_real x + xa)";
  12.345 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  12.346 -by (auto_tac (claset(),simpset() addsimps [starfun,
  12.347 -    hypreal_of_real_def,hypreal_add]));
  12.348 -qed "starfun_lambda_cancel2";
  12.349 -
  12.350 -Goal "[| ( *f* f) xa @= l; ( *f* g) xa @= m; \
  12.351 -\                 l: HFinite; m: HFinite  \
  12.352 -\              |] ==>  ( *f* (%x. f x * g x)) xa @= l * m";
  12.353 -by (dtac approx_mult_HFinite 1);
  12.354 -by (REPEAT(assume_tac 1));
  12.355 -by (auto_tac (claset() addIs [approx_sym RSN (2,approx_HFinite)],
  12.356 -              simpset()));
  12.357 -qed "starfun_mult_HFinite_approx";
  12.358 -
  12.359 -Goal "[| ( *f* f) xa @= l; ( *f* g) xa @= m \
  12.360 -\              |] ==>  ( *f* (%x. f x + g x)) xa @= l + m";
  12.361 -by (auto_tac (claset() addIs [approx_add], simpset()));
  12.362 -qed "starfun_add_approx";
  12.363 -
  12.364 -(*----------------------------------------------------
  12.365 -    Examples: hrabs is nonstandard extension of rabs 
  12.366 -              inverse is nonstandard extension of inverse
  12.367 - ---------------------------------------------------*)
  12.368 -
  12.369 -(* can be proved easily using theorem "starfun" and *)
  12.370 -(* properties of ultrafilter as for inverse below we  *)
  12.371 -(* use the theorem we proved above instead          *)
  12.372 -
  12.373 -Goal "*f* abs = abs";
  12.374 -by (rtac (hrabs_is_starext_rabs RS 
  12.375 -          (is_starext_starfun_iff RS iffD1) RS sym) 1);
  12.376 -qed "starfun_rabs_hrabs";
  12.377 -
  12.378 -Goal "( *f* inverse) x = inverse(x)";
  12.379 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.380 -by (auto_tac (claset(),
  12.381 -            simpset() addsimps [starfun, hypreal_inverse, hypreal_zero_def]));
  12.382 -qed "starfun_inverse_inverse";
  12.383 -Addsimps [starfun_inverse_inverse];
  12.384 -
  12.385 -Goal "inverse (( *f* f) x) = ( *f* (%x. inverse (f x))) x";
  12.386 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.387 -by (auto_tac (claset(),
  12.388 -              simpset() addsimps [starfun, hypreal_inverse]));
  12.389 -qed "starfun_inverse";
  12.390 -Addsimps [starfun_inverse RS sym];
  12.391 -
  12.392 -Goalw [hypreal_divide_def,real_divide_def]
  12.393 -  "( *f* f) xa  / ( *f* g) xa = ( *f* (%x. f x / g x)) xa";
  12.394 -by Auto_tac;
  12.395 -qed "starfun_divide";
  12.396 -Addsimps [starfun_divide RS sym];
  12.397 -
  12.398 -Goal "inverse (( *f* f) x) = ( *f* (%x. inverse (f x))) x";
  12.399 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.400 -by (auto_tac (claset() addIs [FreeUltrafilterNat_subset]
  12.401 -                       addSDs [FreeUltrafilterNat_Compl_mem],
  12.402 -    simpset() addsimps [starfun, hypreal_inverse, hypreal_zero_def]));
  12.403 -qed "starfun_inverse2";
  12.404 -
  12.405 -(*-------------------------------------------------------------
  12.406 -    General lemma/theorem needed for proofs in elementary
  12.407 -    topology of the reals
  12.408 - ------------------------------------------------------------*)
  12.409 -Goalw [starset_def] 
  12.410 -      "( *f* f) x : *s* A ==> x : *s* {x. f x : A}";
  12.411 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.412 -by (auto_tac (claset(),simpset() addsimps [starfun]));
  12.413 -by (rename_tac "X" 1);
  12.414 -by (dres_inst_tac [("x","%n. f (X n)")] bspec 1);
  12.415 -by (Auto_tac THEN Fuf_tac 1);
  12.416 -qed "starfun_mem_starset";
  12.417 -
  12.418 -(*------------------------------------------------------------
  12.419 -   Alternative definition for hrabs with rabs function
  12.420 -   applied entrywise to equivalence class representative.
  12.421 -   This is easily proved using starfun and ns extension thm
  12.422 - ------------------------------------------------------------*)
  12.423 -Goal "abs (Abs_hypreal (hyprel `` {X})) = \
  12.424 -\                 Abs_hypreal(hyprel `` {%n. abs (X n)})";
  12.425 -by (simp_tac (simpset() addsimps [starfun_rabs_hrabs RS sym,starfun]) 1);
  12.426 -qed "hypreal_hrabs";
  12.427 -
  12.428 -(*----------------------------------------------------------------
  12.429 -   nonstandard extension of set through nonstandard extension
  12.430 -   of rabs function i.e hrabs. A more general result should be 
  12.431 -   where we replace rabs by some arbitrary function f and hrabs
  12.432 -   by its NS extenson ( *f* f). See second NS set extension below.
  12.433 - ----------------------------------------------------------------*)
  12.434 -Goalw [starset_def]
  12.435 -   "*s* {x. abs (x + - y) < r} = \
  12.436 -\    {x. abs(x + -hypreal_of_real y) < hypreal_of_real r}";
  12.437 -by (Step_tac 1);
  12.438 -by (ALLGOALS(res_inst_tac [("z","x")] eq_Abs_hypreal));
  12.439 -by (auto_tac (claset() addSIs [exI] addSDs [bspec],
  12.440 -          simpset() addsimps [hypreal_minus, hypreal_of_real_def,hypreal_add,
  12.441 -                              hypreal_hrabs,hypreal_less_def]));
  12.442 -by (Fuf_tac 1);
  12.443 -qed "STAR_rabs_add_minus";
  12.444 -
  12.445 -Goalw [starset_def]
  12.446 -  "*s* {x. abs (f x + - y) < r} = \
  12.447 -\      {x. abs(( *f* f) x + -hypreal_of_real y) < hypreal_of_real r}";
  12.448 -by (Step_tac 1);
  12.449 -by (ALLGOALS(res_inst_tac [("z","x")] eq_Abs_hypreal));
  12.450 -by (auto_tac (claset() addSIs [exI] addSDs [bspec],
  12.451 -    simpset() addsimps [hypreal_minus, hypreal_of_real_def,hypreal_add,
  12.452 -    hypreal_hrabs,hypreal_less_def,starfun]));
  12.453 -by (Fuf_tac 1);
  12.454 -qed "STAR_starfun_rabs_add_minus";
  12.455 -
  12.456 -(*-------------------------------------------------------------------
  12.457 -   Another characterization of Infinitesimal and one of @= relation. 
  12.458 -   In this theory since hypreal_hrabs proved here. (To Check:) Maybe 
  12.459 -   move both if possible? 
  12.460 - -------------------------------------------------------------------*)
  12.461 -Goal "(x:Infinitesimal) = \
  12.462 -\     (EX X:Rep_hypreal(x). \
  12.463 -\       ALL m. {n. abs(X n) < inverse(real(Suc m))} \
  12.464 -\              : FreeUltrafilterNat)";
  12.465 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.466 -by (auto_tac (claset() addSIs [bexI,lemma_hyprel_refl],
  12.467 -	simpset() addsimps [Infinitesimal_hypreal_of_nat_iff,
  12.468 -	    hypreal_of_real_def,hypreal_inverse,
  12.469 -	    hypreal_hrabs,hypreal_less, hypreal_of_nat_def])); 
  12.470 -by (asm_full_simp_tac (simpset() addsimps [real_of_nat_Suc_gt_zero, 
  12.471 -			  real_not_refl2 RS not_sym]) 1) ;
  12.472 -by (dres_inst_tac [("x","n")] spec 1);
  12.473 -by (Fuf_tac 1);
  12.474 -qed  "Infinitesimal_FreeUltrafilterNat_iff2";
  12.475 -
  12.476 -Goal "(Abs_hypreal(hyprel``{X}) @= Abs_hypreal(hyprel``{Y})) = \
  12.477 -\     (ALL m. {n. abs (X n + - Y n) < \
  12.478 -\                 inverse(real(Suc m))} : FreeUltrafilterNat)";
  12.479 -by (stac approx_minus_iff 1);
  12.480 -by (rtac (mem_infmal_iff RS subst) 1);
  12.481 -by (auto_tac (claset(), 
  12.482 -              simpset() addsimps [hypreal_minus, hypreal_add,
  12.483 -                                  Infinitesimal_FreeUltrafilterNat_iff2]));
  12.484 -by (dres_inst_tac [("x","m")] spec 1);
  12.485 -by (Fuf_tac 1);
  12.486 -qed "approx_FreeUltrafilterNat_iff";
  12.487 -
  12.488 -Goal "inj starfun";
  12.489 -by (rtac injI 1);
  12.490 -by (rtac ext 1 THEN rtac ccontr 1);
  12.491 -by (dres_inst_tac [("x","Abs_hypreal(hyprel ``{%n. xa})")] fun_cong 1);
  12.492 -by (auto_tac (claset(),simpset() addsimps [starfun]));
  12.493 -qed "inj_starfun";
    13.1 --- a/src/HOL/Hyperreal/Star.thy	Wed Jan 28 17:01:01 2004 +0100
    13.2 +++ b/src/HOL/Hyperreal/Star.thy	Thu Jan 29 16:51:17 2004 +0100
    13.3 @@ -1,39 +1,589 @@
    13.4  (*  Title       : Star.thy
    13.5      Author      : Jacques D. Fleuriot
    13.6      Copyright   : 1998  University of Cambridge
    13.7 -    Description : defining *-transforms in NSA which extends sets of reals, 
    13.8 +    Description : defining *-transforms in NSA which extends sets of reals,
    13.9                    and real=>real functions
   13.10 -*) 
   13.11 +*)
   13.12  
   13.13 -Star = NSA +
   13.14 +header{*Star-Transforms in Non-Standard Analysis*}
   13.15 +
   13.16 +theory Star = NSA:
   13.17  
   13.18  constdefs
   13.19      (* nonstandard extension of sets *)
   13.20 -    starset :: real set => hypreal set          ("*s* _" [80] 80)
   13.21 +    starset :: "real set => hypreal set"          ("*s* _" [80] 80)
   13.22      "*s* A  == {x. ALL X: Rep_hypreal(x). {n::nat. X n : A}: FreeUltrafilterNat}"
   13.23  
   13.24      (* internal sets *)
   13.25 -    starset_n :: (nat => real set) => hypreal set        ("*sn* _" [80] 80)
   13.26 -    "*sn* As  == {x. ALL X: Rep_hypreal(x). {n::nat. X n : (As n)}: FreeUltrafilterNat}"   
   13.27 -    
   13.28 +    starset_n :: "(nat => real set) => hypreal set"        ("*sn* _" [80] 80)
   13.29 +    "*sn* As  == {x. ALL X: Rep_hypreal(x). {n::nat. X n : (As n)}: FreeUltrafilterNat}"
   13.30 +
   13.31      InternalSets :: "hypreal set set"
   13.32      "InternalSets == {X. EX As. X = *sn* As}"
   13.33  
   13.34      (* nonstandard extension of function *)
   13.35 -    is_starext  ::  [hypreal => hypreal, real => real] => bool
   13.36 +    is_starext  :: "[hypreal => hypreal, real => real] => bool"
   13.37      "is_starext F f == (ALL x y. EX X: Rep_hypreal(x). EX Y: Rep_hypreal(y).
   13.38                          ((y = (F x)) = ({n. Y n = f(X n)} : FreeUltrafilterNat)))"
   13.39 -    
   13.40 -    starfun :: (real => real) => hypreal => hypreal        ("*f* _" [80] 80)
   13.41 -    "*f* f  == (%x. Abs_hypreal(UN X: Rep_hypreal(x). hyprel``{%n. f(X n)}))" 
   13.42 +
   13.43 +    starfun :: "(real => real) => hypreal => hypreal"       ("*f* _" [80] 80)
   13.44 +    "*f* f  == (%x. Abs_hypreal(UN X: Rep_hypreal(x). hyprel``{%n. f(X n)}))"
   13.45  
   13.46      (* internal functions *)
   13.47 -    starfun_n :: (nat => (real => real)) => hypreal => hypreal        ("*fn* _" [80] 80)
   13.48 -    "*fn* F  == (%x. Abs_hypreal(UN X: Rep_hypreal(x). hyprel``{%n. (F n)(X n)}))" 
   13.49 +    starfun_n :: "(nat => (real => real)) => hypreal => hypreal"
   13.50 +                 ("*fn* _" [80] 80)
   13.51 +    "*fn* F  == (%x. Abs_hypreal(UN X: Rep_hypreal(x). hyprel``{%n. (F n)(X n)}))"
   13.52  
   13.53 -    InternalFuns :: (hypreal => hypreal) set
   13.54 +    InternalFuns :: "(hypreal => hypreal) set"
   13.55      "InternalFuns == {X. EX F. X = *fn* F}"
   13.56 -end
   13.57  
   13.58  
   13.59  
   13.60 +(*--------------------------------------------------------
   13.61 +   Preamble - Pulling "EX" over "ALL"
   13.62 + ---------------------------------------------------------*)
   13.63 +
   13.64 +(* This proof does not need AC and was suggested by the
   13.65 +   referee for the JCM Paper: let f(x) be least y such
   13.66 +   that  Q(x,y)
   13.67 +*)
   13.68 +lemma no_choice: "ALL x. EX y. Q x y ==> EX (f :: nat => nat). ALL x. Q x (f x)"
   13.69 +apply (rule_tac x = "%x. LEAST y. Q x y" in exI)
   13.70 +apply (blast intro: LeastI)
   13.71 +done
   13.72 +
   13.73 +(*------------------------------------------------------------
   13.74 +    Properties of the *-transform applied to sets of reals
   13.75 + ------------------------------------------------------------*)
   13.76 +
   13.77 +lemma STAR_real_set: "*s*(UNIV::real set) = (UNIV::hypreal set)"
   13.78 +
   13.79 +apply (unfold starset_def)
   13.80 +apply auto
   13.81 +done
   13.82 +declare STAR_real_set [simp]
   13.83 +
   13.84 +lemma STAR_empty_set: "*s* {} = {}"
   13.85 +apply (unfold starset_def)
   13.86 +apply safe
   13.87 +apply (rule_tac z = "x" in eq_Abs_hypreal)
   13.88 +apply (drule_tac x = "%n. xa n" in bspec)
   13.89 +apply auto
   13.90 +done
   13.91 +declare STAR_empty_set [simp]
   13.92 +
   13.93 +lemma STAR_Un: "*s* (A Un B) = *s* A Un *s* B"
   13.94 +apply (unfold starset_def)
   13.95 +apply auto
   13.96 +  prefer 3 apply (blast intro: FreeUltrafilterNat_subset)
   13.97 + prefer 2 apply (blast intro: FreeUltrafilterNat_subset)
   13.98 +apply (drule FreeUltrafilterNat_Compl_mem)
   13.99 +apply (drule bspec , assumption)
  13.100 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.101 +apply auto
  13.102 +apply ultra
  13.103 +done
  13.104 +
  13.105 +lemma STAR_Int: "*s* (A Int B) = *s* A Int *s* B"
  13.106 +apply (unfold starset_def)
  13.107 +apply auto
  13.108 +prefer 3 apply (blast intro: FreeUltrafilterNat_Int FreeUltrafilterNat_subset)
  13.109 +apply (blast intro: FreeUltrafilterNat_subset)+
  13.110 +done
  13.111 +
  13.112 +lemma STAR_Compl: "*s* -A = -( *s* A)"
  13.113 +apply (auto simp add: starset_def)
  13.114 +apply (rule_tac [!] z = "x" in eq_Abs_hypreal)
  13.115 +apply (auto dest!: bspec);
  13.116 +apply ultra
  13.117 +apply (drule FreeUltrafilterNat_Compl_mem)
  13.118 +apply ultra
  13.119 +done
  13.120 +
  13.121 +lemma STAR_mem_Compl: "x \<notin> *s* F ==> x : *s* (- F)"
  13.122 +apply (auto simp add: STAR_Compl)
  13.123 +done
  13.124 +
  13.125 +lemma STAR_diff: "*s* (A - B) = *s* A - *s* B"
  13.126 +apply (auto simp add: Diff_eq STAR_Int STAR_Compl)
  13.127 +done
  13.128 +
  13.129 +lemma STAR_subset: "A <= B ==> *s* A <= *s* B"
  13.130 +apply (unfold starset_def)
  13.131 +apply (blast intro: FreeUltrafilterNat_subset)+
  13.132 +done
  13.133 +
  13.134 +lemma STAR_mem: "a : A ==> hypreal_of_real a : *s* A"
  13.135 +apply (unfold starset_def hypreal_of_real_def)
  13.136 +apply (auto intro: FreeUltrafilterNat_subset)
  13.137 +done
  13.138 +
  13.139 +lemma STAR_hypreal_of_real_image_subset: "hypreal_of_real ` A <= *s* A"
  13.140 +apply (unfold starset_def)
  13.141 +apply (auto simp add: hypreal_of_real_def)
  13.142 +apply (blast intro: FreeUltrafilterNat_subset)
  13.143 +done
  13.144 +
  13.145 +lemma STAR_hypreal_of_real_Int: "*s* X Int Reals = hypreal_of_real ` X"
  13.146 +apply (unfold starset_def)
  13.147 +apply (auto simp add: hypreal_of_real_def SReal_def)
  13.148 +apply (simp add: hypreal_of_real_def [symmetric])
  13.149 +apply (rule imageI , rule ccontr)
  13.150 +apply (drule bspec)
  13.151 +apply (rule lemma_hyprel_refl)
  13.152 +prefer 2 apply (blast intro: FreeUltrafilterNat_subset)
  13.153 +apply auto
  13.154 +done
  13.155 +
  13.156 +lemma lemma_not_hyprealA: "x \<notin> hypreal_of_real ` A ==> ALL y: A. x \<noteq> hypreal_of_real y"
  13.157 +apply auto
  13.158 +done
  13.159 +
  13.160 +lemma lemma_Compl_eq: "- {n. X n = xa} = {n. X n \<noteq> xa}"
  13.161 +apply auto
  13.162 +done
  13.163 +
  13.164 +lemma STAR_real_seq_to_hypreal:
  13.165 +    "ALL n. (X n) \<notin> M
  13.166 +          ==> Abs_hypreal(hyprel``{X}) \<notin> *s* M"
  13.167 +apply (unfold starset_def)
  13.168 +apply (auto , rule bexI , rule_tac [2] lemma_hyprel_refl)
  13.169 +apply auto
  13.170 +done
  13.171 +
  13.172 +lemma STAR_singleton: "*s* {x} = {hypreal_of_real x}"
  13.173 +apply (unfold starset_def)
  13.174 +apply (auto simp add: hypreal_of_real_def)
  13.175 +apply (rule_tac z = "xa" in eq_Abs_hypreal)
  13.176 +apply (auto intro: FreeUltrafilterNat_subset)
  13.177 +done
  13.178 +declare STAR_singleton [simp]
  13.179 +
  13.180 +lemma STAR_not_mem: "x \<notin> F ==> hypreal_of_real x \<notin> *s* F"
  13.181 +apply (auto simp add: starset_def hypreal_of_real_def)
  13.182 +apply (rule bexI , rule_tac [2] lemma_hyprel_refl)
  13.183 +apply auto
  13.184 +done
  13.185 +
  13.186 +lemma STAR_subset_closed: "[| x : *s* A; A <= B |] ==> x : *s* B"
  13.187 +apply (blast dest: STAR_subset)
  13.188 +done
  13.189 +
  13.190 +(*------------------------------------------------------------------
  13.191 +   Nonstandard extension of a set (defined using a constant
  13.192 +   sequence) as a special case of an internal set
  13.193 + -----------------------------------------------------------------*)
  13.194 +
  13.195 +lemma starset_n_starset:
  13.196 +     "ALL n. (As n = A) ==> *sn* As = *s* A"
  13.197 +
  13.198 +apply (unfold starset_n_def starset_def)
  13.199 +apply auto
  13.200 +done
  13.201 +
  13.202 +
  13.203 +(*----------------------------------------------------------------*)
  13.204 +(* Theorems about nonstandard extensions of functions             *)
  13.205 +(*----------------------------------------------------------------*)
  13.206 +
  13.207 +(*----------------------------------------------------------------*)
  13.208 +(* Nonstandard extension of a function (defined using a           *)
  13.209 +(* constant sequence) as a special case of an internal function   *)
  13.210 +(*----------------------------------------------------------------*)
  13.211 +
  13.212 +lemma starfun_n_starfun:
  13.213 +     "ALL n. (F n = f) ==> *fn* F = *f* f"
  13.214 +
  13.215 +apply (unfold starfun_n_def starfun_def)
  13.216 +apply auto
  13.217 +done
  13.218 +
  13.219 +
  13.220 +(*
  13.221 +   Prove that hrabs is a nonstandard extension of rabs without
  13.222 +   use of congruence property (proved after this for general
  13.223 +   nonstandard extensions of real valued functions). This makes
  13.224 +   proof much longer- see comments at end of HREALABS.thy where
  13.225 +   we proved a congruence theorem for hrabs.
  13.226 +
  13.227 +   NEW!!! No need to prove all the lemmas anymore. Use the ultrafilter
  13.228 +   tactic!
  13.229 +*)
  13.230 +
  13.231 +lemma hrabs_is_starext_rabs: "is_starext abs abs"
  13.232 +
  13.233 +apply (unfold is_starext_def)
  13.234 +apply safe
  13.235 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.236 +apply (rule_tac z = "y" in eq_Abs_hypreal)
  13.237 +apply auto
  13.238 +apply (rule bexI , rule_tac [2] lemma_hyprel_refl)
  13.239 +apply (rule bexI , rule_tac [2] lemma_hyprel_refl)
  13.240 +apply (auto dest!: spec simp add: hypreal_minus hrabs_def hypreal_zero_def hypreal_le_def hypreal_less_def)
  13.241 +apply (arith | ultra)+
  13.242 +done
  13.243 +
  13.244 +lemma Rep_hypreal_FreeUltrafilterNat: "[| X: Rep_hypreal z; Y: Rep_hypreal z |]
  13.245 +      ==> {n. X n = Y n} : FreeUltrafilterNat"
  13.246 +apply (rule_tac z = "z" in eq_Abs_hypreal)
  13.247 +apply (auto , ultra)
  13.248 +done
  13.249 +
  13.250 +(*-----------------------------------------------------------------------
  13.251 +    Nonstandard extension of functions- congruence
  13.252 + -----------------------------------------------------------------------*)
  13.253 +
  13.254 +lemma starfun_congruent: "congruent hyprel (%X. hyprel``{%n. f (X n)})"
  13.255 +apply (unfold congruent_def)
  13.256 +apply auto
  13.257 +apply ultra
  13.258 +done
  13.259 +
  13.260 +lemma starfun:
  13.261 +      "( *f* f) (Abs_hypreal(hyprel``{%n. X n})) =
  13.262 +       Abs_hypreal(hyprel `` {%n. f (X n)})"
  13.263 +apply (unfold starfun_def)
  13.264 +apply (rule_tac f = "Abs_hypreal" in arg_cong)
  13.265 +apply (simp add: hyprel_in_hypreal [THEN Abs_hypreal_inverse] 
  13.266 +                 UN_equiv_class [OF equiv_hyprel starfun_congruent])
  13.267 +done
  13.268 +
  13.269 +(*-------------------------------------------
  13.270 +  multiplication: ( *f ) x ( *g ) = *(f x g)
  13.271 + ------------------------------------------*)
  13.272 +lemma starfun_mult: "( *f* f) xa * ( *f* g) xa = ( *f* (%x. f x * g x)) xa"
  13.273 +apply (rule_tac z = "xa" in eq_Abs_hypreal)
  13.274 +apply (auto simp add: starfun hypreal_mult)
  13.275 +done
  13.276 +declare starfun_mult [symmetric, simp]
  13.277 +
  13.278 +(*---------------------------------------
  13.279 +  addition: ( *f ) + ( *g ) = *(f + g)
  13.280 + ---------------------------------------*)
  13.281 +lemma starfun_add: "( *f* f) xa + ( *f* g) xa = ( *f* (%x. f x + g x)) xa"
  13.282 +apply (rule_tac z = "xa" in eq_Abs_hypreal)
  13.283 +apply (auto simp add: starfun hypreal_add)
  13.284 +done
  13.285 +declare starfun_add [symmetric, simp]
  13.286 +
  13.287 +(*--------------------------------------------
  13.288 +  subtraction: ( *f ) + -( *g ) = *(f + -g)
  13.289 + -------------------------------------------*)
  13.290 +
  13.291 +lemma starfun_minus: "- ( *f* f) x = ( *f* (%x. - f x)) x"
  13.292 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.293 +apply (auto simp add: starfun hypreal_minus)
  13.294 +done
  13.295 +declare starfun_minus [symmetric, simp]
  13.296 +
  13.297 +(*FIXME: delete*)
  13.298 +lemma starfun_add_minus: "( *f* f) xa + -( *f* g) xa = ( *f* (%x. f x + -g x)) xa"
  13.299 +apply (simp (no_asm))
  13.300 +done
  13.301 +declare starfun_add_minus [symmetric, simp]
  13.302 +
  13.303 +lemma starfun_diff:
  13.304 +  "( *f* f) xa  - ( *f* g) xa = ( *f* (%x. f x - g x)) xa"
  13.305 +apply (unfold hypreal_diff_def real_diff_def)
  13.306 +apply (rule starfun_add_minus)
  13.307 +done
  13.308 +declare starfun_diff [symmetric, simp]
  13.309 +
  13.310 +(*--------------------------------------
  13.311 +  composition: ( *f ) o ( *g ) = *(f o g)
  13.312 + ---------------------------------------*)
  13.313 +
  13.314 +lemma starfun_o2: "(%x. ( *f* f) (( *f* g) x)) = *f* (%x. f (g x))"
  13.315 +apply (rule ext)
  13.316 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.317 +apply (auto simp add: starfun)
  13.318 +done
  13.319 +
  13.320 +lemma starfun_o: "( *f* f) o ( *f* g) = ( *f* (f o g))"
  13.321 +apply (unfold o_def)
  13.322 +apply (simp (no_asm) add: starfun_o2)
  13.323 +done
  13.324 +
  13.325 +(*--------------------------------------
  13.326 +  NS extension of constant function
  13.327 + --------------------------------------*)
  13.328 +lemma starfun_const_fun: "( *f* (%x. k)) xa = hypreal_of_real  k"
  13.329 +apply (rule_tac z = "xa" in eq_Abs_hypreal)
  13.330 +apply (auto simp add: starfun hypreal_of_real_def)
  13.331 +done
  13.332 +
  13.333 +declare starfun_const_fun [simp]
  13.334 +
  13.335 +(*----------------------------------------------------
  13.336 +   the NS extension of the identity function
  13.337 + ----------------------------------------------------*)
  13.338 +
  13.339 +lemma starfun_Idfun_approx: "x @= hypreal_of_real a ==> ( *f* (%x. x)) x @= hypreal_of_real  a"
  13.340 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.341 +apply (auto simp add: starfun)
  13.342 +done
  13.343 +
  13.344 +lemma starfun_Id: "( *f* (%x. x)) x = x"
  13.345 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.346 +apply (auto simp add: starfun)
  13.347 +done
  13.348 +declare starfun_Id [simp]
  13.349 +
  13.350 +(*----------------------------------------------------------------------
  13.351 +      the *-function is a (nonstandard) extension of the function
  13.352 + ----------------------------------------------------------------------*)
  13.353 +
  13.354 +lemma is_starext_starfun: "is_starext ( *f* f) f"
  13.355 +
  13.356 +apply (unfold is_starext_def)
  13.357 +apply auto
  13.358 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.359 +apply (rule_tac z = "y" in eq_Abs_hypreal)
  13.360 +apply (auto intro!: bexI simp add: starfun)
  13.361 +done
  13.362 +
  13.363 +(*----------------------------------------------------------------------
  13.364 +     Any nonstandard extension is in fact the *-function
  13.365 + ----------------------------------------------------------------------*)
  13.366 +
  13.367 +lemma is_starfun_starext: "is_starext F f ==> F = *f* f"
  13.368 +
  13.369 +apply (unfold is_starext_def)
  13.370 +apply (rule ext)
  13.371 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.372 +apply (drule_tac x = "x" in spec)
  13.373 +apply (drule_tac x = "( *f* f) x" in spec)
  13.374 +apply (auto dest!: FreeUltrafilterNat_Compl_mem simp add: starfun)
  13.375 +apply ultra
  13.376 +done
  13.377 +
  13.378 +lemma is_starext_starfun_iff: "(is_starext F f) = (F = *f* f)"
  13.379 +apply (blast intro: is_starfun_starext is_starext_starfun)
  13.380 +done
  13.381 +
  13.382 +(*--------------------------------------------------------
  13.383 +   extented function has same solution as its standard
  13.384 +   version for real arguments. i.e they are the same
  13.385 +   for all real arguments
  13.386 + -------------------------------------------------------*)
  13.387 +lemma starfun_eq: "( *f* f) (hypreal_of_real a) = hypreal_of_real (f a)"
  13.388 +apply (auto simp add: starfun hypreal_of_real_def)
  13.389 +done
  13.390 +
  13.391 +declare starfun_eq [simp]
  13.392 +
  13.393 +lemma starfun_approx: "( *f* f) (hypreal_of_real a) @= hypreal_of_real (f a)"
  13.394 +apply auto
  13.395 +done
  13.396 +
  13.397 +(* useful for NS definition of derivatives *)
  13.398 +lemma starfun_lambda_cancel: "( *f* (%h. f (x + h))) xa  = ( *f* f) (hypreal_of_real  x + xa)"
  13.399 +apply (rule_tac z = "xa" in eq_Abs_hypreal)
  13.400 +apply (auto simp add: starfun hypreal_of_real_def hypreal_add)
  13.401 +done
  13.402 +
  13.403 +lemma starfun_lambda_cancel2: "( *f* (%h. f(g(x + h)))) xa = ( *f* (f o g)) (hypreal_of_real x + xa)"
  13.404 +apply (rule_tac z = "xa" in eq_Abs_hypreal)
  13.405 +apply (auto simp add: starfun hypreal_of_real_def hypreal_add)
  13.406 +done
  13.407 +
  13.408 +lemma starfun_mult_HFinite_approx: "[| ( *f* f) xa @= l; ( *f* g) xa @= m;
  13.409 +                  l: HFinite; m: HFinite
  13.410 +               |] ==>  ( *f* (%x. f x * g x)) xa @= l * m"
  13.411 +apply (drule approx_mult_HFinite)
  13.412 +apply (assumption)+
  13.413 +apply (auto intro: approx_HFinite [OF _ approx_sym])
  13.414 +done
  13.415 +
  13.416 +lemma starfun_add_approx: "[| ( *f* f) xa @= l; ( *f* g) xa @= m
  13.417 +               |] ==>  ( *f* (%x. f x + g x)) xa @= l + m"
  13.418 +apply (auto intro: approx_add)
  13.419 +done
  13.420 +
  13.421 +(*----------------------------------------------------
  13.422 +    Examples: hrabs is nonstandard extension of rabs
  13.423 +              inverse is nonstandard extension of inverse
  13.424 + ---------------------------------------------------*)
  13.425 +
  13.426 +(* can be proved easily using theorem "starfun" and *)
  13.427 +(* properties of ultrafilter as for inverse below we  *)
  13.428 +(* use the theorem we proved above instead          *)
  13.429 +
  13.430 +lemma starfun_rabs_hrabs: "*f* abs = abs"
  13.431 +apply (rule hrabs_is_starext_rabs [THEN is_starext_starfun_iff [THEN iffD1], symmetric])
  13.432 +done
  13.433 +
  13.434 +lemma starfun_inverse_inverse: "( *f* inverse) x = inverse(x)"
  13.435 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.436 +apply (auto simp add: starfun hypreal_inverse hypreal_zero_def)
  13.437 +done
  13.438 +declare starfun_inverse_inverse [simp]
  13.439 +
  13.440 +lemma starfun_inverse: "inverse (( *f* f) x) = ( *f* (%x. inverse (f x))) x"
  13.441 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.442 +apply (auto simp add: starfun hypreal_inverse)
  13.443 +done
  13.444 +declare starfun_inverse [symmetric, simp]
  13.445 +
  13.446 +lemma starfun_divide:
  13.447 +  "( *f* f) xa  / ( *f* g) xa = ( *f* (%x. f x / g x)) xa"
  13.448 +apply (unfold hypreal_divide_def real_divide_def)
  13.449 +apply auto
  13.450 +done
  13.451 +declare starfun_divide [symmetric, simp]
  13.452 +
  13.453 +lemma starfun_inverse2: "inverse (( *f* f) x) = ( *f* (%x. inverse (f x))) x"
  13.454 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.455 +apply (auto intro: FreeUltrafilterNat_subset dest!: FreeUltrafilterNat_Compl_mem simp add: starfun hypreal_inverse hypreal_zero_def)
  13.456 +done
  13.457 +
  13.458 +(*-------------------------------------------------------------
  13.459 +    General lemma/theorem needed for proofs in elementary
  13.460 +    topology of the reals
  13.461 + ------------------------------------------------------------*)
  13.462 +lemma starfun_mem_starset:
  13.463 +      "( *f* f) x : *s* A ==> x : *s* {x. f x : A}"
  13.464 +apply (unfold starset_def)
  13.465 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.466 +apply (auto simp add: starfun)
  13.467 +apply (rename_tac "X")
  13.468 +apply (drule_tac x = "%n. f (X n) " in bspec)
  13.469 +apply (auto , ultra)
  13.470 +done
  13.471 +
  13.472 +(*------------------------------------------------------------
  13.473 +   Alternative definition for hrabs with rabs function
  13.474 +   applied entrywise to equivalence class representative.
  13.475 +   This is easily proved using starfun and ns extension thm
  13.476 + ------------------------------------------------------------*)
  13.477 +lemma hypreal_hrabs: "abs (Abs_hypreal (hyprel `` {X})) =
  13.478 +                  Abs_hypreal(hyprel `` {%n. abs (X n)})"
  13.479 +apply (simp (no_asm) add: starfun_rabs_hrabs [symmetric] starfun)
  13.480 +done
  13.481 +
  13.482 +(*----------------------------------------------------------------
  13.483 +   nonstandard extension of set through nonstandard extension
  13.484 +   of rabs function i.e hrabs. A more general result should be
  13.485 +   where we replace rabs by some arbitrary function f and hrabs
  13.486 +   by its NS extenson ( *f* f). See second NS set extension below.
  13.487 + ----------------------------------------------------------------*)
  13.488 +lemma STAR_rabs_add_minus:
  13.489 +   "*s* {x. abs (x + - y) < r} =
  13.490 +     {x. abs(x + -hypreal_of_real y) < hypreal_of_real r}"
  13.491 +apply (unfold starset_def)
  13.492 +apply safe
  13.493 +apply (rule_tac [!] z = "x" in eq_Abs_hypreal)
  13.494 +apply (auto intro!: exI dest!: bspec simp add: hypreal_minus hypreal_of_real_def hypreal_add hypreal_hrabs hypreal_less)
  13.495 +apply ultra
  13.496 +done
  13.497 +
  13.498 +lemma STAR_starfun_rabs_add_minus:
  13.499 +  "*s* {x. abs (f x + - y) < r} =
  13.500 +       {x. abs(( *f* f) x + -hypreal_of_real y) < hypreal_of_real r}"
  13.501 +apply (unfold starset_def)
  13.502 +apply safe
  13.503 +apply (rule_tac [!] z = "x" in eq_Abs_hypreal)
  13.504 +apply (auto intro!: exI dest!: bspec simp add: hypreal_minus hypreal_of_real_def hypreal_add hypreal_hrabs hypreal_less starfun)
  13.505 +apply ultra
  13.506 +done
  13.507 +
  13.508 +(*-------------------------------------------------------------------
  13.509 +   Another characterization of Infinitesimal and one of @= relation.
  13.510 +   In this theory since hypreal_hrabs proved here. (To Check:) Maybe
  13.511 +   move both if possible?
  13.512 + -------------------------------------------------------------------*)
  13.513 +lemma Infinitesimal_FreeUltrafilterNat_iff2: "(x:Infinitesimal) =
  13.514 +      (EX X:Rep_hypreal(x).
  13.515 +        ALL m. {n. abs(X n) < inverse(real(Suc m))}
  13.516 +               : FreeUltrafilterNat)"
  13.517 +apply (rule_tac z = "x" in eq_Abs_hypreal)
  13.518 +apply (auto intro!: bexI lemma_hyprel_refl 
  13.519 +            simp add: Infinitesimal_hypreal_of_nat_iff hypreal_of_real_def 
  13.520 +     hypreal_inverse hypreal_hrabs hypreal_less hypreal_of_nat_def)
  13.521 +apply (drule_tac x = "n" in spec)
  13.522 +apply ultra
  13.523 +done
  13.524 +
  13.525 +lemma approx_FreeUltrafilterNat_iff: "(Abs_hypreal(hyprel``{X}) @= Abs_hypreal(hyprel``{Y})) =
  13.526 +      (ALL m. {n. abs (X n + - Y n) <
  13.527 +                  inverse(real(Suc m))} : FreeUltrafilterNat)"
  13.528 +apply (subst approx_minus_iff)
  13.529 +apply (rule mem_infmal_iff [THEN subst])
  13.530 +apply (auto simp add: hypreal_minus hypreal_add Infinitesimal_FreeUltrafilterNat_iff2)
  13.531 +apply (drule_tac x = "m" in spec)
  13.532 +apply ultra
  13.533 +done
  13.534 +
  13.535 +lemma inj_starfun: "inj starfun"
  13.536 +apply (rule inj_onI)
  13.537 +apply (rule ext , rule ccontr)
  13.538 +apply (drule_tac x = "Abs_hypreal (hyprel ``{%n. xa}) " in fun_cong)
  13.539 +apply (auto simp add: starfun)
  13.540 +done
  13.541 +
  13.542 +ML
  13.543 +{*
  13.544 +val starset_def = thm"starset_def";
  13.545 +val starset_n_def = thm"starset_n_def";
  13.546 +val InternalSets_def = thm"InternalSets_def";
  13.547 +val is_starext_def = thm"is_starext_def";
  13.548 +val starfun_def = thm"starfun_def";
  13.549 +val starfun_n_def = thm"starfun_n_def";
  13.550 +val InternalFuns_def = thm"InternalFuns_def";
  13.551 +
  13.552 +val no_choice = thm "no_choice";
  13.553 +val STAR_real_set = thm "STAR_real_set";
  13.554 +val STAR_empty_set = thm "STAR_empty_set";
  13.555 +val STAR_Un = thm "STAR_Un";
  13.556 +val STAR_Int = thm "STAR_Int";
  13.557 +val STAR_Compl = thm "STAR_Compl";
  13.558 +val STAR_mem_Compl = thm "STAR_mem_Compl";
  13.559 +val STAR_diff = thm "STAR_diff";
  13.560 +val STAR_subset = thm "STAR_subset";
  13.561 +val STAR_mem = thm "STAR_mem";
  13.562 +val STAR_hypreal_of_real_image_subset = thm "STAR_hypreal_of_real_image_subset";
  13.563 +val STAR_hypreal_of_real_Int = thm "STAR_hypreal_of_real_Int";
  13.564 +val STAR_real_seq_to_hypreal = thm "STAR_real_seq_to_hypreal";
  13.565 +val STAR_singleton = thm "STAR_singleton";
  13.566 +val STAR_not_mem = thm "STAR_not_mem";
  13.567 +val STAR_subset_closed = thm "STAR_subset_closed";
  13.568 +val starset_n_starset = thm "starset_n_starset";
  13.569 +val starfun_n_starfun = thm "starfun_n_starfun";
  13.570 +val hrabs_is_starext_rabs = thm "hrabs_is_starext_rabs";
  13.571 +val Rep_hypreal_FreeUltrafilterNat = thm "Rep_hypreal_FreeUltrafilterNat";
  13.572 +val starfun_congruent = thm "starfun_congruent";
  13.573 +val starfun = thm "starfun";
  13.574 +val starfun_mult = thm "starfun_mult";
  13.575 +val starfun_add = thm "starfun_add";
  13.576 +val starfun_minus = thm "starfun_minus";
  13.577 +val starfun_add_minus = thm "starfun_add_minus";
  13.578 +val starfun_diff = thm "starfun_diff";
  13.579 +val starfun_o2 = thm "starfun_o2";
  13.580 +val starfun_o = thm "starfun_o";
  13.581 +val starfun_const_fun = thm "starfun_const_fun";
  13.582 +val starfun_Idfun_approx = thm "starfun_Idfun_approx";
  13.583 +val starfun_Id = thm "starfun_Id";
  13.584 +val is_starext_starfun = thm "is_starext_starfun";
  13.585 +val is_starfun_starext = thm "is_starfun_starext";
  13.586 +val is_starext_starfun_iff = thm "is_starext_starfun_iff";
  13.587 +val starfun_eq = thm "starfun_eq";
  13.588 +val starfun_approx = thm "starfun_approx";
  13.589 +val starfun_lambda_cancel = thm "starfun_lambda_cancel";
  13.590 +val starfun_lambda_cancel2 = thm "starfun_lambda_cancel2";
  13.591 +val starfun_mult_HFinite_approx = thm "starfun_mult_HFinite_approx";
  13.592 +val starfun_add_approx = thm "starfun_add_approx";
  13.593 +val starfun_rabs_hrabs = thm "starfun_rabs_hrabs";
  13.594 +val starfun_inverse_inverse = thm "starfun_inverse_inverse";
  13.595 +val starfun_inverse = thm "starfun_inverse";
  13.596 +val starfun_divide = thm "starfun_divide";
  13.597 +val starfun_inverse2 = thm "starfun_inverse2";
  13.598 +val starfun_mem_starset = thm "starfun_mem_starset";
  13.599 +val hypreal_hrabs = thm "hypreal_hrabs";
  13.600 +val STAR_rabs_add_minus = thm "STAR_rabs_add_minus";
  13.601 +val STAR_starfun_rabs_add_minus = thm "STAR_starfun_rabs_add_minus";
  13.602 +val Infinitesimal_FreeUltrafilterNat_iff2 = thm "Infinitesimal_FreeUltrafilterNat_iff2";
  13.603 +val approx_FreeUltrafilterNat_iff = thm "approx_FreeUltrafilterNat_iff";
  13.604 +val inj_starfun = thm "inj_starfun";
  13.605 +*}
  13.606 +
  13.607 +end
    14.1 --- a/src/HOL/Hyperreal/Transcendental.ML	Wed Jan 28 17:01:01 2004 +0100
    14.2 +++ b/src/HOL/Hyperreal/Transcendental.ML	Thu Jan 29 16:51:17 2004 +0100
    14.3 @@ -1216,7 +1216,6 @@
    14.4  by Auto_tac;
    14.5  qed "exp_ln_eq";
    14.6  
    14.7 -Addsimps [hypreal_less_not_refl];
    14.8  
    14.9  (* ------------------------------------------------------------------------ *)
   14.10  (* Basic properties of the trig functions                                   *)
    15.1 --- a/src/HOL/Hyperreal/hypreal_arith.ML	Wed Jan 28 17:01:01 2004 +0100
    15.2 +++ b/src/HOL/Hyperreal/hypreal_arith.ML	Thu Jan 29 16:51:17 2004 +0100
    15.3 @@ -9,6 +9,8 @@
    15.4  *)
    15.5  
    15.6  (*FIXME DELETE*)
    15.7 +val hypreal_mult_less_mono2 = thm"hypreal_mult_less_mono2";
    15.8 +
    15.9  val hypreal_mult_left_mono =
   15.10      read_instantiate_sg(sign_of (the_context())) [("a","?a::hypreal")] mult_left_mono;
   15.11  
    16.1 --- a/src/HOL/IsaMakefile	Wed Jan 28 17:01:01 2004 +0100
    16.2 +++ b/src/HOL/IsaMakefile	Thu Jan 29 16:51:17 2004 +0100
    16.3 @@ -154,10 +154,10 @@
    16.4    Hyperreal/Lim.ML Hyperreal/Lim.thy  Hyperreal/Log.ML Hyperreal/Log.thy\
    16.5    Hyperreal/MacLaurin.ML Hyperreal/MacLaurin.thy\
    16.6    Hyperreal/NatStar.ML Hyperreal/NatStar.thy\
    16.7 -  Hyperreal/NSA.ML Hyperreal/NSA.thy Hyperreal/NthRoot.thy\
    16.8 +  Hyperreal/NSA.thy Hyperreal/NthRoot.thy\
    16.9    Hyperreal/Poly.ML Hyperreal/Poly.thy\
   16.10    Hyperreal/SEQ.ML Hyperreal/SEQ.thy Hyperreal/Series.ML Hyperreal/Series.thy\
   16.11 -  Hyperreal/Star.ML Hyperreal/Star.thy Hyperreal/Transcendental.ML\
   16.12 +  Hyperreal/Star.thy Hyperreal/Transcendental.ML\
   16.13    Hyperreal/Transcendental.thy Hyperreal/fuf.ML Hyperreal/hypreal_arith.ML \
   16.14    Complex/Complex_Main.thy\
   16.15    Complex/CLim.ML Complex/CLim.thy\
    17.1 --- a/src/HOL/Ring_and_Field.thy	Wed Jan 28 17:01:01 2004 +0100
    17.2 +++ b/src/HOL/Ring_and_Field.thy	Thu Jan 29 16:51:17 2004 +0100
    17.3 @@ -249,7 +249,8 @@
    17.4  apply (erule add_strict_left_mono)
    17.5  done
    17.6  
    17.7 -lemma add_less_le_mono: "[| a<b; c\<le>d |] ==> a + c < b + (d::'a::ordered_semiring)"
    17.8 +lemma add_less_le_mono:
    17.9 +     "[| a<b; c\<le>d |] ==> a + c < b + (d::'a::ordered_semiring)"
   17.10  apply (erule add_strict_right_mono [THEN order_less_le_trans])
   17.11  apply (erule add_left_mono) 
   17.12  done