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