src/HOL/Lim.thy
author hoelzl
Wed Sep 23 13:17:17 2009 +0200 (2009-09-23)
changeset 32650 34bfa2492298
parent 32642 026e7c6a6d08
child 36661 0a5b7b818d65
permissions -rw-r--r--
correct variable order in approximate-method
     1 (*  Title       : Lim.thy
     2     Author      : Jacques D. Fleuriot
     3     Copyright   : 1998  University of Cambridge
     4     Conversion to Isar and new proofs by Lawrence C Paulson, 2004
     5 *)
     6 
     7 header{* Limits and Continuity *}
     8 
     9 theory Lim
    10 imports SEQ
    11 begin
    12 
    13 text{*Standard Definitions*}
    14 
    15 definition
    16   LIM :: "['a::metric_space \<Rightarrow> 'b::metric_space, 'a, 'b] \<Rightarrow> bool"
    17         ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
    18   [code del]: "f -- a --> L =
    19      (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & dist x a < s
    20         --> dist (f x) L < r)"
    21 
    22 definition
    23   isCont :: "['a::metric_space \<Rightarrow> 'b::metric_space, 'a] \<Rightarrow> bool" where
    24   "isCont f a = (f -- a --> (f a))"
    25 
    26 definition
    27   isUCont :: "['a::metric_space \<Rightarrow> 'b::metric_space] \<Rightarrow> bool" where
    28   [code del]: "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. dist x y < s \<longrightarrow> dist (f x) (f y) < r)"
    29 
    30 subsection {* Limits of Functions *}
    31 
    32 lemma LIM_conv_tendsto: "(f -- a --> L) \<longleftrightarrow> (f ---> L) (at a)"
    33 unfolding LIM_def tendsto_iff eventually_at ..
    34 
    35 lemma metric_LIM_I:
    36   "(\<And>r. 0 < r \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r)
    37     \<Longrightarrow> f -- a --> L"
    38 by (simp add: LIM_def)
    39 
    40 lemma metric_LIM_D:
    41   "\<lbrakk>f -- a --> L; 0 < r\<rbrakk>
    42     \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r"
    43 by (simp add: LIM_def)
    44 
    45 lemma LIM_eq:
    46   fixes a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
    47   shows "f -- a --> L =
    48      (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)"
    49 by (simp add: LIM_def dist_norm)
    50 
    51 lemma LIM_I:
    52   fixes a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
    53   shows "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r)
    54       ==> f -- a --> L"
    55 by (simp add: LIM_eq)
    56 
    57 lemma LIM_D:
    58   fixes a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
    59   shows "[| f -- a --> L; 0<r |]
    60       ==> \<exists>s>0.\<forall>x. x \<noteq> a & norm (x-a) < s --> norm (f x - L) < r"
    61 by (simp add: LIM_eq)
    62 
    63 lemma LIM_offset:
    64   fixes a :: "'a::real_normed_vector" and L :: "'b::metric_space"
    65   shows "f -- a --> L \<Longrightarrow> (\<lambda>x. f (x + k)) -- a - k --> L"
    66 unfolding LIM_def dist_norm
    67 apply clarify
    68 apply (drule_tac x="r" in spec, safe)
    69 apply (rule_tac x="s" in exI, safe)
    70 apply (drule_tac x="x + k" in spec)
    71 apply (simp add: algebra_simps)
    72 done
    73 
    74 lemma LIM_offset_zero:
    75   fixes a :: "'a::real_normed_vector" and L :: "'b::metric_space"
    76   shows "f -- a --> L \<Longrightarrow> (\<lambda>h. f (a + h)) -- 0 --> L"
    77 by (drule_tac k="a" in LIM_offset, simp add: add_commute)
    78 
    79 lemma LIM_offset_zero_cancel:
    80   fixes a :: "'a::real_normed_vector" and L :: "'b::metric_space"
    81   shows "(\<lambda>h. f (a + h)) -- 0 --> L \<Longrightarrow> f -- a --> L"
    82 by (drule_tac k="- a" in LIM_offset, simp)
    83 
    84 lemma LIM_const [simp]: "(%x. k) -- x --> k"
    85 by (simp add: LIM_def)
    86 
    87 lemma LIM_cong_limit: "\<lbrakk> f -- x --> L ; K = L \<rbrakk> \<Longrightarrow> f -- x --> K" by simp
    88 
    89 lemma LIM_add:
    90   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    91   assumes f: "f -- a --> L" and g: "g -- a --> M"
    92   shows "(\<lambda>x. f x + g x) -- a --> (L + M)"
    93 using assms unfolding LIM_conv_tendsto by (rule tendsto_add)
    94 
    95 lemma LIM_add_zero:
    96   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    97   shows "\<lbrakk>f -- a --> 0; g -- a --> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. f x + g x) -- a --> 0"
    98 by (drule (1) LIM_add, simp)
    99 
   100 lemma minus_diff_minus:
   101   fixes a b :: "'a::ab_group_add"
   102   shows "(- a) - (- b) = - (a - b)"
   103 by simp
   104 
   105 lemma LIM_minus:
   106   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   107   shows "f -- a --> L \<Longrightarrow> (\<lambda>x. - f x) -- a --> - L"
   108 unfolding LIM_conv_tendsto by (rule tendsto_minus)
   109 
   110 (* TODO: delete *)
   111 lemma LIM_add_minus:
   112   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   113   shows "[| f -- x --> l; g -- x --> m |] ==> (%x. f(x) + -g(x)) -- x --> (l + -m)"
   114 by (intro LIM_add LIM_minus)
   115 
   116 lemma LIM_diff:
   117   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   118   shows "\<lbrakk>f -- x --> l; g -- x --> m\<rbrakk> \<Longrightarrow> (\<lambda>x. f x - g x) -- x --> l - m"
   119 unfolding LIM_conv_tendsto by (rule tendsto_diff)
   120 
   121 lemma LIM_zero:
   122   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   123   shows "f -- a --> l \<Longrightarrow> (\<lambda>x. f x - l) -- a --> 0"
   124 by (simp add: LIM_def dist_norm)
   125 
   126 lemma LIM_zero_cancel:
   127   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   128   shows "(\<lambda>x. f x - l) -- a --> 0 \<Longrightarrow> f -- a --> l"
   129 by (simp add: LIM_def dist_norm)
   130 
   131 lemma LIM_zero_iff:
   132   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   133   shows "(\<lambda>x. f x - l) -- a --> 0 = f -- a --> l"
   134 by (simp add: LIM_def dist_norm)
   135 
   136 lemma metric_LIM_imp_LIM:
   137   assumes f: "f -- a --> l"
   138   assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l"
   139   shows "g -- a --> m"
   140 apply (rule metric_LIM_I, drule metric_LIM_D [OF f], safe)
   141 apply (rule_tac x="s" in exI, safe)
   142 apply (drule_tac x="x" in spec, safe)
   143 apply (erule (1) order_le_less_trans [OF le])
   144 done
   145 
   146 lemma LIM_imp_LIM:
   147   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   148   fixes g :: "'a::metric_space \<Rightarrow> 'c::real_normed_vector"
   149   assumes f: "f -- a --> l"
   150   assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> norm (g x - m) \<le> norm (f x - l)"
   151   shows "g -- a --> m"
   152 apply (rule metric_LIM_imp_LIM [OF f])
   153 apply (simp add: dist_norm le)
   154 done
   155 
   156 lemma LIM_norm:
   157   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   158   shows "f -- a --> l \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> norm l"
   159 unfolding LIM_conv_tendsto by (rule tendsto_norm)
   160 
   161 lemma LIM_norm_zero:
   162   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   163   shows "f -- a --> 0 \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> 0"
   164 by (drule LIM_norm, simp)
   165 
   166 lemma LIM_norm_zero_cancel:
   167   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   168   shows "(\<lambda>x. norm (f x)) -- a --> 0 \<Longrightarrow> f -- a --> 0"
   169 by (erule LIM_imp_LIM, simp)
   170 
   171 lemma LIM_norm_zero_iff:
   172   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   173   shows "(\<lambda>x. norm (f x)) -- a --> 0 = f -- a --> 0"
   174 by (rule iffI [OF LIM_norm_zero_cancel LIM_norm_zero])
   175 
   176 lemma LIM_rabs: "f -- a --> (l::real) \<Longrightarrow> (\<lambda>x. \<bar>f x\<bar>) -- a --> \<bar>l\<bar>"
   177 by (fold real_norm_def, rule LIM_norm)
   178 
   179 lemma LIM_rabs_zero: "f -- a --> (0::real) \<Longrightarrow> (\<lambda>x. \<bar>f x\<bar>) -- a --> 0"
   180 by (fold real_norm_def, rule LIM_norm_zero)
   181 
   182 lemma LIM_rabs_zero_cancel: "(\<lambda>x. \<bar>f x\<bar>) -- a --> (0::real) \<Longrightarrow> f -- a --> 0"
   183 by (fold real_norm_def, rule LIM_norm_zero_cancel)
   184 
   185 lemma LIM_rabs_zero_iff: "(\<lambda>x. \<bar>f x\<bar>) -- a --> (0::real) = f -- a --> 0"
   186 by (fold real_norm_def, rule LIM_norm_zero_iff)
   187 
   188 lemma LIM_const_not_eq:
   189   fixes a :: "'a::real_normed_algebra_1"
   190   shows "k \<noteq> L \<Longrightarrow> \<not> (\<lambda>x. k) -- a --> L"
   191 apply (simp add: LIM_def)
   192 apply (rule_tac x="dist k L" in exI, simp add: zero_less_dist_iff, safe)
   193 apply (rule_tac x="a + of_real (s/2)" in exI, simp add: dist_norm)
   194 done
   195 
   196 lemmas LIM_not_zero = LIM_const_not_eq [where L = 0]
   197 
   198 lemma LIM_const_eq:
   199   fixes a :: "'a::real_normed_algebra_1"
   200   shows "(\<lambda>x. k) -- a --> L \<Longrightarrow> k = L"
   201 apply (rule ccontr)
   202 apply (blast dest: LIM_const_not_eq)
   203 done
   204 
   205 lemma LIM_unique:
   206   fixes a :: "'a::real_normed_algebra_1" -- {* TODO: find a more appropriate class *}
   207   shows "\<lbrakk>f -- a --> L; f -- a --> M\<rbrakk> \<Longrightarrow> L = M"
   208 apply (rule ccontr)
   209 apply (drule_tac r="dist L M / 2" in metric_LIM_D, simp add: zero_less_dist_iff)
   210 apply (drule_tac r="dist L M / 2" in metric_LIM_D, simp add: zero_less_dist_iff)
   211 apply (clarify, rename_tac r s)
   212 apply (subgoal_tac "min r s \<noteq> 0")
   213 apply (subgoal_tac "dist L M < dist L M / 2 + dist L M / 2", simp)
   214 apply (subgoal_tac "dist L M \<le> dist (f (a + of_real (min r s / 2))) L +
   215                                dist (f (a + of_real (min r s / 2))) M")
   216 apply (erule le_less_trans, rule add_strict_mono)
   217 apply (drule spec, erule mp, simp add: dist_norm)
   218 apply (drule spec, erule mp, simp add: dist_norm)
   219 apply (subst dist_commute, rule dist_triangle)
   220 apply simp
   221 done
   222 
   223 lemma LIM_ident [simp]: "(\<lambda>x. x) -- a --> a"
   224 by (auto simp add: LIM_def)
   225 
   226 text{*Limits are equal for functions equal except at limit point*}
   227 lemma LIM_equal:
   228      "[| \<forall>x. x \<noteq> a --> (f x = g x) |] ==> (f -- a --> l) = (g -- a --> l)"
   229 by (simp add: LIM_def)
   230 
   231 lemma LIM_cong:
   232   "\<lbrakk>a = b; \<And>x. x \<noteq> b \<Longrightarrow> f x = g x; l = m\<rbrakk>
   233    \<Longrightarrow> ((\<lambda>x. f x) -- a --> l) = ((\<lambda>x. g x) -- b --> m)"
   234 by (simp add: LIM_def)
   235 
   236 lemma metric_LIM_equal2:
   237   assumes 1: "0 < R"
   238   assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < R\<rbrakk> \<Longrightarrow> f x = g x"
   239   shows "g -- a --> l \<Longrightarrow> f -- a --> l"
   240 apply (unfold LIM_def, safe)
   241 apply (drule_tac x="r" in spec, safe)
   242 apply (rule_tac x="min s R" in exI, safe)
   243 apply (simp add: 1)
   244 apply (simp add: 2)
   245 done
   246 
   247 lemma LIM_equal2:
   248   fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
   249   assumes 1: "0 < R"
   250   assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; norm (x - a) < R\<rbrakk> \<Longrightarrow> f x = g x"
   251   shows "g -- a --> l \<Longrightarrow> f -- a --> l"
   252 apply (unfold LIM_def dist_norm, safe)
   253 apply (drule_tac x="r" in spec, safe)
   254 apply (rule_tac x="min s R" in exI, safe)
   255 apply (simp add: 1)
   256 apply (simp add: 2)
   257 done
   258 
   259 text{*Two uses in Transcendental.ML*}
   260 lemma LIM_trans:
   261   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   262   shows "[| (%x. f(x) + -g(x)) -- a --> 0;  g -- a --> l |] ==> f -- a --> l"
   263 apply (drule LIM_add, assumption)
   264 apply (auto simp add: add_assoc)
   265 done
   266 
   267 lemma LIM_compose:
   268   assumes g: "g -- l --> g l"
   269   assumes f: "f -- a --> l"
   270   shows "(\<lambda>x. g (f x)) -- a --> g l"
   271 proof (rule metric_LIM_I)
   272   fix r::real assume r: "0 < r"
   273   obtain s where s: "0 < s"
   274     and less_r: "\<And>y. \<lbrakk>y \<noteq> l; dist y l < s\<rbrakk> \<Longrightarrow> dist (g y) (g l) < r"
   275     using metric_LIM_D [OF g r] by fast
   276   obtain t where t: "0 < t"
   277     and less_s: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> dist (f x) l < s"
   278     using metric_LIM_D [OF f s] by fast
   279 
   280   show "\<exists>t>0. \<forall>x. x \<noteq> a \<and> dist x a < t \<longrightarrow> dist (g (f x)) (g l) < r"
   281   proof (rule exI, safe)
   282     show "0 < t" using t .
   283   next
   284     fix x assume "x \<noteq> a" and "dist x a < t"
   285     hence "dist (f x) l < s" by (rule less_s)
   286     thus "dist (g (f x)) (g l) < r"
   287       using r less_r by (case_tac "f x = l", simp_all)
   288   qed
   289 qed
   290 
   291 lemma metric_LIM_compose2:
   292   assumes f: "f -- a --> b"
   293   assumes g: "g -- b --> c"
   294   assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> b"
   295   shows "(\<lambda>x. g (f x)) -- a --> c"
   296 proof (rule metric_LIM_I)
   297   fix r :: real
   298   assume r: "0 < r"
   299   obtain s where s: "0 < s"
   300     and less_r: "\<And>y. \<lbrakk>y \<noteq> b; dist y b < s\<rbrakk> \<Longrightarrow> dist (g y) c < r"
   301     using metric_LIM_D [OF g r] by fast
   302   obtain t where t: "0 < t"
   303     and less_s: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> dist (f x) b < s"
   304     using metric_LIM_D [OF f s] by fast
   305   obtain d where d: "0 < d"
   306     and neq_b: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < d\<rbrakk> \<Longrightarrow> f x \<noteq> b"
   307     using inj by fast
   308 
   309   show "\<exists>t>0. \<forall>x. x \<noteq> a \<and> dist x a < t \<longrightarrow> dist (g (f x)) c < r"
   310   proof (safe intro!: exI)
   311     show "0 < min d t" using d t by simp
   312   next
   313     fix x
   314     assume "x \<noteq> a" and "dist x a < min d t"
   315     hence "f x \<noteq> b" and "dist (f x) b < s"
   316       using neq_b less_s by simp_all
   317     thus "dist (g (f x)) c < r"
   318       by (rule less_r)
   319   qed
   320 qed
   321 
   322 lemma LIM_compose2:
   323   fixes a :: "'a::real_normed_vector"
   324   assumes f: "f -- a --> b"
   325   assumes g: "g -- b --> c"
   326   assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> b"
   327   shows "(\<lambda>x. g (f x)) -- a --> c"
   328 by (rule metric_LIM_compose2 [OF f g inj [folded dist_norm]])
   329 
   330 lemma LIM_o: "\<lbrakk>g -- l --> g l; f -- a --> l\<rbrakk> \<Longrightarrow> (g \<circ> f) -- a --> g l"
   331 unfolding o_def by (rule LIM_compose)
   332 
   333 lemma real_LIM_sandwich_zero:
   334   fixes f g :: "'a::metric_space \<Rightarrow> real"
   335   assumes f: "f -- a --> 0"
   336   assumes 1: "\<And>x. x \<noteq> a \<Longrightarrow> 0 \<le> g x"
   337   assumes 2: "\<And>x. x \<noteq> a \<Longrightarrow> g x \<le> f x"
   338   shows "g -- a --> 0"
   339 proof (rule LIM_imp_LIM [OF f])
   340   fix x assume x: "x \<noteq> a"
   341   have "norm (g x - 0) = g x" by (simp add: 1 x)
   342   also have "g x \<le> f x" by (rule 2 [OF x])
   343   also have "f x \<le> \<bar>f x\<bar>" by (rule abs_ge_self)
   344   also have "\<bar>f x\<bar> = norm (f x - 0)" by simp
   345   finally show "norm (g x - 0) \<le> norm (f x - 0)" .
   346 qed
   347 
   348 text {* Bounded Linear Operators *}
   349 
   350 lemma (in bounded_linear) LIM:
   351   "g -- a --> l \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> f l"
   352 unfolding LIM_conv_tendsto by (rule tendsto)
   353 
   354 lemma (in bounded_linear) cont: "f -- a --> f a"
   355 by (rule LIM [OF LIM_ident])
   356 
   357 lemma (in bounded_linear) LIM_zero:
   358   "g -- a --> 0 \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> 0"
   359 by (drule LIM, simp only: zero)
   360 
   361 text {* Bounded Bilinear Operators *}
   362 
   363 lemma (in bounded_bilinear) LIM:
   364   "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
   365 unfolding LIM_conv_tendsto by (rule tendsto)
   366 
   367 lemma (in bounded_bilinear) LIM_prod_zero:
   368   fixes a :: "'d::metric_space"
   369   assumes f: "f -- a --> 0"
   370   assumes g: "g -- a --> 0"
   371   shows "(\<lambda>x. f x ** g x) -- a --> 0"
   372 using LIM [OF f g] by (simp add: zero_left)
   373 
   374 lemma (in bounded_bilinear) LIM_left_zero:
   375   "f -- a --> 0 \<Longrightarrow> (\<lambda>x. f x ** c) -- a --> 0"
   376 by (rule bounded_linear.LIM_zero [OF bounded_linear_left])
   377 
   378 lemma (in bounded_bilinear) LIM_right_zero:
   379   "f -- a --> 0 \<Longrightarrow> (\<lambda>x. c ** f x) -- a --> 0"
   380 by (rule bounded_linear.LIM_zero [OF bounded_linear_right])
   381 
   382 lemmas LIM_mult = mult.LIM
   383 
   384 lemmas LIM_mult_zero = mult.LIM_prod_zero
   385 
   386 lemmas LIM_mult_left_zero = mult.LIM_left_zero
   387 
   388 lemmas LIM_mult_right_zero = mult.LIM_right_zero
   389 
   390 lemmas LIM_scaleR = scaleR.LIM
   391 
   392 lemmas LIM_of_real = of_real.LIM
   393 
   394 lemma LIM_power:
   395   fixes f :: "'a::metric_space \<Rightarrow> 'b::{power,real_normed_algebra}"
   396   assumes f: "f -- a --> l"
   397   shows "(\<lambda>x. f x ^ n) -- a --> l ^ n"
   398 by (induct n, simp, simp add: LIM_mult f)
   399 
   400 subsubsection {* Derived theorems about @{term LIM} *}
   401 
   402 lemma LIM_inverse:
   403   fixes L :: "'a::real_normed_div_algebra"
   404   shows "\<lbrakk>f -- a --> L; L \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. inverse (f x)) -- a --> inverse L"
   405 unfolding LIM_conv_tendsto
   406 by (rule tendsto_inverse)
   407 
   408 lemma LIM_inverse_fun:
   409   assumes a: "a \<noteq> (0::'a::real_normed_div_algebra)"
   410   shows "inverse -- a --> inverse a"
   411 by (rule LIM_inverse [OF LIM_ident a])
   412 
   413 lemma LIM_sgn:
   414   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   415   shows "\<lbrakk>f -- a --> l; l \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. sgn (f x)) -- a --> sgn l"
   416 unfolding sgn_div_norm
   417 by (simp add: LIM_scaleR LIM_inverse LIM_norm)
   418 
   419 
   420 subsection {* Continuity *}
   421 
   422 lemma LIM_isCont_iff:
   423   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
   424   shows "(f -- a --> f a) = ((\<lambda>h. f (a + h)) -- 0 --> f a)"
   425 by (rule iffI [OF LIM_offset_zero LIM_offset_zero_cancel])
   426 
   427 lemma isCont_iff:
   428   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
   429   shows "isCont f x = (\<lambda>h. f (x + h)) -- 0 --> f x"
   430 by (simp add: isCont_def LIM_isCont_iff)
   431 
   432 lemma isCont_ident [simp]: "isCont (\<lambda>x. x) a"
   433   unfolding isCont_def by (rule LIM_ident)
   434 
   435 lemma isCont_const [simp]: "isCont (\<lambda>x. k) a"
   436   unfolding isCont_def by (rule LIM_const)
   437 
   438 lemma isCont_norm:
   439   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   440   shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. norm (f x)) a"
   441   unfolding isCont_def by (rule LIM_norm)
   442 
   443 lemma isCont_rabs: "isCont f a \<Longrightarrow> isCont (\<lambda>x. \<bar>f x :: real\<bar>) a"
   444   unfolding isCont_def by (rule LIM_rabs)
   445 
   446 lemma isCont_add:
   447   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   448   shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x + g x) a"
   449   unfolding isCont_def by (rule LIM_add)
   450 
   451 lemma isCont_minus:
   452   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   453   shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. - f x) a"
   454   unfolding isCont_def by (rule LIM_minus)
   455 
   456 lemma isCont_diff:
   457   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   458   shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x - g x) a"
   459   unfolding isCont_def by (rule LIM_diff)
   460 
   461 lemma isCont_mult:
   462   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_algebra"
   463   shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x * g x) a"
   464   unfolding isCont_def by (rule LIM_mult)
   465 
   466 lemma isCont_inverse:
   467   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_div_algebra"
   468   shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. inverse (f x)) a"
   469   unfolding isCont_def by (rule LIM_inverse)
   470 
   471 lemma isCont_LIM_compose:
   472   "\<lbrakk>isCont g l; f -- a --> l\<rbrakk> \<Longrightarrow> (\<lambda>x. g (f x)) -- a --> g l"
   473   unfolding isCont_def by (rule LIM_compose)
   474 
   475 lemma metric_isCont_LIM_compose2:
   476   assumes f [unfolded isCont_def]: "isCont f a"
   477   assumes g: "g -- f a --> l"
   478   assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
   479   shows "(\<lambda>x. g (f x)) -- a --> l"
   480 by (rule metric_LIM_compose2 [OF f g inj])
   481 
   482 lemma isCont_LIM_compose2:
   483   fixes a :: "'a::real_normed_vector"
   484   assumes f [unfolded isCont_def]: "isCont f a"
   485   assumes g: "g -- f a --> l"
   486   assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> f a"
   487   shows "(\<lambda>x. g (f x)) -- a --> l"
   488 by (rule LIM_compose2 [OF f g inj])
   489 
   490 lemma isCont_o2: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
   491   unfolding isCont_def by (rule LIM_compose)
   492 
   493 lemma isCont_o: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (g o f) a"
   494   unfolding o_def by (rule isCont_o2)
   495 
   496 lemma (in bounded_linear) isCont: "isCont f a"
   497   unfolding isCont_def by (rule cont)
   498 
   499 lemma (in bounded_bilinear) isCont:
   500   "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x ** g x) a"
   501   unfolding isCont_def by (rule LIM)
   502 
   503 lemmas isCont_scaleR = scaleR.isCont
   504 
   505 lemma isCont_of_real:
   506   "isCont f a \<Longrightarrow> isCont (\<lambda>x. of_real (f x)::'b::real_normed_algebra_1) a"
   507   unfolding isCont_def by (rule LIM_of_real)
   508 
   509 lemma isCont_power:
   510   fixes f :: "'a::metric_space \<Rightarrow> 'b::{power,real_normed_algebra}"
   511   shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. f x ^ n) a"
   512   unfolding isCont_def by (rule LIM_power)
   513 
   514 lemma isCont_sgn:
   515   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   516   shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. sgn (f x)) a"
   517   unfolding isCont_def by (rule LIM_sgn)
   518 
   519 lemma isCont_abs [simp]: "isCont abs (a::real)"
   520 by (rule isCont_rabs [OF isCont_ident])
   521 
   522 lemma isCont_setsum:
   523   fixes f :: "'a \<Rightarrow> 'b::metric_space \<Rightarrow> 'c::real_normed_vector"
   524   fixes A :: "'a set" assumes "finite A"
   525   shows "\<forall> i \<in> A. isCont (f i) x \<Longrightarrow> isCont (\<lambda> x. \<Sum> i \<in> A. f i x) x"
   526   using `finite A`
   527 proof induct
   528   case (insert a F) show "isCont (\<lambda> x. \<Sum> i \<in> (insert a F). f i x) x" 
   529     unfolding setsum_insert[OF `finite F` `a \<notin> F`] by (rule isCont_add, auto simp add: insert)
   530 qed auto
   531 
   532 lemma LIM_less_bound: fixes f :: "real \<Rightarrow> real" assumes "b < x"
   533   and all_le: "\<forall> x' \<in> { b <..< x}. 0 \<le> f x'" and isCont: "isCont f x"
   534   shows "0 \<le> f x"
   535 proof (rule ccontr)
   536   assume "\<not> 0 \<le> f x" hence "f x < 0" by auto
   537   hence "0 < - f x / 2" by auto
   538   from isCont[unfolded isCont_def, THEN LIM_D, OF this]
   539   obtain s where "s > 0" and s_D: "\<And>x'. \<lbrakk> x' \<noteq> x ; \<bar> x' - x \<bar> < s \<rbrakk> \<Longrightarrow> \<bar> f x' - f x \<bar> < - f x / 2" by auto
   540 
   541   let ?x = "x - min (s / 2) ((x - b) / 2)"
   542   have "?x < x" and "\<bar> ?x - x \<bar> < s"
   543     using `b < x` and `0 < s` by auto
   544   have "b < ?x"
   545   proof (cases "s < x - b")
   546     case True thus ?thesis using `0 < s` by auto
   547   next
   548     case False hence "s / 2 \<ge> (x - b) / 2" by auto
   549     hence "?x = (x + b) / 2" by (simp add: field_simps min_max.inf_absorb2)
   550     thus ?thesis using `b < x` by auto
   551   qed
   552   hence "0 \<le> f ?x" using all_le `?x < x` by auto
   553   moreover have "\<bar>f ?x - f x\<bar> < - f x / 2"
   554     using s_D[OF _ `\<bar> ?x - x \<bar> < s`] `?x < x` by auto
   555   hence "f ?x - f x < - f x / 2" by auto
   556   hence "f ?x < f x / 2" by auto
   557   hence "f ?x < 0" using `f x < 0` by auto
   558   thus False using `0 \<le> f ?x` by auto
   559 qed
   560 
   561 
   562 subsection {* Uniform Continuity *}
   563 
   564 lemma isUCont_isCont: "isUCont f ==> isCont f x"
   565 by (simp add: isUCont_def isCont_def LIM_def, force)
   566 
   567 lemma isUCont_Cauchy:
   568   "\<lbrakk>isUCont f; Cauchy X\<rbrakk> \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
   569 unfolding isUCont_def
   570 apply (rule metric_CauchyI)
   571 apply (drule_tac x=e in spec, safe)
   572 apply (drule_tac e=s in metric_CauchyD, safe)
   573 apply (rule_tac x=M in exI, simp)
   574 done
   575 
   576 lemma (in bounded_linear) isUCont: "isUCont f"
   577 unfolding isUCont_def dist_norm
   578 proof (intro allI impI)
   579   fix r::real assume r: "0 < r"
   580   obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
   581     using pos_bounded by fast
   582   show "\<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r"
   583   proof (rule exI, safe)
   584     from r K show "0 < r / K" by (rule divide_pos_pos)
   585   next
   586     fix x y :: 'a
   587     assume xy: "norm (x - y) < r / K"
   588     have "norm (f x - f y) = norm (f (x - y))" by (simp only: diff)
   589     also have "\<dots> \<le> norm (x - y) * K" by (rule norm_le)
   590     also from K xy have "\<dots> < r" by (simp only: pos_less_divide_eq)
   591     finally show "norm (f x - f y) < r" .
   592   qed
   593 qed
   594 
   595 lemma (in bounded_linear) Cauchy: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
   596 by (rule isUCont [THEN isUCont_Cauchy])
   597 
   598 
   599 subsection {* Relation of LIM and LIMSEQ *}
   600 
   601 lemma LIMSEQ_SEQ_conv1:
   602   fixes a :: "'a::metric_space"
   603   assumes X: "X -- a --> L"
   604   shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
   605 proof (safe intro!: metric_LIMSEQ_I)
   606   fix S :: "nat \<Rightarrow> 'a"
   607   fix r :: real
   608   assume rgz: "0 < r"
   609   assume as: "\<forall>n. S n \<noteq> a"
   610   assume S: "S ----> a"
   611   from metric_LIM_D [OF X rgz] obtain s
   612     where sgz: "0 < s"
   613     and aux: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < s\<rbrakk> \<Longrightarrow> dist (X x) L < r"
   614     by fast
   615   from metric_LIMSEQ_D [OF S sgz]
   616   obtain no where "\<forall>n\<ge>no. dist (S n) a < s" by blast
   617   hence "\<forall>n\<ge>no. dist (X (S n)) L < r" by (simp add: aux as)
   618   thus "\<exists>no. \<forall>n\<ge>no. dist (X (S n)) L < r" ..
   619 qed
   620 
   621 
   622 lemma LIMSEQ_SEQ_conv2:
   623   fixes a :: real
   624   assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
   625   shows "X -- a --> L"
   626 proof (rule ccontr)
   627   assume "\<not> (X -- a --> L)"
   628   hence "\<not> (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & norm (x - a) < s --> dist (X x) L < r)"
   629     unfolding LIM_def dist_norm .
   630   hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. \<not>(x \<noteq> a \<and> \<bar>x - a\<bar> < s --> dist (X x) L < r)" by simp
   631   hence "\<exists>r > 0. \<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x - a\<bar> < s \<and> dist (X x) L \<ge> r)" by (simp add: not_less)
   632   then obtain r where rdef: "r > 0 \<and> (\<forall>s > 0. \<exists>x. (x \<noteq> a \<and> \<bar>x - a\<bar> < s \<and> dist (X x) L \<ge> r))" by auto
   633 
   634   let ?F = "\<lambda>n::nat. SOME x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> dist (X x) L \<ge> r"
   635   have "\<And>n. \<exists>x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> dist (X x) L \<ge> r"
   636     using rdef by simp
   637   hence F: "\<And>n. ?F n \<noteq> a \<and> \<bar>?F n - a\<bar> < inverse (real (Suc n)) \<and> dist (X (?F n)) L \<ge> r"
   638     by (rule someI_ex)
   639   hence F1: "\<And>n. ?F n \<noteq> a"
   640     and F2: "\<And>n. \<bar>?F n - a\<bar> < inverse (real (Suc n))"
   641     and F3: "\<And>n. dist (X (?F n)) L \<ge> r"
   642     by fast+
   643 
   644   have "?F ----> a"
   645   proof (rule LIMSEQ_I, unfold real_norm_def)
   646       fix e::real
   647       assume "0 < e"
   648         (* choose no such that inverse (real (Suc n)) < e *)
   649       then have "\<exists>no. inverse (real (Suc no)) < e" by (rule reals_Archimedean)
   650       then obtain m where nodef: "inverse (real (Suc m)) < e" by auto
   651       show "\<exists>no. \<forall>n. no \<le> n --> \<bar>?F n - a\<bar> < e"
   652       proof (intro exI allI impI)
   653         fix n
   654         assume mlen: "m \<le> n"
   655         have "\<bar>?F n - a\<bar> < inverse (real (Suc n))"
   656           by (rule F2)
   657         also have "inverse (real (Suc n)) \<le> inverse (real (Suc m))"
   658           using mlen by auto
   659         also from nodef have
   660           "inverse (real (Suc m)) < e" .
   661         finally show "\<bar>?F n - a\<bar> < e" .
   662       qed
   663   qed
   664   
   665   moreover have "\<forall>n. ?F n \<noteq> a"
   666     by (rule allI) (rule F1)
   667 
   668   moreover from prems have "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by simp
   669   ultimately have "(\<lambda>n. X (?F n)) ----> L" by simp
   670   
   671   moreover have "\<not> ((\<lambda>n. X (?F n)) ----> L)"
   672   proof -
   673     {
   674       fix no::nat
   675       obtain n where "n = no + 1" by simp
   676       then have nolen: "no \<le> n" by simp
   677         (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
   678       have "dist (X (?F n)) L \<ge> r"
   679         by (rule F3)
   680       with nolen have "\<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> r" by fast
   681     }
   682     then have "(\<forall>no. \<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> r)" by simp
   683     with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> e)" by auto
   684     thus ?thesis by (unfold LIMSEQ_def, auto simp add: not_less)
   685   qed
   686   ultimately show False by simp
   687 qed
   688 
   689 lemma LIMSEQ_SEQ_conv:
   690   "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::real) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
   691    (X -- a --> L)"
   692 proof
   693   assume "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
   694   thus "X -- a --> L" by (rule LIMSEQ_SEQ_conv2)
   695 next
   696   assume "(X -- a --> L)"
   697   thus "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by (rule LIMSEQ_SEQ_conv1)
   698 qed
   699 
   700 end