src/HOL/Hyperreal/Lim.thy
changeset 19023 5652a536b7e8
parent 17318 bc1c75855f3d
child 19765 dfe940911617
equal deleted inserted replaced
19022:0e6ec4fd204c 19023:5652a536b7e8
     1 (*  Title       : Lim.thy
     1 (*  Title       : Lim.thy
     2     ID          : $Id$
     2     ID          : $Id$
     3     Author      : Jacques D. Fleuriot
     3     Author      : Jacques D. Fleuriot
     4     Copyright   : 1998  University of Cambridge
     4     Copyright   : 1998  University of Cambridge
     5     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     5     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
       
     6     GMVT by Benjamin Porter, 2005
     6 *)
     7 *)
     7 
     8 
     8 header{*Limits, Continuity and Differentiation*}
     9 header{*Limits, Continuity and Differentiation*}
     9 
    10 
    10 theory Lim
    11 theory Lim
    13 
    14 
    14 text{*Standard and Nonstandard Definitions*}
    15 text{*Standard and Nonstandard Definitions*}
    15 
    16 
    16 constdefs
    17 constdefs
    17   LIM :: "[real=>real,real,real] => bool"
    18   LIM :: "[real=>real,real,real] => bool"
    18 				("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    19         ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    19   "f -- a --> L ==
    20   "f -- a --> L ==
    20      \<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s
    21      \<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s
    21 			  --> \<bar>f x + -L\<bar> < r"
    22         --> \<bar>f x + -L\<bar> < r"
    22 
    23 
    23   NSLIM :: "[real=>real,real,real] => bool"
    24   NSLIM :: "[real=>real,real,real] => bool"
    24 			      ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    25             ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    25   "f -- a --NS> L == (\<forall>x. (x \<noteq> hypreal_of_real a &
    26   "f -- a --NS> L == (\<forall>x. (x \<noteq> hypreal_of_real a &
    26 		      x @= hypreal_of_real a -->
    27           x @= hypreal_of_real a -->
    27 		      ( *f* f) x @= hypreal_of_real L))"
    28           ( *f* f) x @= hypreal_of_real L))"
    28 
    29 
    29   isCont :: "[real=>real,real] => bool"
    30   isCont :: "[real=>real,real] => bool"
    30   "isCont f a == (f -- a --> (f a))"
    31   "isCont f a == (f -- a --> (f a))"
    31 
    32 
    32   isNSCont :: "[real=>real,real] => bool"
    33   isNSCont :: "[real=>real,real] => bool"
    33     --{*NS definition dispenses with limit notions*}
    34     --{*NS definition dispenses with limit notions*}
    34   "isNSCont f a == (\<forall>y. y @= hypreal_of_real a -->
    35   "isNSCont f a == (\<forall>y. y @= hypreal_of_real a -->
    35 			   ( *f* f) y @= hypreal_of_real (f a))"
    36          ( *f* f) y @= hypreal_of_real (f a))"
    36 
    37 
    37   deriv:: "[real=>real,real,real] => bool"
    38   deriv:: "[real=>real,real,real] => bool"
    38     --{*Differentiation: D is derivative of function f at x*}
    39     --{*Differentiation: D is derivative of function f at x*}
    39 			    ("(DERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
    40           ("(DERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
    40   "DERIV f x :> D == ((%h. (f(x + h) + -f x)/h) -- 0 --> D)"
    41   "DERIV f x :> D == ((%h. (f(x + h) + -f x)/h) -- 0 --> D)"
    41 
    42 
    42   nsderiv :: "[real=>real,real,real] => bool"
    43   nsderiv :: "[real=>real,real,real] => bool"
    43 			    ("(NSDERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
    44           ("(NSDERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
    44   "NSDERIV f x :> D == (\<forall>h \<in> Infinitesimal - {0}.
    45   "NSDERIV f x :> D == (\<forall>h \<in> Infinitesimal - {0}.
    45 			(( *f* f)(hypreal_of_real x + h) +
    46       (( *f* f)(hypreal_of_real x + h) +
    46 			 - hypreal_of_real (f x))/h @= hypreal_of_real D)"
    47        - hypreal_of_real (f x))/h @= hypreal_of_real D)"
    47 
    48 
    48   differentiable :: "[real=>real,real] => bool"   (infixl "differentiable" 60)
    49   differentiable :: "[real=>real,real] => bool"   (infixl "differentiable" 60)
    49   "f differentiable x == (\<exists>D. DERIV f x :> D)"
    50   "f differentiable x == (\<exists>D. DERIV f x :> D)"
    50 
    51 
    51   NSdifferentiable :: "[real=>real,real] => bool"   
    52   NSdifferentiable :: "[real=>real,real] => bool"
    52                        (infixl "NSdifferentiable" 60)
    53                        (infixl "NSdifferentiable" 60)
    53   "f NSdifferentiable x == (\<exists>D. NSDERIV f x :> D)"
    54   "f NSdifferentiable x == (\<exists>D. NSDERIV f x :> D)"
    54 
    55 
    55   increment :: "[real=>real,real,hypreal] => hypreal"
    56   increment :: "[real=>real,real,hypreal] => hypreal"
    56   "increment f x h == (@inc. f NSdifferentiable x &
    57   "increment f x h == (@inc. f NSdifferentiable x &
    57 		       inc = ( *f* f)(hypreal_of_real x + h) + -hypreal_of_real (f x))"
    58            inc = ( *f* f)(hypreal_of_real x + h) + -hypreal_of_real (f x))"
    58 
    59 
    59   isUCont :: "(real=>real) => bool"
    60   isUCont :: "(real=>real) => bool"
    60   "isUCont f ==  \<forall>r > 0. \<exists>s > 0. \<forall>x y. \<bar>x + -y\<bar> < s --> \<bar>f x + -f y\<bar> < r"
    61   "isUCont f ==  \<forall>r > 0. \<exists>s > 0. \<forall>x y. \<bar>x + -y\<bar> < s --> \<bar>f x + -f y\<bar> < r"
    61 
    62 
    62   isNSUCont :: "(real=>real) => bool"
    63   isNSUCont :: "(real=>real) => bool"
   131     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   132     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   132 by (blast dest: LIM_add LIM_minus)
   133 by (blast dest: LIM_add LIM_minus)
   133 
   134 
   134 lemma LIM_diff:
   135 lemma LIM_diff:
   135     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
   136     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
   136 by (simp add: diff_minus LIM_add_minus) 
   137 by (simp add: diff_minus LIM_add_minus)
   137 
   138 
   138 
   139 
   139 lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   140 lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   140 proof (simp add: linorder_neq_iff LIM_eq, elim disjE)
   141 proof (simp add: linorder_neq_iff LIM_eq, elim disjE)
   141   assume k: "k < L"
   142   assume k: "k < L"
   144     show "0 < L-k" by (simp add: k compare_rls)
   145     show "0 < L-k" by (simp add: k compare_rls)
   145     fix s :: real
   146     fix s :: real
   146     assume s: "0<s"
   147     assume s: "0<s"
   147     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   148     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   148      next
   149      next
   149       from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if) 
   150       from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if)
   150      next
   151      next
   151       from s show "~ \<bar>k-L\<bar> < L-k" by (simp add: abs_if) }
   152       from s show "~ \<bar>k-L\<bar> < L-k" by (simp add: abs_if) }
   152   qed
   153   qed
   153 next
   154 next
   154   assume k: "L < k"
   155   assume k: "L < k"
   157     show "0 < k-L" by (simp add: k compare_rls)
   158     show "0 < k-L" by (simp add: k compare_rls)
   158     fix s :: real
   159     fix s :: real
   159     assume s: "0<s"
   160     assume s: "0<s"
   160     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   161     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   161      next
   162      next
   162       from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if) 
   163       from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if)
   163      next
   164      next
   164       from s show "~ \<bar>k-L\<bar> < k-L" by (simp add: abs_if) }
   165       from s show "~ \<bar>k-L\<bar> < k-L" by (simp add: abs_if) }
   165   qed
   166   qed
   166 qed
   167 qed
   167 
   168 
   168 lemma LIM_const_eq: "(%x. k) -- x --> L ==> k = L"
   169 lemma LIM_const_eq: "(%x. k) -- x --> L ==> k = L"
   169 apply (rule ccontr)
   170 apply (rule ccontr)
   170 apply (blast dest: LIM_const_not_eq) 
   171 apply (blast dest: LIM_const_not_eq)
   171 done
   172 done
   172 
   173 
   173 lemma LIM_unique: "[| f -- a --> L; f -- a --> M |] ==> L = M"
   174 lemma LIM_unique: "[| f -- a --> L; f -- a --> M |] ==> L = M"
   174 apply (drule LIM_diff, assumption) 
   175 apply (drule LIM_diff, assumption)
   175 apply (auto dest!: LIM_const_eq)
   176 apply (auto dest!: LIM_const_eq)
   176 done
   177 done
   177 
   178 
   178 lemma LIM_mult_zero:
   179 lemma LIM_mult_zero:
   179   assumes f: "f -- a --> 0" and g: "g -- a --> 0"
   180   assumes f: "f -- a --> 0" and g: "g -- a --> 0"
   196     show "0 < min fs gs"  by (simp add: fs gs)
   197     show "0 < min fs gs"  by (simp add: fs gs)
   197     fix x :: real
   198     fix x :: real
   198     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   199     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   199     with fs_lt gs_lt
   200     with fs_lt gs_lt
   200     have "\<bar>f x\<bar> < 1" and "\<bar>g x\<bar> < r" by (auto simp add: fs_lt)
   201     have "\<bar>f x\<bar> < 1" and "\<bar>g x\<bar> < r" by (auto simp add: fs_lt)
   201     hence "\<bar>f x\<bar> * \<bar>g x\<bar> < 1*r" by (rule abs_mult_less) 
   202     hence "\<bar>f x\<bar> * \<bar>g x\<bar> < 1*r" by (rule abs_mult_less)
   202     thus "\<bar>f x\<bar> * \<bar>g x\<bar> < r" by simp
   203     thus "\<bar>f x\<bar> * \<bar>g x\<bar> < r" by simp
   203   qed
   204   qed
   204 qed
   205 qed
   205 
   206 
   206 lemma LIM_self: "(%x. x) -- a --> a"
   207 lemma LIM_self: "(%x. x) -- a --> a"
   226       "f -- x --> L ==> f -- x --NS> L"
   227       "f -- x --> L ==> f -- x --NS> L"
   227 apply (simp add: LIM_def NSLIM_def approx_def)
   228 apply (simp add: LIM_def NSLIM_def approx_def)
   228 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   229 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   229 apply (rule_tac x = xa in star_cases)
   230 apply (rule_tac x = xa in star_cases)
   230 apply (auto simp add: real_add_minus_iff starfun star_n_minus star_of_def star_n_add star_n_eq_iff)
   231 apply (auto simp add: real_add_minus_iff starfun star_n_minus star_of_def star_n_add star_n_eq_iff)
   231 apply (rule bexI [OF _ Rep_star_star_n], clarify) 
   232 apply (rule bexI [OF _ Rep_star_star_n], clarify)
   232 apply (drule_tac x = u in spec, clarify)
   233 apply (drule_tac x = u in spec, clarify)
   233 apply (drule_tac x = s in spec, clarify)
   234 apply (drule_tac x = s in spec, clarify)
   234 apply (subgoal_tac "\<forall>n::nat. (Xa n) \<noteq> x & \<bar>(Xa n) + - x\<bar> < s --> \<bar>f (Xa n) + - L\<bar> < u")
   235 apply (subgoal_tac "\<forall>n::nat. (Xa n) \<noteq> x & \<bar>(Xa n) + - x\<bar> < s --> \<bar>f (Xa n) + - L\<bar> < u")
   235 prefer 2 apply blast
   236 prefer 2 apply blast
   236 apply (drule FreeUltrafilterNat_all, ultra)
   237 apply (drule FreeUltrafilterNat_all, ultra)
   592 done
   593 done
   593 
   594 
   594 lemma lemma_LIMu: "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s & r \<le> \<bar>f z + -f y\<bar>
   595 lemma lemma_LIMu: "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s & r \<le> \<bar>f z + -f y\<bar>
   595       ==> \<forall>n::nat. \<exists>z y. \<bar>z + -y\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f z + -f y\<bar>"
   596       ==> \<forall>n::nat. \<exists>z y. \<bar>z + -y\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f z + -f y\<bar>"
   596 apply clarify
   597 apply clarify
   597 apply (cut_tac n1 = n 
   598 apply (cut_tac n1 = n
   598        in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   599        in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   599 done
   600 done
   600 
   601 
   601 lemma lemma_skolemize_LIM2u:
   602 lemma lemma_skolemize_LIM2u:
   602      "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s  & r \<le> \<bar>f z + -f y\<bar>
   603      "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s  & r \<le> \<bar>f z + -f y\<bar>
   770 apply (drule_tac x = u in spec, auto)
   771 apply (drule_tac x = u in spec, auto)
   771 apply (drule_tac c = "u - hypreal_of_real x" and b = "hypreal_of_real D" in approx_mult1)
   772 apply (drule_tac c = "u - hypreal_of_real x" and b = "hypreal_of_real D" in approx_mult1)
   772 apply (drule_tac [!] hypreal_not_eq_minus_iff [THEN iffD1])
   773 apply (drule_tac [!] hypreal_not_eq_minus_iff [THEN iffD1])
   773 apply (subgoal_tac [2] "( *f* (%z. z-x)) u \<noteq> (0::hypreal) ")
   774 apply (subgoal_tac [2] "( *f* (%z. z-x)) u \<noteq> (0::hypreal) ")
   774 apply (auto simp add: diff_minus
   775 apply (auto simp add: diff_minus
   775 	       approx_minus_iff [THEN iffD1, THEN mem_infmal_iff [THEN iffD2]]
   776          approx_minus_iff [THEN iffD1, THEN mem_infmal_iff [THEN iffD2]]
   776 		     Infinitesimal_subset_HFinite [THEN subsetD])
   777          Infinitesimal_subset_HFinite [THEN subsetD])
   777 done
   778 done
   778 
   779 
   779 lemma NSDERIVD4:
   780 lemma NSDERIVD4:
   780      "(NSDERIV f x :> D) ==>
   781      "(NSDERIV f x :> D) ==>
   781       (\<forall>h \<in> Infinitesimal.
   782       (\<forall>h \<in> Infinitesimal.
   879 
   880 
   880 lemma NSDERIV_mult: "[| NSDERIV f x :> Da; NSDERIV g x :> Db |]
   881 lemma NSDERIV_mult: "[| NSDERIV f x :> Da; NSDERIV g x :> Db |]
   881       ==> NSDERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))"
   882       ==> NSDERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))"
   882 apply (auto simp add: NSDERIV_NSLIM_iff NSLIM_def)
   883 apply (auto simp add: NSDERIV_NSLIM_iff NSLIM_def)
   883 apply (auto dest!: spec
   884 apply (auto dest!: spec
   884 	    simp add: starfun_lambda_cancel lemma_nsderiv1)
   885       simp add: starfun_lambda_cancel lemma_nsderiv1)
   885 apply (simp (no_asm) add: add_divide_distrib)
   886 apply (simp (no_asm) add: add_divide_distrib)
   886 apply (drule bex_Infinitesimal_iff2 [THEN iffD2])+
   887 apply (drule bex_Infinitesimal_iff2 [THEN iffD2])+
   887 apply (auto simp add: times_divide_eq_right [symmetric]
   888 apply (auto simp add: times_divide_eq_right [symmetric]
   888             simp del: times_divide_eq)
   889             simp del: times_divide_eq)
   889 apply (drule_tac D = Db in lemma_nsderiv2)
   890 apply (drule_tac D = Db in lemma_nsderiv2)
  1328 apply (rule allI)
  1329 apply (rule allI)
  1329 apply (induct_tac "n")
  1330 apply (induct_tac "n")
  1330 apply (auto simp add: Bolzano_bisect_le Let_def split_def)
  1331 apply (auto simp add: Bolzano_bisect_le Let_def split_def)
  1331 done
  1332 done
  1332 
  1333 
  1333 lemma eq_divide_2_times_iff: "((x::real) = y / (2 * z)) = (2 * x = y/z)" 
  1334 lemma eq_divide_2_times_iff: "((x::real) = y / (2 * z)) = (2 * x = y/z)"
  1334 apply (auto)
  1335 apply (auto)
  1335 apply (drule_tac f = "%u. (1/2) *u" in arg_cong)
  1336 apply (drule_tac f = "%u. (1/2) *u" in arg_cong)
  1336 apply (simp)
  1337 apply (simp)
  1337 done
  1338 done
  1338 
  1339 
  1496 by (blast intro: reals_complete)
  1497 by (blast intro: reals_complete)
  1497 
  1498 
  1498 lemma isCont_has_Ub: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1499 lemma isCont_has_Ub: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1499          ==> \<exists>M. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  1500          ==> \<exists>M. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  1500                    (\<forall>N. N < M --> (\<exists>x. a \<le> x & x \<le> b & N < f(x)))"
  1501                    (\<forall>N. N < M --> (\<exists>x. a \<le> x & x \<le> b & N < f(x)))"
  1501 apply (cut_tac S = "Collect (%y. \<exists>x. a \<le> x & x \<le> b & y = f x)" 
  1502 apply (cut_tac S = "Collect (%y. \<exists>x. a \<le> x & x \<le> b & y = f x)"
  1502         in lemma_reals_complete)
  1503         in lemma_reals_complete)
  1503 apply auto
  1504 apply auto
  1504 apply (drule isCont_bounded, assumption)
  1505 apply (drule isCont_bounded, assumption)
  1505 apply (auto simp add: isUb_def leastP_def isLub_def setge_def setle_def)
  1506 apply (auto simp add: isUb_def leastP_def isLub_def setge_def setle_def)
  1506 apply (rule exI, auto)
  1507 apply (rule exI, auto)
  1599     show "0<s" .
  1600     show "0<s" .
  1600     fix h::real
  1601     fix h::real
  1601     assume "0 < h" "h < s"
  1602     assume "0 < h" "h < s"
  1602     with all [of h] show "f x < f (x+h)"
  1603     with all [of h] show "f x < f (x+h)"
  1603     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1604     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1604 		split add: split_if_asm)
  1605     split add: split_if_asm)
  1605       assume "~ (f (x+h) - f x) / h < l" and h: "0 < h"
  1606       assume "~ (f (x+h) - f x) / h < l" and h: "0 < h"
  1606       with l
  1607       with l
  1607       have "0 < (f (x+h) - f x) / h" by arith
  1608       have "0 < (f (x+h) - f x) / h" by arith
  1608       thus "f x < f (x+h)"
  1609       thus "f x < f (x+h)"
  1609 	by (simp add: pos_less_divide_eq h)
  1610   by (simp add: pos_less_divide_eq h)
  1610     qed
  1611     qed
  1611   qed
  1612   qed
  1612 qed
  1613 qed
  1613 
  1614 
  1614 lemma DERIV_left_dec:
  1615 lemma DERIV_left_dec:
  1628     show "0<s" .
  1629     show "0<s" .
  1629     fix h::real
  1630     fix h::real
  1630     assume "0 < h" "h < s"
  1631     assume "0 < h" "h < s"
  1631     with all [of "-h"] show "f x < f (x-h)"
  1632     with all [of "-h"] show "f x < f (x-h)"
  1632     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1633     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1633 		split add: split_if_asm)
  1634     split add: split_if_asm)
  1634       assume " - ((f (x-h) - f x) / h) < l" and h: "0 < h"
  1635       assume " - ((f (x-h) - f x) / h) < l" and h: "0 < h"
  1635       with l
  1636       with l
  1636       have "0 < (f (x-h) - f x) / h" by arith
  1637       have "0 < (f (x-h) - f x) / h" by arith
  1637       thus "f x < f (x-h)"
  1638       thus "f x < f (x-h)"
  1638 	by (simp add: pos_less_divide_eq h)
  1639   by (simp add: pos_less_divide_eq h)
  1639     qed
  1640     qed
  1640   qed
  1641   qed
  1641 qed
  1642 qed
  1642 
  1643 
  1643 lemma DERIV_local_max:
  1644 lemma DERIV_local_max:
  1740       assume ax'b: "a < x' & x' < b"
  1741       assume ax'b: "a < x' & x' < b"
  1741         --{*@{term f} attains its minimum within the interval*}
  1742         --{*@{term f} attains its minimum within the interval*}
  1742       hence ax': "a<x'" and x'b: "x'<b" by auto
  1743       hence ax': "a<x'" and x'b: "x'<b" by auto
  1743       from lemma_interval [OF ax' x'b]
  1744       from lemma_interval [OF ax' x'b]
  1744       obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1745       obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1745 	by blast
  1746   by blast
  1746       hence bound': "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> f x' \<le> f y" using x'_min
  1747       hence bound': "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> f x' \<le> f y" using x'_min
  1747 	by blast
  1748   by blast
  1748       from differentiableD [OF dif [OF ax'b]]
  1749       from differentiableD [OF dif [OF ax'b]]
  1749       obtain l where der: "DERIV f x' :> l" ..
  1750       obtain l where der: "DERIV f x' :> l" ..
  1750       have "l=0" by (rule DERIV_local_min [OF der d bound'])
  1751       have "l=0" by (rule DERIV_local_min [OF der d bound'])
  1751         --{*the derivative at a local minimum is zero*}
  1752         --{*the derivative at a local minimum is zero*}
  1752       thus ?thesis using ax' x'b der by auto
  1753       thus ?thesis using ax' x'b der by auto
  1757       hence fb_eq_fx': "f b = f x'" by (auto simp add: eq)
  1758       hence fb_eq_fx': "f b = f x'" by (auto simp add: eq)
  1758       from dense [OF lt]
  1759       from dense [OF lt]
  1759       obtain r where ar: "a < r" and rb: "r < b" by blast
  1760       obtain r where ar: "a < r" and rb: "r < b" by blast
  1760       from lemma_interval [OF ar rb]
  1761       from lemma_interval [OF ar rb]
  1761       obtain d where d: "0<d" and bound: "\<forall>y. \<bar>r-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1762       obtain d where d: "0<d" and bound: "\<forall>y. \<bar>r-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1762 	by blast
  1763   by blast
  1763       have eq_fb: "\<forall>z. a \<le> z --> z \<le> b --> f z = f b"
  1764       have eq_fb: "\<forall>z. a \<le> z --> z \<le> b --> f z = f b"
  1764       proof (clarify)
  1765       proof (clarify)
  1765         fix z::real
  1766         fix z::real
  1766         assume az: "a \<le> z" and zb: "z \<le> b"
  1767         assume az: "a \<le> z" and zb: "z \<le> b"
  1767         show "f z = f b"
  1768         show "f z = f b"
  1796 next
  1797 next
  1797   assume "a\<noteq>b"
  1798   assume "a\<noteq>b"
  1798   hence ba: "b-a \<noteq> 0" by arith
  1799   hence ba: "b-a \<noteq> 0" by arith
  1799   show ?thesis
  1800   show ?thesis
  1800     by (rule real_mult_left_cancel [OF ba, THEN iffD1],
  1801     by (rule real_mult_left_cancel [OF ba, THEN iffD1],
  1801         simp add: right_diff_distrib, 
  1802         simp add: right_diff_distrib,
  1802         simp add: left_diff_distrib)
  1803         simp add: left_diff_distrib)
  1803 qed
  1804 qed
  1804 
  1805 
  1805 theorem MVT:
  1806 theorem MVT:
  1806   assumes lt:  "a < b"
  1807   assumes lt:  "a < b"
  1886 apply (rule_tac c1 = "b-a" in real_mult_right_cancel [THEN iffD1])
  1887 apply (rule_tac c1 = "b-a" in real_mult_right_cancel [THEN iffD1])
  1887 apply (auto dest!: DERIV_const_ratio_const simp add: mult_assoc)
  1888 apply (auto dest!: DERIV_const_ratio_const simp add: mult_assoc)
  1888 done
  1889 done
  1889 
  1890 
  1890 lemma real_average_minus_first [simp]: "((a + b) /2 - a) = (b-a)/(2::real)"
  1891 lemma real_average_minus_first [simp]: "((a + b) /2 - a) = (b-a)/(2::real)"
  1891 by (simp) 
  1892 by (simp)
  1892 
  1893 
  1893 lemma real_average_minus_second [simp]: "((b + a)/2 - a) = (b-a)/(2::real)"
  1894 lemma real_average_minus_second [simp]: "((b + a)/2 - a) = (b-a)/(2::real)"
  1894 by (simp) 
  1895 by (simp)
  1895 
  1896 
  1896 text{*Gallileo's "trick": average velocity = av. of end velocities*}
  1897 text{*Gallileo's "trick": average velocity = av. of end velocities*}
  1897 
  1898 
  1898 lemma DERIV_const_average:
  1899 lemma DERIV_const_average:
  1899   assumes neq: "a \<noteq> (b::real)"
  1900   assumes neq: "a \<noteq> (b::real)"
  2057         show "\<bar>g (f x + z) - g (f x)\<bar> < r" by force
  2058         show "\<bar>g (f x + z) - g (f x)\<bar> < r" by force
  2058       qed
  2059       qed
  2059     qed
  2060     qed
  2060   qed
  2061   qed
  2061 qed
  2062 qed
       
  2063 
       
  2064 
       
  2065 lemma differentiable_const: "(\<lambda>z. a) differentiable x"
       
  2066   apply (unfold differentiable_def)
       
  2067   apply (rule_tac x=0 in exI)
       
  2068   apply simp
       
  2069   done
       
  2070 
       
  2071 lemma differentiable_sum:
       
  2072   assumes "f differentiable x"
       
  2073   and "g differentiable x"
       
  2074   shows "(\<lambda>x. f x + g x) differentiable x"
       
  2075 proof -
       
  2076   from prems have "\<exists>D. DERIV f x :> D" by (unfold differentiable_def)
       
  2077   then obtain df where "DERIV f x :> df" ..
       
  2078   moreover from prems have "\<exists>D. DERIV g x :> D" by (unfold differentiable_def)
       
  2079   then obtain dg where "DERIV g x :> dg" ..
       
  2080   ultimately have "DERIV (\<lambda>x. f x + g x) x :> df + dg" by (rule DERIV_add)
       
  2081   hence "\<exists>D. DERIV (\<lambda>x. f x + g x) x :> D" by auto
       
  2082   thus ?thesis by (fold differentiable_def)
       
  2083 qed
       
  2084 
       
  2085 lemma differentiable_diff:
       
  2086   assumes "f differentiable x"
       
  2087   and "g differentiable x"
       
  2088   shows "(\<lambda>x. f x - g x) differentiable x"
       
  2089 proof -
       
  2090   from prems have "f differentiable x" by simp
       
  2091   moreover
       
  2092   from prems have "\<exists>D. DERIV g x :> D" by (unfold differentiable_def)
       
  2093   then obtain dg where "DERIV g x :> dg" ..
       
  2094   then have "DERIV (\<lambda>x. - g x) x :> -dg" by (rule DERIV_minus)
       
  2095   hence "\<exists>D. DERIV (\<lambda>x. - g x) x :> D" by auto
       
  2096   hence "(\<lambda>x. - g x) differentiable x" by (fold differentiable_def)
       
  2097   ultimately 
       
  2098   show ?thesis
       
  2099     by (auto simp: real_diff_def dest: differentiable_sum)
       
  2100 qed
       
  2101 
       
  2102 lemma differentiable_mult:
       
  2103   assumes "f differentiable x"
       
  2104   and "g differentiable x"
       
  2105   shows "(\<lambda>x. f x * g x) differentiable x"
       
  2106 proof -
       
  2107   from prems have "\<exists>D. DERIV f x :> D" by (unfold differentiable_def)
       
  2108   then obtain df where "DERIV f x :> df" ..
       
  2109   moreover from prems have "\<exists>D. DERIV g x :> D" by (unfold differentiable_def)
       
  2110   then obtain dg where "DERIV g x :> dg" ..
       
  2111   ultimately have "DERIV (\<lambda>x. f x * g x) x :> df * g x + dg * f x" by (simp add: DERIV_mult)
       
  2112   hence "\<exists>D. DERIV (\<lambda>x. f x * g x) x :> D" by auto
       
  2113   thus ?thesis by (fold differentiable_def)
       
  2114 qed
       
  2115 
       
  2116 
       
  2117 theorem GMVT:
       
  2118   assumes alb: "a < b"
       
  2119   and fc: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont f x"
       
  2120   and fd: "\<forall>x. a < x \<and> x < b \<longrightarrow> f differentiable x"
       
  2121   and gc: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont g x"
       
  2122   and gd: "\<forall>x. a < x \<and> x < b \<longrightarrow> g differentiable x"
       
  2123   shows "\<exists>g'c f'c c. DERIV g c :> g'c \<and> DERIV f c :> f'c \<and> a < c \<and> c < b \<and> ((f b - f a) * g'c) = ((g b - g a) * f'c)"
       
  2124 proof -
       
  2125   let ?h = "\<lambda>x. (f b - f a)*(g x) - (g b - g a)*(f x)"
       
  2126   from prems have "a < b" by simp
       
  2127   moreover have "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont ?h x"
       
  2128   proof -
       
  2129     have "\<forall>x. a <= x \<and> x <= b \<longrightarrow> isCont (\<lambda>x. f b - f a) x" by simp
       
  2130     with gc have "\<forall>x. a <= x \<and> x <= b \<longrightarrow> isCont (\<lambda>x. (f b - f a) * g x) x"
       
  2131       by (auto intro: isCont_mult)
       
  2132     moreover
       
  2133     have "\<forall>x. a <= x \<and> x <= b \<longrightarrow> isCont (\<lambda>x. g b - g a) x" by simp
       
  2134     with fc have "\<forall>x. a <= x \<and> x <= b \<longrightarrow> isCont (\<lambda>x. (g b - g a) * f x) x"
       
  2135       by (auto intro: isCont_mult)
       
  2136     ultimately show ?thesis
       
  2137       by (fastsimp intro: isCont_diff)
       
  2138   qed
       
  2139   moreover
       
  2140   have "\<forall>x. a < x \<and> x < b \<longrightarrow> ?h differentiable x"
       
  2141   proof -
       
  2142     have "\<forall>x. a < x \<and> x < b \<longrightarrow> (\<lambda>x. f b - f a) differentiable x" by (simp add: differentiable_const)
       
  2143     with gd have "\<forall>x. a < x \<and> x < b \<longrightarrow> (\<lambda>x. (f b - f a) * g x) differentiable x" by (simp add: differentiable_mult)
       
  2144     moreover
       
  2145     have "\<forall>x. a < x \<and> x < b \<longrightarrow> (\<lambda>x. g b - g a) differentiable x" by (simp add: differentiable_const)
       
  2146     with fd have "\<forall>x. a < x \<and> x < b \<longrightarrow> (\<lambda>x. (g b - g a) * f x) differentiable x" by (simp add: differentiable_mult)
       
  2147     ultimately show ?thesis by (simp add: differentiable_diff)
       
  2148   qed
       
  2149   ultimately have "\<exists>l z. a < z \<and> z < b \<and> DERIV ?h z :> l \<and> ?h b - ?h a = (b - a) * l" by (rule MVT)
       
  2150   then obtain l where ldef: "\<exists>z. a < z \<and> z < b \<and> DERIV ?h z :> l \<and> ?h b - ?h a = (b - a) * l" ..
       
  2151   then obtain c where cdef: "a < c \<and> c < b \<and> DERIV ?h c :> l \<and> ?h b - ?h a = (b - a) * l" ..
       
  2152 
       
  2153   from cdef have cint: "a < c \<and> c < b" by auto
       
  2154   with gd have "g differentiable c" by simp
       
  2155   hence "\<exists>D. DERIV g c :> D" by (rule differentiableD)
       
  2156   then obtain g'c where g'cdef: "DERIV g c :> g'c" ..
       
  2157 
       
  2158   from cdef have "a < c \<and> c < b" by auto
       
  2159   with fd have "f differentiable c" by simp
       
  2160   hence "\<exists>D. DERIV f c :> D" by (rule differentiableD)
       
  2161   then obtain f'c where f'cdef: "DERIV f c :> f'c" ..
       
  2162 
       
  2163   from cdef have "DERIV ?h c :> l" by auto
       
  2164   moreover
       
  2165   {
       
  2166     from g'cdef have "DERIV (\<lambda>x. (f b - f a) * g x) c :> g'c * (f b - f a)"
       
  2167       apply (insert DERIV_const [where k="f b - f a"])
       
  2168       apply (drule meta_spec [of _ c])
       
  2169       apply (drule DERIV_mult [where f="(\<lambda>x. f b - f a)" and g=g])
       
  2170       by simp_all
       
  2171     moreover from f'cdef have "DERIV (\<lambda>x. (g b - g a) * f x) c :> f'c * (g b - g a)"
       
  2172       apply (insert DERIV_const [where k="g b - g a"])
       
  2173       apply (drule meta_spec [of _ c])
       
  2174       apply (drule DERIV_mult [where f="(\<lambda>x. g b - g a)" and g=f])
       
  2175       by simp_all
       
  2176     ultimately have "DERIV ?h c :>  g'c * (f b - f a) - f'c * (g b - g a)"
       
  2177       by (simp add: DERIV_diff)
       
  2178   }
       
  2179   ultimately have leq: "l =  g'c * (f b - f a) - f'c * (g b - g a)" by (rule DERIV_unique)
       
  2180 
       
  2181   {
       
  2182     from cdef have "?h b - ?h a = (b - a) * l" by auto
       
  2183     also with leq have "\<dots> = (b - a) * (g'c * (f b - f a) - f'c * (g b - g a))" by simp
       
  2184     finally have "?h b - ?h a = (b - a) * (g'c * (f b - f a) - f'c * (g b - g a))" by simp
       
  2185   }
       
  2186   moreover
       
  2187   {
       
  2188     have "?h b - ?h a =
       
  2189          ((f b)*(g b) - (f a)*(g b) - (g b)*(f b) + (g a)*(f b)) -
       
  2190           ((f b)*(g a) - (f a)*(g a) - (g b)*(f a) + (g a)*(f a))"
       
  2191       by (simp add: mult_ac add_ac real_diff_mult_distrib)
       
  2192     hence "?h b - ?h a = 0" by auto
       
  2193   }
       
  2194   ultimately have "(b - a) * (g'c * (f b - f a) - f'c * (g b - g a)) = 0" by auto
       
  2195   with alb have "g'c * (f b - f a) - f'c * (g b - g a) = 0" by simp
       
  2196   hence "g'c * (f b - f a) = f'c * (g b - g a)" by simp
       
  2197   hence "(f b - f a) * g'c = (g b - g a) * f'c" by (simp add: mult_ac)
       
  2198 
       
  2199   with g'cdef f'cdef cint show ?thesis by auto
       
  2200 qed
       
  2201 
       
  2202 
       
  2203 lemma LIMSEQ_SEQ_conv1:
       
  2204   assumes "X -- a --> L"
       
  2205   shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
       
  2206 proof -
       
  2207   {
       
  2208     from prems have Xdef: "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> \<bar>X x + -L\<bar> < r" by (unfold LIM_def)
       
  2209     
       
  2210     fix S
       
  2211     assume as: "(\<forall>n. S n \<noteq> a) \<and> S ----> a"
       
  2212     then have "S ----> a" by auto
       
  2213     then have Sdef: "(\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> \<bar>S n + -a\<bar> < r))" by (unfold LIMSEQ_def)
       
  2214     {
       
  2215       fix r
       
  2216       from Xdef have Xdef2: "0 < r --> (\<exists>s > 0. \<forall>x. x \<noteq> a \<and> \<bar>x + -a\<bar> < s --> \<bar>X x + -L\<bar> < r)" by simp
       
  2217       {
       
  2218         assume rgz: "0 < r"
       
  2219 
       
  2220         from Xdef2 rgz have "\<exists>s > 0. \<forall>x. x \<noteq> a \<and> \<bar>x + -a\<bar> < s --> \<bar>X x + -L\<bar> < r" by simp 
       
  2221         then obtain s where sdef: "s > 0 \<and> (\<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s \<longrightarrow> \<bar>X x + -L\<bar> < r)" by auto
       
  2222         then have aux: "\<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s \<longrightarrow> \<bar>X x + -L\<bar> < r" by auto
       
  2223         {
       
  2224           fix n
       
  2225           from aux have "S n \<noteq> a \<and> \<bar>S n + -a\<bar> < s \<longrightarrow> \<bar>X (S n) + -L\<bar> < r" by simp
       
  2226           with as have imp2: "\<bar>S n + -a\<bar> < s --> \<bar>X (S n) + -L\<bar> < r" by auto
       
  2227         }
       
  2228         hence "\<forall>n. \<bar>S n + -a\<bar> < s --> \<bar>X (S n) + -L\<bar> < r" ..
       
  2229         moreover
       
  2230         from Sdef sdef have imp1: "\<exists>no. \<forall>n. no \<le> n --> \<bar>S n + -a\<bar> < s" by auto  
       
  2231         then obtain no where "\<forall>n. no \<le> n --> \<bar>S n + -a\<bar> < s" by auto
       
  2232         ultimately have "\<forall>n. no \<le> n \<longrightarrow> \<bar>X (S n) + -L\<bar> < r" by simp
       
  2233         hence "\<exists>no. \<forall>n. no \<le> n \<longrightarrow> \<bar>X (S n) + -L\<bar> < r" by auto
       
  2234       }
       
  2235     }
       
  2236     hence "(\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> \<bar>X (S n) + -L\<bar> < r))" by simp
       
  2237     hence "(\<lambda>n. X (S n)) ----> L" by (fold LIMSEQ_def)
       
  2238   }
       
  2239   thus ?thesis by simp
       
  2240 qed
       
  2241 
       
  2242 lemma LIMSEQ_SEQ_conv2:
       
  2243   assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
       
  2244   shows "X -- a --> L"
       
  2245 proof (rule ccontr)
       
  2246   assume "\<not> (X -- a --> L)"
       
  2247   hence "\<not> (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> \<bar>X x + -L\<bar> < r)" by (unfold LIM_def)
       
  2248   hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. \<not>(x \<noteq> a \<and> \<bar>x + -a\<bar> < s --> \<bar>X x + -L\<bar> < r)" by simp
       
  2249   hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x + -a\<bar> < s \<and> \<bar>X x + -L\<bar> \<ge> r)" by (simp add: linorder_not_less)
       
  2250   then obtain r where rdef: "r > 0 \<and> (\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x + -a\<bar> < s \<and> \<bar>X x + -L\<bar> \<ge> r))" by auto
       
  2251 
       
  2252   let ?F = "\<lambda>n::nat. SOME x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X x + -L\<bar> \<ge> r"
       
  2253   have "?F ----> a"
       
  2254   proof -
       
  2255     {
       
  2256       fix e::real
       
  2257       assume "0 < e"
       
  2258         (* choose no such that inverse (real (Suc n)) < e *)
       
  2259       have "\<exists>no. inverse (real (Suc no)) < e" by (rule reals_Archimedean)
       
  2260       then obtain m where nodef: "inverse (real (Suc m)) < e" by auto
       
  2261       {
       
  2262         fix n
       
  2263         assume mlen: "m \<le> n"
       
  2264         then have
       
  2265           "inverse (real (Suc n)) \<le> inverse (real (Suc m))"
       
  2266           by auto
       
  2267         moreover have
       
  2268           "\<bar>?F n + -a\<bar> < inverse (real (Suc n))"
       
  2269         proof -
       
  2270           from rdef have
       
  2271             "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X x + -L\<bar> \<ge> r"
       
  2272             by simp
       
  2273           hence
       
  2274             "(?F n)\<noteq>a \<and> \<bar>(?F n) + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X (?F n) + -L\<bar> \<ge> r"
       
  2275             by (simp add: some_eq_ex [symmetric])
       
  2276           thus ?thesis by simp
       
  2277         qed
       
  2278         moreover from nodef have
       
  2279           "inverse (real (Suc m)) < e" .
       
  2280         ultimately have "\<bar>?F n + -a\<bar> < e" by arith
       
  2281       }
       
  2282       then have "\<exists>no. \<forall>n. no \<le> n --> \<bar>?F n + -a\<bar> < e" by auto
       
  2283     }
       
  2284     thus ?thesis by (unfold LIMSEQ_def, simp)
       
  2285   qed
       
  2286   
       
  2287   moreover have "\<forall>n. ?F n \<noteq> a"
       
  2288   proof -
       
  2289     {
       
  2290       fix n
       
  2291       from rdef have
       
  2292         "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X x + -L\<bar> \<ge> r"
       
  2293         by simp
       
  2294       hence "?F n \<noteq> a" by (simp add: some_eq_ex [symmetric])
       
  2295     }
       
  2296     thus ?thesis ..
       
  2297   qed
       
  2298   moreover from prems have "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by simp
       
  2299   ultimately have "(\<lambda>n. X (?F n)) ----> L" by simp
       
  2300   
       
  2301   moreover have "\<not> ((\<lambda>n. X (?F n)) ----> L)"
       
  2302   proof -
       
  2303     {
       
  2304       fix no::nat
       
  2305       obtain n where "n = no + 1" by simp
       
  2306       then have nolen: "no \<le> n" by simp
       
  2307         (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
       
  2308       from rdef have "\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x + -a\<bar> < s \<and> \<bar>X x + -L\<bar> \<ge> r)" ..
       
  2309 
       
  2310       then have "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X x + -L\<bar> \<ge> r" by simp
       
  2311       
       
  2312       hence "\<bar>X (?F n) + -L\<bar> \<ge> r" by (simp add: some_eq_ex [symmetric])
       
  2313       with nolen have "\<exists>n. no \<le> n \<and> \<bar>X (?F n) + -L\<bar> \<ge> r" by auto
       
  2314     }
       
  2315     then have "(\<forall>no. \<exists>n. no \<le> n \<and> \<bar>X (?F n) + -L\<bar> \<ge> r)" by simp
       
  2316     with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> \<bar>X (?F n) + -L\<bar> \<ge> e)" by auto
       
  2317     thus ?thesis by (unfold LIMSEQ_def, auto simp add: linorder_not_less)
       
  2318   qed
       
  2319   ultimately show False by simp
       
  2320 qed
       
  2321 
       
  2322 
       
  2323 lemma LIMSEQ_SEQ_conv:
       
  2324   "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L) = (X -- a --> L)"
       
  2325 proof
       
  2326   assume "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
       
  2327   show "X -- a --> L" by (rule LIMSEQ_SEQ_conv2)
       
  2328 next
       
  2329   assume "(X -- a --> L)"
       
  2330   show "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by (rule LIMSEQ_SEQ_conv1)
       
  2331 qed
       
  2332 
       
  2333 lemma real_sqz:
       
  2334   fixes a::real
       
  2335   assumes "a < c"
       
  2336   shows "\<exists>b. a < b \<and> b < c"
       
  2337 proof
       
  2338   let ?b = "(a + c) / 2"
       
  2339   have "a < ?b" by simp
       
  2340   moreover
       
  2341   have "?b < c" by simp
       
  2342   ultimately
       
  2343   show "a < ?b \<and> ?b < c" by simp
       
  2344 qed
       
  2345 
       
  2346 lemma LIM_offset:
       
  2347   assumes "(\<lambda>x. f x) -- a --> L"
       
  2348   shows "(\<lambda>x. f (x+c)) -- (a-c) --> L"
       
  2349 proof -
       
  2350   have "f -- a --> L" .
       
  2351   hence
       
  2352     fd: "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> \<bar>f x + -L\<bar> < r"
       
  2353     by (unfold LIM_def)
       
  2354   {
       
  2355     fix r::real
       
  2356     assume rgz: "0 < r"
       
  2357     with fd have "\<exists>s > 0. \<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s --> \<bar>f x + -L\<bar> < r" by simp
       
  2358     then obtain s where sgz: "s > 0" and ax: "\<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s \<longrightarrow> \<bar>f x + -L\<bar> < r" by auto
       
  2359     from ax have ax2: "\<forall>x. (x+c)\<noteq>a \<and> \<bar>(x+c) + -a\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" by auto
       
  2360     {
       
  2361       fix x::real
       
  2362       from ax2 have nt: "(x+c)\<noteq>a \<and> \<bar>(x+c) + -a\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" ..
       
  2363       moreover have "((x+c)\<noteq>a) = (x\<noteq>(a-c))" by auto
       
  2364       moreover have "((x+c) + -a) = (x + -(a-c))" by simp
       
  2365       ultimately have "x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" by simp
       
  2366     }
       
  2367     then have "\<forall>x. x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" ..
       
  2368     with sgz have "\<exists>s > 0. \<forall>x. x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" by auto
       
  2369   }
       
  2370   then have
       
  2371     "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> (a-c) & \<bar>x + -(a-c)\<bar> < s --> \<bar>f (x+c) + -L\<bar> < r" by simp
       
  2372   thus ?thesis by (fold LIM_def)
       
  2373 qed
       
  2374 
       
  2375 
  2062 
  2376 
  2063 ML
  2377 ML
  2064 {*
  2378 {*
  2065 val LIM_def = thm"LIM_def";
  2379 val LIM_def = thm"LIM_def";
  2066 val NSLIM_def = thm"NSLIM_def";
  2380 val NSLIM_def = thm"NSLIM_def";