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