src/HOL/Hyperreal/Lim.ML
changeset 11701 3d51fbf81c17
parent 11468 02cd5d5bc497
child 11704 3c50a2cd6f00
equal deleted inserted replaced
11700:a0e6bda62b7b 11701:3d51fbf81c17
    27     LIM_add    
    27     LIM_add    
    28  ---------------*)
    28  ---------------*)
    29 Goalw [LIM_def] 
    29 Goalw [LIM_def] 
    30      "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + g(x)) -- x --> (l + m)";
    30      "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + g(x)) -- x --> (l + m)";
    31 by (Clarify_tac 1);
    31 by (Clarify_tac 1);
    32 by (REPEAT(dres_inst_tac [("x","r/#2")] spec 1));
    32 by (REPEAT(dres_inst_tac [("x","r/# 2")] spec 1));
    33 by (Asm_full_simp_tac 1);
    33 by (Asm_full_simp_tac 1);
    34 by (Clarify_tac 1);
    34 by (Clarify_tac 1);
    35 by (res_inst_tac [("R1.0","s"),("R2.0","sa")] 
    35 by (res_inst_tac [("R1.0","s"),("R2.0","sa")] 
    36     real_linear_less2 1);
    36     real_linear_less2 1);
    37 by (res_inst_tac [("x","s")] exI 1);
    37 by (res_inst_tac [("x","s")] exI 1);
    63 qed "LIM_add_minus";
    63 qed "LIM_add_minus";
    64 
    64 
    65 (*----------------------------------------------
    65 (*----------------------------------------------
    66      LIM_zero
    66      LIM_zero
    67  ----------------------------------------------*)
    67  ----------------------------------------------*)
    68 Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> #0";
    68 Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> Numeral0";
    69 by (res_inst_tac [("z1","l")] (rename_numerals (real_add_minus RS subst)) 1);
    69 by (res_inst_tac [("z1","l")] (rename_numerals (real_add_minus RS subst)) 1);
    70 by (rtac LIM_add_minus 1 THEN Auto_tac);
    70 by (rtac LIM_add_minus 1 THEN Auto_tac);
    71 qed "LIM_zero";
    71 qed "LIM_zero";
    72 
    72 
    73 (*--------------------------
    73 (*--------------------------
    74    Limit not zero
    74    Limit not zero
    75  --------------------------*)
    75  --------------------------*)
    76 Goalw [LIM_def] "k \\<noteq> #0 ==> ~ ((%x. k) -- x --> #0)";
    76 Goalw [LIM_def] "k \\<noteq> Numeral0 ==> ~ ((%x. k) -- x --> Numeral0)";
    77 by (res_inst_tac [("R1.0","k"),("R2.0","#0")] real_linear_less2 1);
    77 by (res_inst_tac [("R1.0","k"),("R2.0","Numeral0")] real_linear_less2 1);
    78 by (auto_tac (claset(), simpset() addsimps [real_abs_def]));
    78 by (auto_tac (claset(), simpset() addsimps [real_abs_def]));
    79 by (res_inst_tac [("x","-k")] exI 1);
    79 by (res_inst_tac [("x","-k")] exI 1);
    80 by (res_inst_tac [("x","k")] exI 2);
    80 by (res_inst_tac [("x","k")] exI 2);
    81 by Auto_tac;
    81 by Auto_tac;
    82 by (ALLGOALS(dres_inst_tac [("y","s")] real_dense));
    82 by (ALLGOALS(dres_inst_tac [("y","s")] real_dense));
    83 by Safe_tac;
    83 by Safe_tac;
    84 by (ALLGOALS(res_inst_tac [("x","r + x")] exI));
    84 by (ALLGOALS(res_inst_tac [("x","r + x")] exI));
    85 by Auto_tac;  
    85 by Auto_tac;  
    86 qed "LIM_not_zero";
    86 qed "LIM_not_zero";
    87 
    87 
    88 (* [| k \\<noteq> #0; (%x. k) -- x --> #0 |] ==> R *)
    88 (* [| k \\<noteq> Numeral0; (%x. k) -- x --> Numeral0 |] ==> R *)
    89 bind_thm("LIM_not_zeroE", LIM_not_zero RS notE);
    89 bind_thm("LIM_not_zeroE", LIM_not_zero RS notE);
    90 
    90 
    91 Goal "(%x. k) -- x --> L ==> k = L";
    91 Goal "(%x. k) -- x --> L ==> k = L";
    92 by (rtac ccontr 1);
    92 by (rtac ccontr 1);
    93 by (dtac LIM_zero 1);
    93 by (dtac LIM_zero 1);
   106 
   106 
   107 (*-------------
   107 (*-------------
   108     LIM_mult_zero
   108     LIM_mult_zero
   109  -------------*)
   109  -------------*)
   110 Goalw [LIM_def]
   110 Goalw [LIM_def]
   111      "[| f -- x --> #0; g -- x --> #0 |] ==> (%x. f(x)*g(x)) -- x --> #0";
   111      "[| f -- x --> Numeral0; g -- x --> Numeral0 |] ==> (%x. f(x)*g(x)) -- x --> Numeral0";
   112 by Safe_tac;
   112 by Safe_tac;
   113 by (dres_inst_tac [("x","#1")] spec 1);
   113 by (dres_inst_tac [("x","Numeral1")] spec 1);
   114 by (dres_inst_tac [("x","r")] spec 1);
   114 by (dres_inst_tac [("x","r")] spec 1);
   115 by (cut_facts_tac [real_zero_less_one] 1);
   115 by (cut_facts_tac [real_zero_less_one] 1);
   116 by (asm_full_simp_tac (simpset() addsimps 
   116 by (asm_full_simp_tac (simpset() addsimps 
   117     [abs_mult]) 1);
   117     [abs_mult]) 1);
   118 by (Clarify_tac 1);
   118 by (Clarify_tac 1);
   144      "[| \\<forall>x. x \\<noteq> a --> (f x = g x) |] \
   144      "[| \\<forall>x. x \\<noteq> a --> (f x = g x) |] \
   145 \     ==> (f -- a --> l) = (g -- a --> l)";
   145 \     ==> (f -- a --> l) = (g -- a --> l)";
   146 by (auto_tac (claset(), simpset() addsimps [real_add_minus_iff]));
   146 by (auto_tac (claset(), simpset() addsimps [real_add_minus_iff]));
   147 qed "LIM_equal";
   147 qed "LIM_equal";
   148 
   148 
   149 Goal "[| (%x. f(x) + -g(x)) -- a --> #0;  g -- a --> l |] \
   149 Goal "[| (%x. f(x) + -g(x)) -- a --> Numeral0;  g -- a --> l |] \
   150 \     ==> f -- a --> l";
   150 \     ==> f -- a --> l";
   151 by (dtac LIM_add 1 THEN assume_tac 1);
   151 by (dtac LIM_add 1 THEN assume_tac 1);
   152 by (auto_tac (claset(), simpset() addsimps [real_add_assoc]));
   152 by (auto_tac (claset(), simpset() addsimps [real_add_assoc]));
   153 qed "LIM_trans";
   153 qed "LIM_trans";
   154 
   154 
   179  
   179  
   180 (*---------------------------------------------------------------------
   180 (*---------------------------------------------------------------------
   181     Limit: NS definition ==> standard definition
   181     Limit: NS definition ==> standard definition
   182  ---------------------------------------------------------------------*)
   182  ---------------------------------------------------------------------*)
   183 
   183 
   184 Goal "\\<forall>s. #0 < s --> (\\<exists>xa.  xa \\<noteq> x & \
   184 Goal "\\<forall>s. Numeral0 < s --> (\\<exists>xa.  xa \\<noteq> x & \
   185 \        abs (xa + - x) < s  & r \\<le> abs (f xa + -L)) \
   185 \        abs (xa + - x) < s  & r \\<le> abs (f xa + -L)) \
   186 \     ==> \\<forall>n::nat. \\<exists>xa.  xa \\<noteq> x & \
   186 \     ==> \\<forall>n::nat. \\<exists>xa.  xa \\<noteq> x & \
   187 \             abs(xa + -x) < inverse(real(Suc n)) & r \\<le> abs(f xa + -L)";
   187 \             abs(xa + -x) < inverse(real(Suc n)) & r \\<le> abs(f xa + -L)";
   188 by (Clarify_tac 1); 
   188 by (Clarify_tac 1); 
   189 by (cut_inst_tac [("n1","n")]
   189 by (cut_inst_tac [("n1","n")]
   190     (real_of_nat_Suc_gt_zero RS rename_numerals real_inverse_gt_zero) 1);
   190     (real_of_nat_Suc_gt_zero RS rename_numerals real_inverse_gt_zero) 1);
   191 by Auto_tac;
   191 by Auto_tac;
   192 val lemma_LIM = result();
   192 val lemma_LIM = result();
   193 
   193 
   194 Goal "\\<forall>s. #0 < s --> (\\<exists>xa.  xa \\<noteq> x & \
   194 Goal "\\<forall>s. Numeral0 < s --> (\\<exists>xa.  xa \\<noteq> x & \
   195 \        abs (xa + - x) < s  & r \\<le> abs (f xa + -L)) \
   195 \        abs (xa + - x) < s  & r \\<le> abs (f xa + -L)) \
   196 \     ==> \\<exists>X. \\<forall>n::nat. X n \\<noteq> x & \
   196 \     ==> \\<exists>X. \\<forall>n::nat. X n \\<noteq> x & \
   197 \               abs(X n + -x) < inverse(real(Suc n)) & r \\<le> abs(f (X n) + -L)";
   197 \               abs(X n + -x) < inverse(real(Suc n)) & r \\<le> abs(f (X n) + -L)";
   198 by (dtac lemma_LIM 1);
   198 by (dtac lemma_LIM 1);
   199 by (dtac choice 1);
   199 by (dtac choice 1);
   318 
   318 
   319 (*-----------------------------
   319 (*-----------------------------
   320     NSLIM_inverse
   320     NSLIM_inverse
   321  -----------------------------*)
   321  -----------------------------*)
   322 Goalw [NSLIM_def] 
   322 Goalw [NSLIM_def] 
   323      "[| f -- a --NS> L;  L \\<noteq> #0 |] \
   323      "[| f -- a --NS> L;  L \\<noteq> Numeral0 |] \
   324 \     ==> (%x. inverse(f(x))) -- a --NS> (inverse L)";
   324 \     ==> (%x. inverse(f(x))) -- a --NS> (inverse L)";
   325 by (Clarify_tac 1);
   325 by (Clarify_tac 1);
   326 by (dtac spec 1);
   326 by (dtac spec 1);
   327 by (auto_tac (claset(), 
   327 by (auto_tac (claset(), 
   328               simpset() addsimps [hypreal_of_real_approx_inverse]));  
   328               simpset() addsimps [hypreal_of_real_approx_inverse]));  
   329 qed "NSLIM_inverse";
   329 qed "NSLIM_inverse";
   330 
   330 
   331 Goal "[| f -- a --> L; \
   331 Goal "[| f -- a --> L; \
   332 \        L \\<noteq> #0 |] ==> (%x. inverse(f(x))) -- a --> (inverse L)";
   332 \        L \\<noteq> Numeral0 |] ==> (%x. inverse(f(x))) -- a --> (inverse L)";
   333 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_inverse]) 1);
   333 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_inverse]) 1);
   334 qed "LIM_inverse";
   334 qed "LIM_inverse";
   335 
   335 
   336 (*------------------------------
   336 (*------------------------------
   337     NSLIM_zero
   337     NSLIM_zero
   338  ------------------------------*)
   338  ------------------------------*)
   339 Goal "f -- a --NS> l ==> (%x. f(x) + -l) -- a --NS> #0";
   339 Goal "f -- a --NS> l ==> (%x. f(x) + -l) -- a --NS> Numeral0";
   340 by (res_inst_tac [("z1","l")] (rename_numerals (real_add_minus RS subst)) 1);
   340 by (res_inst_tac [("z1","l")] (rename_numerals (real_add_minus RS subst)) 1);
   341 by (rtac NSLIM_add_minus 1 THEN Auto_tac);
   341 by (rtac NSLIM_add_minus 1 THEN Auto_tac);
   342 qed "NSLIM_zero";
   342 qed "NSLIM_zero";
   343 
   343 
   344 Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> #0";
   344 Goal "f -- a --> l ==> (%x. f(x) + -l) -- a --> Numeral0";
   345 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_zero]) 1);
   345 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_zero]) 1);
   346 qed "LIM_zero2";
   346 qed "LIM_zero2";
   347 
   347 
   348 Goal "(%x. f(x) - l) -- x --NS> #0 ==> f -- x --NS> l";
   348 Goal "(%x. f(x) - l) -- x --NS> Numeral0 ==> f -- x --NS> l";
   349 by (dres_inst_tac [("g","%x. l"),("m","l")] NSLIM_add 1);
   349 by (dres_inst_tac [("g","%x. l"),("m","l")] NSLIM_add 1);
   350 by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
   350 by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
   351 qed "NSLIM_zero_cancel";
   351 qed "NSLIM_zero_cancel";
   352 
   352 
   353 Goal "(%x. f(x) - l) -- x --> #0 ==> f -- x --> l";
   353 Goal "(%x. f(x) - l) -- x --> Numeral0 ==> f -- x --> l";
   354 by (dres_inst_tac [("g","%x. l"),("m","l")] LIM_add 1);
   354 by (dres_inst_tac [("g","%x. l"),("m","l")] LIM_add 1);
   355 by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
   355 by (auto_tac (claset(),simpset() addsimps [real_diff_def, real_add_assoc]));
   356 qed "LIM_zero_cancel";
   356 qed "LIM_zero_cancel";
   357 
   357 
   358 
   358 
   359 (*--------------------------
   359 (*--------------------------
   360    NSLIM_not_zero
   360    NSLIM_not_zero
   361  --------------------------*)
   361  --------------------------*)
   362 Goalw [NSLIM_def] "k \\<noteq> #0 ==> ~ ((%x. k) -- x --NS> #0)";
   362 Goalw [NSLIM_def] "k \\<noteq> Numeral0 ==> ~ ((%x. k) -- x --NS> Numeral0)";
   363 by Auto_tac;
   363 by Auto_tac;
   364 by (res_inst_tac [("x","hypreal_of_real x + epsilon")] exI 1);
   364 by (res_inst_tac [("x","hypreal_of_real x + epsilon")] exI 1);
   365 by (auto_tac (claset() addIs [Infinitesimal_add_approx_self RS approx_sym],
   365 by (auto_tac (claset() addIs [Infinitesimal_add_approx_self RS approx_sym],
   366               simpset() addsimps [rename_numerals hypreal_epsilon_not_zero]));
   366               simpset() addsimps [rename_numerals hypreal_epsilon_not_zero]));
   367 qed "NSLIM_not_zero";
   367 qed "NSLIM_not_zero";
   368 
   368 
   369 (* [| k \\<noteq> #0; (%x. k) -- x --NS> #0 |] ==> R *)
   369 (* [| k \\<noteq> Numeral0; (%x. k) -- x --NS> Numeral0 |] ==> R *)
   370 bind_thm("NSLIM_not_zeroE", NSLIM_not_zero RS notE);
   370 bind_thm("NSLIM_not_zeroE", NSLIM_not_zero RS notE);
   371 
   371 
   372 Goal "k \\<noteq> #0 ==> ~ ((%x. k) -- x --> #0)";
   372 Goal "k \\<noteq> Numeral0 ==> ~ ((%x. k) -- x --> Numeral0)";
   373 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_not_zero]) 1);
   373 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_not_zero]) 1);
   374 qed "LIM_not_zero2";
   374 qed "LIM_not_zero2";
   375 
   375 
   376 (*-------------------------------------
   376 (*-------------------------------------
   377    NSLIM of constant function
   377    NSLIM of constant function
   403 qed "LIM_unique2";
   403 qed "LIM_unique2";
   404 
   404 
   405 (*--------------------
   405 (*--------------------
   406     NSLIM_mult_zero
   406     NSLIM_mult_zero
   407  --------------------*)
   407  --------------------*)
   408 Goal "[| f -- x --NS> #0; g -- x --NS> #0 |] \
   408 Goal "[| f -- x --NS> Numeral0; g -- x --NS> Numeral0 |] \
   409 \         ==> (%x. f(x)*g(x)) -- x --NS> #0";
   409 \         ==> (%x. f(x)*g(x)) -- x --NS> Numeral0";
   410 by (dtac NSLIM_mult 1 THEN Auto_tac);
   410 by (dtac NSLIM_mult 1 THEN Auto_tac);
   411 qed "NSLIM_mult_zero";
   411 qed "NSLIM_mult_zero";
   412 
   412 
   413 (* we can use the corresponding thm LIM_mult2 *)
   413 (* we can use the corresponding thm LIM_mult2 *)
   414 (* for standard definition of limit           *)
   414 (* for standard definition of limit           *)
   415 
   415 
   416 Goal "[| f -- x --> #0; g -- x --> #0 |] \
   416 Goal "[| f -- x --> Numeral0; g -- x --> Numeral0 |] \
   417 \     ==> (%x. f(x)*g(x)) -- x --> #0";
   417 \     ==> (%x. f(x)*g(x)) -- x --> Numeral0";
   418 by (dtac LIM_mult2 1 THEN Auto_tac);
   418 by (dtac LIM_mult2 1 THEN Auto_tac);
   419 qed "LIM_mult_zero2";
   419 qed "LIM_mult_zero2";
   420 
   420 
   421 (*----------------------------
   421 (*----------------------------
   422     NSLIM_self
   422     NSLIM_self
   497 (*--------------------------------------------------------------------------
   497 (*--------------------------------------------------------------------------
   498                  Alternative definition of continuity
   498                  Alternative definition of continuity
   499  --------------------------------------------------------------------------*)
   499  --------------------------------------------------------------------------*)
   500 (* Prove equivalence between NS limits - *)
   500 (* Prove equivalence between NS limits - *)
   501 (* seems easier than using standard def  *)
   501 (* seems easier than using standard def  *)
   502 Goalw [NSLIM_def] "(f -- a --NS> L) = ((%h. f(a + h)) -- #0 --NS> L)";
   502 Goalw [NSLIM_def] "(f -- a --NS> L) = ((%h. f(a + h)) -- Numeral0 --NS> L)";
   503 by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_zero]));
   503 by (auto_tac (claset(),simpset() addsimps [hypreal_of_real_zero]));
   504 by (dres_inst_tac [("x","hypreal_of_real a + x")] spec 1);
   504 by (dres_inst_tac [("x","hypreal_of_real a + x")] spec 1);
   505 by (dres_inst_tac [("x","-hypreal_of_real a + x")] spec 2);
   505 by (dres_inst_tac [("x","-hypreal_of_real a + x")] spec 2);
   506 by Safe_tac;
   506 by Safe_tac;
   507 by (Asm_full_simp_tac 1);
   507 by (Asm_full_simp_tac 1);
   514 by (auto_tac (claset(),
   514 by (auto_tac (claset(),
   515        simpset() addsimps [starfun, hypreal_of_real_def, hypreal_minus,
   515        simpset() addsimps [starfun, hypreal_of_real_def, hypreal_minus,
   516               hypreal_add, real_add_assoc, approx_refl, hypreal_zero_def]));
   516               hypreal_add, real_add_assoc, approx_refl, hypreal_zero_def]));
   517 qed "NSLIM_h_iff";
   517 qed "NSLIM_h_iff";
   518 
   518 
   519 Goal "(f -- a --NS> f a) = ((%h. f(a + h)) -- #0 --NS> f a)";
   519 Goal "(f -- a --NS> f a) = ((%h. f(a + h)) -- Numeral0 --NS> f a)";
   520 by (rtac NSLIM_h_iff 1);
   520 by (rtac NSLIM_h_iff 1);
   521 qed "NSLIM_isCont_iff";
   521 qed "NSLIM_isCont_iff";
   522 
   522 
   523 Goal "(f -- a --> f a) = ((%h. f(a + h)) -- #0 --> f(a))";
   523 Goal "(f -- a --> f a) = ((%h. f(a + h)) -- Numeral0 --> f(a))";
   524 by (simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_isCont_iff]) 1);
   524 by (simp_tac (simpset() addsimps [LIM_NSLIM_iff, NSLIM_isCont_iff]) 1);
   525 qed "LIM_isCont_iff";
   525 qed "LIM_isCont_iff";
   526 
   526 
   527 Goalw [isCont_def] "(isCont f x) = ((%h. f(x + h)) -- #0 --> f(x))";
   527 Goalw [isCont_def] "(isCont f x) = ((%h. f(x + h)) -- Numeral0 --> f(x))";
   528 by (simp_tac (simpset() addsimps [LIM_isCont_iff]) 1);
   528 by (simp_tac (simpset() addsimps [LIM_isCont_iff]) 1);
   529 qed "isCont_iff";
   529 qed "isCont_iff";
   530 
   530 
   531 (*--------------------------------------------------------------------------
   531 (*--------------------------------------------------------------------------
   532    Immediate application of nonstandard criterion for continuity can offer 
   532    Immediate application of nonstandard criterion for continuity can offer 
   572 by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
   572 by (auto_tac (claset(),simpset() addsimps [isNSCont_isCont_iff RS sym,
   573               isNSCont_minus]));
   573               isNSCont_minus]));
   574 qed "isCont_minus";
   574 qed "isCont_minus";
   575 
   575 
   576 Goalw [isCont_def]  
   576 Goalw [isCont_def]  
   577       "[| isCont f x; f x \\<noteq> #0 |] ==> isCont (%x. inverse (f x)) x";
   577       "[| isCont f x; f x \\<noteq> Numeral0 |] ==> isCont (%x. inverse (f x)) x";
   578 by (blast_tac (claset() addIs [LIM_inverse]) 1);
   578 by (blast_tac (claset() addIs [LIM_inverse]) 1);
   579 qed "isCont_inverse";
   579 qed "isCont_inverse";
   580 
   580 
   581 Goal "[| isNSCont f x; f x \\<noteq> #0 |] ==> isNSCont (%x. inverse (f x)) x";
   581 Goal "[| isNSCont f x; f x \\<noteq> Numeral0 |] ==> isNSCont (%x. inverse (f x)) x";
   582 by (auto_tac (claset() addIs [isCont_inverse],simpset() addsimps 
   582 by (auto_tac (claset() addIs [isCont_inverse],simpset() addsimps 
   583     [isNSCont_isCont_iff]));
   583     [isNSCont_isCont_iff]));
   584 qed "isNSCont_inverse";
   584 qed "isNSCont_inverse";
   585 
   585 
   586 Goalw [real_diff_def] 
   586 Goalw [real_diff_def] 
   688 by (thin_tac "\\<forall>x y. abs (x + - y) < s --> abs (f x + - f y) < u" 1);
   688 by (thin_tac "\\<forall>x y. abs (x + - y) < s --> abs (f x + - f y) < u" 1);
   689 by (dtac FreeUltrafilterNat_all 1);
   689 by (dtac FreeUltrafilterNat_all 1);
   690 by (Ultra_tac 1);
   690 by (Ultra_tac 1);
   691 qed "isUCont_isNSUCont";
   691 qed "isUCont_isNSUCont";
   692 
   692 
   693 Goal "\\<forall>s. #0 < s --> (\\<exists>z y. abs (z + - y) < s & r \\<le> abs (f z + -f y)) \
   693 Goal "\\<forall>s. Numeral0 < s --> (\\<exists>z y. abs (z + - y) < s & r \\<le> abs (f z + -f y)) \
   694 \     ==> \\<forall>n::nat. \\<exists>z y.  \
   694 \     ==> \\<forall>n::nat. \\<exists>z y.  \
   695 \              abs(z + -y) < inverse(real(Suc n)) & \
   695 \              abs(z + -y) < inverse(real(Suc n)) & \
   696 \              r \\<le> abs(f z + -f y)";
   696 \              r \\<le> abs(f z + -f y)";
   697 by (Clarify_tac 1); 
   697 by (Clarify_tac 1); 
   698 by (cut_inst_tac [("n1","n")]
   698 by (cut_inst_tac [("n1","n")]
   699     (real_of_nat_Suc_gt_zero RS rename_numerals real_inverse_gt_zero) 1);
   699     (real_of_nat_Suc_gt_zero RS rename_numerals real_inverse_gt_zero) 1);
   700 by Auto_tac;
   700 by Auto_tac;
   701 val lemma_LIMu = result();
   701 val lemma_LIMu = result();
   702 
   702 
   703 Goal "\\<forall>s. #0 < s --> (\\<exists>z y. abs (z + - y) < s  & r \\<le> abs (f z + -f y)) \
   703 Goal "\\<forall>s. Numeral0 < s --> (\\<exists>z y. abs (z + - y) < s  & r \\<le> abs (f z + -f y)) \
   704 \     ==> \\<exists>X Y. \\<forall>n::nat. \
   704 \     ==> \\<exists>X Y. \\<forall>n::nat. \
   705 \              abs(X n + -(Y n)) < inverse(real(Suc n)) & \
   705 \              abs(X n + -(Y n)) < inverse(real(Suc n)) & \
   706 \              r \\<le> abs(f (X n) + -f (Y n))";
   706 \              r \\<le> abs(f (X n) + -f (Y n))";
   707 by (dtac lemma_LIMu 1);
   707 by (dtac lemma_LIMu 1);
   708 by (dtac choice 1);
   708 by (dtac choice 1);
   743 
   743 
   744 (*------------------------------------------------------------------
   744 (*------------------------------------------------------------------
   745                          Derivatives
   745                          Derivatives
   746  ------------------------------------------------------------------*)
   746  ------------------------------------------------------------------*)
   747 Goalw [deriv_def] 
   747 Goalw [deriv_def] 
   748       "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- #0 --> D)";
   748       "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- Numeral0 --> D)";
   749 by (Blast_tac 1);        
   749 by (Blast_tac 1);        
   750 qed "DERIV_iff";
   750 qed "DERIV_iff";
   751 
   751 
   752 Goalw [deriv_def] 
   752 Goalw [deriv_def] 
   753       "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- #0 --NS> D)";
   753       "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- Numeral0 --NS> D)";
   754 by (simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   754 by (simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   755 qed "DERIV_NS_iff";
   755 qed "DERIV_NS_iff";
   756 
   756 
   757 Goalw [deriv_def] 
   757 Goalw [deriv_def] 
   758       "DERIV f x :> D \
   758       "DERIV f x :> D \
   759 \      ==> (%h. (f(x + h) + - f(x))/h) -- #0 --> D";
   759 \      ==> (%h. (f(x + h) + - f(x))/h) -- Numeral0 --> D";
   760 by (Blast_tac 1);        
   760 by (Blast_tac 1);        
   761 qed "DERIVD";
   761 qed "DERIVD";
   762 
   762 
   763 Goalw [deriv_def] "DERIV f x :> D ==> \
   763 Goalw [deriv_def] "DERIV f x :> D ==> \
   764 \          (%h. (f(x + h) + - f(x))/h) -- #0 --NS> D";
   764 \          (%h. (f(x + h) + - f(x))/h) -- Numeral0 --NS> D";
   765 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   765 by (asm_full_simp_tac (simpset() addsimps [LIM_NSLIM_iff]) 1);
   766 qed "NS_DERIVD";
   766 qed "NS_DERIVD";
   767 
   767 
   768 (* Uniqueness *)
   768 (* Uniqueness *)
   769 Goalw [deriv_def] 
   769 Goalw [deriv_def] 
   807 (*--------------------------------------------------------
   807 (*--------------------------------------------------------
   808       Alternative definition for differentiability
   808       Alternative definition for differentiability
   809  -------------------------------------------------------*)
   809  -------------------------------------------------------*)
   810 
   810 
   811 Goalw [LIM_def] 
   811 Goalw [LIM_def] 
   812  "((%h. (f(a + h) + - f(a))/h) -- #0 --> D) = \
   812  "((%h. (f(a + h) + - f(a))/h) -- Numeral0 --> D) = \
   813 \ ((%x. (f(x) + -f(a)) / (x + -a)) -- a --> D)";
   813 \ ((%x. (f(x) + -f(a)) / (x + -a)) -- a --> D)";
   814 by Safe_tac;
   814 by Safe_tac;
   815 by (ALLGOALS(dtac spec));
   815 by (ALLGOALS(dtac spec));
   816 by Safe_tac;
   816 by Safe_tac;
   817 by (Blast_tac 1 THEN Blast_tac 2);
   817 by (Blast_tac 1 THEN Blast_tac 2);
   834    First NSDERIV in terms of NSLIM 
   834    First NSDERIV in terms of NSLIM 
   835  -------------------------------------------*)
   835  -------------------------------------------*)
   836 
   836 
   837 (*--- first equivalence ---*)
   837 (*--- first equivalence ---*)
   838 Goalw [nsderiv_def,NSLIM_def] 
   838 Goalw [nsderiv_def,NSLIM_def] 
   839       "(NSDERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- #0 --NS> D)";
   839       "(NSDERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- Numeral0 --NS> D)";
   840 by (auto_tac (claset(), simpset() addsimps [hypreal_of_real_zero]));
   840 by (auto_tac (claset(), simpset() addsimps [hypreal_of_real_zero]));
   841 by (dres_inst_tac [("x","xa")] bspec 1);
   841 by (dres_inst_tac [("x","xa")] bspec 1);
   842 by (rtac ccontr 3);
   842 by (rtac ccontr 3);
   843 by (dres_inst_tac [("x","h")] spec 3);
   843 by (dres_inst_tac [("x","h")] spec 3);
   844 by (auto_tac (claset(),
   844 by (auto_tac (claset(),
   954 (*-------------------------
   954 (*-------------------------
   955     Constant function
   955     Constant function
   956  ------------------------*)
   956  ------------------------*)
   957 
   957 
   958 (* use simple constant nslimit theorem *)
   958 (* use simple constant nslimit theorem *)
   959 Goal "(NSDERIV (%x. k) x :> #0)";
   959 Goal "(NSDERIV (%x. k) x :> Numeral0)";
   960 by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
   960 by (simp_tac (simpset() addsimps [NSDERIV_NSLIM_iff]) 1);
   961 qed "NSDERIV_const";
   961 qed "NSDERIV_const";
   962 Addsimps [NSDERIV_const];
   962 Addsimps [NSDERIV_const];
   963 
   963 
   964 Goal "(DERIV (%x. k) x :> #0)";
   964 Goal "(DERIV (%x. k) x :> Numeral0)";
   965 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
   965 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
   966 qed "DERIV_const";
   966 qed "DERIV_const";
   967 Addsimps [DERIV_const];
   967 Addsimps [DERIV_const];
   968 
   968 
   969 (*-----------------------------------------------------
   969 (*-----------------------------------------------------
   998 by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib2]) 1);
   998 by (simp_tac (simpset() addsimps [hypreal_add_mult_distrib2]) 1);
   999 val lemma_nsderiv1 = result();
   999 val lemma_nsderiv1 = result();
  1000 
  1000 
  1001 Goal "[| (x + y) / z = hypreal_of_real D + yb; z \\<noteq> 0; \
  1001 Goal "[| (x + y) / z = hypreal_of_real D + yb; z \\<noteq> 0; \
  1002 \        z \\<in> Infinitesimal; yb \\<in> Infinitesimal |] \
  1002 \        z \\<in> Infinitesimal; yb \\<in> Infinitesimal |] \
  1003 \     ==> x + y \\<approx> #0";
  1003 \     ==> x + y \\<approx> Numeral0";
  1004 by (forw_inst_tac [("c1","z")] (hypreal_mult_right_cancel RS iffD2) 1 
  1004 by (forw_inst_tac [("c1","z")] (hypreal_mult_right_cancel RS iffD2) 1 
  1005     THEN assume_tac 1);
  1005     THEN assume_tac 1);
  1006 by (thin_tac "(x + y) / z = hypreal_of_real D + yb" 1);
  1006 by (thin_tac "(x + y) / z = hypreal_of_real D + yb" 1);
  1007 by (auto_tac (claset() addSIs [Infinitesimal_HFinite_mult2, HFinite_add],
  1007 by (auto_tac (claset() addSIs [Infinitesimal_HFinite_mult2, HFinite_add],
  1008               simpset() addsimps [hypreal_mult_assoc, mem_infmal_iff RS sym]));
  1008               simpset() addsimps [hypreal_mult_assoc, mem_infmal_iff RS sym]));
  1125 \    -hypreal_of_real (f x)";
  1125 \    -hypreal_of_real (f x)";
  1126 by (etac (NSdifferentiableI RS incrementI) 1);
  1126 by (etac (NSdifferentiableI RS incrementI) 1);
  1127 qed "incrementI2";
  1127 qed "incrementI2";
  1128 
  1128 
  1129 (* The Increment theorem -- Keisler p. 65 *)
  1129 (* The Increment theorem -- Keisler p. 65 *)
  1130 Goal "[| NSDERIV f x :> D; h \\<in> Infinitesimal; h \\<noteq> #0 |] \
  1130 Goal "[| NSDERIV f x :> D; h \\<in> Infinitesimal; h \\<noteq> Numeral0 |] \
  1131 \     ==> \\<exists>e \\<in> Infinitesimal. increment f x h = hypreal_of_real(D)*h + e*h";
  1131 \     ==> \\<exists>e \\<in> Infinitesimal. increment f x h = hypreal_of_real(D)*h + e*h";
  1132 by (forw_inst_tac [("h","h")] incrementI2 1 THEN rewtac nsderiv_def);
  1132 by (forw_inst_tac [("h","h")] incrementI2 1 THEN rewtac nsderiv_def);
  1133 by (dtac bspec 1 THEN Auto_tac);
  1133 by (dtac bspec 1 THEN Auto_tac);
  1134 by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1 THEN Step_tac 1);
  1134 by (dtac (bex_Infinitesimal_iff2 RS iffD2) 1 THEN Step_tac 1);
  1135 by (forw_inst_tac [("b1","hypreal_of_real(D) + y")] 
  1135 by (forw_inst_tac [("b1","hypreal_of_real(D) + y")] 
  1141              delsimps [hypreal_times_divide1_eq]) 1);
  1141              delsimps [hypreal_times_divide1_eq]) 1);
  1142 by (auto_tac (claset(),
  1142 by (auto_tac (claset(),
  1143               simpset() addsimps [hypreal_add_mult_distrib]));
  1143               simpset() addsimps [hypreal_add_mult_distrib]));
  1144 qed "increment_thm";
  1144 qed "increment_thm";
  1145 
  1145 
  1146 Goal "[| NSDERIV f x :> D; h \\<approx> #0; h \\<noteq> #0 |] \
  1146 Goal "[| NSDERIV f x :> D; h \\<approx> Numeral0; h \\<noteq> Numeral0 |] \
  1147 \     ==> \\<exists>e \\<in> Infinitesimal. increment f x h = \
  1147 \     ==> \\<exists>e \\<in> Infinitesimal. increment f x h = \
  1148 \             hypreal_of_real(D)*h + e*h";
  1148 \             hypreal_of_real(D)*h + e*h";
  1149 by (blast_tac (claset() addSDs [mem_infmal_iff RS iffD2] 
  1149 by (blast_tac (claset() addSDs [mem_infmal_iff RS iffD2] 
  1150                         addSIs [increment_thm]) 1);
  1150                         addSIs [increment_thm]) 1);
  1151 qed "increment_thm2";
  1151 qed "increment_thm2";
  1152 
  1152 
  1153 Goal "[| NSDERIV f x :> D; h \\<approx> #0; h \\<noteq> #0 |] \
  1153 Goal "[| NSDERIV f x :> D; h \\<approx> Numeral0; h \\<noteq> Numeral0 |] \
  1154 \     ==> increment f x h \\<approx> #0";
  1154 \     ==> increment f x h \\<approx> Numeral0";
  1155 by (dtac increment_thm2 1 THEN auto_tac (claset() addSIs 
  1155 by (dtac increment_thm2 1 THEN auto_tac (claset() addSIs 
  1156     [Infinitesimal_HFinite_mult2,HFinite_add],simpset() addsimps 
  1156     [Infinitesimal_HFinite_mult2,HFinite_add],simpset() addsimps 
  1157     [hypreal_add_mult_distrib RS sym,mem_infmal_iff RS sym]));
  1157     [hypreal_add_mult_distrib RS sym,mem_infmal_iff RS sym]));
  1158 by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
  1158 by (etac (Infinitesimal_subset_HFinite RS subsetD) 1);
  1159 qed "increment_approx_zero";
  1159 qed "increment_approx_zero";
  1170 (* lemmas *)
  1170 (* lemmas *)
  1171 Goalw [nsderiv_def] 
  1171 Goalw [nsderiv_def] 
  1172       "[| NSDERIV g x :> D; \
  1172       "[| NSDERIV g x :> D; \
  1173 \              (*f* g) (hypreal_of_real(x) + xa) = hypreal_of_real(g x);\
  1173 \              (*f* g) (hypreal_of_real(x) + xa) = hypreal_of_real(g x);\
  1174 \              xa \\<in> Infinitesimal;\
  1174 \              xa \\<in> Infinitesimal;\
  1175 \              xa \\<noteq> #0 \
  1175 \              xa \\<noteq> Numeral0 \
  1176 \           |] ==> D = #0";
  1176 \           |] ==> D = Numeral0";
  1177 by (dtac bspec 1);
  1177 by (dtac bspec 1);
  1178 by Auto_tac;
  1178 by Auto_tac;
  1179 qed "NSDERIV_zero";
  1179 qed "NSDERIV_zero";
  1180 
  1180 
  1181 (* can be proved differently using NSLIM_isCont_iff *)
  1181 (* can be proved differently using NSLIM_isCont_iff *)
  1182 Goalw [nsderiv_def] 
  1182 Goalw [nsderiv_def] 
  1183      "[| NSDERIV f x :> D;  h \\<in> Infinitesimal;  h \\<noteq> #0 |]  \
  1183      "[| NSDERIV f x :> D;  h \\<in> Infinitesimal;  h \\<noteq> Numeral0 |]  \
  1184 \     ==> (*f* f) (hypreal_of_real(x) + h) + -hypreal_of_real(f x) \\<approx> #0";    
  1184 \     ==> (*f* f) (hypreal_of_real(x) + h) + -hypreal_of_real(f x) \\<approx> Numeral0";    
  1185 by (asm_full_simp_tac (simpset() addsimps 
  1185 by (asm_full_simp_tac (simpset() addsimps 
  1186     [mem_infmal_iff RS sym]) 1);
  1186     [mem_infmal_iff RS sym]) 1);
  1187 by (rtac Infinitesimal_ratio 1);
  1187 by (rtac Infinitesimal_ratio 1);
  1188 by (rtac approx_hypreal_of_real_HFinite 3);
  1188 by (rtac approx_hypreal_of_real_HFinite 3);
  1189 by Auto_tac;
  1189 by Auto_tac;
  1212 
  1212 
  1213                 f(x + h) - f(x)
  1213                 f(x + h) - f(x)
  1214                ----------------- \\<approx> Db
  1214                ----------------- \\<approx> Db
  1215                        h
  1215                        h
  1216  --------------------------------------------------------------*)
  1216  --------------------------------------------------------------*)
  1217 Goal "[| NSDERIV g x :> Db; xa \\<in> Infinitesimal; xa \\<noteq> #0 |] \
  1217 Goal "[| NSDERIV g x :> Db; xa \\<in> Infinitesimal; xa \\<noteq> Numeral0 |] \
  1218 \     ==> ((*f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real(g x)) / xa \
  1218 \     ==> ((*f* g) (hypreal_of_real(x) + xa) + - hypreal_of_real(g x)) / xa \
  1219 \         \\<approx> hypreal_of_real(Db)";
  1219 \         \\<approx> hypreal_of_real(Db)";
  1220 by (auto_tac (claset(),
  1220 by (auto_tac (claset(),
  1221     simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def, 
  1221     simpset() addsimps [NSDERIV_NSLIM_iff, NSLIM_def, 
  1222 		hypreal_of_real_zero, mem_infmal_iff, starfun_lambda_cancel]));
  1222 		hypreal_of_real_zero, mem_infmal_iff, starfun_lambda_cancel]));
  1264 qed "DERIV_chain2";
  1264 qed "DERIV_chain2";
  1265 
  1265 
  1266 (*------------------------------------------------------------------
  1266 (*------------------------------------------------------------------
  1267            Differentiation of natural number powers
  1267            Differentiation of natural number powers
  1268  ------------------------------------------------------------------*)
  1268  ------------------------------------------------------------------*)
  1269 Goal "NSDERIV (%x. x) x :> #1";
  1269 Goal "NSDERIV (%x. x) x :> Numeral1";
  1270 by (auto_tac (claset(),
  1270 by (auto_tac (claset(),
  1271      simpset() addsimps [NSDERIV_NSLIM_iff,
  1271      simpset() addsimps [NSDERIV_NSLIM_iff,
  1272           NSLIM_def ,starfun_Id, hypreal_of_real_zero,
  1272           NSLIM_def ,starfun_Id, hypreal_of_real_zero,
  1273            hypreal_of_real_one]));
  1273            hypreal_of_real_one]));
  1274 qed "NSDERIV_Id";
  1274 qed "NSDERIV_Id";
  1275 Addsimps [NSDERIV_Id];
  1275 Addsimps [NSDERIV_Id];
  1276 
  1276 
  1277 (*derivative of the identity function*)
  1277 (*derivative of the identity function*)
  1278 Goal "DERIV (%x. x) x :> #1";
  1278 Goal "DERIV (%x. x) x :> Numeral1";
  1279 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
  1279 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff RS sym]) 1);
  1280 qed "DERIV_Id";
  1280 qed "DERIV_Id";
  1281 Addsimps [DERIV_Id];
  1281 Addsimps [DERIV_Id];
  1282 
  1282 
  1283 bind_thm ("isCont_Id", DERIV_Id RS DERIV_isCont);
  1283 bind_thm ("isCont_Id", DERIV_Id RS DERIV_isCont);
  1292 Goal "NSDERIV (op * c) x :> c";
  1292 Goal "NSDERIV (op * c) x :> c";
  1293 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff]) 1);
  1293 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff]) 1);
  1294 qed "NSDERIV_cmult_Id";
  1294 qed "NSDERIV_cmult_Id";
  1295 Addsimps [NSDERIV_cmult_Id];
  1295 Addsimps [NSDERIV_cmult_Id];
  1296 
  1296 
  1297 Goal "DERIV (%x. x ^ n) x :> real n * (x ^ (n - 1'))";
  1297 Goal "DERIV (%x. x ^ n) x :> real n * (x ^ (n - Suc 0))";
  1298 by (induct_tac "n" 1);
  1298 by (induct_tac "n" 1);
  1299 by (dtac (DERIV_Id RS DERIV_mult) 2);
  1299 by (dtac (DERIV_Id RS DERIV_mult) 2);
  1300 by (auto_tac (claset(), 
  1300 by (auto_tac (claset(), 
  1301               simpset() addsimps [real_of_nat_Suc, real_add_mult_distrib]));
  1301               simpset() addsimps [real_of_nat_Suc, real_add_mult_distrib]));
  1302 by (case_tac "0 < n" 1);
  1302 by (case_tac "0 < n" 1);
  1304 by (auto_tac (claset(), 
  1304 by (auto_tac (claset(), 
  1305               simpset() addsimps [real_mult_assoc, real_add_commute]));
  1305               simpset() addsimps [real_mult_assoc, real_add_commute]));
  1306 qed "DERIV_pow";
  1306 qed "DERIV_pow";
  1307 
  1307 
  1308 (* NS version *)
  1308 (* NS version *)
  1309 Goal "NSDERIV (%x. x ^ n) x :> real n * (x ^ (n - 1'))";
  1309 Goal "NSDERIV (%x. x ^ n) x :> real n * (x ^ (n - Suc 0))";
  1310 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff, DERIV_pow]) 1);
  1310 by (simp_tac (simpset() addsimps [NSDERIV_DERIV_iff, DERIV_pow]) 1);
  1311 qed "NSDERIV_pow";
  1311 qed "NSDERIV_pow";
  1312 
  1312 
  1313 (*---------------------------------------------------------------
  1313 (*---------------------------------------------------------------
  1314                     Power of -1 
  1314                     Power of -1 
  1315  ---------------------------------------------------------------*)
  1315  ---------------------------------------------------------------*)
  1316 
  1316 
  1317 (*Can't get rid of x \\<noteq> #0 because it isn't continuous at zero*)
  1317 (*Can't get rid of x \\<noteq> Numeral0 because it isn't continuous at zero*)
  1318 Goalw [nsderiv_def]
  1318 Goalw [nsderiv_def]
  1319      "x \\<noteq> #0 ==> NSDERIV (%x. inverse(x)) x :> (- (inverse x ^ 2))";
  1319      "x \\<noteq> Numeral0 ==> NSDERIV (%x. inverse(x)) x :> (- (inverse x ^ Suc (Suc 0)))";
  1320 by (rtac ballI 1 THEN Asm_full_simp_tac 1 THEN Step_tac 1);
  1320 by (rtac ballI 1 THEN Asm_full_simp_tac 1 THEN Step_tac 1);
  1321 by (forward_tac [Infinitesimal_add_not_zero] 1);
  1321 by (forward_tac [Infinitesimal_add_not_zero] 1);
  1322 by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 2); 
  1322 by (asm_full_simp_tac (simpset() addsimps [hypreal_add_commute]) 2); 
  1323 by (auto_tac (claset(),
  1323 by (auto_tac (claset(),
  1324      simpset() addsimps [starfun_inverse_inverse, realpow_two] 
  1324      simpset() addsimps [starfun_inverse_inverse, realpow_two] 
  1343 by (rtac Infinitesimal_HFinite_mult2 1); 
  1343 by (rtac Infinitesimal_HFinite_mult2 1); 
  1344 by Auto_tac;  
  1344 by Auto_tac;  
  1345 qed "NSDERIV_inverse";
  1345 qed "NSDERIV_inverse";
  1346 
  1346 
  1347 
  1347 
  1348 Goal "x \\<noteq> #0 ==> DERIV (%x. inverse(x)) x :> (-(inverse x ^ 2))";
  1348 Goal "x \\<noteq> Numeral0 ==> DERIV (%x. inverse(x)) x :> (-(inverse x ^ Suc (Suc 0)))";
  1349 by (asm_simp_tac (simpset() addsimps [NSDERIV_inverse,
  1349 by (asm_simp_tac (simpset() addsimps [NSDERIV_inverse,
  1350          NSDERIV_DERIV_iff RS sym] delsimps [realpow_Suc]) 1);
  1350          NSDERIV_DERIV_iff RS sym] delsimps [realpow_Suc]) 1);
  1351 qed "DERIV_inverse";
  1351 qed "DERIV_inverse";
  1352 
  1352 
  1353 (*--------------------------------------------------------------
  1353 (*--------------------------------------------------------------
  1354         Derivative of inverse 
  1354         Derivative of inverse 
  1355  -------------------------------------------------------------*)
  1355  -------------------------------------------------------------*)
  1356 Goal "[| DERIV f x :> d; f(x) \\<noteq> #0 |] \
  1356 Goal "[| DERIV f x :> d; f(x) \\<noteq> Numeral0 |] \
  1357 \     ==> DERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ 2)))";
  1357 \     ==> DERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ Suc (Suc 0))))";
  1358 by (rtac (real_mult_commute RS subst) 1);
  1358 by (rtac (real_mult_commute RS subst) 1);
  1359 by (asm_simp_tac (simpset() addsimps [real_minus_mult_eq1,
  1359 by (asm_simp_tac (simpset() addsimps [real_minus_mult_eq1,
  1360     realpow_inverse] delsimps [realpow_Suc, 
  1360     realpow_inverse] delsimps [realpow_Suc, 
  1361     real_minus_mult_eq1 RS sym]) 1);
  1361     real_minus_mult_eq1 RS sym]) 1);
  1362 by (fold_goals_tac [o_def]);
  1362 by (fold_goals_tac [o_def]);
  1363 by (blast_tac (claset() addSIs [DERIV_chain,DERIV_inverse]) 1);
  1363 by (blast_tac (claset() addSIs [DERIV_chain,DERIV_inverse]) 1);
  1364 qed "DERIV_inverse_fun";
  1364 qed "DERIV_inverse_fun";
  1365 
  1365 
  1366 Goal "[| NSDERIV f x :> d; f(x) \\<noteq> #0 |] \
  1366 Goal "[| NSDERIV f x :> d; f(x) \\<noteq> Numeral0 |] \
  1367 \     ==> NSDERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ 2)))";
  1367 \     ==> NSDERIV (%x. inverse(f x)) x :> (- (d * inverse(f(x) ^ Suc (Suc 0))))";
  1368 by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  1368 by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  1369             DERIV_inverse_fun] delsimps [realpow_Suc]) 1);
  1369             DERIV_inverse_fun] delsimps [realpow_Suc]) 1);
  1370 qed "NSDERIV_inverse_fun";
  1370 qed "NSDERIV_inverse_fun";
  1371 
  1371 
  1372 (*--------------------------------------------------------------
  1372 (*--------------------------------------------------------------
  1373         Derivative of quotient 
  1373         Derivative of quotient 
  1374  -------------------------------------------------------------*)
  1374  -------------------------------------------------------------*)
  1375 Goal "[| DERIV f x :> d; DERIV g x :> e; g(x) \\<noteq> #0 |] \
  1375 Goal "[| DERIV f x :> d; DERIV g x :> e; g(x) \\<noteq> Numeral0 |] \
  1376 \      ==> DERIV (%y. f(y) / (g y)) x :> (d*g(x) + -(e*f(x))) / (g(x) ^ 2)";
  1376 \      ==> DERIV (%y. f(y) / (g y)) x :> (d*g(x) + -(e*f(x))) / (g(x) ^ Suc (Suc 0))";
  1377 by (dres_inst_tac [("f","g")] DERIV_inverse_fun 1);
  1377 by (dres_inst_tac [("f","g")] DERIV_inverse_fun 1);
  1378 by (dtac DERIV_mult 2);
  1378 by (dtac DERIV_mult 2);
  1379 by (REPEAT(assume_tac 1));
  1379 by (REPEAT(assume_tac 1));
  1380 by (asm_full_simp_tac
  1380 by (asm_full_simp_tac
  1381     (simpset() addsimps [real_divide_def, real_add_mult_distrib2,
  1381     (simpset() addsimps [real_divide_def, real_add_mult_distrib2,
  1382                          realpow_inverse,real_minus_mult_eq1] @ real_mult_ac 
  1382                          realpow_inverse,real_minus_mult_eq1] @ real_mult_ac 
  1383        delsimps [realpow_Suc, real_minus_mult_eq1 RS sym,
  1383        delsimps [realpow_Suc, real_minus_mult_eq1 RS sym,
  1384                  real_minus_mult_eq2 RS sym]) 1);
  1384                  real_minus_mult_eq2 RS sym]) 1);
  1385 qed "DERIV_quotient";
  1385 qed "DERIV_quotient";
  1386 
  1386 
  1387 Goal "[| NSDERIV f x :> d; DERIV g x :> e; g(x) \\<noteq> #0 |] \
  1387 Goal "[| NSDERIV f x :> d; DERIV g x :> e; g(x) \\<noteq> Numeral0 |] \
  1388 \      ==> NSDERIV (%y. f(y) / (g y)) x :> (d*g(x) \
  1388 \      ==> NSDERIV (%y. f(y) / (g y)) x :> (d*g(x) \
  1389 \                           + -(e*f(x))) / (g(x) ^ 2)";
  1389 \                           + -(e*f(x))) / (g(x) ^ Suc (Suc 0))";
  1390 by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  1390 by (asm_full_simp_tac (simpset() addsimps [NSDERIV_DERIV_iff,
  1391             DERIV_quotient] delsimps [realpow_Suc]) 1);
  1391             DERIV_quotient] delsimps [realpow_Suc]) 1);
  1392 qed "NSDERIV_quotient";
  1392 qed "NSDERIV_quotient";
  1393  
  1393  
  1394 (* ------------------------------------------------------------------------ *)
  1394 (* ------------------------------------------------------------------------ *)
  1399 \     (\\<exists>g. (\\<forall>z. f z - f x = g z * (z - x)) & isCont g x & g x = l)";
  1399 \     (\\<exists>g. (\\<forall>z. f z - f x = g z * (z - x)) & isCont g x & g x = l)";
  1400 by Safe_tac;
  1400 by Safe_tac;
  1401 by (res_inst_tac 
  1401 by (res_inst_tac 
  1402     [("x","%z. if  z = x then l else (f(z) - f(x)) / (z - x)")] exI 1);
  1402     [("x","%z. if  z = x then l else (f(z) - f(x)) / (z - x)")] exI 1);
  1403 by (auto_tac (claset(),simpset() addsimps [real_mult_assoc,
  1403 by (auto_tac (claset(),simpset() addsimps [real_mult_assoc,
  1404     ARITH_PROVE "z \\<noteq> x ==> z - x \\<noteq> (#0::real)"]));
  1404     ARITH_PROVE "z \\<noteq> x ==> z - x \\<noteq> (Numeral0::real)"]));
  1405 by (auto_tac (claset(),simpset() addsimps [isCont_iff,DERIV_iff]));
  1405 by (auto_tac (claset(),simpset() addsimps [isCont_iff,DERIV_iff]));
  1406 by (ALLGOALS(rtac (LIM_equal RS iffD1)));
  1406 by (ALLGOALS(rtac (LIM_equal RS iffD1)));
  1407 by (auto_tac (claset(),simpset() addsimps [real_diff_def,real_mult_assoc]));
  1407 by (auto_tac (claset(),simpset() addsimps [real_diff_def,real_mult_assoc]));
  1408 qed "CARAT_DERIV";
  1408 qed "CARAT_DERIV";
  1409 
  1409 
  1509 qed "lemma_nest";
  1509 qed "lemma_nest";
  1510 
  1510 
  1511 Goal "[| \\<forall>n. f(n) \\<le> f(Suc n); \
  1511 Goal "[| \\<forall>n. f(n) \\<le> f(Suc n); \
  1512 \        \\<forall>n. g(Suc n) \\<le> g(n); \
  1512 \        \\<forall>n. g(Suc n) \\<le> g(n); \
  1513 \        \\<forall>n. f(n) \\<le> g(n); \
  1513 \        \\<forall>n. f(n) \\<le> g(n); \
  1514 \        (%n. f(n) - g(n)) ----> #0 |] \
  1514 \        (%n. f(n) - g(n)) ----> Numeral0 |] \
  1515 \     ==> \\<exists>l. ((\\<forall>n. f(n) \\<le> l) & f ----> l) & \
  1515 \     ==> \\<exists>l. ((\\<forall>n. f(n) \\<le> l) & f ----> l) & \
  1516 \               ((\\<forall>n. l \\<le> g(n)) & g ----> l)";
  1516 \               ((\\<forall>n. l \\<le> g(n)) & g ----> l)";
  1517 by (dtac lemma_nest 1 THEN Auto_tac);
  1517 by (dtac lemma_nest 1 THEN Auto_tac);
  1518 by (subgoal_tac "l = m" 1);
  1518 by (subgoal_tac "l = m" 1);
  1519 by (dres_inst_tac [("X","f")] LIMSEQ_diff 2);
  1519 by (dres_inst_tac [("X","f")] LIMSEQ_diff 2);
  1542 by (induct_tac "n" 1);
  1542 by (induct_tac "n" 1);
  1543 by (auto_tac (claset(), 
  1543 by (auto_tac (claset(), 
  1544               simpset() addsimps [Bolzano_bisect_le, Let_def, split_def]));  
  1544               simpset() addsimps [Bolzano_bisect_le, Let_def, split_def]));  
  1545 qed "Bolzano_bisect_Suc_le_snd";
  1545 qed "Bolzano_bisect_Suc_le_snd";
  1546 
  1546 
  1547 Goal "((x::real) = y / (#2 * z)) = (#2 * x = y/z)";
  1547 Goal "((x::real) = y / (# 2 * z)) = (# 2 * x = y/z)";
  1548 by Auto_tac;  
  1548 by Auto_tac;  
  1549 by (dres_inst_tac [("f","%u. (#1/#2)*u")] arg_cong 1); 
  1549 by (dres_inst_tac [("f","%u. (Numeral1/# 2)*u")] arg_cong 1); 
  1550 by Auto_tac;  
  1550 by Auto_tac;  
  1551 qed "eq_divide_2_times_iff";
  1551 qed "eq_divide_2_times_iff";
  1552 
  1552 
  1553 Goal "a \\<le> b ==> \
  1553 Goal "a \\<le> b ==> \
  1554 \     snd(Bolzano_bisect P a b n) - fst(Bolzano_bisect P a b n) = \
  1554 \     snd(Bolzano_bisect P a b n) - fst(Bolzano_bisect P a b n) = \
  1555 \     (b-a) / (#2 ^ n)";
  1555 \     (b-a) / (# 2 ^ n)";
  1556 by (induct_tac "n" 1);
  1556 by (induct_tac "n" 1);
  1557 by (auto_tac (claset(), 
  1557 by (auto_tac (claset(), 
  1558       simpset() addsimps [eq_divide_2_times_iff, real_add_divide_distrib, 
  1558       simpset() addsimps [eq_divide_2_times_iff, real_add_divide_distrib, 
  1559                           Let_def, split_def]));
  1559                           Let_def, split_def]));
  1560 by (auto_tac (claset(), 
  1560 by (auto_tac (claset(), 
  1587 by (blast_tac (claset() addSEs [not_P_Bolzano_bisect RSN (2,rev_notE)]) 1); 
  1587 by (blast_tac (claset() addSEs [not_P_Bolzano_bisect RSN (2,rev_notE)]) 1); 
  1588 qed "not_P_Bolzano_bisect'";
  1588 qed "not_P_Bolzano_bisect'";
  1589 
  1589 
  1590 
  1590 
  1591 Goal "[| \\<forall>a b c. P(a,b) & P(b,c) & a \\<le> b & b \\<le> c --> P(a,c); \
  1591 Goal "[| \\<forall>a b c. P(a,b) & P(b,c) & a \\<le> b & b \\<le> c --> P(a,c); \
  1592 \        \\<forall>x. \\<exists>d::real. #0 < d & \
  1592 \        \\<forall>x. \\<exists>d::real. Numeral0 < d & \
  1593 \               (\\<forall>a b. a \\<le> x & x \\<le> b & (b - a) < d --> P(a,b)); \
  1593 \               (\\<forall>a b. a \\<le> x & x \\<le> b & (b - a) < d --> P(a,b)); \
  1594 \        a \\<le> b |]  \
  1594 \        a \\<le> b |]  \
  1595 \     ==> P(a,b)";
  1595 \     ==> P(a,b)";
  1596 by (rtac (inst "P1" "P" Bolzano_nest_unique RS exE) 1);
  1596 by (rtac (inst "P1" "P" Bolzano_nest_unique RS exE) 1);
  1597 by (REPEAT (assume_tac 1));
  1597 by (REPEAT (assume_tac 1));
  1602 by (dtac not_P_Bolzano_bisect' 1); 
  1602 by (dtac not_P_Bolzano_bisect' 1); 
  1603 by (REPEAT (assume_tac 1));
  1603 by (REPEAT (assume_tac 1));
  1604 by (rename_tac "l" 1);
  1604 by (rename_tac "l" 1);
  1605 by (dres_inst_tac [("x","l")] spec 1 THEN Clarify_tac 1);
  1605 by (dres_inst_tac [("x","l")] spec 1 THEN Clarify_tac 1);
  1606 by (rewtac LIMSEQ_def);
  1606 by (rewtac LIMSEQ_def);
  1607 by (dres_inst_tac [("P", "%r. #0<r --> ?Q r"), ("x","d/#2")] spec 1);
  1607 by (dres_inst_tac [("P", "%r. Numeral0<r --> ?Q r"), ("x","d/# 2")] spec 1);
  1608 by (dres_inst_tac [("P", "%r. #0<r --> ?Q r"), ("x","d/#2")] spec 1);
  1608 by (dres_inst_tac [("P", "%r. Numeral0<r --> ?Q r"), ("x","d/# 2")] spec 1);
  1609 by (dtac real_less_half_sum 1);
  1609 by (dtac real_less_half_sum 1);
  1610 by Safe_tac;
  1610 by Safe_tac;
  1611 (*linear arithmetic bug if we just use Asm_simp_tac*)
  1611 (*linear arithmetic bug if we just use Asm_simp_tac*)
  1612 by (ALLGOALS Asm_full_simp_tac);
  1612 by (ALLGOALS Asm_full_simp_tac);
  1613 by (dres_inst_tac [("x","fst(Bolzano_bisect P a b (no + noa))")] spec 1);
  1613 by (dres_inst_tac [("x","fst(Bolzano_bisect P a b (no + noa))")] spec 1);
  1624     (asm_full_simp_tac (simpset() addsimps [symmetric real_diff_def])));
  1624     (asm_full_simp_tac (simpset() addsimps [symmetric real_diff_def])));
  1625 qed "lemma_BOLZANO";
  1625 qed "lemma_BOLZANO";
  1626 
  1626 
  1627 
  1627 
  1628 Goal "((\\<forall>a b c. (a \\<le> b & b \\<le> c & P(a,b) & P(b,c)) --> P(a,c)) & \
  1628 Goal "((\\<forall>a b c. (a \\<le> b & b \\<le> c & P(a,b) & P(b,c)) --> P(a,c)) & \
  1629 \      (\\<forall>x. \\<exists>d::real. #0 < d & \
  1629 \      (\\<forall>x. \\<exists>d::real. Numeral0 < d & \
  1630 \               (\\<forall>a b. a \\<le> x & x \\<le> b & (b - a) < d --> P(a,b)))) \
  1630 \               (\\<forall>a b. a \\<le> x & x \\<le> b & (b - a) < d --> P(a,b)))) \
  1631 \     --> (\\<forall>a b. a \\<le> b --> P(a,b))";
  1631 \     --> (\\<forall>a b. a \\<le> b --> P(a,b))";
  1632 by (Clarify_tac 1);
  1632 by (Clarify_tac 1);
  1633 by (blast_tac (claset() addIs [lemma_BOLZANO]) 1); 
  1633 by (blast_tac (claset() addIs [lemma_BOLZANO]) 1); 
  1634 qed "lemma_BOLZANO2";
  1634 qed "lemma_BOLZANO2";
  1652 by (Blast_tac 2);
  1652 by (Blast_tac 2);
  1653 by (asm_full_simp_tac (simpset() addsimps [isCont_iff,LIM_def]) 1);
  1653 by (asm_full_simp_tac (simpset() addsimps [isCont_iff,LIM_def]) 1);
  1654 by (rtac ccontr 1);
  1654 by (rtac ccontr 1);
  1655 by (subgoal_tac "a \\<le> x & x \\<le> b" 1);
  1655 by (subgoal_tac "a \\<le> x & x \\<le> b" 1);
  1656 by (Asm_full_simp_tac 2);
  1656 by (Asm_full_simp_tac 2);
  1657 by (dres_inst_tac [("P", "%d. #0<d --> ?P d"),("x","#1")] spec 2);
  1657 by (dres_inst_tac [("P", "%d. Numeral0<d --> ?P d"),("x","Numeral1")] spec 2);
  1658 by (Step_tac 2);
  1658 by (Step_tac 2);
  1659 by (Asm_full_simp_tac 2);
  1659 by (Asm_full_simp_tac 2);
  1660 by (Asm_full_simp_tac 2);
  1660 by (Asm_full_simp_tac 2);
  1661 by (REPEAT(blast_tac (claset() addIs [order_trans]) 2));
  1661 by (REPEAT(blast_tac (claset() addIs [order_trans]) 2));
  1662 by (REPEAT(dres_inst_tac [("x","x")] spec 1));
  1662 by (REPEAT(dres_inst_tac [("x","x")] spec 1));
  1663 by (Asm_full_simp_tac 1);
  1663 by (Asm_full_simp_tac 1);
  1664 by (dres_inst_tac [("P", "%r. ?P r --> (\\<exists>s. #0<s & ?Q r s)"),
  1664 by (dres_inst_tac [("P", "%r. ?P r --> (\\<exists>s. Numeral0<s & ?Q r s)"),
  1665                    ("x","abs(y - f x)")] spec 1);
  1665                    ("x","abs(y - f x)")] spec 1);
  1666 by Safe_tac;
  1666 by Safe_tac;
  1667 by (asm_full_simp_tac (simpset() addsimps []) 1);
  1667 by (asm_full_simp_tac (simpset() addsimps []) 1);
  1668 by (dres_inst_tac [("x","s")] spec 1);
  1668 by (dres_inst_tac [("x","s")] spec 1);
  1669 by (Clarify_tac 1);
  1669 by (Clarify_tac 1);
  1736 by (res_inst_tac [("x","M")] exI 1);
  1736 by (res_inst_tac [("x","M")] exI 1);
  1737 by (Clarify_tac 1); 
  1737 by (Clarify_tac 1); 
  1738 by (cut_inst_tac [("x","xb"),("y","xa")] linorder_linear 1);
  1738 by (cut_inst_tac [("x","xb"),("y","xa")] linorder_linear 1);
  1739 by (Force_tac 1); 
  1739 by (Force_tac 1); 
  1740 by (case_tac "a \\<le> x & x \\<le> b" 1);
  1740 by (case_tac "a \\<le> x & x \\<le> b" 1);
  1741 by (res_inst_tac [("x","#1")] exI 2);
  1741 by (res_inst_tac [("x","Numeral1")] exI 2);
  1742 by (Force_tac 2); 
  1742 by (Force_tac 2); 
  1743 by (asm_full_simp_tac (simpset() addsimps [LIM_def,isCont_iff]) 1);
  1743 by (asm_full_simp_tac (simpset() addsimps [LIM_def,isCont_iff]) 1);
  1744 by (dres_inst_tac [("x","x")] spec 1 THEN Auto_tac);
  1744 by (dres_inst_tac [("x","x")] spec 1 THEN Auto_tac);
  1745 by (thin_tac "\\<forall>M. \\<exists>x. a \\<le> x & x \\<le> b & ~ f x \\<le> M" 1);
  1745 by (thin_tac "\\<forall>M. \\<exists>x. a \\<le> x & x \\<le> b & ~ f x \\<le> M" 1);
  1746 by (dres_inst_tac [("x","#1")] spec 1);
  1746 by (dres_inst_tac [("x","Numeral1")] spec 1);
  1747 by Auto_tac;  
  1747 by Auto_tac;  
  1748 by (res_inst_tac [("x","s")] exI 1 THEN Clarify_tac 1);
  1748 by (res_inst_tac [("x","s")] exI 1 THEN Clarify_tac 1);
  1749 by (res_inst_tac [("x","abs(f x) + #1")] exI 1 THEN Clarify_tac 1);
  1749 by (res_inst_tac [("x","abs(f x) + Numeral1")] exI 1 THEN Clarify_tac 1);
  1750 by (dres_inst_tac [("x","xa - x")] spec 1 THEN Safe_tac);
  1750 by (dres_inst_tac [("x","xa - x")] spec 1 THEN Safe_tac);
  1751 by (arith_tac 1);
  1751 by (arith_tac 1);
  1752 by (arith_tac 1);
  1752 by (arith_tac 1);
  1753 by (asm_full_simp_tac (simpset() addsimps [abs_ge_self]) 1); 
  1753 by (asm_full_simp_tac (simpset() addsimps [abs_ge_self]) 1); 
  1754 by (arith_tac 1);
  1754 by (arith_tac 1);
  1801 by (Blast_tac 2);
  1801 by (Blast_tac 2);
  1802 by (subgoal_tac 
  1802 by (subgoal_tac 
  1803     "\\<exists>k. \\<forall>x. a \\<le> x & x \\<le> b --> (%x. inverse(M - (f x))) x \\<le> k" 1);
  1803     "\\<exists>k. \\<forall>x. a \\<le> x & x \\<le> b --> (%x. inverse(M - (f x))) x \\<le> k" 1);
  1804 by (rtac isCont_bounded 2);
  1804 by (rtac isCont_bounded 2);
  1805 by Safe_tac;
  1805 by Safe_tac;
  1806 by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> #0 < inverse(M - f(x))" 1);
  1806 by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> Numeral0 < inverse(M - f(x))" 1);
  1807 by (Asm_full_simp_tac 1); 
  1807 by (Asm_full_simp_tac 1); 
  1808 by Safe_tac;
  1808 by Safe_tac;
  1809 by (asm_full_simp_tac (simpset() addsimps [real_less_diff_eq]) 2);
  1809 by (asm_full_simp_tac (simpset() addsimps [real_less_diff_eq]) 2);
  1810 by (subgoal_tac 
  1810 by (subgoal_tac 
  1811     "\\<forall>x. a \\<le> x & x \\<le> b --> (%x. inverse(M - (f x))) x < (k + #1)" 1);
  1811     "\\<forall>x. a \\<le> x & x \\<le> b --> (%x. inverse(M - (f x))) x < (k + Numeral1)" 1);
  1812 by Safe_tac;
  1812 by Safe_tac;
  1813 by (res_inst_tac [("y","k")] order_le_less_trans 2);
  1813 by (res_inst_tac [("y","k")] order_le_less_trans 2);
  1814 by (asm_full_simp_tac (simpset() addsimps [real_zero_less_one]) 3);
  1814 by (asm_full_simp_tac (simpset() addsimps [real_zero_less_one]) 3);
  1815 by (Asm_full_simp_tac 2); 
  1815 by (Asm_full_simp_tac 2); 
  1816 by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> \
  1816 by (subgoal_tac "\\<forall>x. a \\<le> x & x \\<le> b --> \
  1817 \                inverse(k + #1) < inverse((%x. inverse(M - (f x))) x)" 1);
  1817 \                inverse(k + Numeral1) < inverse((%x. inverse(M - (f x))) x)" 1);
  1818 by Safe_tac;
  1818 by Safe_tac;
  1819 by (rtac real_inverse_less_swap 2);
  1819 by (rtac real_inverse_less_swap 2);
  1820 by (ALLGOALS Asm_full_simp_tac);
  1820 by (ALLGOALS Asm_full_simp_tac);
  1821 by (dres_inst_tac [("P", "%N. N<M --> ?Q N"),
  1821 by (dres_inst_tac [("P", "%N. N<M --> ?Q N"),
  1822                    ("x","M - inverse(k + #1)")] spec 1);
  1822                    ("x","M - inverse(k + Numeral1)")] spec 1);
  1823 by (Step_tac 1 THEN dtac real_leI 1);
  1823 by (Step_tac 1 THEN dtac real_leI 1);
  1824 by (dtac (real_le_diff_eq RS iffD1) 1);
  1824 by (dtac (real_le_diff_eq RS iffD1) 1);
  1825 by (REPEAT(dres_inst_tac [("x","a")] spec 1));
  1825 by (REPEAT(dres_inst_tac [("x","a")] spec 1));
  1826 by (Asm_full_simp_tac 1);
  1826 by (Asm_full_simp_tac 1);
  1827 by (asm_full_simp_tac 
  1827 by (asm_full_simp_tac 
  1877 (*----------------------------------------------------------------------------*)
  1877 (*----------------------------------------------------------------------------*)
  1878 (* If f'(x) > 0 then x is locally strictly increasing at the right            *)
  1878 (* If f'(x) > 0 then x is locally strictly increasing at the right            *)
  1879 (*----------------------------------------------------------------------------*)
  1879 (*----------------------------------------------------------------------------*)
  1880 
  1880 
  1881 Goalw [deriv_def,LIM_def] 
  1881 Goalw [deriv_def,LIM_def] 
  1882     "[| DERIV f x :> l;  #0 < l |] ==> \
  1882     "[| DERIV f x :> l;  Numeral0 < l |] ==> \
  1883 \      \\<exists>d. #0 < d & (\\<forall>h. #0 < h & h < d --> f(x) < f(x + h))";
  1883 \      \\<exists>d. Numeral0 < d & (\\<forall>h. Numeral0 < h & h < d --> f(x) < f(x + h))";
  1884 by (dtac spec 1 THEN Auto_tac);
  1884 by (dtac spec 1 THEN Auto_tac);
  1885 by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  1885 by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  1886 by (subgoal_tac "#0 < l*h" 1);
  1886 by (subgoal_tac "Numeral0 < l*h" 1);
  1887 by (asm_full_simp_tac (simpset() addsimps [real_0_less_mult_iff]) 2); 
  1887 by (asm_full_simp_tac (simpset() addsimps [real_0_less_mult_iff]) 2); 
  1888 by (dres_inst_tac [("x","h")] spec 1);
  1888 by (dres_inst_tac [("x","h")] spec 1);
  1889 by (asm_full_simp_tac
  1889 by (asm_full_simp_tac
  1890     (simpset() addsimps [real_abs_def, real_inverse_eq_divide, 
  1890     (simpset() addsimps [real_abs_def, real_inverse_eq_divide, 
  1891                  pos_real_le_divide_eq, pos_real_less_divide_eq]
  1891                  pos_real_le_divide_eq, pos_real_less_divide_eq]
  1892               addsplits [split_if_asm]) 1); 
  1892               addsplits [split_if_asm]) 1); 
  1893 qed "DERIV_left_inc";
  1893 qed "DERIV_left_inc";
  1894 
  1894 
  1895 Goalw [deriv_def,LIM_def] 
  1895 Goalw [deriv_def,LIM_def] 
  1896     "[| DERIV f x :> l;  l < #0 |] ==> \
  1896     "[| DERIV f x :> l;  l < Numeral0 |] ==> \
  1897 \      \\<exists>d. #0 < d & (\\<forall>h. #0 < h & h < d --> f(x) < f(x - h))";
  1897 \      \\<exists>d. Numeral0 < d & (\\<forall>h. Numeral0 < h & h < d --> f(x) < f(x - h))";
  1898 by (dres_inst_tac [("x","-l")] spec 1 THEN Auto_tac);
  1898 by (dres_inst_tac [("x","-l")] spec 1 THEN Auto_tac);
  1899 by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  1899 by (res_inst_tac [("x","s")] exI 1 THEN Auto_tac);
  1900 by (subgoal_tac "l*h < #0" 1);
  1900 by (subgoal_tac "l*h < Numeral0" 1);
  1901 by (asm_full_simp_tac (simpset() addsimps [real_mult_less_0_iff]) 2); 
  1901 by (asm_full_simp_tac (simpset() addsimps [real_mult_less_0_iff]) 2); 
  1902 by (dres_inst_tac [("x","-h")] spec 1);
  1902 by (dres_inst_tac [("x","-h")] spec 1);
  1903 by (asm_full_simp_tac
  1903 by (asm_full_simp_tac
  1904     (simpset() addsimps [real_abs_def, real_inverse_eq_divide, 
  1904     (simpset() addsimps [real_abs_def, real_inverse_eq_divide, 
  1905                          pos_real_less_divide_eq,
  1905                          pos_real_less_divide_eq,
  1906                          symmetric real_diff_def]
  1906                          symmetric real_diff_def]
  1907                addsplits [split_if_asm]) 1);
  1907                addsplits [split_if_asm]) 1);
  1908 by (subgoal_tac "#0 < (f (x - h) - f x)/h" 1);
  1908 by (subgoal_tac "Numeral0 < (f (x - h) - f x)/h" 1);
  1909 by (arith_tac 2);
  1909 by (arith_tac 2);
  1910 by (asm_full_simp_tac
  1910 by (asm_full_simp_tac
  1911     (simpset() addsimps [pos_real_less_divide_eq]) 1); 
  1911     (simpset() addsimps [pos_real_less_divide_eq]) 1); 
  1912 qed "DERIV_left_dec";
  1912 qed "DERIV_left_dec";
  1913 
  1913 
  1914 
  1914 
  1915 Goal "[| DERIV f x :> l; \
  1915 Goal "[| DERIV f x :> l; \
  1916 \        \\<exists>d. #0 < d & (\\<forall>y. abs(x - y) < d --> f(y) \\<le> f(x)) |] \
  1916 \        \\<exists>d. Numeral0 < d & (\\<forall>y. abs(x - y) < d --> f(y) \\<le> f(x)) |] \
  1917 \     ==> l = #0";
  1917 \     ==> l = Numeral0";
  1918 by (res_inst_tac [("R1.0","l"),("R2.0","#0")] real_linear_less2 1);
  1918 by (res_inst_tac [("R1.0","l"),("R2.0","Numeral0")] real_linear_less2 1);
  1919 by Safe_tac;
  1919 by Safe_tac;
  1920 by (dtac DERIV_left_dec 1);
  1920 by (dtac DERIV_left_dec 1);
  1921 by (dtac DERIV_left_inc 3);
  1921 by (dtac DERIV_left_inc 3);
  1922 by Safe_tac;
  1922 by Safe_tac;
  1923 by (dres_inst_tac [("d1.0","d"),("d2.0","da")] real_lbound_gt_zero 1);
  1923 by (dres_inst_tac [("d1.0","d"),("d2.0","da")] real_lbound_gt_zero 1);
  1931 (*----------------------------------------------------------------------------*)
  1931 (*----------------------------------------------------------------------------*)
  1932 (* Similar theorem for a local minimum                                        *)
  1932 (* Similar theorem for a local minimum                                        *)
  1933 (*----------------------------------------------------------------------------*)
  1933 (*----------------------------------------------------------------------------*)
  1934 
  1934 
  1935 Goal "[| DERIV f x :> l; \
  1935 Goal "[| DERIV f x :> l; \
  1936 \        \\<exists>d::real. #0 < d & (\\<forall>y. abs(x - y) < d --> f(x) \\<le> f(y)) |] \
  1936 \        \\<exists>d::real. Numeral0 < d & (\\<forall>y. abs(x - y) < d --> f(x) \\<le> f(y)) |] \
  1937 \     ==> l = #0";
  1937 \     ==> l = Numeral0";
  1938 by (dtac (DERIV_minus RS DERIV_local_max) 1); 
  1938 by (dtac (DERIV_minus RS DERIV_local_max) 1); 
  1939 by Auto_tac;  
  1939 by Auto_tac;  
  1940 qed "DERIV_local_min";
  1940 qed "DERIV_local_min";
  1941 
  1941 
  1942 (*----------------------------------------------------------------------------*)
  1942 (*----------------------------------------------------------------------------*)
  1943 (* In particular if a function is locally flat                                *)
  1943 (* In particular if a function is locally flat                                *)
  1944 (*----------------------------------------------------------------------------*)
  1944 (*----------------------------------------------------------------------------*)
  1945 
  1945 
  1946 Goal "[| DERIV f x :> l; \
  1946 Goal "[| DERIV f x :> l; \
  1947 \        \\<exists>d. #0 < d & (\\<forall>y. abs(x - y) < d --> f(x) = f(y)) |] \
  1947 \        \\<exists>d. Numeral0 < d & (\\<forall>y. abs(x - y) < d --> f(x) = f(y)) |] \
  1948 \     ==> l = #0";
  1948 \     ==> l = Numeral0";
  1949 by (auto_tac (claset() addSDs [DERIV_local_max],simpset()));
  1949 by (auto_tac (claset() addSDs [DERIV_local_max],simpset()));
  1950 qed "DERIV_local_const";
  1950 qed "DERIV_local_const";
  1951 
  1951 
  1952 (*----------------------------------------------------------------------------*)
  1952 (*----------------------------------------------------------------------------*)
  1953 (* Lemma about introducing open ball in open interval                         *)
  1953 (* Lemma about introducing open ball in open interval                         *)
  1954 (*----------------------------------------------------------------------------*)
  1954 (*----------------------------------------------------------------------------*)
  1955 
  1955 
  1956 Goal "[| a < x;  x < b |] ==> \
  1956 Goal "[| a < x;  x < b |] ==> \
  1957 \       \\<exists>d::real. #0 < d &  (\\<forall>y. abs(x - y) < d --> a < y & y < b)";
  1957 \       \\<exists>d::real. Numeral0 < d &  (\\<forall>y. abs(x - y) < d --> a < y & y < b)";
  1958 by (simp_tac (simpset() addsimps [abs_interval_iff]) 1);
  1958 by (simp_tac (simpset() addsimps [abs_interval_iff]) 1);
  1959 by (cut_inst_tac [("x","x - a"),("y","b - x")] linorder_linear 1);
  1959 by (cut_inst_tac [("x","x - a"),("y","b - x")] linorder_linear 1);
  1960 by Safe_tac;
  1960 by Safe_tac;
  1961 by (res_inst_tac [("x","x - a")] exI 1);
  1961 by (res_inst_tac [("x","x - a")] exI 1);
  1962 by (res_inst_tac [("x","b - x")] exI 2);
  1962 by (res_inst_tac [("x","b - x")] exI 2);
  1963 by Auto_tac;
  1963 by Auto_tac;
  1964 by (auto_tac (claset(),simpset() addsimps [real_less_diff_eq]));
  1964 by (auto_tac (claset(),simpset() addsimps [real_less_diff_eq]));
  1965 qed "lemma_interval_lt";
  1965 qed "lemma_interval_lt";
  1966 
  1966 
  1967 Goal "[| a < x;  x < b |] ==> \
  1967 Goal "[| a < x;  x < b |] ==> \
  1968 \       \\<exists>d::real. #0 < d &  (\\<forall>y. abs(x - y) < d --> a \\<le> y & y \\<le> b)";
  1968 \       \\<exists>d::real. Numeral0 < d &  (\\<forall>y. abs(x - y) < d --> a \\<le> y & y \\<le> b)";
  1969 by (dtac lemma_interval_lt 1);
  1969 by (dtac lemma_interval_lt 1);
  1970 by Auto_tac;
  1970 by Auto_tac;
  1971 by (auto_tac (claset() addSIs [exI] ,simpset()));
  1971 by (auto_tac (claset() addSIs [exI] ,simpset()));
  1972 qed "lemma_interval";
  1972 qed "lemma_interval";
  1973 
  1973 
  1974 (*-----------------------------------------------------------------------
  1974 (*-----------------------------------------------------------------------
  1975             Rolle's Theorem
  1975             Rolle's Theorem
  1976    If f is defined and continuous on the finite closed interval [a,b]
  1976    If f is defined and continuous on the finite closed interval [a,b]
  1977    and differentiable a least on the open interval (a,b), and f(a) = f(b),
  1977    and differentiable a least on the open interval (a,b), and f(a) = f(b),
  1978    then x0 \\<in> (a,b) such that f'(x0) = #0
  1978    then x0 \\<in> (a,b) such that f'(x0) = Numeral0
  1979  ----------------------------------------------------------------------*)
  1979  ----------------------------------------------------------------------*)
  1980 
  1980 
  1981 Goal "[| a < b; f(a) = f(b); \
  1981 Goal "[| a < b; f(a) = f(b); \
  1982 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  1982 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  1983 \        \\<forall>x. a < x & x < b --> f differentiable x \
  1983 \        \\<forall>x. a < x & x < b --> f differentiable x \
  1984 \     |] ==> \\<exists>z. a < z & z < b & DERIV f z :> #0";
  1984 \     |] ==> \\<exists>z. a < z & z < b & DERIV f z :> Numeral0";
  1985 by (ftac (order_less_imp_le RS isCont_eq_Ub) 1);
  1985 by (ftac (order_less_imp_le RS isCont_eq_Ub) 1);
  1986 by (EVERY1[assume_tac,Step_tac]);
  1986 by (EVERY1[assume_tac,Step_tac]);
  1987 by (ftac (order_less_imp_le RS isCont_eq_Lb) 1);
  1987 by (ftac (order_less_imp_le RS isCont_eq_Lb) 1);
  1988 by (EVERY1[assume_tac,Step_tac]);
  1988 by (EVERY1[assume_tac,Step_tac]);
  1989 by (case_tac "a < x & x < b" 1 THEN etac conjE 1);
  1989 by (case_tac "a < x & x < b" 1 THEN etac conjE 1);
  1990 by (Asm_full_simp_tac 2);
  1990 by (Asm_full_simp_tac 2);
  1991 by (forw_inst_tac [("a","a"),("x","x")] lemma_interval 1);
  1991 by (forw_inst_tac [("a","a"),("x","x")] lemma_interval 1);
  1992 by (EVERY1[assume_tac,etac exE]);
  1992 by (EVERY1[assume_tac,etac exE]);
  1993 by (res_inst_tac [("x","x")] exI 1 THEN Asm_full_simp_tac 1);
  1993 by (res_inst_tac [("x","x")] exI 1 THEN Asm_full_simp_tac 1);
  1994 by (subgoal_tac "(\\<exists>l. DERIV f x :> l) & \
  1994 by (subgoal_tac "(\\<exists>l. DERIV f x :> l) & \
  1995 \        (\\<exists>d. #0 < d & (\\<forall>y. abs(x - y) < d --> f(y) \\<le> f(x)))" 1);
  1995 \        (\\<exists>d. Numeral0 < d & (\\<forall>y. abs(x - y) < d --> f(y) \\<le> f(x)))" 1);
  1996 by (Clarify_tac 1 THEN rtac conjI 2);
  1996 by (Clarify_tac 1 THEN rtac conjI 2);
  1997 by (blast_tac (claset() addIs [differentiableD]) 2);
  1997 by (blast_tac (claset() addIs [differentiableD]) 2);
  1998 by (Blast_tac 2);
  1998 by (Blast_tac 2);
  1999 by (ftac DERIV_local_max 1);
  1999 by (ftac DERIV_local_max 1);
  2000 by (EVERY1[Blast_tac,Blast_tac]);
  2000 by (EVERY1[Blast_tac,Blast_tac]);
  2002 by (Asm_full_simp_tac 2);
  2002 by (Asm_full_simp_tac 2);
  2003 by (forw_inst_tac [("a","a"),("x","xa")] lemma_interval 1);
  2003 by (forw_inst_tac [("a","a"),("x","xa")] lemma_interval 1);
  2004 by (EVERY1[assume_tac,etac exE]);
  2004 by (EVERY1[assume_tac,etac exE]);
  2005 by (res_inst_tac [("x","xa")] exI 1 THEN Asm_full_simp_tac 1);
  2005 by (res_inst_tac [("x","xa")] exI 1 THEN Asm_full_simp_tac 1);
  2006 by (subgoal_tac "(\\<exists>l. DERIV f xa :> l) & \
  2006 by (subgoal_tac "(\\<exists>l. DERIV f xa :> l) & \
  2007 \        (\\<exists>d. #0 < d & (\\<forall>y. abs(xa - y) < d --> f(xa) \\<le> f(y)))" 1);
  2007 \        (\\<exists>d. Numeral0 < d & (\\<forall>y. abs(xa - y) < d --> f(xa) \\<le> f(y)))" 1);
  2008 by (Clarify_tac 1 THEN rtac conjI 2);
  2008 by (Clarify_tac 1 THEN rtac conjI 2);
  2009 by (blast_tac (claset() addIs [differentiableD]) 2);
  2009 by (blast_tac (claset() addIs [differentiableD]) 2);
  2010 by (Blast_tac 2);
  2010 by (Blast_tac 2);
  2011 by (ftac DERIV_local_min 1);
  2011 by (ftac DERIV_local_min 1);
  2012 by (EVERY1[Blast_tac,Blast_tac]);
  2012 by (EVERY1[Blast_tac,Blast_tac]);
  2028 by (res_inst_tac [("x","r")] exI 1 THEN Asm_full_simp_tac 1);
  2028 by (res_inst_tac [("x","r")] exI 1 THEN Asm_full_simp_tac 1);
  2029 by (etac conjE 1);
  2029 by (etac conjE 1);
  2030 by (forw_inst_tac [("a","a"),("x","r")] lemma_interval 1);
  2030 by (forw_inst_tac [("a","a"),("x","r")] lemma_interval 1);
  2031 by (EVERY1[assume_tac, etac exE]);
  2031 by (EVERY1[assume_tac, etac exE]);
  2032 by (subgoal_tac "(\\<exists>l. DERIV f r :> l) & \
  2032 by (subgoal_tac "(\\<exists>l. DERIV f r :> l) & \
  2033 \        (\\<exists>d. #0 < d & (\\<forall>y. abs(r - y) < d --> f(r) = f(y)))" 1);
  2033 \        (\\<exists>d. Numeral0 < d & (\\<forall>y. abs(r - y) < d --> f(r) = f(y)))" 1);
  2034 by (Clarify_tac 1 THEN rtac conjI 2);
  2034 by (Clarify_tac 1 THEN rtac conjI 2);
  2035 by (blast_tac (claset() addIs [differentiableD]) 2);
  2035 by (blast_tac (claset() addIs [differentiableD]) 2);
  2036 by (EVERY1[ftac DERIV_local_const, Blast_tac, Blast_tac]);
  2036 by (EVERY1[ftac DERIV_local_const, Blast_tac, Blast_tac]);
  2037 by (res_inst_tac [("x","d")] exI 1);
  2037 by (res_inst_tac [("x","d")] exI 1);
  2038 by (EVERY1[rtac conjI, Blast_tac, rtac allI, rtac impI]);
  2038 by (EVERY1[rtac conjI, Blast_tac, rtac allI, rtac impI]);
  2096 (* Theorem that function is constant if its derivative is 0 over an interval. *)
  2096 (* Theorem that function is constant if its derivative is 0 over an interval. *)
  2097 (*----------------------------------------------------------------------------*)
  2097 (*----------------------------------------------------------------------------*)
  2098 
  2098 
  2099 Goal "[| a < b; \
  2099 Goal "[| a < b; \
  2100 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  2100 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  2101 \        \\<forall>x. a < x & x < b --> DERIV f x :> #0 |] \
  2101 \        \\<forall>x. a < x & x < b --> DERIV f x :> Numeral0 |] \
  2102 \       ==> (f b = f a)";
  2102 \       ==> (f b = f a)";
  2103 by (dtac MVT 1 THEN assume_tac 1);
  2103 by (dtac MVT 1 THEN assume_tac 1);
  2104 by (blast_tac (claset() addIs [differentiableI]) 1);
  2104 by (blast_tac (claset() addIs [differentiableI]) 1);
  2105 by (auto_tac (claset() addSDs [DERIV_unique],simpset() 
  2105 by (auto_tac (claset() addSDs [DERIV_unique],simpset() 
  2106     addsimps [real_diff_eq_eq]));
  2106     addsimps [real_diff_eq_eq]));
  2107 qed "DERIV_isconst_end";
  2107 qed "DERIV_isconst_end";
  2108 
  2108 
  2109 Goal "[| a < b; \
  2109 Goal "[| a < b; \
  2110 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  2110 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  2111 \        \\<forall>x. a < x & x < b --> DERIV f x :> #0 |] \
  2111 \        \\<forall>x. a < x & x < b --> DERIV f x :> Numeral0 |] \
  2112 \       ==> \\<forall>x. a \\<le> x & x \\<le> b --> f x = f a";
  2112 \       ==> \\<forall>x. a \\<le> x & x \\<le> b --> f x = f a";
  2113 by Safe_tac;
  2113 by Safe_tac;
  2114 by (dres_inst_tac [("x","a")] order_le_imp_less_or_eq 1);
  2114 by (dres_inst_tac [("x","a")] order_le_imp_less_or_eq 1);
  2115 by Safe_tac;
  2115 by Safe_tac;
  2116 by (dres_inst_tac [("b","x")] DERIV_isconst_end 1);
  2116 by (dres_inst_tac [("b","x")] DERIV_isconst_end 1);
  2117 by Auto_tac;
  2117 by Auto_tac;
  2118 qed "DERIV_isconst1";
  2118 qed "DERIV_isconst1";
  2119 
  2119 
  2120 Goal "[| a < b; \
  2120 Goal "[| a < b; \
  2121 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  2121 \        \\<forall>x. a \\<le> x & x \\<le> b --> isCont f x; \
  2122 \        \\<forall>x. a < x & x < b --> DERIV f x :> #0; \
  2122 \        \\<forall>x. a < x & x < b --> DERIV f x :> Numeral0; \
  2123 \        a \\<le> x; x \\<le> b |] \
  2123 \        a \\<le> x; x \\<le> b |] \
  2124 \       ==> f x = f a";
  2124 \       ==> f x = f a";
  2125 by (blast_tac (claset() addDs [DERIV_isconst1]) 1);
  2125 by (blast_tac (claset() addDs [DERIV_isconst1]) 1);
  2126 qed "DERIV_isconst2";
  2126 qed "DERIV_isconst2";
  2127 
  2127 
  2128 Goal "\\<forall>x. DERIV f x :> #0 ==> f(x) = f(y)";
  2128 Goal "\\<forall>x. DERIV f x :> Numeral0 ==> f(x) = f(y)";
  2129 by (res_inst_tac [("R1.0","x"),("R2.0","y")] real_linear_less2 1);
  2129 by (res_inst_tac [("R1.0","x"),("R2.0","y")] real_linear_less2 1);
  2130 by (rtac sym 1);
  2130 by (rtac sym 1);
  2131 by (auto_tac (claset() addIs [DERIV_isCont,DERIV_isconst_end],simpset()));
  2131 by (auto_tac (claset() addIs [DERIV_isCont,DERIV_isconst_end],simpset()));
  2132 qed "DERIV_isconst_all";
  2132 qed "DERIV_isconst_all";
  2133 
  2133 
  2146 by (res_inst_tac [("c1","b - a")] (real_mult_right_cancel RS iffD1) 1);
  2146 by (res_inst_tac [("c1","b - a")] (real_mult_right_cancel RS iffD1) 1);
  2147 by (auto_tac (claset() addSDs [DERIV_const_ratio_const], 
  2147 by (auto_tac (claset() addSDs [DERIV_const_ratio_const], 
  2148               simpset() addsimps [real_mult_assoc]));
  2148               simpset() addsimps [real_mult_assoc]));
  2149 qed "DERIV_const_ratio_const2";
  2149 qed "DERIV_const_ratio_const2";
  2150 
  2150 
  2151 Goal "((a + b) /#2 - a) = (b - a)/(#2::real)";
  2151 Goal "((a + b) /# 2 - a) = (b - a)/(# 2::real)";
  2152 by Auto_tac;  
  2152 by Auto_tac;  
  2153 qed "real_average_minus_first";
  2153 qed "real_average_minus_first";
  2154 Addsimps [real_average_minus_first];
  2154 Addsimps [real_average_minus_first];
  2155 
  2155 
  2156 Goal "((b + a)/#2 - a) = (b - a)/(#2::real)";
  2156 Goal "((b + a)/# 2 - a) = (b - a)/(# 2::real)";
  2157 by Auto_tac;  
  2157 by Auto_tac;  
  2158 qed "real_average_minus_second";
  2158 qed "real_average_minus_second";
  2159 Addsimps [real_average_minus_second];
  2159 Addsimps [real_average_minus_second];
  2160 
  2160 
  2161 
  2161 
  2162 (* Gallileo's "trick": average velocity = av. of end velocities *)
  2162 (* Gallileo's "trick": average velocity = av. of end velocities *)
  2163 Goal "[|a \\<noteq> (b::real); \\<forall>x. DERIV v x :> k|] \
  2163 Goal "[|a \\<noteq> (b::real); \\<forall>x. DERIV v x :> k|] \
  2164 \     ==> v((a + b)/#2) = (v a + v b)/#2";
  2164 \     ==> v((a + b)/# 2) = (v a + v b)/# 2";
  2165 by (res_inst_tac [("R1.0","a"),("R2.0","b")] real_linear_less2 1);
  2165 by (res_inst_tac [("R1.0","a"),("R2.0","b")] real_linear_less2 1);
  2166 by Auto_tac;
  2166 by Auto_tac;
  2167 by (ftac DERIV_const_ratio_const2 1 THEN assume_tac 1);
  2167 by (ftac DERIV_const_ratio_const2 1 THEN assume_tac 1);
  2168 by (ftac DERIV_const_ratio_const2 2 THEN assume_tac 2);
  2168 by (ftac DERIV_const_ratio_const2 2 THEN assume_tac 2);
  2169 by (dtac real_less_half_sum 1);
  2169 by (dtac real_less_half_sum 1);
  2180 (* ------------------------------------------------------------------------ *)
  2180 (* ------------------------------------------------------------------------ *)
  2181 (* Dull lemma that an continuous injection on an interval must have a strict*)
  2181 (* Dull lemma that an continuous injection on an interval must have a strict*)
  2182 (* maximum at an end point, not in the middle.                              *)
  2182 (* maximum at an end point, not in the middle.                              *)
  2183 (* ------------------------------------------------------------------------ *)
  2183 (* ------------------------------------------------------------------------ *)
  2184 
  2184 
  2185 Goal "[|#0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  2185 Goal "[|Numeral0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  2186 \       \\<forall>z. abs(z - x) \\<le> d --> isCont f z |]  \
  2186 \       \\<forall>z. abs(z - x) \\<le> d --> isCont f z |]  \
  2187 \     ==> ~(\\<forall>z. abs(z - x) \\<le> d --> f(z) \\<le> f(x))";
  2187 \     ==> ~(\\<forall>z. abs(z - x) \\<le> d --> f(z) \\<le> f(x))";
  2188 by (rtac notI 1);
  2188 by (rtac notI 1);
  2189 by (rotate_tac 3 1);
  2189 by (rotate_tac 3 1);
  2190 by (forw_inst_tac [("x","x - d")] spec 1);
  2190 by (forw_inst_tac [("x","x - d")] spec 1);
  2219 
  2219 
  2220 (* ------------------------------------------------------------------------ *)
  2220 (* ------------------------------------------------------------------------ *)
  2221 (* Similar version for lower bound                                          *)
  2221 (* Similar version for lower bound                                          *)
  2222 (* ------------------------------------------------------------------------ *)
  2222 (* ------------------------------------------------------------------------ *)
  2223 
  2223 
  2224 Goal "[|#0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  2224 Goal "[|Numeral0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  2225 \       \\<forall>z. abs(z - x) \\<le> d --> isCont f z |]  \
  2225 \       \\<forall>z. abs(z - x) \\<le> d --> isCont f z |]  \
  2226 \     ==> ~(\\<forall>z. abs(z - x) \\<le> d --> f(x) \\<le> f(z))";
  2226 \     ==> ~(\\<forall>z. abs(z - x) \\<le> d --> f(x) \\<le> f(z))";
  2227 by (auto_tac (claset() addSDs [(asm_full_simplify (simpset()) 
  2227 by (auto_tac (claset() addSDs [(asm_full_simplify (simpset()) 
  2228     (read_instantiate [("f","%x. - f x"),("g","%y. g(-y)"),("x","x"),("d","d")]
  2228     (read_instantiate [("f","%x. - f x"),("g","%y. g(-y)"),("x","x"),("d","d")]
  2229      lemma_isCont_inj))],simpset() addsimps [isCont_minus]));
  2229      lemma_isCont_inj))],simpset() addsimps [isCont_minus]));
  2234 (* Also from John's theory                                                  *)
  2234 (* Also from John's theory                                                  *)
  2235 (* ------------------------------------------------------------------------ *)
  2235 (* ------------------------------------------------------------------------ *)
  2236 
  2236 
  2237 Addsimps [zero_eq_numeral_0,one_eq_numeral_1];
  2237 Addsimps [zero_eq_numeral_0,one_eq_numeral_1];
  2238 
  2238 
  2239 val lemma_le = ARITH_PROVE "#0 \\<le> (d::real) ==> -d \\<le> d";
  2239 val lemma_le = ARITH_PROVE "Numeral0 \\<le> (d::real) ==> -d \\<le> d";
  2240 
  2240 
  2241 (* FIXME: awful proof - needs improvement *)
  2241 (* FIXME: awful proof - needs improvement *)
  2242 Goal "[| #0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  2242 Goal "[| Numeral0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f z) = z; \
  2243 \        \\<forall>z. abs(z - x) \\<le> d --> isCont f z |] \
  2243 \        \\<forall>z. abs(z - x) \\<le> d --> isCont f z |] \
  2244 \      ==> \\<exists>e. #0 < e & \
  2244 \      ==> \\<exists>e. Numeral0 < e & \
  2245 \                 (\\<forall>y. \
  2245 \                 (\\<forall>y. \
  2246 \                     abs(y - f(x)) \\<le> e --> \
  2246 \                     abs(y - f(x)) \\<le> e --> \
  2247 \                     (\\<exists>z. abs(z - x) \\<le> d & (f z = y)))";
  2247 \                     (\\<exists>z. abs(z - x) \\<le> d & (f z = y)))";
  2248 by (ftac order_less_imp_le 1);
  2248 by (ftac order_less_imp_le 1);
  2249 by (dtac (lemma_le RS (asm_full_simplify (simpset()) (read_instantiate 
  2249 by (dtac (lemma_le RS (asm_full_simplify (simpset()) (read_instantiate 
  2253 by (subgoal_tac "L \\<le> f x & f x \\<le> M" 1);
  2253 by (subgoal_tac "L \\<le> f x & f x \\<le> M" 1);
  2254 by (dres_inst_tac [("P", "%v. ?P v --> ?Q v & ?R v"), ("x","x")] spec 2);
  2254 by (dres_inst_tac [("P", "%v. ?P v --> ?Q v & ?R v"), ("x","x")] spec 2);
  2255 by (Asm_full_simp_tac 2);
  2255 by (Asm_full_simp_tac 2);
  2256 by (subgoal_tac "L < f x & f x < M" 1);
  2256 by (subgoal_tac "L < f x & f x < M" 1);
  2257 by Safe_tac;
  2257 by Safe_tac;
  2258 by (dres_inst_tac [("x","L")] (ARITH_PROVE "x < y ==> #0 < y - (x::real)") 1);
  2258 by (dres_inst_tac [("x","L")] (ARITH_PROVE "x < y ==> Numeral0 < y - (x::real)") 1);
  2259 by (dres_inst_tac [("x","f x")] (ARITH_PROVE "x < y ==> #0 < y - (x::real)") 1);
  2259 by (dres_inst_tac [("x","f x")] (ARITH_PROVE "x < y ==> Numeral0 < y - (x::real)") 1);
  2260 by (dres_inst_tac [("d1.0","f x - L"),("d2.0","M - f x")] 
  2260 by (dres_inst_tac [("d1.0","f x - L"),("d2.0","M - f x")] 
  2261     (rename_numerals real_lbound_gt_zero) 1);
  2261     (rename_numerals real_lbound_gt_zero) 1);
  2262 by Safe_tac;
  2262 by Safe_tac;
  2263 by (res_inst_tac [("x","e")] exI 1);
  2263 by (res_inst_tac [("x","e")] exI 1);
  2264 by Safe_tac;
  2264 by Safe_tac;
  2282 
  2282 
  2283 (* ------------------------------------------------------------------------ *)
  2283 (* ------------------------------------------------------------------------ *)
  2284 (* Continuity of inverse function                                           *)
  2284 (* Continuity of inverse function                                           *)
  2285 (* ------------------------------------------------------------------------ *)
  2285 (* ------------------------------------------------------------------------ *)
  2286 
  2286 
  2287 Goal "[| #0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f(z)) = z; \
  2287 Goal "[| Numeral0 < d; \\<forall>z. abs(z - x) \\<le> d --> g(f(z)) = z; \
  2288 \        \\<forall>z. abs(z - x) \\<le> d --> isCont f z |] \
  2288 \        \\<forall>z. abs(z - x) \\<le> d --> isCont f z |] \
  2289 \     ==> isCont g (f x)";
  2289 \     ==> isCont g (f x)";
  2290 by (simp_tac (simpset() addsimps [isCont_iff,LIM_def]) 1);
  2290 by (simp_tac (simpset() addsimps [isCont_iff,LIM_def]) 1);
  2291 by Safe_tac;
  2291 by Safe_tac;
  2292 by (dres_inst_tac [("d1.0","r")] (rename_numerals real_lbound_gt_zero) 1);
  2292 by (dres_inst_tac [("d1.0","r")] (rename_numerals real_lbound_gt_zero) 1);