src/HOL/Hyperreal/Lim.thy
changeset 20552 2c31dd358c21
parent 20432 07ec57376051
child 20561 6a6d8004322f
equal deleted inserted replaced
20551:ba543692bfa1 20552:2c31dd358c21
    13 begin
    13 begin
    14 
    14 
    15 text{*Standard and Nonstandard Definitions*}
    15 text{*Standard and Nonstandard Definitions*}
    16 
    16 
    17 definition
    17 definition
    18   LIM :: "[real=>real,real,real] => bool"
    18   LIM :: "[real => 'a::real_normed_vector, real, 'a] => bool"
    19         ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    19         ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    20   "f -- a --> L =
    20   "f -- a --> L =
    21      (\<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
    22         --> \<bar>f x + -L\<bar> < r)"
    22         --> norm (f x + -L) < r)"
    23 
    23 
    24   NSLIM :: "[real=>real,real,real] => bool"
    24   NSLIM :: "[real => 'a::real_normed_vector, real, 'a] => bool"
    25             ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    25             ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    26   "f -- a --NS> L = (\<forall>x. (x \<noteq> hypreal_of_real a &
    26   "f -- a --NS> L =
    27           x @= hypreal_of_real a -->
    27     (\<forall>x. (x \<noteq> star_of a & x @= star_of a --> ( *f* f) x @= star_of L))"
    28           ( *f* f) x @= hypreal_of_real L))"
    28 
    29 
    29   isCont :: "[real => 'a::real_normed_vector, real] => bool"
    30   isCont :: "[real=>real,real] => bool"
       
    31   "isCont f a = (f -- a --> (f a))"
    30   "isCont f a = (f -- a --> (f a))"
    32 
    31 
    33   isNSCont :: "[real=>real,real] => bool"
    32   isNSCont :: "[real => 'a::real_normed_vector, real] => bool"
    34     --{*NS definition dispenses with limit notions*}
    33     --{*NS definition dispenses with limit notions*}
    35   "isNSCont f a = (\<forall>y. y @= hypreal_of_real a -->
    34   "isNSCont f a = (\<forall>y. y @= star_of a -->
    36          ( *f* f) y @= hypreal_of_real (f a))"
    35          ( *f* f) y @= star_of (f a))"
    37 
    36 
    38   deriv:: "[real=>real,real,real] => bool"
    37   deriv:: "[real=>real,real,real] => bool"
    39     --{*Differentiation: D is derivative of function f at x*}
    38     --{*Differentiation: D is derivative of function f at x*}
    40           ("(DERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
    39           ("(DERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
    41   "DERIV f x :> D = ((%h. (f(x + h) + -f x)/h) -- 0 --> D)"
    40   "DERIV f x :> D = ((%h. (f(x + h) + -f x)/h) -- 0 --> D)"
    77 
    76 
    78 section{*Some Purely Standard Proofs*}
    77 section{*Some Purely Standard Proofs*}
    79 
    78 
    80 lemma LIM_eq:
    79 lemma LIM_eq:
    81      "f -- a --> L =
    80      "f -- a --> L =
    82      (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)"
    81      (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> norm (f x - L) < r)"
    83 by (simp add: LIM_def diff_minus)
    82 by (simp add: LIM_def diff_minus)
       
    83 
       
    84 lemma LIM_I:
       
    85      "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> norm (f x - L) < r)
       
    86       ==> f -- a --> L"
       
    87 by (simp add: LIM_eq)
    84 
    88 
    85 lemma LIM_D:
    89 lemma LIM_D:
    86      "[| f -- a --> L; 0<r |]
    90      "[| f -- a --> L; 0<r |]
    87       ==> \<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r"
    91       ==> \<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> norm (f x - L) < r"
    88 by (simp add: LIM_eq)
    92 by (simp add: LIM_eq)
    89 
    93 
    90 lemma LIM_const [simp]: "(%x. k) -- x --> k"
    94 lemma LIM_const [simp]: "(%x. k) -- x --> k"
    91 by (simp add: LIM_def)
    95 by (simp add: LIM_def)
    92 
    96 
    93 lemma LIM_add:
    97 lemma LIM_add:
    94   assumes f: "f -- a --> L" and g: "g -- a --> M"
    98   assumes f: "f -- a --> L" and g: "g -- a --> M"
    95   shows "(%x. f x + g(x)) -- a --> (L + M)"
    99   shows "(%x. f x + g(x)) -- a --> (L + M)"
    96 proof (unfold LIM_eq, clarify)
   100 proof (rule LIM_I)
    97   fix r :: real
   101   fix r :: real
    98   assume r: "0 < r"
   102   assume r: "0 < r"
    99   from LIM_D [OF f half_gt_zero [OF r]]
   103   from LIM_D [OF f half_gt_zero [OF r]]
   100   obtain fs
   104   obtain fs
   101     where fs:    "0 < fs"
   105     where fs:    "0 < fs"
   102       and fs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < fs --> \<bar>f x - L\<bar> < r/2"
   106       and fs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < fs --> norm (f x - L) < r/2"
   103   by blast
   107   by blast
   104   from LIM_D [OF g half_gt_zero [OF r]]
   108   from LIM_D [OF g half_gt_zero [OF r]]
   105   obtain gs
   109   obtain gs
   106     where gs:    "0 < gs"
   110     where gs:    "0 < gs"
   107       and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> \<bar>g x - M\<bar> < r/2"
   111       and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> norm (g x - M) < r/2"
   108   by blast
   112   by blast
   109   show "\<exists>s>0.\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>f x + g x - (L + M)\<bar> < r"
   113   show "\<exists>s>0.\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> norm (f x + g x - (L + M)) < r"
   110   proof (intro exI conjI strip)
   114   proof (intro exI conjI strip)
   111     show "0 < min fs gs"  by (simp add: fs gs)
   115     show "0 < min fs gs"  by (simp add: fs gs)
   112     fix x :: real
   116     fix x :: real
   113     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   117     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   114     hence "x \<noteq> a \<and> \<bar>x-a\<bar> < fs \<and> \<bar>x-a\<bar> < gs" by simp
   118     hence "x \<noteq> a \<and> \<bar>x-a\<bar> < fs \<and> \<bar>x-a\<bar> < gs" by simp
   115     with fs_lt gs_lt
   119     with fs_lt gs_lt
   116     have "\<bar>f x - L\<bar> < r/2" and "\<bar>g x - M\<bar> < r/2" by blast+
   120     have "norm (f x - L) < r/2" and "norm (g x - M) < r/2" by blast+
   117     hence "\<bar>f x - L\<bar> + \<bar>g x - M\<bar> < r" by arith
   121     hence "norm (f x - L) + norm (g x - M) < r" by arith
   118     thus "\<bar>f x + g x - (L + M)\<bar> < r"
   122     thus "norm (f x + g x - (L + M)) < r"
   119       by (blast intro: abs_diff_triangle_ineq order_le_less_trans)
   123       by (blast intro: norm_diff_triangle_ineq order_le_less_trans)
   120   qed
   124   qed
   121 qed
   125 qed
   122 
   126 
       
   127 lemma minus_diff_minus:
       
   128   fixes a b :: "'a::ab_group_add"
       
   129   shows "(- a) - (- b) = - (a - b)"
       
   130 by simp
       
   131 
   123 lemma LIM_minus: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
   132 lemma LIM_minus: "f -- a --> L ==> (%x. -f(x)) -- a --> -L"
   124 apply (simp add: LIM_eq)
   133 by (simp only: LIM_eq minus_diff_minus norm_minus_cancel)
   125 apply (subgoal_tac "\<forall>x. \<bar>- f x + L\<bar> = \<bar>f x - L\<bar>")
       
   126 apply (simp_all add: abs_if)
       
   127 done
       
   128 
   134 
   129 lemma LIM_add_minus:
   135 lemma LIM_add_minus:
   130     "[| 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)"
   131 by (blast dest: LIM_add LIM_minus)
   137 by (intro LIM_add LIM_minus)
   132 
   138 
   133 lemma LIM_diff:
   139 lemma LIM_diff:
   134     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
   140     "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) - g(x)) -- x --> l-m"
   135 by (simp add: diff_minus LIM_add_minus)
   141 by (simp only: diff_minus LIM_add LIM_minus)
   136 
   142 
   137 
   143 
   138 lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   144 lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   139 proof (simp add: linorder_neq_iff LIM_eq, elim disjE)
   145 apply (simp add: LIM_eq)
   140   assume k: "k < L"
   146 apply (rule_tac x="norm (k - L)" in exI, simp, safe)
   141   show "\<exists>r>0. \<forall>s>0. (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r"
   147 apply (rule_tac x="a + s/2" in exI, simp)
   142   proof (intro exI conjI strip)
   148 done
   143     show "0 < L-k" by (simp add: k compare_rls)
       
   144     fix s :: real
       
   145     assume s: "0<s"
       
   146     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
       
   147      next
       
   148       from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if)
       
   149      next
       
   150       from s show "~ \<bar>k-L\<bar> < L-k" by (simp add: abs_if) }
       
   151   qed
       
   152 next
       
   153   assume k: "L < k"
       
   154   show "\<exists>r>0.\<forall>s>0. (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r"
       
   155   proof (intro exI conjI strip)
       
   156     show "0 < k-L" by (simp add: k compare_rls)
       
   157     fix s :: real
       
   158     assume s: "0<s"
       
   159     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
       
   160      next
       
   161       from s show "\<bar>s / 2 + a - a\<bar> < s" by (simp add: abs_if)
       
   162      next
       
   163       from s show "~ \<bar>k-L\<bar> < k-L" by (simp add: abs_if) }
       
   164   qed
       
   165 qed
       
   166 
   149 
   167 lemma LIM_const_eq: "(%x. k) -- x --> L ==> k = L"
   150 lemma LIM_const_eq: "(%x. k) -- x --> L ==> k = L"
   168 apply (rule ccontr)
   151 apply (rule ccontr)
   169 apply (blast dest: LIM_const_not_eq)
   152 apply (blast dest: LIM_const_not_eq)
   170 done
   153 done
   173 apply (drule LIM_diff, assumption)
   156 apply (drule LIM_diff, assumption)
   174 apply (auto dest!: LIM_const_eq)
   157 apply (auto dest!: LIM_const_eq)
   175 done
   158 done
   176 
   159 
   177 lemma LIM_mult_zero:
   160 lemma LIM_mult_zero:
       
   161   fixes f g :: "real \<Rightarrow> 'a::real_normed_algebra"
   178   assumes f: "f -- a --> 0" and g: "g -- a --> 0"
   162   assumes f: "f -- a --> 0" and g: "g -- a --> 0"
   179   shows "(%x. f(x) * g(x)) -- a --> 0"
   163   shows "(%x. f(x) * g(x)) -- a --> 0"
   180 proof (simp add: LIM_eq abs_mult, clarify)
   164 proof (rule LIM_I, simp)
   181   fix r :: real
   165   fix r :: real
   182   assume r: "0<r"
   166   assume r: "0<r"
   183   from LIM_D [OF f zero_less_one]
   167   from LIM_D [OF f zero_less_one]
   184   obtain fs
   168   obtain fs
   185     where fs:    "0 < fs"
   169     where fs:    "0 < fs"
   186       and fs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < fs --> \<bar>f x\<bar> < 1"
   170       and fs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < fs --> norm (f x) < 1"
   187   by auto
   171   by auto
   188   from LIM_D [OF g r]
   172   from LIM_D [OF g r]
   189   obtain gs
   173   obtain gs
   190     where gs:    "0 < gs"
   174     where gs:    "0 < gs"
   191       and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> \<bar>g x\<bar> < r"
   175       and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> norm (g x) < r"
   192   by auto
   176   by auto
   193   show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>f x\<bar> * \<bar>g x\<bar> < r)"
   177   show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> norm (f x * g x) < r)"
   194   proof (intro exI conjI strip)
   178   proof (intro exI conjI strip)
   195     show "0 < min fs gs"  by (simp add: fs gs)
   179     show "0 < min fs gs"  by (simp add: fs gs)
   196     fix x :: real
   180     fix x :: real
   197     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   181     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   198     hence  "x \<noteq> a \<and> \<bar>x-a\<bar> < fs \<and> \<bar>x-a\<bar> < gs" by simp
   182     hence  "x \<noteq> a \<and> \<bar>x-a\<bar> < fs \<and> \<bar>x-a\<bar> < gs" by simp
   199     with fs_lt gs_lt
   183     with fs_lt gs_lt
   200     have "\<bar>f x\<bar> < 1" and "\<bar>g x\<bar> < r" by blast+
   184     have "norm (f x) < 1" and "norm (g x) < r" by blast+
   201     hence "\<bar>f x\<bar> * \<bar>g x\<bar> < 1*r" by (rule abs_mult_less)
   185     hence "norm (f x) * norm (g x) < 1*r"
   202     thus "\<bar>f x\<bar> * \<bar>g x\<bar> < r" by simp
   186       by (rule mult_strict_mono' [OF _ _ norm_ge_zero norm_ge_zero])
       
   187     thus "norm (f x * g x) < r"
       
   188       by (simp add: order_le_less_trans [OF norm_mult_ineq])
   203   qed
   189   qed
   204 qed
   190 qed
   205 
   191 
   206 lemma LIM_self: "(%x. x) -- a --> a"
   192 lemma LIM_self: "(%x. x) -- a --> a"
   207 by (auto simp add: LIM_def)
   193 by (auto simp add: LIM_def)
   221 
   207 
   222 subsection{*Relationships Between Standard and Nonstandard Concepts*}
   208 subsection{*Relationships Between Standard and Nonstandard Concepts*}
   223 
   209 
   224 text{*Standard and NS definitions of Limit*} (*NEEDS STRUCTURING*)
   210 text{*Standard and NS definitions of Limit*} (*NEEDS STRUCTURING*)
   225 lemma LIM_NSLIM:
   211 lemma LIM_NSLIM:
   226       "f -- x --> L ==> f -- x --NS> L"
   212       "f -- a --> L ==> f -- a --NS> L"
   227 apply (simp add: LIM_def NSLIM_def approx_def)
   213 apply (simp add: LIM_def NSLIM_def approx_def, safe)
       
   214 apply (rule_tac x="x" in star_cases)
       
   215 apply (simp add: star_of_def star_n_minus star_n_add starfun)
   228 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   216 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   229 apply (rule_tac x = xa in star_cases)
   217 apply (simp add: star_n_eq_iff)
   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 (rule bexI [OF _ Rep_star_star_n], clarify)
       
   232 apply (drule_tac x = u in spec, clarify)
   218 apply (drule_tac x = u in spec, clarify)
   233 apply (drule_tac x = s in spec, clarify)
   219 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")
   220 apply (simp only: FUFNat.Collect_not [symmetric])
   235 prefer 2 apply blast
   221 apply (elim ultra, simp)
   236 apply (drule FreeUltrafilterNat_all, ultra)
       
   237 done
   222 done
   238 
   223 
   239 
   224 
   240 subsubsection{*Limit: The NS definition implies the standard definition.*}
   225 subsubsection{*Limit: The NS definition implies the standard definition.*}
   241 
   226 
   242 lemma lemma_LIM: "\<forall>s>0.\<exists>xa.  xa \<noteq> x &
   227 lemma lemma_LIM:
   243          \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>
   228   fixes L :: "'a::real_normed_vector"
   244       ==> \<forall>n::nat. \<exists>xa.  xa \<noteq> x &
   229   shows "\<forall>s>0. \<exists>x. x \<noteq> a \<and> \<bar>x + - a\<bar> < s \<and> \<not> norm (f x + -L) < r
   245               \<bar>xa + -x\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f xa + -L\<bar>"
   230       ==> \<forall>n::nat. \<exists>x. x \<noteq> a \<and>
       
   231               \<bar>x + -a\<bar> < inverse(real(Suc n)) \<and> \<not> norm (f x + -L) < r"
   246 apply clarify
   232 apply clarify
   247 apply (cut_tac n1 = n in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   233 apply (cut_tac n1 = n in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   248 done
   234 done
   249 
   235 
   250 lemma lemma_skolemize_LIM2:
   236 lemma lemma_skolemize_LIM2:
   251      "\<forall>s>0.\<exists>xa.  xa \<noteq> x & \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>
   237   fixes L :: "'a::real_normed_vector"
   252       ==> \<exists>X. \<forall>n::nat. X n \<noteq> x &
   238   shows "\<forall>s>0. \<exists>x. x \<noteq> a \<and> \<bar>x + - a\<bar> < s \<and> \<not> norm (f x + -L) < r
   253                 \<bar>X n + -x\<bar> < inverse(real(Suc n)) & r \<le> abs(f (X n) + -L)"
   239       ==> \<exists>X. \<forall>n::nat. X n \<noteq> a \<and>
       
   240                 \<bar>X n + -a\<bar> < inverse(real(Suc n)) \<and> \<not> norm(f (X n) + -L) < r"
   254 apply (drule lemma_LIM)
   241 apply (drule lemma_LIM)
   255 apply (drule choice, blast)
   242 apply (drule choice, blast)
   256 done
   243 done
   257 
   244 
   258 lemma lemma_simp: "\<forall>n. X n \<noteq> x &
   245 lemma FreeUltrafilterNat_most: "\<exists>N. \<forall>n\<ge>N. P n \<Longrightarrow> {n. P n} \<in> \<U>"
   259           \<bar>X n + - x\<bar> < inverse (real(Suc n)) &
   246 apply (erule exE)
   260           r \<le> abs (f (X n) + - L) ==>
   247 apply (rule_tac u="{n. N \<le> n}" in FUFNat.subset)
   261           \<forall>n. \<bar>X n + - x\<bar> < inverse (real(Suc n))"
   248 apply (rule cofinite_mem_FreeUltrafilterNat)
       
   249 apply (simp add: Collect_neg_eq [symmetric])
       
   250 apply (simp add: linorder_not_le finite_nat_segment)
       
   251 apply fast
       
   252 done
       
   253 
       
   254 lemma lemma_simp: "\<forall>n. X n \<noteq> a &
       
   255           \<bar>X n + - a\<bar> < inverse (real(Suc n)) &
       
   256           \<not> norm (f (X n) + - L) < r ==>
       
   257           \<forall>n. \<bar>X n + - a\<bar> < inverse (real(Suc n))"
   262 by auto
   258 by auto
   263 
   259 
   264 
   260 
   265 text{*NSLIM => LIM*}
   261 text{*NSLIM => LIM*}
   266 
   262 
   267 lemma NSLIM_LIM: "f -- x --NS> L ==> f -- x --> L"
   263 lemma NSLIM_LIM: "f -- a --NS> L ==> f -- a --> L"
   268 apply (simp add: LIM_def NSLIM_def approx_def)
   264 apply (simp add: LIM_def NSLIM_def approx_def)
   269 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, clarify)
   265 apply (rule ccontr, simp, clarify)
   270 apply (rule ccontr, simp)
       
   271 apply (simp add: linorder_not_less)
       
   272 apply (drule lemma_skolemize_LIM2, safe)
   266 apply (drule lemma_skolemize_LIM2, safe)
   273 apply (drule_tac x = "star_n X" in spec)
   267 apply (drule_tac x = "star_n X" in spec)
   274 apply (auto simp add: starfun star_n_minus star_of_def star_n_add star_n_eq_iff)
   268 apply (drule mp, rule conjI)
   275 apply (drule lemma_simp [THEN real_seq_to_hypreal_Infinitesimal])
   269 apply (simp add: star_of_def star_n_eq_iff)
   276 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff star_of_def star_n_minus star_n_add star_n_eq_iff, blast)
   270 apply (rule real_seq_to_hypreal_Infinitesimal, simp)
   277 apply (drule spec, drule mp, assumption)
   271 apply (simp add: starfun star_of_def star_n_minus star_n_add)
   278 apply (drule FreeUltrafilterNat_all, ultra)
   272 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff)
   279 done
   273 apply (drule spec, drule (1) mp)
   280 
   274 apply simp
       
   275 done
   281 
   276 
   282 theorem LIM_NSLIM_iff: "(f -- x --> L) = (f -- x --NS> L)"
   277 theorem LIM_NSLIM_iff: "(f -- x --> L) = (f -- x --NS> L)"
   283 by (blast intro: LIM_NSLIM NSLIM_LIM)
   278 by (blast intro: LIM_NSLIM NSLIM_LIM)
   284 
   279 
   285 text{*Proving properties of limits using nonstandard definition.
   280 text{*Proving properties of limits using nonstandard definition.
   286       The properties hold for standard limits as well!*}
   281       The properties hold for standard limits as well!*}
   287 
   282 
   288 lemma NSLIM_mult:
   283 lemma NSLIM_mult:
   289      "[| f -- x --NS> l; g -- x --NS> m |]
   284   fixes l m :: "'a::real_normed_algebra"
       
   285   shows "[| f -- x --NS> l; g -- x --NS> m |]
   290       ==> (%x. f(x) * g(x)) -- x --NS> (l * m)"
   286       ==> (%x. f(x) * g(x)) -- x --NS> (l * m)"
   291 by (auto simp add: NSLIM_def intro!: approx_mult_HFinite)
   287 by (auto simp add: NSLIM_def intro!: approx_mult_HFinite)
   292 
   288 
   293 lemma LIM_mult2:
   289 lemma LIM_mult2:
   294      "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) * g(x)) -- x --> (l * m)"
   290   fixes l m :: "'a::real_normed_algebra"
       
   291   shows "[| f -- x --> l; g -- x --> m |]
       
   292       ==> (%x. f(x) * g(x)) -- x --> (l * m)"
   295 by (simp add: LIM_NSLIM_iff NSLIM_mult)
   293 by (simp add: LIM_NSLIM_iff NSLIM_mult)
   296 
   294 
   297 lemma NSLIM_add:
   295 lemma NSLIM_add:
   298      "[| f -- x --NS> l; g -- x --NS> m |]
   296      "[| f -- x --NS> l; g -- x --NS> m |]
   299       ==> (%x. f(x) + g(x)) -- x --NS> (l + m)"
   297       ==> (%x. f(x) + g(x)) -- x --NS> (l + m)"
   323 lemma LIM_add_minus2: "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   321 lemma LIM_add_minus2: "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   324 by (simp add: LIM_NSLIM_iff NSLIM_add_minus)
   322 by (simp add: LIM_NSLIM_iff NSLIM_add_minus)
   325 
   323 
   326 
   324 
   327 lemma NSLIM_inverse:
   325 lemma NSLIM_inverse:
   328      "[| f -- a --NS> L;  L \<noteq> 0 |]
   326   fixes L :: "'a::{real_normed_div_algebra,division_by_zero}"
       
   327   shows "[| f -- a --NS> L;  L \<noteq> 0 |]
   329       ==> (%x. inverse(f(x))) -- a --NS> (inverse L)"
   328       ==> (%x. inverse(f(x))) -- a --NS> (inverse L)"
   330 apply (simp add: NSLIM_def, clarify)
   329 apply (simp add: NSLIM_def, clarify)
   331 apply (drule spec)
   330 apply (drule spec)
   332 apply (auto simp add: hypreal_of_real_approx_inverse)
   331 apply (auto simp add: star_of_approx_inverse)
   333 done
   332 done
   334 
   333 
   335 lemma LIM_inverse: "[| f -- a --> L; L \<noteq> 0 |] ==> (%x. inverse(f(x))) -- a --> (inverse L)"
   334 lemma LIM_inverse:
       
   335   fixes L :: "'a::{real_normed_div_algebra,division_by_zero}"
       
   336   shows "[| f -- a --> L; L \<noteq> 0 |]
       
   337       ==> (%x. inverse(f(x))) -- a --> (inverse L)"
   336 by (simp add: LIM_NSLIM_iff NSLIM_inverse)
   338 by (simp add: LIM_NSLIM_iff NSLIM_inverse)
   337 
   339 
   338 
   340 
   339 lemma NSLIM_zero:
   341 lemma NSLIM_zero:
   340   assumes f: "f -- a --NS> l" shows "(%x. f(x) + -l) -- a --NS> 0"
   342   assumes f: "f -- a --NS> l" shows "(%x. f(x) + -l) -- a --NS> 0"
   355 lemma LIM_zero_cancel: "(%x. f(x) - l) -- x --> 0 ==> f -- x --> l"
   357 lemma LIM_zero_cancel: "(%x. f(x) - l) -- x --> 0 ==> f -- x --> l"
   356 apply (drule_tac g = "%x. l" and M = l in LIM_add)
   358 apply (drule_tac g = "%x. l" and M = l in LIM_add)
   357 apply (auto simp add: diff_minus add_assoc)
   359 apply (auto simp add: diff_minus add_assoc)
   358 done
   360 done
   359 
   361 
   360 lemma NSLIM_not_zero: "k \<noteq> 0 ==> ~ ((%x. k) -- x --NS> 0)"
       
   361 apply (simp add: NSLIM_def)
       
   362 apply (rule_tac x = "hypreal_of_real x + epsilon" in exI)
       
   363 apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
       
   364             simp add: hypreal_epsilon_not_zero)
       
   365 done
       
   366 
       
   367 lemma NSLIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- x --NS> L)"
   362 lemma NSLIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- x --NS> L)"
   368 apply (simp add: NSLIM_def)
   363 apply (simp add: NSLIM_def)
   369 apply (rule_tac x = "hypreal_of_real x + epsilon" in exI)
   364 apply (rule_tac x = "hypreal_of_real x + epsilon" in exI)
   370 apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
   365 apply (auto intro: Infinitesimal_add_approx_self [THEN approx_sym]
   371             simp add: hypreal_epsilon_not_zero)
   366             simp add: hypreal_epsilon_not_zero)
   372 done
   367 done
   373 
   368 
       
   369 lemma NSLIM_not_zero: "k \<noteq> 0 ==> ~ ((%x. k) -- x --NS> 0)"
       
   370 by (rule NSLIM_const_not_eq)
       
   371 
   374 lemma NSLIM_const_eq: "(%x. k) -- x --NS> L ==> k = L"
   372 lemma NSLIM_const_eq: "(%x. k) -- x --NS> L ==> k = L"
   375 apply (rule ccontr)
   373 apply (rule ccontr)
   376 apply (blast dest: NSLIM_const_not_eq)
   374 apply (blast dest: NSLIM_const_not_eq)
   377 done
   375 done
   378 
   376 
   379 text{* can actually be proved more easily by unfolding the definition!*}
   377 text{* can actually be proved more easily by unfolding the definition!*}
   380 lemma NSLIM_unique: "[| f -- x --NS> L; f -- x --NS> M |] ==> L = M"
   378 lemma NSLIM_unique: "[| f -- x --NS> L; f -- x --NS> M |] ==> L = M"
   381 apply (drule NSLIM_minus)
   379 apply (drule NSLIM_minus)
   382 apply (drule NSLIM_add, assumption)
   380 apply (drule NSLIM_add, assumption)
   383 apply (auto dest!: NSLIM_const_eq [symmetric])
   381 apply (auto dest!: NSLIM_const_eq [symmetric])
       
   382 apply (simp add: diff_def [symmetric])
   384 done
   383 done
   385 
   384 
   386 lemma LIM_unique2: "[| f -- x --> L; f -- x --> M |] ==> L = M"
   385 lemma LIM_unique2: "[| f -- x --> L; f -- x --> M |] ==> L = M"
   387 by (simp add: LIM_NSLIM_iff NSLIM_unique)
   386 by (simp add: LIM_NSLIM_iff NSLIM_unique)
   388 
   387 
   389 
   388 
   390 lemma NSLIM_mult_zero: "[| f -- x --NS> 0; g -- x --NS> 0 |] ==> (%x. f(x)*g(x)) -- x --NS> 0"
   389 lemma NSLIM_mult_zero:
       
   390   fixes f g :: "real \<Rightarrow> 'a::real_normed_algebra"
       
   391   shows "[| f -- x --NS> 0; g -- x --NS> 0 |] ==> (%x. f(x)*g(x)) -- x --NS> 0"
   391 by (drule NSLIM_mult, auto)
   392 by (drule NSLIM_mult, auto)
   392 
   393 
   393 (* we can use the corresponding thm LIM_mult2 *)
   394 (* we can use the corresponding thm LIM_mult2 *)
   394 (* for standard definition of limit           *)
   395 (* for standard definition of limit           *)
   395 
   396 
   396 lemma LIM_mult_zero2: "[| f -- x --> 0; g -- x --> 0 |] ==> (%x. f(x)*g(x)) -- x --> 0"
   397 lemma LIM_mult_zero2:
       
   398   fixes f g :: "real \<Rightarrow> 'a::real_normed_algebra"
       
   399   shows "[| f -- x --> 0; g -- x --> 0 |] ==> (%x. f(x)*g(x)) -- x --> 0"
   397 by (drule LIM_mult2, auto)
   400 by (drule LIM_mult2, auto)
   398 
   401 
   399 
   402 
   400 lemma NSLIM_self: "(%x. x) -- a --NS> a"
   403 lemma NSLIM_self: "(%x. x) -- a --NS> a"
   401 by (simp add: NSLIM_def)
   404 by (simp add: NSLIM_def)
   470 text{*sum continuous*}
   473 text{*sum continuous*}
   471 lemma isCont_add: "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) + g(x)) a"
   474 lemma isCont_add: "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) + g(x)) a"
   472 by (auto intro: approx_add simp add: isNSCont_isCont_iff [symmetric] isNSCont_def)
   475 by (auto intro: approx_add simp add: isNSCont_isCont_iff [symmetric] isNSCont_def)
   473 
   476 
   474 text{*mult continuous*}
   477 text{*mult continuous*}
   475 lemma isCont_mult: "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a"
   478 lemma isCont_mult:
       
   479   fixes f g :: "real \<Rightarrow> 'a::real_normed_algebra"
       
   480   shows "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) * g(x)) a"
   476 by (auto intro!: starfun_mult_HFinite_approx
   481 by (auto intro!: starfun_mult_HFinite_approx
   477             simp del: starfun_mult [symmetric]
   482             simp del: starfun_mult [symmetric]
   478             simp add: isNSCont_isCont_iff [symmetric] isNSCont_def)
   483             simp add: isNSCont_isCont_iff [symmetric] isNSCont_def)
   479 
   484 
   480 text{*composition of continuous functions
   485 text{*composition of continuous functions
   490 
   495 
   491 lemma isCont_minus: "isCont f a ==> isCont (%x. - f x) a"
   496 lemma isCont_minus: "isCont f a ==> isCont (%x. - f x) a"
   492 by (auto simp add: isNSCont_isCont_iff [symmetric] isNSCont_minus)
   497 by (auto simp add: isNSCont_isCont_iff [symmetric] isNSCont_minus)
   493 
   498 
   494 lemma isCont_inverse:
   499 lemma isCont_inverse:
   495       "[| isCont f x; f x \<noteq> 0 |] ==> isCont (%x. inverse (f x)) x"
   500   fixes f :: "real \<Rightarrow> 'a::{real_normed_div_algebra,division_by_zero}"
       
   501   shows "[| isCont f x; f x \<noteq> 0 |] ==> isCont (%x. inverse (f x)) x"
   496 apply (simp add: isCont_def)
   502 apply (simp add: isCont_def)
   497 apply (blast intro: LIM_inverse)
   503 apply (blast intro: LIM_inverse)
   498 done
   504 done
   499 
   505 
   500 lemma isNSCont_inverse: "[| isNSCont f x; f x \<noteq> 0 |] ==> isNSCont (%x. inverse (f x)) x"
   506 lemma isNSCont_inverse:
       
   507   fixes f :: "real \<Rightarrow> 'a::{real_normed_div_algebra,division_by_zero}"
       
   508   shows "[| isNSCont f x; f x \<noteq> 0 |] ==> isNSCont (%x. inverse (f x)) x"
   501 by (auto intro: isCont_inverse simp add: isNSCont_isCont_iff)
   509 by (auto intro: isCont_inverse simp add: isNSCont_isCont_iff)
   502 
   510 
   503 lemma isCont_diff:
   511 lemma isCont_diff:
   504       "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) - g(x)) a"
   512       "[| isCont f a; isCont g a |] ==> isCont (%x. f(x) - g(x)) a"
   505 apply (simp add: diff_minus)
   513 apply (simp add: diff_minus)
   576 lemma isUCont_isCont: "isUCont f ==> isCont f x"
   584 lemma isUCont_isCont: "isUCont f ==> isCont f x"
   577 by (simp add: isUCont_def isCont_def LIM_def, meson)
   585 by (simp add: isUCont_def isCont_def LIM_def, meson)
   578 
   586 
   579 lemma isUCont_isNSUCont: "isUCont f ==> isNSUCont f"
   587 lemma isUCont_isNSUCont: "isUCont f ==> isNSUCont f"
   580 apply (simp add: isNSUCont_def isUCont_def approx_def)
   588 apply (simp add: isNSUCont_def isUCont_def approx_def)
       
   589 apply (simp add: all_star_eq starfun star_n_minus star_n_add)
   581 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   590 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
   582 apply (rule_tac x = x in star_cases)
   591 apply (rename_tac Xa Xb u)
   583 apply (rule_tac x = y in star_cases)
       
   584 apply (auto simp add: starfun star_n_minus star_n_add)
       
   585 apply (rule bexI [OF _ Rep_star_star_n], safe)
       
   586 apply (drule_tac x = u in spec, clarify)
   592 apply (drule_tac x = u in spec, clarify)
   587 apply (drule_tac x = s in spec, clarify)
   593 apply (drule_tac x = s in spec, clarify)
   588 apply (subgoal_tac "\<forall>n::nat. abs ((Xa n) + - (Xb n)) < s --> abs (f (Xa n) + - f (Xb n)) < u")
   594 apply (subgoal_tac "\<forall>n::nat. abs ((Xa n) + - (Xb n)) < s --> abs (f (Xa n) + - f (Xb n)) < u")
   589 prefer 2 apply blast
   595 prefer 2 apply blast
   590 apply (erule_tac V = "\<forall>x y. \<bar>x + - y\<bar> < s --> \<bar>f x + - f y\<bar> < u" in thin_rl)
   596 apply (erule_tac V = "\<forall>x y. \<bar>x + - y\<bar> < s --> \<bar>f x + - f y\<bar> < u" in thin_rl)
   591 apply (drule FreeUltrafilterNat_all, ultra)
   597 apply (erule ultra, simp)
   592 done
   598 done
   593 
   599 
   594 lemma lemma_LIMu: "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s & r \<le> \<bar>f z + -f y\<bar>
   600 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>"
   601       ==> \<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
   602 apply clarify
   613           \<forall>n. \<bar>X n + - Y n\<bar> < inverse (real(Suc n))"
   619           \<forall>n. \<bar>X n + - Y n\<bar> < inverse (real(Suc n))"
   614 by auto
   620 by auto
   615 
   621 
   616 lemma isNSUCont_isUCont:
   622 lemma isNSUCont_isUCont:
   617      "isNSUCont f ==> isUCont f"
   623      "isNSUCont f ==> isUCont f"
   618 apply (simp add: isNSUCont_def isUCont_def approx_def)
   624 apply (simp add: isNSUCont_def isUCont_def approx_def, safe)
   619 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff, safe)
       
   620 apply (rule ccontr, simp)
   625 apply (rule ccontr, simp)
   621 apply (simp add: linorder_not_less)
   626 apply (simp add: linorder_not_less)
   622 apply (drule lemma_skolemize_LIM2u, safe)
   627 apply (drule lemma_skolemize_LIM2u, safe)
   623 apply (drule_tac x = "star_n X" in spec)
   628 apply (drule_tac x = "star_n X" in spec)
   624 apply (drule_tac x = "star_n Y" in spec)
   629 apply (drule_tac x = "star_n Y" in spec)
   625 apply (simp add: starfun star_n_minus star_n_add, auto)
   630 apply (drule mp)
   626 apply (drule lemma_simpu [THEN real_seq_to_hypreal_Infinitesimal2])
   631 apply (rule real_seq_to_hypreal_Infinitesimal2, simp)
   627 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff star_n_minus star_n_add, blast)
   632 apply (simp add: all_star_eq starfun star_n_minus star_n_add)
   628 apply (drule_tac x = r in spec, clarify)
   633 apply (simp add: Infinitesimal_FreeUltrafilterNat_iff)
       
   634 apply (drule spec, drule (1) mp)
   629 apply (drule FreeUltrafilterNat_all, ultra)
   635 apply (drule FreeUltrafilterNat_all, ultra)
   630 done
   636 done
   631 
   637 
   632 text{*Derivatives*}
   638 text{*Derivatives*}
   633 lemma DERIV_iff: "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --> D)"
   639 lemma DERIV_iff: "(DERIV f x :> D) = ((%h. (f(x + h) + - f(x))/h) -- 0 --> D)"
   674 
   680 
   675 lemma NSdifferentiableI: "NSDERIV f x :> D ==> f NSdifferentiable x"
   681 lemma NSdifferentiableI: "NSDERIV f x :> D ==> f NSdifferentiable x"
   676 by (force simp add: NSdifferentiable_def)
   682 by (force simp add: NSdifferentiable_def)
   677 
   683 
   678 subsubsection{*Alternative definition for differentiability*}
   684 subsubsection{*Alternative definition for differentiability*}
   679 
       
   680 lemma LIM_I:
       
   681      "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)
       
   682       ==> f -- a --> L"
       
   683 by (simp add: LIM_eq)
       
   684 
   685 
   685 lemma DERIV_LIM_iff:
   686 lemma DERIV_LIM_iff:
   686      "((%h. (f(a + h) - f(a)) / h) -- 0 --> D) =
   687      "((%h. (f(a + h) - f(a)) / h) -- 0 --> D) =
   687       ((%x. (f(x)-f(a)) / (x-a)) -- a --> D)"
   688       ((%x. (f(x)-f(a)) / (x-a)) -- a --> D)"
   688 proof (intro iffI LIM_I)
   689 proof (intro iffI LIM_I)
   693   obtain s
   694   obtain s
   694     where s:    "0 < s"
   695     where s:    "0 < s"
   695       and s_lt: "\<forall>x. x \<noteq> 0 & \<bar>x\<bar> < s --> \<bar>(f (a + x) - f a) / x - D\<bar> < r"
   696       and s_lt: "\<forall>x. x \<noteq> 0 & \<bar>x\<bar> < s --> \<bar>(f (a + x) - f a) / x - D\<bar> < r"
   696   by auto
   697   by auto
   697   show "\<exists>s. 0 < s \<and>
   698   show "\<exists>s. 0 < s \<and>
   698             (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>(f x - f a) / (x-a) - D\<bar> < r)"
   699             (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> norm ((f x - f a) / (x-a) - D) < r)"
   699   proof (intro exI conjI strip)
   700   proof (intro exI conjI strip)
   700     show "0 < s"  by (rule s)
   701     show "0 < s"  by (rule s)
   701   next
   702   next
   702     fix x::real
   703     fix x::real
   703     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < s"
   704     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < s"
   704     with s_lt [THEN spec [where x="x-a"]]
   705     with s_lt [THEN spec [where x="x-a"]]
   705     show "\<bar>(f x - f a) / (x-a) - D\<bar> < r" by auto
   706     show "norm ((f x - f a) / (x-a) - D) < r" by auto
   706   qed
   707   qed
   707 next
   708 next
   708   fix r::real
   709   fix r::real
   709   assume r: "0<r"
   710   assume r: "0<r"
   710   assume "(\<lambda>x. (f x - f a) / (x-a)) -- a --> D"
   711   assume "(\<lambda>x. (f x - f a) / (x-a)) -- a --> D"
   712   obtain s
   713   obtain s
   713     where s:    "0 < s"
   714     where s:    "0 < s"
   714       and s_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>(f x - f a)/(x-a) - D\<bar> < r"
   715       and s_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>(f x - f a)/(x-a) - D\<bar> < r"
   715   by auto
   716   by auto
   716   show "\<exists>s. 0 < s \<and>
   717   show "\<exists>s. 0 < s \<and>
   717             (\<forall>x. x \<noteq> 0 & \<bar>x - 0\<bar> < s --> \<bar>(f (a + x) - f a) / x - D\<bar> < r)"
   718             (\<forall>x. x \<noteq> 0 & \<bar>x - 0\<bar> < s --> norm ((f (a + x) - f a) / x - D) < r)"
   718   proof (intro exI conjI strip)
   719   proof (intro exI conjI strip)
   719     show "0 < s"  by (rule s)
   720     show "0 < s"  by (rule s)
   720   next
   721   next
   721     fix x::real
   722     fix x::real
   722     assume "x \<noteq> 0 \<and> \<bar>x - 0\<bar> < s"
   723     assume "x \<noteq> 0 \<and> \<bar>x - 0\<bar> < s"
   723     with s_lt [THEN spec [where x="x+a"]]
   724     with s_lt [THEN spec [where x="x+a"]]
   724     show "\<bar>(f (a + x) - f a) / x - D\<bar> < r" by (auto simp add: add_ac)
   725     show "norm ((f (a + x) - f a) / x - D) < r" by (auto simp add: add_ac)
   725   qed
   726   qed
   726 qed
   727 qed
   727 
   728 
   728 lemma DERIV_iff2: "(DERIV f x :> D) = ((%z. (f(z) - f(x)) / (z-x)) -- x --> D)"
   729 lemma DERIV_iff2: "(DERIV f x :> D) = ((%z. (f(z) - f(x)) / (z-x)) -- x --> D)"
   729 by (simp add: deriv_def diff_minus [symmetric] DERIV_LIM_iff)
   730 by (simp add: deriv_def diff_minus [symmetric] DERIV_LIM_iff)
  1234 done
  1235 done
  1235 
  1236 
  1236 lemma f_inc_g_dec_Beq_f: "[| \<forall>n. f(n) \<le> f(Suc n);
  1237 lemma f_inc_g_dec_Beq_f: "[| \<forall>n. f(n) \<le> f(Suc n);
  1237          \<forall>n. g(Suc n) \<le> g(n);
  1238          \<forall>n. g(Suc n) \<le> g(n);
  1238          \<forall>n. f(n) \<le> g(n) |]
  1239          \<forall>n. f(n) \<le> g(n) |]
  1239       ==> Bseq f"
  1240       ==> Bseq (f :: nat \<Rightarrow> real)"
  1240 apply (rule_tac k = "f 0" and K = "g 0" in BseqI2, rule allI)
  1241 apply (rule_tac k = "f 0" and K = "g 0" in BseqI2, rule allI)
  1241 apply (induct_tac "n")
  1242 apply (induct_tac "n")
  1242 apply (auto intro: order_trans)
  1243 apply (auto intro: order_trans)
  1243 apply (rule_tac y = "g (Suc na)" in order_trans)
  1244 apply (rule_tac y = "g (Suc na)" in order_trans)
  1244 apply (induct_tac [2] "na")
  1245 apply (induct_tac [2] "na")
  1246 done
  1247 done
  1247 
  1248 
  1248 lemma f_inc_g_dec_Beq_g: "[| \<forall>n. f(n) \<le> f(Suc n);
  1249 lemma f_inc_g_dec_Beq_g: "[| \<forall>n. f(n) \<le> f(Suc n);
  1249          \<forall>n. g(Suc n) \<le> g(n);
  1250          \<forall>n. g(Suc n) \<le> g(n);
  1250          \<forall>n. f(n) \<le> g(n) |]
  1251          \<forall>n. f(n) \<le> g(n) |]
  1251       ==> Bseq g"
  1252       ==> Bseq (g :: nat \<Rightarrow> real)"
  1252 apply (subst Bseq_minus_iff [symmetric])
  1253 apply (subst Bseq_minus_iff [symmetric])
  1253 apply (rule_tac g = "%x. - (f x)" in f_inc_g_dec_Beq_f)
  1254 apply (rule_tac g = "%x. - (f x)" in f_inc_g_dec_Beq_f)
  1254 apply auto
  1255 apply auto
  1255 done
  1256 done
  1256 
  1257 
  1280 done
  1281 done
  1281 
  1282 
  1282 lemma lemma_nest: "[| \<forall>n. f(n) \<le> f(Suc n);
  1283 lemma lemma_nest: "[| \<forall>n. f(n) \<le> f(Suc n);
  1283          \<forall>n. g(Suc n) \<le> g(n);
  1284          \<forall>n. g(Suc n) \<le> g(n);
  1284          \<forall>n. f(n) \<le> g(n) |]
  1285          \<forall>n. f(n) \<le> g(n) |]
  1285       ==> \<exists>l m. l \<le> m &  ((\<forall>n. f(n) \<le> l) & f ----> l) &
  1286       ==> \<exists>l m :: real. l \<le> m &  ((\<forall>n. f(n) \<le> l) & f ----> l) &
  1286                             ((\<forall>n. m \<le> g(n)) & g ----> m)"
  1287                             ((\<forall>n. m \<le> g(n)) & g ----> m)"
  1287 apply (subgoal_tac "monoseq f & monoseq g")
  1288 apply (subgoal_tac "monoseq f & monoseq g")
  1288 prefer 2 apply (force simp add: LIMSEQ_iff monoseq_Suc)
  1289 prefer 2 apply (force simp add: LIMSEQ_iff monoseq_Suc)
  1289 apply (subgoal_tac "Bseq f & Bseq g")
  1290 apply (subgoal_tac "Bseq f & Bseq g")
  1290 prefer 2 apply (blast intro: f_inc_g_dec_Beq_f f_inc_g_dec_Beq_g)
  1291 prefer 2 apply (blast intro: f_inc_g_dec_Beq_f f_inc_g_dec_Beq_g)
  1297 
  1298 
  1298 lemma lemma_nest_unique: "[| \<forall>n. f(n) \<le> f(Suc n);
  1299 lemma lemma_nest_unique: "[| \<forall>n. f(n) \<le> f(Suc n);
  1299          \<forall>n. g(Suc n) \<le> g(n);
  1300          \<forall>n. g(Suc n) \<le> g(n);
  1300          \<forall>n. f(n) \<le> g(n);
  1301          \<forall>n. f(n) \<le> g(n);
  1301          (%n. f(n) - g(n)) ----> 0 |]
  1302          (%n. f(n) - g(n)) ----> 0 |]
  1302       ==> \<exists>l. ((\<forall>n. f(n) \<le> l) & f ----> l) &
  1303       ==> \<exists>l::real. ((\<forall>n. f(n) \<le> l) & f ----> l) &
  1303                 ((\<forall>n. l \<le> g(n)) & g ----> l)"
  1304                 ((\<forall>n. l \<le> g(n)) & g ----> l)"
  1304 apply (drule lemma_nest, auto)
  1305 apply (drule lemma_nest, auto)
  1305 apply (subgoal_tac "l = m")
  1306 apply (subgoal_tac "l = m")
  1306 apply (drule_tac [2] X = f in LIMSEQ_diff)
  1307 apply (drule_tac [2] X = f in LIMSEQ_diff)
  1307 apply (auto intro: LIMSEQ_unique)
  1308 apply (auto intro: LIMSEQ_unique)
  1412 done
  1413 done
  1413 
  1414 
  1414 
  1415 
  1415 subsection{*Intermediate Value Theorem: Prove Contrapositive by Bisection*}
  1416 subsection{*Intermediate Value Theorem: Prove Contrapositive by Bisection*}
  1416 
  1417 
  1417 lemma IVT: "[| f(a) \<le> y; y \<le> f(b);
  1418 lemma IVT: "[| f(a) \<le> (y::real); y \<le> f(b);
  1418          a \<le> b;
  1419          a \<le> b;
  1419          (\<forall>x. a \<le> x & x \<le> b --> isCont f x) |]
  1420          (\<forall>x. a \<le> x & x \<le> b --> isCont f x) |]
  1420       ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y"
  1421       ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y"
  1421 apply (rule contrapos_pp, assumption)
  1422 apply (rule contrapos_pp, assumption)
  1422 apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> ~ (f (u) \<le> y & y \<le> f (v))" in lemma_BOLZANO2)
  1423 apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> ~ (f (u) \<le> y & y \<le> f (v))" in lemma_BOLZANO2)
  1439 apply (simp_all add: abs_if)
  1440 apply (simp_all add: abs_if)
  1440 apply (drule_tac x = "aa-x" in spec)
  1441 apply (drule_tac x = "aa-x" in spec)
  1441 apply (case_tac "x \<le> aa", simp_all)
  1442 apply (case_tac "x \<le> aa", simp_all)
  1442 done
  1443 done
  1443 
  1444 
  1444 lemma IVT2: "[| f(b) \<le> y; y \<le> f(a);
  1445 lemma IVT2: "[| f(b) \<le> (y::real); y \<le> f(a);
  1445          a \<le> b;
  1446          a \<le> b;
  1446          (\<forall>x. a \<le> x & x \<le> b --> isCont f x)
  1447          (\<forall>x. a \<le> x & x \<le> b --> isCont f x)
  1447       |] ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y"
  1448       |] ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y"
  1448 apply (subgoal_tac "- f a \<le> -y & -y \<le> - f b", clarify)
  1449 apply (subgoal_tac "- f a \<le> -y & -y \<le> - f b", clarify)
  1449 apply (drule IVT [where f = "%x. - f x"], assumption)
  1450 apply (drule IVT [where f = "%x. - f x"], assumption)
  1450 apply (auto intro: isCont_minus)
  1451 apply (auto intro: isCont_minus)
  1451 done
  1452 done
  1452 
  1453 
  1453 (*HOL style here: object-level formulations*)
  1454 (*HOL style here: object-level formulations*)
  1454 lemma IVT_objl: "(f(a) \<le> y & y \<le> f(b) & a \<le> b &
  1455 lemma IVT_objl: "(f(a) \<le> (y::real) & y \<le> f(b) & a \<le> b &
  1455       (\<forall>x. a \<le> x & x \<le> b --> isCont f x))
  1456       (\<forall>x. a \<le> x & x \<le> b --> isCont f x))
  1456       --> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)"
  1457       --> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)"
  1457 apply (blast intro: IVT)
  1458 apply (blast intro: IVT)
  1458 done
  1459 done
  1459 
  1460 
  1460 lemma IVT2_objl: "(f(b) \<le> y & y \<le> f(a) & a \<le> b &
  1461 lemma IVT2_objl: "(f(b) \<le> (y::real) & y \<le> f(a) & a \<le> b &
  1461       (\<forall>x. a \<le> x & x \<le> b --> isCont f x))
  1462       (\<forall>x. a \<le> x & x \<le> b --> isCont f x))
  1462       --> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)"
  1463       --> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)"
  1463 apply (blast intro: IVT2)
  1464 apply (blast intro: IVT2)
  1464 done
  1465 done
  1465 
  1466 
  1466 subsection{*By bisection, function continuous on closed interval is bounded above*}
  1467 subsection{*By bisection, function continuous on closed interval is bounded above*}
  1467 
  1468 
  1468 lemma isCont_bounded:
  1469 lemma isCont_bounded:
  1469      "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1470      "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1470       ==> \<exists>M. \<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M"
  1471       ==> \<exists>M::real. \<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M"
  1471 apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> (\<exists>M. \<forall>x. u \<le> x & x \<le> v --> f x \<le> M)" in lemma_BOLZANO2)
  1472 apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> (\<exists>M. \<forall>x. u \<le> x & x \<le> v --> f x \<le> M)" in lemma_BOLZANO2)
  1472 apply safe
  1473 apply safe
  1473 apply simp_all
  1474 apply simp_all
  1474 apply (rename_tac x xa ya M Ma)
  1475 apply (rename_tac x xa ya M Ma)
  1475 apply (cut_tac x = M and y = Ma in linorder_linear, safe)
  1476 apply (cut_tac x = M and y = Ma in linorder_linear, safe)
  1495 lemma lemma_reals_complete: "((\<exists>x. x \<in> S) & (\<exists>y. isUb UNIV S (y::real))) -->
  1496 lemma lemma_reals_complete: "((\<exists>x. x \<in> S) & (\<exists>y. isUb UNIV S (y::real))) -->
  1496       (\<exists>t. isLub UNIV S t)"
  1497       (\<exists>t. isLub UNIV S t)"
  1497 by (blast intro: reals_complete)
  1498 by (blast intro: reals_complete)
  1498 
  1499 
  1499 lemma isCont_has_Ub: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1500 lemma isCont_has_Ub: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1500          ==> \<exists>M. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  1501          ==> \<exists>M::real. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  1501                    (\<forall>N. N < M --> (\<exists>x. a \<le> x & x \<le> b & N < f(x)))"
  1502                    (\<forall>N. N < M --> (\<exists>x. a \<le> x & x \<le> b & N < f(x)))"
  1502 apply (cut_tac S = "Collect (%y. \<exists>x. a \<le> x & x \<le> b & y = f x)"
  1503 apply (cut_tac S = "Collect (%y. \<exists>x. a \<le> x & x \<le> b & y = f x)"
  1503         in lemma_reals_complete)
  1504         in lemma_reals_complete)
  1504 apply auto
  1505 apply auto
  1505 apply (drule isCont_bounded, assumption)
  1506 apply (drule isCont_bounded, assumption)
  1511 text{*Now show that it attains its upper bound*}
  1512 text{*Now show that it attains its upper bound*}
  1512 
  1513 
  1513 lemma isCont_eq_Ub:
  1514 lemma isCont_eq_Ub:
  1514   assumes le: "a \<le> b"
  1515   assumes le: "a \<le> b"
  1515       and con: "\<forall>x. a \<le> x & x \<le> b --> isCont f x"
  1516       and con: "\<forall>x. a \<le> x & x \<le> b --> isCont f x"
  1516   shows "\<exists>M. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  1517   shows "\<exists>M::real. (\<forall>x. a \<le> x & x \<le> b --> f(x) \<le> M) &
  1517              (\<exists>x. a \<le> x & x \<le> b & f(x) = M)"
  1518              (\<exists>x. a \<le> x & x \<le> b & f(x) = M)"
  1518 proof -
  1519 proof -
  1519   from isCont_has_Ub [OF le con]
  1520   from isCont_has_Ub [OF le con]
  1520   obtain M where M1: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> f x \<le> M"
  1521   obtain M where M1: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> f x \<le> M"
  1521              and M2: "!!N. N<M ==> \<exists>x. a \<le> x \<and> x \<le> b \<and> N < f x"  by blast
  1522              and M2: "!!N. N<M ==> \<exists>x. a \<le> x \<and> x \<le> b \<and> N < f x"  by blast
  1551 
  1552 
  1552 
  1553 
  1553 text{*Same theorem for lower bound*}
  1554 text{*Same theorem for lower bound*}
  1554 
  1555 
  1555 lemma isCont_eq_Lb: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1556 lemma isCont_eq_Lb: "[| a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1556          ==> \<exists>M. (\<forall>x. a \<le> x & x \<le> b --> M \<le> f(x)) &
  1557          ==> \<exists>M::real. (\<forall>x. a \<le> x & x \<le> b --> M \<le> f(x)) &
  1557                    (\<exists>x. a \<le> x & x \<le> b & f(x) = M)"
  1558                    (\<exists>x. a \<le> x & x \<le> b & f(x) = M)"
  1558 apply (subgoal_tac "\<forall>x. a \<le> x & x \<le> b --> isCont (%x. - (f x)) x")
  1559 apply (subgoal_tac "\<forall>x. a \<le> x & x \<le> b --> isCont (%x. - (f x)) x")
  1559 prefer 2 apply (blast intro: isCont_minus)
  1560 prefer 2 apply (blast intro: isCont_minus)
  1560 apply (drule_tac f = "(%x. - (f x))" in isCont_eq_Ub)
  1561 apply (drule_tac f = "(%x. - (f x))" in isCont_eq_Ub)
  1561 apply safe
  1562 apply safe
  1564 
  1565 
  1565 
  1566 
  1566 text{*Another version.*}
  1567 text{*Another version.*}
  1567 
  1568 
  1568 lemma isCont_Lb_Ub: "[|a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1569 lemma isCont_Lb_Ub: "[|a \<le> b; \<forall>x. a \<le> x & x \<le> b --> isCont f x |]
  1569       ==> \<exists>L M. (\<forall>x. a \<le> x & x \<le> b --> L \<le> f(x) & f(x) \<le> M) &
  1570       ==> \<exists>L M::real. (\<forall>x. a \<le> x & x \<le> b --> L \<le> f(x) & f(x) \<le> M) &
  1570           (\<forall>y. L \<le> y & y \<le> M --> (\<exists>x. a \<le> x & x \<le> b & (f(x) = y)))"
  1571           (\<forall>y. L \<le> y & y \<le> M --> (\<exists>x. a \<le> x & x \<le> b & (f(x) = y)))"
  1571 apply (frule isCont_eq_Lb)
  1572 apply (frule isCont_eq_Lb)
  1572 apply (frule_tac [2] isCont_eq_Ub)
  1573 apply (frule_tac [2] isCont_eq_Ub)
  1573 apply (assumption+, safe)
  1574 apply (assumption+, safe)
  1574 apply (rule_tac x = "f x" in exI)
  1575 apply (rule_tac x = "f x" in exI)
  1923 
  1924 
  1924 text{*Dull lemma: an continuous injection on an interval must have a
  1925 text{*Dull lemma: an continuous injection on an interval must have a
  1925 strict maximum at an end point, not in the middle.*}
  1926 strict maximum at an end point, not in the middle.*}
  1926 
  1927 
  1927 lemma lemma_isCont_inj:
  1928 lemma lemma_isCont_inj:
       
  1929   fixes f :: "real \<Rightarrow> real"
  1928   assumes d: "0 < d"
  1930   assumes d: "0 < d"
  1929       and inj [rule_format]: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  1931       and inj [rule_format]: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  1930       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  1932       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  1931   shows "\<exists>z. \<bar>z-x\<bar> \<le> d & f x < f z"
  1933   shows "\<exists>z. \<bar>z-x\<bar> \<le> d & f x < f z"
  1932 proof (rule ccontr)
  1934 proof (rule ccontr)
  1964 
  1966 
  1965 
  1967 
  1966 text{*Similar version for lower bound.*}
  1968 text{*Similar version for lower bound.*}
  1967 
  1969 
  1968 lemma lemma_isCont_inj2:
  1970 lemma lemma_isCont_inj2:
  1969      "[|0 < d; \<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z;
  1971   fixes f g :: "real \<Rightarrow> real"
       
  1972   shows "[|0 < d; \<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z;
  1970         \<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z |]
  1973         \<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z |]
  1971       ==> \<exists>z. \<bar>z-x\<bar> \<le> d & f z < f x"
  1974       ==> \<exists>z. \<bar>z-x\<bar> \<le> d & f z < f x"
  1972 apply (insert lemma_isCont_inj
  1975 apply (insert lemma_isCont_inj
  1973           [where f = "%x. - f x" and g = "%y. g(-y)" and x = x and d = d])
  1976           [where f = "%x. - f x" and g = "%y. g(-y)" and x = x and d = d])
  1974 apply (simp add: isCont_minus linorder_not_le)
  1977 apply (simp add: isCont_minus linorder_not_le)
  1976 
  1979 
  1977 text{*Show there's an interval surrounding @{term "f(x)"} in
  1980 text{*Show there's an interval surrounding @{term "f(x)"} in
  1978 @{text "f[[x - d, x + d]]"} .*}
  1981 @{text "f[[x - d, x + d]]"} .*}
  1979 
  1982 
  1980 lemma isCont_inj_range:
  1983 lemma isCont_inj_range:
       
  1984   fixes f :: "real \<Rightarrow> real"
  1981   assumes d: "0 < d"
  1985   assumes d: "0 < d"
  1982       and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  1986       and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  1983       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  1987       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  1984   shows "\<exists>e>0. \<forall>y. \<bar>y - f x\<bar> \<le> e --> (\<exists>z. \<bar>z-x\<bar> \<le> d & f z = y)"
  1988   shows "\<exists>e>0. \<forall>y. \<bar>y - f x\<bar> \<le> e --> (\<exists>z. \<bar>z-x\<bar> \<le> d & f z = y)"
  1985 proof -
  1989 proof -
  2203 lemma LIMSEQ_SEQ_conv1:
  2207 lemma LIMSEQ_SEQ_conv1:
  2204   assumes "X -- a --> L"
  2208   assumes "X -- a --> L"
  2205   shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
  2209   shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
  2206 proof -
  2210 proof -
  2207   {
  2211   {
  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)
  2212     from prems have Xdef: "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> norm (X x + -L) < r" by (unfold LIM_def)
  2209     
  2213     
  2210     fix S
  2214     fix S
  2211     assume as: "(\<forall>n. S n \<noteq> a) \<and> S ----> a"
  2215     assume as: "(\<forall>n. S n \<noteq> a) \<and> S ----> a"
  2212     then have "S ----> a" by auto
  2216     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)
  2217     then have Sdef: "(\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> norm (S n + -a) < r))" by (unfold LIMSEQ_def)
  2214     {
  2218     {
  2215       fix r
  2219       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
  2220       from Xdef have Xdef2: "0 < r --> (\<exists>s > 0. \<forall>x. x \<noteq> a \<and> \<bar>x + -a\<bar> < s --> norm (X x + -L) < r)" by simp
  2217       {
  2221       {
  2218         assume rgz: "0 < r"
  2222         assume rgz: "0 < r"
  2219 
  2223 
  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 
  2224         from Xdef2 rgz have "\<exists>s > 0. \<forall>x. x \<noteq> a \<and> \<bar>x + -a\<bar> < s --> norm (X x + -L) < 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
  2225         then obtain s where sdef: "s > 0 \<and> (\<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s \<longrightarrow> norm (X x + -L) < 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
  2226         then have aux: "\<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s \<longrightarrow> norm (X x + -L) < r" by auto
  2223         {
  2227         {
  2224           fix n
  2228           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
  2229           from aux have "S n \<noteq> a \<and> \<bar>S n + -a\<bar> < s \<longrightarrow> norm (X (S n) + -L) < r" by simp
  2226           with as have imp2: "\<bar>S n + -a\<bar> < s --> \<bar>X (S n) + -L\<bar> < r" by auto
  2230           with as have imp2: "\<bar>S n + -a\<bar> < s --> norm (X (S n) + -L) < r" by auto
  2227         }
  2231         }
  2228         hence "\<forall>n. \<bar>S n + -a\<bar> < s --> \<bar>X (S n) + -L\<bar> < r" ..
  2232         hence "\<forall>n. \<bar>S n + -a\<bar> < s --> norm (X (S n) + -L) < r" ..
  2229         moreover
  2233         moreover
  2230         from Sdef sdef have imp1: "\<exists>no. \<forall>n. no \<le> n --> \<bar>S n + -a\<bar> < s" by auto  
  2234         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
  2235         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
  2236         ultimately have "\<forall>n. no \<le> n \<longrightarrow> norm (X (S n) + -L) < r" by simp
  2233         hence "\<exists>no. \<forall>n. no \<le> n \<longrightarrow> \<bar>X (S n) + -L\<bar> < r" by auto
  2237         hence "\<exists>no. \<forall>n. no \<le> n \<longrightarrow> norm (X (S n) + -L) < r" by auto
  2234       }
  2238       }
  2235     }
  2239     }
  2236     hence "(\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> \<bar>X (S n) + -L\<bar> < r))" by simp
  2240     hence "(\<forall>r. 0 < r --> (\<exists>no. \<forall>n. no \<le> n --> norm (X (S n) + -L) < r))" by simp
  2237     hence "(\<lambda>n. X (S n)) ----> L" by (fold LIMSEQ_def)
  2241     hence "(\<lambda>n. X (S n)) ----> L" by (fold LIMSEQ_def)
  2238   }
  2242   }
  2239   thus ?thesis by simp
  2243   thus ?thesis by simp
  2240 qed
  2244 qed
  2241 
  2245 
  2244 lemma LIMSEQ_SEQ_conv2:
  2248 lemma LIMSEQ_SEQ_conv2:
  2245   assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
  2249   assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
  2246   shows "X -- a --> L"
  2250   shows "X -- a --> L"
  2247 proof (rule ccontr)
  2251 proof (rule ccontr)
  2248   assume "\<not> (X -- a --> L)"
  2252   assume "\<not> (X -- a --> L)"
  2249   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)
  2253   hence "\<not> (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> norm (X x + -L) < r)" by (unfold LIM_def)
  2250   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
  2254   hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. \<not>(x \<noteq> a \<and> \<bar>x + -a\<bar> < s --> norm (X x + -L) < r)" by simp
  2251   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)
  2255   hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x + -a\<bar> < s \<and> norm (X x + -L) \<ge> r)" by (simp add: linorder_not_less)
  2252   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
  2256   then obtain r where rdef: "r > 0 \<and> (\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x + -a\<bar> < s \<and> norm (X x + -L) \<ge> r))" by auto
  2253 
  2257 
  2254   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"
  2258   let ?F = "\<lambda>n::nat. SOME x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> norm (X x + -L) \<ge> r"
  2255   have "?F ----> a"
  2259   have "?F ----> a"
  2256   proof -
  2260   proof -
  2257     {
  2261     {
  2258       fix e::real
  2262       fix e::real
  2259       assume "0 < e"
  2263       assume "0 < e"
  2268           by auto
  2272           by auto
  2269         moreover have
  2273         moreover have
  2270           "\<bar>?F n + -a\<bar> < inverse (real (Suc n))"
  2274           "\<bar>?F n + -a\<bar> < inverse (real (Suc n))"
  2271         proof -
  2275         proof -
  2272           from rdef have
  2276           from rdef have
  2273             "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X x + -L\<bar> \<ge> r"
  2277             "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> norm (X x + -L) \<ge> r"
  2274             by simp
  2278             by simp
  2275           hence
  2279           hence
  2276             "(?F n)\<noteq>a \<and> \<bar>(?F n) + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X (?F n) + -L\<bar> \<ge> r"
  2280             "(?F n)\<noteq>a \<and> \<bar>(?F n) + -a\<bar> < inverse (real (Suc n)) \<and> norm (X (?F n) + -L) \<ge> r"
  2277             by (simp add: some_eq_ex [symmetric])
  2281             by (simp add: some_eq_ex [symmetric])
  2278           thus ?thesis by simp
  2282           thus ?thesis by simp
  2279         qed
  2283         qed
  2280         moreover from nodef have
  2284         moreover from nodef have
  2281           "inverse (real (Suc m)) < e" .
  2285           "inverse (real (Suc m)) < e" .
  2289   moreover have "\<forall>n. ?F n \<noteq> a"
  2293   moreover have "\<forall>n. ?F n \<noteq> a"
  2290   proof -
  2294   proof -
  2291     {
  2295     {
  2292       fix n
  2296       fix n
  2293       from rdef have
  2297       from rdef have
  2294         "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> \<bar>X x + -L\<bar> \<ge> r"
  2298         "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> norm (X x + -L) \<ge> r"
  2295         by simp
  2299         by simp
  2296       hence "?F n \<noteq> a" by (simp add: some_eq_ex [symmetric])
  2300       hence "?F n \<noteq> a" by (simp add: some_eq_ex [symmetric])
  2297     }
  2301     }
  2298     thus ?thesis ..
  2302     thus ?thesis ..
  2299   qed
  2303   qed
  2305     {
  2309     {
  2306       fix no::nat
  2310       fix no::nat
  2307       obtain n where "n = no + 1" by simp
  2311       obtain n where "n = no + 1" by simp
  2308       then have nolen: "no \<le> n" by simp
  2312       then have nolen: "no \<le> n" by simp
  2309         (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
  2313         (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
  2310       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)" ..
  2314       from rdef have "\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x + -a\<bar> < s \<and> norm (X x + -L) \<ge> r)" ..
  2311 
  2315 
  2312       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
  2316       then have "\<exists>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < inverse (real (Suc n)) \<and> norm (X x + -L) \<ge> r" by simp
  2313       
  2317       
  2314       hence "\<bar>X (?F n) + -L\<bar> \<ge> r" by (simp add: some_eq_ex [symmetric])
  2318       hence "norm (X (?F n) + -L) \<ge> r" by (simp add: some_eq_ex [symmetric])
  2315       with nolen have "\<exists>n. no \<le> n \<and> \<bar>X (?F n) + -L\<bar> \<ge> r" by auto
  2319       with nolen have "\<exists>n. no \<le> n \<and> norm (X (?F n) + -L) \<ge> r" by auto
  2316     }
  2320     }
  2317     then have "(\<forall>no. \<exists>n. no \<le> n \<and> \<bar>X (?F n) + -L\<bar> \<ge> r)" by simp
  2321     then have "(\<forall>no. \<exists>n. no \<le> n \<and> norm (X (?F n) + -L) \<ge> r)" by simp
  2318     with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> \<bar>X (?F n) + -L\<bar> \<ge> e)" by auto
  2322     with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> norm (X (?F n) + -L) \<ge> e)" by auto
  2319     thus ?thesis by (unfold LIMSEQ_def, auto simp add: linorder_not_less)
  2323     thus ?thesis by (unfold LIMSEQ_def, auto simp add: linorder_not_less)
  2320   qed
  2324   qed
  2321   ultimately show False by simp
  2325   ultimately show False by simp
  2322 qed
  2326 qed
  2323 
  2327 
  2350   assumes "(\<lambda>x. f x) -- a --> L"
  2354   assumes "(\<lambda>x. f x) -- a --> L"
  2351   shows "(\<lambda>x. f (x+c)) -- (a-c) --> L"
  2355   shows "(\<lambda>x. f (x+c)) -- (a-c) --> L"
  2352 proof -
  2356 proof -
  2353   have "f -- a --> L" .
  2357   have "f -- a --> L" .
  2354   hence
  2358   hence
  2355     fd: "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> \<bar>f x + -L\<bar> < r"
  2359     fd: "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s --> norm (f x + -L) < r"
  2356     by (unfold LIM_def)
  2360     by (unfold LIM_def)
  2357   {
  2361   {
  2358     fix r::real
  2362     fix r::real
  2359     assume rgz: "0 < r"
  2363     assume rgz: "0 < r"
  2360     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
  2364     with fd have "\<exists>s > 0. \<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s --> norm (f x + -L) < r" by simp
  2361     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
  2365     then obtain s where sgz: "s > 0" and ax: "\<forall>x. x\<noteq>a \<and> \<bar>x + -a\<bar> < s \<longrightarrow> norm (f x + -L) < r" by auto
  2362     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
  2366     from ax have ax2: "\<forall>x. (x+c)\<noteq>a \<and> \<bar>(x+c) + -a\<bar> < s \<longrightarrow> norm (f (x+c) + -L) < r" by auto
  2363     {
  2367     {
  2364       fix x::real
  2368       fix x::real
  2365       from ax2 have nt: "(x+c)\<noteq>a \<and> \<bar>(x+c) + -a\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" ..
  2369       from ax2 have nt: "(x+c)\<noteq>a \<and> \<bar>(x+c) + -a\<bar> < s \<longrightarrow> norm (f (x+c) + -L) < r" ..
  2366       moreover have "((x+c)\<noteq>a) = (x\<noteq>(a-c))" by auto
  2370       moreover have "((x+c)\<noteq>a) = (x\<noteq>(a-c))" by auto
  2367       moreover have "((x+c) + -a) = (x + -(a-c))" by simp
  2371       moreover have "((x+c) + -a) = (x + -(a-c))" by simp
  2368       ultimately have "x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" by simp
  2372       ultimately have "x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> norm (f (x+c) + -L) < r" by simp
  2369     }
  2373     }
  2370     then have "\<forall>x. x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> \<bar>f (x+c) + -L\<bar> < r" ..
  2374     then have "\<forall>x. x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> norm (f (x+c) + -L) < r" ..
  2371     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
  2375     with sgz have "\<exists>s > 0. \<forall>x. x\<noteq>(a-c) \<and> \<bar>x + -(a-c)\<bar> < s \<longrightarrow> norm (f (x+c) + -L) < r" by auto
  2372   }
  2376   }
  2373   then have
  2377   then have
  2374     "\<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
  2378     "\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> (a-c) & \<bar>x + -(a-c)\<bar> < s --> norm (f (x+c) + -L) < r" by simp
  2375   thus ?thesis by (fold LIM_def)
  2379   thus ?thesis by (fold LIM_def)
  2376 qed
  2380 qed
  2377 
  2381 
  2378 end
  2382 end