separation of HOL-Hyperreal from HOL-Real
authorpaulson
Sat Dec 30 22:03:47 2000 +0100 (2000-12-30)
changeset 10751a81ea5d3dd41
parent 10750 a681d3df1a39
child 10752 c4f1bf2acf4c
separation of HOL-Hyperreal from HOL-Real
src/HOL/Hyperreal/HSeries.ML
src/HOL/Hyperreal/HSeries.thy
src/HOL/Hyperreal/HyperArith.thy
src/HOL/Hyperreal/HyperArith0.ML
src/HOL/Hyperreal/HyperArith0.thy
src/HOL/Hyperreal/HyperBin.ML
src/HOL/Hyperreal/HyperBin.thy
src/HOL/Hyperreal/HyperDef.ML
src/HOL/Hyperreal/HyperDef.thy
src/HOL/Hyperreal/HyperNat.ML
src/HOL/Hyperreal/HyperNat.thy
src/HOL/Hyperreal/HyperOrd.ML
src/HOL/Hyperreal/HyperOrd.thy
src/HOL/Hyperreal/HyperPow.ML
src/HOL/Hyperreal/HyperPow.thy
src/HOL/Hyperreal/Hyperreal.thy
src/HOL/Hyperreal/Lim.ML
src/HOL/Hyperreal/Lim.thy
src/HOL/Hyperreal/NSA.ML
src/HOL/Hyperreal/NSA.thy
src/HOL/Hyperreal/NatStar.ML
src/HOL/Hyperreal/NatStar.thy
src/HOL/Hyperreal/ROOT.ML
src/HOL/Hyperreal/SEQ.ML
src/HOL/Hyperreal/SEQ.thy
src/HOL/Hyperreal/Series.ML
src/HOL/Hyperreal/Series.thy
src/HOL/Hyperreal/Star.ML
src/HOL/Hyperreal/Star.thy
src/HOL/Hyperreal/Zorn.ML
src/HOL/Hyperreal/Zorn.thy
src/HOL/Hyperreal/fuf.ML
src/HOL/Hyperreal/hypreal_arith.ML
src/HOL/Hyperreal/hypreal_arith0.ML
src/HOL/IsaMakefile
src/HOL/Real/Hyperreal/Filter.ML
src/HOL/Real/Hyperreal/Filter.thy
src/HOL/Real/Hyperreal/HRealAbs.ML
src/HOL/Real/Hyperreal/HRealAbs.thy
src/HOL/Real/Hyperreal/HyperDef.ML
src/HOL/Real/Hyperreal/HyperDef.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/Hyperreal.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
src/HOL/Real/Hyperreal/Zorn.ML
src/HOL/Real/Hyperreal/Zorn.thy
src/HOL/Real/Hyperreal/fuf.ML
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Hyperreal/HSeries.ML	Sat Dec 30 22:03:47 2000 +0100
     1.3 @@ -0,0 +1,321 @@
     1.4 +(*  Title       : HSeries.ML
     1.5 +    Author      : Jacques D. Fleuriot
     1.6 +    Copyright   : 1998  University of Cambridge
     1.7 +    Description : Finite summation and infinite series
     1.8 +                  for hyperreals
     1.9 +*) 
    1.10 +
    1.11 +Goalw [sumhr_def]
    1.12 +     "sumhr(M,N,f) =  \
    1.13 +\       Abs_hypreal(UN X:Rep_hypnat(M). UN Y: Rep_hypnat(N). \
    1.14 +\         hyprel ^^{%n::nat. sumr (X n) (Y n) f})";
    1.15 +by (Auto_tac);
    1.16 +qed "sumhr_iff";
    1.17 +
    1.18 +Goalw [sumhr_def]
    1.19 +     "sumhr(Abs_hypnat(hypnatrel^^{%n. M n}), \
    1.20 +\           Abs_hypnat(hypnatrel^^{%n. N n}), f) = \
    1.21 +\     Abs_hypreal(hyprel ^^ {%n. sumr (M n) (N n) f})";
    1.22 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
    1.23 +by (Auto_tac THEN Ultra_tac 1);
    1.24 +qed "sumhr";
    1.25 +
    1.26 +(*------------------------------------------------------- 
    1.27 +  lcp's suggestion: exploit pattern matching 
    1.28 +  facilities and use as definition instead (to do)
    1.29 + -------------------------------------------------------*)
    1.30 +Goalw [sumhr_def]
    1.31 +      "sumhr p = (%(M,N,f). Abs_hypreal(UN X:Rep_hypnat(M). \
    1.32 +\                     UN Y: Rep_hypnat(N). \
    1.33 +\           hyprel ^^{%n::nat. sumr (X n) (Y n) f})) p";
    1.34 +by (res_inst_tac [("p","p")] PairE 1);
    1.35 +by (res_inst_tac [("p","y")] PairE 1);
    1.36 +by (Auto_tac);
    1.37 +qed "sumhr_iff2";
    1.38 +
    1.39 +(* Theorem corresponding to base case in def of sumr *)
    1.40 +Goalw [hypnat_zero_def]
    1.41 +     "sumhr (m,0,f) = #0";
    1.42 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
    1.43 +by (auto_tac (claset(), 
    1.44 +              simpset() addsimps [sumhr, symmetric hypreal_zero_def]));
    1.45 +qed "sumhr_zero";
    1.46 +Addsimps [sumhr_zero];
    1.47 +
    1.48 +(* Theorem corresponding to recursive case in def of sumr *)
    1.49 +Goalw [hypnat_one_def]
    1.50 +     "sumhr(m,n+1hn,f) = (if n + 1hn <= m then #0 \
    1.51 +\                         else sumhr(m,n,f) + (*fNat* f) n)";
    1.52 +by (simp_tac (HOL_ss addsimps
    1.53 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
    1.54 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
    1.55 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
    1.56 +by (auto_tac (claset(),
    1.57 +     simpset() addsimps [sumhr, hypnat_add,hypnat_le,starfunNat,hypreal_add]));
    1.58 +by (ALLGOALS(Ultra_tac));
    1.59 +qed "sumhr_if";
    1.60 +
    1.61 +Goalw [hypnat_one_def] "sumhr (n + 1hn, n, f) = #0";
    1.62 +by (simp_tac (HOL_ss addsimps
    1.63 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
    1.64 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
    1.65 +by (auto_tac (claset(),
    1.66 +              simpset() addsimps [sumhr, hypnat_add]));
    1.67 +qed "sumhr_Suc_zero";
    1.68 +Addsimps [sumhr_Suc_zero];
    1.69 +
    1.70 +Goal "sumhr (n,n,f) = #0";
    1.71 +by (simp_tac (HOL_ss addsimps
    1.72 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
    1.73 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
    1.74 +by (auto_tac (claset(), simpset() addsimps [sumhr]));
    1.75 +qed "sumhr_eq_bounds";
    1.76 +Addsimps [sumhr_eq_bounds];
    1.77 +
    1.78 +Goalw [hypnat_one_def] 
    1.79 +     "sumhr (m,m + 1hn,f) = (*fNat* f) m";
    1.80 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
    1.81 +by (auto_tac (claset(),
    1.82 +              simpset() addsimps [sumhr, hypnat_add,starfunNat]));
    1.83 +qed "sumhr_Suc";
    1.84 +Addsimps [sumhr_Suc];
    1.85 +
    1.86 +Goal "sumhr(m+k,k,f) = #0";
    1.87 +by (simp_tac (HOL_ss addsimps
    1.88 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
    1.89 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
    1.90 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
    1.91 +by (auto_tac (claset(),
    1.92 +              simpset() addsimps [sumhr, hypnat_add]));
    1.93 +qed "sumhr_add_lbound_zero";
    1.94 +Addsimps [sumhr_add_lbound_zero];
    1.95 +
    1.96 +Goal "sumhr (m,n,f) + sumhr(m,n,g) = sumhr(m,n,%i. f i + g i)";
    1.97 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
    1.98 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
    1.99 +by (auto_tac (claset(),
   1.100 +              simpset() addsimps [sumhr, hypreal_add,sumr_add]));
   1.101 +qed "sumhr_add";
   1.102 +
   1.103 +Goalw [hypreal_of_real_def]
   1.104 +      "hypreal_of_real r * sumhr(m,n,f) = sumhr(m,n,%n. r * f n)";
   1.105 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   1.106 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.107 +by (auto_tac (claset(),
   1.108 +              simpset() addsimps [sumhr, hypreal_mult,sumr_mult]));
   1.109 +qed "sumhr_mult";
   1.110 +
   1.111 +Goalw [hypnat_zero_def]
   1.112 +     "n < p ==> sumhr (0,n,f) + sumhr (n,p,f) = sumhr (0,p,f)";
   1.113 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.114 +by (res_inst_tac [("z","p")] eq_Abs_hypnat 1);
   1.115 +by (auto_tac (claset() addSEs [FreeUltrafilterNat_subset],
   1.116 +       simpset() addsimps [sumhr,hypreal_add,hypnat_less, sumr_split_add]));
   1.117 +qed "sumhr_split_add";
   1.118 +
   1.119 +(*FIXME delete*)
   1.120 +Goal "n < p ==> sumhr (0, p, f) + - sumhr (0, n, f) = sumhr (n,p,f)";
   1.121 +by (dres_inst_tac [("f1","f")] (sumhr_split_add RS sym) 1);
   1.122 +by (Asm_simp_tac 1);
   1.123 +qed "sumhr_split_add_minus";
   1.124 +
   1.125 +Goal "n < p ==> sumhr (0, p, f) - sumhr (0, n, f) = sumhr (n,p,f)";
   1.126 +by (dres_inst_tac [("f1","f")] (sumhr_split_add RS sym) 1);
   1.127 +by (Asm_simp_tac 1);
   1.128 +qed "sumhr_split_diff";
   1.129 +
   1.130 +Goal "abs(sumhr(m,n,f)) <= sumhr(m,n,%i. abs(f i))";
   1.131 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.132 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   1.133 +by (auto_tac (claset(),
   1.134 +              simpset() addsimps [sumhr, hypreal_le,hypreal_hrabs,sumr_rabs]));
   1.135 +qed "sumhr_hrabs";
   1.136 +
   1.137 +(* other general version also needed *)
   1.138 +Goalw [hypnat_of_nat_def]
   1.139 +     "(ALL r. m <= r & r < n --> f r = g r) --> \
   1.140 +\     sumhr(hypnat_of_nat m, hypnat_of_nat n, f) = \
   1.141 +\     sumhr(hypnat_of_nat m, hypnat_of_nat n, g)";
   1.142 +by (Step_tac 1 THEN dtac sumr_fun_eq 1);
   1.143 +by (auto_tac (claset(), simpset() addsimps [sumhr]));
   1.144 +qed "sumhr_fun_hypnat_eq";
   1.145 +
   1.146 +Goalw [hypnat_zero_def,hypreal_of_real_def]
   1.147 +      "sumhr(0,n,%i. r) = hypreal_of_hypnat n*hypreal_of_real r";
   1.148 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.149 +by (asm_simp_tac
   1.150 +    (simpset() addsimps [sumhr, hypreal_of_hypnat,hypreal_mult]) 1);
   1.151 +qed "sumhr_const";
   1.152 +
   1.153 +Goalw [hypnat_zero_def,hypreal_of_real_def]
   1.154 +     "sumhr(0,n,f) + -(hypreal_of_hypnat n*hypreal_of_real r) = \
   1.155 +\     sumhr(0,n,%i. f i + -r)";
   1.156 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.157 +by (asm_simp_tac (simpset() addsimps [sumhr,
   1.158 +		    hypreal_of_hypnat,hypreal_mult,hypreal_add,
   1.159 +		    hypreal_minus,sumr_add RS sym]) 1);
   1.160 +qed "sumhr_add_mult_const";
   1.161 +
   1.162 +Goal "n < m ==> sumhr (m,n,f) = #0";
   1.163 +by (simp_tac (HOL_ss addsimps
   1.164 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
   1.165 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   1.166 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.167 +by (auto_tac (claset() addEs [FreeUltrafilterNat_subset],
   1.168 +              simpset() addsimps [sumhr,hypnat_less]));
   1.169 +qed "sumhr_less_bounds_zero";
   1.170 +Addsimps [sumhr_less_bounds_zero];
   1.171 +
   1.172 +Goal "sumhr(m, n, %i. - f i) = - sumhr(m, n, f)";
   1.173 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   1.174 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.175 +by (auto_tac (claset(), simpset() addsimps [sumhr, hypreal_minus,sumr_minus]));
   1.176 +qed "sumhr_minus";
   1.177 +
   1.178 +Goalw [hypnat_of_nat_def]
   1.179 +     "sumhr(m+hypnat_of_nat k,n+hypnat_of_nat k,f) = sumhr(m,n,%i. f(i + k))";
   1.180 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
   1.181 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
   1.182 +by (auto_tac (claset(),
   1.183 +              simpset() addsimps [sumhr, hypnat_add,sumr_shift_bounds]));
   1.184 +qed "sumhr_shift_bounds";
   1.185 +
   1.186 +(*------------------------------------------------------------------
   1.187 +      Theorems about NS sums - infinite sums are obtained
   1.188 +      by summing to some infinite hypernatural (such as whn)
   1.189 + -----------------------------------------------------------------*)
   1.190 +Goalw [hypnat_omega_def,hypnat_zero_def] 
   1.191 +      "sumhr(0,whn,%i. #1) = hypreal_of_hypnat whn";
   1.192 +by (auto_tac (claset(),
   1.193 +              simpset() addsimps [sumhr, hypreal_of_hypnat]));
   1.194 +qed "sumhr_hypreal_of_hypnat_omega";
   1.195 +
   1.196 +Goalw [hypnat_omega_def,hypnat_zero_def,omega_def]  
   1.197 +     "sumhr(0, whn, %i. #1) = whr - #1";
   1.198 +by (simp_tac (HOL_ss addsimps
   1.199 +             [one_eq_numeral_1 RS sym, hypreal_one_def]) 1); 
   1.200 +by (auto_tac (claset(),
   1.201 +              simpset() addsimps [sumhr, hypreal_diff, real_of_nat_def]));
   1.202 +qed "sumhr_hypreal_omega_minus_one";
   1.203 +
   1.204 +Goalw [hypnat_zero_def, hypnat_omega_def]
   1.205 +     "sumhr(0, whn + whn, %i. (-#1) ^ (i+1)) = #0";
   1.206 +by (simp_tac (HOL_ss addsimps
   1.207 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
   1.208 +by (simp_tac (simpset() addsimps [sumhr,hypnat_add] delsimps [realpow_Suc]) 1);
   1.209 +qed "sumhr_minus_one_realpow_zero";
   1.210 +Addsimps [sumhr_minus_one_realpow_zero];
   1.211 +
   1.212 +Goalw [hypnat_of_nat_def,hypreal_of_real_def]
   1.213 +     "(ALL n. m <= Suc n --> f n = r) & m <= na \
   1.214 +\          ==> sumhr(hypnat_of_nat m,hypnat_of_nat na,f) = \
   1.215 +\          (hypreal_of_nat (na - m) * hypreal_of_real r)";
   1.216 +by (auto_tac (claset() addSDs [sumr_interval_const],
   1.217 +    simpset() addsimps [sumhr,hypreal_of_nat_real_of_nat,
   1.218 +              hypreal_of_real_def,hypreal_mult]));
   1.219 +qed "sumhr_interval_const";
   1.220 +
   1.221 +Goalw [hypnat_zero_def]
   1.222 +     "(*fNat* (%n. sumr 0 n f)) N = sumhr(0,N,f)";
   1.223 +by (res_inst_tac [("z","N")] eq_Abs_hypnat 1);
   1.224 +by (asm_full_simp_tac (simpset() addsimps [starfunNat,sumhr]) 1);
   1.225 +qed "starfunNat_sumr";
   1.226 +
   1.227 +Goal "sumhr (0, M, f) @= sumhr (0, N, f) \
   1.228 +\     ==> abs (sumhr (M, N, f)) @= #0";
   1.229 +by (cut_inst_tac [("x","M"),("y","N")] hypnat_linear 1);
   1.230 +by (auto_tac (claset(), simpset() addsimps [inf_close_refl]));
   1.231 +by (dtac (inf_close_sym RS (inf_close_minus_iff RS iffD1)) 1);
   1.232 +by (auto_tac (claset() addDs [inf_close_hrabs],
   1.233 +              simpset() addsimps [sumhr_split_add_minus]));
   1.234 +qed "sumhr_hrabs_inf_close";
   1.235 +Addsimps [sumhr_hrabs_inf_close];
   1.236 +
   1.237 +(*----------------------------------------------------------------
   1.238 +      infinite sums: Standard and NS theorems
   1.239 + ----------------------------------------------------------------*)
   1.240 +Goalw [sums_def,NSsums_def] "(f sums l) = (f NSsums l)";
   1.241 +by (simp_tac (simpset() addsimps [LIMSEQ_NSLIMSEQ_iff]) 1);
   1.242 +qed "sums_NSsums_iff";
   1.243 +
   1.244 +Goalw [summable_def,NSsummable_def] 
   1.245 +      "(summable f) = (NSsummable f)";
   1.246 +by (simp_tac (simpset() addsimps [sums_NSsums_iff]) 1);
   1.247 +qed "summable_NSsummable_iff";
   1.248 +
   1.249 +Goalw [suminf_def,NSsuminf_def] 
   1.250 +      "(suminf f) = (NSsuminf f)";
   1.251 +by (simp_tac (simpset() addsimps [sums_NSsums_iff]) 1);
   1.252 +qed "suminf_NSsuminf_iff";
   1.253 +
   1.254 +Goalw [NSsums_def,NSsummable_def] 
   1.255 +      "f NSsums l ==> NSsummable f";
   1.256 +by (Blast_tac 1);
   1.257 +qed "NSsums_NSsummable";
   1.258 +
   1.259 +Goalw [NSsummable_def,NSsuminf_def]
   1.260 +     "NSsummable f ==> f NSsums (NSsuminf f)";
   1.261 +by (blast_tac (claset() addIs [someI2]) 1);
   1.262 +qed "NSsummable_NSsums";
   1.263 +
   1.264 +Goal "f NSsums s ==> (s = NSsuminf f)";
   1.265 +by (asm_full_simp_tac 
   1.266 +    (simpset() addsimps [suminf_NSsuminf_iff RS sym,sums_NSsums_iff,
   1.267 +                         sums_unique]) 1);
   1.268 +qed "NSsums_unique";
   1.269 +
   1.270 +Goal "ALL m. n <= Suc m --> f(m) = #0 ==> f NSsums (sumr 0 n f)";
   1.271 +by (asm_simp_tac (simpset() addsimps [sums_NSsums_iff RS sym, series_zero]) 1);
   1.272 +qed "NSseries_zero";
   1.273 +
   1.274 +Goal "NSsummable f = \
   1.275 +\     (ALL M: HNatInfinite. ALL N: HNatInfinite. abs (sumhr(M,N,f)) @= #0)";
   1.276 +by (auto_tac (claset(),
   1.277 +              simpset() addsimps [summable_NSsummable_iff RS sym,
   1.278 +                 summable_convergent_sumr_iff, convergent_NSconvergent_iff,
   1.279 +                 NSCauchy_NSconvergent_iff RS sym, NSCauchy_def,
   1.280 +                 starfunNat_sumr]));
   1.281 +by (cut_inst_tac [("x","M"),("y","N")] hypnat_linear 1);
   1.282 +by (auto_tac (claset(), simpset() addsimps [inf_close_refl]));
   1.283 +by (rtac ((inf_close_minus_iff RS iffD2) RS inf_close_sym) 1);
   1.284 +by (rtac (inf_close_minus_iff RS iffD2) 2);
   1.285 +by (auto_tac (claset() addDs [inf_close_hrabs_zero_cancel],
   1.286 +              simpset() addsimps [sumhr_split_add_minus]));
   1.287 +qed "NSsummable_NSCauchy";
   1.288 +
   1.289 +(*-------------------------------------------------------------------
   1.290 +         Terms of a convergent series tend to zero
   1.291 + -------------------------------------------------------------------*)
   1.292 +Goalw [NSLIMSEQ_def] "NSsummable f ==> f ----NS> #0";
   1.293 +by (auto_tac (claset(), simpset() addsimps [NSsummable_NSCauchy]));
   1.294 +by (dtac bspec 1 THEN Auto_tac);
   1.295 +by (dres_inst_tac [("x","N + 1hn")] bspec 1);
   1.296 +by (auto_tac (claset() addIs [HNatInfinite_add_one,
   1.297 +                              inf_close_hrabs_zero_cancel],
   1.298 +              simpset() addsimps [rename_numerals hypreal_of_real_zero]));
   1.299 +qed "NSsummable_NSLIMSEQ_zero";
   1.300 +
   1.301 +(* Easy to prove stsandard case now *)
   1.302 +Goal "summable f ==> f ----> #0";
   1.303 +by (auto_tac (claset(),
   1.304 +        simpset() addsimps [summable_NSsummable_iff,
   1.305 +                            LIMSEQ_NSLIMSEQ_iff, NSsummable_NSLIMSEQ_zero]));
   1.306 +qed "summable_LIMSEQ_zero";
   1.307 +
   1.308 +(*-------------------------------------------------------------------
   1.309 +                  NS Comparison test
   1.310 + -------------------------------------------------------------------*)
   1.311 +
   1.312 +Goal "[| EX N. ALL n. N <= n --> abs(f n) <= g n; \
   1.313 +\        NSsummable g \
   1.314 +\     |] ==> NSsummable f";
   1.315 +by (auto_tac (claset() addIs [summable_comparison_test],
   1.316 +              simpset() addsimps [summable_NSsummable_iff RS sym]));
   1.317 +qed "NSsummable_comparison_test";
   1.318 +
   1.319 +Goal "[| EX N. ALL n. N <= n --> abs(f n) <= g n; \
   1.320 +\        NSsummable g \
   1.321 +\     |] ==> NSsummable (%k. abs (f k))";
   1.322 +by (rtac NSsummable_comparison_test 1);
   1.323 +by (auto_tac (claset(), simpset() addsimps [abs_idempotent]));
   1.324 +qed "NSsummable_rabs_comparison_test";
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/Hyperreal/HSeries.thy	Sat Dec 30 22:03:47 2000 +0100
     2.3 @@ -0,0 +1,30 @@
     2.4 +(*  Title       : HSeries.thy
     2.5 +    Author      : Jacques D. Fleuriot
     2.6 +    Copyright   : 1998  University of Cambridge
     2.7 +    Description : Finite summation and infinite series
     2.8 +                  for hyperreals
     2.9 +*) 
    2.10 +
    2.11 +HSeries = Series +
    2.12 +
    2.13 +consts 
    2.14 +   sumhr :: "(hypnat * hypnat * (nat=>real)) => hypreal"
    2.15 +
    2.16 +defs
    2.17 +   sumhr_def
    2.18 +   "sumhr p
    2.19 +       == Abs_hypreal(UN X:Rep_hypnat(fst p). 
    2.20 +              UN Y: Rep_hypnat(fst(snd p)).
    2.21 +              hyprel ^^{%n::nat. sumr (X n) (Y n) (snd(snd p))})"
    2.22 +
    2.23 +constdefs
    2.24 +   NSsums  :: [nat=>real,real] => bool     (infixr 80)
    2.25 +   "f NSsums s  == (%n. sumr 0 n f) ----NS> s"
    2.26 +
    2.27 +   NSsummable :: (nat=>real) => bool
    2.28 +   "NSsummable f == (EX s. f NSsums s)"
    2.29 +
    2.30 +   NSsuminf   :: (nat=>real) => real
    2.31 +   "NSsuminf f == (@s. f NSsums s)"
    2.32 +
    2.33 +end
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/HOL/Hyperreal/HyperArith.thy	Sat Dec 30 22:03:47 2000 +0100
     3.3 @@ -0,0 +1,6 @@
     3.4 +theory HyperArith = HyperArith0
     3.5 +files "hypreal_arith.ML":
     3.6 +
     3.7 +setup hypreal_arith_setup
     3.8 +
     3.9 +end
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/HOL/Hyperreal/HyperArith0.ML	Sat Dec 30 22:03:47 2000 +0100
     4.3 @@ -0,0 +1,679 @@
     4.4 +(*  Title:      HOL/Hyperreal/HyperRealArith0.ML
     4.5 +    ID:         $Id$
     4.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4.7 +    Copyright   1999  University of Cambridge
     4.8 +
     4.9 +Assorted facts that need binary literals and the arithmetic decision procedure
    4.10 +
    4.11 +Also, common factor cancellation
    4.12 +*)
    4.13 +
    4.14 +Goal "((x * y = #0) = (x = #0 | y = (#0::hypreal)))";
    4.15 +by Auto_tac;  
    4.16 +by (cut_inst_tac [("x","x"),("y","y")] hypreal_mult_zero_disj 1);
    4.17 +by Auto_tac;  
    4.18 +qed "hypreal_mult_is_0";
    4.19 +AddIffs [hypreal_mult_is_0];
    4.20 +
    4.21 +(** Division and inverse **)
    4.22 +
    4.23 +Goal "#0/x = (#0::hypreal)";
    4.24 +by (simp_tac (simpset() addsimps [hypreal_divide_def]) 1); 
    4.25 +qed "hypreal_0_divide";
    4.26 +Addsimps [hypreal_0_divide];
    4.27 +
    4.28 +Goal "((#0::hypreal) < inverse x) = (#0 < x)";
    4.29 +by (case_tac "x=#0" 1);
    4.30 +by (asm_simp_tac (HOL_ss addsimps [rename_numerals HYPREAL_INVERSE_ZERO]) 1); 
    4.31 +by (auto_tac (claset() addDs [hypreal_inverse_less_0], 
    4.32 +              simpset() addsimps [linorder_neq_iff, 
    4.33 +                                  hypreal_inverse_gt_0]));  
    4.34 +qed "hypreal_0_less_inverse_iff";
    4.35 +Addsimps [hypreal_0_less_inverse_iff];
    4.36 +
    4.37 +Goal "(inverse x < (#0::hypreal)) = (x < #0)";
    4.38 +by (case_tac "x=#0" 1);
    4.39 +by (asm_simp_tac (HOL_ss addsimps [rename_numerals HYPREAL_INVERSE_ZERO]) 1); 
    4.40 +by (auto_tac (claset() addDs [hypreal_inverse_less_0], 
    4.41 +              simpset() addsimps [linorder_neq_iff, 
    4.42 +                                  hypreal_inverse_gt_0]));  
    4.43 +qed "hypreal_inverse_less_0_iff";
    4.44 +Addsimps [hypreal_inverse_less_0_iff];
    4.45 +
    4.46 +Goal "((#0::hypreal) <= inverse x) = (#0 <= x)";
    4.47 +by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1); 
    4.48 +qed "hypreal_0_le_inverse_iff";
    4.49 +Addsimps [hypreal_0_le_inverse_iff];
    4.50 +
    4.51 +Goal "(inverse x <= (#0::hypreal)) = (x <= #0)";
    4.52 +by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1); 
    4.53 +qed "hypreal_inverse_le_0_iff";
    4.54 +Addsimps [hypreal_inverse_le_0_iff];
    4.55 +
    4.56 +Goalw [hypreal_divide_def] "x/(#0::hypreal) = #0";
    4.57 +by (stac (rename_numerals HYPREAL_INVERSE_ZERO) 1); 
    4.58 +by (Simp_tac 1); 
    4.59 +qed "HYPREAL_DIVIDE_ZERO";
    4.60 +
    4.61 +Goal "inverse (x::hypreal) = #1/x";
    4.62 +by (simp_tac (simpset() addsimps [hypreal_divide_def]) 1); 
    4.63 +qed "hypreal_inverse_eq_divide";
    4.64 +
    4.65 +Goal "((#0::hypreal) < x/y) = (#0 < x & #0 < y | x < #0 & y < #0)";
    4.66 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_0_less_mult_iff]) 1);
    4.67 +qed "hypreal_0_less_divide_iff";
    4.68 +Addsimps [inst "x" "number_of ?w" hypreal_0_less_divide_iff];
    4.69 +
    4.70 +Goal "(x/y < (#0::hypreal)) = (#0 < x & y < #0 | x < #0 & #0 < y)";
    4.71 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_less_0_iff]) 1);
    4.72 +qed "hypreal_divide_less_0_iff";
    4.73 +Addsimps [inst "x" "number_of ?w" hypreal_divide_less_0_iff];
    4.74 +
    4.75 +Goal "((#0::hypreal) <= x/y) = ((x <= #0 | #0 <= y) & (#0 <= x | y <= #0))";
    4.76 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_0_le_mult_iff]) 1);
    4.77 +by Auto_tac;  
    4.78 +qed "hypreal_0_le_divide_iff";
    4.79 +Addsimps [inst "x" "number_of ?w" hypreal_0_le_divide_iff];
    4.80 +
    4.81 +Goal "(x/y <= (#0::hypreal)) = ((x <= #0 | y <= #0) & (#0 <= x | #0 <= y))";
    4.82 +by (simp_tac (simpset() addsimps [hypreal_divide_def, 
    4.83 +                                  hypreal_mult_le_0_iff]) 1);
    4.84 +by Auto_tac;  
    4.85 +qed "hypreal_divide_le_0_iff";
    4.86 +Addsimps [inst "x" "number_of ?w" hypreal_divide_le_0_iff];
    4.87 +
    4.88 +Goal "(inverse(x::hypreal) = #0) = (x = #0)";
    4.89 +by (auto_tac (claset(), 
    4.90 +              simpset() addsimps [rename_numerals HYPREAL_INVERSE_ZERO]));  
    4.91 +by (rtac ccontr 1); 
    4.92 +by (blast_tac (claset() addDs [rename_numerals hypreal_inverse_not_zero]) 1); 
    4.93 +qed "hypreal_inverse_zero_iff";
    4.94 +Addsimps [hypreal_inverse_zero_iff];
    4.95 +
    4.96 +Goal "(x/y = #0) = (x=#0 | y=(#0::hypreal))";
    4.97 +by (auto_tac (claset(), simpset() addsimps [hypreal_divide_def]));  
    4.98 +qed "hypreal_divide_eq_0_iff";
    4.99 +Addsimps [hypreal_divide_eq_0_iff];
   4.100 +
   4.101 +Goal "h ~= (#0::hypreal) ==> h/h = #1";
   4.102 +by (asm_simp_tac 
   4.103 +    (simpset() addsimps [hypreal_divide_def, hypreal_mult_inverse_left]) 1);
   4.104 +qed "hypreal_divide_self_eq"; 
   4.105 +Addsimps [hypreal_divide_self_eq];
   4.106 +
   4.107 +
   4.108 +(**** Factor cancellation theorems for "hypreal" ****)
   4.109 +
   4.110 +(** Cancellation laws for k*m < k*n and m*k < n*k, also for <= and =,
   4.111 +    but not (yet?) for k*m < n*k. **)
   4.112 +
   4.113 +bind_thm ("hypreal_mult_minus_right", hypreal_minus_mult_eq2 RS sym);
   4.114 +
   4.115 +Goal "(-y < -x) = ((x::hypreal) < y)";
   4.116 +by (arith_tac 1);
   4.117 +qed "hypreal_minus_less_minus";
   4.118 +Addsimps [hypreal_minus_less_minus];
   4.119 +
   4.120 +Goal "[| i<j;  k < (0::hypreal) |] ==> j*k < i*k";
   4.121 +by (rtac (hypreal_minus_less_minus RS iffD1) 1);
   4.122 +by (auto_tac (claset(), 
   4.123 +              simpset() delsimps [hypreal_minus_mult_eq2 RS sym]
   4.124 +                        addsimps [hypreal_minus_mult_eq2,
   4.125 +                                  hypreal_mult_less_mono1])); 
   4.126 +qed "hypreal_mult_less_mono1_neg";
   4.127 +
   4.128 +Goal "[| i<j;  k < (0::hypreal) |] ==> k*j < k*i";
   4.129 +by (rtac (hypreal_minus_less_minus RS iffD1) 1);
   4.130 +by (auto_tac (claset(), 
   4.131 +              simpset() delsimps [hypreal_minus_mult_eq1 RS sym]
   4.132 +                        addsimps [hypreal_minus_mult_eq1,
   4.133 +                                  hypreal_mult_less_mono2]));
   4.134 +qed "hypreal_mult_less_mono2_neg";
   4.135 +
   4.136 +Goal "[| i <= j;  (0::hypreal) <= k |] ==> i*k <= j*k";
   4.137 +by (auto_tac (claset(), 
   4.138 +              simpset() addsimps [order_le_less, hypreal_mult_less_mono1]));  
   4.139 +qed "hypreal_mult_le_mono1";
   4.140 +
   4.141 +Goal "[| i <= j;  k <= (0::hypreal) |] ==> j*k <= i*k";
   4.142 +by (auto_tac (claset(), 
   4.143 +          simpset() addsimps [order_le_less, hypreal_mult_less_mono1_neg]));  
   4.144 +qed "hypreal_mult_le_mono1_neg";
   4.145 +
   4.146 +Goal "[| i <= j;  (0::hypreal) <= k |] ==> k*i <= k*j";
   4.147 +by (dtac hypreal_mult_le_mono1 1);
   4.148 +by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [hypreal_mult_commute])));
   4.149 +qed "hypreal_mult_le_mono2";
   4.150 +
   4.151 +Goal "[| i <= j;  k <= (0::hypreal) |] ==> k*j <= k*i";
   4.152 +by (dtac hypreal_mult_le_mono1_neg 1);
   4.153 +by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [hypreal_mult_commute])));
   4.154 +qed "hypreal_mult_le_mono2_neg";
   4.155 +
   4.156 +Goal "[| u <= v;  x <= y;  0 <= v;  (0::hypreal) <= x |] ==> u * x <= v * y";
   4.157 +by (etac (hypreal_mult_le_mono1 RS order_trans) 1);
   4.158 +by (assume_tac 1);
   4.159 +by (etac hypreal_mult_le_mono2 1);
   4.160 +by (assume_tac 1);
   4.161 +qed "hypreal_mult_le_mono";
   4.162 +
   4.163 +Goal "(m*k < n*k) = (((#0::hypreal) < k & m<n) | (k < #0 & n<m))";
   4.164 +by (case_tac "k = (0::hypreal)" 1);
   4.165 +by (auto_tac (claset(), 
   4.166 +          simpset() addsimps [linorder_neq_iff, 
   4.167 +                      hypreal_mult_less_mono1, hypreal_mult_less_mono1_neg]));  
   4.168 +by (auto_tac (claset(), 
   4.169 +              simpset() addsimps [linorder_not_less,
   4.170 +				  inst "y1" "m*k" (linorder_not_le RS sym),
   4.171 +                                  inst "y1" "m" (linorder_not_le RS sym)]));
   4.172 +by (TRYALL (etac notE));
   4.173 +by (auto_tac (claset(), 
   4.174 +              simpset() addsimps [order_less_imp_le, hypreal_mult_le_mono1,
   4.175 +                                  hypreal_mult_le_mono1_neg]));  
   4.176 +qed "hypreal_mult_less_cancel2";
   4.177 +
   4.178 +Goal "(m*k <= n*k) = (((#0::hypreal) < k --> m<=n) & (k < #0 --> n<=m))";
   4.179 +by (simp_tac (simpset() addsimps [linorder_not_less RS sym, 
   4.180 +                                  hypreal_mult_less_cancel2]) 1);
   4.181 +qed "hypreal_mult_le_cancel2";
   4.182 +
   4.183 +Goal "(k*m < k*n) = (((#0::hypreal) < k & m<n) | (k < #0 & n<m))";
   4.184 +by (simp_tac (simpset() addsimps [inst "z" "k" hypreal_mult_commute, 
   4.185 +                                  hypreal_mult_less_cancel2]) 1);
   4.186 +qed "hypreal_mult_less_cancel1";
   4.187 +
   4.188 +Goal "!!k::hypreal. (k*m <= k*n) = ((#0 < k --> m<=n) & (k < #0 --> n<=m))";
   4.189 +by (simp_tac (simpset() addsimps [linorder_not_less RS sym, 
   4.190 +                                  hypreal_mult_less_cancel1]) 1);
   4.191 +qed "hypreal_mult_le_cancel1";
   4.192 +
   4.193 +Goal "!!k::hypreal. (k*m = k*n) = (k = #0 | m=n)";
   4.194 +by (case_tac "k=0" 1);
   4.195 +by (auto_tac (claset(), simpset() addsimps [hypreal_mult_left_cancel]));  
   4.196 +qed "hypreal_mult_eq_cancel1";
   4.197 +
   4.198 +Goal "!!k::hypreal. (m*k = n*k) = (k = #0 | m=n)";
   4.199 +by (case_tac "k=0" 1);
   4.200 +by (auto_tac (claset(), simpset() addsimps [hypreal_mult_right_cancel]));  
   4.201 +qed "hypreal_mult_eq_cancel2";
   4.202 +
   4.203 +Goal "!!k::hypreal. k~=#0 ==> (k*m) / (k*n) = (m/n)";
   4.204 +by (asm_simp_tac
   4.205 +    (simpset() addsimps [hypreal_divide_def, hypreal_inverse_distrib]) 1); 
   4.206 +by (subgoal_tac "k * m * (inverse k * inverse n) = \
   4.207 +\                (k * inverse k) * (m * inverse n)" 1);
   4.208 +by (asm_full_simp_tac (simpset() addsimps []) 1); 
   4.209 +by (asm_full_simp_tac (HOL_ss addsimps hypreal_mult_ac) 1); 
   4.210 +qed "hypreal_mult_div_cancel1";
   4.211 +
   4.212 +(*For ExtractCommonTerm*)
   4.213 +Goal "(k*m) / (k*n) = (if k = (#0::hypreal) then #0 else m/n)";
   4.214 +by (simp_tac (simpset() addsimps [hypreal_mult_div_cancel1]) 1); 
   4.215 +qed "hypreal_mult_div_cancel_disj";
   4.216 +
   4.217 +
   4.218 +local
   4.219 +  open Hyperreal_Numeral_Simprocs
   4.220 +in
   4.221 +
   4.222 +val rel_hypreal_number_of = [eq_hypreal_number_of, less_hypreal_number_of, 
   4.223 +                          le_hypreal_number_of_eq_not_less];
   4.224 +
   4.225 +structure CancelNumeralFactorCommon =
   4.226 +  struct
   4.227 +  val mk_coeff		= mk_coeff
   4.228 +  val dest_coeff	= dest_coeff 1
   4.229 +  val trans_tac         = trans_tac
   4.230 +  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_plus_1s))
   4.231 +     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@hypreal_mult_minus_simps))
   4.232 +     THEN ALLGOALS
   4.233 +	  (simp_tac 
   4.234 +	   (HOL_ss addsimps [eq_hypreal_number_of, mult_hypreal_number_of, 
   4.235 +                             hypreal_mult_number_of_left]@
   4.236 +           hypreal_minus_from_mult_simps @ hypreal_mult_ac))
   4.237 +  val numeral_simp_tac	= 
   4.238 +         ALLGOALS (simp_tac (HOL_ss addsimps rel_hypreal_number_of@bin_simps))
   4.239 +  val simplify_meta_eq  = simplify_meta_eq
   4.240 +  end
   4.241 +
   4.242 +structure DivCancelNumeralFactor = CancelNumeralFactorFun
   4.243 + (open CancelNumeralFactorCommon
   4.244 +  val prove_conv = prove_conv "hyprealdiv_cancel_numeral_factor"
   4.245 +  val mk_bal   = HOLogic.mk_binop "HOL.divide"
   4.246 +  val dest_bal = HOLogic.dest_bin "HOL.divide" hyprealT
   4.247 +  val cancel = hypreal_mult_div_cancel1 RS trans
   4.248 +  val neg_exchanges = false
   4.249 +)
   4.250 +
   4.251 +structure EqCancelNumeralFactor = CancelNumeralFactorFun
   4.252 + (open CancelNumeralFactorCommon
   4.253 +  val prove_conv = prove_conv "hyprealeq_cancel_numeral_factor"
   4.254 +  val mk_bal   = HOLogic.mk_eq
   4.255 +  val dest_bal = HOLogic.dest_bin "op =" hyprealT
   4.256 +  val cancel = hypreal_mult_eq_cancel1 RS trans
   4.257 +  val neg_exchanges = false
   4.258 +)
   4.259 +
   4.260 +structure LessCancelNumeralFactor = CancelNumeralFactorFun
   4.261 + (open CancelNumeralFactorCommon
   4.262 +  val prove_conv = prove_conv "hyprealless_cancel_numeral_factor"
   4.263 +  val mk_bal   = HOLogic.mk_binrel "op <"
   4.264 +  val dest_bal = HOLogic.dest_bin "op <" hyprealT
   4.265 +  val cancel = hypreal_mult_less_cancel1 RS trans
   4.266 +  val neg_exchanges = true
   4.267 +)
   4.268 +
   4.269 +structure LeCancelNumeralFactor = CancelNumeralFactorFun
   4.270 + (open CancelNumeralFactorCommon
   4.271 +  val prove_conv = prove_conv "hyprealle_cancel_numeral_factor"
   4.272 +  val mk_bal   = HOLogic.mk_binrel "op <="
   4.273 +  val dest_bal = HOLogic.dest_bin "op <=" hyprealT
   4.274 +  val cancel = hypreal_mult_le_cancel1 RS trans
   4.275 +  val neg_exchanges = true
   4.276 +)
   4.277 +
   4.278 +val hypreal_cancel_numeral_factors_relations = 
   4.279 +  map prep_simproc
   4.280 +   [("hyprealeq_cancel_numeral_factor",
   4.281 +     prep_pats ["(l::hypreal) * m = n", "(l::hypreal) = m * n"], 
   4.282 +     EqCancelNumeralFactor.proc),
   4.283 +    ("hyprealless_cancel_numeral_factor", 
   4.284 +     prep_pats ["(l::hypreal) * m < n", "(l::hypreal) < m * n"], 
   4.285 +     LessCancelNumeralFactor.proc),
   4.286 +    ("hyprealle_cancel_numeral_factor", 
   4.287 +     prep_pats ["(l::hypreal) * m <= n", "(l::hypreal) <= m * n"], 
   4.288 +     LeCancelNumeralFactor.proc)];
   4.289 +
   4.290 +val hypreal_cancel_numeral_factors_divide = prep_simproc
   4.291 +	("hyprealdiv_cancel_numeral_factor", 
   4.292 +	 prep_pats ["((l::hypreal) * m) / n", "(l::hypreal) / (m * n)"], 
   4.293 +	 DivCancelNumeralFactor.proc);
   4.294 +
   4.295 +val hypreal_cancel_numeral_factors = 
   4.296 +    hypreal_cancel_numeral_factors_relations @ 
   4.297 +    [hypreal_cancel_numeral_factors_divide];
   4.298 +
   4.299 +end;
   4.300 +
   4.301 +Addsimprocs hypreal_cancel_numeral_factors;
   4.302 +
   4.303 +
   4.304 +(*examples:
   4.305 +print_depth 22;
   4.306 +set timing;
   4.307 +set trace_simp;
   4.308 +fun test s = (Goal s; by (Simp_tac 1)); 
   4.309 +
   4.310 +test "#0 <= (y::hypreal) * #-2";
   4.311 +test "#9*x = #12 * (y::hypreal)";
   4.312 +test "(#9*x) / (#12 * (y::hypreal)) = z";
   4.313 +test "#9*x < #12 * (y::hypreal)";
   4.314 +test "#9*x <= #12 * (y::hypreal)";
   4.315 +
   4.316 +test "#-99*x = #132 * (y::hypreal)";
   4.317 +test "(#-99*x) / (#132 * (y::hypreal)) = z";
   4.318 +test "#-99*x < #132 * (y::hypreal)";
   4.319 +test "#-99*x <= #132 * (y::hypreal)";
   4.320 +
   4.321 +test "#999*x = #-396 * (y::hypreal)";
   4.322 +test "(#999*x) / (#-396 * (y::hypreal)) = z";
   4.323 +test "#999*x < #-396 * (y::hypreal)";
   4.324 +test "#999*x <= #-396 * (y::hypreal)";
   4.325 +
   4.326 +test "#-99*x = #-81 * (y::hypreal)";
   4.327 +test "(#-99*x) / (#-81 * (y::hypreal)) = z";
   4.328 +test "#-99*x <= #-81 * (y::hypreal)";
   4.329 +test "#-99*x < #-81 * (y::hypreal)";
   4.330 +
   4.331 +test "#-2 * x = #-1 * (y::hypreal)";
   4.332 +test "#-2 * x = -(y::hypreal)";
   4.333 +test "(#-2 * x) / (#-1 * (y::hypreal)) = z";
   4.334 +test "#-2 * x < -(y::hypreal)";
   4.335 +test "#-2 * x <= #-1 * (y::hypreal)";
   4.336 +test "-x < #-23 * (y::hypreal)";
   4.337 +test "-x <= #-23 * (y::hypreal)";
   4.338 +*)
   4.339 +
   4.340 +
   4.341 +(** Declarations for ExtractCommonTerm **)
   4.342 +
   4.343 +local
   4.344 +  open Hyperreal_Numeral_Simprocs
   4.345 +in
   4.346 +
   4.347 +structure CancelFactorCommon =
   4.348 +  struct
   4.349 +  val mk_sum    	= long_mk_prod
   4.350 +  val dest_sum		= dest_prod
   4.351 +  val mk_coeff		= mk_coeff
   4.352 +  val dest_coeff	= dest_coeff
   4.353 +  val find_first	= find_first []
   4.354 +  val trans_tac         = trans_tac
   4.355 +  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@hypreal_mult_ac))
   4.356 +  end;
   4.357 +
   4.358 +structure EqCancelFactor = ExtractCommonTermFun
   4.359 + (open CancelFactorCommon
   4.360 +  val prove_conv = prove_conv "hypreal_eq_cancel_factor"
   4.361 +  val mk_bal   = HOLogic.mk_eq
   4.362 +  val dest_bal = HOLogic.dest_bin "op =" hyprealT
   4.363 +  val simplify_meta_eq  = cancel_simplify_meta_eq hypreal_mult_eq_cancel1
   4.364 +);
   4.365 +
   4.366 +
   4.367 +structure DivideCancelFactor = ExtractCommonTermFun
   4.368 + (open CancelFactorCommon
   4.369 +  val prove_conv = prove_conv "hypreal_divide_cancel_factor"
   4.370 +  val mk_bal   = HOLogic.mk_binop "HOL.divide"
   4.371 +  val dest_bal = HOLogic.dest_bin "HOL.divide" hyprealT
   4.372 +  val simplify_meta_eq  = cancel_simplify_meta_eq hypreal_mult_div_cancel_disj
   4.373 +);
   4.374 +
   4.375 +val hypreal_cancel_factor = 
   4.376 +  map prep_simproc
   4.377 +   [("hypreal_eq_cancel_factor",
   4.378 +     prep_pats ["(l::hypreal) * m = n", "(l::hypreal) = m * n"], 
   4.379 +     EqCancelFactor.proc),
   4.380 +    ("hypreal_divide_cancel_factor", 
   4.381 +     prep_pats ["((l::hypreal) * m) / n", "(l::hypreal) / (m * n)"], 
   4.382 +     DivideCancelFactor.proc)];
   4.383 +
   4.384 +end;
   4.385 +
   4.386 +Addsimprocs hypreal_cancel_factor;
   4.387 +
   4.388 +
   4.389 +(*examples:
   4.390 +print_depth 22;
   4.391 +set timing;
   4.392 +set trace_simp;
   4.393 +fun test s = (Goal s; by (Asm_simp_tac 1)); 
   4.394 +
   4.395 +test "x*k = k*(y::hypreal)";
   4.396 +test "k = k*(y::hypreal)"; 
   4.397 +test "a*(b*c) = (b::hypreal)";
   4.398 +test "a*(b*c) = d*(b::hypreal)*(x*a)";
   4.399 +
   4.400 +
   4.401 +test "(x*k) / (k*(y::hypreal)) = (uu::hypreal)";
   4.402 +test "(k) / (k*(y::hypreal)) = (uu::hypreal)"; 
   4.403 +test "(a*(b*c)) / ((b::hypreal)) = (uu::hypreal)";
   4.404 +test "(a*(b*c)) / (d*(b::hypreal)*(x*a)) = (uu::hypreal)";
   4.405 +
   4.406 +(*FIXME: what do we do about this?*)
   4.407 +test "a*(b*c)/(y*z) = d*(b::hypreal)*(x*a)/z";
   4.408 +*)
   4.409 +
   4.410 +
   4.411 +(*** Simplification of inequalities involving literal divisors ***)
   4.412 +
   4.413 +Goal "#0<z ==> ((x::hypreal) <= y/z) = (x*z <= y)";
   4.414 +by (subgoal_tac "(x*z <= y) = (x*z <= (y/z)*z)" 1);
   4.415 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.416 +by (etac ssubst 1);
   4.417 +by (stac hypreal_mult_le_cancel2 1); 
   4.418 +by (Asm_simp_tac 1); 
   4.419 +qed "pos_hypreal_le_divide_eq";
   4.420 +Addsimps [inst "z" "number_of ?w" pos_hypreal_le_divide_eq];
   4.421 +
   4.422 +Goal "z<#0 ==> ((x::hypreal) <= y/z) = (y <= x*z)";
   4.423 +by (subgoal_tac "(y <= x*z) = ((y/z)*z <= x*z)" 1);
   4.424 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.425 +by (etac ssubst 1);
   4.426 +by (stac hypreal_mult_le_cancel2 1); 
   4.427 +by (Asm_simp_tac 1); 
   4.428 +qed "neg_hypreal_le_divide_eq";
   4.429 +Addsimps [inst "z" "number_of ?w" neg_hypreal_le_divide_eq];
   4.430 +
   4.431 +Goal "#0<z ==> (y/z <= (x::hypreal)) = (y <= x*z)";
   4.432 +by (subgoal_tac "(y <= x*z) = ((y/z)*z <= x*z)" 1);
   4.433 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.434 +by (etac ssubst 1);
   4.435 +by (stac hypreal_mult_le_cancel2 1); 
   4.436 +by (Asm_simp_tac 1); 
   4.437 +qed "pos_hypreal_divide_le_eq";
   4.438 +Addsimps [inst "z" "number_of ?w" pos_hypreal_divide_le_eq];
   4.439 +
   4.440 +Goal "z<#0 ==> (y/z <= (x::hypreal)) = (x*z <= y)";
   4.441 +by (subgoal_tac "(x*z <= y) = (x*z <= (y/z)*z)" 1);
   4.442 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.443 +by (etac ssubst 1);
   4.444 +by (stac hypreal_mult_le_cancel2 1); 
   4.445 +by (Asm_simp_tac 1); 
   4.446 +qed "neg_hypreal_divide_le_eq";
   4.447 +Addsimps [inst "z" "number_of ?w" neg_hypreal_divide_le_eq];
   4.448 +
   4.449 +Goal "#0<z ==> ((x::hypreal) < y/z) = (x*z < y)";
   4.450 +by (subgoal_tac "(x*z < y) = (x*z < (y/z)*z)" 1);
   4.451 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.452 +by (etac ssubst 1);
   4.453 +by (stac hypreal_mult_less_cancel2 1); 
   4.454 +by (Asm_simp_tac 1); 
   4.455 +qed "pos_hypreal_less_divide_eq";
   4.456 +Addsimps [inst "z" "number_of ?w" pos_hypreal_less_divide_eq];
   4.457 +
   4.458 +Goal "z<#0 ==> ((x::hypreal) < y/z) = (y < x*z)";
   4.459 +by (subgoal_tac "(y < x*z) = ((y/z)*z < x*z)" 1);
   4.460 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.461 +by (etac ssubst 1);
   4.462 +by (stac hypreal_mult_less_cancel2 1); 
   4.463 +by (Asm_simp_tac 1); 
   4.464 +qed "neg_hypreal_less_divide_eq";
   4.465 +Addsimps [inst "z" "number_of ?w" neg_hypreal_less_divide_eq];
   4.466 +
   4.467 +Goal "#0<z ==> (y/z < (x::hypreal)) = (y < x*z)";
   4.468 +by (subgoal_tac "(y < x*z) = ((y/z)*z < x*z)" 1);
   4.469 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.470 +by (etac ssubst 1);
   4.471 +by (stac hypreal_mult_less_cancel2 1); 
   4.472 +by (Asm_simp_tac 1); 
   4.473 +qed "pos_hypreal_divide_less_eq";
   4.474 +Addsimps [inst "z" "number_of ?w" pos_hypreal_divide_less_eq];
   4.475 +
   4.476 +Goal "z<#0 ==> (y/z < (x::hypreal)) = (x*z < y)";
   4.477 +by (subgoal_tac "(x*z < y) = (x*z < (y/z)*z)" 1);
   4.478 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.479 +by (etac ssubst 1);
   4.480 +by (stac hypreal_mult_less_cancel2 1); 
   4.481 +by (Asm_simp_tac 1); 
   4.482 +qed "neg_hypreal_divide_less_eq";
   4.483 +Addsimps [inst "z" "number_of ?w" neg_hypreal_divide_less_eq];
   4.484 +
   4.485 +Goal "z~=#0 ==> ((x::hypreal) = y/z) = (x*z = y)";
   4.486 +by (subgoal_tac "(x*z = y) = (x*z = (y/z)*z)" 1);
   4.487 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.488 +by (etac ssubst 1);
   4.489 +by (stac hypreal_mult_eq_cancel2 1); 
   4.490 +by (Asm_simp_tac 1); 
   4.491 +qed "hypreal_eq_divide_eq";
   4.492 +Addsimps [inst "z" "number_of ?w" hypreal_eq_divide_eq];
   4.493 +
   4.494 +Goal "z~=#0 ==> (y/z = (x::hypreal)) = (y = x*z)";
   4.495 +by (subgoal_tac "(y = x*z) = ((y/z)*z = x*z)" 1);
   4.496 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 2); 
   4.497 +by (etac ssubst 1);
   4.498 +by (stac hypreal_mult_eq_cancel2 1); 
   4.499 +by (Asm_simp_tac 1); 
   4.500 +qed "hypreal_divide_eq_eq";
   4.501 +Addsimps [inst "z" "number_of ?w" hypreal_divide_eq_eq];
   4.502 +
   4.503 +Goal "(m/k = n/k) = (k = #0 | m = (n::hypreal))";
   4.504 +by (case_tac "k=#0" 1);
   4.505 +by (asm_simp_tac (simpset() addsimps [HYPREAL_DIVIDE_ZERO]) 1); 
   4.506 +by (asm_simp_tac (simpset() addsimps [hypreal_divide_eq_eq, hypreal_eq_divide_eq, 
   4.507 +                                      hypreal_mult_eq_cancel2]) 1); 
   4.508 +qed "hypreal_divide_eq_cancel2";
   4.509 +
   4.510 +Goal "(k/m = k/n) = (k = #0 | m = (n::hypreal))";
   4.511 +by (case_tac "m=#0 | n = #0" 1);
   4.512 +by (auto_tac (claset(), 
   4.513 +              simpset() addsimps [HYPREAL_DIVIDE_ZERO, hypreal_divide_eq_eq, 
   4.514 +                                  hypreal_eq_divide_eq, hypreal_mult_eq_cancel1]));  
   4.515 +qed "hypreal_divide_eq_cancel1";
   4.516 +
   4.517 +Goal "[| #0 < r; #0 < x|] ==> (inverse x < inverse (r::hypreal)) = (r < x)";
   4.518 +by (auto_tac (claset() addIs [hypreal_inverse_less_swap], simpset()));
   4.519 +by (res_inst_tac [("t","r")] (hypreal_inverse_inverse RS subst) 1);
   4.520 +by (res_inst_tac [("t","x")] (hypreal_inverse_inverse RS subst) 1);
   4.521 +by (auto_tac (claset() addIs [hypreal_inverse_less_swap],
   4.522 +	      simpset() delsimps [hypreal_inverse_inverse]
   4.523 +			addsimps [hypreal_inverse_gt_zero]));
   4.524 +qed "hypreal_inverse_less_iff";
   4.525 +
   4.526 +Goal "[| #0 < r; #0 < x|] ==> (inverse x <= inverse r) = (r <= (x::hypreal))";
   4.527 +by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym, 
   4.528 +                                      hypreal_inverse_less_iff]) 1); 
   4.529 +qed "hypreal_inverse_le_iff";
   4.530 +
   4.531 +(** Division by 1, -1 **)
   4.532 +
   4.533 +Goal "(x::hypreal)/#1 = x";
   4.534 +by (simp_tac (simpset() addsimps [hypreal_divide_def]) 1); 
   4.535 +qed "hypreal_divide_1";
   4.536 +Addsimps [hypreal_divide_1];
   4.537 +
   4.538 +Goal "x/#-1 = -(x::hypreal)";
   4.539 +by (Simp_tac 1); 
   4.540 +qed "hypreal_divide_minus1";
   4.541 +Addsimps [hypreal_divide_minus1];
   4.542 +
   4.543 +Goal "#-1/(x::hypreal) = - (#1/x)";
   4.544 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_minus_inverse]) 1); 
   4.545 +qed "hypreal_minus1_divide";
   4.546 +Addsimps [hypreal_minus1_divide];
   4.547 +
   4.548 +Goal "[| (#0::hypreal) < d1; #0 < d2 |] ==> EX e. #0 < e & e < d1 & e < d2";
   4.549 +by (res_inst_tac [("x","(min d1 d2)/#2")] exI 1); 
   4.550 +by (asm_simp_tac (simpset() addsimps [min_def]) 1); 
   4.551 +qed "hypreal_lbound_gt_zero";
   4.552 +
   4.553 +
   4.554 +(*** General rewrites to improve automation, like those for type "int" ***)
   4.555 +
   4.556 +(** The next several equations can make the simplifier loop! **)
   4.557 +
   4.558 +Goal "(x < - y) = (y < - (x::hypreal))";
   4.559 +by Auto_tac;  
   4.560 +qed "hypreal_less_minus"; 
   4.561 +
   4.562 +Goal "(- x < y) = (- y < (x::hypreal))";
   4.563 +by Auto_tac;  
   4.564 +qed "hypreal_minus_less"; 
   4.565 +
   4.566 +Goal "(x <= - y) = (y <= - (x::hypreal))";
   4.567 +by Auto_tac;  
   4.568 +qed "hypreal_le_minus"; 
   4.569 +
   4.570 +Goal "(- x <= y) = (- y <= (x::hypreal))";
   4.571 +by Auto_tac;  
   4.572 +qed "hypreal_minus_le"; 
   4.573 +
   4.574 +Goal "(x = - y) = (y = - (x::hypreal))";
   4.575 +by Auto_tac;
   4.576 +qed "hypreal_equation_minus";
   4.577 +
   4.578 +Goal "(- x = y) = (- (y::hypreal) = x)";
   4.579 +by Auto_tac;
   4.580 +qed "hypreal_minus_equation";
   4.581 +
   4.582 +Goal "(x + - a = (#0::hypreal)) = (x=a)";
   4.583 +by (arith_tac 1);
   4.584 +qed "hypreal_add_minus_iff";
   4.585 +Addsimps [hypreal_add_minus_iff];
   4.586 +
   4.587 +Goal "(-b = -a) = (b = (a::hypreal))";
   4.588 +by (arith_tac 1);
   4.589 +qed "hypreal_minus_eq_cancel";
   4.590 +Addsimps [hypreal_minus_eq_cancel];
   4.591 +
   4.592 +Goal "(-s <= -r) = ((r::hypreal) <= s)";
   4.593 +by (stac hypreal_minus_le 1); 
   4.594 +by (Simp_tac 1); 
   4.595 +qed "hypreal_le_minus_iff";
   4.596 +Addsimps [hypreal_le_minus_iff];          
   4.597 +
   4.598 +
   4.599 +(*Distributive laws for literals*)
   4.600 +Addsimps (map (inst "w" "number_of ?v")
   4.601 +	  [hypreal_add_mult_distrib, hypreal_add_mult_distrib2,
   4.602 +	   hypreal_diff_mult_distrib, hypreal_diff_mult_distrib2]);
   4.603 +
   4.604 +Addsimps (map (inst "x" "number_of ?v") 
   4.605 +	  [hypreal_less_minus, hypreal_le_minus, hypreal_equation_minus]);
   4.606 +Addsimps (map (inst "y" "number_of ?v") 
   4.607 +	  [hypreal_minus_less, hypreal_minus_le, hypreal_minus_equation]);
   4.608 +
   4.609 +
   4.610 +(*** Simprules combining x+y and #0 ***)
   4.611 +
   4.612 +Goal "(x+y = (#0::hypreal)) = (y = -x)";
   4.613 +by Auto_tac;  
   4.614 +qed "hypreal_add_eq_0_iff";
   4.615 +AddIffs [hypreal_add_eq_0_iff];
   4.616 +
   4.617 +Goal "(x+y < (#0::hypreal)) = (y < -x)";
   4.618 +by Auto_tac;  
   4.619 +qed "hypreal_add_less_0_iff";
   4.620 +AddIffs [hypreal_add_less_0_iff];
   4.621 +
   4.622 +Goal "((#0::hypreal) < x+y) = (-x < y)";
   4.623 +by Auto_tac;  
   4.624 +qed "hypreal_0_less_add_iff";
   4.625 +AddIffs [hypreal_0_less_add_iff];
   4.626 +
   4.627 +Goal "(x+y <= (#0::hypreal)) = (y <= -x)";
   4.628 +by Auto_tac;  
   4.629 +qed "hypreal_add_le_0_iff";
   4.630 +AddIffs [hypreal_add_le_0_iff];
   4.631 +
   4.632 +Goal "((#0::hypreal) <= x+y) = (-x <= y)";
   4.633 +by Auto_tac;  
   4.634 +qed "hypreal_0_le_add_iff";
   4.635 +AddIffs [hypreal_0_le_add_iff];
   4.636 +
   4.637 +
   4.638 +(** Simprules combining x-y and #0; see also hypreal_less_iff_diff_less_0 etc
   4.639 +    in HyperBin
   4.640 +**)
   4.641 +
   4.642 +Goal "((#0::hypreal) < x-y) = (y < x)";
   4.643 +by Auto_tac;  
   4.644 +qed "hypreal_0_less_diff_iff";
   4.645 +AddIffs [hypreal_0_less_diff_iff];
   4.646 +
   4.647 +Goal "((#0::hypreal) <= x-y) = (y <= x)";
   4.648 +by Auto_tac;  
   4.649 +qed "hypreal_0_le_diff_iff";
   4.650 +AddIffs [hypreal_0_le_diff_iff];
   4.651 +
   4.652 +(*
   4.653 +FIXME: we should have this, as for type int, but many proofs would break.
   4.654 +It replaces x+-y by x-y.
   4.655 +Addsimps [symmetric hypreal_diff_def];
   4.656 +*)
   4.657 +
   4.658 +Goal "-(x-y) = y - (x::hypreal)";
   4.659 +by (arith_tac 1);
   4.660 +qed "hypreal_minus_diff_eq";
   4.661 +Addsimps [hypreal_minus_diff_eq];
   4.662 +
   4.663 +
   4.664 +(*** Density of the Hyperreals ***)
   4.665 +
   4.666 +Goal "x < y ==> x < (x+y) / (#2::hypreal)";
   4.667 +by Auto_tac;
   4.668 +qed "hypreal_less_half_sum";
   4.669 +
   4.670 +Goal "x < y ==> (x+y)/(#2::hypreal) < y";
   4.671 +by Auto_tac;
   4.672 +qed "hypreal_gt_half_sum";
   4.673 +
   4.674 +Goal "x < y ==> EX r::hypreal. x < r & r < y";
   4.675 +by (blast_tac (claset() addSIs [hypreal_less_half_sum, hypreal_gt_half_sum]) 1);
   4.676 +qed "hypreal_dense";
   4.677 +
   4.678 +
   4.679 +(*Replaces "inverse #nn" by #1/#nn *)
   4.680 +Addsimps [inst "x" "number_of ?w" hypreal_inverse_eq_divide];
   4.681 +
   4.682 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/HOL/Hyperreal/HyperArith0.thy	Sat Dec 30 22:03:47 2000 +0100
     5.3 @@ -0,0 +1,6 @@
     5.4 +theory HyperArith0 = HyperBin
     5.5 +files "hypreal_arith0.ML":
     5.6 +
     5.7 +setup hypreal_arith_setup
     5.8 +
     5.9 +end
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/HOL/Hyperreal/HyperBin.ML	Sat Dec 30 22:03:47 2000 +0100
     6.3 @@ -0,0 +1,626 @@
     6.4 +(*  Title:      HOL/Hyperreal/HyperBin.ML
     6.5 +    ID:         $Id$
     6.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     6.7 +    Copyright   2000  University of Cambridge
     6.8 +
     6.9 +Binary arithmetic for the hypreals (integer literals only).
    6.10 +*)
    6.11 +
    6.12 +(** hypreal_of_real (coercion from int to real) **)
    6.13 +
    6.14 +Goal "hypreal_of_real (number_of w) = number_of w";
    6.15 +by (simp_tac (simpset() addsimps [hypreal_number_of_def]) 1);
    6.16 +qed "hypreal_number_of";
    6.17 +Addsimps [hypreal_number_of];
    6.18 +
    6.19 +Goalw [hypreal_number_of_def] "(0::hypreal) = #0";
    6.20 +by (simp_tac (simpset() addsimps [hypreal_of_real_zero RS sym]) 1);
    6.21 +qed "zero_eq_numeral_0";
    6.22 +
    6.23 +Goalw [hypreal_number_of_def] "1hr = #1";
    6.24 +by (simp_tac (simpset() addsimps [hypreal_of_real_one RS sym]) 1);
    6.25 +qed "one_eq_numeral_1";
    6.26 +
    6.27 +(** Addition **)
    6.28 +
    6.29 +Goal "(number_of v :: hypreal) + number_of v' = number_of (bin_add v v')";
    6.30 +by (simp_tac
    6.31 +    (HOL_ss addsimps [hypreal_number_of_def, 
    6.32 +                      hypreal_of_real_add RS sym, add_real_number_of]) 1);
    6.33 +qed "add_hypreal_number_of";
    6.34 +Addsimps [add_hypreal_number_of];
    6.35 +
    6.36 +
    6.37 +(** Subtraction **)
    6.38 +
    6.39 +Goalw [hypreal_number_of_def]
    6.40 +     "- (number_of w :: hypreal) = number_of (bin_minus w)";
    6.41 +by (simp_tac
    6.42 +    (HOL_ss addsimps [minus_real_number_of, hypreal_of_real_minus RS sym]) 1);
    6.43 +qed "minus_hypreal_number_of";
    6.44 +Addsimps [minus_hypreal_number_of];
    6.45 +
    6.46 +Goalw [hypreal_number_of_def, hypreal_diff_def]
    6.47 +     "(number_of v :: hypreal) - number_of w = \
    6.48 +\     number_of (bin_add v (bin_minus w))";
    6.49 +by (Simp_tac 1); 
    6.50 +qed "diff_hypreal_number_of";
    6.51 +Addsimps [diff_hypreal_number_of];
    6.52 +
    6.53 +
    6.54 +(** Multiplication **)
    6.55 +
    6.56 +Goal "(number_of v :: hypreal) * number_of v' = number_of (bin_mult v v')";
    6.57 +by (simp_tac
    6.58 +    (HOL_ss addsimps [hypreal_number_of_def, 
    6.59 +	              hypreal_of_real_mult RS sym, mult_real_number_of]) 1);
    6.60 +qed "mult_hypreal_number_of";
    6.61 +Addsimps [mult_hypreal_number_of];
    6.62 +
    6.63 +Goal "(#2::hypreal) = #1 + #1";
    6.64 +by (Simp_tac 1);
    6.65 +val lemma = result();
    6.66 +
    6.67 +(*For specialist use: NOT as default simprules*)
    6.68 +Goal "#2 * z = (z+z::hypreal)";
    6.69 +by (simp_tac (simpset ()
    6.70 +	      addsimps [lemma, hypreal_add_mult_distrib,
    6.71 +			one_eq_numeral_1 RS sym]) 1);
    6.72 +qed "hypreal_mult_2";
    6.73 +
    6.74 +Goal "z * #2 = (z+z::hypreal)";
    6.75 +by (stac hypreal_mult_commute 1 THEN rtac hypreal_mult_2 1);
    6.76 +qed "hypreal_mult_2_right";
    6.77 +
    6.78 +
    6.79 +(*** Comparisons ***)
    6.80 +
    6.81 +(** Equals (=) **)
    6.82 +
    6.83 +Goal "((number_of v :: hypreal) = number_of v') = \
    6.84 +\     iszero (number_of (bin_add v (bin_minus v')))";
    6.85 +by (simp_tac
    6.86 +    (HOL_ss addsimps [hypreal_number_of_def, 
    6.87 +	              hypreal_of_real_eq_iff, eq_real_number_of]) 1);
    6.88 +qed "eq_hypreal_number_of";
    6.89 +Addsimps [eq_hypreal_number_of];
    6.90 +
    6.91 +(** Less-than (<) **)
    6.92 +
    6.93 +(*"neg" is used in rewrite rules for binary comparisons*)
    6.94 +Goal "((number_of v :: hypreal) < number_of v') = \
    6.95 +\     neg (number_of (bin_add v (bin_minus v')))";
    6.96 +by (simp_tac
    6.97 +    (HOL_ss addsimps [hypreal_number_of_def, hypreal_of_real_less_iff, 
    6.98 +		      less_real_number_of]) 1);
    6.99 +qed "less_hypreal_number_of";
   6.100 +Addsimps [less_hypreal_number_of];
   6.101 +
   6.102 +
   6.103 +(** Less-than-or-equals (<=) **)
   6.104 +
   6.105 +Goal "(number_of x <= (number_of y::hypreal)) = \
   6.106 +\     (~ number_of y < (number_of x::hypreal))";
   6.107 +by (rtac (linorder_not_less RS sym) 1);
   6.108 +qed "le_hypreal_number_of_eq_not_less"; 
   6.109 +Addsimps [le_hypreal_number_of_eq_not_less];
   6.110 +
   6.111 +(*** New versions of existing theorems involving 0, 1hr ***)
   6.112 +
   6.113 +Goal "- #1 = (#-1::hypreal)";
   6.114 +by (Simp_tac 1);
   6.115 +qed "minus_numeral_one";
   6.116 +
   6.117 +(*Maps 0 to #0 and 1hr to #1 and -1hr to #-1*)
   6.118 +val hypreal_numeral_ss = 
   6.119 +    real_numeral_ss addsimps [zero_eq_numeral_0, one_eq_numeral_1, 
   6.120 +		              minus_numeral_one];
   6.121 +
   6.122 +fun rename_numerals th = 
   6.123 +    asm_full_simplify hypreal_numeral_ss (Thm.transfer (the_context ()) th);
   6.124 +
   6.125 +
   6.126 +(*Now insert some identities previously stated for 0 and 1hr*)
   6.127 +
   6.128 +(** HyperDef **)
   6.129 +
   6.130 +Addsimps (map rename_numerals
   6.131 +	  [hypreal_minus_zero, hypreal_minus_zero_iff,
   6.132 +	   hypreal_add_zero_left, hypreal_add_zero_right, 
   6.133 +	   hypreal_diff_zero, hypreal_diff_zero_right,
   6.134 +	   hypreal_mult_0_right, hypreal_mult_0, 
   6.135 +           hypreal_mult_1_right, hypreal_mult_1,
   6.136 +	   hypreal_inverse_1, hypreal_minus_zero_less_iff]);
   6.137 +
   6.138 +bind_thm ("hypreal_0_less_mult_iff", 
   6.139 +	  rename_numerals hypreal_zero_less_mult_iff);
   6.140 +bind_thm ("hypreal_0_le_mult_iff", 
   6.141 +	  rename_numerals hypreal_zero_le_mult_iff);
   6.142 +bind_thm ("hypreal_mult_less_0_iff", 
   6.143 +	  rename_numerals hypreal_mult_less_zero_iff);
   6.144 +bind_thm ("hypreal_mult_le_0_iff", 
   6.145 +	  rename_numerals hypreal_mult_le_zero_iff);
   6.146 +
   6.147 +bind_thm ("hypreal_inverse_less_0", rename_numerals hypreal_inverse_less_zero);
   6.148 +bind_thm ("hypreal_inverse_gt_0", rename_numerals hypreal_inverse_gt_zero);
   6.149 +
   6.150 +Addsimps [zero_eq_numeral_0,one_eq_numeral_1];
   6.151 +
   6.152 +
   6.153 +(** Simplification of arithmetic when nested to the right **)
   6.154 +
   6.155 +Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::hypreal)";
   6.156 +by Auto_tac; 
   6.157 +qed "hypreal_add_number_of_left";
   6.158 +
   6.159 +Goal "number_of v *(number_of w * z) = (number_of(bin_mult v w) * z::hypreal)";
   6.160 +by (simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym]) 1);
   6.161 +qed "hypreal_mult_number_of_left";
   6.162 +
   6.163 +Goalw [hypreal_diff_def]
   6.164 +    "number_of v + (number_of w - c) = number_of(bin_add v w) - (c::hypreal)";
   6.165 +by (rtac hypreal_add_number_of_left 1);
   6.166 +qed "hypreal_add_number_of_diff1";
   6.167 +
   6.168 +Goal "number_of v + (c - number_of w) = \
   6.169 +\     number_of (bin_add v (bin_minus w)) + (c::hypreal)";
   6.170 +by (stac (diff_hypreal_number_of RS sym) 1);
   6.171 +by Auto_tac;
   6.172 +qed "hypreal_add_number_of_diff2";
   6.173 +
   6.174 +Addsimps [hypreal_add_number_of_left, hypreal_mult_number_of_left,
   6.175 +	  hypreal_add_number_of_diff1, hypreal_add_number_of_diff2]; 
   6.176 +
   6.177 +
   6.178 +(*"neg" is used in rewrite rules for binary comparisons*)
   6.179 +Goal "hypreal_of_nat (number_of v :: nat) = \
   6.180 +\        (if neg (number_of v) then #0 \
   6.181 +\         else (number_of v :: hypreal))";
   6.182 +by (simp_tac (simpset() addsimps [hypreal_of_nat_real_of_nat]) 1);
   6.183 +qed "hypreal_of_nat_number_of";
   6.184 +Addsimps [hypreal_of_nat_number_of];
   6.185 +
   6.186 +
   6.187 +(**** Simprocs for numeric literals ****)
   6.188 +
   6.189 +(** Combining of literal coefficients in sums of products **)
   6.190 +
   6.191 +Goal "(x < y) = (x-y < (#0::hypreal))";
   6.192 +by (simp_tac (simpset() addsimps [hypreal_diff_less_eq]) 1);   
   6.193 +qed "hypreal_less_iff_diff_less_0";
   6.194 +
   6.195 +Goal "(x = y) = (x-y = (#0::hypreal))";
   6.196 +by (simp_tac (simpset() addsimps [hypreal_diff_eq_eq]) 1);   
   6.197 +qed "hypreal_eq_iff_diff_eq_0";
   6.198 +
   6.199 +Goal "(x <= y) = (x-y <= (#0::hypreal))";
   6.200 +by (simp_tac (simpset() addsimps [hypreal_diff_le_eq]) 1);   
   6.201 +qed "hypreal_le_iff_diff_le_0";
   6.202 +
   6.203 +
   6.204 +(** For combine_numerals **)
   6.205 +
   6.206 +Goal "i*u + (j*u + k) = (i+j)*u + (k::hypreal)";
   6.207 +by (asm_simp_tac (simpset() addsimps [hypreal_add_mult_distrib]) 1);
   6.208 +qed "left_hypreal_add_mult_distrib";
   6.209 +
   6.210 +
   6.211 +(** For cancel_numerals **)
   6.212 +
   6.213 +val rel_iff_rel_0_rls = 
   6.214 +    map (inst "y" "?u+?v")
   6.215 +      [hypreal_less_iff_diff_less_0, hypreal_eq_iff_diff_eq_0, 
   6.216 +       hypreal_le_iff_diff_le_0] @
   6.217 +    map (inst "y" "n")
   6.218 +      [hypreal_less_iff_diff_less_0, hypreal_eq_iff_diff_eq_0, 
   6.219 +       hypreal_le_iff_diff_le_0];
   6.220 +
   6.221 +Goal "!!i::hypreal. (i*u + m = j*u + n) = ((i-j)*u + m = n)";
   6.222 +by (asm_simp_tac
   6.223 +    (simpset() addsimps [hypreal_diff_def, hypreal_add_mult_distrib]@
   6.224 +	                 hypreal_add_ac@rel_iff_rel_0_rls) 1);
   6.225 +qed "hypreal_eq_add_iff1";
   6.226 +
   6.227 +Goal "!!i::hypreal. (i*u + m = j*u + n) = (m = (j-i)*u + n)";
   6.228 +by (asm_simp_tac
   6.229 +    (simpset() addsimps [hypreal_diff_def, hypreal_add_mult_distrib]@
   6.230 +                         hypreal_add_ac@rel_iff_rel_0_rls) 1);
   6.231 +qed "hypreal_eq_add_iff2";
   6.232 +
   6.233 +Goal "!!i::hypreal. (i*u + m < j*u + n) = ((i-j)*u + m < n)";
   6.234 +by (asm_simp_tac
   6.235 +    (simpset() addsimps [hypreal_diff_def, hypreal_add_mult_distrib]@
   6.236 +                         hypreal_add_ac@rel_iff_rel_0_rls) 1);
   6.237 +qed "hypreal_less_add_iff1";
   6.238 +
   6.239 +Goal "!!i::hypreal. (i*u + m < j*u + n) = (m < (j-i)*u + n)";
   6.240 +by (asm_simp_tac
   6.241 +    (simpset() addsimps [hypreal_diff_def, hypreal_add_mult_distrib]@
   6.242 +                         hypreal_add_ac@rel_iff_rel_0_rls) 1);
   6.243 +qed "hypreal_less_add_iff2";
   6.244 +
   6.245 +Goal "!!i::hypreal. (i*u + m <= j*u + n) = ((i-j)*u + m <= n)";
   6.246 +by (asm_simp_tac
   6.247 +    (simpset() addsimps [hypreal_diff_def, hypreal_add_mult_distrib]@
   6.248 +                         hypreal_add_ac@rel_iff_rel_0_rls) 1);
   6.249 +qed "hypreal_le_add_iff1";
   6.250 +
   6.251 +Goal "!!i::hypreal. (i*u + m <= j*u + n) = (m <= (j-i)*u + n)";
   6.252 +by (asm_simp_tac
   6.253 +    (simpset() addsimps [hypreal_diff_def, hypreal_add_mult_distrib]@
   6.254 +                        hypreal_add_ac@rel_iff_rel_0_rls) 1);
   6.255 +qed "hypreal_le_add_iff2";
   6.256 +
   6.257 +Goal "(z::hypreal) * #-1 = -z";
   6.258 +by (stac (minus_numeral_one RS sym) 1);
   6.259 +by (stac (hypreal_minus_mult_eq2 RS sym) 1); 
   6.260 +by Auto_tac;  
   6.261 +qed "hypreal_mult_minus_1_right";
   6.262 +Addsimps [hypreal_mult_minus_1_right];
   6.263 +
   6.264 +Goal "#-1 * (z::hypreal) = -z";
   6.265 +by (simp_tac (simpset() addsimps [hypreal_mult_commute]) 1); 
   6.266 +qed "hypreal_mult_minus_1";
   6.267 +Addsimps [hypreal_mult_minus_1];
   6.268 +
   6.269 +
   6.270 +
   6.271 +structure Hyperreal_Numeral_Simprocs =
   6.272 +struct
   6.273 +
   6.274 +(*Utilities*)
   6.275 +
   6.276 +
   6.277 +val hyprealT = Type("HyperDef.hypreal",[]);
   6.278 +
   6.279 +fun mk_numeral n = HOLogic.number_of_const hyprealT $ HOLogic.mk_bin n;
   6.280 +
   6.281 +val dest_numeral = Real_Numeral_Simprocs.dest_numeral;
   6.282 +
   6.283 +val find_first_numeral = Real_Numeral_Simprocs.find_first_numeral;
   6.284 +
   6.285 +val zero = mk_numeral 0;
   6.286 +val mk_plus = HOLogic.mk_binop "op +";
   6.287 +
   6.288 +val uminus_const = Const ("uminus", hyprealT --> hyprealT);
   6.289 +
   6.290 +(*Thus mk_sum[t] yields t+#0; longer sums don't have a trailing zero*)
   6.291 +fun mk_sum []        = zero
   6.292 +  | mk_sum [t,u]     = mk_plus (t, u)
   6.293 +  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
   6.294 +
   6.295 +(*this version ALWAYS includes a trailing zero*)
   6.296 +fun long_mk_sum []        = zero
   6.297 +  | long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
   6.298 +
   6.299 +val dest_plus = HOLogic.dest_bin "op +" hyprealT;
   6.300 +
   6.301 +(*decompose additions AND subtractions as a sum*)
   6.302 +fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) =
   6.303 +        dest_summing (pos, t, dest_summing (pos, u, ts))
   6.304 +  | dest_summing (pos, Const ("op -", _) $ t $ u, ts) =
   6.305 +        dest_summing (pos, t, dest_summing (not pos, u, ts))
   6.306 +  | dest_summing (pos, t, ts) =
   6.307 +	if pos then t::ts else uminus_const$t :: ts;
   6.308 +
   6.309 +fun dest_sum t = dest_summing (true, t, []);
   6.310 +
   6.311 +val mk_diff = HOLogic.mk_binop "op -";
   6.312 +val dest_diff = HOLogic.dest_bin "op -" hyprealT;
   6.313 +
   6.314 +val one = mk_numeral 1;
   6.315 +val mk_times = HOLogic.mk_binop "op *";
   6.316 +
   6.317 +fun mk_prod [] = one
   6.318 +  | mk_prod [t] = t
   6.319 +  | mk_prod (t :: ts) = if t = one then mk_prod ts
   6.320 +                        else mk_times (t, mk_prod ts);
   6.321 +
   6.322 +val dest_times = HOLogic.dest_bin "op *" hyprealT;
   6.323 +
   6.324 +fun dest_prod t =
   6.325 +      let val (t,u) = dest_times t 
   6.326 +      in  dest_prod t @ dest_prod u  end
   6.327 +      handle TERM _ => [t];
   6.328 +
   6.329 +(*DON'T do the obvious simplifications; that would create special cases*) 
   6.330 +fun mk_coeff (k, ts) = mk_times (mk_numeral k, ts);
   6.331 +
   6.332 +(*Express t as a product of (possibly) a numeral with other sorted terms*)
   6.333 +fun dest_coeff sign (Const ("uminus", _) $ t) = dest_coeff (~sign) t
   6.334 +  | dest_coeff sign t =
   6.335 +    let val ts = sort Term.term_ord (dest_prod t)
   6.336 +	val (n, ts') = find_first_numeral [] ts
   6.337 +                          handle TERM _ => (1, ts)
   6.338 +    in (sign*n, mk_prod ts') end;
   6.339 +
   6.340 +(*Find first coefficient-term THAT MATCHES u*)
   6.341 +fun find_first_coeff past u [] = raise TERM("find_first_coeff", []) 
   6.342 +  | find_first_coeff past u (t::terms) =
   6.343 +	let val (n,u') = dest_coeff 1 t
   6.344 +	in  if u aconv u' then (n, rev past @ terms)
   6.345 +			  else find_first_coeff (t::past) u terms
   6.346 +	end
   6.347 +	handle TERM _ => find_first_coeff (t::past) u terms;
   6.348 +
   6.349 +
   6.350 +(*Simplify #1*n and n*#1 to n*)
   6.351 +val add_0s = map rename_numerals
   6.352 +                 [hypreal_add_zero_left, hypreal_add_zero_right];
   6.353 +val mult_plus_1s = map rename_numerals
   6.354 +                      [hypreal_mult_1, hypreal_mult_1_right];
   6.355 +val mult_minus_1s = map rename_numerals
   6.356 +                      [hypreal_mult_minus_1, hypreal_mult_minus_1_right];
   6.357 +val mult_1s = mult_plus_1s @ mult_minus_1s;
   6.358 +
   6.359 +(*To perform binary arithmetic*)
   6.360 +val bin_simps =
   6.361 +    [add_hypreal_number_of, hypreal_add_number_of_left, 
   6.362 +     minus_hypreal_number_of, diff_hypreal_number_of, mult_hypreal_number_of, 
   6.363 +     hypreal_mult_number_of_left] @ bin_arith_simps @ bin_rel_simps;
   6.364 +
   6.365 +(*To evaluate binary negations of coefficients*)
   6.366 +val hypreal_minus_simps = NCons_simps @
   6.367 +                   [minus_hypreal_number_of, 
   6.368 +		    bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min,
   6.369 +		    bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min];
   6.370 +
   6.371 +(*To let us treat subtraction as addition*)
   6.372 +val diff_simps = [hypreal_diff_def, hypreal_minus_add_distrib, 
   6.373 +                  hypreal_minus_minus];
   6.374 +
   6.375 +(*push the unary minus down: - x * y = x * - y *)
   6.376 +val hypreal_minus_mult_eq_1_to_2 = 
   6.377 +    [hypreal_minus_mult_eq1 RS sym, hypreal_minus_mult_eq2] MRS trans 
   6.378 +    |> standard;
   6.379 +
   6.380 +(*to extract again any uncancelled minuses*)
   6.381 +val hypreal_minus_from_mult_simps = 
   6.382 +    [hypreal_minus_minus, hypreal_minus_mult_eq1 RS sym, 
   6.383 +     hypreal_minus_mult_eq2 RS sym];
   6.384 +
   6.385 +(*combine unary minus with numeric literals, however nested within a product*)
   6.386 +val hypreal_mult_minus_simps =
   6.387 +    [hypreal_mult_assoc, hypreal_minus_mult_eq1, hypreal_minus_mult_eq_1_to_2];
   6.388 +
   6.389 +(*Apply the given rewrite (if present) just once*)
   6.390 +fun trans_tac None      = all_tac
   6.391 +  | trans_tac (Some th) = ALLGOALS (rtac (th RS trans));
   6.392 +
   6.393 +fun prove_conv name tacs sg (hyps: thm list) (t,u) =
   6.394 +  if t aconv u then None
   6.395 +  else
   6.396 +  let val ct = cterm_of sg (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)))
   6.397 +  in Some
   6.398 +     (prove_goalw_cterm [] ct (K tacs)
   6.399 +      handle ERROR => error 
   6.400 +	  ("The error(s) above occurred while trying to prove " ^
   6.401 +	   string_of_cterm ct ^ "\nInternal failure of simproc " ^ name))
   6.402 +  end;
   6.403 +
   6.404 +(*version without the hyps argument*)
   6.405 +fun prove_conv_nohyps name tacs sg = prove_conv name tacs sg [];
   6.406 +
   6.407 +(*Final simplification: cancel + and *  *)
   6.408 +val simplify_meta_eq = 
   6.409 +    Int_Numeral_Simprocs.simplify_meta_eq
   6.410 +         [hypreal_add_zero_left, hypreal_add_zero_right,
   6.411 + 	  hypreal_mult_0, hypreal_mult_0_right, hypreal_mult_1, 
   6.412 +          hypreal_mult_1_right];
   6.413 +
   6.414 +val prep_simproc = Real_Numeral_Simprocs.prep_simproc;
   6.415 +val prep_pats = map Real_Numeral_Simprocs.prep_pat;
   6.416 +
   6.417 +structure CancelNumeralsCommon =
   6.418 +  struct
   6.419 +  val mk_sum    	= mk_sum
   6.420 +  val dest_sum		= dest_sum
   6.421 +  val mk_coeff		= mk_coeff
   6.422 +  val dest_coeff	= dest_coeff 1
   6.423 +  val find_first_coeff	= find_first_coeff []
   6.424 +  val trans_tac         = trans_tac
   6.425 +  val norm_tac = 
   6.426 +     ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@
   6.427 +                                         hypreal_minus_simps@hypreal_add_ac))
   6.428 +     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@hypreal_mult_minus_simps))
   6.429 +     THEN ALLGOALS
   6.430 +              (simp_tac (HOL_ss addsimps hypreal_minus_from_mult_simps@
   6.431 +                                         hypreal_add_ac@hypreal_mult_ac))
   6.432 +  val numeral_simp_tac	= ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps))
   6.433 +  val simplify_meta_eq  = simplify_meta_eq
   6.434 +  end;
   6.435 +
   6.436 +
   6.437 +structure EqCancelNumerals = CancelNumeralsFun
   6.438 + (open CancelNumeralsCommon
   6.439 +  val prove_conv = prove_conv "hyprealeq_cancel_numerals"
   6.440 +  val mk_bal   = HOLogic.mk_eq
   6.441 +  val dest_bal = HOLogic.dest_bin "op =" hyprealT
   6.442 +  val bal_add1 = hypreal_eq_add_iff1 RS trans
   6.443 +  val bal_add2 = hypreal_eq_add_iff2 RS trans
   6.444 +);
   6.445 +
   6.446 +structure LessCancelNumerals = CancelNumeralsFun
   6.447 + (open CancelNumeralsCommon
   6.448 +  val prove_conv = prove_conv "hyprealless_cancel_numerals"
   6.449 +  val mk_bal   = HOLogic.mk_binrel "op <"
   6.450 +  val dest_bal = HOLogic.dest_bin "op <" hyprealT
   6.451 +  val bal_add1 = hypreal_less_add_iff1 RS trans
   6.452 +  val bal_add2 = hypreal_less_add_iff2 RS trans
   6.453 +);
   6.454 +
   6.455 +structure LeCancelNumerals = CancelNumeralsFun
   6.456 + (open CancelNumeralsCommon
   6.457 +  val prove_conv = prove_conv "hyprealle_cancel_numerals"
   6.458 +  val mk_bal   = HOLogic.mk_binrel "op <="
   6.459 +  val dest_bal = HOLogic.dest_bin "op <=" hyprealT
   6.460 +  val bal_add1 = hypreal_le_add_iff1 RS trans
   6.461 +  val bal_add2 = hypreal_le_add_iff2 RS trans
   6.462 +);
   6.463 +
   6.464 +val cancel_numerals = 
   6.465 +  map prep_simproc
   6.466 +   [("hyprealeq_cancel_numerals",
   6.467 +     prep_pats ["(l::hypreal) + m = n", "(l::hypreal) = m + n", 
   6.468 +		"(l::hypreal) - m = n", "(l::hypreal) = m - n", 
   6.469 +		"(l::hypreal) * m = n", "(l::hypreal) = m * n"], 
   6.470 +     EqCancelNumerals.proc),
   6.471 +    ("hyprealless_cancel_numerals", 
   6.472 +     prep_pats ["(l::hypreal) + m < n", "(l::hypreal) < m + n", 
   6.473 +		"(l::hypreal) - m < n", "(l::hypreal) < m - n", 
   6.474 +		"(l::hypreal) * m < n", "(l::hypreal) < m * n"], 
   6.475 +     LessCancelNumerals.proc),
   6.476 +    ("hyprealle_cancel_numerals", 
   6.477 +     prep_pats ["(l::hypreal) + m <= n", "(l::hypreal) <= m + n", 
   6.478 +		"(l::hypreal) - m <= n", "(l::hypreal) <= m - n", 
   6.479 +		"(l::hypreal) * m <= n", "(l::hypreal) <= m * n"], 
   6.480 +     LeCancelNumerals.proc)];
   6.481 +
   6.482 +
   6.483 +structure CombineNumeralsData =
   6.484 +  struct
   6.485 +  val add		= op + : int*int -> int 
   6.486 +  val mk_sum    	= long_mk_sum    (*to work for e.g. #2*x + #3*x *)
   6.487 +  val dest_sum		= dest_sum
   6.488 +  val mk_coeff		= mk_coeff
   6.489 +  val dest_coeff	= dest_coeff 1
   6.490 +  val left_distrib	= left_hypreal_add_mult_distrib RS trans
   6.491 +  val prove_conv	= prove_conv_nohyps "hypreal_combine_numerals"
   6.492 +  val trans_tac          = trans_tac
   6.493 +  val norm_tac = 
   6.494 +     ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@
   6.495 +                                         hypreal_minus_simps@hypreal_add_ac))
   6.496 +     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@hypreal_mult_minus_simps))
   6.497 +     THEN ALLGOALS (simp_tac (HOL_ss addsimps hypreal_minus_from_mult_simps@
   6.498 +                                              hypreal_add_ac@hypreal_mult_ac))
   6.499 +  val numeral_simp_tac	= ALLGOALS 
   6.500 +                    (simp_tac (HOL_ss addsimps add_0s@bin_simps))
   6.501 +  val simplify_meta_eq  = simplify_meta_eq
   6.502 +  end;
   6.503 +
   6.504 +structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
   6.505 +  
   6.506 +val combine_numerals = 
   6.507 +    prep_simproc ("hypreal_combine_numerals",
   6.508 +		  prep_pats ["(i::hypreal) + j", "(i::hypreal) - j"],
   6.509 +		  CombineNumerals.proc);
   6.510 +
   6.511 +
   6.512 +(** Declarations for ExtractCommonTerm **)
   6.513 +
   6.514 +(*this version ALWAYS includes a trailing one*)
   6.515 +fun long_mk_prod []        = one
   6.516 +  | long_mk_prod (t :: ts) = mk_times (t, mk_prod ts);
   6.517 +
   6.518 +(*Find first term that matches u*)
   6.519 +fun find_first past u []         = raise TERM("find_first", []) 
   6.520 +  | find_first past u (t::terms) =
   6.521 +	if u aconv t then (rev past @ terms)
   6.522 +        else find_first (t::past) u terms
   6.523 +	handle TERM _ => find_first (t::past) u terms;
   6.524 +
   6.525 +(*Final simplification: cancel + and *  *)
   6.526 +fun cancel_simplify_meta_eq cancel_th th = 
   6.527 +    Int_Numeral_Simprocs.simplify_meta_eq 
   6.528 +        [hypreal_mult_1, hypreal_mult_1_right] 
   6.529 +        (([th, cancel_th]) MRS trans);
   6.530 +
   6.531 +end;
   6.532 +
   6.533 +Addsimprocs Hyperreal_Numeral_Simprocs.cancel_numerals;
   6.534 +Addsimprocs [Hyperreal_Numeral_Simprocs.combine_numerals];
   6.535 +
   6.536 +(*The Abel_Cancel simprocs are now obsolete*)
   6.537 +Delsimprocs [Hyperreal_Cancel.sum_conv, Hyperreal_Cancel.rel_conv];
   6.538 +
   6.539 +(*examples:
   6.540 +print_depth 22;
   6.541 +set timing;
   6.542 +set trace_simp;
   6.543 +fun test s = (Goal s, by (Simp_tac 1)); 
   6.544 +
   6.545 +test "l + #2 + #2 + #2 + (l + #2) + (oo + #2) = (uu::hypreal)";
   6.546 +test "#2*u = (u::hypreal)";
   6.547 +test "(i + j + #12 + (k::hypreal)) - #15 = y";
   6.548 +test "(i + j + #12 + (k::hypreal)) - #5 = y";
   6.549 +
   6.550 +test "y - b < (b::hypreal)";
   6.551 +test "y - (#3*b + c) < (b::hypreal) - #2*c";
   6.552 +
   6.553 +test "(#2*x - (u*v) + y) - v*#3*u = (w::hypreal)";
   6.554 +test "(#2*x*u*v + (u*v)*#4 + y) - v*u*#4 = (w::hypreal)";
   6.555 +test "(#2*x*u*v + (u*v)*#4 + y) - v*u = (w::hypreal)";
   6.556 +test "u*v - (x*u*v + (u*v)*#4 + y) = (w::hypreal)";
   6.557 +
   6.558 +test "(i + j + #12 + (k::hypreal)) = u + #15 + y";
   6.559 +test "(i + j*#2 + #12 + (k::hypreal)) = j + #5 + y";
   6.560 +
   6.561 +test "#2*y + #3*z + #6*w + #2*y + #3*z + #2*u = #2*y' + #3*z' + #6*w' + #2*y' + #3*z' + u + (vv::hypreal)";
   6.562 +
   6.563 +test "a + -(b+c) + b = (d::hypreal)";
   6.564 +test "a + -(b+c) - b = (d::hypreal)";
   6.565 +
   6.566 +(*negative numerals*)
   6.567 +test "(i + j + #-2 + (k::hypreal)) - (u + #5 + y) = zz";
   6.568 +test "(i + j + #-3 + (k::hypreal)) < u + #5 + y";
   6.569 +test "(i + j + #3 + (k::hypreal)) < u + #-6 + y";
   6.570 +test "(i + j + #-12 + (k::hypreal)) - #15 = y";
   6.571 +test "(i + j + #12 + (k::hypreal)) - #-15 = y";
   6.572 +test "(i + j + #-12 + (k::hypreal)) - #-15 = y";
   6.573 +*)
   6.574 +
   6.575 +
   6.576 +(** Constant folding for hypreal plus and times **)
   6.577 +
   6.578 +(*We do not need
   6.579 +    structure Hyperreal_Plus_Assoc = Assoc_Fold (Hyperreal_Plus_Assoc_Data);
   6.580 +  because combine_numerals does the same thing*)
   6.581 +
   6.582 +structure Hyperreal_Times_Assoc_Data : ASSOC_FOLD_DATA =
   6.583 +struct
   6.584 +  val ss		= HOL_ss
   6.585 +  val eq_reflection	= eq_reflection
   6.586 +  val sg_ref    = Sign.self_ref (Theory.sign_of (the_context ()))
   6.587 +  val T	     = Hyperreal_Numeral_Simprocs.hyprealT
   6.588 +  val plus   = Const ("op *", [T,T] ---> T)
   6.589 +  val add_ac = hypreal_mult_ac
   6.590 +end;
   6.591 +
   6.592 +structure Hyperreal_Times_Assoc = Assoc_Fold (Hyperreal_Times_Assoc_Data);
   6.593 +
   6.594 +Addsimprocs [Hyperreal_Times_Assoc.conv];
   6.595 +
   6.596 +Addsimps [rename_numerals hypreal_of_real_zero_iff];
   6.597 +
   6.598 +(*Simplification of  x-y < 0, etc.*)
   6.599 +AddIffs [hypreal_less_iff_diff_less_0 RS sym];
   6.600 +AddIffs [hypreal_eq_iff_diff_eq_0 RS sym];
   6.601 +AddIffs [hypreal_le_iff_diff_le_0 RS sym];
   6.602 +
   6.603 +
   6.604 +(** number_of related to hypreal_of_real **)
   6.605 +
   6.606 +Goal "(number_of w < hypreal_of_real z) = (number_of w < z)";
   6.607 +by (stac (hypreal_of_real_less_iff RS sym) 1); 
   6.608 +by (Simp_tac 1); 
   6.609 +qed "number_of_less_hypreal_of_real_iff";
   6.610 +Addsimps [number_of_less_hypreal_of_real_iff];
   6.611 +
   6.612 +Goal "(number_of w <= hypreal_of_real z) = (number_of w <= z)";
   6.613 +by (stac (hypreal_of_real_le_iff RS sym) 1); 
   6.614 +by (Simp_tac 1); 
   6.615 +qed "number_of_le_hypreal_of_real_iff";
   6.616 +Addsimps [number_of_le_hypreal_of_real_iff];
   6.617 +
   6.618 +Goal "(hypreal_of_real z < number_of w) = (z < number_of w)";
   6.619 +by (stac (hypreal_of_real_less_iff RS sym) 1); 
   6.620 +by (Simp_tac 1); 
   6.621 +qed "hypreal_of_real_less_number_of_iff";
   6.622 +Addsimps [hypreal_of_real_less_number_of_iff];
   6.623 +
   6.624 +Goal "(hypreal_of_real z <= number_of w) = (z <= number_of w)";
   6.625 +by (stac (hypreal_of_real_le_iff RS sym) 1); 
   6.626 +by (Simp_tac 1); 
   6.627 +qed "hypreal_of_real_le_number_of_iff";
   6.628 +Addsimps [hypreal_of_real_le_number_of_iff];
   6.629 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/HOL/Hyperreal/HyperBin.thy	Sat Dec 30 22:03:47 2000 +0100
     7.3 @@ -0,0 +1,21 @@
     7.4 +(*  Title:      HOL/HyperBin.thy
     7.5 +    ID:         $Id$
     7.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     7.7 +    Copyright   1999  University of Cambridge
     7.8 +
     7.9 +Binary arithmetic for the hyperreals
    7.10 +
    7.11 +This case is reduced to that for the reals.
    7.12 +*)
    7.13 +
    7.14 +HyperBin = HyperOrd +
    7.15 +
    7.16 +instance
    7.17 +  hypreal :: number 
    7.18 +
    7.19 +defs
    7.20 +  hypreal_number_of_def
    7.21 +    "number_of v == hypreal_of_real (number_of v)"
    7.22 +     (*::bin=>hypreal               ::bin=>real*)
    7.23 +
    7.24 +end
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/HOL/Hyperreal/HyperDef.ML	Sat Dec 30 22:03:47 2000 +0100
     8.3 @@ -0,0 +1,1354 @@
     8.4 +(*  Title       : HOL/Real/Hyperreal/Hyper.ML
     8.5 +    ID          : $Id$
     8.6 +    Author      : Jacques D. Fleuriot
     8.7 +    Copyright   : 1998  University of Cambridge
     8.8 +    Description : Ultrapower construction of hyperreals
     8.9 +*) 
    8.10 +
    8.11 +(*------------------------------------------------------------------------
    8.12 +             Proof that the set of naturals is not finite
    8.13 + ------------------------------------------------------------------------*)
    8.14 +
    8.15 +(*** based on James' proof that the set of naturals is not finite ***)
    8.16 +Goal "finite (A::nat set) --> (EX n. ALL m. Suc (n + m) ~: A)";
    8.17 +by (rtac impI 1);
    8.18 +by (eres_inst_tac [("F","A")] finite_induct 1);
    8.19 +by (Blast_tac 1 THEN etac exE 1);
    8.20 +by (res_inst_tac [("x","n + x")] exI 1);
    8.21 +by (rtac allI 1 THEN eres_inst_tac [("x","x + m")] allE 1);
    8.22 +by (auto_tac (claset(), simpset() addsimps add_ac));
    8.23 +by (auto_tac (claset(),
    8.24 +	      simpset() addsimps [add_assoc RS sym,
    8.25 +				  less_add_Suc2 RS less_not_refl2]));
    8.26 +qed_spec_mp "finite_exhausts";
    8.27 +
    8.28 +Goal "finite (A :: nat set) --> (EX n. n ~:A)";
    8.29 +by (rtac impI 1 THEN dtac finite_exhausts 1);
    8.30 +by (Blast_tac 1);
    8.31 +qed_spec_mp "finite_not_covers";
    8.32 +
    8.33 +Goal "~ finite(UNIV:: nat set)";
    8.34 +by (fast_tac (claset() addSDs [finite_exhausts]) 1);
    8.35 +qed "not_finite_nat";
    8.36 +
    8.37 +(*------------------------------------------------------------------------
    8.38 +   Existence of free ultrafilter over the naturals and proof of various 
    8.39 +   properties of the FreeUltrafilterNat- an arbitrary free ultrafilter
    8.40 + ------------------------------------------------------------------------*)
    8.41 +
    8.42 +Goal "EX U. U: FreeUltrafilter (UNIV::nat set)";
    8.43 +by (rtac (not_finite_nat RS FreeUltrafilter_Ex) 1);
    8.44 +qed "FreeUltrafilterNat_Ex";
    8.45 +
    8.46 +Goalw [FreeUltrafilterNat_def] 
    8.47 +     "FreeUltrafilterNat: FreeUltrafilter(UNIV:: nat set)";
    8.48 +by (rtac (FreeUltrafilterNat_Ex RS exE) 1);
    8.49 +by (rtac someI2 1 THEN ALLGOALS(assume_tac));
    8.50 +qed "FreeUltrafilterNat_mem";
    8.51 +Addsimps [FreeUltrafilterNat_mem];
    8.52 +
    8.53 +Goalw [FreeUltrafilterNat_def] "finite x ==> x ~: FreeUltrafilterNat";
    8.54 +by (rtac (FreeUltrafilterNat_Ex RS exE) 1);
    8.55 +by (rtac someI2 1 THEN assume_tac 1);
    8.56 +by (blast_tac (claset() addDs [mem_FreeUltrafiltersetD1]) 1);
    8.57 +qed "FreeUltrafilterNat_finite";
    8.58 +
    8.59 +Goal "x: FreeUltrafilterNat ==> ~ finite x";
    8.60 +by (blast_tac (claset() addDs [FreeUltrafilterNat_finite]) 1);
    8.61 +qed "FreeUltrafilterNat_not_finite";
    8.62 +
    8.63 +Goalw [FreeUltrafilterNat_def] "{} ~: FreeUltrafilterNat";
    8.64 +by (rtac (FreeUltrafilterNat_Ex RS exE) 1);
    8.65 +by (rtac someI2 1 THEN assume_tac 1);
    8.66 +by (blast_tac (claset() addDs [FreeUltrafilter_Ultrafilter,
    8.67 +			       Ultrafilter_Filter,Filter_empty_not_mem]) 1);
    8.68 +qed "FreeUltrafilterNat_empty";
    8.69 +Addsimps [FreeUltrafilterNat_empty];
    8.70 +
    8.71 +Goal "[| X: FreeUltrafilterNat;  Y: FreeUltrafilterNat |]  \
    8.72 +\     ==> X Int Y : FreeUltrafilterNat";
    8.73 +by (cut_facts_tac [FreeUltrafilterNat_mem] 1);
    8.74 +by (blast_tac (claset() addDs [FreeUltrafilter_Ultrafilter,
    8.75 +			       Ultrafilter_Filter,mem_FiltersetD1]) 1);
    8.76 +qed "FreeUltrafilterNat_Int";
    8.77 +
    8.78 +Goal "[| X: FreeUltrafilterNat;  X <= Y |] \
    8.79 +\     ==> Y : FreeUltrafilterNat";
    8.80 +by (cut_facts_tac [FreeUltrafilterNat_mem] 1);
    8.81 +by (blast_tac (claset() addDs [FreeUltrafilter_Ultrafilter,
    8.82 +			       Ultrafilter_Filter,mem_FiltersetD2]) 1);
    8.83 +qed "FreeUltrafilterNat_subset";
    8.84 +
    8.85 +Goal "X: FreeUltrafilterNat ==> -X ~: FreeUltrafilterNat";
    8.86 +by (Step_tac 1);
    8.87 +by (dtac FreeUltrafilterNat_Int 1 THEN assume_tac 1);
    8.88 +by Auto_tac;
    8.89 +qed "FreeUltrafilterNat_Compl";
    8.90 +
    8.91 +Goal "X~: FreeUltrafilterNat ==> -X : FreeUltrafilterNat";
    8.92 +by (cut_facts_tac [FreeUltrafilterNat_mem RS (FreeUltrafilter_iff RS iffD1)] 1);
    8.93 +by (Step_tac 1 THEN dres_inst_tac [("x","X")] bspec 1);
    8.94 +by (auto_tac (claset(), simpset() addsimps [UNIV_diff_Compl]));
    8.95 +qed "FreeUltrafilterNat_Compl_mem";
    8.96 +
    8.97 +Goal "(X ~: FreeUltrafilterNat) = (-X: FreeUltrafilterNat)";
    8.98 +by (blast_tac (claset() addDs [FreeUltrafilterNat_Compl,
    8.99 +			       FreeUltrafilterNat_Compl_mem]) 1);
   8.100 +qed "FreeUltrafilterNat_Compl_iff1";
   8.101 +
   8.102 +Goal "(X: FreeUltrafilterNat) = (-X ~: FreeUltrafilterNat)";
   8.103 +by (auto_tac (claset(),
   8.104 +	      simpset() addsimps [FreeUltrafilterNat_Compl_iff1 RS sym]));
   8.105 +qed "FreeUltrafilterNat_Compl_iff2";
   8.106 +
   8.107 +Goal "(UNIV::nat set) : FreeUltrafilterNat";
   8.108 +by (rtac (FreeUltrafilterNat_mem RS FreeUltrafilter_Ultrafilter RS 
   8.109 +          Ultrafilter_Filter RS mem_FiltersetD4) 1);
   8.110 +qed "FreeUltrafilterNat_UNIV";
   8.111 +Addsimps [FreeUltrafilterNat_UNIV];
   8.112 +
   8.113 +Goal "UNIV : FreeUltrafilterNat";
   8.114 +by Auto_tac;
   8.115 +qed "FreeUltrafilterNat_Nat_set";
   8.116 +Addsimps [FreeUltrafilterNat_Nat_set];
   8.117 +
   8.118 +Goal "{n. P(n) = P(n)} : FreeUltrafilterNat";
   8.119 +by (Simp_tac 1);
   8.120 +qed "FreeUltrafilterNat_Nat_set_refl";
   8.121 +AddIs [FreeUltrafilterNat_Nat_set_refl];
   8.122 +
   8.123 +Goal "{n::nat. P} : FreeUltrafilterNat ==> P";
   8.124 +by (rtac ccontr 1);
   8.125 +by (rotate_tac 1 1);
   8.126 +by (Asm_full_simp_tac 1);
   8.127 +qed "FreeUltrafilterNat_P";
   8.128 +
   8.129 +Goal "{n. P(n)} : FreeUltrafilterNat ==> EX n. P(n)";
   8.130 +by (rtac ccontr 1 THEN rotate_tac 1 1);
   8.131 +by (Asm_full_simp_tac 1);
   8.132 +qed "FreeUltrafilterNat_Ex_P";
   8.133 +
   8.134 +Goal "ALL n. P(n) ==> {n. P(n)} : FreeUltrafilterNat";
   8.135 +by (auto_tac (claset() addIs [FreeUltrafilterNat_Nat_set], simpset()));
   8.136 +qed "FreeUltrafilterNat_all";
   8.137 +
   8.138 +(*-------------------------------------------------------
   8.139 +     Define and use Ultrafilter tactics
   8.140 + -------------------------------------------------------*)
   8.141 +use "fuf.ML";
   8.142 +
   8.143 +(*-------------------------------------------------------
   8.144 +  Now prove one further property of our free ultrafilter
   8.145 + -------------------------------------------------------*)
   8.146 +Goal "X Un Y: FreeUltrafilterNat \
   8.147 +\     ==> X: FreeUltrafilterNat | Y: FreeUltrafilterNat";
   8.148 +by Auto_tac;
   8.149 +by (Ultra_tac 1);
   8.150 +qed "FreeUltrafilterNat_Un";
   8.151 +
   8.152 +(*-------------------------------------------------------
   8.153 +   Properties of hyprel
   8.154 + -------------------------------------------------------*)
   8.155 +
   8.156 +(** Proving that hyprel is an equivalence relation **)
   8.157 +(** Natural deduction for hyprel **)
   8.158 +
   8.159 +Goalw [hyprel_def]
   8.160 +   "((X,Y): hyprel) = ({n. X n = Y n}: FreeUltrafilterNat)";
   8.161 +by (Fast_tac 1);
   8.162 +qed "hyprel_iff";
   8.163 +
   8.164 +Goalw [hyprel_def] 
   8.165 +     "{n. X n = Y n}: FreeUltrafilterNat  ==> (X,Y): hyprel";
   8.166 +by (Fast_tac 1);
   8.167 +qed "hyprelI";
   8.168 +
   8.169 +Goalw [hyprel_def]
   8.170 +  "p: hyprel --> (EX X Y. \
   8.171 +\                 p = (X,Y) & {n. X n = Y n} : FreeUltrafilterNat)";
   8.172 +by (Fast_tac 1);
   8.173 +qed "hyprelE_lemma";
   8.174 +
   8.175 +val [major,minor] = goal (the_context ())
   8.176 +  "[| p: hyprel;  \
   8.177 +\     !!X Y. [| p = (X,Y); {n. X n = Y n}: FreeUltrafilterNat\
   8.178 +\                    |] ==> Q |] ==> Q";
   8.179 +by (cut_facts_tac [major RS (hyprelE_lemma RS mp)] 1);
   8.180 +by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1));
   8.181 +qed "hyprelE";
   8.182 +
   8.183 +AddSIs [hyprelI];
   8.184 +AddSEs [hyprelE];
   8.185 +
   8.186 +Goalw [hyprel_def] "(x,x): hyprel";
   8.187 +by (auto_tac (claset(),
   8.188 +              simpset() addsimps [FreeUltrafilterNat_Nat_set]));
   8.189 +qed "hyprel_refl";
   8.190 +
   8.191 +Goal "{n. X n = Y n} = {n. Y n = X n}";
   8.192 +by Auto_tac;
   8.193 +qed "lemma_perm";
   8.194 +
   8.195 +Goalw [hyprel_def] "(x,y): hyprel --> (y,x):hyprel";
   8.196 +by (auto_tac (claset() addIs [lemma_perm RS subst], simpset()));
   8.197 +qed_spec_mp "hyprel_sym";
   8.198 +
   8.199 +Goalw [hyprel_def]
   8.200 +      "(x,y): hyprel --> (y,z):hyprel --> (x,z):hyprel";
   8.201 +by Auto_tac;
   8.202 +by (Ultra_tac 1);
   8.203 +qed_spec_mp "hyprel_trans";
   8.204 +
   8.205 +Goalw [equiv_def, refl_def, sym_def, trans_def] "equiv UNIV hyprel";
   8.206 +by (auto_tac (claset() addSIs [hyprel_refl] 
   8.207 +                       addSEs [hyprel_sym,hyprel_trans] 
   8.208 +                       delrules [hyprelI,hyprelE],
   8.209 +	      simpset() addsimps [FreeUltrafilterNat_Nat_set]));
   8.210 +qed "equiv_hyprel";
   8.211 +
   8.212 +(* (hyprel ^^ {x} = hyprel ^^ {y}) = ((x,y) : hyprel) *)
   8.213 +bind_thm ("equiv_hyprel_iff",
   8.214 +    	  [equiv_hyprel, UNIV_I, UNIV_I] MRS eq_equiv_class_iff);
   8.215 +
   8.216 +Goalw  [hypreal_def,hyprel_def,quotient_def] "hyprel^^{x}:hypreal";
   8.217 +by (Blast_tac 1);
   8.218 +qed "hyprel_in_hypreal";
   8.219 +
   8.220 +Goal "inj_on Abs_hypreal hypreal";
   8.221 +by (rtac inj_on_inverseI 1);
   8.222 +by (etac Abs_hypreal_inverse 1);
   8.223 +qed "inj_on_Abs_hypreal";
   8.224 +
   8.225 +Addsimps [equiv_hyprel_iff,inj_on_Abs_hypreal RS inj_on_iff,
   8.226 +          hyprel_iff, hyprel_in_hypreal, Abs_hypreal_inverse];
   8.227 +
   8.228 +Addsimps [equiv_hyprel RS eq_equiv_class_iff];
   8.229 +bind_thm ("eq_hyprelD", equiv_hyprel RSN (2,eq_equiv_class));
   8.230 +
   8.231 +Goal "inj(Rep_hypreal)";
   8.232 +by (rtac inj_inverseI 1);
   8.233 +by (rtac Rep_hypreal_inverse 1);
   8.234 +qed "inj_Rep_hypreal";
   8.235 +
   8.236 +Goalw [hyprel_def] "x: hyprel ^^ {x}";
   8.237 +by (Step_tac 1);
   8.238 +by (auto_tac (claset() addSIs [FreeUltrafilterNat_Nat_set], simpset()));
   8.239 +qed "lemma_hyprel_refl";
   8.240 +
   8.241 +Addsimps [lemma_hyprel_refl];
   8.242 +
   8.243 +Goalw [hypreal_def] "{} ~: hypreal";
   8.244 +by (auto_tac (claset() addSEs [quotientE], simpset()));
   8.245 +qed "hypreal_empty_not_mem";
   8.246 +
   8.247 +Addsimps [hypreal_empty_not_mem];
   8.248 +
   8.249 +Goal "Rep_hypreal x ~= {}";
   8.250 +by (cut_inst_tac [("x","x")] Rep_hypreal 1);
   8.251 +by Auto_tac;
   8.252 +qed "Rep_hypreal_nonempty";
   8.253 +
   8.254 +Addsimps [Rep_hypreal_nonempty];
   8.255 +
   8.256 +(*------------------------------------------------------------------------
   8.257 +   hypreal_of_real: the injection from real to hypreal
   8.258 + ------------------------------------------------------------------------*)
   8.259 +
   8.260 +Goal "inj(hypreal_of_real)";
   8.261 +by (rtac injI 1);
   8.262 +by (rewtac hypreal_of_real_def);
   8.263 +by (dtac (inj_on_Abs_hypreal RS inj_onD) 1);
   8.264 +by (REPEAT (rtac hyprel_in_hypreal 1));
   8.265 +by (dtac eq_equiv_class 1);
   8.266 +by (rtac equiv_hyprel 1);
   8.267 +by (Fast_tac 1);
   8.268 +by (rtac ccontr 1 THEN rotate_tac 1 1);
   8.269 +by Auto_tac;
   8.270 +qed "inj_hypreal_of_real";
   8.271 +
   8.272 +val [prem] = goal (the_context ())
   8.273 +    "(!!x y. z = Abs_hypreal(hyprel^^{x}) ==> P) ==> P";
   8.274 +by (res_inst_tac [("x1","z")] 
   8.275 +    (rewrite_rule [hypreal_def] Rep_hypreal RS quotientE) 1);
   8.276 +by (dres_inst_tac [("f","Abs_hypreal")] arg_cong 1);
   8.277 +by (res_inst_tac [("x","x")] prem 1);
   8.278 +by (asm_full_simp_tac (simpset() addsimps [Rep_hypreal_inverse]) 1);
   8.279 +qed "eq_Abs_hypreal";
   8.280 +
   8.281 +(**** hypreal_minus: additive inverse on hypreal ****)
   8.282 +
   8.283 +Goalw [congruent_def]
   8.284 +  "congruent hyprel (%X. hyprel^^{%n. - (X n)})";
   8.285 +by Safe_tac;
   8.286 +by (ALLGOALS Ultra_tac);
   8.287 +qed "hypreal_minus_congruent";
   8.288 +
   8.289 +Goalw [hypreal_minus_def]
   8.290 +   "- (Abs_hypreal(hyprel^^{%n. X n})) = Abs_hypreal(hyprel ^^ {%n. -(X n)})";
   8.291 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
   8.292 +by (simp_tac (simpset() addsimps 
   8.293 +      [hyprel_in_hypreal RS Abs_hypreal_inverse,
   8.294 +       [equiv_hyprel, hypreal_minus_congruent] MRS UN_equiv_class]) 1);
   8.295 +qed "hypreal_minus";
   8.296 +
   8.297 +Goal "- (- z) = (z::hypreal)";
   8.298 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.299 +by (asm_simp_tac (simpset() addsimps [hypreal_minus]) 1);
   8.300 +qed "hypreal_minus_minus";
   8.301 +
   8.302 +Addsimps [hypreal_minus_minus];
   8.303 +
   8.304 +Goal "inj(%r::hypreal. -r)";
   8.305 +by (rtac injI 1);
   8.306 +by (dres_inst_tac [("f","uminus")] arg_cong 1);
   8.307 +by (asm_full_simp_tac (simpset() addsimps [hypreal_minus_minus]) 1);
   8.308 +qed "inj_hypreal_minus";
   8.309 +
   8.310 +Goalw [hypreal_zero_def] "-0 = (0::hypreal)";
   8.311 +by (simp_tac (simpset() addsimps [hypreal_minus]) 1);
   8.312 +qed "hypreal_minus_zero";
   8.313 +Addsimps [hypreal_minus_zero];
   8.314 +
   8.315 +Goal "(-x = 0) = (x = (0::hypreal))"; 
   8.316 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.317 +by (auto_tac (claset(),
   8.318 +       simpset() addsimps [hypreal_zero_def, hypreal_minus, eq_commute] @ 
   8.319 +                          real_add_ac));
   8.320 +qed "hypreal_minus_zero_iff";
   8.321 +
   8.322 +Addsimps [hypreal_minus_zero_iff];
   8.323 +
   8.324 +
   8.325 +(**** hyperreal addition: hypreal_add  ****)
   8.326 +
   8.327 +Goalw [congruent2_def]
   8.328 +    "congruent2 hyprel (%X Y. hyprel^^{%n. X n + Y n})";
   8.329 +by Safe_tac;
   8.330 +by (ALLGOALS(Ultra_tac));
   8.331 +qed "hypreal_add_congruent2";
   8.332 +
   8.333 +Goalw [hypreal_add_def]
   8.334 +  "Abs_hypreal(hyprel^^{%n. X n}) + Abs_hypreal(hyprel^^{%n. Y n}) = \
   8.335 +\  Abs_hypreal(hyprel^^{%n. X n + Y n})";
   8.336 +by (simp_tac (simpset() addsimps 
   8.337 +         [[equiv_hyprel, hypreal_add_congruent2] MRS UN_equiv_class2]) 1);
   8.338 +qed "hypreal_add";
   8.339 +
   8.340 +Goal "Abs_hypreal(hyprel^^{%n. X n}) - Abs_hypreal(hyprel^^{%n. Y n}) = \
   8.341 +\     Abs_hypreal(hyprel^^{%n. X n - Y n})";
   8.342 +by (simp_tac (simpset() addsimps 
   8.343 +         [hypreal_diff_def, hypreal_minus,hypreal_add]) 1);
   8.344 +qed "hypreal_diff";
   8.345 +
   8.346 +Goal "(z::hypreal) + w = w + z";
   8.347 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.348 +by (res_inst_tac [("z","w")] eq_Abs_hypreal 1);
   8.349 +by (asm_simp_tac (simpset() addsimps (real_add_ac @ [hypreal_add])) 1);
   8.350 +qed "hypreal_add_commute";
   8.351 +
   8.352 +Goal "((z1::hypreal) + z2) + z3 = z1 + (z2 + z3)";
   8.353 +by (res_inst_tac [("z","z1")] eq_Abs_hypreal 1);
   8.354 +by (res_inst_tac [("z","z2")] eq_Abs_hypreal 1);
   8.355 +by (res_inst_tac [("z","z3")] eq_Abs_hypreal 1);
   8.356 +by (asm_simp_tac (simpset() addsimps [hypreal_add, real_add_assoc]) 1);
   8.357 +qed "hypreal_add_assoc";
   8.358 +
   8.359 +(*For AC rewriting*)
   8.360 +Goal "(x::hypreal)+(y+z)=y+(x+z)";
   8.361 +by (rtac (hypreal_add_commute RS trans) 1);
   8.362 +by (rtac (hypreal_add_assoc RS trans) 1);
   8.363 +by (rtac (hypreal_add_commute RS arg_cong) 1);
   8.364 +qed "hypreal_add_left_commute";
   8.365 +
   8.366 +(* hypreal addition is an AC operator *)
   8.367 +bind_thms ("hypreal_add_ac", [hypreal_add_assoc,hypreal_add_commute,
   8.368 +                      hypreal_add_left_commute]);
   8.369 +
   8.370 +Goalw [hypreal_zero_def] "(0::hypreal) + z = z";
   8.371 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.372 +by (asm_full_simp_tac (simpset() addsimps 
   8.373 +    [hypreal_add]) 1);
   8.374 +qed "hypreal_add_zero_left";
   8.375 +
   8.376 +Goal "z + (0::hypreal) = z";
   8.377 +by (simp_tac (simpset() addsimps 
   8.378 +    [hypreal_add_zero_left,hypreal_add_commute]) 1);
   8.379 +qed "hypreal_add_zero_right";
   8.380 +
   8.381 +Goalw [hypreal_zero_def] "z + -z = (0::hypreal)";
   8.382 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.383 +by (asm_full_simp_tac (simpset() addsimps [hypreal_minus, hypreal_add]) 1);
   8.384 +qed "hypreal_add_minus";
   8.385 +
   8.386 +Goal "-z + z = (0::hypreal)";
   8.387 +by (simp_tac (simpset() addsimps [hypreal_add_commute, hypreal_add_minus]) 1);
   8.388 +qed "hypreal_add_minus_left";
   8.389 +
   8.390 +Addsimps [hypreal_add_minus,hypreal_add_minus_left,
   8.391 +          hypreal_add_zero_left,hypreal_add_zero_right];
   8.392 +
   8.393 +Goal "EX y. (x::hypreal) + y = 0";
   8.394 +by (fast_tac (claset() addIs [hypreal_add_minus]) 1);
   8.395 +qed "hypreal_minus_ex";
   8.396 +
   8.397 +Goal "EX! y. (x::hypreal) + y = 0";
   8.398 +by (auto_tac (claset() addIs [hypreal_add_minus], simpset()));
   8.399 +by (dres_inst_tac [("f","%x. ya+x")] arg_cong 1);
   8.400 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   8.401 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
   8.402 +qed "hypreal_minus_ex1";
   8.403 +
   8.404 +Goal "EX! y. y + (x::hypreal) = 0";
   8.405 +by (auto_tac (claset() addIs [hypreal_add_minus_left], simpset()));
   8.406 +by (dres_inst_tac [("f","%x. x+ya")] arg_cong 1);
   8.407 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
   8.408 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
   8.409 +qed "hypreal_minus_left_ex1";
   8.410 +
   8.411 +Goal "x + y = (0::hypreal) ==> x = -y";
   8.412 +by (cut_inst_tac [("z","y")] hypreal_add_minus_left 1);
   8.413 +by (res_inst_tac [("x1","y")] (hypreal_minus_left_ex1 RS ex1E) 1);
   8.414 +by (Blast_tac 1);
   8.415 +qed "hypreal_add_minus_eq_minus";
   8.416 +
   8.417 +Goal "EX y::hypreal. x = -y";
   8.418 +by (cut_inst_tac [("x","x")] hypreal_minus_ex 1);
   8.419 +by (etac exE 1 THEN dtac hypreal_add_minus_eq_minus 1);
   8.420 +by (Fast_tac 1);
   8.421 +qed "hypreal_as_add_inverse_ex";
   8.422 +
   8.423 +Goal "-(x + (y::hypreal)) = -x + -y";
   8.424 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.425 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.426 +by (auto_tac (claset(),
   8.427 +              simpset() addsimps [hypreal_minus, hypreal_add,
   8.428 +                                  real_minus_add_distrib]));
   8.429 +qed "hypreal_minus_add_distrib";
   8.430 +Addsimps [hypreal_minus_add_distrib];
   8.431 +
   8.432 +Goal "-(y + -(x::hypreal)) = x + -y";
   8.433 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
   8.434 +qed "hypreal_minus_distrib1";
   8.435 +
   8.436 +Goal "(x + - (y::hypreal)) + (y + - z) = x + -z";
   8.437 +by (res_inst_tac [("w1","y")] (hypreal_add_commute RS subst) 1);
   8.438 +by (simp_tac (simpset() addsimps [hypreal_add_left_commute,
   8.439 +                                  hypreal_add_assoc]) 1);
   8.440 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
   8.441 +qed "hypreal_add_minus_cancel1";
   8.442 +
   8.443 +Goal "((x::hypreal) + y = x + z) = (y = z)";
   8.444 +by (Step_tac 1);
   8.445 +by (dres_inst_tac [("f","%t.-x + t")] arg_cong 1);
   8.446 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   8.447 +qed "hypreal_add_left_cancel";
   8.448 +
   8.449 +Goal "z + (x + (y + -z)) = x + (y::hypreal)";
   8.450 +by (simp_tac (simpset() addsimps hypreal_add_ac) 1);
   8.451 +qed "hypreal_add_minus_cancel2";
   8.452 +Addsimps [hypreal_add_minus_cancel2];
   8.453 +
   8.454 +Goal "y + -(x + y) = -(x::hypreal)";
   8.455 +by (Full_simp_tac 1);
   8.456 +by (rtac (hypreal_add_left_commute RS subst) 1);
   8.457 +by (Full_simp_tac 1);
   8.458 +qed "hypreal_add_minus_cancel";
   8.459 +Addsimps [hypreal_add_minus_cancel];
   8.460 +
   8.461 +Goal "y + -(y + x) = -(x::hypreal)";
   8.462 +by (simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   8.463 +qed "hypreal_add_minus_cancelc";
   8.464 +Addsimps [hypreal_add_minus_cancelc];
   8.465 +
   8.466 +Goal "(z + -x) + (y + -z) = (y + -(x::hypreal))";
   8.467 +by (full_simp_tac
   8.468 +    (simpset() addsimps [hypreal_minus_add_distrib RS sym, 
   8.469 +                         hypreal_add_left_cancel] @ hypreal_add_ac 
   8.470 +               delsimps [hypreal_minus_add_distrib]) 1); 
   8.471 +qed "hypreal_add_minus_cancel3";
   8.472 +Addsimps [hypreal_add_minus_cancel3];
   8.473 +
   8.474 +Goal "(y + (x::hypreal)= z + x) = (y = z)";
   8.475 +by (simp_tac (simpset() addsimps [hypreal_add_commute,
   8.476 +                                  hypreal_add_left_cancel]) 1);
   8.477 +qed "hypreal_add_right_cancel";
   8.478 +
   8.479 +Goal "z + (y + -z) = (y::hypreal)";
   8.480 +by (simp_tac (simpset() addsimps hypreal_add_ac) 1);
   8.481 +qed "hypreal_add_minus_cancel4";
   8.482 +Addsimps [hypreal_add_minus_cancel4];
   8.483 +
   8.484 +Goal "z + (w + (x + (-z + y))) = w + x + (y::hypreal)";
   8.485 +by (simp_tac (simpset() addsimps hypreal_add_ac) 1);
   8.486 +qed "hypreal_add_minus_cancel5";
   8.487 +Addsimps [hypreal_add_minus_cancel5];
   8.488 +
   8.489 +Goal "z + ((- z) + w) = (w::hypreal)";
   8.490 +by (simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   8.491 +qed "hypreal_add_minus_cancelA";
   8.492 +
   8.493 +Goal "(-z) + (z + w) = (w::hypreal)";
   8.494 +by (simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   8.495 +qed "hypreal_minus_add_cancelA";
   8.496 +
   8.497 +Addsimps [hypreal_add_minus_cancelA, hypreal_minus_add_cancelA];
   8.498 +
   8.499 +(**** hyperreal multiplication: hypreal_mult  ****)
   8.500 +
   8.501 +Goalw [congruent2_def]
   8.502 +    "congruent2 hyprel (%X Y. hyprel^^{%n. X n * Y n})";
   8.503 +by Safe_tac;
   8.504 +by (ALLGOALS(Ultra_tac));
   8.505 +qed "hypreal_mult_congruent2";
   8.506 +
   8.507 +Goalw [hypreal_mult_def]
   8.508 +  "Abs_hypreal(hyprel^^{%n. X n}) * Abs_hypreal(hyprel^^{%n. Y n}) = \
   8.509 +\  Abs_hypreal(hyprel^^{%n. X n * Y n})";
   8.510 +by (simp_tac (simpset() addsimps 
   8.511 +      [[equiv_hyprel, hypreal_mult_congruent2] MRS UN_equiv_class2]) 1);
   8.512 +qed "hypreal_mult";
   8.513 +
   8.514 +Goal "(z::hypreal) * w = w * z";
   8.515 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.516 +by (res_inst_tac [("z","w")] eq_Abs_hypreal 1);
   8.517 +by (asm_simp_tac (simpset() addsimps ([hypreal_mult] @ real_mult_ac)) 1);
   8.518 +qed "hypreal_mult_commute";
   8.519 +
   8.520 +Goal "((z1::hypreal) * z2) * z3 = z1 * (z2 * z3)";
   8.521 +by (res_inst_tac [("z","z1")] eq_Abs_hypreal 1);
   8.522 +by (res_inst_tac [("z","z2")] eq_Abs_hypreal 1);
   8.523 +by (res_inst_tac [("z","z3")] eq_Abs_hypreal 1);
   8.524 +by (asm_simp_tac (simpset() addsimps [hypreal_mult,real_mult_assoc]) 1);
   8.525 +qed "hypreal_mult_assoc";
   8.526 +
   8.527 +qed_goal "hypreal_mult_left_commute" (the_context ())
   8.528 +    "(z1::hypreal) * (z2 * z3) = z2 * (z1 * z3)"
   8.529 + (fn _ => [rtac (hypreal_mult_commute RS trans) 1, 
   8.530 +           rtac (hypreal_mult_assoc RS trans) 1,
   8.531 +           rtac (hypreal_mult_commute RS arg_cong) 1]);
   8.532 +
   8.533 +(* hypreal multiplication is an AC operator *)
   8.534 +bind_thms ("hypreal_mult_ac", [hypreal_mult_assoc, hypreal_mult_commute, 
   8.535 +                       hypreal_mult_left_commute]);
   8.536 +
   8.537 +Goalw [hypreal_one_def] "1hr * z = z";
   8.538 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.539 +by (asm_full_simp_tac (simpset() addsimps [hypreal_mult]) 1);
   8.540 +qed "hypreal_mult_1";
   8.541 +
   8.542 +Goal "z * 1hr = z";
   8.543 +by (simp_tac (simpset() addsimps [hypreal_mult_commute,
   8.544 +    hypreal_mult_1]) 1);
   8.545 +qed "hypreal_mult_1_right";
   8.546 +
   8.547 +Goalw [hypreal_zero_def] "0 * z = (0::hypreal)";
   8.548 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.549 +by (asm_full_simp_tac (simpset() addsimps [hypreal_mult,real_mult_0]) 1);
   8.550 +qed "hypreal_mult_0";
   8.551 +
   8.552 +Goal "z * 0 = (0::hypreal)";
   8.553 +by (simp_tac (simpset() addsimps [hypreal_mult_commute, hypreal_mult_0]) 1);
   8.554 +qed "hypreal_mult_0_right";
   8.555 +
   8.556 +Addsimps [hypreal_mult_0,hypreal_mult_0_right];
   8.557 +
   8.558 +Goal "-(x * y) = -x * (y::hypreal)";
   8.559 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.560 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.561 +by (auto_tac (claset(),
   8.562 +	      simpset() addsimps [hypreal_minus, hypreal_mult] 
   8.563 +                                 @ real_mult_ac @ real_add_ac));
   8.564 +qed "hypreal_minus_mult_eq1";
   8.565 +
   8.566 +Goal "-(x * y) = (x::hypreal) * -y";
   8.567 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.568 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.569 +by (auto_tac (claset(), simpset() addsimps [hypreal_minus, hypreal_mult] 
   8.570 +                                           @ real_mult_ac @ real_add_ac));
   8.571 +qed "hypreal_minus_mult_eq2";
   8.572 +
   8.573 +(*Pull negations out*)
   8.574 +Addsimps [hypreal_minus_mult_eq2 RS sym, hypreal_minus_mult_eq1 RS sym];
   8.575 +
   8.576 +Goal "-x*y = (x::hypreal)*-y";
   8.577 +by Auto_tac;
   8.578 +qed "hypreal_minus_mult_commute";
   8.579 +
   8.580 +(*-----------------------------------------------------------------------------
   8.581 +    A few more theorems
   8.582 + ----------------------------------------------------------------------------*)
   8.583 +Goal "(z::hypreal) + v = z' + v' ==> z + (v + w) = z' + (v' + w)";
   8.584 +by (asm_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
   8.585 +qed "hypreal_add_assoc_cong";
   8.586 +
   8.587 +Goal "(z::hypreal) + (v + w) = v + (z + w)";
   8.588 +by (REPEAT (ares_tac [hypreal_add_commute RS hypreal_add_assoc_cong] 1));
   8.589 +qed "hypreal_add_assoc_swap";
   8.590 +
   8.591 +Goal "((z1::hypreal) + z2) * w = (z1 * w) + (z2 * w)";
   8.592 +by (res_inst_tac [("z","z1")] eq_Abs_hypreal 1);
   8.593 +by (res_inst_tac [("z","z2")] eq_Abs_hypreal 1);
   8.594 +by (res_inst_tac [("z","w")] eq_Abs_hypreal 1);
   8.595 +by (asm_simp_tac (simpset() addsimps [hypreal_mult,hypreal_add,
   8.596 +     real_add_mult_distrib]) 1);
   8.597 +qed "hypreal_add_mult_distrib";
   8.598 +
   8.599 +val hypreal_mult_commute'= read_instantiate [("z","w")] hypreal_mult_commute;
   8.600 +
   8.601 +Goal "(w::hypreal) * (z1 + z2) = (w * z1) + (w * z2)";
   8.602 +by (simp_tac (simpset() addsimps [hypreal_mult_commute',hypreal_add_mult_distrib]) 1);
   8.603 +qed "hypreal_add_mult_distrib2";
   8.604 +
   8.605 +bind_thms ("hypreal_mult_simps", [hypreal_mult_1, hypreal_mult_1_right]);
   8.606 +Addsimps hypreal_mult_simps;
   8.607 +
   8.608 +(* 07/00 *)
   8.609 +
   8.610 +Goalw [hypreal_diff_def] "((z1::hypreal) - z2) * w = (z1 * w) - (z2 * w)";
   8.611 +by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib]) 1);
   8.612 +qed "hypreal_diff_mult_distrib";
   8.613 +
   8.614 +Goal "(w::hypreal) * (z1 - z2) = (w * z1) - (w * z2)";
   8.615 +by (simp_tac (simpset() addsimps [hypreal_mult_commute', 
   8.616 +				  hypreal_diff_mult_distrib]) 1);
   8.617 +qed "hypreal_diff_mult_distrib2";
   8.618 +
   8.619 +(*** one and zero are distinct ***)
   8.620 +Goalw [hypreal_zero_def,hypreal_one_def] "0 ~= 1hr";
   8.621 +by (auto_tac (claset(), simpset() addsimps [real_zero_not_eq_one]));
   8.622 +qed "hypreal_zero_not_eq_one";
   8.623 +
   8.624 +
   8.625 +(**** multiplicative inverse on hypreal ****)
   8.626 +
   8.627 +Goalw [congruent_def]
   8.628 +  "congruent hyprel (%X. hyprel^^{%n. if X n = #0 then #0 else inverse(X n)})";
   8.629 +by (Auto_tac THEN Ultra_tac 1);
   8.630 +qed "hypreal_inverse_congruent";
   8.631 +
   8.632 +Goalw [hypreal_inverse_def]
   8.633 +      "inverse (Abs_hypreal(hyprel^^{%n. X n})) = \
   8.634 +\      Abs_hypreal(hyprel ^^ {%n. if X n = #0 then #0 else inverse(X n)})";
   8.635 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
   8.636 +by (simp_tac (simpset() addsimps 
   8.637 +   [hyprel_in_hypreal RS Abs_hypreal_inverse,
   8.638 +    [equiv_hyprel, hypreal_inverse_congruent] MRS UN_equiv_class]) 1);
   8.639 +qed "hypreal_inverse";
   8.640 +
   8.641 +Goal "inverse 0 = (0::hypreal)";
   8.642 +by (simp_tac (simpset() addsimps [hypreal_inverse, hypreal_zero_def]) 1);
   8.643 +qed "HYPREAL_INVERSE_ZERO";
   8.644 +
   8.645 +Goal "a / (0::hypreal) = 0";
   8.646 +by (simp_tac
   8.647 +    (simpset() addsimps [hypreal_divide_def, HYPREAL_INVERSE_ZERO]) 1);
   8.648 +qed "HYPREAL_DIVISION_BY_ZERO";  (*NOT for adding to default simpset*)
   8.649 +
   8.650 +fun hypreal_div_undefined_case_tac s i =
   8.651 +  case_tac s i THEN 
   8.652 +  asm_simp_tac 
   8.653 +       (simpset() addsimps [HYPREAL_DIVISION_BY_ZERO, HYPREAL_INVERSE_ZERO]) i;
   8.654 +
   8.655 +Goal "inverse (inverse (z::hypreal)) = z";
   8.656 +by (hypreal_div_undefined_case_tac "z=0" 1);
   8.657 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
   8.658 +by (asm_full_simp_tac (simpset() addsimps 
   8.659 +                       [hypreal_inverse, hypreal_zero_def]) 1);
   8.660 +qed "hypreal_inverse_inverse";
   8.661 +Addsimps [hypreal_inverse_inverse];
   8.662 +
   8.663 +Goalw [hypreal_one_def] "inverse(1hr) = 1hr";
   8.664 +by (full_simp_tac (simpset() addsimps [hypreal_inverse,
   8.665 +                                       real_zero_not_eq_one RS not_sym]) 1);
   8.666 +qed "hypreal_inverse_1";
   8.667 +Addsimps [hypreal_inverse_1];
   8.668 +
   8.669 +
   8.670 +(*** existence of inverse ***)
   8.671 +
   8.672 +Goalw [hypreal_one_def,hypreal_zero_def] 
   8.673 +     "x ~= 0 ==> x*inverse(x) = 1hr";
   8.674 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.675 +by (rotate_tac 1 1);
   8.676 +by (asm_full_simp_tac (simpset() addsimps [hypreal_inverse, hypreal_mult]) 1);
   8.677 +by (dtac FreeUltrafilterNat_Compl_mem 1);
   8.678 +by (blast_tac (claset() addSIs [real_mult_inv_right,
   8.679 +    FreeUltrafilterNat_subset]) 1);
   8.680 +qed "hypreal_mult_inverse";
   8.681 +
   8.682 +Goal "x ~= 0 ==> inverse(x)*x = 1hr";
   8.683 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_inverse,
   8.684 +				      hypreal_mult_commute]) 1);
   8.685 +qed "hypreal_mult_inverse_left";
   8.686 +
   8.687 +Goal "(c::hypreal) ~= 0 ==> (c*a=c*b) = (a=b)";
   8.688 +by Auto_tac;
   8.689 +by (dres_inst_tac [("f","%x. x*inverse c")] arg_cong 1);
   8.690 +by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_inverse] @ hypreal_mult_ac)  1);
   8.691 +qed "hypreal_mult_left_cancel";
   8.692 +    
   8.693 +Goal "(c::hypreal) ~= 0 ==> (a*c=b*c) = (a=b)";
   8.694 +by (Step_tac 1);
   8.695 +by (dres_inst_tac [("f","%x. x*inverse c")] arg_cong 1);
   8.696 +by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_inverse] @ hypreal_mult_ac)  1);
   8.697 +qed "hypreal_mult_right_cancel";
   8.698 +
   8.699 +Goalw [hypreal_zero_def] "x ~= 0 ==> inverse (x::hypreal) ~= 0";
   8.700 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.701 +by (asm_full_simp_tac (simpset() addsimps [hypreal_inverse, hypreal_mult]) 1);
   8.702 +qed "hypreal_inverse_not_zero";
   8.703 +
   8.704 +Addsimps [hypreal_mult_inverse,hypreal_mult_inverse_left];
   8.705 +
   8.706 +Goal "[| x ~= 0; y ~= 0 |] ==> x * y ~= (0::hypreal)";
   8.707 +by (Step_tac 1);
   8.708 +by (dres_inst_tac [("f","%z. inverse x*z")] arg_cong 1);
   8.709 +by (asm_full_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym]) 1);
   8.710 +qed "hypreal_mult_not_0";
   8.711 +
   8.712 +Goal "x*y = (0::hypreal) ==> x = 0 | y = 0";
   8.713 +by (auto_tac (claset() addIs [ccontr] addDs [hypreal_mult_not_0],
   8.714 +              simpset()));
   8.715 +qed "hypreal_mult_zero_disj";
   8.716 +
   8.717 +Goal "inverse(-x) = -inverse(x::hypreal)";
   8.718 +by (hypreal_div_undefined_case_tac "x=0" 1);
   8.719 +by (rtac (hypreal_mult_right_cancel RS iffD1) 1);
   8.720 +by (stac hypreal_mult_inverse_left 2);
   8.721 +by Auto_tac;
   8.722 +qed "hypreal_minus_inverse";
   8.723 +
   8.724 +Goal "inverse(x*y) = inverse(x)*inverse(y::hypreal)";
   8.725 +by (hypreal_div_undefined_case_tac "x=0" 1);
   8.726 +by (hypreal_div_undefined_case_tac "y=0" 1);
   8.727 +by (forw_inst_tac [("y","y")] hypreal_mult_not_0 1 THEN assume_tac 1);
   8.728 +by (res_inst_tac [("c1","x")] (hypreal_mult_left_cancel RS iffD1) 1);
   8.729 +by (auto_tac (claset(), simpset() addsimps [hypreal_mult_assoc RS sym]));
   8.730 +by (res_inst_tac [("c1","y")] (hypreal_mult_left_cancel RS iffD1) 1);
   8.731 +by (auto_tac (claset(), simpset() addsimps [hypreal_mult_left_commute]));
   8.732 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym]) 1);
   8.733 +qed "hypreal_inverse_distrib";
   8.734 +
   8.735 +(*------------------------------------------------------------------
   8.736 +                   Theorems for ordering 
   8.737 + ------------------------------------------------------------------*)
   8.738 +
   8.739 +(* prove introduction and elimination rules for hypreal_less *)
   8.740 +
   8.741 +Goalw [hypreal_less_def]
   8.742 + "P < (Q::hypreal) = (EX X Y. X : Rep_hypreal(P) & \
   8.743 +\                             Y : Rep_hypreal(Q) & \
   8.744 +\                             {n. X n < Y n} : FreeUltrafilterNat)";
   8.745 +by (Fast_tac 1);
   8.746 +qed "hypreal_less_iff";
   8.747 +
   8.748 +Goalw [hypreal_less_def]
   8.749 + "[| {n. X n < Y n} : FreeUltrafilterNat; \
   8.750 +\         X : Rep_hypreal(P); \
   8.751 +\         Y : Rep_hypreal(Q) |] ==> P < (Q::hypreal)";
   8.752 +by (Fast_tac 1);
   8.753 +qed "hypreal_lessI";
   8.754 +
   8.755 +
   8.756 +Goalw [hypreal_less_def]
   8.757 +     "!! R1. [| R1 < (R2::hypreal); \
   8.758 +\         !!X Y. {n. X n < Y n} : FreeUltrafilterNat ==> P; \
   8.759 +\         !!X. X : Rep_hypreal(R1) ==> P; \ 
   8.760 +\         !!Y. Y : Rep_hypreal(R2) ==> P |] \
   8.761 +\     ==> P";
   8.762 +by Auto_tac;
   8.763 +qed "hypreal_lessE";
   8.764 +
   8.765 +Goalw [hypreal_less_def]
   8.766 + "R1 < (R2::hypreal) ==> (EX X Y. {n. X n < Y n} : FreeUltrafilterNat & \
   8.767 +\                                  X : Rep_hypreal(R1) & \
   8.768 +\                                  Y : Rep_hypreal(R2))";
   8.769 +by (Fast_tac 1);
   8.770 +qed "hypreal_lessD";
   8.771 +
   8.772 +Goal "~ (R::hypreal) < R";
   8.773 +by (res_inst_tac [("z","R")] eq_Abs_hypreal 1);
   8.774 +by (auto_tac (claset(), simpset() addsimps [hypreal_less_def]));
   8.775 +by (Ultra_tac 1);
   8.776 +qed "hypreal_less_not_refl";
   8.777 +
   8.778 +(*** y < y ==> P ***)
   8.779 +bind_thm("hypreal_less_irrefl",hypreal_less_not_refl RS notE);
   8.780 +AddSEs [hypreal_less_irrefl];
   8.781 +
   8.782 +Goal "!!(x::hypreal). x < y ==> x ~= y";
   8.783 +by (auto_tac (claset(), simpset() addsimps [hypreal_less_not_refl]));
   8.784 +qed "hypreal_not_refl2";
   8.785 +
   8.786 +Goal "!!(R1::hypreal). [| R1 < R2; R2 < R3 |] ==> R1 < R3";
   8.787 +by (res_inst_tac [("z","R1")] eq_Abs_hypreal 1);
   8.788 +by (res_inst_tac [("z","R2")] eq_Abs_hypreal 1);
   8.789 +by (res_inst_tac [("z","R3")] eq_Abs_hypreal 1);
   8.790 +by (auto_tac (claset() addSIs [exI], simpset() addsimps [hypreal_less_def]));
   8.791 +by (ultra_tac (claset() addIs [order_less_trans], simpset()) 1);
   8.792 +qed "hypreal_less_trans";
   8.793 +
   8.794 +Goal "!! (R1::hypreal). [| R1 < R2; R2 < R1 |] ==> P";
   8.795 +by (dtac hypreal_less_trans 1 THEN assume_tac 1);
   8.796 +by (asm_full_simp_tac (simpset() addsimps 
   8.797 +    [hypreal_less_not_refl]) 1);
   8.798 +qed "hypreal_less_asym";
   8.799 +
   8.800 +(*-------------------------------------------------------
   8.801 +  TODO: The following theorem should have been proved 
   8.802 +  first and then used througout the proofs as it probably 
   8.803 +  makes many of them more straightforward. 
   8.804 + -------------------------------------------------------*)
   8.805 +Goalw [hypreal_less_def]
   8.806 +      "(Abs_hypreal(hyprel^^{%n. X n}) < \
   8.807 +\           Abs_hypreal(hyprel^^{%n. Y n})) = \
   8.808 +\      ({n. X n < Y n} : FreeUltrafilterNat)";
   8.809 +by (auto_tac (claset() addSIs [lemma_hyprel_refl], simpset()));
   8.810 +by (Ultra_tac 1);
   8.811 +qed "hypreal_less";
   8.812 +
   8.813 +(*---------------------------------------------------------------------------------
   8.814 +             Hyperreals as a linearly ordered field
   8.815 + ---------------------------------------------------------------------------------*)
   8.816 +(*** sum order 
   8.817 +Goalw [hypreal_zero_def] 
   8.818 +      "[| 0 < x; 0 < y |] ==> (0::hypreal) < x + y";
   8.819 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.820 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.821 +by (auto_tac (claset(),simpset() addsimps
   8.822 +    [hypreal_less_def,hypreal_add]));
   8.823 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
   8.824 +    [hypreal_less_def,hypreal_add]));
   8.825 +by (ultra_tac (claset() addIs [real_add_order],simpset()) 1);
   8.826 +qed "hypreal_add_order";
   8.827 +***)
   8.828 +
   8.829 +(*** mult order 
   8.830 +Goalw [hypreal_zero_def] 
   8.831 +          "[| 0 < x; 0 < y |] ==> (0::hypreal) < x * y";
   8.832 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.833 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.834 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
   8.835 +    [hypreal_less_def,hypreal_mult]));
   8.836 +by (ultra_tac (claset() addIs [rename_numerals real_mult_order],
   8.837 +	       simpset()) 1);
   8.838 +qed "hypreal_mult_order";
   8.839 +****)
   8.840 +
   8.841 +
   8.842 +(*---------------------------------------------------------------------------------
   8.843 +                         Trichotomy of the hyperreals
   8.844 +  --------------------------------------------------------------------------------*)
   8.845 +
   8.846 +Goalw [hyprel_def] "EX x. x: hyprel ^^ {%n. #0}";
   8.847 +by (res_inst_tac [("x","%n. #0")] exI 1);
   8.848 +by (Step_tac 1);
   8.849 +by (auto_tac (claset() addSIs [FreeUltrafilterNat_Nat_set], simpset()));
   8.850 +qed "lemma_hyprel_0r_mem";
   8.851 +
   8.852 +Goalw [hypreal_zero_def]"0 <  x | x = 0 | x < (0::hypreal)";
   8.853 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.854 +by (auto_tac (claset(),simpset() addsimps [hypreal_less_def]));
   8.855 +by (cut_facts_tac [lemma_hyprel_0r_mem] 1 THEN etac exE 1);
   8.856 +by (dres_inst_tac [("x","xa")] spec 1);
   8.857 +by (dres_inst_tac [("x","x")] spec 1);
   8.858 +by (cut_inst_tac [("x","x")] lemma_hyprel_refl 1);
   8.859 +by Auto_tac;
   8.860 +by (dres_inst_tac [("x","x")] spec 1);
   8.861 +by (dres_inst_tac [("x","xa")] spec 1);
   8.862 +by Auto_tac;
   8.863 +by (Ultra_tac 1);
   8.864 +by (auto_tac (claset() addIs [real_linear_less2],simpset()));
   8.865 +qed "hypreal_trichotomy";
   8.866 +
   8.867 +val prems = Goal "[| (0::hypreal) < x ==> P; \
   8.868 +\                 x = 0 ==> P; \
   8.869 +\                 x < 0 ==> P |] ==> P";
   8.870 +by (cut_inst_tac [("x","x")] hypreal_trichotomy 1);
   8.871 +by (REPEAT (eresolve_tac (disjE::prems) 1));
   8.872 +qed "hypreal_trichotomyE";
   8.873 +
   8.874 +(*----------------------------------------------------------------------------
   8.875 +            More properties of <
   8.876 + ----------------------------------------------------------------------------*)
   8.877 +
   8.878 +Goal "((x::hypreal) < y) = (0 < y + -x)";
   8.879 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.880 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.881 +by (auto_tac (claset(),simpset() addsimps [hypreal_add,
   8.882 +    hypreal_zero_def,hypreal_minus,hypreal_less]));
   8.883 +by (ALLGOALS(Ultra_tac));
   8.884 +qed "hypreal_less_minus_iff"; 
   8.885 +
   8.886 +Goal "((x::hypreal) < y) = (x + -y < 0)";
   8.887 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   8.888 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   8.889 +by (auto_tac (claset(),simpset() addsimps [hypreal_add,
   8.890 +    hypreal_zero_def,hypreal_minus,hypreal_less]));
   8.891 +by (ALLGOALS(Ultra_tac));
   8.892 +qed "hypreal_less_minus_iff2";
   8.893 +
   8.894 +Goal "((x::hypreal) = y) = (x + - y = 0)";
   8.895 +by Auto_tac;
   8.896 +by (res_inst_tac [("x1","-y")] (hypreal_add_right_cancel RS iffD1) 1);
   8.897 +by Auto_tac;
   8.898 +qed "hypreal_eq_minus_iff"; 
   8.899 +
   8.900 +Goal "((x::hypreal) = y) = (0 = y + - x)";
   8.901 +by Auto_tac;
   8.902 +by (res_inst_tac [("x1","-x")] (hypreal_add_right_cancel RS iffD1) 1);
   8.903 +by Auto_tac;
   8.904 +qed "hypreal_eq_minus_iff2"; 
   8.905 +
   8.906 +(* 07/00 *)
   8.907 +Goal "(0::hypreal) - x = -x";
   8.908 +by (simp_tac (simpset() addsimps [hypreal_diff_def]) 1);
   8.909 +qed "hypreal_diff_zero";
   8.910 +
   8.911 +Goal "x - (0::hypreal) = x";
   8.912 +by (simp_tac (simpset() addsimps [hypreal_diff_def]) 1);
   8.913 +qed "hypreal_diff_zero_right";
   8.914 +
   8.915 +Goal "x - x = (0::hypreal)";
   8.916 +by (simp_tac (simpset() addsimps [hypreal_diff_def]) 1);
   8.917 +qed "hypreal_diff_self";
   8.918 +
   8.919 +Addsimps [hypreal_diff_zero, hypreal_diff_zero_right, hypreal_diff_self];
   8.920 +
   8.921 +Goal "(x = y + z) = (x + -z = (y::hypreal))";
   8.922 +by (auto_tac (claset(),simpset() addsimps [hypreal_add_assoc]));
   8.923 +qed "hypreal_eq_minus_iff3";
   8.924 +
   8.925 +Goal "(x ~= a) = (x + -a ~= (0::hypreal))";
   8.926 +by (auto_tac (claset() addDs [hypreal_eq_minus_iff RS iffD2],
   8.927 +              simpset())); 
   8.928 +qed "hypreal_not_eq_minus_iff";
   8.929 +
   8.930 +Goal "(x+y = (0::hypreal)) = (x = -y)";
   8.931 +by (stac hypreal_eq_minus_iff 1);
   8.932 +by Auto_tac;
   8.933 +qed "hypreal_add_eq_0_iff";
   8.934 +AddIffs [hypreal_add_eq_0_iff];
   8.935 +
   8.936 +
   8.937 +(*** linearity ***)
   8.938 +
   8.939 +Goal "(x::hypreal) < y | x = y | y < x";
   8.940 +by (stac hypreal_eq_minus_iff2 1);
   8.941 +by (res_inst_tac [("x1","x")] (hypreal_less_minus_iff RS ssubst) 1);
   8.942 +by (res_inst_tac [("x1","y")] (hypreal_less_minus_iff2 RS ssubst) 1);
   8.943 +by (rtac hypreal_trichotomyE 1);
   8.944 +by Auto_tac;
   8.945 +qed "hypreal_linear";
   8.946 +
   8.947 +Goal "((w::hypreal) ~= z) = (w<z | z<w)";
   8.948 +by (cut_facts_tac [hypreal_linear] 1);
   8.949 +by (Blast_tac 1);
   8.950 +qed "hypreal_neq_iff";
   8.951 +
   8.952 +Goal "!!(x::hypreal). [| x < y ==> P;  x = y ==> P; \
   8.953 +\          y < x ==> P |] ==> P";
   8.954 +by (cut_inst_tac [("x","x"),("y","y")] hypreal_linear 1);
   8.955 +by Auto_tac;
   8.956 +qed "hypreal_linear_less2";
   8.957 +
   8.958 +(*------------------------------------------------------------------------------
   8.959 +                            Properties of <=
   8.960 + ------------------------------------------------------------------------------*)
   8.961 +(*------ hypreal le iff reals le a.e ------*)
   8.962 +
   8.963 +Goalw [hypreal_le_def,real_le_def]
   8.964 +      "(Abs_hypreal(hyprel^^{%n. X n}) <= \
   8.965 +\           Abs_hypreal(hyprel^^{%n. Y n})) = \
   8.966 +\      ({n. X n <= Y n} : FreeUltrafilterNat)";
   8.967 +by (auto_tac (claset(),simpset() addsimps [hypreal_less]));
   8.968 +by (ALLGOALS(Ultra_tac));
   8.969 +qed "hypreal_le";
   8.970 +
   8.971 +(*---------------------------------------------------------*)
   8.972 +(*---------------------------------------------------------*)
   8.973 +Goalw [hypreal_le_def] 
   8.974 +     "~(w < z) ==> z <= (w::hypreal)";
   8.975 +by (assume_tac 1);
   8.976 +qed "hypreal_leI";
   8.977 +
   8.978 +Goalw [hypreal_le_def] 
   8.979 +      "z<=w ==> ~(w<(z::hypreal))";
   8.980 +by (assume_tac 1);
   8.981 +qed "hypreal_leD";
   8.982 +
   8.983 +bind_thm ("hypreal_leE", make_elim hypreal_leD);
   8.984 +
   8.985 +Goal "(~(w < z)) = (z <= (w::hypreal))";
   8.986 +by (fast_tac (claset() addSIs [hypreal_leI,hypreal_leD]) 1);
   8.987 +qed "hypreal_less_le_iff";
   8.988 +
   8.989 +Goalw [hypreal_le_def] "~ z <= w ==> w<(z::hypreal)";
   8.990 +by (Fast_tac 1);
   8.991 +qed "not_hypreal_leE";
   8.992 +
   8.993 +Goalw [hypreal_le_def] "!!(x::hypreal). x <= y ==> x < y | x = y";
   8.994 +by (cut_facts_tac [hypreal_linear] 1);
   8.995 +by (fast_tac (claset() addEs [hypreal_less_irrefl,hypreal_less_asym]) 1);
   8.996 +qed "hypreal_le_imp_less_or_eq";
   8.997 +
   8.998 +Goalw [hypreal_le_def] "z<w | z=w ==> z <=(w::hypreal)";
   8.999 +by (cut_facts_tac [hypreal_linear] 1);
  8.1000 +by (fast_tac (claset() addEs [hypreal_less_irrefl,hypreal_less_asym]) 1);
  8.1001 +qed "hypreal_less_or_eq_imp_le";
  8.1002 +
  8.1003 +Goal "(x <= (y::hypreal)) = (x < y | x=y)";
  8.1004 +by (REPEAT(ares_tac [iffI, hypreal_less_or_eq_imp_le, hypreal_le_imp_less_or_eq] 1));
  8.1005 +qed "hypreal_le_eq_less_or_eq";
  8.1006 +val hypreal_le_less = hypreal_le_eq_less_or_eq;
  8.1007 +
  8.1008 +Goal "w <= (w::hypreal)";
  8.1009 +by (simp_tac (simpset() addsimps [hypreal_le_eq_less_or_eq]) 1);
  8.1010 +qed "hypreal_le_refl";
  8.1011 +
  8.1012 +(* Axiom 'linorder_linear' of class 'linorder': *)
  8.1013 +Goal "(z::hypreal) <= w | w <= z";
  8.1014 +by (simp_tac (simpset() addsimps [hypreal_le_less]) 1);
  8.1015 +by (cut_facts_tac [hypreal_linear] 1);
  8.1016 +by (Blast_tac 1);
  8.1017 +qed "hypreal_le_linear";
  8.1018 +
  8.1019 +Goal "[| i <= j; j <= k |] ==> i <= (k::hypreal)";
  8.1020 +by (EVERY1 [dtac hypreal_le_imp_less_or_eq, dtac hypreal_le_imp_less_or_eq,
  8.1021 +            rtac hypreal_less_or_eq_imp_le, 
  8.1022 +            fast_tac (claset() addIs [hypreal_less_trans])]);
  8.1023 +qed "hypreal_le_trans";
  8.1024 +
  8.1025 +Goal "[| z <= w; w <= z |] ==> z = (w::hypreal)";
  8.1026 +by (EVERY1 [dtac hypreal_le_imp_less_or_eq, dtac hypreal_le_imp_less_or_eq,
  8.1027 +            fast_tac (claset() addEs [hypreal_less_irrefl,hypreal_less_asym])]);
  8.1028 +qed "hypreal_le_anti_sym";
  8.1029 +
  8.1030 +Goal "[| ~ y < x; y ~= x |] ==> x < (y::hypreal)";
  8.1031 +by (rtac not_hypreal_leE 1);
  8.1032 +by (fast_tac (claset() addDs [hypreal_le_imp_less_or_eq]) 1);
  8.1033 +qed "not_less_not_eq_hypreal_less";
  8.1034 +
  8.1035 +(* Axiom 'order_less_le' of class 'order': *)
  8.1036 +Goal "(w::hypreal) < z = (w <= z & w ~= z)";
  8.1037 +by (simp_tac (simpset() addsimps [hypreal_le_def, hypreal_neq_iff]) 1);
  8.1038 +by (blast_tac (claset() addIs [hypreal_less_asym]) 1);
  8.1039 +qed "hypreal_less_le";
  8.1040 +
  8.1041 +Goal "(0 < -R) = (R < (0::hypreal))";
  8.1042 +by (res_inst_tac [("z","R")] eq_Abs_hypreal 1);
  8.1043 +by (auto_tac (claset(),
  8.1044 +       simpset() addsimps [hypreal_zero_def, hypreal_less,hypreal_minus]));
  8.1045 +qed "hypreal_minus_zero_less_iff";
  8.1046 +Addsimps [hypreal_minus_zero_less_iff];
  8.1047 +
  8.1048 +Goal "(-R < 0) = ((0::hypreal) < R)";
  8.1049 +by (res_inst_tac [("z","R")] eq_Abs_hypreal 1);
  8.1050 +by (auto_tac (claset(),
  8.1051 +         simpset() addsimps [hypreal_zero_def, hypreal_less,hypreal_minus]));
  8.1052 +by (ALLGOALS(Ultra_tac));
  8.1053 +qed "hypreal_minus_zero_less_iff2";
  8.1054 +
  8.1055 +Goalw [hypreal_le_def] "((0::hypreal) <= -r) = (r <= (0::hypreal))";
  8.1056 +by (simp_tac (simpset() addsimps [hypreal_minus_zero_less_iff2]) 1);
  8.1057 +qed "hypreal_minus_zero_le_iff";
  8.1058 +Addsimps [hypreal_minus_zero_le_iff];
  8.1059 +
  8.1060 +(*----------------------------------------------------------
  8.1061 +  hypreal_of_real preserves field and order properties
  8.1062 + -----------------------------------------------------------*)
  8.1063 +Goalw [hypreal_of_real_def] 
  8.1064 +     "hypreal_of_real (z1 + z2) = hypreal_of_real z1 + hypreal_of_real z2";
  8.1065 +by (simp_tac (simpset() addsimps [hypreal_add, hypreal_add_mult_distrib]) 1);
  8.1066 +qed "hypreal_of_real_add";
  8.1067 +Addsimps [hypreal_of_real_add];
  8.1068 +
  8.1069 +Goalw [hypreal_of_real_def] 
  8.1070 +     "hypreal_of_real (z1 * z2) = hypreal_of_real z1 * hypreal_of_real z2";
  8.1071 +by (simp_tac (simpset() addsimps [hypreal_mult, hypreal_add_mult_distrib2]) 1);
  8.1072 +qed "hypreal_of_real_mult";
  8.1073 +Addsimps [hypreal_of_real_mult];
  8.1074 +
  8.1075 +Goalw [hypreal_less_def,hypreal_of_real_def] 
  8.1076 +     "(hypreal_of_real z1 <  hypreal_of_real z2) = (z1 < z2)";
  8.1077 +by Auto_tac;
  8.1078 +by (res_inst_tac [("x","%n. z1")] exI 2);
  8.1079 +by (Step_tac 1); 
  8.1080 +by (res_inst_tac [("x","%n. z2")] exI 3);
  8.1081 +by Auto_tac;
  8.1082 +by (rtac FreeUltrafilterNat_P 1);
  8.1083 +by (Ultra_tac 1);
  8.1084 +qed "hypreal_of_real_less_iff";
  8.1085 +Addsimps [hypreal_of_real_less_iff];
  8.1086 +
  8.1087 +Goalw [hypreal_le_def,real_le_def] 
  8.1088 +     "(hypreal_of_real z1 <= hypreal_of_real z2) = (z1 <= z2)";
  8.1089 +by Auto_tac;
  8.1090 +qed "hypreal_of_real_le_iff";
  8.1091 +Addsimps [hypreal_of_real_le_iff];
  8.1092 +
  8.1093 +Goal "(hypreal_of_real z1 = hypreal_of_real z2) = (z1 = z2)";
  8.1094 +by (force_tac (claset() addIs [order_antisym, hypreal_of_real_le_iff RS iffD1],
  8.1095 +               simpset()) 1); 
  8.1096 +qed "hypreal_of_real_eq_iff";
  8.1097 +Addsimps [hypreal_of_real_eq_iff];
  8.1098 +
  8.1099 +Goalw [hypreal_of_real_def] "hypreal_of_real (-r) = - hypreal_of_real  r";
  8.1100 +by (auto_tac (claset(),simpset() addsimps [hypreal_minus]));
  8.1101 +qed "hypreal_of_real_minus";
  8.1102 +Addsimps [hypreal_of_real_minus];
  8.1103 +
  8.1104 +(*DON'T insert this or the next one as default simprules.
  8.1105 +  They are used in both orientations and anyway aren't the ones we finally
  8.1106 +  need, which would use binary literals.*)
  8.1107 +Goalw [hypreal_of_real_def,hypreal_one_def] "hypreal_of_real  #1 = 1hr";
  8.1108 +by (Step_tac 1);
  8.1109 +qed "hypreal_of_real_one";
  8.1110 +
  8.1111 +Goalw [hypreal_of_real_def,hypreal_zero_def] "hypreal_of_real #0 = 0";
  8.1112 +by (Step_tac 1);
  8.1113 +qed "hypreal_of_real_zero";
  8.1114 +
  8.1115 +Goal "(hypreal_of_real r = 0) = (r = #0)";
  8.1116 +by (auto_tac (claset() addIs [FreeUltrafilterNat_P],
  8.1117 +    simpset() addsimps [hypreal_of_real_def,
  8.1118 +                        hypreal_zero_def,FreeUltrafilterNat_Nat_set]));
  8.1119 +qed "hypreal_of_real_zero_iff";
  8.1120 +
  8.1121 +Goal "hypreal_of_real (inverse r) = inverse (hypreal_of_real r)";
  8.1122 +by (case_tac "r=#0" 1);
  8.1123 +by (asm_simp_tac (simpset() addsimps [REAL_DIVIDE_ZERO, INVERSE_ZERO, 
  8.1124 +                              HYPREAL_INVERSE_ZERO, hypreal_of_real_zero]) 1);
  8.1125 +by (res_inst_tac [("c1","hypreal_of_real r")] 
  8.1126 +    (hypreal_mult_left_cancel RS iffD1) 1);
  8.1127 +by (stac (hypreal_of_real_mult RS sym) 2); 
  8.1128 +by (auto_tac (claset(), 
  8.1129 +         simpset() addsimps [hypreal_of_real_one, hypreal_of_real_zero_iff]));
  8.1130 +qed "hypreal_of_real_inverse";
  8.1131 +Addsimps [hypreal_of_real_inverse];
  8.1132 +
  8.1133 +Goal "hypreal_of_real (z1 / z2) = hypreal_of_real z1 / hypreal_of_real z2";
  8.1134 +by (simp_tac (simpset() addsimps [hypreal_divide_def, real_divide_def]) 1);
  8.1135 +qed "hypreal_of_real_divide"; 
  8.1136 +Addsimps [hypreal_of_real_divide];
  8.1137 +
  8.1138 +
  8.1139 +(*** Division lemmas ***)
  8.1140 +
  8.1141 +Goal "(0::hypreal)/x = 0";
  8.1142 +by (simp_tac (simpset() addsimps [hypreal_divide_def]) 1); 
  8.1143 +qed "hypreal_zero_divide";
  8.1144 +
  8.1145 +Goal "x/1hr = x";
  8.1146 +by (simp_tac (simpset() addsimps [hypreal_divide_def]) 1); 
  8.1147 +qed "hypreal_divide_one";
  8.1148 +Addsimps [hypreal_zero_divide, hypreal_divide_one];
  8.1149 +
  8.1150 +Goal "(x::hypreal) * (y/z) = (x*y)/z";
  8.1151 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_mult_assoc]) 1); 
  8.1152 +qed "hypreal_times_divide1_eq";
  8.1153 +
  8.1154 +Goal "(y/z) * (x::hypreal) = (y*x)/z";
  8.1155 +by (simp_tac (simpset() addsimps [hypreal_divide_def]@hypreal_mult_ac) 1); 
  8.1156 +qed "hypreal_times_divide2_eq";
  8.1157 +
  8.1158 +Addsimps [hypreal_times_divide1_eq, hypreal_times_divide2_eq];
  8.1159 +
  8.1160 +Goal "(x::hypreal) / (y/z) = (x*z)/y";
  8.1161 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_inverse_distrib]@
  8.1162 +                                 hypreal_mult_ac) 1); 
  8.1163 +qed "hypreal_divide_divide1_eq";
  8.1164 +
  8.1165 +Goal "((x::hypreal) / y) / z = x/(y*z)";
  8.1166 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_inverse_distrib, 
  8.1167 +                                  hypreal_mult_assoc]) 1); 
  8.1168 +qed "hypreal_divide_divide2_eq";
  8.1169 +
  8.1170 +Addsimps [hypreal_divide_divide1_eq, hypreal_divide_divide2_eq];
  8.1171 +
  8.1172 +(** As with multiplication, pull minus signs OUT of the / operator **)
  8.1173 +
  8.1174 +Goal "(-x) / (y::hypreal) = - (x/y)";
  8.1175 +by (simp_tac (simpset() addsimps [hypreal_divide_def]) 1); 
  8.1176 +qed "hypreal_minus_divide_eq";
  8.1177 +Addsimps [hypreal_minus_divide_eq];
  8.1178 +
  8.1179 +Goal "(x / -(y::hypreal)) = - (x/y)";
  8.1180 +by (simp_tac (simpset() addsimps [hypreal_divide_def, hypreal_minus_inverse]) 1); 
  8.1181 +qed "hypreal_divide_minus_eq";
  8.1182 +Addsimps [hypreal_divide_minus_eq];
  8.1183 +
  8.1184 +Goal "(x+y)/(z::hypreal) = x/z + y/z";
  8.1185 +by (simp_tac (simpset() addsimps [hypreal_divide_def, 
  8.1186 +                                  hypreal_add_mult_distrib]) 1); 
  8.1187 +qed "hypreal_add_divide_distrib";
  8.1188 +
  8.1189 +Goal "[|(x::hypreal) ~= 0;  y ~= 0 |]  \
  8.1190 +\     ==> inverse(x) + inverse(y) = (x + y)*inverse(x*y)";
  8.1191 +by (asm_full_simp_tac (simpset() addsimps [hypreal_inverse_distrib,
  8.1192 +                    hypreal_add_mult_distrib,hypreal_mult_assoc RS sym]) 1);
  8.1193 +by (stac hypreal_mult_assoc 1);
  8.1194 +by (rtac (hypreal_mult_left_commute RS subst) 1);
  8.1195 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
  8.1196 +qed "hypreal_inverse_add";
  8.1197 +
  8.1198 +Goal "x = -x ==> x = (0::hypreal)";
  8.1199 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  8.1200 +by (auto_tac (claset(), simpset() addsimps [hypreal_minus, hypreal_zero_def]));
  8.1201 +by (Ultra_tac 1);
  8.1202 +qed "hypreal_self_eq_minus_self_zero";
  8.1203 +
  8.1204 +Goal "(x + x = 0) = (x = (0::hypreal))";
  8.1205 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  8.1206 +by (auto_tac (claset(), simpset() addsimps [hypreal_add, hypreal_zero_def]));
  8.1207 +qed "hypreal_add_self_zero_cancel";
  8.1208 +Addsimps [hypreal_add_self_zero_cancel];
  8.1209 +
  8.1210 +Goal "(x + x + y = y) = (x = (0::hypreal))";
  8.1211 +by Auto_tac;
  8.1212 +by (dtac (hypreal_eq_minus_iff RS iffD1) 1);
  8.1213 +by (auto_tac (claset(), 
  8.1214 +     simpset() addsimps [hypreal_add_assoc, hypreal_self_eq_minus_self_zero]));
  8.1215 +qed "hypreal_add_self_zero_cancel2";
  8.1216 +Addsimps [hypreal_add_self_zero_cancel2];
  8.1217 +
  8.1218 +Goal "(x + (x + y) = y) = (x = (0::hypreal))";
  8.1219 +by (simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
  8.1220 +qed "hypreal_add_self_zero_cancel2a";
  8.1221 +Addsimps [hypreal_add_self_zero_cancel2a];
  8.1222 +
  8.1223 +Goal "(b = -a) = (-b = (a::hypreal))";
  8.1224 +by Auto_tac;
  8.1225 +qed "hypreal_minus_eq_swap";
  8.1226 +
  8.1227 +Goal "(-b = -a) = (b = (a::hypreal))";
  8.1228 +by (asm_full_simp_tac (simpset() addsimps 
  8.1229 +    [hypreal_minus_eq_swap]) 1);
  8.1230 +qed "hypreal_minus_eq_cancel";
  8.1231 +Addsimps [hypreal_minus_eq_cancel];
  8.1232 +
  8.1233 +Goal "x < x + 1hr";
  8.1234 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  8.1235 +by (auto_tac (claset(),
  8.1236 +              simpset() addsimps [hypreal_add, hypreal_one_def,hypreal_less]));
  8.1237 +qed "hypreal_less_self_add_one";
  8.1238 +Addsimps [hypreal_less_self_add_one];
  8.1239 +
  8.1240 +(*??DELETE MOST OF THE FOLLOWING??*)
  8.1241 +Goal "((x::hypreal) + x = y + y) = (x = y)";
  8.1242 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  8.1243 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  8.1244 +by (auto_tac (claset(),simpset() addsimps [hypreal_add]));
  8.1245 +by (ALLGOALS(Ultra_tac));
  8.1246 +qed "hypreal_add_self_cancel";
  8.1247 +Addsimps [hypreal_add_self_cancel];
  8.1248 +
  8.1249 +Goal "(y = x + - y + x) = (y = (x::hypreal))";
  8.1250 +by Auto_tac;
  8.1251 +by (dres_inst_tac [("x1","y")] 
  8.1252 +    (hypreal_add_right_cancel RS iffD2) 1);
  8.1253 +by (auto_tac (claset(),simpset() addsimps hypreal_add_ac));
  8.1254 +qed "hypreal_add_self_minus_cancel";
  8.1255 +Addsimps [hypreal_add_self_minus_cancel];
  8.1256 +
  8.1257 +Goal "(y = x + (- y + x)) = (y = (x::hypreal))";
  8.1258 +by (asm_full_simp_tac (simpset() addsimps 
  8.1259 +         [hypreal_add_assoc RS sym])1);
  8.1260 +qed "hypreal_add_self_minus_cancel2";
  8.1261 +Addsimps [hypreal_add_self_minus_cancel2];
  8.1262 +
  8.1263 +(* of course, can prove this by "transfer" as well *)
  8.1264 +Goal "z + -x = y + (y + (-x + -z)) = (y = (z::hypreal))";
  8.1265 +by Auto_tac;
  8.1266 +by (dres_inst_tac [("x1","z")] 
  8.1267 +    (hypreal_add_right_cancel RS iffD2) 1);
  8.1268 +by (asm_full_simp_tac (simpset() addsimps 
  8.1269 +    [hypreal_minus_add_distrib RS sym] @ hypreal_add_ac
  8.1270 +    delsimps [hypreal_minus_add_distrib]) 1);
  8.1271 +by (asm_full_simp_tac (simpset() addsimps 
  8.1272 +     [hypreal_add_assoc RS sym,hypreal_add_right_cancel]) 1);
  8.1273 +qed "hypreal_add_self_minus_cancel3";
  8.1274 +Addsimps [hypreal_add_self_minus_cancel3];
  8.1275 +
  8.1276 +Goalw [hypreal_diff_def] "(x<y) = (x-y < (0::hypreal))";
  8.1277 +by (rtac hypreal_less_minus_iff2 1);
  8.1278 +qed "hypreal_less_eq_diff";
  8.1279 +
  8.1280 +(*** Subtraction laws ***)
  8.1281 +
  8.1282 +Goal "x + (y - z) = (x + y) - (z::hypreal)";
  8.1283 +by (simp_tac (simpset() addsimps hypreal_diff_def::hypreal_add_ac) 1);
  8.1284 +qed "hypreal_add_diff_eq";
  8.1285 +
  8.1286 +Goal "(x - y) + z = (x + z) - (y::hypreal)";
  8.1287 +by (simp_tac (simpset() addsimps hypreal_diff_def::hypreal_add_ac) 1);
  8.1288 +qed "hypreal_diff_add_eq";
  8.1289 +
  8.1290 +Goal "(x - y) - z = x - (y + (z::hypreal))";
  8.1291 +by (simp_tac (simpset() addsimps hypreal_diff_def::hypreal_add_ac) 1);
  8.1292 +qed "hypreal_diff_diff_eq";
  8.1293 +
  8.1294 +Goal "x - (y - z) = (x + z) - (y::hypreal)";
  8.1295 +by (simp_tac (simpset() addsimps hypreal_diff_def::hypreal_add_ac) 1);
  8.1296 +qed "hypreal_diff_diff_eq2";
  8.1297 +
  8.1298 +Goal "(x-y < z) = (x < z + (y::hypreal))";
  8.1299 +by (stac hypreal_less_eq_diff 1);
  8.1300 +by (res_inst_tac [("y1", "z")] (hypreal_less_eq_diff RS ssubst) 1);
  8.1301 +by (simp_tac (simpset() addsimps hypreal_diff_def::hypreal_add_ac) 1);
  8.1302 +qed "hypreal_diff_less_eq";
  8.1303 +
  8.1304 +Goal "(x < z-y) = (x + (y::hypreal) < z)";
  8.1305 +by (stac hypreal_less_eq_diff 1);
  8.1306 +by (res_inst_tac [("y1", "z-y")] (hypreal_less_eq_diff RS ssubst) 1);
  8.1307 +by (simp_tac (simpset() addsimps hypreal_diff_def::hypreal_add_ac) 1);
  8.1308 +qed "hypreal_less_diff_eq";
  8.1309 +
  8.1310 +Goalw [hypreal_le_def] "(x-y <= z) = (x <= z + (y::hypreal))";
  8.1311 +by (simp_tac (simpset() addsimps [hypreal_less_diff_eq]) 1);
  8.1312 +qed "hypreal_diff_le_eq";
  8.1313 +
  8.1314 +Goalw [hypreal_le_def] "(x <= z-y) = (x + (y::hypreal) <= z)";
  8.1315 +by (simp_tac (simpset() addsimps [hypreal_diff_less_eq]) 1);
  8.1316 +qed "hypreal_le_diff_eq";
  8.1317 +
  8.1318 +Goalw [hypreal_diff_def] "(x-y = z) = (x = z + (y::hypreal))";
  8.1319 +by (auto_tac (claset(), simpset() addsimps [hypreal_add_assoc]));
  8.1320 +qed "hypreal_diff_eq_eq";
  8.1321 +
  8.1322 +Goalw [hypreal_diff_def] "(x = z-y) = (x + (y::hypreal) = z)";
  8.1323 +by (auto_tac (claset(), simpset() addsimps [hypreal_add_assoc]));
  8.1324 +qed "hypreal_eq_diff_eq";
  8.1325 +
  8.1326 +(*This list of rewrites simplifies (in)equalities by bringing subtractions
  8.1327 +  to the top and then moving negative terms to the other side.  
  8.1328 +  Use with hypreal_add_ac*)
  8.1329 +val hypreal_compare_rls = 
  8.1330 +  [symmetric hypreal_diff_def,
  8.1331 +   hypreal_add_diff_eq, hypreal_diff_add_eq, hypreal_diff_diff_eq, 
  8.1332 +   hypreal_diff_diff_eq2, 
  8.1333 +   hypreal_diff_less_eq, hypreal_less_diff_eq, hypreal_diff_le_eq, 
  8.1334 +   hypreal_le_diff_eq, hypreal_diff_eq_eq, hypreal_eq_diff_eq];
  8.1335 +
  8.1336 +
  8.1337 +(** For the cancellation simproc.
  8.1338 +    The idea is to cancel like terms on opposite sides by subtraction **)
  8.1339 +
  8.1340 +Goal "(x::hypreal) - y = x' - y' ==> (x<y) = (x'<y')";
  8.1341 +by (stac hypreal_less_eq_diff 1);
  8.1342 +by (res_inst_tac [("y1", "y")] (hypreal_less_eq_diff RS ssubst) 1);
  8.1343 +by (Asm_simp_tac 1);
  8.1344 +qed "hypreal_less_eqI";
  8.1345 +
  8.1346 +Goal "(x::hypreal) - y = x' - y' ==> (y<=x) = (y'<=x')";
  8.1347 +by (dtac hypreal_less_eqI 1);
  8.1348 +by (asm_simp_tac (simpset() addsimps [hypreal_le_def]) 1);
  8.1349 +qed "hypreal_le_eqI";
  8.1350 +
  8.1351 +Goal "(x::hypreal) - y = x' - y' ==> (x=y) = (x'=y')";
  8.1352 +by Safe_tac;
  8.1353 +by (ALLGOALS
  8.1354 +    (asm_full_simp_tac
  8.1355 +     (simpset() addsimps [hypreal_eq_diff_eq, hypreal_diff_eq_eq])));
  8.1356 +qed "hypreal_eq_eqI";
  8.1357 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/HOL/Hyperreal/HyperDef.thy	Sat Dec 30 22:03:47 2000 +0100
     9.3 @@ -0,0 +1,98 @@
     9.4 +(*  Title       : HOL/Real/Hyperreal/HyperDef.thy
     9.5 +    ID          : $Id$
     9.6 +    Author      : Jacques D. Fleuriot
     9.7 +    Copyright   : 1998  University of Cambridge
     9.8 +    Description : Construction of hyperreals using ultrafilters
     9.9 +*) 
    9.10 +
    9.11 +HyperDef = Filter + Real +
    9.12 +
    9.13 +consts 
    9.14 + 
    9.15 +    FreeUltrafilterNat   :: nat set set    ("\\<U>")
    9.16 +
    9.17 +defs
    9.18 +
    9.19 +    FreeUltrafilterNat_def
    9.20 +    "FreeUltrafilterNat    ==   (@U. U : FreeUltrafilter (UNIV:: nat set))"
    9.21 +
    9.22 +
    9.23 +constdefs
    9.24 +    hyprel :: "((nat=>real)*(nat=>real)) set"
    9.25 +    "hyprel == {p. ? X Y. p = ((X::nat=>real),Y) & 
    9.26 +                   {n::nat. X(n) = Y(n)}: FreeUltrafilterNat}"
    9.27 +
    9.28 +typedef hypreal = "UNIV//hyprel"   (Equiv.quotient_def)
    9.29 +
    9.30 +instance
    9.31 +   hypreal  :: {ord, zero, plus, times, minus, inverse}
    9.32 +
    9.33 +consts 
    9.34 +
    9.35 +  "1hr"       :: hypreal               ("1hr")  
    9.36 +  "whr"       :: hypreal               ("whr")  
    9.37 +  "ehr"       :: hypreal               ("ehr")  
    9.38 +
    9.39 +
    9.40 +defs
    9.41 +
    9.42 +  hypreal_zero_def
    9.43 +  "0 == Abs_hypreal(hyprel^^{%n::nat. (#0::real)})"
    9.44 +
    9.45 +  hypreal_one_def
    9.46 +  "1hr == Abs_hypreal(hyprel^^{%n::nat. (#1::real)})"
    9.47 +
    9.48 +  (* an infinite number = [<1,2,3,...>] *)
    9.49 +  omega_def
    9.50 +  "whr == Abs_hypreal(hyprel^^{%n::nat. real_of_posnat n})"
    9.51 +    
    9.52 +  (* an infinitesimal number = [<1,1/2,1/3,...>] *)
    9.53 +  epsilon_def
    9.54 +  "ehr == Abs_hypreal(hyprel^^{%n::nat. inverse (real_of_posnat n)})"
    9.55 +
    9.56 +  hypreal_minus_def
    9.57 +  "- P == Abs_hypreal(UN X: Rep_hypreal(P). hyprel^^{%n::nat. - (X n)})"
    9.58 +
    9.59 +  hypreal_diff_def 
    9.60 +  "x - y == x + -(y::hypreal)"
    9.61 +
    9.62 +  hypreal_inverse_def
    9.63 +  "inverse P == Abs_hypreal(UN X: Rep_hypreal(P). 
    9.64 +                    hyprel^^{%n. if X n = #0 then #0 else inverse (X n)})"
    9.65 +
    9.66 +  hypreal_divide_def
    9.67 +  "P / Q::hypreal == P * inverse Q"
    9.68 +  
    9.69 +constdefs
    9.70 +
    9.71 +  hypreal_of_real  :: real => hypreal                 
    9.72 +  "hypreal_of_real r         == Abs_hypreal(hyprel^^{%n::nat. r})"
    9.73 +  
    9.74 +  (* n::nat --> (n+1)::hypreal *)
    9.75 +  hypreal_of_posnat :: nat => hypreal                
    9.76 +  "hypreal_of_posnat n  == (hypreal_of_real(real_of_preal
    9.77 +                            (preal_of_prat(prat_of_pnat(pnat_of_nat n)))))"
    9.78 +
    9.79 +  hypreal_of_nat :: nat => hypreal                   
    9.80 +  "hypreal_of_nat n      == hypreal_of_posnat n + -1hr"
    9.81 +
    9.82 +defs 
    9.83 +
    9.84 +  hypreal_add_def  
    9.85 +  "P + Q == Abs_hypreal(UN X:Rep_hypreal(P). UN Y:Rep_hypreal(Q).
    9.86 +                hyprel^^{%n::nat. X n + Y n})"
    9.87 +
    9.88 +  hypreal_mult_def  
    9.89 +  "P * Q == Abs_hypreal(UN X:Rep_hypreal(P). UN Y:Rep_hypreal(Q).
    9.90 +                hyprel^^{%n::nat. X n * Y n})"
    9.91 +
    9.92 +  hypreal_less_def
    9.93 +  "P < (Q::hypreal) == EX X Y. X: Rep_hypreal(P) & 
    9.94 +                               Y: Rep_hypreal(Q) & 
    9.95 +                               {n::nat. X n < Y n} : FreeUltrafilterNat"
    9.96 +  hypreal_le_def
    9.97 +  "P <= (Q::hypreal) == ~(Q < P)" 
    9.98 +
    9.99 +end
   9.100 + 
   9.101 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/HOL/Hyperreal/HyperNat.ML	Sat Dec 30 22:03:47 2000 +0100
    10.3 @@ -0,0 +1,1335 @@
    10.4 +(*  Title       : HyperNat.ML
    10.5 +    Author      : Jacques D. Fleuriot
    10.6 +    Copyright   : 1998  University of Cambridge
    10.7 +    Description : Explicit construction of hypernaturals using 
    10.8 +                  ultrafilters
    10.9 +*) 
   10.10 +       
   10.11 +(*------------------------------------------------------------------------
   10.12 +                       Properties of hypnatrel
   10.13 + ------------------------------------------------------------------------*)
   10.14 +
   10.15 +(** Proving that hyprel is an equivalence relation       **)
   10.16 +(** Natural deduction for hypnatrel - similar to hyprel! **)
   10.17 +
   10.18 +Goalw [hypnatrel_def]
   10.19 +     "((X,Y): hypnatrel) = ({n. X n = Y n}: FreeUltrafilterNat)";
   10.20 +by (Fast_tac 1);
   10.21 +qed "hypnatrel_iff";
   10.22 +
   10.23 +Goalw [hypnatrel_def] 
   10.24 +     "{n. X n = Y n}: FreeUltrafilterNat ==> (X,Y): hypnatrel";
   10.25 +by (Fast_tac 1);
   10.26 +qed "hypnatrelI";
   10.27 +
   10.28 +Goalw [hypnatrel_def]
   10.29 +  "p: hypnatrel --> (EX X Y. \
   10.30 +\                 p = (X,Y) & {n. X n = Y n} : FreeUltrafilterNat)";
   10.31 +by (Fast_tac 1);
   10.32 +qed "hypnatrelE_lemma";
   10.33 +
   10.34 +val [major,minor] = Goal
   10.35 +  "[| p: hypnatrel;  \
   10.36 +\     !!X Y. [| p = (X,Y); {n. X n = Y n}: FreeUltrafilterNat |] \
   10.37 +\            ==> Q |] \
   10.38 +\  ==> Q";
   10.39 +by (cut_facts_tac [major RS (hypnatrelE_lemma RS mp)] 1);
   10.40 +by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1));
   10.41 +qed "hypnatrelE";
   10.42 +
   10.43 +AddSIs [hypnatrelI];
   10.44 +AddSEs [hypnatrelE];
   10.45 +
   10.46 +Goalw [hypnatrel_def] "(x,x): hypnatrel";
   10.47 +by (Auto_tac);
   10.48 +qed "hypnatrel_refl";
   10.49 +
   10.50 +Goalw [hypnatrel_def] "(x,y): hypnatrel --> (y,x):hypnatrel";
   10.51 +by (auto_tac (claset() addIs [lemma_perm RS subst], simpset()));
   10.52 +qed_spec_mp "hypnatrel_sym";
   10.53 +
   10.54 +Goalw [hypnatrel_def]
   10.55 +     "(x,y): hypnatrel --> (y,z):hypnatrel --> (x,z):hypnatrel";
   10.56 +by (Auto_tac);
   10.57 +by (Fuf_tac 1);
   10.58 +qed_spec_mp "hypnatrel_trans";
   10.59 +
   10.60 +Goalw [equiv_def, refl_def, sym_def, trans_def]
   10.61 +     "equiv UNIV hypnatrel";
   10.62 +by (auto_tac (claset() addSIs [hypnatrel_refl] 
   10.63 +                       addSEs [hypnatrel_sym,hypnatrel_trans] 
   10.64 +                       delrules [hypnatrelI,hypnatrelE],
   10.65 +              simpset()));
   10.66 +qed "equiv_hypnatrel";
   10.67 +
   10.68 +val equiv_hypnatrel_iff =
   10.69 +    [UNIV_I, UNIV_I] MRS (equiv_hypnatrel RS eq_equiv_class_iff);
   10.70 +
   10.71 +Goalw  [hypnat_def,hypnatrel_def,quotient_def] "hypnatrel^^{x}:hypnat";
   10.72 +by (Blast_tac 1);
   10.73 +qed "hypnatrel_in_hypnat";
   10.74 +
   10.75 +Goal "inj_on Abs_hypnat hypnat";
   10.76 +by (rtac inj_on_inverseI 1);
   10.77 +by (etac Abs_hypnat_inverse 1);
   10.78 +qed "inj_on_Abs_hypnat";
   10.79 +
   10.80 +Addsimps [equiv_hypnatrel_iff,inj_on_Abs_hypnat RS inj_on_iff,
   10.81 +          hypnatrel_iff, hypnatrel_in_hypnat, Abs_hypnat_inverse];
   10.82 +
   10.83 +Addsimps [equiv_hypnatrel RS eq_equiv_class_iff];
   10.84 +val eq_hypnatrelD = equiv_hypnatrel RSN (2,eq_equiv_class);
   10.85 +
   10.86 +Goal "inj(Rep_hypnat)";
   10.87 +by (rtac inj_inverseI 1);
   10.88 +by (rtac Rep_hypnat_inverse 1);
   10.89 +qed "inj_Rep_hypnat";
   10.90 +
   10.91 +Goalw [hypnatrel_def] "x: hypnatrel ^^ {x}";
   10.92 +by (Step_tac 1);
   10.93 +by (Auto_tac);
   10.94 +qed "lemma_hypnatrel_refl";
   10.95 +
   10.96 +Addsimps [lemma_hypnatrel_refl];
   10.97 +
   10.98 +Goalw [hypnat_def] "{} ~: hypnat";
   10.99 +by (auto_tac (claset() addSEs [quotientE],simpset()));
  10.100 +qed "hypnat_empty_not_mem";
  10.101 +
  10.102 +Addsimps [hypnat_empty_not_mem];
  10.103 +
  10.104 +Goal "Rep_hypnat x ~= {}";
  10.105 +by (cut_inst_tac [("x","x")] Rep_hypnat 1);
  10.106 +by (Auto_tac);
  10.107 +qed "Rep_hypnat_nonempty";
  10.108 +
  10.109 +Addsimps [Rep_hypnat_nonempty];
  10.110 +
  10.111 +(*------------------------------------------------------------------------
  10.112 +   hypnat_of_nat: the injection from nat to hypnat
  10.113 + ------------------------------------------------------------------------*)
  10.114 +Goal "inj(hypnat_of_nat)";
  10.115 +by (rtac injI 1);
  10.116 +by (rewtac hypnat_of_nat_def);
  10.117 +by (dtac (inj_on_Abs_hypnat RS inj_onD) 1);
  10.118 +by (REPEAT (rtac hypnatrel_in_hypnat 1));
  10.119 +by (dtac eq_equiv_class 1);
  10.120 +by (rtac equiv_hypnatrel 1);
  10.121 +by (Fast_tac 1);
  10.122 +by (rtac ccontr 1 THEN rotate_tac 1 1);
  10.123 +by (Auto_tac);
  10.124 +qed "inj_hypnat_of_nat";
  10.125 +
  10.126 +val [prem] = Goal
  10.127 +    "(!!x. z = Abs_hypnat(hypnatrel^^{x}) ==> P) ==> P";
  10.128 +by (res_inst_tac [("x1","z")] 
  10.129 +    (rewrite_rule [hypnat_def] Rep_hypnat RS quotientE) 1);
  10.130 +by (dres_inst_tac [("f","Abs_hypnat")] arg_cong 1);
  10.131 +by (res_inst_tac [("x","x")] prem 1);
  10.132 +by (asm_full_simp_tac (simpset() addsimps [Rep_hypnat_inverse]) 1);
  10.133 +qed "eq_Abs_hypnat";
  10.134 +
  10.135 +(*-----------------------------------------------------------
  10.136 +   Addition for hyper naturals: hypnat_add 
  10.137 + -----------------------------------------------------------*)
  10.138 +Goalw [congruent2_def]
  10.139 +     "congruent2 hypnatrel (%X Y. hypnatrel^^{%n. X n + Y n})";
  10.140 +by Safe_tac;
  10.141 +by (ALLGOALS(Fuf_tac));
  10.142 +qed "hypnat_add_congruent2";
  10.143 +
  10.144 +Goalw [hypnat_add_def]
  10.145 +  "Abs_hypnat(hypnatrel^^{%n. X n}) + Abs_hypnat(hypnatrel^^{%n. Y n}) = \
  10.146 +\  Abs_hypnat(hypnatrel^^{%n. X n + Y n})";
  10.147 +by (asm_simp_tac
  10.148 +    (simpset() addsimps [[equiv_hypnatrel, hypnat_add_congruent2] 
  10.149 +     MRS UN_equiv_class2]) 1);
  10.150 +qed "hypnat_add";
  10.151 +
  10.152 +Goal "(z::hypnat) + w = w + z";
  10.153 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.154 +by (res_inst_tac [("z","w")] eq_Abs_hypnat 1);
  10.155 +by (asm_simp_tac (simpset() addsimps (add_ac @ [hypnat_add])) 1);
  10.156 +qed "hypnat_add_commute";
  10.157 +
  10.158 +Goal "((z1::hypnat) + z2) + z3 = z1 + (z2 + z3)";
  10.159 +by (res_inst_tac [("z","z1")] eq_Abs_hypnat 1);
  10.160 +by (res_inst_tac [("z","z2")] eq_Abs_hypnat 1);
  10.161 +by (res_inst_tac [("z","z3")] eq_Abs_hypnat 1);
  10.162 +by (asm_simp_tac (simpset() addsimps [hypnat_add,add_assoc]) 1);
  10.163 +qed "hypnat_add_assoc";
  10.164 +
  10.165 +(*For AC rewriting*)
  10.166 +Goal "(x::hypnat)+(y+z)=y+(x+z)";
  10.167 +by (rtac (hypnat_add_commute RS trans) 1);
  10.168 +by (rtac (hypnat_add_assoc RS trans) 1);
  10.169 +by (rtac (hypnat_add_commute RS arg_cong) 1);
  10.170 +qed "hypnat_add_left_commute";
  10.171 +
  10.172 +(* hypnat addition is an AC operator *)
  10.173 +val hypnat_add_ac = [hypnat_add_assoc,hypnat_add_commute,
  10.174 +                      hypnat_add_left_commute];
  10.175 +
  10.176 +Goalw [hypnat_zero_def] "(0::hypnat) + z = z";
  10.177 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.178 +by (asm_full_simp_tac (simpset() addsimps [hypnat_add]) 1);
  10.179 +qed "hypnat_add_zero_left";
  10.180 +
  10.181 +Goal "z + (0::hypnat) = z";
  10.182 +by (simp_tac (simpset() addsimps 
  10.183 +    [hypnat_add_zero_left,hypnat_add_commute]) 1);
  10.184 +qed "hypnat_add_zero_right";
  10.185 +
  10.186 +Addsimps [hypnat_add_zero_left,hypnat_add_zero_right];
  10.187 +
  10.188 +(*-----------------------------------------------------------
  10.189 +   Subtraction for hyper naturals: hypnat_minus
  10.190 + -----------------------------------------------------------*)
  10.191 +Goalw [congruent2_def]
  10.192 +    "congruent2 hypnatrel (%X Y. hypnatrel^^{%n. X n - Y n})";
  10.193 +by Safe_tac;
  10.194 +by (ALLGOALS(Fuf_tac));
  10.195 +qed "hypnat_minus_congruent2";
  10.196 + 
  10.197 +Goalw [hypnat_minus_def]
  10.198 +  "Abs_hypnat(hypnatrel^^{%n. X n}) - Abs_hypnat(hypnatrel^^{%n. Y n}) = \
  10.199 +\  Abs_hypnat(hypnatrel^^{%n. X n - Y n})";
  10.200 +by (asm_simp_tac
  10.201 +    (simpset() addsimps [[equiv_hypnatrel, hypnat_minus_congruent2] 
  10.202 +     MRS UN_equiv_class2]) 1);
  10.203 +qed "hypnat_minus";
  10.204 +
  10.205 +Goalw [hypnat_zero_def] "z - z = (0::hypnat)";
  10.206 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.207 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus]) 1);
  10.208 +qed "hypnat_minus_zero";
  10.209 +
  10.210 +Goalw [hypnat_zero_def] "(0::hypnat) - n = 0";
  10.211 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.212 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus]) 1);
  10.213 +qed "hypnat_diff_0_eq_0";
  10.214 +
  10.215 +Addsimps [hypnat_minus_zero,hypnat_diff_0_eq_0];
  10.216 +
  10.217 +Goalw [hypnat_zero_def] "(m+n = (0::hypnat)) = (m=0 & n=0)";
  10.218 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.219 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.220 +by (auto_tac (claset() addIs [FreeUltrafilterNat_subset]
  10.221 +                       addDs [FreeUltrafilterNat_Int],
  10.222 +              simpset() addsimps [hypnat_add] ));
  10.223 +qed "hypnat_add_is_0";
  10.224 +
  10.225 +AddIffs [hypnat_add_is_0];
  10.226 +
  10.227 +Goal "!!i::hypnat. i-j-k = i - (j+k)";
  10.228 +by (res_inst_tac [("z","i")] eq_Abs_hypnat 1);
  10.229 +by (res_inst_tac [("z","j")] eq_Abs_hypnat 1);
  10.230 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
  10.231 +by (asm_full_simp_tac (simpset() addsimps 
  10.232 +    [hypnat_minus,hypnat_add,diff_diff_left]) 1);
  10.233 +qed "hypnat_diff_diff_left";
  10.234 +
  10.235 +Goal "!!i::hypnat. i-j-k = i-k-j";
  10.236 +by (simp_tac (simpset() addsimps 
  10.237 +    [hypnat_diff_diff_left, hypnat_add_commute]) 1);
  10.238 +qed "hypnat_diff_commute";
  10.239 +
  10.240 +Goal "!!n::hypnat. (n+m) - n = m";
  10.241 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.242 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.243 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus,hypnat_add]) 1);
  10.244 +qed "hypnat_diff_add_inverse";
  10.245 +Addsimps [hypnat_diff_add_inverse];
  10.246 +
  10.247 +Goal "!!n::hypnat.(m+n) - n = m";
  10.248 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.249 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.250 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus,hypnat_add]) 1);
  10.251 +qed "hypnat_diff_add_inverse2";
  10.252 +Addsimps [hypnat_diff_add_inverse2];
  10.253 +
  10.254 +Goal "!!k::hypnat. (k+m) - (k+n) = m - n";
  10.255 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.256 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.257 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
  10.258 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus,hypnat_add]) 1);
  10.259 +qed "hypnat_diff_cancel";
  10.260 +Addsimps [hypnat_diff_cancel];
  10.261 +
  10.262 +Goal "!!m::hypnat. (m+k) - (n+k) = m - n";
  10.263 +val hypnat_add_commute_k = read_instantiate [("w","k")] hypnat_add_commute;
  10.264 +by (asm_simp_tac (simpset() addsimps ([hypnat_add_commute_k])) 1);
  10.265 +qed "hypnat_diff_cancel2";
  10.266 +Addsimps [hypnat_diff_cancel2];
  10.267 +
  10.268 +Goalw [hypnat_zero_def] "!!n::hypnat. n - (n+m) = (0::hypnat)";
  10.269 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.270 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.271 +by (asm_full_simp_tac (simpset() addsimps [hypnat_minus,hypnat_add]) 1);
  10.272 +qed "hypnat_diff_add_0";
  10.273 +Addsimps [hypnat_diff_add_0];
  10.274 +
  10.275 +(*-----------------------------------------------------------
  10.276 +   Multiplication for hyper naturals: hypnat_mult
  10.277 + -----------------------------------------------------------*)
  10.278 +Goalw [congruent2_def]
  10.279 +    "congruent2 hypnatrel (%X Y. hypnatrel^^{%n. X n * Y n})";
  10.280 +by Safe_tac;
  10.281 +by (ALLGOALS(Fuf_tac));
  10.282 +qed "hypnat_mult_congruent2";
  10.283 +
  10.284 +Goalw [hypnat_mult_def]
  10.285 +  "Abs_hypnat(hypnatrel^^{%n. X n}) * Abs_hypnat(hypnatrel^^{%n. Y n}) = \
  10.286 +\  Abs_hypnat(hypnatrel^^{%n. X n * Y n})";
  10.287 +by (asm_simp_tac
  10.288 +    (simpset() addsimps [[equiv_hypnatrel,hypnat_mult_congruent2] MRS
  10.289 +     UN_equiv_class2]) 1);
  10.290 +qed "hypnat_mult";
  10.291 +
  10.292 +Goal "(z::hypnat) * w = w * z";
  10.293 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.294 +by (res_inst_tac [("z","w")] eq_Abs_hypnat 1);
  10.295 +by (asm_simp_tac (simpset() addsimps ([hypnat_mult] @ mult_ac)) 1);
  10.296 +qed "hypnat_mult_commute";
  10.297 +
  10.298 +Goal "((z1::hypnat) * z2) * z3 = z1 * (z2 * z3)";
  10.299 +by (res_inst_tac [("z","z1")] eq_Abs_hypnat 1);
  10.300 +by (res_inst_tac [("z","z2")] eq_Abs_hypnat 1);
  10.301 +by (res_inst_tac [("z","z3")] eq_Abs_hypnat 1);
  10.302 +by (asm_simp_tac (simpset() addsimps [hypnat_mult,mult_assoc]) 1);
  10.303 +qed "hypnat_mult_assoc";
  10.304 +
  10.305 +
  10.306 +Goal "(z1::hypnat) * (z2 * z3) = z2 * (z1 * z3)";
  10.307 +by (rtac (hypnat_mult_commute RS trans) 1);
  10.308 +by (rtac (hypnat_mult_assoc RS trans) 1);
  10.309 +by (rtac (hypnat_mult_commute RS arg_cong) 1);
  10.310 +qed "hypnat_mult_left_commute";
  10.311 +
  10.312 +(* hypnat multiplication is an AC operator *)
  10.313 +val hypnat_mult_ac = [hypnat_mult_assoc, hypnat_mult_commute, 
  10.314 +                      hypnat_mult_left_commute];
  10.315 +
  10.316 +Goalw [hypnat_one_def] "1hn * z = z";
  10.317 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.318 +by (asm_full_simp_tac (simpset() addsimps [hypnat_mult]) 1);
  10.319 +qed "hypnat_mult_1";
  10.320 +Addsimps [hypnat_mult_1];
  10.321 +
  10.322 +Goal "z * 1hn = z";
  10.323 +by (simp_tac (simpset() addsimps [hypnat_mult_commute]) 1);
  10.324 +qed "hypnat_mult_1_right";
  10.325 +Addsimps [hypnat_mult_1_right];
  10.326 +
  10.327 +Goalw [hypnat_zero_def] "(0::hypnat) * z = 0";
  10.328 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.329 +by (asm_full_simp_tac (simpset() addsimps [hypnat_mult]) 1);
  10.330 +qed "hypnat_mult_0";
  10.331 +Addsimps [hypnat_mult_0];
  10.332 +
  10.333 +Goal "z * (0::hypnat) = 0";
  10.334 +by (simp_tac (simpset() addsimps [hypnat_mult_commute]) 1);
  10.335 +qed "hypnat_mult_0_right";
  10.336 +Addsimps [hypnat_mult_0_right];
  10.337 +
  10.338 +Goal "!!m::hypnat. (m - n) * k = (m * k) - (n * k)";
  10.339 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.340 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.341 +by (res_inst_tac [("z","k")] eq_Abs_hypnat 1);
  10.342 +by (asm_simp_tac (simpset() addsimps [hypnat_mult,
  10.343 +    hypnat_minus,diff_mult_distrib]) 1);
  10.344 +qed "hypnat_diff_mult_distrib" ;
  10.345 +
  10.346 +Goal "!!m::hypnat. k * (m - n) = (k * m) - (k * n)";
  10.347 +val hypnat_mult_commute_k = read_instantiate [("z","k")] hypnat_mult_commute;
  10.348 +by (simp_tac (simpset() addsimps [hypnat_diff_mult_distrib, 
  10.349 +                                  hypnat_mult_commute_k]) 1);
  10.350 +qed "hypnat_diff_mult_distrib2" ;
  10.351 +
  10.352 +(*--------------------------
  10.353 +    A Few more theorems
  10.354 + -------------------------*)
  10.355 +
  10.356 +Goal "(z::hypnat) + v = z' + v' ==> z + (v + w) = z' + (v' + w)";
  10.357 +by (asm_simp_tac (simpset() addsimps [hypnat_add_assoc RS sym]) 1);
  10.358 +qed "hypnat_add_assoc_cong";
  10.359 +
  10.360 +Goal "(z::hypnat) + (v + w) = v + (z + w)";
  10.361 +by (REPEAT (ares_tac [hypnat_add_commute RS hypnat_add_assoc_cong] 1));
  10.362 +qed "hypnat_add_assoc_swap";
  10.363 +
  10.364 +Goal "((z1::hypnat) + z2) * w = (z1 * w) + (z2 * w)";
  10.365 +by (res_inst_tac [("z","z1")] eq_Abs_hypnat 1);
  10.366 +by (res_inst_tac [("z","z2")] eq_Abs_hypnat 1);
  10.367 +by (res_inst_tac [("z","w")] eq_Abs_hypnat 1);
  10.368 +by (asm_simp_tac (simpset() addsimps [hypnat_mult,hypnat_add,
  10.369 +                                      add_mult_distrib]) 1);
  10.370 +qed "hypnat_add_mult_distrib";
  10.371 +Addsimps [hypnat_add_mult_distrib];
  10.372 +
  10.373 +val hypnat_mult_commute'= read_instantiate [("z","w")] hypnat_mult_commute;
  10.374 +
  10.375 +Goal "(w::hypnat) * (z1 + z2) = (w * z1) + (w * z2)";
  10.376 +by (simp_tac (simpset() addsimps [hypnat_mult_commute']) 1);
  10.377 +qed "hypnat_add_mult_distrib2";
  10.378 +Addsimps [hypnat_add_mult_distrib2];
  10.379 +
  10.380 +(*** (hypnat) one and zero are distinct ***)
  10.381 +Goalw [hypnat_zero_def,hypnat_one_def] "(0::hypnat) ~= 1hn";
  10.382 +by (Auto_tac);
  10.383 +qed "hypnat_zero_not_eq_one";
  10.384 +Addsimps [hypnat_zero_not_eq_one];
  10.385 +Addsimps [hypnat_zero_not_eq_one RS not_sym];
  10.386 +
  10.387 +Goalw [hypnat_zero_def] "(m*n = (0::hypnat)) = (m=0 | n=0)";
  10.388 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.389 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.390 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
  10.391 +    simpset() addsimps [hypnat_mult]));
  10.392 +by (ALLGOALS(Fuf_tac));
  10.393 +qed "hypnat_mult_is_0";
  10.394 +Addsimps [hypnat_mult_is_0];
  10.395 +
  10.396 +(*------------------------------------------------------------------
  10.397 +                   Theorems for ordering 
  10.398 + ------------------------------------------------------------------*)
  10.399 +
  10.400 +(* prove introduction and elimination rules for hypnat_less *)
  10.401 +
  10.402 +Goalw [hypnat_less_def]
  10.403 + "P < (Q::hypnat) = (EX X Y. X : Rep_hypnat(P) & \
  10.404 +\                             Y : Rep_hypnat(Q) & \
  10.405 +\                             {n. X n < Y n} : FreeUltrafilterNat)";
  10.406 +by (Fast_tac 1);
  10.407 +qed "hypnat_less_iff";
  10.408 +
  10.409 +Goalw [hypnat_less_def]
  10.410 + "!!P. [| {n. X n < Y n} : FreeUltrafilterNat; \
  10.411 +\         X : Rep_hypnat(P); \
  10.412 +\         Y : Rep_hypnat(Q) |] ==> P < (Q::hypnat)";
  10.413 +by (Fast_tac 1);
  10.414 +qed "hypnat_lessI";
  10.415 +
  10.416 +Goalw [hypnat_less_def]
  10.417 +     "!! R1. [| R1 < (R2::hypnat); \
  10.418 +\         !!X Y. {n. X n < Y n} : FreeUltrafilterNat ==> P; \
  10.419 +\         !!X. X : Rep_hypnat(R1) ==> P; \ 
  10.420 +\         !!Y. Y : Rep_hypnat(R2) ==> P |] \
  10.421 +\     ==> P";
  10.422 +by (Auto_tac);
  10.423 +qed "hypnat_lessE";
  10.424 +
  10.425 +Goalw [hypnat_less_def]
  10.426 + "!!R1. R1 < (R2::hypnat) ==> (EX X Y. {n. X n < Y n} : FreeUltrafilterNat & \
  10.427 +\                                  X : Rep_hypnat(R1) & \
  10.428 +\                                  Y : Rep_hypnat(R2))";
  10.429 +by (Fast_tac 1);
  10.430 +qed "hypnat_lessD";
  10.431 +
  10.432 +Goal "~ (R::hypnat) < R";
  10.433 +by (res_inst_tac [("z","R")] eq_Abs_hypnat 1);
  10.434 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def]));
  10.435 +by (Fuf_empty_tac 1);
  10.436 +qed "hypnat_less_not_refl";
  10.437 +Addsimps [hypnat_less_not_refl];
  10.438 +
  10.439 +bind_thm("hypnat_less_irrefl",hypnat_less_not_refl RS notE);
  10.440 +
  10.441 +Goalw [hypnat_less_def,hypnat_zero_def] "~ n<(0::hypnat)";
  10.442 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.443 +by (Auto_tac);
  10.444 +by (Fuf_empty_tac 1);
  10.445 +qed "hypnat_not_less0";
  10.446 +AddIffs [hypnat_not_less0];
  10.447 +
  10.448 +(* n<(0::hypnat) ==> R *)
  10.449 +bind_thm ("hypnat_less_zeroE", hypnat_not_less0 RS notE);
  10.450 +
  10.451 +Goalw [hypnat_less_def,hypnat_zero_def,hypnat_one_def]
  10.452 +      "(n<1hn) = (n=0)";
  10.453 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.454 +by (auto_tac (claset() addSIs [exI] addEs 
  10.455 +    [FreeUltrafilterNat_subset],simpset()));
  10.456 +by (Fuf_tac 1);
  10.457 +qed "hypnat_less_one";
  10.458 +AddIffs [hypnat_less_one];
  10.459 +
  10.460 +Goal "!!(R1::hypnat). [| R1 < R2; R2 < R3 |] ==> R1 < R3";
  10.461 +by (res_inst_tac [("z","R1")] eq_Abs_hypnat 1);
  10.462 +by (res_inst_tac [("z","R2")] eq_Abs_hypnat 1);
  10.463 +by (res_inst_tac [("z","R3")] eq_Abs_hypnat 1);
  10.464 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def]));
  10.465 +by (res_inst_tac [("x","X")] exI 1);
  10.466 +by (Auto_tac);
  10.467 +by (res_inst_tac [("x","Ya")] exI 1);
  10.468 +by (Auto_tac);
  10.469 +by (Fuf_tac 1);
  10.470 +qed "hypnat_less_trans";
  10.471 +
  10.472 +Goal "!! (R1::hypnat). [| R1 < R2; R2 < R1 |] ==> P";
  10.473 +by (dtac hypnat_less_trans 1 THEN assume_tac 1);
  10.474 +by (Asm_full_simp_tac 1);
  10.475 +qed "hypnat_less_asym";
  10.476 +
  10.477 +(*----- hypnat less iff less a.e -----*)
  10.478 +(* See comments in HYPER for corresponding thm *)
  10.479 +
  10.480 +Goalw [hypnat_less_def]
  10.481 +      "(Abs_hypnat(hypnatrel^^{%n. X n}) < \
  10.482 +\           Abs_hypnat(hypnatrel^^{%n. Y n})) = \
  10.483 +\      ({n. X n < Y n} : FreeUltrafilterNat)";
  10.484 +by (auto_tac (claset() addSIs [lemma_hypnatrel_refl],simpset()));
  10.485 +by (Fuf_tac 1);
  10.486 +qed "hypnat_less";
  10.487 +
  10.488 +Goal "~ m<n --> n+(m-n) = (m::hypnat)";
  10.489 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.490 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  10.491 +by (auto_tac (claset(),simpset() addsimps 
  10.492 +    [hypnat_minus,hypnat_add,hypnat_less]));
  10.493 +by (dtac FreeUltrafilterNat_Compl_mem 1);
  10.494 +by (Fuf_tac 1);
  10.495 +qed_spec_mp "hypnat_add_diff_inverse";
  10.496 +
  10.497 +Goal "n<=m ==> n+(m-n) = (m::hypnat)";
  10.498 +by (asm_full_simp_tac (simpset() addsimps 
  10.499 +    [hypnat_add_diff_inverse, hypnat_le_def]) 1);
  10.500 +qed "hypnat_le_add_diff_inverse";
  10.501 +
  10.502 +Goal "n<=m ==> (m-n)+n = (m::hypnat)";
  10.503 +by (asm_simp_tac (simpset() addsimps [hypnat_le_add_diff_inverse, 
  10.504 +    hypnat_add_commute]) 1);
  10.505 +qed "hypnat_le_add_diff_inverse2";
  10.506 +
  10.507 +(*---------------------------------------------------------------------------------
  10.508 +                    Hyper naturals as a linearly ordered field
  10.509 + ---------------------------------------------------------------------------------*)
  10.510 +Goalw [hypnat_zero_def] 
  10.511 +     "[| (0::hypnat) < x; 0 < y |] ==> 0 < x + y";
  10.512 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  10.513 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
  10.514 +by (auto_tac (claset(),simpset() addsimps
  10.515 +   [hypnat_less_def,hypnat_add]));
  10.516 +by (REPEAT(Step_tac 1));
  10.517 +by (Fuf_tac 1);
  10.518 +qed "hypnat_add_order";
  10.519 +
  10.520 +Goalw [hypnat_zero_def] 
  10.521 +      "!!(x::hypnat). [| (0::hypnat) < x; 0 < y |] ==> 0 < x * y";
  10.522 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  10.523 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
  10.524 +by (auto_tac (claset(),simpset() addsimps 
  10.525 +    [hypnat_less_def,hypnat_mult]));
  10.526 +by (REPEAT(Step_tac 1));
  10.527 +by (Fuf_tac 1);
  10.528 +qed "hypnat_mult_order";
  10.529 +
  10.530 +(*---------------------------------------------------------------------------------
  10.531 +                   Trichotomy of the hyper naturals
  10.532 +  --------------------------------------------------------------------------------*)
  10.533 +Goalw [hypnatrel_def] "EX x. x: hypnatrel ^^ {%n. 0}";
  10.534 +by (res_inst_tac [("x","%n. 0")] exI 1);
  10.535 +by (Step_tac 1);
  10.536 +by (Auto_tac);
  10.537 +qed "lemma_hypnatrel_0_mem";
  10.538 +
  10.539 +(* linearity is actually proved further down! *)
  10.540 +Goalw [hypnat_zero_def,
  10.541 +       hypnat_less_def]"(0::hypnat) <  x | x = 0 | x < 0";
  10.542 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  10.543 +by (Auto_tac );
  10.544 +by (REPEAT(Step_tac 1));
  10.545 +by (REPEAT(dtac FreeUltrafilterNat_Compl_mem 1));
  10.546 +by (Fuf_tac 1);
  10.547 +qed "hypnat_trichotomy";
  10.548 +
  10.549 +Goal "!!x. [| (0::hypnat) < x ==> P; \
  10.550 +\                 x = 0 ==> P; \
  10.551 +\                 x < 0 ==> P |] ==> P";
  10.552 +by (cut_inst_tac [("x","x")] hypnat_trichotomy 1);
  10.553 +by (Auto_tac);
  10.554 +qed "hypnat_trichotomyE";
  10.555 +
  10.556 +(*------------------------------------------------------------------------------
  10.557 +            More properties of <
  10.558 + ------------------------------------------------------------------------------*)
  10.559 +Goal "!!(A::hypnat). A < B ==> A + C < B + C";
  10.560 +by (res_inst_tac [("z","A")] eq_Abs_hypnat 1);
  10.561 +by (res_inst_tac [("z","B")] eq_Abs_hypnat 1);
  10.562 +by (res_inst_tac [("z","C")] eq_Abs_hypnat 1);
  10.563 +by (auto_tac (claset(),simpset() addsimps 
  10.564 +    [hypnat_less_def,hypnat_add]));
  10.565 +by (REPEAT(Step_tac 1));
  10.566 +by (Fuf_tac 1);
  10.567 +qed "hypnat_add_less_mono1";
  10.568 +
  10.569 +Goal "!!(A::hypnat). A < B ==> C + A < C + B";
  10.570 +by (auto_tac (claset() addIs [hypnat_add_less_mono1],
  10.571 +    simpset() addsimps [hypnat_add_commute]));
  10.572 +qed "hypnat_add_less_mono2";
  10.573 +
  10.574 +Goal "!!k l::hypnat. [|i<j;  k<l |] ==> i + k < j + l";
  10.575 +by (etac (hypnat_add_less_mono1 RS hypnat_less_trans) 1);
  10.576 +by (simp_tac (simpset() addsimps [hypnat_add_commute]) 1);
  10.577 +(*j moves to the end because it is free while k, l are bound*)
  10.578 +by (etac hypnat_add_less_mono1 1);
  10.579 +qed "hypnat_add_less_mono";
  10.580 +
  10.581 +(*---------------------------------------
  10.582 +        hypnat_minus_less
  10.583 + ---------------------------------------*)
  10.584 +Goalw [hypnat_less_def,hypnat_zero_def] 
  10.585 +      "((x::hypnat) < y) = ((0::hypnat) < y - x)";
  10.586 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  10.587 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
  10.588 +by (auto_tac (claset(),simpset() addsimps 
  10.589 +    [hypnat_minus]));
  10.590 +by (REPEAT(Step_tac 1));
  10.591 +by (REPEAT(Step_tac 2));
  10.592 +by (ALLGOALS(fuf_tac (claset() addDs [sym],simpset())));
  10.593 +
  10.594 +(*** linearity ***)
  10.595 +Goalw [hypnat_less_def] "(x::hypnat) < y | x = y | y < x";
  10.596 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  10.597 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
  10.598 +by (Auto_tac );
  10.599 +by (REPEAT(Step_tac 1));
  10.600 +by (REPEAT(dtac FreeUltrafilterNat_Compl_mem 1));
  10.601 +by (Fuf_tac 1);
  10.602 +qed "hypnat_linear";
  10.603 +
  10.604 +Goal
  10.605 +    "!!(x::hypnat). [| x < y ==> P;  x = y ==> P; \
  10.606 +\          y < x ==> P |] ==> P";
  10.607 +by (cut_inst_tac [("x","x"),("y","y")] hypnat_linear 1);
  10.608 +by (Auto_tac);
  10.609 +qed "hypnat_linear_less2";
  10.610 +
  10.611 +(*------------------------------------------------------------------------------
  10.612 +                            Properties of <=
  10.613 + ------------------------------------------------------------------------------*)
  10.614 +(*------ hypnat le iff nat le a.e ------*)
  10.615 +Goalw [hypnat_le_def,le_def]
  10.616 +      "(Abs_hypnat(hypnatrel^^{%n. X n}) <= \
  10.617 +\           Abs_hypnat(hypnatrel^^{%n. Y n})) = \
  10.618 +\      ({n. X n <= Y n} : FreeUltrafilterNat)";
  10.619 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
  10.620 +    simpset() addsimps [hypnat_less]));
  10.621 +by (Fuf_tac 1 THEN Fuf_empty_tac 1);
  10.622 +qed "hypnat_le";
  10.623 +
  10.624 +(*---------------------------------------------------------*)
  10.625 +(*---------------------------------------------------------*)
  10.626 +Goalw [hypnat_le_def] "!!w. ~(w < z) ==> z <= (w::hypnat)";
  10.627 +by (assume_tac 1);
  10.628 +qed "hypnat_leI";
  10.629 +
  10.630 +Goalw [hypnat_le_def] "!!w. z<=w ==> ~(w<(z::hypnat))";
  10.631 +by (assume_tac 1);
  10.632 +qed "hypnat_leD";
  10.633 +
  10.634 +val hypnat_leE = make_elim hypnat_leD;
  10.635 +
  10.636 +Goal "!!w. (~(w < z)) = (z <= (w::hypnat))";
  10.637 +by (fast_tac (claset() addSIs [hypnat_leI,hypnat_leD]) 1);
  10.638 +qed "hypnat_less_le_iff";
  10.639 +
  10.640 +Goalw [hypnat_le_def] "!!z. ~ z <= w ==> w<(z::hypnat)";
  10.641 +by (Fast_tac 1);
  10.642 +qed "not_hypnat_leE";
  10.643 +
  10.644 +Goalw [hypnat_le_def] "!!z. z < w ==> z <= (w::hypnat)";
  10.645 +by (fast_tac (claset() addEs [hypnat_less_asym]) 1);
  10.646 +qed "hypnat_less_imp_le";
  10.647 +
  10.648 +Goalw [hypnat_le_def] "!!(x::hypnat). x <= y ==> x < y | x = y";
  10.649 +by (cut_facts_tac [hypnat_linear] 1);
  10.650 +by (fast_tac (claset() addEs [hypnat_less_irrefl,hypnat_less_asym]) 1);
  10.651 +qed "hypnat_le_imp_less_or_eq";
  10.652 +
  10.653 +Goalw [hypnat_le_def] "!!z. z<w | z=w ==> z <=(w::hypnat)";
  10.654 +by (cut_facts_tac [hypnat_linear] 1);
  10.655 +by (fast_tac (claset() addEs [hypnat_less_irrefl,hypnat_less_asym]) 1);
  10.656 +qed "hypnat_less_or_eq_imp_le";
  10.657 +
  10.658 +Goal "(x <= (y::hypnat)) = (x < y | x=y)";
  10.659 +by (REPEAT(ares_tac [iffI, hypnat_less_or_eq_imp_le, hypnat_le_imp_less_or_eq] 1));
  10.660 +qed "hypnat_le_eq_less_or_eq";
  10.661 +
  10.662 +Goal "w <= (w::hypnat)";
  10.663 +by (simp_tac (simpset() addsimps [hypnat_le_eq_less_or_eq]) 1);
  10.664 +qed "hypnat_le_refl";
  10.665 +Addsimps [hypnat_le_refl];
  10.666 +
  10.667 +val prems = goal thy "!!i. [| i <= j; j < k |] ==> i < (k::hypnat)";
  10.668 +by (dtac hypnat_le_imp_less_or_eq 1);
  10.669 +by (fast_tac (claset() addIs [hypnat_less_trans]) 1);
  10.670 +qed "hypnat_le_less_trans";
  10.671 +
  10.672 +Goal "!! (i::hypnat). [| i < j; j <= k |] ==> i < k";
  10.673 +by (dtac hypnat_le_imp_less_or_eq 1);
  10.674 +by (fast_tac (claset() addIs [hypnat_less_trans]) 1);
  10.675 +qed "hypnat_less_le_trans";
  10.676 +
  10.677 +Goal "!!i. [| i <= j; j <= k |] ==> i <= (k::hypnat)";
  10.678 +by (EVERY1 [dtac hypnat_le_imp_less_or_eq, dtac hypnat_le_imp_less_or_eq,
  10.679 +            rtac hypnat_less_or_eq_imp_le, fast_tac (claset() addIs [hypnat_less_trans])]);
  10.680 +qed "hypnat_le_trans";
  10.681 +
  10.682 +Goal "!!z. [| z <= w; w <= z |] ==> z = (w::hypnat)";
  10.683 +by (EVERY1 [dtac hypnat_le_imp_less_or_eq, dtac hypnat_le_imp_less_or_eq,
  10.684 +            fast_tac (claset() addEs [hypnat_less_irrefl,hypnat_less_asym])]);
  10.685 +qed "hypnat_le_anti_sym";
  10.686 +
  10.687 +Goal "!!x. [| ~ y < x; y ~= x |] ==> x < (y::hypnat)";
  10.688 +by (rtac not_hypnat_leE 1);
  10.689 +by (fast_tac (claset() addDs [hypnat_le_imp_less_or_eq]) 1);
  10.690 +qed "not_less_not_eq_hypnat_less";
  10.691 +
  10.692 +Goal "!!x. [| (0::hypnat) <= x; 0 <= y |] ==> 0 <= x * y";
  10.693 +by (REPEAT(dtac hypnat_le_imp_less_or_eq 1));
  10.694 +by (auto_tac (claset() addIs [hypnat_mult_order,
  10.695 +    hypnat_less_imp_le],simpset() addsimps [hypnat_le_refl]));
  10.696 +qed "hypnat_le_mult_order";
  10.697 +
  10.698 +Goalw [hypnat_one_def,hypnat_zero_def,hypnat_less_def] 
  10.699 +      "(0::hypnat) < 1hn";
  10.700 +by (res_inst_tac [("x","%n. 0")] exI 1);
  10.701 +by (res_inst_tac [("x","%n. 1")] exI 1);
  10.702 +by (Auto_tac);
  10.703 +qed "hypnat_zero_less_one";
  10.704 +
  10.705 +Goal "!!x. [| (0::hypnat) <= x; 0 <= y |] ==> 0 <= x + y";
  10.706 +by (REPEAT(dtac hypnat_le_imp_less_or_eq 1));
  10.707 +by (auto_tac (claset() addIs [hypnat_add_order,
  10.708 +    hypnat_less_imp_le],simpset() addsimps [hypnat_le_refl]));
  10.709 +qed "hypnat_le_add_order";
  10.710 +
  10.711 +Goal "!!(q1::hypnat). q1 <= q2  ==> x + q1 <= x + q2";
  10.712 +by (dtac hypnat_le_imp_less_or_eq 1);
  10.713 +by (Step_tac 1);
  10.714 +by (auto_tac (claset() addSIs [hypnat_le_refl,
  10.715 +    hypnat_less_imp_le,hypnat_add_less_mono1],
  10.716 +    simpset() addsimps [hypnat_add_commute]));
  10.717 +qed "hypnat_add_le_mono2";
  10.718 +
  10.719 +Goal "!!(q1::hypnat). q1 <= q2  ==> q1 + x <= q2 + x";
  10.720 +by (auto_tac (claset() addDs [hypnat_add_le_mono2],
  10.721 +    simpset() addsimps [hypnat_add_commute]));
  10.722 +qed "hypnat_add_le_mono1";
  10.723 +
  10.724 +Goal "!!k l::hypnat. [|i<=j;  k<=l |] ==> i + k <= j + l";
  10.725 +by (etac (hypnat_add_le_mono1 RS hypnat_le_trans) 1);
  10.726 +by (simp_tac (simpset() addsimps [hypnat_add_commute]) 1);
  10.727 +(*j moves to the end because it is free while k, l are bound*)
  10.728 +by (etac hypnat_add_le_mono1 1);
  10.729 +qed "hypnat_add_le_mono";
  10.730 +
  10.731 +Goalw [hypnat_zero_def]
  10.732 +     "!!x::hypnat. [| (0::hypnat) < z; x < y |] ==> x * z < y * z";
  10.733 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
  10.734 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
  10.735 +by (res_inst_tac [("z","z")] eq_Abs_hypnat 1);
  10.736 +by (auto_tac (claset(),simpset() addsimps 
  10.737 +    [hypnat_less,hypnat_mult]));
  10.738 +by (Fuf_tac 1);
  10.739 +qed "hypnat_mult_less_mono1";
  10.740 +
  10.741 +Goal "!!x::hypnat. [| 0 < z; x < y |] ==> z * x < z * y";
  10.742 +by (auto_tac (claset() addIs [hypnat_mult_less_mono1],
  10.743 +              simpset() addsimps [hypnat_mult_commute]));
  10.744 +qed "hypnat_mult_less_mono2";
  10.745 +
  10.746 +Addsimps [hypnat_mult_less_mono2,hypnat_mult_less_mono1];
  10.747 +
  10.748 +Goal "(x::hypnat) <= n + x";
  10.749 +by (res_inst_tac [("x","n")] hypnat_trichotomyE 1);
  10.750 +by (auto_tac (claset() addDs [(hypnat_less_imp_le RS
  10.751 +    hypnat_add_le_mono1)],simpset() addsimps [hypnat_le_refl]));
  10.752 +qed "hypnat_add_self_le";
  10.753 +Addsimps [hypnat_add_self_le];
  10.754 +
  10.755 +Goal "(x::hypnat) < x + 1hn";
  10.756 +by (cut_facts_tac [hypnat_zero_less_one 
  10.757 +         RS hypnat_add_less_mono2] 1);
  10.758 +by (Auto_tac);
  10.759 +qed "hypnat_add_one_self_less";
  10.760 +Addsimps [hypnat_add_one_self_less];
  10.761 +
  10.762 +Goalw [hypnat_le_def] "~ x + 1hn <= x";
  10.763 +by (Simp_tac 1);
  10.764 +qed "not_hypnat_add_one_le_self";
  10.765 +Addsimps [not_hypnat_add_one_le_self];
  10.766 +
  10.767 +Goal "((0::hypnat) < n) = (1hn <= n)";
  10.768 +by (res_inst_tac [("x","n")] hypnat_trichotomyE 1);
  10.769 +by (auto_tac (claset(),simpset() addsimps [hypnat_le_def]));
  10.770 +qed "hypnat_gt_zero_iff";
  10.771 +
  10.772 +Addsimps  [hypnat_le_add_diff_inverse, hypnat_le_add_diff_inverse2,
  10.773 +           hypnat_less_imp_le RS hypnat_le_add_diff_inverse2];
  10.774 +
  10.775 +Goal "(0 < n) = (EX m. n = m + 1hn)";
  10.776 +by (Step_tac 1);
  10.777 +by (res_inst_tac [("x","m")] hypnat_trichotomyE 2);
  10.778 +by (rtac hypnat_less_trans 2);
  10.779 +by (res_inst_tac [("x","n - 1hn")] exI 1);
  10.780 +by (auto_tac (claset(),simpset() addsimps 
  10.781 +    [hypnat_gt_zero_iff,hypnat_add_commute]));
  10.782 +qed "hypnat_gt_zero_iff2";
  10.783 +
  10.784 +Goalw [hypnat_zero_def] "(0::hypnat) <= n";
  10.785 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  10.786 +by (asm_simp_tac (simpset() addsimps [hypnat_le]) 1);
  10.787 +qed "hypnat_le_zero";
  10.788 +Addsimps [hypnat_le_zero];
  10.789 +
  10.790 +(*------------------------------------------------------------------
  10.791 +     hypnat_of_nat: properties embedding of naturals in hypernaturals
  10.792 + -----------------------------------------------------------------*)
  10.793 +    (** hypnat_of_nat preserves field and order properties **)
  10.794 +
  10.795 +Goalw [hypnat_of_nat_def] 
  10.796 +      "hypnat_of_nat ((z1::nat) + z2) = \
  10.797 +\      hypnat_of_nat z1 + hypnat_of_nat z2";
  10.798 +by (asm_simp_tac (simpset() addsimps [hypnat_add]) 1);
  10.799 +qed "hypnat_of_nat_add";
  10.800 +
  10.801 +Goalw [hypnat_of_nat_def] 
  10.802 +      "hypnat_of_nat ((z1::nat) - z2) = \
  10.803 +\      hypnat_of_nat z1 - hypnat_of_nat z2";
  10.804 +by (asm_simp_tac (simpset() addsimps [hypnat_minus]) 1);
  10.805 +qed "hypnat_of_nat_minus";
  10.806 +
  10.807 +Goalw [hypnat_of_nat_def] 
  10.808 +      "hypnat_of_nat (z1 * z2) = hypnat_of_nat z1 * hypnat_of_nat z2";
  10.809 +by (full_simp_tac (simpset() addsimps [hypnat_mult]) 1);
  10.810 +qed "hypnat_of_nat_mult";
  10.811 +
  10.812 +Goalw [hypnat_less_def,hypnat_of_nat_def] 
  10.813 +      "(z1 < z2) = (hypnat_of_nat z1 < hypnat_of_nat z2)";
  10.814 +by (auto_tac (claset() addSIs [exI] addIs 
  10.815 +   [FreeUltrafilterNat_all],simpset()));
  10.816 +by (rtac FreeUltrafilterNat_P 1 THEN Fuf_tac 1);
  10.817 +qed "hypnat_of_nat_less_iff";
  10.818 +Addsimps [hypnat_of_nat_less_iff RS sym];
  10.819 +
  10.820 +Goalw [hypnat_le_def,le_def] 
  10.821 +      "(z1 <= z2) = (hypnat_of_nat z1 <= hypnat_of_nat z2)";
  10.822 +by (Auto_tac);
  10.823 +qed "hypnat_of_nat_le_iff";
  10.824 +
  10.825 +Goalw [hypnat_of_nat_def,hypnat_one_def] "hypnat_of_nat  1 = 1hn";
  10.826 +by (Simp_tac 1);
  10.827 +qed "hypnat_of_nat_one";
  10.828 +
  10.829 +Goalw [hypnat_of_nat_def,hypnat_zero_def] "hypnat_of_nat  0 = 0";
  10.830 +by (Simp_tac 1);
  10.831 +qed "hypnat_of_nat_zero";
  10.832 +
  10.833 +Goal "(hypnat_of_nat  n = 0) = (n = 0)";
  10.834 +by (auto_tac (claset() addIs [FreeUltrafilterNat_P],
  10.835 +    simpset() addsimps [hypnat_of_nat_def,
  10.836 +    hypnat_zero_def]));
  10.837 +qed "hypnat_of_nat_zero_iff";
  10.838 +
  10.839 +Goal "(hypnat_of_nat  n ~= 0) = (n ~= 0)";
  10.840 +by (full_simp_tac (simpset() addsimps [hypnat_of_nat_zero_iff]) 1);
  10.841 +qed "hypnat_of_nat_not_zero_iff";
  10.842 +
  10.843 +goalw HyperNat.thy [hypnat_of_nat_def,hypnat_one_def]
  10.844 +      "hypnat_of_nat (Suc n) = hypnat_of_nat n + 1hn";
  10.845 +by (auto_tac (claset(),simpset() addsimps [hypnat_add]));
  10.846 +qed "hypnat_of_nat_Suc";
  10.847 +
  10.848 +(*---------------------------------------------------------------------------------
  10.849 +              Existence of infinite hypernatural number
  10.850 + ---------------------------------------------------------------------------------*)
  10.851 +
  10.852 +Goal "hypnatrel^^{%n::nat. n} : hypnat";
  10.853 +by (Auto_tac);
  10.854 +qed "hypnat_omega";
  10.855 +
  10.856 +Goalw [hypnat_omega_def] "Rep_hypnat(whn) : hypnat";
  10.857 +by (rtac Rep_hypnat 1);
  10.858 +qed "Rep_hypnat_omega";
  10.859 +
  10.860 +(* See Hyper.thy for similar argument*)
  10.861 +(* existence of infinite number not corresponding to any natural number *)
  10.862 +(* use assumption that member FreeUltrafilterNat is not finite       *)
  10.863 +(* a few lemmas first *)
  10.864 +
  10.865 +Goalw [hypnat_omega_def,hypnat_of_nat_def]
  10.866 +      "~ (EX x. hypnat_of_nat x = whn)";
  10.867 +by (auto_tac (claset() addDs [FreeUltrafilterNat_not_finite], 
  10.868 +              simpset()));
  10.869 +qed "not_ex_hypnat_of_nat_eq_omega";
  10.870 +
  10.871 +Goal "hypnat_of_nat x ~= whn";
  10.872 +by (cut_facts_tac [not_ex_hypnat_of_nat_eq_omega] 1);
  10.873 +by (Auto_tac);
  10.874 +qed "hypnat_of_nat_not_eq_omega";
  10.875 +Addsimps [hypnat_of_nat_not_eq_omega RS not_sym];
  10.876 +
  10.877 +(*-----------------------------------------------------------
  10.878 +    Properties of the set SHNat of embedded natural numbers
  10.879 +              (cf. set SReal in NSA.thy/NSA.ML)
  10.880 + ----------------------------------------------------------*)
  10.881 +
  10.882 +(* Infinite hypernatural not in embedded SHNat *)
  10.883 +Goalw [SHNat_def] "whn ~: SHNat";
  10.884 +by (Auto_tac);
  10.885 +qed "SHNAT_omega_not_mem";
  10.886 +Addsimps [SHNAT_omega_not_mem];
  10.887 +
  10.888 +(*-----------------------------------------------------------------------
  10.889 +     Closure laws for members of (embedded) set standard naturals SHNat
  10.890 + -----------------------------------------------------------------------*)
  10.891 +Goalw [SHNat_def] 
  10.892 +      "!!x. [| x: SHNat; y: SHNat |] ==> x + y: SHNat";
  10.893 +by (Step_tac 1);
  10.894 +by (res_inst_tac [("x","N + Na")] exI 1);
  10.895 +by (simp_tac (simpset() addsimps [hypnat_of_nat_add]) 1);
  10.896 +qed "SHNat_add";
  10.897 +
  10.898 +Goalw [SHNat_def] 
  10.899 +      "!!x. [| x: SHNat; y: SHNat |] ==> x - y: SHNat";
  10.900 +by (Step_tac 1);
  10.901 +by (res_inst_tac [("x","N - Na")] exI 1);
  10.902 +by (simp_tac (simpset() addsimps [hypnat_of_nat_minus]) 1);
  10.903 +qed "SHNat_minus";
  10.904 +
  10.905 +Goalw [SHNat_def] 
  10.906 +      "!!x. [| x: SHNat; y: SHNat |] ==> x * y: SHNat";
  10.907 +by (Step_tac 1);
  10.908 +by (res_inst_tac [("x","N * Na")] exI 1);
  10.909 +by (simp_tac (simpset() addsimps [hypnat_of_nat_mult]) 1);
  10.910 +qed "SHNat_mult";
  10.911 +
  10.912 +Goal "!!x. [| x + y : SHNat; y: SHNat |] ==> x: SHNat";
  10.913 +by (dres_inst_tac [("x","x+y")] SHNat_minus 1);
  10.914 +by (Auto_tac);
  10.915 +qed "SHNat_add_cancel";
  10.916 +
  10.917 +Goalw [SHNat_def] "hypnat_of_nat x : SHNat";
  10.918 +by (Blast_tac 1);
  10.919 +qed "SHNat_hypnat_of_nat";
  10.920 +Addsimps [SHNat_hypnat_of_nat];
  10.921 +
  10.922 +Goal "hypnat_of_nat 1 : SHNat";
  10.923 +by (Simp_tac 1);
  10.924 +qed "SHNat_hypnat_of_nat_one";
  10.925 +
  10.926 +Goal "hypnat_of_nat 0 : SHNat";
  10.927 +by (Simp_tac 1);
  10.928 +qed "SHNat_hypnat_of_nat_zero";
  10.929 +
  10.930 +Goal "1hn : SHNat";
  10.931 +by (simp_tac (simpset() addsimps [SHNat_hypnat_of_nat_one,
  10.932 +    hypnat_of_nat_one RS sym]) 1);
  10.933 +qed "SHNat_one";
  10.934 +
  10.935 +Goal "0 : SHNat";
  10.936 +by (simp_tac (simpset() addsimps [SHNat_hypnat_of_nat_zero,
  10.937 +    hypnat_of_nat_zero RS sym]) 1);
  10.938 +qed "SHNat_zero";
  10.939 +
  10.940 +Addsimps [SHNat_hypnat_of_nat_one,SHNat_hypnat_of_nat_zero,
  10.941 +          SHNat_one,SHNat_zero];
  10.942 +
  10.943 +Goal "1hn + 1hn : SHNat";
  10.944 +by (rtac ([SHNat_one,SHNat_one] MRS SHNat_add) 1);
  10.945 +qed "SHNat_two";
  10.946 +
  10.947 +Goalw [SHNat_def] "{x. hypnat_of_nat x : SHNat} = (UNIV::nat set)";
  10.948 +by (Auto_tac);
  10.949 +qed "SHNat_UNIV_nat";
  10.950 +
  10.951 +Goalw [SHNat_def] "(x: SHNat) = (EX y. x = hypnat_of_nat  y)";
  10.952 +by (Auto_tac);
  10.953 +qed "SHNat_iff";
  10.954 +
  10.955 +Goalw [SHNat_def] "hypnat_of_nat ``(UNIV::nat set) = SHNat";
  10.956 +by (Auto_tac);
  10.957 +qed "hypnat_of_nat_image";
  10.958 +
  10.959 +Goalw [SHNat_def] "inv hypnat_of_nat ``SHNat = (UNIV::nat set)";
  10.960 +by (Auto_tac);
  10.961 +by (rtac (inj_hypnat_of_nat RS inv_f_f RS subst) 1);
  10.962 +by (Blast_tac 1);
  10.963 +qed "inv_hypnat_of_nat_image";
  10.964 +
  10.965 +Goalw [SHNat_def] 
  10.966 +      "!!P. [| EX x. x: P; P <= SHNat |] ==> \
  10.967 +\           EX Q. P = hypnat_of_nat `` Q";
  10.968 +by (Best_tac 1); 
  10.969 +qed "SHNat_hypnat_of_nat_image";
  10.970 +
  10.971 +Goalw [SHNat_def] 
  10.972 +      "SHNat = hypnat_of_nat `` (UNIV::nat set)";
  10.973 +by (Auto_tac);
  10.974 +qed "SHNat_hypnat_of_nat_iff";
  10.975 +
  10.976 +Goalw [SHNat_def] "SHNat <= (UNIV::hypnat set)";
  10.977 +by (Auto_tac);
  10.978 +qed "SHNat_subset_UNIV";
  10.979 +
  10.980 +Goal "{n. n <= Suc m} = {n. n <= m} Un {n. n = Suc m}";
  10.981 +by (auto_tac (claset(),simpset() addsimps [le_Suc_eq]));
  10.982 +qed "leSuc_Un_eq";
  10.983 +
  10.984 +Goal "finite {n::nat. n <= m}";
  10.985 +by (nat_ind_tac "m" 1);
  10.986 +by (auto_tac (claset(),simpset() addsimps [leSuc_Un_eq]));
  10.987 +qed "finite_nat_le_segment";
  10.988 +
  10.989 +Goal "{n::nat. m < n} : FreeUltrafilterNat";
  10.990 +by (cut_inst_tac [("m2","m")] (finite_nat_le_segment RS 
  10.991 +    FreeUltrafilterNat_finite RS FreeUltrafilterNat_Compl_mem) 1);
  10.992 +by (Fuf_tac 1);
  10.993 +qed "lemma_unbounded_set";
  10.994 +Addsimps [lemma_unbounded_set];
  10.995 +
  10.996 +Goalw [SHNat_def,hypnat_of_nat_def,
  10.997 +           hypnat_less_def,hypnat_omega_def] 
  10.998 +           "ALL n: SHNat. n < whn";
  10.999 +by (Clarify_tac 1);
 10.1000 +by (auto_tac (claset() addSIs [exI],simpset()));
 10.1001 +qed "hypnat_omega_gt_SHNat";
 10.1002 +
 10.1003 +Goal "hypnat_of_nat n < whn";
 10.1004 +by (cut_facts_tac [hypnat_omega_gt_SHNat] 1);
 10.1005 +by (dres_inst_tac [("x","hypnat_of_nat n")] bspec 1);
 10.1006 +by (Auto_tac);
 10.1007 +qed "hypnat_of_nat_less_whn";
 10.1008 +Addsimps [hypnat_of_nat_less_whn];
 10.1009 +
 10.1010 +Goal "hypnat_of_nat n <= whn";
 10.1011 +by (rtac (hypnat_of_nat_less_whn RS hypnat_less_imp_le) 1);
 10.1012 +qed "hypnat_of_nat_le_whn";
 10.1013 +Addsimps [hypnat_of_nat_le_whn];
 10.1014 +
 10.1015 +Goal "0 < whn";
 10.1016 +by (rtac (hypnat_omega_gt_SHNat RS ballE) 1);
 10.1017 +by (Auto_tac);
 10.1018 +qed "hypnat_zero_less_hypnat_omega";
 10.1019 +Addsimps [hypnat_zero_less_hypnat_omega];
 10.1020 +
 10.1021 +Goal "1hn < whn";
 10.1022 +by (rtac (hypnat_omega_gt_SHNat RS ballE) 1);
 10.1023 +by (Auto_tac);
 10.1024 +qed "hypnat_one_less_hypnat_omega";
 10.1025 +Addsimps [hypnat_one_less_hypnat_omega];
 10.1026 +
 10.1027 +(*--------------------------------------------------------------------------
 10.1028 +     Theorems about infinite hypernatural numbers -- HNatInfinite
 10.1029 + -------------------------------------------------------------------------*)
 10.1030 +Goalw [HNatInfinite_def,SHNat_def] "whn : HNatInfinite";
 10.1031 +by (Auto_tac);
 10.1032 +qed "HNatInfinite_whn";
 10.1033 +Addsimps [HNatInfinite_whn];
 10.1034 +
 10.1035 +Goalw [HNatInfinite_def] "!!x. x: SHNat ==> x ~: HNatInfinite";
 10.1036 +by (Simp_tac 1);
 10.1037 +qed "SHNat_not_HNatInfinite";
 10.1038 +
 10.1039 +Goalw [HNatInfinite_def] "!!x. x ~: HNatInfinite ==> x: SHNat";
 10.1040 +by (Asm_full_simp_tac 1);
 10.1041 +qed "not_HNatInfinite_SHNat";
 10.1042 +
 10.1043 +Goalw [HNatInfinite_def] "!!x. x ~: SHNat ==> x: HNatInfinite";
 10.1044 +by (Simp_tac 1);
 10.1045 +qed "not_SHNat_HNatInfinite";
 10.1046 +
 10.1047 +Goalw [HNatInfinite_def] "!!x. x: HNatInfinite ==> x ~: SHNat";
 10.1048 +by (Asm_full_simp_tac 1);
 10.1049 +qed "HNatInfinite_not_SHNat";
 10.1050 +
 10.1051 +Goal "(x: SHNat) = (x ~: HNatInfinite)";
 10.1052 +by (blast_tac (claset() addSIs [SHNat_not_HNatInfinite,
 10.1053 +    not_HNatInfinite_SHNat]) 1);
 10.1054 +qed "SHNat_not_HNatInfinite_iff";
 10.1055 +
 10.1056 +Goal "(x ~: SHNat) = (x: HNatInfinite)";
 10.1057 +by (blast_tac (claset() addSIs [not_SHNat_HNatInfinite,
 10.1058 +    HNatInfinite_not_SHNat]) 1);
 10.1059 +qed "not_SHNat_HNatInfinite_iff";
 10.1060 +
 10.1061 +Goal "x : SHNat | x : HNatInfinite";
 10.1062 +by (simp_tac (simpset() addsimps [SHNat_not_HNatInfinite_iff]) 1);
 10.1063 +qed "SHNat_HNatInfinite_disj";
 10.1064 +
 10.1065 +(*-------------------------------------------------------------------
 10.1066 +   Proof of alternative definition for set of Infinite hypernatural 
 10.1067 +   numbers --- HNatInfinite = {N. ALL n: SHNat. n < N}
 10.1068 + -------------------------------------------------------------------*)
 10.1069 +Goal "!!N (xa::nat=>nat). \
 10.1070 +\         (ALL N. {n. xa n ~= N} : FreeUltrafilterNat) ==> \
 10.1071 +\         ({n. N < xa n} : FreeUltrafilterNat)";
 10.1072 +by (nat_ind_tac "N" 1);
 10.1073 +by (dres_inst_tac [("x","0")] spec 1);
 10.1074 +by (rtac ccontr 1 THEN dtac FreeUltrafilterNat_Compl_mem 1
 10.1075 +    THEN dtac FreeUltrafilterNat_Int 1 THEN assume_tac 1);
 10.1076 +by (Asm_full_simp_tac 1);
 10.1077 +by (dres_inst_tac [("x","Suc N")] spec 1);
 10.1078 +by (fuf_tac (claset() addSDs [Suc_leI],simpset() addsimps 
 10.1079 +    [le_eq_less_or_eq]) 1);
 10.1080 +qed "HNatInfinite_FreeUltrafilterNat_lemma";
 10.1081 +
 10.1082 +(*** alternative definition ***)
 10.1083 +Goalw [HNatInfinite_def,SHNat_def,hypnat_of_nat_def] 
 10.1084 +      "HNatInfinite = {N. ALL n:SHNat. n < N}";
 10.1085 +by (Step_tac 1);
 10.1086 +by (dres_inst_tac [("x","Abs_hypnat \
 10.1087 +\        (hypnatrel ^^ {%n. N})")] bspec 2);
 10.1088 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
 10.1089 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
 10.1090 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_iff]));
 10.1091 +by (auto_tac (claset() addSIs [exI] addEs 
 10.1092 +    [HNatInfinite_FreeUltrafilterNat_lemma],
 10.1093 +    simpset() addsimps [FreeUltrafilterNat_Compl_iff1, 
 10.1094 +     CLAIM "- {n. xa n = N} = {n. xa n ~= N}"]));
 10.1095 +qed "HNatInfinite_iff";
 10.1096 +
 10.1097 +(*--------------------------------------------------------------------
 10.1098 +   Alternative definition for HNatInfinite using Free ultrafilter
 10.1099 + --------------------------------------------------------------------*)
 10.1100 +Goal "!!x. x : HNatInfinite ==> EX X: Rep_hypnat x. \
 10.1101 +\          ALL u. {n. u < X n}:  FreeUltrafilterNat";
 10.1102 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def,
 10.1103 +    HNatInfinite_iff,SHNat_iff,hypnat_of_nat_def]));
 10.1104 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
 10.1105 +by (EVERY[Auto_tac, rtac bexI 1, 
 10.1106 +    rtac lemma_hypnatrel_refl 2, Step_tac 1]);
 10.1107 +by (dres_inst_tac [("x","hypnat_of_nat u")] bspec 1);
 10.1108 +by (Simp_tac 1);
 10.1109 +by (auto_tac (claset(),
 10.1110 +    simpset() addsimps [hypnat_of_nat_def]));
 10.1111 +by (Fuf_tac 1);
 10.1112 +qed "HNatInfinite_FreeUltrafilterNat";
 10.1113 +
 10.1114 +Goal "!!x. EX X: Rep_hypnat x. \
 10.1115 +\          ALL u. {n. u < X n}:  FreeUltrafilterNat \
 10.1116 +\          ==> x: HNatInfinite";
 10.1117 +by (auto_tac (claset(),simpset() addsimps [hypnat_less_def,
 10.1118 +    HNatInfinite_iff,SHNat_iff,hypnat_of_nat_def]));
 10.1119 +by (rtac exI 1 THEN Auto_tac);
 10.1120 +qed "FreeUltrafilterNat_HNatInfinite";
 10.1121 +
 10.1122 +Goal "!!x. (x : HNatInfinite) = (EX X: Rep_hypnat x. \
 10.1123 +\          ALL u. {n. u < X n}:  FreeUltrafilterNat)";
 10.1124 +by (blast_tac (claset() addIs [HNatInfinite_FreeUltrafilterNat,
 10.1125 +    FreeUltrafilterNat_HNatInfinite]) 1);
 10.1126 +qed "HNatInfinite_FreeUltrafilterNat_iff";
 10.1127 +
 10.1128 +Goal "!!x. x : HNatInfinite ==> 1hn < x";
 10.1129 +by (auto_tac (claset(),simpset() addsimps [HNatInfinite_iff]));
 10.1130 +qed "HNatInfinite_gt_one";
 10.1131 +Addsimps [HNatInfinite_gt_one];
 10.1132 +
 10.1133 +Goal "!!x. 0 ~: HNatInfinite";
 10.1134 +by (auto_tac (claset(),simpset() 
 10.1135 +    addsimps [HNatInfinite_iff]));
 10.1136 +by (dres_inst_tac [("a","1hn")] equals0D 1);
 10.1137 +by (Asm_full_simp_tac 1);
 10.1138 +qed "zero_not_mem_HNatInfinite";
 10.1139 +Addsimps [zero_not_mem_HNatInfinite];
 10.1140 +
 10.1141 +Goal "!!x. x : HNatInfinite ==> x ~= 0";
 10.1142 +by (Auto_tac);
 10.1143 +qed "HNatInfinite_not_eq_zero";
 10.1144 +
 10.1145 +Goal "!!x. x : HNatInfinite ==> 1hn <= x";
 10.1146 +by (blast_tac (claset() addIs [hypnat_less_imp_le,
 10.1147 +         HNatInfinite_gt_one]) 1);
 10.1148 +qed "HNatInfinite_ge_one";
 10.1149 +Addsimps [HNatInfinite_ge_one];
 10.1150 +
 10.1151 +(*--------------------------------------------------
 10.1152 +                   Closure Rules
 10.1153 + --------------------------------------------------*)
 10.1154 +Goal "!!x. [| x: HNatInfinite; y: HNatInfinite |] \
 10.1155 +\           ==> x + y: HNatInfinite";
 10.1156 +by (auto_tac (claset(),simpset() addsimps [HNatInfinite_iff]));
 10.1157 +by (dtac bspec 1 THEN assume_tac 1);
 10.1158 +by (dtac (SHNat_zero RSN (2,bspec)) 1);
 10.1159 +by (dtac hypnat_add_less_mono 1 THEN assume_tac 1);
 10.1160 +by (Asm_full_simp_tac 1);
 10.1161 +qed "HNatInfinite_add";
 10.1162 +
 10.1163 +Goal "!!x. [| x: HNatInfinite; y: SHNat |] \
 10.1164 +\                       ==> x + y: HNatInfinite";
 10.1165 +by (rtac ccontr 1 THEN dtac not_HNatInfinite_SHNat 1);
 10.1166 +by (dres_inst_tac [("x","x + y")] SHNat_minus 1);
 10.1167 +by (auto_tac (claset(),simpset() addsimps 
 10.1168 +    [SHNat_not_HNatInfinite_iff]));
 10.1169 +qed "HNatInfinite_SHNat_add";
 10.1170 +
 10.1171 +goal HyperNat.thy "!!x. [| x: HNatInfinite; y: SHNat |] \
 10.1172 +\                       ==> x - y: HNatInfinite";
 10.1173 +by (rtac ccontr 1 THEN dtac not_HNatInfinite_SHNat 1);
 10.1174 +by (dres_inst_tac [("x","x - y")] SHNat_add 1);
 10.1175 +by (subgoal_tac "y <= x" 2);
 10.1176 +by (auto_tac (claset() addSDs [hypnat_le_add_diff_inverse2],
 10.1177 +    simpset() addsimps [not_SHNat_HNatInfinite_iff RS sym]));
 10.1178 +by (auto_tac (claset() addSIs [hypnat_less_imp_le],
 10.1179 +    simpset() addsimps [not_SHNat_HNatInfinite_iff,HNatInfinite_iff]));
 10.1180 +qed "HNatInfinite_SHNat_diff";
 10.1181 +
 10.1182 +Goal 
 10.1183 +     "!!x. x: HNatInfinite ==> x + 1hn: HNatInfinite";
 10.1184 +by (auto_tac (claset() addIs [HNatInfinite_SHNat_add],
 10.1185 +              simpset()));
 10.1186 +qed "HNatInfinite_add_one";
 10.1187 +
 10.1188 +Goal 
 10.1189 +     "!!x. x: HNatInfinite ==> x - 1hn: HNatInfinite";
 10.1190 +by (rtac ccontr 1 THEN dtac not_HNatInfinite_SHNat 1);
 10.1191 +by (dres_inst_tac [("x","x - 1hn"),("y","1hn")] SHNat_add 1);
 10.1192 +by (auto_tac (claset(),simpset() addsimps 
 10.1193 +    [not_SHNat_HNatInfinite_iff RS sym]));
 10.1194 +qed "HNatInfinite_minus_one";
 10.1195 +
 10.1196 +Goal "!!x. x : HNatInfinite ==> EX y. x = y + 1hn";
 10.1197 +by (res_inst_tac [("x","x - 1hn")] exI 1);
 10.1198 +by (Auto_tac);
 10.1199 +qed "HNatInfinite_is_Suc";
 10.1200 +
 10.1201 +(*---------------------------------------------------------------
 10.1202 +       HNat : the hypernaturals embedded in the hyperreals
 10.1203 +       Obtained using the NS extension of the naturals
 10.1204 + --------------------------------------------------------------*)
 10.1205 + 
 10.1206 +Goalw [HNat_def,starset_def,
 10.1207 +         hypreal_of_posnat_def,hypreal_of_real_def] 
 10.1208 +         "hypreal_of_posnat N : HNat";
 10.1209 +by (Auto_tac);
 10.1210 +by (Ultra_tac 1);
 10.1211 +by (res_inst_tac [("x","Suc N")] exI 1);
 10.1212 +by (dtac sym 1 THEN auto_tac (claset(),simpset() 
 10.1213 +    addsimps [real_of_preal_real_of_nat_Suc]));
 10.1214 +qed "HNat_hypreal_of_posnat";
 10.1215 +Addsimps [HNat_hypreal_of_posnat];
 10.1216 +
 10.1217 +Goalw [HNat_def,starset_def]
 10.1218 +     "[| x: HNat; y: HNat |] ==> x + y: HNat";
 10.1219 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
 10.1220 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
 10.1221 +by (auto_tac (claset() addSDs [bspec] addIs [lemma_hyprel_refl],
 10.1222 +    simpset() addsimps [hypreal_add]));
 10.1223 +by (Ultra_tac 1);
 10.1224 +by (dres_inst_tac [("t","Y xb")] sym 1);
 10.1225 +by (auto_tac (claset(),simpset() addsimps [real_of_nat_add RS sym]));
 10.1226 +qed "HNat_add";
 10.1227 +
 10.1228 +Goalw [HNat_def,starset_def]
 10.1229 +     "[| x: HNat; y: HNat |] ==> x * y: HNat";
 10.1230 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
 10.1231 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
 10.1232 +by (auto_tac (claset() addSDs [bspec] addIs [lemma_hyprel_refl],
 10.1233 +    simpset() addsimps [hypreal_mult]));
 10.1234 +by (Ultra_tac 1);
 10.1235 +by (dres_inst_tac [("t","Y xb")] sym 1);
 10.1236 +by (auto_tac (claset(),simpset() addsimps [real_of_nat_mult RS sym]));
 10.1237 +qed "HNat_mult";
 10.1238 +
 10.1239 +(*---------------------------------------------------------------
 10.1240 +    Embedding of the hypernaturals into the hyperreal
 10.1241 + --------------------------------------------------------------*)
 10.1242 +(*** A lemma that should have been derived a long time ago! ***)
 10.1243 +Goal "(Ya : hyprel ^^{%n. f(n)}) = \
 10.1244 +\         ({n. f n = Ya n} : FreeUltrafilterNat)";
 10.1245 +by (Auto_tac);
 10.1246 +qed "lemma_hyprel_FUFN";
 10.1247 +
 10.1248 +Goalw [hypreal_of_hypnat_def]
 10.1249 +      "hypreal_of_hypnat (Abs_hypnat(hypnatrel^^{%n. X n})) = \
 10.1250 +\         Abs_hypreal(hyprel ^^ {%n. real_of_nat (X n)})";
 10.1251 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
 10.1252 +by (auto_tac (claset() addEs [FreeUltrafilterNat_Int RS
 10.1253 +    FreeUltrafilterNat_subset],simpset() addsimps 
 10.1254 +    [lemma_hyprel_FUFN]));
 10.1255 +qed "hypreal_of_hypnat";
 10.1256 +
 10.1257 +Goal "inj(hypreal_of_hypnat)";
 10.1258 +by (rtac injI 1);
 10.1259 +by (res_inst_tac [("z","x")] eq_Abs_hypnat 1);
 10.1260 +by (res_inst_tac [("z","y")] eq_Abs_hypnat 1);
 10.1261 +by (auto_tac (claset(),simpset() addsimps 
 10.1262 +    [hypreal_of_hypnat,real_of_nat_eq_cancel]));
 10.1263 +qed "inj_hypreal_of_hypnat";
 10.1264 +
 10.1265 +Goal "(hypreal_of_hypnat n = hypreal_of_hypnat m) = (n = m)";
 10.1266 +by (auto_tac (claset(),simpset() addsimps [inj_hypreal_of_hypnat RS injD]));
 10.1267 +qed "hypreal_of_hypnat_eq_cancel";
 10.1268 +Addsimps [hypreal_of_hypnat_eq_cancel];
 10.1269 +
 10.1270 +Goal "(hypnat_of_nat n = hypnat_of_nat m) = (n = m)";
 10.1271 +by (auto_tac (claset() addDs [inj_hypnat_of_nat RS injD],
 10.1272 +              simpset()));
 10.1273 +qed "hypnat_of_nat_eq_cancel";
 10.1274 +Addsimps [hypnat_of_nat_eq_cancel];
 10.1275 +
 10.1276 +Goalw [hypnat_zero_def] 
 10.1277 +     "hypreal_of_hypnat 0 = #0";
 10.1278 +by (simp_tac (HOL_ss addsimps
 10.1279 +             [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1); 
 10.1280 +by (simp_tac (simpset() addsimps [hypreal_of_hypnat, real_of_nat_zero]) 1);
 10.1281 +qed "hypreal_of_hypnat_zero";
 10.1282 +
 10.1283 +Goalw [hypnat_one_def] 
 10.1284 +     "hypreal_of_hypnat 1hn = #1";
 10.1285 +by (simp_tac (HOL_ss addsimps
 10.1286 +             [one_eq_numeral_1 RS sym, hypreal_one_def]) 1); 
 10.1287 +by (simp_tac (simpset() addsimps [hypreal_of_hypnat, real_of_nat_one]) 1);
 10.1288 +qed "hypreal_of_hypnat_one";
 10.1289 +
 10.1290 +Goal "hypreal_of_hypnat n1 + hypreal_of_hypnat n2 = hypreal_of_hypnat (n1 + n2)";
 10.1291 +by (res_inst_tac [("z","n1")] eq_Abs_hypnat 1);
 10.1292 +by (res_inst_tac [("z","n2")] eq_Abs_hypnat 1);
 10.1293 +by (asm_simp_tac (simpset() addsimps [hypreal_of_hypnat,
 10.1294 +        hypreal_add,hypnat_add,real_of_nat_add]) 1);
 10.1295 +qed "hypreal_of_hypnat_add";
 10.1296 +
 10.1297 +Goal "hypreal_of_hypnat n1 * hypreal_of_hypnat n2 = hypreal_of_hypnat (n1 * n2)";
 10.1298 +by (res_inst_tac [("z","n1")] eq_Abs_hypnat 1);
 10.1299 +by (res_inst_tac [("z","n2")] eq_Abs_hypnat 1);
 10.1300 +by (asm_simp_tac (simpset() addsimps [hypreal_of_hypnat,
 10.1301 +        hypreal_mult,hypnat_mult,real_of_nat_mult]) 1);
 10.1302 +qed "hypreal_of_hypnat_mult";
 10.1303 +
 10.1304 +Goal "(hypreal_of_hypnat n < hypreal_of_hypnat m) = (n < m)";
 10.1305 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
 10.1306 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
 10.1307 +by (asm_simp_tac (simpset() addsimps 
 10.1308 +    [hypreal_of_hypnat,hypreal_less,hypnat_less]) 1);
 10.1309 +qed "hypreal_of_hypnat_less_iff";
 10.1310 +Addsimps [hypreal_of_hypnat_less_iff];
 10.1311 +
 10.1312 +Goal "(hypreal_of_hypnat N = #0) = (N = 0)";
 10.1313 +by (simp_tac (simpset() addsimps [hypreal_of_hypnat_zero RS sym]) 1);
 10.1314 +qed "hypreal_of_hypnat_eq_zero_iff";
 10.1315 +Addsimps [hypreal_of_hypnat_eq_zero_iff];
 10.1316 +
 10.1317 +Goal "ALL n. N <= n ==> N = (0::hypnat)";
 10.1318 +by (dres_inst_tac [("x","0")] spec 1);
 10.1319 +by (res_inst_tac [("z","N")] eq_Abs_hypnat 1);
 10.1320 +by (auto_tac (claset(),simpset() addsimps [hypnat_le,hypnat_zero_def]));
 10.1321 +qed "hypnat_eq_zero";
 10.1322 +Addsimps [hypnat_eq_zero];
 10.1323 +
 10.1324 +Goal "~ (ALL n. n = (0::hypnat))";
 10.1325 +by Auto_tac;
 10.1326 +by (res_inst_tac [("x","1hn")] exI 1);
 10.1327 +by (Simp_tac 1);
 10.1328 +qed "hypnat_not_all_eq_zero";
 10.1329 +Addsimps [hypnat_not_all_eq_zero];
 10.1330 +
 10.1331 +Goal "n ~= 0 ==> (n <= 1hn) = (n = 1hn)";
 10.1332 +by (auto_tac (claset(),simpset() addsimps [hypnat_le_eq_less_or_eq]));
 10.1333 +qed "hypnat_le_one_eq_one";
 10.1334 +Addsimps [hypnat_le_one_eq_one];
 10.1335 +
 10.1336 +
 10.1337 +
 10.1338 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/HOL/Hyperreal/HyperNat.thy	Sat Dec 30 22:03:47 2000 +0100
    11.3 @@ -0,0 +1,84 @@
    11.4 +(*  Title       : HyperNat.thy
    11.5 +    Author      : Jacques D. Fleuriot
    11.6 +    Copyright   : 1998  University of Cambridge
    11.7 +    Description : Explicit construction of hypernaturals using 
    11.8 +                  ultrafilters
    11.9 +*) 
   11.10 +
   11.11 +HyperNat = Star + 
   11.12 +
   11.13 +constdefs
   11.14 +    hypnatrel :: "((nat=>nat)*(nat=>nat)) set"
   11.15 +    "hypnatrel == {p. EX X Y. p = ((X::nat=>nat),Y) & 
   11.16 +                       {n::nat. X(n) = Y(n)} : FreeUltrafilterNat}"
   11.17 +
   11.18 +typedef hypnat = "UNIV//hypnatrel"              (Equiv.quotient_def)
   11.19 +
   11.20 +instance
   11.21 +   hypnat  :: {ord,zero,plus,times,minus}
   11.22 +
   11.23 +consts
   11.24 +  "1hn"       :: hypnat               ("1hn")  
   11.25 +  "whn"       :: hypnat               ("whn")  
   11.26 +
   11.27 +defs
   11.28 +
   11.29 +  hypnat_zero_def      "0 == Abs_hypnat(hypnatrel^^{%n::nat. 0})"
   11.30 +  hypnat_one_def       "1hn == Abs_hypnat(hypnatrel^^{%n::nat. 1})"
   11.31 +
   11.32 +  (* omega is in fact an infinite hypernatural number = [<1,2,3,...>] *)
   11.33 +  hypnat_omega_def     "whn == Abs_hypnat(hypnatrel^^{%n::nat. n})"
   11.34 + 
   11.35 +
   11.36 +constdefs
   11.37 +
   11.38 +  (* embedding the naturals in the hypernaturals *)
   11.39 +  hypnat_of_nat   :: nat => hypnat
   11.40 +  "hypnat_of_nat m  == Abs_hypnat(hypnatrel^^{%n::nat. m})"
   11.41 +
   11.42 +  (* set of naturals embedded in the hypernaturals*)
   11.43 +  SHNat         :: "hypnat set"
   11.44 +  "SHNat        == {n. EX N. n = hypnat_of_nat N}"  
   11.45 + 
   11.46 +  (* embedding the naturals in the hyperreals*)
   11.47 +  SNat         :: "hypreal set"
   11.48 +  "SNat        == {n. EX N. n = hypreal_of_nat N}"  
   11.49 +
   11.50 +  (* hypernaturals as members of the hyperreals; the set is defined as  *)
   11.51 +  (* the nonstandard extension of set of naturals embedded in the reals *)
   11.52 +  HNat         :: "hypreal set"
   11.53 +  "HNat         == *s* {n. EX no. n = real_of_nat no}"
   11.54 +
   11.55 +  (* the set of infinite hypernatural numbers *)
   11.56 +  HNatInfinite :: "hypnat set"
   11.57 +  "HNatInfinite == {n. n ~: SHNat}"
   11.58 +
   11.59 +  (* explicit embedding of the hypernaturals in the hyperreals *)    
   11.60 +  hypreal_of_hypnat :: hypnat => hypreal
   11.61 +  "hypreal_of_hypnat N  == Abs_hypreal(UN X: Rep_hypnat(N). 
   11.62 +                            hyprel^^{%n::nat. real_of_nat (X n)})"
   11.63 +  
   11.64 +defs
   11.65 +  hypnat_add_def  
   11.66 +  "P + Q == Abs_hypnat(UN X:Rep_hypnat(P). UN Y:Rep_hypnat(Q).
   11.67 +                hypnatrel^^{%n::nat. X n + Y n})"
   11.68 +
   11.69 +  hypnat_mult_def  
   11.70 +  "P * Q == Abs_hypnat(UN X:Rep_hypnat(P). UN Y:Rep_hypnat(Q).
   11.71 +                hypnatrel^^{%n::nat. X n * Y n})"
   11.72 +
   11.73 +  hypnat_minus_def  
   11.74 +  "P - Q == Abs_hypnat(UN X:Rep_hypnat(P). UN Y:Rep_hypnat(Q).
   11.75 +                hypnatrel^^{%n::nat. X n - Y n})"
   11.76 +
   11.77 +  hypnat_less_def
   11.78 +  "P < (Q::hypnat) == EX X Y. X: Rep_hypnat(P) & 
   11.79 +                               Y: Rep_hypnat(Q) & 
   11.80 +                               {n::nat. X n < Y n} : FreeUltrafilterNat"
   11.81 +  hypnat_le_def
   11.82 +  "P <= (Q::hypnat) == ~(Q < P)" 
   11.83 +
   11.84 +end
   11.85 +
   11.86 +
   11.87 +
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/HOL/Hyperreal/HyperOrd.ML	Sat Dec 30 22:03:47 2000 +0100
    12.3 @@ -0,0 +1,715 @@
    12.4 +(*  Title:	 Real/Hyperreal/HyperOrd.ML
    12.5 +    Author:      Jacques D. Fleuriot
    12.6 +    Copyright:   1998 University of Cambridge
    12.7 +                 2000 University of Edinburgh
    12.8 +    Description: Type "hypreal" is a linear order and also 
    12.9 +                 satisfies plus_ac0: + is an AC-operator with zero
   12.10 +*)
   12.11 +
   12.12 +(**** The simproc abel_cancel ****)
   12.13 +
   12.14 +(*** Two lemmas needed for the simprocs ***)
   12.15 +
   12.16 +(*Deletion of other terms in the formula, seeking the -x at the front of z*)
   12.17 +Goal "((x::hypreal) + (y + z) = y + u) = ((x + z) = u)";
   12.18 +by (stac hypreal_add_left_commute 1);
   12.19 +by (rtac hypreal_add_left_cancel 1);
   12.20 +qed "hypreal_add_cancel_21";
   12.21 +
   12.22 +(*A further rule to deal with the case that
   12.23 +  everything gets cancelled on the right.*)
   12.24 +Goal "((x::hypreal) + (y + z) = y) = (x = -z)";
   12.25 +by (stac hypreal_add_left_commute 1);
   12.26 +by (res_inst_tac [("t", "y")] (hypreal_add_zero_right RS subst) 1
   12.27 +    THEN stac hypreal_add_left_cancel 1);
   12.28 +by (simp_tac (simpset() addsimps [hypreal_eq_diff_eq RS sym]) 1);
   12.29 +qed "hypreal_add_cancel_end";
   12.30 +
   12.31 +
   12.32 +structure Hyperreal_Cancel_Data =
   12.33 +struct
   12.34 +  val ss		= HOL_ss
   12.35 +  val eq_reflection	= eq_reflection
   12.36 +
   12.37 +  val sg_ref		= Sign.self_ref (Theory.sign_of (the_context ()))
   12.38 +  val T			= Type("HyperDef.hypreal",[])
   12.39 +  val zero		= Const ("0", T)
   12.40 +  val restrict_to_left  = restrict_to_left
   12.41 +  val add_cancel_21	= hypreal_add_cancel_21
   12.42 +  val add_cancel_end	= hypreal_add_cancel_end
   12.43 +  val add_left_cancel	= hypreal_add_left_cancel
   12.44 +  val add_assoc		= hypreal_add_assoc
   12.45 +  val add_commute	= hypreal_add_commute
   12.46 +  val add_left_commute	= hypreal_add_left_commute
   12.47 +  val add_0		= hypreal_add_zero_left
   12.48 +  val add_0_right	= hypreal_add_zero_right
   12.49 +
   12.50 +  val eq_diff_eq	= hypreal_eq_diff_eq
   12.51 +  val eqI_rules		= [hypreal_less_eqI, hypreal_eq_eqI, hypreal_le_eqI]
   12.52 +  fun dest_eqI th = 
   12.53 +      #1 (HOLogic.dest_bin "op =" HOLogic.boolT 
   12.54 +	      (HOLogic.dest_Trueprop (concl_of th)))
   12.55 +
   12.56 +  val diff_def		= hypreal_diff_def
   12.57 +  val minus_add_distrib	= hypreal_minus_add_distrib
   12.58 +  val minus_minus	= hypreal_minus_minus
   12.59 +  val minus_0		= hypreal_minus_zero
   12.60 +  val add_inverses	= [hypreal_add_minus, hypreal_add_minus_left]
   12.61 +  val cancel_simps	= [hypreal_add_minus_cancelA, hypreal_minus_add_cancelA]
   12.62 +end;
   12.63 +
   12.64 +structure Hyperreal_Cancel = Abel_Cancel (Hyperreal_Cancel_Data);
   12.65 +
   12.66 +Addsimprocs [Hyperreal_Cancel.sum_conv, Hyperreal_Cancel.rel_conv];
   12.67 +
   12.68 +Goal "- (z - y) = y - (z::hypreal)";
   12.69 +by (Simp_tac 1);
   12.70 +qed "hypreal_minus_diff_eq";
   12.71 +Addsimps [hypreal_minus_diff_eq];
   12.72 +
   12.73 +
   12.74 +Goal "((x::hypreal) < y) = (-y < -x)";
   12.75 +by (stac hypreal_less_minus_iff 1);
   12.76 +by (res_inst_tac [("x1","x")] (hypreal_less_minus_iff RS ssubst) 1);
   12.77 +by (simp_tac (simpset() addsimps [hypreal_add_commute]) 1);
   12.78 +qed "hypreal_less_swap_iff";
   12.79 +
   12.80 +Goalw [hypreal_zero_def] 
   12.81 +      "((0::hypreal) < x) = (-x < x)";
   12.82 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   12.83 +by (auto_tac (claset(), simpset() addsimps [hypreal_less, hypreal_minus]));
   12.84 +by (ALLGOALS(Ultra_tac));
   12.85 +qed "hypreal_gt_zero_iff";
   12.86 +
   12.87 +Goal "(A::hypreal) < B ==> A + C < B + C";
   12.88 +by (res_inst_tac [("z","A")] eq_Abs_hypreal 1);
   12.89 +by (res_inst_tac [("z","B")] eq_Abs_hypreal 1);
   12.90 +by (res_inst_tac [("z","C")] eq_Abs_hypreal 1);
   12.91 +by (auto_tac (claset() addSIs [exI], 
   12.92 +              simpset() addsimps [hypreal_less_def,hypreal_add]));
   12.93 +by (Ultra_tac 1);
   12.94 +qed "hypreal_add_less_mono1";
   12.95 +
   12.96 +Goal "!!(A::hypreal). A < B ==> C + A < C + B";
   12.97 +by (auto_tac (claset() addIs [hypreal_add_less_mono1],
   12.98 +    simpset() addsimps [hypreal_add_commute]));
   12.99 +qed "hypreal_add_less_mono2";
  12.100 +
  12.101 +Goal "(x < (0::hypreal)) = (x < -x)";
  12.102 +by (rtac (hypreal_minus_zero_less_iff RS subst) 1);
  12.103 +by (stac hypreal_gt_zero_iff 1);
  12.104 +by (Full_simp_tac 1);
  12.105 +qed "hypreal_lt_zero_iff";
  12.106 +
  12.107 +Goalw [hypreal_le_def] "((0::hypreal) <= x) = (-x <= x)";
  12.108 +by (auto_tac (claset(),simpset() addsimps [hypreal_lt_zero_iff RS sym]));
  12.109 +qed "hypreal_ge_zero_iff";
  12.110 +
  12.111 +Goalw [hypreal_le_def] "(x <= (0::hypreal)) = (x <= -x)";
  12.112 +by (auto_tac (claset(),simpset() addsimps [hypreal_gt_zero_iff RS sym]));
  12.113 +qed "hypreal_le_zero_iff";
  12.114 +
  12.115 +Goalw [hypreal_zero_def] 
  12.116 +      "[| 0 < x; 0 < y |] ==> (0::hypreal) < x + y";
  12.117 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.118 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  12.119 +by (auto_tac (claset(),simpset() addsimps
  12.120 +    [hypreal_less_def,hypreal_add]));
  12.121 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
  12.122 +    [hypreal_less_def,hypreal_add]));
  12.123 +by (ultra_tac (claset() addIs [real_add_order],simpset()) 1);
  12.124 +qed "hypreal_add_order";
  12.125 +
  12.126 +Goal "[| 0 < x; 0 <= y |] ==> (0::hypreal) < x + y";
  12.127 +by (auto_tac (claset() addDs [sym, order_le_imp_less_or_eq]
  12.128 +                       addIs [hypreal_add_order],
  12.129 +              simpset()));
  12.130 +qed "hypreal_add_order_le";            
  12.131 +
  12.132 +Goalw [hypreal_zero_def] 
  12.133 +          "[| 0 < x; 0 < y |] ==> (0::hypreal) < x * y";
  12.134 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.135 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  12.136 +by (auto_tac (claset() addSIs [exI],simpset() addsimps
  12.137 +    [hypreal_less_def,hypreal_mult]));
  12.138 +by (ultra_tac (claset() addIs [rename_numerals real_mult_order],
  12.139 +	       simpset()) 1);
  12.140 +qed "hypreal_mult_order";
  12.141 +
  12.142 +Goal "[| x < 0; y < 0 |] ==> (0::hypreal) < x * y";
  12.143 +by (REPEAT(dtac (hypreal_minus_zero_less_iff RS iffD2) 1));
  12.144 +by (dtac hypreal_mult_order 1 THEN assume_tac 1);
  12.145 +by (Asm_full_simp_tac 1);
  12.146 +qed "hypreal_mult_less_zero1";
  12.147 +
  12.148 +Goal "[| 0 <= x; 0 <= y |] ==> (0::hypreal) <= x * y";
  12.149 +by (REPEAT(dtac order_le_imp_less_or_eq 1));
  12.150 +by (auto_tac (claset() addIs [hypreal_mult_order, order_less_imp_le],
  12.151 +              simpset()));
  12.152 +qed "hypreal_le_mult_order";
  12.153 +
  12.154 +
  12.155 +Goal "[| x <= 0; y <= 0 |] ==> (0::hypreal) <= x * y";
  12.156 +by (rtac hypreal_less_or_eq_imp_le 1);
  12.157 +by (dtac order_le_imp_less_or_eq 1 THEN etac disjE 1);
  12.158 +by Auto_tac;
  12.159 +by (dtac order_le_imp_less_or_eq 1);
  12.160 +by (auto_tac (claset() addDs [hypreal_mult_less_zero1],simpset()));
  12.161 +qed "hypreal_mult_le_zero1";
  12.162 +
  12.163 +Goal "[| 0 <= x; y < 0 |] ==> x * y <= (0::hypreal)";
  12.164 +by (rtac hypreal_less_or_eq_imp_le 1);
  12.165 +by (dtac order_le_imp_less_or_eq 1 THEN etac disjE 1);
  12.166 +by Auto_tac;
  12.167 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
  12.168 +by (rtac (hypreal_minus_zero_less_iff RS subst) 1);
  12.169 +by (blast_tac (claset() addDs [hypreal_mult_order] 
  12.170 +    addIs [hypreal_minus_mult_eq2 RS ssubst]) 1);
  12.171 +qed "hypreal_mult_le_zero";
  12.172 +
  12.173 +Goal "[| 0 < x; y < 0 |] ==> x*y < (0::hypreal)";
  12.174 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
  12.175 +by (dtac hypreal_mult_order 1 THEN assume_tac 1);
  12.176 +by (rtac (hypreal_minus_zero_less_iff RS iffD1) 1);
  12.177 +by (Asm_full_simp_tac 1);
  12.178 +qed "hypreal_mult_less_zero";
  12.179 +
  12.180 +Goalw [hypreal_one_def,hypreal_zero_def,hypreal_less_def] "0 < 1hr";
  12.181 +by (res_inst_tac [("x","%n. #0")] exI 1);
  12.182 +by (res_inst_tac [("x","%n. #1")] exI 1);
  12.183 +by (auto_tac (claset(),
  12.184 +        simpset() addsimps [real_zero_less_one, FreeUltrafilterNat_Nat_set]));
  12.185 +qed "hypreal_zero_less_one";
  12.186 +
  12.187 +Goal "1hr < 1hr + 1hr";
  12.188 +by (rtac (hypreal_less_minus_iff RS iffD2) 1);
  12.189 +by (full_simp_tac (simpset() addsimps [hypreal_zero_less_one,
  12.190 +    hypreal_add_assoc]) 1);
  12.191 +qed "hypreal_one_less_two";
  12.192 +
  12.193 +Goal "0 < 1hr + 1hr";
  12.194 +by (rtac ([hypreal_zero_less_one,
  12.195 +          hypreal_one_less_two] MRS order_less_trans) 1);
  12.196 +qed "hypreal_zero_less_two";
  12.197 +
  12.198 +Goal "1hr + 1hr ~= 0";
  12.199 +by (rtac (hypreal_zero_less_two RS hypreal_not_refl2 RS not_sym) 1);
  12.200 +qed "hypreal_two_not_zero";
  12.201 +Addsimps [hypreal_two_not_zero];
  12.202 +
  12.203 +Goal "[| 0 <= x; 0 <= y |] ==> (0::hypreal) <= x + y";
  12.204 +by (REPEAT(dtac order_le_imp_less_or_eq 1));
  12.205 +by (auto_tac (claset() addIs [hypreal_add_order, order_less_imp_le],
  12.206 +              simpset()));
  12.207 +qed "hypreal_le_add_order";
  12.208 +
  12.209 +(*** Monotonicity results ***)
  12.210 +
  12.211 +Goal "(v+z < w+z) = (v < (w::hypreal))";
  12.212 +by (Simp_tac 1);
  12.213 +qed "hypreal_add_right_cancel_less";
  12.214 +
  12.215 +Goal "(z+v < z+w) = (v < (w::hypreal))";
  12.216 +by (Simp_tac 1);
  12.217 +qed "hypreal_add_left_cancel_less";
  12.218 +
  12.219 +Addsimps [hypreal_add_right_cancel_less, 
  12.220 +          hypreal_add_left_cancel_less];
  12.221 +
  12.222 +Goal "(v+z <= w+z) = (v <= (w::hypreal))";
  12.223 +by (Simp_tac 1);
  12.224 +qed "hypreal_add_right_cancel_le";
  12.225 +
  12.226 +Goal "(z+v <= z+w) = (v <= (w::hypreal))";
  12.227 +by (Simp_tac 1);
  12.228 +qed "hypreal_add_left_cancel_le";
  12.229 +
  12.230 +Addsimps [hypreal_add_right_cancel_le, hypreal_add_left_cancel_le];
  12.231 +
  12.232 +Goal  "[| (z1::hypreal) < y1; z2 < y2 |] ==> z1 + z2 < y1 + y2";
  12.233 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
  12.234 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
  12.235 +by (dtac hypreal_add_order 1 THEN assume_tac 1);
  12.236 +by (thin_tac "0 < y2 + - z2" 1);
  12.237 +by (dres_inst_tac [("C","z1 + z2")] hypreal_add_less_mono1 1);
  12.238 +by (auto_tac (claset(),simpset() addsimps 
  12.239 +    [hypreal_minus_add_distrib RS sym] @ hypreal_add_ac
  12.240 +    delsimps [hypreal_minus_add_distrib]));
  12.241 +qed "hypreal_add_less_mono";
  12.242 +
  12.243 +Goal "(q1::hypreal) <= q2  ==> x + q1 <= x + q2";
  12.244 +by (dtac order_le_imp_less_or_eq 1);
  12.245 +by (Step_tac 1);
  12.246 +by (auto_tac (claset() addSIs [order_less_imp_le,hypreal_add_less_mono1],
  12.247 +              simpset() addsimps [hypreal_add_commute]));
  12.248 +qed "hypreal_add_left_le_mono1";
  12.249 +
  12.250 +Goal "(q1::hypreal) <= q2  ==> q1 + x <= q2 + x";
  12.251 +by (auto_tac (claset() addDs [hypreal_add_left_le_mono1],
  12.252 +              simpset() addsimps [hypreal_add_commute]));
  12.253 +qed "hypreal_add_le_mono1";
  12.254 +
  12.255 +Goal "[|(i::hypreal)<=j;  k<=l |] ==> i + k <= j + l";
  12.256 +by (etac (hypreal_add_le_mono1 RS order_trans) 1);
  12.257 +by (Simp_tac 1);
  12.258 +qed "hypreal_add_le_mono";
  12.259 +
  12.260 +Goal "[|(i::hypreal)<j;  k<=l |] ==> i + k < j + l";
  12.261 +by (auto_tac (claset() addSDs [order_le_imp_less_or_eq] 
  12.262 +                       addIs [hypreal_add_less_mono1,hypreal_add_less_mono],
  12.263 +    simpset()));
  12.264 +qed "hypreal_add_less_le_mono";
  12.265 +
  12.266 +Goal "[|(i::hypreal)<=j;  k<l |] ==> i + k < j + l";
  12.267 +by (auto_tac (claset() addSDs [order_le_imp_less_or_eq] 
  12.268 +                       addIs [hypreal_add_less_mono2,hypreal_add_less_mono],
  12.269 +              simpset()));
  12.270 +qed "hypreal_add_le_less_mono";
  12.271 +
  12.272 +Goal "(A::hypreal) + C < B + C ==> A < B";
  12.273 +by (Full_simp_tac 1);
  12.274 +qed "hypreal_less_add_right_cancel";
  12.275 +
  12.276 +Goal "(C::hypreal) + A < C + B ==> A < B";
  12.277 +by (Full_simp_tac 1);
  12.278 +qed "hypreal_less_add_left_cancel";
  12.279 +
  12.280 +Goal "[|r < x; (0::hypreal) <= y|] ==> r < x + y";
  12.281 +by (auto_tac (claset() addDs [hypreal_add_less_le_mono],
  12.282 +    simpset()));
  12.283 +qed "hypreal_add_zero_less_le_mono";
  12.284 +
  12.285 +Goal "!!(A::hypreal). A + C <= B + C ==> A <= B";
  12.286 +by (dres_inst_tac [("x","-C")] hypreal_add_le_mono1 1);
  12.287 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc]) 1);
  12.288 +qed "hypreal_le_add_right_cancel";
  12.289 +
  12.290 +Goal "!!(A::hypreal). C + A <= C + B ==> A <= B";
  12.291 +by (dres_inst_tac [("x","-C")] hypreal_add_left_le_mono1 1);
  12.292 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_assoc RS sym]) 1);
  12.293 +qed "hypreal_le_add_left_cancel";
  12.294 +
  12.295 +Goal "(0::hypreal) <= x*x";
  12.296 +by (res_inst_tac [("x","0"),("y","x")] hypreal_linear_less2 1);
  12.297 +by (auto_tac (claset() addIs [hypreal_mult_order,
  12.298 +                              hypreal_mult_less_zero1,order_less_imp_le],
  12.299 +              simpset()));
  12.300 +qed "hypreal_le_square";
  12.301 +Addsimps [hypreal_le_square];
  12.302 +
  12.303 +Goalw [hypreal_le_def] "- (x*x) <= (0::hypreal)";
  12.304 +by (auto_tac (claset() addSDs [hypreal_le_square RS order_le_less_trans],
  12.305 +      simpset() addsimps [hypreal_minus_zero_less_iff]));
  12.306 +qed "hypreal_less_minus_square";
  12.307 +Addsimps [hypreal_less_minus_square];
  12.308 +
  12.309 +Goal "(0*x<r)=((0::hypreal)<r)";
  12.310 +by (Simp_tac 1);
  12.311 +qed "hypreal_mult_0_less";
  12.312 +
  12.313 +Goal "[| (0::hypreal) < z; x < y |] ==> x*z < y*z";       
  12.314 +by (rotate_tac 1 1);
  12.315 +by (dtac (hypreal_less_minus_iff RS iffD1) 1);
  12.316 +by (rtac (hypreal_less_minus_iff RS iffD2) 1);
  12.317 +by (dtac hypreal_mult_order 1 THEN assume_tac 1);
  12.318 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_mult_distrib2,
  12.319 +					   hypreal_mult_commute ]) 1);
  12.320 +qed "hypreal_mult_less_mono1";
  12.321 +
  12.322 +Goal "[| (0::hypreal)<z; x<y |] ==> z*x<z*y";       
  12.323 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_commute,hypreal_mult_less_mono1]) 1);
  12.324 +qed "hypreal_mult_less_mono2";
  12.325 +
  12.326 +Goal "[| (0::hypreal)<=z; x<y |] ==> x*z<=y*z";
  12.327 +by (EVERY1 [rtac hypreal_less_or_eq_imp_le, dtac order_le_imp_less_or_eq]);
  12.328 +by (auto_tac (claset() addIs [hypreal_mult_less_mono1],simpset()));
  12.329 +qed "hypreal_mult_le_less_mono1";
  12.330 +
  12.331 +Goal "[| (0::hypreal)<=z; x<y |] ==> z*x<=z*y";
  12.332 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_commute,
  12.333 +				      hypreal_mult_le_less_mono1]) 1);
  12.334 +qed "hypreal_mult_le_less_mono2";
  12.335 +
  12.336 +Goal "[| (0::hypreal)<=z; x<=y |] ==> z*x<=z*y";
  12.337 +by (dres_inst_tac [("x","x")] order_le_imp_less_or_eq 1);
  12.338 +by (auto_tac (claset() addIs [hypreal_mult_le_less_mono2], simpset()));
  12.339 +qed "hypreal_mult_le_le_mono1";
  12.340 +
  12.341 +val prem1::prem2::prem3::rest = goal thy
  12.342 +     "[| (0::hypreal)<y; x<r; y*r<t*s |] ==> y*x<t*s";
  12.343 +by (rtac ([[prem1,prem2] MRS hypreal_mult_less_mono2, prem3] 
  12.344 +          MRS order_less_trans) 1);
  12.345 +qed "hypreal_mult_less_trans";
  12.346 +
  12.347 +Goal "[| 0<=y; x<r; y*r<t*s; (0::hypreal)<t*s|] ==> y*x<t*s";
  12.348 +by (dtac order_le_imp_less_or_eq 1);
  12.349 +by (fast_tac (HOL_cs addEs [hypreal_mult_0_less RS iffD2,
  12.350 +                            hypreal_mult_less_trans]) 1);
  12.351 +qed "hypreal_mult_le_less_trans";
  12.352 +
  12.353 +Goal "[| 0 <= y; x <= r; y*r < t*s; (0::hypreal) < t*s|] ==> y*x < t*s";
  12.354 +by (dres_inst_tac [("x","x")] order_le_imp_less_or_eq 1);
  12.355 +by (fast_tac (claset() addIs [hypreal_mult_le_less_trans]) 1);
  12.356 +qed "hypreal_mult_le_le_trans";
  12.357 +
  12.358 +Goal "[| u<v;  x<y;  (0::hypreal) < v;  0 < x |] ==> u*x < v* y";
  12.359 +by (etac (hypreal_mult_less_mono1 RS order_less_trans) 1);
  12.360 +by (assume_tac 1);
  12.361 +by (etac hypreal_mult_less_mono2 1);
  12.362 +by (assume_tac 1);
  12.363 +qed "hypreal_mult_less_mono";
  12.364 +
  12.365 +(*UNUSED at present but possibly more useful than hypreal_mult_less_mono*)
  12.366 +Goal "[| x < y;  r1 < r2;  (0::hypreal) <= r1;  0 <= x|] ==> r1 * x < r2 * y";
  12.367 +by (subgoal_tac "0<r2" 1);
  12.368 +by (blast_tac (claset() addIs [order_le_less_trans]) 2); 
  12.369 +by (case_tac "x=0" 1);
  12.370 +by (auto_tac (claset() addSDs [order_le_imp_less_or_eq] 
  12.371 +	               addIs [hypreal_mult_less_mono, hypreal_mult_order],
  12.372 +	      simpset()));
  12.373 +qed "hypreal_mult_less_mono'";
  12.374 +
  12.375 +Goal "0 < x ==> 0 < inverse (x::hypreal)";
  12.376 +by (EVERY1[rtac ccontr, dtac hypreal_leI]);
  12.377 +by (forward_tac [hypreal_minus_zero_less_iff2 RS iffD2] 1);
  12.378 +by (forward_tac [hypreal_not_refl2 RS not_sym] 1);
  12.379 +by (dtac (hypreal_not_refl2 RS not_sym RS hypreal_inverse_not_zero) 1);
  12.380 +by (EVERY1[dtac order_le_imp_less_or_eq, Step_tac]); 
  12.381 +by (dtac hypreal_mult_less_zero1 1 THEN assume_tac 1);
  12.382 +by (auto_tac (claset() addIs [hypreal_zero_less_one RS hypreal_less_asym],
  12.383 +                 simpset() addsimps [hypreal_minus_zero_less_iff]));
  12.384 +qed "hypreal_inverse_gt_zero";
  12.385 +
  12.386 +Goal "x < 0 ==> inverse (x::hypreal) < 0";
  12.387 +by (ftac hypreal_not_refl2 1);
  12.388 +by (dtac (hypreal_minus_zero_less_iff RS iffD2) 1);
  12.389 +by (rtac (hypreal_minus_zero_less_iff RS iffD1) 1);
  12.390 +by (stac (hypreal_minus_inverse RS sym) 1);
  12.391 +by (auto_tac (claset() addIs [hypreal_inverse_gt_zero],  simpset()));
  12.392 +qed "hypreal_inverse_less_zero";
  12.393 +
  12.394 +Goal "[| 0 <= x; 0 <= y |] ==> (x+y = 0) = (x = 0 & y = (0::hypreal))";
  12.395 +by (auto_tac (claset() addIs [order_antisym], simpset()));
  12.396 +qed "hypreal_add_nonneg_eq_0_iff";
  12.397 +
  12.398 +Goal "(x*y = 0) = (x = 0 | y = (0::hypreal))";
  12.399 +by Auto_tac;
  12.400 +by (blast_tac (claset() addDs [hypreal_mult_zero_disj]) 1);
  12.401 +qed "hypreal_mult_is_0";
  12.402 +
  12.403 +Goal "(x*x + y*y = 0) = (x = 0 & y = (0::hypreal))";
  12.404 +by (simp_tac (HOL_ss addsimps [hypreal_le_square, hypreal_add_nonneg_eq_0_iff, 
  12.405 +                               hypreal_mult_is_0]) 1);
  12.406 +qed "hypreal_squares_add_zero_iff";
  12.407 +Addsimps [hypreal_squares_add_zero_iff];
  12.408 +
  12.409 +Goal "(x*x + y*y + z*z = 0) = (x = 0 & y = 0 & z = (0::hypreal))";
  12.410 +by (simp_tac (HOL_ss addsimps [hypreal_le_square, hypreal_le_add_order, 
  12.411 +                         hypreal_add_nonneg_eq_0_iff, hypreal_mult_is_0]) 1);
  12.412 +qed "hypreal_three_squares_add_zero_iff";
  12.413 +
  12.414 +Goal "(x::hypreal)*x <= x*x + y*y";
  12.415 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.416 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  12.417 +by (auto_tac (claset(),
  12.418 +              simpset() addsimps [hypreal_mult,hypreal_add,hypreal_le]));
  12.419 +qed "hypreal_self_le_add_pos";
  12.420 +Addsimps [hypreal_self_le_add_pos];
  12.421 +
  12.422 +(*lcp: new lemma unfortunately needed...*)
  12.423 +Goal "-(x*x) <= (y*y::real)";
  12.424 +by (rtac order_trans 1);
  12.425 +by (rtac real_le_square 2);
  12.426 +by Auto_tac;
  12.427 +qed "minus_square_le_square";
  12.428 +
  12.429 +Goal "(x::hypreal)*x <= x*x + y*y + z*z";
  12.430 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.431 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  12.432 +by (res_inst_tac [("z","z")] eq_Abs_hypreal 1);
  12.433 +by (auto_tac (claset(),
  12.434 +	      simpset() addsimps [hypreal_mult, hypreal_add, hypreal_le,
  12.435 +				  minus_square_le_square]));
  12.436 +qed "hypreal_self_le_add_pos2";
  12.437 +Addsimps [hypreal_self_le_add_pos2];
  12.438 +
  12.439 +
  12.440 +(*----------------------------------------------------------------------------
  12.441 +             Embedding of the naturals in the hyperreals
  12.442 + ----------------------------------------------------------------------------*)
  12.443 +Goalw [hypreal_of_posnat_def] "hypreal_of_posnat 0 = 1hr";
  12.444 +by (full_simp_tac (simpset() addsimps 
  12.445 +    [pnat_one_iff RS sym,real_of_preal_def]) 1);
  12.446 +by (fold_tac [real_one_def]);
  12.447 +by (simp_tac (simpset() addsimps [hypreal_of_real_one]) 1);
  12.448 +qed "hypreal_of_posnat_one";
  12.449 +
  12.450 +Goalw [hypreal_of_posnat_def] "hypreal_of_posnat 1 = 1hr + 1hr";
  12.451 +by (full_simp_tac (simpset() addsimps 
  12.452 +		   [real_of_preal_def,
  12.453 +		    rename_numerals (real_one_def RS meta_eq_to_obj_eq),
  12.454 +		    hypreal_add,hypreal_of_real_def,pnat_two_eq,
  12.455 +		    hypreal_one_def, real_add,
  12.456 +		    prat_of_pnat_add RS sym, preal_of_prat_add RS sym] @ 
  12.457 +		    pnat_add_ac) 1);
  12.458 +qed "hypreal_of_posnat_two";
  12.459 +
  12.460 +(*FIXME: delete this and all posnat*)
  12.461 +Goalw [hypreal_of_posnat_def]
  12.462 +     "hypreal_of_posnat n1 + hypreal_of_posnat n2 = \
  12.463 +\     hypreal_of_posnat (n1 + n2) + 1hr";
  12.464 +by (full_simp_tac (HOL_ss addsimps [hypreal_of_posnat_one RS sym,
  12.465 +    hypreal_of_real_add RS sym,hypreal_of_posnat_def,real_of_preal_add RS sym,
  12.466 +    preal_of_prat_add RS sym,prat_of_pnat_add RS sym,pnat_of_nat_add]) 1);
  12.467 +qed "hypreal_of_posnat_add";
  12.468 +
  12.469 +Goal "hypreal_of_posnat (n + 1) = hypreal_of_posnat n + 1hr";
  12.470 +by (res_inst_tac [("x1","1hr")] (hypreal_add_right_cancel RS iffD1) 1);
  12.471 +by (rtac (hypreal_of_posnat_add RS subst) 1);
  12.472 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_two,hypreal_add_assoc]) 1);
  12.473 +qed "hypreal_of_posnat_add_one";
  12.474 +
  12.475 +Goalw [real_of_posnat_def,hypreal_of_posnat_def] 
  12.476 +      "hypreal_of_posnat n = hypreal_of_real (real_of_posnat n)";
  12.477 +by (rtac refl 1);
  12.478 +qed "hypreal_of_real_of_posnat";
  12.479 +
  12.480 +Goalw [hypreal_of_posnat_def] 
  12.481 +      "(n < m) = (hypreal_of_posnat n < hypreal_of_posnat m)";
  12.482 +by Auto_tac;
  12.483 +qed "hypreal_of_posnat_less_iff";
  12.484 +
  12.485 +Addsimps [hypreal_of_posnat_less_iff RS sym];
  12.486 +(*---------------------------------------------------------------------------------
  12.487 +               Existence of infinite hyperreal number
  12.488 + ---------------------------------------------------------------------------------*)
  12.489 +
  12.490 +Goal "hyprel^^{%n::nat. real_of_posnat n} : hypreal";
  12.491 +by Auto_tac;
  12.492 +qed "hypreal_omega";
  12.493 +
  12.494 +Goalw [omega_def] "Rep_hypreal(whr) : hypreal";
  12.495 +by (rtac Rep_hypreal 1);
  12.496 +qed "Rep_hypreal_omega";
  12.497 +
  12.498 +(* existence of infinite number not corresponding to any real number *)
  12.499 +(* use assumption that member FreeUltrafilterNat is not finite       *)
  12.500 +(* a few lemmas first *)
  12.501 +
  12.502 +Goal "{n::nat. x = real_of_posnat n} = {} | \
  12.503 +\     (EX y. {n::nat. x = real_of_posnat n} = {y})";
  12.504 +by (auto_tac (claset() addDs [inj_real_of_posnat RS injD],simpset()));
  12.505 +qed "lemma_omega_empty_singleton_disj";
  12.506 +
  12.507 +Goal "finite {n::nat. x = real_of_posnat n}";
  12.508 +by (cut_inst_tac [("x","x")] lemma_omega_empty_singleton_disj 1);
  12.509 +by Auto_tac;
  12.510 +qed "lemma_finite_omega_set";
  12.511 +
  12.512 +Goalw [omega_def,hypreal_of_real_def] 
  12.513 +      "~ (EX x. hypreal_of_real x = whr)";
  12.514 +by (auto_tac (claset(),simpset() addsimps [lemma_finite_omega_set 
  12.515 +    RS FreeUltrafilterNat_finite]));
  12.516 +qed "not_ex_hypreal_of_real_eq_omega";
  12.517 +
  12.518 +Goal "hypreal_of_real x ~= whr";
  12.519 +by (cut_facts_tac [not_ex_hypreal_of_real_eq_omega] 1);
  12.520 +by Auto_tac;
  12.521 +qed "hypreal_of_real_not_eq_omega";
  12.522 +
  12.523 +(* existence of infinitesimal number also not *)
  12.524 +(* corresponding to any real number *)
  12.525 +
  12.526 +Goal "{n::nat. x = inverse(real_of_posnat n)} = {} | \
  12.527 +\     (EX y. {n::nat. x = inverse(real_of_posnat n)} = {y})";
  12.528 +by (Step_tac 1 THEN Step_tac 1);
  12.529 +by (auto_tac (claset() addIs [real_of_posnat_inverse_inj],simpset()));
  12.530 +qed "lemma_epsilon_empty_singleton_disj";
  12.531 +
  12.532 +Goal "finite {n::nat. x = inverse(real_of_posnat n)}";
  12.533 +by (cut_inst_tac [("x","x")] lemma_epsilon_empty_singleton_disj 1);
  12.534 +by Auto_tac;
  12.535 +qed "lemma_finite_epsilon_set";
  12.536 +
  12.537 +Goalw [epsilon_def,hypreal_of_real_def] 
  12.538 +      "~ (EX x. hypreal_of_real x = ehr)";
  12.539 +by (auto_tac (claset(),simpset() addsimps [lemma_finite_epsilon_set 
  12.540 +    RS FreeUltrafilterNat_finite]));
  12.541 +qed "not_ex_hypreal_of_real_eq_epsilon";
  12.542 +
  12.543 +Goal "hypreal_of_real x ~= ehr";
  12.544 +by (cut_facts_tac [not_ex_hypreal_of_real_eq_epsilon] 1);
  12.545 +by Auto_tac;
  12.546 +qed "hypreal_of_real_not_eq_epsilon";
  12.547 +
  12.548 +Goalw [epsilon_def,hypreal_zero_def] "ehr ~= 0";
  12.549 +by (auto_tac (claset(),
  12.550 +     simpset() addsimps [rename_numerals real_of_posnat_not_eq_zero]));
  12.551 +qed "hypreal_epsilon_not_zero";
  12.552 +
  12.553 +Addsimps [rename_numerals real_of_posnat_not_eq_zero];
  12.554 +Goalw [omega_def,hypreal_zero_def] "whr ~= 0";
  12.555 +by (Simp_tac 1);
  12.556 +qed "hypreal_omega_not_zero";
  12.557 +
  12.558 +Goal "ehr = inverse(whr)";
  12.559 +by (asm_full_simp_tac (simpset() addsimps 
  12.560 +                     [hypreal_inverse, omega_def, epsilon_def]) 1);
  12.561 +qed "hypreal_epsilon_inverse_omega";
  12.562 +
  12.563 +(*----------------------------------------------------------------
  12.564 +     Another embedding of the naturals in the 
  12.565 +    hyperreals (see hypreal_of_posnat)
  12.566 + ----------------------------------------------------------------*)
  12.567 +Goalw [hypreal_of_nat_def] "hypreal_of_nat 0 = 0";
  12.568 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_one]) 1);
  12.569 +qed "hypreal_of_nat_zero";
  12.570 +
  12.571 +Goalw [hypreal_of_nat_def] "hypreal_of_nat 1 = 1hr";
  12.572 +by (full_simp_tac (simpset() addsimps [hypreal_of_posnat_two,
  12.573 +                                       hypreal_add_assoc]) 1);
  12.574 +qed "hypreal_of_nat_one";
  12.575 +
  12.576 +Goalw [hypreal_of_nat_def]
  12.577 +     "hypreal_of_nat n1 + hypreal_of_nat n2 = hypreal_of_nat (n1 + n2)";
  12.578 +by (full_simp_tac (simpset() addsimps hypreal_add_ac) 1);
  12.579 +by (simp_tac (simpset() addsimps [hypreal_of_posnat_add,
  12.580 +                                  hypreal_add_assoc RS sym]) 1);
  12.581 +qed "hypreal_of_nat_add";
  12.582 +
  12.583 +Goal "hypreal_of_nat 2 = 1hr + 1hr";
  12.584 +by (simp_tac (simpset() addsimps [hypreal_of_nat_one 
  12.585 +    RS sym,hypreal_of_nat_add]) 1);
  12.586 +qed "hypreal_of_nat_two";
  12.587 +
  12.588 +Goalw [hypreal_of_nat_def] 
  12.589 +      "(n < m) = (hypreal_of_nat n < hypreal_of_nat m)";
  12.590 +by (auto_tac (claset() addIs [hypreal_add_less_mono1],simpset()));
  12.591 +qed "hypreal_of_nat_less_iff";
  12.592 +Addsimps [hypreal_of_nat_less_iff RS sym];
  12.593 +
  12.594 +(*------------------------------------------------------------*)
  12.595 +(* naturals embedded in hyperreals                            *)
  12.596 +(* is a hyperreal c.f. NS extension                           *)
  12.597 +(*------------------------------------------------------------*)
  12.598 +
  12.599 +Goalw [hypreal_of_nat_def,real_of_nat_def] 
  12.600 +      "hypreal_of_nat  m = Abs_hypreal(hyprel^^{%n. real_of_nat m})";
  12.601 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_def,
  12.602 +    hypreal_of_real_of_posnat,hypreal_minus,hypreal_one_def,hypreal_add]));
  12.603 +qed "hypreal_of_nat_iff";
  12.604 +
  12.605 +Goal "inj hypreal_of_nat";
  12.606 +by (rtac injI 1);
  12.607 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_P],
  12.608 +        simpset() addsimps [split_if_mem1, hypreal_of_nat_iff,
  12.609 +        real_add_right_cancel,inj_real_of_nat RS injD]));
  12.610 +qed "inj_hypreal_of_nat";
  12.611 +
  12.612 +Goalw [hypreal_of_nat_def,hypreal_of_real_def,hypreal_of_posnat_def,
  12.613 +       real_of_posnat_def,hypreal_one_def,real_of_nat_def] 
  12.614 +       "hypreal_of_nat n = hypreal_of_real (real_of_nat n)";
  12.615 +by (simp_tac (simpset() addsimps [hypreal_add,hypreal_minus]) 1);
  12.616 +qed "hypreal_of_nat_real_of_nat";
  12.617 +
  12.618 +Goal "hypreal_of_posnat (Suc n) = hypreal_of_posnat n + 1hr";
  12.619 +by (stac (hypreal_of_posnat_add_one RS sym) 1);
  12.620 +by (Simp_tac 1);
  12.621 +qed "hypreal_of_posnat_Suc";
  12.622 +
  12.623 +Goalw [hypreal_of_nat_def] 
  12.624 +      "hypreal_of_nat (Suc n) = hypreal_of_nat n + 1hr";
  12.625 +by (simp_tac (simpset() addsimps [hypreal_of_posnat_Suc] @ hypreal_add_ac) 1);
  12.626 +qed "hypreal_of_nat_Suc";
  12.627 +
  12.628 +(* this proof is so much simpler than one for reals!! *)
  12.629 +Goal "[| 0 < r; r < x |] ==> inverse x < inverse (r::hypreal)";
  12.630 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  12.631 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  12.632 +by (auto_tac (claset(),simpset() addsimps [hypreal_inverse,
  12.633 +    hypreal_less,hypreal_zero_def]));
  12.634 +by (ultra_tac (claset() addIs [real_inverse_less_swap],simpset()) 1);
  12.635 +qed "hypreal_inverse_less_swap";
  12.636 +
  12.637 +Goal "[| 0 < r; 0 < x|] ==> (r < x) = (inverse x < inverse (r::hypreal))";
  12.638 +by (auto_tac (claset() addIs [hypreal_inverse_less_swap],simpset()));
  12.639 +by (res_inst_tac [("t","r")] (hypreal_inverse_inverse RS subst) 1);
  12.640 +by (res_inst_tac [("t","x")] (hypreal_inverse_inverse RS subst) 1);
  12.641 +by (rtac hypreal_inverse_less_swap 1);
  12.642 +by (auto_tac (claset(), simpset() addsimps [hypreal_inverse_gt_zero]));
  12.643 +qed "hypreal_inverse_less_iff";
  12.644 +
  12.645 +Goal "[| 0 < z; x < y |] ==> x * inverse z < y * inverse (z::hypreal)";
  12.646 +by (blast_tac (claset() addSIs [hypreal_mult_less_mono1,
  12.647 +                                hypreal_inverse_gt_zero]) 1);
  12.648 +qed "hypreal_mult_inverse_less_mono1";
  12.649 +
  12.650 +Goal "[| 0 < z; x < y |] ==> inverse z * x < inverse (z::hypreal) * y";
  12.651 +by (blast_tac (claset() addSIs [hypreal_mult_less_mono2,
  12.652 +                                hypreal_inverse_gt_zero]) 1);
  12.653 +qed "hypreal_mult_inverse_less_mono2";
  12.654 +
  12.655 +Goal "[| (0::hypreal) < z; x*z < y*z |] ==> x < y";
  12.656 +by (forw_inst_tac [("x","x*z")] hypreal_mult_inverse_less_mono1 1);
  12.657 +by (dtac (hypreal_not_refl2 RS not_sym) 2);
  12.658 +by (auto_tac (claset() addSDs [hypreal_mult_inverse],
  12.659 +              simpset() addsimps hypreal_mult_ac));
  12.660 +qed "hypreal_less_mult_right_cancel";
  12.661 +
  12.662 +Goal "[| (0::hypreal) < z; z*x < z*y |] ==> x < y";
  12.663 +by (auto_tac (claset() addIs [hypreal_less_mult_right_cancel],
  12.664 +    simpset() addsimps [hypreal_mult_commute]));
  12.665 +qed "hypreal_less_mult_left_cancel";
  12.666 +
  12.667 +Goal "[| 0 < r; (0::hypreal) < ra; r < x; ra < y |] ==> r*ra < x*y";
  12.668 +by (forw_inst_tac [("y","r")] order_less_trans 1);
  12.669 +by (dres_inst_tac [("z","ra"),("x","r")] hypreal_mult_less_mono1 2);
  12.670 +by (dres_inst_tac [("z","x"),("x","ra")] hypreal_mult_less_mono2 3);
  12.671 +by (auto_tac (claset() addIs [order_less_trans], simpset()));
  12.672 +qed "hypreal_mult_less_gt_zero"; 
  12.673 +
  12.674 +Goal "[| 0 < r; (0::hypreal) < ra; r <= x; ra <= y |] ==> r*ra <= x*y";
  12.675 +by (REPEAT(dtac order_le_imp_less_or_eq 1));
  12.676 +by (rtac hypreal_less_or_eq_imp_le 1);
  12.677 +by (auto_tac (claset() addIs [hypreal_mult_less_mono1,
  12.678 +                         hypreal_mult_less_mono2,hypreal_mult_less_gt_zero],
  12.679 +    simpset()));
  12.680 +qed "hypreal_mult_le_ge_zero"; 
  12.681 +
  12.682 +(*----------------------------------------------------------------------------
  12.683 +     Some convenient biconditionals for products of signs 
  12.684 + ----------------------------------------------------------------------------*)
  12.685 +
  12.686 +Goal "((0::hypreal) < x*y) = (0 < x & 0 < y | x < 0 & y < 0)";
  12.687 + by (auto_tac (claset(), 
  12.688 +               simpset() addsimps [order_le_less, linorder_not_less, 
  12.689 +                              hypreal_mult_order, hypreal_mult_less_zero1]));
  12.690 +by (ALLGOALS (rtac ccontr)); 
  12.691 +by (auto_tac (claset(), 
  12.692 +              simpset() addsimps [order_le_less, linorder_not_less]));
  12.693 +by (ALLGOALS (etac rev_mp)); 
  12.694 +by (ALLGOALS (dtac hypreal_mult_less_zero THEN' assume_tac));
  12.695 +by (auto_tac (claset() addDs [order_less_not_sym], 
  12.696 +              simpset() addsimps [hypreal_mult_commute]));  
  12.697 +qed "hypreal_zero_less_mult_iff";
  12.698 +
  12.699 +Goal "((0::hypreal) <= x*y) = (0 <= x & 0 <= y | x <= 0 & y <= 0)";
  12.700 +by (auto_tac (claset() addDs [hypreal_mult_zero_disj],
  12.701 +              simpset() addsimps [order_le_less, linorder_not_less,
  12.702 +                                  hypreal_zero_less_mult_iff]));
  12.703 +qed "hypreal_zero_le_mult_iff";
  12.704 +
  12.705 +Goal "(x*y < (0::hypreal)) = (0 < x & y < 0 | x < 0 & 0 < y)";
  12.706 +by (auto_tac (claset(), 
  12.707 +              simpset() addsimps [hypreal_zero_le_mult_iff, 
  12.708 +                                  linorder_not_le RS sym]));
  12.709 +by (auto_tac (claset() addDs [order_less_not_sym],  
  12.710 +              simpset() addsimps [linorder_not_le]));
  12.711 +qed "hypreal_mult_less_zero_iff";
  12.712 +
  12.713 +Goal "(x*y <= (0::hypreal)) = (0 <= x & y <= 0 | x <= 0 & 0 <= y)";
  12.714 +by (auto_tac (claset() addDs [order_less_not_sym], 
  12.715 +              simpset() addsimps [hypreal_zero_less_mult_iff, 
  12.716 +                                  linorder_not_less RS sym]));
  12.717 +qed "hypreal_mult_le_zero_iff";
  12.718 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/HOL/Hyperreal/HyperOrd.thy	Sat Dec 30 22:03:47 2000 +0100
    13.3 @@ -0,0 +1,15 @@
    13.4 +(*  Title:	 Real/Hyperreal/HyperOrd.thy
    13.5 +    Author:      Jacques D. Fleuriot
    13.6 +    Copyright:   2000 University of Edinburgh
    13.7 +    Description: Type "hypreal" is a linear order and also 
    13.8 +                 satisfies plus_ac0: + is an AC-operator with zero
    13.9 +*)
   13.10 +
   13.11 +HyperOrd = HyperDef +
   13.12 +
   13.13 +instance hypreal :: order (hypreal_le_refl,hypreal_le_trans,hypreal_le_anti_sym,hypreal_less_le)
   13.14 +instance hypreal :: linorder (hypreal_le_linear)
   13.15 +
   13.16 +instance hypreal :: plus_ac0(hypreal_add_commute,hypreal_add_assoc,hypreal_add_zero_left)
   13.17 +
   13.18 +end
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/HOL/Hyperreal/HyperPow.ML	Sat Dec 30 22:03:47 2000 +0100
    14.3 @@ -0,0 +1,521 @@
    14.4 +(*  Title       : HyperPow.ML
    14.5 +    Author      : Jacques D. Fleuriot  
    14.6 +    Copyright   : 1998  University of Cambridge
    14.7 +    Description : Natural Powers of hyperreals theory
    14.8 +
    14.9 +*)
   14.10 +
   14.11 +Goal "(#0::hypreal) ^ (Suc n) = 0";
   14.12 +by (Auto_tac);
   14.13 +qed "hrealpow_zero";
   14.14 +Addsimps [hrealpow_zero];
   14.15 +
   14.16 +Goal "r ~= (#0::hypreal) --> r ^ n ~= 0";
   14.17 +by (induct_tac "n" 1);
   14.18 +by Auto_tac;
   14.19 +qed_spec_mp "hrealpow_not_zero";
   14.20 +
   14.21 +Goal "r ~= (#0::hypreal) --> inverse(r ^ n) = (inverse r) ^ n";
   14.22 +by (induct_tac "n" 1);
   14.23 +by (Auto_tac);
   14.24 +by (forw_inst_tac [("n","n")] hrealpow_not_zero 1);
   14.25 +by (auto_tac (claset(), simpset() addsimps [hypreal_inverse_distrib]));
   14.26 +qed_spec_mp "hrealpow_inverse";
   14.27 +
   14.28 +Goal "abs (r::hypreal) ^ n = abs (r ^ n)";
   14.29 +by (induct_tac "n" 1);
   14.30 +by (auto_tac (claset(), simpset() addsimps [hrabs_mult]));
   14.31 +qed "hrealpow_hrabs";
   14.32 +
   14.33 +Goal "(r::hypreal) ^ (n + m) = (r ^ n) * (r ^ m)";
   14.34 +by (induct_tac "n" 1);
   14.35 +by (auto_tac (claset(), simpset() addsimps hypreal_mult_ac));
   14.36 +qed "hrealpow_add";
   14.37 +
   14.38 +Goal "(r::hypreal) ^ 1 = r";
   14.39 +by (Simp_tac 1);
   14.40 +qed "hrealpow_one";
   14.41 +Addsimps [hrealpow_one];
   14.42 +
   14.43 +Goal "(r::hypreal) ^ 2 = r * r";
   14.44 +by (Simp_tac 1);
   14.45 +qed "hrealpow_two";
   14.46 +
   14.47 +Goal "(#0::hypreal) <= r --> #0 <= r ^ n";
   14.48 +by (induct_tac "n" 1);
   14.49 +by (auto_tac (claset(), simpset() addsimps [hypreal_0_le_mult_iff]));
   14.50 +qed_spec_mp "hrealpow_ge_zero";
   14.51 +
   14.52 +Goal "(#0::hypreal) < r --> #0 < r ^ n";
   14.53 +by (induct_tac "n" 1);
   14.54 +by (auto_tac (claset(), simpset() addsimps [hypreal_0_less_mult_iff]));
   14.55 +qed_spec_mp "hrealpow_gt_zero";
   14.56 +
   14.57 +Goal "x <= y & (#0::hypreal) < x --> x ^ n <= y ^ n";
   14.58 +by (induct_tac "n" 1);
   14.59 +by (auto_tac (claset() addSIs [hypreal_mult_le_mono], simpset()));
   14.60 +by (asm_simp_tac (simpset() addsimps [hrealpow_ge_zero]) 1);
   14.61 +qed_spec_mp "hrealpow_le";
   14.62 +
   14.63 +Goal "x < y & (#0::hypreal) < x & 0 < n --> x ^ n < y ^ n";
   14.64 +by (induct_tac "n" 1);
   14.65 +by (auto_tac (claset() addIs [hypreal_mult_less_mono,gr0I],
   14.66 +              simpset() addsimps [hrealpow_gt_zero]));
   14.67 +qed "hrealpow_less";
   14.68 +
   14.69 +Goal "#1 ^ n = (#1::hypreal)";
   14.70 +by (induct_tac "n" 1);
   14.71 +by (Auto_tac);
   14.72 +qed "hrealpow_eq_one";
   14.73 +Addsimps [hrealpow_eq_one];
   14.74 +
   14.75 +Goal "abs(-(#1 ^ n)) = (#1::hypreal)";
   14.76 +by Auto_tac;  
   14.77 +qed "hrabs_minus_hrealpow_one";
   14.78 +Addsimps [hrabs_minus_hrealpow_one];
   14.79 +
   14.80 +Goal "abs(#-1 ^ n) = (#1::hypreal)";
   14.81 +by (induct_tac "n" 1);
   14.82 +by Auto_tac;  
   14.83 +qed "hrabs_hrealpow_minus_one";
   14.84 +Addsimps [hrabs_hrealpow_minus_one];
   14.85 +
   14.86 +Goal "((r::hypreal) * s) ^ n = (r ^ n) * (s ^ n)";
   14.87 +by (induct_tac "n" 1);
   14.88 +by (auto_tac (claset(), simpset() addsimps hypreal_mult_ac));
   14.89 +qed "hrealpow_mult";
   14.90 +
   14.91 +Goal "(#0::hypreal) <= r ^ 2";
   14.92 +by (auto_tac (claset(), simpset() addsimps [hypreal_0_le_mult_iff]));
   14.93 +qed "hrealpow_two_le";
   14.94 +Addsimps [hrealpow_two_le];
   14.95 +
   14.96 +Goal "(#0::hypreal) <= u ^ 2 + v ^ 2";
   14.97 +by (simp_tac (HOL_ss addsimps [hrealpow_two_le, 
   14.98 +                    rename_numerals hypreal_le_add_order]) 1); 
   14.99 +qed "hrealpow_two_le_add_order";
  14.100 +Addsimps [hrealpow_two_le_add_order];
  14.101 +
  14.102 +Goal "(#0::hypreal) <= u ^ 2 + v ^ 2 + w ^ 2";
  14.103 +by (simp_tac (HOL_ss addsimps [hrealpow_two_le, 
  14.104 +                    rename_numerals hypreal_le_add_order]) 1); 
  14.105 +qed "hrealpow_two_le_add_order2";
  14.106 +Addsimps [hrealpow_two_le_add_order2];
  14.107 +
  14.108 +Goal "(x ^ 2 + y ^ 2 + z ^ 2 = (#0::hypreal)) = (x = #0 & y = #0 & z = #0)";
  14.109 +by (simp_tac (HOL_ss addsimps
  14.110 +      [rename_numerals hypreal_three_squares_add_zero_iff, hrealpow_two]) 1);
  14.111 +qed "hrealpow_three_squares_add_zero_iff";
  14.112 +Addsimps [hrealpow_three_squares_add_zero_iff];
  14.113 +
  14.114 +Goal "abs(x ^ 2) = (x::hypreal) ^ 2";
  14.115 +by (auto_tac (claset(), 
  14.116 +     simpset() addsimps [hrabs_def, hypreal_0_le_mult_iff])); 
  14.117 +qed "hrabs_hrealpow_two";
  14.118 +Addsimps [hrabs_hrealpow_two];
  14.119 +
  14.120 +Goal "abs(x) ^ 2 = (x::hypreal) ^ 2";
  14.121 +by (simp_tac (simpset() addsimps [hrealpow_hrabs, hrabs_eqI1] 
  14.122 +                        delsimps [hpowr_Suc]) 1);
  14.123 +qed "hrealpow_two_hrabs";
  14.124 +Addsimps [hrealpow_two_hrabs];
  14.125 +
  14.126 +Goal "(#1::hypreal) < r ==> #1 < r ^ 2";
  14.127 +by (auto_tac (claset(), simpset() addsimps [hrealpow_two]));
  14.128 +by (res_inst_tac [("y","#1*#1")] order_le_less_trans 1); 
  14.129 +by (rtac hypreal_mult_less_mono 2); 
  14.130 +by Auto_tac;  
  14.131 +qed "hrealpow_two_gt_one";
  14.132 +
  14.133 +Goal "(#1::hypreal) <= r ==> #1 <= r ^ 2";
  14.134 +by (etac (order_le_imp_less_or_eq RS disjE) 1);
  14.135 +by (etac (hrealpow_two_gt_one RS order_less_imp_le) 1);
  14.136 +by Auto_tac;  
  14.137 +qed "hrealpow_two_ge_one";
  14.138 +
  14.139 +Goal "(#1::hypreal) <= #2 ^ n";
  14.140 +by (res_inst_tac [("y","#1 ^ n")] order_trans 1);
  14.141 +by (rtac hrealpow_le 2);
  14.142 +by (auto_tac (claset() addIs [order_less_imp_le],
  14.143 +         simpset() addsimps [hypreal_zero_less_one, hypreal_one_less_two]));
  14.144 +qed "two_hrealpow_ge_one";
  14.145 +
  14.146 +Goal "hypreal_of_nat n < #2 ^ n";
  14.147 +by (induct_tac "n" 1);
  14.148 +by (auto_tac (claset(),
  14.149 +        simpset() addsimps [hypreal_of_nat_Suc,hypreal_of_nat_zero,
  14.150 +          hypreal_zero_less_one,hypreal_add_mult_distrib,hypreal_of_nat_one]));
  14.151 +by (cut_inst_tac [("n","n")] two_hrealpow_ge_one 1);
  14.152 +by (arith_tac 1);
  14.153 +qed "two_hrealpow_gt";
  14.154 +Addsimps [two_hrealpow_gt,two_hrealpow_ge_one];
  14.155 +
  14.156 +Goal "#-1 ^ (2*n) = (#1::hypreal)";
  14.157 +by (induct_tac "n" 1);
  14.158 +by (Auto_tac);
  14.159 +qed "hrealpow_minus_one";
  14.160 +
  14.161 +Goal "#-1 ^ (n + n) = (#1::hypreal)";
  14.162 +by (induct_tac "n" 1);
  14.163 +by (Auto_tac);
  14.164 +qed "hrealpow_minus_one2";
  14.165 +Addsimps [hrealpow_minus_one2];
  14.166 +
  14.167 +Goal "(-(x::hypreal)) ^ 2 = x ^ 2";
  14.168 +by (Auto_tac);
  14.169 +qed "hrealpow_minus_two";
  14.170 +Addsimps [hrealpow_minus_two];
  14.171 +
  14.172 +Goal "(#0::hypreal) < r & r < #1 --> r ^ Suc n < r ^ n";
  14.173 +by (induct_tac "n" 1);
  14.174 +by (auto_tac (claset(),
  14.175 +              simpset() addsimps [hypreal_mult_less_mono2]));
  14.176 +qed_spec_mp "hrealpow_Suc_less";
  14.177 +
  14.178 +Goal "(#0::hypreal) <= r & r < #1 --> r ^ Suc n <= r ^ n";
  14.179 +by (induct_tac "n" 1);
  14.180 +by (auto_tac (claset() addIs [order_less_imp_le]
  14.181 +                       addSDs [order_le_imp_less_or_eq,hrealpow_Suc_less],
  14.182 +              simpset() addsimps [hypreal_mult_less_mono2]));
  14.183 +qed_spec_mp "hrealpow_Suc_le";
  14.184 +
  14.185 +Goal "Abs_hypreal(hyprel^^{%n. X n}) ^ m = Abs_hypreal(hyprel^^{%n. (X n) ^ m})";
  14.186 +by (induct_tac "m" 1);
  14.187 +by (auto_tac (claset(),
  14.188 +              simpset() delsimps [one_eq_numeral_1]
  14.189 +			addsimps [hypreal_one_def, hypreal_mult,
  14.190 +                                  one_eq_numeral_1 RS sym]));
  14.191 +qed "hrealpow";
  14.192 +
  14.193 +Goal "(x + (y::hypreal)) ^ 2 = \
  14.194 +\     x ^ 2 + y ^ 2 + (hypreal_of_nat 2)*x*y";
  14.195 +by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib2,
  14.196 +               hypreal_add_mult_distrib,hypreal_of_nat_two] 
  14.197 +                @ hypreal_add_ac @ hypreal_mult_ac) 1);
  14.198 +qed "hrealpow_sum_square_expand";
  14.199 +
  14.200 +(*---------------------------------------------------------------
  14.201 +   we'll prove the following theorem by going down to the
  14.202 +   level of the ultrafilter and relying on the analogous
  14.203 +   property for the real rather than prove it directly 
  14.204 +   using induction: proof is much simpler this way!
  14.205 + ---------------------------------------------------------------*)
  14.206 +Goal "[|(#0::hypreal) <= x; #0 <= y;x ^ Suc n <= y ^ Suc n |] ==> x <= y";
  14.207 +by (full_simp_tac
  14.208 +    (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.209 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  14.210 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  14.211 +by (auto_tac (claset(),
  14.212 +              simpset() addsimps [hrealpow,hypreal_le,hypreal_mult]));
  14.213 +by (ultra_tac (claset() addIs [realpow_increasing], simpset()) 1);
  14.214 +qed "hrealpow_increasing";
  14.215 +
  14.216 +(*By antisymmetry with the above we conclude x=y, replacing the deleted 
  14.217 +  theorem hrealpow_Suc_cancel_eq*)
  14.218 +
  14.219 +Goal "x : HFinite --> x ^ n : HFinite";
  14.220 +by (induct_tac "n" 1);
  14.221 +by (auto_tac (claset() addIs [HFinite_mult], simpset()));
  14.222 +qed_spec_mp "hrealpow_HFinite";
  14.223 +
  14.224 +(*---------------------------------------------------------------
  14.225 +                  Hypernaturals Powers
  14.226 + --------------------------------------------------------------*)
  14.227 +Goalw [congruent_def]
  14.228 +     "congruent hyprel \
  14.229 +\    (%X Y. hyprel^^{%n. ((X::nat=>real) n ^ (Y::nat=>nat) n)})";
  14.230 +by (safe_tac (claset() addSIs [ext]));
  14.231 +by (ALLGOALS(Fuf_tac));
  14.232 +qed "hyperpow_congruent";
  14.233 +
  14.234 +Goalw [hyperpow_def]
  14.235 +  "Abs_hypreal(hyprel^^{%n. X n}) pow Abs_hypnat(hypnatrel^^{%n. Y n}) = \
  14.236 +\  Abs_hypreal(hyprel^^{%n. X n ^ Y n})";
  14.237 +by (res_inst_tac [("f","Abs_hypreal")] arg_cong 1);
  14.238 +by (auto_tac (claset() addSIs [lemma_hyprel_refl,bexI],
  14.239 +    simpset() addsimps [hyprel_in_hypreal RS 
  14.240 +    Abs_hypreal_inverse,equiv_hyprel,hyperpow_congruent]));
  14.241 +by (Fuf_tac 1);
  14.242 +qed "hyperpow";
  14.243 +
  14.244 +Goalw [hypnat_one_def] "(#0::hypreal) pow (n + 1hn) = #0";
  14.245 +by (simp_tac (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.246 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.247 +by (auto_tac (claset(), simpset() addsimps [hyperpow,hypnat_add]));
  14.248 +qed "hyperpow_zero";
  14.249 +Addsimps [hyperpow_zero];
  14.250 +
  14.251 +Goal "r ~= (#0::hypreal) --> r pow n ~= #0";
  14.252 +by (simp_tac (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.253 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.254 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.255 +by (auto_tac (claset(), simpset() addsimps [hyperpow]));
  14.256 +by (dtac FreeUltrafilterNat_Compl_mem 1);
  14.257 +by (fuf_empty_tac (claset() addIs [realpow_not_zero RS notE],
  14.258 +    simpset()) 1);
  14.259 +qed_spec_mp "hyperpow_not_zero";
  14.260 +
  14.261 +Goal "r ~= (#0::hypreal) --> inverse(r pow n) = (inverse r) pow n";
  14.262 +by (simp_tac (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.263 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.264 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.265 +by (auto_tac (claset() addSDs [FreeUltrafilterNat_Compl_mem],
  14.266 +              simpset() addsimps [hypreal_inverse,hyperpow]));
  14.267 +by (rtac FreeUltrafilterNat_subset 1);
  14.268 +by (auto_tac (claset() addDs [realpow_not_zero] 
  14.269 +                       addIs [realpow_inverse], 
  14.270 +              simpset()));
  14.271 +qed "hyperpow_inverse";
  14.272 +
  14.273 +Goal "abs r pow n = abs (r pow n)";
  14.274 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.275 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.276 +by (auto_tac (claset(),
  14.277 +              simpset() addsimps [hypreal_hrabs, hyperpow,realpow_abs]));
  14.278 +qed "hyperpow_hrabs";
  14.279 +
  14.280 +Goal "r pow (n + m) = (r pow n) * (r pow m)";
  14.281 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.282 +by (res_inst_tac [("z","m")] eq_Abs_hypnat 1);
  14.283 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.284 +by (auto_tac (claset(),
  14.285 +          simpset() addsimps [hyperpow,hypnat_add, hypreal_mult,realpow_add]));
  14.286 +qed "hyperpow_add";
  14.287 +
  14.288 +Goalw [hypnat_one_def] "r pow 1hn = r";
  14.289 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.290 +by (auto_tac (claset(), simpset() addsimps [hyperpow]));
  14.291 +qed "hyperpow_one";
  14.292 +Addsimps [hyperpow_one];
  14.293 +
  14.294 +Goalw [hypnat_one_def] 
  14.295 +      "r pow (1hn + 1hn) = r * r";
  14.296 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.297 +by (auto_tac (claset(),
  14.298 +           simpset() addsimps [hyperpow,hypnat_add, hypreal_mult,realpow_two]));
  14.299 +qed "hyperpow_two";
  14.300 +
  14.301 +Goal "(#0::hypreal) < r --> #0 < r pow n";
  14.302 +by (simp_tac (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.303 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.304 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.305 +by (auto_tac (claset() addSEs [FreeUltrafilterNat_subset, realpow_gt_zero],
  14.306 +              simpset() addsimps [hyperpow,hypreal_less, hypreal_le]));
  14.307 +qed_spec_mp "hyperpow_gt_zero";
  14.308 +
  14.309 +Goal "(#0::hypreal) < r --> #0 <= r pow n";
  14.310 +by (blast_tac (claset() addSIs [hyperpow_gt_zero, order_less_imp_le]) 1);
  14.311 +qed_spec_mp "hyperpow_ge_zero";
  14.312 +
  14.313 +Goal "(#0::hypreal) <= r --> #0 <= r pow n";
  14.314 +by (simp_tac (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.315 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.316 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.317 +by (auto_tac (claset() addSEs [FreeUltrafilterNat_subset, realpow_ge_zero2],
  14.318 +              simpset() addsimps [hyperpow,hypreal_le]));
  14.319 +qed "hyperpow_ge_zero2";
  14.320 +
  14.321 +Goal "(#0::hypreal) < x & x <= y --> x pow n <= y pow n";
  14.322 +by (full_simp_tac
  14.323 +    (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def]) 1);
  14.324 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.325 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  14.326 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  14.327 +by (auto_tac (claset() addIs [realpow_le,
  14.328 +    (FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset)],
  14.329 +    simpset() addsimps [hyperpow,hypreal_le,hypreal_less]));
  14.330 +qed_spec_mp "hyperpow_le";
  14.331 +
  14.332 +Goal "#1 pow n = (#1::hypreal)";
  14.333 +by (simp_tac (HOL_ss addsimps [one_eq_numeral_1 RS sym, hypreal_one_def]) 1);
  14.334 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.335 +by (auto_tac (claset(), simpset() addsimps [hyperpow]));
  14.336 +qed "hyperpow_eq_one";
  14.337 +Addsimps [hyperpow_eq_one];
  14.338 +
  14.339 +Goal "abs(-(#1 pow n)) = (#1::hypreal)";
  14.340 +by (simp_tac (HOL_ss addsimps [one_eq_numeral_1 RS sym, hypreal_one_def]) 1);
  14.341 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.342 +by (auto_tac (claset(), simpset() addsimps [hyperpow,hypreal_hrabs]));
  14.343 +qed "hrabs_minus_hyperpow_one";
  14.344 +Addsimps [hrabs_minus_hyperpow_one];
  14.345 +
  14.346 +Goal "abs(#-1 pow n) = (#1::hypreal)";
  14.347 +by (subgoal_tac "abs((-1hr) pow n) = 1hr" 1);
  14.348 +by (Asm_full_simp_tac 1); 
  14.349 +by (simp_tac (HOL_ss addsimps [hypreal_one_def]) 1);
  14.350 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.351 +by (auto_tac (claset(),
  14.352 +       simpset() addsimps [hyperpow,hypreal_minus,hypreal_hrabs]));
  14.353 +qed "hrabs_hyperpow_minus_one";
  14.354 +Addsimps [hrabs_hyperpow_minus_one];
  14.355 +
  14.356 +Goal "(r * s) pow n = (r pow n) * (s pow n)";
  14.357 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.358 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.359 +by (res_inst_tac [("z","s")] eq_Abs_hypreal 1);
  14.360 +by (auto_tac (claset(),
  14.361 +       simpset() addsimps [hyperpow, hypreal_mult,realpow_mult]));
  14.362 +qed "hyperpow_mult";
  14.363 +
  14.364 +Goal "(#0::hypreal) <= r pow (1hn + 1hn)";
  14.365 +by (auto_tac (claset(), 
  14.366 +              simpset() addsimps [hyperpow_two, hypreal_0_le_mult_iff]));
  14.367 +qed "hyperpow_two_le";
  14.368 +Addsimps [hyperpow_two_le];
  14.369 +
  14.370 +Goal "abs(x pow (1hn + 1hn)) = x pow (1hn + 1hn)";
  14.371 +by (simp_tac (simpset() addsimps [hrabs_eqI1]) 1);
  14.372 +qed "hrabs_hyperpow_two";
  14.373 +Addsimps [hrabs_hyperpow_two];
  14.374 +
  14.375 +Goal "abs(x) pow (1hn + 1hn)  = x pow (1hn + 1hn)";
  14.376 +by (simp_tac (simpset() addsimps [hyperpow_hrabs,hrabs_eqI1]) 1);
  14.377 +qed "hyperpow_two_hrabs";
  14.378 +Addsimps [hyperpow_two_hrabs];
  14.379 +
  14.380 +(*? very similar to hrealpow_two_gt_one *)
  14.381 +Goal "(#1::hypreal) < r ==> #1 < r pow (1hn + 1hn)";
  14.382 +by (auto_tac (claset(), simpset() addsimps [hyperpow_two]));
  14.383 +by (res_inst_tac [("y","#1*#1")] order_le_less_trans 1); 
  14.384 +by (rtac hypreal_mult_less_mono 2); 
  14.385 +by Auto_tac;  
  14.386 +qed "hyperpow_two_gt_one";
  14.387 +
  14.388 +Goal "(#1::hypreal) <= r ==> #1 <= r pow (1hn + 1hn)";
  14.389 +by (auto_tac (claset() addSDs [order_le_imp_less_or_eq] 
  14.390 +                       addIs [hyperpow_two_gt_one,order_less_imp_le],
  14.391 +              simpset()));
  14.392 +qed "hyperpow_two_ge_one";
  14.393 +
  14.394 +Goal "(#1::hypreal) <= #2 pow n";
  14.395 +by (res_inst_tac [("y","#1 pow n")] order_trans 1);
  14.396 +by (rtac hyperpow_le 2);
  14.397 +by (auto_tac (claset() addIs [order_less_imp_le],
  14.398 +          simpset() addsimps [hypreal_zero_less_one, hypreal_one_less_two]));
  14.399 +qed "two_hyperpow_ge_one";
  14.400 +Addsimps [two_hyperpow_ge_one];
  14.401 +
  14.402 +Addsimps [simplify (simpset()) realpow_minus_one];
  14.403 +
  14.404 +Goal "#-1 pow ((1hn + 1hn)*n) = (#1::hypreal)";
  14.405 +by (subgoal_tac "(-(1hr)) pow ((1hn + 1hn)*n) = 1hr" 1);
  14.406 +by (Asm_full_simp_tac 1); 
  14.407 +by (simp_tac (HOL_ss addsimps [hypreal_one_def]) 1);
  14.408 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.409 +by (auto_tac (claset(),
  14.410 +              simpset() addsimps [hyperpow, hypnat_add,hypreal_minus]));
  14.411 +qed "hyperpow_minus_one2";
  14.412 +Addsimps [hyperpow_minus_one2];
  14.413 +
  14.414 +Goalw [hypnat_one_def]
  14.415 +     "(#0::hypreal) < r & r < #1 --> r pow (n + 1hn) < r pow n";
  14.416 +by (full_simp_tac
  14.417 +    (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def,
  14.418 +                      one_eq_numeral_1 RS sym, hypreal_one_def]) 1);
  14.419 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.420 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.421 +by (auto_tac (claset() addSDs [conjI RS realpow_Suc_less] 
  14.422 +                  addEs [FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset],
  14.423 +              simpset() addsimps [hyperpow,hypreal_less,hypnat_add]));
  14.424 +qed_spec_mp "hyperpow_Suc_less";
  14.425 +
  14.426 +Goalw [hypnat_one_def]
  14.427 +     "#0 <= r & r < (#1::hypreal) --> r pow (n + 1hn) <= r pow n";
  14.428 +by (full_simp_tac
  14.429 +    (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def,
  14.430 +                      one_eq_numeral_1 RS sym, hypreal_one_def]) 1);
  14.431 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.432 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.433 +by (auto_tac (claset() addSDs [conjI RS realpow_Suc_le] addEs
  14.434 +    [FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset ],
  14.435 +    simpset() addsimps [hyperpow,hypreal_le,hypnat_add,
  14.436 +    hypreal_less]));
  14.437 +qed_spec_mp "hyperpow_Suc_le";
  14.438 +
  14.439 +Goalw [hypnat_one_def]
  14.440 +     "(#0::hypreal) <= r & r < #1 & n < N --> r pow N <= r pow n";
  14.441 +by (full_simp_tac
  14.442 +    (HOL_ss addsimps [zero_eq_numeral_0 RS sym, hypreal_zero_def,
  14.443 +                      one_eq_numeral_1 RS sym, hypreal_one_def]) 1);
  14.444 +by (res_inst_tac [("z","n")] eq_Abs_hypnat 1);
  14.445 +by (res_inst_tac [("z","N")] eq_Abs_hypnat 1);
  14.446 +by (res_inst_tac [("z","r")] eq_Abs_hypreal 1);
  14.447 +by (auto_tac (claset(),
  14.448 +        simpset() addsimps [hyperpow, hypreal_le,hypreal_less,hypnat_less]));
  14.449 +by (etac (FreeUltrafilterNat_Int RS FreeUltrafilterNat_subset) 1);
  14.450 +by (etac FreeUltrafilterNat_Int 1);
  14.451 +by (auto_tac (claset() addSDs [conjI RS realpow_less_le],
  14.452 +    simpset()));
  14.453 +qed_spec_mp "hyperpow_less_le";
  14.454 +
  14.455 +Goal "[| (#0::hypreal) <= r; r < #1 |]  \
  14.456 +\     ==> ALL N n. n < N --> r pow N <= r pow n";
  14.457 +by (blast_tac (claset() addSIs [hyperpow_less_le]) 1);
  14.458 +qed "hyperpow_less_le2";
  14.459 +
  14.460 +Goal "[| #0 <= r;  r < (#1::hypreal);  N : HNatInfinite |]  \
  14.461 +\     ==> ALL n:SHNat. r pow N <= r pow n";
  14.462 +by (auto_tac (claset() addSIs [hyperpow_less_le],
  14.463 +              simpset() addsimps [HNatInfinite_iff]));
  14.464 +qed "hyperpow_SHNat_le";
  14.465 +
  14.466 +Goalw [hypreal_of_real_def,hypnat_of_nat_def] 
  14.467 +      "(hypreal_of_real r) pow (hypnat_of_nat n) = hypreal_of_real (r ^ n)";
  14.468 +by (auto_tac (claset(), simpset() addsimps [hyperpow]));
  14.469 +qed "hyperpow_realpow";
  14.470 +
  14.471 +Goalw [SReal_def]
  14.472 +     "(hypreal_of_real r) pow (hypnat_of_nat n) : SReal";
  14.473 +by (auto_tac (claset(), simpset() addsimps [hyperpow_realpow]));
  14.474 +qed "hyperpow_SReal";
  14.475 +Addsimps [hyperpow_SReal];
  14.476 +
  14.477 +Goal "N : HNatInfinite ==> (#0::hypreal) pow N = 0";
  14.478 +by (dtac HNatInfinite_is_Suc 1);
  14.479 +by (Auto_tac);
  14.480 +qed "hyperpow_zero_HNatInfinite";
  14.481 +Addsimps [hyperpow_zero_HNatInfinite];
  14.482 +
  14.483 +Goal "[| (#0::hypreal) <= r; r < #1; n <= N |] ==> r pow N <= r pow n";
  14.484 +by (dres_inst_tac [("y","N")] hypnat_le_imp_less_or_eq 1);
  14.485 +by (auto_tac (claset() addIs [hyperpow_less_le], simpset()));
  14.486 +qed "hyperpow_le_le";
  14.487 +
  14.488 +Goal "[| (#0::hypreal) < r; r < #1 |] ==> r pow (n + 1hn) <= r";
  14.489 +by (dres_inst_tac [("n","1hn")] (order_less_imp_le RS hyperpow_le_le) 1);
  14.490 +by (Auto_tac);
  14.491 +qed "hyperpow_Suc_le_self";
  14.492 +
  14.493 +Goal "[| (#0::hypreal) <= r; r < #1 |] ==> r pow (n + 1hn) <= r";
  14.494 +by (dres_inst_tac [("n","1hn")] hyperpow_le_le 1);
  14.495 +by (Auto_tac);
  14.496 +qed "hyperpow_Suc_le_self2";
  14.497 +
  14.498 +Goalw [Infinitesimal_def]
  14.499 +     "[| x : Infinitesimal; 0 < N |] ==> (abs x) pow N <= abs x";
  14.500 +by (auto_tac (claset() addSIs [hyperpow_Suc_le_self2],
  14.501 +    simpset() addsimps [hyperpow_hrabs RS sym,
  14.502 +                        hypnat_gt_zero_iff2, hrabs_ge_zero,
  14.503 +                        hypreal_zero_less_one]));
  14.504 +qed "lemma_Infinitesimal_hyperpow";
  14.505 +
  14.506 +Goal "[| x : Infinitesimal; 0 < N |] ==> x pow N : Infinitesimal";
  14.507 +by (rtac hrabs_le_Infinitesimal 1);
  14.508 +by (dtac Infinitesimal_hrabs 1);
  14.509 +by (auto_tac (claset() addSIs [lemma_Infinitesimal_hyperpow],
  14.510 +    simpset() addsimps [hyperpow_hrabs RS sym]));
  14.511 +qed "Infinitesimal_hyperpow";
  14.512 +
  14.513 +Goalw [hypnat_of_nat_def] 
  14.514 +     "(x ^ n : Infinitesimal) = (x pow (hypnat_of_nat n) : Infinitesimal)";
  14.515 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  14.516 +by (auto_tac (claset(), simpset() addsimps [hrealpow, hyperpow]));
  14.517 +qed "hrealpow_hyperpow_Infinitesimal_iff";
  14.518 +
  14.519 +Goal "[| x : Infinitesimal; 0 < n |] ==> x ^ n : Infinitesimal";
  14.520 +by (auto_tac (claset() addSIs [Infinitesimal_hyperpow],
  14.521 +    simpset() addsimps [hrealpow_hyperpow_Infinitesimal_iff,
  14.522 +                        hypnat_of_nat_less_iff,hypnat_of_nat_zero] 
  14.523 +              delsimps [hypnat_of_nat_less_iff RS sym]));
  14.524 +qed "Infinitesimal_hrealpow";
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/HOL/Hyperreal/HyperPow.thy	Sat Dec 30 22:03:47 2000 +0100
    15.3 @@ -0,0 +1,26 @@
    15.4 +(*  Title       : HyperPow.thy
    15.5 +    Author      : Jacques D. Fleuriot  
    15.6 +    Copyright   : 1998  University of Cambridge
    15.7 +    Description : Powers theory for hyperreals
    15.8 +*)
    15.9 +
   15.10 +HyperPow = HRealAbs + HyperNat + RealPow +  
   15.11 +
   15.12 +instance hypreal :: {power}
   15.13 +
   15.14 +consts hpowr :: "[hypreal,nat] => hypreal"  
   15.15 +primrec
   15.16 +     hpowr_0   "r ^ 0       = 1hr"
   15.17 +     hpowr_Suc "r ^ (Suc n) = (r::hypreal) * (r ^ n)"
   15.18 +
   15.19 +consts
   15.20 +  "pow"  :: [hypreal,hypnat] => hypreal     (infixr 80)
   15.21 +
   15.22 +defs
   15.23 +
   15.24 +  (* hypernatural powers of hyperreals *)
   15.25 +  hyperpow_def
   15.26 +  "(R::hypreal) pow (N::hypnat) 
   15.27 +      == Abs_hypreal(UN X:Rep_hypreal(R). UN Y: Rep_hypnat(N).
   15.28 +             hyprel^^{%n::nat. (X n) ^ (Y n)})"
   15.29 +end
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/HOL/Hyperreal/Hyperreal.thy	Sat Dec 30 22:03:47 2000 +0100
    16.3 @@ -0,0 +1,4 @@
    16.4 +
    16.5 +theory Hyperreal = HSeries:
    16.6 +
    16.7 +end
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/HOL/Hyperreal/Lim.ML	Sat Dec 30 22:03:47 2000 +0100
    17.3 @@ -0,0 +1,2324 @@
    17.4 +(*  Title       : Lim.ML
    17.5 +    Author      : Jacques D. Fleuriot
    17.6 +    Copyright   : 1998  University of Cambridge
    17.7 +    Description : Theory of limits, continuity and 
    17.8 +                  differentiation of real=>real functions
    17.9 +*)
   17.10 +
   17.11 +
   17.12 +fun ARITH_PROVE str = prove_goal thy str 
   17.13 +                      (fn prems => [cut_facts_tac prems 1,arith_tac 1]);
   17.14 +
   17.15 +
   17.16 +(*---------------------------------------------------------------
   17.17 +   Theory of limits, continuity and differentiation of 
   17.18 +   real=>real functions 
   17.19 + ----------------------------------------------------------------*)
   17.20 +
   17.21 +Goalw [LIM_def] "(%x. k) -- x --> k";
   17.22 +by Auto_tac;
   17.23 +qed "LIM_const";
   17.24 +Addsimps [LIM_const];
   17.25 +
   17.26 +(***-----------------------------------------------------------***)
   17.27 +(***  Some Purely Standard Proofs - Can be used for comparison ***)
   17.28 +(***-----------------------------------------------------------***)
   17.29 + 
   17.30 +(*--------------- 
   17.31 +    LIM_add    
   17.32 + ---------------*)
   17.33 +Goalw [LIM_def] 
   17.34 +     "[| f -- x --> l; g -- x --> m |] \
   17.35 +\     ==> (%x. f(x) + g(x)) -- x --> (l + m)";
   17.36 +by (Step_tac 1);
   17.37 +by (REPEAT(dres_inst_tac [("x","r/#2")] spec 1));
   17.38 +by (dtac (rename_numerals (real_zero_less_two RS real_inverse_gt_zero 
   17.39 +          RSN (2,real_mult_less_mono2))) 1);
   17.40 +by (Asm_full_simp_tac 1);
   17.41 +by (Clarify_tac 1);
   17.42 +by (res_inst_tac [("R1.0","s"),("R2.0","sa")] 
   17.43 +    real_linear_less2 1);
   17.44 +by (res_inst_tac [("x","s")] exI 1);
   17.45 +by (res_inst_tac [("x","sa")] exI 2);
   17.46 +by (res_inst_tac [("x","sa")] exI 3);
   17.47 +by (Step_tac 1);
   17.48 +by (REPEAT(dres_inst_tac [("x","xa")] spec 1) 
   17.49 +    THEN step_tac (claset() addSEs [order_less_trans]) 1);
   17.50 +by (REPEAT(dres_inst_tac [("x","xa")] spec 2) 
   17.51 +    THEN step_tac (claset() addSEs [order_less_trans]) 2);
   17.52 +by (REPEAT(dres_inst_tac [("x","xa")] spec 3) 
   17.53 +    THEN step_tac (claset() addSEs [order_less_trans]) 3);
   17.54 +by (ALLGOALS(rtac (abs_sum_triangle_ineq RS order_le_less_trans)));
   17.55 +by (ALLGOALS(rtac (real_sum_of_halves RS subst)));
   17.56 +by (auto_tac (claset() addIs [real_add_less_mono],simpset()));
   17.57 +qed "LIM_add";
   17.58 +
   17.59 +Goalw [LIM_def] "f -- a --> L ==> (%x. -f(x)) -- a --> -L";
   17.60 +by (full_simp_tac (simpset() addsimps [real_minus_add_distrib RS sym] 
   17.61 +                    delsimps [real_minus_add_distrib, real_minus_minus]) 1);
   17.62 +qed "LIM_minus";
   17.63 +
   17.64 +(*----------------------------------------------
   17.65 +     LIM_add_minus
   17.66 + ----------------------------------------------*)
   17.67 +Goal "[| f -- x --> l; g -- x --> m |] \
   17.68 +\     ==> (%x. f(x) + -g(x)) -- x --> (l + -m)";
   17.69 +by (blast_tac (claset() addDs [LIM_add,LIM_minus]) 1);
   17.70 +qed "LIM_add_minus";
   17.71 +
   17.72 +(*----------------------------------------------
   17.73 +     LIM_zero
   17.74 + ----------------------------------------------*)
   17.75 +Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> #0";
   17.76 +by (res_inst_tac [("z1","l")] (rename_numerals (real_add_minus RS subst)) 1);
   17.77 +by (rtac LIM_add_minus 1 THEN Auto_tac);
   17.78 +qed "LIM_zero";
   17.79 +
   17.80 +(*--------------------------
   17.81 +   Limit not zero
   17.82 + --------------------------*)
   17.83 +Goalw [LIM_def] "k ~= #0 ==> ~ ((%x. k) -- x --> #0)";
   17.84 +by (res_inst_tac [("R1.0","k"),("R2.0","#0")] real_linear_less2 1);
   17.85 +by (auto_tac (claset(), simpset() addsimps [real_abs_def]));
   17.86 +by (res_inst_tac [("x","-k")] exI 1);
   17.87 +by (res_inst_tac [("x","k")] exI 2);
   17.88 +by Auto_tac;
   17.89 +by (ALLGOALS(dres_inst_tac [("y","s")] real_dense));
   17.90 +by Safe_tac;
   17.91 +by (ALLGOALS(res_inst_tac [("x","r + x")] exI));
   17.92 +by Auto_tac;  
   17.93 +qed "LIM_not_zero";
   17.94 +
   17.95 +(* [| k ~= #0; (%x. k) -- x --> #0 |] ==> R *)
   17.96 +bind_thm("LIM_not_zeroE", LIM_not_zero RS notE);
   17.97 +
   17.98 +Goal "(%x. k) -- x --> L ==> k = L";
   17.99 +by (rtac ccontr 1);
  17.100 +by (dtac LIM_zero 1);
  17.101 +by (rtac LIM_not_zeroE 1 THEN assume_tac 2);
  17.102 +by (arith_tac 1);
  17.103 +qed "LIM_const_eq";
  17.104 +
  17.105 +(*------------------------
  17.106 +     Limit is Unique
  17.107 + ------------------------*)
  17.108 +Goal "[| f -- x --> L; f -- x --> M |] ==> L = M";
  17.109 +by (dtac LIM_minus 1);
  17.110 +by (dtac LIM_add 1 THEN assume_tac 1);
  17.111 +by (auto_tac (claset() addSDs [LIM_const_eq RS sym],  simpset()));
  17.112 +qed "LIM_unique";
  17.113 +
  17.114 +(*-------------
  17.115 +    LIM_mult_zero
  17.116 + -------------*)
  17.117 +Goalw [LIM_def] "[| f -- x --> #0; g -- x --> #0 |] \
  17.118 +\         ==> (%x. f(x)*g(x)) -- x --> #0";
  17.119 +by (Step_tac 1);
  17.120 +by (dres_inst_tac [("x","#1")] spec 1);
  17.121 +by (dres_inst_tac [("x","r")] spec 1);
  17.122 +by (cut_facts_tac [real_zero_less_one] 1);
  17.123 +by (asm_full_simp_tac (simpset() addsimps 
  17.124 +    [abs_mult]) 1);
  17.125 +by (Clarify_tac 1);
  17.126 +by (res_inst_tac [("R1.0","s"),("R2.0","sa")] 
  17.127 +    real_linear_less2 1);
  17.128 +by (res_inst_tac [("x","s")] exI 1);
  17.129 +by (res_inst_tac [("x","sa")] exI 2);
  17.130 +by (res_inst_tac [("x","sa")] exI 3);
  17.131 +by (Step_tac 1);
  17.132 +by (REPEAT(dres_inst_tac [("x","xa")] spec 1) 
  17.133 +    THEN step_tac (claset() addSEs [order_less_trans]) 1);
  17.134 +by (REPEAT(dres_inst_tac [("x","xa")] spec 2) 
  17.135 +    THEN step_tac (claset() addSEs [order_less_trans]) 2);
  17.136 +by (REPEAT(dres_inst_tac [("x","xa")] spec 3) 
  17.137 +    THEN step_tac (claset() addSEs [order_less_trans]) 3);
  17.138 +by (ALLGOALS(res_inst_tac [("t","r")] (real_mult_1 RS subst)));
  17.139 +by (ALLGOALS(rtac abs_mult_less2));
  17.140 +by Auto_tac;
  17.141 +qed "LIM_mult_zero";
  17.142 +
  17.143 +Goalw [LIM_def] "(%x. x) -- a --> a";
  17.144 +by Auto_tac;
  17.145 +qed "LIM_self";
  17.146 +
  17.147 +(*--------------------------------------------------------------
  17.148 +   Limits are equal for functions equal except at limit point
  17.149 + --------------------------------------------------------------*)
  17.150 +Goalw [LIM_def] 
  17.151 +      "[| ALL x. x ~= a --> (f x = g x) |] \
  17.152 +\           ==> (f -- a --> l) = (g -- a --> l)";
  17.153 +by (auto_tac (claset(), simpset() addsimps [real_add_minus_iff]));
  17.154 +qed "LIM_equal";
  17.155 +
  17.156 +Goal "[| (%x. f(x) + -g(x)) -- a --> #0; \
  17.157 +\        g -- a --> l |] \
  17.158 +\      ==> f -- a --> l";
  17.159 +by (dtac LIM_add 1 THEN assume_tac 1);
  17.160 +by (auto_tac (claset(), simpset() addsimps [real_add_assoc]));
  17.161 +qed "LIM_trans";
  17.162 +
  17.163 +(***-------------------------------------------------------------***)
  17.164 +(***           End of Purely Standard Proofs                     ***)
  17.165 +(***-------------------------------------------------------------***)
  17.166 +(*--------------------------------------------------------------
  17.167 +       Standard and NS definitions of Limit
  17.168 + --------------------------------------------------------------*)
  17.169 +Goalw [LIM_def,NSLIM_def,inf_close_def] 
  17.170 +      "f -- x --> L ==> f -- x --NS> L";
  17.171 +by (asm_full_simp_tac
  17.172 +    (simpset() addsimps [Infinitesimal_FreeUltrafilterNat_iff]) 1);
  17.173 +by (Step_tac 1);
  17.174 +by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
  17.175 +by (auto_tac (claset(),
  17.176 +      simpset() addsimps [real_add_minus_iff, starfun, hypreal_minus, 
  17.177 +                          hypreal_of_real_def, hypreal_add]));
  17.178 +by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2 THEN Step_tac 1);
  17.179 +by (dres_inst_tac [("x","u")] spec 1 THEN Clarify_tac 1);
  17.180 +by (dres_inst_tac [("x","s")] spec 1 THEN Clarify_tac 1);
  17.181 +by (subgoal_tac "ALL n::nat. (xa n) ~= x & \
  17.182 +\                    abs ((xa n) + - x) < s --> abs (f (xa n) + - L) < u" 1);
  17.183 +by (Blast_tac 2);
  17.184 +by (dtac FreeUltrafilterNat_all 1);
  17.185 +by (Ultra_tac 1);
  17.186 +qed "LIM_NSLIM";
  17.187 + 
  17.188 +(*---------------------------------------------------------------------
  17.189 +    Limit: NS definition ==> standard definition
  17.190 + ---------------------------------------------------------------------*)
  17.191 +
  17.192 +Goal "ALL s. #0 < s --> (EX xa.  xa ~= x & \
  17.193 +\        abs (xa + - x) < s  & r <= abs (f xa + -L)) \
  17.194 +\     ==> ALL n::nat. EX xa.  xa ~= x & \
  17.195 +\             abs(xa + -x) < inverse(real_of_posnat n) & r <= abs(f xa + -L)";
  17.196 +by (Step_tac 1);
  17.197 +by (cut_inst_tac [("n1","n")]
  17.198 +    (real_of_posnat_gt_zero RS real_inverse_gt_zero) 1);
  17.199 +by Auto_tac;
  17.200 +val lemma_LIM = result();
  17.201 +
  17.202 +Goal "ALL s. #0 < s --> (EX xa.  xa ~= x & \
  17.203 +\        abs (xa + - x) < s  & r <= abs (f xa + -L)) \
  17.204 +\     ==> EX X. ALL n::nat. X n ~= x & \
  17.205 +\               abs(X n + -x) < inverse(real_of_posnat n) & r <= abs(f (X n) + -L)";
  17.206 +by (dtac lemma_LIM 1);
  17.207 +by (dtac choice 1);
  17.208 +by (Blast_tac 1);
  17.209 +val lemma_skolemize_LIM2 = result();
  17.210 +
  17.211 +Goal "ALL n. X n ~= x & \
  17.212 +\         abs (X n + - x) < inverse (real_of_posnat  n) & \
  17.213 +\         r <= abs (f (X n) + - L) ==> \
  17.214 +\         ALL n. abs (X n + - x) < inverse (real_of_posnat  n)";
  17.215 +by (Auto_tac );
  17.216 +val lemma_simp = result();
  17.217 + 
  17.218 +(*-------------------
  17.219 +    NSLIM => LIM
  17.220 + -------------------*)
  17.221 +
  17.222 +Goalw [LIM_def,NSLIM_def,inf_close_def] 
  17.223 +      "f -- x --NS> L ==> f -- x --> L";
  17.224 +by (asm_full_simp_tac
  17.225 +    (simpset() addsimps [Infinitesimal_FreeUltrafilterNat_iff]) 1);
  17.226 +by (EVERY1[Step_tac, rtac ccontr, Asm_full_simp_tac]);
  17.227 +by (fold_tac [real_le_def]);
  17.228 +by (dtac lemma_skolemize_LIM2 1);
  17.229 +by (Step_tac 1);
  17.230 +by (dres_inst_tac [("x","Abs_hypreal(hyprel^^{X})")] spec 1);
  17.231 +by (asm_full_simp_tac
  17.232 +    (simpset() addsimps [starfun, hypreal_minus, 
  17.233 +                         hypreal_of_real_def,hypreal_add]) 1);
  17.234 +by (Step_tac 1);
  17.235 +by (dtac (lemma_simp RS real_seq_to_hypreal_Infinitesimal) 1);
  17.236 +by (asm_full_simp_tac
  17.237 +    (simpset() addsimps 
  17.238 +       [Infinitesimal_FreeUltrafilterNat_iff,hypreal_of_real_def,
  17.239 +        hypreal_minus, hypreal_add]) 1);
  17.240 +by (Blast_tac 1); 
  17.241 +by (rotate_tac 2 1);
  17.242 +by (dres_inst_tac [("x","r")] spec 1);
  17.243 +by (Clarify_tac 1);
  17.244 +by (dtac FreeUltrafilterNat_all 1);
  17.245 +by (Ultra_tac 1);
  17.246 +qed "NSLIM_LIM";
  17.247 +
  17.248 +
  17.249 +(**** Key result ****)
  17.250 +Goal "(f -- x --> L) = (f -- x --NS> L)";
  17.251 +by (blast_tac (claset() addIs [LIM_NSLIM,NSLIM_LIM]) 1);
  17.252 +qed "LIM_NSLIM_iff";
  17.253 +
  17.254 +(*-------------------------------------------------------------------*)
  17.255 +(*   Proving properties of limits using nonstandard definition and   *)
  17.256 +(*   hence, the properties hold for standard limits as well          *)
  17.257 +(*-------------------------------------------------------------------*)
  17.258 +(*------------------------------------------------
  17.259 +      NSLIM_mult and hence (trivially) LIM_mult
  17.260 + ------------------------------------------------*)
  17.261 +
  17.262 +Goalw [NSLIM_def]
  17.263 +     "[| f -- x --NS> l; g -- x --NS> m |] \
  17.264 +\     ==> (%x. f(x) * g(x)) -- x --NS> (l * m)";
  17.265 +by (auto_tac (claset() addSIs [inf_close_mult_HFinite],  simpset()));
  17.266 +qed "NSLIM_mult";
  17.267 +
  17.268 +Goal "[| f -- x --> l; g -- x --> m |] \
  17.269 +\     ==> (%x. f(x) * g(x)) -- x --> (l * m)";
  17.270 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_mult]) 1);
  17.271 +qed "LIM_mult2";
  17.272 +
  17.273 +(*----------------------------------------------
  17.274 +      NSLIM_add and hence (trivially) LIM_add
  17.275 +      Note the much shorter proof
  17.276 + ----------------------------------------------*)
  17.277 +Goalw [NSLIM_def]
  17.278 +     "[| f -- x --NS> l; g -- x --NS> m |] \
  17.279 +\     ==> (%x. f(x) + g(x)) -- x --NS> (l + m)";
  17.280 +by (auto_tac (claset() addSIs [inf_close_add], simpset()));
  17.281 +qed "NSLIM_add";
  17.282 +
  17.283 +Goal "[| f -- x --> l; g -- x --> m |] \
  17.284 +\     ==> (%x. f(x) + g(x)) -- x --> (l + m)";
  17.285 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_add]) 1);
  17.286 +qed "LIM_add2";
  17.287 +
  17.288 +(*----------------------------------------------
  17.289 +     NSLIM_const
  17.290 + ----------------------------------------------*)
  17.291 +Goalw [NSLIM_def] "(%x. k) -- x --NS> k";
  17.292 +by Auto_tac;
  17.293 +qed "NSLIM_const";
  17.294 +
  17.295 +Addsimps [NSLIM_const];
  17.296 +
  17.297 +Goal "(%x. k) -- x --> k";
  17.298 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
  17.299 +qed "LIM_const2";
  17.300 +
  17.301 +(*----------------------------------------------
  17.302 +     NSLIM_minus
  17.303 + ----------------------------------------------*)
  17.304 +Goalw [NSLIM_def] 
  17.305 +      "f -- a --NS> L ==> (%x. -f(x)) -- a --NS> -L";
  17.306 +by Auto_tac;  
  17.307 +qed "NSLIM_minus";
  17.308 +
  17.309 +Goal "f -- a --> L ==> (%x. -f(x)) -- a --> -L";
  17.310 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_minus]) 1);
  17.311 +qed "LIM_minus2";
  17.312 +
  17.313 +(*----------------------------------------------
  17.314 +     NSLIM_add_minus
  17.315 + ----------------------------------------------*)
  17.316 +Goal "[| f -- x --NS> l; g -- x --NS> m |] \
  17.317 +\     ==> (%x. f(x) + -g(x)) -- x --NS> (l + -m)";
  17.318 +by (blast_tac (claset() addDs [NSLIM_add,NSLIM_minus]) 1);
  17.319 +qed "NSLIM_add_minus";
  17.320 +
  17.321 +Goal "[| f -- x --> l; g -- x --> m |] \
  17.322 +\     ==> (%x. f(x) + -g(x)) -- x --> (l + -m)";
  17.323 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
  17.324 +    NSLIM_add_minus]) 1);
  17.325 +qed "LIM_add_minus2";
  17.326 +
  17.327 +(*-----------------------------
  17.328 +    NSLIM_inverse
  17.329 + -----------------------------*)
  17.330 +Goalw [NSLIM_def] 
  17.331 +     "[| f -- a --NS> L;  L ~= #0 |] \
  17.332 +\     ==> (%x. inverse(f(x))) -- a --NS> (inverse L)";
  17.333 +by (Clarify_tac 1);
  17.334 +by (dtac spec 1);
  17.335 +by (auto_tac (claset(), 
  17.336 +              simpset() addsimps [hypreal_of_real_inf_close_inverse]));  
  17.337 +qed "NSLIM_inverse";
  17.338 +
  17.339 +Goal "[| f -- a --> L; \
  17.340 +\        L ~= #0 |] ==> (%x. inverse(f(x))) -- a --> (inverse L)";
  17.341 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_inverse]) 1);
  17.342 +qed "LIM_inverse";
  17.343 +
  17.344 +(*------------------------------
  17.345 +    NSLIM_zero
  17.346 + ------------------------------*)
  17.347 +Goal "f -- a --NS> l ==> (%x. f(x) + -l) -- a --NS> #0";
  17.348 +by (res_inst_tac [("z1","l")] (rename_numerals (real_add_minus RS subst)) 1);
  17.349 +by (rtac NSLIM_add_minus 1 THEN Auto_tac);
  17.350 +qed "NSLIM_zero";
  17.351 +
  17.352 +Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> #0";
  17.353 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_zero]) 1);
  17.354 +qed "LIM_zero2";
  17.355 +
  17.356 +Goal "(%x. f(x) - l) -- x --NS> #0 ==> f -- x --NS> l";
  17.357 +by (dres_inst_tac [("g","%x. l"),("m","l")] NSLIM_add 1);
  17.358 +by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
  17.359 +qed "NSLIM_zero_cancel";
  17.360 +
  17.361 +Goal "(%x. f(x) - l) -- x --> #0 ==> f -- x --> l";
  17.362 +by (dres_inst_tac [("g","%x. l"),("m","l")] LIM_add 1);
  17.363 +by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
  17.364 +qed "LIM_zero_cancel";
  17.365 +
  17.366 +
  17.367 +(*--------------------------
  17.368 +   NSLIM_not_zero
  17.369 + --------------------------*)
  17.370 +Goalw [NSLIM_def] "k ~= #0 ==> ~ ((%x. k) -- x --NS> #0)";
  17.371 +by Auto_tac;
  17.372 +by (res_inst_tac [("x","hypreal_of_real x + ehr")] exI 1);
  17.373 +by (auto_tac (claset() addIs [Infinitesimal_add_inf_close_self RS inf_close_sym],
  17.374 +              simpset() addsimps [rename_numerals hypreal_epsilon_not_zero]));
  17.375 +qed "NSLIM_not_zero";
  17.376 +
  17.377 +(* [| k ~= #0; (%x. k) -- x --NS> #0 |] ==> R *)
  17.378 +bind_thm("NSLIM_not_zeroE", NSLIM_not_zero RS notE);
  17.379 +
  17.380 +Goal "k ~= #0 ==> ~ ((%x. k) -- x --> #0)";
  17.381 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_not_zero]) 1);
  17.382 +qed "LIM_not_zero2";
  17.383 +
  17.384 +(*-------------------------------------
  17.385 +   NSLIM of constant function
  17.386 + -------------------------------------*)
  17.387 +Goal "(%x. k) -- x --NS> L ==> k = L";
  17.388 +by (rtac ccontr 1);
  17.389 +by (dtac NSLIM_zero 1);
  17.390 +by (rtac NSLIM_not_zeroE 1 THEN assume_tac 2);
  17.391 +by (arith_tac 1);
  17.392 +qed "NSLIM_const_eq";
  17.393 +
  17.394 +Goal "(%x. k) -- x --> L ==> k = L";
  17.395 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
  17.396 +    NSLIM_const_eq]) 1);
  17.397 +qed "LIM_const_eq2";
  17.398 +
  17.399 +(*------------------------
  17.400 +     NS Limit is Unique
  17.401 + ------------------------*)
  17.402 +(* can actually be proved more easily by unfolding def! *)
  17.403 +Goal "[| f -- x --NS> L; f -- x --NS> M |] ==> L = M";
  17.404 +by (dtac NSLIM_minus 1);
  17.405 +by (dtac NSLIM_add 1 THEN assume_tac 1);
  17.406 +by (auto_tac (claset() addSDs [NSLIM_const_eq RS sym], simpset()));
  17.407 +qed "NSLIM_unique";
  17.408 +
  17.409 +Goal "[| f -- x --> L; f -- x --> M |] ==> L = M";
  17.410 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_unique]) 1);
  17.411 +qed "LIM_unique2";
  17.412 +
  17.413 +(*--------------------
  17.414 +    NSLIM_mult_zero
  17.415 + --------------------*)
  17.416 +Goal "[| f -- x --NS> #0; g -- x --NS> #0 |] \
  17.417 +\         ==> (%x. f(x)*g(x)) -- x --NS> #0";
  17.418 +by (dtac NSLIM_mult 1 THEN Auto_tac);
  17.419 +qed "NSLIM_mult_zero";
  17.420 +
  17.421 +(* we can use the corresponding thm LIM_mult2 *)
  17.422 +(* for standard definition of limit           *)
  17.423 +
  17.424 +Goal "[| f -- x --> #0; g -- x --> #0 |] \
  17.425 +\     ==> (%x. f(x)*g(x)) -- x --> #0";
  17.426 +by (dtac LIM_mult2 1 THEN Auto_tac);
  17.427 +qed "LIM_mult_zero2";
  17.428 +
  17.429 +(*----------------------------
  17.430 +    NSLIM_self
  17.431 + ----------------------------*)
  17.432 +Goalw [NSLIM_def] "(%x. x) -- a --NS> a";
  17.433 +by (auto_tac (claset() addIs [starfun_Idfun_inf_close],simpset()));
  17.434 +qed "NSLIM_self";
  17.435 +
  17.436 +Goal "(%x. x) -- a --> a";
  17.437 +by (simp_tac (simpset() addsimps [LIM_NSLIM_iff,NSLIM_self]) 1);
  17.438 +qed "LIM_self2";
  17.439 +
  17.440 +(*-----------------------------------------------------------------------------
  17.441 +   Derivatives and Continuity - NS and Standard properties
  17.442 + -----------------------------------------------------------------------------*)
  17.443 +(*---------------
  17.444 +    Continuity 
  17.445 + ---------------*)
  17.446 +
  17.447 +Goalw [isNSCont_def] 
  17.448 +      "[| isNSCont f a; y @= hypreal_of_real a |] \
  17.449 +\           ==> (*f* f) y @= hypreal_of_real (f a)";
  17.450 +by (Blast_tac 1);
  17.451 +qed "isNSContD";
  17.452 +
  17.453 +Goalw [isNSCont_def,NSLIM_def] 
  17.454 +      "isNSCont f a ==> f -- a --NS> (f a) ";
  17.455 +by (Blast_tac 1);
  17.456 +qed "isNSCont_NSLIM";
  17.457 +
  17.458 +Goalw [isNSCont_def,NSLIM_def] 
  17.459 +      "f -- a --NS> (f a) ==> isNSCont f a";
  17.460 +by Auto_tac;
  17.461 +by (res_inst_tac [("Q","y = hypreal_of_real a")] 
  17.462 +    (excluded_middle RS disjE) 1);
  17.463 +by Auto_tac;
  17.464 +qed "NSLIM_isNSCont";
  17.465 +
  17.466 +(*-----------------------------------------------------
  17.467 +    NS continuity can be defined using NS Limit in
  17.468 +    similar fashion to standard def of continuity
  17.469 + -----------------------------------------------------*)
  17.470 +Goal "(isNSCont f a) = (f -- a --NS> (f a))";
  17.471 +by (blast_tac (claset() addIs [isNSCont_NSLIM,NSLIM_isNSCont]) 1);
  17.472 +qed "isNSCont_NSLIM_iff";
  17.473 +
  17.474 +(*----------------------------------------------
  17.475 +  Hence, NS continuity can be given
  17.476 +  in terms of standard limit
  17.477 + ---------------------------------------------*)
  17.478 +Goal "(isNSCont f a) = (f -- a --> (f a))";
  17.479 +by (asm_full_simp_tac (simpset() addsimps 
  17.480 +    [LIM_NSLIM_iff,isNSCont_NSLIM_iff]) 1);
  17.481 +qed "isNSCont_LIM_iff";
  17.482 +
  17.483 +(*-----------------------------------------------
  17.484 +  Moreover, it's trivial now that NS continuity 
  17.485 +  is equivalent to standard continuity
  17.486 + -----------------------------------------------*)
  17.487 +Goalw [isCont_def] "(isNSCont f a) = (isCont f a)";
  17.488 +by (rtac isNSCont_LIM_iff 1);
  17.489 +qed "isNSCont_isCont_iff";
  17.490 +
  17.491 +(*----------------------------------------
  17.492 +  Standard continuity ==> NS continuity 
  17.493 + ----------------------------------------*)
  17.494 +Goal "isCont f a ==> isNSCont f a";
  17.495 +by (etac (isNSCont_isCont_iff RS iffD2) 1);
  17.496 +qed "isCont_isNSCont";
  17.497 +
  17.498 +(*----------------------------------------
  17.499 +  NS continuity ==> Standard continuity 
  17.500 + ----------------------------------------*)
  17.501 +Goal "isNSCont f a ==> isCont f a";
  17.502 +by (etac (isNSCont_isCont_iff RS iffD1) 1);
  17.503 +qed "isNSCont_isCont";
  17.504 +
  17.505 +(*--------------------------------------------------------------------------
  17.506 +                 Alternative definition of continuity
  17.507 + --------------------------------------------------------------------------*)
  17.508 +(* Prove equivalence between NS limits - *)
  17.509 +(* seems easier than using standard def  *)
  17.510 +Goalw [NSLIM_def] "(f -- a --NS> L) = ((%h. f(a + h)) -- #0 --NS> L)";
  17.511 +by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_zero]));
  17.512 +by (dres_inst_tac [("x","hypreal_of_real a + x")] spec 1);
  17.513 +by (dres_inst_tac [("x","-hypreal_of_real a + x")] spec 2);
  17.514 +by (Step_tac 1);
  17.515 +by (Asm_full_simp_tac 1);
  17.516 +by (rtac ((mem_infmal_iff RS iffD2) RS 
  17.517 +    (Infinitesimal_add_inf_close_self RS inf_close_sym)) 1);
  17.518 +by (rtac (inf_close_minus_iff2 RS iffD1) 4);
  17.519 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 3);
  17.520 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 2);
  17.521 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 4);
  17.522 +by (auto_tac (claset(),
  17.523 +       simpset() addsimps [starfun, hypreal_of_real_def, hypreal_minus,
  17.524 +              hypreal_add, real_add_assoc, inf_close_refl, hypreal_zero_def]));
  17.525 +qed "NSLIM_h_iff";
  17.526 +
  17.527 +Goal "(f -- a --NS> f a) = ((%h. f(a + h)) -- #0 --NS> f a)";
  17.528 +by (rtac NSLIM_h_iff 1);
  17.529 +qed "NSLIM_isCont_iff";
  17.530 +
  17.531 +Goal "(f -- a --> f a) = ((%h. f(a + h)) -- #0 --> f(a))";
  17.532 +by (simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_isCont_iff]) 1);
  17.533 +qed "LIM_isCont_iff";
  17.534 +
  17.535 +Goalw [isCont_def] "(isCont f x) = ((%h. f(x + h)) -- #0 --> f(x))";
  17.536 +by (simp_tac (simpset() addsimps [LIM_isCont_iff]) 1);
  17.537 +qed "isCont_iff";
  17.538 +
  17.539 +(*--------------------------------------------------------------------------
  17.540 +   Immediate application of nonstandard criterion for continuity can offer 
  17.541 +   very simple proofs of some standard property of continuous functions
  17.542 + --------------------------------------------------------------------------*)
  17.543 +(*------------------------
  17.544 +     sum continuous
  17.545 + ------------------------*)
  17.546 +Goal "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) + g(x)) a";
  17.547 +by (auto_tac (claset() addIs [inf_close_add],
  17.548 +              simpset() addsimps [isNSCont_isCont_iff RS sym, isNSCont_def]));
  17.549 +qed "isCont_add";
  17.550 +
  17.551 +(*------------------------
  17.552 +     mult continuous
  17.553 + ------------------------*)
  17.554 +Goal "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a";
  17.555 +by (auto_tac (claset() addSIs [starfun_mult_HFinite_inf_close],
  17.556 +              simpset() delsimps [starfun_mult RS sym]
  17.557 +			addsimps [isNSCont_isCont_iff RS sym, isNSCont_def]));
  17.558 +qed "isCont_mult";
  17.559 +
  17.560 +(*-------------------------------------------
  17.561 +     composition of continuous functions
  17.562 +     Note very short straightforard proof!
  17.563 + ------------------------------------------*)
  17.564 +Goal "[| isCont f a; isCont g (f a) |] \
  17.565 +\     ==> isCont (g o f) a";
  17.566 +by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
  17.567 +              isNSCont_def,starfun_o RS sym]));
  17.568 +qed "isCont_o";
  17.569 +
  17.570 +Goal "[| isCont f a; isCont g (f a) |] \
  17.571 +\     ==> isCont (%x. g (f x)) a";
  17.572 +by (auto_tac (claset() addDs [isCont_o],simpset() addsimps [o_def]));
  17.573 +qed "isCont_o2";
  17.574 +
  17.575 +Goalw [isNSCont_def] "isNSCont f a ==> isNSCont (%x. - f x) a";
  17.576 +by Auto_tac; 
  17.577 +qed "isNSCont_minus";
  17.578 +
  17.579 +Goal "isCont f a ==> isCont (%x. - f x) a";
  17.580 +by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
  17.581 +              isNSCont_minus]));
  17.582 +qed "isCont_minus";
  17.583 +
  17.584 +Goalw [isCont_def]  
  17.585 +      "[| isCont f x; f x ~= #0 |] ==> isCont (%x. inverse (f x)) x";
  17.586 +by (blast_tac (claset() addIs [LIM_inverse]) 1);
  17.587 +qed "isCont_inverse";
  17.588 +
  17.589 +Goal "[| isNSCont f x; f x ~= #0 |] ==> isNSCont (%x. inverse (f x)) x";
  17.590 +by (auto_tac (claset() addIs [isCont_inverse],simpset() addsimps 
  17.591 +    [isNSCont_isCont_iff]));
  17.592 +qed "isNSCont_inverse";
  17.593 +
  17.594 +Goalw [real_diff_def] 
  17.595 +      "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) - g(x)) a";
  17.596 +by (auto_tac (claset() addIs [isCont_add,isCont_minus],simpset()));
  17.597 +qed "isCont_diff";
  17.598 +
  17.599 +Goalw [isCont_def]  "isCont (%x. k) a";
  17.600 +by (Simp_tac 1);
  17.601 +qed "isCont_const";
  17.602 +Addsimps [isCont_const];
  17.603 +
  17.604 +Goalw [isNSCont_def]  "isNSCont (%x. k) a";
  17.605 +by (Simp_tac 1);
  17.606 +qed "isNSCont_const";
  17.607 +Addsimps [isNSCont_const];
  17.608 +
  17.609 +Goalw [isNSCont_def]  "isNSCont abs a";
  17.610 +by (auto_tac (claset() addIs [inf_close_hrabs],
  17.611 +              simpset() addsimps [hypreal_of_real_hrabs RS sym,
  17.612 +                                  starfun_rabs_hrabs]));
  17.613 +qed "isNSCont_rabs";
  17.614 +Addsimps [isNSCont_rabs];
  17.615 +
  17.616 +Goal "isCont abs a";
  17.617 +by (auto_tac (claset(), simpset() addsimps [isNSCont_isCont_iff RS sym]));
  17.618 +qed "isCont_rabs";
  17.619 +Addsimps [isCont_rabs];
  17.620 +
  17.621 +(****************************************************************
  17.622 +(%* Leave as commented until I add topology theory or remove? *%)
  17.623 +(%*------------------------------------------------------------
  17.624 +  Elementary topology proof for a characterisation of 
  17.625 +  continuity now: a function f is continuous if and only 
  17.626 +  if the inverse image, {x. f(x) : A}, of any open set A 
  17.627 +  is always an open set
  17.628 + ------------------------------------------------------------*%)
  17.629 +Goal "[| isNSopen A; ALL x. isNSCont f x |] \
  17.630 +\              ==> isNSopen {x. f x : A}";
  17.631 +by (auto_tac (claset(),simpset() addsimps [isNSopen_iff1]));
  17.632 +by (dtac (mem_monad_inf_close RS inf_close_sym) 1);
  17.633 +by (dres_inst_tac [("x","a")] spec 1);
  17.634 +by (dtac isNSContD 1 THEN assume_tac 1);
  17.635 +by (dtac bspec 1 THEN assume_tac 1);
  17.636 +by (dres_inst_tac [("x","( *f* f) x")] inf_close_mem_monad2 1);
  17.637 +by (blast_tac (claset() addIs [starfun_mem_starset]) 1);
  17.638 +qed "isNSCont_isNSopen";
  17.639 +
  17.640 +Goalw [isNSCont_def]
  17.641 +          "ALL A. isNSopen A --> isNSopen {x. f x : A} \
  17.642 +\              ==> isNSCont f x";
  17.643 +by (auto_tac (claset() addSIs [(mem_infmal_iff RS iffD1) RS 
  17.644 +     (inf_close_minus_iff RS iffD2)],simpset() addsimps 
  17.645 +      [Infinitesimal_def,SReal_iff]));
  17.646 +by (dres_inst_tac [("x","{z. abs(z + -f(x)) < ya}")] spec 1);
  17.647 +by (etac (isNSopen_open_interval RSN (2,impE)) 1);
  17.648 +by (auto_tac (claset(),simpset() addsimps [isNSopen_def,isNSnbhd_def]));
  17.649 +by (dres_inst_tac [("x","x")] spec 1);
  17.650 +by (auto_tac (claset() addDs [inf_close_sym RS inf_close_mem_monad],
  17.651 +    simpset() addsimps [hypreal_of_real_zero RS sym,STAR_starfun_rabs_add_minus]));
  17.652 +qed "isNSopen_isNSCont";
  17.653 +
  17.654 +Goal "(ALL x. isNSCont f x) = \
  17.655 +\     (ALL A. isNSopen A --> isNSopen {x. f(x) : A})";
  17.656 +by (blast_tac (claset() addIs [isNSCont_isNSopen,
  17.657 +    isNSopen_isNSCont]) 1);
  17.658 +qed "isNSCont_isNSopen_iff";
  17.659 +
  17.660 +(%*------- Standard version of same theorem --------*%)
  17.661 +Goal "(ALL x. isCont f x) = \
  17.662 +\         (ALL A. isopen A --> isopen {x. f(x) : A})";
  17.663 +by (auto_tac (claset() addSIs [isNSCont_isNSopen_iff],
  17.664 +              simpset() addsimps [isNSopen_isopen_iff RS sym,
  17.665 +              isNSCont_isCont_iff RS sym]));
  17.666 +qed "isCont_isopen_iff";
  17.667 +*******************************************************************)
  17.668 +
  17.669 +(*-----------------------------------------------------------------
  17.670 +                        Uniform continuity
  17.671 + ------------------------------------------------------------------*)
  17.672 +Goalw [isNSUCont_def] 
  17.673 +      "[| isNSUCont f; x @= y|] ==> (*f* f) x @= (*f* f) y";
  17.674 +by (Blast_tac 1);
  17.675 +qed "isNSUContD";
  17.676 +
  17.677 +Goalw [isUCont_def,isCont_def,LIM_def]
  17.678 +     "isUCont f ==> EX x. isCont f x";
  17.679 +by (Force_tac 1);
  17.680 +qed "isUCont_isCont";
  17.681 +
  17.682 +Goalw [isNSUCont_def,isUCont_def,inf_close_def] 
  17.683 +     "isUCont f ==> isNSUCont f";
  17.684 +by (asm_full_simp_tac (simpset() addsimps 
  17.685 +    [Infinitesimal_FreeUltrafilterNat_iff]) 1);
  17.686 +by (Step_tac 1);
  17.687 +by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
  17.688 +by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
  17.689 +by (auto_tac (claset(),simpset() addsimps [starfun,
  17.690 +    hypreal_minus, hypreal_add]));
  17.691 +by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2 THEN Step_tac 1);
  17.692 +by (dres_inst_tac [("x","u")] spec 1 THEN Clarify_tac 1);
  17.693 +by (dres_inst_tac [("x","s")] spec 1 THEN Clarify_tac 1);
  17.694 +by (subgoal_tac "ALL n::nat. abs ((xa n) + - (xb n)) < s --> abs (f (xa n) + - f (xb n)) < u" 1);
  17.695 +by (Blast_tac 2);
  17.696 +by (thin_tac "ALL x y. abs (x + - y) < s --> abs (f x + - f y) < u" 1);
  17.697 +by (dtac FreeUltrafilterNat_all 1);
  17.698 +by (Ultra_tac 1);
  17.699 +qed "isUCont_isNSUCont";
  17.700 +
  17.701 +Goal "ALL s. #0 < s --> (EX z y. abs (z + - y) < s & r <= abs (f z + -f y)) \
  17.702 +\     ==> ALL n::nat. EX z y.  \
  17.703 +\              abs(z + -y) < inverse(real_of_posnat n) & \
  17.704 +\              r <= abs(f z + -f y)";
  17.705 +by (Step_tac 1);
  17.706 +by (cut_inst_tac [("n1","n")] (real_of_posnat_gt_zero RS real_inverse_gt_zero) 1);
  17.707 +by Auto_tac;
  17.708 +val lemma_LIMu = result();
  17.709 +
  17.710 +Goal "ALL s. #0 < s --> (EX z y. abs (z + - y) < s  & r <= abs (f z + -f y)) \
  17.711 +\     ==> EX X Y. ALL n::nat. \
  17.712 +\              abs(X n + -(Y n)) < inverse(real_of_posnat n) & \
  17.713 +\              r <= abs(f (X n) + -f (Y n))";
  17.714 +by (dtac lemma_LIMu 1);
  17.715 +by (dtac choice 1);
  17.716 +by (Step_tac 1);
  17.717 +by (dtac choice 1);
  17.718 +by (Blast_tac 1);
  17.719 +val lemma_skolemize_LIM2u = result();
  17.720 +
  17.721 +Goal "ALL n. abs (X n + -Y n) < inverse (real_of_posnat  n) & \
  17.722 +\         r <= abs (f (X n) + - f(Y n)) ==> \
  17.723 +\         ALL n. abs (X n + - Y n) < inverse (real_of_posnat  n)";
  17.724 +by (Auto_tac );
  17.725 +val lemma_simpu = result();
  17.726 +
  17.727 +Goalw [isNSUCont_def,isUCont_def,inf_close_def] 
  17.728 +     "isNSUCont f ==> isUCont f";
  17.729 +by (asm_full_simp_tac (simpset() addsimps 
  17.730 +                       [Infinitesimal_FreeUltrafilterNat_iff]) 1);
  17.731 +by (EVERY1[Step_tac, rtac ccontr, Asm_full_simp_tac]);
  17.732 +by (fold_tac [real_le_def]);
  17.733 +by (dtac lemma_skolemize_LIM2u 1);
  17.734 +by (Step_tac 1);
  17.735 +by (dres_inst_tac [("x","Abs_hypreal(hyprel^^{X})")] spec 1);
  17.736 +by (dres_inst_tac [("x","Abs_hypreal(hyprel^^{Y})")] spec 1);
  17.737 +by (asm_full_simp_tac
  17.738 +    (simpset() addsimps [starfun, hypreal_minus,hypreal_add]) 1);
  17.739 +by Auto_tac;
  17.740 +by (dtac (lemma_simpu RS real_seq_to_hypreal_Infinitesimal2) 1);
  17.741 +by (asm_full_simp_tac (simpset() addsimps 
  17.742 +     [Infinitesimal_FreeUltrafilterNat_iff, hypreal_minus,hypreal_add]) 1);
  17.743 +by (Blast_tac 1);
  17.744 +by (rotate_tac 2 1);
  17.745 +by (dres_inst_tac [("x","r")] spec 1);
  17.746 +by (Clarify_tac 1);
  17.747 +by (dtac FreeUltrafilterNat_all 1);
  17.748 +by (Ultra_tac 1);
  17.749 +qed "isNSUCont_isUCont";
  17.750 +
  17.751 +(*------------------------------------------------------------------
  17.752 +                         Derivatives
  17.753 + ------------------------------------------------------------------*)
  17.754 +Goalw [deriv_def] 
  17.755 +      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- #0 --> D)";
  17.756 +by (Blast_tac 1);        
  17.757 +qed "DERIV_iff";
  17.758 +
  17.759 +Goalw [deriv_def] 
  17.760 +      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- #0 --NS> D)";
  17.761 +by (simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
  17.762 +qed "DERIV_NS_iff";
  17.763 +
  17.764 +Goalw [deriv_def] 
  17.765 +      "DERIV f x :> D \
  17.766 +\      ==> (%h. (f(x + h) + - f(x))/h) -- #0 --> D";
  17.767 +by (Blast_tac 1);        
  17.768 +qed "DERIVD";
  17.769 +
  17.770 +Goalw [deriv_def] "DERIV f x :> D ==> \
  17.771 +\          (%h. (f(x + h) + - f(x))/h) -- #0 --NS> D";
  17.772 +by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
  17.773 +qed "NS_DERIVD";
  17.774 +
  17.775 +(* Uniqueness *)
  17.776 +Goalw [deriv_def] 
  17.777 +      "[| DERIV f x :> D; DERIV f x :> E |] ==> D = E";
  17.778 +by (blast_tac (claset() addIs [LIM_unique]) 1);
  17.779 +qed "DERIV_unique";
  17.780 +
  17.781 +Goalw [nsderiv_def] 
  17.782 +     "[| NSDERIV f x :> D; NSDERIV f x :> E |] ==> D = E";
  17.783 +by (cut_facts_tac [Infinitesimal_epsilon, hypreal_epsilon_not_zero] 1);
  17.784 +by (auto_tac (claset() addSDs [inst "x" "ehr" bspec] 
  17.785 +                       addSIs [inj_hypreal_of_real RS injD] 
  17.786 +                       addDs [inf_close_trans3],
  17.787 +              simpset()));
  17.788 +qed "NSDeriv_unique";
  17.789 +
  17.790 +(*------------------------------------------------------------------------
  17.791 +                          Differentiable
  17.792 + ------------------------------------------------------------------------*)
  17.793 +
  17.794 +Goalw [differentiable_def] 
  17.795 +      "f differentiable x ==> EX D. DERIV f x :> D";
  17.796 +by (assume_tac 1);
  17.797 +qed "differentiableD";
  17.798 +
  17.799 +Goalw [differentiable_def] 
  17.800 +      "DERIV f x :> D ==> f differentiable x";
  17.801 +by (Blast_tac 1);
  17.802 +qed "differentiableI";
  17.803 +
  17.804 +Goalw [NSdifferentiable_def] 
  17.805 +      "f NSdifferentiable x ==> EX D. NSDERIV f x :> D";
  17.806 +by (assume_tac 1);
  17.807 +qed "NSdifferentiableD";
  17.808 +
  17.809 +Goalw [NSdifferentiable_def] 
  17.810 +      "NSDERIV f x :> D ==> f NSdifferentiable x";
  17.811 +by (Blast_tac 1);
  17.812 +qed "NSdifferentiableI";
  17.813 +
  17.814 +(*--------------------------------------------------------
  17.815 +      Alternative definition for differentiability
  17.816 + -------------------------------------------------------*)
  17.817 +
  17.818 +Goalw [LIM_def] 
  17.819 + "((%h. (f(a + h) + - f(a))/h) -- #0 --> D) = \
  17.820 +\ ((%x. (f(x) + -f(a)) / (x + -a)) -- a --> D)";
  17.821 +by (Step_tac 1);
  17.822 +by (ALLGOALS(dtac spec));
  17.823 +by (Step_tac 1);
  17.824 +by (Blast_tac 1 THEN Blast_tac 2);
  17.825 +by (ALLGOALS(res_inst_tac [("x","s")] exI));
  17.826 +by (Step_tac 1);
  17.827 +by (dres_inst_tac [("x","x + -a")] spec 1);
  17.828 +by (dres_inst_tac [("x","x + a")] spec 2);
  17.829 +by (auto_tac (claset(), simpset() addsimps real_add_ac));
  17.830 +qed "DERIV_LIM_iff";
  17.831 +
  17.832 +Goalw [deriv_def] "(DERIV f x :> D) = \
  17.833 +\         ((%z. (f(z) + -f(x)) / (z + -x)) -- x --> D)";
  17.834 +by (simp_tac (simpset() addsimps [DERIV_LIM_iff]) 1);
  17.835 +qed "DERIV_iff2";
  17.836 +
  17.837 +(*--------------------------------------------------------
  17.838 +  Equivalence of NS and standard defs of differentiation
  17.839 + -------------------------------------------------------*)
  17.840 +(*-------------------------------------------
  17.841 +   First NSDERIV in terms of NSLIM 
  17.842 + -------------------------------------------*)
  17.843 +
  17.844 +(*--- first equivalence ---*)
  17.845 +Goalw [nsderiv_def,NSLIM_def] 
  17.846 +      "(NSDERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- #0 --NS> D)";
  17.847 +by (auto_tac (claset(), simpset() addsimps [hypreal_of_real_zero]));
  17.848 +by (dres_inst_tac [("x","xa")] bspec 1);
  17.849 +by (rtac ccontr 3);
  17.850 +by (dres_inst_tac [("x","h")] spec 3);
  17.851 +by (auto_tac (claset(),
  17.852 +              simpset() addsimps [mem_infmal_iff, starfun_lambda_cancel]));
  17.853 +qed "NSDERIV_NSLIM_iff";
  17.854 +
  17.855 +(*--- second equivalence ---*)
  17.856 +Goal "(NSDERIV f x :> D) = \
  17.857 +\         ((%z. (f(z) + -f(x)) / (z + -x)) -- x --NS> D)";
  17.858 +by (full_simp_tac (simpset() addsimps 
  17.859 +     [NSDERIV_NSLIM_iff, DERIV_LIM_iff, LIM_NSLIM_iff RS sym]) 1);
  17.860 +qed "NSDERIV_NSLIM_iff2";
  17.861 +
  17.862 +(* while we're at it! *)
  17.863 +Goalw [real_diff_def]
  17.864 +     "(NSDERIV f x :> D) = \
  17.865 +\     (ALL xa. \
  17.866 +\       xa ~= hypreal_of_real x & xa @= hypreal_of_real x --> \
  17.867 +\       (*f* (%z. (f z - f x) / (z - x))) xa @= hypreal_of_real D)";
  17.868 +by (auto_tac (claset(), simpset() addsimps [NSDERIV_NSLIM_iff2, NSLIM_def]));
  17.869 +qed "NSDERIV_iff2";
  17.870 +
  17.871 +
  17.872 +Goal "(NSDERIV f x :> D) ==> \
  17.873 +\    (ALL u. \
  17.874 +\       u @= hypreal_of_real x --> \
  17.875 +\       (*f* (%z. f z - f x)) u @= hypreal_of_real D * (u - hypreal_of_real x))";
  17.876 +by (auto_tac (claset(), simpset() addsimps [NSDERIV_iff2]));
  17.877 +by (case_tac "u = hypreal_of_real x" 1);
  17.878 +by (auto_tac (claset(), 
  17.879 +              simpset() addsimps [hypreal_diff_def, hypreal_of_real_zero]));
  17.880 +by (dres_inst_tac [("x","u")] spec 1);
  17.881 +by Auto_tac;
  17.882 +by (dres_inst_tac [("c","u - hypreal_of_real x"),("b","hypreal_of_real D")]
  17.883 +     inf_close_mult1 1);
  17.884 +by (ALLGOALS(dtac (hypreal_not_eq_minus_iff RS iffD1)));
  17.885 +by (subgoal_tac "(*f* (%z. z - x)) u ~= (0::hypreal)" 2);
  17.886 +by (rotate_tac ~1 2);
  17.887 +by (auto_tac (claset(),
  17.888 +    simpset() addsimps [real_diff_def, hypreal_diff_def, 
  17.889 +		(inf_close_minus_iff RS iffD1) RS (mem_infmal_iff RS iffD2),  
  17.890 +			Infinitesimal_subset_HFinite RS subsetD]));
  17.891 +qed "NSDERIVD5";
  17.892 +
  17.893 +Goal "(NSDERIV f x :> D) ==> \
  17.894 +\     (ALL h: Infinitesimal. \
  17.895 +\              ((*f* f)(hypreal_of_real x + h) - \
  17.896 +\                hypreal_of_real (f x))@= (hypreal_of_real D) * h)";
  17.897 +by (auto_tac (claset(),simpset() addsimps [nsderiv_def]));
  17.898 +by (case_tac "h = (0::hypreal)" 1);
  17.899 +by (auto_tac (claset(),simpset() addsimps [hypreal_diff_def]));
  17.900 +by (dres_inst_tac [("x","h")] bspec 1);
  17.901 +by (dres_inst_tac [("c","h")] inf_close_mult1 2);
  17.902 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
  17.903 +              simpset() addsimps [hypreal_diff_def]));
  17.904 +qed "NSDERIVD4";
  17.905 +
  17.906 +Goal "(NSDERIV f x :> D) ==> \
  17.907 +\     (ALL h: Infinitesimal - {0}. \
  17.908 +\              ((*f* f)(hypreal_of_real x + h) - \
  17.909 +\                hypreal_of_real (f x))@= (hypreal_of_real D) * h)";
  17.910 +by (auto_tac (claset(),simpset() addsimps [nsderiv_def]));
  17.911 +by (rtac ccontr 1 THEN dres_inst_tac [("x","h")] bspec 1);
  17.912 +by (dres_inst_tac [("c","h")] inf_close_mult1 2);
  17.913 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
  17.914 +              simpset() addsimps [hypreal_mult_assoc, hypreal_diff_def]));
  17.915 +qed "NSDERIVD3";
  17.916 +
  17.917 +(*--------------------------------------------------------------
  17.918 +          Now equivalence between NSDERIV and DERIV
  17.919 + -------------------------------------------------------------*)
  17.920 +Goalw [deriv_def] "(NSDERIV f x :> D) = (DERIV f x :> D)";
  17.921 +by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,LIM_NSLIM_iff]) 1);
  17.922 +qed "NSDERIV_DERIV_iff";
  17.923 +
  17.924 +(*---------------------------------------------------
  17.925 +         Differentiability implies continuity 
  17.926 +         nice and simple "algebraic" proof
  17.927 + --------------------------------------------------*)
  17.928 +Goalw [nsderiv_def]
  17.929 +      "NSDERIV f x :> D ==> isNSCont f x";
  17.930 +by (auto_tac (claset(),simpset() addsimps 
  17.931 +        [isNSCont_NSLIM_iff,NSLIM_def]));
  17.932 +by (dtac (inf_close_minus_iff RS iffD1) 1);
  17.933 +by (dtac (hypreal_not_eq_minus_iff RS iffD1) 1);
  17.934 +by (dres_inst_tac [("x","-hypreal_of_real x + xa")] bspec 1);
  17.935 +by (asm_full_simp_tac (simpset() addsimps 
  17.936 +    [hypreal_add_assoc RS sym]) 2);
  17.937 +by (auto_tac (claset(),simpset() addsimps 
  17.938 +    [mem_infmal_iff RS sym,hypreal_add_commute]));
  17.939 +by (dres_inst_tac [("c","xa + -hypreal_of_real x")] inf_close_mult1 1);
  17.940 +by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite
  17.941 +    RS subsetD],simpset() addsimps [hypreal_mult_assoc]));
  17.942 +by (dres_inst_tac [("x3","D")] (HFinite_hypreal_of_real RSN
  17.943 +    (2,Infinitesimal_HFinite_mult) RS (mem_infmal_iff RS iffD1)) 1);
  17.944 +by (blast_tac (claset() addIs [inf_close_trans,
  17.945 +    hypreal_mult_commute RS subst,
  17.946 +    (inf_close_minus_iff RS iffD2)]) 1);
  17.947 +qed "NSDERIV_isNSCont";
  17.948 +
  17.949 +(* Now Sandard proof *)
  17.950 +Goal "DERIV f x :> D ==> isCont f x";
  17.951 +by (asm_full_simp_tac (simpset() addsimps 
  17.952 +    [NSDERIV_DERIV_iff RS sym, isNSCont_isCont_iff RS sym,
  17.953 +     NSDERIV_isNSCont]) 1);
  17.954 +qed "DERIV_isCont";
  17.955 +
  17.956 +(*----------------------------------------------------------------------------
  17.957 +      Differentiation rules for combinations of functions
  17.958 +      follow from clear, straightforard, algebraic 
  17.959 +      manipulations
  17.960 + ----------------------------------------------------------------------------*)
  17.961 +(*-------------------------
  17.962 +    Constant function
  17.963 + ------------------------*)
  17.964 +
  17.965 +(* use simple constant nslimit theorem *)
  17.966 +Goal "(NSDERIV (%x. k) x :> #0)";
  17.967 +by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
  17.968 +qed "NSDERIV_const";
  17.969 +Addsimps [NSDERIV_const];
  17.970 +
  17.971 +Goal "(DERIV (%x. k) x :> #0)";
  17.972 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
  17.973 +qed "DERIV_const";
  17.974 +Addsimps [DERIV_const];
  17.975 +
  17.976 +(*-----------------------------------------------------
  17.977 +    Sum of functions- proved easily
  17.978 + ----------------------------------------------------*)
  17.979 +
  17.980 +
  17.981 +Goal "[| NSDERIV f x :> Da;  NSDERIV g x :> Db |] \
  17.982 +\     ==> NSDERIV (%x. f x + g x) x :> Da + Db";
  17.983 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
  17.984 +           NSLIM_def]) 1 THEN REPEAT(Step_tac 1));
  17.985 +by (auto_tac (claset(),
  17.986 +       simpset() addsimps [hypreal_add_divide_distrib]));
  17.987 +by (dres_inst_tac [("b","hypreal_of_real Da"),
  17.988 +                   ("d","hypreal_of_real Db")] inf_close_add 1);
  17.989 +by (auto_tac (claset(), simpset() addsimps hypreal_add_ac));
  17.990 +qed "NSDERIV_add";
  17.991 +
  17.992 +(* Standard theorem *)
  17.993 +Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
  17.994 +\     ==> DERIV (%x. f x + g x) x :> Da + Db";
  17.995 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_add,
  17.996 +                                     NSDERIV_DERIV_iff RS sym]) 1);
  17.997 +qed "DERIV_add";
  17.998 +
  17.999 +(*-----------------------------------------------------
 17.1000 +  Product of functions - Proof is trivial but tedious
 17.1001 +  and long due to rearrangement of terms  
 17.1002 + ----------------------------------------------------*)
 17.1003 +
 17.1004 +Goal "((a::hypreal)*b) + -(c*d) = (b*(a + -c)) + (c*(b + -d))";
 17.1005 +by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib2]) 1);
 17.1006 +val lemma_nsderiv1 = result();
 17.1007 +
 17.1008 +Goal "[| (x + y) / z = hypreal_of_real D + yb; z ~= 0; \
 17.1009 +\        z : Infinitesimal; yb : Infinitesimal |] \
 17.1010 +\     ==> x + y @= #0";
 17.1011 +by (forw_inst_tac [("c1","z")] (hypreal_mult_right_cancel RS iffD2) 1 
 17.1012 +    THEN assume_tac 1);
 17.1013 +by (thin_tac "(x + y) / z = hypreal_of_real D + yb" 1);
 17.1014 +by (auto_tac (claset() addSIs [Infinitesimal_HFinite_mult2, HFinite_add],
 17.1015 +              simpset() addsimps [hypreal_mult_assoc, mem_infmal_iff RS sym]));
 17.1016 +by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
 17.1017 +val lemma_nsderiv2 = result();
 17.1018 +
 17.1019 +
 17.1020 +Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
 17.1021 +\     ==> NSDERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))";
 17.1022 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def]) 1 
 17.1023 +    THEN REPEAT(Step_tac 1));
 17.1024 +by (auto_tac (claset(),
 17.1025 +       simpset() addsimps [starfun_lambda_cancel, hypreal_of_real_zero,
 17.1026 +              lemma_nsderiv1]));
 17.1027 +by (simp_tac (simpset() addsimps [hypreal_add_divide_distrib]) 1); 
 17.1028 +by (REPEAT(dtac (bex_Infinitesimal_iff2 RS iffD2) 1));
 17.1029 +by (auto_tac (claset(),
 17.1030 +        simpset() delsimps [hypreal_times_divide1_eq]
 17.1031 +		  addsimps [hypreal_times_divide1_eq RS sym]));
 17.1032 +by (dres_inst_tac [("D","Db")] lemma_nsderiv2 1);
 17.1033 +by (dtac (inf_close_minus_iff RS iffD2 RS (bex_Infinitesimal_iff2 RS iffD2)) 4);
 17.1034 +by (auto_tac (claset() addSIs [inf_close_add_mono1],
 17.1035 +      simpset() addsimps [hypreal_add_mult_distrib, hypreal_add_mult_distrib2, 
 17.1036 +			  hypreal_mult_commute, hypreal_add_assoc]));
 17.1037 +by (res_inst_tac [("w1","hypreal_of_real Db * hypreal_of_real (f x)")]
 17.1038 +    (hypreal_add_commute RS subst) 1);
 17.1039 +by (auto_tac (claset() addSIs [Infinitesimal_add_inf_close_self2 RS inf_close_sym,
 17.1040 +			       Infinitesimal_add, Infinitesimal_mult,
 17.1041 +			       Infinitesimal_hypreal_of_real_mult,
 17.1042 +			       Infinitesimal_hypreal_of_real_mult2],
 17.1043 +	      simpset() addsimps [hypreal_add_assoc RS sym]));
 17.1044 +qed "NSDERIV_mult";
 17.1045 +
 17.1046 +Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
 17.1047 +\     ==> DERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))";
 17.1048 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_mult,
 17.1049 +                                           NSDERIV_DERIV_iff RS sym]) 1);
 17.1050 +qed "DERIV_mult";
 17.1051 +
 17.1052 +(*----------------------------
 17.1053 +   Multiplying by a constant
 17.1054 + ---------------------------*)
 17.1055 +Goal "NSDERIV f x :> D \
 17.1056 +\     ==> NSDERIV (%x. c * f x) x :> c*D";
 17.1057 +by (asm_full_simp_tac 
 17.1058 +    (simpset() addsimps [real_times_divide1_eq RS sym, NSDERIV_NSLIM_iff,
 17.1059 +                         real_minus_mult_eq2, real_add_mult_distrib2 RS sym] 
 17.1060 +             delsimps [real_times_divide1_eq, real_minus_mult_eq2 RS sym]) 1);
 17.1061 +by (etac (NSLIM_const RS NSLIM_mult) 1);
 17.1062 +qed "NSDERIV_cmult";
 17.1063 +
 17.1064 +(* let's do the standard proof though theorem *)
 17.1065 +(* LIM_mult2 follows from a NS proof          *)
 17.1066 +
 17.1067 +Goalw [deriv_def] 
 17.1068 +      "DERIV f x :> D \
 17.1069 +\      ==> DERIV (%x. c * f x) x :> c*D";
 17.1070 +by (asm_full_simp_tac 
 17.1071 +    (simpset() addsimps [real_times_divide1_eq RS sym, NSDERIV_NSLIM_iff,
 17.1072 +                         real_minus_mult_eq2, real_add_mult_distrib2 RS sym] 
 17.1073 +             delsimps [real_times_divide1_eq, real_minus_mult_eq2 RS sym]) 1);
 17.1074 +by (etac (LIM_const RS LIM_mult2) 1);
 17.1075 +qed "DERIV_cmult";
 17.1076 +
 17.1077 +(*--------------------------------
 17.1078 +   Negation of function
 17.1079 + -------------------------------*)
 17.1080 +Goal "NSDERIV f x :> D ==> NSDERIV (%x. -(f x)) x :> -D";
 17.1081 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
 17.1082 +by (res_inst_tac [("t","f x")] (real_minus_minus RS subst) 1);
 17.1083 +by (asm_simp_tac (simpset() addsimps [real_minus_add_distrib RS sym,
 17.1084 +                                      real_minus_mult_eq1 RS sym] 
 17.1085 +                   delsimps [real_minus_add_distrib, real_minus_minus]) 1);
 17.1086 +by (etac NSLIM_minus 1);
 17.1087 +qed "NSDERIV_minus";
 17.1088 +
 17.1089 +Goal "DERIV f x :> D \
 17.1090 +\     ==> DERIV (%x. -(f x)) x :> -D";
 17.1091 +by (asm_full_simp_tac (simpset() addsimps 
 17.1092 +    [NSDERIV_minus,NSDERIV_DERIV_iff RS sym]) 1);
 17.1093 +qed "DERIV_minus";
 17.1094 +
 17.1095 +(*-------------------------------
 17.1096 +   Subtraction
 17.1097 + ------------------------------*)
 17.1098 +Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
 17.1099 +\     ==> NSDERIV (%x. f x + -g x) x :> Da + -Db";
 17.1100 +by (blast_tac (claset() addDs [NSDERIV_add,NSDERIV_minus]) 1);
 17.1101 +qed "NSDERIV_add_minus";
 17.1102 +
 17.1103 +Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
 17.1104 +\     ==> DERIV (%x. f x + -g x) x :> Da + -Db";
 17.1105 +by (blast_tac (claset() addDs [DERIV_add,DERIV_minus]) 1);
 17.1106 +qed "DERIV_add_minus";
 17.1107 +
 17.1108 +Goalw [real_diff_def]
 17.1109 +     "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
 17.1110 +\     ==> NSDERIV (%x. f x - g x) x :> Da - Db";
 17.1111 +by (blast_tac (claset() addIs [NSDERIV_add_minus]) 1);
 17.1112 +qed "NSDERIV_diff";
 17.1113 +
 17.1114 +Goalw [real_diff_def]
 17.1115 +     "[| DERIV f x :> Da; DERIV g x :> Db |] \
 17.1116 +\      ==> DERIV (%x. f x - g x) x :> Da - Db";
 17.1117 +by (blast_tac (claset() addIs [DERIV_add_minus]) 1);
 17.1118 +qed "DERIV_diff";
 17.1119 +
 17.1120 +(*---------------------------------------------------------------
 17.1121 +                     (NS) Increment
 17.1122 + ---------------------------------------------------------------*)
 17.1123 +Goalw [increment_def] 
 17.1124 +      "f NSdifferentiable x ==> \
 17.1125 +\     increment f x h = (*f* f) (hypreal_of_real(x) + h) + \
 17.1126 +\     -hypreal_of_real (f x)";
 17.1127 +by (Blast_tac 1);
 17.1128 +qed "incrementI";
 17.1129 +
 17.1130 +Goal "NSDERIV f x :> D ==> \
 17.1131 +\    increment f x h = (*f* f) (hypreal_of_real(x) + h) + \
 17.1132 +\    -hypreal_of_real (f x)";
 17.1133 +by (etac (NSdifferentiableI RS incrementI) 1);
 17.1134 +qed "incrementI2";
 17.1135 +
 17.1136 +(* The Increment theorem -- Keisler p. 65 *)
 17.1137 +Goal "[| NSDERIV f x :> D; h: Infinitesimal; h ~= #0 |] \
 17.1138 +\     ==> EX e: Infinitesimal. increment f x h = hypreal_of_real(D)*h + e*h";
 17.1139 +by (forw_inst_tac [("h","h")] incrementI2 1 THEN rewtac nsderiv_def);
 17.1140 +by (dtac bspec 1 THEN Auto_tac);
 17.1141 +by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1 THEN Step_tac 1);
 17.1142 +by (forw_inst_tac [("b1","hypreal_of_real(D) + y")] 
 17.1143 +    (rename_numerals (hypreal_mult_right_cancel RS iffD2)) 1);
 17.1144 +by (thin_tac "((*f* f) (hypreal_of_real(x) + h) + \
 17.1145 +\   - hypreal_of_real (f x)) / h = hypreal_of_real(D) + y" 2);
 17.1146 +by (assume_tac 1);
 17.1147 +by (asm_full_simp_tac (simpset() addsimps [hypreal_times_divide1_eq RS sym]
 17.1148 +             delsimps [hypreal_times_divide1_eq]) 1);
 17.1149 +by (auto_tac (claset(),
 17.1150 +              simpset() addsimps [hypreal_add_mult_distrib]));
 17.1151 +qed "increment_thm";
 17.1152 +
 17.1153 +Goal "[| NSDERIV f x :> D; h @= #0; h ~= #0 |] \
 17.1154 +\     ==> EX e: Infinitesimal. increment f x h = \
 17.1155 +\             hypreal_of_real(D)*h + e*h";
 17.1156 +by (blast_tac (claset() addSDs [mem_infmal_iff RS iffD2] 
 17.1157 +                        addSIs [increment_thm]) 1);
 17.1158 +qed "increment_thm2";
 17.1159 +
 17.1160 +Goal "[| NSDERIV f x :> D; h @= #0; h ~= #0 |] \
 17.1161 +\     ==> increment f x h @= #0";
 17.1162 +by (dtac increment_thm2 1 THEN auto_tac (claset() addSIs 
 17.1163 +    [Infinitesimal_HFinite_mult2,HFinite_add],simpset() addsimps 
 17.1164 +    [hypreal_add_mult_distrib RS sym,mem_infmal_iff RS sym]));
 17.1165 +by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
 17.1166 +qed "increment_inf_close_zero";
 17.1167 +
 17.1168 +(*---------------------------------------------------------------
 17.1169 +   Similarly to the above, the chain rule admits an entirely
 17.1170 +   straightforward derivation. Compare this with Harrison's
 17.1171 +   HOL proof of the chain rule, which proved to be trickier and
 17.1172 +   required an alternative characterisation of differentiability- 
 17.1173 +   the so-called Carathedory derivative. Our main problem is
 17.1174 +   manipulation of terms.
 17.1175 + --------------------------------------------------------------*)
 17.1176 +
 17.1177 +(* lemmas *)
 17.1178 +Goalw [nsderiv_def] 
 17.1179 +      "[| NSDERIV g x :> D; \
 17.1180 +\              (*f* g) (hypreal_of_real(x) + xa) = hypreal_of_real(g x);\
 17.1181 +\              xa : Infinitesimal;\
 17.1182 +\              xa ~= #0 \
 17.1183 +\           |] ==> D = #0";
 17.1184 +by (dtac bspec 1);
 17.1185 +by Auto_tac;
 17.1186 +qed "NSDERIV_zero";
 17.1187 +
 17.1188 +(* can be proved differently using NSLIM_isCont_iff *)
 17.1189 +Goalw [nsderiv_def] 
 17.1190 +     "[| NSDERIV f x :> D;  h: Infinitesimal;  h ~= #0 |]  \
 17.1191 +\     ==> (*f* f) (hypreal_of_real(x) + h) + -hypreal_of_real(f x) @= #0";    
 17.1192 +by (asm_full_simp_tac (simpset() addsimps 
 17.1193 +    [mem_infmal_iff RS sym]) 1);
 17.1194 +by (rtac Infinitesimal_ratio 1);
 17.1195 +by (rtac inf_close_hypreal_of_real_HFinite 3);
 17.1196 +by Auto_tac;
 17.1197 +qed "NSDERIV_inf_close";
 17.1198 +
 17.1199 +(*--------------------------------------------------------------- 
 17.1200 +   from one version of differentiability 
 17.1201 + 
 17.1202 +                f(x) - f(a)
 17.1203 +              --------------- @= Db
 17.1204 +                  x - a
 17.1205 + ---------------------------------------------------------------*)
 17.1206 +Goal "[| NSDERIV f (g x) :> Da; \
 17.1207 +\        (*f* g) (hypreal_of_real(x) + xa) ~= hypreal_of_real (g x); \
 17.1208 +\        (*f* g) (hypreal_of_real(x) + xa) @= hypreal_of_real (g x) \
 17.1209 +\     |] ==> ((*f* f) ((*f* g) (hypreal_of_real(x) + xa)) \
 17.1210 +\                  + - hypreal_of_real (f (g x))) \
 17.1211 +\             / ((*f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real (g x)) \
 17.1212 +\            @= hypreal_of_real(Da)";
 17.1213 +by (auto_tac (claset(),
 17.1214 +       simpset() addsimps [NSDERIV_NSLIM_iff2, NSLIM_def]));
 17.1215 +qed "NSDERIVD1";
 17.1216 +
 17.1217 +(*-------------------------------------------------------------- 
 17.1218 +   from other version of differentiability 
 17.1219 +
 17.1220 +                f(x + h) - f(x)
 17.1221 +               ----------------- @= Db
 17.1222 +                       h
 17.1223 + --------------------------------------------------------------*)
 17.1224 +Goal "[| NSDERIV g x :> Db; xa: Infinitesimal; xa ~= #0 |] \
 17.1225 +\     ==> ((*f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real(g x)) / xa \
 17.1226 +\         @= hypreal_of_real(Db)";
 17.1227 +by (auto_tac (claset(),
 17.1228 +    simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def, 
 17.1229 +		hypreal_of_real_zero, mem_infmal_iff, starfun_lambda_cancel]));
 17.1230 +qed "NSDERIVD2";
 17.1231 +
 17.1232 +Goal "(z::hypreal) ~= 0 ==> x*y = (x*inverse(z))*(z*y)";
 17.1233 +by Auto_tac;  
 17.1234 +qed "lemma_chain";
 17.1235 +
 17.1236 +(*------------------------------------------------------
 17.1237 +  This proof uses both definitions of differentiability.
 17.1238 + ------------------------------------------------------*)
 17.1239 +Goal "[| NSDERIV f (g x) :> Da; NSDERIV g x :> Db |] \
 17.1240 +\     ==> NSDERIV (f o g) x :> Da * Db";
 17.1241 +by (asm_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
 17.1242 +    NSLIM_def,hypreal_of_real_zero,mem_infmal_iff RS sym]) 1 THEN Step_tac 1);
 17.1243 +by (forw_inst_tac [("f","g")] NSDERIV_inf_close 1);
 17.1244 +by (auto_tac (claset(),
 17.1245 +              simpset() addsimps [starfun_lambda_cancel2, starfun_o RS sym]));
 17.1246 +by (case_tac "(*f* g) (hypreal_of_real(x) + xa) = hypreal_of_real (g x)" 1);
 17.1247 +by (dres_inst_tac [("g","g")] NSDERIV_zero 1);
 17.1248 +by (auto_tac (claset(),
 17.1249 +    simpset() addsimps [hypreal_divide_def, hypreal_of_real_zero]));
 17.1250 +by (res_inst_tac [("z1","(*f* g) (hypreal_of_real(x) + xa) + -hypreal_of_real (g x)"),
 17.1251 +    ("y1","inverse xa")] (lemma_chain RS ssubst) 1);
 17.1252 +by (etac (hypreal_not_eq_minus_iff RS iffD1) 1);
 17.1253 +by (rtac inf_close_mult_hypreal_of_real 1);
 17.1254 +by (fold_tac [hypreal_divide_def]);
 17.1255 +by (blast_tac (claset() addIs [NSDERIVD1,
 17.1256 +    inf_close_minus_iff RS iffD2]) 1);
 17.1257 +by (blast_tac (claset() addIs [NSDERIVD2]) 1);
 17.1258 +qed "NSDERIV_chain";
 17.1259 +
 17.1260 +(* standard version *)
 17.1261 +Goal "[| DERIV f (g x) :> Da; \
 17.1262 +\                 DERIV g x :> Db \
 17.1263 +\              |] ==> DERIV (f o g) x :> Da * Db";
 17.1264 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym,
 17.1265 +    NSDERIV_chain]) 1);
 17.1266 +qed "DERIV_chain";
 17.1267 +
 17.1268 +Goal "[| DERIV f (g x) :> Da; DERIV g x :> Db |] \
 17.1269 +\     ==> DERIV (%x. f (g x)) x :> Da * Db";
 17.1270 +by (auto_tac (claset() addDs [DERIV_chain], simpset() addsimps [o_def]));
 17.1271 +qed "DERIV_chain2";
 17.1272 +
 17.1273 +(*------------------------------------------------------------------
 17.1274 +           Differentiation of natural number powers
 17.1275 + ------------------------------------------------------------------*)
 17.1276 +Goal "NSDERIV (%x. x) x :> #1";
 17.1277 +by (auto_tac (claset(),
 17.1278 +     simpset() addsimps [NSDERIV_NSLIM_iff,
 17.1279 +          NSLIM_def ,starfun_Id, hypreal_of_real_zero,
 17.1280 +           hypreal_of_real_one]));
 17.1281 +qed "NSDERIV_Id";
 17.1282 +Addsimps [NSDERIV_Id];
 17.1283 +
 17.1284 +(*derivative of the identity function*)
 17.1285 +Goal "DERIV (%x. x) x :> #1";
 17.1286 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
 17.1287 +qed "DERIV_Id";
 17.1288 +Addsimps [DERIV_Id];
 17.1289 +
 17.1290 +bind_thm ("isCont_Id", DERIV_Id RS DERIV_isCont);
 17.1291 +
 17.1292 +(*derivative of linear multiplication*)
 17.1293 +Goal "DERIV (op * c) x :> c";
 17.1294 +by (cut_inst_tac [("c","c"),("x","x")] (DERIV_Id RS DERIV_cmult) 1);
 17.1295 +by (Asm_full_simp_tac 1);
 17.1296 +qed "DERIV_cmult_Id";
 17.1297 +Addsimps [DERIV_cmult_Id];
 17.1298 +
 17.1299 +Goal "NSDERIV (op * c) x :> c";
 17.1300 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff]) 1);
 17.1301 +qed "NSDERIV_cmult_Id";
 17.1302 +Addsimps [NSDERIV_cmult_Id];
 17.1303 +
 17.1304 +Goal "DERIV (%x. x ^ n) x :> real_of_nat n * (x ^ (n - 1))";
 17.1305 +by (induct_tac "n" 1);
 17.1306 +by (dtac (DERIV_Id RS DERIV_mult) 2);
 17.1307 +by (auto_tac (claset(),simpset() addsimps 
 17.1308 +    [real_add_mult_distrib]));
 17.1309 +by (case_tac "0 < n" 1);
 17.1310 +by (dres_inst_tac [("x","x")] realpow_minus_mult 1);
 17.1311 +by (auto_tac (claset(),simpset() addsimps 
 17.1312 +    [real_mult_assoc,real_add_commute]));
 17.1313 +qed "DERIV_pow";
 17.1314 +
 17.1315 +(* NS version *)
 17.1316 +Goal "NSDERIV (%x. x ^ n) x :> real_of_nat n * (x ^ (n - 1))";
 17.1317 +by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,DERIV_pow]) 1);
 17.1318 +qed "NSDERIV_pow";
 17.1319 +
 17.1320 +(*---------------------------------------------------------------
 17.1321 +                    Power of -1 
 17.1322 + ---------------------------------------------------------------*)
 17.1323 +
 17.1324 +(*Can't get rid of x ~= #0 because it isn't continuous at zero*)
 17.1325 +Goalw [nsderiv_def]
 17.1326 +     "x ~= #0 ==> NSDERIV (%x. inverse(x)) x :> (- (inverse x ^ 2))";
 17.1327 +by (rtac ballI 1 THEN Asm_full_simp_tac 1 THEN Step_tac 1);
 17.1328 +by (forward_tac [Infinitesimal_add_not_zero] 1);
 17.1329 +by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 2); 
 17.1330 +by (auto_tac (claset(),
 17.1331 +     simpset() addsimps [starfun_inverse_inverse, realpow_two] 
 17.1332 +               delsimps [hypreal_minus_mult_eq1 RS sym,
 17.1333 +                         hypreal_minus_mult_eq2 RS sym]));
 17.1334 +by (asm_full_simp_tac
 17.1335 +     (simpset() addsimps [hypreal_inverse_add,
 17.1336 +          hypreal_inverse_distrib RS sym, hypreal_minus_inverse RS sym] 
 17.1337 +          @ hypreal_add_ac @ hypreal_mult_ac 
 17.1338 +       delsimps [hypreal_minus_mult_eq1 RS sym,
 17.1339 +                 hypreal_minus_mult_eq2 RS sym] ) 1);
 17.1340 +by (asm_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym,
 17.1341 +                                      hypreal_add_mult_distrib2] 
 17.1342 +         delsimps [hypreal_minus_mult_eq1 RS sym, 
 17.1343 +                   hypreal_minus_mult_eq2 RS sym]) 1);
 17.1344 +by (res_inst_tac [("y"," inverse(- hypreal_of_real x * hypreal_of_real x)")] 
 17.1345 +                 inf_close_trans 1);
 17.1346 +by (rtac inverse_add_Infinitesimal_inf_close2 1);
 17.1347 +by (auto_tac (claset() addSDs [hypreal_of_real_HFinite_diff_Infinitesimal], 
 17.1348 +         simpset() addsimps [hypreal_minus_inverse RS sym,
 17.1349 +                             HFinite_minus_iff]));
 17.1350 +by (rtac Infinitesimal_HFinite_mult2 1); 
 17.1351 +by Auto_tac;  
 17.1352 +qed "NSDERIV_inverse";
 17.1353 +
 17.1354 +
 17.1355 +Goal "x ~= #0 ==> DERIV (%x. inverse(x)) x :> (-(inverse x ^ 2))";
 17.1356 +by (asm_simp_tac (simpset() addsimps [NSDERIV_inverse,
 17.1357 +         NSDERIV_DERIV_iff RS sym] delsimps [realpow_Suc]) 1);
 17.1358 +qed "DERIV_inverse";
 17.1359 +
 17.1360 +(*--------------------------------------------------------------
 17.1361 +        Derivative of inverse 
 17.1362 + -------------------------------------------------------------*)
 17.1363 +Goal "[| DERIV f x :> d; f(x) ~= #0 |] \
 17.1364 +\     ==> DERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ 2)))";
 17.1365 +by (rtac (real_mult_commute RS subst) 1);
 17.1366 +by (asm_simp_tac (simpset() addsimps [real_minus_mult_eq1,
 17.1367 +    realpow_inverse] delsimps [realpow_Suc, 
 17.1368 +    real_minus_mult_eq1 RS sym]) 1);
 17.1369 +by (fold_goals_tac [o_def]);
 17.1370 +by (blast_tac (claset() addSIs [DERIV_chain,DERIV_inverse]) 1);
 17.1371 +qed "DERIV_inverse_fun";
 17.1372 +
 17.1373 +Goal "[| NSDERIV f x :> d; f(x) ~= #0 |] \
 17.1374 +\     ==> NSDERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ 2)))";
 17.1375 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
 17.1376 +            DERIV_inverse_fun] delsimps [realpow_Suc]) 1);
 17.1377 +qed "NSDERIV_inverse_fun";
 17.1378 +
 17.1379 +(*--------------------------------------------------------------
 17.1380 +        Derivative of quotient 
 17.1381 + -------------------------------------------------------------*)
 17.1382 +Goal "[| DERIV f x :> d; DERIV g x :> e; g(x) ~= #0 |] \
 17.1383 +\      ==> DERIV (%y. f(y) / (g y)) x :> (d*g(x) + -(e*f(x))) / (g(x) ^ 2)";
 17.1384 +by (dres_inst_tac [("f","g")] DERIV_inverse_fun 1);
 17.1385 +by (dtac DERIV_mult 2);
 17.1386 +by (REPEAT(assume_tac 1));
 17.1387 +by (asm_full_simp_tac
 17.1388 +    (simpset() addsimps [real_divide_def, real_add_mult_distrib2,
 17.1389 +                         realpow_inverse,real_minus_mult_eq1] @ real_mult_ac 
 17.1390 +       delsimps [realpow_Suc, real_minus_mult_eq1 RS sym,
 17.1391 +                 real_minus_mult_eq2 RS sym]) 1);
 17.1392 +qed "DERIV_quotient";
 17.1393 +
 17.1394 +Goal "[| NSDERIV f x :> d; DERIV g x :> e; g(x) ~= #0 |] \
 17.1395 +\      ==> NSDERIV (%y. f(y) / (g y)) x :> (d*g(x) \
 17.1396 +\                           + -(e*f(x))) / (g(x) ^ 2)";
 17.1397 +by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
 17.1398 +            DERIV_quotient] delsimps [realpow_Suc]) 1);
 17.1399 +qed "NSDERIV_quotient";
 17.1400 + 
 17.1401 +(* ------------------------------------------------------------------------ *)
 17.1402 +(* Caratheodory formulation of derivative at a point: standard proof        *)
 17.1403 +(* ------------------------------------------------------------------------ *)
 17.1404 +
 17.1405 +Goal "(DERIV f x :> l) = \
 17.1406 +\     (EX g. (ALL z. f z - f x = g z * (z - x)) & isCont g x & g x = l)";
 17.1407 +by (Step_tac 1);
 17.1408 +by (res_inst_tac 
 17.1409 +    [("x","%z. if  z = x then l else (f(z) - f(x)) / (z - x)")] exI 1);
 17.1410 +by (auto_tac (claset(),simpset() addsimps [real_mult_assoc,
 17.1411 +    ARITH_PROVE "z ~= x ==> z - x ~= (#0::real)"]));
 17.1412 +by (auto_tac (claset(),simpset() addsimps [isCont_iff,DERIV_iff]));
 17.1413 +by (ALLGOALS(rtac (LIM_equal RS iffD1)));
 17.1414 +by (auto_tac (claset(),simpset() addsimps [real_diff_def,real_mult_assoc]));
 17.1415 +qed "CARAT_DERIV";
 17.1416 +
 17.1417 +Goal "NSDERIV f x :> l ==> \
 17.1418 +\     EX g. (ALL z. f z - f x = g z * (z - x)) & isNSCont g x & g x = l";
 17.1419 +by (auto_tac (claset(),simpset() addsimps [NSDERIV_DERIV_iff,
 17.1420 +    isNSCont_isCont_iff,CARAT_DERIV]));
 17.1421 +qed "CARAT_NSDERIV";
 17.1422 +
 17.1423 +(* How about a NS proof? *)
 17.1424 +Goal "(ALL z. f z - f x = g z * (z - x)) & isNSCont g x & g x = l \
 17.1425 +\     ==> NSDERIV f x :> l";
 17.1426 +by (auto_tac (claset(), 
 17.1427 +              simpset() delsimprocs real_cancel_factor
 17.1428 +                        addsimps [NSDERIV_iff2]));
 17.1429 +by (auto_tac (claset(),
 17.1430 +              simpset() addsimps [hypreal_mult_assoc]));
 17.1431 +by (asm_full_simp_tac (simpset() addsimps [hypreal_eq_minus_iff3 RS sym,
 17.1432 +                                           hypreal_diff_def]) 1);
 17.1433 +by (asm_full_simp_tac (simpset() addsimps [isNSCont_def]) 1);
 17.1434 +qed "CARAT_DERIVD";
 17.1435 + 
 17.1436 +
 17.1437 +
 17.1438 +(*--------------------------------------------------------------------------*)
 17.1439 +(* Lemmas about nested intervals and proof by bisection (cf.Harrison)       *)
 17.1440 +(* All considerably tidied by lcp                                           *)
 17.1441 +(*--------------------------------------------------------------------------*)
 17.1442 +
 17.1443 +Goal "(ALL n. (f::nat=>real) n <= f (Suc n)) --> f m <= f(m + no)";
 17.1444 +by (induct_tac "no" 1);
 17.1445 +by (auto_tac (claset() addIs [order_trans], simpset()));
 17.1446 +qed_spec_mp "lemma_f_mono_add";
 17.1447 +
 17.1448 +Goal "[| ALL n. f(n) <= f(Suc n); \
 17.1449 +\        ALL n. g(Suc n) <= g(n); \
 17.1450 +\        ALL n. f(n) <= g(n) |] \
 17.1451 +\     ==> Bseq f";
 17.1452 +by (res_inst_tac [("k","f 0"),("K","g 0")] BseqI2 1 THEN rtac allI 1);
 17.1453 +by (induct_tac "n" 1);
 17.1454 +by (auto_tac (claset() addIs [order_trans], simpset()));
 17.1455 +by (res_inst_tac [("y","g(Suc na)")] order_trans 1);
 17.1456 +by (induct_tac "na" 2);
 17.1457 +by (auto_tac (claset() addIs [order_trans], simpset()));
 17.1458 +qed "f_inc_g_dec_Beq_f";
 17.1459 +
 17.1460 +Goal "[| ALL n. f(n) <= f(Suc n); \
 17.1461 +\        ALL n. g(Suc n) <= g(n); \
 17.1462 +\        ALL n. f(n) <= g(n) |] \
 17.1463 +\     ==> Bseq g";
 17.1464 +by (stac (Bseq_minus_iff RS sym) 1);
 17.1465 +by (res_inst_tac [("g","%x. -(f x)")] f_inc_g_dec_Beq_f 1); 
 17.1466 +by Auto_tac;  
 17.1467 +qed "f_inc_g_dec_Beq_g";
 17.1468 +
 17.1469 +Goal "[| ALL n. f n <= f (Suc n);  convergent f |] ==> f n <= lim f";
 17.1470 +by (rtac real_leI 1);
 17.1471 +by (auto_tac (claset(), 
 17.1472 +      simpset() addsimps [convergent_LIMSEQ_iff, LIMSEQ_iff, monoseq_Suc]));
 17.1473 +by (dtac real_less_sum_gt_zero 1);
 17.1474 +by (dres_inst_tac [("x","f n + - lim f")] spec 1);
 17.1475 +by Safe_tac;
 17.1476 +by (dres_inst_tac [("P","%na. no<=na --> ?Q na"),("x","no + n")] spec 2);
 17.1477 +by Auto_tac;
 17.1478 +by (subgoal_tac "lim f <= f(no + n)" 1);
 17.1479 +by (induct_tac "no" 2);
 17.1480 +by (auto_tac (claset() addIs [order_trans],
 17.1481 +              simpset() addsimps [real_diff_def, real_abs_def]));
 17.1482 +by (dres_inst_tac [("x","f(no + n)"),("no1","no")] 
 17.1483 +    (lemma_f_mono_add RSN (2,order_less_le_trans)) 1);
 17.1484 +by (auto_tac (claset(), simpset() addsimps [add_commute]));
 17.1485 +qed "f_inc_imp_le_lim";
 17.1486 +
 17.1487 +Goal "convergent g ==> lim (%x. - g x) = - (lim g)";
 17.1488 +by (rtac (LIMSEQ_minus RS limI) 1); 
 17.1489 +by (asm_full_simp_tac (simpset() addsimps [convergent_LIMSEQ_iff]) 1); 
 17.1490 +qed "lim_uminus";
 17.1491 +
 17.1492 +Goal "[| ALL n. g(Suc n) <= g(n);  convergent g |] ==> lim g <= g n";
 17.1493 +by (subgoal_tac "- (g n) <= - (lim g)" 1);
 17.1494 +by (cut_inst_tac [("f", "%x. - (g x)")] f_inc_imp_le_lim 2);
 17.1495 +by (auto_tac (claset(), 
 17.1496 +              simpset() addsimps [lim_uminus, convergent_minus_iff RS sym]));  
 17.1497 +qed "g_dec_imp_lim_le";
 17.1498 +
 17.1499 +Goal "[| ALL n. f(n) <= f(Suc n); \
 17.1500 +\        ALL n. g(Suc n) <= g(n); \
 17.1501 +\        ALL n. f(n) <= g(n) |] \
 17.1502 +\     ==> EX l m. l <= m &  ((ALL n. f(n) <= l) & f ----> l) & \
 17.1503 +\                           ((ALL n. m <= g(n)) & g ----> m)";
 17.1504 +by (subgoal_tac "monoseq f & monoseq g" 1);
 17.1505 +by (force_tac (claset(), simpset() addsimps [LIMSEQ_iff,monoseq_Suc]) 2);
 17.1506 +by (subgoal_tac "Bseq f & Bseq g" 1);
 17.1507 +by (blast_tac (claset() addIs [f_inc_g_dec_Beq_f, f_inc_g_dec_Beq_g]) 2); 
 17.1508 +by (auto_tac (claset() addSDs [Bseq_monoseq_convergent],
 17.1509 +              simpset() addsimps [convergent_LIMSEQ_iff]));
 17.1510 +by (res_inst_tac [("x","lim f")] exI 1);
 17.1511 +by (res_inst_tac [("x","lim g")] exI 1);
 17.1512 +by (auto_tac (claset() addIs [LIMSEQ_le], simpset()));
 17.1513 +by (auto_tac (claset(), 
 17.1514 +              simpset() addsimps [f_inc_imp_le_lim, g_dec_imp_lim_le, 
 17.1515 +                                  convergent_LIMSEQ_iff]));  
 17.1516 +qed "lemma_nest";
 17.1517 +
 17.1518 +Goal "[| ALL n. f(n) <= f(Suc n); \
 17.1519 +\        ALL n. g(Suc n) <= g(n); \
 17.1520 +\        ALL n. f(n) <= g(n); \
 17.1521 +\        (%n. f(n) - g(n)) ----> #0 |] \
 17.1522 +\     ==> EX l. ((ALL n. f(n) <= l) & f ----> l) & \
 17.1523 +\               ((ALL n. l <= g(n)) & g ----> l)";
 17.1524 +by (dtac lemma_nest 1 THEN Auto_tac);
 17.1525 +by (subgoal_tac "l = m" 1);
 17.1526 +by (dres_inst_tac [("X","f")] LIMSEQ_diff 2);
 17.1527 +by (auto_tac (claset() addIs [LIMSEQ_unique], simpset()));
 17.1528 +qed "lemma_nest_unique";
 17.1529 +
 17.1530 +
 17.1531 +Goal "a <= b ==> \
 17.1532 +\  ALL n. fst (Bolzano_bisect P a b n) <= snd (Bolzano_bisect P a b n)";
 17.1533 +by (rtac allI 1);
 17.1534 +by (induct_tac "n" 1);
 17.1535 +by (auto_tac (claset(), simpset() addsimps [Let_def, split_def]));  
 17.1536 +qed "Bolzano_bisect_le";
 17.1537 +
 17.1538 +Goal "a <= b ==> \
 17.1539 +\  ALL n. fst(Bolzano_bisect P a b n) <= fst (Bolzano_bisect P a b (Suc n))";
 17.1540 +by (rtac allI 1);
 17.1541 +by (induct_tac "n" 1);
 17.1542 +by (auto_tac (claset(), 
 17.1543 +              simpset() addsimps [Bolzano_bisect_le, Let_