New theories: construction of hypernaturals, nonstandard extensions,
authorfleuriot
Thu Sep 21 12:17:11 2000 +0200 (2000-09-21)
changeset 10045c76b73e16711
parent 10044 07218d743c62
child 10046 22bf56fa9b44
New theories: construction of hypernaturals, nonstandard extensions,
and some nonstandard analysis.
src/HOL/Real/Hyperreal/HRealAbs.ML
src/HOL/Real/Hyperreal/HRealAbs.thy
src/HOL/Real/Hyperreal/HyperNat.ML
src/HOL/Real/Hyperreal/HyperNat.thy
src/HOL/Real/Hyperreal/HyperOrd.ML
src/HOL/Real/Hyperreal/HyperOrd.thy
src/HOL/Real/Hyperreal/HyperPow.ML
src/HOL/Real/Hyperreal/HyperPow.thy
src/HOL/Real/Hyperreal/Lim.ML
src/HOL/Real/Hyperreal/Lim.thy
src/HOL/Real/Hyperreal/NSA.ML
src/HOL/Real/Hyperreal/NSA.thy
src/HOL/Real/Hyperreal/NatStar.ML
src/HOL/Real/Hyperreal/NatStar.thy
src/HOL/Real/Hyperreal/SEQ.ML
src/HOL/Real/Hyperreal/SEQ.thy
src/HOL/Real/Hyperreal/Series.ML
src/HOL/Real/Hyperreal/Series.thy
src/HOL/Real/Hyperreal/Star.ML
src/HOL/Real/Hyperreal/Star.thy
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Real/Hyperreal/HRealAbs.ML	Thu Sep 21 12:17:11 2000 +0200
     1.3 @@ -0,0 +1,309 @@
     1.4 +(*  Title       : HRealAbs.ML
     1.5 +    Author      : Jacques D. Fleuriot
     1.6 +    Copyright   : 1998  University of Cambridge
     1.7 +    Description : Absolute value function for the hyperreals
     1.8 +                  Similar to RealAbs.thy
     1.9 +*) 
    1.10 +
    1.11 +
    1.12 +(*------------------------------------------------------------
    1.13 +  absolute value on hyperreals as pointwise operation on 
    1.14 +  equivalence class representative
    1.15 + ------------------------------------------------------------*)
    1.16 +
    1.17 +Goalw [hrabs_def]
    1.18 +"abs (Abs_hypreal (hyprel ^^ {X})) = \
    1.19 +\            Abs_hypreal(hyprel ^^ {%n. abs (X n)})";
    1.20 +by (auto_tac (claset(),simpset() addsimps [hypreal_zero_def,
    1.21 +    hypreal_le,hypreal_minus]));
    1.22 +by (ALLGOALS(Ultra_tac THEN' arith_tac ));
    1.23 +qed "hypreal_hrabs";
    1.24 +
    1.25 +(*------------------------------------------------------------
    1.26 +   Properties of the absolute value function over the reals
    1.27 +   (adapted version of previously proved theorems about abs)
    1.28 + ------------------------------------------------------------*)
    1.29 +Goalw [hrabs_def] "abs r = (if (0::hypreal)<=r then r else -r)";
    1.30 +by (Step_tac 1);
    1.31 +qed "hrabs_iff";
    1.32 +
    1.33 +Goalw [hrabs_def] "abs (0::hypreal) = (0::hypreal)";
    1.34 +by (rtac (hypreal_le_refl RS if_P) 1);
    1.35 +qed "hrabs_zero";
    1.36 +
    1.37 +Addsimps [hrabs_zero];
    1.38 +
    1.39 +Goalw [hrabs_def] "abs (0::hypreal) = -(0::hypreal)";
    1.40 +by (rtac (hypreal_minus_zero RS ssubst) 1);
    1.41 +by (rtac if_cancel 1);
    1.42 +qed "hrabs_minus_zero";
    1.43 +
    1.44 +val [prem] = goalw thy [hrabs_def] "(0::hypreal)<=x ==> abs x = x";
    1.45 +by (rtac (prem RS if_P) 1);
    1.46 +qed "hrabs_eqI1";
    1.47 +
    1.48 +val [prem] = goalw thy [hrabs_def] "(0::hypreal)<x ==> abs x = x";
    1.49 +by (simp_tac (simpset() addsimps [(prem 
    1.50 +    RS hypreal_less_imp_le),hrabs_eqI1]) 1);
    1.51 +qed "hrabs_eqI2";
    1.52 +
    1.53 +val [prem] = goalw thy [hrabs_def,hypreal_le_def] 
    1.54 +    "x<(0::hypreal) ==> abs x = -x";
    1.55 +by (simp_tac (simpset() addsimps [prem,if_not_P]) 1);
    1.56 +qed "hrabs_minus_eqI2";
    1.57 +
    1.58 +Goal "!!x. x<=(0::hypreal) ==> abs x = -x";
    1.59 +by (dtac hypreal_le_imp_less_or_eq 1);
    1.60 +by (fast_tac (HOL_cs addIs [hrabs_minus_zero,
    1.61 +    hrabs_minus_eqI2]) 1);
    1.62 +qed "hrabs_minus_eqI1";
    1.63 +
    1.64 +Goalw [hrabs_def,hypreal_le_def] "(0::hypreal)<= abs x";
    1.65 +by (auto_tac (claset() addDs [hypreal_minus_zero_less_iff RS iffD2,
    1.66 +    hypreal_less_asym],simpset()));
    1.67 +qed "hrabs_ge_zero";
    1.68 +
    1.69 +Goal "abs(abs x)=abs (x::hypreal)";
    1.70 +by (res_inst_tac [("r1","abs x")] (hrabs_iff RS ssubst) 1);
    1.71 +by (blast_tac (claset() addIs [if_P,hrabs_ge_zero]) 1);
    1.72 +qed "hrabs_idempotent";
    1.73 +
    1.74 +Goalw [hrabs_def] "(x=(0::hypreal)) = (abs x = (0::hypreal))";
    1.75 +by (Simp_tac 1);
    1.76 +qed "hrabs_zero_iff";
    1.77 +Addsimps [hrabs_zero_iff RS sym];
    1.78 +
    1.79 +Goal  "(x ~= (0::hypreal)) = (abs x ~= 0)";
    1.80 +by (Simp_tac 1);
    1.81 +qed "hrabs_not_zero_iff";
    1.82 +
    1.83 +Goalw [hrabs_def] "(x::hypreal)<=abs x";
    1.84 +by (auto_tac (claset() addDs [not_hypreal_leE RS hypreal_less_imp_le],
    1.85 +    simpset() addsimps [hypreal_le_zero_iff]));
    1.86 +qed "hrabs_ge_self";
    1.87 +
    1.88 +Goalw [hrabs_def] "-(x::hypreal)<=abs x";
    1.89 +by (full_simp_tac (simpset() addsimps [hypreal_ge_zero_iff]) 1);
    1.90 +qed "hrabs_ge_minus_self";
    1.91 +
    1.92 +(* very short proof by "transfer" *)
    1.93 +Goal "abs(x*(y::hypreal)) = (abs x)*(abs y)";
    1.94 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
    1.95 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
    1.96 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrabs,
    1.97 +    hypreal_mult,abs_mult]));
    1.98 +qed "hrabs_mult";
    1.99 +
   1.100 +Goal "x~= (0::hypreal) ==> abs(hrinv(x)) = hrinv(abs(x))";
   1.101 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   1.102 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrabs,
   1.103 +    hypreal_hrinv,hypreal_zero_def]));
   1.104 +by (ultra_tac (claset(),simpset() addsimps [abs_rinv]) 1);
   1.105 +by (arith_tac 1);
   1.106 +qed "hrabs_hrinv";
   1.107 +
   1.108 +(* old version of proof:
   1.109 +Goalw [hrabs_def] 
   1.110 +   "x~= (0::hypreal) ==> abs(hrinv(x)) = hrinv(abs(x))";
   1.111 +by (auto_tac (claset(),simpset() addsimps [hypreal_minus_hrinv]));
   1.112 +by (ALLGOALS(dtac not_hypreal_leE));
   1.113 +by (etac hypreal_less_asym 1);
   1.114 +by (blast_tac (claset() addDs [hypreal_le_imp_less_or_eq,
   1.115 +          hypreal_hrinv_gt_zero]) 1);
   1.116 +by (dtac (hrinv_not_zero RS not_sym) 1);
   1.117 +by (rtac (hypreal_hrinv_less_zero RSN (2,hypreal_less_asym)) 1);
   1.118 +by (assume_tac 2);
   1.119 +by (blast_tac (claset() addSDs [hypreal_le_imp_less_or_eq]) 1);
   1.120 +qed "hrabs_hrinv";
   1.121 +*)
   1.122 +
   1.123 +val [prem] = goal thy "y ~= (0::hypreal) ==> \
   1.124 +\            abs(x*hrinv(y)) = abs(x)*hrinv(abs(y))";
   1.125 +by (res_inst_tac [("c1","abs y")] (hypreal_mult_left_cancel RS subst) 1);
   1.126 +by (simp_tac (simpset() addsimps [(hrabs_not_zero_iff RS sym), prem]) 1);
   1.127 +by (simp_tac (simpset() addsimps [(hrabs_mult RS sym), prem, 
   1.128 +    hrabs_not_zero_iff RS sym] @ hypreal_mult_ac) 1);
   1.129 +qed "hrabs_mult_hrinv";
   1.130 +
   1.131 +Goal "abs(x+(y::hypreal)) <= abs x + abs y";
   1.132 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   1.133 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   1.134 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrabs,
   1.135 +    hypreal_add,hypreal_le,abs_triangle_ineq]));
   1.136 +qed "hrabs_triangle_ineq";
   1.137 +
   1.138 +Goal "abs((w::hypreal) + x + y) <= abs(w) + abs(x) + abs(y)";
   1.139 +by (auto_tac (claset() addSIs [(hrabs_triangle_ineq 
   1.140 +    RS hypreal_le_trans),hypreal_add_left_le_mono1],
   1.141 +    simpset() addsimps [hypreal_add_assoc]));
   1.142 +qed "hrabs_triangle_ineq_three";
   1.143 +
   1.144 +Goalw [hrabs_def] "abs(-x)=abs((x::hypreal))";
   1.145 +by (auto_tac (claset() addSDs [not_hypreal_leE,
   1.146 +   hypreal_less_asym] addIs [hypreal_le_anti_sym],
   1.147 +   simpset() addsimps [hypreal_ge_zero_iff]));
   1.148 +qed "hrabs_minus_cancel";
   1.149 +
   1.150 +Goal "abs((x::hypreal) + -y) = abs (y + -x)";
   1.151 +by (rtac (hrabs_minus_cancel RS subst) 1);
   1.152 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
   1.153 +qed "hrabs_minus_add_cancel";
   1.154 +
   1.155 +Goal "abs((x::hypreal) + -y) <= abs x + abs y";
   1.156 +by (res_inst_tac [("x1","y")] (hrabs_minus_cancel RS subst) 1);
   1.157 +by (rtac hrabs_triangle_ineq 1);
   1.158 +qed "rhabs_triangle_minus_ineq";
   1.159 +
   1.160 +val prem1::prem2::rest = goal thy 
   1.161 +    "[| abs x < r; abs y < s |] ==> abs(x+y) < r + (s::hypreal)";
   1.162 +by (rtac hypreal_le_less_trans 1);
   1.163 +by (rtac hrabs_triangle_ineq 1);
   1.164 +by (rtac ([prem1,prem2] MRS hypreal_add_less_mono) 1);
   1.165 +qed "hrabs_add_less";
   1.166 +
   1.167 +Goal "[| abs x < r; abs y < s |] \
   1.168 +\     ==> abs(x+ -y) < r + (s::hypreal)";
   1.169 +by (rotate_tac 1 1);
   1.170 +by (dtac (hrabs_minus_cancel RS ssubst) 1);
   1.171 +by (asm_simp_tac (simpset() addsimps [hrabs_add_less]) 1);
   1.172 +qed "hrabs_add_minus_less";
   1.173 +
   1.174 +val prem1::prem2::rest = 
   1.175 +    goal thy "[| abs x<r; abs y<s |] ==> abs(x*y)<r*(s::hypreal)";
   1.176 +by (simp_tac (simpset() addsimps [hrabs_mult]) 1);
   1.177 +by (rtac hypreal_mult_le_less_trans 1);
   1.178 +by (rtac hrabs_ge_zero 1);
   1.179 +by (rtac prem2 1);
   1.180 +by (rtac hypreal_mult_less_mono1 1);
   1.181 +by (rtac (prem2 RS (hrabs_ge_zero RS hypreal_le_less_trans)) 1);
   1.182 +by (rtac prem1 1);
   1.183 +by (rtac ([prem1 RS (hrabs_ge_zero RS hypreal_le_less_trans),
   1.184 +   prem2 RS (hrabs_ge_zero RS hypreal_le_less_trans)] 
   1.185 +   MRS hypreal_mult_order) 1);
   1.186 +qed "hrabs_mult_less";
   1.187 +
   1.188 +Goal "!! x y r. 1hr < abs x ==> abs y <= abs(x*y)";
   1.189 +by (cut_inst_tac [("x1","y")] (hrabs_ge_zero RS hypreal_le_imp_less_or_eq) 1);
   1.190 +by (EVERY1[etac disjE,rtac hypreal_less_imp_le]);
   1.191 +by (dres_inst_tac [("x1","1hr")]  (hypreal_less_minus_iff RS iffD1) 1);
   1.192 +by (forw_inst_tac [("y","abs x +-1hr")] hypreal_mult_order 1);
   1.193 +by (assume_tac 1);
   1.194 +by (rtac (hypreal_less_minus_iff RS iffD2) 1);
   1.195 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_mult_distrib2,
   1.196 +    hrabs_mult, hypreal_mult_commute,hypreal_minus_mult_eq2 RS sym]) 1);
   1.197 +by (dtac sym 1);
   1.198 +by (asm_full_simp_tac (simpset() addsimps [hypreal_le_refl,hrabs_mult]) 1);
   1.199 +qed "hrabs_mult_le";
   1.200 +
   1.201 +Goal "!!x. [| 1hr < abs x; r < abs y|] ==> r < abs(x*y)";
   1.202 +by (fast_tac (HOL_cs addIs [hrabs_mult_le, hypreal_less_le_trans]) 1);
   1.203 +qed "hrabs_mult_gt";
   1.204 +
   1.205 +Goal "!!r. abs x < r ==> (0::hypreal) < r";
   1.206 +by (blast_tac (claset() addSIs [hypreal_le_less_trans,
   1.207 +    hrabs_ge_zero]) 1);
   1.208 +qed "hrabs_less_gt_zero";
   1.209 +
   1.210 +Goalw [hrabs_def] "abs 1hr = 1hr";
   1.211 +by (auto_tac (claset() addSDs [not_hypreal_leE 
   1.212 +    RS hypreal_less_asym],simpset() addsimps 
   1.213 +    [hypreal_zero_less_one]));
   1.214 +qed "hrabs_one";
   1.215 +
   1.216 +val prem1::prem2::rest = 
   1.217 +    goal thy "[| (0::hypreal) < x ; x < r |] ==> abs x < r";
   1.218 +by (simp_tac (simpset() addsimps [(prem1 RS hrabs_eqI2),prem2]) 1);
   1.219 +qed "hrabs_lessI";
   1.220 +
   1.221 +Goal "abs x = (x::hypreal) | abs x = -x";
   1.222 +by (cut_inst_tac [("x","0"),("y","x")] hypreal_linear 1);
   1.223 +by (fast_tac (claset() addIs [hrabs_eqI2,hrabs_minus_eqI2,
   1.224 +                            hrabs_zero,hrabs_minus_zero]) 1);
   1.225 +qed "hrabs_disj";
   1.226 +
   1.227 +Goal "abs x = (y::hypreal) ==> x = y | -x = y";
   1.228 +by (dtac sym 1);
   1.229 +by (hyp_subst_tac 1);
   1.230 +by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
   1.231 +by (REPEAT(Asm_simp_tac 1));
   1.232 +qed "hrabs_eq_disj";
   1.233 +
   1.234 +Goal "(abs x < (r::hypreal)) = (-r < x & x < r)";
   1.235 +by (Step_tac 1);
   1.236 +by (rtac (hypreal_less_swap_iff RS iffD2) 1);
   1.237 +by (asm_simp_tac (simpset() addsimps [(hrabs_ge_minus_self 
   1.238 +    RS hypreal_le_less_trans)]) 1);
   1.239 +by (asm_simp_tac (simpset() addsimps [(hrabs_ge_self 
   1.240 +    RS hypreal_le_less_trans)]) 1);
   1.241 +by (EVERY1 [dtac (hypreal_less_swap_iff RS iffD1), rotate_tac 1, 
   1.242 +            dtac (hypreal_minus_minus RS subst), 
   1.243 +            cut_inst_tac [("x","x")] hrabs_disj, dtac disjE ]);
   1.244 +by (assume_tac 3 THEN Auto_tac);
   1.245 +qed "hrabs_interval_iff";
   1.246 +
   1.247 +Goal "(abs x < (r::hypreal)) = (- x < r & x < r)";
   1.248 +by (auto_tac (claset(),simpset() addsimps [hrabs_interval_iff]));
   1.249 +by (dtac (hypreal_less_swap_iff RS iffD1) 1);
   1.250 +by (dtac (hypreal_less_swap_iff RS iffD1) 2);
   1.251 +by (Auto_tac);
   1.252 +qed "hrabs_interval_iff2";
   1.253 +
   1.254 +Goal 
   1.255 +     "(abs (x + -y) < (r::hypreal)) = (y + -r < x & x < y + r)";
   1.256 +by (auto_tac (claset(),simpset() addsimps 
   1.257 +     [hrabs_interval_iff]));
   1.258 +by (ALLGOALS(dtac (hypreal_less_minus_iff RS iffD1)));
   1.259 +by (ALLGOALS(dtac (hypreal_less_minus_iff RS iffD1)));
   1.260 +by (ALLGOALS(rtac (hypreal_less_minus_iff RS iffD2)));
   1.261 +by (auto_tac (claset(),simpset() addsimps 
   1.262 +    [hypreal_minus_add_distrib] addsimps hypreal_add_ac));
   1.263 +qed "hrabs_add_minus_interval_iff";
   1.264 +
   1.265 +Goal "x < (y::hypreal) ==> abs(y + -x) = y + -x";
   1.266 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
   1.267 +by (etac hrabs_eqI2 1);
   1.268 +qed "hrabs_less_eqI2";
   1.269 +
   1.270 +Goal "x < (y::hypreal) ==> abs(x + -y) = y + -x";
   1.271 +by (auto_tac (claset() addDs [hrabs_less_eqI2],
   1.272 +              simpset() addsimps [hrabs_minus_add_cancel]));
   1.273 +qed "hrabs_less_eqI2a";
   1.274 +
   1.275 +Goal "x <= (y::hypreal) ==> abs(y + -x) = y + -x";
   1.276 +by (auto_tac (claset() addDs  [hypreal_le_imp_less_or_eq,
   1.277 +              hrabs_less_eqI2],simpset()));
   1.278 +qed "hrabs_le_eqI2";
   1.279 +
   1.280 +Goal "x <= (y::hypreal) ==> abs(x + -y) = y + -x";
   1.281 +by (auto_tac (claset() addDs [hrabs_le_eqI2],
   1.282 +              simpset() addsimps [hrabs_minus_add_cancel]));
   1.283 +qed "hrabs_le_eqI2a";
   1.284 +
   1.285 +(* Needed in Geom.ML *)
   1.286 +Goal "(y::hypreal) + - x + (y + - z) = abs (x + - z) \
   1.287 +\     ==> y = z | x = y";
   1.288 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   1.289 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   1.290 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   1.291 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrabs,
   1.292 +    hypreal_minus,hypreal_add]));
   1.293 +by (Ultra_tac 1 THEN arith_tac 1);
   1.294 +qed "hrabs_add_lemma_disj";
   1.295 +
   1.296 +(* Needed in Geom.ML *)
   1.297 +Goal "(x::hypreal) + - y + (z + - y) = abs (x + - z) \
   1.298 +\     ==> y = z | x = y";
   1.299 +by (rtac (hypreal_minus_eq_cancel RS subst) 1);
   1.300 +by (res_inst_tac [("b1","y")] (hypreal_minus_eq_cancel RS subst) 1);
   1.301 +by (rtac hrabs_add_lemma_disj 1);
   1.302 +by (asm_full_simp_tac (simpset() addsimps [hrabs_minus_add_cancel] 
   1.303 +         @ hypreal_add_ac) 1);
   1.304 +qed "hrabs_add_lemma_disj2";
   1.305 + 
   1.306 +(*----------------------------------------------------------
   1.307 +    Relating hrabs to abs through embedding of IR into IR*
   1.308 + ----------------------------------------------------------*)
   1.309 +Goalw [hypreal_of_real_def] 
   1.310 +    "abs (hypreal_of_real r) = hypreal_of_real (abs r)";
   1.311 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrabs]));
   1.312 +qed "hypreal_of_real_hrabs";
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/Real/Hyperreal/HRealAbs.thy	Thu Sep 21 12:17:11 2000 +0200
     2.3 @@ -0,0 +1,12 @@
     2.4 +(*  Title       : HRealAbs.thy
     2.5 +    Author      : Jacques D. Fleuriot
     2.6 +    Copyright   : 1998  University of Cambridge
     2.7 +    Description : Absolute value function for the hyperreals
     2.8 +*) 
     2.9 +
    2.10 +HRealAbs = HyperOrd + RealAbs + 
    2.11 +
    2.12 +defs
    2.13 +    hrabs_def "abs r  == if (0::hypreal) <=r then r else -r" 
    2.14 +
    2.15 +end
    2.16 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/HOL/Real/Hyperreal/HyperNat.ML	Thu Sep 21 12:17:11 2000 +0200
     3.3 @@ -0,0 +1,1338 @@
     3.4 +(*  Title       : HyperNat.ML
     3.5 +    Author      : Jacques D. Fleuriot
     3.6 +    Copyright   : 1998  University of Cambridge
     3.7 +    Description : Explicit construction of hypernaturals using 
     3.8 +                  ultrafilters
     3.9 +*) 
    3.10 +       
    3.11 +(*------------------------------------------------------------------------
    3.12 +                       Properties of hypnatrel
    3.13 + ------------------------------------------------------------------------*)
    3.14 +
    3.15 +(** Proving that hyprel is an equivalence relation       **)
    3.16 +(** Natural deduction for hypnatrel - similar to hyprel! **)
    3.17 +
    3.18 +Goalw [hypnatrel_def]
    3.19 +   "((X,Y): hypnatrel) = ({n. X n = Y n}: FreeUltrafilterNat)";
    3.20 +by (Fast_tac 1);
    3.21 +qed "hypnatrel_iff";
    3.22 +
    3.23 +Goalw [hypnatrel_def] 
    3.24 +     "{n. X n = Y n}: FreeUltrafilterNat ==> (X,Y): hypnatrel";
    3.25 +by (Fast_tac 1);
    3.26 +qed "hypnatrelI";
    3.27 +
    3.28 +Goalw [hypnatrel_def]
    3.29 +  "p: hypnatrel --> (EX X Y. \
    3.30 +\                 p = (X,Y) & {n. X n = Y n} : FreeUltrafilterNat)";
    3.31 +by (Fast_tac 1);
    3.32 +qed "hypnatrelE_lemma";
    3.33 +
    3.34 +val [major,minor] = goal thy
    3.35 +  "[| p: hypnatrel;  \
    3.36 +\     !!X Y. [| p = (X,Y); {n. X n = Y n}: FreeUltrafilterNat\
    3.37 +\            |] ==> Q |] ==> Q";
    3.38 +by (cut_facts_tac [major RS (hypnatrelE_lemma RS mp)] 1);
    3.39 +by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1));
    3.40 +qed "hypnatrelE";
    3.41 +
    3.42 +AddSIs [hypnatrelI];
    3.43 +AddSEs [hypnatrelE];
    3.44 +
    3.45 +Goalw [hypnatrel_def] "(x,x): hypnatrel";
    3.46 +by (Auto_tac);
    3.47 +qed "hypnatrel_refl";
    3.48 +
    3.49 +Goalw [hypnatrel_def] "(x,y): hypnatrel --> (y,x):hypnatrel";
    3.50 +by (auto_tac (claset() addIs [lemma_perm RS subst],simpset()));
    3.51 +qed_spec_mp "hypnatrel_sym";
    3.52 +
    3.53 +Goalw [hypnatrel_def]
    3.54 +      "(x,y): hypnatrel --> (y,z):hypnatrel --> (x,z):hypnatrel";
    3.55 +by (Auto_tac);
    3.56 +by (Fuf_tac 1);
    3.57 +qed_spec_mp "hypnatrel_trans";
    3.58 +
    3.59 +Goalw [equiv_def, refl_def, sym_def, trans_def]
    3.60 +    "equiv {x::nat=>nat. True} hypnatrel";
    3.61 +by (auto_tac (claset() addSIs [hypnatrel_refl] addSEs 
    3.62 +    [hypnatrel_sym,hypnatrel_trans] delrules [hypnatrelI,hypnatrelE],
    3.63 +    simpset()));
    3.64 +qed "equiv_hypnatrel";
    3.65 +
    3.66 +val equiv_hypnatrel_iff =
    3.67 +    [TrueI, TrueI] MRS 
    3.68 +    ([CollectI, CollectI] MRS 
    3.69 +    (equiv_hypnatrel RS eq_equiv_class_iff));
    3.70 +
    3.71 +Goalw  [hypnat_def,hypnatrel_def,quotient_def] "hypnatrel^^{x}:hypnat";
    3.72 +by (Blast_tac 1);
    3.73 +qed "hypnatrel_in_hypnat";
    3.74 +
    3.75 +Goal "inj_on Abs_hypnat hypnat";
    3.76 +by (rtac inj_on_inverseI 1);
    3.77 +by (etac Abs_hypnat_inverse 1);
    3.78 +qed "inj_on_Abs_hypnat";
    3.79 +
    3.80 +Addsimps [equiv_hypnatrel_iff,inj_on_Abs_hypnat RS inj_on_iff,
    3.81 +          hypnatrel_iff, hypnatrel_in_hypnat, Abs_hypnat_inverse];
    3.82 +
    3.83 +Addsimps [equiv_hypnatrel RS eq_equiv_class_iff];
    3.84 +val eq_hypnatrelD = equiv_hypnatrel RSN (2,eq_equiv_class);
    3.85 +
    3.86 +Goal "inj(Rep_hypnat)";
    3.87 +by (rtac inj_inverseI 1);
    3.88 +by (rtac Rep_hypnat_inverse 1);
    3.89 +qed "inj_Rep_hypnat";
    3.90 +
    3.91 +Goalw [hypnatrel_def] "x: hypnatrel ^^ {x}";
    3.92 +by (Step_tac 1);
    3.93 +by (Auto_tac);
    3.94 +qed "lemma_hypnatrel_refl";
    3.95 +
    3.96 +Addsimps [lemma_hypnatrel_refl];
    3.97 +
    3.98 +Goalw [hypnat_def] "{} ~: hypnat";
    3.99 +by (auto_tac (claset() addSEs [quotientE],simpset()));
   3.100 +qed "hypnat_empty_not_mem";
   3.101 +
   3.102 +Addsimps [hypnat_empty_not_mem];
   3.103 +
   3.104 +Goal "Rep_hypnat x ~= {}";
   3.105 +by (cut_inst_tac [("x","x")] Rep_hypnat 1);
   3.106 +by (Auto_tac);
   3.107 +qed "Rep_hypnat_nonempty";
   3.108 +
   3.109 +Addsimps [Rep_hypnat_nonempty];
   3.110 +
   3.111 +(*------------------------------------------------------------------------
   3.112 +   hypnat_of_nat: the injection from nat to hypnat
   3.113 + ------------------------------------------------------------------------*)
   3.114 +Goal "inj(hypnat_of_nat)";
   3.115 +by (rtac injI 1);
   3.116 +by (rewtac hypnat_of_nat_def);
   3.117 +by (dtac (inj_on_Abs_hypnat RS inj_onD) 1);
   3.118 +by (REPEAT (rtac hypnatrel_in_hypnat 1));
   3.119 +by (dtac eq_equiv_class 1);
   3.120 +by (rtac equiv_hypnatrel 1);
   3.121 +by (Fast_tac 1);
   3.122 +by (rtac ccontr 1 THEN rotate_tac 1 1);
   3.123 +by (Auto_tac);
   3.124 +qed "inj_hypnat_of_nat";
   3.125 +
   3.126 +val [prem] = goal thy
   3.127 +    "(!!x. z = Abs_hypnat(hypnatrel^^{x}) ==> P) ==> P";
   3.128 +by (res_inst_tac [("x1","z")] 
   3.129 +    (rewrite_rule [hypnat_def] Rep_hypnat RS quotientE) 1);
   3.130 +by (dres_inst_tac [("f","Abs_hypnat")] arg_cong 1);
   3.131 +by (res_inst_tac [("x","x")] prem 1);
   3.132 +by (asm_full_simp_tac (simpset() addsimps [Rep_hypnat_inverse]) 1);
   3.133 +qed "eq_Abs_hypnat";
   3.134 +
   3.135 +(*-----------------------------------------------------------
   3.136 +   Addition for hyper naturals: hypnat_add 
   3.137 + -----------------------------------------------------------*)
   3.138 +Goalw [congruent2_def]
   3.139 +    "congruent2 hypnatrel (%X Y. hypnatrel^^{%n. X n + Y n})";
   3.140 +by (safe_tac (claset()));
   3.141 +by (ALLGOALS(Fuf_tac));
   3.142 +qed "hypnat_add_congruent2";
   3.143 +
   3.144 +Goalw [hypnat_add_def]
   3.145 +  "Abs_hypnat(hypnatrel^^{%n. X n}) + Abs_hypnat(hypnatrel^^{%n. Y n}) = \
   3.146 +\  Abs_hypnat(hypnatrel^^{%n. X n + Y n})";
   3.147 +by (asm_simp_tac
   3.148 +    (simpset() addsimps [[equiv_hypnatrel, hypnat_add_congruent2] 
   3.149 +     MRS UN_equiv_class2]) 1);
   3.150 +qed "hypnat_add";
   3.151 +
   3.152 +Goal "(z::hypnat) + w = w + z";
   3.153 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.154 +by (res_inst_tac [("z","w")] eq_Abs_hypnat 1);
   3.155 +by (asm_simp_tac (simpset() addsimps (add_ac @ [hypnat_add])) 1);
   3.156 +qed "hypnat_add_commute";
   3.157 +
   3.158 +Goal "((z1::hypnat) + z2) + z3 = z1 + (z2 + z3)";
   3.159 +by (res_inst_tac [("z","z1")] eq_Abs_hypnat 1);
   3.160 +by (res_inst_tac [("z","z2")] eq_Abs_hypnat 1);
   3.161 +by (res_inst_tac [("z","z3")] eq_Abs_hypnat 1);
   3.162 +by (asm_simp_tac (simpset() addsimps [hypnat_add,add_assoc]) 1);
   3.163 +qed "hypnat_add_assoc";
   3.164 +
   3.165 +(*For AC rewriting*)
   3.166 +Goal "(x::hypnat)+(y+z)=y+(x+z)";
   3.167 +by (rtac (hypnat_add_commute RS trans) 1);
   3.168 +by (rtac (hypnat_add_assoc RS trans) 1);
   3.169 +by (rtac (hypnat_add_commute RS arg_cong) 1);
   3.170 +qed "hypnat_add_left_commute";
   3.171 +
   3.172 +(* hypnat addition is an AC operator *)
   3.173 +val hypnat_add_ac = [hypnat_add_assoc,hypnat_add_commute,
   3.174 +                      hypnat_add_left_commute];
   3.175 +
   3.176 +Goalw [hypnat_zero_def] "(0::hypnat) + z = z";
   3.177 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.178 +by (asm_full_simp_tac (simpset() addsimps 
   3.179 +    [hypnat_add]) 1);
   3.180 +qed "hypnat_add_zero_left";
   3.181 +
   3.182 +Goal "z + (0::hypnat) = z";
   3.183 +by (simp_tac (simpset() addsimps 
   3.184 +    [hypnat_add_zero_left,hypnat_add_commute]) 1);
   3.185 +qed "hypnat_add_zero_right";
   3.186 +
   3.187 +Addsimps [hypnat_add_zero_left,hypnat_add_zero_right];
   3.188 +
   3.189 +(*-----------------------------------------------------------
   3.190 +   Subtraction for hyper naturals: hypnat_minus
   3.191 + -----------------------------------------------------------*)
   3.192 +Goalw [congruent2_def]
   3.193 +    "congruent2 hypnatrel (%X Y. hypnatrel^^{%n. X n - Y n})";
   3.194 +by (safe_tac (claset()));
   3.195 +by (ALLGOALS(Fuf_tac));
   3.196 +qed "hypnat_minus_congruent2";
   3.197 + 
   3.198 +Goalw [hypnat_minus_def]
   3.199 +  "Abs_hypnat(hypnatrel^^{%n. X n}) - Abs_hypnat(hypnatrel^^{%n. Y n}) = \
   3.200 +\  Abs_hypnat(hypnatrel^^{%n. X n - Y n})";
   3.201 +by (asm_simp_tac
   3.202 +    (simpset() addsimps [[equiv_hypnatrel, hypnat_minus_congruent2] 
   3.203 +     MRS UN_equiv_class2]) 1);
   3.204 +qed "hypnat_minus";
   3.205 +
   3.206 +Goalw [hypnat_zero_def] "z - z = (0::hypnat)";
   3.207 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.208 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus]) 1);
   3.209 +qed "hypnat_minus_zero";
   3.210 +
   3.211 +Goalw [hypnat_zero_def] "(0::hypnat) - n = 0";
   3.212 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.213 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus]) 1);
   3.214 +qed "hypnat_diff_0_eq_0";
   3.215 +
   3.216 +Addsimps [hypnat_minus_zero,hypnat_diff_0_eq_0];
   3.217 +
   3.218 +Goalw [hypnat_zero_def] "(m+n = (0::hypnat)) = (m=0 & n=0)";
   3.219 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.220 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.221 +by (auto_tac (claset() addIs [FreeUltrafilterNat_subset]
   3.222 +    addDs [FreeUltrafilterNat_Int],
   3.223 +    simpset() addsimps [hypnat_add] ));
   3.224 +qed "hypnat_add_is_0";
   3.225 +
   3.226 +AddIffs [hypnat_add_is_0];
   3.227 +
   3.228 +Goal "!!i::hypnat. i-j-k = i - (j+k)";
   3.229 +by (res_inst_tac [("z","i")] eq_Abs_hypnat 1);
   3.230 +by (res_inst_tac [("z","j")] eq_Abs_hypnat 1);
   3.231 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
   3.232 +by (asm_full_simp_tac (simpset() addsimps 
   3.233 +    [hypnat_minus,hypnat_add,diff_diff_left]) 1);
   3.234 +qed "hypnat_diff_diff_left";
   3.235 +
   3.236 +Goal "!!i::hypnat. i-j-k = i-k-j";
   3.237 +by (simp_tac (simpset() addsimps 
   3.238 +    [hypnat_diff_diff_left, hypnat_add_commute]) 1);
   3.239 +qed "hypnat_diff_commute";
   3.240 +
   3.241 +Goal "!!n::hypnat. (n+m) - n = m";
   3.242 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.243 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.244 +by (asm_full_simp_tac (simpset() addsimps 
   3.245 +    [hypnat_minus,hypnat_add]) 1);
   3.246 +qed "hypnat_diff_add_inverse";
   3.247 +Addsimps [hypnat_diff_add_inverse];
   3.248 +
   3.249 +Goal "!!n::hypnat.(m+n) - n = m";
   3.250 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.251 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.252 +by (asm_full_simp_tac (simpset() addsimps 
   3.253 +    [hypnat_minus,hypnat_add]) 1);
   3.254 +qed "hypnat_diff_add_inverse2";
   3.255 +Addsimps [hypnat_diff_add_inverse2];
   3.256 +
   3.257 +Goal "!!k::hypnat. (k+m) - (k+n) = m - n";
   3.258 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.259 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.260 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
   3.261 +by (asm_full_simp_tac (simpset() addsimps 
   3.262 +    [hypnat_minus,hypnat_add]) 1);
   3.263 +qed "hypnat_diff_cancel";
   3.264 +Addsimps [hypnat_diff_cancel];
   3.265 +
   3.266 +Goal "!!m::hypnat. (m+k) - (n+k) = m - n";
   3.267 +val hypnat_add_commute_k = read_instantiate [("w","k")] hypnat_add_commute;
   3.268 +by (asm_simp_tac (simpset() addsimps ([hypnat_add_commute_k])) 1);
   3.269 +qed "hypnat_diff_cancel2";
   3.270 +Addsimps [hypnat_diff_cancel2];
   3.271 +
   3.272 +Goalw [hypnat_zero_def] "!!n::hypnat. n - (n+m) = (0::hypnat)";
   3.273 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.274 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.275 +by (asm_full_simp_tac (simpset() addsimps 
   3.276 +    [hypnat_minus,hypnat_add]) 1);
   3.277 +qed "hypnat_diff_add_0";
   3.278 +Addsimps [hypnat_diff_add_0];
   3.279 +
   3.280 +(*-----------------------------------------------------------
   3.281 +   Multiplication for hyper naturals: hypnat_mult
   3.282 + -----------------------------------------------------------*)
   3.283 +Goalw [congruent2_def]
   3.284 +    "congruent2 hypnatrel (%X Y. hypnatrel^^{%n. X n * Y n})";
   3.285 +by (safe_tac (claset()));
   3.286 +by (ALLGOALS(Fuf_tac));
   3.287 +qed "hypnat_mult_congruent2";
   3.288 +
   3.289 +Goalw [hypnat_mult_def]
   3.290 +  "Abs_hypnat(hypnatrel^^{%n. X n}) * Abs_hypnat(hypnatrel^^{%n. Y n}) = \
   3.291 +\  Abs_hypnat(hypnatrel^^{%n. X n * Y n})";
   3.292 +by (asm_simp_tac
   3.293 +    (simpset() addsimps [[equiv_hypnatrel,hypnat_mult_congruent2] MRS
   3.294 +     UN_equiv_class2]) 1);
   3.295 +qed "hypnat_mult";
   3.296 +
   3.297 +Goal "(z::hypnat) * w = w * z";
   3.298 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.299 +by (res_inst_tac [("z","w")] eq_Abs_hypnat 1);
   3.300 +by (asm_simp_tac (simpset() addsimps ([hypnat_mult] @ mult_ac)) 1);
   3.301 +qed "hypnat_mult_commute";
   3.302 +
   3.303 +Goal "((z1::hypnat) * z2) * z3 = z1 * (z2 * z3)";
   3.304 +by (res_inst_tac [("z","z1")] eq_Abs_hypnat 1);
   3.305 +by (res_inst_tac [("z","z2")] eq_Abs_hypnat 1);
   3.306 +by (res_inst_tac [("z","z3")] eq_Abs_hypnat 1);
   3.307 +by (asm_simp_tac (simpset() addsimps [hypnat_mult,mult_assoc]) 1);
   3.308 +qed "hypnat_mult_assoc";
   3.309 +
   3.310 +qed_goal "hypnat_mult_left_commute" thy
   3.311 +    "(z1::hypnat) * (z2 * z3) = z2 * (z1 * z3)"
   3.312 + (fn _ => [rtac (hypnat_mult_commute RS trans) 1, rtac (hypnat_mult_assoc RS trans) 1,
   3.313 +           rtac (hypnat_mult_commute RS arg_cong) 1]);
   3.314 +
   3.315 +(* hypnat multiplication is an AC operator *)
   3.316 +val hypnat_mult_ac = [hypnat_mult_assoc, hypnat_mult_commute, 
   3.317 +                       hypnat_mult_left_commute];
   3.318 +
   3.319 +Goalw [hypnat_one_def] "1hn * z = z";
   3.320 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.321 +by (asm_full_simp_tac (simpset() addsimps [hypnat_mult]) 1);
   3.322 +qed "hypnat_mult_1";
   3.323 +Addsimps [hypnat_mult_1];
   3.324 +
   3.325 +Goal "z * 1hn = z";
   3.326 +by (simp_tac (simpset() addsimps [hypnat_mult_commute]) 1);
   3.327 +qed "hypnat_mult_1_right";
   3.328 +Addsimps [hypnat_mult_1_right];
   3.329 +
   3.330 +Goalw [hypnat_zero_def] "(0::hypnat) * z = 0";
   3.331 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.332 +by (asm_full_simp_tac (simpset() addsimps [hypnat_mult]) 1);
   3.333 +qed "hypnat_mult_0";
   3.334 +Addsimps [hypnat_mult_0];
   3.335 +
   3.336 +Goal "z * (0::hypnat) = 0";
   3.337 +by (simp_tac (simpset() addsimps [hypnat_mult_commute]) 1);
   3.338 +qed "hypnat_mult_0_right";
   3.339 +Addsimps [hypnat_mult_0_right];
   3.340 +
   3.341 +Goal "!!m::hypnat. (m - n) * k = (m * k) - (n * k)";
   3.342 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.343 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.344 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
   3.345 +by (asm_simp_tac (simpset() addsimps [hypnat_mult,
   3.346 +    hypnat_minus,diff_mult_distrib]) 1);
   3.347 +qed "hypnat_diff_mult_distrib" ;
   3.348 +
   3.349 +Goal "!!m::hypnat. k * (m - n) = (k * m) - (k * n)";
   3.350 +val hypnat_mult_commute_k = read_instantiate [("z","k")] hypnat_mult_commute;
   3.351 +by (simp_tac (simpset() addsimps [hypnat_diff_mult_distrib, 
   3.352 +    hypnat_mult_commute_k]) 1);
   3.353 +qed "hypnat_diff_mult_distrib2" ;
   3.354 +
   3.355 +(*--------------------------
   3.356 +    A Few more theorems
   3.357 + -------------------------*)
   3.358 +qed_goal "hypnat_add_assoc_cong" thy
   3.359 +    "!!z. (z::hypnat) + v = z' + v' ==> z + (v + w) = z' + (v' + w)"
   3.360 + (fn _ => [(asm_simp_tac (simpset() addsimps [hypnat_add_assoc RS sym]) 1)]);
   3.361 +
   3.362 +qed_goal "hypnat_add_assoc_swap" thy 
   3.363 +          "(z::hypnat) + (v + w) = v + (z + w)"
   3.364 + (fn _ => [(REPEAT (ares_tac [hypnat_add_commute RS hypnat_add_assoc_cong] 1))]);
   3.365 +
   3.366 +Goal "((z1::hypnat) + z2) * w = (z1 * w) + (z2 * w)";
   3.367 +by (res_inst_tac [("z","z1")] eq_Abs_hypnat 1);
   3.368 +by (res_inst_tac [("z","z2")] eq_Abs_hypnat 1);
   3.369 +by (res_inst_tac [("z","w")] eq_Abs_hypnat 1);
   3.370 +by (asm_simp_tac (simpset() addsimps [hypnat_mult,hypnat_add,
   3.371 +     add_mult_distrib]) 1);
   3.372 +qed "hypnat_add_mult_distrib";
   3.373 +Addsimps [hypnat_add_mult_distrib];
   3.374 +
   3.375 +val hypnat_mult_commute'= read_instantiate [("z","w")] hypnat_mult_commute;
   3.376 +
   3.377 +Goal "(w::hypnat) * (z1 + z2) = (w * z1) + (w * z2)";
   3.378 +by (simp_tac (simpset() addsimps [hypnat_mult_commute']) 1);
   3.379 +qed "hypnat_add_mult_distrib2";
   3.380 +Addsimps [hypnat_add_mult_distrib2];
   3.381 +
   3.382 +(*** (hypnat) one and zero are distinct ***)
   3.383 +Goalw [hypnat_zero_def,hypnat_one_def] "(0::hypnat) ~= 1hn";
   3.384 +by (Auto_tac);
   3.385 +qed "hypnat_zero_not_eq_one";
   3.386 +Addsimps [hypnat_zero_not_eq_one];
   3.387 +Addsimps [hypnat_zero_not_eq_one RS not_sym];
   3.388 +
   3.389 +Goalw [hypnat_zero_def] "(m*n = (0::hypnat)) = (m=0 | n=0)";
   3.390 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.391 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.392 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
   3.393 +    simpset() addsimps [hypnat_mult]));
   3.394 +by (ALLGOALS(Fuf_tac));
   3.395 +qed "hypnat_mult_is_0";
   3.396 +Addsimps [hypnat_mult_is_0];
   3.397 +
   3.398 +(*------------------------------------------------------------------
   3.399 +                   Theorems for ordering 
   3.400 + ------------------------------------------------------------------*)
   3.401 +
   3.402 +(* prove introduction and elimination rules for hypnat_less *)
   3.403 +
   3.404 +Goalw [hypnat_less_def]
   3.405 + "P < (Q::hypnat) = (EX X Y. X : Rep_hypnat(P) & \
   3.406 +\                             Y : Rep_hypnat(Q) & \
   3.407 +\                             {n. X n < Y n} : FreeUltrafilterNat)";
   3.408 +by (Fast_tac 1);
   3.409 +qed "hypnat_less_iff";
   3.410 +
   3.411 +Goalw [hypnat_less_def]
   3.412 + "!!P. [| {n. X n < Y n} : FreeUltrafilterNat; \
   3.413 +\         X : Rep_hypnat(P); \
   3.414 +\         Y : Rep_hypnat(Q) |] ==> P < (Q::hypnat)";
   3.415 +by (Fast_tac 1);
   3.416 +qed "hypnat_lessI";
   3.417 +
   3.418 +Goalw [hypnat_less_def]
   3.419 +     "!! R1. [| R1 < (R2::hypnat); \
   3.420 +\         !!X Y. {n. X n < Y n} : FreeUltrafilterNat ==> P; \
   3.421 +\         !!X. X : Rep_hypnat(R1) ==> P; \ 
   3.422 +\         !!Y. Y : Rep_hypnat(R2) ==> P |] \
   3.423 +\     ==> P";
   3.424 +by (Auto_tac);
   3.425 +qed "hypnat_lessE";
   3.426 +
   3.427 +Goalw [hypnat_less_def]
   3.428 + "!!R1. R1 < (R2::hypnat) ==> (EX X Y. {n. X n < Y n} : FreeUltrafilterNat & \
   3.429 +\                                  X : Rep_hypnat(R1) & \
   3.430 +\                                  Y : Rep_hypnat(R2))";
   3.431 +by (Fast_tac 1);
   3.432 +qed "hypnat_lessD";
   3.433 +
   3.434 +Goal "~ (R::hypnat) < R";
   3.435 +by (res_inst_tac [("z","R")] eq_Abs_hypnat 1);
   3.436 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def]));
   3.437 +by (Fuf_empty_tac 1);
   3.438 +qed "hypnat_less_not_refl";
   3.439 +Addsimps [hypnat_less_not_refl];
   3.440 +
   3.441 +bind_thm("hypnat_less_irrefl",hypnat_less_not_refl RS notE);
   3.442 +
   3.443 +qed_goal "hypnat_not_refl2" thy 
   3.444 +    "!!(x::hypnat). x < y ==> x ~= y" (fn _ => [Auto_tac]);
   3.445 +
   3.446 +Goalw [hypnat_less_def,hypnat_zero_def] "~ n<(0::hypnat)";
   3.447 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.448 +by (Auto_tac);
   3.449 +by (Fuf_empty_tac 1);
   3.450 +qed "hypnat_not_less0";
   3.451 +AddIffs [hypnat_not_less0];
   3.452 +
   3.453 +(* n<(0::hypnat) ==> R *)
   3.454 +bind_thm ("hypnat_less_zeroE", hypnat_not_less0 RS notE);
   3.455 +
   3.456 +Goalw [hypnat_less_def,hypnat_zero_def,hypnat_one_def]
   3.457 +      "(n<1hn) = (n=0)";
   3.458 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.459 +by (auto_tac (claset() addSIs [exI] addEs 
   3.460 +    [FreeUltrafilterNat_subset],simpset()));
   3.461 +by (Fuf_tac 1);
   3.462 +qed "hypnat_less_one";
   3.463 +AddIffs [hypnat_less_one];
   3.464 +
   3.465 +Goal "!!(R1::hypnat). [| R1 < R2; R2 < R3 |] ==> R1 < R3";
   3.466 +by (res_inst_tac [("z","R1")] eq_Abs_hypnat 1);
   3.467 +by (res_inst_tac [("z","R2")] eq_Abs_hypnat 1);
   3.468 +by (res_inst_tac [("z","R3")] eq_Abs_hypnat 1);
   3.469 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def]));
   3.470 +by (res_inst_tac [("x","X")] exI 1);
   3.471 +by (Auto_tac);
   3.472 +by (res_inst_tac [("x","Ya")] exI 1);
   3.473 +by (Auto_tac);
   3.474 +by (Fuf_tac 1);
   3.475 +qed "hypnat_less_trans";
   3.476 +
   3.477 +Goal "!! (R1::hypnat). [| R1 < R2; R2 < R1 |] ==> P";
   3.478 +by (dtac hypnat_less_trans 1 THEN assume_tac 1);
   3.479 +by (Asm_full_simp_tac 1);
   3.480 +qed "hypnat_less_asym";
   3.481 +
   3.482 +(*----- hypnat less iff less a.e -----*)
   3.483 +(* See comments in HYPER for corresponding thm *)
   3.484 +
   3.485 +Goalw [hypnat_less_def]
   3.486 +      "(Abs_hypnat(hypnatrel^^{%n. X n}) < \
   3.487 +\           Abs_hypnat(hypnatrel^^{%n. Y n})) = \
   3.488 +\      ({n. X n < Y n} : FreeUltrafilterNat)";
   3.489 +by (auto_tac (claset() addSIs [lemma_hypnatrel_refl],simpset()));
   3.490 +by (Fuf_tac 1);
   3.491 +qed "hypnat_less";
   3.492 +
   3.493 +Goal "~ m<n --> n+(m-n) = (m::hypnat)";
   3.494 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.495 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   3.496 +by (auto_tac (claset(),simpset() addsimps 
   3.497 +    [hypnat_minus,hypnat_add,hypnat_less]));
   3.498 +by (dtac FreeUltrafilterNat_Compl_mem 1);
   3.499 +by (Fuf_tac 1);
   3.500 +qed_spec_mp "hypnat_add_diff_inverse";
   3.501 +
   3.502 +Goal "n<=m ==> n+(m-n) = (m::hypnat)";
   3.503 +by (asm_full_simp_tac (simpset() addsimps 
   3.504 +    [hypnat_add_diff_inverse, hypnat_le_def]) 1);
   3.505 +qed "hypnat_le_add_diff_inverse";
   3.506 +
   3.507 +Goal "n<=m ==> (m-n)+n = (m::hypnat)";
   3.508 +by (asm_simp_tac (simpset() addsimps [hypnat_le_add_diff_inverse, 
   3.509 +    hypnat_add_commute]) 1);
   3.510 +qed "hypnat_le_add_diff_inverse2";
   3.511 +
   3.512 +(*---------------------------------------------------------------------------------
   3.513 +                    Hyper naturals as a linearly ordered field
   3.514 + ---------------------------------------------------------------------------------*)
   3.515 +Goalw [hypnat_zero_def] 
   3.516 +     "[| (0::hypnat) < x; 0 < y |] ==> 0 < x + y";
   3.517 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   3.518 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
   3.519 +by (auto_tac (claset(),simpset() addsimps
   3.520 +   [hypnat_less_def,hypnat_add]));
   3.521 +by (REPEAT(Step_tac 1));
   3.522 +by (Fuf_tac 1);
   3.523 +qed "hypnat_add_order";
   3.524 +
   3.525 +Goalw [hypnat_zero_def] 
   3.526 +      "!!(x::hypnat). [| (0::hypnat) < x; 0 < y |] ==> 0 < x * y";
   3.527 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   3.528 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
   3.529 +by (auto_tac (claset(),simpset() addsimps 
   3.530 +    [hypnat_less_def,hypnat_mult]));
   3.531 +by (REPEAT(Step_tac 1));
   3.532 +by (Fuf_tac 1);
   3.533 +qed "hypnat_mult_order";
   3.534 +
   3.535 +(*---------------------------------------------------------------------------------
   3.536 +                   Trichotomy of the hyper naturals
   3.537 +  --------------------------------------------------------------------------------*)
   3.538 +Goalw [hypnatrel_def] "EX x. x: hypnatrel ^^ {%n. 0}";
   3.539 +by (res_inst_tac [("x","%n. 0")] exI 1);
   3.540 +by (Step_tac 1);
   3.541 +by (Auto_tac);
   3.542 +qed "lemma_hypnatrel_0_mem";
   3.543 +
   3.544 +(* linearity is actually proved further down! *)
   3.545 +Goalw [hypnat_zero_def,
   3.546 +       hypnat_less_def]"(0::hypnat) <  x | x = 0 | x < 0";
   3.547 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   3.548 +by (Auto_tac );
   3.549 +by (REPEAT(Step_tac 1));
   3.550 +by (REPEAT(dtac FreeUltrafilterNat_Compl_mem 1));
   3.551 +by (Fuf_tac 1);
   3.552 +qed "hypnat_trichotomy";
   3.553 +
   3.554 +Goal "!!x. [| (0::hypnat) < x ==> P; \
   3.555 +\                 x = 0 ==> P; \
   3.556 +\                 x < 0 ==> P |] ==> P";
   3.557 +by (cut_inst_tac [("x","x")] hypnat_trichotomy 1);
   3.558 +by (Auto_tac);
   3.559 +qed "hypnat_trichotomyE";
   3.560 +
   3.561 +(*------------------------------------------------------------------------------
   3.562 +            More properties of <
   3.563 + ------------------------------------------------------------------------------*)
   3.564 +Goal "!!(A::hypnat). A < B ==> A + C < B + C";
   3.565 +by (res_inst_tac [("z","A")] eq_Abs_hypnat 1);
   3.566 +by (res_inst_tac [("z","B")] eq_Abs_hypnat 1);
   3.567 +by (res_inst_tac [("z","C")] eq_Abs_hypnat 1);
   3.568 +by (auto_tac (claset(),simpset() addsimps 
   3.569 +    [hypnat_less_def,hypnat_add]));
   3.570 +by (REPEAT(Step_tac 1));
   3.571 +by (Fuf_tac 1);
   3.572 +qed "hypnat_add_less_mono1";
   3.573 +
   3.574 +Goal "!!(A::hypnat). A < B ==> C + A < C + B";
   3.575 +by (auto_tac (claset() addIs [hypnat_add_less_mono1],
   3.576 +    simpset() addsimps [hypnat_add_commute]));
   3.577 +qed "hypnat_add_less_mono2";
   3.578 +
   3.579 +Goal "!!k l::hypnat. [|i<j;  k<l |] ==> i + k < j + l";
   3.580 +by (etac (hypnat_add_less_mono1 RS hypnat_less_trans) 1);
   3.581 +by (simp_tac (simpset() addsimps [hypnat_add_commute]) 1);
   3.582 +(*j moves to the end because it is free while k, l are bound*)
   3.583 +by (etac hypnat_add_less_mono1 1);
   3.584 +qed "hypnat_add_less_mono";
   3.585 +
   3.586 +(*---------------------------------------
   3.587 +        hypnat_minus_less
   3.588 + ---------------------------------------*)
   3.589 +Goalw [hypnat_less_def,hypnat_zero_def] 
   3.590 +      "((x::hypnat) < y) = ((0::hypnat) < y - x)";
   3.591 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   3.592 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
   3.593 +by (auto_tac (claset(),simpset() addsimps 
   3.594 +    [hypnat_minus]));
   3.595 +by (REPEAT(Step_tac 1));
   3.596 +by (REPEAT(Step_tac 2));
   3.597 +by (ALLGOALS(fuf_tac (claset() addDs [sym],simpset())));
   3.598 +
   3.599 +(*** linearity ***)
   3.600 +Goalw [hypnat_less_def] "(x::hypnat) < y | x = y | y < x";
   3.601 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   3.602 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
   3.603 +by (Auto_tac );
   3.604 +by (REPEAT(Step_tac 1));
   3.605 +by (REPEAT(dtac FreeUltrafilterNat_Compl_mem 1));
   3.606 +by (Fuf_tac 1);
   3.607 +qed "hypnat_linear";
   3.608 +
   3.609 +Goal
   3.610 +    "!!(x::hypnat). [| x < y ==> P;  x = y ==> P; \
   3.611 +\          y < x ==> P |] ==> P";
   3.612 +by (cut_inst_tac [("x","x"),("y","y")] hypnat_linear 1);
   3.613 +by (Auto_tac);
   3.614 +qed "hypnat_linear_less2";
   3.615 +
   3.616 +(*------------------------------------------------------------------------------
   3.617 +                            Properties of <=
   3.618 + ------------------------------------------------------------------------------*)
   3.619 +(*------ hypnat le iff nat le a.e ------*)
   3.620 +Goalw [hypnat_le_def,le_def]
   3.621 +      "(Abs_hypnat(hypnatrel^^{%n. X n}) <= \
   3.622 +\           Abs_hypnat(hypnatrel^^{%n. Y n})) = \
   3.623 +\      ({n. X n <= Y n} : FreeUltrafilterNat)";
   3.624 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
   3.625 +    simpset() addsimps [hypnat_less]));
   3.626 +by (Fuf_tac 1 THEN Fuf_empty_tac 1);
   3.627 +qed "hypnat_le";
   3.628 +
   3.629 +(*---------------------------------------------------------*)
   3.630 +(*---------------------------------------------------------*)
   3.631 +Goalw [hypnat_le_def] "!!w. ~(w < z) ==> z <= (w::hypnat)";
   3.632 +by (assume_tac 1);
   3.633 +qed "hypnat_leI";
   3.634 +
   3.635 +Goalw [hypnat_le_def] "!!w. z<=w ==> ~(w<(z::hypnat))";
   3.636 +by (assume_tac 1);
   3.637 +qed "hypnat_leD";
   3.638 +
   3.639 +val hypnat_leE = make_elim hypnat_leD;
   3.640 +
   3.641 +Goal "!!w. (~(w < z)) = (z <= (w::hypnat))";
   3.642 +by (fast_tac (claset() addSIs [hypnat_leI,hypnat_leD]) 1);
   3.643 +qed "hypnat_less_le_iff";
   3.644 +
   3.645 +Goalw [hypnat_le_def] "!!z. ~ z <= w ==> w<(z::hypnat)";
   3.646 +by (Fast_tac 1);
   3.647 +qed "not_hypnat_leE";
   3.648 +
   3.649 +Goalw [hypnat_le_def] "!!z. z < w ==> z <= (w::hypnat)";
   3.650 +by (fast_tac (claset() addEs [hypnat_less_asym]) 1);
   3.651 +qed "hypnat_less_imp_le";
   3.652 +
   3.653 +Goalw [hypnat_le_def] "!!(x::hypnat). x <= y ==> x < y | x = y";
   3.654 +by (cut_facts_tac [hypnat_linear] 1);
   3.655 +by (fast_tac (claset() addEs [hypnat_less_irrefl,hypnat_less_asym]) 1);
   3.656 +qed "hypnat_le_imp_less_or_eq";
   3.657 +
   3.658 +Goalw [hypnat_le_def] "!!z. z<w | z=w ==> z <=(w::hypnat)";
   3.659 +by (cut_facts_tac [hypnat_linear] 1);
   3.660 +by (fast_tac (claset() addEs [hypnat_less_irrefl,hypnat_less_asym]) 1);
   3.661 +qed "hypnat_less_or_eq_imp_le";
   3.662 +
   3.663 +Goal "(x <= (y::hypnat)) = (x < y | x=y)";
   3.664 +by (REPEAT(ares_tac [iffI, hypnat_less_or_eq_imp_le, hypnat_le_imp_less_or_eq] 1));
   3.665 +qed "hypnat_le_eq_less_or_eq";
   3.666 +
   3.667 +Goal "w <= (w::hypnat)";
   3.668 +by (simp_tac (simpset() addsimps [hypnat_le_eq_less_or_eq]) 1);
   3.669 +qed "hypnat_le_refl";
   3.670 +Addsimps [hypnat_le_refl];
   3.671 +
   3.672 +val prems = goal thy "!!i. [| i <= j; j < k |] ==> i < (k::hypnat)";
   3.673 +by (dtac hypnat_le_imp_less_or_eq 1);
   3.674 +by (fast_tac (claset() addIs [hypnat_less_trans]) 1);
   3.675 +qed "hypnat_le_less_trans";
   3.676 +
   3.677 +Goal "!! (i::hypnat). [| i < j; j <= k |] ==> i < k";
   3.678 +by (dtac hypnat_le_imp_less_or_eq 1);
   3.679 +by (fast_tac (claset() addIs [hypnat_less_trans]) 1);
   3.680 +qed "hypnat_less_le_trans";
   3.681 +
   3.682 +Goal "!!i. [| i <= j; j <= k |] ==> i <= (k::hypnat)";
   3.683 +by (EVERY1 [dtac hypnat_le_imp_less_or_eq, dtac hypnat_le_imp_less_or_eq,
   3.684 +            rtac hypnat_less_or_eq_imp_le, fast_tac (claset() addIs [hypnat_less_trans])]);
   3.685 +qed "hypnat_le_trans";
   3.686 +
   3.687 +Goal "!!z. [| z <= w; w <= z |] ==> z = (w::hypnat)";
   3.688 +by (EVERY1 [dtac hypnat_le_imp_less_or_eq, dtac hypnat_le_imp_less_or_eq,
   3.689 +            fast_tac (claset() addEs [hypnat_less_irrefl,hypnat_less_asym])]);
   3.690 +qed "hypnat_le_anti_sym";
   3.691 +
   3.692 +Goal "!!x. [| ~ y < x; y ~= x |] ==> x < (y::hypnat)";
   3.693 +by (rtac not_hypnat_leE 1);
   3.694 +by (fast_tac (claset() addDs [hypnat_le_imp_less_or_eq]) 1);
   3.695 +qed "not_less_not_eq_hypnat_less";
   3.696 +
   3.697 +Goal "!!x. [| (0::hypnat) <= x; 0 <= y |] ==> 0 <= x * y";
   3.698 +by (REPEAT(dtac hypnat_le_imp_less_or_eq 1));
   3.699 +by (auto_tac (claset() addIs [hypnat_mult_order,
   3.700 +    hypnat_less_imp_le],simpset() addsimps [hypnat_le_refl]));
   3.701 +qed "hypnat_le_mult_order";
   3.702 +
   3.703 +Goalw [hypnat_one_def,hypnat_zero_def,hypnat_less_def] 
   3.704 +      "(0::hypnat) < 1hn";
   3.705 +by (res_inst_tac [("x","%n. 0")] exI 1);
   3.706 +by (res_inst_tac [("x","%n. 1")] exI 1);
   3.707 +by (Auto_tac);
   3.708 +qed "hypnat_zero_less_one";
   3.709 +
   3.710 +Goal "!!x. [| (0::hypnat) <= x; 0 <= y |] ==> 0 <= x + y";
   3.711 +by (REPEAT(dtac hypnat_le_imp_less_or_eq 1));
   3.712 +by (auto_tac (claset() addIs [hypnat_add_order,
   3.713 +    hypnat_less_imp_le],simpset() addsimps [hypnat_le_refl]));
   3.714 +qed "hypnat_le_add_order";
   3.715 +
   3.716 +Goal "!!(q1::hypnat). q1 <= q2  ==> x + q1 <= x + q2";
   3.717 +by (dtac hypnat_le_imp_less_or_eq 1);
   3.718 +by (Step_tac 1);
   3.719 +by (auto_tac (claset() addSIs [hypnat_le_refl,
   3.720 +    hypnat_less_imp_le,hypnat_add_less_mono1],
   3.721 +    simpset() addsimps [hypnat_add_commute]));
   3.722 +qed "hypnat_add_le_mono2";
   3.723 +
   3.724 +Goal "!!(q1::hypnat). q1 <= q2  ==> q1 + x <= q2 + x";
   3.725 +by (auto_tac (claset() addDs [hypnat_add_le_mono2],
   3.726 +    simpset() addsimps [hypnat_add_commute]));
   3.727 +qed "hypnat_add_le_mono1";
   3.728 +
   3.729 +Goal "!!k l::hypnat. [|i<=j;  k<=l |] ==> i + k <= j + l";
   3.730 +by (etac (hypnat_add_le_mono1 RS hypnat_le_trans) 1);
   3.731 +by (simp_tac (simpset() addsimps [hypnat_add_commute]) 1);
   3.732 +(*j moves to the end because it is free while k, l are bound*)
   3.733 +by (etac hypnat_add_le_mono1 1);
   3.734 +qed "hypnat_add_le_mono";
   3.735 +
   3.736 +Goalw [hypnat_zero_def]
   3.737 +     "!!x::hypnat. [| (0::hypnat) < z; x < y |] ==> x * z < y * z";
   3.738 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   3.739 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
   3.740 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
   3.741 +by (auto_tac (claset(),simpset() addsimps 
   3.742 +    [hypnat_less,hypnat_mult]));
   3.743 +by (Fuf_tac 1);
   3.744 +qed "hypnat_mult_less_mono1";
   3.745 +
   3.746 +Goal "!!x::hypnat. [| 0 < z; x < y |] ==> z * x < z * y";
   3.747 +by (auto_tac (claset() addIs [hypnat_mult_less_mono1],
   3.748 +              simpset() addsimps [hypnat_mult_commute]));
   3.749 +qed "hypnat_mult_less_mono2";
   3.750 +
   3.751 +Addsimps [hypnat_mult_less_mono2,hypnat_mult_less_mono1];
   3.752 +
   3.753 +Goal "(x::hypnat) <= n + x";
   3.754 +by (res_inst_tac [("x","n")] hypnat_trichotomyE 1);
   3.755 +by (auto_tac (claset() addDs [(hypnat_less_imp_le RS
   3.756 +    hypnat_add_le_mono1)],simpset() addsimps [hypnat_le_refl]));
   3.757 +qed "hypnat_add_self_le";
   3.758 +Addsimps [hypnat_add_self_le];
   3.759 +
   3.760 +Goal "(x::hypnat) < x + 1hn";
   3.761 +by (cut_facts_tac [hypnat_zero_less_one 
   3.762 +         RS hypnat_add_less_mono2] 1);
   3.763 +by (Auto_tac);
   3.764 +qed "hypnat_add_one_self_less";
   3.765 +Addsimps [hypnat_add_one_self_less];
   3.766 +
   3.767 +Goalw [hypnat_le_def] "~ x + 1hn <= x";
   3.768 +by (Simp_tac 1);
   3.769 +qed "not_hypnat_add_one_le_self";
   3.770 +Addsimps [not_hypnat_add_one_le_self];
   3.771 +
   3.772 +Goal "((0::hypnat) < n) = (1hn <= n)";
   3.773 +by (res_inst_tac [("x","n")] hypnat_trichotomyE 1);
   3.774 +by (auto_tac (claset(),simpset() addsimps [hypnat_le_def]));
   3.775 +qed "hypnat_gt_zero_iff";
   3.776 +
   3.777 +Addsimps  [hypnat_le_add_diff_inverse, hypnat_le_add_diff_inverse2,
   3.778 +           hypnat_less_imp_le RS hypnat_le_add_diff_inverse2];
   3.779 +
   3.780 +Goal "(0 < n) = (EX m. n = m + 1hn)";
   3.781 +by (Step_tac 1);
   3.782 +by (res_inst_tac [("x","m")] hypnat_trichotomyE 2);
   3.783 +by (rtac hypnat_less_trans 2);
   3.784 +by (res_inst_tac [("x","n - 1hn")] exI 1);
   3.785 +by (auto_tac (claset(),simpset() addsimps 
   3.786 +    [hypnat_gt_zero_iff,hypnat_add_commute]));
   3.787 +qed "hypnat_gt_zero_iff2";
   3.788 +
   3.789 +Goalw [hypnat_zero_def] "(0::hypnat) <= n";
   3.790 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   3.791 +by (asm_simp_tac (simpset() addsimps [hypnat_le]) 1);
   3.792 +qed "hypnat_le_zero";
   3.793 +Addsimps [hypnat_le_zero];
   3.794 +
   3.795 +(*------------------------------------------------------------------
   3.796 +     hypnat_of_nat: properties embedding of naturals in hypernaturals
   3.797 + -----------------------------------------------------------------*)
   3.798 +    (** hypnat_of_nat preserves field and order properties **)
   3.799 +
   3.800 +Goalw [hypnat_of_nat_def] 
   3.801 +      "hypnat_of_nat ((z1::nat) + z2) = \
   3.802 +\      hypnat_of_nat z1 + hypnat_of_nat z2";
   3.803 +by (asm_simp_tac (simpset() addsimps [hypnat_add]) 1);
   3.804 +qed "hypnat_of_nat_add";
   3.805 +
   3.806 +Goalw [hypnat_of_nat_def] 
   3.807 +      "hypnat_of_nat ((z1::nat) - z2) = \
   3.808 +\      hypnat_of_nat z1 - hypnat_of_nat z2";
   3.809 +by (asm_simp_tac (simpset() addsimps [hypnat_minus]) 1);
   3.810 +qed "hypnat_of_nat_minus";
   3.811 +
   3.812 +Goalw [hypnat_of_nat_def] 
   3.813 +      "hypnat_of_nat (z1 * z2) = hypnat_of_nat z1 * hypnat_of_nat z2";
   3.814 +by (full_simp_tac (simpset() addsimps [hypnat_mult]) 1);
   3.815 +qed "hypnat_of_nat_mult";
   3.816 +
   3.817 +Goalw [hypnat_less_def,hypnat_of_nat_def] 
   3.818 +      "(z1 < z2) = (hypnat_of_nat z1 < hypnat_of_nat z2)";
   3.819 +by (auto_tac (claset() addSIs [exI] addIs 
   3.820 +   [FreeUltrafilterNat_all],simpset()));
   3.821 +by (rtac FreeUltrafilterNat_P 1 THEN Fuf_tac 1);
   3.822 +qed "hypnat_of_nat_less_iff";
   3.823 +Addsimps [hypnat_of_nat_less_iff RS sym];
   3.824 +
   3.825 +Goalw [hypnat_le_def,le_def] 
   3.826 +      "(z1 <= z2) = (hypnat_of_nat z1 <= hypnat_of_nat z2)";
   3.827 +by (Auto_tac);
   3.828 +qed "hypnat_of_nat_le_iff";
   3.829 +
   3.830 +Goalw [hypnat_of_nat_def,hypnat_one_def] "hypnat_of_nat  1 = 1hn";
   3.831 +by (Simp_tac 1);
   3.832 +qed "hypnat_of_nat_one";
   3.833 +
   3.834 +Goalw [hypnat_of_nat_def,hypnat_zero_def] "hypnat_of_nat  0 = 0";
   3.835 +by (Simp_tac 1);
   3.836 +qed "hypnat_of_nat_zero";
   3.837 +
   3.838 +Goal "(hypnat_of_nat  n = 0) = (n = 0)";
   3.839 +by (auto_tac (claset() addIs [FreeUltrafilterNat_P],
   3.840 +    simpset() addsimps [hypnat_of_nat_def,
   3.841 +    hypnat_zero_def]));
   3.842 +qed "hypnat_of_nat_zero_iff";
   3.843 +
   3.844 +Goal "(hypnat_of_nat  n ~= 0) = (n ~= 0)";
   3.845 +by (full_simp_tac (simpset() addsimps [hypnat_of_nat_zero_iff]) 1);
   3.846 +qed "hypnat_of_nat_not_zero_iff";
   3.847 +
   3.848 +goalw HyperNat.thy [hypnat_of_nat_def,hypnat_one_def]
   3.849 +      "hypnat_of_nat (Suc n) = hypnat_of_nat n + 1hn";
   3.850 +by (auto_tac (claset(),simpset() addsimps [hypnat_add]));
   3.851 +qed "hypnat_of_nat_Suc";
   3.852 +
   3.853 +(*---------------------------------------------------------------------------------
   3.854 +              Existence of infinite hypernatural number
   3.855 + ---------------------------------------------------------------------------------*)
   3.856 +
   3.857 +Goal "hypnatrel^^{%n::nat. n} : hypnat";
   3.858 +by (Auto_tac);
   3.859 +qed "hypnat_omega";
   3.860 +
   3.861 +Goalw [hypnat_omega_def] "Rep_hypnat(whn) : hypnat";
   3.862 +by (rtac Rep_hypnat 1);
   3.863 +qed "Rep_hypnat_omega";
   3.864 +
   3.865 +(* See Hyper.thy for similar argument*)
   3.866 +(* existence of infinite number not corresponding to any natural number *)
   3.867 +(* use assumption that member FreeUltrafilterNat is not finite       *)
   3.868 +(* a few lemmas first *)
   3.869 +
   3.870 +Goalw [hypnat_omega_def,hypnat_of_nat_def]
   3.871 +      "~ (EX x. hypnat_of_nat x = whn)";
   3.872 +by (auto_tac (claset() addDs [FreeUltrafilterNat_not_finite], 
   3.873 +              simpset()));
   3.874 +qed "not_ex_hypnat_of_nat_eq_omega";
   3.875 +
   3.876 +Goal "hypnat_of_nat x ~= whn";
   3.877 +by (cut_facts_tac [not_ex_hypnat_of_nat_eq_omega] 1);
   3.878 +by (Auto_tac);
   3.879 +qed "hypnat_of_nat_not_eq_omega";
   3.880 +Addsimps [hypnat_of_nat_not_eq_omega RS not_sym];
   3.881 +
   3.882 +(*-----------------------------------------------------------
   3.883 +    Properties of the set SHNat of embedded natural numbers
   3.884 +              (cf. set SReal in NSA.thy/NSA.ML)
   3.885 + ----------------------------------------------------------*)
   3.886 +
   3.887 +(* Infinite hypernatural not in embedded SHNat *)
   3.888 +Goalw [SHNat_def] "whn ~: SHNat";
   3.889 +by (Auto_tac);
   3.890 +qed "SHNAT_omega_not_mem";
   3.891 +Addsimps [SHNAT_omega_not_mem];
   3.892 +
   3.893 +(*-----------------------------------------------------------------------
   3.894 +     Closure laws for members of (embedded) set standard naturals SHNat
   3.895 + -----------------------------------------------------------------------*)
   3.896 +Goalw [SHNat_def] 
   3.897 +      "!!x. [| x: SHNat; y: SHNat |] ==> x + y: SHNat";
   3.898 +by (Step_tac 1);
   3.899 +by (res_inst_tac [("x","N + Na")] exI 1);
   3.900 +by (simp_tac (simpset() addsimps [hypnat_of_nat_add]) 1);
   3.901 +qed "SHNat_add";
   3.902 +
   3.903 +Goalw [SHNat_def] 
   3.904 +      "!!x. [| x: SHNat; y: SHNat |] ==> x - y: SHNat";
   3.905 +by (Step_tac 1);
   3.906 +by (res_inst_tac [("x","N - Na")] exI 1);
   3.907 +by (simp_tac (simpset() addsimps [hypnat_of_nat_minus]) 1);
   3.908 +qed "SHNat_minus";
   3.909 +
   3.910 +Goalw [SHNat_def] 
   3.911 +      "!!x. [| x: SHNat; y: SHNat |] ==> x * y: SHNat";
   3.912 +by (Step_tac 1);
   3.913 +by (res_inst_tac [("x","N * Na")] exI 1);
   3.914 +by (simp_tac (simpset() addsimps [hypnat_of_nat_mult]) 1);
   3.915 +qed "SHNat_mult";
   3.916 +
   3.917 +Goal "!!x. [| x + y : SHNat; y: SHNat |] ==> x: SHNat";
   3.918 +by (dres_inst_tac [("x","x+y")] SHNat_minus 1);
   3.919 +by (Auto_tac);
   3.920 +qed "SHNat_add_cancel";
   3.921 +
   3.922 +Goalw [SHNat_def] "hypnat_of_nat x : SHNat";
   3.923 +by (Blast_tac 1);
   3.924 +qed "SHNat_hypnat_of_nat";
   3.925 +Addsimps [SHNat_hypnat_of_nat];
   3.926 +
   3.927 +Goal "hypnat_of_nat 1 : SHNat";
   3.928 +by (Simp_tac 1);
   3.929 +qed "SHNat_hypnat_of_nat_one";
   3.930 +
   3.931 +Goal "hypnat_of_nat 0 : SHNat";
   3.932 +by (Simp_tac 1);
   3.933 +qed "SHNat_hypnat_of_nat_zero";
   3.934 +
   3.935 +Goal "1hn : SHNat";
   3.936 +by (simp_tac (simpset() addsimps [SHNat_hypnat_of_nat_one,
   3.937 +    hypnat_of_nat_one RS sym]) 1);
   3.938 +qed "SHNat_one";
   3.939 +
   3.940 +Goal "0 : SHNat";
   3.941 +by (simp_tac (simpset() addsimps [SHNat_hypnat_of_nat_zero,
   3.942 +    hypnat_of_nat_zero RS sym]) 1);
   3.943 +qed "SHNat_zero";
   3.944 +
   3.945 +Addsimps [SHNat_hypnat_of_nat_one,SHNat_hypnat_of_nat_zero,
   3.946 +          SHNat_one,SHNat_zero];
   3.947 +
   3.948 +Goal "1hn + 1hn : SHNat";
   3.949 +by (rtac ([SHNat_one,SHNat_one] MRS SHNat_add) 1);
   3.950 +qed "SHNat_two";
   3.951 +
   3.952 +Goalw [SHNat_def] "{x. hypnat_of_nat x : SHNat} = (UNIV::nat set)";
   3.953 +by (Auto_tac);
   3.954 +qed "SHNat_UNIV_nat";
   3.955 +
   3.956 +Goalw [SHNat_def] "(x: SHNat) = (EX y. x = hypnat_of_nat  y)";
   3.957 +by (Auto_tac);
   3.958 +qed "SHNat_iff";
   3.959 +
   3.960 +Goalw [SHNat_def] "hypnat_of_nat ``(UNIV::nat set) = SHNat";
   3.961 +by (Auto_tac);
   3.962 +qed "hypnat_of_nat_image";
   3.963 +
   3.964 +Goalw [SHNat_def] "inv hypnat_of_nat ``SHNat = (UNIV::nat set)";
   3.965 +by (Auto_tac);
   3.966 +by (rtac (inj_hypnat_of_nat RS inv_f_f RS subst) 1);
   3.967 +by (Blast_tac 1);
   3.968 +qed "inv_hypnat_of_nat_image";
   3.969 +
   3.970 +Goalw [SHNat_def] 
   3.971 +      "!!P. [| EX x. x: P; P <= SHNat |] ==> \
   3.972 +\           EX Q. P = hypnat_of_nat `` Q";
   3.973 +by (Best_tac 1); 
   3.974 +qed "SHNat_hypnat_of_nat_image";
   3.975 +
   3.976 +Goalw [SHNat_def] 
   3.977 +      "SHNat = hypnat_of_nat `` (UNIV::nat set)";
   3.978 +by (Auto_tac);
   3.979 +qed "SHNat_hypnat_of_nat_iff";
   3.980 +
   3.981 +Goalw [SHNat_def] "SHNat <= (UNIV::hypnat set)";
   3.982 +by (Auto_tac);
   3.983 +qed "SHNat_subset_UNIV";
   3.984 +
   3.985 +Goal "{n. n <= Suc m} = {n. n <= m} Un {n. n = Suc m}";
   3.986 +by (auto_tac (claset(),simpset() addsimps [le_Suc_eq]));
   3.987 +qed "leSuc_Un_eq";
   3.988 +
   3.989 +Goal "finite {n::nat. n <= m}";
   3.990 +by (nat_ind_tac "m" 1);
   3.991 +by (auto_tac (claset(),simpset() addsimps [leSuc_Un_eq]));
   3.992 +qed "finite_nat_le_segment";
   3.993 +
   3.994 +Goal "{n::nat. m < n} : FreeUltrafilterNat";
   3.995 +by (cut_inst_tac [("m2","m")] (finite_nat_le_segment RS 
   3.996 +    FreeUltrafilterNat_finite RS FreeUltrafilterNat_Compl_mem) 1);
   3.997 +by (Fuf_tac 1);
   3.998 +qed "lemma_unbounded_set";
   3.999 +Addsimps [lemma_unbounded_set];
  3.1000 +
  3.1001 +Goalw [SHNat_def,hypnat_of_nat_def,
  3.1002 +           hypnat_less_def,hypnat_omega_def] 
  3.1003 +           "ALL n: SHNat. n < whn";
  3.1004 +by (Clarify_tac 1);
  3.1005 +by (auto_tac (claset() addSIs [exI],simpset()));
  3.1006 +qed "hypnat_omega_gt_SHNat";
  3.1007 +
  3.1008 +Goal "hypnat_of_nat n < whn";
  3.1009 +by (cut_facts_tac [hypnat_omega_gt_SHNat] 1);
  3.1010 +by (dres_inst_tac [("x","hypnat_of_nat n")] bspec 1);
  3.1011 +by (Auto_tac);
  3.1012 +qed "hypnat_of_nat_less_whn";
  3.1013 +Addsimps [hypnat_of_nat_less_whn];
  3.1014 +
  3.1015 +Goal "hypnat_of_nat n <= whn";
  3.1016 +by (rtac (hypnat_of_nat_less_whn RS hypnat_less_imp_le) 1);
  3.1017 +qed "hypnat_of_nat_le_whn";
  3.1018 +Addsimps [hypnat_of_nat_le_whn];
  3.1019 +
  3.1020 +Goal "0 < whn";
  3.1021 +by (rtac (hypnat_omega_gt_SHNat RS ballE) 1);
  3.1022 +by (Auto_tac);
  3.1023 +qed "hypnat_zero_less_hypnat_omega";
  3.1024 +Addsimps [hypnat_zero_less_hypnat_omega];
  3.1025 +
  3.1026 +Goal "1hn < whn";
  3.1027 +by (rtac (hypnat_omega_gt_SHNat RS ballE) 1);
  3.1028 +by (Auto_tac);
  3.1029 +qed "hypnat_one_less_hypnat_omega";
  3.1030 +Addsimps [hypnat_one_less_hypnat_omega];
  3.1031 +
  3.1032 +(*--------------------------------------------------------------------------
  3.1033 +     Theorems about infinite hypernatural numbers -- HNatInfinite
  3.1034 + -------------------------------------------------------------------------*)
  3.1035 +Goalw [HNatInfinite_def,SHNat_def] "whn : HNatInfinite";
  3.1036 +by (Auto_tac);
  3.1037 +qed "HNatInfinite_whn";
  3.1038 +Addsimps [HNatInfinite_whn];
  3.1039 +
  3.1040 +Goalw [HNatInfinite_def] "!!x. x: SHNat ==> x ~: HNatInfinite";
  3.1041 +by (Simp_tac 1);
  3.1042 +qed "SHNat_not_HNatInfinite";
  3.1043 +
  3.1044 +Goalw [HNatInfinite_def] "!!x. x ~: HNatInfinite ==> x: SHNat";
  3.1045 +by (Asm_full_simp_tac 1);
  3.1046 +qed "not_HNatInfinite_SHNat";
  3.1047 +
  3.1048 +Goalw [HNatInfinite_def] "!!x. x ~: SHNat ==> x: HNatInfinite";
  3.1049 +by (Simp_tac 1);
  3.1050 +qed "not_SHNat_HNatInfinite";
  3.1051 +
  3.1052 +Goalw [HNatInfinite_def] "!!x. x: HNatInfinite ==> x ~: SHNat";
  3.1053 +by (Asm_full_simp_tac 1);
  3.1054 +qed "HNatInfinite_not_SHNat";
  3.1055 +
  3.1056 +Goal "(x: SHNat) = (x ~: HNatInfinite)";
  3.1057 +by (blast_tac (claset() addSIs [SHNat_not_HNatInfinite,
  3.1058 +    not_HNatInfinite_SHNat]) 1);
  3.1059 +qed "SHNat_not_HNatInfinite_iff";
  3.1060 +
  3.1061 +Goal "(x ~: SHNat) = (x: HNatInfinite)";
  3.1062 +by (blast_tac (claset() addSIs [not_SHNat_HNatInfinite,
  3.1063 +    HNatInfinite_not_SHNat]) 1);
  3.1064 +qed "not_SHNat_HNatInfinite_iff";
  3.1065 +
  3.1066 +Goal "x : SHNat | x : HNatInfinite";
  3.1067 +by (simp_tac (simpset() addsimps [SHNat_not_HNatInfinite_iff]) 1);
  3.1068 +qed "SHNat_HNatInfinite_disj";
  3.1069 +
  3.1070 +(*-------------------------------------------------------------------
  3.1071 +   Proof of alternative definition for set of Infinite hypernatural 
  3.1072 +   numbers --- HNatInfinite = {N. ALL n: SHNat. n < N}
  3.1073 + -------------------------------------------------------------------*)
  3.1074 +Goal "!!N (xa::nat=>nat). \
  3.1075 +\         (ALL N. {n. xa n ~= N} : FreeUltrafilterNat) ==> \
  3.1076 +\         ({n. N < xa n} : FreeUltrafilterNat)";
  3.1077 +by (nat_ind_tac "N" 1);
  3.1078 +by (dres_inst_tac [("x","0")] spec 1);
  3.1079 +by (rtac ccontr 1 THEN dtac FreeUltrafilterNat_Compl_mem 1
  3.1080 +    THEN dtac FreeUltrafilterNat_Int 1 THEN assume_tac 1);
  3.1081 +by (Asm_full_simp_tac 1);
  3.1082 +by (dres_inst_tac [("x","Suc N")] spec 1);
  3.1083 +by (fuf_tac (claset() addSDs [Suc_leI],simpset() addsimps 
  3.1084 +    [le_eq_less_or_eq]) 1);
  3.1085 +qed "HNatInfinite_FreeUltrafilterNat_lemma";
  3.1086 +
  3.1087 +(*** alternative definition ***)
  3.1088 +Goalw [HNatInfinite_def,SHNat_def,hypnat_of_nat_def] 
  3.1089 +      "HNatInfinite = {N. ALL n:SHNat. n < N}";
  3.1090 +by (Step_tac 1);
  3.1091 +by (dres_inst_tac [("x","Abs_hypnat \
  3.1092 +\        (hypnatrel ^^ {%n. N})")] bspec 2);
  3.1093 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  3.1094 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  3.1095 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_iff]));
  3.1096 +by (auto_tac (claset() addSIs [exI] addEs 
  3.1097 +    [HNatInfinite_FreeUltrafilterNat_lemma],
  3.1098 +    simpset() addsimps [FreeUltrafilterNat_Compl_iff1, 
  3.1099 +     CLAIM "- {n. xa n = N} = {n. xa n ~= N}"]));
  3.1100 +qed "HNatInfinite_iff";
  3.1101 +
  3.1102 +(*--------------------------------------------------------------------
  3.1103 +   Alternative definition for HNatInfinite using Free ultrafilter
  3.1104 + --------------------------------------------------------------------*)
  3.1105 +Goal "!!x. x : HNatInfinite ==> EX X: Rep_hypnat x. \
  3.1106 +\          ALL u. {n. u < X n}:  FreeUltrafilterNat";
  3.1107 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def,
  3.1108 +    HNatInfinite_iff,SHNat_iff,hypnat_of_nat_def]));
  3.1109 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  3.1110 +by (EVERY[Auto_tac, rtac bexI 1, 
  3.1111 +    rtac lemma_hypnatrel_refl 2, Step_tac 1]);
  3.1112 +by (dres_inst_tac [("x","hypnat_of_nat u")] bspec 1);
  3.1113 +by (Simp_tac 1);
  3.1114 +by (auto_tac (claset(),
  3.1115 +    simpset() addsimps [hypnat_of_nat_def]));
  3.1116 +by (Fuf_tac 1);
  3.1117 +qed "HNatInfinite_FreeUltrafilterNat";
  3.1118 +
  3.1119 +Goal "!!x. EX X: Rep_hypnat x. \
  3.1120 +\          ALL u. {n. u < X n}:  FreeUltrafilterNat \
  3.1121 +\          ==> x: HNatInfinite";
  3.1122 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def,
  3.1123 +    HNatInfinite_iff,SHNat_iff,hypnat_of_nat_def]));
  3.1124 +by (rtac exI 1 THEN Auto_tac);
  3.1125 +qed "FreeUltrafilterNat_HNatInfinite";
  3.1126 +
  3.1127 +Goal "!!x. (x : HNatInfinite) = (EX X: Rep_hypnat x. \
  3.1128 +\          ALL u. {n. u < X n}:  FreeUltrafilterNat)";
  3.1129 +by (blast_tac (claset() addIs [HNatInfinite_FreeUltrafilterNat,
  3.1130 +    FreeUltrafilterNat_HNatInfinite]) 1);
  3.1131 +qed "HNatInfinite_FreeUltrafilterNat_iff";
  3.1132 +
  3.1133 +Goal "!!x. x : HNatInfinite ==> 1hn < x";
  3.1134 +by (auto_tac (claset(),simpset() addsimps [HNatInfinite_iff]));
  3.1135 +qed "HNatInfinite_gt_one";
  3.1136 +Addsimps [HNatInfinite_gt_one];
  3.1137 +
  3.1138 +Goal "!!x. 0 ~: HNatInfinite";
  3.1139 +by (auto_tac (claset(),simpset() 
  3.1140 +    addsimps [HNatInfinite_iff]));
  3.1141 +by (dres_inst_tac [("a","1hn")] equals0D 1);
  3.1142 +by (Asm_full_simp_tac 1);
  3.1143 +qed "zero_not_mem_HNatInfinite";
  3.1144 +Addsimps [zero_not_mem_HNatInfinite];
  3.1145 +
  3.1146 +Goal "!!x. x : HNatInfinite ==> x ~= 0";
  3.1147 +by (Auto_tac);
  3.1148 +qed "HNatInfinite_not_eq_zero";
  3.1149 +
  3.1150 +Goal "!!x. x : HNatInfinite ==> 1hn <= x";
  3.1151 +by (blast_tac (claset() addIs [hypnat_less_imp_le,
  3.1152 +         HNatInfinite_gt_one]) 1);
  3.1153 +qed "HNatInfinite_ge_one";
  3.1154 +Addsimps [HNatInfinite_ge_one];
  3.1155 +
  3.1156 +(*--------------------------------------------------
  3.1157 +                   Closure Rules
  3.1158 + --------------------------------------------------*)
  3.1159 +Goal "!!x. [| x: HNatInfinite; y: HNatInfinite |] \
  3.1160 +\           ==> x + y: HNatInfinite";
  3.1161 +by (auto_tac (claset(),simpset() addsimps [HNatInfinite_iff]));
  3.1162 +by (dtac bspec 1 THEN assume_tac 1);
  3.1163 +by (dtac (SHNat_zero RSN (2,bspec)) 1);
  3.1164 +by (dtac hypnat_add_less_mono 1 THEN assume_tac 1);
  3.1165 +by (Asm_full_simp_tac 1);
  3.1166 +qed "HNatInfinite_add";
  3.1167 +
  3.1168 +Goal "!!x. [| x: HNatInfinite; y: SHNat |] \
  3.1169 +\                       ==> x + y: HNatInfinite";
  3.1170 +by (rtac ccontr 1 THEN dtac not_HNatInfinite_SHNat 1);
  3.1171 +by (dres_inst_tac [("x","x + y")] SHNat_minus 1);
  3.1172 +by (auto_tac (claset(),simpset() addsimps 
  3.1173 +    [SHNat_not_HNatInfinite_iff]));
  3.1174 +qed "HNatInfinite_SHNat_add";
  3.1175 +
  3.1176 +goal HyperNat.thy "!!x. [| x: HNatInfinite; y: SHNat |] \
  3.1177 +\                       ==> x - y: HNatInfinite";
  3.1178 +by (rtac ccontr 1 THEN dtac not_HNatInfinite_SHNat 1);
  3.1179 +by (dres_inst_tac [("x","x - y")] SHNat_add 1);
  3.1180 +by (subgoal_tac "y <= x" 2);
  3.1181 +by (auto_tac (claset() addSDs [hypnat_le_add_diff_inverse2],
  3.1182 +    simpset() addsimps [not_SHNat_HNatInfinite_iff RS sym]));
  3.1183 +by (auto_tac (claset() addSIs [hypnat_less_imp_le],
  3.1184 +    simpset() addsimps [not_SHNat_HNatInfinite_iff,HNatInfinite_iff]));
  3.1185 +qed "HNatInfinite_SHNat_diff";
  3.1186 +
  3.1187 +Goal 
  3.1188 +     "!!x. x: HNatInfinite ==> x + 1hn: HNatInfinite";
  3.1189 +by (auto_tac (claset() addIs [HNatInfinite_SHNat_add],
  3.1190 +              simpset()));
  3.1191 +qed "HNatInfinite_add_one";
  3.1192 +
  3.1193 +Goal 
  3.1194 +     "!!x. x: HNatInfinite ==> x - 1hn: HNatInfinite";
  3.1195 +by (rtac ccontr 1 THEN dtac not_HNatInfinite_SHNat 1);
  3.1196 +by (dres_inst_tac [("x","x - 1hn"),("y","1hn")] SHNat_add 1);
  3.1197 +by (auto_tac (claset(),simpset() addsimps 
  3.1198 +    [not_SHNat_HNatInfinite_iff RS sym]));
  3.1199 +qed "HNatInfinite_minus_one";
  3.1200 +
  3.1201 +Goal "!!x. x : HNatInfinite ==> EX y. x = y + 1hn";
  3.1202 +by (res_inst_tac [("x","x - 1hn")] exI 1);
  3.1203 +by (Auto_tac);
  3.1204 +qed "HNatInfinite_is_Suc";
  3.1205 +
  3.1206 +(*---------------------------------------------------------------
  3.1207 +       HNat : the hypernaturals embedded in the hyperreals
  3.1208 +       Obtained using the NS extension of the naturals
  3.1209 + --------------------------------------------------------------*)
  3.1210 + 
  3.1211 +Goalw [HNat_def,starset_def,
  3.1212 +         hypreal_of_posnat_def,hypreal_of_real_def] 
  3.1213 +         "hypreal_of_posnat N : HNat";
  3.1214 +by (Auto_tac);
  3.1215 +by (Ultra_tac 1);
  3.1216 +by (res_inst_tac [("x","Suc N")] exI 1);
  3.1217 +by (dtac sym 1 THEN auto_tac (claset(),simpset() 
  3.1218 +    addsimps [real_of_preal_real_of_nat_Suc]));
  3.1219 +qed "HNat_hypreal_of_posnat";
  3.1220 +Addsimps [HNat_hypreal_of_posnat];
  3.1221 +
  3.1222 +Goalw [HNat_def,starset_def]
  3.1223 +     "[| x: HNat; y: HNat |] ==> x + y: HNat";
  3.1224 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  3.1225 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  3.1226 +by (auto_tac (claset() addSDs [bspec] addIs [lemma_hyprel_refl],
  3.1227 +    simpset() addsimps [hypreal_add]));
  3.1228 +by (Ultra_tac 1);
  3.1229 +by (dres_inst_tac [("t","Y xb")] sym 1);
  3.1230 +by (auto_tac (claset(),simpset() addsimps [real_of_nat_add RS sym]));
  3.1231 +qed "HNat_add";
  3.1232 +
  3.1233 +Goalw [HNat_def,starset_def]
  3.1234 +     "[| x: HNat; y: HNat |] ==> x * y: HNat";
  3.1235 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  3.1236 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  3.1237 +by (auto_tac (claset() addSDs [bspec] addIs [lemma_hyprel_refl],
  3.1238 +    simpset() addsimps [hypreal_mult]));
  3.1239 +by (Ultra_tac 1);
  3.1240 +by (dres_inst_tac [("t","Y xb")] sym 1);
  3.1241 +by (auto_tac (claset(),simpset() addsimps [real_of_nat_mult RS sym]));
  3.1242 +qed "HNat_mult";
  3.1243 +
  3.1244 +(*---------------------------------------------------------------
  3.1245 +    Embedding of the hypernaturals into the hyperreal
  3.1246 + --------------------------------------------------------------*)
  3.1247 +(*** A lemma that should have been derived a long time ago! ***)
  3.1248 +Goal "(Ya : hyprel ^^{%n. f(n)}) = \
  3.1249 +\         ({n. f n = Ya n} : FreeUltrafilterNat)";
  3.1250 +by (Auto_tac);
  3.1251 +qed "lemma_hyprel_FUFN";
  3.1252 +
  3.1253 +Goalw [hypreal_of_hypnat_def]
  3.1254 +      "hypreal_of_hypnat (Abs_hypnat(hypnatrel^^{%n. X n})) = \
  3.1255 +\         Abs_hypreal(hyprel ^^ {%n. real_of_nat (X n)})";
  3.1256 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
  3.1257 +by (auto_tac (claset() addEs [FreeUltrafilterNat_Int RS
  3.1258 +    FreeUltrafilterNat_subset],simpset() addsimps 
  3.1259 +    [lemma_hyprel_FUFN]));
  3.1260 +qed "hypreal_of_hypnat";
  3.1261 +
  3.1262 +Goal "inj(hypreal_of_hypnat)";
  3.1263 +by (rtac injI 1);
  3.1264 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  3.1265 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
  3.1266 +by (auto_tac (claset(),simpset() addsimps 
  3.1267 +    [hypreal_of_hypnat,real_of_nat_eq_cancel]));
  3.1268 +qed "inj_hypreal_of_hypnat";
  3.1269 +
  3.1270 +Goal "(hypreal_of_hypnat n = hypreal_of_hypnat m) = (n = m)";
  3.1271 +by (auto_tac (claset(),simpset() addsimps [inj_hypreal_of_hypnat RS injD]));
  3.1272 +qed "hypreal_of_hypnat_eq_cancel";
  3.1273 +Addsimps [hypreal_of_hypnat_eq_cancel];
  3.1274 +
  3.1275 +Goal "(hypnat_of_nat n = hypnat_of_nat m) = (n = m)";
  3.1276 +by (auto_tac (claset() addDs [inj_hypnat_of_nat RS injD],
  3.1277 +              simpset()));
  3.1278 +qed "hypnat_of_nat_eq_cancel";
  3.1279 +Addsimps [hypnat_of_nat_eq_cancel];
  3.1280 +
  3.1281 +Goalw [hypreal_zero_def,hypnat_zero_def] 
  3.1282 +           "hypreal_of_hypnat  0 = 0";
  3.1283 +by (simp_tac (simpset() addsimps [hypreal_of_hypnat,
  3.1284 +    real_of_nat_zero]) 1);
  3.1285 +qed "hypreal_of_hypnat_zero";
  3.1286 +
  3.1287 +Goalw [hypreal_one_def,hypnat_one_def] 
  3.1288 +           "hypreal_of_hypnat  1hn = 1hr";
  3.1289 +by (simp_tac (simpset() addsimps [hypreal_of_hypnat,
  3.1290 +    real_of_nat_one]) 1);
  3.1291 +qed "hypreal_of_hypnat_one";
  3.1292 +
  3.1293 +Goal "hypreal_of_hypnat n1 + hypreal_of_hypnat n2 = hypreal_of_hypnat (n1 + n2)";
  3.1294 +by (res_inst_tac [("z","n1")] eq_Abs_hypnat 1);
  3.1295 +by (res_inst_tac [("z","n2")] eq_Abs_hypnat 1);
  3.1296 +by (asm_simp_tac (simpset() addsimps [hypreal_of_hypnat,
  3.1297 +        hypreal_add,hypnat_add,real_of_nat_add]) 1);
  3.1298 +qed "hypreal_of_hypnat_add";
  3.1299 +
  3.1300 +Goal "hypreal_of_hypnat n1 * hypreal_of_hypnat n2 = hypreal_of_hypnat (n1 * n2)";
  3.1301 +by (res_inst_tac [("z","n1")] eq_Abs_hypnat 1);
  3.1302 +by (res_inst_tac [("z","n2")] eq_Abs_hypnat 1);
  3.1303 +by (asm_simp_tac (simpset() addsimps [hypreal_of_hypnat,
  3.1304 +        hypreal_mult,hypnat_mult,real_of_nat_mult]) 1);
  3.1305 +qed "hypreal_of_hypnat_mult";
  3.1306 +
  3.1307 +Goal "(hypreal_of_hypnat n < hypreal_of_hypnat m) = (n < m)";
  3.1308 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  3.1309 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  3.1310 +by (asm_simp_tac (simpset() addsimps 
  3.1311 +    [hypreal_of_hypnat,hypreal_less,hypnat_less]) 1);
  3.1312 +qed "hypreal_of_hypnat_less_iff";
  3.1313 +Addsimps [hypreal_of_hypnat_less_iff];
  3.1314 +
  3.1315 +Goal "(hypreal_of_hypnat N = 0) = (N = 0)";
  3.1316 +by (simp_tac (simpset() addsimps [hypreal_of_hypnat_zero RS sym]) 1);
  3.1317 +qed "hypreal_of_hypnat_eq_zero_iff";
  3.1318 +Addsimps [hypreal_of_hypnat_eq_zero_iff];
  3.1319 +
  3.1320 +Goal "ALL n. N <= n ==> N = (0::hypnat)";
  3.1321 +by (dres_inst_tac [("x","0")] spec 1);
  3.1322 +by (res_inst_tac [("z","N")] eq_Abs_hypnat 1);
  3.1323 +by (auto_tac (claset(),simpset() addsimps [hypnat_le,hypnat_zero_def]));
  3.1324 +qed "hypnat_eq_zero";
  3.1325 +Addsimps [hypnat_eq_zero];
  3.1326 +
  3.1327 +Goal "~ (ALL n. n = (0::hypnat))";
  3.1328 +by Auto_tac;
  3.1329 +by (res_inst_tac [("x","1hn")] exI 1);
  3.1330 +by (Simp_tac 1);
  3.1331 +qed "hypnat_not_all_eq_zero";
  3.1332 +Addsimps [hypnat_not_all_eq_zero];
  3.1333 +
  3.1334 +Goal "n ~= 0 ==> (n <= 1hn) = (n = 1hn)";
  3.1335 +by (auto_tac (claset(),simpset() addsimps [hypnat_le_eq_less_or_eq]));
  3.1336 +qed "hypnat_le_one_eq_one";
  3.1337 +Addsimps [hypnat_le_one_eq_one];
  3.1338 +
  3.1339 +
  3.1340 +
  3.1341 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/HOL/Real/Hyperreal/HyperNat.thy	Thu Sep 21 12:17:11 2000 +0200
     4.3 @@ -0,0 +1,84 @@
     4.4 +(*  Title       : HyperNat.thy
     4.5 +    Author      : Jacques D. Fleuriot
     4.6 +    Copyright   : 1998  University of Cambridge
     4.7 +    Description : Explicit construction of hypernaturals using 
     4.8 +                  ultrafilters
     4.9 +*) 
    4.10 +
    4.11 +HyperNat = Star + 
    4.12 +
    4.13 +constdefs
    4.14 +    hypnatrel :: "((nat=>nat)*(nat=>nat)) set"
    4.15 +    "hypnatrel == {p. ? X Y. p = ((X::nat=>nat),Y) & 
    4.16 +                   {n::nat. X(n) = Y(n)}: FreeUltrafilterNat}"
    4.17 +
    4.18 +typedef hypnat = "{x::nat=>nat. True}//hypnatrel"              (Equiv.quotient_def)
    4.19 +
    4.20 +instance
    4.21 +   hypnat  :: {ord,zero,plus,times,minus}
    4.22 +
    4.23 +consts
    4.24 +  "1hn"       :: hypnat               ("1hn")  
    4.25 +  "whn"       :: hypnat               ("whn")  
    4.26 +
    4.27 +defs
    4.28 +
    4.29 +  hypnat_zero_def      "0 == Abs_hypnat(hypnatrel^^{%n::nat. 0})"
    4.30 +  hypnat_one_def       "1hn == Abs_hypnat(hypnatrel^^{%n::nat. 1})"
    4.31 +
    4.32 +  (* omega is in fact an infinite hypernatural number = [<1,2,3,...>] *)
    4.33 +  hypnat_omega_def     "whn == Abs_hypnat(hypnatrel^^{%n::nat. n})"
    4.34 + 
    4.35 +
    4.36 +constdefs
    4.37 +
    4.38 +  (* embedding the naturals in the hypernaturals *)
    4.39 +  hypnat_of_nat   :: nat => hypnat		  ("**# _" [80] 80)	 
    4.40 +  "hypnat_of_nat m  == Abs_hypnat(hypnatrel^^{%n::nat. m})"
    4.41 +
    4.42 +  (* set of naturals embedded in the hypernaturals*)
    4.43 +  SHNat         :: "hypnat set"
    4.44 +  "SHNat        == {n. EX N. n = hypnat_of_nat N}"  
    4.45 + 
    4.46 +  (* embedding the naturals in the hyperreals*)
    4.47 +  SNat         :: "hypreal set"
    4.48 +  "SNat        == {n. EX N. n = hypreal_of_nat N}"  
    4.49 +
    4.50 +  (* hypernaturals as members of the hyperreals; the set is defined as  *)
    4.51 +  (* the nonstandard extension of set of naturals embedded in the reals *)
    4.52 +  HNat         :: "hypreal set"
    4.53 +  "HNat         == *s* {n. EX no. n = real_of_nat no}"
    4.54 +
    4.55 +  (* the set of infinite hypernatural numbers *)
    4.56 +  HNatInfinite :: "hypnat set"
    4.57 +  "HNatInfinite == {n. n ~: SHNat}"
    4.58 +
    4.59 +  (* explicit embedding of the hypernaturals in the hyperreals *)    
    4.60 +  hypreal_of_hypnat :: hypnat => hypreal    ("&H# _" [80] 80)
    4.61 +  "hypreal_of_hypnat N  == Abs_hypreal(UN X: Rep_hypnat(N). 
    4.62 +                            hyprel^^{%n::nat. real_of_nat (X n)})"
    4.63 +  
    4.64 +defs
    4.65 +  hypnat_add_def  
    4.66 +  "P + Q == Abs_hypnat(UN X:Rep_hypnat(P). UN Y:Rep_hypnat(Q).
    4.67 +                hypnatrel^^{%n::nat. X n + Y n})"
    4.68 +
    4.69 +  hypnat_mult_def  
    4.70 +  "P * Q == Abs_hypnat(UN X:Rep_hypnat(P). UN Y:Rep_hypnat(Q).
    4.71 +                hypnatrel^^{%n::nat. X n * Y n})"
    4.72 +
    4.73 +  hypnat_minus_def  
    4.74 +  "P - Q == Abs_hypnat(UN X:Rep_hypnat(P). UN Y:Rep_hypnat(Q).
    4.75 +                hypnatrel^^{%n::nat. X n - Y n})"
    4.76 +
    4.77 +  hypnat_less_def
    4.78 +  "P < (Q::hypnat) == EX X Y. X: Rep_hypnat(P) & 
    4.79 +                               Y: Rep_hypnat(Q) & 
    4.80 +                               {n::nat. X n < Y n} : FreeUltrafilterNat"
    4.81 +  hypnat_le_def
    4.82 +  "P <= (Q::hypnat) == ~(Q < P)" 
    4.83 +
    4.84 +end
    4.85 +
    4.86 +
    4.87 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/HOL/Real/Hyperreal/HyperOrd.ML	Thu Sep 21 12:17:11 2000 +0200
     5.3 @@ -0,0 +1,791 @@
     5.4 +(*  Title:	 Real/Hyperreal/HyperOrd.ML
     5.5 +    Author:      Jacques D. Fleuriot
     5.6 +    Copyright:   1998 University of Cambridge
     5.7 +                 2000 University of Edinburgh
     5.8 +    Description: Type "hypreal" is a linear order and also 
     5.9 +                 satisfies plus_ac0: + is an AC-operator with zero
    5.10 +*)
    5.11 +
    5.12 +(**** The simproc abel_cancel ****)
    5.13 +
    5.14 +(*** Two lemmas needed for the simprocs ***)
    5.15 +
    5.16 +(*Deletion of other terms in the formula, seeking the -x at the front of z*)
    5.17 +Goal "((x::hypreal) + (y + z) = y + u) = ((x + z) = u)";
    5.18 +by (stac hypreal_add_left_commute 1);
    5.19 +by (rtac hypreal_add_left_cancel 1);
    5.20 +qed "hypreal_add_cancel_21";
    5.21 +
    5.22 +(*A further rule to deal with the case that
    5.23 +  everything gets cancelled on the right.*)
    5.24 +Goal "((x::hypreal) + (y + z) = y) = (x = -z)";
    5.25 +by (stac hypreal_add_left_commute 1);
    5.26 +by (res_inst_tac [("t", "y")] (hypreal_add_zero_right RS subst) 1
    5.27 +    THEN stac hypreal_add_left_cancel 1);
    5.28 +by (simp_tac (simpset() addsimps [hypreal_eq_diff_eq RS sym]) 1);
    5.29 +qed "hypreal_add_cancel_end";
    5.30 +
    5.31 +
    5.32 +structure Hyperreal_Cancel_Data =
    5.33 +struct
    5.34 +  val ss		= HOL_ss
    5.35 +  val eq_reflection	= eq_reflection
    5.36 +
    5.37 +  val sg_ref		= Sign.self_ref (Theory.sign_of (the_context ()))
    5.38 +  val T			= Type("HyperDef.hypreal",[])
    5.39 +  val zero		= Const ("0", T)
    5.40 +  val restrict_to_left  = restrict_to_left
    5.41 +  val add_cancel_21	= hypreal_add_cancel_21
    5.42 +  val add_cancel_end	= hypreal_add_cancel_end
    5.43 +  val add_left_cancel	= hypreal_add_left_cancel
    5.44 +  val add_assoc		= hypreal_add_assoc
    5.45 +  val add_commute	= hypreal_add_commute
    5.46 +  val add_left_commute	= hypreal_add_left_commute
    5.47 +  val add_0		= hypreal_add_zero_left
    5.48 +  val add_0_right	= hypreal_add_zero_right
    5.49 +
    5.50 +  val eq_diff_eq	= hypreal_eq_diff_eq
    5.51 +  val eqI_rules		= [hypreal_less_eqI, hypreal_eq_eqI, hypreal_le_eqI]
    5.52 +  fun dest_eqI th = 
    5.53 +      #1 (HOLogic.dest_bin "op =" HOLogic.boolT 
    5.54 +	      (HOLogic.dest_Trueprop (concl_of th)))
    5.55 +
    5.56 +  val diff_def		= hypreal_diff_def
    5.57 +  val minus_add_distrib	= hypreal_minus_add_distrib
    5.58 +  val minus_minus	= hypreal_minus_minus
    5.59 +  val minus_0		= hypreal_minus_zero
    5.60 +  val add_inverses	= [hypreal_add_minus, hypreal_add_minus_left];
    5.61 +  val cancel_simps	= [hypreal_add_minus_cancelA, hypreal_minus_add_cancelA]
    5.62 +end;
    5.63 +
    5.64 +structure Hyperreal_Cancel = Abel_Cancel (Hyperreal_Cancel_Data);
    5.65 +
    5.66 +Addsimprocs [Hyperreal_Cancel.sum_conv, Hyperreal_Cancel.rel_conv];
    5.67 +
    5.68 +Goal "- (z - y) = y - (z::hypreal)";
    5.69 +by (Simp_tac 1);
    5.70 +qed "hypreal_minus_diff_eq";
    5.71 +Addsimps [hypreal_minus_diff_eq];
    5.72 +
    5.73 +
    5.74 +Goal "((x::hypreal) < y) = (-y < -x)";
    5.75 +by (stac hypreal_less_minus_iff 1);
    5.76 +by (res_inst_tac [("x1","x")] (hypreal_less_minus_iff RS ssubst) 1);
    5.77 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
    5.78 +qed "hypreal_less_swap_iff";
    5.79 +
    5.80 +Goalw [hypreal_zero_def] 
    5.81 +      "((0::hypreal) < x) = (-x < x)";
    5.82 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
    5.83 +by (auto_tac (claset(),simpset() addsimps [hypreal_less,
    5.84 +    hypreal_minus]));
    5.85 +by (ALLGOALS(Ultra_tac));
    5.86 +qed "hypreal_gt_zero_iff";
    5.87 +
    5.88 +Goal "(A::hypreal) < B ==> A + C < B + C";
    5.89 +by (res_inst_tac [("z","A")] eq_Abs_hypreal 1);
    5.90 +by (res_inst_tac [("z","B")] eq_Abs_hypreal 1);
    5.91 +by (res_inst_tac [("z","C")] eq_Abs_hypreal 1);
    5.92 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
    5.93 +    [hypreal_less_def,hypreal_add]));
    5.94 +by (Ultra_tac 1);
    5.95 +qed "hypreal_add_less_mono1";
    5.96 +
    5.97 +Goal "!!(A::hypreal). A < B ==> C + A < C + B";
    5.98 +by (auto_tac (claset() addIs [hypreal_add_less_mono1],
    5.99 +    simpset() addsimps [hypreal_add_commute]));
   5.100 +qed "hypreal_add_less_mono2";
   5.101 +
   5.102 +Goal "(x < (0::hypreal)) = (x < -x)";
   5.103 +by (rtac (hypreal_minus_zero_less_iff RS subst) 1);
   5.104 +by (stac hypreal_gt_zero_iff 1);
   5.105 +by (Full_simp_tac 1);
   5.106 +qed "hypreal_lt_zero_iff";
   5.107 +
   5.108 +Goalw [hypreal_le_def] "((0::hypreal) <= x) = (-x <= x)";
   5.109 +by (auto_tac (claset(),simpset() addsimps [hypreal_lt_zero_iff RS sym]));
   5.110 +qed "hypreal_ge_zero_iff";
   5.111 +
   5.112 +Goalw [hypreal_le_def] "(x <= (0::hypreal)) = (x <= -x)";
   5.113 +by (auto_tac (claset(),simpset() addsimps [hypreal_gt_zero_iff RS sym]));
   5.114 +qed "hypreal_le_zero_iff";
   5.115 +
   5.116 +Goalw [hypreal_zero_def] 
   5.117 +      "[| 0 < x; 0 < y |] ==> (0::hypreal) < x + y";
   5.118 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   5.119 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   5.120 +by (auto_tac (claset(),simpset() addsimps
   5.121 +    [hypreal_less_def,hypreal_add]));
   5.122 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
   5.123 +    [hypreal_less_def,hypreal_add]));
   5.124 +by (ultra_tac (claset() addIs [real_add_order],simpset()) 1);
   5.125 +qed "hypreal_add_order";
   5.126 +
   5.127 +Goal "[| 0 < x; 0 <= y |] ==> (0::hypreal) < x + y";
   5.128 +by (auto_tac (claset() addDs [sym,hypreal_le_imp_less_or_eq]
   5.129 +              addIs [hypreal_add_order],simpset()));
   5.130 +qed "hypreal_add_order_le";            
   5.131 +
   5.132 +Goalw [hypreal_zero_def] 
   5.133 +          "[| 0 < x; 0 < y |] ==> (0::hypreal) < x * y";
   5.134 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   5.135 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   5.136 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
   5.137 +    [hypreal_less_def,hypreal_mult]));
   5.138 +by (ultra_tac (claset() addIs [rename_numerals real_mult_order],
   5.139 +	       simpset()) 1);
   5.140 +qed "hypreal_mult_order";
   5.141 +
   5.142 +Goal "[| x < 0; y < 0 |] ==> (0::hypreal) < x * y";
   5.143 +by (REPEAT(dtac (hypreal_minus_zero_less_iff RS iffD2) 1));
   5.144 +by (dtac hypreal_mult_order 1 THEN assume_tac 1);
   5.145 +by (Asm_full_simp_tac 1);
   5.146 +qed "hypreal_mult_less_zero1";
   5.147 +
   5.148 +Goal "[| 0 <= x; 0 <= y |] ==> (0::hypreal) <= x * y";
   5.149 +by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
   5.150 +by (auto_tac (claset() addIs [hypreal_mult_order,
   5.151 +    hypreal_less_imp_le],simpset()));
   5.152 +qed "hypreal_le_mult_order";
   5.153 +
   5.154 +
   5.155 +Goal "[| x <= 0; y <= 0 |] ==> (0::hypreal) <= x * y";
   5.156 +by (rtac hypreal_less_or_eq_imp_le 1);
   5.157 +by (dtac hypreal_le_imp_less_or_eq 1 THEN etac disjE 1);
   5.158 +by Auto_tac;
   5.159 +by (dtac hypreal_le_imp_less_or_eq 1);
   5.160 +by (auto_tac (claset() addDs [hypreal_mult_less_zero1],simpset()));
   5.161 +qed "hypreal_mult_le_zero1";
   5.162 +
   5.163 +Goal "[| 0 <= x; y < 0 |] ==> x * y <= (0::hypreal)";
   5.164 +by (rtac hypreal_less_or_eq_imp_le 1);
   5.165 +by (dtac hypreal_le_imp_less_or_eq 1 THEN etac disjE 1);
   5.166 +by Auto_tac;
   5.167 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
   5.168 +by (rtac (hypreal_minus_zero_less_iff RS subst) 1);
   5.169 +by (blast_tac (claset() addDs [hypreal_mult_order] 
   5.170 +    addIs [hypreal_minus_mult_eq2 RS ssubst]) 1);
   5.171 +qed "hypreal_mult_le_zero";
   5.172 +
   5.173 +Goal "[| 0 < x; y < 0 |] ==> x*y < (0::hypreal)";
   5.174 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
   5.175 +by (dtac hypreal_mult_order 1 THEN assume_tac 1);
   5.176 +by (rtac (hypreal_minus_zero_less_iff RS iffD1) 1);
   5.177 +by (Asm_full_simp_tac 1);
   5.178 +qed "hypreal_mult_less_zero";
   5.179 +
   5.180 +Goalw [hypreal_one_def,hypreal_zero_def,hypreal_less_def] "0 < 1hr";
   5.181 +by (res_inst_tac [("x","%n. #0")] exI 1);
   5.182 +by (res_inst_tac [("x","%n. #1")] exI 1);
   5.183 +by (auto_tac (claset(),simpset() addsimps [real_zero_less_one,
   5.184 +    FreeUltrafilterNat_Nat_set]));
   5.185 +qed "hypreal_zero_less_one";
   5.186 +
   5.187 +Goal "1hr < 1hr + 1hr";
   5.188 +by (rtac (hypreal_less_minus_iff RS iffD2) 1);
   5.189 +by (full_simp_tac (simpset() addsimps [hypreal_zero_less_one,
   5.190 +    hypreal_add_assoc]) 1);
   5.191 +qed "hypreal_one_less_two";
   5.192 +
   5.193 +Goal "0 < 1hr + 1hr";
   5.194 +by (rtac ([hypreal_zero_less_one,
   5.195 +          hypreal_one_less_two] MRS hypreal_less_trans) 1);
   5.196 +qed "hypreal_zero_less_two";
   5.197 +
   5.198 +Goal "1hr + 1hr ~= 0";
   5.199 +by (rtac (hypreal_zero_less_two RS hypreal_not_refl2 RS not_sym) 1);
   5.200 +qed "hypreal_two_not_zero";
   5.201 +Addsimps [hypreal_two_not_zero];
   5.202 +
   5.203 +Goal "x*hrinv(1hr + 1hr) + x*hrinv(1hr + 1hr) = x";
   5.204 +by (stac hypreal_add_self 1);
   5.205 +by (full_simp_tac (simpset() addsimps [hypreal_mult_assoc,
   5.206 +    hypreal_two_not_zero RS hypreal_mult_hrinv_left]) 1);
   5.207 +qed "hypreal_sum_of_halves";
   5.208 +
   5.209 +Goal "[| 0 <= x; 0 <= y |] ==> (0::hypreal) <= x + y";
   5.210 +by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
   5.211 +by (auto_tac (claset() addIs [hypreal_add_order,
   5.212 +    hypreal_less_imp_le],simpset()));
   5.213 +qed "hypreal_le_add_order";
   5.214 +
   5.215 +(*** Monotonicity results ***)
   5.216 +
   5.217 +Goal "(v+z < w+z) = (v < (w::hypreal))";
   5.218 +by (Simp_tac 1);
   5.219 +qed "hypreal_add_right_cancel_less";
   5.220 +
   5.221 +Goal "(z+v < z+w) = (v < (w::hypreal))";
   5.222 +by (Simp_tac 1);
   5.223 +qed "hypreal_add_left_cancel_less";
   5.224 +
   5.225 +Addsimps [hypreal_add_right_cancel_less, 
   5.226 +          hypreal_add_left_cancel_less];
   5.227 +
   5.228 +Goal "(v+z <= w+z) = (v <= (w::hypreal))";
   5.229 +by (Simp_tac 1);
   5.230 +qed "hypreal_add_right_cancel_le";
   5.231 +
   5.232 +Goal "(z+v <= z+w) = (v <= (w::hypreal))";
   5.233 +by (Simp_tac 1);
   5.234 +qed "hypreal_add_left_cancel_le";
   5.235 +
   5.236 +Addsimps [hypreal_add_right_cancel_le, hypreal_add_left_cancel_le];
   5.237 +
   5.238 +Goal  "[| (z1::hypreal) < y1; z2 < y2 |] ==> z1 + z2 < y1 + y2";
   5.239 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
   5.240 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
   5.241 +by (dtac hypreal_add_order 1 THEN assume_tac 1);
   5.242 +by (thin_tac "0 < y2 + - z2" 1);
   5.243 +by (dres_inst_tac [("C","z1 + z2")] hypreal_add_less_mono1 1);
   5.244 +by (auto_tac (claset(),simpset() addsimps 
   5.245 +    [hypreal_minus_add_distrib RS sym] @ hypreal_add_ac
   5.246 +    delsimps [hypreal_minus_add_distrib]));
   5.247 +qed "hypreal_add_less_mono";
   5.248 +
   5.249 +Goal "(q1::hypreal) <= q2  ==> x + q1 <= x + q2";
   5.250 +by (dtac hypreal_le_imp_less_or_eq 1);
   5.251 +by (Step_tac 1);
   5.252 +by (auto_tac (claset() addSIs [hypreal_le_refl,
   5.253 +    hypreal_less_imp_le,hypreal_add_less_mono1],
   5.254 +    simpset() addsimps [hypreal_add_commute]));
   5.255 +qed "hypreal_add_left_le_mono1";
   5.256 +
   5.257 +Goal "(q1::hypreal) <= q2  ==> q1 + x <= q2 + x";
   5.258 +by (auto_tac (claset() addDs [hypreal_add_left_le_mono1],
   5.259 +    simpset() addsimps [hypreal_add_commute]));
   5.260 +qed "hypreal_add_le_mono1";
   5.261 +
   5.262 +Goal "[|(i::hypreal)<=j;  k<=l |] ==> i + k <= j + l";
   5.263 +by (etac (hypreal_add_le_mono1 RS hypreal_le_trans) 1);
   5.264 +by (Simp_tac 1);
   5.265 +qed "hypreal_add_le_mono";
   5.266 +
   5.267 +Goal "[|(i::hypreal)<j;  k<=l |] ==> i + k < j + l";
   5.268 +by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq] 
   5.269 +    addIs [hypreal_add_less_mono1,hypreal_add_less_mono],
   5.270 +    simpset()));
   5.271 +qed "hypreal_add_less_le_mono";
   5.272 +
   5.273 +Goal "[|(i::hypreal)<=j;  k<l |] ==> i + k < j + l";
   5.274 +by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq] 
   5.275 +    addIs [hypreal_add_less_mono2,hypreal_add_less_mono],simpset()));
   5.276 +qed "hypreal_add_le_less_mono";
   5.277 +
   5.278 +Goal "(A::hypreal) + C < B + C ==> A < B";
   5.279 +by (Full_simp_tac 1);
   5.280 +qed "hypreal_less_add_right_cancel";
   5.281 +
   5.282 +Goal "(C::hypreal) + A < C + B ==> A < B";
   5.283 +by (Full_simp_tac 1);
   5.284 +qed "hypreal_less_add_left_cancel";
   5.285 +
   5.286 +Goal "[|r < x; (0::hypreal) <= y|] ==> r < x + y";
   5.287 +by (auto_tac (claset() addDs [hypreal_add_less_le_mono],
   5.288 +    simpset()));
   5.289 +qed "hypreal_add_zero_less_le_mono";
   5.290 +
   5.291 +Goal "!!(A::hypreal). A + C <= B + C ==> A <= B";
   5.292 +by (dres_inst_tac [("x","-C")] hypreal_add_le_mono1 1);
   5.293 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
   5.294 +qed "hypreal_le_add_right_cancel";
   5.295 +
   5.296 +Goal "!!(A::hypreal). C + A <= C + B ==> A <= B";
   5.297 +by (dres_inst_tac [("x","-C")] hypreal_add_left_le_mono1 1);
   5.298 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   5.299 +qed "hypreal_le_add_left_cancel";
   5.300 +
   5.301 +Goal "(0::hypreal) <= x*x";
   5.302 +by (res_inst_tac [("x","0"),("y","x")] hypreal_linear_less2 1);
   5.303 +by (auto_tac (claset() addIs [hypreal_mult_order,
   5.304 +    hypreal_mult_less_zero1,hypreal_less_imp_le],
   5.305 +    simpset()));
   5.306 +qed "hypreal_le_square";
   5.307 +Addsimps [hypreal_le_square];
   5.308 +
   5.309 +Goalw [hypreal_le_def] "- (x*x) <= (0::hypreal)";
   5.310 +by (auto_tac (claset() addSDs [(hypreal_le_square RS 
   5.311 +    hypreal_le_less_trans)],simpset() addsimps 
   5.312 +    [hypreal_minus_zero_less_iff,hypreal_less_not_refl]));
   5.313 +qed "hypreal_less_minus_square";
   5.314 +Addsimps [hypreal_less_minus_square];
   5.315 +
   5.316 +Goal "(0*x<r)=((0::hypreal)<r)";
   5.317 +by (Simp_tac 1);
   5.318 +qed "hypreal_mult_0_less";
   5.319 +
   5.320 +Goal "[| (0::hypreal) < z; x < y |] ==> x*z < y*z";       
   5.321 +by (rotate_tac 1 1);
   5.322 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
   5.323 +by (rtac (hypreal_less_minus_iff RS iffD2) 1);
   5.324 +by (dtac hypreal_mult_order 1 THEN assume_tac 1);
   5.325 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_mult_distrib2,
   5.326 +					   hypreal_mult_commute ]) 1);
   5.327 +qed "hypreal_mult_less_mono1";
   5.328 +
   5.329 +Goal "[| (0::hypreal)<z; x<y |] ==> z*x<z*y";       
   5.330 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_commute,hypreal_mult_less_mono1]) 1);
   5.331 +qed "hypreal_mult_less_mono2";
   5.332 +
   5.333 +Goal "[| (0::hypreal)<=z; x<y |] ==> x*z<=y*z";
   5.334 +by (EVERY1 [rtac hypreal_less_or_eq_imp_le, dtac hypreal_le_imp_less_or_eq]);
   5.335 +by (auto_tac (claset() addIs [hypreal_mult_less_mono1],simpset()));
   5.336 +qed "hypreal_mult_le_less_mono1";
   5.337 +
   5.338 +Goal "[| (0::hypreal)<=z; x<y |] ==> z*x<=z*y";
   5.339 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_commute,
   5.340 +				      hypreal_mult_le_less_mono1]) 1);
   5.341 +qed "hypreal_mult_le_less_mono2";
   5.342 +
   5.343 +Goal "[| (0::hypreal)<=z; x<=y |] ==> z*x<=z*y";
   5.344 +by (dres_inst_tac [("x","x")] hypreal_le_imp_less_or_eq 1);
   5.345 +by (auto_tac (claset() addIs [hypreal_mult_le_less_mono2,hypreal_le_refl],simpset()));
   5.346 +qed "hypreal_mult_le_le_mono1";
   5.347 +
   5.348 +val prem1::prem2::prem3::rest = goal thy
   5.349 +     "[| (0::hypreal)<y; x<r; y*r<t*s |] ==> y*x<t*s";
   5.350 +by (rtac ([([prem1,prem2] MRS hypreal_mult_less_mono2),prem3] MRS hypreal_less_trans) 1);
   5.351 +qed "hypreal_mult_less_trans";
   5.352 +
   5.353 +Goal "[| 0<=y; x<r; y*r<t*s; (0::hypreal)<t*s|] ==> y*x<t*s";
   5.354 +by (dtac hypreal_le_imp_less_or_eq 1);
   5.355 +by (fast_tac (HOL_cs addEs [(hypreal_mult_0_less RS iffD2),hypreal_mult_less_trans]) 1);
   5.356 +qed "hypreal_mult_le_less_trans";
   5.357 +
   5.358 +Goal "[| 0 <= y; x <= r; y*r < t*s; (0::hypreal) < t*s|] ==> y*x < t*s";
   5.359 +by (dres_inst_tac [("x","x")] hypreal_le_imp_less_or_eq 1);
   5.360 +by (fast_tac (claset() addIs [hypreal_mult_le_less_trans]) 1);
   5.361 +qed "hypreal_mult_le_le_trans";
   5.362 +
   5.363 +Goal "[| 0 < r1; r1 <r2; (0::hypreal) < x; x < y|] \
   5.364 +\                     ==> r1 * x < r2 * y";
   5.365 +by (dres_inst_tac [("x","x")] hypreal_mult_less_mono2 1);
   5.366 +by (dres_inst_tac [("R1.0","0")] hypreal_less_trans 2);
   5.367 +by (dres_inst_tac [("x","r1")] hypreal_mult_less_mono1 3);
   5.368 +by Auto_tac;
   5.369 +by (blast_tac (claset() addIs [hypreal_less_trans]) 1);
   5.370 +qed "hypreal_mult_less_mono";
   5.371 +
   5.372 +Goal "[| 0 < r1; r1 <r2; 0 < y|] \
   5.373 +\                           ==> (0::hypreal) < r2 * y";
   5.374 +by (dres_inst_tac [("R1.0","0")] hypreal_less_trans 1);
   5.375 +by (assume_tac 1);
   5.376 +by (blast_tac (claset() addIs [hypreal_mult_order]) 1);
   5.377 +qed "hypreal_mult_order_trans";
   5.378 +
   5.379 +Goal "[| 0 < r1; r1 <= r2; (0::hypreal) <= x; x <= y |] \
   5.380 +\                  ==> r1 * x <= r2 * y";
   5.381 +by (rtac hypreal_less_or_eq_imp_le 1);
   5.382 +by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
   5.383 +by (auto_tac (claset() addIs [hypreal_mult_less_mono,
   5.384 +    hypreal_mult_less_mono1,hypreal_mult_less_mono2,
   5.385 +    hypreal_mult_order_trans,hypreal_mult_order],simpset()));
   5.386 +qed "hypreal_mult_le_mono";
   5.387 +
   5.388 +Goal "0 < x ==> 0 < hrinv x";
   5.389 +by (EVERY1[rtac ccontr, dtac hypreal_leI]);
   5.390 +by (forward_tac [hypreal_minus_zero_less_iff2 RS iffD2] 1);
   5.391 +by (forward_tac [hypreal_not_refl2 RS not_sym] 1);
   5.392 +by (dtac (hypreal_not_refl2 RS not_sym RS hrinv_not_zero) 1);
   5.393 +by (EVERY1[dtac hypreal_le_imp_less_or_eq, Step_tac]); 
   5.394 +by (dtac hypreal_mult_less_zero1 1 THEN assume_tac 1);
   5.395 +by (auto_tac (claset() addIs [hypreal_zero_less_one RS hypreal_less_asym],
   5.396 +    simpset() addsimps [hypreal_minus_zero_less_iff]));
   5.397 +qed "hypreal_hrinv_gt_zero";
   5.398 +
   5.399 +Goal "x < 0 ==> hrinv x < 0";
   5.400 +by (ftac hypreal_not_refl2 1);
   5.401 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
   5.402 +by (rtac (hypreal_minus_zero_less_iff RS iffD1) 1);
   5.403 +by (dtac (hypreal_minus_hrinv RS sym) 1);
   5.404 +by (auto_tac (claset() addIs [hypreal_hrinv_gt_zero],
   5.405 +    simpset()));
   5.406 +qed "hypreal_hrinv_less_zero";
   5.407 +
   5.408 +(* check why this does not work without 2nd substitution anymore! *)
   5.409 +Goal "x < y ==> x < (x + y)*hrinv(1hr + 1hr)";
   5.410 +by (dres_inst_tac [("C","x")] hypreal_add_less_mono2 1);
   5.411 +by (dtac (hypreal_add_self RS subst) 1);
   5.412 +by (dtac (hypreal_zero_less_two RS hypreal_hrinv_gt_zero RS 
   5.413 +          hypreal_mult_less_mono1) 1);
   5.414 +by (auto_tac (claset() addDs [hypreal_two_not_zero RS 
   5.415 +          (hypreal_mult_hrinv RS subst)],simpset() 
   5.416 +          addsimps [hypreal_mult_assoc]));
   5.417 +qed "hypreal_less_half_sum";
   5.418 +
   5.419 +(* check why this does not work without 2nd substitution anymore! *)
   5.420 +Goal "x < y ==> (x + y)*hrinv(1hr + 1hr) < y";
   5.421 +by (dres_inst_tac [("C","y")] hypreal_add_less_mono1 1);
   5.422 +by (dtac (hypreal_add_self RS subst) 1);
   5.423 +by (dtac (hypreal_zero_less_two RS hypreal_hrinv_gt_zero RS 
   5.424 +          hypreal_mult_less_mono1) 1);
   5.425 +by (auto_tac (claset() addDs [hypreal_two_not_zero RS 
   5.426 +          (hypreal_mult_hrinv RS subst)],simpset() 
   5.427 +          addsimps [hypreal_mult_assoc]));
   5.428 +qed "hypreal_gt_half_sum";
   5.429 +
   5.430 +Goal "!!(x::hypreal). x < y ==> EX r. x < r & r < y";
   5.431 +by (blast_tac (claset() addSIs [hypreal_less_half_sum,
   5.432 +    hypreal_gt_half_sum]) 1);
   5.433 +qed "hypreal_dense";
   5.434 +
   5.435 +
   5.436 +Goal "(x*x + y*y = 0) = (x = 0 & y = (0::hypreal))";
   5.437 +by Auto_tac;
   5.438 +by (dtac (sym RS (hypreal_eq_minus_iff3 RS iffD1))  1);
   5.439 +by (dtac (sym RS (hypreal_eq_minus_iff4 RS iffD1))  2);
   5.440 +by (ALLGOALS(rtac ccontr));
   5.441 +by (ALLGOALS(dtac hypreal_mult_self_not_zero));
   5.442 +by (cut_inst_tac [("x1","x")] (hypreal_le_square 
   5.443 +        RS hypreal_le_imp_less_or_eq) 1);
   5.444 +by (cut_inst_tac [("x1","y")] (hypreal_le_square 
   5.445 +        RS hypreal_le_imp_less_or_eq) 2);
   5.446 +by (auto_tac (claset() addDs [sym],simpset()));
   5.447 +by (dres_inst_tac [("x1","y")] (hypreal_less_minus_square 
   5.448 +    RS hypreal_le_less_trans) 1);
   5.449 +by (dres_inst_tac [("x1","x")] (hypreal_less_minus_square 
   5.450 +    RS hypreal_le_less_trans) 2);
   5.451 +by (auto_tac (claset(),simpset() addsimps 
   5.452 +       [hypreal_less_not_refl]));
   5.453 +qed "hypreal_squares_add_zero_iff";
   5.454 +Addsimps [hypreal_squares_add_zero_iff];
   5.455 +
   5.456 +Goal "x * x ~= 0 ==> (0::hypreal) < x* x + y*y + z*z";
   5.457 +by (cut_inst_tac [("x1","x")] (hypreal_le_square 
   5.458 +        RS hypreal_le_imp_less_or_eq) 1);
   5.459 +by (auto_tac (claset() addSIs 
   5.460 +              [hypreal_add_order_le],simpset()));
   5.461 +qed "hypreal_sum_squares3_gt_zero";
   5.462 +
   5.463 +Goal "x * x ~= 0 ==> (0::hypreal) < y*y + x*x + z*z";
   5.464 +by (dtac hypreal_sum_squares3_gt_zero 1);
   5.465 +by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
   5.466 +qed "hypreal_sum_squares3_gt_zero2";
   5.467 +
   5.468 +Goal "x * x ~= 0 ==> (0::hypreal) < y*y + z*z + x*x";
   5.469 +by (dtac hypreal_sum_squares3_gt_zero 1);
   5.470 +by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
   5.471 +qed "hypreal_sum_squares3_gt_zero3";
   5.472 +
   5.473 +
   5.474 +Goal "(x*x + y*y + z*z = 0) = (x = 0 & y = 0 & z = (0::hypreal))";
   5.475 +by Auto_tac;
   5.476 +by (ALLGOALS(rtac ccontr));
   5.477 +by (ALLGOALS(dtac hypreal_mult_self_not_zero));
   5.478 +by (auto_tac (claset() addDs [hypreal_not_refl2 RS not_sym,
   5.479 +   hypreal_sum_squares3_gt_zero3,hypreal_sum_squares3_gt_zero,
   5.480 +   hypreal_sum_squares3_gt_zero2],simpset() delsimps
   5.481 +   [hypreal_mult_self_eq_zero_iff]));
   5.482 +qed "hypreal_three_squares_add_zero_iff";
   5.483 +Addsimps [hypreal_three_squares_add_zero_iff];
   5.484 +
   5.485 +Addsimps [rename_numerals real_le_square];
   5.486 +Goal "(x::hypreal)*x <= x*x + y*y";
   5.487 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   5.488 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   5.489 +by (auto_tac (claset(),simpset() addsimps 
   5.490 +    [hypreal_mult,hypreal_add,hypreal_le]));
   5.491 +qed "hypreal_self_le_add_pos";
   5.492 +Addsimps [hypreal_self_le_add_pos];
   5.493 +
   5.494 +Goal "(x::hypreal)*x <= x*x + y*y + z*z";
   5.495 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   5.496 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   5.497 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   5.498 +by (auto_tac (claset(),
   5.499 +	      simpset() addsimps [hypreal_mult, hypreal_add, hypreal_le,
   5.500 +				  rename_numerals real_le_add_order]));
   5.501 +qed "hypreal_self_le_add_pos2";
   5.502 +Addsimps [hypreal_self_le_add_pos2];
   5.503 +
   5.504 +
   5.505 +(*---------------------------------------------------------------------------------
   5.506 +             Embedding of the naturals in the hyperreals
   5.507 + ---------------------------------------------------------------------------------*)
   5.508 +Goalw [hypreal_of_posnat_def] "hypreal_of_posnat 0 = 1hr";
   5.509 +by (full_simp_tac (simpset() addsimps 
   5.510 +    [pnat_one_iff RS sym,real_of_preal_def]) 1);
   5.511 +by (fold_tac [real_one_def]);
   5.512 +by (simp_tac (simpset() addsimps [hypreal_of_real_one]) 1);
   5.513 +qed "hypreal_of_posnat_one";
   5.514 +
   5.515 +Goalw [hypreal_of_posnat_def] "hypreal_of_posnat 1 = 1hr + 1hr";
   5.516 +by (full_simp_tac (simpset() addsimps 
   5.517 +		   [real_of_preal_def,
   5.518 +		    rename_numerals (real_one_def RS meta_eq_to_obj_eq),
   5.519 +		    hypreal_add,hypreal_of_real_def,pnat_two_eq,
   5.520 +		    hypreal_one_def, real_add,
   5.521 +		    prat_of_pnat_add RS sym, preal_of_prat_add RS sym] @ 
   5.522 +		    pnat_add_ac) 1);
   5.523 +qed "hypreal_of_posnat_two";
   5.524 +
   5.525 +Goalw [hypreal_of_posnat_def]
   5.526 +          "hypreal_of_posnat n1 + hypreal_of_posnat n2 = \
   5.527 +\          hypreal_of_posnat (n1 + n2) + 1hr";
   5.528 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_one RS sym,
   5.529 +    hypreal_of_real_add RS sym,hypreal_of_posnat_def,real_of_preal_add RS sym,
   5.530 +    preal_of_prat_add RS sym,prat_of_pnat_add RS sym,pnat_of_nat_add]) 1);
   5.531 +qed "hypreal_of_posnat_add";
   5.532 +
   5.533 +Goal "hypreal_of_posnat (n + 1) = hypreal_of_posnat n + 1hr";
   5.534 +by (res_inst_tac [("x1","1hr")] (hypreal_add_right_cancel RS iffD1) 1);
   5.535 +by (rtac (hypreal_of_posnat_add RS subst) 1);
   5.536 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_two,hypreal_add_assoc]) 1);
   5.537 +qed "hypreal_of_posnat_add_one";
   5.538 +
   5.539 +Goalw [real_of_posnat_def,hypreal_of_posnat_def] 
   5.540 +      "hypreal_of_posnat n = hypreal_of_real (real_of_posnat n)";
   5.541 +by (rtac refl 1);
   5.542 +qed "hypreal_of_real_of_posnat";
   5.543 +
   5.544 +Goalw [hypreal_of_posnat_def] 
   5.545 +      "(n < m) = (hypreal_of_posnat n < hypreal_of_posnat m)";
   5.546 +by Auto_tac;
   5.547 +qed "hypreal_of_posnat_less_iff";
   5.548 +
   5.549 +Addsimps [hypreal_of_posnat_less_iff RS sym];
   5.550 +(*---------------------------------------------------------------------------------
   5.551 +               Existence of infinite hyperreal number
   5.552 + ---------------------------------------------------------------------------------*)
   5.553 +
   5.554 +Goal "hyprel^^{%n::nat. real_of_posnat n} : hypreal";
   5.555 +by Auto_tac;
   5.556 +qed "hypreal_omega";
   5.557 +
   5.558 +Goalw [omega_def] "Rep_hypreal(whr) : hypreal";
   5.559 +by (rtac Rep_hypreal 1);
   5.560 +qed "Rep_hypreal_omega";
   5.561 +
   5.562 +(* existence of infinite number not corresponding to any real number *)
   5.563 +(* use assumption that member FreeUltrafilterNat is not finite       *)
   5.564 +(* a few lemmas first *)
   5.565 +
   5.566 +Goal "{n::nat. x = real_of_posnat n} = {} | \
   5.567 +\     (EX y. {n::nat. x = real_of_posnat n} = {y})";
   5.568 +by (auto_tac (claset() addDs [inj_real_of_posnat RS injD],simpset()));
   5.569 +qed "lemma_omega_empty_singleton_disj";
   5.570 +
   5.571 +Goal "finite {n::nat. x = real_of_posnat n}";
   5.572 +by (cut_inst_tac [("x","x")] lemma_omega_empty_singleton_disj 1);
   5.573 +by Auto_tac;
   5.574 +qed "lemma_finite_omega_set";
   5.575 +
   5.576 +Goalw [omega_def,hypreal_of_real_def] 
   5.577 +      "~ (EX x. hypreal_of_real x = whr)";
   5.578 +by (auto_tac (claset(),simpset() addsimps [lemma_finite_omega_set 
   5.579 +    RS FreeUltrafilterNat_finite]));
   5.580 +qed "not_ex_hypreal_of_real_eq_omega";
   5.581 +
   5.582 +Goal "hypreal_of_real x ~= whr";
   5.583 +by (cut_facts_tac [not_ex_hypreal_of_real_eq_omega] 1);
   5.584 +by Auto_tac;
   5.585 +qed "hypreal_of_real_not_eq_omega";
   5.586 +
   5.587 +(* existence of infinitesimal number also not *)
   5.588 +(* corresponding to any real number *)
   5.589 +
   5.590 +Goal "{n::nat. x = rinv(real_of_posnat n)} = {} | \
   5.591 +\     (EX y. {n::nat. x = rinv(real_of_posnat n)} = {y})";
   5.592 +by (Step_tac 1 THEN Step_tac 1);
   5.593 +by (auto_tac (claset() addIs [real_of_posnat_rinv_inj],simpset()));
   5.594 +qed "lemma_epsilon_empty_singleton_disj";
   5.595 +
   5.596 +Goal "finite {n::nat. x = rinv(real_of_posnat n)}";
   5.597 +by (cut_inst_tac [("x","x")] lemma_epsilon_empty_singleton_disj 1);
   5.598 +by Auto_tac;
   5.599 +qed "lemma_finite_epsilon_set";
   5.600 +
   5.601 +Goalw [epsilon_def,hypreal_of_real_def] 
   5.602 +      "~ (EX x. hypreal_of_real x = ehr)";
   5.603 +by (auto_tac (claset(),simpset() addsimps [lemma_finite_epsilon_set 
   5.604 +    RS FreeUltrafilterNat_finite]));
   5.605 +qed "not_ex_hypreal_of_real_eq_epsilon";
   5.606 +
   5.607 +Goal "hypreal_of_real x ~= ehr";
   5.608 +by (cut_facts_tac [not_ex_hypreal_of_real_eq_epsilon] 1);
   5.609 +by Auto_tac;
   5.610 +qed "hypreal_of_real_not_eq_epsilon";
   5.611 +
   5.612 +Goalw [epsilon_def,hypreal_zero_def] "ehr ~= 0";
   5.613 +by (auto_tac (claset(),
   5.614 +     simpset() addsimps [rename_numerals real_of_posnat_rinv_not_zero]));
   5.615 +qed "hypreal_epsilon_not_zero";
   5.616 +
   5.617 +Addsimps [rename_numerals real_of_posnat_not_eq_zero];
   5.618 +Goalw [omega_def,hypreal_zero_def] "whr ~= 0";
   5.619 +by (Simp_tac 1);
   5.620 +qed "hypreal_omega_not_zero";
   5.621 +
   5.622 +Goal "ehr = hrinv(whr)";
   5.623 +by (asm_full_simp_tac (simpset() addsimps 
   5.624 +    [hypreal_hrinv,omega_def,epsilon_def]) 1);
   5.625 +qed "hypreal_epsilon_hrinv_omega";
   5.626 +
   5.627 +(*----------------------------------------------------------------
   5.628 +     Another embedding of the naturals in the 
   5.629 +    hyperreals (see hypreal_of_posnat)
   5.630 + ----------------------------------------------------------------*)
   5.631 +Goalw [hypreal_of_nat_def] "hypreal_of_nat 0 = 0";
   5.632 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_one]) 1);
   5.633 +qed "hypreal_of_nat_zero";
   5.634 +
   5.635 +Goalw [hypreal_of_nat_def] "hypreal_of_nat 1 = 1hr";
   5.636 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_two,
   5.637 +    hypreal_add_assoc]) 1);
   5.638 +qed "hypreal_of_nat_one";
   5.639 +
   5.640 +Goalw [hypreal_of_nat_def]
   5.641 +      "hypreal_of_nat n1 + hypreal_of_nat n2 = \
   5.642 +\      hypreal_of_nat (n1 + n2)";
   5.643 +by (full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
   5.644 +by (simp_tac (simpset() addsimps [hypreal_of_posnat_add,
   5.645 +    hypreal_add_assoc RS sym]) 1);
   5.646 +qed "hypreal_of_nat_add";
   5.647 +
   5.648 +Goal "hypreal_of_nat 2 = 1hr + 1hr";
   5.649 +by (simp_tac (simpset() addsimps [hypreal_of_nat_one 
   5.650 +    RS sym,hypreal_of_nat_add]) 1);
   5.651 +qed "hypreal_of_nat_two";
   5.652 +
   5.653 +Goalw [hypreal_of_nat_def] 
   5.654 +      "(n < m) = (hypreal_of_nat n < hypreal_of_nat m)";
   5.655 +by (auto_tac (claset() addIs [hypreal_add_less_mono1],simpset()));
   5.656 +qed "hypreal_of_nat_less_iff";
   5.657 +Addsimps [hypreal_of_nat_less_iff RS sym];
   5.658 +
   5.659 +(*------------------------------------------------------------*)
   5.660 +(* naturals embedded in hyperreals                            *)
   5.661 +(* is a hyperreal c.f. NS extension                           *)
   5.662 +(*------------------------------------------------------------*)
   5.663 +
   5.664 +Goalw [hypreal_of_nat_def,real_of_nat_def] 
   5.665 +      "hypreal_of_nat  m = Abs_hypreal(hyprel^^{%n. real_of_nat m})";
   5.666 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_def,
   5.667 +    hypreal_of_real_of_posnat,hypreal_minus,hypreal_one_def,hypreal_add]));
   5.668 +qed "hypreal_of_nat_iff";
   5.669 +
   5.670 +Goal "inj hypreal_of_nat";
   5.671 +by (rtac injI 1);
   5.672 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_P],
   5.673 +        simpset() addsimps [split_if_mem1, hypreal_of_nat_iff,
   5.674 +        real_add_right_cancel,inj_real_of_nat RS injD]));
   5.675 +qed "inj_hypreal_of_nat";
   5.676 +
   5.677 +Goalw [hypreal_of_nat_def,hypreal_of_real_def,hypreal_of_posnat_def,
   5.678 +       real_of_posnat_def,hypreal_one_def,real_of_nat_def] 
   5.679 +       "hypreal_of_nat n = hypreal_of_real (real_of_nat n)";
   5.680 +by (simp_tac (simpset() addsimps [hypreal_add,hypreal_minus]) 1);
   5.681 +qed "hypreal_of_nat_real_of_nat";
   5.682 +
   5.683 +Goal "hypreal_of_posnat (Suc n) = hypreal_of_posnat n + 1hr";
   5.684 +by (stac (hypreal_of_posnat_add_one RS sym) 1);
   5.685 +by (Simp_tac 1);
   5.686 +qed "hypreal_of_posnat_Suc";
   5.687 +
   5.688 +Goalw [hypreal_of_nat_def] 
   5.689 +      "hypreal_of_nat (Suc n) = hypreal_of_nat n + 1hr";
   5.690 +by (simp_tac (simpset() addsimps [hypreal_of_posnat_Suc] @ hypreal_add_ac) 1);
   5.691 +qed "hypreal_of_nat_Suc";
   5.692 +
   5.693 +Goal "0 < r ==> 0 < r*hrinv(1hr+1hr)";
   5.694 +by (dtac (hypreal_zero_less_two RS hypreal_hrinv_gt_zero 
   5.695 +          RS hypreal_mult_less_mono1) 1);
   5.696 +by Auto_tac;
   5.697 +qed "hypreal_half_gt_zero";
   5.698 +
   5.699 +(* this proof is so much simpler than one for reals!! *)
   5.700 +Goal "[| 0 < r; r < x |] ==> hrinv x < hrinv r";
   5.701 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   5.702 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   5.703 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrinv,
   5.704 +    hypreal_less,hypreal_zero_def]));
   5.705 +by (ultra_tac (claset() addIs [real_rinv_less_swap],simpset()) 1);
   5.706 +qed "hypreal_hrinv_less_swap";
   5.707 +
   5.708 +Goal "[| 0 < r; 0 < x|] ==> (r < x) = (hrinv x < hrinv r)";
   5.709 +by (auto_tac (claset() addIs [hypreal_hrinv_less_swap],simpset()));
   5.710 +by (res_inst_tac [("t","r")] (hypreal_hrinv_hrinv RS subst) 1);
   5.711 +by (etac (hypreal_not_refl2 RS not_sym) 1);
   5.712 +by (res_inst_tac [("t","x")] (hypreal_hrinv_hrinv RS subst) 1);
   5.713 +by (etac (hypreal_not_refl2 RS not_sym) 1);
   5.714 +by (auto_tac (claset() addIs [hypreal_hrinv_less_swap],
   5.715 +    simpset() addsimps [hypreal_hrinv_gt_zero]));
   5.716 +qed "hypreal_hrinv_less_iff";
   5.717 +
   5.718 +Goal "[| 0 < z; x < y |] ==> x*hrinv(z) < y*hrinv(z)";
   5.719 +by (blast_tac (claset() addSIs [hypreal_mult_less_mono1,
   5.720 +    hypreal_hrinv_gt_zero]) 1);
   5.721 +qed "hypreal_mult_hrinv_less_mono1";
   5.722 +
   5.723 +Goal "[| 0 < z; x < y |] ==> hrinv(z)*x < hrinv(z)*y";
   5.724 +by (blast_tac (claset() addSIs [hypreal_mult_less_mono2,
   5.725 +    hypreal_hrinv_gt_zero]) 1);
   5.726 +qed "hypreal_mult_hrinv_less_mono2";
   5.727 +
   5.728 +Goal "[| (0::hypreal) < z; x*z < y*z |] ==> x < y";
   5.729 +by (forw_inst_tac [("x","x*z")] hypreal_mult_hrinv_less_mono1 1);
   5.730 +by (dtac (hypreal_not_refl2 RS not_sym) 2);
   5.731 +by (auto_tac (claset() addSDs [hypreal_mult_hrinv],
   5.732 +              simpset() addsimps hypreal_mult_ac));
   5.733 +qed "hypreal_less_mult_right_cancel";
   5.734 +
   5.735 +Goal "[| (0::hypreal) < z; z*x < z*y |] ==> x < y";
   5.736 +by (auto_tac (claset() addIs [hypreal_less_mult_right_cancel],
   5.737 +    simpset() addsimps [hypreal_mult_commute]));
   5.738 +qed "hypreal_less_mult_left_cancel";
   5.739 +
   5.740 +Goal "[| 0 < r; (0::hypreal) < ra; \
   5.741 +\                 r < x; ra < y |] \
   5.742 +\              ==> r*ra < x*y";
   5.743 +by (forw_inst_tac [("R2.0","r")] hypreal_less_trans 1);
   5.744 +by (dres_inst_tac [("z","ra"),("x","r")] hypreal_mult_less_mono1 2);
   5.745 +by (dres_inst_tac [("z","x"),("x","ra")] hypreal_mult_less_mono2 3);
   5.746 +by (auto_tac (claset() addIs [hypreal_less_trans],simpset()));
   5.747 +qed "hypreal_mult_less_gt_zero"; 
   5.748 +
   5.749 +Goal "[| 0 < r; (0::hypreal) < ra; \
   5.750 +\                 r <= x; ra <= y |] \
   5.751 +\              ==> r*ra <= x*y";
   5.752 +by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
   5.753 +by (rtac hypreal_less_or_eq_imp_le 1);
   5.754 +by (auto_tac (claset() addIs [hypreal_mult_less_mono1,
   5.755 +    hypreal_mult_less_mono2,hypreal_mult_less_gt_zero],
   5.756 +    simpset()));
   5.757 +qed "hypreal_mult_le_ge_zero"; 
   5.758 +
   5.759 +(*----------------------------------------------------------------------------
   5.760 +     Some convenient biconditionals for products of signs 
   5.761 + ----------------------------------------------------------------------------*)
   5.762 +
   5.763 +Goal "((0::hypreal) < x*y) = (0 < x & 0 < y | x < 0 & y < 0)";
   5.764 + by (auto_tac (claset(), simpset() addsimps [order_le_less, 
   5.765 +    linorder_not_less, hypreal_mult_order, hypreal_mult_less_zero1]));
   5.766 +by (ALLGOALS (rtac ccontr)); 
   5.767 +by (auto_tac (claset(), simpset() addsimps 
   5.768 +    [order_le_less, linorder_not_less]));
   5.769 +by (ALLGOALS (etac rev_mp)); 
   5.770 +by (ALLGOALS (dtac hypreal_mult_less_zero THEN' assume_tac));
   5.771 +by (auto_tac (claset() addDs [order_less_not_sym], 
   5.772 +              simpset() addsimps [hypreal_mult_commute]));  
   5.773 +qed "hypreal_zero_less_mult_iff";
   5.774 +
   5.775 +Goal "((0::hypreal) <= x*y) = (0 <= x & 0 <= y | x <= 0 & y <= 0)";
   5.776 +by (auto_tac (claset() addDs [sym RS hypreal_mult_zero_disj],
   5.777 +    simpset() addsimps [order_le_less,
   5.778 +    linorder_not_less,hypreal_zero_less_mult_iff]));
   5.779 +qed "hypreal_zero_le_mult_iff";
   5.780 +
   5.781 +Goal "(x*y < (0::hypreal)) = (0 < x & y < 0 | x < 0 & 0 < y)";
   5.782 +by (auto_tac (claset(), 
   5.783 +              simpset() addsimps [hypreal_zero_le_mult_iff, 
   5.784 +                                  linorder_not_le RS sym]));
   5.785 +by (auto_tac (claset() addDs [order_less_not_sym],  
   5.786 +              simpset() addsimps [linorder_not_le]));
   5.787 +qed "hypreal_mult_less_zero_iff";
   5.788 +
   5.789 +Goal "(x*y <= (0::hypreal)) = (0 <= x & y <= 0 | x <= 0 & 0 <= y)";
   5.790 +by (auto_tac (claset() addDs [order_less_not_sym], 
   5.791 +              simpset() addsimps [hypreal_zero_less_mult_iff, 
   5.792 +                                  linorder_not_less RS sym]));
   5.793 +qed "hypreal_mult_le_zero_iff";
   5.794 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/HOL/Real/Hyperreal/HyperOrd.thy	Thu Sep 21 12:17:11 2000 +0200
     6.3 @@ -0,0 +1,15 @@
     6.4 +(*  Title:	 Real/Hyperreal/HyperOrd.thy
     6.5 +    Author:      Jacques D. Fleuriot
     6.6 +    Copyright:   2000 University of Edinburgh
     6.7 +    Description: Type "hypreal" is a linear order and also 
     6.8 +                 satisfies plus_ac0: + is an AC-operator with zero
     6.9 +*)
    6.10 +
    6.11 +HyperOrd = HyperDef +
    6.12 +
    6.13 +instance hypreal :: order (hypreal_le_refl,hypreal_le_trans,hypreal_le_anti_sym,hypreal_less_le)
    6.14 +instance hypreal :: linorder (hypreal_le_linear)
    6.15 +
    6.16 +instance hypreal :: plus_ac0(hypreal_add_commute,hypreal_add_assoc,hypreal_add_zero_left)
    6.17 +
    6.18 +end
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/HOL/Real/Hyperreal/HyperPow.ML	Thu Sep 21 12:17:11 2000 +0200
     7.3 @@ -0,0 +1,585 @@
     7.4 +(*  Title       : HyperPow.ML
     7.5 +    Author      : Jacques D. Fleuriot  
     7.6 +    Copyright   : 1998  University of Cambridge
     7.7 +    Description : Natural Powers of hyperreals theory
     7.8 +
     7.9 +*)
    7.10 +
    7.11 +Goal "(0::hypreal) ^ (Suc n) = 0";
    7.12 +by (Auto_tac);
    7.13 +qed "hrealpow_zero";
    7.14 +Addsimps [hrealpow_zero];
    7.15 +
    7.16 +Goal "r ~= (0::hypreal) --> r ^ n ~= 0";
    7.17 +by (induct_tac "n" 1);
    7.18 +by (auto_tac (claset() addIs [hypreal_mult_not_0E],
    7.19 +    simpset() addsimps [hypreal_zero_not_eq_one RS not_sym]));
    7.20 +qed_spec_mp "hrealpow_not_zero";
    7.21 +
    7.22 +Goal "r ~= (0::hypreal) --> hrinv(r ^ n) = (hrinv r) ^ n";
    7.23 +by (induct_tac "n" 1);
    7.24 +by (Auto_tac);
    7.25 +by (forw_inst_tac [("n","n")] hrealpow_not_zero 1);
    7.26 +by (auto_tac (claset() addDs [hrinv_mult_eq],
    7.27 +    simpset()));
    7.28 +qed_spec_mp "hrealpow_hrinv";
    7.29 +
    7.30 +Goal "abs (r::hypreal) ^ n = abs (r ^ n)";
    7.31 +by (induct_tac "n" 1);
    7.32 +by (auto_tac (claset(),simpset() addsimps [hrabs_mult,hrabs_one]));
    7.33 +qed "hrealpow_hrabs";
    7.34 +
    7.35 +Goal "(r::hypreal) ^ (n + m) = (r ^ n) * (r ^ m)";
    7.36 +by (induct_tac "n" 1);
    7.37 +by (auto_tac (claset(),simpset() addsimps hypreal_mult_ac));
    7.38 +qed "hrealpow_add";
    7.39 +
    7.40 +Goal "(r::hypreal) ^ 1 = r";
    7.41 +by (Simp_tac 1);
    7.42 +qed "hrealpow_one";
    7.43 +Addsimps [hrealpow_one];
    7.44 +
    7.45 +Goal "(r::hypreal) ^ 2 = r * r";
    7.46 +by (Simp_tac 1);
    7.47 +qed "hrealpow_two";
    7.48 +
    7.49 +Goal "(0::hypreal) < r --> 0 <= r ^ n";
    7.50 +by (induct_tac "n" 1);
    7.51 +by (auto_tac (claset() addDs [hypreal_less_imp_le] 
    7.52 +    addIs [hypreal_le_mult_order],simpset() addsimps 
    7.53 +    [hypreal_zero_less_one RS hypreal_less_imp_le]));
    7.54 +qed_spec_mp "hrealpow_ge_zero";
    7.55 +
    7.56 +Goal "(0::hypreal) < r --> 0 < r ^ n";
    7.57 +by (induct_tac "n" 1);
    7.58 +by (auto_tac (claset() addIs [hypreal_mult_order],
    7.59 +    simpset() addsimps [hypreal_zero_less_one]));
    7.60 +qed_spec_mp "hrealpow_gt_zero";
    7.61 +
    7.62 +Goal "(0::hypreal) <= r --> 0 <= r ^ n";
    7.63 +by (induct_tac "n" 1);
    7.64 +by (auto_tac (claset() addIs [hypreal_le_mult_order],simpset() 
    7.65 +    addsimps [hypreal_zero_less_one RS hypreal_less_imp_le]));
    7.66 +qed_spec_mp "hrealpow_ge_zero2";
    7.67 +
    7.68 +Goal "(0::hypreal) < x & x <= y --> x ^ n <= y ^ n";
    7.69 +by (induct_tac "n" 1);
    7.70 +by (auto_tac (claset() addSIs [hypreal_mult_le_mono],
    7.71 +    simpset() addsimps [hypreal_le_refl]));
    7.72 +by (asm_simp_tac (simpset() addsimps [hrealpow_ge_zero]) 1);
    7.73 +qed_spec_mp "hrealpow_le";
    7.74 +
    7.75 +Goal "(0::hypreal) < x & x < y & 0 < n --> x ^ n < y ^ n";
    7.76 +by (induct_tac "n" 1);
    7.77 +by (auto_tac (claset() addIs [hypreal_mult_less_mono,gr0I] 
    7.78 +    addDs [hrealpow_gt_zero],simpset()));
    7.79 +qed "hrealpow_less";
    7.80 +
    7.81 +Goal "1hr ^ n = 1hr";
    7.82 +by (induct_tac "n" 1);
    7.83 +by (Auto_tac);
    7.84 +qed "hrealpow_eq_one";
    7.85 +Addsimps [hrealpow_eq_one];
    7.86 +
    7.87 +Goal "abs(-(1hr ^ n)) = 1hr";
    7.88 +by (simp_tac (simpset() addsimps 
    7.89 +    [hrabs_minus_cancel,hrabs_one]) 1);
    7.90 +qed "hrabs_minus_hrealpow_one";
    7.91 +Addsimps [hrabs_minus_hrealpow_one];
    7.92 +
    7.93 +Goal "abs((-1hr) ^ n) = 1hr";
    7.94 +by (induct_tac "n" 1);
    7.95 +by (auto_tac (claset(),simpset() addsimps [hrabs_mult,
    7.96 +         hrabs_minus_cancel,hrabs_one]));
    7.97 +qed "hrabs_hrealpow_minus_one";
    7.98 +Addsimps [hrabs_hrealpow_minus_one];
    7.99 +
   7.100 +Goal "((r::hypreal) * s) ^ n = (r ^ n) * (s ^ n)";
   7.101 +by (induct_tac "n" 1);
   7.102 +by (auto_tac (claset(),simpset() addsimps hypreal_mult_ac));
   7.103 +qed "hrealpow_mult";
   7.104 +
   7.105 +Goal "(0::hypreal) <= r ^ 2";
   7.106 +by (simp_tac (simpset() addsimps [hrealpow_two]) 1);
   7.107 +qed "hrealpow_two_le";
   7.108 +Addsimps [hrealpow_two_le];
   7.109 +
   7.110 +Goal "(0::hypreal) <= u ^ 2 + v ^ 2";
   7.111 +by (auto_tac (claset() addIs [hypreal_le_add_order],simpset()));
   7.112 +qed "hrealpow_two_le_add_order";
   7.113 +Addsimps [hrealpow_two_le_add_order];
   7.114 +
   7.115 +Goal "(0::hypreal) <= u ^ 2 + v ^ 2 + w ^ 2";
   7.116 +by (auto_tac (claset() addSIs [hypreal_le_add_order],simpset()));
   7.117 +qed "hrealpow_two_le_add_order2";
   7.118 +Addsimps [hrealpow_two_le_add_order2];
   7.119 +
   7.120 +(* See HYPER.ML *)
   7.121 +Goal "(x ^ 2 + y ^ 2 + z ^ 2 = (0::hypreal)) = \ 
   7.122 +\               (x = 0 & y = 0 & z = 0)";
   7.123 +by (simp_tac (simpset() addsimps [hrealpow_two]) 1);
   7.124 +qed "hrealpow_three_squares_add_zero_iff";
   7.125 +Addsimps [hrealpow_three_squares_add_zero_iff];
   7.126 +
   7.127 +Goal "abs(x ^ 2) = (x::hypreal) ^ 2";
   7.128 +by (simp_tac (simpset() addsimps [hrabs_eqI1]) 1);
   7.129 +qed "hrabs_hrealpow_two";
   7.130 +Addsimps [hrabs_hrealpow_two];
   7.131 +
   7.132 +Goal "abs(x) ^ 2 = (x::hypreal) ^ 2";
   7.133 +by (simp_tac (simpset() addsimps [hrealpow_hrabs,
   7.134 +    hrabs_eqI1] delsimps [hpowr_Suc]) 1);
   7.135 +qed "hrealpow_two_hrabs";
   7.136 +Addsimps [hrealpow_two_hrabs];
   7.137 +
   7.138 +Goal "!!r. 1hr < r ==> 1hr < r ^ 2";
   7.139 +by (auto_tac (claset(),simpset() addsimps [hrealpow_two]));
   7.140 +by (cut_facts_tac [hypreal_zero_less_one] 1);
   7.141 +by (forw_inst_tac [("R1.0","0")] hypreal_less_trans 1);
   7.142 +by (assume_tac 1);
   7.143 +by (dres_inst_tac [("z","r"),("x","1hr")] hypreal_mult_less_mono1 1);
   7.144 +by (auto_tac (claset() addIs [hypreal_less_trans],simpset()));
   7.145 +qed "hrealpow_two_gt_one";
   7.146 +
   7.147 +Goal "!!r. 1hr <= r ==> 1hr <= r ^ 2";
   7.148 +by (etac (hypreal_le_imp_less_or_eq RS disjE) 1);
   7.149 +by (etac (hrealpow_two_gt_one RS hypreal_less_imp_le) 1);
   7.150 +by (asm_simp_tac (simpset() addsimps [hypreal_le_refl]) 1);
   7.151 +qed "hrealpow_two_ge_one";
   7.152 +
   7.153 +Goal "!!r. (0::hypreal) < r ==> 0 < r ^ Suc n";
   7.154 +by (forw_inst_tac [("n","n")] hrealpow_ge_zero 1);
   7.155 +by (forw_inst_tac [("n1","n")]
   7.156 +    ((hypreal_not_refl2 RS not_sym) RS hrealpow_not_zero RS not_sym) 1);
   7.157 +by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq]
   7.158 +     addIs [hypreal_mult_order],simpset()));
   7.159 +qed "hrealpow_Suc_gt_zero";
   7.160 +
   7.161 +Goal "!!r. (0::hypreal) <= r ==> 0 <= r ^ Suc n";
   7.162 +by (etac (hypreal_le_imp_less_or_eq RS disjE) 1);
   7.163 +by (etac (hrealpow_ge_zero) 1);
   7.164 +by (asm_simp_tac (simpset() addsimps [hypreal_le_refl]) 1);
   7.165 +qed "hrealpow_Suc_ge_zero";
   7.166 +
   7.167 +Goal "1hr <= (1hr +1hr) ^ n";
   7.168 +by (res_inst_tac [("j","1hr ^ n")] hypreal_le_trans 1);
   7.169 +by (rtac hrealpow_le 2);
   7.170 +by (auto_tac (claset() addIs [hypreal_less_imp_le],
   7.171 +    simpset() addsimps [hypreal_zero_less_one,
   7.172 +    hypreal_one_less_two,hypreal_le_refl]));
   7.173 +qed "two_hrealpow_ge_one";
   7.174 +
   7.175 +Goal "hypreal_of_nat n < (1hr + 1hr) ^ n";
   7.176 +by (induct_tac "n" 1);
   7.177 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_nat_Suc,hypreal_of_nat_zero,
   7.178 +    hypreal_zero_less_one,hypreal_add_mult_distrib,hypreal_of_nat_one]));
   7.179 +by (blast_tac (claset() addSIs [hypreal_add_less_le_mono,
   7.180 +    two_hrealpow_ge_one]) 1);
   7.181 +qed "two_hrealpow_gt";
   7.182 +Addsimps [two_hrealpow_gt,two_hrealpow_ge_one];
   7.183 +
   7.184 +Goal "(-1hr) ^ (2*n) = 1hr";
   7.185 +by (induct_tac "n" 1);
   7.186 +by (Auto_tac);
   7.187 +qed "hrealpow_minus_one";
   7.188 +
   7.189 +Goal "(-1hr) ^ (n + n) = 1hr";
   7.190 +by (induct_tac "n" 1);
   7.191 +by (Auto_tac);
   7.192 +qed "hrealpow_minus_one2";
   7.193 +Addsimps [hrealpow_minus_one2];
   7.194 +
   7.195 +Goal "(-(x::hypreal)) ^ 2 = x ^ 2";
   7.196 +by (Auto_tac);
   7.197 +qed "hrealpow_minus_two";
   7.198 +Addsimps [hrealpow_minus_two];
   7.199 +
   7.200 +Goal "(0::hypreal) < r & r < 1hr --> r ^ Suc n < r ^ n";
   7.201 +by (induct_tac "n" 1);
   7.202 +by (auto_tac (claset(),simpset() addsimps 
   7.203 +        [hypreal_mult_less_mono2]));
   7.204 +qed_spec_mp "hrealpow_Suc_less";
   7.205 +
   7.206 +Goal "(0::hypreal) <= r & r < 1hr --> r ^ Suc n <= r ^ n";
   7.207 +by (induct_tac "n" 1);
   7.208 +by (auto_tac (claset() addIs [hypreal_less_imp_le] addSDs
   7.209 +     [hypreal_le_imp_less_or_eq,hrealpow_Suc_less],simpset()
   7.210 +     addsimps [hypreal_le_refl,hypreal_mult_less_mono2]));
   7.211 +qed_spec_mp "hrealpow_Suc_le";
   7.212 +
   7.213 +(* a few more theorems needed here *)
   7.214 +Goal "1hr <= r --> r ^ n <= r ^ Suc n";
   7.215 +by (induct_tac "n" 1);
   7.216 +by (auto_tac (claset() addSIs [hypreal_mult_le_le_mono1],simpset()));
   7.217 +by (rtac ccontr 1 THEN dtac not_hypreal_leE 1);
   7.218 +by (dtac hypreal_le_less_trans 1 THEN assume_tac 1);
   7.219 +by (etac (hypreal_zero_less_one RS hypreal_less_asym) 1);
   7.220 +qed "hrealpow_less_Suc";
   7.221 +
   7.222 +Goal "Abs_hypreal(hyprel^^{%n. X n}) ^ m = Abs_hypreal(hyprel^^{%n. (X n) ^ m})";
   7.223 +by (nat_ind_tac "m" 1);
   7.224 +by (auto_tac (claset(),simpset() addsimps 
   7.225 +    [hypreal_one_def,hypreal_mult]));
   7.226 +qed "hrealpow";
   7.227 +
   7.228 +Goal "(x + (y::hypreal)) ^ 2 = \
   7.229 +\     x ^ 2 + y ^ 2 + (hypreal_of_nat 2)*x*y";
   7.230 +by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib2,
   7.231 +    hypreal_add_mult_distrib,hypreal_of_nat_two] 
   7.232 +    @ hypreal_add_ac @ hypreal_mult_ac) 1);
   7.233 +qed "hrealpow_sum_square_expand";
   7.234 +
   7.235 +(*---------------------------------------------------------------
   7.236 +   we'll prove the following theorem by going down to the
   7.237 +   level of the ultrafilter and relying on the analogous
   7.238 +   property for the real rather than prove it directly 
   7.239 +   using induction: proof is much simpler this way!
   7.240 + ---------------------------------------------------------------*)
   7.241 +Goalw [hypreal_zero_def] 
   7.242 +  "[|(0::hypreal) <= x;0 <= y;x ^ Suc n <= y ^ Suc n |] ==> x <= y";
   7.243 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   7.244 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   7.245 +by (auto_tac (claset(),simpset() addsimps 
   7.246 +    [hrealpow,hypreal_le,hypreal_mult]));
   7.247 +by (ultra_tac (claset() addIs [realpow_increasing],simpset()) 1);
   7.248 +qed "hrealpow_increasing";
   7.249 +
   7.250 +goalw HyperPow.thy [hypreal_zero_def] 
   7.251 +  "!!x. [|(0::hypreal) <= x;0 <= y;x ^ Suc n = y ^ Suc n |] ==> x = y";
   7.252 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   7.253 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   7.254 +by (auto_tac (claset(),simpset() addsimps 
   7.255 +    [hrealpow,hypreal_mult,hypreal_le]));
   7.256 +by (ultra_tac (claset() addIs [realpow_Suc_cancel_eq],
   7.257 +    simpset()) 1);
   7.258 +qed "hrealpow_Suc_cancel_eq";
   7.259 +
   7.260 +Goal "x : HFinite --> x ^ n : HFinite";
   7.261 +by (induct_tac "n" 1);
   7.262 +by (auto_tac (claset() addIs [HFinite_mult],simpset()));
   7.263 +qed_spec_mp "hrealpow_HFinite";
   7.264 +
   7.265 +(*---------------------------------------------------------------
   7.266 +                  Hypernaturals Powers
   7.267 + --------------------------------------------------------------*)
   7.268 +Goalw [congruent_def]
   7.269 +     "congruent hyprel \
   7.270 +\    (%X Y. hyprel^^{%n. ((X::nat=>real) n ^ (Y::nat=>nat) n)})";
   7.271 +by (safe_tac (claset() addSIs [ext]));
   7.272 +by (ALLGOALS(Fuf_tac));
   7.273 +qed "hyperpow_congruent";
   7.274 +
   7.275 +Goalw [hyperpow_def]
   7.276 +  "Abs_hypreal(hyprel^^{%n. X n}) pow Abs_hypnat(hypnatrel^^{%n. Y n}) = \
   7.277 +\  Abs_hypreal(hyprel^^{%n. X n ^ Y n})";
   7.278 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
   7.279 +by (auto_tac (claset() addSIs [lemma_hyprel_refl,bexI],
   7.280 +    simpset() addsimps [hyprel_in_hypreal RS 
   7.281 +    Abs_hypreal_inverse,equiv_hyprel,hyperpow_congruent]));
   7.282 +by (Fuf_tac 1);
   7.283 +qed "hyperpow";
   7.284 +
   7.285 +Goalw [hypreal_zero_def,hypnat_one_def]
   7.286 +      "(0::hypreal) pow (n + 1hn) = 0";
   7.287 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.288 +by (auto_tac (claset(),simpset() addsimps 
   7.289 +    [hyperpow,hypnat_add]));
   7.290 +qed "hyperpow_zero";
   7.291 +Addsimps [hyperpow_zero];
   7.292 +
   7.293 +Goalw [hypreal_zero_def]
   7.294 +      "r ~= (0::hypreal) --> r pow n ~= 0";
   7.295 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.296 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.297 +by (auto_tac (claset(),simpset() addsimps [hyperpow]));
   7.298 +by (dtac FreeUltrafilterNat_Compl_mem 1);
   7.299 +by (fuf_empty_tac (claset() addIs [realpow_not_zero RS notE],
   7.300 +    simpset()) 1);
   7.301 +qed_spec_mp "hyperpow_not_zero";
   7.302 +
   7.303 +Goalw [hypreal_zero_def] 
   7.304 +      "r ~= (0::hypreal) --> hrinv(r pow n) = (hrinv r) pow n";
   7.305 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.306 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.307 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
   7.308 +    simpset() addsimps [hypreal_hrinv,hyperpow]));
   7.309 +by (rtac FreeUltrafilterNat_subset 1);
   7.310 +by (auto_tac (claset() addDs [realpow_not_zero] 
   7.311 +    addIs [realpow_rinv],simpset()));
   7.312 +qed "hyperpow_hrinv";
   7.313 +
   7.314 +Goal "abs r pow n = abs (r pow n)";
   7.315 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.316 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.317 +by (auto_tac (claset(),simpset() addsimps [hypreal_hrabs,
   7.318 +    hyperpow,realpow_abs]));
   7.319 +qed "hyperpow_hrabs";
   7.320 +
   7.321 +Goal "r pow (n + m) = (r pow n) * (r pow m)";
   7.322 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.323 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   7.324 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.325 +by (auto_tac (claset(),simpset() addsimps [hyperpow,hypnat_add,
   7.326 +     hypreal_mult,realpow_add]));
   7.327 +qed "hyperpow_add";
   7.328 +
   7.329 +Goalw [hypnat_one_def] "r pow 1hn = r";
   7.330 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.331 +by (auto_tac (claset(),simpset() addsimps [hyperpow]));
   7.332 +qed "hyperpow_one";
   7.333 +Addsimps [hyperpow_one];
   7.334 +
   7.335 +Goalw [hypnat_one_def] 
   7.336 +      "r pow (1hn + 1hn) = r * r";
   7.337 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.338 +by (auto_tac (claset(),simpset() addsimps [hyperpow,hypnat_add,
   7.339 +     hypreal_mult,realpow_two]));
   7.340 +qed "hyperpow_two";
   7.341 +
   7.342 +Goalw [hypreal_zero_def]
   7.343 +      "(0::hypreal) < r --> 0 < r pow n";
   7.344 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.345 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.346 +by (auto_tac (claset() addSEs [FreeUltrafilterNat_subset,
   7.347 +    realpow_gt_zero],simpset() addsimps [hyperpow,hypreal_less,
   7.348 +    hypreal_le]));
   7.349 +qed_spec_mp "hyperpow_gt_zero";
   7.350 +
   7.351 +Goal "(0::hypreal) < r --> 0 <= r pow n";
   7.352 +by (blast_tac (claset() addSIs [hyperpow_gt_zero,
   7.353 +    hypreal_less_imp_le]) 1);
   7.354 +qed_spec_mp "hyperpow_ge_zero";
   7.355 +
   7.356 +Goalw [hypreal_zero_def]
   7.357 +      "(0::hypreal) <= r --> 0 <= r pow n";
   7.358 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.359 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.360 +by (auto_tac (claset() addSEs [FreeUltrafilterNat_subset,
   7.361 +    realpow_ge_zero2],simpset() addsimps [hyperpow,hypreal_le]));
   7.362 +qed "hyperpow_ge_zero2";
   7.363 +
   7.364 +Goalw [hypreal_zero_def]
   7.365 +      "(0::hypreal) < x & x <= y --> x pow n <= y pow n";
   7.366 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.367 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   7.368 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   7.369 +by (auto_tac (claset() addIs [realpow_le,
   7.370 +    (FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset)],
   7.371 +    simpset() addsimps [hyperpow,hypreal_le,hypreal_less]));
   7.372 +qed_spec_mp "hyperpow_le";
   7.373 +
   7.374 +Goalw [hypreal_one_def] "1hr pow n = 1hr";
   7.375 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.376 +by (auto_tac (claset(),simpset() addsimps [hyperpow]));
   7.377 +qed "hyperpow_eq_one";
   7.378 +Addsimps [hyperpow_eq_one];
   7.379 +
   7.380 +Goalw [hypreal_one_def]
   7.381 +      "abs(-(1hr pow n)) = 1hr";
   7.382 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.383 +by (auto_tac (claset(),simpset() addsimps [abs_one,
   7.384 +    hrabs_minus_cancel,hyperpow,hypreal_hrabs]));
   7.385 +qed "hrabs_minus_hyperpow_one";
   7.386 +Addsimps [hrabs_minus_hyperpow_one];
   7.387 +
   7.388 +Goalw [hypreal_one_def]
   7.389 +      "abs((-1hr) pow n) = 1hr";
   7.390 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.391 +by (auto_tac (claset(),simpset() addsimps 
   7.392 +    [hyperpow,hypreal_minus,hypreal_hrabs]));
   7.393 +qed "hrabs_hyperpow_minus_one";
   7.394 +Addsimps [hrabs_hyperpow_minus_one];
   7.395 +
   7.396 +Goal "(r * s) pow n = (r pow n) * (s pow n)";
   7.397 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.398 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.399 +by (res_inst_tac [("z","s")] eq_Abs_hypreal 1);
   7.400 +by (auto_tac (claset(),simpset() addsimps [hyperpow,
   7.401 +    hypreal_mult,realpow_mult]));
   7.402 +qed "hyperpow_mult";
   7.403 +
   7.404 +Goal "(0::hypreal) <= r pow (1hn + 1hn)";
   7.405 +by (simp_tac (simpset() addsimps [hyperpow_two]) 1);
   7.406 +qed "hyperpow_two_le";
   7.407 +Addsimps [hyperpow_two_le];
   7.408 +
   7.409 +Goal "abs(x pow (1hn + 1hn)) = x pow (1hn + 1hn)";
   7.410 +by (simp_tac (simpset() addsimps [hrabs_eqI1]) 1);
   7.411 +qed "hrabs_hyperpow_two";
   7.412 +Addsimps [hrabs_hyperpow_two];
   7.413 +
   7.414 +Goal "abs(x) pow (1hn + 1hn)  = x pow (1hn + 1hn)";
   7.415 +by (simp_tac (simpset() addsimps [hyperpow_hrabs,hrabs_eqI1]) 1);
   7.416 +qed "hyperpow_two_hrabs";
   7.417 +Addsimps [hyperpow_two_hrabs];
   7.418 +
   7.419 +Goal "!!r. 1hr < r ==> 1hr < r pow (1hn + 1hn)";
   7.420 +by (auto_tac (claset(),simpset() addsimps [hyperpow_two]));
   7.421 +by (cut_facts_tac [hypreal_zero_less_one] 1);
   7.422 +by (forw_inst_tac [("R1.0","0")] hypreal_less_trans 1);
   7.423 +by (assume_tac 1);
   7.424 +by (dres_inst_tac [("z","r"),("x","1hr")] 
   7.425 +    hypreal_mult_less_mono1 1);
   7.426 +by (auto_tac (claset() addIs [hypreal_less_trans],simpset()));
   7.427 +qed "hyperpow_two_gt_one";
   7.428 +
   7.429 +Goal "!!r. 1hr <= r ==> 1hr <= r pow (1hn + 1hn)";
   7.430 +by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq] 
   7.431 +     addIs [hyperpow_two_gt_one,hypreal_less_imp_le],
   7.432 +     simpset() addsimps [hypreal_le_refl]));
   7.433 +qed "hyperpow_two_ge_one";
   7.434 +
   7.435 +Goalw [hypnat_one_def,hypreal_zero_def]
   7.436 +      "!!r. (0::hypreal) < r ==> 0 < r pow (n + 1hn)";
   7.437 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.438 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.439 +by (auto_tac (claset() addSEs [FreeUltrafilterNat_subset]
   7.440 +    addDs [realpow_Suc_gt_zero],simpset() addsimps [hyperpow,
   7.441 +    hypreal_less,hypnat_add]));
   7.442 +qed "hyperpow_Suc_gt_zero";
   7.443 +
   7.444 +Goal "!!r. (0::hypreal) <= r ==> 0 <= r pow (n + 1hn)";
   7.445 +by (auto_tac (claset() addSDs [hypreal_le_imp_less_or_eq] 
   7.446 +    addIs [hyperpow_ge_zero,hypreal_less_imp_le], 
   7.447 +    simpset() addsimps [hypreal_le_refl]));
   7.448 +qed "hyperpow_Suc_ge_zero";
   7.449 +
   7.450 +Goal "1hr <= (1hr +1hr) pow n";
   7.451 +by (res_inst_tac [("j","1hr pow n")] hypreal_le_trans 1);
   7.452 +by (rtac hyperpow_le 2);
   7.453 +by (auto_tac (claset() addIs [hypreal_less_imp_le],
   7.454 +    simpset() addsimps [hypreal_zero_less_one,
   7.455 +    hypreal_one_less_two,hypreal_le_refl]));
   7.456 +qed "two_hyperpow_ge_one";
   7.457 +Addsimps [two_hyperpow_ge_one];
   7.458 +
   7.459 +Addsimps [simplify (simpset()) realpow_minus_one];
   7.460 +Goalw [hypreal_one_def]
   7.461 +      "(-1hr) pow ((1hn + 1hn)*n) = 1hr";
   7.462 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.463 +by (auto_tac (claset(),simpset() addsimps [hyperpow,
   7.464 +    hypnat_add,hypreal_minus]));
   7.465 +qed "hyperpow_minus_one2";
   7.466 +Addsimps [hyperpow_minus_one2];
   7.467 +
   7.468 +Goalw [hypreal_zero_def,
   7.469 +      hypreal_one_def,hypnat_one_def]
   7.470 +     "(0::hypreal) < r & r < 1hr --> r pow (n + 1hn) < r pow n";
   7.471 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.472 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.473 +by (auto_tac (claset() addSDs [conjI RS realpow_Suc_less] addEs
   7.474 +    [FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset ],
   7.475 +    simpset() addsimps [hyperpow,hypreal_less,hypnat_add]));
   7.476 +qed_spec_mp "hyperpow_Suc_less";
   7.477 +
   7.478 +Goalw [hypreal_zero_def,
   7.479 +      hypreal_one_def,hypnat_one_def]
   7.480 +     "0 <= r & r < 1hr --> r pow (n + 1hn) <= r pow n";
   7.481 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.482 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.483 +by (auto_tac (claset() addSDs [conjI RS realpow_Suc_le] addEs
   7.484 +    [FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset ],
   7.485 +    simpset() addsimps [hyperpow,hypreal_le,hypnat_add,
   7.486 +    hypreal_less]));
   7.487 +qed_spec_mp "hyperpow_Suc_le";
   7.488 +
   7.489 +Goalw [hypreal_zero_def,
   7.490 +      hypreal_one_def,hypnat_one_def]
   7.491 +     "(0::hypreal) <= r & r < 1hr & n < N --> r pow N <= r pow n";
   7.492 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   7.493 +by (res_inst_tac [("z","N")] eq_Abs_hypnat 1);
   7.494 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
   7.495 +by (auto_tac (claset(),simpset() addsimps [hyperpow,
   7.496 +    hypreal_le,hypreal_less,hypnat_less]));
   7.497 +by (etac (FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset) 1);
   7.498 +by (etac FreeUltrafilterNat_Int 1);
   7.499 +by (auto_tac (claset() addSDs [conjI RS realpow_less_le],
   7.500 +    simpset()));
   7.501 +qed_spec_mp "hyperpow_less_le";
   7.502 +
   7.503 +Goal "!!r. [| (0::hypreal) <= r; r < 1hr |] ==> \
   7.504 +\          ALL N n. n < N --> r pow N <= r pow n";
   7.505 +by (blast_tac (claset() addSIs [hyperpow_less_le]) 1);
   7.506 +qed "hyperpow_less_le2";
   7.507 +
   7.508 +Goal "!!r. [| 0 <= r; r < 1hr; \
   7.509 +\             N : HNatInfinite \
   7.510 +\          |] ==> ALL n:SHNat. r pow N <= r pow n";
   7.511 +by (auto_tac (claset() addSIs [hyperpow_less_le],
   7.512 +              simpset() addsimps [HNatInfinite_iff]));
   7.513 +qed "hyperpow_SHNat_le";
   7.514 +
   7.515 +Goalw [hypreal_of_real_def,hypnat_of_nat_def] 
   7.516 +      "(hypreal_of_real r) pow (hypnat_of_nat n) = hypreal_of_real (r ^ n)";
   7.517 +by (auto_tac (claset(),simpset() addsimps [hyperpow]));
   7.518 +qed "hyperpow_realpow";
   7.519 +
   7.520 +Goalw [SReal_def]
   7.521 +     "(hypreal_of_real r) pow (hypnat_of_nat n) : SReal";
   7.522 +by (auto_tac (claset(),simpset() addsimps [hyperpow_realpow]));
   7.523 +qed "hyperpow_SReal";
   7.524 +Addsimps [hyperpow_SReal];
   7.525 +
   7.526 +Goal "!!N. N : HNatInfinite ==> (0::hypreal) pow N = 0";
   7.527 +by (dtac HNatInfinite_is_Suc 1);
   7.528 +by (Auto_tac);
   7.529 +qed "hyperpow_zero_HNatInfinite";
   7.530 +Addsimps [hyperpow_zero_HNatInfinite];
   7.531 +
   7.532 +Goal "!!r. [| (0::hypreal) <= r; r < 1hr; n <= N |] ==> r pow N <= r pow n";
   7.533 +by (dres_inst_tac [("y","N")] hypnat_le_imp_less_or_eq 1);
   7.534 +by (auto_tac (claset() addIs [hyperpow_less_le],
   7.535 +    simpset() addsimps [hypreal_le_refl]));
   7.536 +qed "hyperpow_le_le";
   7.537 +
   7.538 +Goal "!!r. [| (0::hypreal) < r; r < 1hr |] ==> r pow (n + 1hn) <= r";
   7.539 +by (dres_inst_tac [("n","1hn")] (hypreal_less_imp_le RS 
   7.540 +    hyperpow_le_le) 1);
   7.541 +by (Auto_tac);
   7.542 +qed "hyperpow_Suc_le_self";
   7.543 +
   7.544 +Goal "!!r. [| (0::hypreal) <= r; r < 1hr |] ==> r pow (n + 1hn) <= r";
   7.545 +by (dres_inst_tac [("n","1hn")] hyperpow_le_le 1);
   7.546 +by (Auto_tac);
   7.547 +qed "hyperpow_Suc_le_self2";
   7.548 +
   7.549 +Goalw [Infinitesimal_def]
   7.550 +     "!!x. [| x : Infinitesimal; 0 < N |] \
   7.551 +\          ==> (abs x) pow N <= abs x";
   7.552 +by (auto_tac (claset() addSIs [hyperpow_Suc_le_self2],
   7.553 +    simpset() addsimps [hyperpow_hrabs RS sym,
   7.554 +    hypnat_gt_zero_iff2,hrabs_ge_zero,SReal_one,
   7.555 +    hypreal_zero_less_one]));
   7.556 +qed "lemma_Infinitesimal_hyperpow";
   7.557 +
   7.558 +Goal "!!x. [| x : Infinitesimal; 0 < N |] \
   7.559 +\           ==> x pow N : Infinitesimal";
   7.560 +by (rtac hrabs_le_Infinitesimal 1);
   7.561 +by (dtac Infinitesimal_hrabs 1);
   7.562 +by (auto_tac (claset() addSIs [lemma_Infinitesimal_hyperpow],
   7.563 +    simpset() addsimps [hyperpow_hrabs RS sym]));
   7.564 +qed "Infinitesimal_hyperpow";
   7.565 +
   7.566 +goalw HyperPow.thy [hypnat_of_nat_def] 
   7.567 +     "(x ^ n : Infinitesimal) = \
   7.568 +\     (x pow (hypnat_of_nat n) : Infinitesimal)";
   7.569 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   7.570 +by (auto_tac (claset(),simpset() addsimps [hrealpow,
   7.571 +    hyperpow]));
   7.572 +qed "hrealpow_hyperpow_Infinitesimal_iff";
   7.573 +
   7.574 +goal HyperPow.thy 
   7.575 +     "!!x. [| x : Infinitesimal; 0 < n |] \
   7.576 +\           ==> x ^ n : Infinitesimal";
   7.577 +by (auto_tac (claset() addSIs [Infinitesimal_hyperpow],
   7.578 +    simpset() addsimps [hrealpow_hyperpow_Infinitesimal_iff,
   7.579 +    hypnat_of_nat_less_iff,hypnat_of_nat_zero] 
   7.580 +    delsimps [hypnat_of_nat_less_iff RS sym]));
   7.581 +qed "Infinitesimal_hrealpow";
   7.582 +
   7.583 +
   7.584 +
   7.585 +
   7.586 +
   7.587 +
   7.588 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/HOL/Real/Hyperreal/HyperPow.thy	Thu Sep 21 12:17:11 2000 +0200
     8.3 @@ -0,0 +1,26 @@
     8.4 +(*  Title       : HyperPow.thy
     8.5 +    Author      : Jacques D. Fleuriot  
     8.6 +    Copyright   : 1998  University of Cambridge
     8.7 +    Description : Powers theory for hyperreals
     8.8 +*)
     8.9 +
    8.10 +HyperPow = HRealAbs + HyperNat + RealPow +  
    8.11 +
    8.12 +instance hypreal :: {power}
    8.13 +
    8.14 +consts hpowr :: "[hypreal,nat] => hypreal"  
    8.15 +primrec
    8.16 +     hpowr_0   "r ^ 0       = 1hr"
    8.17 +     hpowr_Suc "r ^ (Suc n) = (r::hypreal) * (r ^ n)"
    8.18 +
    8.19 +consts
    8.20 +  "pow"  :: [hypreal,hypnat] => hypreal     (infixr 80)
    8.21 +
    8.22 +defs
    8.23 +
    8.24 +  (* hypernatural powers of hyperreals *)
    8.25 +  hyperpow_def
    8.26 +  "(R::hypreal) pow (N::hypnat) 
    8.27 +      == Abs_hypreal(UN X:Rep_hypreal(R). UN Y: Rep_hypnat(N).
    8.28 +             hyprel^^{%n::nat. (X n) ^ (Y n)})"
    8.29 +end
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/HOL/Real/Hyperreal/Lim.ML	Thu Sep 21 12:17:11 2000 +0200
     9.3 @@ -0,0 +1,1508 @@
     9.4 +(*  Title       : Lim.ML
     9.5 +    Author      : Jacques D. Fleuriot
     9.6 +    Copyright   : 1998  University of Cambridge
     9.7 +    Description : Theory of limits, continuity and 
     9.8 +                  differentiation of real=>real functions
     9.9 +*)
    9.10 +
    9.11 +
    9.12 +fun ARITH_PROVE str = prove_goal thy str 
    9.13 +                      (fn prems => [cut_facts_tac prems 1,arith_tac 1]);
    9.14 +
    9.15 +(*---------------------------------------------------------------
    9.16 +   Theory of limits, continuity and differentiation of 
    9.17 +   real=>real functions 
    9.18 + ----------------------------------------------------------------*)
    9.19 +Goalw [LIM_def] "(f -- a --> L) = (ALL r. #0 < r --> \
    9.20 +\    (EX s. #0 < s & (ALL x. (#0 < abs(x + -a) & (abs(x + -a) < s) \
    9.21 +\          --> abs(f x + -L) < r))))";
    9.22 +by (Blast_tac 1);
    9.23 +qed "LIM_iff";
    9.24 +
    9.25 +Goalw [LIM_def] 
    9.26 +      "!!a. [| f -- a --> L; #0 < r |] \
    9.27 +\           ==> (EX s. #0 < s & (ALL x. (#0 < abs(x + -a) \
    9.28 +\           & (abs(x + -a) < s) --> abs(f x + -L) < r)))";
    9.29 +by (Blast_tac 1);
    9.30 +qed "LIMD";
    9.31 +
    9.32 +Goalw [LIM_def] "(%x. k) -- x --> k";
    9.33 +by (Auto_tac);
    9.34 +qed "LIM_const";
    9.35 +Addsimps [LIM_const];
    9.36 +
    9.37 +(***-----------------------------------------------------------***)
    9.38 +(***  Some Purely Standard Proofs - Can be used for comparison ***)
    9.39 +(***-----------------------------------------------------------***)
    9.40 + 
    9.41 +(*--------------- 
    9.42 +    LIM_add    
    9.43 + ---------------*)
    9.44 +Goalw [LIM_def] 
    9.45 +     "[| f -- x --> l; g -- x --> m |] \
    9.46 +\     ==> (%x. f(x) + g(x)) -- x --> (l + m)";
    9.47 +by (Step_tac 1);
    9.48 +by (REPEAT(dres_inst_tac [("x","r*rinv(#1 + #1)")] spec 1));
    9.49 +by (dtac (rename_numerals (real_zero_less_two RS real_rinv_gt_zero 
    9.50 +    RSN (2,real_mult_less_mono2))) 1);
    9.51 +by (Asm_full_simp_tac 1);
    9.52 +by (Clarify_tac 1);
    9.53 +by (res_inst_tac [("R1.0","s"),("R2.0","sa")] 
    9.54 +    real_linear_less2 1);
    9.55 +by (res_inst_tac [("x","s")] exI 1);
    9.56 +by (res_inst_tac [("x","sa")] exI 2);
    9.57 +by (res_inst_tac [("x","sa")] exI 3);
    9.58 +by (Step_tac 1);
    9.59 +by (REPEAT(dres_inst_tac [("x","xa")] spec 1) 
    9.60 +    THEN step_tac (claset() addSEs [real_less_trans]) 1);
    9.61 +by (REPEAT(dres_inst_tac [("x","xa")] spec 2) 
    9.62 +    THEN step_tac (claset() addSEs [real_less_trans]) 2);
    9.63 +by (REPEAT(dres_inst_tac [("x","xa")] spec 3) 
    9.64 +    THEN step_tac (claset() addSEs [real_less_trans]) 3);
    9.65 +by (ALLGOALS(rtac (abs_sum_triangle_ineq RS real_le_less_trans)));
    9.66 +by (ALLGOALS(rtac (real_sum_of_halves RS subst)));
    9.67 +by (auto_tac (claset() addIs [real_add_less_mono],simpset()));
    9.68 +qed "LIM_add";
    9.69 +
    9.70 +Goalw [LIM_def] "f -- a --> L ==> (%x. -f(x)) -- a --> -L";
    9.71 +by (full_simp_tac (simpset() addsimps [real_minus_add_distrib RS sym,
    9.72 +    abs_minus_cancel] delsimps [real_minus_add_distrib,real_minus_minus]) 1);
    9.73 +qed "LIM_minus";
    9.74 +
    9.75 +(*----------------------------------------------
    9.76 +     LIM_add_minus
    9.77 + ----------------------------------------------*)
    9.78 +Goal "[| f -- x --> l; g -- x --> m |] \
    9.79 +\     ==> (%x. f(x) + -g(x)) -- x --> (l + -m)";
    9.80 +by (blast_tac (claset() addDs [LIM_add,LIM_minus]) 1);
    9.81 +qed "LIM_add_minus";
    9.82 +
    9.83 +(*----------------------------------------------
    9.84 +     LIM_zero
    9.85 + ----------------------------------------------*)
    9.86 +Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> #0";
    9.87 +by (res_inst_tac [("z1","l")] (rename_numerals 
    9.88 +    (real_add_minus RS subst)) 1);
    9.89 +by (rtac LIM_add_minus 1 THEN Auto_tac);
    9.90 +qed "LIM_zero";
    9.91 +
    9.92 +(*--------------------------
    9.93 +   Limit not zero
    9.94 + --------------------------*)
    9.95 +Goalw [LIM_def] "k ~= #0 ==> ~ ((%x. k) -- x --> #0)";
    9.96 +by (res_inst_tac [("R1.0","k"),("R2.0","#0")] real_linear_less2 1);
    9.97 +by (auto_tac (claset(),simpset() addsimps [abs_minus_eqI2,abs_eqI2]));
    9.98 +by (dtac (rename_numerals (real_minus_zero_less_iff RS iffD2)) 1);
    9.99 +by (res_inst_tac [("x","-k")] exI 1);
   9.100 +by (res_inst_tac [("x","k")] exI 2);
   9.101 +by Auto_tac;
   9.102 +by (ALLGOALS(dres_inst_tac [("y","s")] real_dense));
   9.103 +by (Step_tac 1);
   9.104 +by (ALLGOALS(res_inst_tac [("x","r + x")] exI));
   9.105 +by (auto_tac (claset(),simpset() addsimps [real_add_assoc,abs_eqI2]));
   9.106 +qed "LIM_not_zero";
   9.107 +
   9.108 +(* [| k ~= #0; (%x. k) -- x --> #0 |] ==> R *)
   9.109 +bind_thm("LIM_not_zeroE", (LIM_not_zero RS notE));
   9.110 +
   9.111 +Goal "(%x. k) -- x --> L ==> k = L";
   9.112 +by (rtac ccontr 1);
   9.113 +by (dtac LIM_zero 1);
   9.114 +by (rtac LIM_not_zeroE 1 THEN assume_tac 2);
   9.115 +by (arith_tac 1);
   9.116 +qed "LIM_const_eq";
   9.117 +
   9.118 +(*------------------------
   9.119 +     Limit is Unique
   9.120 + ------------------------*)
   9.121 +Goal "[| f -- x --> L; f -- x --> M |] ==> L = M";
   9.122 +by (dtac LIM_minus 1);
   9.123 +by (dtac LIM_add 1 THEN assume_tac 1);
   9.124 +by (auto_tac (claset() addSDs [LIM_const_eq RS sym],
   9.125 +    simpset()));
   9.126 +qed "LIM_unique";
   9.127 +
   9.128 +(*-------------
   9.129 +    LIM_mult_zero
   9.130 + -------------*)
   9.131 +Goalw [LIM_def] "!!f. [| f -- x --> #0; g -- x --> #0 |] \
   9.132 +\         ==> (%x. f(x)*g(x)) -- x --> #0";
   9.133 +by (Step_tac 1);
   9.134 +by (dres_inst_tac [("x","#1")] spec 1);
   9.135 +by (dres_inst_tac [("x","r")] spec 1);
   9.136 +by (cut_facts_tac [real_zero_less_one] 1);
   9.137 +by (asm_full_simp_tac (simpset() addsimps 
   9.138 +    [abs_mult]) 1);
   9.139 +by (Clarify_tac 1);
   9.140 +by (res_inst_tac [("R1.0","s"),("R2.0","sa")] 
   9.141 +    real_linear_less2 1);
   9.142 +by (res_inst_tac [("x","s")] exI 1);
   9.143 +by (res_inst_tac [("x","sa")] exI 2);
   9.144 +by (res_inst_tac [("x","sa")] exI 3);
   9.145 +by (Step_tac 1);
   9.146 +by (REPEAT(dres_inst_tac [("x","xa")] spec 1) 
   9.147 +    THEN step_tac (claset() addSEs [real_less_trans]) 1);
   9.148 +by (REPEAT(dres_inst_tac [("x","xa")] spec 2) 
   9.149 +    THEN step_tac (claset() addSEs [real_less_trans]) 2);
   9.150 +by (REPEAT(dres_inst_tac [("x","xa")] spec 3) 
   9.151 +    THEN step_tac (claset() addSEs [real_less_trans]) 3);
   9.152 +by (ALLGOALS(res_inst_tac [("t","r")] (real_mult_1 RS subst)));
   9.153 +by (ALLGOALS(rtac abs_mult_less2));
   9.154 +by Auto_tac;
   9.155 +qed "LIM_mult_zero";
   9.156 +
   9.157 +Goalw [LIM_def] "(%x. x) -- a --> a";
   9.158 +by (Auto_tac);
   9.159 +qed "LIM_self";
   9.160 +
   9.161 +Goal "(#0::real) < abs (x + -a) ==> x ~= a";
   9.162 +by (arith_tac 1);
   9.163 +qed "lemma_rabs_not_eq";
   9.164 +
   9.165 +(*--------------------------------------------------------------
   9.166 +   Limits are equal for functions equal except at limit point
   9.167 + --------------------------------------------------------------*)
   9.168 +Goalw [LIM_def] 
   9.169 +      "[| ALL x. x ~= a --> (f x = g x) |] \
   9.170 +\           ==> (f -- a --> l) = (g -- a --> l)";
   9.171 +by (auto_tac (claset(),simpset() addsimps [lemma_rabs_not_eq]));
   9.172 +qed "LIM_equal";
   9.173 +
   9.174 +Goal "[| (%x. f(x) + -g(x)) -- a --> #0; \
   9.175 +\        g -- a --> l |] \
   9.176 +\      ==> f -- a --> l";
   9.177 +by (dtac LIM_add 1 THEN assume_tac 1);
   9.178 +by (auto_tac (claset(),simpset() addsimps 
   9.179 +    [real_add_assoc]));
   9.180 +qed "LIM_trans";
   9.181 +
   9.182 +(***-------------------------------------------------------------***)
   9.183 +(***           End of Purely Standard Proofs                     ***)
   9.184 +(***-------------------------------------------------------------***)
   9.185 +(*--------------------------------------------------------------
   9.186 +       Standard and NS definitions of Limit
   9.187 + --------------------------------------------------------------*)
   9.188 +Goalw [LIM_def,NSLIM_def,inf_close_def] 
   9.189 +      "f -- x --> L ==> f -- x --NS> L";
   9.190 +by (asm_full_simp_tac (simpset() addsimps 
   9.191 +    [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   9.192 +by (Step_tac 1);
   9.193 +by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
   9.194 +by (auto_tac (claset(),simpset() addsimps [starfun,
   9.195 +    hypreal_minus,hypreal_of_real_minus RS sym,
   9.196 +    hypreal_of_real_def,hypreal_add]));
   9.197 +by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2 THEN Step_tac 1);
   9.198 +by (dres_inst_tac [("x","u")] spec 1 THEN Clarify_tac 1);
   9.199 +by (dres_inst_tac [("x","s")] spec 1 THEN Clarify_tac 1);
   9.200 +by (subgoal_tac "ALL n::nat. (#0::real) < abs ((xa n) + - x) & \
   9.201 +\  abs ((xa n) + - x) < s --> abs (f (xa n) + - L) < u" 1);
   9.202 +by (Blast_tac 2);
   9.203 +by (dtac FreeUltrafilterNat_all 1);
   9.204 +by (Ultra_tac 1 THEN arith_tac 1);
   9.205 +qed "LIM_NSLIM";
   9.206 + 
   9.207 +(*---------------------------------------------------------------------
   9.208 +    Limit: NS definition ==> standard definition
   9.209 + ---------------------------------------------------------------------*)
   9.210 +
   9.211 +Goal "ALL s. #0 < s --> (EX xa.  #0 < abs (xa + - x) & \
   9.212 +\        abs (xa + - x) < s  & r <= abs (f xa + -L)) \
   9.213 +\     ==> ALL n::nat. EX xa.  #0 < abs (xa + - x) & \
   9.214 +\             abs(xa + -x) < rinv(real_of_posnat n) & r <= abs(f xa + -L)";
   9.215 +by (Step_tac 1);
   9.216 +by (cut_inst_tac [("n1","n")] (real_of_posnat_gt_zero RS real_rinv_gt_zero) 1);
   9.217 +by Auto_tac;
   9.218 +val lemma_LIM = result();
   9.219 +
   9.220 +Goal "ALL s. #0 < s --> (EX xa.  #0 < abs (xa + - x) & \
   9.221 +\        abs (xa + - x) < s  & r <= abs (f xa + -L)) \
   9.222 +\     ==> EX X. ALL n::nat. #0 < abs (X n + - x) & \
   9.223 +\               abs(X n + -x) < rinv(real_of_posnat n) & r <= abs(f (X n) + -L)";
   9.224 +by (dtac lemma_LIM 1);
   9.225 +by (dtac choice 1);
   9.226 +by (Blast_tac 1);
   9.227 +val lemma_skolemize_LIM2 = result();
   9.228 +
   9.229 +Goal "{n. f (X n) + - L = Y n} Int \
   9.230 +\         {n. #0 < abs (X n + - x) & \
   9.231 +\             abs (X n + - x) < rinv (real_of_posnat  n) & \
   9.232 +\             r <= abs (f (X n) + - L)} <= \
   9.233 +\         {n. r <= abs (Y n)}";
   9.234 +by (Auto_tac);
   9.235 +val lemma_Int = result ();
   9.236 +
   9.237 +Goal "!!X. ALL n. #0 < abs (X n + - x) & \
   9.238 +\         abs (X n + - x) < rinv (real_of_posnat  n) & \
   9.239 +\         r <= abs (f (X n) + - L) ==> \
   9.240 +\         ALL n. abs (X n + - x) < rinv (real_of_posnat  n)";
   9.241 +by (Auto_tac );
   9.242 +val lemma_simp = result();
   9.243 + 
   9.244 +(*-------------------
   9.245 +    NSLIM => LIM
   9.246 + -------------------*)
   9.247 +
   9.248 +Goalw [LIM_def,NSLIM_def,inf_close_def] 
   9.249 +      "!!f. f -- x --NS> L ==> f -- x --> L";
   9.250 +by (asm_full_simp_tac (simpset() addsimps 
   9.251 +    [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   9.252 +by (EVERY1[Step_tac, rtac ccontr, Asm_full_simp_tac]);
   9.253 +by (fold_tac [real_le_def]);
   9.254 +by (dtac lemma_skolemize_LIM2 1);
   9.255 +by (Step_tac 1);
   9.256 +by (dres_inst_tac [("x","Abs_hypreal(hyprel^^{X})")] spec 1);
   9.257 +by (asm_full_simp_tac (simpset() addsimps [starfun,
   9.258 +    hypreal_minus,hypreal_of_real_minus RS sym,
   9.259 +    hypreal_of_real_def,hypreal_add]) 1);
   9.260 +by (Step_tac 1);
   9.261 +by (dtac FreeUltrafilterNat_Ex_P 1 THEN etac exE 1);
   9.262 +by (dres_inst_tac [("x","n")] spec 1);
   9.263 +by (asm_full_simp_tac (simpset() addsimps 
   9.264 +    [real_add_minus,real_less_not_refl]) 1);
   9.265 +by (dtac (lemma_simp RS real_seq_to_hypreal_Infinitesimal) 1);
   9.266 +by (asm_full_simp_tac (simpset() addsimps 
   9.267 +    [Infinitesimal_FreeUltrafilterNat_iff,hypreal_of_real_def,
   9.268 +     hypreal_minus,hypreal_of_real_minus,hypreal_add]) 1);
   9.269 +by (rotate_tac 2 1);
   9.270 +by (dres_inst_tac [("x","r")] spec 1);
   9.271 +by (Clarify_tac 1);
   9.272 +by (dtac FreeUltrafilterNat_all 1);
   9.273 +by (Ultra_tac 1);
   9.274 +qed "NSLIM_LIM";
   9.275 +
   9.276 +(**** Key result ****)
   9.277 +Goal "(f -- x --> L) = (f -- x --NS> L)";
   9.278 +by (blast_tac (claset() addIs [LIM_NSLIM,NSLIM_LIM]) 1);
   9.279 +qed "LIM_NSLIM_iff";
   9.280 +
   9.281 +(*-------------------------------------------------------------------*)
   9.282 +(*   Proving properties of limits using nonstandard definition and   *)
   9.283 +(*   hence, the properties hold for standard limits as well          *)
   9.284 +(*-------------------------------------------------------------------*)
   9.285 +(*------------------------------------------------
   9.286 +      NSLIM_mult and hence (trivially) LIM_mult
   9.287 + ------------------------------------------------*)
   9.288 +
   9.289 +Goalw [NSLIM_def]
   9.290 +     "[| f -- x --NS> l; g -- x --NS> m |] \
   9.291 +\     ==> (%x. f(x) * g(x)) -- x --NS> (l * m)";
   9.292 +by (auto_tac (claset() addSIs [starfun_mult_HFinite_inf_close],
   9.293 +              simpset() addsimps [hypreal_of_real_mult]));
   9.294 +qed "NSLIM_mult";
   9.295 +
   9.296 +Goal "[| f -- x --> l; g -- x --> m |] \
   9.297 +\     ==> (%x. f(x) * g(x)) -- x --> (l * m)";
   9.298 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.299 +    NSLIM_mult]) 1);
   9.300 +qed "LIM_mult2";
   9.301 +
   9.302 +(*----------------------------------------------
   9.303 +      NSLIM_add and hence (trivially) LIM_add
   9.304 +      Note the much shorter proof
   9.305 + ----------------------------------------------*)
   9.306 +Goalw [NSLIM_def]
   9.307 +     "[| f -- x --NS> l; g -- x --NS> m |] \
   9.308 +\     ==> (%x. f(x) + g(x)) -- x --NS> (l + m)";
   9.309 +by (auto_tac (claset() addSIs [starfun_add_inf_close],
   9.310 +              simpset() addsimps [hypreal_of_real_add]));
   9.311 +qed "NSLIM_add";
   9.312 +
   9.313 +Goal "[| f -- x --> l; g -- x --> m |] \
   9.314 +\     ==> (%x. f(x) + g(x)) -- x --> (l + m)";
   9.315 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.316 +    NSLIM_add]) 1);
   9.317 +qed "LIM_add2";
   9.318 +
   9.319 +(*----------------------------------------------
   9.320 +     NSLIM_const
   9.321 + ----------------------------------------------*)
   9.322 +Goalw [NSLIM_def] "(%x. k) -- x --NS> k";
   9.323 +by (Auto_tac);
   9.324 +qed "NSLIM_const";
   9.325 +
   9.326 +Addsimps [NSLIM_const];
   9.327 +
   9.328 +Goal "(%x. k) -- x --> k";
   9.329 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   9.330 +qed "LIM_const2";
   9.331 +
   9.332 +(*----------------------------------------------
   9.333 +     NSLIM_minus
   9.334 + ----------------------------------------------*)
   9.335 +Goalw [NSLIM_def] 
   9.336 +      "f -- a --NS> L ==> (%x. -f(x)) -- a --NS> -L";
   9.337 +by (auto_tac (claset() addIs [inf_close_minus],
   9.338 +    simpset() addsimps [starfun_minus RS sym,
   9.339 +    hypreal_of_real_minus]));
   9.340 +qed "NSLIM_minus";
   9.341 +
   9.342 +Goal "f -- a --> L ==> (%x. -f(x)) -- a --> -L";
   9.343 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.344 +    NSLIM_minus]) 1);
   9.345 +qed "LIM_minus2";
   9.346 +
   9.347 +(*----------------------------------------------
   9.348 +     NSLIM_add_minus
   9.349 + ----------------------------------------------*)
   9.350 +Goal "!!f. [| f -- x --NS> l; g -- x --NS> m |] \
   9.351 +\     ==> (%x. f(x) + -g(x)) -- x --NS> (l + -m)";
   9.352 +by (blast_tac (claset() addDs [NSLIM_add,NSLIM_minus]) 1);
   9.353 +qed "NSLIM_add_minus";
   9.354 +
   9.355 +Goal "!!f. [| f -- x --> l; g -- x --> m |] \
   9.356 +\     ==> (%x. f(x) + -g(x)) -- x --> (l + -m)";
   9.357 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.358 +    NSLIM_add_minus]) 1);
   9.359 +qed "LIM_add_minus2";
   9.360 +
   9.361 +(*-----------------------------
   9.362 +    NSLIM_rinv
   9.363 + -----------------------------*)
   9.364 +Goalw [NSLIM_def] 
   9.365 +      "!!f. [| f -- a --NS> L; \
   9.366 +\              L ~= #0 \
   9.367 +\           |] ==> (%x. rinv(f(x))) -- a --NS> (rinv L)";
   9.368 +by (Step_tac 1);
   9.369 +by (dtac spec 1 THEN auto_tac (claset(),simpset() 
   9.370 +    addsimps [hypreal_of_real_not_zero_iff RS sym,
   9.371 +    hypreal_of_real_hrinv RS sym]));
   9.372 +by (forward_tac [inf_close_hypreal_of_real_not_zero] 1 
   9.373 +    THEN assume_tac 1);
   9.374 +by (auto_tac (claset() addSEs [(starfun_hrinv2 RS subst),
   9.375 +    inf_close_hrinv,hypreal_of_real_HFinite_diff_Infinitesimal],
   9.376 +    simpset()));
   9.377 +qed "NSLIM_rinv";
   9.378 +
   9.379 +Goal "[| f -- a --> L; \
   9.380 +\        L ~= #0 |] ==> (%x. rinv(f(x))) -- a --> (rinv L)";
   9.381 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.382 +    NSLIM_rinv]) 1);
   9.383 +qed "LIM_rinv";
   9.384 +
   9.385 +(*------------------------------
   9.386 +    NSLIM_zero
   9.387 + ------------------------------*)
   9.388 +Goal "f -- a --NS> l ==> (%x. f(x) + -l) -- a --NS> #0";
   9.389 +by (res_inst_tac [("z1","l")] (rename_numerals 
   9.390 +    (real_add_minus RS subst)) 1);
   9.391 +by (rtac NSLIM_add_minus 1 THEN Auto_tac);
   9.392 +qed "NSLIM_zero";
   9.393 +
   9.394 +Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> #0";
   9.395 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.396 +    NSLIM_zero]) 1);
   9.397 +qed "LIM_zero2";
   9.398 +
   9.399 +Goal "(%x. f(x) - l) -- x --NS> #0 ==> f -- x --NS> l";
   9.400 +by (dres_inst_tac [("g","%x. l"),("m","l")] NSLIM_add 1);
   9.401 +by (auto_tac (claset(),simpset() addsimps [real_diff_def,
   9.402 +    real_add_assoc]));
   9.403 +qed "NSLIM_zero_cancel";
   9.404 +
   9.405 +Goal "(%x. f(x) - l) -- x --> #0 ==> f -- x --> l";
   9.406 +by (dres_inst_tac [("g","%x. l"),("m","l")] LIM_add 1);
   9.407 +by (auto_tac (claset(),simpset() addsimps [real_diff_def,
   9.408 +    real_add_assoc]));
   9.409 +qed "LIM_zero_cancel";
   9.410 +
   9.411 +(*--------------------------
   9.412 +   NSLIM_not_zero
   9.413 + --------------------------*)
   9.414 +Goalw [NSLIM_def] "k ~= #0 ==> ~ ((%x. k) -- x --NS> #0)";
   9.415 +by (Auto_tac);
   9.416 +by (res_inst_tac [("x","hypreal_of_real x + ehr")] exI 1);
   9.417 +by (auto_tac (claset() addIs [Infinitesimal_add_inf_close_self 
   9.418 +    RS inf_close_sym],simpset()));
   9.419 +by (dres_inst_tac [("x1","-hypreal_of_real x")] (hypreal_add_left_cancel RS iffD2) 1);
   9.420 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym,
   9.421 +    hypreal_epsilon_not_zero]) 1);
   9.422 +qed "NSLIM_not_zero";
   9.423 +
   9.424 +(* [| k ~= #0; (%x. k) -- x --NS> #0 |] ==> R *)
   9.425 +bind_thm("NSLIM_not_zeroE", (NSLIM_not_zero RS notE));
   9.426 +
   9.427 +Goal "k ~= #0 ==> ~ ((%x. k) -- x --> #0)";
   9.428 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.429 +    NSLIM_not_zero]) 1);
   9.430 +qed "LIM_not_zero2";
   9.431 +
   9.432 +(*-------------------------------------
   9.433 +   NSLIM of constant function
   9.434 + -------------------------------------*)
   9.435 +Goal "(%x. k) -- x --NS> L ==> k = L";
   9.436 +by (rtac ccontr 1);
   9.437 +by (dtac NSLIM_zero 1);
   9.438 +by (rtac NSLIM_not_zeroE 1 THEN assume_tac 2);
   9.439 +by (arith_tac 1);
   9.440 +qed "NSLIM_const_eq";
   9.441 +
   9.442 +Goal "(%x. k) -- x --> L ==> k = L";
   9.443 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.444 +    NSLIM_const_eq]) 1);
   9.445 +qed "LIM_const_eq2";
   9.446 +
   9.447 +(*------------------------
   9.448 +     NS Limit is Unique
   9.449 + ------------------------*)
   9.450 +(* can actually be proved more easily by unfolding def! *)
   9.451 +Goal "[| f -- x --NS> L; f -- x --NS> M |] ==> L = M";
   9.452 +by (dtac NSLIM_minus 1);
   9.453 +by (dtac NSLIM_add 1 THEN assume_tac 1);
   9.454 +by (auto_tac (claset() addSDs [NSLIM_const_eq RS sym],
   9.455 +    simpset() addsimps [real_add_minus]));
   9.456 +qed "NSLIM_unique";
   9.457 +
   9.458 +Goal "[| f -- x --> L; f -- x --> M |] ==> L = M";
   9.459 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.460 +    NSLIM_unique]) 1);
   9.461 +qed "LIM_unique2";
   9.462 +
   9.463 +(*--------------------
   9.464 +    NSLIM_mult_zero
   9.465 + --------------------*)
   9.466 +Goal "[| f -- x --NS> #0; g -- x --NS> #0 |] \
   9.467 +\         ==> (%x. f(x)*g(x)) -- x --NS> #0";
   9.468 +by (dtac NSLIM_mult 1 THEN Auto_tac);
   9.469 +qed "NSLIM_mult_zero";
   9.470 +
   9.471 +(* we can use the corresponding thm LIM_mult2 *)
   9.472 +(* for standard definition of limit           *)
   9.473 +
   9.474 +Goal "[| f -- x --> #0; g -- x --> #0 |] \
   9.475 +\     ==> (%x. f(x)*g(x)) -- x --> #0";
   9.476 +by (dtac LIM_mult2 1 THEN Auto_tac);
   9.477 +qed "LIM_mult_zero2";
   9.478 +
   9.479 +(*----------------------------
   9.480 +    NSLIM_self
   9.481 + ----------------------------*)
   9.482 +Goalw [NSLIM_def] "(%x. x) -- a --NS> a";
   9.483 +by (auto_tac (claset() addIs [starfun_Idfun_inf_close],simpset()));
   9.484 +qed "NSLIM_self";
   9.485 +
   9.486 +Goal "(%x. x) -- a --> a";
   9.487 +by (simp_tac (simpset() addsimps [LIM_NSLIM_iff,NSLIM_self]) 1);
   9.488 +qed "LIM_self2";
   9.489 +
   9.490 +(*-----------------------------------------------------------------------------
   9.491 +   Derivatives and Continuity - NS and Standard properties
   9.492 + -----------------------------------------------------------------------------*)
   9.493 +(*---------------
   9.494 +    Continuity 
   9.495 + ---------------*)
   9.496 +
   9.497 +Goalw [isNSCont_def] 
   9.498 +      "!!f. [| isNSCont f a; y @= hypreal_of_real a |] \
   9.499 +\           ==> (*f* f) y @= hypreal_of_real (f a)";
   9.500 +by (Blast_tac 1);
   9.501 +qed "isNSContD";
   9.502 +
   9.503 +Goalw [isNSCont_def,NSLIM_def] 
   9.504 +      "!!f. isNSCont f a ==> f -- a --NS> (f a) ";
   9.505 +by (Blast_tac 1);
   9.506 +qed "isNSCont_NSLIM";
   9.507 +
   9.508 +Goalw [isNSCont_def,NSLIM_def] 
   9.509 +      "!!f. f -- a --NS> (f a) ==> isNSCont f a";
   9.510 +by (Auto_tac);
   9.511 +by (res_inst_tac [("Q","y = hypreal_of_real a")] 
   9.512 +    (excluded_middle RS disjE) 1);
   9.513 +by (Auto_tac);
   9.514 +qed "NSLIM_isNSCont";
   9.515 +
   9.516 +(*-----------------------------------------------------
   9.517 +    NS continuity can be defined using NS Limit in
   9.518 +    similar fashion to standard def of continuity
   9.519 + -----------------------------------------------------*)
   9.520 +Goal "(isNSCont f a) = (f -- a --NS> (f a))";
   9.521 +by (blast_tac (claset() addIs [isNSCont_NSLIM,NSLIM_isNSCont]) 1);
   9.522 +qed "isNSCont_NSLIM_iff";
   9.523 +
   9.524 +(*----------------------------------------------
   9.525 +  Hence, NS continuity can be given
   9.526 +  in terms of standard limit
   9.527 + ---------------------------------------------*)
   9.528 +Goal "(isNSCont f a) = (f -- a --> (f a))";
   9.529 +by (asm_full_simp_tac (simpset() addsimps 
   9.530 +    [LIM_NSLIM_iff,isNSCont_NSLIM_iff]) 1);
   9.531 +qed "isNSCont_LIM_iff";
   9.532 +
   9.533 +(*-----------------------------------------------
   9.534 +  Moreover, it's trivial now that NS continuity 
   9.535 +  is equivalent to standard continuity
   9.536 + -----------------------------------------------*)
   9.537 +Goalw [isCont_def] "(isNSCont f a) = (isCont f a)";
   9.538 +by (rtac isNSCont_LIM_iff 1);
   9.539 +qed "isNSCont_isCont_iff";
   9.540 +
   9.541 +(*----------------------------------------
   9.542 +  Standard continuity ==> NS continuity 
   9.543 + ----------------------------------------*)
   9.544 +Goal "!!f. isCont f a ==> isNSCont f a";
   9.545 +by (etac (isNSCont_isCont_iff RS iffD2) 1);
   9.546 +qed "isCont_isNSCont";
   9.547 +
   9.548 +(*----------------------------------------
   9.549 +  NS continuity ==> Standard continuity 
   9.550 + ----------------------------------------*)
   9.551 +Goal "!!f. isNSCont f a ==> isCont f a";
   9.552 +by (etac (isNSCont_isCont_iff RS iffD1) 1);
   9.553 +qed "isNSCont_isCont";
   9.554 +
   9.555 +(*--------------------------------------------------------------------------
   9.556 +                 Alternative definition of continuity
   9.557 + --------------------------------------------------------------------------*)
   9.558 +(* Prove equivalence between NS limits - *)
   9.559 +(* seems easier than using standard def  *)
   9.560 +Goalw [NSLIM_def] 
   9.561 +      "(f -- a --NS> L) = ((%h. f(a + h)) -- #0 --NS> L)";
   9.562 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_zero]));
   9.563 +by (dres_inst_tac [("x","hypreal_of_real a + x")] spec 1);
   9.564 +by (dres_inst_tac [("x","-hypreal_of_real a + x")] spec 2);
   9.565 +by (Step_tac 1);
   9.566 +by (dtac (sym RS (hypreal_eq_minus_iff4 RS iffD1)) 1);
   9.567 +by (rtac ((mem_infmal_iff RS iffD2) RS 
   9.568 +    (Infinitesimal_add_inf_close_self RS inf_close_sym)) 2);
   9.569 +by (rtac (inf_close_minus_iff2 RS iffD1) 5);
   9.570 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 4);
   9.571 +by (dtac (sym RS (hypreal_eq_minus_iff RS iffD2)) 4);
   9.572 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 3);
   9.573 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 6);
   9.574 +by (auto_tac (claset(),simpset() addsimps [starfun,
   9.575 +    hypreal_of_real_def,hypreal_minus,hypreal_add,
   9.576 +    real_add_assoc,inf_close_refl,hypreal_zero_def]));
   9.577 +qed "NSLIM_h_iff";
   9.578 +
   9.579 +Goal "(f -- a --NS> f a) = ((%h. f(a + h)) -- #0 --NS> f a)";
   9.580 +by (rtac NSLIM_h_iff 1);
   9.581 +qed "NSLIM_isCont_iff";
   9.582 +
   9.583 +Goal "(f -- a --> f a) = ((%h. f(a + h)) -- #0 --> f(a))";
   9.584 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   9.585 +    NSLIM_isCont_iff]) 1);
   9.586 +qed "LIM_isCont_iff";
   9.587 +
   9.588 +Goalw [isCont_def] 
   9.589 +      "(isCont f x) = ((%h. f(x + h)) -- #0 --> f(x))";
   9.590 +by (simp_tac (simpset() addsimps [LIM_isCont_iff]) 1);
   9.591 +qed "isCont_iff";
   9.592 +
   9.593 +(*--------------------------------------------------------------------------
   9.594 +   Immediate application of nonstandard criterion for continuity can offer 
   9.595 +   very simple proofs of some standard property of continuous functions
   9.596 + --------------------------------------------------------------------------*)
   9.597 +(*------------------------
   9.598 +     sum continuous
   9.599 + ------------------------*)
   9.600 +Goal "!!f. [| isCont f a; isCont g a |] ==> isCont (%x. f(x) + g(x)) a";
   9.601 +by (auto_tac (claset() addIs [starfun_add_inf_close],simpset() addsimps 
   9.602 +              [isNSCont_isCont_iff RS sym,isNSCont_def,hypreal_of_real_add]));
   9.603 +qed "isCont_add";
   9.604 +
   9.605 +(*------------------------
   9.606 +     mult continuous
   9.607 + ------------------------*)
   9.608 +Goal "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a";
   9.609 +by (auto_tac (claset() addSIs [starfun_mult_HFinite_inf_close],simpset() addsimps 
   9.610 +              [isNSCont_isCont_iff RS sym,isNSCont_def,hypreal_of_real_mult]));
   9.611 +qed "isCont_mult";
   9.612 +
   9.613 +(*-------------------------------------------
   9.614 +     composition of continuous functions
   9.615 +     Note very short straightforard proof!
   9.616 + ------------------------------------------*)
   9.617 +Goal "[| isCont f a; isCont g (f a) |] \
   9.618 +\     ==> isCont (g o f) a";
   9.619 +by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
   9.620 +              isNSCont_def,starfun_o RS sym]));
   9.621 +qed "isCont_o";
   9.622 +
   9.623 +Goal "[| isCont f a; isCont g (f a) |] \
   9.624 +\     ==> isCont (%x. g (f x)) a";
   9.625 +by (auto_tac (claset() addDs [isCont_o],simpset() addsimps [o_def]));
   9.626 +qed "isCont_o2";
   9.627 +
   9.628 +Goalw [isNSCont_def] "isNSCont f a ==> isNSCont (%x. - f x) a";
   9.629 +by (auto_tac (claset(),simpset() addsimps [starfun_minus RS sym, 
   9.630 +    hypreal_of_real_minus])); 
   9.631 +qed "isNSCont_minus";
   9.632 +
   9.633 +Goal "isCont f a ==> isCont (%x. - f x) a";
   9.634 +by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
   9.635 +              isNSCont_minus]));
   9.636 +qed "isCont_minus";
   9.637 +
   9.638 +Goalw [isCont_def]  
   9.639 +      "[| isCont f x; f x ~= #0 |] ==> isCont (%x. rinv (f x)) x";
   9.640 +by (blast_tac (claset() addIs [LIM_rinv]) 1);
   9.641 +qed "isCont_rinv";
   9.642 +
   9.643 +Goal "[| isNSCont f x; f x ~= #0 |] ==> isNSCont (%x. rinv (f x)) x";
   9.644 +by (auto_tac (claset() addIs [isCont_rinv],simpset() addsimps 
   9.645 +    [isNSCont_isCont_iff]));
   9.646 +qed "isNSCont_rinv";
   9.647 +
   9.648 +Goalw [real_diff_def] 
   9.649 +      "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) - g(x)) a";
   9.650 +by (auto_tac (claset() addIs [isCont_add,isCont_minus],simpset()));
   9.651 +qed "isCont_diff";
   9.652 +
   9.653 +Goalw [isCont_def]  "isCont (%x. k) a";
   9.654 +by (Simp_tac 1);
   9.655 +qed "isCont_const";
   9.656 +Addsimps [isCont_const];
   9.657 +
   9.658 +Goalw [isNSCont_def]  "isNSCont (%x. k) a";
   9.659 +by (Simp_tac 1);
   9.660 +qed "isNSCont_const";
   9.661 +Addsimps [isNSCont_const];
   9.662 +
   9.663 +Goalw [isNSCont_def]  "isNSCont abs a";
   9.664 +by (auto_tac (claset() addIs [inf_close_hrabs],simpset() addsimps 
   9.665 +    [hypreal_of_real_hrabs RS sym,starfun_rabs_hrabs]));
   9.666 +qed "isNSCont_rabs";
   9.667 +Addsimps [isNSCont_rabs];
   9.668 +
   9.669 +Goal "isCont abs a";
   9.670 +by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym]));
   9.671 +qed "isCont_rabs";
   9.672 +Addsimps [isCont_rabs];
   9.673 +
   9.674 +(****************************************************************
   9.675 +(* Leave as commented until I add topology theory or remove? *)
   9.676 +(*------------------------------------------------------------
   9.677 +  Elementary topology proof for a characterisation of 
   9.678 +  continuity now: a function f is continuous if and only 
   9.679 +  if the inverse image, {x. f(x) : A}, of any open set A 
   9.680 +  is always an open set
   9.681 + ------------------------------------------------------------*)
   9.682 +Goal "!!A. [| isNSopen A; ALL x. isNSCont f x |] \
   9.683 +\              ==> isNSopen {x. f x : A}";
   9.684 +by (auto_tac (claset(),simpset() addsimps [isNSopen_iff1]));
   9.685 +by (dtac (mem_monad_inf_close RS inf_close_sym) 1);
   9.686 +by (dres_inst_tac [("x","a")] spec 1);
   9.687 +by (dtac isNSContD 1 THEN assume_tac 1);
   9.688 +by (dtac bspec 1 THEN assume_tac 1);
   9.689 +by (dres_inst_tac [("x","( *f* f) x")] inf_close_mem_monad2 1);
   9.690 +by (blast_tac (claset() addIs [starfun_mem_starset]) 1);
   9.691 +qed "isNSCont_isNSopen";
   9.692 +
   9.693 +Goalw [isNSCont_def]
   9.694 +          "!!x. ALL A. isNSopen A --> isNSopen {x. f x : A} \
   9.695 +\              ==> isNSCont f x";
   9.696 +by (auto_tac (claset() addSIs [(mem_infmal_iff RS iffD1) RS 
   9.697 +     (inf_close_minus_iff RS iffD2)],simpset() addsimps 
   9.698 +      [Infinitesimal_def,SReal_iff]));
   9.699 +by (dres_inst_tac [("x","{z. abs(z + -f(x)) < ya}")] spec 1);
   9.700 +by (etac (isNSopen_open_interval RSN (2,impE)) 1);
   9.701 +by (auto_tac (claset(),simpset() addsimps [isNSopen_def,isNSnbhd_def]));
   9.702 +by (dres_inst_tac [("x","x")] spec 1);
   9.703 +by (auto_tac (claset() addDs [inf_close_sym RS inf_close_mem_monad],
   9.704 +    simpset() addsimps [hypreal_of_real_zero RS sym,STAR_starfun_rabs_add_minus]));
   9.705 +qed "isNSopen_isNSCont";
   9.706 +
   9.707 +Goal "(ALL x. isNSCont f x) = \
   9.708 +\     (ALL A. isNSopen A --> isNSopen {x. f(x) : A})";
   9.709 +by (blast_tac (claset() addIs [isNSCont_isNSopen,
   9.710 +    isNSopen_isNSCont]) 1);
   9.711 +qed "isNSCont_isNSopen_iff";
   9.712 +
   9.713 +(*------- Standard version of same theorem --------*)
   9.714 +Goal "(ALL x. isCont f x) = \
   9.715 +\         (ALL A. isopen A --> isopen {x. f(x) : A})";
   9.716 +by (auto_tac (claset() addSIs [isNSCont_isNSopen_iff],
   9.717 +              simpset() addsimps [isNSopen_isopen_iff RS sym,
   9.718 +              isNSCont_isCont_iff RS sym]));
   9.719 +qed "isCont_isopen_iff";
   9.720 +*******************************************************************)
   9.721 +
   9.722 +(*-----------------------------------------------------------------
   9.723 +                        Uniform continuity
   9.724 + ------------------------------------------------------------------*)
   9.725 +Goalw [isNSUCont_def] 
   9.726 +      "[| isNSUCont f; x @= y|] ==> (*f* f) x @= (*f* f) y";
   9.727 +by (Blast_tac 1);
   9.728 +qed "isNSUContD";
   9.729 +
   9.730 +Goalw [isUCont_def,isCont_def,LIM_def]
   9.731 +     "isUCont f ==> EX x. isCont f x";
   9.732 +by (Fast_tac 1);
   9.733 +qed "isUCont_isCont";
   9.734 +
   9.735 +Goalw [isNSUCont_def,isUCont_def,inf_close_def] 
   9.736 +     "isUCont f ==> isNSUCont f";
   9.737 +by (asm_full_simp_tac (simpset() addsimps 
   9.738 +    [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   9.739 +by (Step_tac 1);
   9.740 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   9.741 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   9.742 +by (auto_tac (claset(),simpset() addsimps [starfun,
   9.743 +    hypreal_minus, hypreal_add]));
   9.744 +by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2 THEN Step_tac 1);
   9.745 +by (dres_inst_tac [("x","u")] spec 1 THEN Clarify_tac 1);
   9.746 +by (dres_inst_tac [("x","s")] spec 1 THEN Clarify_tac 1);
   9.747 +by (subgoal_tac "ALL n::nat. abs ((xa n) + - (xb n)) < s --> abs (f (xa n) + - f (xb n)) < u" 1);
   9.748 +by (Blast_tac 2);
   9.749 +by (thin_tac "ALL x y. abs (x + - y) < s --> abs (f x + - f y) < u" 1);
   9.750 +by (dtac FreeUltrafilterNat_all 1);
   9.751 +by (Ultra_tac 1);
   9.752 +qed "isUCont_isNSUCont";
   9.753 +
   9.754 +Goal "!!x. ALL s. #0 < s --> \
   9.755 +\              (EX xa y. abs (xa + - y) < s  & \
   9.756 +\              r <= abs (f xa + -f y)) ==> \
   9.757 +\              ALL n::nat. EX xa y.  \
   9.758 +\              abs(xa + -y) < rinv(real_of_posnat n) & \
   9.759 +\              r <= abs(f xa + -f y)";
   9.760 +by (Step_tac 1);
   9.761 +by (cut_inst_tac [("n1","n")] (real_of_posnat_gt_zero RS real_rinv_gt_zero) 1);
   9.762 +by Auto_tac;
   9.763 +val lemma_LIMu = result();
   9.764 +
   9.765 +Goal "!!x. ALL s. #0 < s --> \
   9.766 +\              (EX xa y. abs (xa + - y) < s  & \
   9.767 +\              r <= abs (f xa + -f y)) ==> \
   9.768 +\              EX X Y. ALL n::nat. \
   9.769 +\              abs(X n + -(Y n)) < rinv(real_of_posnat n) & \
   9.770 +\              r <= abs(f (X n) + -f (Y n))";
   9.771 +by (dtac lemma_LIMu 1);
   9.772 +by (dtac choice 1);
   9.773 +by (Step_tac 1);
   9.774 +by (dtac choice 1);
   9.775 +by (Blast_tac 1);
   9.776 +val lemma_skolemize_LIM2u = result();
   9.777 +
   9.778 +Goal "ALL n. abs (X n + -Y n) < rinv (real_of_posnat  n) & \
   9.779 +\         r <= abs (f (X n) + - f(Y n)) ==> \
   9.780 +\         ALL n. abs (X n + - Y n) < rinv (real_of_posnat  n)";
   9.781 +by (Auto_tac );
   9.782 +val lemma_simpu = result();
   9.783 +
   9.784 +Goal "{n. f (X n) + - f(Y n) = Ya n} Int \
   9.785 +\         {n. abs (X n + - Y n) < rinv (real_of_posnat  n) & \
   9.786 +\             r <= abs (f (X n) + - f(Y n))} <= \
   9.787 +\         {n. r <= abs (Ya n)}";
   9.788 +by (Auto_tac);
   9.789 +val lemma_Intu = result ();
   9.790 +
   9.791 +Goalw [isNSUCont_def,isUCont_def,inf_close_def] 
   9.792 +     "isNSUCont f ==> isUCont f";
   9.793 +by (asm_full_simp_tac (simpset() addsimps 
   9.794 +    [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   9.795 +by (EVERY1[Step_tac, rtac ccontr, Asm_full_simp_tac]);
   9.796 +by (fold_tac [real_le_def]);
   9.797 +by (dtac lemma_skolemize_LIM2u 1);
   9.798 +by (Step_tac 1);
   9.799 +by (dres_inst_tac [("x","Abs_hypreal(hyprel^^{X})")] spec 1);
   9.800 +by (dres_inst_tac [("x","Abs_hypreal(hyprel^^{Y})")] spec 1);
   9.801 +by (asm_full_simp_tac (simpset() addsimps [starfun,
   9.802 +    hypreal_minus,hypreal_add]) 1);
   9.803 +by (Auto_tac);
   9.804 +by (dtac (lemma_simpu RS real_seq_to_hypreal_Infinitesimal2) 1);
   9.805 +by (asm_full_simp_tac (simpset() addsimps 
   9.806 +    [Infinitesimal_FreeUltrafilterNat_iff,
   9.807 +     hypreal_minus,hypreal_add]) 1);
   9.808 +by (Blast_tac 1);
   9.809 +by (rotate_tac 2 1);
   9.810 +by (dres_inst_tac [("x","r")] spec 1);
   9.811 +by (Clarify_tac 1);
   9.812 +by (dtac FreeUltrafilterNat_all 1);
   9.813 +by (Ultra_tac 1);
   9.814 +qed "isNSUCont_isUCont";
   9.815 +
   9.816 +(*------------------------------------------------------------------
   9.817 +                         Derivatives
   9.818 + ------------------------------------------------------------------*)
   9.819 +Goalw [deriv_def] 
   9.820 +      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))*rinv(h)) -- #0 --> D)";
   9.821 +by (Blast_tac 1);        
   9.822 +qed "DERIV_iff";
   9.823 +
   9.824 +Goalw [deriv_def] 
   9.825 +      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))*rinv(h)) -- #0 --NS> D)";
   9.826 +by (simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   9.827 +qed "DERIV_NS_iff";
   9.828 +
   9.829 +Goalw [deriv_def] 
   9.830 +      "DERIV f x :> D \
   9.831 +\      ==> (%h. (f(x + h) + - f(x))*rinv(h)) -- #0 --> D";
   9.832 +by (Blast_tac 1);        
   9.833 +qed "DERIVD";
   9.834 +
   9.835 +Goalw [deriv_def] "DERIV f x :> D ==> \
   9.836 +\          (%h. (f(x + h) + - f(x))*rinv(h)) -- #0 --NS> D";
   9.837 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   9.838 +qed "NS_DERIVD";
   9.839 +
   9.840 +(* Uniqueness *)
   9.841 +Goalw [deriv_def] 
   9.842 +      "!!f. [| DERIV f x :> D; DERIV f x :> E |] ==> D = E";
   9.843 +by (blast_tac (claset() addIs [LIM_unique]) 1);
   9.844 +qed "DERIV_unique";
   9.845 +
   9.846 +Goalw [nsderiv_def] 
   9.847 +     "!!f. [| NSDERIV f x :> D; NSDERIV f x :> E |] ==> D = E";
   9.848 +by (cut_facts_tac [Infinitesimal_epsilon,
   9.849 +             hypreal_epsilon_not_zero] 1);
   9.850 +by (auto_tac (claset() addSDs [bspec] addSIs 
   9.851 +   [inj_hypreal_of_real RS injD] addDs [inf_close_trans3],simpset()));
   9.852 +qed "NSDeriv_unique";
   9.853 +
   9.854 +(*------------------------------------------------------------------------
   9.855 +                          Differentiable
   9.856 + ------------------------------------------------------------------------*)
   9.857 +
   9.858 +Goalw [differentiable_def] 
   9.859 +      "!!f. f differentiable x ==> EX D. DERIV f x :> D";
   9.860 +by (assume_tac 1);
   9.861 +qed "differentiableD";
   9.862 +
   9.863 +Goalw [differentiable_def] 
   9.864 +      "!!f. DERIV f x :> D ==> f differentiable x";
   9.865 +by (Blast_tac 1);
   9.866 +qed "differentiableI";
   9.867 +
   9.868 +Goalw [NSdifferentiable_def] 
   9.869 +      "!!f. f NSdifferentiable x ==> EX D. NSDERIV f x :> D";
   9.870 +by (assume_tac 1);
   9.871 +qed "NSdifferentiableD";
   9.872 +
   9.873 +Goalw [NSdifferentiable_def] 
   9.874 +      "!!f. NSDERIV f x :> D ==> f NSdifferentiable x";
   9.875 +by (Blast_tac 1);
   9.876 +qed "NSdifferentiableI";
   9.877 +
   9.878 +(*--------------------------------------------------------
   9.879 +      Alternative definition for differentiability
   9.880 + -------------------------------------------------------*)
   9.881 +
   9.882 +Goalw [LIM_def] 
   9.883 + "((%h. (f(a + h) + - f(a))*rinv(h)) -- #0 --> D) = \
   9.884 +\ ((%x. (f(x) + -f(a))*rinv(x + -a)) -- a --> D)";
   9.885 +by (Step_tac 1);
   9.886 +by (ALLGOALS(dtac spec));
   9.887 +by (Step_tac 1);
   9.888 +by (Blast_tac 1 THEN Blast_tac 2);
   9.889 +by (ALLGOALS(res_inst_tac [("x","s")] exI));
   9.890 +by (Step_tac 1);
   9.891 +by (dres_inst_tac [("x","x + -a")] spec 1);
   9.892 +by (dres_inst_tac [("x","x + a")] spec 2);
   9.893 +by (auto_tac (claset(),simpset() addsimps 
   9.894 +     real_add_ac));
   9.895 +qed "DERIV_LIM_iff";
   9.896 +
   9.897 +Goalw [deriv_def] "(DERIV f x :> D) = \
   9.898 +\         ((%z. (f(z) + -f(x))*rinv(z + -x)) -- x --> D)";
   9.899 +by (simp_tac (simpset() addsimps [DERIV_LIM_iff]) 1);
   9.900 +qed "DERIV_iff2";
   9.901 +
   9.902 +(*--------------------------------------------------------
   9.903 +  Equivalence of NS and standard defs of differentiation
   9.904 + -------------------------------------------------------*)
   9.905 +(*-------------------------------------------
   9.906 +   First NSDERIV in terms of NSLIM 
   9.907 + -------------------------------------------*)
   9.908 +(*--- first equivalence ---*)
   9.909 +Goalw [nsderiv_def,NSLIM_def] 
   9.910 +      "(NSDERIV f x :> D) = ((%h. (f(x + h) + - f(x))*rinv(h)) -- #0 --NS> D)";
   9.911 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_zero]));
   9.912 +by (dres_inst_tac [("x","xa")] bspec 1);
   9.913 +by (rtac ccontr 3);
   9.914 +by (dres_inst_tac [("x","h")] spec 3);
   9.915 +by (auto_tac (claset(),simpset() addsimps [mem_infmal_iff,
   9.916 +    starfun_mult RS sym,starfun_rinv_hrinv,starfun_add RS sym,
   9.917 +    hypreal_of_real_minus,starfun_lambda_cancel]));
   9.918 +qed "NSDERIV_NSLIM_iff";
   9.919 +
   9.920 +(*--- second equivalence ---*)
   9.921 +Goal "(NSDERIV f x :> D) = \
   9.922 +\         ((%z. (f(z) + -f(x))*rinv(z + -x)) -- x --NS> D)";
   9.923 +by (full_simp_tac (simpset() addsimps 
   9.924 +    [NSDERIV_NSLIM_iff,DERIV_LIM_iff,LIM_NSLIM_iff RS sym]) 1);
   9.925 +qed "NSDERIV_NSLIM_iff2";
   9.926 +
   9.927 +(* while we're at it! *)
   9.928 +Goalw [real_diff_def]
   9.929 +     "(NSDERIV f x :> D) = \
   9.930 +\     (ALL xa. \
   9.931 +\       xa ~= hypreal_of_real x & xa @= hypreal_of_real x --> \
   9.932 +\       (*f* (%z. (f z - f x) * rinv (z - x))) xa @= hypreal_of_real D)";
   9.933 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_NSLIM_iff2,
   9.934 +    NSLIM_def]));
   9.935 +qed "NSDERIV_iff2";
   9.936 +
   9.937 +Addsimps [inf_close_refl];
   9.938 +Goal "(NSDERIV f x :> D) ==> \
   9.939 +\    (ALL xa. \
   9.940 +\       xa @= hypreal_of_real x --> \
   9.941 +\       (*f* (%z. f z - f x)) xa @= hypreal_of_real D * (xa - hypreal_of_real x))";
   9.942 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_iff2]));
   9.943 +by (case_tac "xa = hypreal_of_real x" 1);
   9.944 +by (auto_tac (claset(),simpset() addsimps [hypreal_diff_def,
   9.945 +    hypreal_of_real_zero]));
   9.946 +by (dres_inst_tac [("x","xa")] spec 1);
   9.947 +by Auto_tac;
   9.948 +by (dres_inst_tac [("c","xa - hypreal_of_real x"),("b","hypreal_of_real D")]
   9.949 +     inf_close_mult1 1);
   9.950 +by (ALLGOALS(dtac (hypreal_not_eq_minus_iff RS iffD1)));
   9.951 +by (subgoal_tac "(*f* (%z. z - x)) xa ~= (0::hypreal)" 2);
   9.952 +by (dtac (starfun_hrinv2 RS sym) 2);
   9.953 +by (auto_tac (claset() addDs [hypreal_mult_hrinv_left],
   9.954 +    simpset() addsimps [starfun_mult RS sym,
   9.955 +    hypreal_mult_assoc,starfun_add RS sym,real_diff_def,
   9.956 +    starfun_Id,hypreal_of_real_minus,hypreal_diff_def,
   9.957 +    (inf_close_minus_iff RS iffD1) RS (mem_infmal_iff RS iffD2), 
   9.958 +    Infinitesimal_subset_HFinite RS subsetD]));
   9.959 +qed "NSDERIVD5";
   9.960 +
   9.961 +Goal "(NSDERIV f x :> D) ==> \
   9.962 +\     (ALL h: Infinitesimal. \
   9.963 +\              ((*f* f)(hypreal_of_real x + h) - \
   9.964 +\                hypreal_of_real (f x))@= (hypreal_of_real D) * h)";
   9.965 +by (auto_tac (claset(),simpset() addsimps [nsderiv_def]));
   9.966 +by (case_tac "h = (0::hypreal)" 1);
   9.967 +by (auto_tac (claset(),simpset() addsimps [hypreal_diff_def]));
   9.968 +by (dres_inst_tac [("x","h")] bspec 1);
   9.969 +by (dres_inst_tac [("c","h")] inf_close_mult1 2);
   9.970 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
   9.971 +    simpset() addsimps [hypreal_mult_assoc,hypreal_diff_def]));
   9.972 +qed "NSDERIVD4";
   9.973 +
   9.974 +Goal "(NSDERIV f x :> D) ==> \
   9.975 +\     (ALL h: Infinitesimal - {0}. \
   9.976 +\              ((*f* f)(hypreal_of_real x + h) - \
   9.977 +\                hypreal_of_real (f x))@= (hypreal_of_real D) * h)";
   9.978 +by (auto_tac (claset(),simpset() addsimps [nsderiv_def]));
   9.979 +by (rtac ccontr 1 THEN dres_inst_tac [("x","h")] bspec 1);
   9.980 +by (dres_inst_tac [("c","h")] inf_close_mult1 2);
   9.981 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
   9.982 +    simpset() addsimps [hypreal_mult_assoc,hypreal_diff_def]));
   9.983 +qed "NSDERIVD3";
   9.984 +
   9.985 +(*--------------------------------------------------------------
   9.986 +          Now equivalence between NSDERIV and DERIV
   9.987 + -------------------------------------------------------------*)
   9.988 +Goalw [deriv_def] "(NSDERIV f x :> D) = (DERIV f x :> D)";
   9.989 +by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,LIM_NSLIM_iff]) 1);
   9.990 +qed "NSDERIV_DERIV_iff";
   9.991 +
   9.992 +(*---------------------------------------------------
   9.993 +         Differentiability implies continuity 
   9.994 +         nice and simple "algebraic" proof
   9.995 + --------------------------------------------------*)
   9.996 +Goalw [nsderiv_def]
   9.997 +      "NSDERIV f x :> D ==> isNSCont f x";
   9.998 +by (auto_tac (claset(),simpset() addsimps 
   9.999 +        [isNSCont_NSLIM_iff,NSLIM_def]));
  9.1000 +by (dtac (inf_close_minus_iff RS iffD1) 1);
  9.1001 +by (dtac (hypreal_not_eq_minus_iff RS iffD1) 1);
  9.1002 +by (dres_inst_tac [("x","-hypreal_of_real x + xa")] bspec 1);
  9.1003 +by (asm_full_simp_tac (simpset() addsimps 
  9.1004 +    [hypreal_add_assoc RS sym]) 2);
  9.1005 +by (auto_tac (claset(),simpset() addsimps 
  9.1006 +    [mem_infmal_iff RS sym,hypreal_add_commute]));
  9.1007 +by (dres_inst_tac [("c","xa + -hypreal_of_real x")] inf_close_mult1 1);
  9.1008 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite
  9.1009 +    RS subsetD],simpset() addsimps [hypreal_mult_assoc]));
  9.1010 +by (dres_inst_tac [("x3","D")] (HFinite_hypreal_of_real RSN
  9.1011 +    (2,Infinitesimal_HFinite_mult) RS (mem_infmal_iff RS iffD1)) 1);
  9.1012 +by (blast_tac (claset() addIs [inf_close_trans,
  9.1013 +    hypreal_mult_commute RS subst,
  9.1014 +    (inf_close_minus_iff RS iffD2)]) 1);
  9.1015 +qed "NSDERIV_isNSCont";
  9.1016 +
  9.1017 +(* Now Sandard proof *)
  9.1018 +Goal "DERIV f x :> D ==> isCont f x";
  9.1019 +by (asm_full_simp_tac (simpset() addsimps 
  9.1020 +    [NSDERIV_DERIV_iff RS sym, isNSCont_isCont_iff RS sym,
  9.1021 +     NSDERIV_isNSCont]) 1);
  9.1022 +qed "DERIV_isCont";
  9.1023 +
  9.1024 +(*----------------------------------------------------------------------------
  9.1025 +      Differentiation rules for combinations of functions
  9.1026 +      follow from clear, straightforard, algebraic 
  9.1027 +      manipulations
  9.1028 + ----------------------------------------------------------------------------*)
  9.1029 +(*-------------------------
  9.1030 +    Constant function
  9.1031 + ------------------------*)
  9.1032 +
  9.1033 +(* use simple constant nslimit theorem *)
  9.1034 +Goal "(NSDERIV (%x. k) x :> #0)";
  9.1035 +by (simp_tac (simpset() addsimps 
  9.1036 +    [NSDERIV_NSLIM_iff,real_add_minus]) 1);
  9.1037 +qed "NSDERIV_const";
  9.1038 +Addsimps [NSDERIV_const];
  9.1039 +
  9.1040 +Goal "(DERIV (%x. k) x :> #0)";
  9.1041 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
  9.1042 +qed "DERIV_const";
  9.1043 +Addsimps [DERIV_const];
  9.1044 +
  9.1045 +(*-----------------------------------------------------
  9.1046 +    Sum of functions- proved easily
  9.1047 + ----------------------------------------------------*)
  9.1048 +Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  9.1049 +\     ==> NSDERIV (%x. f x + g x) x :> Da + Db";
  9.1050 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
  9.1051 +    NSLIM_def]) 1 THEN REPEAT(Step_tac 1));
  9.1052 +by (auto_tac (claset(),simpset() addsimps [starfun_add RS sym,
  9.1053 +    starfun_mult RS sym,hypreal_of_real_minus,hypreal_of_real_add,
  9.1054 +    hypreal_minus_add_distrib,hypreal_add_mult_distrib]));
  9.1055 +by (thin_tac "xa @= hypreal_of_real #0" 1 THEN dtac inf_close_add 1);
  9.1056 +by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
  9.1057 +qed "NSDERIV_add";
  9.1058 +
  9.1059 +(* Standard theorem *)
  9.1060 +Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
  9.1061 +\     ==> DERIV (%x. f x + g x) x :> Da + Db";
  9.1062 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_add,
  9.1063 +    NSDERIV_DERIV_iff RS sym]) 1);
  9.1064 +qed "DERIV_add";
  9.1065 +
  9.1066 +(*-----------------------------------------------------
  9.1067 +  Product of functions - Proof is trivial but tedious
  9.1068 +  and long due to rearrangement of terms  
  9.1069 + ----------------------------------------------------*)
  9.1070 +(* lemma - terms manipulation tedious as usual*)
  9.1071 +
  9.1072 +Goal "((a::real)*b) + -(c*d) = (b*(a + -c)) + \
  9.1073 +\                           (c*(b + -d))";
  9.1074 +by (full_simp_tac (simpset() addsimps [real_add_mult_distrib2,
  9.1075 +    real_minus_mult_eq2 RS sym,real_mult_commute]) 1);
  9.1076 +val lemma_nsderiv1 = result();
  9.1077 +
  9.1078 +Goal "[| (x + y) * hrinv z = hypreal_of_real D + yb; z ~= 0; \
  9.1079 +\        z : Infinitesimal; yb : Infinitesimal |] \
  9.1080 +\     ==> x + y @= 0";
  9.1081 +by (forw_inst_tac [("c1","z")] (hypreal_mult_right_cancel 
  9.1082 +               RS iffD2) 1 THEN assume_tac 1);
  9.1083 +by (thin_tac "(x + y) * hrinv z = hypreal_of_real  D + yb" 1);
  9.1084 +by (auto_tac (claset() addSIs [Infinitesimal_HFinite_mult2,
  9.1085 +              HFinite_add],simpset() addsimps [hypreal_mult_assoc,
  9.1086 +              mem_infmal_iff RS sym]));
  9.1087 +by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
  9.1088 +val lemma_nsderiv2 = result();
  9.1089 +
  9.1090 +Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  9.1091 +\     ==> NSDERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))";
  9.1092 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
  9.1093 +    NSLIM_def]) 1 THEN REPEAT(Step_tac 1));
  9.1094 +by (auto_tac (claset(),simpset() addsimps [starfun_mult RS sym,
  9.1095 +    starfun_add RS sym,starfun_lambda_cancel,
  9.1096 +    starfun_rinv_hrinv,hypreal_of_real_zero,lemma_nsderiv1]));
  9.1097 +by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib]) 1);
  9.1098 +by (REPEAT(dtac (bex_Infinitesimal_iff2 RS iffD2) 1));
  9.1099 +by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc,
  9.1100 +    hypreal_of_real_minus]));
  9.1101 +by (dres_inst_tac [("D","Db")] lemma_nsderiv2 1);
  9.1102 +by (dtac ((inf_close_minus_iff RS iffD2) RS 
  9.1103 +    (bex_Infinitesimal_iff2 RS iffD2)) 4);
  9.1104 +by (auto_tac (claset() addSIs [inf_close_add_mono1],
  9.1105 +    simpset() addsimps [hypreal_of_real_add,hypreal_add_mult_distrib,
  9.1106 +    hypreal_add_mult_distrib2,hypreal_of_real_mult,hypreal_mult_commute,
  9.1107 +    hypreal_add_assoc]));
  9.1108 +by (res_inst_tac [("w1","hypreal_of_real Db * hypreal_of_real (f x)")]
  9.1109 +    (hypreal_add_commute RS subst) 1);
  9.1110 +by (auto_tac (claset() addSIs [Infinitesimal_add_inf_close_self2 RS 
  9.1111 +    inf_close_sym,Infinitesimal_add,Infinitesimal_mult,
  9.1112 +    Infinitesimal_hypreal_of_real_mult,Infinitesimal_hypreal_of_real_mult2 ],
  9.1113 +    simpset() addsimps [hypreal_add_assoc RS sym]));
  9.1114 +qed "NSDERIV_mult";
  9.1115 +
  9.1116 +Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
  9.1117 +\     ==> DERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))";
  9.1118 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_mult,
  9.1119 +    NSDERIV_DERIV_iff RS sym]) 1);
  9.1120 +qed "DERIV_mult";
  9.1121 +
  9.1122 +(*----------------------------
  9.1123 +   Multiplying by a constant
  9.1124 + ---------------------------*)
  9.1125 +Goal "NSDERIV f x :> D \
  9.1126 +\     ==> NSDERIV (%x. c * f x) x :> c*D";
  9.1127 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
  9.1128 +    real_minus_mult_eq2,real_add_mult_distrib2 RS sym,
  9.1129 +    real_mult_assoc] delsimps [real_minus_mult_eq2 RS sym]) 1);
  9.1130 +by (etac (NSLIM_const RS NSLIM_mult) 1);
  9.1131 +qed "NSDERIV_cmult";
  9.1132 +
  9.1133 +(* let's do the standard proof though theorem *)
  9.1134 +(* LIM_mult2 follows from a NS proof          *)
  9.1135 +
  9.1136 +Goalw [deriv_def] 
  9.1137 +      "DERIV f x :> D \
  9.1138 +\      ==> DERIV (%x. c * f x) x :> c*D";
  9.1139 +by (asm_full_simp_tac (simpset() addsimps [
  9.1140 +    real_minus_mult_eq2,real_add_mult_distrib2 RS sym,
  9.1141 +    real_mult_assoc] delsimps [real_minus_mult_eq2 RS sym]) 1);
  9.1142 +by (etac (LIM_const RS LIM_mult2) 1);
  9.1143 +qed "DERIV_cmult";
  9.1144 +
  9.1145 +(*--------------------------------
  9.1146 +   Negation of function
  9.1147 + -------------------------------*)
  9.1148 +Goal "NSDERIV f x :> D \
  9.1149 +\      ==> NSDERIV (%x. -(f x)) x :> -D";
  9.1150 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
  9.1151 +by (res_inst_tac [("t","f x")] (real_minus_minus RS subst) 1);
  9.1152 +by (asm_simp_tac (simpset() addsimps [real_minus_add_distrib RS sym,
  9.1153 +    real_minus_mult_eq1 RS sym] delsimps [real_minus_add_distrib,
  9.1154 +    real_minus_minus]) 1);
  9.1155 +by (etac NSLIM_minus 1);
  9.1156 +qed "NSDERIV_minus";
  9.1157 +
  9.1158 +Goal "DERIV f x :> D \
  9.1159 +\     ==> DERIV (%x. -(f x)) x :> -D";
  9.1160 +by (asm_full_simp_tac (simpset() addsimps 
  9.1161 +    [NSDERIV_minus,NSDERIV_DERIV_iff RS sym]) 1);
  9.1162 +qed "DERIV_minus";
  9.1163 +
  9.1164 +(*-------------------------------
  9.1165 +   Subtraction
  9.1166 + ------------------------------*)
  9.1167 +Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  9.1168 +\     ==> NSDERIV (%x. f x + -g x) x :> Da + -Db";
  9.1169 +by (blast_tac (claset() addDs [NSDERIV_add,NSDERIV_minus]) 1);
  9.1170 +qed "NSDERIV_add_minus";
  9.1171 +
  9.1172 +Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
  9.1173 +\     ==> DERIV (%x. f x + -g x) x :> Da + -Db";
  9.1174 +by (blast_tac (claset() addDs [DERIV_add,DERIV_minus]) 1);
  9.1175 +qed "DERIV_add_minus";
  9.1176 +
  9.1177 +Goalw [real_diff_def]
  9.1178 +     "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  9.1179 +\     ==> NSDERIV (%x. f x - g x) x :> Da - Db";
  9.1180 +by (blast_tac (claset() addIs [NSDERIV_add_minus]) 1);
  9.1181 +qed "NSDERIV_diff";
  9.1182 +
  9.1183 +Goalw [real_diff_def]
  9.1184 +     "[| DERIV f x :> Da; DERIV g x :> Db |] \
  9.1185 +\      ==> DERIV (%x. f x - g x) x :> Da - Db";
  9.1186 +by (blast_tac (claset() addIs [DERIV_add_minus]) 1);
  9.1187 +qed "DERIV_diff";
  9.1188 +
  9.1189 +(*---------------------------------------------------------------
  9.1190 +                     (NS) Increment
  9.1191 + ---------------------------------------------------------------*)
  9.1192 +Goalw [increment_def] 
  9.1193 +      "f NSdifferentiable x ==> \
  9.1194 +\     increment f x h = (*f* f) (hypreal_of_real(x) + h) + \
  9.1195 +\     -hypreal_of_real (f x)";
  9.1196 +by (Blast_tac 1);
  9.1197 +qed "incrementI";
  9.1198 +
  9.1199 +Goal "NSDERIV f x :> D ==> \
  9.1200 +\    increment f x h = (*f* f) (hypreal_of_real(x) + h) + \
  9.1201 +\    -hypreal_of_real (f x)";
  9.1202 +by (etac (NSdifferentiableI RS incrementI) 1);
  9.1203 +qed "incrementI2";
  9.1204 +
  9.1205 +(* The Increment theorem -- Keisler p. 65 *)
  9.1206 +Goal "[| NSDERIV f x :> D; h: Infinitesimal; h ~= 0 |] \
  9.1207 +\     ==> EX e: Infinitesimal. increment f x h = hypreal_of_real(D)*h + e*h";
  9.1208 +by (forw_inst_tac [("h","h")] incrementI2 1 THEN rewtac nsderiv_def);
  9.1209 +by (dtac bspec 1 THEN Auto_tac);
  9.1210 +by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1 THEN Step_tac 1);
  9.1211 +by (forw_inst_tac [("b1","hypreal_of_real(D) + y")] 
  9.1212 +   (hypreal_mult_right_cancel RS iffD2) 1);
  9.1213 +by (thin_tac "((*f* f) (hypreal_of_real(x) + h) + \
  9.1214 +\   - hypreal_of_real (f x)) * hrinv h = hypreal_of_real(D) + y" 2);
  9.1215 +by (assume_tac 1);
  9.1216 +by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc,
  9.1217 +    hypreal_add_mult_distrib]));
  9.1218 +qed "increment_thm";
  9.1219 +
  9.1220 +Goal "[| NSDERIV f x :> D; h @= 0; h ~= 0 |] \
  9.1221 +\      ==> EX e: Infinitesimal. increment f x h = \
  9.1222 +\             hypreal_of_real(D)*h + e*h";
  9.1223 +by (blast_tac (claset() addSDs [mem_infmal_iff RS iffD2] 
  9.1224 +    addSIs [increment_thm]) 1);
  9.1225 +qed "increment_thm2";
  9.1226 +
  9.1227 +Goal "[| NSDERIV f x :> D; h @= 0; h ~= 0 |] \
  9.1228 +\     ==> increment f x h @= 0";
  9.1229 +by (dtac increment_thm2 1 THEN auto_tac (claset() addSIs 
  9.1230 +    [Infinitesimal_HFinite_mult2,HFinite_add],simpset() addsimps 
  9.1231 +    [hypreal_add_mult_distrib RS sym,mem_infmal_iff RS sym]));
  9.1232 +by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
  9.1233 +qed "increment_inf_close_zero";
  9.1234 +
  9.1235 +(*---------------------------------------------------------------
  9.1236 +   Similarly to the above, the chain rule admits an entirely
  9.1237 +   straightforward derivation. Compare this with Harrison's
  9.1238 +   HOL proof of the chain rule, which proved to be trickier and
  9.1239 +   required an alternative characterisation of differentiability- 
  9.1240 +   the so-called Carathedory derivative. Our main problem is
  9.1241 +   manipulation of terms.
  9.1242 + --------------------------------------------------------------*)
  9.1243 +(* lemmas *)
  9.1244 +Goalw [nsderiv_def] 
  9.1245 +      "!!f. [| NSDERIV g x :> D; \
  9.1246 +\              (*f* g) (hypreal_of_real(x) + xa) = hypreal_of_real(g x);\
  9.1247 +\              xa : Infinitesimal;\
  9.1248 +\              xa ~= 0 \
  9.1249 +\           |] ==> D = #0";
  9.1250 +by (dtac bspec 1);
  9.1251 +by (Auto_tac);
  9.1252 +by (asm_full_simp_tac (simpset() addsimps 
  9.1253 +    [hypreal_of_real_zero RS sym]) 1);
  9.1254 +qed "NSDERIV_zero";
  9.1255 +
  9.1256 +(* can be proved differently using NSLIM_isCont_iff *)
  9.1257 +Goalw [nsderiv_def] 
  9.1258 +      "!!f. [| NSDERIV f x :> D; \
  9.1259 +\              h: Infinitesimal; h ~= 0 \
  9.1260 +\           |] ==> (*f* f) (hypreal_of_real(x) + h) + -hypreal_of_real(f x) @= 0";    
  9.1261 +by (asm_full_simp_tac (simpset() addsimps 
  9.1262 +    [mem_infmal_iff RS sym]) 1);
  9.1263 +by (rtac Infinitesimal_ratio 1);
  9.1264 +by (rtac inf_close_hypreal_of_real_HFinite 3);
  9.1265 +by (Auto_tac);
  9.1266 +qed "NSDERIV_inf_close";
  9.1267 +
  9.1268 +(*--------------------------------------------------------------- 
  9.1269 +   from one version of differentiability 
  9.1270 + 
  9.1271 +                f(x) - f(a)
  9.1272 +              --------------- @= Db
  9.1273 +                  x - a
  9.1274 + ---------------------------------------------------------------*)
  9.1275 +Goal "[| NSDERIV f (g x) :> Da; \
  9.1276 +\        (*f* g) (hypreal_of_real(x) + xa) ~= hypreal_of_real (g x); \
  9.1277 +\        (*f* g) (hypreal_of_real(x) + xa) @= hypreal_of_real (g x) \
  9.1278 +\     |] ==> ((*f* f) ((*f* g) (hypreal_of_real(x) + xa)) \
  9.1279 +\                  + - hypreal_of_real (f (g x)))* \
  9.1280 +\                  hrinv ((*f* g) (hypreal_of_real(x) + xa) + \
  9.1281 +\                        - hypreal_of_real (g x)) @= hypreal_of_real(Da)";
  9.1282 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_NSLIM_iff2,
  9.1283 +    NSLIM_def,starfun_mult RS sym,hypreal_of_real_minus,
  9.1284 +    starfun_add RS sym,starfun_hrinv3]));
  9.1285 +qed "NSDERIVD1";
  9.1286 +
  9.1287 +(*-------------------------------------------------------------- 
  9.1288 +   from other version of differentiability 
  9.1289 +
  9.1290 +                f(x + h) - f(x)
  9.1291 +               ----------------- @= Db
  9.1292 +                       h
  9.1293 + --------------------------------------------------------------*)
  9.1294 +Goal "[| NSDERIV g x :> Db; xa: Infinitesimal; xa ~= 0 |] \
  9.1295 +\     ==> ((*f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real(g x)) * \
  9.1296 +\                     hrinv xa @= hypreal_of_real(Db)";
  9.1297 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_NSLIM_iff,
  9.1298 +    NSLIM_def,starfun_mult RS sym,starfun_rinv_hrinv,
  9.1299 +    starfun_add RS sym,hypreal_of_real_zero,mem_infmal_iff,
  9.1300 +    starfun_lambda_cancel,hypreal_of_real_minus]));
  9.1301 +qed "NSDERIVD2";
  9.1302 +
  9.1303 +(*---------------------------------------------
  9.1304 +  This proof uses both possible definitions
  9.1305 +  for differentiability.
  9.1306 + --------------------------------------------*)
  9.1307 +Goal "[| NSDERIV f (g x) :> Da; NSDERIV g x :> Db |] \
  9.1308 +\     ==> NSDERIV (f o g) x :> Da * Db";
  9.1309 +by (asm_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
  9.1310 +    NSLIM_def,hypreal_of_real_zero,mem_infmal_iff RS sym]) 1 THEN Step_tac 1);
  9.1311 +by (forw_inst_tac [("f","g")] NSDERIV_inf_close 1);
  9.1312 +by (auto_tac (claset(),simpset() addsimps [starfun_add RS sym,
  9.1313 +    hypreal_of_real_minus,starfun_rinv_hrinv,hypreal_of_real_mult,
  9.1314 +    starfun_lambda_cancel2,starfun_o RS sym,starfun_mult RS sym]));
  9.1315 +by (case_tac "(*f* g) (hypreal_of_real(x) + xa) = hypreal_of_real (g x)" 1);
  9.1316 +by (dres_inst_tac [("g","g")] NSDERIV_zero 1);
  9.1317 +by (auto_tac (claset(),simpset() 
  9.1318 +    addsimps [hypreal_of_real_zero,inf_close_refl]));
  9.1319 +by (res_inst_tac [("z1","(*f* g) (hypreal_of_real(x) + xa) + -hypreal_of_real (g x)"),
  9.1320 +    ("y1","hrinv xa")] (lemma_chain RS ssubst) 1);
  9.1321 +by (etac (hypreal_not_eq_minus_iff RS iffD1) 1);
  9.1322 +by (rtac inf_close_mult_hypreal_of_real 1);
  9.1323 +by (blast_tac (claset() addIs [NSDERIVD1,
  9.1324 +    inf_close_minus_iff RS iffD2]) 1);
  9.1325 +by (blast_tac (claset() addIs [NSDERIVD2]) 1);
  9.1326 +qed "NSDERIV_chain";
  9.1327 +
  9.1328 +(* standard version *)
  9.1329 +Goal "!!f. [| DERIV f (g x) :> Da; \
  9.1330 +\                 DERIV g x :> Db \
  9.1331 +\              |] ==> DERIV (f o g) x :> Da * Db";
  9.1332 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym,
  9.1333 +    NSDERIV_chain]) 1);
  9.1334 +qed "DERIV_chain";
  9.1335 +
  9.1336 +Goal "[| DERIV f g x :> Da; DERIV g x :> Db |] \
  9.1337 +\     ==> DERIV (%x. f (g x)) x :> Da * Db";
  9.1338 +by (auto_tac (claset() addDs [DERIV_chain],simpset() addsimps [o_def]));
  9.1339 +qed "DERIV_chain2";
  9.1340 +
  9.1341 +Goal "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E";
  9.1342 +by (Auto_tac);
  9.1343 +val lemma_DERIV_tac = result();
  9.1344 +
  9.1345 +(*------------------------------------------------------------------
  9.1346 +           Differentiation of natural number powers
  9.1347 + ------------------------------------------------------------------*)
  9.1348 +Goal "NSDERIV (%x. x) x :> #1";
  9.1349 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_NSLIM_iff,
  9.1350 +    NSLIM_def,starfun_mult RS sym,starfun_Id,hypreal_of_real_zero,
  9.1351 +    starfun_rinv_hrinv,hypreal_of_real_one] 
  9.1352 +    @ real_add_ac));
  9.1353 +qed "NSDERIV_Id";
  9.1354 +Addsimps [NSDERIV_Id];
  9.1355 +
  9.1356 +Goal "DERIV (%x. x) x :> #1";
  9.1357 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
  9.1358 +qed "DERIV_Id";
  9.1359 +Addsimps [DERIV_Id];
  9.1360 +
  9.1361 +Goal "DERIV op * c x :> c";
  9.1362 +by (cut_inst_tac [("c","c"),("x","x")] (DERIV_Id RS DERIV_cmult) 1);
  9.1363 +by (Asm_full_simp_tac 1);
  9.1364 +qed "DERIV_cmult_Id";
  9.1365 +Addsimps [DERIV_cmult_Id];
  9.1366 +
  9.1367 +Goal "NSDERIV op * c x :> c";
  9.1368 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff]) 1);
  9.1369 +qed "NSDERIV_cmult_Id";
  9.1370 +Addsimps [NSDERIV_cmult_Id];
  9.1371 +
  9.1372 +Goal "DERIV (%x. x ^ n) x :> real_of_nat n * (x ^ (n - 1))";
  9.1373 +by (induct_tac "n" 1);
  9.1374 +by (dtac (DERIV_Id RS DERIV_mult) 2);
  9.1375 +by (auto_tac (claset(),simpset() addsimps 
  9.1376 +    [real_add_mult_distrib]));
  9.1377 +by (case_tac "0 < n" 1);
  9.1378 +by (dres_inst_tac [("x","x")] realpow_minus_mult 1);
  9.1379 +by (auto_tac (claset(),simpset() addsimps 
  9.1380 +    [real_mult_assoc,real_add_commute]));
  9.1381 +qed "DERIV_pow";
  9.1382 +
  9.1383 +(* NS version *)
  9.1384 +Goal "NSDERIV (%x. x ^ n) x :> real_of_nat n * (x ^ (n - 1))";
  9.1385 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,DERIV_pow]) 1);
  9.1386 +qed "NSDERIV_pow";
  9.1387 +
  9.1388 +(*---------------------------------------------------------------
  9.1389 +                    Power of -1 
  9.1390 + ---------------------------------------------------------------*)
  9.1391 +Goalw [nsderiv_def]
  9.1392 +     "x ~= #0 ==> NSDERIV (%x. rinv(x)) x :> (- (rinv x ^ 2))";
  9.1393 +by (rtac ballI 1 THEN Asm_full_simp_tac 1 THEN Step_tac 1);
  9.1394 +by (forward_tac [Infinitesimal_add_not_zero] 1);
  9.1395 +by (auto_tac (claset(),simpset() addsimps [starfun_rinv_hrinv,
  9.1396 +         hypreal_of_real_hrinv RS sym,hypreal_of_real_minus,realpow_two,
  9.1397 +         hypreal_of_real_mult] delsimps [hypreal_minus_mult_eq1 RS
  9.1398 +         sym,hypreal_minus_mult_eq2 RS sym]));
  9.1399 +by (dtac (hypreal_of_real_not_zero_iff RS iffD2) 1);
  9.1400 +by (asm_full_simp_tac (simpset() addsimps [hypreal_hrinv_add,
  9.1401 +         hrinv_mult_eq RS sym, hypreal_minus_hrinv RS sym] 
  9.1402 +         @ hypreal_add_ac @ hypreal_mult_ac delsimps [hypreal_minus_mult_eq1 RS
  9.1403 +         sym,hypreal_minus_mult_eq2 RS sym] ) 1);
  9.1404 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym,
  9.1405 +         hypreal_add_mult_distrib2] delsimps [hypreal_minus_mult_eq1 RS
  9.1406 +         sym,hypreal_minus_mult_eq2 RS sym]) 1);
  9.1407 +by (dres_inst_tac [("x3","x") ] ((HFinite_hypreal_of_real RSN
  9.1408 +         (2,Infinitesimal_HFinite_mult2)) RS  
  9.1409 +          (Infinitesimal_minus_iff RS iffD1)) 1); 
  9.1410 +by (forw_inst_tac [("x","hypreal_of_real x"),("y","hypreal_of_real x")] hypreal_mult_not_0 1);
  9.1411 +by (res_inst_tac [("y"," hrinv(- hypreal_of_real x * hypreal_of_real x)")] inf_close_trans 2);
  9.1412 +by (rtac hrinv_add_Infinitesimal_inf_close2 2);
  9.1413 +by (auto_tac (claset() addIs [HFinite_minus_iff RS iffD1]
  9.1414 +         addSDs [Infinitesimal_minus_iff RS iffD2,
  9.1415 +         hypreal_of_real_HFinite_diff_Infinitesimal], simpset() addsimps 
  9.1416 +         [hypreal_minus_hrinv RS sym,hypreal_of_real_mult RS sym]));
  9.1417 +qed "NSDERIV_rinv";
  9.1418 +
  9.1419 +Goal "x ~= #0 ==> DERIV (%x. rinv(x)) x :> (-(rinv x ^ 2))";
  9.1420 +by (asm_simp_tac (simpset() addsimps [NSDERIV_rinv,
  9.1421 +         NSDERIV_DERIV_iff RS sym] delsimps [thm "realpow_Suc"]) 1);
  9.1422 +qed "DERIV_rinv";
  9.1423 +
  9.1424 +(*--------------------------------------------------------------
  9.1425 +        Derivative of inverse 
  9.1426 + -------------------------------------------------------------*)
  9.1427 +Goal "[| DERIV f x :> d; f(x) ~= #0 |] \
  9.1428 +\     ==> DERIV (%x. rinv(f x)) x :> (- (d * rinv(f(x) ^ 2)))";
  9.1429 +by (rtac (real_mult_commute RS subst) 1);
  9.1430 +by (asm_simp_tac (simpset() addsimps [real_minus_mult_eq1,
  9.1431 +    realpow_rinv] delsimps [thm "realpow_Suc", 
  9.1432 +    real_minus_mult_eq1 RS sym]) 1);
  9.1433 +by (fold_goals_tac [o_def]);
  9.1434 +by (blast_tac (claset() addSIs [DERIV_chain,DERIV_rinv]) 1);
  9.1435 +qed "DERIV_rinv_fun";
  9.1436 +
  9.1437 +Goal "[| NSDERIV f x :> d; f(x) ~= #0 |] \
  9.1438 +\     ==> NSDERIV (%x. rinv(f x)) x :> (- (d * rinv(f(x) ^ 2)))";
  9.1439 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  9.1440 +            DERIV_rinv_fun] delsimps [thm "realpow_Suc"]) 1);
  9.1441 +qed "NSDERIV_rinv_fun";
  9.1442 +
  9.1443 +(*--------------------------------------------------------------
  9.1444 +        Derivative of quotient 
  9.1445 + -------------------------------------------------------------*)
  9.1446 +Goal "[| DERIV f x :> d; DERIV g x :> e; g(x) ~= #0 |] \
  9.1447 +\      ==> DERIV (%y. f(y)*rinv(g y)) x :> (d*g(x) \
  9.1448 +\                           + -(e*f(x)))*rinv(g(x) ^ 2)";
  9.1449 +by (dres_inst_tac [("f","g")] DERIV_rinv_fun 1);
  9.1450 +by (dtac DERIV_mult 2);
  9.1451 +by (REPEAT(assume_tac 1));
  9.1452 +by (asm_full_simp_tac (simpset() addsimps [real_add_mult_distrib2,
  9.1453 +        realpow_rinv,real_minus_mult_eq1] @ real_mult_ac delsimps
  9.1454 +        [thm "realpow_Suc",real_minus_mult_eq1 RS sym,
  9.1455 +         real_minus_mult_eq2 RS sym]) 1);
  9.1456 +qed "DERIV_quotient";
  9.1457 +
  9.1458 +Goal "[| NSDERIV f x :> d; DERIV g x :> e; g(x) ~= #0 |] \
  9.1459 +\      ==> NSDERIV (%y. f(y)*rinv(g y)) x :> (d*g(x) \
  9.1460 +\                           + -(e*f(x)))*rinv(g(x) ^ 2)";
  9.1461 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  9.1462 +            DERIV_quotient] delsimps [thm "realpow_Suc"]) 1);
  9.1463 +qed "NSDERIV_quotient";
  9.1464 + 
  9.1465 +(* ------------------------------------------------------------------------ *)
  9.1466 +(* Caratheodory formulation of derivative at a point: standard proof        *)
  9.1467 +(* ------------------------------------------------------------------------ *)
  9.1468 +
  9.1469 +Goal "(DERIV f x :> l) = \
  9.1470 +\     (EX g. (ALL z. f z - f x = g z * (z - x)) & isCont g x & g x = l)";
  9.1471 +by (Step_tac 1);
  9.1472 +by (res_inst_tac 
  9.1473 +    [("x","%z. if  z = x then l else (f(z) - f(x)) * rinv (z - x)")] exI 1);
  9.1474 +by (auto_tac (claset(),simpset() addsimps [real_mult_assoc,
  9.1475 +    ARITH_PROVE "z ~= x ==> z - x ~= (#0::real)"]));
  9.1476 +by (auto_tac (claset(),simpset() addsimps [isCont_iff,DERIV_iff]));
  9.1477 +by (ALLGOALS(rtac (LIM_equal RS iffD1)));
  9.1478 +by (auto_tac (claset(),simpset() addsimps [real_diff_def,real_mult_assoc]));
  9.1479 +qed "CARAT_DERIV";
  9.1480 +
  9.1481 +Goal "NSDERIV f x :> l ==> \
  9.1482 +\     EX g. (ALL z. f z - f x = g z * (z - x)) & isNSCont g x & g x = l";
  9.1483 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_DERIV_iff,
  9.1484 +    isNSCont_isCont_iff,CARAT_DERIV]));
  9.1485 +qed "CARAT_NSDERIV";
  9.1486 +
  9.1487 +(* How about a NS proof? *)
  9.1488 +Goal "(ALL z. f z - f x = g z * (z - x)) & isNSCont g x & g x = l \
  9.1489 +\     ==> NSDERIV f x :> l";
  9.1490 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_iff2,starfun_mult
  9.1491 +    RS sym]));
  9.1492 +by (rtac (starfun_hrinv2 RS subst) 1);
  9.1493 +by (auto_tac (claset(),simpset() addsimps [hypreal_mult_assoc,
  9.1494 +    starfun_diff RS sym,starfun_Id]));
  9.1495 +by (asm_full_simp_tac (simpset() addsimps [hypreal_eq_minus_iff3 RS sym,
  9.1496 +    hypreal_diff_def]) 1);
  9.1497 +by (dtac (CLAIM_SIMP "x ~= y ==> x - y ~= (0::hypreal)" [hypreal_eq_minus_iff3 RS sym,
  9.1498 +            hypreal_diff_def]) 1);
  9.1499 +by (asm_full_simp_tac (simpset() addsimps [isNSCont_def]) 1);
  9.1500 +qed "CARAT_DERIVD";
  9.1501 + 
  9.1502 +(*--------------------------------------------------------------------*)
  9.1503 +(* In this theory, still have to include Bisection theorem, IVT, MVT, *)
  9.1504 +(* Rolle etc.                                                         *)
  9.1505 +(*--------------------------------------------------------------------*)
  9.1506 +
  9.1507 +
  9.1508 + 
  9.1509 +
  9.1510 +
  9.1511 + 
  9.1512 \ No newline at end of file
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/HOL/Real/Hyperreal/Lim.thy	Thu Sep 21 12:17:11 2000 +0200
    10.3 @@ -0,0 +1,58 @@
    10.4 +(*  Title       : Lim.thy
    10.5 +    Author      : Jacques D. Fleuriot
    10.6 +    Copyright   : 1998  University of Cambridge
    10.7 +    Description : Theory of limits, continuity and 
    10.8 +                  differentiation of real=>real functions
    10.9 +*)
   10.10 +
   10.11 +Lim = SEQ + RealAbs + 
   10.12 +
   10.13 +     (*-----------------------------------------------------------------------
   10.14 +         Limits, continuity and differentiation: standard and NS definitions
   10.15 +      -----------------------------------------------------------------------*)
   10.16 +constdefs
   10.17 +      LIM :: [real=>real,real,real] => bool    ("((_)/ -- (_)/ --> (_))" 60)
   10.18 +      "f -- a --> L == (ALL r. #0 < r --> 
   10.19 +                          (EX s. #0 < s & (ALL x. (#0 < abs(x + -a) & (abs(x + -a) < s)
   10.20 +                                --> abs(f x + -L) < r))))"
   10.21 +
   10.22 +      NSLIM :: [real=>real,real,real] => bool  ("((_)/ -- (_)/ --NS> (_))" 60)
   10.23 +      "f -- a --NS> L == (ALL x. (x ~= hypreal_of_real a & 
   10.24 +                          x @= hypreal_of_real a --> (*f* f) x @= hypreal_of_real L))"   
   10.25 +
   10.26 +      isCont :: [real=>real,real] => bool
   10.27 +      "isCont f a == (f -- a --> (f a))"        
   10.28 +
   10.29 +      (* NS definition dispenses with limit notions *)
   10.30 +      isNSCont :: [real=>real,real] => bool
   10.31 +      "isNSCont f a == (ALL y. y @= hypreal_of_real a --> 
   10.32 +                               (*f* f) y @= hypreal_of_real (f a))"
   10.33 +      
   10.34 +      (* differentiation: D is derivative of function f at x *)
   10.35 +      deriv:: [real=>real,real,real] => bool   ("(DERIV (_)/ (_)/ :> (_))" 60)
   10.36 +      "DERIV f x :> D == ((%h. (f(x + h) + -f(x))*rinv(h)) -- #0 --> D)"
   10.37 +
   10.38 +      nsderiv :: [real=>real,real,real] => bool   ("(NSDERIV (_)/ (_)/ :> (_))" 60)
   10.39 +      "NSDERIV f x :> D == (ALL h: Infinitesimal - {0}. 
   10.40 +                            ((*f* f)(hypreal_of_real x + h) + 
   10.41 +                             -hypreal_of_real (f x))*hrinv(h) @= hypreal_of_real D)"
   10.42 +
   10.43 +      differentiable :: [real=>real,real] => bool   (infixl 60)
   10.44 +      "f differentiable x == (EX D. DERIV f x :> D)"
   10.45 +
   10.46 +      NSdifferentiable :: [real=>real,real] => bool   (infixl 60)
   10.47 +      "f NSdifferentiable x == (EX D. NSDERIV f x :> D)"
   10.48 +
   10.49 +      increment :: [real=>real,real,hypreal] => hypreal
   10.50 +      "increment f x h == (@inc. f NSdifferentiable x & 
   10.51 +                           inc = (*f* f)(hypreal_of_real x + h) + -hypreal_of_real (f x))"
   10.52 +
   10.53 +      isUCont :: (real=>real) => bool
   10.54 +      "isUCont f ==  (ALL r. #0 < r --> 
   10.55 +                          (EX s. #0 < s & (ALL x y. abs(x + -y) < s
   10.56 +                                --> abs(f x + -f y) < r)))"
   10.57 +
   10.58 +      isNSUCont :: (real=>real) => bool
   10.59 +      "isNSUCont f == (ALL x y. x @= y --> (*f* f) x @= (*f* f) y)"
   10.60 +end
   10.61 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/HOL/Real/Hyperreal/NSA.ML	Thu Sep 21 12:17:11 2000 +0200
    11.3 @@ -0,0 +1,2297 @@
    11.4 +(*  Title       : NSA.ML
    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 +fun CLAIM_SIMP str thms =
   11.12 +               prove_goal (the_context()) str
   11.13 +               (fn prems => [cut_facts_tac prems 1,
   11.14 +                   auto_tac (claset(),simpset() addsimps thms)]);
   11.15 +fun CLAIM str = CLAIM_SIMP str [];
   11.16 +
   11.17 +(*--------------------------------------------------------------------
   11.18 +     Closure laws for members of (embedded) set standard real SReal
   11.19 + --------------------------------------------------------------------*)
   11.20 +
   11.21 +Goalw [SReal_def] "[| x: SReal; y: SReal |] ==> x + y: SReal";
   11.22 +by (Step_tac 1);
   11.23 +by (res_inst_tac [("x","r + ra")] exI 1);
   11.24 +by (simp_tac (simpset() addsimps [hypreal_of_real_add]) 1);
   11.25 +qed "SReal_add";
   11.26 +
   11.27 +Goalw [SReal_def] "[| x: SReal; y: SReal |] ==> x * y: SReal";
   11.28 +by (Step_tac 1);
   11.29 +by (res_inst_tac [("x","r * ra")] exI 1);
   11.30 +by (simp_tac (simpset() addsimps [hypreal_of_real_mult]) 1);
   11.31 +qed "SReal_mult";
   11.32 +
   11.33 +Goalw [SReal_def] "[| x: SReal; x ~= 0 |] ==> hrinv x : SReal";
   11.34 +by (blast_tac (claset() addSDs [hypreal_of_real_hrinv2]) 1);
   11.35 +qed "SReal_hrinv";
   11.36 +
   11.37 +Goalw [SReal_def] "x: SReal ==> -x : SReal";
   11.38 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_minus RS sym]));
   11.39 +qed "SReal_minus";
   11.40 +
   11.41 +Goal "[| x + y : SReal; y: SReal |] ==> x: SReal";
   11.42 +by (dres_inst_tac [("x","y")] SReal_minus 1);
   11.43 +by (dtac SReal_add 1);
   11.44 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
   11.45 +qed "SReal_add_cancel";
   11.46 +
   11.47 +Goalw [SReal_def] "x: SReal ==> abs x : SReal";
   11.48 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_hrabs]));
   11.49 +qed "SReal_hrabs";
   11.50 +
   11.51 +Goalw [SReal_def] "hypreal_of_real #1 : SReal";
   11.52 +by (Auto_tac);
   11.53 +qed "SReal_hypreal_of_real_one";
   11.54 +
   11.55 +Goalw [SReal_def] "hypreal_of_real 0 : SReal";
   11.56 +by (Auto_tac);
   11.57 +qed "SReal_hypreal_of_real_zero";
   11.58 +
   11.59 +Goal "1hr : SReal";
   11.60 +by (simp_tac (simpset() addsimps [SReal_hypreal_of_real_one,
   11.61 +    hypreal_of_real_one RS sym]) 1);
   11.62 +qed "SReal_one";
   11.63 +
   11.64 +Goal "0 : SReal";
   11.65 +by (simp_tac (simpset() addsimps [rename_numerals 
   11.66 +    SReal_hypreal_of_real_zero,hypreal_of_real_zero RS sym]) 1);
   11.67 +qed "SReal_zero";
   11.68 +
   11.69 +Goal "1hr + 1hr : SReal";
   11.70 +by (rtac ([SReal_one,SReal_one] MRS SReal_add) 1);
   11.71 +qed "SReal_two";
   11.72 +
   11.73 +Addsimps [SReal_zero,SReal_two];
   11.74 +
   11.75 +Goal "r : SReal ==> r*hrinv(1hr + 1hr): SReal";
   11.76 +by (blast_tac (claset() addSIs [SReal_mult,SReal_hrinv,
   11.77 +    SReal_two,hypreal_two_not_zero]) 1);
   11.78 +qed "SReal_half";
   11.79 +
   11.80 +(* in general: move before previous thms!*)
   11.81 +Goalw [SReal_def] "hypreal_of_real  x: SReal";
   11.82 +by (Blast_tac 1);
   11.83 +qed "SReal_hypreal_of_real";
   11.84 +
   11.85 +Addsimps [SReal_hypreal_of_real];
   11.86 +
   11.87 +(* Infinitesimal ehr not in SReal *)
   11.88 +
   11.89 +Goalw [SReal_def] "ehr ~: SReal";
   11.90 +by (auto_tac (claset(),simpset() addsimps 
   11.91 +    [hypreal_of_real_not_eq_epsilon RS not_sym]));
   11.92 +qed "SReal_epsilon_not_mem";
   11.93 +
   11.94 +Goalw [SReal_def] "whr ~: SReal";
   11.95 +by (auto_tac (claset(),simpset() addsimps 
   11.96 +    [hypreal_of_real_not_eq_omega RS not_sym]));
   11.97 +qed "SReal_omega_not_mem";
   11.98 +
   11.99 +Goalw [SReal_def] "{x. hypreal_of_real x : SReal} = (UNIV::real set)";
  11.100 +by (Auto_tac);
  11.101 +qed "SReal_UNIV_real";
  11.102 +
  11.103 +Goalw [SReal_def] "(x: SReal) = (? y. x = hypreal_of_real  y)";
  11.104 +by (Auto_tac);
  11.105 +qed "SReal_iff";
  11.106 +
  11.107 +Goalw [SReal_def] "hypreal_of_real ``(UNIV::real set) = SReal";
  11.108 +by (Auto_tac);
  11.109 +qed "hypreal_of_real_image";
  11.110 +
  11.111 +Goalw [SReal_def] "inv hypreal_of_real ``SReal = (UNIV::real set)";
  11.112 +by (Auto_tac);
  11.113 +by (rtac (inj_hypreal_of_real RS inv_f_f RS subst) 1);
  11.114 +by (Blast_tac 1);
  11.115 +qed "inv_hypreal_of_real_image";
  11.116 +
  11.117 +Goalw [SReal_def] 
  11.118 +      "[| EX x. x: P; P <= SReal |] ==> EX Q. P = hypreal_of_real `` Q";
  11.119 +by (Best_tac 1); 
  11.120 +qed "SReal_hypreal_of_real_image";
  11.121 +
  11.122 +Goal "[| x: SReal; y: SReal; x < y |] ==> EX r: SReal. x < r & r < y";
  11.123 +by (auto_tac (claset(),simpset() addsimps [SReal_iff]));
  11.124 +by (dtac real_dense 1 THEN Step_tac 1);
  11.125 +by (res_inst_tac [("x","hypreal_of_real r")] bexI 1);
  11.126 +by (Auto_tac);
  11.127 +qed "SReal_dense";
  11.128 +
  11.129 +(*------------------------------------------------------------------
  11.130 +                   Completeness of SReal
  11.131 + ------------------------------------------------------------------*)
  11.132 +Goal "P <= SReal ==> ((? x:P. y < x) = \ 
  11.133 +\     (? X. hypreal_of_real X : P & y < hypreal_of_real X))";
  11.134 +by (blast_tac (claset() addSDs [SReal_iff RS iffD1]) 1);
  11.135 +by (flexflex_tac );
  11.136 +qed "SReal_sup_lemma";
  11.137 +
  11.138 +Goal "[| P <= SReal; ? x. x: P; ? y : SReal. !x: P. x < y |] \
  11.139 +\     ==> (? X. X: {w. hypreal_of_real w : P}) & \
  11.140 +\         (? Y. !X: {w. hypreal_of_real w : P}. X < Y)";
  11.141 +by (rtac conjI 1);
  11.142 +by (fast_tac (claset() addSDs [SReal_iff RS iffD1]) 1);
  11.143 +by (Auto_tac THEN forward_tac [subsetD] 1 THEN assume_tac 1);
  11.144 +by (dtac (SReal_iff RS iffD1) 1);
  11.145 +by (Auto_tac THEN res_inst_tac [("x","ya")] exI 1);
  11.146 +by (auto_tac (claset() addDs [bspec],
  11.147 +   simpset() addsimps [hypreal_of_real_less_iff RS sym]));
  11.148 +qed "SReal_sup_lemma2";
  11.149 +
  11.150 +(*------------------------------------------------------
  11.151 +    lifting of ub and property of lub
  11.152 + -------------------------------------------------------*)
  11.153 +Goalw [isUb_def,setle_def] 
  11.154 +      "(isUb (SReal) (hypreal_of_real `` Q) (hypreal_of_real Y)) = \
  11.155 +\      (isUb (UNIV :: real set) Q Y)";
  11.156 +by (blast_tac (claset() addIs [hypreal_of_real_le_iff RS iffD1,
  11.157 +                hypreal_of_real_le_iff RS iffD2,SReal_hypreal_of_real]) 1);
  11.158 +qed "hypreal_of_real_isUb_iff";
  11.159 +
  11.160 +Goalw [isLub_def,leastP_def] 
  11.161 +      "isLub SReal (hypreal_of_real `` Q) (hypreal_of_real Y) \
  11.162 +\      ==> isLub (UNIV :: real set) Q Y";
  11.163 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_isUb_iff,
  11.164 +               setge_def]));
  11.165 +by (blast_tac (claset() addIs [hypreal_of_real_isUb_iff RS iffD2,
  11.166 +               hypreal_of_real_le_iff RS iffD2]) 1);
  11.167 +qed "hypreal_of_real_isLub1";
  11.168 +
  11.169 +Goalw [isLub_def,leastP_def] 
  11.170 +      "isLub (UNIV :: real set) Q Y \
  11.171 +\      ==> isLub SReal (hypreal_of_real `` Q) (hypreal_of_real Y)";
  11.172 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_isUb_iff,
  11.173 +               setge_def]));
  11.174 +by (forw_inst_tac [("x2","x")] (isUbD2a RS (SReal_iff RS iffD1) RS exE) 1);
  11.175 +by (assume_tac 2);
  11.176 +by (dres_inst_tac [("x","xa")] spec 1);
  11.177 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_isUb_iff,
  11.178 +    hypreal_of_real_le_iff RS iffD1]));
  11.179 +qed "hypreal_of_real_isLub2";
  11.180 +
  11.181 +Goal
  11.182 +    "(isLub SReal (hypreal_of_real `` Q) (hypreal_of_real Y)) = \
  11.183 +\    (isLub (UNIV :: real set) Q Y)";
  11.184 +by (blast_tac (claset() addIs [hypreal_of_real_isLub1,hypreal_of_real_isLub2]) 1);
  11.185 +qed "hypreal_of_real_isLub_iff";
  11.186 +
  11.187 +(* lemmas *)
  11.188 +Goalw [isUb_def] 
  11.189 +     "isUb SReal P Y \
  11.190 +\     ==> EX Yo. isUb SReal P (hypreal_of_real Yo)";
  11.191 +by (auto_tac (claset(),simpset() addsimps [SReal_iff]));
  11.192 +qed "lemma_isUb_hypreal_of_real";
  11.193 +
  11.194 +Goalw [isLub_def,leastP_def,isUb_def] 
  11.195 +      "isLub SReal P Y ==> EX Yo. isLub SReal P (hypreal_of_real Yo)";
  11.196 +by (auto_tac (claset(),simpset() addsimps [SReal_iff]));
  11.197 +qed "lemma_isLub_hypreal_of_real";
  11.198 +
  11.199 +Goalw [isLub_def,leastP_def,isUb_def] 
  11.200 +      "EX Yo. isLub SReal P (hypreal_of_real Yo) \
  11.201 +\      ==> EX Y. isLub SReal P Y";
  11.202 +by (Auto_tac);
  11.203 +qed "lemma_isLub_hypreal_of_real2";
  11.204 +
  11.205 +Goal "[| P <= SReal; EX x. x: P; \
  11.206 +\        EX Y. isUb SReal P Y |] \
  11.207 +\     ==> EX t. isLub SReal P t";
  11.208 +by (forward_tac [SReal_hypreal_of_real_image] 1);
  11.209 +by (Auto_tac THEN dtac lemma_isUb_hypreal_of_real 1);
  11.210 +by (auto_tac (claset() addSIs [reals_complete,
  11.211 +    lemma_isLub_hypreal_of_real2], simpset() addsimps 
  11.212 +    [hypreal_of_real_isLub_iff,hypreal_of_real_isUb_iff]));
  11.213 +qed "SReal_complete";
  11.214 +
  11.215 +(*--------------------------------------------------------------------
  11.216 +        Set of finite elements is a subring of the extended reals
  11.217 + --------------------------------------------------------------------*)
  11.218 +Goalw [HFinite_def] "[|x : HFinite;y : HFinite|] ==> (x+y) : HFinite";
  11.219 +by (blast_tac (claset() addSIs [SReal_add,hrabs_add_less]) 1);
  11.220 +qed "HFinite_add";
  11.221 +
  11.222 +Goalw [HFinite_def] "[|x : HFinite;y : HFinite|] ==> (x*y) : HFinite";
  11.223 +by (blast_tac (claset() addSIs [SReal_mult,hrabs_mult_less]) 1);
  11.224 +qed "HFinite_mult";
  11.225 +
  11.226 +Goalw [HFinite_def] "(x:HFinite)=(-x:HFinite)";
  11.227 +by (simp_tac (simpset() addsimps [hrabs_minus_cancel]) 1);
  11.228 +qed "HFinite_minus_iff";
  11.229 +
  11.230 +Goal "[| x: HFinite; y: HFinite|] ==> (x + -y): HFinite";
  11.231 +by (blast_tac (claset() addDs [HFinite_minus_iff RS iffD1] addIs [HFinite_add]) 1);
  11.232 +qed "HFinite_add_minus";
  11.233 +
  11.234 +Goalw [SReal_def,HFinite_def] "SReal <= HFinite";
  11.235 +by Auto_tac;
  11.236 +by (res_inst_tac [("x","1hr + abs(hypreal_of_real r)")] exI 1);
  11.237 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_hrabs,
  11.238 +    hypreal_of_real_one RS sym,hypreal_of_real_add RS sym,
  11.239 +    hypreal_of_real_zero RS sym]));
  11.240 +qed "SReal_subset_HFinite";
  11.241 +
  11.242 +Goal "hypreal_of_real x : HFinite";
  11.243 +by (auto_tac (claset() addIs [(SReal_subset_HFinite RS subsetD)],
  11.244 +              simpset()));
  11.245 +qed "HFinite_hypreal_of_real";
  11.246 +
  11.247 +Addsimps [HFinite_hypreal_of_real];
  11.248 +
  11.249 +Goalw [HFinite_def] "x : HFinite ==> EX t: SReal. abs x < t";
  11.250 +by (Auto_tac);
  11.251 +qed "HFiniteD";
  11.252 +
  11.253 +Goalw [HFinite_def] "x : HFinite ==> abs x : HFinite";
  11.254 +by (auto_tac (claset(),simpset() addsimps [hrabs_idempotent]));
  11.255 +qed "HFinite_hrabs";
  11.256 +
  11.257 +Goalw [HFinite_def,Bex_def] "x ~: HFinite ==> abs x ~: HFinite";
  11.258 +by (auto_tac (claset() addDs [spec],simpset() addsimps [hrabs_idempotent]));
  11.259 +qed "not_HFinite_hrabs";
  11.260 +
  11.261 +goal NSA.thy "0 : HFinite";
  11.262 +by (rtac (SReal_zero RS (SReal_subset_HFinite RS subsetD)) 1);
  11.263 +qed "HFinite_zero";
  11.264 +Addsimps [HFinite_zero];
  11.265 +
  11.266 +goal NSA.thy "1hr : HFinite";
  11.267 +by (rtac (SReal_one RS (SReal_subset_HFinite RS subsetD)) 1);
  11.268 +qed "HFinite_one";
  11.269 +Addsimps [HFinite_one];
  11.270 +
  11.271 +Goal "[|x : HFinite; y <= x; 0 <= y |] ==> y: HFinite";
  11.272 +by (case_tac "x <= 0" 1);
  11.273 +by (dres_inst_tac [("j","x")] hypreal_le_trans 1);
  11.274 +by (dtac hypreal_le_anti_sym 2);
  11.275 +by (auto_tac (claset() addSDs [not_hypreal_leE],simpset()));
  11.276 +by (auto_tac (claset() addSIs [bexI]
  11.277 +    addIs [hypreal_le_less_trans],simpset() addsimps 
  11.278 +    [hrabs_eqI1,hrabs_eqI2,hrabs_minus_eqI1,HFinite_def]));
  11.279 +qed "HFinite_bounded"; 
  11.280 +
  11.281 +(*------------------------------------------------------------------
  11.282 +       Set of infinitesimals is a subring of the hyperreals   
  11.283 + ------------------------------------------------------------------*)
  11.284 +Goalw [Infinitesimal_def]
  11.285 +      "x : Infinitesimal ==> ALL r: SReal. 0 < r --> abs x < r";
  11.286 +by (Auto_tac);
  11.287 +qed "InfinitesimalD";
  11.288 +
  11.289 +Goalw [Infinitesimal_def] "0 : Infinitesimal";
  11.290 +by (simp_tac (simpset() addsimps [hrabs_zero]) 1);
  11.291 +qed "Infinitesimal_zero";
  11.292 +
  11.293 +Addsimps [Infinitesimal_zero];
  11.294 +
  11.295 +Goalw [Infinitesimal_def] 
  11.296 +      "[| x : Infinitesimal; y : Infinitesimal |] \
  11.297 +\      ==> (x + y) : Infinitesimal";
  11.298 +by (Auto_tac);
  11.299 +by (rtac (hypreal_sum_of_halves RS subst) 1);
  11.300 +by (dtac hypreal_half_gt_zero 1);
  11.301 +by (dtac SReal_half 1);
  11.302 +by (auto_tac (claset() addSDs [bspec] 
  11.303 +    addIs [hrabs_add_less],simpset()));
  11.304 +qed "Infinitesimal_add";
  11.305 +
  11.306 +Goalw [Infinitesimal_def] 
  11.307 +     "(x:Infinitesimal) = (-x:Infinitesimal)";
  11.308 +by (full_simp_tac (simpset() addsimps [hrabs_minus_cancel]) 1);
  11.309 +qed "Infinitesimal_minus_iff";
  11.310 +
  11.311 +Goal "x ~:Infinitesimal = (-x ~:Infinitesimal)";
  11.312 +by (full_simp_tac (simpset() addsimps [Infinitesimal_minus_iff RS sym]) 1);
  11.313 +qed "not_Infinitesimal_minus_iff";
  11.314 +
  11.315 +val prem1::prem2::rest = 
  11.316 +goal thy "[| x : Infinitesimal; y : Infinitesimal  |] \
  11.317 +\         ==> (x + -y):Infinitesimal";
  11.318 +by (full_simp_tac (simpset() addsimps [prem1,prem2,
  11.319 +    (Infinitesimal_minus_iff RS iffD1),Infinitesimal_add]) 1);
  11.320 +qed "Infinitesimal_add_minus";
  11.321 +
  11.322 +Goalw [Infinitesimal_def] 
  11.323 +      "[| x : Infinitesimal; y : Infinitesimal |] \
  11.324 +\      ==> (x * y) : Infinitesimal";
  11.325 +by (Auto_tac);
  11.326 +by (rtac (hypreal_mult_1_right RS subst) 1);
  11.327 +by (rtac hrabs_mult_less 1);
  11.328 +by (cut_facts_tac [SReal_one,hypreal_zero_less_one] 2);
  11.329 +by (ALLGOALS(blast_tac (claset() addSDs [bspec])));
  11.330 +qed "Infinitesimal_mult";
  11.331 +
  11.332 +Goal "[| x : Infinitesimal; y : HFinite |] \
  11.333 +\     ==> (x * y) : Infinitesimal";
  11.334 +by (auto_tac (claset() addSDs [HFiniteD],
  11.335 +    simpset() addsimps [Infinitesimal_def]));
  11.336 +by (forward_tac [hrabs_less_gt_zero] 1);
  11.337 +by (dtac (hypreal_hrinv_gt_zero RSN (2,hypreal_mult_less_mono2)) 1 
  11.338 +    THEN assume_tac 1);
  11.339 +by (dtac ((hypreal_not_refl2 RS not_sym) RSN (2,SReal_hrinv)) 1 
  11.340 +    THEN assume_tac 1);
  11.341 +by (dtac SReal_mult 1 THEN assume_tac 1);
  11.342 +by (thin_tac "hrinv t : SReal" 1);
  11.343 +by (auto_tac (claset() addSDs [bspec],simpset() addsimps [hrabs_mult]));
  11.344 +by (dtac hrabs_mult_less 1 THEN assume_tac 1);
  11.345 +by (dtac (hypreal_not_refl2 RS not_sym) 1);
  11.346 +by (auto_tac (claset() addSDs [hypreal_mult_hrinv],
  11.347 +     simpset() addsimps [hrabs_mult] @ hypreal_mult_ac));
  11.348 +qed "Infinitesimal_HFinite_mult";
  11.349 +
  11.350 +Goal "[| x : Infinitesimal; y : HFinite |] \
  11.351 +\     ==> (y * x) : Infinitesimal";
  11.352 +by (auto_tac (claset() addDs [Infinitesimal_HFinite_mult],
  11.353 +              simpset() addsimps [hypreal_mult_commute]));
  11.354 +qed "Infinitesimal_HFinite_mult2";
  11.355 +
  11.356 +(*** rather long proof ***)
  11.357 +Goalw [HInfinite_def,Infinitesimal_def] 
  11.358 +      "x: HInfinite ==> hrinv x: Infinitesimal";
  11.359 +by (Auto_tac);
  11.360 +by (eres_inst_tac [("x","hrinv r")] ballE 1);
  11.361 +by (rtac (hrabs_hrinv RS ssubst) 1);
  11.362 +by (etac (((hypreal_hrinv_gt_zero RS hypreal_less_trans) 
  11.363 +   RS hypreal_not_refl2 RS not_sym) RS (hrabs_not_zero_iff 
  11.364 +   RS iffD2)) 1 THEN assume_tac 1);
  11.365 +by (forw_inst_tac [("x1","r"),("R3.0","abs x")] 
  11.366 +    (hypreal_hrinv_gt_zero RS hypreal_less_trans) 1);
  11.367 +by (assume_tac 1);
  11.368 +by (forw_inst_tac [("s","abs x"),("t","0")] 
  11.369 +              (hypreal_not_refl2 RS not_sym) 1);
  11.370 +by (dtac ((hypreal_hrinv_hrinv RS sym) RS subst) 1);
  11.371 +by (rotate_tac 2 1 THEN assume_tac 1);
  11.372 +by (dres_inst_tac [("x","abs x")] hypreal_hrinv_gt_zero 1);
  11.373 +by (rtac (hypreal_hrinv_less_iff RS ssubst) 1);
  11.374 +by (auto_tac (claset() addSDs [SReal_hrinv],
  11.375 +    simpset() addsimps [hypreal_not_refl2 RS not_sym,
  11.376 +    hypreal_less_not_refl]));
  11.377 +qed "HInfinite_hrinv_Infinitesimal";
  11.378 +
  11.379 +Goalw [HInfinite_def] 
  11.380 +   "[|x: HInfinite;y: HInfinite|] ==> (x*y): HInfinite";
  11.381 +by (Auto_tac);
  11.382 +by (cut_facts_tac [SReal_one] 1);
  11.383 +by (eres_inst_tac [("x","1hr")] ballE 1);
  11.384 +by (eres_inst_tac [("x","r")] ballE 1);
  11.385 +by (REPEAT(fast_tac (HOL_cs addSIs [hrabs_mult_gt]) 1));
  11.386 +qed "HInfinite_mult";
  11.387 +
  11.388 +Goalw [HInfinite_def] 
  11.389 +      "[|x: HInfinite; 0 <= y; 0 <= x|] \
  11.390 +\      ==> (x + y): HInfinite";
  11.391 +by (auto_tac (claset() addSIs  
  11.392 +    [hypreal_add_zero_less_le_mono],
  11.393 +    simpset() addsimps [hrabs_eqI1,
  11.394 +    hypreal_add_commute,hypreal_le_add_order]));
  11.395 +qed "HInfinite_add_ge_zero";
  11.396 +
  11.397 +Goal "[|x: HInfinite; 0 <= y; 0 <= x|] \
  11.398 +\      ==> (y + x): HInfinite";
  11.399 +by (auto_tac (claset() addSIs [HInfinite_add_ge_zero],
  11.400 +    simpset() addsimps [hypreal_add_commute]));
  11.401 +qed "HInfinite_add_ge_zero2";
  11.402 +
  11.403 +Goal "[|x: HInfinite; 0 < y; 0 < x|] \
  11.404 +\      ==> (x + y): HInfinite";
  11.405 +by (blast_tac (claset() addIs [HInfinite_add_ge_zero,
  11.406 +    hypreal_less_imp_le]) 1);
  11.407 +qed "HInfinite_add_gt_zero";
  11.408 +
  11.409 +goalw NSA.thy [HInfinite_def] 
  11.410 +     "(-x: HInfinite) = (x: HInfinite)";
  11.411 +by (auto_tac (claset(),simpset() addsimps 
  11.412 +    [hrabs_minus_cancel]));
  11.413 +qed "HInfinite_minus_iff";
  11.414 +
  11.415 +Goal "[|x: HInfinite; y <= 0; x <= 0|] \
  11.416 +\      ==> (x + y): HInfinite";
  11.417 +by (dtac (HInfinite_minus_iff RS iffD2) 1);
  11.418 +by (rtac (HInfinite_minus_iff RS iffD1) 1);
  11.419 +by (auto_tac (claset() addIs [HInfinite_add_ge_zero],
  11.420 +    simpset() addsimps [hypreal_minus_zero_le_iff RS sym,
  11.421 +    hypreal_minus_add_distrib]));
  11.422 +qed "HInfinite_add_le_zero";
  11.423 +
  11.424 +Goal "[|x: HInfinite; y < 0; x < 0|] \
  11.425 +\      ==> (x + y): HInfinite";
  11.426 +by (blast_tac (claset() addIs [HInfinite_add_le_zero,
  11.427 +    hypreal_less_imp_le]) 1);
  11.428 +qed "HInfinite_add_lt_zero";
  11.429 +
  11.430 +Goal "[|a: HFinite; b: HFinite; c: HFinite|] \ 
  11.431 +\     ==> a*a + b*b + c*c : HFinite";
  11.432 +by (auto_tac (claset() addIs [HFinite_mult,HFinite_add],
  11.433 +    simpset()));
  11.434 +qed "HFinite_sum_squares";
  11.435 +
  11.436 +Goal "!!x. x ~: Infinitesimal ==> x ~= 0";
  11.437 +by (Auto_tac);
  11.438 +qed "not_Infinitesimal_not_zero";
  11.439 +
  11.440 +Goal "!!x. x: HFinite - Infinitesimal ==> x ~= 0";
  11.441 +by (Auto_tac);
  11.442 +qed "not_Infinitesimal_not_zero2";
  11.443 +
  11.444 +Goal "!!x. x : Infinitesimal ==> abs x : Infinitesimal";
  11.445 +by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
  11.446 +by (auto_tac (claset(),simpset() addsimps [Infinitesimal_minus_iff RS sym]));
  11.447 +qed "Infinitesimal_hrabs";
  11.448 +
  11.449 +Goal "!!x. x ~: Infinitesimal ==> abs x ~: Infinitesimal";
  11.450 +by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
  11.451 +by (auto_tac (claset(),simpset() addsimps [Infinitesimal_minus_iff RS sym]));
  11.452 +qed "not_Infinitesimal_hrabs";
  11.453 +
  11.454 +Goal "!!x. abs x : Infinitesimal ==> x : Infinitesimal";
  11.455 +by (rtac ccontr 1);
  11.456 +by (blast_tac (claset() addDs [not_Infinitesimal_hrabs]) 1);
  11.457 +qed "hrabs_Infinitesimal_Infinitesimal";
  11.458 +
  11.459 +Goal "!!x. x : HFinite - Infinitesimal ==> abs x : HFinite - Infinitesimal";
  11.460 +by (fast_tac (set_cs addSEs [HFinite_hrabs,not_Infinitesimal_hrabs]) 1);
  11.461 +qed "HFinite_diff_Infinitesimal_hrabs";
  11.462 +
  11.463 +Goalw [Infinitesimal_def] 
  11.464 +      "!!x. [| e : Infinitesimal; abs x < e |] ==> x : Infinitesimal";
  11.465 +by (auto_tac (claset() addSDs [bspec],simpset()));
  11.466 +by (dres_inst_tac [("i","e")] (hrabs_ge_self RS hypreal_le_less_trans) 1);
  11.467 +by (fast_tac (claset() addIs [hypreal_less_trans]) 1);
  11.468 +qed "hrabs_less_Infinitesimal";
  11.469 +
  11.470 +Goal 
  11.471 + "!!x. [| e : Infinitesimal; abs x <= e |] ==> x : Infinitesimal";
  11.472 +by (blast_tac (claset() addDs [hypreal_le_imp_less_or_eq] addIs
  11.473 +    [hrabs_Infinitesimal_Infinitesimal,hrabs_less_Infinitesimal]) 1);
  11.474 +qed "hrabs_le_Infinitesimal";
  11.475 +
  11.476 +Goalw [Infinitesimal_def] 
  11.477 +      "!!x. [| e : Infinitesimal; \
  11.478 +\              e' : Infinitesimal; \
  11.479 +\              e' < x ; x < e |] ==> x : Infinitesimal";
  11.480 +by (auto_tac (claset() addSDs [bspec],simpset()));
  11.481 +by (dres_inst_tac [("i","e")] (hrabs_ge_self RS hypreal_le_less_trans) 1);
  11.482 +by (dtac (hrabs_interval_iff RS iffD1 RS conjunct1) 1);
  11.483 +by (fast_tac (claset() addIs [hypreal_less_trans,hrabs_interval_iff RS iffD2]) 1);
  11.484 +qed "Infinitesimal_interval";
  11.485 +
  11.486 +Goal "[| e : Infinitesimal; e' : Infinitesimal; \
  11.487 +\       e' <= x ; x <= e |] ==> x : Infinitesimal";
  11.488 +by (auto_tac (claset() addIs [Infinitesimal_interval],
  11.489 +    simpset() addsimps [hypreal_le_eq_less_or_eq]));
  11.490 +qed "Infinitesimal_interval2";
  11.491 +
  11.492 +Goalw [Infinitesimal_def] 
  11.493 +      "!! x y. [| x ~: Infinitesimal; \
  11.494 +\                 y ~: Infinitesimal|] \
  11.495 +\               ==> (x*y) ~:Infinitesimal";
  11.496 +by (Clarify_tac 1);
  11.497 +by (eres_inst_tac [("x","r*ra")] ballE 1);
  11.498 +by (fast_tac (claset() addIs [SReal_mult]) 2);
  11.499 +by (auto_tac (claset(),simpset() addsimps [hrabs_mult]));
  11.500 +by (blast_tac (claset() addSDs [hypreal_mult_order]) 1);
  11.501 +by (REPEAT(dtac hypreal_leI 1));
  11.502 +by (dtac hypreal_mult_le_ge_zero 1);
  11.503 +by (dres_inst_tac [("j","r*ra")] hypreal_less_le_trans 4);
  11.504 +by (auto_tac (claset(),simpset() addsimps [hypreal_less_not_refl]));
  11.505 +qed "not_Infinitesimal_mult";
  11.506 +
  11.507 +Goal "!! x. x*y : Infinitesimal ==> x : Infinitesimal | y : Infinitesimal";
  11.508 +by (rtac ccontr 1);
  11.509 +by (dtac (de_Morgan_disj RS iffD1) 1);
  11.510 +by (fast_tac (claset() addDs [not_Infinitesimal_mult]) 1);
  11.511 +qed "Infinitesimal_mult_disj";
  11.512 +
  11.513 +Goal "!! x. x: HFinite-Infinitesimal ==> x ~= 0";
  11.514 +by (fast_tac (claset() addIs [Infinitesimal_zero]) 1);
  11.515 +qed "HFinite_Infinitesimal_not_zero";
  11.516 +
  11.517 +Goal "!! x. [| x : HFinite - Infinitesimal; \
  11.518 +\                  y : HFinite - Infinitesimal \
  11.519 +\               |] ==> (x*y) : HFinite - Infinitesimal";
  11.520 +by (Clarify_tac 1);
  11.521 +by (blast_tac (claset() addDs [HFinite_mult,not_Infinitesimal_mult]) 1);
  11.522 +qed "HFinite_Infinitesimal_diff_mult";
  11.523 +
  11.524 +Goalw [Infinitesimal_def,HFinite_def]  
  11.525 +      "Infinitesimal <= HFinite";
  11.526 +by (blast_tac (claset() addSIs [SReal_one] 
  11.527 +    addSEs [(hypreal_zero_less_one RSN (2,impE))]) 1);
  11.528 +qed "Infinitesimal_subset_HFinite";
  11.529 +
  11.530 +Goal "!!x. x: Infinitesimal ==> x * hypreal_of_real r : Infinitesimal";
  11.531 +by (etac (HFinite_hypreal_of_real RSN 
  11.532 +          (2,Infinitesimal_HFinite_mult)) 1);
  11.533 +qed "Infinitesimal_hypreal_of_real_mult";
  11.534 +
  11.535 +Goal "!!x. x: Infinitesimal ==> hypreal_of_real r * x: Infinitesimal";
  11.536 +by (etac (HFinite_hypreal_of_real RSN 
  11.537 +          (2,Infinitesimal_HFinite_mult2)) 1);
  11.538 +qed "Infinitesimal_hypreal_of_real_mult2";
  11.539 +
  11.540 +(*----------------------------------------------------------------------
  11.541 +                   Infinitely close relation @=
  11.542 + ----------------------------------------------------------------------*)
  11.543 +
  11.544 +Goalw [Infinitesimal_def,inf_close_def] 
  11.545 +        "x:Infinitesimal = (x @= 0)";
  11.546 +by (Simp_tac 1);
  11.547 +qed "mem_infmal_iff";
  11.548 +
  11.549 +Goalw [inf_close_def]" (x @= y) = (x + -y @= 0)";
  11.550 +by (Simp_tac 1);
  11.551 +qed "inf_close_minus_iff";
  11.552 +
  11.553 +Goalw [inf_close_def]" (x @= y) = (-y + x @= 0)";
  11.554 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  11.555 +qed "inf_close_minus_iff2";
  11.556 +
  11.557 +Goalw [inf_close_def,Infinitesimal_def]  "x @= x";
  11.558 +by (Simp_tac 1);
  11.559 +qed "inf_close_refl";
  11.560 +
  11.561 +Goalw [inf_close_def]  "!! x y. x @= y ==> y @= x";
  11.562 +by (rtac (hypreal_minus_distrib1 RS subst) 1);
  11.563 +by (etac (Infinitesimal_minus_iff RS iffD1) 1);
  11.564 +qed "inf_close_sym";
  11.565 +
  11.566 +val prem1::prem2::rest = 
  11.567 +goalw thy [inf_close_def]  "[| x @= y; y @= z |] ==> x @= z";
  11.568 +by (res_inst_tac [("y1","y")] (hypreal_add_minus_cancel1 RS subst) 1);
  11.569 +by (simp_tac (simpset() addsimps [([prem1,prem2] MRS Infinitesimal_add)]) 1);
  11.570 +qed "inf_close_trans";
  11.571 +
  11.572 +val prem1::prem2::rest = goal thy "[| r @= x; s @= x |] ==> r @= s";
  11.573 +by (rtac ([prem1,prem2 RS inf_close_sym] MRS inf_close_trans) 1);
  11.574 +qed "inf_close_trans2";
  11.575 +
  11.576 +val prem1::prem2::rest = goal thy "[| x @= r; x @= s|] ==> r @= s";
  11.577 +by (rtac ([prem1 RS inf_close_sym,prem2] MRS inf_close_trans) 1);
  11.578 +qed "inf_close_trans3";
  11.579 +
  11.580 +Goal "(x + -y : Infinitesimal) = (x @= y)";
  11.581 +by (auto_tac (claset(),simpset() addsimps 
  11.582 +    [inf_close_minus_iff RS sym,mem_infmal_iff]));
  11.583 +qed "Infinitesimal_inf_close_minus";
  11.584 +
  11.585 +Goal "(x + -y : Infinitesimal) = (y @= x)";
  11.586 +by (auto_tac (claset() addIs [inf_close_sym],
  11.587 +    simpset() addsimps [inf_close_minus_iff RS sym,
  11.588 +    mem_infmal_iff]));
  11.589 +qed "Infinitesimal_inf_close_minus2";
  11.590 +
  11.591 +Goalw [monad_def] "(x @= y) = (monad(x)=monad(y))";
  11.592 +by (auto_tac (claset() addDs [inf_close_sym] 
  11.593 +    addSEs [inf_close_trans,equalityCE],
  11.594 +    simpset() addsimps [inf_close_refl]));
  11.595 +qed "inf_close_monad_iff";
  11.596 +
  11.597 +Goal "!!x y. [| x: Infinitesimal; y: Infinitesimal |] ==> x @= y";
  11.598 +by (asm_full_simp_tac (simpset() addsimps [mem_infmal_iff]) 1);
  11.599 +by (fast_tac (claset() addIs [inf_close_trans2]) 1);
  11.600 +qed "Infinitesimal_inf_close";
  11.601 +
  11.602 +val prem1::prem2::rest = 
  11.603 +goalw thy [inf_close_def] "[| a @= b; c @= d |] ==> a+c @= b+d";
  11.604 +by (rtac (hypreal_minus_add_distrib RS ssubst) 1);
  11.605 +by (rtac (hypreal_add_assoc RS ssubst) 1);
  11.606 +by (res_inst_tac [("y1","c")] (hypreal_add_left_commute RS subst) 1);
  11.607 +by (rtac (hypreal_add_assoc RS subst) 1);
  11.608 +by (rtac ([prem1,prem2] MRS Infinitesimal_add) 1);
  11.609 +qed "inf_close_add";
  11.610 +
  11.611 +Goal "!!a. a @= b ==> -a @= -b";
  11.612 +by (rtac ((inf_close_minus_iff RS iffD2) RS inf_close_sym) 1);
  11.613 +by (dtac (inf_close_minus_iff RS iffD1) 1);
  11.614 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  11.615 +qed "inf_close_minus";
  11.616 +
  11.617 +Goal "!!a. -a @= -b ==> a @= b";
  11.618 +by (auto_tac (claset() addDs [inf_close_minus],simpset()));
  11.619 +qed "inf_close_minus2";
  11.620 +
  11.621 +Goal "(-a @= -b) = (a @= b)";
  11.622 +by (blast_tac (claset() addIs [inf_close_minus,inf_close_minus2]) 1);
  11.623 +qed "inf_close_minus_cancel";
  11.624 +
  11.625 +Addsimps [inf_close_minus_cancel];
  11.626 +
  11.627 +Goal "!!a. [| a @= b; c @= d |] ==> a + -c @= b + -d";
  11.628 +by (blast_tac (claset() addSIs [inf_close_add,inf_close_minus]) 1);
  11.629 +qed "inf_close_add_minus";
  11.630 +
  11.631 +Goalw [inf_close_def] "!!a. [| a @= b; c: HFinite|] ==> a*c @= b*c"; 
  11.632 +by (asm_full_simp_tac (simpset() addsimps [Infinitesimal_HFinite_mult,
  11.633 +    hypreal_minus_mult_eq1,hypreal_add_mult_distrib RS sym] 
  11.634 +    delsimps [hypreal_minus_mult_eq1 RS sym]) 1);
  11.635 +qed "inf_close_mult1";
  11.636 +
  11.637 +Goal "!!a. [|a @= b; c: HFinite|] ==> c*a @= c*b"; 
  11.638 +by (asm_simp_tac (simpset() addsimps [inf_close_mult1,hypreal_mult_commute]) 1);
  11.639 +qed "inf_close_mult2";
  11.640 +
  11.641 +val [prem1,prem2,prem3,prem4] = 
  11.642 +goal thy "[|a @= b; c @= d; b: HFinite; c: HFinite|] ==> a*c @= b*d";
  11.643 +by (fast_tac (claset() addIs [([prem1,prem4] MRS inf_close_mult1), 
  11.644 +    ([prem2,prem3] MRS inf_close_mult2),inf_close_trans]) 1);
  11.645 +qed "inf_close_mult_HFinite";
  11.646 +
  11.647 +Goal "!!u. [|u @= v*x; x @= y; v: HFinite|] ==> u @= v*y";
  11.648 +by (fast_tac (claset() addIs [inf_close_mult2,inf_close_trans]) 1);
  11.649 +qed "inf_close_mult_subst";
  11.650 +
  11.651 +Goal "!!u. [| u @= x*v; x @= y; v: HFinite |] ==> u @= y*v";
  11.652 +by (fast_tac (claset() addIs [inf_close_mult1,inf_close_trans]) 1);
  11.653 +qed "inf_close_mult_subst2";
  11.654 +
  11.655 +Goal "!!u. [| u @= x*hypreal_of_real v; x @= y |] ==> u @= y*hypreal_of_real v";
  11.656 +by (auto_tac (claset() addIs [inf_close_mult_subst2],simpset()));
  11.657 +qed "inf_close_mult_subst_SReal";
  11.658 +
  11.659 +Goalw [inf_close_def]  "!!a. a = b ==> a @= b";
  11.660 +by (Asm_simp_tac 1);
  11.661 +qed "inf_close_eq_imp";
  11.662 +
  11.663 +Goal "!!x. x: Infinitesimal ==> -x @= x"; 
  11.664 +by (fast_tac (HOL_cs addIs [Infinitesimal_minus_iff RS iffD1,
  11.665 +    mem_infmal_iff RS iffD1,inf_close_trans2]) 1);
  11.666 +qed "Infinitesimal_minus_inf_close";
  11.667 +
  11.668 +Goalw [inf_close_def]  "(EX y: Infinitesimal. x + -z = y) = (x @= z)";
  11.669 +by (Blast_tac 1);
  11.670 +qed "bex_Infinitesimal_iff";
  11.671 +
  11.672 +Goal "(EX y: Infinitesimal. x = z + y) = (x @= z)";
  11.673 +by (asm_full_simp_tac (simpset() addsimps [hypreal_eq_minus_iff4,
  11.674 +    bex_Infinitesimal_iff RS sym]) 1);
  11.675 +qed "bex_Infinitesimal_iff2";
  11.676 +
  11.677 +Goal "!!x. [| y: Infinitesimal; x + y = z |] ==> x @= z";
  11.678 +by (rtac (bex_Infinitesimal_iff RS iffD1) 1);
  11.679 +by (dtac (Infinitesimal_minus_iff RS iffD1) 1);
  11.680 +by (auto_tac (claset(),simpset() addsimps [hypreal_minus_add_distrib,
  11.681 +    hypreal_add_assoc RS sym]));
  11.682 +qed "Infinitesimal_add_inf_close";
  11.683 +
  11.684 +Goal "!!y. y: Infinitesimal ==> x @= x + y";
  11.685 +by (rtac (bex_Infinitesimal_iff RS iffD1) 1);
  11.686 +by (dtac (Infinitesimal_minus_iff RS iffD1) 1);
  11.687 +by (auto_tac (claset(),simpset() addsimps [hypreal_minus_add_distrib,
  11.688 +    hypreal_add_assoc RS sym]));
  11.689 +qed "Infinitesimal_add_inf_close_self";
  11.690 +
  11.691 +Goal "!!y. y: Infinitesimal ==> x @= y + x";
  11.692 +by (auto_tac (claset() addDs [Infinitesimal_add_inf_close_self],
  11.693 +    simpset() addsimps [hypreal_add_commute]));
  11.694 +qed "Infinitesimal_add_inf_close_self2";
  11.695 +
  11.696 +Goal "!!y. y: Infinitesimal ==> x @= x + -y";
  11.697 +by (blast_tac (claset() addSIs [Infinitesimal_add_inf_close_self,
  11.698 +    Infinitesimal_minus_iff RS iffD1]) 1);
  11.699 +qed "Infinitesimal_add_minus_inf_close_self";
  11.700 +
  11.701 +Goal "!!x. [| y: Infinitesimal; x+y @= z|] ==> x @= z";
  11.702 +by (dres_inst_tac [("x","x")] (Infinitesimal_add_inf_close_self RS inf_close_sym) 1);
  11.703 +by (etac (inf_close_trans3 RS inf_close_sym) 1);
  11.704 +by (assume_tac 1);
  11.705 +qed "Infinitesimal_add_cancel";
  11.706 +
  11.707 +Goal "!!x. [| y: Infinitesimal; x @= z + y|] ==> x @= z";
  11.708 +by (dres_inst_tac [("x","z")] (Infinitesimal_add_inf_close_self2  RS inf_close_sym) 1);
  11.709 +by (etac (inf_close_trans3 RS inf_close_sym) 1);
  11.710 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  11.711 +by (etac inf_close_sym 1);
  11.712 +qed "Infinitesimal_add_right_cancel";
  11.713 +
  11.714 +Goal "!!a. d + b  @= d + c ==> b @= c";
  11.715 +by (dtac (inf_close_minus_iff RS iffD1) 1);
  11.716 +by (asm_full_simp_tac (simpset() addsimps 
  11.717 +    [hypreal_minus_add_distrib,inf_close_minus_iff RS sym] 
  11.718 +    @ hypreal_add_ac) 1);
  11.719 +qed "inf_close_add_left_cancel";
  11.720 +
  11.721 +Goal "!!a. b + d @= c + d ==> b @= c";
  11.722 +by (rtac inf_close_add_left_cancel 1);
  11.723 +by (asm_full_simp_tac (simpset() addsimps 
  11.724 +    [hypreal_add_commute]) 1);
  11.725 +qed "inf_close_add_right_cancel";
  11.726 +
  11.727 +Goal "!!a. b @= c ==> d + b @= d + c";
  11.728 +by (rtac (inf_close_minus_iff RS iffD2) 1);
  11.729 +by (asm_full_simp_tac (simpset() addsimps 
  11.730 +    [hypreal_minus_add_distrib,inf_close_minus_iff RS sym] 
  11.731 +    @ hypreal_add_ac) 1);
  11.732 +qed "inf_close_add_mono1";
  11.733 +
  11.734 +Goal "!!a. b @= c ==> b + a @= c + a";
  11.735 +by (asm_simp_tac (simpset() addsimps 
  11.736 +    [hypreal_add_commute,inf_close_add_mono1]) 1);
  11.737 +qed "inf_close_add_mono2";
  11.738 +
  11.739 +Goal "(a + b @= a + c) = (b @= c)";
  11.740 +by (fast_tac (claset() addEs [inf_close_add_left_cancel,
  11.741 +    inf_close_add_mono1]) 1);
  11.742 +qed "inf_close_add_left_iff";
  11.743 +
  11.744 +Addsimps [inf_close_add_left_iff];
  11.745 +
  11.746 +Goal "(b + a @= c + a) = (b @= c)";
  11.747 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  11.748 +qed "inf_close_add_right_iff";
  11.749 +
  11.750 +Addsimps [inf_close_add_right_iff];
  11.751 +
  11.752 +Goal "!!x. [| x: HFinite; x @= y |] ==> y: HFinite";
  11.753 +by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1);
  11.754 +by (Step_tac 1);
  11.755 +by (dtac (Infinitesimal_subset_HFinite RS subsetD 
  11.756 +           RS (HFinite_minus_iff RS iffD1)) 1);
  11.757 +by (dtac HFinite_add 1);
  11.758 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
  11.759 +qed "inf_close_HFinite";
  11.760 +
  11.761 +Goal "!!x. x @= hypreal_of_real D ==> x: HFinite";
  11.762 +by (rtac (inf_close_sym RSN (2,inf_close_HFinite)) 1);
  11.763 +by (Auto_tac);
  11.764 +qed "inf_close_hypreal_of_real_HFinite";
  11.765 +
  11.766 +Goal "[|a @= hypreal_of_real b; c @= hypreal_of_real d |] \
  11.767 +\     ==> a*c @= hypreal_of_real b*hypreal_of_real d";
  11.768 +by (blast_tac (claset() addSIs [inf_close_mult_HFinite,
  11.769 +     inf_close_hypreal_of_real_HFinite,HFinite_hypreal_of_real]) 1);
  11.770 +qed "inf_close_mult_hypreal_of_real";
  11.771 +
  11.772 +Goal "!!a. [| a: SReal; a ~= 0; a*x @= 0 |] ==> x @= 0";
  11.773 +by (dtac (SReal_hrinv RS (SReal_subset_HFinite RS subsetD)) 1);
  11.774 +by (auto_tac (claset() addDs [inf_close_mult2],
  11.775 +    simpset() addsimps [hypreal_mult_assoc RS sym]));
  11.776 +qed "inf_close_SReal_mult_cancel_zero";
  11.777 +
  11.778 +(* REM comments: newly added *)
  11.779 +Goal "!!a. [| a: SReal; x @= 0 |] ==> x*a @= 0";
  11.780 +by (auto_tac (claset() addDs [(SReal_subset_HFinite RS subsetD),
  11.781 +              inf_close_mult1],simpset()));
  11.782 +qed "inf_close_mult_SReal1";
  11.783 +
  11.784 +Goal "!!a. [| a: SReal; x @= 0 |] ==> a*x @= 0";
  11.785 +by (auto_tac (claset() addDs [(SReal_subset_HFinite RS subsetD),
  11.786 +              inf_close_mult2],simpset()));
  11.787 +qed "inf_close_mult_SReal2";
  11.788 +
  11.789 +Goal "[|a : SReal; a ~= 0 |] ==> (a*x @= 0) = (x @= 0)";
  11.790 +by (blast_tac (claset() addIs [inf_close_SReal_mult_cancel_zero,
  11.791 +    inf_close_mult_SReal2]) 1);
  11.792 +qed "inf_close_mult_SReal_zero_cancel_iff";
  11.793 +Addsimps [inf_close_mult_SReal_zero_cancel_iff];
  11.794 +
  11.795 +Goal "!!a. [| a: SReal; a ~= 0; a* w @= a*z |] ==> w @= z";
  11.796 +by (dtac (SReal_hrinv RS (SReal_subset_HFinite RS subsetD)) 1);
  11.797 +by (auto_tac (claset() addDs [inf_close_mult2],
  11.798 +    simpset() addsimps [hypreal_mult_assoc RS sym]));
  11.799 +qed "inf_close_SReal_mult_cancel";
  11.800 +
  11.801 +Goal "!!a. [| a: SReal; a ~= 0|] ==> (a* w @= a*z) = (w @= z)";
  11.802 +by (auto_tac (claset() addSIs [inf_close_mult2,SReal_subset_HFinite RS subsetD] 
  11.803 +    addIs [inf_close_SReal_mult_cancel],simpset()));
  11.804 +qed "inf_close_SReal_mult_cancel_iff1";
  11.805 +Addsimps [inf_close_SReal_mult_cancel_iff1];
  11.806 +
  11.807 +Goal "[| z <= f; f @= g; g <= z |] ==> f @= z";
  11.808 +by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1);
  11.809 +by (Auto_tac);
  11.810 +by (dres_inst_tac [("x","-g")] hypreal_add_left_le_mono1 1);
  11.811 +by (dres_inst_tac [("x","-g")] hypreal_add_le_mono1 1);
  11.812 +by (res_inst_tac [("y","-y")] Infinitesimal_add_cancel 1);
  11.813 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc RS sym,
  11.814 +    Infinitesimal_minus_iff RS sym]));
  11.815 +by (rtac inf_close_sym 1);
  11.816 +by (simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
  11.817 +by (rtac (inf_close_minus_iff RS iffD2) 1);
  11.818 +by (auto_tac (claset(),simpset() addsimps [mem_infmal_iff RS sym,
  11.819 +    hypreal_add_commute]));
  11.820 +by (rtac Infinitesimal_interval2 1 THEN Auto_tac);
  11.821 +qed "inf_close_le_bound";
  11.822 +
  11.823 +Goal "[| z <= f; f @= g; g <= z |] ==> g @= z";
  11.824 +by (rtac inf_close_trans3 1);
  11.825 +by (auto_tac (claset() addIs [inf_close_le_bound],simpset()));
  11.826 +qed "inf_close_le_bound2";
  11.827 +
  11.828 +(*-----------------------------------------------------------------
  11.829 +    Zero is the only infinitesimal that is also a real
  11.830 + -----------------------------------------------------------------*)
  11.831 +
  11.832 +Goalw [Infinitesimal_def] 
  11.833 +      "[| x: SReal; y: Infinitesimal; 0 < x |] ==> y < x";
  11.834 +by (rtac (hrabs_ge_self RS hypreal_le_less_trans) 1);
  11.835 +by (Blast_tac 1);
  11.836 +qed "Infinitesimal_less_SReal";
  11.837 +
  11.838 +Goal "y: Infinitesimal ==> ALL r: SReal. 0 < r --> y < r";
  11.839 +by (blast_tac (claset() addIs [Infinitesimal_less_SReal]) 1);
  11.840 +qed "Infinitesimal_less_SReal2";
  11.841 +
  11.842 +Goalw [Infinitesimal_def] 
  11.843 +      "!!y. [| y: SReal; 0 < y|] ==> y ~: Infinitesimal";
  11.844 +by (auto_tac (claset() addSDs [bspec] addSEs [hypreal_less_irrefl],
  11.845 +    simpset() addsimps [hrabs_eqI2]));
  11.846 +qed "SReal_not_Infinitesimal";
  11.847 +
  11.848 +(* [| y : SReal; 0 < y; y : Infinitesimal |] ==> R *)
  11.849 +bind_thm("SReal_not_InfinitesimalE", (SReal_not_Infinitesimal RS notE));
  11.850 +
  11.851 +Goal "!!y. [| y : SReal; y < 0 |] ==> y ~:Infinitesimal";
  11.852 +by (blast_tac (claset() addDs [(hypreal_minus_zero_less_iff RS iffD2),
  11.853 +    SReal_minus,(Infinitesimal_minus_iff RS iffD1),SReal_not_Infinitesimal]) 1);
  11.854 +qed "SReal_minus_not_Infinitesimal";
  11.855 +
  11.856 +(* [| y : SReal; y < 0; y : Infinitesimal |] ==> R *)
  11.857 +bind_thm("SReal_minus_not_InfinitesimalE", (SReal_minus_not_Infinitesimal RS notE));
  11.858 +
  11.859 +Goal "SReal Int Infinitesimal = {0}";
  11.860 +by (auto_tac (claset(),simpset() addsimps [SReal_zero]));
  11.861 +by (cut_inst_tac [("x","x"),("y","0")] hypreal_linear 1);
  11.862 +by (blast_tac (claset() addIs [SReal_not_InfinitesimalE,
  11.863 +    SReal_minus_not_InfinitesimalE]) 1);
  11.864 +qed "SReal_Int_Infinitesimal_zero";
  11.865 +
  11.866 +Goal "0 : (SReal Int Infinitesimal)";
  11.867 +by (simp_tac (simpset() addsimps [SReal_zero]) 1);
  11.868 +qed "zero_mem_SReal_Int_Infinitesimal";
  11.869 +
  11.870 +Goal "!!x. [| x: SReal; x: Infinitesimal|] ==> x = 0";
  11.871 +by (cut_facts_tac [SReal_Int_Infinitesimal_zero] 1);
  11.872 +by (blast_tac (claset() addEs [equalityE]) 1);
  11.873 +qed "SReal_Infinitesimal_zero";
  11.874 +
  11.875 +Goal "!!x. [| x : SReal; x ~= 0 |] \
  11.876 +\              ==> x : HFinite - Infinitesimal";
  11.877 +by (auto_tac (claset() addDs [SReal_Infinitesimal_zero,
  11.878 +          SReal_subset_HFinite RS subsetD],simpset()));
  11.879 +qed "SReal_HFinite_diff_Infinitesimal";
  11.880 +
  11.881 +Goal "!!x. hypreal_of_real x ~= 0 ==> hypreal_of_real x : HFinite - Infinitesimal";
  11.882 +by (rtac SReal_HFinite_diff_Infinitesimal 1);
  11.883 +by (Auto_tac);
  11.884 +qed "hypreal_of_real_HFinite_diff_Infinitesimal";
  11.885 +
  11.886 +Goal "1hr+1hr ~: Infinitesimal";
  11.887 +by (fast_tac (claset() addIs [SReal_two RS SReal_Infinitesimal_zero,
  11.888 +    hypreal_two_not_zero RS notE]) 1);
  11.889 +qed "two_not_Infinitesimal";
  11.890 +
  11.891 +Goal "1hr ~: Infinitesimal";
  11.892 +by (auto_tac (claset() addSDs [SReal_one RS SReal_Infinitesimal_zero],
  11.893 +    simpset() addsimps [hypreal_zero_not_eq_one RS not_sym]));
  11.894 +qed "hypreal_one_not_Infinitesimal";
  11.895 +Addsimps [hypreal_one_not_Infinitesimal];
  11.896 +
  11.897 +Goal "!!x. [| y: SReal; x @= y; y~= 0 |] ==> x ~= 0";
  11.898 +by (cut_inst_tac [("x","y")] hypreal_trichotomy 1);
  11.899 +by (blast_tac (claset() addDs 
  11.900 +    [inf_close_sym RS (mem_infmal_iff RS iffD2),
  11.901 +     SReal_not_Infinitesimal,SReal_minus_not_Infinitesimal]) 1);
  11.902 +qed "inf_close_SReal_not_zero";
  11.903 +
  11.904 +Goal "!!x. [| x @= hypreal_of_real y; hypreal_of_real y ~= 0 |] ==> x ~= 0";
  11.905 +by (rtac inf_close_SReal_not_zero 1);
  11.906 +by (Auto_tac);
  11.907 +qed "inf_close_hypreal_of_real_not_zero";
  11.908 +
  11.909 +Goal "!!x. [| x @= y; y : HFinite - Infinitesimal |] \
  11.910 +\                  ==> x : HFinite - Infinitesimal";
  11.911 +by (auto_tac (claset() addIs [inf_close_sym RSN (2,inf_close_HFinite)],
  11.912 +    simpset() addsimps [mem_infmal_iff]));
  11.913 +by (dtac inf_close_trans3 1 THEN assume_tac 1);
  11.914 +by (blast_tac (claset() addDs [inf_close_sym]) 1);
  11.915 +qed "HFinite_diff_Infinitesimal_inf_close";
  11.916 +
  11.917 +Goal "!!x. [| y ~= 0; y: Infinitesimal; \
  11.918 +\                 x*hrinv(y) : HFinite \
  11.919 +\              |] ==> x : Infinitesimal";
  11.920 +by (dtac Infinitesimal_HFinite_mult2 1);
  11.921 +by (assume_tac 1);
  11.922 +by (asm_full_simp_tac (simpset() 
  11.923 +    addsimps [hypreal_mult_assoc]) 1);
  11.924 +qed "Infinitesimal_ratio";
  11.925 +
  11.926 +(*------------------------------------------------------------------
  11.927 +       Standard Part Theorem: Every finite x: R* is infinitely 
  11.928 +       close to a unique real number (i.e a member of SReal)
  11.929 + ------------------------------------------------------------------*)
  11.930 +(*------------------------------------------------------------------
  11.931 +         Uniqueness: Two infinitely close reals are equal
  11.932 + ------------------------------------------------------------------*)
  11.933 +
  11.934 +Goal "!!x. [|x: SReal; y: SReal|] ==> (x @= y) = (x = y)";
  11.935 +by (auto_tac (claset(),simpset() addsimps [inf_close_refl]));
  11.936 +by (rewrite_goals_tac [inf_close_def]);
  11.937 +by (dres_inst_tac [("x","y")] SReal_minus 1);
  11.938 +by (dtac SReal_add 1 THEN assume_tac 1);
  11.939 +by (dtac SReal_Infinitesimal_zero 1 THEN assume_tac 1);
  11.940 +by (dtac sym 1);
  11.941 +by (asm_full_simp_tac (simpset() addsimps [hypreal_eq_minus_iff RS sym]) 1);
  11.942 +qed "SReal_inf_close_iff";
  11.943 +
  11.944 +Goal "(hypreal_of_real k @= hypreal_of_real m) = (k = m)";
  11.945 +by (auto_tac (claset(),simpset() addsimps [inf_close_refl,
  11.946 +    SReal_inf_close_iff,inj_hypreal_of_real RS injD]));
  11.947 +qed "hypreal_of_real_inf_close_iff";
  11.948 + 
  11.949 +Addsimps [hypreal_of_real_inf_close_iff];
  11.950 +
  11.951 +Goal "!!r. [| r: SReal; s: SReal; r @= x; s @= x|] ==> r = s";
  11.952 +by (blast_tac (claset() addIs [(SReal_inf_close_iff RS iffD1),
  11.953 +               inf_close_trans2]) 1);
  11.954 +qed "inf_close_unique_real";
  11.955 +
  11.956 +(*------------------------------------------------------------------
  11.957 +       Existence of unique real infinitely close
  11.958 + ------------------------------------------------------------------*)
  11.959 +(* lemma about lubs *)
  11.960 +Goal "!!(x::hypreal). [| isLub R S x; isLub R S y |] ==> x = y";
  11.961 +by (forward_tac [isLub_isUb] 1);
  11.962 +by (forw_inst_tac [("x","y")] isLub_isUb 1);
  11.963 +by (blast_tac (claset() addSIs [hypreal_le_anti_sym]
  11.964 +                addSDs [isLub_le_isUb]) 1);
  11.965 +qed "hypreal_isLub_unique";
  11.966 +
  11.967 +Goal "!!x. x: HFinite ==> EX u. isUb SReal {s. s: SReal & s < x} u";
  11.968 +by (dtac HFiniteD 1 THEN Step_tac 1);
  11.969 +by (rtac exI 1 THEN rtac isUbI 1 THEN assume_tac 2);
  11.970 +by (auto_tac (claset() addIs [hypreal_less_imp_le,setleI,isUbI,
  11.971 +    hypreal_less_trans],simpset() addsimps [hrabs_interval_iff]));
  11.972 +qed "lemma_st_part_ub";
  11.973 +
  11.974 +Goal "!!x. x: HFinite ==> EX y. y: {s. s: SReal & s < x}";
  11.975 +by (dtac HFiniteD 1 THEN Step_tac 1);
  11.976 +by (dtac SReal_minus 1);
  11.977 +by (auto_tac (claset(),simpset() addsimps [hrabs_interval_iff]));
  11.978 +qed "lemma_st_part_nonempty";
  11.979 +
  11.980 +Goal "{s. s: SReal & s < x} <= SReal";
  11.981 +by (Auto_tac);
  11.982 +qed "lemma_st_part_subset";
  11.983 +
  11.984 +Goal "!!x. x: HFinite ==> EX t. isLub SReal {s. s: SReal & s < x} t";
  11.985 +by (blast_tac (claset() addSIs [SReal_complete,lemma_st_part_ub,
  11.986 +    lemma_st_part_nonempty, lemma_st_part_subset]) 1);
  11.987 +qed "lemma_st_part_lub";
  11.988 +
  11.989 +Goal "((t::hypreal) + r <= t) = (r <= 0)";
  11.990 +by (Step_tac 1);
  11.991 +by (dres_inst_tac [("x","-t")] hypreal_add_left_le_mono1 1);
  11.992 +by (dres_inst_tac [("x","t")] hypreal_add_left_le_mono1 2);
  11.993 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc RS sym]));
  11.994 +qed "lemma_hypreal_le_left_cancel";
  11.995 +
  11.996 +Goal "!!x. [| x: HFinite; \
  11.997 +\                 isLub SReal {s. s: SReal & s < x} t; \
  11.998 +\                 r: SReal; 0 < r \
  11.999 +\              |] ==> x <= t + r";
 11.1000 +by (forward_tac [isLubD1a] 1);
 11.1001 +by (rtac ccontr 1 THEN dtac not_hypreal_leE 1);
 11.1002 +by (dres_inst_tac [("x","t")] SReal_add 1 THEN assume_tac 1);
 11.1003 +by (dres_inst_tac [("y","t + r")] (isLubD1 RS setleD) 1);
 11.1004 +by (auto_tac (claset(),simpset() addsimps [lemma_hypreal_le_left_cancel]));
 11.1005 +by (dtac hypreal_less_le_trans 1 THEN assume_tac 1);
 11.1006 +by (asm_full_simp_tac (simpset() addsimps [hypreal_less_not_refl]) 1);
 11.1007 +qed "lemma_st_part_le1";
 11.1008 +
 11.1009 +Goalw [setle_def] "!!x::hypreal. [| S *<= x; x < y |] ==> S *<= y";
 11.1010 +by (auto_tac (claset() addSDs [bspec,hypreal_le_less_trans]
 11.1011 +    addIs [hypreal_less_imp_le],simpset()));
 11.1012 +qed "hypreal_setle_less_trans";
 11.1013 +
 11.1014 +Goalw [isUb_def] 
 11.1015 +     "!!x::hypreal. [| isUb R S x; x < y; y: R |] ==> isUb R S y";
 11.1016 +by (blast_tac (claset() addIs [hypreal_setle_less_trans]) 1);
 11.1017 +qed "hypreal_gt_isUb";
 11.1018 +
 11.1019 +Goal "!!x. [| x: HFinite; x < y; y: SReal |] \
 11.1020 +\              ==> isUb SReal {s. s: SReal & s < x} y";
 11.1021 +by (auto_tac (claset() addDs [hypreal_less_trans]
 11.1022 +    addIs [hypreal_less_imp_le] addSIs [isUbI,setleI],simpset()));
 11.1023 +qed "lemma_st_part_gt_ub";
 11.1024 +
 11.1025 +Goal "!!t. t <= t + -r ==> r <= (0::hypreal)";
 11.1026 +by (dres_inst_tac [("x","-t")] hypreal_add_left_le_mono1 1);
 11.1027 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc RS sym]));
 11.1028 +by (dres_inst_tac [("x","r")] hypreal_add_left_le_mono1 1);
 11.1029 +by (Auto_tac);
 11.1030 +qed "lemma_minus_le_zero";
 11.1031 +
 11.1032 +Goal "[| x: HFinite; \
 11.1033 +\        isLub SReal {s. s: SReal & s < x} t; \
 11.1034 +\        r: SReal; 0 < r |] \
 11.1035 +\     ==> t + -r <= x";
 11.1036 +by (forward_tac [isLubD1a] 1);
 11.1037 +by (rtac ccontr 1 THEN dtac not_hypreal_leE 1);
 11.1038 +by (dtac SReal_minus 1 THEN dres_inst_tac [("x","t")] 
 11.1039 +    SReal_add 1 THEN assume_tac 1);
 11.1040 +by (dtac lemma_st_part_gt_ub 1 THEN REPEAT(assume_tac 1));
 11.1041 +by (dtac isLub_le_isUb 1 THEN assume_tac 1);
 11.1042 +by (dtac lemma_minus_le_zero 1);
 11.1043 +by (auto_tac (claset() addDs [hypreal_less_le_trans],
 11.1044 +    simpset() addsimps [hypreal_less_not_refl]));
 11.1045 +qed "lemma_st_part_le2";
 11.1046 +
 11.1047 +Goal "((x::hypreal) <= t + r) = (x + -t <= r)";
 11.1048 +by (Step_tac 1);
 11.1049 +by (dres_inst_tac [("x","-t")] hypreal_add_left_le_mono1 1);
 11.1050 +by (dres_inst_tac [("x","t")] hypreal_add_le_mono1 2);
 11.1051 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
 11.1052 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 2);
 11.1053 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_commute]));
 11.1054 +qed "lemma_hypreal_le_swap";
 11.1055 +
 11.1056 +Goal "[| x: HFinite; \
 11.1057 +\        isLub SReal {s. s: SReal & s < x} t; \
 11.1058 +\        r: SReal; 0 < r |] \
 11.1059 +\     ==> x + -t <= r";
 11.1060 +by (blast_tac (claset() addSIs [lemma_hypreal_le_swap RS iffD1,
 11.1061 +                lemma_st_part_le1]) 1);
 11.1062 +qed "lemma_st_part1a";
 11.1063 +
 11.1064 +Goal "(t + -r <= x) = (-(x + -t) <= (r::hypreal))";
 11.1065 +by (auto_tac (claset(),simpset() addsimps [hypreal_minus_add_distrib,
 11.1066 +    hypreal_add_commute,lemma_hypreal_le_swap  RS sym]));
 11.1067 +qed "lemma_hypreal_le_swap2";
 11.1068 +
 11.1069 +Goal "[| x: HFinite; \
 11.1070 +\        isLub SReal {s. s: SReal & s < x} t; \
 11.1071 +\        r: SReal; 0 < r |] \
 11.1072 +\     ==> -(x + -t) <= r";
 11.1073 +by (blast_tac (claset() addSIs [lemma_hypreal_le_swap2 RS iffD1,
 11.1074 +                lemma_st_part_le2]) 1);
 11.1075 +qed "lemma_st_part2a";
 11.1076 +
 11.1077 +Goal "x: SReal ==> isUb SReal {s. s: SReal & s < x} x";
 11.1078 +by (auto_tac (claset() addIs [isUbI, setleI,hypreal_less_imp_le],simpset()));
 11.1079 +qed "lemma_SReal_ub";
 11.1080 +
 11.1081 +Goal "x: SReal ==> isLub SReal {s. s: SReal & s < x} x";
 11.1082 +by (auto_tac (claset() addSIs [isLubI2,lemma_SReal_ub,setgeI],simpset()));
 11.1083 +by (forward_tac [isUbD2a] 1);
 11.1084 +by (res_inst_tac [("x","x"),("y","y")] hypreal_linear_less2 1);
 11.1085 +by (auto_tac (claset() addSIs [hypreal_less_imp_le,hypreal_le_refl],simpset()));
 11.1086 +by (EVERY1[dtac SReal_dense, assume_tac, assume_tac, Step_tac]);
 11.1087 +by (dres_inst_tac [("y","r")] isUbD 1);
 11.1088 +by (auto_tac (claset() addDs [hypreal_less_le_trans],
 11.1089 +    simpset() addsimps [hypreal_less_not_refl]));
 11.1090 +qed "lemma_SReal_lub";
 11.1091 +
 11.1092 +Goal "[| x: HFinite; \
 11.1093 +\        isLub SReal {s. s: SReal & s < x} t; \
 11.1094 +\        r: SReal; 0 < r |] \
 11.1095 +\     ==> x + -t ~= r";
 11.1096 +by (Auto_tac);
 11.1097 +by (forward_tac [isLubD1a RS SReal_minus] 1);
 11.1098 +by (dtac SReal_add_cancel 1 THEN assume_tac 1);
 11.1099 +by (dres_inst_tac [("x","x")] lemma_SReal_lub 1);
 11.1100 +by (dtac hypreal_isLub_unique 1 THEN assume_tac 1);
 11.1101 +by (auto_tac (claset(),simpset() addsimps [hypreal_less_not_refl]));
 11.1102 +qed "lemma_st_part_not_eq1";
 11.1103 +
 11.1104 +Goal "[| x: HFinite; \
 11.1105 +\        isLub SReal {s. s: SReal & s < x} t; \
 11.1106 +\        r: SReal; 0 < r |] \
 11.1107 +\     ==> -(x + -t) ~= r";
 11.1108 +by (auto_tac (claset(),simpset() addsimps [hypreal_minus_add_distrib]));
 11.1109 +by (forward_tac [isLubD1a] 1);
 11.1110 +by (dtac SReal_add_cancel 1 THEN assume_tac 1);
 11.1111 +by (dres_inst_tac [("x","-x")] SReal_minus 1);
 11.1112 +by (Asm_full_simp_tac 1);
 11.1113 +by (dres_inst_tac [("x","x")] lemma_SReal_lub 1);
 11.1114 +by (dtac hypreal_isLub_unique 1 THEN assume_tac 1);
 11.1115 +by (auto_tac (claset(),simpset() addsimps [hypreal_less_not_refl]));
 11.1116 +qed "lemma_st_part_not_eq2";
 11.1117 +
 11.1118 +Goal "[| x: HFinite; \
 11.1119 +\        isLub SReal {s. s: SReal & s < x} t; \
 11.1120 +\        r: SReal; 0 < r |] \
 11.1121 +\     ==> abs (x + -t) < r";
 11.1122 +by (forward_tac [lemma_st_part1a] 1);
 11.1123 +by (forward_tac [lemma_st_part2a] 4);
 11.1124 +by (Auto_tac);
 11.1125 +by (REPEAT(dtac hypreal_le_imp_less_or_eq 1));
 11.1126 +by (auto_tac (claset() addDs [lemma_st_part_not_eq1,
 11.1127 +    lemma_st_part_not_eq2],simpset() addsimps [hrabs_interval_iff2]));
 11.1128 +qed "lemma_st_part_major";
 11.1129 +
 11.1130 +Goal "[| x: HFinite; \
 11.1131 +\        isLub SReal {s. s: SReal & s < x} t |] \
 11.1132 +\     ==> ALL r: SReal. 0 < r --> abs (x + -t) < r";
 11.1133 +by (blast_tac (claset() addSDs [lemma_st_part_major]) 1);
 11.1134 +qed "lemma_st_part_major2";
 11.1135 +
 11.1136 +(*----------------------------------------------
 11.1137 +  Existence of real and Standard Part Theorem
 11.1138 + ----------------------------------------------*)
 11.1139 +Goal "x: HFinite ==> \
 11.1140 +\     EX t: SReal. ALL r: SReal. 0 < r --> abs (x + -t) < r";
 11.1141 +by (forward_tac [lemma_st_part_lub] 1 THEN Step_tac 1);
 11.1142 +by (forward_tac [isLubD1a] 1);
 11.1143 +by (blast_tac (claset() addDs [lemma_st_part_major2]) 1);
 11.1144 +qed "lemma_st_part_Ex";
 11.1145 +
 11.1146 +Goalw [inf_close_def,Infinitesimal_def] 
 11.1147 +          "x:HFinite ==> EX t: SReal. x @= t";
 11.1148 +by (blast_tac (claset() addSDs [lemma_st_part_Ex]) 1);
 11.1149 +qed "st_part_Ex";
 11.1150 +
 11.1151 +(*--------------------------------
 11.1152 +  Unique real infinitely close
 11.1153 + -------------------------------*)
 11.1154 +Goal "x:HFinite ==> EX! t. t: SReal & x @= t";
 11.1155 +by (dtac st_part_Ex 1 THEN Step_tac 1);
 11.1156 +by (dtac inf_close_sym 2 THEN dtac inf_close_sym 2 
 11.1157 +    THEN dtac inf_close_sym 2);
 11.1158 +by (auto_tac (claset() addSIs [inf_close_unique_real],simpset()));
 11.1159 +qed "st_part_Ex1";
 11.1160 +
 11.1161 +(*------------------------------------------------------------------
 11.1162 +       Finite and Infinite --- more theorems
 11.1163 + ------------------------------------------------------------------*)
 11.1164 +
 11.1165 +Goalw [HFinite_def,HInfinite_def] "HFinite Int HInfinite = {}";
 11.1166 +by (auto_tac (claset() addIs [hypreal_less_irrefl] 
 11.1167 +              addDs [hypreal_less_trans,bspec],
 11.1168 +              simpset()));
 11.1169 +qed "HFinite_Int_HInfinite_empty";
 11.1170 +Addsimps [HFinite_Int_HInfinite_empty];
 11.1171 +
 11.1172 +Goal "x: HFinite ==> x ~: HInfinite";
 11.1173 +by (EVERY1[Step_tac, dtac IntI, assume_tac]);
 11.1174 +by (Auto_tac);
 11.1175 +qed "HFinite_not_HInfinite";
 11.1176 +
 11.1177 +val [prem] = goalw thy [HInfinite_def] "x~: HFinite ==> x: HInfinite";
 11.1178 +by (cut_facts_tac [prem] 1);
 11.1179 +by (Clarify_tac 1);
 11.1180 +by (auto_tac (claset() addSDs [spec],simpset() addsimps [HFinite_def,Bex_def]));
 11.1181 +by (dtac (hypreal_leI RS hypreal_le_imp_less_or_eq) 1);
 11.1182 +by (auto_tac (claset() addSDs [(SReal_subset_HFinite RS subsetD)],
 11.1183 +    simpset() addsimps [prem,hrabs_idempotent,prem RS not_HFinite_hrabs]));
 11.1184 +qed "not_HFinite_HInfinite";
 11.1185 +
 11.1186 +Goal "x : HInfinite | x : HFinite";
 11.1187 +by (blast_tac (claset() addIs [not_HFinite_HInfinite]) 1);
 11.1188 +qed "HInfinite_HFinite_disj";
 11.1189 +
 11.1190 +Goal "(x : HInfinite) = (x ~: HFinite)";
 11.1191 +by (blast_tac (claset() addDs [HFinite_not_HInfinite,
 11.1192 +               not_HFinite_HInfinite]) 1);
 11.1193 +qed "HInfinite_HFinite_iff";
 11.1194 +
 11.1195 +Goal "(x : HFinite) = (x ~: HInfinite)";
 11.1196 +by (simp_tac (simpset() addsimps [HInfinite_HFinite_iff]) 1);
 11.1197 +qed "HFinite_HInfinite_iff";
 11.1198 +
 11.1199 +(*------------------------------------------------------------------
 11.1200 +       Finite, Infinite and Infinitesimal --- more theorems
 11.1201 + ------------------------------------------------------------------*)
 11.1202 +
 11.1203 +Goal "x ~: Infinitesimal ==> x : HInfinite | x : HFinite - Infinitesimal";
 11.1204 +by (fast_tac (claset() addIs [not_HFinite_HInfinite]) 1);
 11.1205 +qed "HInfinite_diff_HFinite_Infinitesimal_disj";
 11.1206 +
 11.1207 +Goal "[| x : HFinite; x ~: Infinitesimal |] ==> hrinv x : HFinite";
 11.1208 +by (cut_inst_tac [("x","hrinv x")] HInfinite_HFinite_disj 1);
 11.1209 +by (forward_tac [not_Infinitesimal_not_zero RS hypreal_hrinv_hrinv] 1);
 11.1210 +by (auto_tac (claset() addSDs [HInfinite_hrinv_Infinitesimal],simpset()));
 11.1211 +qed "HFinite_hrinv";
 11.1212 +
 11.1213 +Goal "x : HFinite - Infinitesimal ==> hrinv x : HFinite";
 11.1214 +by (blast_tac (claset() addIs [HFinite_hrinv]) 1);
 11.1215 +qed "HFinite_hrinv2";
 11.1216 +
 11.1217 +(* stronger statement possible in fact *)
 11.1218 +Goal "x ~: Infinitesimal ==> hrinv(x) : HFinite";
 11.1219 +by (dtac HInfinite_diff_HFinite_Infinitesimal_disj 1);
 11.1220 +by (blast_tac (claset() addIs [HFinite_hrinv,
 11.1221 +    HInfinite_hrinv_Infinitesimal,
 11.1222 +    Infinitesimal_subset_HFinite RS subsetD]) 1);
 11.1223 +qed "Infinitesimal_hrinv_HFinite";
 11.1224 +
 11.1225 +Goal "x : HFinite - Infinitesimal ==> hrinv x : HFinite - Infinitesimal";
 11.1226 +by (auto_tac (claset() addIs [Infinitesimal_hrinv_HFinite],simpset()));
 11.1227 +by (dtac Infinitesimal_HFinite_mult2 1);
 11.1228 +by (auto_tac (claset() addSDs [not_Infinitesimal_not_zero,
 11.1229 +    hypreal_mult_hrinv],simpset()));
 11.1230 +qed "HFinite_not_Infinitesimal_hrinv";
 11.1231 +
 11.1232 +Goal "[| x @= y; y :  HFinite - Infinitesimal |] \
 11.1233 +\     ==> hrinv x @= hrinv y";
 11.1234 +by (forward_tac [HFinite_diff_Infinitesimal_inf_close] 1);
 11.1235 +by (assume_tac 1);
 11.1236 +by (forward_tac [not_Infinitesimal_not_zero2] 1);
 11.1237 +by (forw_inst_tac [("x","x")] not_Infinitesimal_not_zero2 1);
 11.1238 +by (REPEAT(dtac HFinite_hrinv2 1));
 11.1239 +by (dtac inf_close_mult2 1 THEN assume_tac 1);
 11.1240 +by (Auto_tac);
 11.1241 +by (dres_inst_tac [("c","hrinv x")] inf_close_mult1 1 
 11.1242 +    THEN assume_tac 1);
 11.1243 +by (auto_tac (claset() addIs [inf_close_sym],
 11.1244 +    simpset() addsimps [hypreal_mult_assoc]));
 11.1245 +qed "inf_close_hrinv";
 11.1246 +
 11.1247 +Goal "!!x. [| x: HFinite - Infinitesimal; \
 11.1248 +\                     h : Infinitesimal |] ==> hrinv(x + h) @= hrinv x";
 11.1249 +by (auto_tac (claset() addIs [inf_close_hrinv,
 11.1250 +    Infinitesimal_add_inf_close_self,inf_close_sym],simpset()));
 11.1251 +qed "hrinv_add_Infinitesimal_inf_close";
 11.1252 +
 11.1253 +Goal "!!x. [| x: HFinite - Infinitesimal; \
 11.1254 +\                     h : Infinitesimal |] ==> hrinv(h + x) @= hrinv x";
 11.1255 +by (rtac (hypreal_add_commute RS subst) 1);
 11.1256 +by (blast_tac (claset() addIs [hrinv_add_Infinitesimal_inf_close]) 1);
 11.1257 +qed "hrinv_add_Infinitesimal_inf_close2";
 11.1258 +
 11.1259 +Goal 
 11.1260 +     "!!x. [| x: HFinite - Infinitesimal; \
 11.1261 +\             h : Infinitesimal |] ==> hrinv(x + h) + -hrinv x @= h"; 
 11.1262 +by (rtac inf_close_trans2 1);
 11.1263 +by (auto_tac (claset() addIs [hrinv_add_Infinitesimal_inf_close,
 11.1264 +    inf_close_minus_iff RS iffD1],simpset() addsimps [mem_infmal_iff RS sym]));
 11.1265 +qed "hrinv_add_Infinitesimal_inf_close_Infinitesimal";
 11.1266 +
 11.1267 +Goal "(x : Infinitesimal) = (x*x : Infinitesimal)";
 11.1268 +by (auto_tac (claset() addIs [Infinitesimal_mult],simpset()));
 11.1269 +by (rtac ccontr 1 THEN forward_tac [Infinitesimal_hrinv_HFinite] 1);
 11.1270 +by (forward_tac [not_Infinitesimal_not_zero] 1);
 11.1271 +by (auto_tac (claset() addDs [Infinitesimal_HFinite_mult],
 11.1272 +    simpset() addsimps [hypreal_mult_assoc]));
 11.1273 +qed "Infinitesimal_square_iff";
 11.1274 +Addsimps [Infinitesimal_square_iff RS sym];
 11.1275 +
 11.1276 +Goal "(x*x : HFinite) = (x : HFinite)";
 11.1277 +by (auto_tac (claset() addIs [HFinite_mult],simpset()));
 11.1278 +by (auto_tac (claset() addDs [HInfinite_mult],
 11.1279 +    simpset() addsimps [HFinite_HInfinite_iff]));
 11.1280 +qed "HFinite_square_iff";
 11.1281 +Addsimps [HFinite_square_iff];
 11.1282 +
 11.1283 +Goal "(x*x : HInfinite) = (x : HInfinite)";
 11.1284 +by (auto_tac (claset(),simpset() addsimps 
 11.1285 +    [HInfinite_HFinite_iff]));
 11.1286 +qed "HInfinite_square_iff";
 11.1287 +Addsimps [HInfinite_square_iff];
 11.1288 +
 11.1289 +Goal "!!a. [| a: HFinite-Infinitesimal; a* w @= a*z |] ==> w @= z";
 11.1290 +by (Step_tac 1);
 11.1291 +by (ftac HFinite_hrinv 1 THEN assume_tac 1);
 11.1292 +by (dtac not_Infinitesimal_not_zero 1);
 11.1293 +by (auto_tac (claset() addDs [inf_close_mult2],
 11.1294 +    simpset() addsimps [hypreal_mult_assoc RS sym]));
 11.1295 +qed "inf_close_HFinite_mult_cancel";
 11.1296 +
 11.1297 +Goal "a: HFinite-Infinitesimal ==> (a * w @= a * z) = (w @= z)";
 11.1298 +by (auto_tac (claset() addIs [inf_close_mult2,
 11.1299 +    inf_close_HFinite_mult_cancel],simpset()));
 11.1300 +qed "inf_close_HFinite_mult_cancel_iff1";
 11.1301 +
 11.1302 +(*------------------------------------------------------------------
 11.1303 +                  more about absolute value (hrabs)
 11.1304 + ------------------------------------------------------------------*)
 11.1305 +
 11.1306 +Goal "abs x @= x | abs x @= -x";
 11.1307 +by (cut_inst_tac [("x","x")] hrabs_disj 1);
 11.1308 +by (auto_tac (claset(),simpset() addsimps [inf_close_refl]));
 11.1309 +qed "inf_close_hrabs_disj";
 11.1310 +
 11.1311 +(*------------------------------------------------------------------
 11.1312 +                  Theorems about monads
 11.1313 + ------------------------------------------------------------------*)
 11.1314 +
 11.1315 +Goal "monad (abs x) <= monad(x) Un monad(-x)";
 11.1316 +by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
 11.1317 +by (Auto_tac);
 11.1318 +qed "monad_hrabs_Un_subset";
 11.1319 +
 11.1320 +Goal "!! e. e : Infinitesimal ==> monad (x+e) = monad x";
 11.1321 +by (fast_tac (claset() addSIs [Infinitesimal_add_inf_close_self RS inf_close_sym,
 11.1322 +    inf_close_monad_iff RS iffD1]) 1);
 11.1323 +qed "Infinitesimal_monad_eq";
 11.1324 +
 11.1325 +Goalw [monad_def] "(u:monad x) = (-u:monad (-x))";
 11.1326 +by (Auto_tac);
 11.1327 +qed "mem_monad_iff";
 11.1328 +
 11.1329 +Goalw [monad_def] "(x:Infinitesimal) = (x:monad 0)";
 11.1330 +by (auto_tac (claset() addIs [inf_close_sym],
 11.1331 +    simpset() addsimps [mem_infmal_iff]));
 11.1332 +qed "Infinitesimal_monad_zero_iff";
 11.1333 +
 11.1334 +Goal "(x:monad 0) = (-x:monad 0)";
 11.1335 +by (simp_tac (simpset() addsimps [Infinitesimal_monad_zero_iff RS sym,
 11.1336 +    Infinitesimal_minus_iff RS sym]) 1);
 11.1337 +qed "monad_zero_minus_iff";
 11.1338 +
 11.1339 +Goal "(x:monad 0) = (abs x:monad 0)";
 11.1340 +by (res_inst_tac [("x1","x")] (hrabs_disj RS disjE) 1);
 11.1341 +by (auto_tac (claset(),simpset() addsimps [monad_zero_minus_iff RS sym]));
 11.1342 +qed "monad_zero_hrabs_iff";
 11.1343 +
 11.1344 +Goalw [monad_def] "x:monad x";
 11.1345 +by (simp_tac (simpset() addsimps [inf_close_refl]) 1);
 11.1346 +qed "mem_monad_self";
 11.1347 +Addsimps [mem_monad_self];
 11.1348 +
 11.1349 +(*------------------------------------------------------------------
 11.1350 +         Proof that x @= y ==> abs x @= abs y
 11.1351 + ------------------------------------------------------------------*)
 11.1352 +Goal "x @= y ==> {x,y}<=monad x";
 11.1353 +by (Simp_tac 1);
 11.1354 +by (asm_full_simp_tac (simpset() addsimps 
 11.1355 +    [inf_close_monad_iff]) 1);
 11.1356 +qed "inf_close_subset_monad";
 11.1357 +
 11.1358 +Goal "x @= y ==> {x,y}<=monad y";
 11.1359 +by (dtac inf_close_sym 1);
 11.1360 +by (fast_tac (claset() addDs [inf_close_subset_monad]) 1);
 11.1361 +qed "inf_close_subset_monad2";
 11.1362 +
 11.1363 +Goalw [monad_def] "u:monad x ==> x @= u";
 11.1364 +by (Fast_tac 1);
 11.1365 +qed "mem_monad_inf_close";
 11.1366 +
 11.1367 +Goalw [monad_def] "x @= u ==> u:monad x";
 11.1368 +by (Fast_tac 1);
 11.1369 +qed "inf_close_mem_monad";
 11.1370 +
 11.1371 +Goalw [monad_def] "!!u. x @= u ==> x:monad u";
 11.1372 +by (blast_tac (claset() addSIs [inf_close_sym]) 1);
 11.1373 +qed "inf_close_mem_monad2";
 11.1374 +
 11.1375 +Goal "!! x y. [| x @= y;x:monad 0 |] ==> y:monad 0";
 11.1376 +by (dtac mem_monad_inf_close 1);
 11.1377 +by (fast_tac (claset() addIs [inf_close_mem_monad,inf_close_trans]) 1);
 11.1378 +qed "inf_close_mem_monad_zero";
 11.1379 +
 11.1380 +Goal "!! x y. [| x @= y; x: Infinitesimal |] ==> abs x @= abs y";
 11.1381 +by (fast_tac (claset() addIs [(Infinitesimal_monad_zero_iff RS iffD1), 
 11.1382 +    inf_close_mem_monad_zero,(monad_zero_hrabs_iff RS iffD1),
 11.1383 +    mem_monad_inf_close,inf_close_trans3]) 1);
 11.1384 +qed "Infinitesimal_inf_close_hrabs";
 11.1385 +
 11.1386 +Goal "!! x. [| 0 < x; x ~:Infinitesimal |] \
 11.1387 +\     ==> ALL e: Infinitesimal. e < x";
 11.1388 +by (Step_tac 1 THEN rtac ccontr 1);
 11.1389 +by (auto_tac (claset() addIs [Infinitesimal_zero RSN (2, Infinitesimal_interval)] 
 11.1390 +    addSDs [hypreal_leI RS hypreal_le_imp_less_or_eq],simpset()));
 11.1391 +qed "Ball_Infinitesimal_less";
 11.1392 +
 11.1393 +Goal "!! x. [| 0 < x; x ~: Infinitesimal|] \
 11.1394 +\     ==> ALL u: monad x. 0 < u";
 11.1395 +by (Step_tac 1);
 11.1396 +by (dtac (mem_monad_inf_close RS inf_close_sym) 1);
 11.1397 +by (etac (bex_Infinitesimal_iff2 RS iffD2 RS bexE) 1);
 11.1398 +by (eres_inst_tac [("x","-xa")] (Ball_Infinitesimal_less RS ballE) 1);
 11.1399 +by (dtac (hypreal_less_minus_iff RS iffD1) 2);
 11.1400 +by (auto_tac (claset(),simpset() addsimps [Infinitesimal_minus_iff RS sym]));
 11.1401 +qed "Ball_mem_monad_gt_zero";
 11.1402 +
 11.1403 +Goal "!! x. [| x < 0; x ~: Infinitesimal|] \
 11.1404 +\     ==> ALL u: monad x. u < 0";
 11.1405 +by (Step_tac 1);
 11.1406 +by (dtac (mem_monad_inf_close RS inf_close_sym) 1);
 11.1407 +by (etac (bex_Infinitesimal_iff RS iffD2 RS bexE) 1);
 11.1408 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
 11.1409 +by (eres_inst_tac [("x","xa")] (Ball_Infinitesimal_less RS ballE) 1);
 11.1410 +by (dtac (hypreal_less_minus_iff2 RS iffD1) 2);
 11.1411 +by (auto_tac (claset(),simpset() addsimps [Infinitesimal_minus_iff RS sym] @ hypreal_add_ac));
 11.1412 +qed "Ball_mem_monad_less_zero";
 11.1413 +
 11.1414 +Goal "[|0 < x; x ~: Infinitesimal; x @= y|] ==> 0 < y";
 11.1415 +by (blast_tac (claset() addDs [Ball_mem_monad_gt_zero,
 11.1416 +    inf_close_subset_monad]) 1);
 11.1417 +qed "lemma_inf_close_gt_zero";
 11.1418 +
 11.1419 +Goal "[|x < 0; x ~: Infinitesimal; x @= y|] ==> y < 0";
 11.1420 +by (blast_tac (claset() addDs [Ball_mem_monad_less_zero,
 11.1421 +    inf_close_subset_monad]) 1);
 11.1422 +qed "lemma_inf_close_less_zero";
 11.1423 +
 11.1424 +Goal "[| x @= y; x < 0; x ~: Infinitesimal |] \
 11.1425 +\     ==> abs x @= abs y";
 11.1426 +by (forward_tac [lemma_inf_close_less_zero] 1);
 11.1427 +by (REPEAT(assume_tac 1));
 11.1428 +by (REPEAT(dtac hrabs_minus_eqI2 1));
 11.1429 +by (Auto_tac);
 11.1430 +qed "inf_close_hrabs1";
 11.1431 +
 11.1432 +Goal "[| x @= y; 0 < x; x ~: Infinitesimal |] \
 11.1433 +\     ==> abs x @= abs y";
 11.1434 +by (forward_tac [lemma_inf_close_gt_zero] 1);
 11.1435 +by (REPEAT(assume_tac 1));
 11.1436 +by (REPEAT(dtac hrabs_eqI2 1));
 11.1437 +by (Auto_tac);
 11.1438 +qed "inf_close_hrabs2";
 11.1439 +
 11.1440 +Goal "x @= y ==> abs x @= abs y";
 11.1441 +by (res_inst_tac [("Q","x:Infinitesimal")] (excluded_middle RS disjE) 1);
 11.1442 +by (res_inst_tac [("x1","x"),("y1","0")] (hypreal_linear RS disjE) 1);
 11.1443 +by (auto_tac (claset() addIs [inf_close_hrabs1,inf_close_hrabs2,
 11.1444 +    Infinitesimal_inf_close_hrabs],simpset()));
 11.1445 +qed "inf_close_hrabs";
 11.1446 +
 11.1447 +Goal "abs(x) @= 0 ==> x @= 0";
 11.1448 +by (cut_inst_tac [("x","x")] hrabs_disj 1);
 11.1449 +by (auto_tac (claset() addDs [inf_close_minus],simpset()));
 11.1450 +qed "inf_close_hrabs_zero_cancel";
 11.1451 +
 11.1452 +Goal "e: Infinitesimal ==> abs x @= abs(x+e)";
 11.1453 +by (fast_tac (claset() addIs [inf_close_hrabs,
 11.1454 +       Infinitesimal_add_inf_close_self]) 1);
 11.1455 +qed "inf_close_hrabs_add_Infinitesimal";
 11.1456 +
 11.1457 +Goal "e: Infinitesimal ==> abs x @= abs(x + -e)";
 11.1458 +by (fast_tac (claset() addIs [inf_close_hrabs,
 11.1459 +    Infinitesimal_add_minus_inf_close_self]) 1);
 11.1460 +qed "inf_close_hrabs_add_minus_Infinitesimal";
 11.1461 +
 11.1462 +Goal "[| e: Infinitesimal; e': Infinitesimal; \
 11.1463 +\        abs(x+e) = abs(y+e')|] ==> abs x @= abs y";
 11.1464 +by (dres_inst_tac [("x","x")] inf_close_hrabs_add_Infinitesimal 1);
 11.1465 +by (dres_inst_tac [("x","y")] inf_close_hrabs_add_Infinitesimal 1);
 11.1466 +by (auto_tac (claset() addIs [inf_close_trans2],simpset()));
 11.1467 +qed "hrabs_add_Infinitesimal_cancel";
 11.1468 +
 11.1469 +Goal "[| e: Infinitesimal; e': Infinitesimal; \
 11.1470 +\        abs(x + -e) = abs(y + -e')|] ==> abs x @= abs y";
 11.1471 +by (dres_inst_tac [("x","x")] inf_close_hrabs_add_minus_Infinitesimal 1);
 11.1472 +by (dres_inst_tac [("x","y")] inf_close_hrabs_add_minus_Infinitesimal 1);
 11.1473 +by (auto_tac (claset() addIs [inf_close_trans2],simpset()));
 11.1474 +qed "hrabs_add_minus_Infinitesimal_cancel";
 11.1475 +
 11.1476 +(* interesting slightly counterintuitive theorem: necessary 
 11.1477 +   for proving that an open interval is an NS open set 
 11.1478 +*)
 11.1479 +Goalw [Infinitesimal_def] 
 11.1480 +      "[| xa: Infinitesimal; hypreal_of_real x < hypreal_of_real y |] \
 11.1481 +\      ==> hypreal_of_real x + xa < hypreal_of_real y";
 11.1482 +by (dtac (hypreal_less_minus_iff RS iffD1) 1 THEN Step_tac 1);
 11.1483 +by (rtac (hypreal_less_minus_iff RS iffD2) 1);
 11.1484 +by (dres_inst_tac [("x","hypreal_of_real y + -hypreal_of_real x")] bspec 1);
 11.1485 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_commute,
 11.1486 +    hypreal_of_real_minus RS sym, hypreal_of_real_add RS sym,
 11.1487 +    hrabs_interval_iff]));
 11.1488 +by (dres_inst_tac [("x1","xa")] (hypreal_less_minus_iff RS iffD1) 1);
 11.1489 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_minus,
 11.1490 +    hypreal_minus_add_distrib,hypreal_of_real_add] @ hypreal_add_ac));
 11.1491 +qed "Infinitesimal_add_hypreal_of_real_less";
 11.1492 +
 11.1493 +Goal "[| x: Infinitesimal; abs(hypreal_of_real r) < hypreal_of_real y |] \
 11.1494 +\     ==> abs (hypreal_of_real r + x) < hypreal_of_real y";
 11.1495 +by (dres_inst_tac [("x","hypreal_of_real r")] 
 11.1496 +    inf_close_hrabs_add_Infinitesimal 1);
 11.1497 +by (dtac (inf_close_sym RS (bex_Infinitesimal_iff2 RS iffD2)) 1);
 11.1498 +by (auto_tac (claset() addSIs [Infinitesimal_add_hypreal_of_real_less],
 11.1499 +        simpset() addsimps [hypreal_of_real_hrabs]));
 11.1500 +qed "Infinitesimal_add_hrabs_hypreal_of_real_less";
 11.1501 +
 11.1502 +Goal "[| x: Infinitesimal; abs(hypreal_of_real r) < hypreal_of_real y |] \
 11.1503 +\     ==> abs (x + hypreal_of_real r) < hypreal_of_real y";
 11.1504 +by (rtac (hypreal_add_commute RS subst) 1);
 11.1505 +by (etac Infinitesimal_add_hrabs_hypreal_of_real_less 1);
 11.1506 +by (assume_tac 1);
 11.1507 +qed "Infinitesimal_add_hrabs_hypreal_of_real_less2";
 11.1508 +
 11.1509 +Goalw [hypreal_le_def]
 11.1510 +      "[| xa: Infinitesimal; hypreal_of_real x + xa <= hypreal_of_real y |] \
 11.1511 +\      ==> hypreal_of_real x <= hypreal_of_real y";
 11.1512 +by (EVERY1[rtac notI, rtac swap, assume_tac]);
 11.1513 +by (res_inst_tac [("C","-xa")] hypreal_less_add_right_cancel 1);
 11.1514 +by (auto_tac (claset() addDs [Infinitesimal_minus_iff RS iffD1]
 11.1515 +    addIs [Infinitesimal_add_hypreal_of_real_less],
 11.1516 +    simpset() addsimps [hypreal_add_assoc]));
 11.1517 +qed "Infinitesimal_add_cancel_hypreal_of_real_le";
 11.1518 +
 11.1519 +Goal "!!xa. [| xa: Infinitesimal; hypreal_of_real x + xa <= hypreal_of_real y |] \
 11.1520 +\                   ==> x <= y";
 11.1521 +by (blast_tac (claset() addSIs [hypreal_of_real_le_iff RS iffD2,
 11.1522 +               Infinitesimal_add_cancel_hypreal_of_real_le]) 1);
 11.1523 +qed "Infinitesimal_add_cancel_real_le";
 11.1524 +
 11.1525 +Goalw [hypreal_le_def]
 11.1526 +      "!!xa. [| xa: Infinitesimal; ya: Infinitesimal; \
 11.1527 +\               hypreal_of_real x + xa <= hypreal_of_real y + ya \
 11.1528 +\            |] ==> hypreal_of_real x <= hypreal_of_real y";
 11.1529 +by (EVERY1[rtac notI, rtac swap, assume_tac]);
 11.1530 +by (res_inst_tac [("C","-xa")] hypreal_less_add_right_cancel 1);
 11.1531 +by (dtac (Infinitesimal_minus_iff RS iffD1) 1);
 11.1532 +by (dtac Infinitesimal_add 1 THEN assume_tac 1);
 11.1533 +by (auto_tac (claset() addIs [Infinitesimal_add_hypreal_of_real_less],
 11.1534 +    simpset() addsimps [hypreal_add_assoc]));
 11.1535 +qed "hypreal_of_real_le_add_Infininitesimal_cancel";
 11.1536 +
 11.1537 +Goal "!!xa. [| xa: Infinitesimal; ya: Infinitesimal; \
 11.1538 +\               hypreal_of_real x + xa <= hypreal_of_real y + ya \
 11.1539 +\            |] ==> x <= y";
 11.1540 +by (blast_tac (claset() addSIs [hypreal_of_real_le_iff RS iffD2,
 11.1541 +               hypreal_of_real_le_add_Infininitesimal_cancel]) 1);
 11.1542 +qed "hypreal_of_real_le_add_Infininitesimal_cancel2";
 11.1543 +
 11.1544 +Goal "[| hypreal_of_real x < e; e: Infinitesimal |] ==> hypreal_of_real x <= 0";
 11.1545 +by (rtac hypreal_leI 1 THEN Step_tac 1);
 11.1546 +by (dtac Infinitesimal_interval 1);
 11.1547 +by (dtac (SReal_hypreal_of_real RS SReal_Infinitesimal_zero) 4);
 11.1548 +by (auto_tac (claset(),simpset() addsimps [hypreal_less_not_refl]));
 11.1549 +qed "hypreal_of_real_less_Infinitesimal_le_zero";
 11.1550 +
 11.1551 +Goal "!!x. [| h: Infinitesimal; x ~= 0 |] \
 11.1552 +\                  ==> hypreal_of_real x + h ~= 0";
 11.1553 +by (res_inst_tac [("t","h")] (hypreal_minus_minus RS subst) 1);
 11.1554 +by (rtac (not_sym RS (hypreal_not_eq_minus_iff RS iffD1)) 1);
 11.1555 +by (dtac (Infinitesimal_minus_iff RS iffD1) 1);
 11.1556 +by (auto_tac (claset() addDs [((hypreal_of_real_not_zero_iff RS iffD2) RS
 11.1557 +          hypreal_of_real_HFinite_diff_Infinitesimal)],simpset()));
 11.1558 +qed "Infinitesimal_add_not_zero";
 11.1559 +
 11.1560 +Goal "x*x + y*y : Infinitesimal ==> x*x : Infinitesimal";
 11.1561 +by (blast_tac (claset() addIs [hypreal_self_le_add_pos,
 11.1562 +    Infinitesimal_interval2,hypreal_le_square,
 11.1563 +    Infinitesimal_zero]) 1);
 11.1564 +qed "Infinitesimal_square_cancel";
 11.1565 +Addsimps [Infinitesimal_square_cancel];
 11.1566 +
 11.1567 +Goal "x*x + y*y : HFinite ==> x*x : HFinite";
 11.1568 +by (blast_tac (claset() addIs [hypreal_self_le_add_pos,
 11.1569 +    HFinite_bounded,hypreal_le_square,
 11.1570 +    HFinite_zero]) 1);
 11.1571 +qed "HFinite_square_cancel";
 11.1572 +Addsimps [HFinite_square_cancel];
 11.1573 +
 11.1574 +Goal "x*x + y*y : Infinitesimal ==> y*y : Infinitesimal";
 11.1575 +by (rtac Infinitesimal_square_cancel 1);
 11.1576 +by (rtac (hypreal_add_commute RS subst) 1);
 11.1577 +by (Simp_tac 1);
 11.1578 +qed "Infinitesimal_square_cancel2";
 11.1579 +Addsimps [Infinitesimal_square_cancel2];
 11.1580 +
 11.1581 +Goal "x*x + y*y : HFinite ==> y*y : HFinite";
 11.1582 +by (rtac HFinite_square_cancel 1);
 11.1583 +by (rtac (hypreal_add_commute RS subst) 1);
 11.1584 +by (Simp_tac 1);
 11.1585 +qed "HFinite_square_cancel2";
 11.1586 +Addsimps [HFinite_square_cancel2];
 11.1587 +
 11.1588 +Goal "x*x + y*y + z*z : Infinitesimal ==> x*x : Infinitesimal";
 11.1589 +by (blast_tac (claset() addIs [hypreal_self_le_add_pos2,
 11.1590 +    Infinitesimal_interval2,hypreal_le_square,
 11.1591 +    Infinitesimal_zero]) 1);
 11.1592 +qed "Infinitesimal_sum_square_cancel";
 11.1593 +Addsimps [Infinitesimal_sum_square_cancel];
 11.1594 +
 11.1595 +Goal "x*x + y*y + z*z : HFinite ==> x*x : HFinite";
 11.1596 +by (blast_tac (claset() addIs [hypreal_self_le_add_pos2,
 11.1597 +    HFinite_bounded,hypreal_le_square,
 11.1598 +    HFinite_zero]) 1);
 11.1599 +qed "HFinite_sum_square_cancel";
 11.1600 +Addsimps [HFinite_sum_square_cancel];
 11.1601 +
 11.1602 +Goal "y*y + x*x + z*z : Infinitesimal ==> x*x : Infinitesimal";
 11.1603 +by (rtac Infinitesimal_sum_square_cancel 1);
 11.1604 +by (asm_full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
 11.1605 +qed "Infinitesimal_sum_square_cancel2";
 11.1606 +Addsimps [Infinitesimal_sum_square_cancel2];
 11.1607 +
 11.1608 +Goal "y*y + x*x + z*z : HFinite ==> x*x : HFinite";
 11.1609 +by (rtac HFinite_sum_square_cancel 1);
 11.1610 +by (asm_full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
 11.1611 +qed "HFinite_sum_square_cancel2";
 11.1612 +Addsimps [HFinite_sum_square_cancel2];
 11.1613 +
 11.1614 +Goal "z*z + y*y + x*x : Infinitesimal ==> x*x : Infinitesimal";
 11.1615 +by (rtac Infinitesimal_sum_square_cancel 1);
 11.1616 +by (asm_full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
 11.1617 +qed "Infinitesimal_sum_square_cancel3";
 11.1618 +Addsimps [Infinitesimal_sum_square_cancel3];
 11.1619 +
 11.1620 +Goal "z*z + y*y + x*x : HFinite ==> x*x : HFinite";
 11.1621 +by (rtac HFinite_sum_square_cancel 1);
 11.1622 +by (asm_full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
 11.1623 +qed "HFinite_sum_square_cancel3";
 11.1624 +Addsimps [HFinite_sum_square_cancel3];
 11.1625 +
 11.1626 +Goal "[| y: monad x; 0 < hypreal_of_real e |] \
 11.1627 +\     ==> abs (y + -x) < hypreal_of_real e";
 11.1628 +by (dtac (mem_monad_inf_close RS inf_close_sym) 1);
 11.1629 +by (dtac (bex_Infinitesimal_iff RS iffD2) 1);
 11.1630 +by (auto_tac (claset() addSDs [InfinitesimalD],simpset()));
 11.1631 +qed "monad_hrabs_less";
 11.1632 +
 11.1633 +Goal "x: monad (hypreal_of_real  a) ==> x: HFinite";
 11.1634 +by (dtac (mem_monad_inf_close RS inf_close_sym) 1);
 11.1635 +by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1);
 11.1636 +by (step_tac (claset() addSDs 
 11.1637 +       [Infinitesimal_subset_HFinite RS subsetD]) 1);
 11.1638 +by (etac (SReal_hypreal_of_real RS (SReal_subset_HFinite 
 11.1639 +         RS subsetD) RS HFinite_add) 1);
 11.1640 +qed "mem_monad_SReal_HFinite";
 11.1641 +
 11.1642 +(*------------------------------------------------------------------
 11.1643 +              Theorems about standard part
 11.1644 + ------------------------------------------------------------------*)
 11.1645 +
 11.1646 +Goalw [st_def] "x: HFinite ==> st x @= x";
 11.1647 +by (forward_tac [st_part_Ex] 1 THEN Step_tac 1);
 11.1648 +by (rtac someI2 1);
 11.1649 +by (auto_tac (claset() addIs [inf_close_sym],simpset()));
 11.1650 +qed "st_inf_close_self";
 11.1651 +
 11.1652 +Goalw [st_def] "x: HFinite ==> st x: SReal";
 11.1653 +by (forward_tac [st_part_Ex] 1 THEN Step_tac 1);
 11.1654 +by (rtac someI2 1);
 11.1655 +by (auto_tac (claset() addIs [inf_close_sym],simpset()));
 11.1656 +qed "st_SReal";
 11.1657 +
 11.1658 +Goal "x: HFinite ==> st x: HFinite";
 11.1659 +by (etac (st_SReal RS (SReal_subset_HFinite RS subsetD)) 1);
 11.1660 +qed "st_HFinite";
 11.1661 +
 11.1662 +Goalw [st_def] "x: SReal ==> st x = x";
 11.1663 +by (rtac some_equality 1);
 11.1664 +by (fast_tac (claset() addIs [(SReal_subset_HFinite RS subsetD), 
 11.1665 +    inf_close_refl]) 1);
 11.1666 +by (blast_tac (claset() addDs [SReal_inf_close_iff RS iffD1]) 1);
 11.1667 +qed "st_SReal_eq";
 11.1668 +
 11.1669 +(* should be added to simpset *)
 11.1670 +Goal "st (hypreal_of_real x) = hypreal_of_real x";
 11.1671 +by (rtac (SReal_hypreal_of_real RS st_SReal_eq) 1);
 11.1672 +qed "st_hypreal_of_real";
 11.1673 +
 11.1674 +Goal "[| x: HFinite; y: HFinite; st x = st y |] ==> x @= y";
 11.1675 +by (auto_tac (claset() addSDs [st_inf_close_self] 
 11.1676 +              addSEs [inf_close_trans3],simpset()));
 11.1677 +qed "st_eq_inf_close";
 11.1678 +
 11.1679 +Goal "!! x. [| x: HFinite; y: HFinite; x @= y |] ==> st x = st y";
 11.1680 +by (EVERY1 [forward_tac [st_inf_close_self],
 11.1681 +    forw_inst_tac [("x","y")] st_inf_close_self,
 11.1682 +    dtac st_SReal,dtac st_SReal]);
 11.1683 +by (fast_tac (claset() addEs [inf_close_trans,
 11.1684 +    inf_close_trans2,SReal_inf_close_iff RS iffD1]) 1);
 11.1685 +qed "inf_close_st_eq";
 11.1686 +
 11.1687 +Goal "!! x y.  [| x: HFinite; y: HFinite|] \
 11.1688 +\                  ==> (x @= y) = (st x = st y)";
 11.1689 +by (blast_tac (claset() addIs [inf_close_st_eq,
 11.1690 +               st_eq_inf_close]) 1);
 11.1691 +qed "st_eq_inf_close_iff";
 11.1692 +
 11.1693 +Goal "!!x. [| x: SReal; e: Infinitesimal |] ==> st(x + e) = x";
 11.1694 +by (forward_tac [st_SReal_eq RS subst] 1);
 11.1695 +by (assume_tac 2);
 11.1696 +by (forward_tac [SReal_subset_HFinite RS subsetD] 1);
 11.1697 +by (forward_tac [Infinitesimal_subset_HFinite RS subsetD] 1);
 11.1698 +by (dtac st_SReal_eq 1);
 11.1699 +by (rtac inf_close_st_eq 1);
 11.1700 +by (auto_tac (claset() addIs  [HFinite_add],
 11.1701 +    simpset() addsimps [Infinitesimal_add_inf_close_self 
 11.1702 +    RS inf_close_sym]));
 11.1703 +qed "st_Infinitesimal_add_SReal";
 11.1704 +
 11.1705 +Goal "[| x: SReal; e: Infinitesimal |] \
 11.1706 +\     ==> st(e + x) = x";
 11.1707 +by (rtac (hypreal_add_commute RS subst) 1);
 11.1708 +by (blast_tac (claset() addSIs [st_Infinitesimal_add_SReal]) 1);
 11.1709 +qed "st_Infinitesimal_add_SReal2";
 11.1710 +
 11.1711 +Goal "x: HFinite ==> \
 11.1712 +\     EX e: Infinitesimal. x = st(x) + e";
 11.1713 +by (blast_tac (claset() addSDs [(st_inf_close_self RS 
 11.1714 +    inf_close_sym),bex_Infinitesimal_iff2 RS iffD2]) 1);
 11.1715 +qed "HFinite_st_Infinitesimal_add";
 11.1716 +
 11.1717 +Goal "[| x: HFinite; y: HFinite |] \
 11.1718 +\     ==> st (x + y) = st(x) + st(y)";
 11.1719 +by (forward_tac [HFinite_st_Infinitesimal_add] 1);
 11.1720 +by (forw_inst_tac [("x","y")] HFinite_st_Infinitesimal_add 1);
 11.1721 +by (Step_tac 1);
 11.1722 +by (subgoal_tac "st (x + y) = st ((st x + e) + (st y + ea))" 1);
 11.1723 +by (dtac sym 2 THEN dtac sym 2);
 11.1724 +by (Asm_full_simp_tac 2);
 11.1725 +by (asm_simp_tac (simpset() addsimps hypreal_add_ac) 1);
 11.1726 +by (REPEAT(dtac st_SReal 1));
 11.1727 +by (dtac SReal_add 1 THEN assume_tac 1);
 11.1728 +by (dtac Infinitesimal_add 1 THEN assume_tac 1);
 11.1729 +by (rtac (hypreal_add_assoc RS subst) 1);
 11.1730 +by (blast_tac (claset() addSIs [st_Infinitesimal_add_SReal2]) 1);
 11.1731 +qed "st_add";
 11.1732 +
 11.1733 +Goal "st 0 = 0";
 11.1734 +by (rtac (SReal_zero RS st_SReal_eq) 1);
 11.1735 +qed "st_zero";
 11.1736 +
 11.1737 +Goal "st 1hr = 1hr";
 11.1738 +by (rtac (SReal_one RS st_SReal_eq) 1);
 11.1739 +qed "st_one";
 11.1740 +
 11.1741 +Addsimps [st_zero,st_one];
 11.1742 +
 11.1743 +Goal "!!y. y: HFinite ==> st(-y) = -st(y)";
 11.1744 +by (forward_tac [HFinite_minus_iff RS iffD1] 1);
 11.1745 +by (rtac hypreal_add_minus_eq_minus 1);
 11.1746 +by (dtac (st_add RS sym) 1 THEN assume_tac 1);
 11.1747 +by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
 11.1748 +qed "st_minus";
 11.1749 +
 11.1750 +Goal "!!x. [| x: HFinite; y: HFinite |] \
 11.1751 +\              ==> st (x + -y) = st(x) + -st(y)";
 11.1752 +by (forw_inst_tac [("y1","y")] (st_minus RS sym) 1);
 11.1753 +by (dres_inst_tac [("x1","y")] (HFinite_minus_iff RS iffD1) 1);
 11.1754 +by (asm_simp_tac (simpset() addsimps [st_add]) 1);
 11.1755 +qed "st_add_minus";
 11.1756 +
 11.1757 +(* lemma *)
 11.1758 +Goal "!!x. [| x: HFinite; y: HFinite; \
 11.1759 +\                 e: Infinitesimal; \
 11.1760 +\                 ea : Infinitesimal \
 11.1761 +\              |] ==> e*y + x*ea + e*ea: Infinitesimal";
 11.1762 +by (forw_inst_tac [("x","e"),("y","y")] Infinitesimal_HFinite_mult 1);
 11.1763 +by (forw_inst_tac [("x","ea"),("y","x")] Infinitesimal_HFinite_mult 2);
 11.1764 +by (dtac Infinitesimal_mult 3);
 11.1765 +by (auto_tac (claset() addIs [Infinitesimal_add],
 11.1766 +    simpset() addsimps hypreal_add_ac @ hypreal_mult_ac));
 11.1767 +qed "lemma_st_mult";
 11.1768 +
 11.1769 +Goal "!!x. [| x: HFinite; y: HFinite |] \
 11.1770 +\              ==> st (x * y) = st(x) * st(y)";
 11.1771 +by (forward_tac [HFinite_st_Infinitesimal_add] 1);
 11.1772 +by (forw_inst_tac [("x","y")] HFinite_st_Infinitesimal_add 1);
 11.1773 +by (Step_tac 1);
 11.1774 +by (subgoal_tac "st (x * y) = st ((st x + e) * (st y + ea))" 1);
 11.1775 +by (dtac sym 2 THEN dtac sym 2);
 11.1776 +by (Asm_full_simp_tac 2);
 11.1777 +by (thin_tac "x = st x + e" 1);
 11.1778 +by (thin_tac "y = st y + ea" 1);
 11.1779 +by (asm_full_simp_tac (simpset() addsimps 
 11.1780 +    [hypreal_add_mult_distrib,hypreal_add_mult_distrib2]) 1);
 11.1781 +by (REPEAT(dtac st_SReal 1));
 11.1782 +by (full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
 11.1783 +by (rtac st_Infinitesimal_add_SReal 1);
 11.1784 +by (blast_tac (claset() addSIs [SReal_mult]) 1);
 11.1785 +by (REPEAT(dtac (SReal_subset_HFinite RS subsetD) 1));
 11.1786 +by (rtac (hypreal_add_assoc RS subst) 1);
 11.1787 +by (blast_tac (claset() addSIs [lemma_st_mult]) 1);
 11.1788 +qed "st_mult";
 11.1789 +
 11.1790 +Goal "!! x. st(x) ~= 0 ==> x ~=0";
 11.1791 +by (fast_tac (claset() addIs [st_zero]) 1);
 11.1792 +qed "st_not_zero";
 11.1793 +
 11.1794 +Goal "!!x. x: Infinitesimal ==> st x = 0";
 11.1795 +by (rtac (st_zero RS subst) 1);
 11.1796 +by (rtac inf_close_st_eq 1);
 11.1797 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite 
 11.1798 +    RS subsetD],simpset() addsimps [mem_infmal_iff RS sym]));
 11.1799 +qed "st_Infinitesimal";
 11.1800 +
 11.1801 +Goal "!! x. st(x) ~= 0 ==> x ~: Infinitesimal";
 11.1802 +by (fast_tac (claset() addIs [st_Infinitesimal]) 1);
 11.1803 +qed "st_not_Infinitesimal";
 11.1804 +
 11.1805 +val [prem1,prem2] = 
 11.1806 +goal thy "[| x: HFinite; st x ~= 0 |] \
 11.1807 +\         ==> st(hrinv x) = hrinv (st x)";
 11.1808 +by (rtac ((prem2 RS hypreal_mult_left_cancel) RS iffD1) 1);
 11.1809 +by (auto_tac (claset(),simpset() addsimps [st_not_zero,
 11.1810 +    st_mult RS sym,prem2,st_not_Infinitesimal,HFinite_hrinv,prem1]));
 11.1811 +qed "st_hrinv";
 11.1812 +
 11.1813 +val [prem1,prem2,prem3] = 
 11.1814 +goal thy "[| x: HFinite; y: HFinite; st y ~= 0 |] \
 11.1815 +\                 ==> st(x * hrinv y) = (st x) * hrinv (st y)";
 11.1816 +by (auto_tac (claset(),simpset() addsimps [st_not_zero,prem3,
 11.1817 +    st_mult,prem2,st_not_Infinitesimal,HFinite_hrinv,prem1,st_hrinv]));
 11.1818 +qed "st_mult_hrinv";
 11.1819 +
 11.1820 +Goal "!!x. x: HFinite ==> st(st(x)) = st(x)";
 11.1821 +by (blast_tac (claset() addIs [st_HFinite,
 11.1822 +    st_inf_close_self,inf_close_st_eq]) 1);
 11.1823 +qed "st_idempotent";
 11.1824 +
 11.1825 +(*** lemmas ***)
 11.1826 +Goal "[| x: HFinite; y: HFinite; \
 11.1827 +\        xa: Infinitesimal; st x < st y \
 11.1828 +\     |] ==> st x + xa < st y";
 11.1829 +by (REPEAT(dtac st_SReal 1));
 11.1830 +by (auto_tac (claset() addSIs 
 11.1831 +    [Infinitesimal_add_hypreal_of_real_less],
 11.1832 +    simpset() addsimps [SReal_iff]));
 11.1833 +qed "Infinitesimal_add_st_less";
 11.1834 +
 11.1835 +Goalw [hypreal_le_def]
 11.1836 +     "[| x: HFinite; y: HFinite; \
 11.1837 +\        xa: Infinitesimal; st x <= st y + xa\
 11.1838 +\     |] ==> st x <= st y";
 11.1839 +by (auto_tac (claset() addDs [Infinitesimal_add_st_less],
 11.1840 +    simpset()));
 11.1841 +qed "Infinitesimal_add_st_le_cancel";
 11.1842 +
 11.1843 +Goal "[| x: HFinite; y: HFinite; x <= y |] \
 11.1844 +\     ==> st(x) <= st(y)";
 11.1845 +by (forward_tac [HFinite_st_Infinitesimal_add] 1);
 11.1846 +by (rotate_tac 1 1);
 11.1847 +by (forward_tac [HFinite_st_Infinitesimal_add] 1);
 11.1848 +by (Step_tac 1);
 11.1849 +by (rtac Infinitesimal_add_st_le_cancel 1);
 11.1850 +by (res_inst_tac [("x","ea"),("y","e")] 
 11.1851 +             Infinitesimal_add_minus 3);
 11.1852 +by (auto_tac (claset(),simpset() addsimps 
 11.1853 +    [hypreal_add_assoc RS sym]));
 11.1854 +by (res_inst_tac [("C","e")] hypreal_le_add_right_cancel 1);
 11.1855 +by (asm_full_simp_tac (simpset() addsimps 
 11.1856 +    [hypreal_add_assoc]) 1);
 11.1857 +qed "st_le";
 11.1858 +
 11.1859 +Goal "[| x: HFinite; 0 <= x |] ==> 0 <= st x";
 11.1860 +by (rtac (st_zero RS subst) 1);
 11.1861 +by (auto_tac (claset() addIs [st_le],simpset() 
 11.1862 +    delsimps [st_zero]));
 11.1863 +qed "st_zero_le";
 11.1864 +
 11.1865 +Goal "[| x: HFinite; x <= 0 |] ==> st x <= 0";
 11.1866 +by (rtac (st_zero RS subst) 1);
 11.1867 +by (auto_tac (claset() addIs [st_le],simpset() 
 11.1868 +    delsimps [st_zero]));
 11.1869 +qed "st_zero_ge";
 11.1870 +
 11.1871 +Goal "x: HFinite ==> abs(st x) = st(abs x)";
 11.1872 +by (case_tac "0 <= x" 1);
 11.1873 +by (auto_tac (claset() addSDs [not_hypreal_leE,
 11.1874 +    hypreal_less_imp_le],simpset() addsimps 
 11.1875 +    [st_zero_le,hrabs_eqI1, hrabs_minus_eqI1,
 11.1876 +     st_zero_ge,st_minus]));
 11.1877 +qed "st_hrabs";
 11.1878 +
 11.1879 +(*--------------------------------------------------------------------
 11.1880 +   Alternative definitions for HFinite using Free ultrafilter
 11.1881 + --------------------------------------------------------------------*)
 11.1882 +
 11.1883 +Goal "!!x. [| X: Rep_hypreal x; Y: Rep_hypreal x |] \
 11.1884 +\              ==> {n. X n = Y n} : FreeUltrafilterNat";
 11.1885 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
 11.1886 +by (Auto_tac);
 11.1887 +by (Ultra_tac 1);
 11.1888 +qed "FreeUltrafilterNat_Rep_hypreal";
 11.1889 +
 11.1890 +Goal "{n. Yb n < Y n} Int {n. -y = Yb n} <= {n. -y < Y n}";
 11.1891 +by (Auto_tac);
 11.1892 +qed "lemma_free1";
 11.1893 +
 11.1894 +Goal "{n. Xa n < Yc n} Int {n. y = Yc n} <= {n. Xa n < y}";
 11.1895 +by (Auto_tac);
 11.1896 +qed "lemma_free2";
 11.1897 +
 11.1898 +Goalw [HFinite_def] 
 11.1899 +    "x : HFinite ==> EX X: Rep_hypreal x. \
 11.1900 +\    EX u. {n. abs (X n) < u}:  FreeUltrafilterNat";
 11.1901 +by (auto_tac (claset(),simpset() addsimps 
 11.1902 +    [hrabs_interval_iff]));
 11.1903 +by (auto_tac (claset(),simpset() addsimps 
 11.1904 +    [hypreal_less_def,SReal_iff,hypreal_minus,
 11.1905 +     hypreal_of_real_def]));
 11.1906 +by (dtac FreeUltrafilterNat_Rep_hypreal 1 THEN assume_tac 1);
 11.1907 +by (res_inst_tac [("x","Y")] bexI 1 THEN assume_tac 2);
 11.1908 +by (res_inst_tac [("x","y")] exI 1);
 11.1909 +by (Ultra_tac 1 THEN arith_tac 1);
 11.1910 +qed "HFinite_FreeUltrafilterNat";
 11.1911 +
 11.1912 +Goalw [HFinite_def] 
 11.1913 +     "EX X: Rep_hypreal x. \
 11.1914 +\      EX u. {n. abs (X n) < u}: FreeUltrafilterNat\
 11.1915 +\      ==>  x : HFinite";
 11.1916 +by (auto_tac (claset(),simpset() addsimps 
 11.1917 +    [hrabs_interval_iff]));
 11.1918 +by (res_inst_tac [("x","hypreal_of_real u")] bexI 1);
 11.1919 +by (auto_tac (claset() addSIs [exI],simpset() addsimps 
 11.1920 +    [hypreal_less_def,SReal_iff,hypreal_minus,
 11.1921 +     hypreal_of_real_def]));
 11.1922 +by (ALLGOALS(Ultra_tac THEN' arith_tac));
 11.1923 +qed "FreeUltrafilterNat_HFinite";
 11.1924 +
 11.1925 +Goal "(x : HFinite) = (EX X: Rep_hypreal x. \
 11.1926 +\          EX u. {n. abs (X n) < u}:  FreeUltrafilterNat)";
 11.1927 +by (blast_tac (claset() addSIs [HFinite_FreeUltrafilterNat,
 11.1928 +               FreeUltrafilterNat_HFinite]) 1);
 11.1929 +qed "HFinite_FreeUltrafilterNat_iff";
 11.1930 +
 11.1931 +(*--------------------------------------------------------------------
 11.1932 +   Alternative definitions for HInfinite using Free ultrafilter
 11.1933 + --------------------------------------------------------------------*)
 11.1934 +Goal "- {n. (u::real) < abs (xa n)} = {n. abs (xa n) <= u}";
 11.1935 +by Auto_tac;
 11.1936 +qed "lemma_Compl_eq";
 11.1937 +
 11.1938 +Goal "- {n. abs (xa n) < (u::real)} = {n. u <= abs (xa n)}";
 11.1939 +by Auto_tac;
 11.1940 +qed "lemma_Compl_eq2";
 11.1941 +
 11.1942 +Goal "{n. abs (xa n) <= (u::real)} Int {n. u <= abs (xa n)} \
 11.1943 +\         = {n. abs(xa n) = u}";
 11.1944 +by Auto_tac;
 11.1945 +qed "lemma_Int_eq1";
 11.1946 +
 11.1947 +Goal "{n. abs (xa n) = u} <= {n. abs (xa n) < u + (#1::real)}";
 11.1948 +by Auto_tac;
 11.1949 +qed "lemma_FreeUltrafilterNat_one";
 11.1950 +
 11.1951 +(*-------------------------------------
 11.1952 +  Exclude this type of sets from free 
 11.1953 +  ultrafilter for Infinite numbers!
 11.1954 + -------------------------------------*)
 11.1955 +Goal "!!x. [| xa: Rep_hypreal x; \
 11.1956 +\                 {n. abs (xa n) = u} : FreeUltrafilterNat \
 11.1957 +\              |] ==> x: HFinite";
 11.1958 +by (rtac FreeUltrafilterNat_HFinite 1);
 11.1959 +by (res_inst_tac [("x","xa")] bexI 1);
 11.1960 +by (res_inst_tac [("x","u + #1")] exI 1);
 11.1961 +by (Ultra_tac 1 THEN assume_tac 1);
 11.1962 +qed "FreeUltrafilterNat_const_Finite";
 11.1963 +
 11.1964 +val [prem] = goal thy "x : HInfinite ==> EX X: Rep_hypreal x. \
 11.1965 +\          ALL u. {n. u < abs (X n)}:  FreeUltrafilterNat";
 11.1966 +by (cut_facts_tac [(prem RS (HInfinite_HFinite_iff RS iffD1))] 1);
 11.1967 +by (cut_inst_tac [("x","x")] Rep_hypreal_nonempty 1);
 11.1968 +by (auto_tac (claset(),simpset() delsimps [Rep_hypreal_nonempty] 
 11.1969 +    addsimps [HFinite_FreeUltrafilterNat_iff,Bex_def]));
 11.1970 +by (REPEAT(dtac spec 1));
 11.1971 +by (Auto_tac);
 11.1972 +by (dres_inst_tac [("x","u")] spec 1 THEN 
 11.1973 +    REPEAT(dtac FreeUltrafilterNat_Compl_mem 1));
 11.1974 +by (dtac FreeUltrafilterNat_Int 1 THEN assume_tac 1);
 11.1975 +
 11.1976 +
 11.1977 +by (asm_full_simp_tac (simpset() addsimps [lemma_Compl_eq,
 11.1978 +    lemma_Compl_eq2,lemma_Int_eq1]) 1);
 11.1979 +by (auto_tac (claset() addDs [FreeUltrafilterNat_const_Finite],
 11.1980 +    simpset() addsimps [(prem RS (HInfinite_HFinite_iff RS iffD1))]));
 11.1981 +qed "HInfinite_FreeUltrafilterNat";
 11.1982 +
 11.1983 +(* yet more lemmas! *)
 11.1984 +Goal "{n. abs (Xa n) < u} Int {n. X n = Xa n} \
 11.1985 +\         <= {n. abs (X n) < (u::real)}";
 11.1986 +by (Auto_tac);
 11.1987 +qed "lemma_Int_HI";
 11.1988 +
 11.1989 +Goal "{n. u < abs (X n)} Int {n. abs (X n) < (u::real)} = {}";
 11.1990 +by (auto_tac (claset() addIs [real_less_asym],simpset()));
 11.1991 +qed "lemma_Int_HIa";
 11.1992 +
 11.1993 +Goal "!!x. EX X: Rep_hypreal x. ALL u. \
 11.1994 +\              {n. u < abs (X n)}: FreeUltrafilterNat\
 11.1995 +\              ==>  x : HInfinite";
 11.1996 +by (rtac (HInfinite_HFinite_iff RS iffD2) 1);
 11.1997 +by (Step_tac 1 THEN dtac HFinite_FreeUltrafilterNat 1);
 11.1998 +by (Auto_tac);
 11.1999 +by (dres_inst_tac [("x","u")] spec 1);
 11.2000 +by (dtac FreeUltrafilterNat_Rep_hypreal 1 THEN assume_tac 1);
 11.2001 +by (dres_inst_tac [("Y","{n. X n = Xa n}")] FreeUltrafilterNat_Int 1);
 11.2002 +by (dtac (lemma_Int_HI RSN (2,FreeUltrafilterNat_subset)) 2);
 11.2003 +by (dres_inst_tac [("Y","{n. abs (X n) < u}")] FreeUltrafilterNat_Int 2);
 11.2004 +by (auto_tac (claset(),simpset() addsimps [lemma_Int_HIa,
 11.2005 +              FreeUltrafilterNat_empty]));
 11.2006 +qed "FreeUltrafilterNat_HInfinite";
 11.2007 +
 11.2008 +Goal "(x : HInfinite) = (EX X: Rep_hypreal x. \
 11.2009 +\          ALL u. {n. u < abs (X n)}:  FreeUltrafilterNat)";
 11.2010 +by (blast_tac (claset() addSIs [HInfinite_FreeUltrafilterNat,
 11.2011 +               FreeUltrafilterNat_HInfinite]) 1);
 11.2012 +qed "HInfinite_FreeUltrafilterNat_iff";
 11.2013 +
 11.2014 +(*--------------------------------------------------------------------
 11.2015 +   Alternative definitions for Infinitesimal using Free ultrafilter
 11.2016 + --------------------------------------------------------------------*)
 11.2017 +
 11.2018 +Goal "{n. - u < Yd n} Int {n. xa n = Yd n} <= {n. -u < xa n}";
 11.2019 +by (Auto_tac);
 11.2020 +qed "lemma_free4";
 11.2021 +
 11.2022 +Goal "{n. Yb n < u} Int {n. xa n = Yb n} <= {n. xa n < u}";
 11.2023 +by (Auto_tac);
 11.2024 +qed "lemma_free5";
 11.2025 +
 11.2026 +Goalw [Infinitesimal_def] 
 11.2027 +          "!!x. x : Infinitesimal ==> EX X: Rep_hypreal x. \
 11.2028 +\          ALL u. 0 < u --> {n. abs (X n) < u}:  FreeUltrafilterNat";
 11.2029 +by (auto_tac (claset(),simpset() addsimps [hrabs_interval_iff]));
 11.2030 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
 11.2031 +by (EVERY[Auto_tac, rtac bexI 1, rtac lemma_hyprel_refl 2, Step_tac 1]);
 11.2032 +by (dtac (hypreal_of_real_less_iff RS iffD1) 1);
 11.2033 +by (dres_inst_tac [("x","hypreal_of_real u")] bspec 1);
 11.2034 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_zero]));
 11.2035 +by (thin_tac "0 < hypreal_of_real  u" 1);
 11.2036 +by (auto_tac (claset(),simpset() addsimps [hypreal_less_def,       
 11.2037 +     hypreal_minus,hypreal_of_real_def,hypreal_of_real_zero]));
 11.2038 +by (Ultra_tac 1 THEN arith_tac 1);
 11.2039 +qed "Infinitesimal_FreeUltrafilterNat";
 11.2040 +
 11.2041 +Goalw [Infinitesimal_def] 
 11.2042 +          "!!x. EX X: Rep_hypreal x. \
 11.2043 +\               ALL u. 0 < u --> \
 11.2044 +\               {n. abs (X n) < u}:  FreeUltrafilterNat \
 11.2045 +\               ==> x : Infinitesimal";
 11.2046 +by (auto_tac (claset(),simpset() addsimps 
 11.2047 +    [hrabs_interval_iff,abs_interval_iff]));
 11.2048 +by (auto_tac (claset(),simpset() addsimps [SReal_iff,
 11.2049 +    hypreal_of_real_zero RS sym]));
 11.2050 +by (auto_tac (claset() addSIs [exI] 
 11.2051 +    addIs [FreeUltrafilterNat_subset],
 11.2052 +    simpset() addsimps [hypreal_less_def,
 11.2053 +    hypreal_minus,hypreal_of_real_def]));
 11.2054 +qed "FreeUltrafilterNat_Infinitesimal";
 11.2055 +
 11.2056 +Goal "(x : Infinitesimal) = (EX X: Rep_hypreal x. \
 11.2057 +\          ALL u. 0 < u --> {n. abs (X n) < u}:  FreeUltrafilterNat)";
 11.2058 +by (blast_tac (claset() addSIs [Infinitesimal_FreeUltrafilterNat,
 11.2059 +               FreeUltrafilterNat_Infinitesimal]) 1);
 11.2060 +qed "Infinitesimal_FreeUltrafilterNat_iff";
 11.2061 +
 11.2062 +(*------------------------------------------------------------------------
 11.2063 +         Infinitesimals as smaller than 1/n for all n::nat (> 0)
 11.2064 + ------------------------------------------------------------------------*)
 11.2065 +Goal "(ALL r. 0 < r --> x < r) = (ALL n. x < rinv(real_of_posnat n))";
 11.2066 +by (auto_tac (claset(),simpset() addsimps 
 11.2067 +    [rename_numerals (real_of_posnat_gt_zero RS real_rinv_gt_zero)]));
 11.2068 +by (blast_tac (claset() addSDs [rename_numerals reals_Archimedean] 
 11.2069 +    addIs [real_less_trans]) 1);
 11.2070 +qed "lemma_Infinitesimal";
 11.2071 +
 11.2072 +Goal "(ALL r: SReal. 0 < r --> x < r) = \
 11.2073 +\     (ALL n. x < hrinv(hypreal_of_posnat n))";
 11.2074 +by (Step_tac 1);
 11.2075 +by (dres_inst_tac [("x","hypreal_of_real (rinv(real_of_posnat n))")] bspec 1);
 11.2076 +by (Full_simp_tac 1);
 11.2077 +by (rtac (real_of_posnat_gt_zero RS real_rinv_gt_zero RS 
 11.2078 +          (hypreal_of_real_less_iff RS iffD1) RSN(2,impE)) 1);
 11.2079 +by (assume_tac 2);
 11.2080 +by (asm_full_simp_tac (simpset() addsimps 
 11.2081 +   [real_not_refl2 RS not_sym RS hypreal_of_real_hrinv RS sym,
 11.2082 +   rename_numerals real_of_posnat_gt_zero,hypreal_of_real_zero,
 11.2083 +    hypreal_of_real_of_posnat]) 1);
 11.2084 +by (auto_tac (claset() addSDs [reals_Archimedean],
 11.2085 +    simpset() addsimps [SReal_iff,hypreal_of_real_zero RS sym]));
 11.2086 +by (dtac (hypreal_of_real_less_iff RS iffD1) 1);
 11.2087 +by (asm_full_simp_tac (simpset() addsimps 
 11.2088 +   [real_not_refl2 RS not_sym RS hypreal_of_real_hrinv RS sym,
 11.2089 +   rename_numerals real_of_posnat_gt_zero,hypreal_of_real_of_posnat])1);
 11.2090 +by (blast_tac (claset() addIs [hypreal_less_trans]) 1);
 11.2091 +qed "lemma_Infinitesimal2";
 11.2092 +
 11.2093 +Goalw [Infinitesimal_def] 
 11.2094 +      "Infinitesimal = {x. ALL n. abs x < hrinv (hypreal_of_posnat n)}";
 11.2095 +by (auto_tac (claset(),simpset() addsimps [lemma_Infinitesimal2]));
 11.2096 +qed "Infinitesimal_hypreal_of_posnat_iff";
 11.2097 +
 11.2098 +(*-----------------------------------------------------------------------------
 11.2099 +       Actual proof that omega (whr) is an infinite number and 
 11.2100 +       hence that epsilon (ehr) is an infinitesimal number.
 11.2101 + -----------------------------------------------------------------------------*)
 11.2102 +Goal "{n. n < Suc m} = {n. n < m} Un {n. n = m}";
 11.2103 +by (auto_tac (claset(),simpset() addsimps [less_Suc_eq]));
 11.2104 +qed "Suc_Un_eq";
 11.2105 +
 11.2106 +(*-------------------------------------------
 11.2107 +  Prove that any segment is finite and 
 11.2108 +  hence cannot belong to FreeUltrafilterNat
 11.2109 + -------------------------------------------*)
 11.2110 +Goal "finite {n::nat. n < m}";
 11.2111 +by (nat_ind_tac "m" 1);
 11.2112 +by (auto_tac (claset(),simpset() addsimps [Suc_Un_eq]));
 11.2113 +qed "finite_nat_segment";
 11.2114 +
 11.2115 +Goal "finite {n::nat. real_of_posnat n < real_of_posnat m}";
 11.2116 +by (auto_tac (claset() addIs [finite_nat_segment],simpset()));
 11.2117 +qed "finite_real_of_posnat_segment";
 11.2118 +
 11.2119 +Goal "finite {n. real_of_posnat n < u}";
 11.2120 +by (cut_inst_tac [("x","u")] reals_Archimedean2 1);
 11.2121 +by (Step_tac 1);
 11.2122 +by (rtac (finite_real_of_posnat_segment RSN (2,finite_subset)) 1);
 11.2123 +by (auto_tac (claset() addDs [real_less_trans],simpset()));
 11.2124 +qed "finite_real_of_posnat_less_real";
 11.2125 +
 11.2126 +Goal "{n. real_of_posnat n <= u} = \
 11.2127 +\     {n. real_of_posnat n < u} Un {n. u = real_of_posnat n}";
 11.2128 +by (auto_tac (claset() addDs [real_le_imp_less_or_eq],
 11.2129 +    simpset() addsimps [real_le_refl,real_less_imp_le]));
 11.2130 +qed "lemma_real_le_Un_eq";
 11.2131 +
 11.2132 +Goal "finite {n. real_of_posnat n <= u}";
 11.2133 +by (auto_tac (claset(),simpset() addsimps 
 11.2134 +    [lemma_real_le_Un_eq,lemma_finite_omega_set,
 11.2135 +     finite_real_of_posnat_less_real]));
 11.2136 +qed "finite_real_of_posnat_le_real";
 11.2137 +
 11.2138 +Goal "finite {n. abs(real_of_posnat n) <= u}";
 11.2139 +by (full_simp_tac (simpset() addsimps [rename_numerals 
 11.2140 +    real_of_posnat_gt_zero,abs_eqI2,
 11.2141 +    finite_real_of_posnat_le_real]) 1);
 11.2142 +qed "finite_rabs_real_of_posnat_le_real";
 11.2143 +
 11.2144 +Goal "{n. abs(real_of_posnat n) <= u} ~: FreeUltrafilterNat";
 11.2145 +by (blast_tac (claset() addSIs [FreeUltrafilterNat_finite,
 11.2146 +    finite_rabs_real_of_posnat_le_real]) 1);
 11.2147 +qed "rabs_real_of_posnat_le_real_FreeUltrafilterNat";
 11.2148 +
 11.2149 +Goal "{n. u < real_of_posnat n} : FreeUltrafilterNat";
 11.2150 +by (rtac ccontr 1 THEN dtac FreeUltrafilterNat_Compl_mem 1);
 11.2151 +by (auto_tac (claset(),simpset() addsimps 
 11.2152 +    [CLAIM_SIMP "- {n. u < real_of_posnat  n} = \
 11.2153 +\                {n. real_of_posnat n <= u}" 
 11.2154 +     [real_le_def],finite_real_of_posnat_le_real 
 11.2155 +                   RS FreeUltrafilterNat_finite]));
 11.2156 +qed "FreeUltrafilterNat_nat_gt_real";
 11.2157 +
 11.2158 +(*--------------------------------------------------------------
 11.2159 + The complement of {n. abs(real_of_posnat n) <= u} = 
 11.2160 + {n. u < abs (real_of_posnat n)} is in FreeUltrafilterNat 
 11.2161 + by property of (free) ultrafilters
 11.2162 + --------------------------------------------------------------*)
 11.2163 +Goal "- {n. abs (real_of_posnat  n) <= u} = \
 11.2164 +\     {n. u < abs (real_of_posnat  n)}";
 11.2165 +by (auto_tac (claset() addSDs [real_le_less_trans],
 11.2166 +   simpset() addsimps [not_real_leE,real_less_not_refl]));
 11.2167 +val lemma = result();
 11.2168 +
 11.2169 +Goal "{n. u < abs (real_of_posnat n)} : FreeUltrafilterNat";
 11.2170 +by (cut_inst_tac [("u","u")] rabs_real_of_posnat_le_real_FreeUltrafilterNat 1);
 11.2171 +by (auto_tac (claset() addDs [FreeUltrafilterNat_Compl_mem],
 11.2172 +    simpset() addsimps [lemma]));
 11.2173 +qed "FreeUltrafilterNat_omega";
 11.2174 +
 11.2175 +(*-----------------------------------------------
 11.2176 +       Omega is a member of HInfinite
 11.2177 + -----------------------------------------------*)
 11.2178 +Goalw [omega_def] "whr: HInfinite";
 11.2179 +by (auto_tac (claset() addSIs [FreeUltrafilterNat_HInfinite,
 11.2180 +    lemma_hyprel_refl,FreeUltrafilterNat_omega],simpset()));
 11.2181 +qed "HInfinite_omega";
 11.2182 +
 11.2183 +(*-----------------------------------------------
 11.2184 +       Epsilon is a member of Infinitesimal
 11.2185 + -----------------------------------------------*)
 11.2186 +
 11.2187 +Goal "ehr : Infinitesimal";
 11.2188 +by (auto_tac (claset() addSIs [HInfinite_hrinv_Infinitesimal,HInfinite_omega],
 11.2189 +    simpset() addsimps [hypreal_epsilon_hrinv_omega]));
 11.2190 +qed "Infinitesimal_epsilon";
 11.2191 +Addsimps [Infinitesimal_epsilon];
 11.2192 +
 11.2193 +Goal "ehr : HFinite";
 11.2194 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
 11.2195 +    simpset()));
 11.2196 +qed "HFinite_epsilon";
 11.2197 +Addsimps [HFinite_epsilon];
 11.2198 +
 11.2199 +Goal "ehr @= 0";
 11.2200 +by (simp_tac (simpset() addsimps [mem_infmal_iff RS sym]) 1);
 11.2201 +qed "epsilon_inf_close_zero";
 11.2202 +Addsimps [epsilon_inf_close_zero];
 11.2203 +
 11.2204 +(*------------------------------------------------------------------------
 11.2205 +  Needed for proof that we define a hyperreal [<X(n)] @= hypreal_of_real a given 
 11.2206 +  that ALL n. |X n - a| < 1/n. Used in proof of NSLIM => LIM.
 11.2207 + -----------------------------------------------------------------------*)
 11.2208 +
 11.2209 +Goal "!!u. 0 < u ==> finite {n. u < rinv(real_of_posnat n)}";
 11.2210 +by (asm_simp_tac (simpset() addsimps [real_of_posnat_less_rinv_iff]) 1);
 11.2211 +by (rtac finite_real_of_posnat_less_real 1);
 11.2212 +qed "finite_rinv_real_of_posnat_gt_real";
 11.2213 +
 11.2214 +Goal "{n. u <= rinv(real_of_posnat n)} = \
 11.2215 +\      {n. u < rinv(real_of_posnat n)} Un {n. u = rinv(real_of_posnat n)}";
 11.2216 +by (auto_tac (claset() addDs [real_le_imp_less_or_eq],
 11.2217 +    simpset() addsimps [real_le_refl,real_less_imp_le]));
 11.2218 +qed "lemma_real_le_Un_eq2";
 11.2219 +
 11.2220 +Goal "!!u. 0 < u ==> finite {n::nat. u = rinv(real_of_posnat  n)}";
 11.2221 +by (asm_simp_tac (simpset() addsimps [real_of_posnat_rinv_eq_iff]) 1);
 11.2222 +by (auto_tac (claset() addIs [lemma_finite_omega_set RSN 
 11.2223 +    (2,finite_subset)],simpset()));
 11.2224 +qed "lemma_finite_omega_set2";
 11.2225 +
 11.2226 +Goal "!!u. 0 < u ==> finite {n. u <= rinv(real_of_posnat n)}";
 11.2227 +by (auto_tac (claset(),simpset() addsimps 
 11.2228 +    [lemma_real_le_Un_eq2,lemma_finite_omega_set2,
 11.2229 +     finite_rinv_real_of_posnat_gt_real]));
 11.2230 +qed "finite_rinv_real_of_posnat_ge_real";
 11.2231 +
 11.2232 +Goal "!!u. 0 < u ==> \
 11.2233 +\    {n. u <= rinv(real_of_posnat n)} ~: FreeUltrafilterNat";
 11.2234 +by (blast_tac (claset() addSIs [FreeUltrafilterNat_finite,
 11.2235 +    finite_rinv_real_of_posnat_ge_real]) 1);
 11.2236 +qed "rinv_real_of_posnat_ge_real_FreeUltrafilterNat";
 11.2237 +
 11.2238 +(*--------------------------------------------------------------
 11.2239 +    The complement of  {n. u <= rinv(real_of_posnat n)} =
 11.2240 +    {n. rinv(real_of_posnat n) < u} is in FreeUltrafilterNat 
 11.2241 +    by property of (free) ultrafilters
 11.2242 + --------------------------------------------------------------*)
 11.2243 +Goal "- {n. u <= rinv(real_of_posnat n)} = \
 11.2244 +\     {n. rinv(real_of_posnat n) < u}";
 11.2245 +by (auto_tac (claset() addSDs [real_le_less_trans],
 11.2246 +   simpset() addsimps [not_real_leE,real_less_not_refl]));
 11.2247 +val lemma = result();
 11.2248 +
 11.2249 +Goal "!!u. 0 < u ==> \
 11.2250 +\     {n. rinv(real_of_posnat n) < u} : FreeUltrafilterNat";
 11.2251 +by (cut_inst_tac [("u","u")]  rinv_real_of_posnat_ge_real_FreeUltrafilterNat 1);
 11.2252 +by (auto_tac (claset() addDs [FreeUltrafilterNat_Compl_mem],
 11.2253 +    simpset() addsimps [lemma]));
 11.2254 +qed "FreeUltrafilterNat_rinv_real_of_posnat";
 11.2255 +
 11.2256 +(*--------------------------------------------------------------
 11.2257 +      Example where we get a hyperreal from a real sequence
 11.2258 +      for which a particular property holds. The theorem is
 11.2259 +      used in proofs about equivalence of nonstandard and
 11.2260 +      standard neighbourhoods. Also used for equivalence of
 11.2261 +      nonstandard ans standard definitions of pointwise 
 11.2262 +      limit (the theorem was previously in REALTOPOS.thy).
 11.2263 + -------------------------------------------------------------*)
 11.2264 +(*-----------------------------------------------------
 11.2265 +    |X(n) - x| < 1/n ==> [<X n>] - hypreal_of_real x|: Infinitesimal 
 11.2266 + -----------------------------------------------------*)
 11.2267 +Goal "ALL n. abs(X n + -x) < rinv(real_of_posnat n) \ 
 11.2268 +\    ==> Abs_hypreal(hyprel^^{X}) + -hypreal_of_real x : Infinitesimal";
 11.2269 +by (auto_tac (claset() addSIs [bexI] addDs [rename_numerals 
 11.2270 +    FreeUltrafilterNat_rinv_real_of_posnat,
 11.2271 +    FreeUltrafilterNat_all,FreeUltrafilterNat_Int] addIs [real_less_trans,
 11.2272 +    FreeUltrafilterNat_subset],simpset() addsimps [hypreal_minus,
 11.2273 +    hypreal_of_real_minus RS sym,hypreal_of_real_def,hypreal_add,
 11.2274 +    Infinitesimal_FreeUltrafilterNat_iff,hypreal_hrinv,hypreal_of_real_of_posnat]));
 11.2275 +qed "real_seq_to_hypreal_Infinitesimal";
 11.2276 +
 11.2277 +Goal "ALL n. abs(X n + -x) < rinv(real_of_posnat n) \ 
 11.2278 +\     ==> Abs_hypreal(hyprel^^{X}) @= hypreal_of_real x";
 11.2279 +by (rtac (inf_close_minus_iff RS ssubst) 1);
 11.2280 +by (rtac (mem_infmal_iff RS subst) 1);
 11.2281 +by (etac real_seq_to_hypreal_Infinitesimal 1);
 11.2282 +qed "real_seq_to_hypreal_inf_close";
 11.2283 +
 11.2284 +Goal "ALL n. abs(x + -X n) < rinv(real_of_posnat n) \ 
 11.2285 +\              ==> Abs_hypreal(hyprel^^{X}) @= hypreal_of_real x";
 11.2286 +by (asm_full_simp_tac (simpset() addsimps [abs_minus_add_cancel,
 11.2287 +        real_seq_to_hypreal_inf_close]) 1);
 11.2288 +qed "real_seq_to_hypreal_inf_close2";
 11.2289 +
 11.2290 +Goal "ALL n. abs(X n + -Y n) < rinv(real_of_posnat n) \ 
 11.2291 +\     ==> Abs_hypreal(hyprel^^{X}) + \
 11.2292 +\         -Abs_hypreal(hyprel^^{Y}) : Infinitesimal";
 11.2293 +by (auto_tac (claset() addSIs [bexI] addDs [rename_numerals 
 11.2294 +    FreeUltrafilterNat_rinv_real_of_posnat,
 11.2295 +    FreeUltrafilterNat_all,FreeUltrafilterNat_Int] addIs [real_less_trans,
 11.2296 +    FreeUltrafilterNat_subset],simpset() addsimps 
 11.2297 +    [Infinitesimal_FreeUltrafilterNat_iff,hypreal_minus,hypreal_add, 
 11.2298 +    hypreal_hrinv,hypreal_of_real_of_posnat]));
 11.2299 +qed "real_seq_to_hypreal_Infinitesimal2";
 11.2300 + 
 11.2301 \ No newline at end of file
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/HOL/Real/Hyperreal/NSA.thy	Thu Sep 21 12:17:11 2000 +0200
    12.3 @@ -0,0 +1,49 @@
    12.4 +(*  Title       : NSA.thy
    12.5 +    Author      : Jacques D. Fleuriot
    12.6 +    Copyright   : 1998  University of Cambridge
    12.7 +    Description : Infinite numbers, Infinitesimals,
    12.8 +                  infinitely close relation etc.
    12.9 +*) 
   12.10 +
   12.11 +NSA = HRealAbs + RComplete +
   12.12 +
   12.13 +constdefs
   12.14 +
   12.15 +   (* standard real numbers reagarded as *)
   12.16 +   (* an embedded subset of hyperreals   *)
   12.17 +   SReal  :: "hypreal set"
   12.18 +   "SReal == {x. EX r. x = hypreal_of_real r}"
   12.19 +
   12.20 +   Infinitesimal  :: "hypreal set"
   12.21 +   "Infinitesimal == {x. ALL r: SReal. 0 < r --> abs x < r}"
   12.22 +
   12.23 +   HFinite :: "hypreal set"
   12.24 +   "HFinite == {x. EX r: SReal. abs x < r}"
   12.25 +
   12.26 +   HInfinite :: "hypreal set"
   12.27 +   "HInfinite == {x. ALL r: SReal. r < abs x}"
   12.28 +
   12.29 +consts   
   12.30 +
   12.31 +    (* standard part map *)
   12.32 +    st       :: hypreal => hypreal
   12.33 +
   12.34 +    (* infinitely close *)
   12.35 +    "@="     :: [hypreal,hypreal] => bool  (infixl 50)  
   12.36 +
   12.37 +    monad    :: hypreal => hypreal set
   12.38 +    galaxy   :: hypreal => hypreal set
   12.39 +
   12.40 +defs  
   12.41 +
   12.42 +   inf_close_def  "x @= y       == (x + -y) : Infinitesimal"     
   12.43 +   st_def         "st           == (%x. @r. x : HFinite & r:SReal & r @= x)"
   12.44 +
   12.45 +   monad_def      "monad x      == {y. x @= y}"
   12.46 +   galaxy_def     "galaxy x     == {y. (x + -y) : HFinite}"
   12.47 + 
   12.48 +end
   12.49 +
   12.50 +
   12.51 +
   12.52 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/HOL/Real/Hyperreal/NatStar.ML	Thu Sep 21 12:17:11 2000 +0200
    13.3 @@ -0,0 +1,541 @@
    13.4 +(*  Title       : NatStar.ML
    13.5 +    Author      : Jacques D. Fleuriot
    13.6 +    Copyright   : 1998  University of Cambridge
    13.7 +    Description : *-transforms in NSA which extends 
    13.8 +                  sets of reals, and nat=>real, 
    13.9 +                  nat=>nat functions
   13.10 +*) 
   13.11 +
   13.12 +Goalw [starsetNat_def] 
   13.13 +      "*sNat*(UNIV::nat set) = (UNIV::hypnat set)";
   13.14 +by (auto_tac (claset(),simpset() addsimps 
   13.15 +    [FreeUltrafilterNat_Nat_set]));
   13.16 +qed "NatStar_real_set";
   13.17 +
   13.18 +Goalw [starsetNat_def] "*sNat* {} = {}";
   13.19 +by (Step_tac 1);
   13.20 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   13.21 +by (dres_inst_tac [("x","%n. xa n")] bspec 1);
   13.22 +by (auto_tac (claset(),simpset() addsimps 
   13.23 +    [FreeUltrafilterNat_empty]));
   13.24 +qed "NatStar_empty_set";
   13.25 +
   13.26 +Addsimps [NatStar_empty_set];
   13.27 +
   13.28 +Goalw [starsetNat_def] 
   13.29 +      "*sNat* (A Un B) = *sNat* A Un *sNat* B";
   13.30 +by (Auto_tac);
   13.31 +by (REPEAT(blast_tac (claset() addIs 
   13.32 +   [FreeUltrafilterNat_subset]) 2));
   13.33 +by (dtac FreeUltrafilterNat_Compl_mem 1);
   13.34 +by (dtac bspec 1 THEN assume_tac 1);
   13.35 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   13.36 +by (Auto_tac);
   13.37 +by (Fuf_tac 1);
   13.38 +qed "NatStar_Un";
   13.39 +
   13.40 +Goalw [starsetNat_n_def] 
   13.41 +      "*sNatn* (%n. (A n) Un (B n)) = *sNatn* A Un *sNatn* B";
   13.42 +by Auto_tac;
   13.43 +by (dres_inst_tac [("x","Xa")] bspec 1);
   13.44 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 2);
   13.45 +by (auto_tac (claset() addSDs [bspec],simpset()));
   13.46 +by (TRYALL(Ultra_tac));
   13.47 +qed "starsetNat_n_Un";
   13.48 +
   13.49 +Goalw [InternalNatSets_def]
   13.50 +     "[| X : InternalNatSets; Y : InternalNatSets |] \
   13.51 +\     ==> (X Un Y) : InternalNatSets";
   13.52 +by (auto_tac (claset(),simpset() addsimps [starsetNat_n_Un RS sym]));
   13.53 +qed "InternalNatSets_Un";
   13.54 +
   13.55 +Goalw [starsetNat_def] "*sNat* (A Int B) = *sNat* A Int *sNat* B";
   13.56 +by (Auto_tac);
   13.57 +by (blast_tac (claset() addIs [FreeUltrafilterNat_Int,
   13.58 +    FreeUltrafilterNat_subset]) 3);
   13.59 +by (REPEAT(blast_tac (claset() addIs 
   13.60 +    [FreeUltrafilterNat_subset]) 1));
   13.61 +qed "NatStar_Int";
   13.62 +
   13.63 +Goalw [starsetNat_n_def] 
   13.64 +      "*sNatn* (%n. (A n) Int (B n)) = *sNatn* A Int *sNatn* B";
   13.65 +by (Auto_tac);
   13.66 +by (auto_tac (claset() addSDs [bspec],simpset()));
   13.67 +by (TRYALL(Ultra_tac));
   13.68 +qed "starsetNat_n_Int";
   13.69 +
   13.70 +Goalw [InternalNatSets_def]
   13.71 +     "[| X : InternalNatSets; Y : InternalNatSets |] \
   13.72 +\     ==> (X Int Y) : InternalNatSets";
   13.73 +by (auto_tac (claset(),simpset() addsimps [starsetNat_n_Int RS sym]));
   13.74 +qed "InternalNatSets_Int";
   13.75 +
   13.76 +Goalw [starsetNat_def] "*sNat* (-A) = -(*sNat* A)";
   13.77 +by (Auto_tac);
   13.78 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   13.79 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 2);
   13.80 +by (REPEAT(Step_tac 1) THEN Auto_tac);
   13.81 +by (TRYALL(Ultra_tac));
   13.82 +qed "NatStar_Compl";
   13.83 +
   13.84 +Goalw [starsetNat_n_def] "*sNatn* ((%n. - A n)) = -(*sNatn* A)";
   13.85 +by (Auto_tac);
   13.86 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
   13.87 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 2);
   13.88 +by (REPEAT(Step_tac 1) THEN Auto_tac);
   13.89 +by (TRYALL(Ultra_tac));
   13.90 +qed "starsetNat_n_Compl";
   13.91 +
   13.92 +Goalw [InternalNatSets_def]
   13.93 +     "X :InternalNatSets ==> -X : InternalNatSets";
   13.94 +by (auto_tac (claset(),simpset() addsimps [starsetNat_n_Compl RS sym]));
   13.95 +qed "InternalNatSets_Compl";
   13.96 +
   13.97 +Goalw [starsetNat_n_def] 
   13.98 +      "*sNatn* (%n. (A n) - (B n)) = *sNatn* A - *sNatn* B";
   13.99 +by (Auto_tac);
  13.100 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 2);
  13.101 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 3);
  13.102 +by (auto_tac (claset() addSDs [bspec],simpset()));
  13.103 +by (TRYALL(Ultra_tac));
  13.104 +qed "starsetNat_n_diff";
  13.105 +
  13.106 +Goalw [InternalNatSets_def]
  13.107 +     "[| X : InternalNatSets; Y : InternalNatSets |] \
  13.108 +\     ==> (X - Y) : InternalNatSets";
  13.109 +by (auto_tac (claset(),simpset() addsimps [starsetNat_n_diff RS sym]));
  13.110 +qed "InternalNatSets_diff";
  13.111 +
  13.112 +Goalw [starsetNat_def] "!!A. A <= B ==> *sNat* A <= *sNat* B";
  13.113 +by (REPEAT(blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 1));
  13.114 +qed "NatStar_subset";
  13.115 +
  13.116 +Goalw [starsetNat_def,hypnat_of_nat_def] 
  13.117 +          "!!A. a : A ==> hypnat_of_nat a : *sNat* A";
  13.118 +by (auto_tac (claset() addIs [FreeUltrafilterNat_subset],simpset()));
  13.119 +qed "NatStar_mem";
  13.120 +
  13.121 +Goalw [starsetNat_def] "hypnat_of_nat `` A <= *sNat* A";
  13.122 +by (auto_tac (claset(),simpset() addsimps [hypnat_of_nat_def]));
  13.123 +by (blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 1);
  13.124 +qed "NatStar_hypreal_of_real_image_subset";
  13.125 +
  13.126 +Goal "SHNat <= *sNat* (UNIV:: nat set)";
  13.127 +by (simp_tac (simpset() addsimps [SHNat_hypnat_of_nat_iff,
  13.128 +    NatStar_hypreal_of_real_image_subset]) 1);
  13.129 +qed "NatStar_SHNat_subset";
  13.130 +
  13.131 +Goalw [starsetNat_def] 
  13.132 +      "*sNat* X Int SHNat = hypnat_of_nat `` X";
  13.133 +by (auto_tac (claset(),simpset() addsimps 
  13.134 +           [hypnat_of_nat_def,SHNat_def]));
  13.135 +by (fold_tac [hypnat_of_nat_def]);
  13.136 +by (rtac imageI 1 THEN rtac ccontr 1);
  13.137 +by (dtac bspec 1);
  13.138 +by (rtac lemma_hypnatrel_refl 1);
  13.139 +by (blast_tac (claset() addIs [FreeUltrafilterNat_subset]) 2);
  13.140 +by (Auto_tac);
  13.141 +qed "NatStar_hypreal_of_real_Int";
  13.142 +
  13.143 +Goal "!!x. x ~: hypnat_of_nat `` A ==> ALL y: A. x ~= hypnat_of_nat y";
  13.144 +by (Auto_tac);
  13.145 +qed "lemma_not_hypnatA";
  13.146 +
  13.147 +Goalw [starsetNat_n_def,starsetNat_def] "*sNat* X = *sNatn* (%n. X)";
  13.148 +by Auto_tac;
  13.149 +qed "starsetNat_starsetNat_n_eq";
  13.150 +
  13.151 +Goalw [InternalNatSets_def] "(*sNat* X) : InternalNatSets";
  13.152 +by (auto_tac (claset(),simpset() addsimps [starsetNat_starsetNat_n_eq]));
  13.153 +qed "InternalNatSets_starsetNat_n";
  13.154 +Addsimps [InternalNatSets_starsetNat_n];
  13.155 +
  13.156 +Goal "X : InternalNatSets ==> UNIV - X : InternalNatSets";
  13.157 +by (auto_tac (claset() addIs [InternalNatSets_Compl],simpset()));
  13.158 +qed "InternalNatSets_UNIV_diff";
  13.159 +
  13.160 +(*------------------------------------------------------------------ 
  13.161 +   Nonstandard extension of a set (defined using a constant 
  13.162 +   sequence) as a special case of an internal set
  13.163 + -----------------------------------------------------------------*)
  13.164 +
  13.165 +Goalw [starsetNat_n_def,starsetNat_def] 
  13.166 +     "!!A. ALL n. (As n = A) ==> *sNatn* As = *sNat* A";
  13.167 +by (Auto_tac);
  13.168 +qed "starsetNat_n_starsetNat";
  13.169 +
  13.170 +(*------------------------------------------------------
  13.171 +   Theorems about nonstandard extensions of functions
  13.172 + ------------------------------------------------------*)
  13.173 +
  13.174 +(*------------------------------------------------------------------ 
  13.175 +   Nonstandard extension of a function (defined using a constant 
  13.176 +   sequence) as a special case of an internal function
  13.177 + -----------------------------------------------------------------*)
  13.178 +
  13.179 +Goalw [starfunNat_n_def,starfunNat_def] 
  13.180 +     "!!A. ALL n. (F n = f) ==> *fNatn* F = *fNat* f";
  13.181 +by (Auto_tac);
  13.182 +qed "starfunNat_n_starfunNat";
  13.183 +
  13.184 +Goalw [starfunNat2_n_def,starfunNat2_def] 
  13.185 +     "!!A. ALL n. (F n = f) ==> *fNat2n* F = *fNat2* f";
  13.186 +by (Auto_tac);
  13.187 +qed "starfunNat2_n_starfunNat2";
  13.188 +
  13.189 +Goalw [congruent_def] 
  13.190 +      "congruent hypnatrel (%X. hypnatrel^^{%n. f (X n)})";
  13.191 +by (safe_tac (claset()));
  13.192 +by (ALLGOALS(Fuf_tac));
  13.193 +qed "starfunNat_congruent";
  13.194 +
  13.195 +(* f::nat=>real *)
  13.196 +Goalw [starfunNat_def]
  13.197 +      "(*fNat* f) (Abs_hypnat(hypnatrel^^{%n. X n})) = \
  13.198 +\      Abs_hypreal(hyprel ^^ {%n. f (X n)})";
  13.199 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
  13.200 +by (simp_tac (simpset() addsimps 
  13.201 +   [hyprel_in_hypreal RS Abs_hypreal_inverse]) 1);
  13.202 +by (Auto_tac THEN Fuf_tac 1);
  13.203 +qed "starfunNat";
  13.204 +
  13.205 +(* f::nat=>nat *)
  13.206 +Goalw [starfunNat2_def]
  13.207 +      "(*fNat2* f) (Abs_hypnat(hypnatrel^^{%n. X n})) = \
  13.208 +\      Abs_hypnat(hypnatrel ^^ {%n. f (X n)})";
  13.209 +by (res_inst_tac [("f","Abs_hypnat")] arg_cong 1);
  13.210 +by (simp_tac (simpset() addsimps 
  13.211 +   [hypnatrel_in_hypnat RS Abs_hypnat_inverse,
  13.212 +    [equiv_hypnatrel, starfunNat_congruent] MRS UN_equiv_class]) 1);
  13.213 +qed "starfunNat2";
  13.214 +
  13.215 +(*---------------------------------------------
  13.216 +  multiplication: ( *f ) x ( *g ) = *(f x g)  
  13.217 + ---------------------------------------------*)
  13.218 +Goal "(*fNat* f) xa * (*fNat* g) xa = (*fNat* (%x. f x * g x)) xa";
  13.219 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.220 +by (auto_tac (claset(),simpset() addsimps 
  13.221 +    [starfunNat,hypreal_mult]));
  13.222 +qed "starfunNat_mult";
  13.223 +
  13.224 +Goal "(*fNat2* f) xa * (*fNat2* g) xa = (*fNat2* (%x. f x * g x)) xa";
  13.225 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.226 +by (auto_tac (claset(),simpset() addsimps 
  13.227 +    [starfunNat2,hypnat_mult]));
  13.228 +qed "starfunNat2_mult";
  13.229 +
  13.230 +(*---------------------------------------
  13.231 +  addition: ( *f ) + ( *g ) = *(f + g)  
  13.232 + ---------------------------------------*)
  13.233 +Goal "(*fNat* f) xa + (*fNat* g) xa = (*fNat* (%x. f x + g x)) xa";
  13.234 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.235 +by (auto_tac (claset(),simpset() addsimps 
  13.236 +    [starfunNat,hypreal_add]));
  13.237 +qed "starfunNat_add";
  13.238 +
  13.239 +Goal "(*fNat2* f) xa + (*fNat2* g) xa = (*fNat2* (%x. f x + g x)) xa";
  13.240 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.241 +by (auto_tac (claset(),simpset() addsimps 
  13.242 +    [starfunNat2,hypnat_add]));
  13.243 +qed "starfunNat2_add";
  13.244 +
  13.245 +(*--------------------------------------------
  13.246 +  subtraction: ( *f ) + -( *g ) = *(f + -g)  
  13.247 + --------------------------------------------*)
  13.248 +Goal "(*fNat* f) xa + -(*fNat* g) xa = (*fNat* (%x. f x + -g x)) xa";
  13.249 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.250 +by (auto_tac (claset(),simpset() addsimps [starfunNat,
  13.251 +    hypreal_minus,hypreal_add]));
  13.252 +qed "starfunNat_add_minus";
  13.253 +
  13.254 +Goal "(*fNat2* f) xa - (*fNat2* g) xa = (*fNat2* (%x. f x - g x)) xa";
  13.255 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.256 +by (auto_tac (claset(),simpset() addsimps [starfunNat2,
  13.257 +    hypnat_minus]));
  13.258 +qed "starfunNat2_minus";
  13.259 +
  13.260 +(*--------------------------------------
  13.261 +  composition: ( *f ) o ( *g ) = *(f o g)  
  13.262 + ---------------------------------------*)
  13.263 +(***** ( *f::nat=>real ) o ( *g::nat=>nat ) = *(f o g) *****)
  13.264 + 
  13.265 +Goal "(*fNat* f) o (*fNat2* g) = (*fNat* (f o g))";
  13.266 +by (rtac ext 1);
  13.267 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  13.268 +by (auto_tac (claset(),simpset() addsimps [starfunNat2,
  13.269 +    starfunNat]));
  13.270 +qed "starfunNatNat2_o";
  13.271 +
  13.272 +Goal "(%x. (*fNat* f) ((*fNat2* g) x)) = (*fNat* (%x. f(g x)))";
  13.273 +by (rtac ( simplify (simpset() addsimps [o_def]) starfunNatNat2_o) 1);
  13.274 +qed "starfunNatNat2_o2";
  13.275 +
  13.276 +(***** ( *f::nat=>nat ) o ( *g::nat=>nat ) = *(f o g) *****)
  13.277 +Goal "(*fNat2* f) o (*fNat2* g) = (*fNat2* (f o g))";
  13.278 +by (rtac ext 1);
  13.279 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  13.280 +by (auto_tac (claset(),simpset() addsimps [starfunNat2]));
  13.281 +qed "starfunNat2_o";
  13.282 +
  13.283 +(***** ( *f::real=>real ) o ( *g::nat=>real ) = *(f o g) *****)
  13.284 +
  13.285 +Goal "(*f* f) o (*fNat* g) = (*fNat* (f o g))"; 
  13.286 +by (rtac ext 1);
  13.287 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  13.288 +by (auto_tac (claset(),simpset() addsimps [starfunNat,starfun]));
  13.289 +qed "starfun_stafunNat_o";
  13.290 +
  13.291 +Goal "(%x. (*f* f) ((*fNat* g) x)) = (*fNat* (%x. f (g x)))"; 
  13.292 +by (rtac ( simplify (simpset() addsimps [o_def]) starfun_stafunNat_o) 1);
  13.293 +qed "starfun_stafunNat_o2";
  13.294 +
  13.295 +(*--------------------------------------
  13.296 +  NS extension of constant function
  13.297 + --------------------------------------*)
  13.298 +Goal "(*fNat* (%x. k)) xa = hypreal_of_real k";
  13.299 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.300 +by (auto_tac (claset(),simpset() addsimps [starfunNat,
  13.301 +    hypreal_of_real_def]));
  13.302 +qed "starfunNat_const_fun";
  13.303 +Addsimps [starfunNat_const_fun];
  13.304 +
  13.305 +Goal "(*fNat2* (%x. k)) xa = hypnat_of_nat  k";
  13.306 +by (res_inst_tac [("z","xa")] eq_Abs_hypnat 1);
  13.307 +by (auto_tac (claset(),simpset() addsimps [starfunNat2,
  13.308 +    hypnat_of_nat_def]));
  13.309 +qed "starfunNat2_const_fun";
  13.310 +
  13.311 +Addsimps [starfunNat2_const_fun];
  13.312 +
  13.313 +Goal "- (*fNat* f) x = (*fNat* (%x. - f x)) x";
  13.314 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  13.315 +by (auto_tac (claset(),simpset() addsimps [starfunNat,
  13.316 +              hypreal_minus]));
  13.317 +qed "starfunNat_minus";
  13.318 +
  13.319 +Goal "ALL x. f x ~= 0 ==> \
  13.320 +\     hrinv ((*fNat* f) x) = (*fNat* (%x. rinv (f x))) x";
  13.321 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  13.322 +by (auto_tac (claset(),simpset() addsimps [starfunNat,
  13.323 +              hypreal_hrinv]));
  13.324 +qed "starfunNat_hrinv";
  13.325 +
  13.326 +(*--------------------------------------------------------
  13.327 +   extented function has same solution as its standard
  13.328 +   version for natural arguments. i.e they are the same
  13.329 +   for all natural arguments (c.f. Hoskins pg. 107- SEQ)
  13.330 + -------------------------------------------------------*)
  13.331 +
  13.332 +Goal "(*fNat* f) (hypnat_of_nat a) = hypreal_of_real (f a)";
  13.333 +by (auto_tac (claset(),simpset() addsimps 
  13.334 +     [starfunNat,hypnat_of_nat_def,hypreal_of_real_def]));
  13.335 +qed "starfunNat_eq";
  13.336 +
  13.337 +Addsimps [starfunNat_eq];
  13.338 +
  13.339 +Goal "(*fNat2* f) (hypnat_of_nat a) = hypnat_of_nat (f a)";
  13.340 +by (auto_tac (claset(),simpset() addsimps 
  13.341 +     [starfunNat2,hypnat_of_nat_def]));
  13.342 +qed "starfunNat2_eq";
  13.343 +
  13.344 +Addsimps [starfunNat2_eq];
  13.345 +
  13.346 +Goal "(*fNat* f) (hypnat_of_nat a) @= hypreal_of_real (f a)";
  13.347 +by (Auto_tac);
  13.348 +qed "starfunNat_inf_close";
  13.349 +
  13.350 +Goal "!!f. [| (*fNat* f) xa @= l; (*fNat* g) xa @= m; \
  13.351 +\                 l: HFinite; m: HFinite  \
  13.352 +\              |] ==>  (*fNat* (%x. f x * g x)) xa @= l * m";
  13.353 +by (dtac inf_close_mult_HFinite 1);
  13.354 +by (REPEAT(assume_tac 1));
  13.355 +by (auto_tac (claset() addIs [inf_close_sym RSN (2,inf_close_HFinite)],
  13.356 +              simpset() addsimps [starfunNat_mult]));
  13.357 +qed "starfunNat_mult_HFinite_inf_close";
  13.358 +
  13.359 +Goal "!!f. [| (*fNat* f) xa @= l; (*fNat* g) xa @= m \
  13.360 +\              |] ==>  (*fNat* (%x. f x + g x)) xa @= l + m";
  13.361 +by (auto_tac (claset() addIs [inf_close_add],
  13.362 +              simpset() addsimps [starfunNat_add RS sym]));
  13.363 +qed "starfunNat_add_inf_close";
  13.364 +
  13.365 +(*-------------------------------------------------------------------
  13.366 +  A few more theorems involving NS extension of real sequences
  13.367 +  See analogous theorems for starfun- NS extension of f::real=>real
  13.368 + ------------------------------------------------------------------*)
  13.369 +Goal 
  13.370 +     "!!f. (*fNat* f) x ~= 0 ==> \
  13.371 +\     hrinv ((*fNat* f) x) = (*fNat* (%x. rinv (f x))) x";
  13.372 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  13.373 +by (auto_tac (claset() addIs [FreeUltrafilterNat_subset]
  13.374 +    addSDs [FreeUltrafilterNat_Compl_mem],
  13.375 +    simpset() addsimps [starfunNat,hypreal_hrinv,
  13.376 +    hypreal_zero_def]));
  13.377 +qed "starfunNat_hrinv2";
  13.378 +
  13.379 +(*-----------------------------------------------------------------
  13.380 +    Example of transfer of a property from reals to hyperreals
  13.381 +    --- used for limit comparison of sequences
  13.382 + ----------------------------------------------------------------*)
  13.383 +Goal "!!f. ALL n. N <= n --> f n <= g n \
  13.384 +\         ==> ALL n. hypnat_of_nat N <= n --> (*fNat* f) n <= (*fNat* g) n";
  13.385 +by (Step_tac 1);
  13.386 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  13.387 +by (auto_tac (claset(),simpset() addsimps [starfunNat,
  13.388 +        hypnat_of_nat_def,hypreal_le,hypreal_less,
  13.389 +        hypnat_le,hypnat_less]));
  13.390 +by (Ultra_tac 1);
  13.391 +by Auto_tac;
  13.392 +qed "starfun_le_mono";
  13.393 +
  13.394 +(*****----- and another -----*****) 
  13.395 +goal NatStar.thy 
  13.396 +     "!!f. ALL n. N <= n --> f n < g n \
  13.397 +\         ==> ALL n. hypnat_of_nat N <= n --> (*fNat* f) n < (*fNat* g) n";
  13.398 +by (Step_tac 1);
<