conversion of Hyperreal/Lim to new-style
authorpaulson
Fri Mar 19 10:51:03 2004 +0100 (2004-03-19)
changeset 14477cc61fd03e589
parent 14476 758e7acdea2f
child 14478 bdf6b7adc3ec
conversion of Hyperreal/Lim to new-style
src/HOL/Hyperreal/HTranscendental.thy
src/HOL/Hyperreal/HyperDef.thy
src/HOL/Hyperreal/Integration.ML
src/HOL/Hyperreal/Lim.ML
src/HOL/Hyperreal/Lim.thy
src/HOL/Hyperreal/NSA.thy
src/HOL/Hyperreal/NthRoot.thy
src/HOL/Hyperreal/SEQ.ML
src/HOL/Hyperreal/Star.thy
src/HOL/Hyperreal/Transcendental.ML
src/HOL/IsaMakefile
     1.1 --- a/src/HOL/Hyperreal/HTranscendental.thy	Fri Mar 19 10:50:06 2004 +0100
     1.2 +++ b/src/HOL/Hyperreal/HTranscendental.thy	Fri Mar 19 10:51:03 2004 +0100
     1.3 @@ -573,7 +573,7 @@
     1.4  apply (frule STAR_sin_Infinitesimal_divide
     1.5                 [OF Infinitesimal_pi_divide_HNatInfinite 
     1.6                     pi_divide_HNatInfinite_not_zero])
     1.7 -apply (auto simp add: hypreal_inverse_distrib)
     1.8 +apply (auto simp add: inverse_mult_distrib)
     1.9  apply (rule approx_SReal_mult_cancel [of "inverse (hypreal_of_real pi)"])
    1.10  apply (auto intro: SReal_inverse simp add: divide_inverse mult_ac)
    1.11  done
     2.1 --- a/src/HOL/Hyperreal/HyperDef.thy	Fri Mar 19 10:50:06 2004 +0100
     2.2 +++ b/src/HOL/Hyperreal/HyperDef.thy	Fri Mar 19 10:51:03 2004 +0100
     2.3 @@ -543,64 +543,17 @@
     2.4      by (auto dest: order_le_less_trans simp add: hrabs_def linorder_not_le)
     2.5  qed
     2.6  
     2.7 -lemma hypreal_mult_1_right: "z * (1::hypreal) = z"
     2.8 -  by (rule Ring_and_Field.mult_1_right)
     2.9 -
    2.10 -lemma hypreal_mult_minus_1 [simp]: "(- (1::hypreal)) * z = -z"
    2.11 -by simp
    2.12 -
    2.13 -lemma hypreal_mult_minus_1_right [simp]: "z * (- (1::hypreal)) = -z"
    2.14 -by (subst hypreal_mult_commute, simp)
    2.15 -
    2.16 -(*Used ONCE: in NSA.ML*)
    2.17 -lemma hypreal_minus_distrib1: "-(y + -(x::hypreal)) = x + -y"
    2.18 -by (simp add: hypreal_add_commute)
    2.19 -
    2.20 -(*Used ONCE: in Lim.ML*)
    2.21 -lemma hypreal_eq_minus_iff3: "(x = y + z) = (x + -z = (y::hypreal))"
    2.22 -by (auto simp add: hypreal_add_assoc)
    2.23 -
    2.24  lemma hypreal_eq_minus_iff: "((x::hypreal) = y) = (x + - y = 0)"
    2.25  apply auto
    2.26  apply (rule Ring_and_Field.add_right_cancel [of _ "-y", THEN iffD1], auto)
    2.27  done
    2.28  
    2.29 -(*Used 3 TIMES: in Lim.ML*)
    2.30 -lemma hypreal_not_eq_minus_iff: "(x \<noteq> a) = (x + -a \<noteq> (0::hypreal))"
    2.31 -by (auto dest: hypreal_eq_minus_iff [THEN iffD2])
    2.32 -
    2.33  lemma hypreal_mult_left_cancel: "(c::hypreal) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
    2.34  by auto
    2.35      
    2.36  lemma hypreal_mult_right_cancel: "(c::hypreal) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
    2.37  by auto
    2.38  
    2.39 -lemma hypreal_mult_not_0: "[| x \<noteq> 0; y \<noteq> 0 |] ==> x * y \<noteq> (0::hypreal)"
    2.40 -by simp
    2.41 -
    2.42 -lemma hypreal_minus_inverse: "inverse(-x) = -inverse(x::hypreal)"
    2.43 -  by (rule Ring_and_Field.inverse_minus_eq)
    2.44 -
    2.45 -lemma hypreal_inverse_distrib: "inverse(x*y) = inverse(x)*inverse(y::hypreal)"
    2.46 -  by (rule Ring_and_Field.inverse_mult_distrib)
    2.47 -
    2.48 -
    2.49 -subsection{* Division lemmas *}
    2.50 -
    2.51 -lemma hypreal_divide_one: "x/(1::hypreal) = x"
    2.52 -by (simp add: hypreal_divide_def)
    2.53 -
    2.54 -
    2.55 -(** As with multiplication, pull minus signs OUT of the / operator **)
    2.56 -
    2.57 -lemma hypreal_add_divide_distrib: "(x+y)/(z::hypreal) = x/z + y/z"
    2.58 -  by (rule Ring_and_Field.add_divide_distrib)
    2.59 -
    2.60 -lemma hypreal_inverse_add:
    2.61 -     "[|(x::hypreal) \<noteq> 0;  y \<noteq> 0 |]   
    2.62 -      ==> inverse(x) + inverse(y) = (x + y)*inverse(x*y)"
    2.63 -by (simp add: Ring_and_Field.inverse_add mult_assoc)
    2.64 -
    2.65  
    2.66  subsection{*The Embedding @{term hypreal_of_real} Preserves Field and 
    2.67        Order Properties*}
    2.68 @@ -832,15 +785,11 @@
    2.69  val hypreal_add_zero_right = thm "hypreal_add_zero_right";
    2.70  val hypreal_add_minus = thm "hypreal_add_minus";
    2.71  val hypreal_add_minus_left = thm "hypreal_add_minus_left";
    2.72 -val hypreal_minus_distrib1 = thm "hypreal_minus_distrib1";
    2.73  val hypreal_mult_congruent2 = thm "hypreal_mult_congruent2";
    2.74  val hypreal_mult = thm "hypreal_mult";
    2.75  val hypreal_mult_commute = thm "hypreal_mult_commute";
    2.76  val hypreal_mult_assoc = thm "hypreal_mult_assoc";
    2.77  val hypreal_mult_1 = thm "hypreal_mult_1";
    2.78 -val hypreal_mult_1_right = thm "hypreal_mult_1_right";
    2.79 -val hypreal_mult_minus_1 = thm "hypreal_mult_minus_1";
    2.80 -val hypreal_mult_minus_1_right = thm "hypreal_mult_minus_1_right";
    2.81  val hypreal_zero_not_eq_one = thm "hypreal_zero_not_eq_one";
    2.82  val hypreal_inverse_congruent = thm "hypreal_inverse_congruent";
    2.83  val hypreal_inverse = thm "hypreal_inverse";
    2.84 @@ -848,14 +797,9 @@
    2.85  val hypreal_mult_inverse_left = thm "hypreal_mult_inverse_left";
    2.86  val hypreal_mult_left_cancel = thm "hypreal_mult_left_cancel";
    2.87  val hypreal_mult_right_cancel = thm "hypreal_mult_right_cancel";
    2.88 -val hypreal_mult_not_0 = thm "hypreal_mult_not_0";
    2.89 -val hypreal_minus_inverse = thm "hypreal_minus_inverse";
    2.90 -val hypreal_inverse_distrib = thm "hypreal_inverse_distrib";
    2.91  val hypreal_not_refl2 = thm "hypreal_not_refl2";
    2.92  val hypreal_less = thm "hypreal_less";
    2.93  val hypreal_eq_minus_iff = thm "hypreal_eq_minus_iff";
    2.94 -val hypreal_eq_minus_iff3 = thm "hypreal_eq_minus_iff3";
    2.95 -val hypreal_not_eq_minus_iff = thm "hypreal_not_eq_minus_iff";
    2.96  val hypreal_le = thm "hypreal_le";
    2.97  val hypreal_le_refl = thm "hypreal_le_refl";
    2.98  val hypreal_le_linear = thm "hypreal_le_linear";
    2.99 @@ -872,9 +816,6 @@
   2.100  val hypreal_of_real_zero = thm "hypreal_of_real_zero";
   2.101  val hypreal_of_real_inverse = thm "hypreal_of_real_inverse";
   2.102  val hypreal_of_real_divide = thm "hypreal_of_real_divide";
   2.103 -val hypreal_divide_one = thm "hypreal_divide_one";
   2.104 -val hypreal_add_divide_distrib = thm "hypreal_add_divide_distrib";
   2.105 -val hypreal_inverse_add = thm "hypreal_inverse_add";
   2.106  val hypreal_zero_num = thm "hypreal_zero_num";
   2.107  val hypreal_one_num = thm "hypreal_one_num";
   2.108  val hypreal_omega_gt_zero = thm "hypreal_omega_gt_zero";
     3.1 --- a/src/HOL/Hyperreal/Integration.ML	Fri Mar 19 10:50:06 2004 +0100
     3.2 +++ b/src/HOL/Hyperreal/Integration.ML	Fri Mar 19 10:51:03 2004 +0100
     3.3 @@ -508,7 +508,7 @@
     3.4  by (Asm_full_simp_tac 2 THEN arith_tac 2);
     3.5  by (ALLGOALS (thin_tac "ALL xa. \
     3.6  \             xa ~= x & abs (xa + - x) < s --> \
     3.7 -\             abs ((f xa + - f x) / (xa + - x) + - f' x) * 2 < e"));
     3.8 +\             abs ((f xa - f x) / (xa - x) + - f' x) * 2 < e"));
     3.9  by (dres_inst_tac [("x","v")] spec 1 THEN Auto_tac);
    3.10  by (arith_tac 1);
    3.11  by (dres_inst_tac [("x","u")] spec 1 THEN Auto_tac);
     4.1 --- a/src/HOL/Hyperreal/Lim.ML	Fri Mar 19 10:50:06 2004 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,2307 +0,0 @@
     4.4 -(*  Title       : Lim.ML
     4.5 -    Author      : Jacques D. Fleuriot
     4.6 -    Copyright   : 1998  University of Cambridge
     4.7 -    Description : Theory of limits, continuity and
     4.8 -                  differentiation of real=>real functions
     4.9 -*)
    4.10 -
    4.11 -fun ARITH_PROVE str = prove_goal thy str
    4.12 -                      (fn prems => [cut_facts_tac prems 1,arith_tac 1]);
    4.13 -
    4.14 -
    4.15 -(*---------------------------------------------------------------
    4.16 -   Theory of limits, continuity and differentiation of
    4.17 -   real=>real functions
    4.18 - ----------------------------------------------------------------*)
    4.19 -
    4.20 -Goalw [LIM_def] "(%x. k) -- x --> k";
    4.21 -by Auto_tac;
    4.22 -qed "LIM_const";
    4.23 -Addsimps [LIM_const];
    4.24 -
    4.25 -(***-----------------------------------------------------------***)
    4.26 -(***  Some Purely Standard Proofs - Can be used for comparison ***)
    4.27 -(***-----------------------------------------------------------***)
    4.28 -
    4.29 -(*---------------
    4.30 -    LIM_add
    4.31 - ---------------*)
    4.32 -Goalw [LIM_def]
    4.33 -     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + g(x)) -- x --> (l + m)";
    4.34 -by (Clarify_tac 1);
    4.35 -by (REPEAT(dres_inst_tac [("x","r/2")] spec 1));
    4.36 -by (Asm_full_simp_tac 1);
    4.37 -by (Clarify_tac 1);
    4.38 -by (res_inst_tac [("x","s"),("y","sa")] linorder_cases 1);
    4.39 -by (res_inst_tac [("x","s")] exI 1);
    4.40 -by (res_inst_tac [("x","sa")] exI 2);
    4.41 -by (res_inst_tac [("x","sa")] exI 3);
    4.42 -by Safe_tac;
    4.43 -by (REPEAT(dres_inst_tac [("x","xa")] spec 1)
    4.44 -    THEN step_tac (claset() addSEs [order_less_trans]) 1);
    4.45 -by (REPEAT(dres_inst_tac [("x","xa")] spec 2)
    4.46 -    THEN step_tac (claset() addSEs [order_less_trans]) 2);
    4.47 -by (REPEAT(dres_inst_tac [("x","xa")] spec 3)
    4.48 -    THEN step_tac (claset() addSEs [order_less_trans]) 3);
    4.49 -by (ALLGOALS(rtac (abs_sum_triangle_ineq RS order_le_less_trans)));
    4.50 -by (ALLGOALS(rtac (real_sum_of_halves RS subst)));
    4.51 -by (auto_tac (claset() addIs [add_strict_mono],simpset()));
    4.52 -qed "LIM_add";
    4.53 -
    4.54 -Goalw [LIM_def] "f -- a --> L ==> (%x. -f(x)) -- a --> -L";
    4.55 -by (subgoal_tac "ALL x. abs(- f x + L) = abs(f x + - L)" 1);
    4.56 -by (Asm_full_simp_tac 1);
    4.57 -by (asm_full_simp_tac (simpset() addsimps [real_abs_def]) 1);
    4.58 -qed "LIM_minus";
    4.59 -
    4.60 -(*----------------------------------------------
    4.61 -     LIM_add_minus
    4.62 - ----------------------------------------------*)
    4.63 -Goal "[| f -- x --> l; g -- x --> m |] \
    4.64 -\     ==> (%x. f(x) + -g(x)) -- x --> (l + -m)";
    4.65 -by (blast_tac (claset() addDs [LIM_add,LIM_minus]) 1);
    4.66 -qed "LIM_add_minus";
    4.67 -
    4.68 -(*----------------------------------------------
    4.69 -     LIM_zero
    4.70 - ----------------------------------------------*)
    4.71 -Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> 0";
    4.72 -by (res_inst_tac [("a1","l")] ((right_minus RS subst)) 1);
    4.73 -by (rtac LIM_add_minus 1 THEN Auto_tac);
    4.74 -qed "LIM_zero";
    4.75 -
    4.76 -(*--------------------------
    4.77 -   Limit not zero
    4.78 - --------------------------*)
    4.79 -Goalw [LIM_def] "k \\<noteq> 0 ==> ~ ((%x. k) -- x --> 0)";
    4.80 -by (res_inst_tac [("x","k"),("y","0")] linorder_cases 1);
    4.81 -by (auto_tac (claset(), simpset() addsimps [real_abs_def]));
    4.82 -by (res_inst_tac [("x","-k")] exI 1);
    4.83 -by (res_inst_tac [("x","k")] exI 2);
    4.84 -by Auto_tac;
    4.85 -by (ALLGOALS(dres_inst_tac [("y","s")] real_dense));
    4.86 -by Safe_tac;
    4.87 -by (ALLGOALS(res_inst_tac [("x","r + x")] exI));
    4.88 -by Auto_tac;
    4.89 -qed "LIM_not_zero";
    4.90 -
    4.91 -(* [| k \\<noteq> 0; (%x. k) -- x --> 0 |] ==> R *)
    4.92 -bind_thm("LIM_not_zeroE", LIM_not_zero RS notE);
    4.93 -
    4.94 -Goal "(%x. k) -- x --> L ==> k = L";
    4.95 -by (rtac ccontr 1);
    4.96 -by (dtac LIM_zero 1);
    4.97 -by (rtac LIM_not_zeroE 1 THEN assume_tac 2);
    4.98 -by (arith_tac 1);
    4.99 -qed "LIM_const_eq";
   4.100 -
   4.101 -(*------------------------
   4.102 -     Limit is Unique
   4.103 - ------------------------*)
   4.104 -Goal "[| f -- x --> L; f -- x --> M |] ==> L = M";
   4.105 -by (dtac LIM_minus 1);
   4.106 -by (dtac LIM_add 1 THEN assume_tac 1);
   4.107 -by (auto_tac (claset() addSDs [LIM_const_eq RS sym],  simpset()));
   4.108 -qed "LIM_unique";
   4.109 -
   4.110 -(*-------------
   4.111 -    LIM_mult_zero
   4.112 - -------------*)
   4.113 -Goalw [LIM_def]
   4.114 -     "[| f -- x --> 0; g -- x --> 0 |] ==> (%x. f(x)*g(x)) -- x --> 0";
   4.115 -by Safe_tac;
   4.116 -by (dres_inst_tac [("x","1")] spec 1);
   4.117 -by (dres_inst_tac [("x","r")] spec 1);
   4.118 -by (cut_facts_tac [real_zero_less_one] 1);
   4.119 -by (asm_full_simp_tac (simpset() addsimps [abs_mult]) 1);
   4.120 -by (Clarify_tac 1);
   4.121 -by (res_inst_tac [("x","s"),("y","sa")]
   4.122 -    linorder_cases 1);
   4.123 -by (res_inst_tac [("x","s")] exI 1);
   4.124 -by (res_inst_tac [("x","sa")] exI 2);
   4.125 -by (res_inst_tac [("x","sa")] exI 3);
   4.126 -by Safe_tac;
   4.127 -by (REPEAT(dres_inst_tac [("x","xa")] spec 1)
   4.128 -    THEN step_tac (claset() addSEs [order_less_trans]) 1);
   4.129 -by (REPEAT(dres_inst_tac [("x","xa")] spec 2)
   4.130 -    THEN step_tac (claset() addSEs [order_less_trans]) 2);
   4.131 -by (REPEAT(dres_inst_tac [("x","xa")] spec 3)
   4.132 -    THEN step_tac (claset() addSEs [order_less_trans]) 3);
   4.133 -by (ALLGOALS(res_inst_tac [("t","r")] (real_mult_1 RS subst)));
   4.134 -by (ALLGOALS(rtac abs_mult_less));
   4.135 -by Auto_tac;
   4.136 -qed "LIM_mult_zero";
   4.137 -
   4.138 -Goalw [LIM_def] "(%x. x) -- a --> a";
   4.139 -by Auto_tac;
   4.140 -qed "LIM_self";
   4.141 -
   4.142 -(*--------------------------------------------------------------
   4.143 -   Limits are equal for functions equal except at limit point
   4.144 - --------------------------------------------------------------*)
   4.145 -Goalw [LIM_def]
   4.146 -     "[| \\<forall>x. x \\<noteq> a --> (f x = g x) |] \
   4.147 -\     ==> (f -- a --> l) = (g -- a --> l)";
   4.148 -by (auto_tac (claset(), simpset() addsimps [real_add_minus_iff]));
   4.149 -qed "LIM_equal";
   4.150 -
   4.151 -Goal "[| (%x. f(x) + -g(x)) -- a --> 0;  g -- a --> l |] \
   4.152 -\     ==> f -- a --> l";
   4.153 -by (dtac LIM_add 1 THEN assume_tac 1);
   4.154 -by (auto_tac (claset(), simpset() addsimps [real_add_assoc]));
   4.155 -qed "LIM_trans";
   4.156 -
   4.157 -(***-------------------------------------------------------------***)
   4.158 -(***           End of Purely Standard Proofs                     ***)
   4.159 -(***-------------------------------------------------------------***)
   4.160 -(*--------------------------------------------------------------
   4.161 -       Standard and NS definitions of Limit
   4.162 - --------------------------------------------------------------*)
   4.163 -Goalw [LIM_def,NSLIM_def,approx_def]
   4.164 -      "f -- x --> L ==> f -- x --NS> L";
   4.165 -by (asm_full_simp_tac
   4.166 -    (simpset() addsimps [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   4.167 -by Safe_tac;
   4.168 -by (res_inst_tac [("z","xa")] eq_Abs_hypreal 1);
   4.169 -by (auto_tac (claset(),
   4.170 -      simpset() addsimps [real_add_minus_iff, starfun, hypreal_minus,
   4.171 -                          hypreal_of_real_def, hypreal_add]));
   4.172 -by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2 THEN Step_tac 1);
   4.173 -by (dres_inst_tac [("x","u")] spec 1 THEN Clarify_tac 1);
   4.174 -by (dres_inst_tac [("x","s")] spec 1 THEN Clarify_tac 1);
   4.175 -by (subgoal_tac "\\<forall>n::nat. (xa n) \\<noteq> x & \
   4.176 -\                    abs ((xa n) + - x) < s --> abs (f (xa n) + - L) < u" 1);
   4.177 -by (Blast_tac 2);
   4.178 -by (dtac FreeUltrafilterNat_all 1);
   4.179 -by (Ultra_tac 1);
   4.180 -qed "LIM_NSLIM";
   4.181 -
   4.182 -(*---------------------------------------------------------------------
   4.183 -    Limit: NS definition ==> standard definition
   4.184 - ---------------------------------------------------------------------*)
   4.185 -
   4.186 -Goal "\\<forall>s. 0 < s --> (\\<exists>xa.  xa \\<noteq> x & \
   4.187 -\        abs (xa + - x) < s  & r \\<le> abs (f xa + -L)) \
   4.188 -\     ==> \\<forall>n::nat. \\<exists>xa.  xa \\<noteq> x & \
   4.189 -\             abs(xa + -x) < inverse(real(Suc n)) & r \\<le> abs(f xa + -L)";
   4.190 -by (Clarify_tac 1);
   4.191 -by (cut_inst_tac [("n1","n")]
   4.192 -    (real_of_nat_Suc_gt_zero RS positive_imp_inverse_positive) 1);
   4.193 -by Auto_tac;
   4.194 -qed "lemma_LIM";
   4.195 -
   4.196 -Goal "\\<forall>s. 0 < s --> (\\<exists>xa.  xa \\<noteq> x & \
   4.197 -\        abs (xa + - x) < s  & r \\<le> abs (f xa + -L)) \
   4.198 -\     ==> \\<exists>X. \\<forall>n::nat. X n \\<noteq> x & \
   4.199 -\               abs(X n + -x) < inverse(real(Suc n)) & r \\<le> abs(f (X n) + -L)";
   4.200 -by (dtac lemma_LIM 1);
   4.201 -by (dtac choice 1);
   4.202 -by (Blast_tac 1);
   4.203 -qed "lemma_skolemize_LIM2";
   4.204 -
   4.205 -Goal "\\<forall>n. X n \\<noteq> x & \
   4.206 -\         abs (X n + - x) < inverse (real(Suc n)) & \
   4.207 -\         r \\<le> abs (f (X n) + - L) ==> \
   4.208 -\         \\<forall>n. abs (X n + - x) < inverse (real(Suc n))";
   4.209 -by (Auto_tac );
   4.210 -qed "lemma_simp";
   4.211 -
   4.212 -(*-------------------
   4.213 -    NSLIM => LIM
   4.214 - -------------------*)
   4.215 -
   4.216 -Goalw [LIM_def,NSLIM_def,approx_def]
   4.217 -     "f -- x --NS> L ==> f -- x --> L";
   4.218 -by (asm_full_simp_tac
   4.219 -    (simpset() addsimps [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   4.220 -by (EVERY1[Step_tac, rtac ccontr, Asm_full_simp_tac]);
   4.221 -by (asm_full_simp_tac (simpset() addsimps [linorder_not_less]) 1);
   4.222 -by (dtac lemma_skolemize_LIM2 1);
   4.223 -by Safe_tac;
   4.224 -by (dres_inst_tac [("x","Abs_hypreal(hyprel``{X})")] spec 1);
   4.225 -by (auto_tac
   4.226 -    (claset(),
   4.227 -     simpset() addsimps [starfun, hypreal_minus,
   4.228 -                         hypreal_of_real_def,hypreal_add]));
   4.229 -by (dtac (lemma_simp RS real_seq_to_hypreal_Infinitesimal) 1);
   4.230 -by (asm_full_simp_tac
   4.231 -    (simpset() addsimps
   4.232 -       [Infinitesimal_FreeUltrafilterNat_iff,hypreal_of_real_def,
   4.233 -        hypreal_minus, hypreal_add]) 1);
   4.234 -by (Blast_tac 1);
   4.235 -by (dtac spec 1 THEN dtac mp 1 THEN assume_tac 1);
   4.236 -by (dtac FreeUltrafilterNat_all 1);
   4.237 -by (Ultra_tac 1);
   4.238 -qed "NSLIM_LIM";
   4.239 -
   4.240 -
   4.241 -(**** Key result ****)
   4.242 -Goal "(f -- x --> L) = (f -- x --NS> L)";
   4.243 -by (blast_tac (claset() addIs [LIM_NSLIM,NSLIM_LIM]) 1);
   4.244 -qed "LIM_NSLIM_iff";
   4.245 -
   4.246 -(*-------------------------------------------------------------------*)
   4.247 -(*   Proving properties of limits using nonstandard definition and   *)
   4.248 -(*   hence, the properties hold for standard limits as well          *)
   4.249 -(*-------------------------------------------------------------------*)
   4.250 -(*------------------------------------------------
   4.251 -      NSLIM_mult and hence (trivially) LIM_mult
   4.252 - ------------------------------------------------*)
   4.253 -
   4.254 -Goalw [NSLIM_def]
   4.255 -     "[| f -- x --NS> l; g -- x --NS> m |] \
   4.256 -\     ==> (%x. f(x) * g(x)) -- x --NS> (l * m)";
   4.257 -by (auto_tac (claset() addSIs [approx_mult_HFinite],  simpset()));
   4.258 -qed "NSLIM_mult";
   4.259 -
   4.260 -Goal "[| f -- x --> l; g -- x --> m |] \
   4.261 -\     ==> (%x. f(x) * g(x)) -- x --> (l * m)";
   4.262 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_mult]) 1);
   4.263 -qed "LIM_mult2";
   4.264 -
   4.265 -(*----------------------------------------------
   4.266 -      NSLIM_add and hence (trivially) LIM_add
   4.267 -      Note the much shorter proof
   4.268 - ----------------------------------------------*)
   4.269 -Goalw [NSLIM_def]
   4.270 -     "[| f -- x --NS> l; g -- x --NS> m |] \
   4.271 -\     ==> (%x. f(x) + g(x)) -- x --NS> (l + m)";
   4.272 -by (auto_tac (claset() addSIs [approx_add], simpset()));
   4.273 -qed "NSLIM_add";
   4.274 -
   4.275 -Goal "[| f -- x --> l; g -- x --> m |] \
   4.276 -\     ==> (%x. f(x) + g(x)) -- x --> (l + m)";
   4.277 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_add]) 1);
   4.278 -qed "LIM_add2";
   4.279 -
   4.280 -(*----------------------------------------------
   4.281 -     NSLIM_const
   4.282 - ----------------------------------------------*)
   4.283 -Goalw [NSLIM_def] "(%x. k) -- x --NS> k";
   4.284 -by Auto_tac;
   4.285 -qed "NSLIM_const";
   4.286 -
   4.287 -Addsimps [NSLIM_const];
   4.288 -
   4.289 -Goal "(%x. k) -- x --> k";
   4.290 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   4.291 -qed "LIM_const2";
   4.292 -
   4.293 -(*----------------------------------------------
   4.294 -     NSLIM_minus
   4.295 - ----------------------------------------------*)
   4.296 -Goalw [NSLIM_def]
   4.297 -      "f -- a --NS> L ==> (%x. -f(x)) -- a --NS> -L";
   4.298 -by Auto_tac;
   4.299 -qed "NSLIM_minus";
   4.300 -
   4.301 -Goal "f -- a --> L ==> (%x. -f(x)) -- a --> -L";
   4.302 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_minus]) 1);
   4.303 -qed "LIM_minus2";
   4.304 -
   4.305 -(*----------------------------------------------
   4.306 -     NSLIM_add_minus
   4.307 - ----------------------------------------------*)
   4.308 -Goal "[| f -- x --NS> l; g -- x --NS> m |] \
   4.309 -\     ==> (%x. f(x) + -g(x)) -- x --NS> (l + -m)";
   4.310 -by (blast_tac (claset() addDs [NSLIM_add,NSLIM_minus]) 1);
   4.311 -qed "NSLIM_add_minus";
   4.312 -
   4.313 -Goal "[| f -- x --> l; g -- x --> m |] \
   4.314 -\     ==> (%x. f(x) + -g(x)) -- x --> (l + -m)";
   4.315 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   4.316 -    NSLIM_add_minus]) 1);
   4.317 -qed "LIM_add_minus2";
   4.318 -
   4.319 -(*-----------------------------
   4.320 -    NSLIM_inverse
   4.321 - -----------------------------*)
   4.322 -Goalw [NSLIM_def]
   4.323 -     "[| f -- a --NS> L;  L \\<noteq> 0 |] \
   4.324 -\     ==> (%x. inverse(f(x))) -- a --NS> (inverse L)";
   4.325 -by (Clarify_tac 1);
   4.326 -by (dtac spec 1);
   4.327 -by (auto_tac (claset(),
   4.328 -              simpset() addsimps [hypreal_of_real_approx_inverse]));
   4.329 -qed "NSLIM_inverse";
   4.330 -
   4.331 -Goal "[| f -- a --> L; \
   4.332 -\        L \\<noteq> 0 |] ==> (%x. inverse(f(x))) -- a --> (inverse L)";
   4.333 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_inverse]) 1);
   4.334 -qed "LIM_inverse";
   4.335 -
   4.336 -(*------------------------------
   4.337 -    NSLIM_zero
   4.338 - ------------------------------*)
   4.339 -Goal "f -- a --NS> l ==> (%x. f(x) + -l) -- a --NS> 0";
   4.340 -by (res_inst_tac [("a1","l")] ((right_minus RS subst)) 1);
   4.341 -by (rtac NSLIM_add_minus 1 THEN Auto_tac);
   4.342 -qed "NSLIM_zero";
   4.343 -
   4.344 -Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> 0";
   4.345 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_zero]) 1);
   4.346 -qed "LIM_zero2";
   4.347 -
   4.348 -Goal "(%x. f(x) - l) -- x --NS> 0 ==> f -- x --NS> l";
   4.349 -by (dres_inst_tac [("g","%x. l"),("m","l")] NSLIM_add 1);
   4.350 -by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
   4.351 -qed "NSLIM_zero_cancel";
   4.352 -
   4.353 -Goal "(%x. f(x) - l) -- x --> 0 ==> f -- x --> l";
   4.354 -by (dres_inst_tac [("g","%x. l"),("m","l")] LIM_add 1);
   4.355 -by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
   4.356 -qed "LIM_zero_cancel";
   4.357 -
   4.358 -
   4.359 -(*--------------------------
   4.360 -   NSLIM_not_zero
   4.361 - --------------------------*)
   4.362 -Goalw [NSLIM_def] "k \\<noteq> 0 ==> ~ ((%x. k) -- x --NS> 0)";
   4.363 -by Auto_tac;
   4.364 -by (res_inst_tac [("x","hypreal_of_real x + epsilon")] exI 1);
   4.365 -by (auto_tac (claset() addIs [Infinitesimal_add_approx_self RS approx_sym],
   4.366 -              simpset() addsimps [hypreal_epsilon_not_zero]));
   4.367 -qed "NSLIM_not_zero";
   4.368 -
   4.369 -(* [| k \\<noteq> 0; (%x. k) -- x --NS> 0 |] ==> R *)
   4.370 -bind_thm("NSLIM_not_zeroE", NSLIM_not_zero RS notE);
   4.371 -
   4.372 -Goal "k \\<noteq> 0 ==> ~ ((%x. k) -- x --> 0)";
   4.373 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_not_zero]) 1);
   4.374 -qed "LIM_not_zero2";
   4.375 -
   4.376 -(*-------------------------------------
   4.377 -   NSLIM of constant function
   4.378 - -------------------------------------*)
   4.379 -Goal "(%x. k) -- x --NS> L ==> k = L";
   4.380 -by (rtac ccontr 1);
   4.381 -by (dtac NSLIM_zero 1);
   4.382 -by (rtac NSLIM_not_zeroE 1 THEN assume_tac 2);
   4.383 -by (arith_tac 1);
   4.384 -qed "NSLIM_const_eq";
   4.385 -
   4.386 -Goal "(%x. k) -- x --> L ==> k = L";
   4.387 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff,
   4.388 -    NSLIM_const_eq]) 1);
   4.389 -qed "LIM_const_eq2";
   4.390 -
   4.391 -(*------------------------
   4.392 -     NS Limit is Unique
   4.393 - ------------------------*)
   4.394 -(* can actually be proved more easily by unfolding def! *)
   4.395 -Goal "[| f -- x --NS> L; f -- x --NS> M |] ==> L = M";
   4.396 -by (dtac NSLIM_minus 1);
   4.397 -by (dtac NSLIM_add 1 THEN assume_tac 1);
   4.398 -by (auto_tac (claset() addSDs [NSLIM_const_eq RS sym], simpset()));
   4.399 -qed "NSLIM_unique";
   4.400 -
   4.401 -Goal "[| f -- x --> L; f -- x --> M |] ==> L = M";
   4.402 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_unique]) 1);
   4.403 -qed "LIM_unique2";
   4.404 -
   4.405 -(*--------------------
   4.406 -    NSLIM_mult_zero
   4.407 - --------------------*)
   4.408 -Goal "[| f -- x --NS> 0; g -- x --NS> 0 |] \
   4.409 -\         ==> (%x. f(x)*g(x)) -- x --NS> 0";
   4.410 -by (dtac NSLIM_mult 1 THEN Auto_tac);
   4.411 -qed "NSLIM_mult_zero";
   4.412 -
   4.413 -(* we can use the corresponding thm LIM_mult2 *)
   4.414 -(* for standard definition of limit           *)
   4.415 -
   4.416 -Goal "[| f -- x --> 0; g -- x --> 0 |] \
   4.417 -\     ==> (%x. f(x)*g(x)) -- x --> 0";
   4.418 -by (dtac LIM_mult2 1 THEN Auto_tac);
   4.419 -qed "LIM_mult_zero2";
   4.420 -
   4.421 -(*----------------------------
   4.422 -    NSLIM_self
   4.423 - ----------------------------*)
   4.424 -Goalw [NSLIM_def] "(%x. x) -- a --NS> a";
   4.425 -by (auto_tac (claset() addIs [starfun_Idfun_approx],simpset()));
   4.426 -qed "NSLIM_self";
   4.427 -
   4.428 -Goal "(%x. x) -- a --> a";
   4.429 -by (simp_tac (simpset() addsimps [LIM_NSLIM_iff,NSLIM_self]) 1);
   4.430 -qed "LIM_self2";
   4.431 -
   4.432 -(*-----------------------------------------------------------------------------
   4.433 -   Derivatives and Continuity - NS and Standard properties
   4.434 - -----------------------------------------------------------------------------*)
   4.435 -(*---------------
   4.436 -    Continuity
   4.437 - ---------------*)
   4.438 -
   4.439 -Goalw [isNSCont_def]
   4.440 -      "[| isNSCont f a; y \\<approx> hypreal_of_real a |] \
   4.441 -\           ==> ( *f* f) y \\<approx> hypreal_of_real (f a)";
   4.442 -by (Blast_tac 1);
   4.443 -qed "isNSContD";
   4.444 -
   4.445 -Goalw [isNSCont_def,NSLIM_def]
   4.446 -      "isNSCont f a ==> f -- a --NS> (f a) ";
   4.447 -by (Blast_tac 1);
   4.448 -qed "isNSCont_NSLIM";
   4.449 -
   4.450 -Goalw [isNSCont_def,NSLIM_def]
   4.451 -      "f -- a --NS> (f a) ==> isNSCont f a";
   4.452 -by Auto_tac;
   4.453 -by (res_inst_tac [("Q","y = hypreal_of_real a")]
   4.454 -    (excluded_middle RS disjE) 1);
   4.455 -by Auto_tac;
   4.456 -qed "NSLIM_isNSCont";
   4.457 -
   4.458 -(*-----------------------------------------------------
   4.459 -    NS continuity can be defined using NS Limit in
   4.460 -    similar fashion to standard def of continuity
   4.461 - -----------------------------------------------------*)
   4.462 -Goal "(isNSCont f a) = (f -- a --NS> (f a))";
   4.463 -by (blast_tac (claset() addIs [isNSCont_NSLIM,NSLIM_isNSCont]) 1);
   4.464 -qed "isNSCont_NSLIM_iff";
   4.465 -
   4.466 -(*----------------------------------------------
   4.467 -  Hence, NS continuity can be given
   4.468 -  in terms of standard limit
   4.469 - ---------------------------------------------*)
   4.470 -Goal "(isNSCont f a) = (f -- a --> (f a))";
   4.471 -by (asm_full_simp_tac (simpset() addsimps
   4.472 -    [LIM_NSLIM_iff,isNSCont_NSLIM_iff]) 1);
   4.473 -qed "isNSCont_LIM_iff";
   4.474 -
   4.475 -(*-----------------------------------------------
   4.476 -  Moreover, it's trivial now that NS continuity
   4.477 -  is equivalent to standard continuity
   4.478 - -----------------------------------------------*)
   4.479 -Goalw [isCont_def] "(isNSCont f a) = (isCont f a)";
   4.480 -by (rtac isNSCont_LIM_iff 1);
   4.481 -qed "isNSCont_isCont_iff";
   4.482 -
   4.483 -(*----------------------------------------
   4.484 -  Standard continuity ==> NS continuity
   4.485 - ----------------------------------------*)
   4.486 -Goal "isCont f a ==> isNSCont f a";
   4.487 -by (etac (isNSCont_isCont_iff RS iffD2) 1);
   4.488 -qed "isCont_isNSCont";
   4.489 -
   4.490 -(*----------------------------------------
   4.491 -  NS continuity ==> Standard continuity
   4.492 - ----------------------------------------*)
   4.493 -Goal "isNSCont f a ==> isCont f a";
   4.494 -by (etac (isNSCont_isCont_iff RS iffD1) 1);
   4.495 -qed "isNSCont_isCont";
   4.496 -
   4.497 -(*--------------------------------------------------------------------------
   4.498 -                 Alternative definition of continuity
   4.499 - --------------------------------------------------------------------------*)
   4.500 -(* Prove equivalence between NS limits - *)
   4.501 -(* seems easier than using standard def  *)
   4.502 -Goalw [NSLIM_def] "(f -- a --NS> L) = ((%h. f(a + h)) -- 0 --NS> L)";
   4.503 -by Auto_tac;
   4.504 -by (dres_inst_tac [("x","hypreal_of_real a + x")] spec 1);
   4.505 -by (dres_inst_tac [("x","-hypreal_of_real a + x")] spec 2);
   4.506 -by Safe_tac;
   4.507 -by (Asm_full_simp_tac 1);
   4.508 -by (rtac ((mem_infmal_iff RS iffD2) RS
   4.509 -    (Infinitesimal_add_approx_self RS approx_sym)) 1);
   4.510 -by (rtac (approx_minus_iff2 RS iffD1) 4);
   4.511 -by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 3);
   4.512 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 2);
   4.513 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 4);
   4.514 -by (auto_tac (claset(),
   4.515 -       simpset() addsimps [starfun, hypreal_of_real_def, hypreal_minus,
   4.516 -              hypreal_add, real_add_assoc, approx_refl, hypreal_zero_def]));
   4.517 -qed "NSLIM_h_iff";
   4.518 -
   4.519 -Goal "(f -- a --NS> f a) = ((%h. f(a + h)) -- 0 --NS> f a)";
   4.520 -by (rtac NSLIM_h_iff 1);
   4.521 -qed "NSLIM_isCont_iff";
   4.522 -
   4.523 -Goal "(f -- a --> f a) = ((%h. f(a + h)) -- 0 --> f(a))";
   4.524 -by (simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_isCont_iff]) 1);
   4.525 -qed "LIM_isCont_iff";
   4.526 -
   4.527 -Goalw [isCont_def] "(isCont f x) = ((%h. f(x + h)) -- 0 --> f(x))";
   4.528 -by (simp_tac (simpset() addsimps [LIM_isCont_iff]) 1);
   4.529 -qed "isCont_iff";
   4.530 -
   4.531 -(*--------------------------------------------------------------------------
   4.532 -   Immediate application of nonstandard criterion for continuity can offer
   4.533 -   very simple proofs of some standard property of continuous functions
   4.534 - --------------------------------------------------------------------------*)
   4.535 -(*------------------------
   4.536 -     sum continuous
   4.537 - ------------------------*)
   4.538 -Goal "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) + g(x)) a";
   4.539 -by (auto_tac (claset() addIs [approx_add],
   4.540 -              simpset() addsimps [isNSCont_isCont_iff RS sym, isNSCont_def]));
   4.541 -qed "isCont_add";
   4.542 -
   4.543 -(*------------------------
   4.544 -     mult continuous
   4.545 - ------------------------*)
   4.546 -Goal "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a";
   4.547 -by (auto_tac (claset() addSIs [starfun_mult_HFinite_approx],
   4.548 -              simpset() delsimps [starfun_mult RS sym]
   4.549 -			addsimps [isNSCont_isCont_iff RS sym, isNSCont_def]));
   4.550 -qed "isCont_mult";
   4.551 -
   4.552 -(*-------------------------------------------
   4.553 -     composition of continuous functions
   4.554 -     Note very short straightforard proof!
   4.555 - ------------------------------------------*)
   4.556 -Goal "[| isCont f a; isCont g (f a) |] \
   4.557 -\     ==> isCont (g o f) a";
   4.558 -by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
   4.559 -              isNSCont_def,starfun_o RS sym]));
   4.560 -qed "isCont_o";
   4.561 -
   4.562 -Goal "[| isCont f a; isCont g (f a) |] \
   4.563 -\     ==> isCont (%x. g (f x)) a";
   4.564 -by (auto_tac (claset() addDs [isCont_o],simpset() addsimps [o_def]));
   4.565 -qed "isCont_o2";
   4.566 -
   4.567 -Goalw [isNSCont_def] "isNSCont f a ==> isNSCont (%x. - f x) a";
   4.568 -by Auto_tac;
   4.569 -qed "isNSCont_minus";
   4.570 -
   4.571 -Goal "isCont f a ==> isCont (%x. - f x) a";
   4.572 -by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
   4.573 -              isNSCont_minus]));
   4.574 -qed "isCont_minus";
   4.575 -
   4.576 -Goalw [isCont_def]
   4.577 -      "[| isCont f x; f x \\<noteq> 0 |] ==> isCont (%x. inverse (f x)) x";
   4.578 -by (blast_tac (claset() addIs [LIM_inverse]) 1);
   4.579 -qed "isCont_inverse";
   4.580 -
   4.581 -Goal "[| isNSCont f x; f x \\<noteq> 0 |] ==> isNSCont (%x. inverse (f x)) x";
   4.582 -by (auto_tac (claset() addIs [isCont_inverse],simpset() addsimps
   4.583 -    [isNSCont_isCont_iff]));
   4.584 -qed "isNSCont_inverse";
   4.585 -
   4.586 -Goalw [real_diff_def]
   4.587 -      "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) - g(x)) a";
   4.588 -by (auto_tac (claset() addIs [isCont_add,isCont_minus],simpset()));
   4.589 -qed "isCont_diff";
   4.590 -
   4.591 -Goalw [isCont_def]  "isCont (%x. k) a";
   4.592 -by (Simp_tac 1);
   4.593 -qed "isCont_const";
   4.594 -Addsimps [isCont_const];
   4.595 -
   4.596 -Goalw [isNSCont_def]  "isNSCont (%x. k) a";
   4.597 -by (Simp_tac 1);
   4.598 -qed "isNSCont_const";
   4.599 -Addsimps [isNSCont_const];
   4.600 -
   4.601 -Goalw [isNSCont_def]  "isNSCont abs a";
   4.602 -by (auto_tac (claset() addIs [approx_hrabs],
   4.603 -              simpset() addsimps [hypreal_of_real_hrabs RS sym,
   4.604 -                                  starfun_rabs_hrabs]));
   4.605 -qed "isNSCont_rabs";
   4.606 -Addsimps [isNSCont_rabs];
   4.607 -
   4.608 -Goal "isCont abs a";
   4.609 -by (auto_tac (claset(), simpset() addsimps [isNSCont_isCont_iff RS sym]));
   4.610 -qed "isCont_rabs";
   4.611 -Addsimps [isCont_rabs];
   4.612 -
   4.613 -(****************************************************************
   4.614 -(%* Leave as commented until I add topology theory or remove? *%)
   4.615 -(%*------------------------------------------------------------
   4.616 -  Elementary topology proof for a characterisation of
   4.617 -  continuity now: a function f is continuous if and only
   4.618 -  if the inverse image, {x. f(x) \\<in> A}, of any open set A
   4.619 -  is always an open set
   4.620 - ------------------------------------------------------------*%)
   4.621 -Goal "[| isNSopen A; \\<forall>x. isNSCont f x |] \
   4.622 -\              ==> isNSopen {x. f x \\<in> A}";
   4.623 -by (auto_tac (claset(),simpset() addsimps [isNSopen_iff1]));
   4.624 -by (dtac (mem_monad_approx RS approx_sym) 1);
   4.625 -by (dres_inst_tac [("x","a")] spec 1);
   4.626 -by (dtac isNSContD 1 THEN assume_tac 1);
   4.627 -by (dtac bspec 1 THEN assume_tac 1);
   4.628 -by (dres_inst_tac [("x","( *f* f) x")] approx_mem_monad2 1);
   4.629 -by (blast_tac (claset() addIs [starfun_mem_starset]) 1);
   4.630 -qed "isNSCont_isNSopen";
   4.631 -
   4.632 -Goalw [isNSCont_def]
   4.633 -          "\\<forall>A. isNSopen A --> isNSopen {x. f x \\<in> A} \
   4.634 -\              ==> isNSCont f x";
   4.635 -by (auto_tac (claset() addSIs [(mem_infmal_iff RS iffD1) RS
   4.636 -     (approx_minus_iff RS iffD2)],simpset() addsimps
   4.637 -      [Infinitesimal_def,SReal_iff]));
   4.638 -by (dres_inst_tac [("x","{z. abs(z + -f(x)) < ya}")] spec 1);
   4.639 -by (etac (isNSopen_open_interval RSN (2,impE)) 1);
   4.640 -by (auto_tac (claset(),simpset() addsimps [isNSopen_def,isNSnbhd_def]));
   4.641 -by (dres_inst_tac [("x","x")] spec 1);
   4.642 -by (auto_tac (claset() addDs [approx_sym RS approx_mem_monad],
   4.643 -    simpset() addsimps [hypreal_of_real_zero RS sym,STAR_starfun_rabs_add_minus]));
   4.644 -qed "isNSopen_isNSCont";
   4.645 -
   4.646 -Goal "(\\<forall>x. isNSCont f x) = \
   4.647 -\     (\\<forall>A. isNSopen A --> isNSopen {x. f(x) \\<in> A})";
   4.648 -by (blast_tac (claset() addIs [isNSCont_isNSopen,
   4.649 -    isNSopen_isNSCont]) 1);
   4.650 -qed "isNSCont_isNSopen_iff";
   4.651 -
   4.652 -(%*------- Standard version of same theorem --------*%)
   4.653 -Goal "(\\<forall>x. isCont f x) = \
   4.654 -\         (\\<forall>A. isopen A --> isopen {x. f(x) \\<in> A})";
   4.655 -by (auto_tac (claset() addSIs [isNSCont_isNSopen_iff],
   4.656 -              simpset() addsimps [isNSopen_isopen_iff RS sym,
   4.657 -              isNSCont_isCont_iff RS sym]));
   4.658 -qed "isCont_isopen_iff";
   4.659 -*******************************************************************)
   4.660 -
   4.661 -(*-----------------------------------------------------------------
   4.662 -                        Uniform continuity
   4.663 - ------------------------------------------------------------------*)
   4.664 -Goalw [isNSUCont_def]
   4.665 -      "[| isNSUCont f; x \\<approx> y|] ==> ( *f* f) x \\<approx> ( *f* f) y";
   4.666 -by (Blast_tac 1);
   4.667 -qed "isNSUContD";
   4.668 -
   4.669 -Goalw [isUCont_def,isCont_def,LIM_def]
   4.670 -     "isUCont f ==> isCont f x";
   4.671 -by (Clarify_tac 1);
   4.672 -by (dtac spec 1);
   4.673 -by (Blast_tac 1);
   4.674 -qed "isUCont_isCont";
   4.675 -
   4.676 -Goalw [isNSUCont_def,isUCont_def,approx_def]
   4.677 -     "isUCont f ==> isNSUCont f";
   4.678 -by (asm_full_simp_tac (simpset() addsimps
   4.679 -    [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   4.680 -by Safe_tac;
   4.681 -by (res_inst_tac [("z","x")] eq_Abs_hypreal 1);
   4.682 -by (res_inst_tac [("z","y")] eq_Abs_hypreal 1);
   4.683 -by (auto_tac (claset(),simpset() addsimps [starfun,
   4.684 -    hypreal_minus, hypreal_add]));
   4.685 -by (rtac bexI 1 THEN rtac lemma_hyprel_refl 2 THEN Step_tac 1);
   4.686 -by (dres_inst_tac [("x","u")] spec 1 THEN Clarify_tac 1);
   4.687 -by (dres_inst_tac [("x","s")] spec 1 THEN Clarify_tac 1);
   4.688 -by (subgoal_tac "\\<forall>n::nat. abs ((xa n) + - (xb n)) < s --> abs (f (xa n) + - f (xb n)) < u" 1);
   4.689 -by (Blast_tac 2);
   4.690 -by (thin_tac "\\<forall>x y. abs (x + - y) < s --> abs (f x + - f y) < u" 1);
   4.691 -by (dtac FreeUltrafilterNat_all 1);
   4.692 -by (Ultra_tac 1);
   4.693 -qed "isUCont_isNSUCont";
   4.694 -
   4.695 -Goal "\\<forall>s. 0 < s --> (\\<exists>z y. abs (z + - y) < s & r \\<le> abs (f z + -f y)) \
   4.696 -\     ==> \\<forall>n::nat. \\<exists>z y.  \
   4.697 -\              abs(z + -y) < inverse(real(Suc n)) & \
   4.698 -\              r \\<le> abs(f z + -f y)";
   4.699 -by (Clarify_tac 1);
   4.700 -by (cut_inst_tac [("n1","n")]
   4.701 -    (real_of_nat_Suc_gt_zero RS positive_imp_inverse_positive) 1);
   4.702 -by Auto_tac;
   4.703 -qed "lemma_LIMu";
   4.704 -
   4.705 -Goal "\\<forall>s. 0 < s --> (\\<exists>z y. abs (z + - y) < s  & r \\<le> abs (f z + -f y)) \
   4.706 -\     ==> \\<exists>X Y. \\<forall>n::nat. \
   4.707 -\              abs(X n + -(Y n)) < inverse(real(Suc n)) & \
   4.708 -\              r \\<le> abs(f (X n) + -f (Y n))";
   4.709 -by (dtac lemma_LIMu 1);
   4.710 -by (dtac choice 1);
   4.711 -by Safe_tac;
   4.712 -by (dtac choice 1);
   4.713 -by (Blast_tac 1);
   4.714 -qed "lemma_skolemize_LIM2u";
   4.715 -
   4.716 -Goal "\\<forall>n. abs (X n + -Y n) < inverse (real(Suc n)) & \
   4.717 -\         r \\<le> abs (f (X n) + - f(Y n)) ==> \
   4.718 -\         \\<forall>n. abs (X n + - Y n) < inverse (real(Suc n))";
   4.719 -by (Auto_tac );
   4.720 -qed "lemma_simpu";
   4.721 -
   4.722 -Goalw [isNSUCont_def,isUCont_def,approx_def]
   4.723 -     "isNSUCont f ==> isUCont f";
   4.724 -by (asm_full_simp_tac (simpset() addsimps
   4.725 -                       [Infinitesimal_FreeUltrafilterNat_iff]) 1);
   4.726 -by (EVERY1[Step_tac, rtac ccontr, Asm_full_simp_tac]);
   4.727 -by (asm_full_simp_tac (simpset() addsimps [linorder_not_less]) 1);
   4.728 -by (dtac lemma_skolemize_LIM2u 1);
   4.729 -by Safe_tac;
   4.730 -by (dres_inst_tac [("x","Abs_hypreal(hyprel``{X})")] spec 1);
   4.731 -by (dres_inst_tac [("x","Abs_hypreal(hyprel``{Y})")] spec 1);
   4.732 -by (asm_full_simp_tac
   4.733 -    (simpset() addsimps [starfun, hypreal_minus,hypreal_add]) 1);
   4.734 -by Auto_tac;
   4.735 -by (dtac (lemma_simpu RS real_seq_to_hypreal_Infinitesimal2) 1);
   4.736 -by (asm_full_simp_tac (simpset() addsimps
   4.737 -     [Infinitesimal_FreeUltrafilterNat_iff, hypreal_minus,hypreal_add]) 1);
   4.738 -by (Blast_tac 1);
   4.739 -by (rotate_tac 2 1);
   4.740 -by (dres_inst_tac [("x","r")] spec 1);
   4.741 -by (Clarify_tac 1);
   4.742 -by (dtac FreeUltrafilterNat_all 1);
   4.743 -by (Ultra_tac 1);
   4.744 -qed "isNSUCont_isUCont";
   4.745 -
   4.746 -(*------------------------------------------------------------------
   4.747 -                         Derivatives
   4.748 - ------------------------------------------------------------------*)
   4.749 -Goalw [deriv_def]
   4.750 -      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --> D)";
   4.751 -by (Blast_tac 1);
   4.752 -qed "DERIV_iff";
   4.753 -
   4.754 -Goalw [deriv_def]
   4.755 -      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --NS> D)";
   4.756 -by (simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   4.757 -qed "DERIV_NS_iff";
   4.758 -
   4.759 -Goalw [deriv_def]
   4.760 -      "DERIV f x :> D \
   4.761 -\      ==> (%h. (f(x + h) + - f(x))/h) -- 0 --> D";
   4.762 -by (Blast_tac 1);
   4.763 -qed "DERIVD";
   4.764 -
   4.765 -Goalw [deriv_def] "DERIV f x :> D ==> \
   4.766 -\          (%h. (f(x + h) + - f(x))/h) -- 0 --NS> D";
   4.767 -by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   4.768 -qed "NS_DERIVD";
   4.769 -
   4.770 -(* Uniqueness *)
   4.771 -Goalw [deriv_def]
   4.772 -      "[| DERIV f x :> D; DERIV f x :> E |] ==> D = E";
   4.773 -by (blast_tac (claset() addIs [LIM_unique]) 1);
   4.774 -qed "DERIV_unique";
   4.775 -
   4.776 -Goalw [nsderiv_def]
   4.777 -     "[| NSDERIV f x :> D; NSDERIV f x :> E |] ==> D = E";
   4.778 -by (cut_facts_tac [Infinitesimal_epsilon, hypreal_epsilon_not_zero] 1);
   4.779 -by (auto_tac (claset() addSDs [inst "x" "epsilon" bspec]
   4.780 -                       addSIs [inj_hypreal_of_real RS injD]
   4.781 -                       addDs [approx_trans3],
   4.782 -              simpset()));
   4.783 -qed "NSDeriv_unique";
   4.784 -
   4.785 -(*------------------------------------------------------------------------
   4.786 -                          Differentiable
   4.787 - ------------------------------------------------------------------------*)
   4.788 -
   4.789 -Goalw [differentiable_def]
   4.790 -      "f differentiable x ==> \\<exists>D. DERIV f x :> D";
   4.791 -by (assume_tac 1);
   4.792 -qed "differentiableD";
   4.793 -
   4.794 -Goalw [differentiable_def]
   4.795 -      "DERIV f x :> D ==> f differentiable x";
   4.796 -by (Blast_tac 1);
   4.797 -qed "differentiableI";
   4.798 -
   4.799 -Goalw [NSdifferentiable_def]
   4.800 -      "f NSdifferentiable x ==> \\<exists>D. NSDERIV f x :> D";
   4.801 -by (assume_tac 1);
   4.802 -qed "NSdifferentiableD";
   4.803 -
   4.804 -Goalw [NSdifferentiable_def]
   4.805 -      "NSDERIV f x :> D ==> f NSdifferentiable x";
   4.806 -by (Blast_tac 1);
   4.807 -qed "NSdifferentiableI";
   4.808 -
   4.809 -(*--------------------------------------------------------
   4.810 -      Alternative definition for differentiability
   4.811 - -------------------------------------------------------*)
   4.812 -
   4.813 -Goalw [LIM_def]
   4.814 - "((%h. (f(a + h) + - f(a))/h) -- 0 --> D) = \
   4.815 -\ ((%x. (f(x) + -f(a)) / (x + -a)) -- a --> D)";
   4.816 -by Safe_tac;
   4.817 -by (ALLGOALS(dtac spec));
   4.818 -by Safe_tac;
   4.819 -by (Blast_tac 1 THEN Blast_tac 2);
   4.820 -by (ALLGOALS(res_inst_tac [("x","s")] exI));
   4.821 -by Safe_tac;
   4.822 -by (dres_inst_tac [("x","x + -a")] spec 1);
   4.823 -by (dres_inst_tac [("x","x + a")] spec 2);
   4.824 -by (auto_tac (claset(), simpset() addsimps add_ac));
   4.825 -qed "DERIV_LIM_iff";
   4.826 -
   4.827 -Goalw [deriv_def] "(DERIV f x :> D) = \
   4.828 -\         ((%z. (f(z) + -f(x)) / (z + -x)) -- x --> D)";
   4.829 -by (simp_tac (simpset() addsimps [DERIV_LIM_iff]) 1);
   4.830 -qed "DERIV_iff2";
   4.831 -
   4.832 -(*--------------------------------------------------------
   4.833 -  Equivalence of NS and standard defs of differentiation
   4.834 - -------------------------------------------------------*)
   4.835 -(*-------------------------------------------
   4.836 -   First NSDERIV in terms of NSLIM
   4.837 - -------------------------------------------*)
   4.838 -
   4.839 -(*--- first equivalence ---*)
   4.840 -Goalw [nsderiv_def,NSLIM_def]
   4.841 -      "(NSDERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --NS> D)";
   4.842 -by Auto_tac;
   4.843 -by (dres_inst_tac [("x","xa")] bspec 1);
   4.844 -by (rtac ccontr 3);
   4.845 -by (dres_inst_tac [("x","h")] spec 3);
   4.846 -by (auto_tac (claset(),
   4.847 -              simpset() addsimps [mem_infmal_iff, starfun_lambda_cancel]));
   4.848 -qed "NSDERIV_NSLIM_iff";
   4.849 -
   4.850 -(*--- second equivalence ---*)
   4.851 -Goal "(NSDERIV f x :> D) = \
   4.852 -\         ((%z. (f(z) + -f(x)) / (z + -x)) -- x --NS> D)";
   4.853 -by (full_simp_tac (simpset() addsimps
   4.854 -     [NSDERIV_NSLIM_iff, DERIV_LIM_iff, LIM_NSLIM_iff RS sym]) 1);
   4.855 -qed "NSDERIV_NSLIM_iff2";
   4.856 -
   4.857 -(* while we're at it! *)
   4.858 -Goalw [real_diff_def]
   4.859 -     "(NSDERIV f x :> D) = \
   4.860 -\     (\\<forall>xa. \
   4.861 -\       xa \\<noteq> hypreal_of_real x & xa \\<approx> hypreal_of_real x --> \
   4.862 -\       ( *f* (%z. (f z - f x) / (z - x))) xa \\<approx> hypreal_of_real D)";
   4.863 -by (auto_tac (claset(), simpset() addsimps [NSDERIV_NSLIM_iff2, NSLIM_def]));
   4.864 -qed "NSDERIV_iff2";
   4.865 -
   4.866 -
   4.867 -Goal "(NSDERIV f x :> D) ==> \
   4.868 -\    (\\<forall>u. \
   4.869 -\       u \\<approx> hypreal_of_real x --> \
   4.870 -\       ( *f* (%z. f z - f x)) u \\<approx> hypreal_of_real D * (u - hypreal_of_real x))";
   4.871 -by (auto_tac (claset(), simpset() addsimps [NSDERIV_iff2]));
   4.872 -by (case_tac "u = hypreal_of_real x" 1);
   4.873 -by (auto_tac (claset(), simpset() addsimps [hypreal_diff_def]));
   4.874 -by (dres_inst_tac [("x","u")] spec 1);
   4.875 -by Auto_tac;
   4.876 -by (dres_inst_tac [("c","u - hypreal_of_real x"),("b","hypreal_of_real D")]
   4.877 -     approx_mult1 1);
   4.878 -by (ALLGOALS(dtac (hypreal_not_eq_minus_iff RS iffD1)));
   4.879 -by (subgoal_tac "( *f* (%z. z - x)) u \\<noteq> (0::hypreal)" 2);
   4.880 -by (auto_tac (claset(),
   4.881 -    simpset() addsimps [real_diff_def, hypreal_diff_def,
   4.882 -		(approx_minus_iff RS iffD1) RS (mem_infmal_iff RS iffD2),
   4.883 -			Infinitesimal_subset_HFinite RS subsetD]));
   4.884 -qed "NSDERIVD5";
   4.885 -
   4.886 -Goal "(NSDERIV f x :> D) ==> \
   4.887 -\     (\\<forall>h \\<in> Infinitesimal. \
   4.888 -\              (( *f* f)(hypreal_of_real x + h) - \
   4.889 -\                hypreal_of_real (f x))\\<approx> (hypreal_of_real D) * h)";
   4.890 -by (auto_tac (claset(),simpset() addsimps [nsderiv_def]));
   4.891 -by (case_tac "h = (0::hypreal)" 1);
   4.892 -by (auto_tac (claset(),simpset() addsimps [hypreal_diff_def]));
   4.893 -by (dres_inst_tac [("x","h")] bspec 1);
   4.894 -by (dres_inst_tac [("c","h")] approx_mult1 2);
   4.895 -by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
   4.896 -              simpset() addsimps [hypreal_diff_def]));
   4.897 -qed "NSDERIVD4";
   4.898 -
   4.899 -Goal "(NSDERIV f x :> D) ==> \
   4.900 -\     (\\<forall>h \\<in> Infinitesimal - {0}. \
   4.901 -\              (( *f* f)(hypreal_of_real x + h) - \
   4.902 -\                hypreal_of_real (f x))\\<approx> (hypreal_of_real D) * h)";
   4.903 -by (auto_tac (claset(),simpset() addsimps [nsderiv_def]));
   4.904 -by (rtac ccontr 1 THEN dres_inst_tac [("x","h")] bspec 1);
   4.905 -by (dres_inst_tac [("c","h")] approx_mult1 2);
   4.906 -by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite RS subsetD],
   4.907 -              simpset() addsimps [hypreal_mult_assoc, hypreal_diff_def]));
   4.908 -qed "NSDERIVD3";
   4.909 -
   4.910 -(*--------------------------------------------------------------
   4.911 -          Now equivalence between NSDERIV and DERIV
   4.912 - -------------------------------------------------------------*)
   4.913 -Goalw [deriv_def] "(NSDERIV f x :> D) = (DERIV f x :> D)";
   4.914 -by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,LIM_NSLIM_iff]) 1);
   4.915 -qed "NSDERIV_DERIV_iff";
   4.916 -
   4.917 -(*---------------------------------------------------
   4.918 -         Differentiability implies continuity
   4.919 -         nice and simple "algebraic" proof
   4.920 - --------------------------------------------------*)
   4.921 -Goalw [nsderiv_def]
   4.922 -      "NSDERIV f x :> D ==> isNSCont f x";
   4.923 -by (auto_tac (claset(),simpset() addsimps
   4.924 -        [isNSCont_NSLIM_iff,NSLIM_def]));
   4.925 -by (dtac (approx_minus_iff RS iffD1) 1);
   4.926 -by (dtac (hypreal_not_eq_minus_iff RS iffD1) 1);
   4.927 -by (dres_inst_tac [("x","-hypreal_of_real x + xa")] bspec 1);
   4.928 -by (asm_full_simp_tac (simpset() addsimps
   4.929 -    [hypreal_add_assoc RS sym]) 2);
   4.930 -by (auto_tac (claset(),simpset() addsimps
   4.931 -    [mem_infmal_iff RS sym,hypreal_add_commute]));
   4.932 -by (dres_inst_tac [("c","xa + -hypreal_of_real x")] approx_mult1 1);
   4.933 -by (auto_tac (claset() addIs [Infinitesimal_subset_HFinite
   4.934 -    RS subsetD],simpset() addsimps [hypreal_mult_assoc]));
   4.935 -by (dres_inst_tac [("x3","D")] (HFinite_hypreal_of_real RSN
   4.936 -    (2,Infinitesimal_HFinite_mult) RS (mem_infmal_iff RS iffD1)) 1);
   4.937 -by (blast_tac (claset() addIs [approx_trans,
   4.938 -    hypreal_mult_commute RS subst,
   4.939 -    (approx_minus_iff RS iffD2)]) 1);
   4.940 -qed "NSDERIV_isNSCont";
   4.941 -
   4.942 -(* Now Sandard proof *)
   4.943 -Goal "DERIV f x :> D ==> isCont f x";
   4.944 -by (asm_full_simp_tac (simpset() addsimps
   4.945 -    [NSDERIV_DERIV_iff RS sym, isNSCont_isCont_iff RS sym,
   4.946 -     NSDERIV_isNSCont]) 1);
   4.947 -qed "DERIV_isCont";
   4.948 -
   4.949 -(*----------------------------------------------------------------------------
   4.950 -      Differentiation rules for combinations of functions
   4.951 -      follow from clear, straightforard, algebraic
   4.952 -      manipulations
   4.953 - ----------------------------------------------------------------------------*)
   4.954 -(*-------------------------
   4.955 -    Constant function
   4.956 - ------------------------*)
   4.957 -
   4.958 -(* use simple constant nslimit theorem *)
   4.959 -Goal "(NSDERIV (%x. k) x :> 0)";
   4.960 -by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
   4.961 -qed "NSDERIV_const";
   4.962 -Addsimps [NSDERIV_const];
   4.963 -
   4.964 -Goal "(DERIV (%x. k) x :> 0)";
   4.965 -by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
   4.966 -qed "DERIV_const";
   4.967 -Addsimps [DERIV_const];
   4.968 -
   4.969 -(*-----------------------------------------------------
   4.970 -    Sum of functions- proved easily
   4.971 - ----------------------------------------------------*)
   4.972 -
   4.973 -
   4.974 -Goal "[| NSDERIV f x :> Da;  NSDERIV g x :> Db |] \
   4.975 -\     ==> NSDERIV (%x. f x + g x) x :> Da + Db";
   4.976 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
   4.977 -           NSLIM_def]) 1 THEN REPEAT (Step_tac 1));
   4.978 -by (auto_tac (claset(),
   4.979 -       simpset() addsimps [add_divide_distrib]));
   4.980 -by (dres_inst_tac [("b","hypreal_of_real Da"),
   4.981 -                   ("d","hypreal_of_real Db")] approx_add 1);
   4.982 -by (auto_tac (claset(), simpset() addsimps add_ac));
   4.983 -qed "NSDERIV_add";
   4.984 -
   4.985 -(* Standard theorem *)
   4.986 -Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
   4.987 -\     ==> DERIV (%x. f x + g x) x :> Da + Db";
   4.988 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_add,
   4.989 -                                     NSDERIV_DERIV_iff RS sym]) 1);
   4.990 -qed "DERIV_add";
   4.991 -
   4.992 -(*-----------------------------------------------------
   4.993 -  Product of functions - Proof is trivial but tedious
   4.994 -  and long due to rearrangement of terms
   4.995 - ----------------------------------------------------*)
   4.996 -
   4.997 -Goal "((a::hypreal)*b) + -(c*d) = (b*(a + -c)) + (c*(b + -d))";
   4.998 -by (simp_tac (simpset() addsimps [right_distrib]) 1);
   4.999 -qed "lemma_nsderiv1";
  4.1000 -
  4.1001 -Goal "[| (x + y) / z = hypreal_of_real D + yb; z \\<noteq> 0; \
  4.1002 -\        z \\<in> Infinitesimal; yb \\<in> Infinitesimal |] \
  4.1003 -\     ==> x + y \\<approx> 0";
  4.1004 -by (forw_inst_tac [("c1","z")] (hypreal_mult_right_cancel RS iffD2) 1
  4.1005 -    THEN assume_tac 1);
  4.1006 -by (thin_tac "(x + y) / z = hypreal_of_real D + yb" 1);
  4.1007 -by (auto_tac (claset() addSIs [Infinitesimal_HFinite_mult2, HFinite_add],
  4.1008 -              simpset() addsimps [hypreal_mult_assoc, mem_infmal_iff RS sym]));
  4.1009 -by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
  4.1010 -qed "lemma_nsderiv2";
  4.1011 -
  4.1012 -
  4.1013 -Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  4.1014 -\     ==> NSDERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))";
  4.1015 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def]) 1);
  4.1016 -by (REPEAT (Step_tac 1));
  4.1017 -by (auto_tac (claset(),
  4.1018 -       simpset() addsimps [starfun_lambda_cancel, lemma_nsderiv1]));
  4.1019 -by (simp_tac (simpset() addsimps [add_divide_distrib]) 1);
  4.1020 -by (REPEAT(dtac (bex_Infinitesimal_iff2 RS iffD2) 1));
  4.1021 -by (auto_tac (claset(),
  4.1022 -        simpset() delsimps [times_divide_eq_right]
  4.1023 -		  addsimps [times_divide_eq_right RS sym]));
  4.1024 -by (dres_inst_tac [("D","Db")] lemma_nsderiv2 1);
  4.1025 -by (dtac (approx_minus_iff RS iffD2 RS (bex_Infinitesimal_iff2 RS iffD2)) 4);
  4.1026 -by (auto_tac (claset() addSIs [approx_add_mono1],
  4.1027 -      simpset() addsimps [left_distrib, right_distrib,
  4.1028 -			  hypreal_mult_commute, hypreal_add_assoc]));
  4.1029 -by (res_inst_tac [("w1","hypreal_of_real Db * hypreal_of_real (f x)")]
  4.1030 -    (hypreal_add_commute RS subst) 1);
  4.1031 -by (auto_tac (claset() addSIs [Infinitesimal_add_approx_self2 RS approx_sym,
  4.1032 -			       Infinitesimal_add, Infinitesimal_mult,
  4.1033 -			       Infinitesimal_hypreal_of_real_mult,
  4.1034 -			       Infinitesimal_hypreal_of_real_mult2],
  4.1035 -	      simpset() addsimps [hypreal_add_assoc RS sym]));
  4.1036 -qed "NSDERIV_mult";
  4.1037 -
  4.1038 -Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
  4.1039 -\     ==> DERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))";
  4.1040 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_mult,
  4.1041 -                                           NSDERIV_DERIV_iff RS sym]) 1);
  4.1042 -qed "DERIV_mult";
  4.1043 -
  4.1044 -(*----------------------------
  4.1045 -   Multiplying by a constant
  4.1046 - ---------------------------*)
  4.1047 -Goal "NSDERIV f x :> D \
  4.1048 -\     ==> NSDERIV (%x. c * f x) x :> c*D";
  4.1049 -by (asm_full_simp_tac
  4.1050 -    (HOL_ss addsimps [times_divide_eq_right RS sym, NSDERIV_NSLIM_iff,
  4.1051 -                      minus_mult_right, right_distrib RS sym]) 1);
  4.1052 -by (etac (NSLIM_const RS NSLIM_mult) 1);
  4.1053 -qed "NSDERIV_cmult";
  4.1054 -
  4.1055 -(* let's do the standard proof though theorem *)
  4.1056 -(* LIM_mult2 follows from a NS proof          *)
  4.1057 -
  4.1058 -Goalw [deriv_def]
  4.1059 -      "DERIV f x :> D \
  4.1060 -\      ==> DERIV (%x. c * f x) x :> c*D";
  4.1061 -by (asm_full_simp_tac
  4.1062 -    (HOL_ss addsimps [times_divide_eq_right RS sym, NSDERIV_NSLIM_iff,
  4.1063 -                      minus_mult_right, right_distrib RS sym]) 1);
  4.1064 -by (etac (LIM_const RS LIM_mult2) 1);
  4.1065 -qed "DERIV_cmult";
  4.1066 -
  4.1067 -(*--------------------------------
  4.1068 -   Negation of function
  4.1069 - -------------------------------*)
  4.1070 -Goal "NSDERIV f x :> D ==> NSDERIV (%x. -(f x)) x :> -D";
  4.1071 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
  4.1072 -by (dtac NSLIM_minus 1);
  4.1073 -by (subgoal_tac "ALL a::real. ALL b. - a + b = - (a + - b)" 1);
  4.1074 -by (asm_full_simp_tac (HOL_ss addsimps [thm"minus_divide_left" RS sym]) 1);
  4.1075 -by (Asm_full_simp_tac 1);
  4.1076 -qed "NSDERIV_minus";
  4.1077 -
  4.1078 -Goal "DERIV f x :> D \
  4.1079 -\     ==> DERIV (%x. -(f x)) x :> -D";
  4.1080 -by (asm_full_simp_tac (simpset() addsimps
  4.1081 -    [NSDERIV_minus,NSDERIV_DERIV_iff RS sym]) 1);
  4.1082 -qed "DERIV_minus";
  4.1083 -
  4.1084 -(*-------------------------------
  4.1085 -   Subtraction
  4.1086 - ------------------------------*)
  4.1087 -Goal "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  4.1088 -\     ==> NSDERIV (%x. f x + -g x) x :> Da + -Db";
  4.1089 -by (blast_tac (claset() addDs [NSDERIV_add,NSDERIV_minus]) 1);
  4.1090 -qed "NSDERIV_add_minus";
  4.1091 -
  4.1092 -Goal "[| DERIV f x :> Da; DERIV g x :> Db |] \
  4.1093 -\     ==> DERIV (%x. f x + -g x) x :> Da + -Db";
  4.1094 -by (blast_tac (claset() addDs [DERIV_add,DERIV_minus]) 1);
  4.1095 -qed "DERIV_add_minus";
  4.1096 -
  4.1097 -Goalw [real_diff_def]
  4.1098 -     "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] \
  4.1099 -\     ==> NSDERIV (%x. f x - g x) x :> Da - Db";
  4.1100 -by (blast_tac (claset() addIs [NSDERIV_add_minus]) 1);
  4.1101 -qed "NSDERIV_diff";
  4.1102 -
  4.1103 -Goalw [real_diff_def]
  4.1104 -     "[| DERIV f x :> Da; DERIV g x :> Db |] \
  4.1105 -\      ==> DERIV (%x. f x - g x) x :> Da - Db";
  4.1106 -by (blast_tac (claset() addIs [DERIV_add_minus]) 1);
  4.1107 -qed "DERIV_diff";
  4.1108 -
  4.1109 -(*---------------------------------------------------------------
  4.1110 -                     (NS) Increment
  4.1111 - ---------------------------------------------------------------*)
  4.1112 -Goalw [increment_def]
  4.1113 -      "f NSdifferentiable x ==> \
  4.1114 -\     increment f x h = ( *f* f) (hypreal_of_real(x) + h) + \
  4.1115 -\     -hypreal_of_real (f x)";
  4.1116 -by (Blast_tac 1);
  4.1117 -qed "incrementI";
  4.1118 -
  4.1119 -Goal "NSDERIV f x :> D ==> \
  4.1120 -\    increment f x h = ( *f* f) (hypreal_of_real(x) + h) + \
  4.1121 -\    -hypreal_of_real (f x)";
  4.1122 -by (etac (NSdifferentiableI RS incrementI) 1);
  4.1123 -qed "incrementI2";
  4.1124 -
  4.1125 -(* The Increment theorem -- Keisler p. 65 *)
  4.1126 -Goal "[| NSDERIV f x :> D; h \\<in> Infinitesimal; h \\<noteq> 0 |] \
  4.1127 -\     ==> \\<exists>e \\<in> Infinitesimal. increment f x h = hypreal_of_real(D)*h + e*h";
  4.1128 -by (forw_inst_tac [("h","h")] incrementI2 1 THEN rewtac nsderiv_def);
  4.1129 -by (dtac bspec 1 THEN Auto_tac);
  4.1130 -by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1 THEN Step_tac 1);
  4.1131 -by (forw_inst_tac [("b1","hypreal_of_real(D) + y")]
  4.1132 -    ((hypreal_mult_right_cancel RS iffD2)) 1);
  4.1133 -by (thin_tac "(( *f* f) (hypreal_of_real(x) + h) + \
  4.1134 -\   - hypreal_of_real (f x)) / h = hypreal_of_real(D) + y" 2);
  4.1135 -by (assume_tac 1);
  4.1136 -by (asm_full_simp_tac (simpset() addsimps [times_divide_eq_right RS sym]
  4.1137 -             delsimps [times_divide_eq_right]) 1);
  4.1138 -by (auto_tac (claset(),
  4.1139 -              simpset() addsimps [left_distrib]));
  4.1140 -qed "increment_thm";
  4.1141 -
  4.1142 -Goal "[| NSDERIV f x :> D; h \\<approx> 0; h \\<noteq> 0 |] \
  4.1143 -\     ==> \\<exists>e \\<in> Infinitesimal. increment f x h = \
  4.1144 -\             hypreal_of_real(D)*h + e*h";
  4.1145 -by (blast_tac (claset() addSDs [mem_infmal_iff RS iffD2]
  4.1146 -                        addSIs [increment_thm]) 1);
  4.1147 -qed "increment_thm2";
  4.1148 -
  4.1149 -Goal "[| NSDERIV f x :> D; h \\<approx> 0; h \\<noteq> 0 |] \
  4.1150 -\     ==> increment f x h \\<approx> 0";
  4.1151 -by (dtac increment_thm2 1 THEN auto_tac (claset() addSIs
  4.1152 -    [Infinitesimal_HFinite_mult2,HFinite_add],simpset() addsimps
  4.1153 -    [left_distrib RS sym,mem_infmal_iff RS sym]));
  4.1154 -by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
  4.1155 -qed "increment_approx_zero";
  4.1156 -
  4.1157 -(*---------------------------------------------------------------
  4.1158 -   Similarly to the above, the chain rule admits an entirely
  4.1159 -   straightforward derivation. Compare this with Harrison's
  4.1160 -   HOL proof of the chain rule, which proved to be trickier and
  4.1161 -   required an alternative characterisation of differentiability-
  4.1162 -   the so-called Carathedory derivative. Our main problem is
  4.1163 -   manipulation of terms.
  4.1164 - --------------------------------------------------------------*)
  4.1165 -
  4.1166 -(* lemmas *)
  4.1167 -Goalw [nsderiv_def]
  4.1168 -      "[| NSDERIV g x :> D; \
  4.1169 -\              ( *f* g) (hypreal_of_real(x) + xa) = hypreal_of_real(g x);\
  4.1170 -\              xa \\<in> Infinitesimal;\
  4.1171 -\              xa \\<noteq> 0 \
  4.1172 -\           |] ==> D = 0";
  4.1173 -by (dtac bspec 1);
  4.1174 -by Auto_tac;
  4.1175 -qed "NSDERIV_zero";
  4.1176 -
  4.1177 -(* can be proved differently using NSLIM_isCont_iff *)
  4.1178 -Goalw [nsderiv_def]
  4.1179 -     "[| NSDERIV f x :> D;  h \\<in> Infinitesimal;  h \\<noteq> 0 |]  \
  4.1180 -\     ==> ( *f* f) (hypreal_of_real(x) + h) + -hypreal_of_real(f x) \\<approx> 0";
  4.1181 -by (asm_full_simp_tac (simpset() addsimps
  4.1182 -    [mem_infmal_iff RS sym]) 1);
  4.1183 -by (rtac Infinitesimal_ratio 1);
  4.1184 -by (rtac approx_hypreal_of_real_HFinite 3);
  4.1185 -by Auto_tac;
  4.1186 -qed "NSDERIV_approx";
  4.1187 -
  4.1188 -(*---------------------------------------------------------------
  4.1189 -   from one version of differentiability
  4.1190 -
  4.1191 -                f(x) - f(a)
  4.1192 -              --------------- \\<approx> Db
  4.1193 -                  x - a
  4.1194 - ---------------------------------------------------------------*)
  4.1195 -Goal "[| NSDERIV f (g x) :> Da; \
  4.1196 -\        ( *f* g) (hypreal_of_real(x) + xa) \\<noteq> hypreal_of_real (g x); \
  4.1197 -\        ( *f* g) (hypreal_of_real(x) + xa) \\<approx> hypreal_of_real (g x) \
  4.1198 -\     |] ==> (( *f* f) (( *f* g) (hypreal_of_real(x) + xa)) \
  4.1199 -\                  + - hypreal_of_real (f (g x))) \
  4.1200 -\             / (( *f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real (g x)) \
  4.1201 -\            \\<approx> hypreal_of_real(Da)";
  4.1202 -by (auto_tac (claset(),
  4.1203 -       simpset() addsimps [NSDERIV_NSLIM_iff2, NSLIM_def]));
  4.1204 -qed "NSDERIVD1";
  4.1205 -
  4.1206 -(*--------------------------------------------------------------
  4.1207 -   from other version of differentiability
  4.1208 -
  4.1209 -                f(x + h) - f(x)
  4.1210 -               ----------------- \\<approx> Db
  4.1211 -                       h
  4.1212 - --------------------------------------------------------------*)
  4.1213 -Goal "[| NSDERIV g x :> Db; xa \\<in> Infinitesimal; xa \\<noteq> 0 |] \
  4.1214 -\     ==> (( *f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real(g x)) / xa \
  4.1215 -\         \\<approx> hypreal_of_real(Db)";
  4.1216 -by (auto_tac (claset(),
  4.1217 -    simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def,
  4.1218 -		        mem_infmal_iff, starfun_lambda_cancel]));
  4.1219 -qed "NSDERIVD2";
  4.1220 -
  4.1221 -Goal "(z::hypreal) \\<noteq> 0 ==> x*y = (x*inverse(z))*(z*y)";
  4.1222 -by Auto_tac;
  4.1223 -qed "lemma_chain";
  4.1224 -
  4.1225 -(*------------------------------------------------------
  4.1226 -  This proof uses both definitions of differentiability.
  4.1227 - ------------------------------------------------------*)
  4.1228 -Goal "[| NSDERIV f (g x) :> Da; NSDERIV g x :> Db |] \
  4.1229 -\     ==> NSDERIV (f o g) x :> Da * Db";
  4.1230 -by (asm_simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff,
  4.1231 -    NSLIM_def,mem_infmal_iff RS sym]) 1 THEN Step_tac 1);
  4.1232 -by (forw_inst_tac [("f","g")] NSDERIV_approx 1);
  4.1233 -by (auto_tac (claset(),
  4.1234 -              simpset() addsimps [starfun_lambda_cancel2, starfun_o RS sym]));
  4.1235 -by (case_tac "( *f* g) (hypreal_of_real(x) + xa) = hypreal_of_real (g x)" 1);
  4.1236 -by (dres_inst_tac [("g","g")] NSDERIV_zero 1);
  4.1237 -by (auto_tac (claset(), simpset() addsimps [hypreal_divide_def]));
  4.1238 -by (res_inst_tac [("z1","( *f* g) (hypreal_of_real(x) + xa) + -hypreal_of_real (g x)"),
  4.1239 -    ("y1","inverse xa")] (lemma_chain RS ssubst) 1);
  4.1240 -by (etac (hypreal_not_eq_minus_iff RS iffD1) 1);
  4.1241 -by (rtac approx_mult_hypreal_of_real 1);
  4.1242 -by (fold_tac [hypreal_divide_def]);
  4.1243 -by (blast_tac (claset() addIs [NSDERIVD1,
  4.1244 -    approx_minus_iff RS iffD2]) 1);
  4.1245 -by (blast_tac (claset() addIs [NSDERIVD2]) 1);
  4.1246 -qed "NSDERIV_chain";
  4.1247 -
  4.1248 -(* standard version *)
  4.1249 -Goal "[| DERIV f (g x) :> Da; \
  4.1250 -\                 DERIV g x :> Db \
  4.1251 -\              |] ==> DERIV (f o g) x :> Da * Db";
  4.1252 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym,
  4.1253 -    NSDERIV_chain]) 1);
  4.1254 -qed "DERIV_chain";
  4.1255 -
  4.1256 -Goal "[| DERIV f (g x) :> Da; DERIV g x :> Db |] \
  4.1257 -\     ==> DERIV (%x. f (g x)) x :> Da * Db";
  4.1258 -by (auto_tac (claset() addDs [DERIV_chain], simpset() addsimps [o_def]));
  4.1259 -qed "DERIV_chain2";
  4.1260 -
  4.1261 -(*------------------------------------------------------------------
  4.1262 -           Differentiation of natural number powers
  4.1263 - ------------------------------------------------------------------*)
  4.1264 -Goal "NSDERIV (%x. x) x :> 1";
  4.1265 -by (auto_tac (claset(),
  4.1266 -     simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def ,starfun_Id]));
  4.1267 -qed "NSDERIV_Id";
  4.1268 -Addsimps [NSDERIV_Id];
  4.1269 -
  4.1270 -(*derivative of the identity function*)
  4.1271 -Goal "DERIV (%x. x) x :> 1";
  4.1272 -by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
  4.1273 -qed "DERIV_Id";
  4.1274 -Addsimps [DERIV_Id];
  4.1275 -
  4.1276 -bind_thm ("isCont_Id", DERIV_Id RS DERIV_isCont);
  4.1277 -
  4.1278 -(*derivative of linear multiplication*)
  4.1279 -Goal "DERIV (op * c) x :> c";
  4.1280 -by (cut_inst_tac [("c","c"),("x","x")] (DERIV_Id RS DERIV_cmult) 1);
  4.1281 -by (Asm_full_simp_tac 1);
  4.1282 -qed "DERIV_cmult_Id";
  4.1283 -Addsimps [DERIV_cmult_Id];
  4.1284 -
  4.1285 -Goal "NSDERIV (op * c) x :> c";
  4.1286 -by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff]) 1);
  4.1287 -qed "NSDERIV_cmult_Id";
  4.1288 -Addsimps [NSDERIV_cmult_Id];
  4.1289 -
  4.1290 -Goal "DERIV (%x. x ^ n) x :> real n * (x ^ (n - Suc 0))";
  4.1291 -by (induct_tac "n" 1);
  4.1292 -by (dtac (DERIV_Id RS DERIV_mult) 2);
  4.1293 -by (auto_tac (claset(),
  4.1294 -              simpset() addsimps [real_of_nat_Suc, left_distrib]));
  4.1295 -by (case_tac "0 < n" 1);
  4.1296 -by (dres_inst_tac [("x","x")] realpow_minus_mult 1);
  4.1297 -by (auto_tac (claset(),
  4.1298 -              simpset() addsimps [real_mult_assoc, real_add_commute]));
  4.1299 -qed "DERIV_pow";
  4.1300 -
  4.1301 -(* NS version *)
  4.1302 -Goal "NSDERIV (%x. x ^ n) x :> real n * (x ^ (n - Suc 0))";
  4.1303 -by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff, DERIV_pow]) 1);
  4.1304 -qed "NSDERIV_pow";
  4.1305 -
  4.1306 -(*---------------------------------------------------------------
  4.1307 -                    Power of -1
  4.1308 - ---------------------------------------------------------------*)
  4.1309 -
  4.1310 -(*Can't get rid of x \\<noteq> 0 because it isn't continuous at zero*)
  4.1311 -Goalw [nsderiv_def]
  4.1312 -     "x \\<noteq> 0 ==> NSDERIV (%x. inverse(x)) x :> (- (inverse x ^ Suc (Suc 0)))";
  4.1313 -by (rtac ballI 1 THEN Asm_full_simp_tac 1 THEN Step_tac 1);
  4.1314 -by (ftac Infinitesimal_add_not_zero 1);
  4.1315 -by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 2);
  4.1316 -by (auto_tac (claset(),
  4.1317 -     simpset() addsimps [starfun_inverse_inverse, realpow_two]
  4.1318 -               delsimps [minus_mult_left RS sym,
  4.1319 -                         minus_mult_right RS sym]));
  4.1320 -by (asm_full_simp_tac
  4.1321 -     (simpset() addsimps [hypreal_inverse_add,
  4.1322 -          hypreal_inverse_distrib RS sym, hypreal_minus_inverse RS sym]
  4.1323 -          @ add_ac @ mult_ac
  4.1324 -       delsimps [inverse_mult_distrib,inverse_minus_eq,
  4.1325 -		 minus_mult_left RS sym,
  4.1326 -                 minus_mult_right RS sym] ) 1);
  4.1327 -by (asm_simp_tac (simpset() addsimps [hypreal_mult_assoc RS sym,
  4.1328 -                                      right_distrib]
  4.1329 -         delsimps [minus_mult_left RS sym,
  4.1330 -                   minus_mult_right RS sym]) 1);
  4.1331 -by (res_inst_tac [("y"," inverse(- hypreal_of_real x * hypreal_of_real x)")]
  4.1332 -                 approx_trans 1);
  4.1333 -by (rtac inverse_add_Infinitesimal_approx2 1);
  4.1334 -by (auto_tac (claset() addSDs [hypreal_of_real_HFinite_diff_Infinitesimal],
  4.1335 -         simpset() addsimps [hypreal_minus_inverse RS sym,
  4.1336 -                             HFinite_minus_iff]));
  4.1337 -by (rtac Infinitesimal_HFinite_mult2 1);
  4.1338 -by Auto_tac;
  4.1339 -qed "NSDERIV_inverse";
  4.1340 -
  4.1341 -
  4.1342 -Goal "x \\<noteq> 0 ==> DERIV (%x. inverse(x)) x :> (-(inverse x ^ Suc (Suc 0)))";
  4.1343 -by (asm_simp_tac (simpset() addsimps [NSDERIV_inverse,
  4.1344 -         NSDERIV_DERIV_iff RS sym] delsimps [realpow_Suc]) 1);
  4.1345 -qed "DERIV_inverse";
  4.1346 -
  4.1347 -(*--------------------------------------------------------------
  4.1348 -        Derivative of inverse
  4.1349 - -------------------------------------------------------------*)
  4.1350 -Goal "[| DERIV f x :> d; f(x) \\<noteq> 0 |] \
  4.1351 -\     ==> DERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ Suc (Suc 0))))";
  4.1352 -by (rtac (real_mult_commute RS subst) 1);
  4.1353 -by (asm_simp_tac (HOL_ss addsimps [minus_mult_left, power_inverse]) 1);
  4.1354 -by (fold_goals_tac [o_def]);
  4.1355 -by (blast_tac (claset() addSIs [DERIV_chain,DERIV_inverse]) 1);
  4.1356 -qed "DERIV_inverse_fun";
  4.1357 -
  4.1358 -Goal "[| NSDERIV f x :> d; f(x) \\<noteq> 0 |] \
  4.1359 -\     ==> NSDERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ Suc (Suc 0))))";
  4.1360 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  4.1361 -            DERIV_inverse_fun] delsimps [realpow_Suc]) 1);
  4.1362 -qed "NSDERIV_inverse_fun";
  4.1363 -
  4.1364 -(*--------------------------------------------------------------
  4.1365 -        Derivative of quotient
  4.1366 - -------------------------------------------------------------*)
  4.1367 -Goal "[| DERIV f x :> d; DERIV g x :> e; g(x) \\<noteq> 0 |] \
  4.1368 -\      ==> DERIV (%y. f(y) / (g y)) x :> (d*g(x) + -(e*f(x))) / (g(x) ^ Suc (Suc 0))";
  4.1369 -by (dres_inst_tac [("f","g")] DERIV_inverse_fun 1);
  4.1370 -by (dtac DERIV_mult 2);
  4.1371 -by (REPEAT(assume_tac 1));
  4.1372 -by (asm_full_simp_tac
  4.1373 -    (simpset() addsimps [real_divide_def, right_distrib,
  4.1374 -                         power_inverse,minus_mult_left] @ mult_ac
  4.1375 -       delsimps [realpow_Suc, minus_mult_right RS sym, minus_mult_left RS sym]) 1);
  4.1376 -qed "DERIV_quotient";
  4.1377 -
  4.1378 -Goal "[| NSDERIV f x :> d; DERIV g x :> e; g(x) \\<noteq> 0 |] \
  4.1379 -\      ==> NSDERIV (%y. f(y) / (g y)) x :> (d*g(x) \
  4.1380 -\                           + -(e*f(x))) / (g(x) ^ Suc (Suc 0))";
  4.1381 -by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  4.1382 -            DERIV_quotient] delsimps [realpow_Suc]) 1);
  4.1383 -qed "NSDERIV_quotient";
  4.1384 -
  4.1385 -(* ------------------------------------------------------------------------ *)
  4.1386 -(* Caratheodory formulation of derivative at a point: standard proof        *)
  4.1387 -(* ------------------------------------------------------------------------ *)
  4.1388 -
  4.1389 -Goal "(DERIV f x :> l) = \
  4.1390 -\     (\\<exists>g. (\\<forall>z. f z - f x = g z * (z - x)) & isCont g x & g x = l)";
  4.1391 -by Safe_tac;
  4.1392 -by (res_inst_tac
  4.1393 -    [("x","%z. if  z = x then l else (f(z) - f(x)) / (z - x)")] exI 1);
  4.1394 -by (auto_tac (claset(),simpset() addsimps [real_mult_assoc,
  4.1395 -    ARITH_PROVE "z \\<noteq> x ==> z - x \\<noteq> (0::real)"]));
  4.1396 -by (auto_tac (claset(),simpset() addsimps [isCont_iff,DERIV_iff]));
  4.1397 -by (ALLGOALS(rtac (LIM_equal RS iffD1)));
  4.1398 -by (auto_tac (claset(),simpset() addsimps [real_diff_def,real_mult_assoc]));
  4.1399 -qed "CARAT_DERIV";
  4.1400 -
  4.1401 -Goal "NSDERIV f x :> l ==> \
  4.1402 -\     \\<exists>g. (\\<forall>z. f z - f x = g z * (z - x)) & isNSCont g x & g x = l";
  4.1403 -by (auto_tac (claset(),simpset() addsimps [NSDERIV_DERIV_iff,
  4.1404 -    isNSCont_isCont_iff,CARAT_DERIV]));
  4.1405 -qed "CARAT_NSDERIV";
  4.1406 -
  4.1407 -(* How about a NS proof? *)
  4.1408 -Goal "(\\<forall>z. f z - f x = g z * (z - x)) & isNSCont g x & g x = l \
  4.1409 -\     ==> NSDERIV f x :> l";
  4.1410 -by (auto_tac (claset(),
  4.1411 -              simpset() delsimprocs field_cancel_factor
  4.1412 -                        addsimps [NSDERIV_iff2]));
  4.1413 -by (auto_tac (claset(),
  4.1414 -              simpset() addsimps [hypreal_mult_assoc]));
  4.1415 -by (asm_full_simp_tac (simpset() addsimps [hypreal_eq_minus_iff3 RS sym,
  4.1416 -                                           hypreal_diff_def]) 1);
  4.1417 -by (asm_full_simp_tac (simpset() addsimps [isNSCont_def]) 1);
  4.1418 -qed "CARAT_DERIVD";
  4.1419 -
  4.1420 -
  4.1421 -
  4.1422 -(*--------------------------------------------------------------------------*)
  4.1423 -(* Lemmas about nested intervals and proof by bisection (cf.Harrison)       *)
  4.1424 -(* All considerably tidied by lcp                                           *)
  4.1425 -(*--------------------------------------------------------------------------*)
  4.1426 -
  4.1427 -Goal "(\\<forall>n. (f::nat=>real) n \\<le> f (Suc n)) --> f m \\<le> f(m + no)";
  4.1428 -by (induct_tac "no" 1);
  4.1429 -by (auto_tac (claset() addIs [order_trans], simpset()));
  4.1430 -qed_spec_mp "lemma_f_mono_add";
  4.1431 -
  4.1432 -Goal "[| \\<forall>n. f(n) \\<le> f(Suc n); \
  4.1433 -\        \\<forall>n. g(Suc n) \\<le> g(n); \
  4.1434 -\        \\<forall>n. f(n) \\<le> g(n) |] \
  4.1435 -\     ==> Bseq f";
  4.1436 -by (res_inst_tac [("k","f 0"),("K","g 0")] BseqI2 1 THEN rtac allI 1);
  4.1437 -by (induct_tac "n" 1);
  4.1438 -by (auto_tac (claset() addIs [order_trans], simpset()));
  4.1439 -by (res_inst_tac [("y","g(Suc na)")] order_trans 1);
  4.1440 -by (induct_tac "na" 2);
  4.1441 -by (auto_tac (claset() addIs [order_trans], simpset()));
  4.1442 -qed "f_inc_g_dec_Beq_f";
  4.1443 -
  4.1444 -Goal "[| \\<forall>n. f(n) \\<le> f(Suc n); \
  4.1445 -\        \\<forall>n. g(Suc n) \\<le> g(n); \
  4.1446 -\        \\<forall>n. f(n) \\<le> g(n) |] \
  4.1447 -\     ==> Bseq g";
  4.1448 -by (stac (Bseq_minus_iff RS sym) 1);
  4.1449 -by (res_inst_tac [("g","%x. -(f x)")] f_inc_g_dec_Beq_f 1);
  4.1450 -by Auto_tac;
  4.1451 -qed "f_inc_g_dec_Beq_g";
  4.1452 -
  4.1453 -Goal "[| \\<forall>n. f n \\<le> f (Suc n);  convergent f |] ==> f n \\<le> lim f";
  4.1454 -by (rtac (linorder_not_less RS iffD1) 1);
  4.1455 -by (auto_tac (claset(),
  4.1456 -      simpset() addsimps [convergent_LIMSEQ_iff, LIMSEQ_iff, monoseq_Suc]));
  4.1457 -by (dtac real_less_sum_gt_zero 1);
  4.1458 -by (dres_inst_tac [("x","f n + - lim f")] spec 1);
  4.1459 -by Safe_tac;
  4.1460 -by (dres_inst_tac [("P","%na. no\\<le>na --> ?Q na"),("x","no + n")] spec 1);
  4.1461 -by Auto_tac;
  4.1462 -by (subgoal_tac "lim f \\<le> f(no + n)" 1);
  4.1463 -by (induct_tac "no" 2);
  4.1464 -by (auto_tac (claset() addIs [order_trans],
  4.1465 -              simpset() addsimps [real_diff_def, real_abs_def]));
  4.1466 -by (dres_inst_tac [("x","f(no + n)"),("no1","no")]
  4.1467 -    (lemma_f_mono_add RSN (2,order_less_le_trans)) 1);
  4.1468 -by (auto_tac (claset(), simpset() addsimps [add_commute]));
  4.1469 -qed "f_inc_imp_le_lim";
  4.1470 -
  4.1471 -Goal "convergent g ==> lim (%x. - g x) = - (lim g)";
  4.1472 -by (rtac (LIMSEQ_minus RS limI) 1);
  4.1473 -by (asm_full_simp_tac (simpset() addsimps [convergent_LIMSEQ_iff]) 1);
  4.1474 -qed "lim_uminus";
  4.1475 -
  4.1476 -Goal "[| \\<forall>n. g(Suc n) \\<le> g(n);  convergent g |] ==> lim g \\<le> g n";
  4.1477 -by (subgoal_tac "- (g n) \\<le> - (lim g)" 1);
  4.1478 -by (cut_inst_tac [("f", "%x. - (g x)")] f_inc_imp_le_lim 2);
  4.1479 -by (auto_tac (claset(),
  4.1480 -              simpset() addsimps [lim_uminus, convergent_minus_iff RS sym]));
  4.1481 -qed "g_dec_imp_lim_le";
  4.1482 -
  4.1483 -Goal "[| \\<forall>n. f(n) \\<le> f(Suc n); \
  4.1484 -\        \\<forall>n. g(Suc n) \\<le> g(n); \
  4.1485 -\        \\<forall>n. f(n) \\<le> g(n) |] \
  4.1486 -\     ==> \\<exists>l m. l \\<le> m &  ((\\<forall>n. f(n) \\<le> l) & f ----> l) & \
  4.1487 -\                           ((\\<forall>n. m \\<le> g(n)) & g ----> m)";
  4.1488 -by (subgoal_tac "monoseq f & monoseq g" 1);
  4.1489 -by (force_tac (claset(), simpset() addsimps [LIMSEQ_iff,monoseq_Suc]) 2);
  4.1490 -by (subgoal_tac "Bseq f & Bseq g" 1);
  4.1491 -by (blast_tac (claset() addIs [f_inc_g_dec_Beq_f, f_inc_g_dec_Beq_g]) 2);
  4.1492 -by (auto_tac (claset() addSDs [Bseq_monoseq_convergent],
  4.1493 -              simpset() addsimps [convergent_LIMSEQ_iff]));
  4.1494 -by (res_inst_tac [("x","lim f")] exI 1);
  4.1495 -by (res_inst_tac [("x","lim g")] exI 1);
  4.1496 -by (auto_tac (claset() addIs [LIMSEQ_le], simpset()));
  4.1497 -by (auto_tac (claset(),
  4.1498 -              simpset() addsimps [f_inc_imp_le_lim, g_dec_imp_lim_le,
  4.1499 -                                  convergent_LIMSEQ_iff]));
  4.1500 -qed "lemma_nest";
  4.1501 -
  4.1502 -Goal "[| \\<forall>n. f(n) \\<le> f(Suc n); \
  4.1503 -\        \\<forall>n. g(Suc n) \\<le> g(n); \
  4.1504 -\        \\<forall>n. f(n) \\<le> g(n); \
  4.1505 -\        (%n. f(n) - g(n)) ----> 0 |] \
  4.1506 -\     ==> \\<exists>l. ((\\<forall>n. f(n) \\<le> l) & f ----> l) & \
  4.1507 -\               ((\\<forall>n. l \\<le> g(n)) & g ----> l)";
  4.1508 -by (dtac lemma_nest 1 THEN Auto_tac);
  4.1509 -by (subgoal_tac "l = m" 1);
  4.1510 -by (dres_inst_tac [("X","f")] LIMSEQ_diff 2);
  4.1511 -by (auto_tac (claset() addIs [LIMSEQ_unique], simpset()));
  4.1512 -qed "lemma_nest_unique";
  4.1513 -
  4.1514 -
  4.1515 -Goal "a \\<le> b ==> \
  4.1516 -\  \\<forall>n. fst (Bolzano_bisect P a b n) \\<le> snd (Bolzano_bisect P a b n)";
  4.1517 -by (rtac allI 1);
  4.1518 -by (induct_tac "n" 1);
  4.1519 -by (auto_tac (claset(), simpset() addsimps [Let_def, split_def]));
  4.1520 -qed "Bolzano_bisect_le";
  4.1521 -
  4.1522 -Goal "a \\<le> b ==> \
  4.1523 -\  \\<forall>n. fst(Bolzano_bisect P a b n) \\<le> fst (Bolzano_bisect P a b (Suc n))";
  4.1524 -by (rtac allI 1);
  4.1525 -by (induct_tac "n" 1);
  4.1526 -by (auto_tac (claset(),
  4.1527 -              simpset() addsimps [Bolzano_bisect_le, Let_def, split_def]));
  4.1528 -qed "Bolzano_bisect_fst_le_Suc";
  4.1529 -
  4.1530 -Goal "a \\<le> b ==> \
  4.1531 -\  \\<forall>n. snd(Bolzano_bisect P a b (Suc n)) \\<le> snd (Bolzano_bisect P a b n)";
  4.1532 -by (rtac allI 1);
  4.1533 -by (induct_tac "n" 1);
  4.1534 -by (auto_tac (claset(),
  4.1535 -              simpset() addsimps [Bolzano_bisect_le, Let_def, split_def]));
  4.1536 -qed "Bolzano_bisect_Suc_le_snd";
  4.1537 -
  4.1538 -Goal "((x::real) = y / (2 * z)) = (2 * x = y/z)";
  4.1539 -by Auto_tac;
  4.1540 -by (dres_inst_tac [("f","%u. (1/2)*u")] arg_cong 1);
  4.1541 -by Auto_tac;
  4.1542 -qed "eq_divide_2_times_iff";
  4.1543 -
  4.1544 -Goal "a \\<le> b ==> \
  4.1545 -\     snd(Bolzano_bisect P a b n) - fst(Bolzano_bisect P a b n) = \
  4.1546 -\     (b-a) / (2 ^ n)";
  4.1547 -by (induct_tac "n" 1);
  4.1548 -by (auto_tac (claset(),
  4.1549 -      simpset() addsimps [eq_divide_2_times_iff, add_divide_distrib,
  4.1550 -                          Let_def, split_def]));
  4.1551 -by (auto_tac (claset(),
  4.1552 -              simpset() addsimps (add_ac@[Bolzano_bisect_le, real_diff_def])));
  4.1553 -qed "Bolzano_bisect_diff";
  4.1554 -
  4.1555 -val Bolzano_nest_unique =
  4.1556 -    [Bolzano_bisect_fst_le_Suc, Bolzano_bisect_Suc_le_snd, Bolzano_bisect_le]
  4.1557 -    MRS lemma_nest_unique;
  4.1558 -
  4.1559 -(*P_prem is a looping simprule, so it works better if it isn't an assumption*)
  4.1560 -val P_prem::notP_prem::rest =
  4.1561 -Goal "[| !!a b c. [| P(a,b); P(b,c); a \\<le> b; b \\<le> c|] ==> P(a,c); \
  4.1562 -\        ~ P(a,b);  a \\<le> b |] ==> \
  4.1563 -\     ~ P(fst(Bolzano_bisect P a b n), snd(Bolzano_bisect P a b n))";
  4.1564 -by (cut_facts_tac rest 1);
  4.1565 -by (induct_tac "n" 1);
  4.1566 -by (auto_tac (claset(),
  4.1567 -              simpset() delsimps [surjective_pairing RS sym]
  4.1568 -			addsimps [notP_prem, Let_def, split_def]));
  4.1569 -by (swap_res_tac [P_prem] 1);
  4.1570 -by (assume_tac 1);
  4.1571 -by (auto_tac (claset(), simpset() addsimps [Bolzano_bisect_le]));
  4.1572 -qed "not_P_Bolzano_bisect";
  4.1573 -
  4.1574 -(*Now we re-package P_prem as a formula*)
  4.1575 -Goal "[| \\<forall>a b c. P(a,b) & P(b,c) & a \\<le> b & b \\<le> c --> P(a,c); \
  4.1576 -\        ~ P(a,b);  a \\<le> b |] ==> \
  4.1577 -\     \\<forall>n. ~ P(fst(Bolzano_bisect P a b n), snd(Bolzano_bisect P a b n))";
  4.1578 -by (blast_tac (claset() addSEs [not_P_Bolzano_bisect RSN (2,rev_notE)]) 1);
  4.1579 -qed "not_P_Bolzano_bisect'";
  4.1580 -
  4.1581 -
  4.1582 -Goal "[| \\<forall>a b c. P(a,b) & P(b,c) & a \\<le> b & b \\<le> c --> P(a,c); \
  4.1583 -\        \\<forall>x. \\<exists>d::real. 0 < d & \
  4.1584 -\               (\\<forall>a b. a \\<le> x & x \\<le> b & (b - a) < d --> P(a,b)); \
  4.1585 -\        a \\<le> b |]  \
  4.1586 -\     ==> P(a,b)";
  4.1587 -by (rtac (inst "P1" "P" Bolzano_nest_unique RS exE) 1);
  4.1588 -by (REPEAT (assume_tac 1));
  4.1589 -by (rtac LIMSEQ_minus_cancel 1);
  4.1590 -by (asm_simp_tac (simpset() addsimps [Bolzano_bisect_diff,
  4.1591 -                                      LIMSEQ_divide_realpow_zero]) 1);
  4.1592 -by (rtac ccontr 1);
  4.1593 -by (dtac not_P_Bolzano_bisect' 1);
  4.1594 -by (REPEAT (assume_tac 1));
  4.1595 -by (rename_tac "l" 1);
  4.1596 -by (dres_inst_tac [("x","l")] spec 1 THEN Clarify_tac 1);
  4.1597 -by (rewtac LIMSEQ_def);
  4.1598 -by (dres_inst_tac [("P", "%r. 0<r --> ?Q r"), ("x","d/2")] spec 1);
  4.1599 -by (dres_inst_tac [("P", "%r. 0<r --> ?Q r"), ("x","d/2")] spec 1);
  4.1600 -by (dtac real_less_half_sum 1);
  4.1601 -by Safe_tac;
  4.1602 -(*linear arithmetic bug if we just use Asm_simp_tac*)
  4.1603 -by (ALLGOALS Asm_full_simp_tac);
  4.1604 -by (dres_inst_tac [("x","fst(Bolzano_bisect P a b (no + noa))")] spec 1);
  4.1605 -by (dres_inst_tac [("x","snd(Bolzano_bisect P a b (no + noa))")] spec 1);
  4.1606 -by Safe_tac;
  4.1607 -by (ALLGOALS Asm_simp_tac);
  4.1608 -by (res_inst_tac [("y","abs(fst(Bolzano_bisect P a b(no + noa)) - l) + \
  4.1609 -\                       abs(snd(Bolzano_bisect P a b(no + noa)) - l)")]
  4.1610 -    order_le_less_trans 1);
  4.1611 -by (asm_simp_tac (simpset() addsimps [real_abs_def]) 1);
  4.1612 -by (rtac (real_sum_of_halves RS subst) 1);
  4.1613 -by (rtac add_strict_mono 1);
  4.1614 -by (ALLGOALS
  4.1615 -    (asm_full_simp_tac (simpset() addsimps [symmetric real_diff_def])));
  4.1616 -qed "lemma_BOLZANO";
  4.1617 -
  4.1618 -
  4.1619 -Goal "((\\<forall>a b c. (a \\<le> b & b \\<le> c & P(a,b) & P(b,c)) --> P(a,c)) & \
  4.1620 -\      (\\<forall>x. \\<exists>d::real. 0 < d & \
  4.1621 -\               (\\<forall>a b. a \\<le> x & x \\<le> b & (b - a) < d --> P(a,b)))) \
  4.1622 -\     --> (\\<forall>a b. a \\<le> b --> P(a,b))";
  4.1623 -by (Clarify_tac 1);
  4.1624 -by (blast_tac (claset() addIs [lemma_BOLZANO]) 1);
  4.1625 -qed "lemma_BOLZANO2";
  4.1626 -
  4.1627 -
  4.1628 -(*----------------------------------------------------------------------------*)
  4.1629 -(* Intermediate Value Theorem (prove contrapositive by bisection)             *)
  4.1630 -(*----------------------------------------------------------------------------*)
  4.1631 -
  4.1632 -Goal "[| f(a) \\<le> y & y \\<le> f(b); \
  4.1633 -\        a \\<le> b; \
  4.1634 -\        (\\<forall>x. a \\<le> x & x \\<le> b --> isCont f x) |] \
  4.1635 -\     ==> \\<exists>x. a \\<le> x & x \\<le> b & f(x) = y";
  4.1636 -by (rtac contrapos_pp 1);
  4.1637 -by (assume_tac 1);
  4.1638 -by (cut_inst_tac
  4.1639 -    [("P","%(u,v). a \\<le> u & u \\<le> v & v \\<le> b --> ~(f(u) \\<le> y & y \\<le> f(v))")]
  4.1640 -    lemma_BOLZANO2 1);
  4.1641 -by Safe_tac;
  4.1642 -by (ALLGOALS(Asm_full_simp_tac));
  4.1643 -by (asm_full_simp_tac (simpset() addsimps [isCont_iff,LIM_def]) 1);
  4.1644 -by (rtac ccontr 1);
  4.1645 -by (subgoal_tac "a \\<le> x & x \\<le> b" 1);
  4.1646 -by (Asm_full_simp_tac 2);
  4.1647 -by (dres_inst_tac [("P", "%d. 0<d --> ?P d"),("x","1")] spec 2);
  4.1648 -by (Step_tac 2);
  4.1649 -by (Asm_full_simp_tac 2);
  4.1650 -by (Asm_full_simp_tac 2);
  4.1651 -by (REPEAT(blast_tac (claset() addIs [order_trans]) 2));
  4.1652 -by (REPEAT(dres_inst_tac [("x","x")] spec 1));
  4.1653 -by (Asm_full_simp_tac 1);
  4.1654 -by (dres_inst_tac [("P", "%r. ?P r --> (\\<exists>s. 0<s & ?Q r s)"),
  4.1655 -                   ("x","abs(y - f x)")] spec 1);
  4.1656 -by Safe_tac;
  4.1657 -by (asm_full_simp_tac (simpset() addsimps []) 1);
  4.1658 -by (dres_inst_tac [("x","s")] spec 1);
  4.1659 -by (Clarify_tac 1);
  4.1660 -by (cut_inst_tac [("x","f x"),("y","y")] linorder_less_linear 1);
  4.1661 -by Safe_tac;
  4.1662 -by (dres_inst_tac [("x","ba - x")] spec 1);
  4.1663 -by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [thm"abs_if"])));
  4.1664 -by (dres_inst_tac [("x","aa - x")] spec 1);
  4.1665 -by (case_tac "x \\<le> aa" 1);
  4.1666 -by (ALLGOALS Asm_full_simp_tac);
  4.1667 -by (dres_inst_tac [("z","x"),("w","aa")] real_le_anti_sym 1);
  4.1668 -by (assume_tac 1 THEN Asm_full_simp_tac 1);
  4.1669 -qed "IVT";
  4.1670 -
  4.1671 -
  4.1672 -Goal "[| f(b) \\<le> y & y \\<le> f(a); \
  4.1673 -\        a \\<le> b; \
  4.1674 -\        (\\<forall>x. a \\<le> x & x \\<le> b --> isCont f x) \
  4.1675 -\     |] ==> \\<exists>x. a \\<le> x & x \\<le> b & f(x) = y";
  4.1676 -by (subgoal_tac "- f a \\<le> -y & -y \\<le> - f b" 1);
  4.1677 -by (thin_tac "f b \\<le> y & y \\<le> f a" 1);
  4.1678 -by (dres_inst_tac [("f","%x. - f x")] IVT 1);
  4.1679 -by (auto_tac (claset() addIs [isCont_minus],simpset()));
  4.1680 -qed "IVT2";
  4.1681 -
  4.1682 -
  4.1683 -(*HOL style here: object-level formulations*)
  4.1684 -Goal "(f(a) \\<le> y & y \\<le> f(b) & a \\<le> b & \
  4.1685 -\     (\\<forall>x. a \\<le> x & x \\<le> b --> isCont f x)) \
  4.1686 -\     --> (\\<exists>x. a \\<le> x & x \\<le> b & f(x) = y)";
  4.1687 -by (blast_tac (claset() addIs [IVT]) 1);
  4.1688 -qed "IVT_objl";
  4.1689 -
  4.1690 -Goal "(f(b) \\<le> y & y \\<le> f(a) & a \\<le> b & \
  4.1691 -\     (\\<forall>x. a \\<le> x & x \\<le> b --> isCont f x)) \
  4.1692 -\     --> (\\<exists>x. a \\<le> x & x \\<le> b & f(x) = y)";
  4.1693 -by (blast_tac (claset() addIs [IVT2]) 1);
  4.1694 -qed "IVT2_objl";
  4.1695 -
  4.1696 -(*---------------------------------------------------------------------------*)
  4.1697 -(* By bisection, function continuous on closed interval is bounded above     *)
  4.1698 -(*---------------------------------------------------------------------------*)
  4.1699 -
  4.1700 -Goal "abs (real x) = real (x::nat)";
  4.1701 -by (auto_tac (claset() addIs [abs_eqI1], simpset()));
  4.1702 -qed "abs_real_of_nat_cancel";
  4.1703 -Addsimps [abs_real_of_nat_cancel];
  4.1704 -
  4.1705 -Goal "~ abs(x) + (1::real) < x";
  4.1706 -by (asm_full_simp_tac (simpset() addsimps [linorder_not_less]) 1);
  4.1707 -by (auto_tac (claset() addIs [abs_ge_self RS order_trans],simpset()));
  4.1708 -qed "abs_add_one_not_less_self";
  4.1709 -Addsimps [abs_add_one_not_less_self];
  4.1710 -
  4.1711 -
  4.1712 -Goal "[| a \\<le> b; \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x |]\
  4.1713 -\     ==> \\<exists>M. \\<forall>x. a \\<le> x & x \\<le> b --> f(x) \\<le> M";
  4.1714 -by (cut_inst_tac [("P","%(u,v). a \\<le> u & u \\<le> v & v \\<le> b --> \
  4.1715 -\                         (\\<exists>M. \\<forall>x. u \\<le> x & x \\<le> v --> f x \\<le> M)")]
  4.1716 -    lemma_BOLZANO2 1);
  4.1717 -by Safe_tac;
  4.1718 -by (ALLGOALS Asm_full_simp_tac);
  4.1719 -by (rename_tac "x xa ya M Ma" 1);
  4.1720 -by (cut_inst_tac [("x","M"),("y","Ma")] linorder_linear 1);
  4.1721 -by Safe_tac;
  4.1722 -by (res_inst_tac [("x","Ma")] exI 1);
  4.1723 -by (Clarify_tac 1);
  4.1724 -by (cut_inst_tac [("x","xb"),("y","xa")] linorder_linear 1);
  4.1725 -by (Force_tac 1);
  4.1726 -by (res_inst_tac [("x","M")] exI 1);
  4.1727 -by (Clarify_tac 1);
  4.1728 -by (cut_inst_tac [("x","xb"),("y","xa")] linorder_linear 1);
  4.1729 -by (Force_tac 1);
  4.1730 -by (case_tac "a \\<le> x & x \\<le> b" 1);
  4.1731 -by (res_inst_tac [("x","1")] exI 2);
  4.1732 -by (Force_tac 2);
  4.1733 -by (asm_full_simp_tac (simpset() addsimps [LIM_def,isCont_iff]) 1);
  4.1734 -by (dres_inst_tac [("x","x")] spec 1 THEN Auto_tac);
  4.1735 -by (thin_tac "\\<forall>M. \\<exists>x. a \\<le> x & x \\<le> b & ~ f x \\<le> M" 1);
  4.1736 -by (dres_inst_tac [("x","1")] spec 1);
  4.1737 -by Auto_tac;
  4.1738 -by (res_inst_tac [("x","s")] exI 1 THEN Clarify_tac 1);
  4.1739 -by (res_inst_tac [("x","abs(f x) + 1")] exI 1 THEN Clarify_tac 1);
  4.1740 -by (dres_inst_tac [("x","xa - x")] spec 1);
  4.1741 -by (auto_tac (claset(), simpset() addsimps [abs_ge_self]));
  4.1742 -by (REPEAT (arith_tac 1));
  4.1743 -qed "isCont_bounded";
  4.1744 -
  4.1745 -(*----------------------------------------------------------------------------*)
  4.1746 -(* Refine the above to existence of least upper bound                         *)
  4.1747 -(*----------------------------------------------------------------------------*)
  4.1748 -
  4.1749 -Goal "((\\<exists>x. x \\<in> S) & (\\<exists>y. isUb UNIV S (y::real))) --> \
  4.1750 -\     (\\<exists>t. isLub UNIV S t)";
  4.1751 -by (blast_tac (claset() addIs [reals_complete]) 1);
  4.1752 -qed "lemma_reals_complete";
  4.1753 -
  4.1754 -Goal "[| a \\<le> b; \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x |] \
  4.1755 -\        ==> \\<exists>M. (\\<forall>x. a \\<le> x & x \\<le> b --> f(x) \\<le> M) & \
  4.1756 -\                  (\\<forall>N. N < M --> (\\<exists>x. a \\<le> x & x \\<le> b & N < f(x)))";
  4.1757 -by (cut_inst_tac [("S","Collect (%y. \\<exists>x. a \\<le> x & x \\<le> b & y = f x)")]
  4.1758 -    lemma_reals_complete 1);
  4.1759 -by Auto_tac;
  4.1760 -by (dtac isCont_bounded 1 THEN assume_tac 1);
  4.1761 -by (auto_tac (claset(),simpset() addsimps [isUb_def,leastP_def,
  4.1762 -    isLub_def,setge_def,setle_def]));
  4.1763 -by (rtac exI 1 THEN Auto_tac);
  4.1764 -by (REPEAT(dtac spec 1) THEN Auto_tac);
  4.1765 -by (dres_inst_tac [("x","x")] spec 1);
  4.1766 -by (auto_tac (claset() addSIs [(linorder_not_less RS iffD1)],simpset()));
  4.1767 -qed "isCont_has_Ub";
  4.1768 -
  4.1769 -(*----------------------------------------------------------------------------*)
  4.1770 -(* Now show that it attains its upper bound                                   *)
  4.1771 -(*----------------------------------------------------------------------------*)
  4.1772 -
  4.1773 -Goal "[| a \\<le> b; \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x |] \
  4.1774 -\        ==> \\<exists>M. (\\<forall>x. a \\<le> x & x \\<le> b --> f(x) \\<le> M) & \
  4.1775 -\                  (\\<exists>x. a \\<le> x & x \\<le> b & f(x) = M)";
  4.1776 -by (ftac isCont_has_Ub 1 THEN assume_tac 1);
  4.1777 -by (Clarify_tac 1);
  4.1778 -by (res_inst_tac [("x","M")] exI 1);
  4.1779 -by (Asm_full_simp_tac 1);
  4.1780 -by (rtac ccontr 1);
  4.1781 -by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> f x < M" 1 THEN Step_tac 1);
  4.1782 -by (rtac ccontr 2 THEN dtac (linorder_not_less RS iffD1) 2);
  4.1783 -by (dres_inst_tac [("z","M")] real_le_anti_sym 2);
  4.1784 -by (REPEAT(Blast_tac 2));
  4.1785 -by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> isCont (%x. inverse(M - f x)) x" 1);
  4.1786 -by Safe_tac;
  4.1787 -by (EVERY[rtac isCont_inverse 2, rtac isCont_diff 2, rtac notI 4]);
  4.1788 -by (ALLGOALS(asm_full_simp_tac (simpset() addsimps [diff_eq_eq])));
  4.1789 -by (Blast_tac 2);
  4.1790 -by (subgoal_tac
  4.1791 -    "\\<exists>k. \\<forall>x. a \\<le> x & x \\<le> b --> (%x. inverse(M - (f x))) x \\<le> k" 1);
  4.1792 -by (rtac isCont_bounded 2);
  4.1793 -by Safe_tac;
  4.1794 -by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> 0 < inverse(M - f(x))" 1);
  4.1795 -by (Asm_full_simp_tac 1);
  4.1796 -by Safe_tac;
  4.1797 -by (asm_full_simp_tac (simpset() addsimps [less_diff_eq]) 2);
  4.1798 -by (subgoal_tac
  4.1799 -    "\\<forall>x. a \\<le> x & x \\<le> b --> (%x. inverse(M - (f x))) x < (k + 1)" 1);
  4.1800 -by Safe_tac;
  4.1801 -by (res_inst_tac [("y","k")] order_le_less_trans 2);
  4.1802 -by (asm_full_simp_tac (simpset() addsimps [zero_less_one]) 3);
  4.1803 -by (Asm_full_simp_tac 2);
  4.1804 -by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> \
  4.1805 -\                inverse(k + 1) < inverse((%x. inverse(M - (f x))) x)" 1);
  4.1806 -by Safe_tac;
  4.1807 -by (rtac less_imp_inverse_less 2);
  4.1808 -by (ALLGOALS Asm_full_simp_tac);
  4.1809 -by (dres_inst_tac [("P", "%N. N<M --> ?Q N"),
  4.1810 -                   ("x","M - inverse(k + 1)")] spec 1);
  4.1811 -by (Step_tac 1 THEN dtac (linorder_not_less RS iffD1) 1);
  4.1812 -by (dtac (le_diff_eq RS iffD1) 1);
  4.1813 -by (REPEAT(dres_inst_tac [("x","a")] spec 1));
  4.1814 -by (Asm_full_simp_tac 1);
  4.1815 -by (asm_full_simp_tac
  4.1816 -    (simpset() addsimps [inverse_eq_divide, pos_divide_le_eq]) 1);
  4.1817 -by (cut_inst_tac [("a","k"),("b","M-f a")] zero_less_mult_iff 1);
  4.1818 -by (Asm_full_simp_tac 1);
  4.1819 -(*last one*)
  4.1820 -by (REPEAT(dres_inst_tac [("x","x")] spec 1));
  4.1821 -by (Asm_full_simp_tac 1);
  4.1822 -qed "isCont_eq_Ub";
  4.1823 -
  4.1824 -
  4.1825 -(*----------------------------------------------------------------------------*)
  4.1826 -(* Same theorem for lower bound                                               *)
  4.1827 -(*----------------------------------------------------------------------------*)
  4.1828 -
  4.1829 -Goal "[| a \\<le> b; \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x |] \
  4.1830 -\        ==> \\<exists>M. (\\<forall>x. a \\<le> x & x \\<le> b --> M \\<le> f(x)) & \
  4.1831 -\                  (\\<exists>x. a \\<le> x & x \\<le> b & f(x) = M)";
  4.1832 -by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> isCont (%x. -(f x)) x" 1);
  4.1833 -by (blast_tac (claset() addIs [isCont_minus]) 2);
  4.1834 -by (dres_inst_tac [("f","(%x. -(f x))")] isCont_eq_Ub 1);
  4.1835 -by Safe_tac;
  4.1836 -by Auto_tac;
  4.1837 -qed "isCont_eq_Lb";
  4.1838 -
  4.1839 -
  4.1840 -(* ------------------------------------------------------------------------- *)
  4.1841 -(* Another version.                                                          *)
  4.1842 -(* ------------------------------------------------------------------------- *)
  4.1843 -
  4.1844 -Goal "[|a \\<le> b; \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x |] \
  4.1845 -\     ==> \\<exists>L M. (\\<forall>x. a \\<le> x & x \\<le> b --> L \\<le> f(x) & f(x) \\<le> M) & \
  4.1846 -\         (\\<forall>y. L \\<le> y & y \\<le> M --> (\\<exists>x. a \\<le> x & x \\<le> b & (f(x) = y)))";
  4.1847 -by (ftac isCont_eq_Lb 1);
  4.1848 -by (ftac isCont_eq_Ub 2);
  4.1849 -by (REPEAT(assume_tac 1));
  4.1850 -by Safe_tac;
  4.1851 -by (res_inst_tac [("x","f x")] exI 1);
  4.1852 -by (res_inst_tac [("x","f xa")] exI 1);
  4.1853 -by (Asm_full_simp_tac 1);
  4.1854 -by Safe_tac;
  4.1855 -by (cut_inst_tac [("x","x"),("y","xa")] linorder_linear 1);
  4.1856 -by Safe_tac;
  4.1857 -by (cut_inst_tac [("f","f"),("a","x"),("b","xa"),("y","y")] IVT_objl 1);
  4.1858 -by (cut_inst_tac [("f","f"),("a","xa"),("b","x"),("y","y")] IVT2_objl 2);
  4.1859 -by Safe_tac;
  4.1860 -by (res_inst_tac [("x","xb")] exI 2);
  4.1861 -by (res_inst_tac [("x","xb")] exI 4);
  4.1862 -by (ALLGOALS(Asm_full_simp_tac));
  4.1863 -qed "isCont_Lb_Ub";
  4.1864 -
  4.1865 -(*----------------------------------------------------------------------------*)
  4.1866 -(* If f'(x) > 0 then x is locally strictly increasing at the right            *)
  4.1867 -(*----------------------------------------------------------------------------*)
  4.1868 -
  4.1869 -Goalw [deriv_def,LIM_def]
  4.1870 -    "[| DERIV f x :> l;  0 < l |] \
  4.1871 -\    ==> \\<exists>d. 0 < d & (\\<forall>h. 0 < h & h < d --> f(x) < f(x + h))";
  4.1872 -by (dtac spec 1 THEN Auto_tac);
  4.1873 -by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  4.1874 -by (subgoal_tac "0 < l*h" 1);
  4.1875 -by (asm_full_simp_tac (simpset() addsimps [zero_less_mult_iff]) 2);
  4.1876 -by (dres_inst_tac [("x","h")] spec 1);
  4.1877 -by (asm_full_simp_tac
  4.1878 -    (simpset() addsimps [real_abs_def, inverse_eq_divide,
  4.1879 -                 pos_le_divide_eq, pos_less_divide_eq]
  4.1880 -              addsplits [split_if_asm]) 1);
  4.1881 -qed "DERIV_left_inc";
  4.1882 -
  4.1883 -val prems = goalw (the_context()) [deriv_def,LIM_def]
  4.1884 -    "[| DERIV f x :> l;  l < 0 |] ==> \
  4.1885 -\      \\<exists>d. 0 < d & (\\<forall>h. 0 < h & h < d --> f(x) < f(x - h))";
  4.1886 -by (cut_facts_tac prems 1);  (*needed because arith removes the assumption l<0*)
  4.1887 -by (dres_inst_tac [("x","-l")] spec 1 THEN Auto_tac);
  4.1888 -by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  4.1889 -by (dres_inst_tac [("x","-h")] spec 1);
  4.1890 -by (asm_full_simp_tac
  4.1891 -    (simpset() addsimps [real_abs_def, inverse_eq_divide,
  4.1892 -                         pos_less_divide_eq,
  4.1893 -                         symmetric real_diff_def]
  4.1894 -               addsplits [split_if_asm]) 1);
  4.1895 -by (subgoal_tac "0 < (f (x - h) - f x)/h" 1);
  4.1896 -by (asm_full_simp_tac (simpset() addsimps [pos_less_divide_eq]) 1);
  4.1897 -by (cut_facts_tac prems 1);
  4.1898 -by (arith_tac 1);
  4.1899 -qed "DERIV_left_dec";
  4.1900 -
  4.1901 -(*????previous proof, revealing arith problem:
  4.1902 -by (dres_inst_tac [("x","-l")] spec 1 THEN Auto_tac);
  4.1903 -by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  4.1904 -by (subgoal_tac "l*h < 0" 1);
  4.1905 -by (asm_full_simp_tac (simpset() addsimps [mult_less_0_iff]) 2);
  4.1906 -by (dres_inst_tac [("x","-h")] spec 1);
  4.1907 -by (asm_full_simp_tac
  4.1908 -    (simpset() addsimps [real_abs_def, inverse_eq_divide,
  4.1909 -                         pos_less_divide_eq,
  4.1910 -                         symmetric real_diff_def]
  4.1911 -               addsplits [split_if_asm]
  4.1912 -               delsimprocs [fast_real_arith_simproc]) 1);
  4.1913 -by (subgoal_tac "0 < (f (x - h) - f x)/h" 1);
  4.1914 -by (arith_tac 2);
  4.1915 -by (asm_full_simp_tac
  4.1916 -    (simpset() addsimps [pos_less_divide_eq]) 1);
  4.1917 -qed "DERIV_left_dec";
  4.1918 -*)
  4.1919 -
  4.1920 -
  4.1921 -Goal "[| DERIV f x :> l; \
  4.1922 -\        \\<exists>d. 0 < d & (\\<forall>y. abs(x - y) < d --> f(y) \\<le> f(x)) |] \
  4.1923 -\     ==> l = 0";
  4.1924 -by (res_inst_tac [("x","l"),("y","0")] linorder_cases 1);
  4.1925 -by Safe_tac;
  4.1926 -by (dtac DERIV_left_dec 1);
  4.1927 -by (dtac DERIV_left_inc 3);
  4.1928 -by Safe_tac;
  4.1929 -by (dres_inst_tac [("d1.0","d"),("d2.0","da")] real_lbound_gt_zero 1);
  4.1930 -by (dres_inst_tac [("d1.0","d"),("d2.0","da")] real_lbound_gt_zero 3);
  4.1931 -by Safe_tac;
  4.1932 -by (dres_inst_tac [("x","x - e")] spec 1);
  4.1933 -by (dres_inst_tac [("x","x + e")] spec 2);
  4.1934 -by (auto_tac (claset(), simpset() addsimps [real_abs_def]));
  4.1935 -qed "DERIV_local_max";
  4.1936 -
  4.1937 -(*----------------------------------------------------------------------------*)
  4.1938 -(* Similar theorem for a local minimum                                        *)
  4.1939 -(*----------------------------------------------------------------------------*)
  4.1940 -
  4.1941 -Goal "[| DERIV f x :> l; \
  4.1942 -\        \\<exists>d::real. 0 < d & (\\<forall>y. abs(x - y) < d --> f(x) \\<le> f(y)) |] \
  4.1943 -\     ==> l = 0";
  4.1944 -by (dtac (DERIV_minus RS DERIV_local_max) 1);
  4.1945 -by Auto_tac;
  4.1946 -qed "DERIV_local_min";
  4.1947 -
  4.1948 -(*----------------------------------------------------------------------------*)
  4.1949 -(* In particular if a function is locally flat                                *)
  4.1950 -(*----------------------------------------------------------------------------*)
  4.1951 -
  4.1952 -Goal "[| DERIV f x :> l; \
  4.1953 -\        \\<exists>d. 0 < d & (\\<forall>y. abs(x - y) < d --> f(x) = f(y)) |] \
  4.1954 -\     ==> l = 0";
  4.1955 -by (auto_tac (claset() addSDs [DERIV_local_max],simpset()));
  4.1956 -qed "DERIV_local_const";
  4.1957 -
  4.1958 -(*----------------------------------------------------------------------------*)
  4.1959 -(* Lemma about introducing open ball in open interval                         *)
  4.1960 -(*----------------------------------------------------------------------------*)
  4.1961 -
  4.1962 -Goal "[| a < x;  x < b |] ==> \
  4.1963 -\       \\<exists>d::real. 0 < d &  (\\<forall>y. abs(x - y) < d --> a < y & y < b)";
  4.1964 -by (simp_tac (simpset() addsimps [abs_interval_iff]) 1);
  4.1965 -by (cut_inst_tac [("x","x - a"),("y","b - x")] linorder_linear 1);
  4.1966 -by Safe_tac;
  4.1967 -by (res_inst_tac [("x","x - a")] exI 1);
  4.1968 -by (res_inst_tac [("x","b - x")] exI 2);
  4.1969 -by Auto_tac;
  4.1970 -by (auto_tac (claset(),simpset() addsimps [less_diff_eq]));
  4.1971 -qed "lemma_interval_lt";
  4.1972 -
  4.1973 -Goal "[| a < x;  x < b |] ==> \
  4.1974 -\       \\<exists>d::real. 0 < d &  (\\<forall>y. abs(x - y) < d --> a \\<le> y & y \\<le> b)";
  4.1975 -by (dtac lemma_interval_lt 1);
  4.1976 -by Auto_tac;
  4.1977 -by (auto_tac (claset() addSIs [exI] ,simpset()));
  4.1978 -qed "lemma_interval";
  4.1979 -
  4.1980 -(*-----------------------------------------------------------------------
  4.1981 -            Rolle's Theorem
  4.1982 -   If f is defined and continuous on the finite closed interval [a,b]
  4.1983 -   and differentiable a least on the open interval (a,b), and f(a) = f(b),
  4.1984 -   then x0 \\<in> (a,b) such that f'(x0) = 0
  4.1985 - ----------------------------------------------------------------------*)
  4.1986 -
  4.1987 -Goal "[| a < b; f(a) = f(b); \
  4.1988 -\        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  4.1989 -\        \\<forall>x. a < x & x < b --> f differentiable x \
  4.1990 -\     |] ==> \\<exists>z. a < z & z < b & DERIV f z :> 0";
  4.1991 -by (ftac (order_less_imp_le RS isCont_eq_Ub) 1);
  4.1992 -by (EVERY1[assume_tac,Step_tac]);
  4.1993 -by (ftac (order_less_imp_le RS isCont_eq_Lb) 1);
  4.1994 -by (EVERY1[assume_tac,Step_tac]);
  4.1995 -by (case_tac "a < x & x < b" 1 THEN etac conjE 1);
  4.1996 -by (Asm_full_simp_tac 2);
  4.1997 -by (forw_inst_tac [("a","a"),("x","x")] lemma_interval 1);
  4.1998 -by (EVERY1[assume_tac,etac exE]);
  4.1999 -by (res_inst_tac [("x","x")] exI 1 THEN Asm_full_simp_tac 1);
  4.2000 -by (subgoal_tac "(\\<exists>l. DERIV f x :> l) & \
  4.2001 -\        (\\<exists>d. 0 < d & (\\<forall>y. abs(x - y) < d --> f(y) \\<le> f(x)))" 1);
  4.2002 -by (Clarify_tac 1 THEN rtac conjI 2);
  4.2003 -by (blast_tac (claset() addIs [differentiableD]) 2);
  4.2004 -by (Blast_tac 2);
  4.2005 -by (ftac DERIV_local_max 1);
  4.2006 -by (EVERY1[Blast_tac,Blast_tac]);
  4.2007 -by (case_tac "a < xa & xa < b" 1 THEN etac conjE 1);
  4.2008 -by (Asm_full_simp_tac 2);
  4.2009 -by (forw_inst_tac [("a","a"),("x","xa")] lemma_interval 1);
  4.2010 -by (EVERY1[assume_tac,etac exE]);
  4.2011 -by (res_inst_tac [("x","xa")] exI 1 THEN Asm_full_simp_tac 1);
  4.2012 -by (subgoal_tac "(\\<exists>l. DERIV f xa :> l) & \
  4.2013 -\        (\\<exists>d. 0 < d & (\\<forall>y. abs(xa - y) < d --> f(xa) \\<le> f(y)))" 1);
  4.2014 -by (Clarify_tac 1 THEN rtac conjI 2);
  4.2015 -by (blast_tac (claset() addIs [differentiableD]) 2);
  4.2016 -by (Blast_tac 2);
  4.2017 -by (ftac DERIV_local_min 1);
  4.2018 -by (EVERY1[Blast_tac,Blast_tac]);
  4.2019 -by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> f(x) = f(b)" 1);
  4.2020 -by (Clarify_tac 2);
  4.2021 -by (rtac real_le_anti_sym 2);
  4.2022 -by (subgoal_tac "f b = f x" 2);
  4.2023 -by (Asm_full_simp_tac 2);
  4.2024 -by (res_inst_tac [("x1","a"),("y1","x")] (order_le_imp_less_or_eq RS disjE) 2);
  4.2025 -by (assume_tac 2);
  4.2026 -by (dres_inst_tac [("z","x"),("w","b")] real_le_anti_sym 2);
  4.2027 -by (subgoal_tac "f b = f xa" 5);
  4.2028 -by (Asm_full_simp_tac 5);
  4.2029 -by (res_inst_tac [("x1","a"),("y1","xa")] (order_le_imp_less_or_eq RS disjE) 5);
  4.2030 -by (assume_tac 5);
  4.2031 -by (dres_inst_tac [("z","xa"),("w","b")] real_le_anti_sym 5);
  4.2032 -by (REPEAT(Asm_full_simp_tac 2));
  4.2033 -by (dtac real_dense 1 THEN etac exE 1);
  4.2034 -by (res_inst_tac [("x","r")] exI 1 THEN Asm_simp_tac 1);
  4.2035 -by (etac conjE 1);
  4.2036 -by (forw_inst_tac [("a","a"),("x","r")] lemma_interval 1);
  4.2037 -by (EVERY1[assume_tac, etac exE]);
  4.2038 -by (subgoal_tac "(\\<exists>l. DERIV f r :> l) & \
  4.2039 -\        (\\<exists>d. 0 < d & (\\<forall>y. abs(r - y) < d --> f(r) = f(y)))" 1);
  4.2040 -by (Clarify_tac 1 THEN rtac conjI 2);
  4.2041 -by (blast_tac (claset() addIs [differentiableD]) 2);
  4.2042 -by (EVERY1[ftac DERIV_local_const, Blast_tac, Blast_tac]);
  4.2043 -by (res_inst_tac [("x","d")] exI 1);
  4.2044 -by (EVERY1[rtac conjI, Blast_tac, rtac allI, rtac impI]);
  4.2045 -by (res_inst_tac [("s","f b")] trans 1);
  4.2046 -by (blast_tac (claset() addSDs [order_less_imp_le]) 1);
  4.2047 -by (rtac sym 1 THEN Blast_tac 1);
  4.2048 -qed "Rolle";
  4.2049 -
  4.2050 -(*----------------------------------------------------------------------------*)
  4.2051 -(* Mean value theorem                                                         *)
  4.2052 -(*----------------------------------------------------------------------------*)
  4.2053 -
  4.2054 -Goal "f a - (f b - f a)/(b - a) * a = \
  4.2055 -\     f b - (f b - f a)/(b - a) * (b::real)";
  4.2056 -by (case_tac "a = b" 1);
  4.2057 -by (Asm_full_simp_tac 1);
  4.2058 -by (res_inst_tac [("c1","b - a")] (real_mult_left_cancel RS iffD1) 1);
  4.2059 -by (arith_tac 1);
  4.2060 -by (auto_tac (claset(), simpset() addsimps [right_diff_distrib]));
  4.2061 -by (auto_tac (claset(), simpset() addsimps [left_diff_distrib]));
  4.2062 -qed "lemma_MVT";
  4.2063 -
  4.2064 -Goal "[| a < b; \
  4.2065 -\        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  4.2066 -\        \\<forall>x. a < x & x < b --> f differentiable x |] \
  4.2067 -\     ==>  \\<exists>l z. a < z & z < b & DERIV f z :> l & \
  4.2068 -\                  (f(b) - f(a) = (b - a) * l)";
  4.2069 -by (dres_inst_tac [("f","%x. f(x) - (((f(b) - f(a)) / (b - a)) * x)")]
  4.2070 -    Rolle 1);
  4.2071 -by (rtac lemma_MVT 1);
  4.2072 -by Safe_tac;
  4.2073 -by (rtac isCont_diff 1 THEN Blast_tac 1);
  4.2074 -by (rtac (isCont_const RS isCont_mult) 1);
  4.2075 -by (rtac isCont_Id 1);
  4.2076 -by (dres_inst_tac [("P", "%x. ?Pre x --> f differentiable x"),
  4.2077 -                   ("x","x")] spec 1);
  4.2078 -by (asm_full_simp_tac (simpset() addsimps [differentiable_def]) 1);
  4.2079 -by Safe_tac;
  4.2080 -by (res_inst_tac [("x","xa - ((f(b) - f(a)) / (b - a))")] exI 1);
  4.2081 -by (rtac DERIV_diff 1 THEN assume_tac 1);
  4.2082 -(*derivative of a linear function is the constant...*)
  4.2083 -by (subgoal_tac "(%x. (f b - f a) * x / (b - a)) = \
  4.2084 -\                op * ((f b - f a) / (b - a))" 1);
  4.2085 -by (rtac ext 2 THEN Simp_tac 2);
  4.2086 -by (Asm_full_simp_tac 1);
  4.2087 -(*final case*)
  4.2088 -by (res_inst_tac [("x","((f(b) - f(a)) / (b - a))")] exI 1);
  4.2089 -by (res_inst_tac [("x","z")] exI 1);
  4.2090 -by Safe_tac;
  4.2091 -by (Asm_full_simp_tac 2);
  4.2092 -by (subgoal_tac "DERIV (%x. ((f(b) - f(a)) / (b - a)) * x) z :> \
  4.2093 -\                           ((f(b) - f(a)) / (b - a))" 1);
  4.2094 -by (rtac DERIV_cmult_Id 2);
  4.2095 -by (dtac DERIV_add 1 THEN assume_tac 1);
  4.2096 -by (asm_full_simp_tac (simpset() addsimps [real_add_assoc, real_diff_def]) 1);
  4.2097 -qed "MVT";
  4.2098 -
  4.2099 -(*----------------------------------------------------------------------------*)
  4.2100 -(* Theorem that function is constant if its derivative is 0 over an interval. *)
  4.2101 -(*----------------------------------------------------------------------------*)
  4.2102 -
  4.2103 -Goal "[| a < b; \
  4.2104 -\        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  4.2105 -\        \\<forall>x. a < x & x < b --> DERIV f x :> 0 |] \
  4.2106 -\       ==> (f b = f a)";
  4.2107 -by (dtac MVT 1 THEN assume_tac 1);
  4.2108 -by (blast_tac (claset() addIs [differentiableI]) 1);
  4.2109 -by (auto_tac (claset() addSDs [DERIV_unique],simpset()
  4.2110 -    addsimps [diff_eq_eq]));
  4.2111 -qed "DERIV_isconst_end";
  4.2112 -
  4.2113 -Goal "[| a < b; \
  4.2114 -\        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  4.2115 -\        \\<forall>x. a < x & x < b --> DERIV f x :> 0 |] \
  4.2116 -\       ==> \\<forall>x. a \\<le> x & x \\<le> b --> f x = f a";
  4.2117 -by Safe_tac;
  4.2118 -by (dres_inst_tac [("x","a")] order_le_imp_less_or_eq 1);
  4.2119 -by Safe_tac;
  4.2120 -by (dres_inst_tac [("b","x")] DERIV_isconst_end 1);
  4.2121 -by Auto_tac;
  4.2122 -qed "DERIV_isconst1";
  4.2123 -
  4.2124 -Goal "[| a < b; \
  4.2125 -\        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  4.2126 -\        \\<forall>x. a < x & x < b --> DERIV f x :> 0; \
  4.2127 -\        a \\<le> x; x \\<le> b |] \
  4.2128 -\       ==> f x = f a";
  4.2129 -by (blast_tac (claset() addDs [DERIV_isconst1]) 1);
  4.2130 -qed "DERIV_isconst2";
  4.2131 -
  4.2132 -Goal "\\<forall>x. DERIV f x :> 0 ==> f(x) = f(y)";
  4.2133 -by (res_inst_tac [("x","x"),("y","y")] linorder_cases 1);
  4.2134 -by (rtac sym 1);
  4.2135 -by (auto_tac (claset() addIs [DERIV_isCont,DERIV_isconst_end],simpset()));
  4.2136 -qed "DERIV_isconst_all";
  4.2137 -
  4.2138 -Goal "[|a \\<noteq> b; \\<forall>x. DERIV f x :> k |] ==> (f(b) - f(a)) = (b - a) * k";
  4.2139 -by (res_inst_tac [("x","a"),("y","b")] linorder_cases 1);
  4.2140 -by Auto_tac;
  4.2141 -by (ALLGOALS(dres_inst_tac [("f","f")] MVT));
  4.2142 -by (auto_tac (claset() addDs [DERIV_isCont,DERIV_unique],simpset() addsimps
  4.2143 -    [differentiable_def]));
  4.2144 -by (auto_tac (claset() addDs [DERIV_unique],
  4.2145 -       simpset() addsimps [left_distrib, real_diff_def]));
  4.2146 -qed "DERIV_const_ratio_const";
  4.2147 -
  4.2148 -Goal "[|a \\<noteq> b; \\<forall>x. DERIV f x :> k |] ==> (f(b) - f(a))/(b - a) = k";
  4.2149 -by (res_inst_tac [("c1","b - a")] (real_mult_right_cancel RS iffD1) 1);
  4.2150 -by (auto_tac (claset() addSDs [DERIV_const_ratio_const],
  4.2151 -              simpset() addsimps [real_mult_assoc]));
  4.2152 -qed "DERIV_const_ratio_const2";
  4.2153 -
  4.2154 -Goal "((a + b) /2 - a) = (b - a)/(2::real)";
  4.2155 -by Auto_tac;
  4.2156 -qed "real_average_minus_first";
  4.2157 -Addsimps [real_average_minus_first];
  4.2158 -
  4.2159 -Goal "((b + a)/2 - a) = (b - a)/(2::real)";
  4.2160 -by Auto_tac;
  4.2161 -qed "real_average_minus_second";
  4.2162 -Addsimps [real_average_minus_second];
  4.2163 -
  4.2164 -
  4.2165 -(* Gallileo's "trick": average velocity = av. of end velocities *)
  4.2166 -Goal "[|a \\<noteq> (b::real); \\<forall>x. DERIV v x :> k|] \
  4.2167 -\     ==> v((a + b)/2) = (v a + v b)/2";
  4.2168 -by (res_inst_tac [("x","a"),("y","b")] linorder_cases 1);
  4.2169 -by Safe_tac;
  4.2170 -by (ftac DERIV_const_ratio_const2 1 THEN assume_tac 1);
  4.2171 -by (ftac DERIV_const_ratio_const2 2 THEN assume_tac 2);
  4.2172 -by (dtac real_less_half_sum 1);
  4.2173 -by (dtac real_gt_half_sum 2);
  4.2174 -by (ftac (real_not_refl2 RS DERIV_const_ratio_const2) 1 THEN assume_tac 1);
  4.2175 -by (dtac ((real_not_refl2 RS not_sym) RS DERIV_const_ratio_const2) 2
  4.2176 -    THEN assume_tac 2);
  4.2177 -by (ALLGOALS (dres_inst_tac [("f","%u. (b-a)*u")] arg_cong));
  4.2178 -by (auto_tac (claset(), simpset() addsimps [inverse_eq_divide]));
  4.2179 -by (asm_full_simp_tac (simpset() addsimps [real_add_commute, eq_commute]) 1);
  4.2180 -qed "DERIV_const_average";
  4.2181 -
  4.2182 -
  4.2183 -(* ------------------------------------------------------------------------ *)
  4.2184 -(* Dull lemma that an continuous injection on an interval must have a strict*)
  4.2185 -(* maximum at an end point, not in the middle.                              *)
  4.2186 -(* ------------------------------------------------------------------------ *)
  4.2187 -
  4.2188 -Goal "[|0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  4.2189 -\       \\<forall>z. abs(z - x) \\<le> d --> isCont f z |]  \
  4.2190 -\     ==> ~(\\<forall>z. abs(z - x) \\<le> d --> f(z) \\<le> f(x))";
  4.2191 -by (rtac notI 1);
  4.2192 -by (rotate_tac 3 1);
  4.2193 -by (forw_inst_tac [("x","x - d")] spec 1);
  4.2194 -by (forw_inst_tac [("x","x + d")] spec 1);
  4.2195 -by Safe_tac;
  4.2196 -by (cut_inst_tac [("x","f(x - d)"),("y","f(x + d)")]
  4.2197 -    (ARITH_PROVE "x \\<le> y | y \\<le> (x::real)") 4);
  4.2198 -by (etac disjE 4);
  4.2199 -by (REPEAT(arith_tac 1));
  4.2200 -by (cut_inst_tac [("f","f"),("a","x - d"),("b","x"),("y","f(x + d)")]
  4.2201 -    IVT_objl 1);
  4.2202 -by Safe_tac;
  4.2203 -by (arith_tac 1);
  4.2204 -by (asm_full_simp_tac (simpset() addsimps [abs_le_interval_iff]) 1);
  4.2205 -by (dres_inst_tac [("f","g")] arg_cong 1);
  4.2206 -by (rotate_tac 2 1);
  4.2207 -by (forw_inst_tac [("x","xa")] spec 1);
  4.2208 -by (dres_inst_tac [("x","x + d")] spec 1);
  4.2209 -by (asm_full_simp_tac (simpset() addsimps [abs_le_interval_iff]) 1);
  4.2210 -(* 2nd case: similar *)
  4.2211 -by (cut_inst_tac [("f","f"),("a","x"),("b","x + d"),("y","f(x - d)")]
  4.2212 -    IVT2_objl 1);
  4.2213 -by Safe_tac;
  4.2214 -by (arith_tac 1);
  4.2215 -by (asm_full_simp_tac (simpset() addsimps [abs_le_interval_iff]) 1);
  4.2216 -by (dres_inst_tac [("f","g")] arg_cong 1);
  4.2217 -by (rotate_tac 2 1);
  4.2218 -by (forw_inst_tac [("x","xa")] spec 1);
  4.2219 -by (dres_inst_tac [("x","x - d")] spec 1);
  4.2220 -by (asm_full_simp_tac (simpset() addsimps [abs_le_interval_iff]) 1);
  4.2221 -qed "lemma_isCont_inj";
  4.2222 -
  4.2223 -(* ------------------------------------------------------------------------ *)
  4.2224 -(* Similar version for lower bound                                          *)
  4.2225 -(* ------------------------------------------------------------------------ *)
  4.2226 -
  4.2227 -Goal "[|0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  4.2228 -\       \\<forall>z. abs(z - x) \\<le> d --> isCont f z |]  \
  4.2229 -\     ==> ~(\\<forall>z. abs(z - x) \\<le> d --> f(x) \\<le> f(z))";
  4.2230 -by (auto_tac (claset() addSDs [(asm_full_simplify (simpset())
  4.2231 -    (read_instantiate [("f","%x. - f x"),("g","%y. g(-y)"),("x","x"),("d","d")]
  4.2232 -     lemma_isCont_inj))],simpset() addsimps [isCont_minus]));
  4.2233 -qed "lemma_isCont_inj2";
  4.2234 -
  4.2235 -(* ------------------------------------------------------------------------ *)
  4.2236 -(* Show there's an interval surrounding f(x) in f[[x - d, x + d]]           *)
  4.2237 -(* Also from John's theory                                                  *)
  4.2238 -(* ------------------------------------------------------------------------ *)
  4.2239 -
  4.2240 -val lemma_le = ARITH_PROVE "0 \\<le> (d::real) ==> -d \\<le> d";
  4.2241 -
  4.2242 -(* FIXME: awful proof - needs improvement *)
  4.2243 -Goal "[| 0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  4.2244 -\        \\<forall>z. abs(z - x) \\<le> d --> isCont f z |] \
  4.2245 -\      ==> \\<exists>e. 0 < e & \
  4.2246 -\                 (\\<forall>y. \
  4.2247 -\                     abs(y - f(x)) \\<le> e --> \
  4.2248 -\                     (\\<exists>z. abs(z - x) \\<le> d & (f z = y)))";
  4.2249 -by (ftac order_less_imp_le 1);
  4.2250 -by (dtac (lemma_le RS (asm_full_simplify (simpset()) (read_instantiate
  4.2251 -    [("f","f"),("a","x - d"),("b","x + d")] isCont_Lb_Ub))) 1);
  4.2252 -by Safe_tac;
  4.2253 -by (asm_full_simp_tac (simpset() addsimps [abs_le_interval_iff]) 1);
  4.2254 -by (subgoal_tac "L \\<le> f x & f x \\<le> M" 1);
  4.2255 -by (dres_inst_tac [("P", "%v. ?P v --> ?Q v & ?R v"), ("x","x")] spec 2);
  4.2256 -by (Asm_full_simp_tac 2);
  4.2257 -by (subgoal_tac "L < f x & f x < M" 1);
  4.2258 -by Safe_tac;
  4.2259 -by (dres_inst_tac [("x","L")] (ARITH_PROVE "x < y ==> 0 < y - (x::real)") 1);
  4.2260 -by (dres_inst_tac [("x","f x")] (ARITH_PROVE "x < y ==> 0 < y - (x::real)") 1);
  4.2261 -by (dres_inst_tac [("d1.0","f x - L"),("d2.0","M - f x")]
  4.2262 -    (real_lbound_gt_zero) 1);
  4.2263 -by Safe_tac;
  4.2264 -by (res_inst_tac [("x","e")] exI 1);
  4.2265 -by Safe_tac;
  4.2266 -by (asm_full_simp_tac (simpset() addsimps [abs_le_interval_iff]) 1);
  4.2267 -by (dres_inst_tac [("P","%v. ?PP v --> (\\<exists>xa. ?Q v xa)"),("x","y")] spec 1);
  4.2268 -by (Step_tac 1 THEN REPEAT(arith_tac 1));
  4.2269 -by (res_inst_tac [("x","xa")] exI 1);
  4.2270 -by (arith_tac 1);
  4.2271 -by (ALLGOALS(etac (ARITH_PROVE "[|x \\<le> y; x \\<noteq> y |] ==> x < (y::real)")));
  4.2272 -by (ALLGOALS(rotate_tac 3));
  4.2273 -by (dtac lemma_isCont_inj2 1);
  4.2274 -by (assume_tac 2);
  4.2275 -by (dtac lemma_isCont_inj 3);
  4.2276 -by (assume_tac 4);
  4.2277 -by (TRYALL(assume_tac));
  4.2278 -by Safe_tac;
  4.2279 -by (ALLGOALS(dres_inst_tac [("x","z")] spec));
  4.2280 -by (ALLGOALS(arith_tac));
  4.2281 -qed "isCont_inj_range";
  4.2282 -
  4.2283 -
  4.2284 -(* ------------------------------------------------------------------------ *)
  4.2285 -(* Continuity of inverse function                                           *)
  4.2286 -(* ------------------------------------------------------------------------ *)
  4.2287 -
  4.2288 -Goal "[| 0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f(z)) = z; \
  4.2289 -\        \\<forall>z. abs(z - x) \\<le> d --> isCont f z |] \
  4.2290 -\     ==> isCont g (f x)";
  4.2291 -by (simp_tac (simpset() addsimps [isCont_iff,LIM_def]) 1);
  4.2292 -by Safe_tac;
  4.2293 -by (dres_inst_tac [("d1.0","r")] (real_lbound_gt_zero) 1);
  4.2294 -by (assume_tac 1 THEN Step_tac 1);
  4.2295 -by (subgoal_tac "\\<forall>z. abs(z - x) \\<le> e --> (g(f z) = z)" 1);
  4.2296 -by (Force_tac 2);
  4.2297 -by (subgoal_tac "\\<forall>z. abs(z - x) \\<le> e --> isCont f z" 1);
  4.2298 -by (Force_tac 2);
  4.2299 -by (dres_inst_tac [("d","e")] isCont_inj_range 1);
  4.2300 -by (assume_tac 2 THEN assume_tac 1);
  4.2301 -by Safe_tac;
  4.2302 -by (res_inst_tac [("x","ea")] exI 1);
  4.2303 -by Auto_tac;
  4.2304 -by (rotate_tac 4 1);
  4.2305 -by (dres_inst_tac [("x","f(x) + xa")] spec 1);
  4.2306 -by Auto_tac;
  4.2307 -by (dtac sym 1 THEN Auto_tac);
  4.2308 -by (arith_tac 1);
  4.2309 -qed "isCont_inverse_function";
  4.2310 -
     5.1 --- a/src/HOL/Hyperreal/Lim.thy	Fri Mar 19 10:50:06 2004 +0100
     5.2 +++ b/src/HOL/Hyperreal/Lim.thy	Fri Mar 19 10:51:03 2004 +0100
     5.3 @@ -1,66 +1,67 @@
     5.4  (*  Title       : Lim.thy
     5.5 +    ID          : $Id$
     5.6      Author      : Jacques D. Fleuriot
     5.7      Copyright   : 1998  University of Cambridge
     5.8 -    Description : Theory of limits, continuity and 
     5.9 -                  differentiation of real=>real functions
    5.10 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
    5.11  *)
    5.12  
    5.13 -Lim = SEQ + RealDef + 
    5.14 +header{*Limits, Continuity and Differentiation*}
    5.15  
    5.16 -(*-----------------------------------------------------------------------
    5.17 -    Limits, continuity and differentiation: standard and NS definitions
    5.18 - -----------------------------------------------------------------------*)
    5.19 +theory Lim = SEQ + RealDef:
    5.20 +
    5.21 +text{*Standard and Nonstandard Definitions*}
    5.22  
    5.23  constdefs
    5.24 -  LIM :: [real=>real,real,real] => bool
    5.25 +  LIM :: "[real=>real,real,real] => bool"
    5.26  				("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    5.27    "f -- a --> L ==
    5.28 -     ALL r. 0 < r --> 
    5.29 -	     (EX s. 0 < s & (ALL x. (x ~= a & (abs(x + -a) < s)
    5.30 -			  --> abs(f x + -L) < r)))"
    5.31 +     \<forall>r. 0 < r -->
    5.32 +	     (\<exists>s. 0 < s & (\<forall>x. (x \<noteq> a & (\<bar>x + -a\<bar> < s)
    5.33 +			  --> \<bar>f x + -L\<bar> < r)))"
    5.34  
    5.35 -  NSLIM :: [real=>real,real,real] => bool
    5.36 +  NSLIM :: "[real=>real,real,real] => bool"
    5.37  			      ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    5.38 -  "f -- a --NS> L == (ALL x. (x ~= hypreal_of_real a & 
    5.39 +  "f -- a --NS> L == (\<forall>x. (x \<noteq> hypreal_of_real a &
    5.40  		      x @= hypreal_of_real a -->
    5.41 -		      ( *f* f) x @= hypreal_of_real L))"   
    5.42 +		      ( *f* f) x @= hypreal_of_real L))"
    5.43  
    5.44 -  isCont :: [real=>real,real] => bool
    5.45 -  "isCont f a == (f -- a --> (f a))"        
    5.46 +  isCont :: "[real=>real,real] => bool"
    5.47 +  "isCont f a == (f -- a --> (f a))"
    5.48  
    5.49    (* NS definition dispenses with limit notions *)
    5.50 -  isNSCont :: [real=>real,real] => bool
    5.51 -  "isNSCont f a == (ALL y. y @= hypreal_of_real a --> 
    5.52 +  isNSCont :: "[real=>real,real] => bool"
    5.53 +  "isNSCont f a == (\<forall>y. y @= hypreal_of_real a -->
    5.54  			   ( *f* f) y @= hypreal_of_real (f a))"
    5.55  
    5.56    (* differentiation: D is derivative of function f at x *)
    5.57 -  deriv:: [real=>real,real,real] => bool
    5.58 +  deriv:: "[real=>real,real,real] => bool"
    5.59  			    ("(DERIV (_)/ (_)/ :> (_))" [60, 0, 60] 60)
    5.60 -  "DERIV f x :> D == ((%h. (f(x + h) + -f(x))/h) -- 0 --> D)"
    5.61 +  "DERIV f x :> D == ((%h. (f(x + h) + -f x)/h) -- 0 --> D)"
    5.62  
    5.63 -  nsderiv :: [real=>real,real,real] => bool
    5.64 +  nsderiv :: "[real=>real,real,real] => bool"
    5.65  			    ("(NSDERIV (_)/ (_)/ :> (_))" [60, 0, 60] 60)
    5.66 -  "NSDERIV f x :> D == (ALL h: Infinitesimal - {0}. 
    5.67 -			(( *f* f)(hypreal_of_real x + h) + 
    5.68 +  "NSDERIV f x :> D == (\<forall>h \<in> Infinitesimal - {0}.
    5.69 +			(( *f* f)(hypreal_of_real x + h) +
    5.70  			 - hypreal_of_real (f x))/h @= hypreal_of_real D)"
    5.71  
    5.72 -  differentiable :: [real=>real,real] => bool   (infixl 60)
    5.73 -  "f differentiable x == (EX D. DERIV f x :> D)"
    5.74 +  differentiable :: "[real=>real,real] => bool"   (infixl "differentiable" 60)
    5.75 +  "f differentiable x == (\<exists>D. DERIV f x :> D)"
    5.76  
    5.77 -  NSdifferentiable :: [real=>real,real] => bool   (infixl 60)
    5.78 -  "f NSdifferentiable x == (EX D. NSDERIV f x :> D)"
    5.79 +  NSdifferentiable :: "[real=>real,real] => bool"   
    5.80 +                       (infixl "NSdifferentiable" 60)
    5.81 +  "f NSdifferentiable x == (\<exists>D. NSDERIV f x :> D)"
    5.82  
    5.83 -  increment :: [real=>real,real,hypreal] => hypreal
    5.84 -  "increment f x h == (@inc. f NSdifferentiable x & 
    5.85 +  increment :: "[real=>real,real,hypreal] => hypreal"
    5.86 +  "increment f x h == (@inc. f NSdifferentiable x &
    5.87  		       inc = ( *f* f)(hypreal_of_real x + h) + -hypreal_of_real (f x))"
    5.88  
    5.89 -  isUCont :: (real=>real) => bool
    5.90 -  "isUCont f ==  (ALL r. 0 < r --> 
    5.91 -		      (EX s. 0 < s & (ALL x y. abs(x + -y) < s
    5.92 -			    --> abs(f x + -f y) < r)))"
    5.93 +  isUCont :: "(real=>real) => bool"
    5.94 +  "isUCont f ==  (\<forall>r. 0 < r -->
    5.95 +		      (\<exists>s. 0 < s & (\<forall>x y. \<bar>x + -y\<bar> < s
    5.96 +			    --> \<bar>f x + -f y\<bar> < r)))"
    5.97  
    5.98 -  isNSUCont :: (real=>real) => bool
    5.99 -  "isNSUCont f == (ALL x y. x @= y --> ( *f* f) x @= ( *f* f) y)"
   5.100 +  isNSUCont :: "(real=>real) => bool"
   5.101 +  "isNSUCont f == (\<forall>x y. x @= y --> ( *f* f) x @= ( *f* f) y)"
   5.102  
   5.103  
   5.104  (*Used in the proof of the Bolzano theorem*)
   5.105 @@ -72,8 +73,2258 @@
   5.106    "Bolzano_bisect P a b (Suc n) =
   5.107        (let (x,y) = Bolzano_bisect P a b n
   5.108         in if P(x, (x+y)/2) then ((x+y)/2, y)
   5.109 -                            else (x, (x+y)/2) )"
   5.110 -  
   5.111 +                            else (x, (x+y)/2))"
   5.112 +
   5.113 +
   5.114 +
   5.115 +section{*Some Purely Standard Proofs*}
   5.116 +
   5.117 +lemma LIM_eq:
   5.118 +     "f -- a --> L =
   5.119 +     (\<forall>r. 0<r --> (\<exists>s. 0 < s & (\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)))"
   5.120 +by (simp add: LIM_def diff_minus)
   5.121 +
   5.122 +lemma LIM_D:
   5.123 +     "[| f -- a --> L; 0<r |]
   5.124 +      ==> \<exists>s. 0 < s & (\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)"
   5.125 +by (simp add: LIM_eq)
   5.126 +
   5.127 +lemma LIM_const: "(%x. k) -- x --> k"
   5.128 +by (simp add: LIM_def)
   5.129 +declare LIM_const [simp]
   5.130 +
   5.131 +lemma LIM_add:
   5.132 +  assumes f: "f -- a --> L" and g: "g -- a --> M"
   5.133 +  shows "(%x. f x + g(x)) -- a --> (L + M)"
   5.134 +proof (simp add: LIM_eq, clarify)
   5.135 +  fix r :: real
   5.136 +  assume r: "0<r"
   5.137 +  from LIM_D [OF f half_gt_zero [OF r]]
   5.138 +  obtain fs
   5.139 +    where fs:    "0 < fs"
   5.140 +      and fs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < fs --> \<bar>f x - L\<bar> < r/2"
   5.141 +  by blast
   5.142 +  from LIM_D [OF g half_gt_zero [OF r]]
   5.143 +  obtain gs
   5.144 +    where gs:    "0 < gs"
   5.145 +      and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> \<bar>g x - M\<bar> < r/2"
   5.146 +  by blast
   5.147 +  show "\<exists>s. 0 < s \<and>
   5.148 +            (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>f x + g x - (L + M)\<bar> < r)"
   5.149 +  proof (intro exI conjI strip)
   5.150 +    show "0 < min fs gs"  by (simp add: fs gs)
   5.151 +    fix x :: real
   5.152 +    assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   5.153 +    with fs_lt gs_lt
   5.154 +    have "\<bar>f x - L\<bar> < r/2" and "\<bar>g x - M\<bar> < r/2" by (auto simp add: fs_lt)
   5.155 +    hence "\<bar>f x - L\<bar> + \<bar>g x - M\<bar> < r" by arith
   5.156 +    thus "\<bar>f x + g x - (L + M)\<bar> < r"
   5.157 +      by (blast intro: abs_diff_triangle_ineq order_le_less_trans)
   5.158 +  qed
   5.159 +qed
   5.160 +
   5.161 +lemma LIM_minus: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
   5.162 +apply (simp add: LIM_eq)
   5.163 +apply (subgoal_tac "\<forall>x. \<bar>- f x + L\<bar> = \<bar>f x - L\<bar>")
   5.164 +apply (simp_all add: abs_if)
   5.165 +done
   5.166 +
   5.167 +lemma LIM_add_minus:
   5.168 +    "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   5.169 +by (blast dest: LIM_add LIM_minus)
   5.170 +
   5.171 +lemma LIM_diff:
   5.172 +    "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
   5.173 +by (simp add: diff_minus LIM_add_minus) 
   5.174 +
   5.175 +
   5.176 +lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   5.177 +proof (simp add: linorder_neq_iff LIM_eq, elim disjE)
   5.178 +  assume k: "k < L"
   5.179 +  show "\<exists>r. 0 < r \<and>
   5.180 +        (\<forall>s. 0 < s \<longrightarrow> (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r)"
   5.181 +  proof (intro exI conjI strip)
   5.182 +    show "0 < L-k" by (simp add: k)
   5.183 +    fix s :: real
   5.184 +    assume s: "0<s"
   5.185 +    { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   5.186 +     next
   5.187 +      from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if) 
   5.188 +     next
   5.189 +      from s show "~ \<bar>k-L\<bar> < L-k" by (simp add: abs_if) }
   5.190 +  qed
   5.191 +next
   5.192 +  assume k: "L < k"
   5.193 +  show "\<exists>r. 0 < r \<and>
   5.194 +        (\<forall>s. 0 < s \<longrightarrow> (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r)"
   5.195 +  proof (intro exI conjI strip)
   5.196 +    show "0 < k-L" by (simp add: k)
   5.197 +    fix s :: real
   5.198 +    assume s: "0<s"
   5.199 +    { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   5.200 +     next
   5.201 +      from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if) 
   5.202 +     next
   5.203 +      from s show "~ \<bar>k-L\<bar> < k-L" by (simp add: abs_if) }
   5.204 +  qed
   5.205 +qed
   5.206 +
   5.207 +lemma LIM_const_eq: "(%x. k) -- x --> L ==> k = L"
   5.208 +apply (rule ccontr)
   5.209 +apply (blast dest: LIM_const_not_eq) 
   5.210 +done
   5.211 +
   5.212 +lemma LIM_unique: "[| f -- a --> L; f -- a --> M |] ==> L = M"
   5.213 +apply (drule LIM_diff, assumption) 
   5.214 +apply (auto dest!: LIM_const_eq)
   5.215 +done
   5.216 +
   5.217 +lemma LIM_mult_zero:
   5.218 +  assumes f: "f -- a --> 0" and g: "g -- a --> 0"
   5.219 +  shows "(%x. f(x) * g(x)) -- a --> 0"
   5.220 +proof (simp add: LIM_eq, clarify)
   5.221 +  fix r :: real
   5.222 +  assume r: "0<r"
   5.223 +  from LIM_D [OF f zero_less_one]
   5.224 +  obtain fs
   5.225 +    where fs:    "0 < fs"
   5.226 +      and fs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < fs --> \<bar>f x\<bar> < 1"
   5.227 +  by auto
   5.228 +  from LIM_D [OF g r]
   5.229 +  obtain gs
   5.230 +    where gs:    "0 < gs"
   5.231 +      and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> \<bar>g x\<bar> < r"
   5.232 +  by auto
   5.233 +  show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>f x\<bar> * \<bar>g x\<bar> < r)"
   5.234 +  proof (intro exI conjI strip)
   5.235 +    show "0 < min fs gs"  by (simp add: fs gs)
   5.236 +    fix x :: real
   5.237 +    assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   5.238 +    with fs_lt gs_lt
   5.239 +    have "\<bar>f x\<bar> < 1" and "\<bar>g x\<bar> < r" by (auto simp add: fs_lt)
   5.240 +    hence "\<bar>f x\<bar> * \<bar>g x\<bar> < 1*r" by (rule abs_mult_less) 
   5.241 +    thus "\<bar>f x\<bar> * \<bar>g x\<bar> < r" by simp
   5.242 +  qed
   5.243 +qed
   5.244 +
   5.245 +lemma LIM_self: "(%x. x) -- a --> a"
   5.246 +by (auto simp add: LIM_def)
   5.247 +
   5.248 +text{*Limits are equal for functions equal except at limit point*}
   5.249 +lemma LIM_equal:
   5.250 +     "[| \<forall>x. x \<noteq> a --> (f x = g x) |] ==> (f -- a --> l) = (g -- a --> l)"
   5.251 +by (simp add: LIM_def)
   5.252 +
   5.253 +text{*Two uses in Hyperreal/Transcendental.ML*}
   5.254 +lemma LIM_trans:
   5.255 +     "[| (%x. f(x) + -g(x)) -- a --> 0;  g -- a --> l |] ==> f -- a --> l"
   5.256 +apply (drule LIM_add, assumption)
   5.257 +apply (auto simp add: add_assoc)
   5.258 +done
   5.259 +
   5.260 +
   5.261 +subsection{*Relationships Between Standard and Nonstandard Concepts*}
   5.262 +
   5.263 +text{*Standard and NS definitions of Limit*} (*NEEDS STRUCTURING*)
   5.264 +lemma LIM_NSLIM:
   5.265 +      "f -- x --> L ==> f -- x --NS> L"
   5.266 +apply (simp add: LIM_def NSLIM_def approx_def)
   5.267 +apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   5.268 +apply (rule_tac z = xa in eq_Abs_hypreal)
   5.269 +apply (auto simp add: real_add_minus_iff starfun hypreal_minus hypreal_of_real_def hypreal_add)
   5.270 +apply (rule bexI, rule_tac [2] lemma_hyprel_refl, clarify) 
   5.271 +apply (drule_tac x = u in spec, clarify)
   5.272 +apply (drule_tac x = s in spec, clarify)
   5.273 +apply (subgoal_tac "\<forall>n::nat. (xa n) \<noteq> x & abs ((xa n) + - x) < s --> abs (f (xa n) + - L) < u")
   5.274 +prefer 2 apply blast
   5.275 +apply (drule FreeUltrafilterNat_all, ultra)
   5.276 +done
   5.277 +
   5.278 +(*---------------------------------------------------------------------
   5.279 +    Limit: NS definition ==> standard definition
   5.280 + ---------------------------------------------------------------------*)
   5.281 +
   5.282 +lemma lemma_LIM: "\<forall>s. 0 < s --> (\<exists>xa.  xa \<noteq> x &
   5.283 +         \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>)
   5.284 +      ==> \<forall>n::nat. \<exists>xa.  xa \<noteq> x &
   5.285 +              \<bar>xa + -x\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f xa + -L\<bar>"
   5.286 +apply clarify
   5.287 +apply (cut_tac n1 = n in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   5.288 +done
   5.289 +
   5.290 +lemma lemma_skolemize_LIM2:
   5.291 +     "\<forall>s. 0 < s --> (\<exists>xa.  xa \<noteq> x &
   5.292 +         \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>)
   5.293 +      ==> \<exists>X. \<forall>n::nat. X n \<noteq> x &
   5.294 +                \<bar>X n + -x\<bar> < inverse(real(Suc n)) & r \<le> abs(f (X n) + -L)"
   5.295 +apply (drule lemma_LIM)
   5.296 +apply (drule choice, blast)
   5.297 +done
   5.298 +
   5.299 +lemma lemma_simp: "\<forall>n. X n \<noteq> x &
   5.300 +          \<bar>X n + - x\<bar> < inverse (real(Suc n)) &
   5.301 +          r \<le> abs (f (X n) + - L) ==>
   5.302 +          \<forall>n. \<bar>X n + - x\<bar> < inverse (real(Suc n))"
   5.303 +by auto
   5.304 +
   5.305 +
   5.306 +(*-------------------
   5.307 +    NSLIM => LIM
   5.308 + -------------------*)
   5.309 +
   5.310 +lemma NSLIM_LIM: "f -- x --NS> L ==> f -- x --> L"
   5.311 +apply (simp add: LIM_def NSLIM_def approx_def)
   5.312 +apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, clarify)
   5.313 +apply (rule ccontr, simp)  
   5.314 +apply (simp add: linorder_not_less)
   5.315 +apply (drule lemma_skolemize_LIM2, safe)
   5.316 +apply (drule_tac x = "Abs_hypreal (hyprel``{X}) " in spec)
   5.317 +apply (auto simp add: starfun hypreal_minus hypreal_of_real_def hypreal_add)
   5.318 +apply (drule lemma_simp [THEN real_seq_to_hypreal_Infinitesimal])
   5.319 +apply (simp add: Infinitesimal_FreeUltrafilterNat_iff hypreal_of_real_def hypreal_minus hypreal_add, blast)
   5.320 +apply (drule spec, drule mp, assumption)
   5.321 +apply (drule FreeUltrafilterNat_all, ultra)
   5.322 +done
   5.323 +
   5.324 +
   5.325 +(**** Key result ****)
   5.326 +lemma LIM_NSLIM_iff: "(f -- x --> L) = (f -- x --NS> L)"
   5.327 +by (blast intro: LIM_NSLIM NSLIM_LIM)
   5.328 +
   5.329 +(*-------------------------------------------------------------------*)
   5.330 +(*   Proving properties of limits using nonstandard definition and   *)
   5.331 +(*   hence, the properties hold for standard limits as well          *)
   5.332 +(*-------------------------------------------------------------------*)
   5.333 +(*------------------------------------------------
   5.334 +      NSLIM_mult and hence (trivially) LIM_mult
   5.335 + ------------------------------------------------*)
   5.336 +
   5.337 +lemma NSLIM_mult:
   5.338 +     "[| f -- x --NS> l; g -- x --NS> m |]
   5.339 +      ==> (%x. f(x) * g(x)) -- x --NS> (l * m)"
   5.340 +apply (simp add: NSLIM_def)
   5.341 +apply (auto intro!: approx_mult_HFinite)
   5.342 +done
   5.343 +
   5.344 +lemma LIM_mult2: "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) * g(x)) -- x --> (l * m)"
   5.345 +by (simp add: LIM_NSLIM_iff NSLIM_mult)
   5.346 +
   5.347 +(*----------------------------------------------
   5.348 +      NSLIM_add and hence (trivially) LIM_add
   5.349 +      Note the much shorter proof
   5.350 + ----------------------------------------------*)
   5.351 +lemma NSLIM_add:
   5.352 +     "[| f -- x --NS> l; g -- x --NS> m |]
   5.353 +      ==> (%x. f(x) + g(x)) -- x --NS> (l + m)"
   5.354 +apply (simp add: NSLIM_def)
   5.355 +apply (auto intro!: approx_add)
   5.356 +done
   5.357 +
   5.358 +lemma LIM_add2: "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + g(x)) -- x --> (l + m)"
   5.359 +by (simp add: LIM_NSLIM_iff NSLIM_add)
   5.360 +
   5.361 +
   5.362 +lemma NSLIM_const: "(%x. k) -- x --NS> k"
   5.363 +by (simp add: NSLIM_def)
   5.364 +
   5.365 +declare NSLIM_const [simp]
   5.366 +
   5.367 +lemma LIM_const2: "(%x. k) -- x --> k"
   5.368 +by (simp add: LIM_NSLIM_iff)
   5.369 +
   5.370 +
   5.371 +lemma NSLIM_minus: "f -- a --NS> L ==> (%x. -f(x)) -- a --NS> -L"
   5.372 +by (simp add: NSLIM_def)
   5.373 +
   5.374 +lemma LIM_minus2: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
   5.375 +by (simp add: LIM_NSLIM_iff NSLIM_minus)
   5.376 +
   5.377 +
   5.378 +lemma NSLIM_add_minus: "[| f -- x --NS> l; g -- x --NS> m |] ==> (%x. f(x) + -g(x)) -- x --NS> (l + -m)"
   5.379 +by (blast dest: NSLIM_add NSLIM_minus)
   5.380 +
   5.381 +lemma LIM_add_minus2: "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   5.382 +by (simp add: LIM_NSLIM_iff NSLIM_add_minus)
   5.383 +
   5.384 +
   5.385 +lemma NSLIM_inverse:
   5.386 +     "[| f -- a --NS> L;  L \<noteq> 0 |]
   5.387 +      ==> (%x. inverse(f(x))) -- a --NS> (inverse L)"
   5.388 +apply (simp add: NSLIM_def, clarify)
   5.389 +apply (drule spec)
   5.390 +apply (auto simp add: hypreal_of_real_approx_inverse)
   5.391 +done
   5.392 +
   5.393 +lemma LIM_inverse: "[| f -- a --> L; L \<noteq> 0 |] ==> (%x. inverse(f(x))) -- a --> (inverse L)"
   5.394 +by (simp add: LIM_NSLIM_iff NSLIM_inverse)
   5.395 +
   5.396 +
   5.397 +lemma NSLIM_zero:
   5.398 +  assumes f: "f -- a --NS> l" shows "(%x. f(x) + -l) -- a --NS> 0"
   5.399 +proof -;
   5.400 +  have "(\<lambda>x. f x + - l) -- a --NS> l + -l"
   5.401 +    by (rule NSLIM_add_minus [OF f NSLIM_const]) 
   5.402 +  thus ?thesis by simp
   5.403 +qed
   5.404 +
   5.405 +lemma LIM_zero2: "f -- a --> l ==> (%x. f(x) + -l) -- a --> 0"
   5.406 +by (simp add: LIM_NSLIM_iff NSLIM_zero)
   5.407 +
   5.408 +lemma NSLIM_zero_cancel: "(%x. f(x) - l) -- x --NS> 0 ==> f -- x --NS> l"
   5.409 +apply (drule_tac g = "%x. l" and m = l in NSLIM_add)
   5.410 +apply (auto simp add: diff_minus add_assoc)
   5.411 +done
   5.412 +
   5.413 +lemma LIM_zero_cancel: "(%x. f(x) - l) -- x --> 0 ==> f -- x --> l"
   5.414 +apply (drule_tac g = "%x. l" and M = l in LIM_add)
   5.415 +apply (auto simp add: diff_minus add_assoc)
   5.416 +done
   5.417 +
   5.418 +
   5.419 +
   5.420 +lemma NSLIM_not_zero: "k \<noteq> 0 ==> ~ ((%x. k) -- x --NS> 0)"
   5.421 +apply (simp add: NSLIM_def)
   5.422 +apply (rule_tac x = "hypreal_of_real x + epsilon" in exI)
   5.423 +apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
   5.424 +            simp add: hypreal_epsilon_not_zero)
   5.425 +done
   5.426 +
   5.427 +lemma NSLIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- x --NS> L)"
   5.428 +apply (simp add: NSLIM_def)
   5.429 +apply (rule_tac x = "hypreal_of_real x + epsilon" in exI)
   5.430 +apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
   5.431 +            simp add: hypreal_epsilon_not_zero)
   5.432 +done
   5.433 +
   5.434 +lemma NSLIM_const_eq: "(%x. k) -- x --NS> L ==> k = L"
   5.435 +apply (rule ccontr)
   5.436 +apply (blast dest: NSLIM_const_not_eq) 
   5.437 +done
   5.438 +
   5.439 +(* can actually be proved more easily by unfolding def! *)
   5.440 +lemma NSLIM_unique: "[| f -- x --NS> L; f -- x --NS> M |] ==> L = M"
   5.441 +apply (drule NSLIM_minus)
   5.442 +apply (drule NSLIM_add, assumption)
   5.443 +apply (auto dest!: NSLIM_const_eq [symmetric])
   5.444 +done
   5.445 +
   5.446 +lemma LIM_unique2: "[| f -- x --> L; f -- x --> M |] ==> L = M"
   5.447 +by (simp add: LIM_NSLIM_iff NSLIM_unique)
   5.448 +
   5.449 +
   5.450 +lemma NSLIM_mult_zero: "[| f -- x --NS> 0; g -- x --NS> 0 |] ==> (%x. f(x)*g(x)) -- x --NS> 0"
   5.451 +by (drule NSLIM_mult, auto)
   5.452 +
   5.453 +(* we can use the corresponding thm LIM_mult2 *)
   5.454 +(* for standard definition of limit           *)
   5.455 +
   5.456 +lemma LIM_mult_zero2: "[| f -- x --> 0; g -- x --> 0 |] ==> (%x. f(x)*g(x)) -- x --> 0"
   5.457 +by (drule LIM_mult2, auto)
   5.458 +
   5.459 +
   5.460 +lemma NSLIM_self: "(%x. x) -- a --NS> a"
   5.461 +by (simp add: NSLIM_def)
   5.462 +
   5.463 +
   5.464 +(*-----------------------------------------------------------------------------
   5.465 +   Derivatives and Continuity - NS and Standard properties
   5.466 + -----------------------------------------------------------------------------*)
   5.467 +text{*Continuity*}
   5.468 +
   5.469 +lemma isNSContD: "[| isNSCont f a; y \<approx> hypreal_of_real a |] ==> ( *f* f) y \<approx> hypreal_of_real (f a)"
   5.470 +by (simp add: isNSCont_def)
   5.471 +
   5.472 +lemma isNSCont_NSLIM: "isNSCont f a ==> f -- a --NS> (f a) "
   5.473 +by (simp add: isNSCont_def NSLIM_def)
   5.474 +
   5.475 +lemma NSLIM_isNSCont: "f -- a --NS> (f a) ==> isNSCont f a"
   5.476 +apply (simp add: isNSCont_def NSLIM_def, auto)
   5.477 +apply (rule_tac Q = "y = hypreal_of_real a" in excluded_middle [THEN disjE], auto)
   5.478 +done
   5.479 +
   5.480 +(*-----------------------------------------------------
   5.481 +    NS continuity can be defined using NS Limit in
   5.482 +    similar fashion to standard def of continuity
   5.483 + -----------------------------------------------------*)
   5.484 +lemma isNSCont_NSLIM_iff: "(isNSCont f a) = (f -- a --NS> (f a))"
   5.485 +by (blast intro: isNSCont_NSLIM NSLIM_isNSCont)
   5.486 +
   5.487 +(*----------------------------------------------
   5.488 +  Hence, NS continuity can be given
   5.489 +  in terms of standard limit
   5.490 + ---------------------------------------------*)
   5.491 +lemma isNSCont_LIM_iff: "(isNSCont f a) = (f -- a --> (f a))"
   5.492 +by (simp add: LIM_NSLIM_iff isNSCont_NSLIM_iff)
   5.493 +
   5.494 +(*-----------------------------------------------
   5.495 +  Moreover, it's trivial now that NS continuity
   5.496 +  is equivalent to standard continuity
   5.497 + -----------------------------------------------*)
   5.498 +lemma isNSCont_isCont_iff: "(isNSCont f a) = (isCont f a)"
   5.499 +apply (simp add: isCont_def)
   5.500 +apply (rule isNSCont_LIM_iff)
   5.501 +done
   5.502 +
   5.503 +(*----------------------------------------
   5.504 +  Standard continuity ==> NS continuity
   5.505 + ----------------------------------------*)
   5.506 +lemma isCont_isNSCont: "isCont f a ==> isNSCont f a"
   5.507 +by (erule isNSCont_isCont_iff [THEN iffD2])
   5.508 +
   5.509 +(*----------------------------------------
   5.510 +  NS continuity ==> Standard continuity
   5.511 + ----------------------------------------*)
   5.512 +lemma isNSCont_isCont: "isNSCont f a ==> isCont f a"
   5.513 +by (erule isNSCont_isCont_iff [THEN iffD1])
   5.514 +
   5.515 +text{*Alternative definition of continuity*}
   5.516 +(* Prove equivalence between NS limits - *)
   5.517 +(* seems easier than using standard def  *)
   5.518 +lemma NSLIM_h_iff: "(f -- a --NS> L) = ((%h. f(a + h)) -- 0 --NS> L)"
   5.519 +apply (simp add: NSLIM_def, auto)
   5.520 +apply (drule_tac x = "hypreal_of_real a + x" in spec)
   5.521 +apply (drule_tac [2] x = "-hypreal_of_real a + x" in spec, safe, simp)
   5.522 +apply (rule mem_infmal_iff [THEN iffD2, THEN Infinitesimal_add_approx_self [THEN approx_sym]])
   5.523 +apply (rule_tac [4] approx_minus_iff2 [THEN iffD1])
   5.524 + prefer 3 apply (simp add: add_commute) 
   5.525 +apply (rule_tac [2] z = x in eq_Abs_hypreal)
   5.526 +apply (rule_tac [4] z = x in eq_Abs_hypreal)
   5.527 +apply (auto simp add: starfun hypreal_of_real_def hypreal_minus hypreal_add add_assoc approx_refl hypreal_zero_def)
   5.528 +done
   5.529 +
   5.530 +lemma NSLIM_isCont_iff: "(f -- a --NS> f a) = ((%h. f(a + h)) -- 0 --NS> f a)"
   5.531 +by (rule NSLIM_h_iff)
   5.532 +
   5.533 +lemma LIM_isCont_iff: "(f -- a --> f a) = ((%h. f(a + h)) -- 0 --> f(a))"
   5.534 +by (simp add: LIM_NSLIM_iff NSLIM_isCont_iff)
   5.535 +
   5.536 +lemma isCont_iff: "(isCont f x) = ((%h. f(x + h)) -- 0 --> f(x))"
   5.537 +by (simp add: isCont_def LIM_isCont_iff)
   5.538 +
   5.539 +(*--------------------------------------------------------------------------
   5.540 +   Immediate application of nonstandard criterion for continuity can offer
   5.541 +   very simple proofs of some standard property of continuous functions
   5.542 + --------------------------------------------------------------------------*)
   5.543 +text{*sum continuous*}
   5.544 +lemma isCont_add: "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) + g(x)) a"
   5.545 +by (auto intro: approx_add simp add: isNSCont_isCont_iff [symmetric] isNSCont_def)
   5.546 +
   5.547 +text{*mult continuous*}
   5.548 +lemma isCont_mult: "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a"
   5.549 +by (auto intro!: starfun_mult_HFinite_approx 
   5.550 +            simp del: starfun_mult [symmetric] 
   5.551 +            simp add: isNSCont_isCont_iff [symmetric] isNSCont_def)
   5.552 +
   5.553 +(*-------------------------------------------
   5.554 +     composition of continuous functions
   5.555 +     Note very short straightforard proof!
   5.556 + ------------------------------------------*)
   5.557 +lemma isCont_o: "[| isCont f a; isCont g (f a) |] ==> isCont (g o f) a"
   5.558 +by (auto simp add: isNSCont_isCont_iff [symmetric] isNSCont_def starfun_o [symmetric])
   5.559 +
   5.560 +lemma isCont_o2: "[| isCont f a; isCont g (f a) |] ==> isCont (%x. g (f x)) a"
   5.561 +by (auto dest: isCont_o simp add: o_def)
   5.562 +
   5.563 +lemma isNSCont_minus: "isNSCont f a ==> isNSCont (%x. - f x) a"
   5.564 +by (simp add: isNSCont_def)
   5.565 +
   5.566 +lemma isCont_minus: "isCont f a ==> isCont (%x. - f x) a"
   5.567 +by (auto simp add: isNSCont_isCont_iff [symmetric] isNSCont_minus)
   5.568 +
   5.569 +lemma isCont_inverse:
   5.570 +      "[| isCont f x; f x \<noteq> 0 |] ==> isCont (%x. inverse (f x)) x"
   5.571 +apply (simp add: isCont_def)
   5.572 +apply (blast intro: LIM_inverse)
   5.573 +done
   5.574 +
   5.575 +lemma isNSCont_inverse: "[| isNSCont f x; f x \<noteq> 0 |] ==> isNSCont (%x. inverse (f x)) x"
   5.576 +by (auto intro: isCont_inverse simp add: isNSCont_isCont_iff)
   5.577 +
   5.578 +lemma isCont_diff:
   5.579 +      "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) - g(x)) a"
   5.580 +apply (simp add: diff_minus)
   5.581 +apply (auto intro: isCont_add isCont_minus)
   5.582 +done
   5.583 +
   5.584 +lemma isCont_const: "isCont (%x. k) a"
   5.585 +by (simp add: isCont_def)
   5.586 +declare isCont_const [simp]
   5.587 +
   5.588 +lemma isNSCont_const: "isNSCont (%x. k) a"
   5.589 +by (simp add: isNSCont_def)
   5.590 +declare isNSCont_const [simp]
   5.591 +
   5.592 +lemma isNSCont_rabs: "isNSCont abs a"
   5.593 +apply (simp add: isNSCont_def)
   5.594 +apply (auto intro: approx_hrabs simp add: hypreal_of_real_hrabs [symmetric] starfun_rabs_hrabs)
   5.595 +done
   5.596 +declare isNSCont_rabs [simp]
   5.597 +
   5.598 +lemma isCont_rabs: "isCont abs a"
   5.599 +by (auto simp add: isNSCont_isCont_iff [symmetric])
   5.600 +declare isCont_rabs [simp]
   5.601 +
   5.602 +(****************************************************************
   5.603 +(%* Leave as commented until I add topology theory or remove? *%)
   5.604 +(%*------------------------------------------------------------
   5.605 +  Elementary topology proof for a characterisation of
   5.606 +  continuity now: a function f is continuous if and only
   5.607 +  if the inverse image, {x. f(x) \<in> A}, of any open set A
   5.608 +  is always an open set
   5.609 + ------------------------------------------------------------*%)
   5.610 +Goal "[| isNSopen A; \<forall>x. isNSCont f x |]
   5.611 +               ==> isNSopen {x. f x \<in> A}"
   5.612 +by (auto_tac (claset(),simpset() addsimps [isNSopen_iff1]));
   5.613 +by (dtac (mem_monad_approx RS approx_sym);
   5.614 +by (dres_inst_tac [("x","a")] spec 1);
   5.615 +by (dtac isNSContD 1 THEN assume_tac 1)
   5.616 +by (dtac bspec 1 THEN assume_tac 1)
   5.617 +by (dres_inst_tac [("x","( *f* f) x")] approx_mem_monad2 1);
   5.618 +by (blast_tac (claset() addIs [starfun_mem_starset]);
   5.619 +qed "isNSCont_isNSopen";
   5.620 +
   5.621 +Goalw [isNSCont_def]
   5.622 +          "\<forall>A. isNSopen A --> isNSopen {x. f x \<in> A} \
   5.623 +\              ==> isNSCont f x";
   5.624 +by (auto_tac (claset() addSIs [(mem_infmal_iff RS iffD1) RS
   5.625 +     (approx_minus_iff RS iffD2)],simpset() addsimps
   5.626 +      [Infinitesimal_def,SReal_iff]));
   5.627 +by (dres_inst_tac [("x","{z. abs(z + -f(x)) < ya}")] spec 1);
   5.628 +by (etac (isNSopen_open_interval RSN (2,impE));
   5.629 +by (auto_tac (claset(),simpset() addsimps [isNSopen_def,isNSnbhd_def]));
   5.630 +by (dres_inst_tac [("x","x")] spec 1);
   5.631 +by (auto_tac (claset() addDs [approx_sym RS approx_mem_monad],
   5.632 +    simpset() addsimps [hypreal_of_real_zero RS sym,STAR_starfun_rabs_add_minus]));
   5.633 +qed "isNSopen_isNSCont";
   5.634 +
   5.635 +Goal "(\<forall>x. isNSCont f x) = \
   5.636 +\     (\<forall>A. isNSopen A --> isNSopen {x. f(x) \<in> A})";
   5.637 +by (blast_tac (claset() addIs [isNSCont_isNSopen,
   5.638 +    isNSopen_isNSCont]);
   5.639 +qed "isNSCont_isNSopen_iff";
   5.640 +
   5.641 +(%*------- Standard version of same theorem --------*%)
   5.642 +Goal "(\<forall>x. isCont f x) = \
   5.643 +\         (\<forall>A. isopen A --> isopen {x. f(x) \<in> A})";
   5.644 +by (auto_tac (claset() addSIs [isNSCont_isNSopen_iff],
   5.645 +              simpset() addsimps [isNSopen_isopen_iff RS sym,
   5.646 +              isNSCont_isCont_iff RS sym]));
   5.647 +qed "isCont_isopen_iff";
   5.648 +*******************************************************************)
   5.649 +
   5.650 +text{*Uniform continuity*}
   5.651 +lemma isNSUContD: "[| isNSUCont f; x \<approx> y|] ==> ( *f* f) x \<approx> ( *f* f) y"
   5.652 +by (simp add: isNSUCont_def)
   5.653 +
   5.654 +lemma isUCont_isCont: "isUCont f ==> isCont f x"
   5.655 +by (simp add: isUCont_def isCont_def LIM_def, meson)
   5.656 +
   5.657 +lemma isUCont_isNSUCont: "isUCont f ==> isNSUCont f"
   5.658 +apply (simp add: isNSUCont_def isUCont_def approx_def)
   5.659 +apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   5.660 +apply (rule_tac z = x in eq_Abs_hypreal)
   5.661 +apply (rule_tac z = y in eq_Abs_hypreal)
   5.662 +apply (auto simp add: starfun hypreal_minus hypreal_add)
   5.663 +apply (rule bexI, rule_tac [2] lemma_hyprel_refl, safe)
   5.664 +apply (drule_tac x = u in spec, clarify)
   5.665 +apply (drule_tac x = s in spec, clarify)
   5.666 +apply (subgoal_tac "\<forall>n::nat. abs ((xa n) + - (xb n)) < s --> abs (f (xa n) + - f (xb n)) < u")
   5.667 +prefer 2 apply blast
   5.668 +apply (erule_tac V = "\<forall>x y. \<bar>x + - y\<bar> < s --> \<bar>f x + - f y\<bar> < u" in thin_rl)
   5.669 +apply (drule FreeUltrafilterNat_all, ultra)
   5.670 +done
   5.671 +
   5.672 +lemma lemma_LIMu: "\<forall>s. 0 < s --> (\<exists>z y. \<bar>z + - y\<bar> < s & r \<le> \<bar>f z + -f y\<bar>)
   5.673 +      ==> \<forall>n::nat. \<exists>z y.
   5.674 +               \<bar>z + -y\<bar> < inverse(real(Suc n)) &
   5.675 +               r \<le> \<bar>f z + -f y\<bar>"
   5.676 +apply clarify
   5.677 +apply (cut_tac n1 = n in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   5.678 +done
   5.679 +
   5.680 +lemma lemma_skolemize_LIM2u: "\<forall>s. 0 < s --> (\<exists>z y. \<bar>z + - y\<bar> < s  & r \<le> \<bar>f z + -f y\<bar>)
   5.681 +      ==> \<exists>X Y. \<forall>n::nat.
   5.682 +               abs(X n + -(Y n)) < inverse(real(Suc n)) &
   5.683 +               r \<le> abs(f (X n) + -f (Y n))"
   5.684 +apply (drule lemma_LIMu)
   5.685 +apply (drule choice, safe)
   5.686 +apply (drule choice, blast)
   5.687 +done
   5.688 +
   5.689 +lemma lemma_simpu: "\<forall>n. \<bar>X n + -Y n\<bar> < inverse (real(Suc n)) &
   5.690 +          r \<le> abs (f (X n) + - f(Y n)) ==>
   5.691 +          \<forall>n. \<bar>X n + - Y n\<bar> < inverse (real(Suc n))"
   5.692 +apply auto
   5.693 +done
   5.694 +
   5.695 +lemma isNSUCont_isUCont:
   5.696 +     "isNSUCont f ==> isUCont f"
   5.697 +apply (simp add: isNSUCont_def isUCont_def approx_def)
   5.698 +apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   5.699 +apply (rule ccontr, simp) 
   5.700 +apply (simp add: linorder_not_less)
   5.701 +apply (drule lemma_skolemize_LIM2u, safe)
   5.702 +apply (drule_tac x = "Abs_hypreal (hyprel``{X}) " in spec)
   5.703 +apply (drule_tac x = "Abs_hypreal (hyprel``{Y}) " in spec)
   5.704 +apply (simp add: starfun hypreal_minus hypreal_add, auto)
   5.705 +apply (drule lemma_simpu [THEN real_seq_to_hypreal_Infinitesimal2])
   5.706 +apply (simp add: Infinitesimal_FreeUltrafilterNat_iff hypreal_minus hypreal_add, blast)
   5.707 +apply (rotate_tac 2)
   5.708 +apply (drule_tac x = r in spec, clarify)
   5.709 +apply (drule FreeUltrafilterNat_all, ultra)
   5.710 +done
   5.711 +
   5.712 +text{*Derivatives*}
   5.713 +lemma DERIV_iff: "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --> D)"
   5.714 +by (simp add: deriv_def)
   5.715 +
   5.716 +lemma DERIV_NS_iff:
   5.717 +      "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --NS> D)"
   5.718 +by (simp add: deriv_def LIM_NSLIM_iff)
   5.719 +
   5.720 +lemma DERIV_D: "DERIV f x :> D ==> (%h. (f(x + h) + - f(x))/h) -- 0 --> D"
   5.721 +by (simp add: deriv_def)
   5.722 +
   5.723 +lemma NS_DERIV_D: "DERIV f x :> D ==>
   5.724 +           (%h. (f(x + h) + - f(x))/h) -- 0 --NS> D"
   5.725 +by (simp add: deriv_def LIM_NSLIM_iff)
   5.726 +
   5.727 +subsubsection{*Uniqueness*}
   5.728 +
   5.729 +lemma DERIV_unique:
   5.730 +      "[| DERIV f x :> D; DERIV f x :> E |] ==> D = E"
   5.731 +apply (simp add: deriv_def)
   5.732 +apply (blast intro: LIM_unique)
   5.733 +done
   5.734 +
   5.735 +lemma NSDeriv_unique:
   5.736 +     "[| NSDERIV f x :> D; NSDERIV f x :> E |] ==> D = E"
   5.737 +apply (simp add: nsderiv_def)
   5.738 +apply (cut_tac Infinitesimal_epsilon hypreal_epsilon_not_zero)
   5.739 +apply (auto dest!: bspec [where x=epsilon] 
   5.740 +            intro!: inj_hypreal_of_real [THEN injD] 
   5.741 +            dest: approx_trans3)
   5.742 +done
   5.743 +
   5.744 +subsubsection{*Differentiable*}
   5.745 +
   5.746 +lemma differentiableD: "f differentiable x ==> \<exists>D. DERIV f x :> D"
   5.747 +by (simp add: differentiable_def)
   5.748 +
   5.749 +lemma differentiableI: "DERIV f x :> D ==> f differentiable x"
   5.750 +by (force simp add: differentiable_def)
   5.751 +
   5.752 +lemma NSdifferentiableD: "f NSdifferentiable x ==> \<exists>D. NSDERIV f x :> D"
   5.753 +by (simp add: NSdifferentiable_def)
   5.754 +
   5.755 +lemma NSdifferentiableI: "NSDERIV f x :> D ==> f NSdifferentiable x"
   5.756 +by (force simp add: NSdifferentiable_def)
   5.757 +
   5.758 +subsubsection{*Alternative definition for differentiability*}
   5.759 +
   5.760 +lemma LIM_I:
   5.761 +     "(!!r. 0<r ==> (\<exists>s. 0 < s & (\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)))
   5.762 +      ==> f -- a --> L"
   5.763 +by (simp add: LIM_eq)
   5.764 +
   5.765 +lemma DERIV_LIM_iff:
   5.766 +     "((%h. (f(a + h) - f(a)) / h) -- 0 --> D) =
   5.767 +      ((%x. (f(x)-f(a)) / (x-a)) -- a --> D)"
   5.768 +proof (intro iffI LIM_I)
   5.769 +  fix r::real
   5.770 +  assume r: "0<r"
   5.771 +  assume "(\<lambda>h. (f (a + h) - f a) / h) -- 0 --> D"
   5.772 +  from LIM_D [OF this r]
   5.773 +  obtain s
   5.774 +    where s:    "0 < s"
   5.775 +      and s_lt: "\<forall>x. x \<noteq> 0 & \<bar>x\<bar> < s --> \<bar>(f (a + x) - f a) / x - D\<bar> < r"
   5.776 +  by auto
   5.777 +  show "\<exists>s. 0 < s \<and>
   5.778 +            (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>(f x - f a) / (x-a) - D\<bar> < r)"
   5.779 +  proof (intro exI conjI strip)
   5.780 +    show "0 < s"  by (rule s)
   5.781 +  next
   5.782 +    fix x::real
   5.783 +    assume "x \<noteq> a \<and> \<bar>x-a\<bar> < s"
   5.784 +    with s_lt [THEN spec [where x="x-a"]]
   5.785 +    show "\<bar>(f x - f a) / (x-a) - D\<bar> < r" by auto
   5.786 +  qed
   5.787 +next
   5.788 +  fix r::real
   5.789 +  assume r: "0<r"
   5.790 +  assume "(\<lambda>x. (f x - f a) / (x-a)) -- a --> D"
   5.791 +  from LIM_D [OF this r]
   5.792 +  obtain s
   5.793 +    where s:    "0 < s"
   5.794 +      and s_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>(f x - f a)/(x-a) - D\<bar> < r"
   5.795 +  by auto
   5.796 +  show "\<exists>s. 0 < s \<and>
   5.797 +            (\<forall>x. x \<noteq> 0 & \<bar>x - 0\<bar> < s --> \<bar>(f (a + x) - f a) / x - D\<bar> < r)"
   5.798 +  proof (intro exI conjI strip)
   5.799 +    show "0 < s"  by (rule s)
   5.800 +  next
   5.801 +    fix x::real
   5.802 +    assume "x \<noteq> 0 \<and> \<bar>x - 0\<bar> < s"
   5.803 +    with s_lt [THEN spec [where x="x+a"]]
   5.804 +    show "\<bar>(f (a + x) - f a) / x - D\<bar> < r" by (auto simp add: add_ac)
   5.805 +  qed
   5.806 +qed
   5.807 +
   5.808 +lemma DERIV_iff2: "(DERIV f x :> D) = ((%z. (f(z) - f(x)) / (z-x)) -- x --> D)"
   5.809 +by (simp add: deriv_def diff_minus [symmetric] DERIV_LIM_iff)
   5.810 +
   5.811 +
   5.812 +subsection{*Equivalence of NS and standard definitions of differentiation*}
   5.813 +
   5.814 +text{*First NSDERIV in terms of NSLIM*}
   5.815 +
   5.816 +(*--- first equivalence ---*)
   5.817 +lemma NSDERIV_NSLIM_iff:
   5.818 +      "(NSDERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --NS> D)"
   5.819 +apply (simp add: nsderiv_def NSLIM_def, auto)
   5.820 +apply (drule_tac x = xa in bspec)
   5.821 +apply (rule_tac [3] ccontr)
   5.822 +apply (drule_tac [3] x = h in spec)
   5.823 +apply (auto simp add: mem_infmal_iff starfun_lambda_cancel)
   5.824 +done
   5.825 +
   5.826 +(*--- second equivalence ---*)
   5.827 +lemma NSDERIV_NSLIM_iff2:
   5.828 +     "(NSDERIV f x :> D) = ((%z. (f(z) - f(x)) / (z-x)) -- x --NS> D)"
   5.829 +by (simp add: NSDERIV_NSLIM_iff DERIV_LIM_iff  diff_minus [symmetric] 
   5.830 +              LIM_NSLIM_iff [symmetric])
   5.831 +
   5.832 +(* while we're at it! *)
   5.833 +lemma NSDERIV_iff2:
   5.834 +     "(NSDERIV f x :> D) =
   5.835 +      (\<forall>w.
   5.836 +        w \<noteq> hypreal_of_real x & w \<approx> hypreal_of_real x -->
   5.837 +        ( *f* (%z. (f z - f x) / (z-x))) w \<approx> hypreal_of_real D)"
   5.838 +by (simp add: NSDERIV_NSLIM_iff2 NSLIM_def)
   5.839 +
   5.840 +(*FIXME DELETE*)
   5.841 +lemma hypreal_not_eq_minus_iff: "(x \<noteq> a) = (x + -a \<noteq> (0::hypreal))"
   5.842 +by (auto dest: hypreal_eq_minus_iff [THEN iffD2])
   5.843 +
   5.844 +lemma NSDERIVD5:
   5.845 +  "(NSDERIV f x :> D) ==>
   5.846 +   (\<forall>u. u \<approx> hypreal_of_real x -->
   5.847 +     ( *f* (%z. f z - f x)) u \<approx> hypreal_of_real D * (u - hypreal_of_real x))"
   5.848 +apply (auto simp add: NSDERIV_iff2)
   5.849 +apply (case_tac "u = hypreal_of_real x", auto)
   5.850 +apply (drule_tac x = u in spec, auto)
   5.851 +apply (drule_tac c = "u - hypreal_of_real x" and b = "hypreal_of_real D" in approx_mult1)
   5.852 +apply (drule_tac [!] hypreal_not_eq_minus_iff [THEN iffD1])
   5.853 +apply (subgoal_tac [2] "( *f* (%z. z-x)) u \<noteq> (0::hypreal) ")
   5.854 +apply (auto simp add: diff_minus
   5.855 +	       approx_minus_iff [THEN iffD1, THEN mem_infmal_iff [THEN iffD2]]
   5.856 +		     Infinitesimal_subset_HFinite [THEN subsetD])
   5.857 +done
   5.858 +
   5.859 +lemma NSDERIVD4:
   5.860 +     "(NSDERIV f x :> D) ==>
   5.861 +      (\<forall>h \<in> Infinitesimal.
   5.862 +               (( *f* f)(hypreal_of_real x + h) -
   5.863 +                 hypreal_of_real (f x))\<approx> (hypreal_of_real D) * h)"
   5.864 +apply (auto simp add: nsderiv_def)
   5.865 +apply (case_tac "h = (0::hypreal) ")
   5.866 +apply (auto simp add: diff_minus)
   5.867 +apply (drule_tac x = h in bspec)
   5.868 +apply (drule_tac [2] c = h in approx_mult1)
   5.869 +apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD]
   5.870 +            simp add: diff_minus)
   5.871 +done
   5.872 +
   5.873 +lemma NSDERIVD3:
   5.874 +     "(NSDERIV f x :> D) ==>
   5.875 +      (\<forall>h \<in> Infinitesimal - {0}.
   5.876 +               (( *f* f)(hypreal_of_real x + h) -
   5.877 +                 hypreal_of_real (f x))\<approx> (hypreal_of_real D) * h)"
   5.878 +apply (auto simp add: nsderiv_def)
   5.879 +apply (rule ccontr, drule_tac x = h in bspec)
   5.880 +apply (drule_tac [2] c = h in approx_mult1)
   5.881 +apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD]
   5.882 +            simp add: mult_assoc diff_minus)
   5.883 +done
   5.884 +
   5.885 +text{*Now equivalence between NSDERIV and DERIV*}
   5.886 +lemma NSDERIV_DERIV_iff: "(NSDERIV f x :> D) = (DERIV f x :> D)"
   5.887 +by (simp add: deriv_def NSDERIV_NSLIM_iff LIM_NSLIM_iff)
   5.888 +
   5.889 +(*---------------------------------------------------
   5.890 +         Differentiability implies continuity
   5.891 +         nice and simple "algebraic" proof
   5.892 + --------------------------------------------------*)
   5.893 +lemma NSDERIV_isNSCont: "NSDERIV f x :> D ==> isNSCont f x"
   5.894 +apply (auto simp add: nsderiv_def isNSCont_NSLIM_iff NSLIM_def)
   5.895 +apply (drule approx_minus_iff [THEN iffD1])
   5.896 +apply (drule hypreal_not_eq_minus_iff [THEN iffD1])
   5.897 +apply (drule_tac x = "-hypreal_of_real x + xa" in bspec)
   5.898 + prefer 2 apply (simp add: add_assoc [symmetric]) 
   5.899 +apply (auto simp add: mem_infmal_iff [symmetric] hypreal_add_commute)
   5.900 +apply (drule_tac c = "xa + -hypreal_of_real x" in approx_mult1)
   5.901 +apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD]
   5.902 +            simp add: mult_assoc)
   5.903 +apply (drule_tac x3=D in
   5.904 +           HFinite_hypreal_of_real [THEN [2] Infinitesimal_HFinite_mult,
   5.905 +             THEN mem_infmal_iff [THEN iffD1]])
   5.906 +apply (auto simp add: mult_commute 
   5.907 +            intro: approx_trans approx_minus_iff [THEN iffD2])
   5.908 +done
   5.909 +
   5.910 +text{*Now Sandard proof*}
   5.911 +lemma DERIV_isCont: "DERIV f x :> D ==> isCont f x"
   5.912 +by (simp add: NSDERIV_DERIV_iff [symmetric] isNSCont_isCont_iff [symmetric] 
   5.913 +              NSDERIV_isNSCont)
   5.914 +
   5.915 +
   5.916 +(*----------------------------------------------------------------------------
   5.917 +      Differentiation rules for combinations of functions
   5.918 +      follow from clear, straightforard, algebraic
   5.919 +      manipulations
   5.920 + ----------------------------------------------------------------------------*)
   5.921 +text{*Constant function*}
   5.922 +
   5.923 +(* use simple constant nslimit theorem *)
   5.924 +lemma NSDERIV_const: "(NSDERIV (%x. k) x :> 0)"
   5.925 +by (simp add: NSDERIV_NSLIM_iff)
   5.926 +declare NSDERIV_const [simp]
   5.927 +
   5.928 +lemma DERIV_const: "(DERIV (%x. k) x :> 0)"
   5.929 +by (simp add: NSDERIV_DERIV_iff [symmetric])
   5.930 +declare DERIV_const [simp]
   5.931 +
   5.932 +(*-----------------------------------------------------
   5.933 +    Sum of functions- proved easily
   5.934 + ----------------------------------------------------*)
   5.935 +
   5.936 +
   5.937 +lemma NSDERIV_add: "[| NSDERIV f x :> Da;  NSDERIV g x :> Db |]
   5.938 +      ==> NSDERIV (%x. f x + g x) x :> Da + Db"
   5.939 +apply (auto simp add: NSDERIV_NSLIM_iff NSLIM_def)
   5.940 +apply (auto simp add: add_divide_distrib dest!: spec)
   5.941 +apply (drule_tac b = "hypreal_of_real Da" and d = "hypreal_of_real Db" in approx_add)
   5.942 +apply (auto simp add: add_ac)
   5.943 +done
   5.944 +
   5.945 +(* Standard theorem *)
   5.946 +lemma DERIV_add: "[| DERIV f x :> Da; DERIV g x :> Db |]
   5.947 +      ==> DERIV (%x. f x + g x) x :> Da + Db"
   5.948 +apply (simp add: NSDERIV_add NSDERIV_DERIV_iff [symmetric])
   5.949 +done
   5.950 +
   5.951 +(*-----------------------------------------------------
   5.952 +  Product of functions - Proof is trivial but tedious
   5.953 +  and long due to rearrangement of terms
   5.954 + ----------------------------------------------------*)
   5.955 +
   5.956 +lemma lemma_nsderiv1: "((a::hypreal)*b) + -(c*d) = (b*(a + -c)) + (c*(b + -d))"
   5.957 +by (simp add: right_distrib)
   5.958 +
   5.959 +lemma lemma_nsderiv2: "[| (x + y) / z = hypreal_of_real D + yb; z \<noteq> 0;
   5.960 +         z \<in> Infinitesimal; yb \<in> Infinitesimal |]
   5.961 +      ==> x + y \<approx> 0"
   5.962 +apply (frule_tac c1 = z in hypreal_mult_right_cancel [THEN iffD2], assumption)
   5.963 +apply (erule_tac V = " (x + y) / z = hypreal_of_real D + yb" in thin_rl)
   5.964 +apply (auto intro!: Infinitesimal_HFinite_mult2 HFinite_add
   5.965 +            simp add: hypreal_mult_assoc mem_infmal_iff [symmetric])
   5.966 +apply (erule Infinitesimal_subset_HFinite [THEN subsetD])
   5.967 +done
   5.968 +
   5.969 +
   5.970 +lemma NSDERIV_mult: "[| NSDERIV f x :> Da; NSDERIV g x :> Db |]
   5.971 +      ==> NSDERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))"
   5.972 +apply (auto simp add: NSDERIV_NSLIM_iff NSLIM_def)
   5.973 +apply (auto dest!: spec
   5.974 +	    simp add: starfun_lambda_cancel lemma_nsderiv1)
   5.975 +apply (simp (no_asm) add: add_divide_distrib)
   5.976 +apply (drule bex_Infinitesimal_iff2 [THEN iffD2])+
   5.977 +apply (auto simp del: times_divide_eq_right simp add: times_divide_eq_right [symmetric])
   5.978 +apply (drule_tac D = Db in lemma_nsderiv2)
   5.979 +apply (drule_tac [4]
   5.980 +     approx_minus_iff [THEN iffD2, THEN bex_Infinitesimal_iff2 [THEN iffD2]]) 
   5.981 +apply (auto intro!: approx_add_mono1 
   5.982 +            simp add: left_distrib right_distrib mult_commute add_assoc)
   5.983 +apply (rule_tac b1 = "hypreal_of_real Db * hypreal_of_real (f x)" 
   5.984 +         in add_commute [THEN subst])
   5.985 +apply (auto intro!: Infinitesimal_add_approx_self2 [THEN approx_sym] 
   5.986 +                    Infinitesimal_add Infinitesimal_mult 
   5.987 +                    Infinitesimal_hypreal_of_real_mult 
   5.988 +                    Infinitesimal_hypreal_of_real_mult2
   5.989 +          simp add: add_assoc [symmetric])
   5.990 +done
   5.991 +
   5.992 +lemma DERIV_mult:
   5.993 +     "[| DERIV f x :> Da; DERIV g x :> Db |] 
   5.994 +      ==> DERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))"
   5.995 +by (simp add: NSDERIV_mult NSDERIV_DERIV_iff [symmetric])
   5.996 +
   5.997 +text{*Multiplying by a constant*}
   5.998 +lemma NSDERIV_cmult: "NSDERIV f x :> D
   5.999 +      ==> NSDERIV (%x. c * f x) x :> c*D"
  5.1000 +apply (simp only: times_divide_eq_right [symmetric] NSDERIV_NSLIM_iff 
  5.1001 +                  minus_mult_right right_distrib [symmetric])
  5.1002 +apply (erule NSLIM_const [THEN NSLIM_mult])
  5.1003 +done
  5.1004 +
  5.1005 +(* let's do the standard proof though theorem *)
  5.1006 +(* LIM_mult2 follows from a NS proof          *)
  5.1007 +
  5.1008 +lemma DERIV_cmult:
  5.1009 +      "DERIV f x :> D ==> DERIV (%x. c * f x) x :> c*D"
  5.1010 +apply (simp only: deriv_def times_divide_eq_right [symmetric] 
  5.1011 +                  NSDERIV_NSLIM_iff minus_mult_right right_distrib [symmetric])
  5.1012 +apply (erule LIM_const [THEN LIM_mult2])
  5.1013 +done
  5.1014 +
  5.1015 +text{*Negation of function*}
  5.1016 +lemma NSDERIV_minus: "NSDERIV f x :> D ==> NSDERIV (%x. -(f x)) x :> -D"
  5.1017 +proof (simp add: NSDERIV_NSLIM_iff)
  5.1018 +  assume "(\<lambda>h. (f (x + h) + - f x) / h) -- 0 --NS> D"
  5.1019 +  hence deriv: "(\<lambda>h. - ((f(x+h) + - f x) / h)) -- 0 --NS> - D" 
  5.1020 +    by (rule NSLIM_minus)
  5.1021 +  have "\<forall>h. - ((f (x + h) + - f x) / h) = (- f (x + h) + f x) / h"
  5.1022 +    by (simp add: minus_divide_left) 
  5.1023 +  with deriv
  5.1024 +  show "(\<lambda>h. (- f (x + h) + f x) / h) -- 0 --NS> - D" by simp
  5.1025 +qed
  5.1026 +
  5.1027 +
  5.1028 +lemma DERIV_minus: "DERIV f x :> D ==> DERIV (%x. -(f x)) x :> -D"
  5.1029 +by (simp add: NSDERIV_minus NSDERIV_DERIV_iff [symmetric])
  5.1030 +
  5.1031 +text{*Subtraction*}
  5.1032 +lemma NSDERIV_add_minus: "[| NSDERIV f x :> Da; NSDERIV g x :> Db |] ==> NSDERIV (%x. f x + -g x) x :> Da + -Db"
  5.1033 +by (blast dest: NSDERIV_add NSDERIV_minus)
  5.1034 +
  5.1035 +lemma DERIV_add_minus: "[| DERIV f x :> Da; DERIV g x :> Db |] ==> DERIV (%x. f x + -g x) x :> Da + -Db"
  5.1036 +by (blast dest: DERIV_add DERIV_minus)
  5.1037 +
  5.1038 +lemma NSDERIV_diff:
  5.1039 +     "[| NSDERIV f x :> Da; NSDERIV g x :> Db |]
  5.1040 +      ==> NSDERIV (%x. f x - g x) x :> Da-Db"
  5.1041 +apply (simp add: diff_minus)
  5.1042 +apply (blast intro: NSDERIV_add_minus)
  5.1043 +done
  5.1044 +
  5.1045 +lemma DERIV_diff:
  5.1046 +     "[| DERIV f x :> Da; DERIV g x :> Db |]
  5.1047 +       ==> DERIV (%x. f x - g x) x :> Da-Db"
  5.1048 +apply (simp add: diff_minus)
  5.1049 +apply (blast intro: DERIV_add_minus)
  5.1050 +done
  5.1051 +
  5.1052 +(*---------------------------------------------------------------
  5.1053 +                     (NS) Increment
  5.1054 + ---------------------------------------------------------------*)
  5.1055 +lemma incrementI:
  5.1056 +      "f NSdifferentiable x ==>
  5.1057 +      increment f x h = ( *f* f) (hypreal_of_real(x) + h) +
  5.1058 +      -hypreal_of_real (f x)"
  5.1059 +by (simp add: increment_def)
  5.1060 +
  5.1061 +lemma incrementI2: "NSDERIV f x :> D ==>
  5.1062 +     increment f x h = ( *f* f) (hypreal_of_real(x) + h) +
  5.1063 +     -hypreal_of_real (f x)"
  5.1064 +apply (erule NSdifferentiableI [THEN incrementI])
  5.1065 +done
  5.1066 +
  5.1067 +(* The Increment theorem -- Keisler p. 65 *)
  5.1068 +lemma increment_thm: "[| NSDERIV f x :> D; h \<in> Infinitesimal; h \<noteq> 0 |]
  5.1069 +      ==> \<exists>e \<in> Infinitesimal. increment f x h = hypreal_of_real(D)*h + e*h"
  5.1070 +apply (frule_tac h = h in incrementI2, simp add: nsderiv_def)
  5.1071 +apply (drule bspec, auto)
  5.1072 +apply (drule bex_Infinitesimal_iff2 [THEN iffD2], clarify) 
  5.1073 +apply (frule_tac b1 = "hypreal_of_real (D) + y" 
  5.1074 +        in hypreal_mult_right_cancel [THEN iffD2])
  5.1075 +apply (erule_tac [2] V = "(( *f* f) (hypreal_of_real (x) + h) + - hypreal_of_real (f x)) / h = hypreal_of_real (D) + y" in thin_rl)
  5.1076 +apply assumption
  5.1077 +apply (simp add: times_divide_eq_right [symmetric] del: times_divide_eq_right)
  5.1078 +apply (auto simp add: left_distrib)
  5.1079 +done
  5.1080 + 
  5.1081 +lemma increment_thm2:
  5.1082 +     "[| NSDERIV f x :> D; h \<approx> 0; h \<noteq> 0 |]
  5.1083 +      ==> \<exists>e \<in> Infinitesimal. increment f x h =
  5.1084 +              hypreal_of_real(D)*h + e*h"
  5.1085 +by (blast dest!: mem_infmal_iff [THEN iffD2] intro!: increment_thm)
  5.1086 +
  5.1087 +
  5.1088 +lemma increment_approx_zero: "[| NSDERIV f x :> D; h \<approx> 0; h \<noteq> 0 |]
  5.1089 +      ==> increment f x h \<approx> 0"
  5.1090 +apply (drule increment_thm2, 
  5.1091 +       auto intro!: Infinitesimal_HFinite_mult2 HFinite_add simp add: left_distrib [symmetric] mem_infmal_iff [symmetric])
  5.1092 +apply (erule Infinitesimal_subset_HFinite [THEN subsetD])
  5.1093 +done
  5.1094 +
  5.1095 +text{*  Similarly to the above, the chain rule admits an entirely
  5.1096 +   straightforward derivation. Compare this with Harrison's
  5.1097 +   HOL proof of the chain rule, which proved to be trickier and
  5.1098 +   required an alternative characterisation of differentiability-
  5.1099 +   the so-called Carathedory derivative. Our main problem is
  5.1100 +   manipulation of terms.*}
  5.1101 +
  5.1102 +
  5.1103 +(* lemmas *)
  5.1104 +lemma NSDERIV_zero:
  5.1105 +      "[| NSDERIV g x :> D;
  5.1106 +               ( *f* g) (hypreal_of_real(x) + xa) = hypreal_of_real(g x);
  5.1107 +               xa \<in> Infinitesimal;
  5.1108 +               xa \<noteq> 0
  5.1109 +            |] ==> D = 0"
  5.1110 +apply (simp add: nsderiv_def)
  5.1111 +apply (drule bspec, auto)
  5.1112 +done
  5.1113 +
  5.1114 +(* can be proved differently using NSLIM_isCont_iff *)
  5.1115 +lemma NSDERIV_approx:
  5.1116 +     "[| NSDERIV f x :> D;  h \<in> Infinitesimal;  h \<noteq> 0 |]
  5.1117 +      ==> ( *f* f) (hypreal_of_real(x) + h) + -hypreal_of_real(f x) \<approx> 0"
  5.1118 +apply (simp add: nsderiv_def)
  5.1119 +apply (simp add: mem_infmal_iff [symmetric])
  5.1120 +apply (rule Infinitesimal_ratio)
  5.1121 +apply (rule_tac [3] approx_hypreal_of_real_HFinite, auto)
  5.1122 +done
  5.1123 +
  5.1124 +(*---------------------------------------------------------------
  5.1125 +   from one version of differentiability
  5.1126 +
  5.1127 +                f(x) - f(a)
  5.1128 +              --------------- \<approx> Db
  5.1129 +                  x - a
  5.1130 + ---------------------------------------------------------------*)
  5.1131 +lemma NSDERIVD1: "[| NSDERIV f (g x) :> Da;
  5.1132 +         ( *f* g) (hypreal_of_real(x) + xa) \<noteq> hypreal_of_real (g x);
  5.1133 +         ( *f* g) (hypreal_of_real(x) + xa) \<approx> hypreal_of_real (g x)
  5.1134 +      |] ==> (( *f* f) (( *f* g) (hypreal_of_real(x) + xa))
  5.1135 +                   + - hypreal_of_real (f (g x)))
  5.1136 +              / (( *f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real (g x))
  5.1137 +             \<approx> hypreal_of_real(Da)"
  5.1138 +by (auto simp add: NSDERIV_NSLIM_iff2 NSLIM_def diff_minus [symmetric])
  5.1139 +
  5.1140 +(*--------------------------------------------------------------
  5.1141 +   from other version of differentiability
  5.1142 +
  5.1143 +                f(x + h) - f(x)
  5.1144 +               ----------------- \<approx> Db
  5.1145 +                       h
  5.1146 + --------------------------------------------------------------*)
  5.1147 +lemma NSDERIVD2: "[| NSDERIV g x :> Db; xa \<in> Infinitesimal; xa \<noteq> 0 |]
  5.1148 +      ==> (( *f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real(g x)) / xa
  5.1149 +          \<approx> hypreal_of_real(Db)"
  5.1150 +by (auto simp add: NSDERIV_NSLIM_iff NSLIM_def mem_infmal_iff starfun_lambda_cancel)
  5.1151 +
  5.1152 +lemma lemma_chain: "(z::hypreal) \<noteq> 0 ==> x*y = (x*inverse(z))*(z*y)"
  5.1153 +by auto
  5.1154 +
  5.1155 +(*------------------------------------------------------
  5.1156 +  This proof uses both definitions of differentiability.
  5.1157 + ------------------------------------------------------*)
  5.1158 +lemma NSDERIV_chain: "[| NSDERIV f (g x) :> Da; NSDERIV g x :> Db |]
  5.1159 +      ==> NSDERIV (f o g) x :> Da * Db"
  5.1160 +apply (simp (no_asm_simp) add: NSDERIV_NSLIM_iff NSLIM_def
  5.1161 +                mem_infmal_iff [symmetric])
  5.1162 +apply clarify
  5.1163 +apply (frule_tac f = g in NSDERIV_approx)
  5.1164 +apply (auto simp add: starfun_lambda_cancel2 starfun_o [symmetric])
  5.1165 +apply (case_tac "( *f* g) (hypreal_of_real (x) + xa) = hypreal_of_real (g x) ")
  5.1166 +apply (drule_tac g = g in NSDERIV_zero)
  5.1167 +apply (auto simp add: divide_inverse)
  5.1168 +apply (rule_tac z1 = "( *f* g) (hypreal_of_real (x) + xa) + -hypreal_of_real (g x) " and y1 = "inverse xa" in lemma_chain [THEN ssubst])
  5.1169 +apply (erule hypreal_not_eq_minus_iff [THEN iffD1])
  5.1170 +apply (rule approx_mult_hypreal_of_real)
  5.1171 +apply (simp_all add: divide_inverse [symmetric])
  5.1172 +apply (blast intro: NSDERIVD1 approx_minus_iff [THEN iffD2])
  5.1173 +apply (blast intro: NSDERIVD2)
  5.1174 +done
  5.1175 +
  5.1176 +(* standard version *)
  5.1177 +lemma DERIV_chain: "[| DERIV f (g x) :> Da; DERIV g x :> Db |] ==> DERIV (f o g) x :> Da * Db"
  5.1178 +by (simp add: NSDERIV_DERIV_iff [symmetric] NSDERIV_chain)
  5.1179 +
  5.1180 +lemma DERIV_chain2: "[| DERIV f (g x) :> Da; DERIV g x :> Db |] ==> DERIV (%x. f (g x)) x :> Da * Db"
  5.1181 +by (auto dest: DERIV_chain simp add: o_def)
  5.1182 +
  5.1183 +text{*Differentiation of natural number powers*}
  5.1184 +lemma NSDERIV_Id: "NSDERIV (%x. x) x :> 1"
  5.1185 +by (auto simp add: NSDERIV_NSLIM_iff NSLIM_def starfun_Id)
  5.1186 +declare NSDERIV_Id [simp]
  5.1187 +
  5.1188 +(*derivative of the identity function*)
  5.1189 +lemma DERIV_Id: "DERIV (%x. x) x :> 1"
  5.1190 +by (simp add: NSDERIV_DERIV_iff [symmetric])
  5.1191 +declare DERIV_Id [simp]
  5.1192 +
  5.1193 +lemmas isCont_Id = DERIV_Id [THEN DERIV_isCont, standard]
  5.1194 +
  5.1195 +(*derivative of linear multiplication*)
  5.1196 +lemma DERIV_cmult_Id: "DERIV (op * c) x :> c"
  5.1197 +by (cut_tac c = c and x = x in DERIV_Id [THEN DERIV_cmult], simp)
  5.1198 +declare DERIV_cmult_Id [simp]
  5.1199 +
  5.1200 +lemma NSDERIV_cmult_Id: "NSDERIV (op * c) x :> c"
  5.1201 +by (simp add: NSDERIV_DERIV_iff)
  5.1202 +declare NSDERIV_cmult_Id [simp]
  5.1203 +
  5.1204 +lemma DERIV_pow: "DERIV (%x. x ^ n) x :> real n * (x ^ (n - Suc 0))"
  5.1205 +apply (induct_tac "n")
  5.1206 +apply (drule_tac [2] DERIV_Id [THEN DERIV_mult])
  5.1207 +apply (auto simp add: real_of_nat_Suc left_distrib)
  5.1208 +apply (case_tac "0 < n")
  5.1209 +apply (drule_tac x = x in realpow_minus_mult)
  5.1210 +apply (auto simp add: real_mult_assoc real_add_commute)
  5.1211 +done
  5.1212 +
  5.1213 +(* NS version *)
  5.1214 +lemma NSDERIV_pow: "NSDERIV (%x. x ^ n) x :> real n * (x ^ (n - Suc 0))"
  5.1215 +by (simp add: NSDERIV_DERIV_iff DERIV_pow)
  5.1216 +
  5.1217 +(*---------------------------------------------------------------
  5.1218 +                    Power of -1
  5.1219 + ---------------------------------------------------------------*)
  5.1220 +
  5.1221 +(*Can't get rid of x \<noteq> 0 because it isn't continuous at zero*)
  5.1222 +lemma NSDERIV_inverse:
  5.1223 +     "x \<noteq> 0 ==> NSDERIV (%x. inverse(x)) x :> (- (inverse x ^ Suc (Suc 0)))"
  5.1224 +apply (simp add: nsderiv_def)
  5.1225 +apply (rule ballI, simp, clarify) 
  5.1226 +apply (frule Infinitesimal_add_not_zero)
  5.1227 +prefer 2 apply (simp add: add_commute) 
  5.1228 +apply (auto simp add: starfun_inverse_inverse realpow_two 
  5.1229 +        simp del: minus_mult_left [symmetric] minus_mult_right [symmetric])
  5.1230 +apply (simp add: inverse_add inverse_mult_distrib [symmetric]
  5.1231 +              inverse_minus_eq [symmetric] add_ac mult_ac
  5.1232 +            del: inverse_mult_distrib inverse_minus_eq 
  5.1233 +                 minus_mult_left [symmetric] minus_mult_right [symmetric])
  5.1234 +apply (simp (no_asm_simp) add: mult_assoc [symmetric] right_distrib
  5.1235 +            del: minus_mult_left [symmetric] minus_mult_right [symmetric])
  5.1236 +apply (rule_tac y = " inverse (- hypreal_of_real x * hypreal_of_real x) " in approx_trans)
  5.1237 +apply (rule inverse_add_Infinitesimal_approx2)
  5.1238 +apply (auto dest!: hypreal_of_real_HFinite_diff_Infinitesimal 
  5.1239 +            simp add: inverse_minus_eq [symmetric] HFinite_minus_iff)
  5.1240 +apply (rule Infinitesimal_HFinite_mult2, auto)
  5.1241 +done
  5.1242 +
  5.1243 +
  5.1244 +
  5.1245 +
  5.1246 +lemma DERIV_inverse: "x \<noteq> 0 ==> DERIV (%x. inverse(x)) x :> (-(inverse x ^ Suc (Suc 0)))"
  5.1247 +by (simp add: NSDERIV_inverse NSDERIV_DERIV_iff [symmetric] del: realpow_Suc)
  5.1248 +
  5.1249 +text{*Derivative of inverse*}
  5.1250 +lemma DERIV_inverse_fun: "[| DERIV f x :> d; f(x) \<noteq> 0 |]
  5.1251 +      ==> DERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ Suc (Suc 0))))"
  5.1252 +apply (simp only: mult_commute [of d] minus_mult_left power_inverse)
  5.1253 +apply (fold o_def)
  5.1254 +apply (blast intro!: DERIV_chain DERIV_inverse)
  5.1255 +done
  5.1256 +
  5.1257 +lemma NSDERIV_inverse_fun: "[| NSDERIV f x :> d; f(x) \<noteq> 0 |]
  5.1258 +      ==> NSDERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ Suc (Suc 0))))"
  5.1259 +by (simp add: NSDERIV_DERIV_iff DERIV_inverse_fun del: realpow_Suc)
  5.1260 +
  5.1261 +text{*Derivative of quotient*}
  5.1262 +lemma DERIV_quotient: "[| DERIV f x :> d; DERIV g x :> e; g(x) \<noteq> 0 |]
  5.1263 +       ==> DERIV (%y. f(y) / (g y)) x :> (d*g(x) + -(e*f(x))) / (g(x) ^ Suc (Suc 0))"
  5.1264 +apply (drule_tac f = g in DERIV_inverse_fun)
  5.1265 +apply (drule_tac [2] DERIV_mult)
  5.1266 +apply (assumption+)
  5.1267 +apply (simp add: divide_inverse right_distrib power_inverse minus_mult_left
  5.1268 +                 mult_ac 
  5.1269 +     del: realpow_Suc minus_mult_right [symmetric] minus_mult_left [symmetric])
  5.1270 +done
  5.1271 +
  5.1272 +lemma NSDERIV_quotient: "[| NSDERIV f x :> d; DERIV g x :> e; g(x) \<noteq> 0 |]
  5.1273 +       ==> NSDERIV (%y. f(y) / (g y)) x :> (d*g(x)
  5.1274 +                            + -(e*f(x))) / (g(x) ^ Suc (Suc 0))"
  5.1275 +by (simp add: NSDERIV_DERIV_iff DERIV_quotient del: realpow_Suc)
  5.1276 +
  5.1277 +(* ------------------------------------------------------------------------ *)
  5.1278 +(* Caratheodory formulation of derivative at a point: standard proof        *)
  5.1279 +(* ------------------------------------------------------------------------ *)
  5.1280 +
  5.1281 +lemma CARAT_DERIV:
  5.1282 +     "(DERIV f x :> l) =
  5.1283 +      (\<exists>g. (\<forall>z. f z - f x = g z * (z-x)) & isCont g x & g x = l)"
  5.1284 +      (is "?lhs = ?rhs")
  5.1285 +proof
  5.1286 +  assume der: "DERIV f x :> l"
  5.1287 +  show "\<exists>g. (\<forall>z. f z - f x = g z * (z-x)) \<and> isCont g x \<and> g x = l"
  5.1288 +  proof (intro exI conjI)
  5.1289 +    let ?g = "(%z. if z = x then l else (f z - f x) / (z-x))"
  5.1290 +    show "\<forall>z. f z - f x = ?g z * (z-x)" by simp
  5.1291 +    show "isCont ?g x" using der 
  5.1292 +      by (simp add: isCont_iff DERIV_iff diff_minus 
  5.1293 +               cong: LIM_equal [rule_format])
  5.1294 +    show "?g x = l" by simp
  5.1295 +  qed
  5.1296 +next
  5.1297 +  assume "?rhs"
  5.1298 +  then obtain g where 
  5.1299 +    "(\<forall>z. f z - f x = g z * (z-x))" and "isCont g x" and "g x = l" by blast
  5.1300 +  thus "(DERIV f x :> l)" 
  5.1301 +     by (auto simp add: isCont_iff DERIV_iff diff_minus 
  5.1302 +               cong: LIM_equal [rule_format])
  5.1303 +qed
  5.1304 +
  5.1305 +
  5.1306 +lemma CARAT_NSDERIV: "NSDERIV f x :> l ==>
  5.1307 +      \<exists>g. (\<forall>z. f z - f x = g z * (z-x)) & isNSCont g x & g x = l"
  5.1308 +by (auto simp add: NSDERIV_DERIV_iff isNSCont_isCont_iff CARAT_DERIV)
  5.1309 +
  5.1310 +lemma hypreal_eq_minus_iff3: "(x = y + z) = (x + -z = (y::hypreal))"
  5.1311 +by auto
  5.1312 +
  5.1313 +lemma CARAT_DERIVD:
  5.1314 +  assumes all: "\<forall>z. f z - f x = g z * (z-x)"
  5.1315 +      and nsc: "isNSCont g x"
  5.1316 +  shows "NSDERIV f x :> g x"
  5.1317 +proof -
  5.1318 +  from nsc
  5.1319 +  have "\<forall>w. w \<noteq> hypreal_of_real x \<and> w \<approx> hypreal_of_real x \<longrightarrow>
  5.1320 +         ( *f* g) w * (w - hypreal_of_real x) / (w - hypreal_of_real x) \<approx>
  5.1321 +         hypreal_of_real (g x)" 
  5.1322 +    by (simp add: diff_minus isNSCont_def)
  5.1323 +  thus ?thesis using all
  5.1324 +    by (simp add: NSDERIV_iff2 starfun_if_eq cong: if_cong) 
  5.1325 +qed
  5.1326 +
  5.1327 +(*--------------------------------------------------------------------------*)
  5.1328 +(* Lemmas about nested intervals and proof by bisection (cf.Harrison)       *)
  5.1329 +(* All considerably tidied by lcp                                           *)
  5.1330 +(*--------------------------------------------------------------------------*)
  5.1331 +
  5.1332 +lemma lemma_f_mono_add [rule_format (no_asm)]: "(\<forall>n. (f::nat=>real) n \<le> f (Suc n)) --> f m \<le> f(m + no)"
  5.1333 +apply (induct_tac "no")
  5.1334 +apply (auto intro: order_trans)
  5.1335 +done
  5.1336 +
  5.1337 +lemma f_inc_g_dec_Beq_f: "[| \<forall>n. f(n) \<le> f(Suc n);
  5.1338 +         \<forall>n. g(Suc n) \<le> g(n);
  5.1339 +         \<forall>n. f(n) \<le> g(n) |]
  5.1340 +      ==> Bseq f"
  5.1341 +apply (rule_tac k = "f 0" and K = "g 0" in BseqI2, rule allI)
  5.1342 +apply (induct_tac "n")
  5.1343 +apply (auto intro: order_trans)
  5.1344 +apply (rule_tac y = "g (Suc na) " in order_trans)
  5.1345 +apply (induct_tac [2] "na")
  5.1346 +apply (auto intro: order_trans)
  5.1347 +done
  5.1348 +
  5.1349 +lemma f_inc_g_dec_Beq_g: "[| \<forall>n. f(n) \<le> f(Suc n);
  5.1350 +         \<forall>n. g(Suc n) \<le> g(n);
  5.1351 +         \<forall>n. f(n) \<le> g(n) |]
  5.1352 +      ==> Bseq g"
  5.1353 +apply (subst Bseq_minus_iff [symmetric])
  5.1354 +apply (rule_tac g = "%x. - (f x) " in f_inc_g_dec_Beq_f)
  5.1355 +apply auto
  5.1356 +done
  5.1357 +
  5.1358 +lemma f_inc_imp_le_lim: "[| \<forall>n. f n \<le> f (Suc n);  convergent f |] ==> f n \<le> lim f"
  5.1359 +apply (rule linorder_not_less [THEN iffD1])
  5.1360 +apply (auto simp add: convergent_LIMSEQ_iff LIMSEQ_iff monoseq_Suc)
  5.1361 +apply (drule real_less_sum_gt_zero)
  5.1362 +apply (drule_tac x = "f n + - lim f" in spec, safe)
  5.1363 +apply (drule_tac P = "%na. no\<le>na --> ?Q na" and x = "no + n" in spec, auto)
  5.1364 +apply (subgoal_tac "lim f \<le> f (no + n) ")
  5.1365 +apply (induct_tac [2] "no")
  5.1366 +apply (auto intro: order_trans simp add: diff_minus real_abs_def)
  5.1367 +apply (drule_tac no=no and m=n in lemma_f_mono_add)
  5.1368 +apply (auto simp add: add_commute)
  5.1369 +done
  5.1370 +
  5.1371 +lemma lim_uminus: "convergent g ==> lim (%x. - g x) = - (lim g)"
  5.1372 +apply (rule LIMSEQ_minus [THEN limI])
  5.1373 +apply (simp add: convergent_LIMSEQ_iff)
  5.1374 +done
  5.1375 +
  5.1376 +lemma g_dec_imp_lim_le: "[| \<forall>n. g(Suc n) \<le> g(n);  convergent g |] ==> lim g \<le> g n"
  5.1377 +apply (subgoal_tac "- (g n) \<le> - (lim g) ")
  5.1378 +apply (cut_tac [2] f = "%x. - (g x) " in f_inc_imp_le_lim)
  5.1379 +apply (auto simp add: lim_uminus convergent_minus_iff [symmetric])
  5.1380 +done
  5.1381 +
  5.1382 +lemma lemma_nest: "[| \<forall>n. f(n) \<le> f(Suc n);
  5.1383 +         \<forall>n. g(Suc n) \<le> g(n);
  5.1384 +         \<forall>n. f(n) \<le> g(n) |]
  5.1385 +      ==> \<exists>l m. l \<le> m &  ((\<forall>n. f(n) \<le> l) & f ----> l) &
  5.1386 +                            ((\<forall>n. m \<le> g(n)) & g ----> m)"
  5.1387 +apply (subgoal_tac "monoseq f & monoseq g")
  5.1388 +prefer 2 apply (force simp add: LIMSEQ_iff monoseq_Suc)
  5.1389 +apply (subgoal_tac "Bseq f & Bseq g")
  5.1390 +prefer 2 apply (blast intro: f_inc_g_dec_Beq_f f_inc_g_dec_Beq_g)
  5.1391 +apply (auto dest!: Bseq_monoseq_convergent simp add: convergent_LIMSEQ_iff)
  5.1392 +apply (rule_tac x = "lim f" in exI)
  5.1393 +apply (rule_tac x = "lim g" in exI)
  5.1394 +apply (auto intro: LIMSEQ_le)
  5.1395 +apply (auto simp add: f_inc_imp_le_lim g_dec_imp_lim_le convergent_LIMSEQ_iff)
  5.1396 +done
  5.1397 +
  5.1398 +lemma lemma_nest_unique: "[| \<forall>n. f(n) \<le> f(Suc n);
  5.1399 +         \<forall>n. g(Suc n) \<le> g(n);
  5.1400 +         \<forall>n. f(n) \<le> g(n);
  5.1401 +         (%n. f(n) - g(n)) ----> 0 |]
  5.1402 +      ==> \<exists>l. ((\<forall>n. f(n) \<le> l) & f ----> l) &
  5.1403 +                ((\<forall>n. l \<le> g(n)) & g ----> l)"
  5.1404 +apply (drule lemma_nest, auto)
  5.1405 +apply (subgoal_tac "l = m")
  5.1406 +apply (drule_tac [2] X = f in LIMSEQ_diff)
  5.1407 +apply (auto intro: LIMSEQ_unique)
  5.1408 +done
  5.1409 +
  5.1410 +text{*The universal quantifiers below are required for the declaration
  5.1411 +  of @{text Bolzano_nest_unique} below.*}
  5.1412 +
  5.1413 +lemma Bolzano_bisect_le:
  5.1414 + "a \<le> b ==> \<forall>n. fst (Bolzano_bisect P a b n) \<le> snd (Bolzano_bisect P a b n)"
  5.1415 +apply (rule allI)
  5.1416 +apply (induct_tac "n")
  5.1417 +apply (auto simp add: Let_def split_def)
  5.1418 +done
  5.1419 +
  5.1420 +lemma Bolzano_bisect_fst_le_Suc: "a \<le> b ==>
  5.1421 +   \<forall>n. fst(Bolzano_bisect P a b n) \<le> fst (Bolzano_bisect P a b (Suc n))"
  5.1422 +apply (rule allI)
  5.1423 +apply (induct_tac "n")
  5.1424 +apply (auto simp add: Bolzano_bisect_le Let_def split_def)
  5.1425 +done
  5.1426 +
  5.1427 +lemma Bolzano_bisect_Suc_le_snd: "a \<le> b ==>
  5.1428 +   \<forall>n. snd(Bolzano_bisect P a b (Suc n)) \<le> snd (Bolzano_bisect P a b n)"
  5.1429 +apply (rule allI)
  5.1430 +apply (induct_tac "n")
  5.1431 +apply (auto simp add: Bolzano_bisect_le Let_def split_def)
  5.1432 +done
  5.1433 +
  5.1434 +lemma eq_divide_2_times_iff: "((x::real) = y / (2 * z)) = (2 * x = y/z)"
  5.1435 +apply auto
  5.1436 +apply (drule_tac f = "%u. (1/2) *u" in arg_cong)
  5.1437 +apply auto
  5.1438 +done
  5.1439 +
  5.1440 +lemma Bolzano_bisect_diff:
  5.1441 +     "a \<le> b ==>
  5.1442 +      snd(Bolzano_bisect P a b n) - fst(Bolzano_bisect P a b n) =
  5.1443 +      (b-a) / (2 ^ n)"
  5.1444 +apply (induct_tac "n")
  5.1445 +apply (auto simp add: eq_divide_2_times_iff add_divide_distrib Let_def split_def)
  5.1446 +apply (auto simp add: add_ac Bolzano_bisect_le diff_minus)
  5.1447 +done
  5.1448 +
  5.1449 +lemmas Bolzano_nest_unique =
  5.1450 +    lemma_nest_unique
  5.1451 +    [OF Bolzano_bisect_fst_le_Suc Bolzano_bisect_Suc_le_snd Bolzano_bisect_le]
  5.1452 +
  5.1453 +
  5.1454 +lemma not_P_Bolzano_bisect:
  5.1455 +  assumes P:    "!!a b c. [| P(a,b); P(b,c); a \<le> b; b \<le> c|] ==> P(a,c)"
  5.1456 +      and notP: "~ P(a,b)"
  5.1457 +      and le:   "a \<le> b"
  5.1458 +  shows "~ P(fst(Bolzano_bisect P a b n), snd(Bolzano_bisect P a b n))"
  5.1459 +proof (induct n)
  5.1460 +  case 0 thus ?case by simp
  5.1461 + next
  5.1462 +  case (Suc n)
  5.1463 +  thus ?case
  5.1464 + by (auto simp del: surjective_pairing [symmetric] 
  5.1465 +             simp add: Let_def split_def Bolzano_bisect_le [OF le] 
  5.1466 +     P [of "fst (Bolzano_bisect P a b n)" _ "snd (Bolzano_bisect P a b n)"]) 
  5.1467 +qed
  5.1468 +
  5.1469 +(*Now we re-package P_prem as a formula*)
  5.1470 +lemma not_P_Bolzano_bisect':
  5.1471 +     "[| \<forall>a b c. P(a,b) & P(b,c) & a \<le> b & b \<le> c --> P(a,c);
  5.1472 +         ~ P(a,b);  a \<le> b |] ==>
  5.1473 +      \<forall>n. ~ P(fst(Bolzano_bisect P a b n), snd(Bolzano_bisect P a b n))"
  5.1474 +by (blast elim!: not_P_Bolzano_bisect [THEN [2] rev_notE])
  5.1475 +
  5.1476 +
  5.1477 +
  5.1478 +lemma lemma_BOLZANO:
  5.1479 +     "[| \<forall>a b c. P(a,b) & P(b,c) & a \<le> b & b \<le> c --> P(a,c);
  5.1480 +         \<forall>x. \<exists>d::real. 0 < d &
  5.1481 +                (\<forall>a b. a \<le> x & x \<le> b & (b-a) < d --> P(a,b));
  5.1482 +         a \<le> b |]
  5.1483 +      ==> P(a,b)"
  5.1484 +apply (rule Bolzano_nest_unique [where P1=P, THEN exE], assumption+)
  5.1485 +apply (rule LIMSEQ_minus_cancel)
  5.1486 +apply (simp (no_asm_simp) add: Bolzano_bisect_diff LIMSEQ_divide_realpow_zero)
  5.1487 +apply (rule ccontr)
  5.1488 +apply (drule not_P_Bolzano_bisect', assumption+)
  5.1489 +apply (rename_tac "l")
  5.1490 +apply (drule_tac x = l in spec, clarify)
  5.1491 +apply (simp add: LIMSEQ_def)
  5.1492 +apply (drule_tac P = "%r. 0<r --> ?Q r" and x = "d/2" in spec)
  5.1493 +apply (drule_tac P = "%r. 0<r --> ?Q r" and x = "d/2" in spec)
  5.1494 +apply (drule real_less_half_sum, auto) 
  5.1495 +apply (drule_tac x = "fst (Bolzano_bisect P a b (no + noa))" in spec)
  5.1496 +apply (drule_tac x = "snd (Bolzano_bisect P a b (no + noa))" in spec)
  5.1497 +apply safe
  5.1498 +apply (simp_all (no_asm_simp))
  5.1499 +apply (rule_tac y = "abs (fst (Bolzano_bisect P a b (no + noa)) - l) + abs (snd (Bolzano_bisect P a b (no + noa)) - l) " in order_le_less_trans)
  5.1500 +apply (simp (no_asm_simp) add: abs_if)
  5.1501 +apply (rule real_sum_of_halves [THEN subst])
  5.1502 +apply (rule add_strict_mono)
  5.1503 +apply (simp_all add: diff_minus [symmetric])
  5.1504 +done
  5.1505 +
  5.1506 +
  5.1507 +lemma lemma_BOLZANO2: "((\<forall>a b c. (a \<le> b & b \<le> c & P(a,b) & P(b,c)) --> P(a,c)) &
  5.1508 +       (\<forall>x. \<exists>d::real. 0 < d &
  5.1509 +                (\<forall>a b. a \<le> x & x \<le> b & (b-a) < d --> P(a,b))))
  5.1510 +      --> (\<forall>a b. a \<le> b --> P(a,b))"
  5.1511 +apply clarify
  5.1512 +apply (blast intro: lemma_BOLZANO)
  5.1513 +done
  5.1514 +
  5.1515 +
  5.1516 +subsection{*Intermediate Value Theorem: Prove Contrapositive by Bisection*}
  5.1517 +
  5.1518 +lemma IVT: "[| f(a) \<le> y; y \<le> f(b);
  5.1519 +         a \<le> b;
  5.1520 +         (\<forall>x. a \<le> x & x \<le> b --> isCont f x) |]
  5.1521 +      ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y"
  5.1522 +apply (rule contrapos_pp, assumption)
  5.1523 +apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> ~ (f (u) \<le> y & y \<le> f (v))" in lemma_BOLZANO2)
  5.1524 +apply safe
  5.1525 +apply simp_all
  5.1526 +apply (simp add: isCont_iff LIM_def)
  5.1527 +apply (rule ccontr)
  5.1528 +apply (subgoal_tac "a \<le> x & x \<le> b")
  5.1529 + prefer 2
  5.1530 + apply simp 
  5.1531 + apply (drule_tac P = "%d. 0<d --> ?P d" and x = 1 in spec, arith)
  5.1532 +apply (drule_tac x = x in spec)+
  5.1533 +apply simp
  5.1534 +apply (drule_tac P = "%r. ?P r --> (\<exists>s. 0<s & ?Q r s) " and x = "\<bar>y - f x\<bar> " in spec)
  5.1535 +apply safe
  5.1536 +apply simp
  5.1537 +apply (drule_tac x = s in spec, clarify)
  5.1538 +apply (cut_tac x = "f x" and y = y in linorder_less_linear, safe)
  5.1539 +apply (drule_tac x = "ba-x" in spec)
  5.1540 +apply (simp_all add: abs_if)
  5.1541 +apply (drule_tac x = "aa-x" in spec)
  5.1542 +apply (case_tac "x \<le> aa", simp_all)
  5.1543 +apply (drule_tac x = x and y = aa in order_antisym)
  5.1544 +apply (assumption, simp)
  5.1545 +done
  5.1546 +
  5.1547 +lemma IVT2: "[| f(b) \<le> y; y \<le> f(a);
  5.1548 +         a \<le> b;
  5.1549 +         (\<forall>x. a \<le> x & x \<le> b --> isCont f x)
  5.1550 +      |] ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y"
  5.1551 +apply (subgoal_tac "- f a \<le> -y & -y \<le> - f b", clarify) 
  5.1552 +apply (drule IVT [where f = "%x. - f x"], assumption)
  5.1553 +apply (auto intro: isCont_minus)
  5.1554 +done
  5.1555 +
  5.1556 +(*HOL style here: object-level formulations*)
  5.1557 +lemma IVT_objl: "(f(a) \<le> y & y \<le> f(b) & a \<le> b &
  5.1558 +      (\<forall>x. a \<le> x & x \<le> b --> isCont f x))
  5.1559 +      --> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)"
  5.1560 +apply (blast intro: IVT)
  5.1561 +done
  5.1562 +
  5.1563 +lemma IVT2_objl: "(f(b) \<le> y & y \<le> f(a) & a \<le> b &
  5.1564 +      (\<forall>x. a \<le> x & x \<le> b --> isCont f x))
  5.1565 +      --> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)"
  5.1566 +apply (blast intro: IVT2)
  5.1567 +done
  5.1568 +
  5.1569 +(*---------------------------------------------------------------------------*)
  5.1570 +(* By bisection, function continuous on closed interval is bounded above     *)
  5.1571 +(*---------------------------------------------------------------------------*)
  5.1572 +
  5.1573 +
  5.1574 +lemma isCont_bounded:
  5.1575 +     "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  5.1576 +      ==> \<exists>M. \<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M"
  5.1577 +apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> (\<exists>M. \<forall>x. u \<le> x & x \<le> v --> f x \<le> M) " in lemma_BOLZANO2)
  5.1578 +apply safe
  5.1579 +apply simp_all
  5.1580 +apply (rename_tac x xa ya M Ma)
  5.1581 +apply (cut_tac x = M and y = Ma in linorder_linear, safe)
  5.1582 +apply (rule_tac x = Ma in exI, clarify)
  5.1583 +apply (cut_tac x = xb and y = xa in linorder_linear, force)
  5.1584 +apply (rule_tac x = M in exI, clarify)
  5.1585 +apply (cut_tac x = xb and y = xa in linorder_linear, force)
  5.1586 +apply (case_tac "a \<le> x & x \<le> b")
  5.1587 +apply (rule_tac [2] x = 1 in exI)
  5.1588 +prefer 2 apply force
  5.1589 +apply (simp add: LIM_def isCont_iff)
  5.1590 +apply (drule_tac x = x in spec, auto)
  5.1591 +apply (erule_tac V = "\<forall>M. \<exists>x. a \<le> x & x \<le> b & ~ f x \<le> M" in thin_rl)
  5.1592 +apply (drule_tac x = 1 in spec, auto)
  5.1593 +apply (rule_tac x = s in exI, clarify)
  5.1594 +apply (rule_tac x = "\<bar>f x\<bar> + 1" in exI, clarify)
  5.1595 +apply (drule_tac x = "xa-x" in spec)
  5.1596 +apply (auto simp add: abs_ge_self, arith+)
  5.1597 +done
  5.1598 +
  5.1599 +(*----------------------------------------------------------------------------*)
  5.1600 +(* Refine the above to existence of least upper bound                         *)
  5.1601 +(*----------------------------------------------------------------------------*)
  5.1602 +
  5.1603 +lemma lemma_reals_complete: "((\<exists>x. x \<in> S) & (\<exists>y. isUb UNIV S (y::real))) -->
  5.1604 +      (\<exists>t. isLub UNIV S t)"
  5.1605 +apply (blast intro: reals_complete)
  5.1606 +done
  5.1607 +
  5.1608 +lemma isCont_has_Ub: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  5.1609 +         ==> \<exists>M. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  5.1610 +                   (\<forall>N. N < M --> (\<exists>x. a \<le> x & x \<le> b & N < f(x)))"
  5.1611 +apply (cut_tac S = "Collect (%y. \<exists>x. a \<le> x & x \<le> b & y = f x) " in lemma_reals_complete)
  5.1612 +apply auto
  5.1613 +apply (drule isCont_bounded, assumption)
  5.1614 +apply (auto simp add: isUb_def leastP_def isLub_def setge_def setle_def)
  5.1615 +apply (rule exI, auto)
  5.1616 +apply (auto dest!: spec simp add: linorder_not_less) 
  5.1617 +done
  5.1618 +
  5.1619 +(*----------------------------------------------------------------------------*)
  5.1620 +(* Now show that it attains its upper bound                                   *)
  5.1621 +(*----------------------------------------------------------------------------*)
  5.1622 +
  5.1623 +lemma isCont_eq_Ub:
  5.1624 +  assumes le: "a \<le> b"
  5.1625 +      and con: "\<forall>x. a \<le> x & x \<le> b --> isCont f x"
  5.1626 +  shows "\<exists>M. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  5.1627 +             (\<exists>x. a \<le> x & x \<le> b & f(x) = M)"
  5.1628 +proof -
  5.1629 +  from isCont_has_Ub [OF le con]
  5.1630 +  obtain M where M1: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> f x \<le> M"
  5.1631 +             and M2: "!!N. N<M ==> \<exists>x. a \<le> x \<and> x \<le> b \<and> N < f x"  by blast
  5.1632 +  show ?thesis
  5.1633 +  proof (intro exI, intro conjI)
  5.1634 +    show " \<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> f x \<le> M" by (rule M1)
  5.1635 +    show "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = M" 
  5.1636 +    proof (rule ccontr)
  5.1637 +      assume "\<not> (\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = M)"
  5.1638 +      with M1 have M3: "\<forall>x. a \<le> x & x \<le> b --> f x < M"
  5.1639 +        by (auto simp add: linorder_not_le [symmetric] intro: order_antisym)
  5.1640 +      hence "\<forall>x. a \<le> x & x \<le> b --> isCont (%x. inverse (M - f x)) x"
  5.1641 +        by (auto simp add: isCont_inverse isCont_diff con)
  5.1642 +      from isCont_bounded [OF le this]
  5.1643 +      obtain k where k: "!!x. a \<le> x & x \<le> b --> inverse (M - f x) \<le> k" by auto
  5.1644 +      have Minv: "!!x. a \<le> x & x \<le> b --> 0 < inverse (M - f (x))"
  5.1645 +        by (simp add: M3) 
  5.1646 +      have "!!x. a \<le> x & x \<le> b --> inverse (M - f x) < k+1" using k 
  5.1647 +        by (auto intro: order_le_less_trans [of _ k]) 
  5.1648 +      with Minv 
  5.1649 +      have "!!x. a \<le> x & x \<le> b --> inverse(k+1) < inverse(inverse(M - f x))" 
  5.1650 +        by (intro strip less_imp_inverse_less, simp_all)
  5.1651 +      hence invlt: "!!x. a \<le> x & x \<le> b --> inverse(k+1) < M - f x" 
  5.1652 +        by simp
  5.1653 +      have "M - inverse (k+1) < M" using k [of a] Minv [of a] le 
  5.1654 +        by (simp, arith)
  5.1655 +      from M2 [OF this]
  5.1656 +      obtain x where ax: "a \<le> x & x \<le> b & M - inverse(k+1) < f x" ..
  5.1657 +      thus False using invlt [of x] by force
  5.1658 +    qed
  5.1659 +  qed
  5.1660 +qed
  5.1661 +
  5.1662 +
  5.1663 +
  5.1664 +(*----------------------------------------------------------------------------*)
  5.1665 +(* Same theorem for lower bound                                               *)
  5.1666 +(*----------------------------------------------------------------------------*)
  5.1667 +
  5.1668 +lemma isCont_eq_Lb: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  5.1669 +         ==> \<exists>M. (\<forall>x. a \<le> x & x \<le> b --> M \<le> f(x)) &
  5.1670 +                   (\<exists>x. a \<le> x & x \<le> b & f(x) = M)"
  5.1671 +apply (subgoal_tac "\<forall>x. a \<le> x & x \<le> b --> isCont (%x. - (f x)) x")
  5.1672 +prefer 2 apply (blast intro: isCont_minus)
  5.1673 +apply (drule_tac f = " (%x. - (f x))" in isCont_eq_Ub)
  5.1674 +apply safe
  5.1675 +apply auto
  5.1676 +done
  5.1677 +
  5.1678 +
  5.1679 +(* ------------------------------------------------------------------------- *)
  5.1680 +(* Another version.                                                          *)
  5.1681 +(* ------------------------------------------------------------------------- *)
  5.1682 +
  5.1683 +lemma isCont_Lb_Ub: "[|a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  5.1684 +      ==> \<exists>L M. (\<forall>x. a \<le> x & x \<le> b --> L \<le> f(x) & f(x) \<le> M) &
  5.1685 +          (\<forall>y. L \<le> y & y \<le> M --> (\<exists>x. a \<le> x & x \<le> b & (f(x) = y)))"
  5.1686 +apply (frule isCont_eq_Lb)
  5.1687 +apply (frule_tac [2] isCont_eq_Ub)
  5.1688 +apply (assumption+, safe)
  5.1689 +apply (rule_tac x = "f x" in exI)
  5.1690 +apply (rule_tac x = "f xa" in exI, simp, safe)
  5.1691 +apply (cut_tac x = x and y = xa in linorder_linear, safe)
  5.1692 +apply (cut_tac f = f and a = x and b = xa and y = y in IVT_objl)
  5.1693 +apply (cut_tac [2] f = f and a = xa and b = x and y = y in IVT2_objl, safe)
  5.1694 +apply (rule_tac [2] x = xb in exI)
  5.1695 +apply (rule_tac [4] x = xb in exI, simp_all)
  5.1696 +done
  5.1697 +
  5.1698 +(*----------------------------------------------------------------------------*)
  5.1699 +(* If f'(x) > 0 then x is locally strictly increasing at the right            *)
  5.1700 +(*----------------------------------------------------------------------------*)
  5.1701 +
  5.1702 +lemma DERIV_left_inc:
  5.1703 +    "[| DERIV f x :> l;  0 < l |]
  5.1704 +     ==> \<exists>d. 0 < d & (\<forall>h. 0 < h & h < d --> f(x) < f(x + h))"
  5.1705 +apply (simp add: deriv_def LIM_def)
  5.1706 +apply (drule spec, auto)
  5.1707 +apply (rule_tac x = s in exI, auto)
  5.1708 +apply (subgoal_tac "0 < l*h")
  5.1709 + prefer 2 apply (simp add: zero_less_mult_iff)
  5.1710 +apply (drule_tac x = h in spec)
  5.1711 +apply (simp add: real_abs_def pos_le_divide_eq pos_less_divide_eq 
  5.1712 +            split add: split_if_asm)
  5.1713 +done
  5.1714 +
  5.1715 +lemma DERIV_left_dec:
  5.1716 +  assumes der: "DERIV f x :> l"
  5.1717 +      and l:   "l < 0"
  5.1718 +  shows "\<exists>d. 0 < d & (\<forall>h. 0 < h & h < d --> f(x) < f(x-h))"
  5.1719 +proof -
  5.1720 +  from l der [THEN DERIV_D, THEN LIM_D [where r = "-l"]]
  5.1721 +  have "\<exists>s. 0 < s \<and>
  5.1722 +              (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < -l)"
  5.1723 +    by (simp add: diff_minus)
  5.1724 +  then obtain s
  5.1725 +        where s:   "0 < s" 
  5.1726 +          and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < -l"
  5.1727 +    by auto
  5.1728 +  thus ?thesis
  5.1729 +  proof (intro exI conjI strip)
  5.1730 +    show "0<s" .
  5.1731 +    fix h::real
  5.1732 +    assume "0 < h \<and> h < s"
  5.1733 +    with all [of "-h"] show "f x < f (x-h)" 
  5.1734 +    proof (simp add: real_abs_def pos_less_divide_eq diff_minus [symmetric] 
  5.1735 +		split add: split_if_asm)
  5.1736 +      assume "~ l \<le> - ((f (x-h) - f x) / h)" and h: "0 < h" 
  5.1737 +      with l 
  5.1738 +      have "0 < (f (x-h) - f x) / h" by arith
  5.1739 +      thus "f x < f (x-h)"
  5.1740 +	by (simp add: pos_less_divide_eq h)
  5.1741 +    qed
  5.1742 +  qed
  5.1743 +qed
  5.1744 +
  5.1745 +lemma DERIV_local_max: 
  5.1746 +  assumes der: "DERIV f x :> l"
  5.1747 +      and d:   "0 < d"
  5.1748 +      and le:  "\<forall>y. \<bar>x-y\<bar> < d --> f(y) \<le> f(x)"
  5.1749 +  shows "l = 0"
  5.1750 +proof (cases rule: linorder_cases [of l 0])
  5.1751 +  case equal show ?thesis .
  5.1752 +next
  5.1753 +  case less
  5.1754 +  from DERIV_left_dec [OF der less]
  5.1755 +  obtain d' where d': "0 < d'"
  5.1756 +             and lt: "\<forall>h. 0 < h \<and> h < d' \<longrightarrow> f x < f (x-h)" by blast
  5.1757 +  from real_lbound_gt_zero [OF d d']
  5.1758 +  obtain e where "0 < e \<and> e < d \<and> e < d'" ..
  5.1759 +  with lt le [THEN spec [where x="x-e"]] 
  5.1760 +  show ?thesis by (auto simp add: abs_if)
  5.1761 +next
  5.1762 +  case greater
  5.1763 +  from DERIV_left_inc [OF der greater]
  5.1764 +  obtain d' where d': "0 < d'"
  5.1765 +             and lt: "\<forall>h. 0 < h \<and> h < d' \<longrightarrow> f x < f (x + h)" by blast
  5.1766 +  from real_lbound_gt_zero [OF d d']
  5.1767 +  obtain e where "0 < e \<and> e < d \<and> e < d'" ..
  5.1768 +  with lt le [THEN spec [where x="x+e"]]
  5.1769 +  show ?thesis by (auto simp add: abs_if)
  5.1770 +qed
  5.1771 +
  5.1772 +
  5.1773 +text{*Similar theorem for a local minimum*}
  5.1774 +lemma DERIV_local_min:
  5.1775 +     "[| DERIV f x :> l; 0 < d; \<forall>y. \<bar>x-y\<bar> < d --> f(x) \<le> f(y) |] ==> l = 0"
  5.1776 +by (drule DERIV_minus [THEN DERIV_local_max], auto)
  5.1777 +
  5.1778 +
  5.1779 +text{*In particular, if a function is locally flat*}
  5.1780 +lemma DERIV_local_const:
  5.1781 +     "[| DERIV f x :> l; 0 < d; \<forall>y. \<bar>x-y\<bar> < d --> f(x) = f(y) |] ==> l = 0"
  5.1782 +by (auto dest!: DERIV_local_max)
  5.1783 +
  5.1784 +text{*Lemma about introducing open ball in open interval*}
  5.1785 +lemma lemma_interval_lt:
  5.1786 +     "[| a < x;  x < b |] 
  5.1787 +      ==> \<exists>d::real. 0 < d & (\<forall>y. \<bar>x-y\<bar> < d --> a < y & y < b)"
  5.1788 +apply (simp add: abs_interval_iff)
  5.1789 +apply (insert linorder_linear [of "x-a" "b-x"], safe)
  5.1790 +apply (rule_tac x = "x-a" in exI)
  5.1791 +apply (rule_tac [2] x = "b-x" in exI, auto)
  5.1792 +done
  5.1793 +
  5.1794 +lemma lemma_interval: "[| a < x;  x < b |] ==>
  5.1795 +        \<exists>d::real. 0 < d &  (\<forall>y. \<bar>x-y\<bar> < d --> a \<le> y & y \<le> b)"
  5.1796 +apply (drule lemma_interval_lt, auto)
  5.1797 +apply (auto intro!: exI)
  5.1798 +done
  5.1799 +
  5.1800 +text{*Rolle's Theorem.
  5.1801 +   If @{term f} is defined and continuous on the closed interval 
  5.1802 +   @{text "[a,b]"} and differentiable on the open interval @{text "(a,b)"}, 
  5.1803 +   and @{term "f(a) = f(b)"},
  5.1804 +   then there exists @{text "x0 \<in> (a,b)"} such that @{term "f'(x0) = 0"}*}
  5.1805 +theorem Rolle: 
  5.1806 +  assumes lt: "a < b"
  5.1807 +      and eq: "f(a) = f(b)"
  5.1808 +      and con: "\<forall>x. a \<le> x & x \<le> b --> isCont f x"
  5.1809 +      and dif [rule_format]: "\<forall>x. a < x & x < b --> f differentiable x"
  5.1810 +  shows "\<exists>z. a < z & z < b & DERIV f z :> 0"
  5.1811 +proof -
  5.1812 +  have le: "a \<le> b" using lt by simp
  5.1813 +  from isCont_eq_Ub [OF le con]
  5.1814 +  obtain x where x_max: "\<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> f z \<le> f x" 
  5.1815 +             and alex: "a \<le> x" and xleb: "x \<le> b" 
  5.1816 +    by blast
  5.1817 +  from isCont_eq_Lb [OF le con]
  5.1818 +  obtain x' where x'_min: "\<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> f x' \<le> f z" 
  5.1819 +              and alex': "a \<le> x'" and x'leb: "x' \<le> b" 
  5.1820 +    by blast
  5.1821 +  show ?thesis
  5.1822 +  proof cases
  5.1823 +    assume axb: "a < x & x < b"
  5.1824 +        --{*@{term f} attains its maximum within the interval*}
  5.1825 +    hence ax: "a<x" and xb: "x<b" by auto
  5.1826 +    from lemma_interval [OF ax xb]
  5.1827 +    obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  5.1828 +      by blast
  5.1829 +    hence bound': "\<forall>y. \<bar>x-y\<bar> < d \<longrightarrow> f y \<le> f x" using x_max
  5.1830 +      by blast
  5.1831 +    from differentiableD [OF dif [OF axb]]
  5.1832 +    obtain l where der: "DERIV f x :> l" ..
  5.1833 +    have "l=0" by (rule DERIV_local_max [OF der d bound']) 
  5.1834 +        --{*the derivative at a local maximum is zero*}
  5.1835 +    thus ?thesis using ax xb der by auto
  5.1836 +  next
  5.1837 +    assume notaxb: "~ (a < x & x < b)"
  5.1838 +    hence xeqab: "x=a | x=b" using alex xleb by arith
  5.1839 +    hence fb_eq_fx: "f b = f x" by (auto simp add: eq) 
  5.1840 +    show ?thesis
  5.1841 +    proof cases
  5.1842 +      assume ax'b: "a < x' & x' < b"
  5.1843 +        --{*@{term f} attains its minimum within the interval*}
  5.1844 +      hence ax': "a<x'" and x'b: "x'<b" by auto
  5.1845 +      from lemma_interval [OF ax' x'b]
  5.1846 +      obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  5.1847 +	by blast
  5.1848 +      hence bound': "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> f x' \<le> f y" using x'_min
  5.1849 +	by blast
  5.1850 +      from differentiableD [OF dif [OF ax'b]]
  5.1851 +      obtain l where der: "DERIV f x' :> l" ..
  5.1852 +      have "l=0" by (rule DERIV_local_min [OF der d bound']) 
  5.1853 +        --{*the derivative at a local minimum is zero*}
  5.1854 +      thus ?thesis using ax' x'b der by auto
  5.1855 +    next
  5.1856 +      assume notax'b: "~ (a < x' & x' < b)"
  5.1857 +        --{*@{term f} is constant througout the interval*}
  5.1858 +      hence x'eqab: "x'=a | x'=b" using alex' x'leb by arith
  5.1859 +      hence fb_eq_fx': "f b = f x'" by (auto simp add: eq) 
  5.1860 +      from dense [OF lt]
  5.1861 +      obtain r where ar: "a < r" and rb: "r < b" by blast
  5.1862 +      from lemma_interval [OF ar rb]
  5.1863 +      obtain d where d: "0<d" and bound: "\<forall>y. \<bar>r-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  5.1864 +	by blast
  5.1865 +      have eq_fb: "\<forall>z. a \<le> z --> z \<le> b --> f z = f b" 
  5.1866 +      proof (clarify) 
  5.1867 +        fix z::real
  5.1868 +        assume az: "a \<le> z" and zb: "z \<le> b"
  5.1869 +        show "f z = f b"
  5.1870 +        proof (rule order_antisym)
  5.1871 +          show "f z \<le> f b" by (simp add: fb_eq_fx x_max az zb) 
  5.1872 +          show "f b \<le> f z" by (simp add: fb_eq_fx' x'_min az zb) 
  5.1873 +        qed
  5.1874 +      qed
  5.1875 +      have bound': "\<forall>y. \<bar>r-y\<bar> < d \<longrightarrow> f r = f y"
  5.1876 +      proof (intro strip)
  5.1877 +        fix y::real
  5.1878 +        assume lt: "\<bar>r-y\<bar> < d"
  5.1879 +        hence "f y = f b" by (simp add: eq_fb bound) 
  5.1880 +        thus "f r = f y" by (simp add: eq_fb ar rb order_less_imp_le)
  5.1881 +      qed
  5.1882 +      from differentiableD [OF dif [OF conjI [OF ar rb]]]
  5.1883 +      obtain l where der: "DERIV f r :> l" ..
  5.1884 +      have "l=0" by (rule DERIV_local_const [OF der d bound']) 
  5.1885 +        --{*the derivative of a constant function is zero*}
  5.1886 +      thus ?thesis using ar rb der by auto
  5.1887 +    qed
  5.1888 +  qed
  5.1889 +qed
  5.1890 +
  5.1891 +
  5.1892 +subsection{*Mean Value Theorem*}
  5.1893 +
  5.1894 +lemma lemma_MVT:
  5.1895 +     "f a - (f b - f a)/(b-a) * a = f b - (f b - f a)/(b-a) * (b::real)"
  5.1896 +proof cases
  5.1897 +  assume "a=b" thus ?thesis by simp
  5.1898 +next
  5.1899 +  assume "a\<noteq>b" 
  5.1900 +  hence ba: "b-a \<noteq> 0" by arith
  5.1901 +  show ?thesis
  5.1902 +    by (rule real_mult_left_cancel [OF ba, THEN iffD1],
  5.1903 +        simp add: right_diff_distrib, simp add: left_diff_distrib)
  5.1904 +qed
  5.1905 +
  5.1906 +theorem MVT: 
  5.1907 +  assumes lt:  "a < b"
  5.1908 +      and con: "\<forall>x. a \<le> x & x \<le> b --> isCont f x"
  5.1909 +      and dif [rule_format]: "\<forall>x. a < x & x < b --> f differentiable x"
  5.1910 +  shows "\<exists>l z. a < z & z < b & DERIV f z :> l &
  5.1911 +                   (f(b) - f(a) = (b-a) * l)"
  5.1912 +proof -
  5.1913 +  let ?F = "%x. f x - ((f b - f a) / (b-a)) * x"
  5.1914 +  have contF: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont ?F x" using con
  5.1915 +    by (fast intro: isCont_diff isCont_const isCont_mult isCont_Id) 
  5.1916 +  have difF: "\<forall>x. a < x \<and> x < b \<longrightarrow> ?F differentiable x"
  5.1917 +  proof (clarify)
  5.1918 +    fix x::real
  5.1919 +    assume ax: "a < x" and xb: "x < b"
  5.1920 +    from differentiableD [OF dif [OF conjI [OF ax xb]]]
  5.1921 +    obtain l where der: "DERIV f x :> l" ..
  5.1922 +    show "?F differentiable x"
  5.1923 +      by (rule differentiableI [where D = "l - (f b - f a)/(b-a)"],
  5.1924 +          blast intro: DERIV_diff DERIV_cmult_Id der) 
  5.1925 +  qed  
  5.1926 +  from Rolle [where f = ?F, OF lt lemma_MVT contF difF]
  5.1927 +  obtain z where az: "a < z" and zb: "z < b" and der: "DERIV ?F z :> 0" 
  5.1928 +    by blast
  5.1929 +  have "DERIV (%x. ((f b - f a)/(b-a)) * x) z :> (f b - f a)/(b-a)"
  5.1930 +    by (rule DERIV_cmult_Id)
  5.1931 +  hence derF: "DERIV (\<lambda>x. ?F x + (f b - f a) / (b - a) * x) z 
  5.1932 +                   :> 0 + (f b - f a) / (b - a)"
  5.1933 +    by (rule DERIV_add [OF der])
  5.1934 +  show ?thesis  
  5.1935 +  proof (intro exI conjI)
  5.1936 +    show "a < z" .
  5.1937 +    show "z < b" .
  5.1938 +    show "f b - f a = (b - a) * ((f b - f a)/(b-a))" by simp
  5.1939 +    show "DERIV f z :> ((f b - f a)/(b-a))"  using derF by simp
  5.1940 +  qed
  5.1941 +qed
  5.1942 +
  5.1943 +
  5.1944 +text{*A function is constant if its derivative is 0 over an interval.*}
  5.1945 +
  5.1946 +lemma DERIV_isconst_end: "[| a < b;
  5.1947 +         \<forall>x. a \<le> x & x \<le> b --> isCont f x;
  5.1948 +         \<forall>x. a < x & x < b --> DERIV f x :> 0 |]
  5.1949 +        ==> (f b = f a)"
  5.1950 +apply (drule MVT, assumption)
  5.1951 +apply (blast intro: differentiableI)
  5.1952 +apply (auto dest!: DERIV_unique simp add: diff_eq_eq)
  5.1953 +done
  5.1954 +
  5.1955 +lemma DERIV_isconst1: "[| a < b;
  5.1956 +         \<forall>x. a \<le> x & x \<le> b --> isCont f x;
  5.1957 +         \<forall>x. a < x & x < b --> DERIV f x :> 0 |]
  5.1958 +        ==> \<forall>x. a \<le> x & x \<le> b --> f x = f a"
  5.1959 +apply safe
  5.1960 +apply (drule_tac x = a in order_le_imp_less_or_eq, safe)
  5.1961 +apply (drule_tac b = x in DERIV_isconst_end, auto)
  5.1962 +done
  5.1963 +
  5.1964 +lemma DERIV_isconst2: "[| a < b;
  5.1965 +         \<forall>x. a \<le> x & x \<le> b --> isCont f x;
  5.1966 +         \<forall>x. a < x & x < b --> DERIV f x :> 0;
  5.1967 +         a \<le> x; x \<le> b |]
  5.1968 +        ==> f x = f a"
  5.1969 +apply (blast dest: DERIV_isconst1)
  5.1970 +done
  5.1971 +
  5.1972 +lemma DERIV_isconst_all: "\<forall>x. DERIV f x :> 0 ==> f(x) = f(y)"
  5.1973 +apply (rule linorder_cases [of x y])
  5.1974 +apply (blast intro: sym DERIV_isCont DERIV_isconst_end)+
  5.1975 +done
  5.1976 +
  5.1977 +lemma DERIV_const_ratio_const:
  5.1978 +     "[|a \<noteq> b; \<forall>x. DERIV f x :> k |] ==> (f(b) - f(a)) = (b-a) * k"
  5.1979 +apply (rule linorder_cases [of a b], auto)
  5.1980 +apply (drule_tac [!] f = f in MVT)
  5.1981 +apply (auto dest: DERIV_isCont DERIV_unique simp add: differentiable_def)
  5.1982 +apply (auto dest: DERIV_unique simp add: left_distrib diff_minus)
  5.1983 +done
  5.1984 +
  5.1985 +lemma DERIV_const_ratio_const2:
  5.1986 +     "[|a \<noteq> b; \<forall>x. DERIV f x :> k |] ==> (f(b) - f(a))/(b-a) = k"
  5.1987 +apply (rule_tac c1 = "b-a" in real_mult_right_cancel [THEN iffD1])
  5.1988 +apply (auto dest!: DERIV_const_ratio_const simp add: real_mult_assoc)
  5.1989 +done
  5.1990 +
  5.1991 +lemma real_average_minus_first: "((a + b) /2 - a) = (b-a)/(2::real)"
  5.1992 +by auto
  5.1993 +declare real_average_minus_first [simp]
  5.1994 +
  5.1995 +lemma real_average_minus_second: "((b + a)/2 - a) = (b-a)/(2::real)"
  5.1996 +by auto
  5.1997 +declare real_average_minus_second [simp]
  5.1998 +
  5.1999 +text{*Gallileo's "trick": average velocity = av. of end velocities*}
  5.2000 +
  5.2001 +lemma DERIV_const_average:
  5.2002 +  assumes neq: "a \<noteq> (b::real)"
  5.2003 +      and der: "\<forall>x. DERIV v x :> k"
  5.2004 +  shows "v ((a + b)/2) = (v a + v b)/2"
  5.2005 +proof (cases rule: linorder_cases [of a b])
  5.2006 +  case equal with neq show ?thesis by simp
  5.2007 +next
  5.2008 +  case less
  5.2009 +  have "(v b - v a) / (b - a) = k"
  5.2010 +    by (rule DERIV_const_ratio_const2 [OF neq der])
  5.2011 +  hence "(b-a) * ((v b - v a) / (b-a)) = (b-a) * k" by simp 
  5.2012 +  moreover have "(v ((a + b) / 2) - v a) / ((a + b) / 2 - a) = k"
  5.2013 +    by (rule DERIV_const_ratio_const2 [OF _ der], simp add: neq)
  5.2014 +  ultimately show ?thesis using neq by force
  5.2015 +next
  5.2016 +  case greater
  5.2017 +  have "(v b - v a) / (b - a) = k"
  5.2018 +    by (rule DERIV_const_ratio_const2 [OF neq der])
  5.2019 +  hence "(b-a) * ((v b - v a) / (b-a)) = (b-a) * k" by simp 
  5.2020 +  moreover have " (v ((b + a) / 2) - v a) / ((b + a) / 2 - a) = k"
  5.2021 +    by (rule DERIV_const_ratio_const2 [OF _ der], simp add: neq)
  5.2022 +  ultimately show ?thesis using neq by (force simp add: add_commute) 
  5.2023 +qed
  5.2024 +
  5.2025 +
  5.2026 +text{*Dull lemma: an continuous injection on an interval must have a
  5.2027 +strict maximum at an end point, not in the middle.*}
  5.2028 +
  5.2029 +lemma lemma_isCont_inj:
  5.2030 +  assumes d: "0 < d"
  5.2031 +      and inj [rule_format]: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  5.2032 +      and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  5.2033 +  shows "\<exists>z. \<bar>z-x\<bar> \<le> d & f x < f z"
  5.2034 +proof (rule ccontr)
  5.2035 +  assume  "~ (\<exists>z. \<bar>z-x\<bar> \<le> d & f x < f z)"
  5.2036 +  hence all [rule_format]: "\<forall>z. \<bar>z - x\<bar> \<le> d --> f z \<le> f x" by auto 
  5.2037 +  show False
  5.2038 +  proof (cases rule: linorder_le_cases [of "f(x-d)" "f(x+d)"])
  5.2039 +    case le
  5.2040 +    from d cont all [of "x+d"]
  5.2041 +    have flef: "f(x+d) \<le> f x" 
  5.2042 +     and xlex: "x - d \<le> x" 
  5.2043 +     and cont': "\<forall>z. x - d \<le> z \<and> z \<le> x \<longrightarrow> isCont f z" 
  5.2044 +       by (auto simp add: abs_if)
  5.2045 +    from IVT [OF le flef xlex cont']
  5.2046 +    obtain x' where "x-d \<le> x'" "x' \<le> x" "f x' = f(x+d)" by blast
  5.2047 +    moreover
  5.2048 +    hence "g(f x') = g (f(x+d))" by simp
  5.2049 +    ultimately show False using d inj [of x'] inj [of "x+d"]
  5.2050 +      by (simp add: abs_le_interval_iff)
  5.2051 +  next
  5.2052 +    case ge
  5.2053 +    from d cont all [of "x-d"]
  5.2054 +    have flef: "f(x-d) \<le> f x" 
  5.2055 +     and xlex: "x \<le> x+d" 
  5.2056 +     and cont': "\<forall>z. x \<le> z \<and> z \<le> x+d \<longrightarrow> isCont f z" 
  5.2057 +       by (auto simp add: abs_if)
  5.2058 +    from IVT2 [OF ge flef xlex cont']
  5.2059 +    obtain x' where "x \<le> x'" "x' \<le> x+d" "f x' = f(x-d)" by blast
  5.2060 +    moreover
  5.2061 +    hence "g(f x') = g (f(x-d))" by simp
  5.2062 +    ultimately show False using d inj [of x'] inj [of "x-d"]
  5.2063 +      by (simp add: abs_le_interval_iff)
  5.2064 +  qed
  5.2065 +qed
  5.2066 +
  5.2067 +
  5.2068 +text{*Similar version for lower bound.*}
  5.2069 +
  5.2070 +lemma lemma_isCont_inj2:
  5.2071 +     "[|0 < d; \<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z;
  5.2072 +        \<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z |]
  5.2073 +      ==> \<exists>z. \<bar>z-x\<bar> \<le> d & f z < f x"
  5.2074 +apply (insert lemma_isCont_inj
  5.2075 +          [where f = "%x. - f x" and g = "%y. g(-y)" and x = x and d = d])
  5.2076 +apply (simp add: isCont_minus linorder_not_le) 
  5.2077 +done
  5.2078 +
  5.2079 +text{*Show there's an interval surrounding @{term "f(x)"} in 
  5.2080 +@{text "f[[x - d, x + d]]"} .*}
  5.2081 +
  5.2082 +lemma isCont_inj_range: 
  5.2083 +  assumes d: "0 < d"
  5.2084 +      and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  5.2085 +      and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  5.2086 +  shows "\<exists>e. 0<e & (\<forall>y. \<bar>y - f x\<bar> \<le> e --> (\<exists>z. \<bar>z-x\<bar> \<le> d & f z = y))"
  5.2087 +proof -
  5.2088 +  have "x-d \<le> x+d" "\<forall>z. x-d \<le> z \<and> z \<le> x+d \<longrightarrow> isCont f z" using cont d
  5.2089 +    by (auto simp add: abs_le_interval_iff)
  5.2090 +  from isCont_Lb_Ub [OF this]
  5.2091 +  obtain L M 
  5.2092 +  where all1 [rule_format]: "\<forall>z. x-d \<le> z \<and> z \<le> x+d \<longrightarrow> L \<le> f z \<and> f z \<le> M"
  5.2093 +    and all2 [rule_format]:
  5.2094 +           "\<forall>y. L \<le> y \<and> y \<le> M \<longrightarrow> (\<exists>z. x-d \<le> z \<and> z \<le> x+d \<and> f z = y)"
  5.2095 +    by auto
  5.2096 +  with d have "L \<le> f x & f x \<le> M" by simp
  5.2097 +  moreover have "L \<noteq> f x"
  5.2098 +  proof -
  5.2099 +    from lemma_isCont_inj2 [OF d inj cont]
  5.2100 +    obtain u where "\<bar>u - x\<bar> \<le> d" "f u < f x"  by auto
  5.2101 +    thus ?thesis using all1 [of u] by arith
  5.2102 +  qed
  5.2103 +  moreover have "f x \<noteq> M"
  5.2104 +  proof -
  5.2105 +    from lemma_isCont_inj [OF d inj cont]
  5.2106 +    obtain u where "\<bar>u - x\<bar> \<le> d" "f x < f u"  by auto
  5.2107 +    thus ?thesis using all1 [of u] by arith
  5.2108 +  qed
  5.2109 +  ultimately have "L < f x & f x < M" by arith
  5.2110 +  hence "0 < f x - L" "0 < M - f x" by arith+
  5.2111 +  from real_lbound_gt_zero [OF this]
  5.2112 +  obtain e where e: "0 < e" "e < f x - L" "e < M - f x" by auto
  5.2113 +  thus ?thesis
  5.2114 +  proof (intro exI conjI)
  5.2115 +    show "0<e" .
  5.2116 +    show "\<forall>y. \<bar>y - f x\<bar> \<le> e \<longrightarrow> (\<exists>z. \<bar>z - x\<bar> \<le> d \<and> f z = y)"
  5.2117 +    proof (intro strip)
  5.2118 +      fix y::real
  5.2119 +      assume "\<bar>y - f x\<bar> \<le> e"
  5.2120 +      with e have "L \<le> y \<and> y \<le> M" by arith
  5.2121 +      from all2 [OF this]
  5.2122 +      obtain z where "x - d \<le> z" "z \<le> x + d" "f z = y" by blast
  5.2123 +      thus "\<exists>z. \<bar>z - x\<bar> \<le> d \<and> f z = y" 
  5.2124 +        by (force simp add: abs_le_interval_iff)
  5.2125 +    qed
  5.2126 +  qed
  5.2127 +qed
  5.2128 +
  5.2129 +
  5.2130 +text{*Continuity of inverse function*}
  5.2131 +
  5.2132 +lemma isCont_inverse_function:
  5.2133 +  assumes d: "0 < d"
  5.2134 +      and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  5.2135 +      and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  5.2136 +  shows "isCont g (f x)"
  5.2137 +proof (simp add: isCont_iff LIM_eq)
  5.2138 +  show "\<forall>r. 0 < r \<longrightarrow>
  5.2139 +         (\<exists>s. 0<s \<and> (\<forall>z. z\<noteq>0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>g(f x + z) - g(f x)\<bar> < r))"
  5.2140 +  proof (intro strip)
  5.2141 +    fix r::real
  5.2142 +    assume r: "0<r"
  5.2143 +    from real_lbound_gt_zero [OF r d]
  5.2144 +    obtain e where e: "0 < e" and e_lt: "e < r \<and> e < d" by blast
  5.2145 +    with inj cont
  5.2146 +    have e_simps: "\<forall>z. \<bar>z-x\<bar> \<le> e --> g (f z) = z" 
  5.2147 +                  "\<forall>z. \<bar>z-x\<bar> \<le> e --> isCont f z"   by auto
  5.2148 +    from isCont_inj_range [OF e this]
  5.2149 +    obtain e' where e': "0 < e'" 
  5.2150 +        and all: "\<forall>y. \<bar>y - f x\<bar> \<le> e' \<longrightarrow> (\<exists>z. \<bar>z - x\<bar> \<le> e \<and> f z = y)"
  5.2151 +          by blast
  5.2152 +    show "\<exists>s. 0<s \<and> (\<forall>z. z\<noteq>0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>g(f x + z) - g(f x)\<bar> < r)"
  5.2153 +    proof (intro exI conjI)
  5.2154 +      show "0<e'" .
  5.2155 +      show "\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < e' \<longrightarrow> \<bar>g (f x + z) - g (f x)\<bar> < r"
  5.2156 +      proof (intro strip)
  5.2157 +        fix z::real
  5.2158 +        assume z: "z \<noteq> 0 \<and> \<bar>z\<bar> < e'"
  5.2159 +        with e e_lt e_simps all [rule_format, of "f x + z"]
  5.2160 +        show "\<bar>g (f x + z) - g (f x)\<bar> < r" by force
  5.2161 +      qed
  5.2162 +    qed
  5.2163 +  qed
  5.2164 +qed  
  5.2165 +
  5.2166 +ML
  5.2167 +{*
  5.2168 +val LIM_def = thm"LIM_def";
  5.2169 +val NSLIM_def = thm"NSLIM_def";
  5.2170 +val isCont_def = thm"isCont_def";
  5.2171 +val isNSCont_def = thm"isNSCont_def";
  5.2172 +val deriv_def = thm"deriv_def";
  5.2173 +val nsderiv_def = thm"nsderiv_def";
  5.2174 +val differentiable_def = thm"differentiable_def";
  5.2175 +val NSdifferentiable_def = thm"NSdifferentiable_def";
  5.2176 +val increment_def = thm"increment_def";
  5.2177 +val isUCont_def = thm"isUCont_def";
  5.2178 +val isNSUCont_def = thm"isNSUCont_def";
  5.2179 +
  5.2180 +val half_gt_zero_iff = thm "half_gt_zero_iff";
  5.2181 +val half_gt_zero = thms "half_gt_zero";
  5.2182 +val abs_diff_triangle_ineq = thm "abs_diff_triangle_ineq";
  5.2183 +val LIM_eq = thm "LIM_eq";
  5.2184 +val LIM_D = thm "LIM_D";
  5.2185 +val LIM_const = thm "LIM_const";
  5.2186 +val LIM_add = thm "LIM_add";
  5.2187 +val LIM_minus = thm "LIM_minus";
  5.2188 +val LIM_add_minus = thm "LIM_add_minus";
  5.2189 +val LIM_diff = thm "LIM_diff";
  5.2190 +val LIM_const_not_eq = thm "LIM_const_not_eq";
  5.2191 +val LIM_const_eq = thm "LIM_const_eq";
  5.2192 +val LIM_unique = thm "LIM_unique";
  5.2193 +val LIM_mult_zero = thm "LIM_mult_zero";
  5.2194 +val LIM_self = thm "LIM_self";
  5.2195 +val LIM_equal = thm "LIM_equal";
  5.2196 +val LIM_trans = thm "LIM_trans";
  5.2197 +val LIM_NSLIM = thm "LIM_NSLIM";
  5.2198 +val NSLIM_LIM = thm "NSLIM_LIM";
  5.2199 +val LIM_NSLIM_iff = thm "LIM_NSLIM_iff";
  5.2200 +val NSLIM_mult = thm "NSLIM_mult";
  5.2201 +val LIM_mult2 = thm "LIM_mult2";
  5.2202 +val NSLIM_add = thm "NSLIM_add";
  5.2203 +val LIM_add2 = thm "LIM_add2";
  5.2204 +val NSLIM_const = thm "NSLIM_const";
  5.2205 +val LIM_const2 = thm "LIM_const2";
  5.2206 +val NSLIM_minus = thm "NSLIM_minus";
  5.2207 +val LIM_minus2 = thm "LIM_minus2";
  5.2208 +val NSLIM_add_minus = thm "NSLIM_add_minus";
  5.2209 +val LIM_add_minus2 = thm "LIM_add_minus2";
  5.2210 +val NSLIM_inverse = thm "NSLIM_inverse";
  5.2211 +val LIM_inverse = thm "LIM_inverse";
  5.2212 +val NSLIM_zero = thm "NSLIM_zero";
  5.2213 +val LIM_zero2 = thm "LIM_zero2";
  5.2214 +val NSLIM_zero_cancel = thm "NSLIM_zero_cancel";
  5.2215 +val LIM_zero_cancel = thm "LIM_zero_cancel";
  5.2216 +val NSLIM_not_zero = thm "NSLIM_not_zero";
  5.2217 +val NSLIM_const_not_eq = thm "NSLIM_const_not_eq";
  5.2218 +val NSLIM_const_eq = thm "NSLIM_const_eq";
  5.2219 +val NSLIM_unique = thm "NSLIM_unique";
  5.2220 +val LIM_unique2 = thm "LIM_unique2";
  5.2221 +val NSLIM_mult_zero = thm "NSLIM_mult_zero";
  5.2222 +val LIM_mult_zero2 = thm "LIM_mult_zero2";
  5.2223 +val NSLIM_self = thm "NSLIM_self";
  5.2224 +val isNSContD = thm "isNSContD";
  5.2225 +val isNSCont_NSLIM = thm "isNSCont_NSLIM";
  5.2226 +val NSLIM_isNSCont = thm "NSLIM_isNSCont";
  5.2227 +val isNSCont_NSLIM_iff = thm "isNSCont_NSLIM_iff";
  5.2228 +val isNSCont_LIM_iff = thm "isNSCont_LIM_iff";
  5.2229 +val isNSCont_isCont_iff = thm "isNSCont_isCont_iff";
  5.2230 +val isCont_isNSCont = thm "isCont_isNSCont";
  5.2231 +val isNSCont_isCont = thm "isNSCont_isCont";
  5.2232 +val NSLIM_h_iff = thm "NSLIM_h_iff";
  5.2233 +val NSLIM_isCont_iff = thm "NSLIM_isCont_iff";
  5.2234 +val LIM_isCont_iff = thm "LIM_isCont_iff";
  5.2235 +val isCont_iff = thm "isCont_iff";
  5.2236 +val isCont_add = thm "isCont_add";
  5.2237 +val isCont_mult = thm "isCont_mult";
  5.2238 +val isCont_o = thm "isCont_o";
  5.2239 +val isCont_o2 = thm "isCont_o2";
  5.2240 +val isNSCont_minus = thm "isNSCont_minus";
  5.2241 +val isCont_minus = thm "isCont_minus";
  5.2242 +val isCont_inverse = thm "isCont_inverse";
  5.2243 +val isNSCont_inverse = thm "isNSCont_inverse";
  5.2244 +val isCont_diff = thm "isCont_diff";
  5.2245 +val isCont_const = thm "isCont_const";
  5.2246 +val isNSCont_const = thm "isNSCont_const";
  5.2247 +val isNSCont_rabs = thm "isNSCont_rabs";
  5.2248 +val isCont_rabs = thm "isCont_rabs";
  5.2249 +val isNSUContD = thm "isNSUContD";
  5.2250 +val isUCont_isCont = thm "isUCont_isCont";
  5.2251 +val isUCont_isNSUCont = thm "isUCont_isNSUCont";
  5.2252 +val isNSUCont_isUCont = thm "isNSUCont_isUCont";
  5.2253 +val DERIV_iff = thm "DERIV_iff";
  5.2254 +val DERIV_NS_iff = thm "DERIV_NS_iff";
  5.2255 +val DERIV_D = thm "DERIV_D";
  5.2256 +val NS_DERIV_D = thm "NS_DERIV_D";
  5.2257 +val DERIV_unique = thm "DERIV_unique";
  5.2258 +val NSDeriv_unique = thm "NSDeriv_unique";
  5.2259 +val differentiableD = thm "differentiableD";
  5.2260 +val differentiableI = thm "differentiableI";
  5.2261 +val NSdifferentiableD = thm "NSdifferentiableD";
  5.2262 +val NSdifferentiableI = thm "NSdifferentiableI";
  5.2263 +val LIM_I = thm "LIM_I";
  5.2264 +val DERIV_LIM_iff = thm "DERIV_LIM_iff";
  5.2265 +val DERIV_iff2 = thm "DERIV_iff2";
  5.2266 +val NSDERIV_NSLIM_iff = thm "NSDERIV_NSLIM_iff";
  5.2267 +val NSDERIV_NSLIM_iff2 = thm "NSDERIV_NSLIM_iff2";
  5.2268 +val NSDERIV_iff2 = thm "NSDERIV_iff2";
  5.2269 +val hypreal_not_eq_minus_iff = thm "hypreal_not_eq_minus_iff";
  5.2270 +val NSDERIVD5 = thm "NSDERIVD5";
  5.2271 +val NSDERIVD4 = thm "NSDERIVD4";
  5.2272 +val NSDERIVD3 = thm "NSDERIVD3";
  5.2273 +val NSDERIV_DERIV_iff = thm "NSDERIV_DERIV_iff";
  5.2274 +val NSDERIV_isNSCont = thm "NSDERIV_isNSCont";
  5.2275 +val DERIV_isCont = thm "DERIV_isCont";
  5.2276 +val NSDERIV_const = thm "NSDERIV_const";
  5.2277 +val DERIV_const = thm "DERIV_const";
  5.2278 +val NSDERIV_add = thm "NSDERIV_add";
  5.2279 +val DERIV_add = thm "DERIV_add";
  5.2280 +val NSDERIV_mult = thm "NSDERIV_mult";
  5.2281 +val DERIV_mult = thm "DERIV_mult";
  5.2282 +val NSDERIV_cmult = thm "NSDERIV_cmult";
  5.2283 +val DERIV_cmult = thm "DERIV_cmult";
  5.2284 +val NSDERIV_minus = thm "NSDERIV_minus";
  5.2285 +val DERIV_minus = thm "DERIV_minus";
  5.2286 +val NSDERIV_add_minus = thm "NSDERIV_add_minus";
  5.2287 +val DERIV_add_minus = thm "DERIV_add_minus";
  5.2288 +val NSDERIV_diff = thm "NSDERIV_diff";
  5.2289 +val DERIV_diff = thm "DERIV_diff";
  5.2290 +val incrementI = thm "incrementI";
  5.2291 +val incrementI2 = thm "incrementI2";
  5.2292 +val increment_thm = thm "increment_thm";
  5.2293 +val increment_thm2 = thm "increment_thm2";
  5.2294 +val increment_approx_zero = thm "increment_approx_zero";
  5.2295 +val NSDERIV_zero = thm "NSDERIV_zero";
  5.2296 +val NSDERIV_approx = thm "NSDERIV_approx";
  5.2297 +val NSDERIVD1 = thm "NSDERIVD1";
  5.2298 +val NSDERIVD2 = thm "NSDERIVD2";
  5.2299 +val NSDERIV_chain = thm "NSDERIV_chain";
  5.2300 +val DERIV_chain = thm "DERIV_chain";
  5.2301 +val DERIV_chain2 = thm "DERIV_chain2";
  5.2302 +val NSDERIV_Id = thm "NSDERIV_Id";
  5.2303 +val DERIV_Id = thm "DERIV_Id";
  5.2304 +val isCont_Id = thms "isCont_Id";
  5.2305 +val DERIV_cmult_Id = thm "DERIV_cmult_Id";
  5.2306 +val NSDERIV_cmult_Id = thm "NSDERIV_cmult_Id";
  5.2307 +val DERIV_pow = thm "DERIV_pow";
  5.2308 +val NSDERIV_pow = thm "NSDERIV_pow";
  5.2309 +val NSDERIV_inverse = thm "NSDERIV_inverse";
  5.2310 +val DERIV_inverse = thm "DERIV_inverse";
  5.2311 +val DERIV_inverse_fun = thm "DERIV_inverse_fun";
  5.2312 +val NSDERIV_inverse_fun = thm "NSDERIV_inverse_fun";
  5.2313 +val DERIV_quotient = thm "DERIV_quotient";
  5.2314 +val NSDERIV_quotient = thm "NSDERIV_quotient";
  5.2315 +val CARAT_DERIV = thm "CARAT_DERIV";
  5.2316 +val CARAT_NSDERIV = thm "CARAT_NSDERIV";
  5.2317 +val hypreal_eq_minus_iff3 = thm "hypreal_eq_minus_iff3";
  5.2318 +val starfun_if_eq = thm "starfun_if_eq";
  5.2319 +val CARAT_DERIVD = thm "CARAT_DERIVD";
  5.2320 +val f_inc_g_dec_Beq_f = thm "f_inc_g_dec_Beq_f";
  5.2321 +val f_inc_g_dec_Beq_g = thm "f_inc_g_dec_Beq_g";
  5.2322 +val f_inc_imp_le_lim = thm "f_inc_imp_le_lim";
  5.2323 +val lim_uminus = thm "lim_uminus";
  5.2324 +val g_dec_imp_lim_le = thm "g_dec_imp_lim_le";
  5.2325 +val Bolzano_bisect_le = thm "Bolzano_bisect_le";
  5.2326 +val Bolzano_bisect_fst_le_Suc = thm "Bolzano_bisect_fst_le_Suc";
  5.2327 +val Bolzano_bisect_Suc_le_snd = thm "Bolzano_bisect_Suc_le_snd";
  5.2328 +val eq_divide_2_times_iff = thm "eq_divide_2_times_iff";
  5.2329 +val Bolzano_bisect_diff = thm "Bolzano_bisect_diff";
  5.2330 +val Bolzano_nest_unique = thms "Bolzano_nest_unique";
  5.2331 +val not_P_Bolzano_bisect = thm "not_P_Bolzano_bisect";
  5.2332 +val not_P_Bolzano_bisect = thm "not_P_Bolzano_bisect";
  5.2333 +val lemma_BOLZANO2 = thm "lemma_BOLZANO2";
  5.2334 +val IVT = thm "IVT";
  5.2335 +val IVT2 = thm "IVT2";
  5.2336 +val IVT_objl = thm "IVT_objl";
  5.2337 +val IVT2_objl = thm "IVT2_objl";
  5.2338 +val isCont_bounded = thm "isCont_bounded";
  5.2339 +val isCont_has_Ub = thm "isCont_has_Ub";
  5.2340 +val isCont_eq_Ub = thm "isCont_eq_Ub";
  5.2341 +val isCont_eq_Lb = thm "isCont_eq_Lb";
  5.2342 +val isCont_Lb_Ub = thm "isCont_Lb_Ub";
  5.2343 +val DERIV_left_inc = thm "DERIV_left_inc";
  5.2344 +val DERIV_left_dec = thm "DERIV_left_dec";
  5.2345 +val DERIV_local_max = thm "DERIV_local_max";
  5.2346 +val DERIV_local_min = thm "DERIV_local_min";
  5.2347 +val DERIV_local_const = thm "DERIV_local_const";
  5.2348 +val Rolle = thm "Rolle";
  5.2349 +val MVT = thm "MVT";
  5.2350 +val DERIV_isconst_end = thm "DERIV_isconst_end";
  5.2351 +val DERIV_isconst1 = thm "DERIV_isconst1";
  5.2352 +val DERIV_isconst2 = thm "DERIV_isconst2";
  5.2353 +val DERIV_isconst_all = thm "DERIV_isconst_all";
  5.2354 +val DERIV_const_ratio_const = thm "DERIV_const_ratio_const";
  5.2355 +val DERIV_const_ratio_const2 = thm "DERIV_const_ratio_const2";
  5.2356 +val real_average_minus_first = thm "real_average_minus_first";
  5.2357 +val real_average_minus_second = thm "real_average_minus_second";
  5.2358 +val DERIV_const_average = thm "DERIV_const_average";
  5.2359 +val isCont_inj_range = thm "isCont_inj_range";
  5.2360 +val isCont_inverse_function = thm "isCont_inverse_function";
  5.2361 +*}
  5.2362 +
  5.2363  
  5.2364  end
  5.2365  
     6.1 --- a/src/HOL/Hyperreal/NSA.thy	Fri Mar 19 10:50:06 2004 +0100
     6.2 +++ b/src/HOL/Hyperreal/NSA.thy	Fri Mar 19 10:51:03 2004 +0100
     6.3 @@ -154,7 +154,7 @@
     6.4  lemma SReal_dense:
     6.5       "[| (x::hypreal) \<in> Reals; y \<in> Reals;  x<y |] ==> \<exists>r \<in> Reals. x<r & r<y"
     6.6  apply (auto simp add: SReal_iff)
     6.7 -apply (drule real_dense, safe)
     6.8 +apply (drule dense, safe)
     6.9  apply (rule_tac x = "hypreal_of_real r" in bexI, auto)
    6.10  done
    6.11  
    6.12 @@ -304,14 +304,11 @@
    6.13  lemma hypreal_sum_of_halves: "x/(2::hypreal) + x/(2::hypreal) = x"
    6.14  by auto
    6.15  
    6.16 -lemma hypreal_half_gt_zero: "0 < r ==> 0 < r/(2::hypreal)"
    6.17 -by auto
    6.18 -
    6.19  lemma Infinitesimal_add:
    6.20       "[| x \<in> Infinitesimal; y \<in> Infinitesimal |] ==> (x+y) \<in> Infinitesimal"
    6.21  apply (auto simp add: Infinitesimal_def)
    6.22  apply (rule hypreal_sum_of_halves [THEN subst])
    6.23 -apply (drule hypreal_half_gt_zero)
    6.24 +apply (drule half_gt_zero)
    6.25  apply (blast intro: hrabs_add_less hrabs_add_less SReal_divide_number_of)
    6.26  done
    6.27  
    6.28 @@ -488,6 +485,9 @@
    6.29  by (simp add: approx_def Infinitesimal_def)
    6.30  declare approx_refl [iff]
    6.31  
    6.32 +lemma hypreal_minus_distrib1: "-(y + -(x::hypreal)) = x + -y"
    6.33 +by (simp add: hypreal_add_commute)
    6.34 +
    6.35  lemma approx_sym: "x @= y ==> y @= x"
    6.36  apply (simp add: approx_def)
    6.37  apply (rule hypreal_minus_distrib1 [THEN subst])
    6.38 @@ -562,7 +562,6 @@
    6.39  val InfinitesimalD = thm "InfinitesimalD";
    6.40  val Infinitesimal_zero = thm "Infinitesimal_zero";
    6.41  val hypreal_sum_of_halves = thm "hypreal_sum_of_halves";
    6.42 -val hypreal_half_gt_zero = thm "hypreal_half_gt_zero";
    6.43  val Infinitesimal_add = thm "Infinitesimal_add";
    6.44  val Infinitesimal_minus_iff = thm "Infinitesimal_minus_iff";
    6.45  val Infinitesimal_diff = thm "Infinitesimal_diff";
     7.1 --- a/src/HOL/Hyperreal/NthRoot.thy	Fri Mar 19 10:50:06 2004 +0100
     7.2 +++ b/src/HOL/Hyperreal/NthRoot.thy	Fri Mar 19 10:51:03 2004 +0100
     7.3 @@ -1,8 +1,7 @@
     7.4  (*  Title       : NthRoot.thy
     7.5      Author      : Jacques D. Fleuriot
     7.6      Copyright   : 1998  University of Cambridge
     7.7 -    Description : Existence of nth root. Adapted from
     7.8 -                   http://www.math.unl.edu/~webnotes
     7.9 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
    7.10  *)
    7.11  
    7.12  header{*Existence of Nth Root*}
    7.13 @@ -17,10 +16,9 @@
    7.14  lemma lemma_nth_realpow_non_empty:
    7.15       "[| (0::real) < a; 0 < n |] ==> \<exists>s. s : {x. x ^ n <= a & 0 < x}"
    7.16  apply (case_tac "1 <= a")
    7.17 -apply (rule_tac x = "1" in exI)
    7.18 +apply (rule_tac x = 1 in exI)
    7.19  apply (drule_tac [2] linorder_not_le [THEN iffD1])
    7.20 -apply (drule_tac [2] less_not_refl2 [THEN not0_implies_Suc])
    7.21 -apply (simp add: ); 
    7.22 +apply (drule_tac [2] less_not_refl2 [THEN not0_implies_Suc], simp) 
    7.23  apply (force intro!: realpow_Suc_le_self simp del: realpow_Suc)
    7.24  done
    7.25  
    7.26 @@ -32,23 +30,19 @@
    7.27       "[| (0::real) < a; 0 < n |]  
    7.28        ==> \<exists>u. isUb (UNIV::real set) {x. x ^ n <= a & 0 < x} u"
    7.29  apply (case_tac "1 <= a")
    7.30 -apply (rule_tac x = "a" in exI)
    7.31 +apply (rule_tac x = a in exI)
    7.32  apply (drule_tac [2] linorder_not_le [THEN iffD1])
    7.33 -apply (rule_tac [2] x = "1" in exI)
    7.34 -apply (rule_tac [!] setleI [THEN isUbI])
    7.35 -apply safe
    7.36 +apply (rule_tac [2] x = 1 in exI)
    7.37 +apply (rule_tac [!] setleI [THEN isUbI], safe)
    7.38  apply (simp_all (no_asm))
    7.39  apply (rule_tac [!] ccontr)
    7.40  apply (drule_tac [!] linorder_not_le [THEN iffD1])
    7.41 -apply (drule realpow_ge_self2 , assumption)
    7.42 -apply (drule_tac n = "n" in realpow_less)
    7.43 +apply (drule realpow_ge_self2, assumption)
    7.44 +apply (drule_tac n = n in realpow_less)
    7.45  apply (assumption+)
    7.46 -apply (drule real_le_trans , assumption)
    7.47 -apply (drule_tac y = "y ^ n" in order_less_le_trans)
    7.48 -apply (assumption)
    7.49 -apply (simp); 
    7.50 -apply (drule_tac n = "n" in zero_less_one [THEN realpow_less])
    7.51 -apply auto
    7.52 +apply (drule real_le_trans, assumption)
    7.53 +apply (drule_tac y = "y ^ n" in order_less_le_trans, assumption, simp) 
    7.54 +apply (drule_tac n = n in zero_less_one [THEN realpow_less], auto)
    7.55  done
    7.56  
    7.57  lemma nth_realpow_isLub_ex:
    7.58 @@ -62,23 +56,23 @@
    7.59  lemma lemma_nth_realpow_seq:
    7.60       "isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u  
    7.61             ==> u + inverse(real (Suc k)) ~: {x. x ^ n <= a & 0 < x}"
    7.62 -apply (safe , drule isLubD2 , blast)
    7.63 +apply (safe, drule isLubD2, blast)
    7.64  apply (simp add: linorder_not_less [symmetric])
    7.65  done
    7.66  
    7.67  lemma lemma_nth_realpow_isLub_gt_zero:
    7.68       "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;  
    7.69           0 < a; 0 < n |] ==> 0 < u"
    7.70 -apply (drule lemma_nth_realpow_non_empty , auto)
    7.71 -apply (drule_tac y = "s" in isLub_isUb [THEN isUbD])
    7.72 +apply (drule lemma_nth_realpow_non_empty, auto)
    7.73 +apply (drule_tac y = s in isLub_isUb [THEN isUbD])
    7.74  apply (auto intro: order_less_le_trans)
    7.75  done
    7.76  
    7.77  lemma lemma_nth_realpow_isLub_ge:
    7.78       "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;  
    7.79           0 < a; 0 < n |] ==> ALL k. a <= (u + inverse(real (Suc k))) ^ n"
    7.80 -apply (safe)
    7.81 -apply (frule lemma_nth_realpow_seq , safe)
    7.82 +apply safe
    7.83 +apply (frule lemma_nth_realpow_seq, safe)
    7.84  apply (auto elim: order_less_asym simp add: linorder_not_less [symmetric])
    7.85  apply (simp add: linorder_not_less)
    7.86  apply (rule order_less_trans [of _ 0])
    7.87 @@ -90,7 +84,7 @@
    7.88       "[| (0::real) < a; 0 < n;  
    7.89       isLub (UNIV::real set)  
    7.90       {x. x ^ n <= a & 0 < x} u |] ==> a <= u ^ n"
    7.91 -apply (frule lemma_nth_realpow_isLub_ge , safe)
    7.92 +apply (frule lemma_nth_realpow_isLub_ge, safe)
    7.93  apply (rule LIMSEQ_inverse_real_of_nat_add [THEN LIMSEQ_pow, THEN LIMSEQ_le_const])
    7.94  apply (auto simp add: real_of_nat_def)
    7.95  done
    7.96 @@ -100,16 +94,14 @@
    7.97  lemma less_isLub_not_isUb:
    7.98       "[| isLub (UNIV::real set) S u; x < u |]  
    7.99             ==> ~ isUb (UNIV::real set) S x"
   7.100 -apply (safe)
   7.101 -apply (drule isLub_le_isUb)
   7.102 -apply assumption
   7.103 -apply (drule order_less_le_trans)
   7.104 -apply (auto)
   7.105 +apply safe
   7.106 +apply (drule isLub_le_isUb, assumption)
   7.107 +apply (drule order_less_le_trans, auto)
   7.108  done
   7.109  
   7.110  lemma not_isUb_less_ex:
   7.111       "~ isUb (UNIV::real set) S u ==> \<exists>x \<in> S. u < x"
   7.112 -apply (rule ccontr , erule swap)
   7.113 +apply (rule ccontr, erule swap)
   7.114  apply (rule setleI [THEN isUbI])
   7.115  apply (auto simp add: linorder_not_less [symmetric])
   7.116  done
   7.117 @@ -129,14 +121,12 @@
   7.118  lemma lemma_nth_realpow_isLub_le:
   7.119       "[| isLub (UNIV::real set) {x. x ^ n <= a & (0::real) < x} u;  
   7.120         0 < a; 0 < n |] ==> ALL k. (u*(1 + -inverse(real (Suc k)))) ^ n <= a"
   7.121 -apply (safe)
   7.122 +apply safe
   7.123  apply (frule less_isLub_not_isUb [THEN not_isUb_less_ex])
   7.124 -apply (rule_tac n = "k" in real_mult_less_self)
   7.125 -apply (blast intro: lemma_nth_realpow_isLub_gt_zero)
   7.126 -apply (safe)
   7.127 -apply (drule_tac n = "k" in
   7.128 -        lemma_nth_realpow_isLub_gt_zero [THEN real_mult_add_one_minus_ge_zero])
   7.129 -apply assumption+
   7.130 +apply (rule_tac n = k in real_mult_less_self)
   7.131 +apply (blast intro: lemma_nth_realpow_isLub_gt_zero, safe)
   7.132 +apply (drule_tac n = k in
   7.133 +        lemma_nth_realpow_isLub_gt_zero [THEN real_mult_add_one_minus_ge_zero], assumption+)
   7.134  apply (blast intro: order_trans order_less_imp_le power_mono) 
   7.135  done
   7.136  
   7.137 @@ -145,7 +135,7 @@
   7.138       "[| (0::real) < a; 0 < n;  
   7.139       isLub (UNIV::real set)  
   7.140       {x. x ^ n <= a & 0 < x} u |] ==> u ^ n <= a"
   7.141 -apply (frule lemma_nth_realpow_isLub_le , safe)
   7.142 +apply (frule lemma_nth_realpow_isLub_le, safe)
   7.143  apply (rule LIMSEQ_inverse_real_of_nat_add_minus_mult
   7.144                  [THEN LIMSEQ_pow, THEN LIMSEQ_le_const2])
   7.145  apply (auto simp add: real_of_nat_def)
   7.146 @@ -153,29 +143,26 @@
   7.147  
   7.148  text{*The theorem at last!*}
   7.149  lemma realpow_nth: "[| (0::real) < a; 0 < n |] ==> \<exists>r. r ^ n = a"
   7.150 -apply (frule nth_realpow_isLub_ex , auto)
   7.151 -apply (auto intro: realpow_nth_le realpow_nth_ge real_le_anti_sym)
   7.152 +apply (frule nth_realpow_isLub_ex, auto)
   7.153 +apply (auto intro: realpow_nth_le realpow_nth_ge order_antisym)
   7.154  done
   7.155  
   7.156  (* positive only *)
   7.157  lemma realpow_pos_nth: "[| (0::real) < a; 0 < n |] ==> \<exists>r. 0 < r & r ^ n = a"
   7.158 -apply (frule nth_realpow_isLub_ex , auto)
   7.159 -apply (auto intro: realpow_nth_le realpow_nth_ge real_le_anti_sym lemma_nth_realpow_isLub_gt_zero)
   7.160 +apply (frule nth_realpow_isLub_ex, auto)
   7.161 +apply (auto intro: realpow_nth_le realpow_nth_ge order_antisym lemma_nth_realpow_isLub_gt_zero)
   7.162  done
   7.163  
   7.164  lemma realpow_pos_nth2: "(0::real) < a  ==> \<exists>r. 0 < r & r ^ Suc n = a"
   7.165 -apply (blast intro: realpow_pos_nth)
   7.166 -done
   7.167 +by (blast intro: realpow_pos_nth)
   7.168  
   7.169  (* uniqueness of nth positive root *)
   7.170  lemma realpow_pos_nth_unique:
   7.171       "[| (0::real) < a; 0 < n |] ==> EX! r. 0 < r & r ^ n = a"
   7.172  apply (auto intro!: realpow_pos_nth)
   7.173 -apply (cut_tac x = "r" and y = "y" in linorder_less_linear)
   7.174 -apply auto
   7.175 -apply (drule_tac x = "r" in realpow_less)
   7.176 -apply (drule_tac [4] x = "y" in realpow_less)
   7.177 -apply (auto)
   7.178 +apply (cut_tac x = r and y = y in linorder_less_linear, auto)
   7.179 +apply (drule_tac x = r in realpow_less)
   7.180 +apply (drule_tac [4] x = y in realpow_less, auto)
   7.181  done
   7.182  
   7.183  ML
     8.1 --- a/src/HOL/Hyperreal/SEQ.ML	Fri Mar 19 10:50:06 2004 +0100
     8.2 +++ b/src/HOL/Hyperreal/SEQ.ML	Fri Mar 19 10:51:03 2004 +0100
     8.3 @@ -618,7 +618,7 @@
     8.4  \              |] ==> ALL n. ma <= n --> X n = X ma";
     8.5  by (Step_tac 1);
     8.6  by (dres_inst_tac [("y","X n")] isLubD2 1);
     8.7 -by (ALLGOALS(blast_tac (claset() addDs [real_le_anti_sym])));
     8.8 +by (ALLGOALS(blast_tac (claset() addDs [order_antisym])));
     8.9  qed "lemma_converg1";
    8.10  
    8.11  (*------------------------------------------------------------------- 
     9.1 --- a/src/HOL/Hyperreal/Star.thy	Fri Mar 19 10:50:06 2004 +0100
     9.2 +++ b/src/HOL/Hyperreal/Star.thy	Fri Mar 19 10:51:03 2004 +0100
     9.3 @@ -180,7 +180,6 @@
     9.4  *)
     9.5  
     9.6  lemma hrabs_is_starext_rabs: "is_starext abs abs"
     9.7 -
     9.8  apply (simp add: is_starext_def, safe)
     9.9  apply (rule_tac z = x in eq_Abs_hypreal)
    9.10  apply (rule_tac z = y in eq_Abs_hypreal, auto)
    9.11 @@ -190,9 +189,10 @@
    9.12  apply (arith | ultra)+
    9.13  done
    9.14  
    9.15 -lemma Rep_hypreal_FreeUltrafilterNat: "[| X \<in> Rep_hypreal z; Y \<in> Rep_hypreal z |]
    9.16 +lemma Rep_hypreal_FreeUltrafilterNat:
    9.17 +     "[| X \<in> Rep_hypreal z; Y \<in> Rep_hypreal z |]
    9.18        ==> {n. X n = Y n} : FreeUltrafilterNat"
    9.19 -apply (rule_tac z = z in eq_Abs_hypreal)
    9.20 +apply (cases z)
    9.21  apply (auto, ultra)
    9.22  done
    9.23  
    9.24 @@ -212,22 +212,25 @@
    9.25                   UN_equiv_class [OF equiv_hyprel starfun_congruent])
    9.26  done
    9.27  
    9.28 +lemma starfun_if_eq:
    9.29 +     "w \<noteq> hypreal_of_real x
    9.30 +       ==> ( *f* (\<lambda>z. if z = x then a else g z)) w = ( *f* g) w" 
    9.31 +apply (cases w) 
    9.32 +apply (simp add: hypreal_of_real_def starfun, ultra)
    9.33 +done
    9.34 +
    9.35  (*-------------------------------------------
    9.36    multiplication: ( *f) x ( *g) = *(f x g)
    9.37   ------------------------------------------*)
    9.38  lemma starfun_mult: "( *f* f) xa * ( *f* g) xa = ( *f* (%x. f x * g x)) xa"
    9.39 -apply (rule_tac z = xa in eq_Abs_hypreal)
    9.40 -apply (auto simp add: starfun hypreal_mult)
    9.41 -done
    9.42 +by (cases xa, simp add: starfun hypreal_mult)
    9.43  declare starfun_mult [symmetric, simp]
    9.44  
    9.45  (*---------------------------------------
    9.46    addition: ( *f) + ( *g) = *(f + g)
    9.47   ---------------------------------------*)
    9.48  lemma starfun_add: "( *f* f) xa + ( *f* g) xa = ( *f* (%x. f x + g x)) xa"
    9.49 -apply (rule_tac z = xa in eq_Abs_hypreal)
    9.50 -apply (auto simp add: starfun hypreal_add)
    9.51 -done
    9.52 +by (cases xa, simp add: starfun hypreal_add)
    9.53  declare starfun_add [symmetric, simp]
    9.54  
    9.55  (*--------------------------------------------
    9.56 @@ -235,7 +238,7 @@
    9.57   -------------------------------------------*)
    9.58  
    9.59  lemma starfun_minus: "- ( *f* f) x = ( *f* (%x. - f x)) x"
    9.60 -apply (rule_tac z = x in eq_Abs_hypreal)
    9.61 +apply (cases x)
    9.62  apply (auto simp add: starfun hypreal_minus)
    9.63  done
    9.64  declare starfun_minus [symmetric, simp]
    9.65 @@ -271,7 +274,7 @@
    9.66    NS extension of constant function
    9.67   --------------------------------------*)
    9.68  lemma starfun_const_fun: "( *f* (%x. k)) xa = hypreal_of_real  k"
    9.69 -apply (rule_tac z = xa in eq_Abs_hypreal)
    9.70 +apply (cases xa)
    9.71  apply (auto simp add: starfun hypreal_of_real_def)
    9.72  done
    9.73  
    9.74 @@ -282,12 +285,12 @@
    9.75   ----------------------------------------------------*)
    9.76  
    9.77  lemma starfun_Idfun_approx: "x @= hypreal_of_real a ==> ( *f* (%x. x)) x @= hypreal_of_real  a"
    9.78 -apply (rule_tac z = x in eq_Abs_hypreal)
    9.79 +apply (cases x)
    9.80  apply (auto simp add: starfun)
    9.81  done
    9.82  
    9.83  lemma starfun_Id: "( *f* (%x. x)) x = x"
    9.84 -apply (rule_tac z = x in eq_Abs_hypreal)
    9.85 +apply (cases x)
    9.86  apply (auto simp add: starfun)
    9.87  done
    9.88  declare starfun_Id [simp]
    9.89 @@ -297,7 +300,6 @@
    9.90   ----------------------------------------------------------------------*)
    9.91  
    9.92  lemma is_starext_starfun: "is_starext ( *f* f) f"
    9.93 -
    9.94  apply (simp add: is_starext_def, auto)
    9.95  apply (rule_tac z = x in eq_Abs_hypreal)
    9.96  apply (rule_tac z = y in eq_Abs_hypreal)
    9.97 @@ -309,7 +311,6 @@
    9.98   ----------------------------------------------------------------------*)
    9.99  
   9.100  lemma is_starfun_starext: "is_starext F f ==> F = *f* f"
   9.101 -
   9.102  apply (simp add: is_starext_def)
   9.103  apply (rule ext)
   9.104  apply (rule_tac z = x in eq_Abs_hypreal)
   9.105 @@ -336,12 +337,12 @@
   9.106  
   9.107  (* useful for NS definition of derivatives *)
   9.108  lemma starfun_lambda_cancel: "( *f* (%h. f (x + h))) xa  = ( *f* f) (hypreal_of_real  x + xa)"
   9.109 -apply (rule_tac z = xa in eq_Abs_hypreal)
   9.110 +apply (cases xa)
   9.111  apply (auto simp add: starfun hypreal_of_real_def hypreal_add)
   9.112  done
   9.113  
   9.114  lemma starfun_lambda_cancel2: "( *f* (%h. f(g(x + h)))) xa = ( *f* (f o g)) (hypreal_of_real x + xa)"
   9.115 -apply (rule_tac z = xa in eq_Abs_hypreal)
   9.116 +apply (cases xa)
   9.117  apply (auto simp add: starfun hypreal_of_real_def hypreal_add)
   9.118  done
   9.119  
   9.120 @@ -370,13 +371,13 @@
   9.121  by (rule hrabs_is_starext_rabs [THEN is_starext_starfun_iff [THEN iffD1], symmetric])
   9.122  
   9.123  lemma starfun_inverse_inverse: "( *f* inverse) x = inverse(x)"
   9.124 -apply (rule_tac z = x in eq_Abs_hypreal)
   9.125 +apply (cases x)
   9.126  apply (auto simp add: starfun hypreal_inverse hypreal_zero_def)
   9.127  done
   9.128  declare starfun_inverse_inverse [simp]
   9.129  
   9.130  lemma starfun_inverse: "inverse (( *f* f) x) = ( *f* (%x. inverse (f x))) x"
   9.131 -apply (rule_tac z = x in eq_Abs_hypreal)
   9.132 +apply (cases x)
   9.133  apply (auto simp add: starfun hypreal_inverse)
   9.134  done
   9.135  declare starfun_inverse [symmetric, simp]
   9.136 @@ -386,7 +387,7 @@
   9.137  declare starfun_divide [symmetric, simp]
   9.138  
   9.139  lemma starfun_inverse2: "inverse (( *f* f) x) = ( *f* (%x. inverse (f x))) x"
   9.140 -apply (rule_tac z = x in eq_Abs_hypreal)
   9.141 +apply (cases x)
   9.142  apply (auto intro: FreeUltrafilterNat_subset dest!: FreeUltrafilterNat_Compl_mem simp add: starfun hypreal_inverse hypreal_zero_def)
   9.143  done
   9.144  
   9.145 @@ -397,7 +398,7 @@
   9.146  lemma starfun_mem_starset:
   9.147        "( *f* f) x : *s* A ==> x : *s* {x. f x  \<in> A}"
   9.148  apply (simp add: starset_def)
   9.149 -apply (rule_tac z = x in eq_Abs_hypreal)
   9.150 +apply (cases x)
   9.151  apply (auto simp add: starfun)
   9.152  apply (rename_tac "X")
   9.153  apply (drule_tac x = "%n. f (X n) " in bspec)
   9.154 @@ -446,7 +447,7 @@
   9.155        (\<exists>X \<in> Rep_hypreal(x).
   9.156          \<forall>m. {n. abs(X n) < inverse(real(Suc m))}
   9.157                  \<in>  FreeUltrafilterNat)"
   9.158 -apply (rule eq_Abs_hypreal [of x])
   9.159 +apply (cases x)
   9.160  apply (auto intro!: bexI lemma_hyprel_refl 
   9.161              simp add: Infinitesimal_hypreal_of_nat_iff hypreal_of_real_def
   9.162       hypreal_inverse hypreal_hrabs hypreal_less hypreal_of_nat_eq)
    10.1 --- a/src/HOL/Hyperreal/Transcendental.ML	Fri Mar 19 10:50:06 2004 +0100
    10.2 +++ b/src/HOL/Hyperreal/Transcendental.ML	Fri Mar 19 10:51:03 2004 +0100
    10.3 @@ -5,6 +5,9 @@
    10.4      Description : Power Series
    10.5  *)
    10.6  
    10.7 +fun ARITH_PROVE str = prove_goal thy str
    10.8 +                      (fn prems => [cut_facts_tac prems 1,arith_tac 1]);
    10.9 +
   10.10  fun multr_by_tac x i = 
   10.11         let val cancel_thm = 
   10.12             CLAIM "[| (0::real)<z; x*z<y*z |] ==> x<y" 
   10.13 @@ -272,7 +275,7 @@
   10.14  (*-------------------------------------------------------------------------*)
   10.15  
   10.16  Goal "summable (%n. inverse (real (fact n)) * x ^ n)";
   10.17 -by (cut_facts_tac [zero_less_one RS real_dense] 1);
   10.18 +by (cut_inst_tac [("'a","real")] (zero_less_one RS dense) 1);
   10.19  by (Step_tac 1);
   10.20  by (cut_inst_tac [("x","r")] reals_Archimedean3 1);
   10.21  by Auto_tac;
   10.22 @@ -727,7 +730,7 @@
   10.23  by (asm_full_simp_tac (simpset() addsimps [real_diff_def,
   10.24       right_distrib] @ add_ac @ mult_ac) 1);
   10.25  (* 46 *)
   10.26 -by (dtac real_dense 1 THEN Step_tac 1);
   10.27 +by (dtac dense 1 THEN Step_tac 1);
   10.28  by (ftac (real_less_sum_gt_zero) 1);
   10.29  by (dres_inst_tac [("f","%n. abs(c n) * real n * \
   10.30  \                    real (n - Suc 0) * (r ^ (n - 2))"),
   10.31 @@ -2551,7 +2554,7 @@
   10.32  Addsimps [real_root_le_iff];
   10.33  
   10.34  Goal "[| 0 <= x; 0 <= y |] ==> (root(Suc n) x = root(Suc n) y) = (x = y)";
   10.35 -by (auto_tac (claset() addSIs [real_le_anti_sym],simpset()));
   10.36 +by (auto_tac (claset() addSIs [order_antisym],simpset()));
   10.37  by (res_inst_tac [("n1","n")] (real_root_le_iff RS iffD1) 1);
   10.38  by (res_inst_tac [("n1","n")] (real_root_le_iff RS iffD1) 4);
   10.39  by Auto_tac;
    11.1 --- a/src/HOL/IsaMakefile	Fri Mar 19 10:50:06 2004 +0100
    11.2 +++ b/src/HOL/IsaMakefile	Fri Mar 19 10:51:03 2004 +0100
    11.3 @@ -148,7 +148,7 @@
    11.4    Hyperreal/HTranscendental.thy Hyperreal/HyperArith.thy\
    11.5    Hyperreal/HyperDef.thy Hyperreal/HyperNat.thy\
    11.6    Hyperreal/HyperPow.thy Hyperreal/Hyperreal.thy Hyperreal/IntFloor.thy\
    11.7 -  Hyperreal/Lim.ML Hyperreal/Lim.thy Hyperreal/Log.thy\
    11.8 +  Hyperreal/Lim.thy Hyperreal/Log.thy\
    11.9    Hyperreal/MacLaurin.ML Hyperreal/MacLaurin.thy Hyperreal/NatStar.thy\
   11.10    Hyperreal/NSA.thy Hyperreal/NthRoot.thy Hyperreal/Poly.thy\
   11.11    Hyperreal/SEQ.ML Hyperreal/SEQ.thy Hyperreal/Series.thy\