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