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