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