src/HOL/Lim.thy
author huffman
Mon Jun 01 10:36:42 2009 -0700 (2009-06-01)
changeset 31355 3d18766ddc4b
parent 31353 14a58e2ca374
child 31392 69570155ddf8
permissions -rw-r--r--
limits of inverse using filters
     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:
   417   fixes L :: "'a::real_normed_div_algebra"
   418   shows "\<lbrakk>f -- a --> L; L \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. inverse (f x)) -- a --> inverse L"
   419 unfolding LIM_conv_tendsto
   420 by (rule tendsto_inverse)
   421 
   422 lemma LIM_inverse_fun:
   423   assumes a: "a \<noteq> (0::'a::real_normed_div_algebra)"
   424   shows "inverse -- a --> inverse a"
   425 by (rule LIM_inverse [OF LIM_ident a])
   426 
   427 lemma LIM_sgn:
   428   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   429   shows "\<lbrakk>f -- a --> l; l \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>x. sgn (f x)) -- a --> sgn l"
   430 unfolding sgn_div_norm
   431 by (simp add: LIM_scaleR LIM_inverse LIM_norm)
   432 
   433 
   434 subsection {* Continuity *}
   435 
   436 lemma LIM_isCont_iff:
   437   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
   438   shows "(f -- a --> f a) = ((\<lambda>h. f (a + h)) -- 0 --> f a)"
   439 by (rule iffI [OF LIM_offset_zero LIM_offset_zero_cancel])
   440 
   441 lemma isCont_iff:
   442   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::metric_space"
   443   shows "isCont f x = (\<lambda>h. f (x + h)) -- 0 --> f x"
   444 by (simp add: isCont_def LIM_isCont_iff)
   445 
   446 lemma isCont_ident [simp]: "isCont (\<lambda>x. x) a"
   447   unfolding isCont_def by (rule LIM_ident)
   448 
   449 lemma isCont_const [simp]: "isCont (\<lambda>x. k) a"
   450   unfolding isCont_def by (rule LIM_const)
   451 
   452 lemma isCont_norm:
   453   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   454   shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. norm (f x)) a"
   455   unfolding isCont_def by (rule LIM_norm)
   456 
   457 lemma isCont_rabs: "isCont f a \<Longrightarrow> isCont (\<lambda>x. \<bar>f x :: real\<bar>) a"
   458   unfolding isCont_def by (rule LIM_rabs)
   459 
   460 lemma isCont_add:
   461   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   462   shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x + g x) a"
   463   unfolding isCont_def by (rule LIM_add)
   464 
   465 lemma isCont_minus:
   466   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   467   shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. - f x) a"
   468   unfolding isCont_def by (rule LIM_minus)
   469 
   470 lemma isCont_diff:
   471   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   472   shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x - g x) a"
   473   unfolding isCont_def by (rule LIM_diff)
   474 
   475 lemma isCont_mult:
   476   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_algebra"
   477   shows "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x * g x) a"
   478   unfolding isCont_def by (rule LIM_mult)
   479 
   480 lemma isCont_inverse:
   481   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_div_algebra"
   482   shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. inverse (f x)) a"
   483   unfolding isCont_def by (rule LIM_inverse)
   484 
   485 lemma isCont_LIM_compose:
   486   "\<lbrakk>isCont g l; f -- a --> l\<rbrakk> \<Longrightarrow> (\<lambda>x. g (f x)) -- a --> g l"
   487   unfolding isCont_def by (rule LIM_compose)
   488 
   489 lemma metric_isCont_LIM_compose2:
   490   assumes f [unfolded isCont_def]: "isCont f a"
   491   assumes g: "g -- f a --> l"
   492   assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
   493   shows "(\<lambda>x. g (f x)) -- a --> l"
   494 by (rule metric_LIM_compose2 [OF f g inj])
   495 
   496 lemma isCont_LIM_compose2:
   497   fixes a :: "'a::real_normed_vector"
   498   assumes f [unfolded isCont_def]: "isCont f a"
   499   assumes g: "g -- f a --> l"
   500   assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> f a"
   501   shows "(\<lambda>x. g (f x)) -- a --> l"
   502 by (rule LIM_compose2 [OF f g inj])
   503 
   504 lemma isCont_o2: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. g (f x)) a"
   505   unfolding isCont_def by (rule LIM_compose)
   506 
   507 lemma isCont_o: "\<lbrakk>isCont f a; isCont g (f a)\<rbrakk> \<Longrightarrow> isCont (g o f) a"
   508   unfolding o_def by (rule isCont_o2)
   509 
   510 lemma (in bounded_linear) isCont: "isCont f a"
   511   unfolding isCont_def by (rule cont)
   512 
   513 lemma (in bounded_bilinear) isCont:
   514   "\<lbrakk>isCont f a; isCont g a\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. f x ** g x) a"
   515   unfolding isCont_def by (rule LIM)
   516 
   517 lemmas isCont_scaleR = scaleR.isCont
   518 
   519 lemma isCont_of_real:
   520   "isCont f a \<Longrightarrow> isCont (\<lambda>x. of_real (f x)::'b::real_normed_algebra_1) a"
   521   unfolding isCont_def by (rule LIM_of_real)
   522 
   523 lemma isCont_power:
   524   fixes f :: "'a::metric_space \<Rightarrow> 'b::{power,real_normed_algebra}"
   525   shows "isCont f a \<Longrightarrow> isCont (\<lambda>x. f x ^ n) a"
   526   unfolding isCont_def by (rule LIM_power)
   527 
   528 lemma isCont_sgn:
   529   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   530   shows "\<lbrakk>isCont f a; f a \<noteq> 0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. sgn (f x)) a"
   531   unfolding isCont_def by (rule LIM_sgn)
   532 
   533 lemma isCont_abs [simp]: "isCont abs (a::real)"
   534 by (rule isCont_rabs [OF isCont_ident])
   535 
   536 lemma isCont_setsum:
   537   fixes f :: "'a \<Rightarrow> 'b::metric_space \<Rightarrow> 'c::real_normed_vector"
   538   fixes A :: "'a set" assumes "finite A"
   539   shows "\<forall> i \<in> A. isCont (f i) x \<Longrightarrow> isCont (\<lambda> x. \<Sum> i \<in> A. f i x) x"
   540   using `finite A`
   541 proof induct
   542   case (insert a F) show "isCont (\<lambda> x. \<Sum> i \<in> (insert a F). f i x) x" 
   543     unfolding setsum_insert[OF `finite F` `a \<notin> F`] by (rule isCont_add, auto simp add: insert)
   544 qed auto
   545 
   546 lemma LIM_less_bound: fixes f :: "real \<Rightarrow> real" assumes "b < x"
   547   and all_le: "\<forall> x' \<in> { b <..< x}. 0 \<le> f x'" and isCont: "isCont f x"
   548   shows "0 \<le> f x"
   549 proof (rule ccontr)
   550   assume "\<not> 0 \<le> f x" hence "f x < 0" by auto
   551   hence "0 < - f x / 2" by auto
   552   from isCont[unfolded isCont_def, THEN LIM_D, OF this]
   553   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
   554 
   555   let ?x = "x - min (s / 2) ((x - b) / 2)"
   556   have "?x < x" and "\<bar> ?x - x \<bar> < s"
   557     using `b < x` and `0 < s` by auto
   558   have "b < ?x"
   559   proof (cases "s < x - b")
   560     case True thus ?thesis using `0 < s` by auto
   561   next
   562     case False hence "s / 2 \<ge> (x - b) / 2" by auto
   563     from inf_absorb2[OF this, unfolded inf_real_def]
   564     have "?x = (x + b) / 2" by auto
   565     thus ?thesis using `b < x` by auto
   566   qed
   567   hence "0 \<le> f ?x" using all_le `?x < x` by auto
   568   moreover have "\<bar>f ?x - f x\<bar> < - f x / 2"
   569     using s_D[OF _ `\<bar> ?x - x \<bar> < s`] `?x < x` by auto
   570   hence "f ?x - f x < - f x / 2" by auto
   571   hence "f ?x < f x / 2" by auto
   572   hence "f ?x < 0" using `f x < 0` by auto
   573   thus False using `0 \<le> f ?x` by auto
   574 qed
   575 
   576 
   577 subsection {* Uniform Continuity *}
   578 
   579 lemma isUCont_isCont: "isUCont f ==> isCont f x"
   580 by (simp add: isUCont_def isCont_def LIM_def, force)
   581 
   582 lemma isUCont_Cauchy:
   583   "\<lbrakk>isUCont f; Cauchy X\<rbrakk> \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
   584 unfolding isUCont_def
   585 apply (rule metric_CauchyI)
   586 apply (drule_tac x=e in spec, safe)
   587 apply (drule_tac e=s in metric_CauchyD, safe)
   588 apply (rule_tac x=M in exI, simp)
   589 done
   590 
   591 lemma (in bounded_linear) isUCont: "isUCont f"
   592 unfolding isUCont_def dist_norm
   593 proof (intro allI impI)
   594   fix r::real assume r: "0 < r"
   595   obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
   596     using pos_bounded by fast
   597   show "\<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r"
   598   proof (rule exI, safe)
   599     from r K show "0 < r / K" by (rule divide_pos_pos)
   600   next
   601     fix x y :: 'a
   602     assume xy: "norm (x - y) < r / K"
   603     have "norm (f x - f y) = norm (f (x - y))" by (simp only: diff)
   604     also have "\<dots> \<le> norm (x - y) * K" by (rule norm_le)
   605     also from K xy have "\<dots> < r" by (simp only: pos_less_divide_eq)
   606     finally show "norm (f x - f y) < r" .
   607   qed
   608 qed
   609 
   610 lemma (in bounded_linear) Cauchy: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
   611 by (rule isUCont [THEN isUCont_Cauchy])
   612 
   613 
   614 subsection {* Relation of LIM and LIMSEQ *}
   615 
   616 lemma LIMSEQ_SEQ_conv1:
   617   fixes a :: "'a::metric_space"
   618   assumes X: "X -- a --> L"
   619   shows "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
   620 proof (safe intro!: metric_LIMSEQ_I)
   621   fix S :: "nat \<Rightarrow> 'a"
   622   fix r :: real
   623   assume rgz: "0 < r"
   624   assume as: "\<forall>n. S n \<noteq> a"
   625   assume S: "S ----> a"
   626   from metric_LIM_D [OF X rgz] obtain s
   627     where sgz: "0 < s"
   628     and aux: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < s\<rbrakk> \<Longrightarrow> dist (X x) L < r"
   629     by fast
   630   from metric_LIMSEQ_D [OF S sgz]
   631   obtain no where "\<forall>n\<ge>no. dist (S n) a < s" by blast
   632   hence "\<forall>n\<ge>no. dist (X (S n)) L < r" by (simp add: aux as)
   633   thus "\<exists>no. \<forall>n\<ge>no. dist (X (S n)) L < r" ..
   634 qed
   635 
   636 
   637 lemma LIMSEQ_SEQ_conv2:
   638   fixes a :: real
   639   assumes "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
   640   shows "X -- a --> L"
   641 proof (rule ccontr)
   642   assume "\<not> (X -- a --> L)"
   643   hence "\<not> (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & norm (x - a) < s --> dist (X x) L < r)"
   644     unfolding LIM_def dist_norm .
   645   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
   646   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)
   647   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
   648 
   649   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"
   650   have "\<And>n. \<exists>x. x\<noteq>a \<and> \<bar>x - a\<bar> < inverse (real (Suc n)) \<and> dist (X x) L \<ge> r"
   651     using rdef by simp
   652   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"
   653     by (rule someI_ex)
   654   hence F1: "\<And>n. ?F n \<noteq> a"
   655     and F2: "\<And>n. \<bar>?F n - a\<bar> < inverse (real (Suc n))"
   656     and F3: "\<And>n. dist (X (?F n)) L \<ge> r"
   657     by fast+
   658 
   659   have "?F ----> a"
   660   proof (rule LIMSEQ_I, unfold real_norm_def)
   661       fix e::real
   662       assume "0 < e"
   663         (* choose no such that inverse (real (Suc n)) < e *)
   664       then have "\<exists>no. inverse (real (Suc no)) < e" by (rule reals_Archimedean)
   665       then obtain m where nodef: "inverse (real (Suc m)) < e" by auto
   666       show "\<exists>no. \<forall>n. no \<le> n --> \<bar>?F n - a\<bar> < e"
   667       proof (intro exI allI impI)
   668         fix n
   669         assume mlen: "m \<le> n"
   670         have "\<bar>?F n - a\<bar> < inverse (real (Suc n))"
   671           by (rule F2)
   672         also have "inverse (real (Suc n)) \<le> inverse (real (Suc m))"
   673           using mlen by auto
   674         also from nodef have
   675           "inverse (real (Suc m)) < e" .
   676         finally show "\<bar>?F n - a\<bar> < e" .
   677       qed
   678   qed
   679   
   680   moreover have "\<forall>n. ?F n \<noteq> a"
   681     by (rule allI) (rule F1)
   682 
   683   moreover from prems have "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by simp
   684   ultimately have "(\<lambda>n. X (?F n)) ----> L" by simp
   685   
   686   moreover have "\<not> ((\<lambda>n. X (?F n)) ----> L)"
   687   proof -
   688     {
   689       fix no::nat
   690       obtain n where "n = no + 1" by simp
   691       then have nolen: "no \<le> n" by simp
   692         (* We prove this by showing that for any m there is an n\<ge>m such that |X (?F n) - L| \<ge> r *)
   693       have "dist (X (?F n)) L \<ge> r"
   694         by (rule F3)
   695       with nolen have "\<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> r" by fast
   696     }
   697     then have "(\<forall>no. \<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> r)" by simp
   698     with rdef have "\<exists>e>0. (\<forall>no. \<exists>n. no \<le> n \<and> dist (X (?F n)) L \<ge> e)" by auto
   699     thus ?thesis by (unfold LIMSEQ_def, auto simp add: not_less)
   700   qed
   701   ultimately show False by simp
   702 qed
   703 
   704 lemma LIMSEQ_SEQ_conv:
   705   "(\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> (a::real) \<longrightarrow> (\<lambda>n. X (S n)) ----> L) =
   706    (X -- a --> L)"
   707 proof
   708   assume "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L"
   709   thus "X -- a --> L" by (rule LIMSEQ_SEQ_conv2)
   710 next
   711   assume "(X -- a --> L)"
   712   thus "\<forall>S. (\<forall>n. S n \<noteq> a) \<and> S ----> a \<longrightarrow> (\<lambda>n. X (S n)) ----> L" by (rule LIMSEQ_SEQ_conv1)
   713 qed
   714 
   715 end