src/HOL/Analysis/Uniform_Limit.thy
author immler
Fri Mar 10 23:16:40 2017 +0100 (2017-03-10)
changeset 65204 d23eded35a33
parent 65037 2cf841ff23be
child 66827 c94531b5007d
permissions -rw-r--r--
modernized construction of type bcontfun; base explicit theorems on Uniform_Limit.thy; added some lemmas
     1 (*  Title:      HOL/Analysis/Uniform_Limit.thy
     2     Author:     Christoph Traut, TU München
     3     Author:     Fabian Immler, TU München
     4 *)
     5 
     6 section \<open>Uniform Limit and Uniform Convergence\<close>
     7 
     8 theory Uniform_Limit
     9 imports Topology_Euclidean_Space Summation_Tests
    10 begin
    11 
    12 definition uniformly_on :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::metric_space) \<Rightarrow> ('a \<Rightarrow> 'b) filter"
    13   where "uniformly_on S l = (INF e:{0 <..}. principal {f. \<forall>x\<in>S. dist (f x) (l x) < e})"
    14 
    15 abbreviation
    16   "uniform_limit S f l \<equiv> filterlim f (uniformly_on S l)"
    17 
    18 definition uniformly_convergent_on where
    19   "uniformly_convergent_on X f \<longleftrightarrow> (\<exists>l. uniform_limit X f l sequentially)"
    20 
    21 definition uniformly_Cauchy_on where
    22   "uniformly_Cauchy_on X f \<longleftrightarrow> (\<forall>e>0. \<exists>M. \<forall>x\<in>X. \<forall>(m::nat)\<ge>M. \<forall>n\<ge>M. dist (f m x) (f n x) < e)"
    23 
    24 lemma uniform_limit_iff:
    25   "uniform_limit S f l F \<longleftrightarrow> (\<forall>e>0. \<forall>\<^sub>F n in F. \<forall>x\<in>S. dist (f n x) (l x) < e)"
    26   unfolding filterlim_iff uniformly_on_def
    27   by (subst eventually_INF_base)
    28     (fastforce
    29       simp: eventually_principal uniformly_on_def
    30       intro: bexI[where x="min a b" for a b]
    31       elim: eventually_mono)+
    32 
    33 lemma uniform_limitD:
    34   "uniform_limit S f l F \<Longrightarrow> e > 0 \<Longrightarrow> \<forall>\<^sub>F n in F. \<forall>x\<in>S. dist (f n x) (l x) < e"
    35   by (simp add: uniform_limit_iff)
    36 
    37 lemma uniform_limitI:
    38   "(\<And>e. e > 0 \<Longrightarrow> \<forall>\<^sub>F n in F. \<forall>x\<in>S. dist (f n x) (l x) < e) \<Longrightarrow> uniform_limit S f l F"
    39   by (simp add: uniform_limit_iff)
    40 
    41 lemma uniform_limit_sequentially_iff:
    42   "uniform_limit S f l sequentially \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x \<in> S. dist (f n x) (l x) < e)"
    43   unfolding uniform_limit_iff eventually_sequentially ..
    44 
    45 lemma uniform_limit_at_iff:
    46   "uniform_limit S f l (at x) \<longleftrightarrow>
    47     (\<forall>e>0. \<exists>d>0. \<forall>z. 0 < dist z x \<and> dist z x < d \<longrightarrow> (\<forall>x\<in>S. dist (f z x) (l x) < e))"
    48   unfolding uniform_limit_iff eventually_at by simp
    49 
    50 lemma uniform_limit_at_le_iff:
    51   "uniform_limit S f l (at x) \<longleftrightarrow>
    52     (\<forall>e>0. \<exists>d>0. \<forall>z. 0 < dist z x \<and> dist z x < d \<longrightarrow> (\<forall>x\<in>S. dist (f z x) (l x) \<le> e))"
    53   unfolding uniform_limit_iff eventually_at
    54   by (fastforce dest: spec[where x = "e / 2" for e])
    55 
    56 lemma metric_uniform_limit_imp_uniform_limit:
    57   assumes f: "uniform_limit S f a F"
    58   assumes le: "eventually (\<lambda>x. \<forall>y\<in>S. dist (g x y) (b y) \<le> dist (f x y) (a y)) F"
    59   shows "uniform_limit S g b F"
    60 proof (rule uniform_limitI)
    61   fix e :: real assume "0 < e"
    62   from uniform_limitD[OF f this] le
    63   show "\<forall>\<^sub>F x in F. \<forall>y\<in>S. dist (g x y) (b y) < e"
    64     by eventually_elim force
    65 qed
    66 
    67 lemma swap_uniform_limit:
    68   assumes f: "\<forall>\<^sub>F n in F. (f n \<longlongrightarrow> g n) (at x within S)"
    69   assumes g: "(g \<longlongrightarrow> l) F"
    70   assumes uc: "uniform_limit S f h F"
    71   assumes "\<not>trivial_limit F"
    72   shows "(h \<longlongrightarrow> l) (at x within S)"
    73 proof (rule tendstoI)
    74   fix e :: real
    75   define e' where "e' = e/3"
    76   assume "0 < e"
    77   then have "0 < e'" by (simp add: e'_def)
    78   from uniform_limitD[OF uc \<open>0 < e'\<close>]
    79   have "\<forall>\<^sub>F n in F. \<forall>x\<in>S. dist (h x) (f n x) < e'"
    80     by (simp add: dist_commute)
    81   moreover
    82   from f
    83   have "\<forall>\<^sub>F n in F. \<forall>\<^sub>F x in at x within S. dist (g n) (f n x) < e'"
    84     by eventually_elim (auto dest!: tendstoD[OF _ \<open>0 < e'\<close>] simp: dist_commute)
    85   moreover
    86   from tendstoD[OF g \<open>0 < e'\<close>] have "\<forall>\<^sub>F x in F. dist l (g x) < e'"
    87     by (simp add: dist_commute)
    88   ultimately
    89   have "\<forall>\<^sub>F _ in F. \<forall>\<^sub>F x in at x within S. dist (h x) l < e"
    90   proof eventually_elim
    91     case (elim n)
    92     note fh = elim(1)
    93     note gl = elim(3)
    94     have "\<forall>\<^sub>F x in at x within S. x \<in> S"
    95       by (auto simp: eventually_at_filter)
    96     with elim(2)
    97     show ?case
    98     proof eventually_elim
    99       case (elim x)
   100       from fh[rule_format, OF \<open>x \<in> S\<close>] elim(1)
   101       have "dist (h x) (g n) < e' + e'"
   102         by (rule dist_triangle_lt[OF add_strict_mono])
   103       from dist_triangle_lt[OF add_strict_mono, OF this gl]
   104       show ?case by (simp add: e'_def)
   105     qed
   106   qed
   107   thus "\<forall>\<^sub>F x in at x within S. dist (h x) l < e"
   108     using eventually_happens by (metis \<open>\<not>trivial_limit F\<close>)
   109 qed
   110 
   111 lemma
   112   tendsto_uniform_limitI:
   113   assumes "uniform_limit S f l F"
   114   assumes "x \<in> S"
   115   shows "((\<lambda>y. f y x) \<longlongrightarrow> l x) F"
   116   using assms
   117   by (auto intro!: tendstoI simp: eventually_mono dest!: uniform_limitD)
   118 
   119 lemma uniform_limit_theorem:
   120   assumes c: "\<forall>\<^sub>F n in F. continuous_on A (f n)"
   121   assumes ul: "uniform_limit A f l F"
   122   assumes "\<not> trivial_limit F"
   123   shows "continuous_on A l"
   124   unfolding continuous_on_def
   125 proof safe
   126   fix x assume "x \<in> A"
   127   then have "\<forall>\<^sub>F n in F. (f n \<longlongrightarrow> f n x) (at x within A)" "((\<lambda>n. f n x) \<longlongrightarrow> l x) F"
   128     using c ul
   129     by (auto simp: continuous_on_def eventually_mono tendsto_uniform_limitI)
   130   then show "(l \<longlongrightarrow> l x) (at x within A)"
   131     by (rule swap_uniform_limit) fact+
   132 qed
   133 
   134 lemma uniformly_Cauchy_onI:
   135   assumes "\<And>e. e > 0 \<Longrightarrow> \<exists>M. \<forall>x\<in>X. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (f m x) (f n x) < e"
   136   shows   "uniformly_Cauchy_on X f"
   137   using assms unfolding uniformly_Cauchy_on_def by blast
   138 
   139 lemma uniformly_Cauchy_onI':
   140   assumes "\<And>e. e > 0 \<Longrightarrow> \<exists>M. \<forall>x\<in>X. \<forall>m\<ge>M. \<forall>n>m. dist (f m x) (f n x) < e"
   141   shows   "uniformly_Cauchy_on X f"
   142 proof (rule uniformly_Cauchy_onI)
   143   fix e :: real assume e: "e > 0"
   144   from assms[OF this] obtain M
   145     where M: "\<And>x m n. x \<in> X \<Longrightarrow> m \<ge> M \<Longrightarrow> n > m \<Longrightarrow> dist (f m x) (f n x) < e" by fast
   146   {
   147     fix x m n assume x: "x \<in> X" and m: "m \<ge> M" and n: "n \<ge> M"
   148     with M[OF this(1,2), of n] M[OF this(1,3), of m] e have "dist (f m x) (f n x) < e"
   149       by (cases m n rule: linorder_cases) (simp_all add: dist_commute)
   150   }
   151   thus "\<exists>M. \<forall>x\<in>X. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (f m x) (f n x) < e" by fast
   152 qed
   153 
   154 lemma uniformly_Cauchy_imp_Cauchy:
   155   "uniformly_Cauchy_on X f \<Longrightarrow> x \<in> X \<Longrightarrow> Cauchy (\<lambda>n. f n x)"
   156   unfolding Cauchy_def uniformly_Cauchy_on_def by fast
   157 
   158 lemma uniform_limit_cong:
   159   fixes f g :: "'a \<Rightarrow> 'b \<Rightarrow> ('c :: metric_space)" and h i :: "'b \<Rightarrow> 'c"
   160   assumes "eventually (\<lambda>y. \<forall>x\<in>X. f y x = g y x) F"
   161   assumes "\<And>x. x \<in> X \<Longrightarrow> h x = i x"
   162   shows   "uniform_limit X f h F \<longleftrightarrow> uniform_limit X g i F"
   163 proof -
   164   {
   165     fix f g :: "'a \<Rightarrow> 'b \<Rightarrow> 'c" and h i :: "'b \<Rightarrow> 'c"
   166     assume C: "uniform_limit X f h F" and A: "eventually (\<lambda>y. \<forall>x\<in>X. f y x = g y x) F"
   167        and B: "\<And>x. x \<in> X \<Longrightarrow> h x = i x"
   168     {
   169       fix e ::real assume "e > 0"
   170       with C have "eventually (\<lambda>y. \<forall>x\<in>X. dist (f y x) (h x) < e) F"
   171         unfolding uniform_limit_iff by blast
   172       with A have "eventually (\<lambda>y. \<forall>x\<in>X. dist (g y x) (i x) < e) F"
   173         by eventually_elim (insert B, simp_all)
   174     }
   175     hence "uniform_limit X g i F" unfolding uniform_limit_iff by blast
   176   } note A = this
   177   show ?thesis by (rule iffI) (erule A; insert assms; simp add: eq_commute)+
   178 qed
   179 
   180 lemma uniform_limit_cong':
   181   fixes f g :: "'a \<Rightarrow> 'b \<Rightarrow> ('c :: metric_space)" and h i :: "'b \<Rightarrow> 'c"
   182   assumes "\<And>y x. x \<in> X \<Longrightarrow> f y x = g y x"
   183   assumes "\<And>x. x \<in> X \<Longrightarrow> h x = i x"
   184   shows   "uniform_limit X f h F \<longleftrightarrow> uniform_limit X g i F"
   185   using assms by (intro uniform_limit_cong always_eventually) blast+
   186 
   187 lemma uniformly_convergent_uniform_limit_iff:
   188   "uniformly_convergent_on X f \<longleftrightarrow> uniform_limit X f (\<lambda>x. lim (\<lambda>n. f n x)) sequentially"
   189 proof
   190   assume "uniformly_convergent_on X f"
   191   then obtain l where l: "uniform_limit X f l sequentially"
   192     unfolding uniformly_convergent_on_def by blast
   193   from l have "uniform_limit X f (\<lambda>x. lim (\<lambda>n. f n x)) sequentially \<longleftrightarrow>
   194                       uniform_limit X f l sequentially"
   195     by (intro uniform_limit_cong' limI tendsto_uniform_limitI[of f X l]) simp_all
   196   also note l
   197   finally show "uniform_limit X f (\<lambda>x. lim (\<lambda>n. f n x)) sequentially" .
   198 qed (auto simp: uniformly_convergent_on_def)
   199 
   200 lemma uniformly_convergentI: "uniform_limit X f l sequentially \<Longrightarrow> uniformly_convergent_on X f"
   201   unfolding uniformly_convergent_on_def by blast
   202 
   203 lemma uniformly_convergent_on_empty [iff]: "uniformly_convergent_on {} f"
   204   by (simp add: uniformly_convergent_on_def uniform_limit_sequentially_iff)
   205 
   206 text\<open>Cauchy-type criteria for uniform convergence.\<close>
   207 
   208 lemma Cauchy_uniformly_convergent:
   209   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b :: complete_space"
   210   assumes "uniformly_Cauchy_on X f"
   211   shows   "uniformly_convergent_on X f"
   212 unfolding uniformly_convergent_uniform_limit_iff uniform_limit_iff
   213 proof safe
   214   let ?f = "\<lambda>x. lim (\<lambda>n. f n x)"
   215   fix e :: real assume e: "e > 0"
   216   hence "e/2 > 0" by simp
   217   with assms obtain N where N: "\<And>x m n. x \<in> X \<Longrightarrow> m \<ge> N \<Longrightarrow> n \<ge> N \<Longrightarrow> dist (f m x) (f n x) < e/2"
   218     unfolding uniformly_Cauchy_on_def by fast
   219   show "eventually (\<lambda>n. \<forall>x\<in>X. dist (f n x) (?f x) < e) sequentially"
   220     using eventually_ge_at_top[of N]
   221   proof eventually_elim
   222     fix n assume n: "n \<ge> N"
   223     show "\<forall>x\<in>X. dist (f n x) (?f x) < e"
   224     proof
   225       fix x assume x: "x \<in> X"
   226       with assms have "(\<lambda>n. f n x) \<longlonglongrightarrow> ?f x"
   227         by (auto dest!: Cauchy_convergent uniformly_Cauchy_imp_Cauchy simp: convergent_LIMSEQ_iff)
   228       with \<open>e/2 > 0\<close> have "eventually (\<lambda>m. m \<ge> N \<and> dist (f m x) (?f x) < e/2) sequentially"
   229         by (intro tendstoD eventually_conj eventually_ge_at_top)
   230       then obtain m where m: "m \<ge> N" "dist (f m x) (?f x) < e/2"
   231         unfolding eventually_at_top_linorder by blast
   232       have "dist (f n x) (?f x) \<le> dist (f n x) (f m x) + dist (f m x) (?f x)"
   233           by (rule dist_triangle)
   234       also from x n have "... < e/2 + e/2" by (intro add_strict_mono N m)
   235       finally show "dist (f n x) (?f x) < e" by simp
   236     qed
   237   qed
   238 qed
   239 
   240 lemma uniformly_convergent_Cauchy:
   241   assumes "uniformly_convergent_on X f"
   242   shows "uniformly_Cauchy_on X f"
   243 proof (rule uniformly_Cauchy_onI)
   244   fix e::real assume "e > 0"
   245   then have "0 < e / 2" by simp
   246   with assms[unfolded uniformly_convergent_on_def uniform_limit_sequentially_iff]
   247   obtain l N where l:"x \<in> X \<Longrightarrow> n \<ge> N \<Longrightarrow> dist (f n x) (l x) < e / 2" for n x
   248     by metis
   249   from l l have "x \<in> X \<Longrightarrow> n \<ge> N \<Longrightarrow> m \<ge> N \<Longrightarrow> dist (f n x) (f m x) < e" for n m x
   250     by (rule dist_triangle_half_l)
   251   then show "\<exists>M. \<forall>x\<in>X. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (f m x) (f n x) < e" by blast
   252 qed
   253 
   254 lemma uniformly_convergent_eq_Cauchy:
   255   "uniformly_convergent_on X f = uniformly_Cauchy_on X f" for f::"nat \<Rightarrow> 'b \<Rightarrow> 'a::complete_space"
   256   using Cauchy_uniformly_convergent uniformly_convergent_Cauchy by blast
   257 
   258 lemma uniformly_convergent_eq_cauchy:
   259   fixes s::"nat \<Rightarrow> 'b \<Rightarrow> 'a::complete_space"
   260   shows
   261     "(\<exists>l. \<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e) \<longleftrightarrow>
   262       (\<forall>e>0. \<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  \<longrightarrow> dist (s m x) (s n x) < e)"
   263 proof -
   264   have *: "(\<forall>n\<ge>N. \<forall>x. Q x \<longrightarrow> R n x) \<longleftrightarrow> (\<forall>n x. N \<le> n \<and> Q x \<longrightarrow> R n x)"
   265     "(\<forall>x. Q x \<longrightarrow> (\<forall>m\<ge>N. \<forall>n\<ge>N. S n m x)) \<longleftrightarrow> (\<forall>m n x. N \<le> m \<and> N \<le> n \<and> Q x \<longrightarrow> S n m x)"
   266     for N::nat and Q::"'b \<Rightarrow> bool" and R S
   267     by blast+
   268   show ?thesis
   269     using uniformly_convergent_eq_Cauchy[of "Collect P" s]
   270     unfolding uniformly_convergent_on_def uniformly_Cauchy_on_def uniform_limit_sequentially_iff
   271     by (simp add: *)
   272 qed
   273 
   274 lemma uniformly_cauchy_imp_uniformly_convergent:
   275   fixes s :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::complete_space"
   276   assumes "\<forall>e>0.\<exists>N. \<forall>m (n::nat) x. N \<le> m \<and> N \<le> n \<and> P x --> dist(s m x)(s n x) < e"
   277     and "\<forall>x. P x --> (\<forall>e>0. \<exists>N. \<forall>n. N \<le> n \<longrightarrow> dist(s n x)(l x) < e)"
   278   shows "\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e"
   279 proof -
   280   obtain l' where l:"\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l' x) < e"
   281     using assms(1) unfolding uniformly_convergent_eq_cauchy[symmetric] by auto
   282   moreover
   283   {
   284     fix x
   285     assume "P x"
   286     then have "l x = l' x"
   287       using tendsto_unique[OF trivial_limit_sequentially, of "\<lambda>n. s n x" "l x" "l' x"]
   288       using l and assms(2) unfolding lim_sequentially by blast
   289   }
   290   ultimately show ?thesis by auto
   291 qed
   292 
   293 text \<open>TODO: remove explicit formulations
   294   @{thm uniformly_convergent_eq_cauchy uniformly_cauchy_imp_uniformly_convergent}?!\<close>
   295 
   296 lemma uniformly_convergent_imp_convergent:
   297   "uniformly_convergent_on X f \<Longrightarrow> x \<in> X \<Longrightarrow> convergent (\<lambda>n. f n x)"
   298   unfolding uniformly_convergent_on_def convergent_def
   299   by (auto dest: tendsto_uniform_limitI)
   300 
   301 lemma weierstrass_m_test_ev:
   302 fixes f :: "_ \<Rightarrow> _ \<Rightarrow> _ :: banach"
   303 assumes "eventually (\<lambda>n. \<forall>x\<in>A. norm (f n x) \<le> M n) sequentially"
   304 assumes "summable M"
   305 shows "uniform_limit A (\<lambda>n x. \<Sum>i<n. f i x) (\<lambda>x. suminf (\<lambda>i. f i x)) sequentially"
   306 proof (rule uniform_limitI)
   307   fix e :: real
   308   assume "0 < e"
   309   from suminf_exist_split[OF \<open>0 < e\<close> \<open>summable M\<close>]
   310   have "\<forall>\<^sub>F k in sequentially. norm (\<Sum>i. M (i + k)) < e"
   311     by (auto simp: eventually_sequentially)
   312   with eventually_all_ge_at_top[OF assms(1)]
   313     show "\<forall>\<^sub>F n in sequentially. \<forall>x\<in>A. dist (\<Sum>i<n. f i x) (\<Sum>i. f i x) < e"
   314   proof eventually_elim
   315     case (elim k)
   316     show ?case
   317     proof safe
   318       fix x assume "x \<in> A"
   319       have "\<exists>N. \<forall>n\<ge>N. norm (f n x) \<le> M n"
   320         using assms(1) \<open>x \<in> A\<close> by (force simp: eventually_at_top_linorder)
   321       hence summable_norm_f: "summable (\<lambda>n. norm (f n x))"
   322         by(rule summable_norm_comparison_test[OF _ \<open>summable M\<close>])
   323       have summable_f: "summable (\<lambda>n. f n x)"
   324         using summable_norm_cancel[OF summable_norm_f] .
   325       have summable_norm_f_plus_k: "summable (\<lambda>i. norm (f (i + k) x))"
   326         using summable_ignore_initial_segment[OF summable_norm_f]
   327         by auto
   328       have summable_M_plus_k: "summable (\<lambda>i. M (i + k))"
   329         using summable_ignore_initial_segment[OF \<open>summable M\<close>]
   330         by auto
   331 
   332       have "dist (\<Sum>i<k. f i x) (\<Sum>i. f i x) = norm ((\<Sum>i. f i x) - (\<Sum>i<k. f i x))"
   333         using dist_norm dist_commute by (subst dist_commute)
   334       also have "... = norm (\<Sum>i. f (i + k) x)"
   335         using suminf_minus_initial_segment[OF summable_f, where k=k] by simp
   336       also have "... \<le> (\<Sum>i. norm (f (i + k) x))"
   337         using summable_norm[OF summable_norm_f_plus_k] .
   338       also have "... \<le> (\<Sum>i. M (i + k))"
   339         by (rule suminf_le[OF _ summable_norm_f_plus_k summable_M_plus_k])
   340            (insert elim(1) \<open>x \<in> A\<close>, simp)
   341       finally show "dist (\<Sum>i<k. f i x) (\<Sum>i. f i x) < e"
   342         using elim by auto
   343     qed
   344   qed
   345 qed
   346 
   347 text\<open>Alternative version, formulated as in HOL Light\<close>
   348 corollary series_comparison_uniform:
   349   fixes f :: "_ \<Rightarrow> nat \<Rightarrow> _ :: banach"
   350   assumes g: "summable g" and le: "\<And>n x. N \<le> n \<and> x \<in> A \<Longrightarrow> norm(f x n) \<le> g n"
   351     shows "\<exists>l. \<forall>e. 0 < e \<longrightarrow> (\<exists>N. \<forall>n x. N \<le> n \<and> x \<in> A \<longrightarrow> dist(sum (f x) {..<n}) (l x) < e)"
   352 proof -
   353   have 1: "\<forall>\<^sub>F n in sequentially. \<forall>x\<in>A. norm (f x n) \<le> g n"
   354     using le eventually_sequentially by auto
   355   show ?thesis
   356     apply (rule_tac x="(\<lambda>x. \<Sum>i. f x i)" in exI)
   357     apply (metis (no_types, lifting) eventually_sequentially uniform_limitD [OF weierstrass_m_test_ev [OF 1 g]])
   358     done
   359 qed
   360 
   361 corollary weierstrass_m_test:
   362   fixes f :: "_ \<Rightarrow> _ \<Rightarrow> _ :: banach"
   363   assumes "\<And>n x. x \<in> A \<Longrightarrow> norm (f n x) \<le> M n"
   364   assumes "summable M"
   365   shows "uniform_limit A (\<lambda>n x. \<Sum>i<n. f i x) (\<lambda>x. suminf (\<lambda>i. f i x)) sequentially"
   366   using assms by (intro weierstrass_m_test_ev always_eventually) auto
   367 
   368 corollary weierstrass_m_test'_ev:
   369   fixes f :: "_ \<Rightarrow> _ \<Rightarrow> _ :: banach"
   370   assumes "eventually (\<lambda>n. \<forall>x\<in>A. norm (f n x) \<le> M n) sequentially" "summable M"
   371   shows   "uniformly_convergent_on A (\<lambda>n x. \<Sum>i<n. f i x)"
   372   unfolding uniformly_convergent_on_def by (rule exI, rule weierstrass_m_test_ev[OF assms])
   373 
   374 corollary weierstrass_m_test':
   375   fixes f :: "_ \<Rightarrow> _ \<Rightarrow> _ :: banach"
   376   assumes "\<And>n x. x \<in> A \<Longrightarrow> norm (f n x) \<le> M n" "summable M"
   377   shows   "uniformly_convergent_on A (\<lambda>n x. \<Sum>i<n. f i x)"
   378   unfolding uniformly_convergent_on_def by (rule exI, rule weierstrass_m_test[OF assms])
   379 
   380 lemma uniform_limit_eq_rhs: "uniform_limit X f l F \<Longrightarrow> l = m \<Longrightarrow> uniform_limit X f m F"
   381   by simp
   382 
   383 named_theorems uniform_limit_intros "introduction rules for uniform_limit"
   384 setup \<open>
   385   Global_Theory.add_thms_dynamic (@{binding uniform_limit_eq_intros},
   386     fn context =>
   387       Named_Theorems.get (Context.proof_of context) @{named_theorems uniform_limit_intros}
   388       |> map_filter (try (fn thm => @{thm uniform_limit_eq_rhs} OF [thm])))
   389 \<close>
   390 
   391 lemma (in bounded_linear) uniform_limit[uniform_limit_intros]:
   392   assumes "uniform_limit X g l F"
   393   shows "uniform_limit X (\<lambda>a b. f (g a b)) (\<lambda>a. f (l a)) F"
   394 proof (rule uniform_limitI)
   395   fix e::real
   396   from pos_bounded obtain K
   397     where K: "\<And>x y. dist (f x) (f y) \<le> K * dist x y" "K > 0"
   398     by (auto simp: ac_simps dist_norm diff[symmetric])
   399   assume "0 < e" with \<open>K > 0\<close> have "e / K > 0" by simp
   400   from uniform_limitD[OF assms this]
   401   show "\<forall>\<^sub>F n in F. \<forall>x\<in>X. dist (f (g n x)) (f (l x)) < e"
   402     by eventually_elim (metis le_less_trans mult.commute pos_less_divide_eq K)
   403 qed
   404 
   405 lemmas bounded_linear_uniform_limit_intros[uniform_limit_intros] =
   406   bounded_linear.uniform_limit[OF bounded_linear_Im]
   407   bounded_linear.uniform_limit[OF bounded_linear_Re]
   408   bounded_linear.uniform_limit[OF bounded_linear_cnj]
   409   bounded_linear.uniform_limit[OF bounded_linear_fst]
   410   bounded_linear.uniform_limit[OF bounded_linear_snd]
   411   bounded_linear.uniform_limit[OF bounded_linear_zero]
   412   bounded_linear.uniform_limit[OF bounded_linear_of_real]
   413   bounded_linear.uniform_limit[OF bounded_linear_inner_left]
   414   bounded_linear.uniform_limit[OF bounded_linear_inner_right]
   415   bounded_linear.uniform_limit[OF bounded_linear_divide]
   416   bounded_linear.uniform_limit[OF bounded_linear_scaleR_right]
   417   bounded_linear.uniform_limit[OF bounded_linear_mult_left]
   418   bounded_linear.uniform_limit[OF bounded_linear_mult_right]
   419   bounded_linear.uniform_limit[OF bounded_linear_scaleR_left]
   420 
   421 lemmas uniform_limit_uminus[uniform_limit_intros] =
   422   bounded_linear.uniform_limit[OF bounded_linear_minus[OF bounded_linear_ident]]
   423 
   424 lemma uniform_limit_const[uniform_limit_intros]: "uniform_limit S (\<lambda>x. c) c f"
   425   by (auto intro!: uniform_limitI)
   426 
   427 lemma uniform_limit_add[uniform_limit_intros]:
   428   fixes f g::"'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
   429   assumes "uniform_limit X f l F"
   430   assumes "uniform_limit X g m F"
   431   shows "uniform_limit X (\<lambda>a b. f a b + g a b) (\<lambda>a. l a + m a) F"
   432 proof (rule uniform_limitI)
   433   fix e::real
   434   assume "0 < e"
   435   hence "0 < e / 2" by simp
   436   from
   437     uniform_limitD[OF assms(1) this]
   438     uniform_limitD[OF assms(2) this]
   439   show "\<forall>\<^sub>F n in F. \<forall>x\<in>X. dist (f n x + g n x) (l x + m x) < e"
   440     by eventually_elim (simp add: dist_triangle_add_half)
   441 qed
   442 
   443 lemma uniform_limit_minus[uniform_limit_intros]:
   444   fixes f g::"'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
   445   assumes "uniform_limit X f l F"
   446   assumes "uniform_limit X g m F"
   447   shows "uniform_limit X (\<lambda>a b. f a b - g a b) (\<lambda>a. l a - m a) F"
   448   unfolding diff_conv_add_uminus
   449   by (rule uniform_limit_intros assms)+
   450 
   451 lemma uniform_limit_norm[uniform_limit_intros]:
   452   assumes "uniform_limit S g l f"
   453   shows "uniform_limit S (\<lambda>x y. norm (g x y)) (\<lambda>x. norm (l x)) f"
   454   using assms
   455   apply (rule metric_uniform_limit_imp_uniform_limit)
   456   apply (rule eventuallyI)
   457   by (metis dist_norm norm_triangle_ineq3 real_norm_def)
   458 
   459 lemma (in bounded_bilinear) bounded_uniform_limit[uniform_limit_intros]:
   460   assumes "uniform_limit X f l F"
   461   assumes "uniform_limit X g m F"
   462   assumes "bounded (m ` X)"
   463   assumes "bounded (l ` X)"
   464   shows "uniform_limit X (\<lambda>a b. prod (f a b) (g a b)) (\<lambda>a. prod (l a) (m a)) F"
   465 proof (rule uniform_limitI)
   466   fix e::real
   467   from pos_bounded obtain K where K:
   468     "0 < K" "\<And>a b. norm (prod a b) \<le> norm a * norm b * K"
   469     by auto
   470   hence "sqrt (K*4) > 0" by simp
   471 
   472   from assms obtain Km Kl
   473   where Km: "Km > 0" "\<And>x. x \<in> X \<Longrightarrow> norm (m x) \<le> Km"
   474     and Kl: "Kl > 0" "\<And>x. x \<in> X \<Longrightarrow> norm (l x) \<le> Kl"
   475     by (auto simp: bounded_pos)
   476   hence "K * Km * 4 > 0" "K * Kl * 4 > 0"
   477     using \<open>K > 0\<close>
   478     by simp_all
   479   assume "0 < e"
   480 
   481   hence "sqrt e > 0" by simp
   482   from uniform_limitD[OF assms(1) divide_pos_pos[OF this \<open>sqrt (K*4) > 0\<close>]]
   483     uniform_limitD[OF assms(2) divide_pos_pos[OF this \<open>sqrt (K*4) > 0\<close>]]
   484     uniform_limitD[OF assms(1) divide_pos_pos[OF \<open>e > 0\<close> \<open>K * Km * 4 > 0\<close>]]
   485     uniform_limitD[OF assms(2) divide_pos_pos[OF \<open>e > 0\<close> \<open>K * Kl * 4 > 0\<close>]]
   486   show "\<forall>\<^sub>F n in F. \<forall>x\<in>X. dist (prod (f n x) (g n x)) (prod (l x) (m x)) < e"
   487   proof eventually_elim
   488     case (elim n)
   489     show ?case
   490     proof safe
   491       fix x assume "x \<in> X"
   492       have "dist (prod (f n x) (g n x)) (prod (l x) (m x)) \<le>
   493         norm (prod (f n x - l x) (g n x - m x)) +
   494         norm (prod (f n x - l x) (m x)) +
   495         norm (prod (l x) (g n x - m x))"
   496         by (auto simp: dist_norm prod_diff_prod intro: order_trans norm_triangle_ineq add_mono)
   497       also note K(2)[of "f n x - l x" "g n x - m x"]
   498       also from elim(1)[THEN bspec, OF \<open>_ \<in> X\<close>, unfolded dist_norm]
   499       have "norm (f n x - l x) \<le> sqrt e / sqrt (K * 4)"
   500         by simp
   501       also from elim(2)[THEN bspec, OF \<open>_ \<in> X\<close>, unfolded dist_norm]
   502       have "norm (g n x - m x) \<le> sqrt e / sqrt (K * 4)"
   503         by simp
   504       also have "sqrt e / sqrt (K * 4) * (sqrt e / sqrt (K * 4)) * K = e / 4"
   505         using \<open>K > 0\<close> \<open>e > 0\<close> by auto
   506       also note K(2)[of "f n x - l x" "m x"]
   507       also note K(2)[of "l x" "g n x - m x"]
   508       also from elim(3)[THEN bspec, OF \<open>_ \<in> X\<close>, unfolded dist_norm]
   509       have "norm (f n x - l x) \<le> e / (K * Km * 4)"
   510         by simp
   511       also from elim(4)[THEN bspec, OF \<open>_ \<in> X\<close>, unfolded dist_norm]
   512       have "norm (g n x - m x) \<le> e / (K * Kl * 4)"
   513         by simp
   514       also note Kl(2)[OF \<open>_ \<in> X\<close>]
   515       also note Km(2)[OF \<open>_ \<in> X\<close>]
   516       also have "e / (K * Km * 4) * Km * K = e / 4"
   517         using \<open>K > 0\<close> \<open>Km > 0\<close> by simp
   518       also have " Kl * (e / (K * Kl * 4)) * K = e / 4"
   519         using \<open>K > 0\<close> \<open>Kl > 0\<close> by simp
   520       also have "e / 4 + e / 4 + e / 4 < e" using \<open>e > 0\<close> by simp
   521       finally show "dist (prod (f n x) (g n x)) (prod (l x) (m x)) < e"
   522         using \<open>K > 0\<close> \<open>Kl > 0\<close> \<open>Km > 0\<close> \<open>e > 0\<close>
   523         by (simp add: algebra_simps mult_right_mono divide_right_mono)
   524     qed
   525   qed
   526 qed
   527 
   528 lemmas bounded_bilinear_bounded_uniform_limit_intros[uniform_limit_intros] =
   529   bounded_bilinear.bounded_uniform_limit[OF Inner_Product.bounded_bilinear_inner]
   530   bounded_bilinear.bounded_uniform_limit[OF Real_Vector_Spaces.bounded_bilinear_mult]
   531   bounded_bilinear.bounded_uniform_limit[OF Real_Vector_Spaces.bounded_bilinear_scaleR]
   532 
   533 lemma uniform_lim_mult:
   534   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_algebra"
   535   assumes f: "uniform_limit S f l F"
   536       and g: "uniform_limit S g m F"
   537       and l: "bounded (l ` S)"
   538       and m: "bounded (m ` S)"
   539     shows "uniform_limit S (\<lambda>a b. f a b * g a b) (\<lambda>a. l a * m a) F"
   540   by (intro bounded_bilinear_bounded_uniform_limit_intros assms)
   541 
   542 lemma uniform_lim_inverse:
   543   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_field"
   544   assumes f: "uniform_limit S f l F"
   545       and b: "\<And>x. x \<in> S \<Longrightarrow> b \<le> norm(l x)"
   546       and "b > 0"
   547     shows "uniform_limit S (\<lambda>x y. inverse (f x y)) (inverse \<circ> l) F"
   548 proof (rule uniform_limitI)
   549   fix e::real
   550   assume "e > 0"
   551   have lte: "dist (inverse (f x y)) ((inverse \<circ> l) y) < e"
   552            if "b/2 \<le> norm (f x y)" "norm (f x y - l y) < e * b\<^sup>2 / 2" "y \<in> S"
   553            for x y
   554   proof -
   555     have [simp]: "l y \<noteq> 0" "f x y \<noteq> 0"
   556       using \<open>b > 0\<close> that b [OF \<open>y \<in> S\<close>] by fastforce+
   557     have "norm (l y - f x y) <  e * b\<^sup>2 / 2"
   558       by (metis norm_minus_commute that(2))
   559     also have "... \<le> e * (norm (f x y) * norm (l y))"
   560       using \<open>e > 0\<close> that b [OF \<open>y \<in> S\<close>] apply (simp add: power2_eq_square)
   561       by (metis \<open>b > 0\<close> less_eq_real_def mult.left_commute mult_mono')
   562     finally show ?thesis
   563       by (auto simp: dist_norm divide_simps norm_mult norm_divide)
   564   qed
   565   have "\<forall>\<^sub>F n in F. \<forall>x\<in>S. dist (f n x) (l x) < b/2"
   566     using uniform_limitD [OF f, of "b/2"] by (simp add: \<open>b > 0\<close>)
   567   then have "\<forall>\<^sub>F x in F. \<forall>y\<in>S. b/2 \<le> norm (f x y)"
   568     apply (rule eventually_mono)
   569     using b apply (simp only: dist_norm)
   570     by (metis (no_types, hide_lams) diff_zero dist_commute dist_norm norm_triangle_half_l not_less)
   571   then have "\<forall>\<^sub>F x in F. \<forall>y\<in>S. b/2 \<le> norm (f x y) \<and> norm (f x y - l y) < e * b\<^sup>2 / 2"
   572     apply (simp only: ball_conj_distrib dist_norm [symmetric])
   573     apply (rule eventually_conj, assumption)
   574       apply (rule uniform_limitD [OF f, of "e * b ^ 2 / 2"])
   575     using \<open>b > 0\<close> \<open>e > 0\<close> by auto
   576   then show "\<forall>\<^sub>F x in F. \<forall>y\<in>S. dist (inverse (f x y)) ((inverse \<circ> l) y) < e"
   577     using lte by (force intro: eventually_mono)
   578 qed
   579 
   580 lemma uniform_lim_divide:
   581   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_field"
   582   assumes f: "uniform_limit S f l F"
   583       and g: "uniform_limit S g m F"
   584       and l: "bounded (l ` S)"
   585       and b: "\<And>x. x \<in> S \<Longrightarrow> b \<le> norm(m x)"
   586       and "b > 0"
   587     shows "uniform_limit S (\<lambda>a b. f a b / g a b) (\<lambda>a. l a / m a) F"
   588 proof -
   589   have m: "bounded ((inverse \<circ> m) ` S)"
   590     using b \<open>b > 0\<close>
   591     apply (simp add: bounded_iff)
   592     by (metis le_imp_inverse_le norm_inverse)
   593   have "uniform_limit S (\<lambda>a b. f a b * inverse (g a b))
   594          (\<lambda>a. l a * (inverse \<circ> m) a) F"
   595     by (rule uniform_lim_mult [OF f uniform_lim_inverse [OF g b \<open>b > 0\<close>] l m])
   596   then show ?thesis
   597     by (simp add: field_class.field_divide_inverse)
   598 qed
   599 
   600 lemma uniform_limit_null_comparison:
   601   assumes "\<forall>\<^sub>F x in F. \<forall>a\<in>S. norm (f x a) \<le> g x a"
   602   assumes "uniform_limit S g (\<lambda>_. 0) F"
   603   shows "uniform_limit S f (\<lambda>_. 0) F"
   604   using assms(2)
   605 proof (rule metric_uniform_limit_imp_uniform_limit)
   606   show "\<forall>\<^sub>F x in F. \<forall>y\<in>S. dist (f x y) 0 \<le> dist (g x y) 0"
   607     using assms(1) by (rule eventually_mono) (force simp add: dist_norm)
   608 qed
   609 
   610 lemma uniform_limit_on_Un:
   611   "uniform_limit I f g F \<Longrightarrow> uniform_limit J f g F \<Longrightarrow> uniform_limit (I \<union> J) f g F"
   612   by (auto intro!: uniform_limitI dest!: uniform_limitD elim: eventually_elim2)
   613 
   614 lemma uniform_limit_on_empty [iff]:
   615   "uniform_limit {} f g F"
   616   by (auto intro!: uniform_limitI)
   617 
   618 lemma uniform_limit_on_UNION:
   619   assumes "finite S"
   620   assumes "\<And>s. s \<in> S \<Longrightarrow> uniform_limit (h s) f g F"
   621   shows "uniform_limit (UNION S h) f g F"
   622   using assms
   623   by induct (auto intro: uniform_limit_on_empty uniform_limit_on_Un)
   624 
   625 lemma uniform_limit_on_Union:
   626   assumes "finite I"
   627   assumes "\<And>J. J \<in> I \<Longrightarrow> uniform_limit J f g F"
   628   shows "uniform_limit (Union I) f g F"
   629   by (metis SUP_identity_eq assms uniform_limit_on_UNION)
   630 
   631 lemma uniform_limit_on_subset:
   632   "uniform_limit J f g F \<Longrightarrow> I \<subseteq> J \<Longrightarrow> uniform_limit I f g F"
   633   by (auto intro!: uniform_limitI dest!: uniform_limitD intro: eventually_mono)
   634 
   635 lemma uniform_limit_bounded:
   636   fixes f::"'i \<Rightarrow> 'a::topological_space \<Rightarrow> 'b::metric_space"
   637   assumes l: "uniform_limit S f l F"
   638   assumes bnd: "\<forall>\<^sub>F i in F. bounded (f i ` S)"
   639   assumes "F \<noteq> bot"
   640   shows "bounded (l ` S)"
   641 proof -
   642   from l have "\<forall>\<^sub>F n in F. \<forall>x\<in>S. dist (l x) (f n x) < 1"
   643     by (auto simp: uniform_limit_iff dist_commute dest!: spec[where x=1])
   644   with bnd
   645   have "\<forall>\<^sub>F n in F. \<exists>M. \<forall>x\<in>S. dist undefined (l x) \<le> M + 1"
   646     by eventually_elim
   647       (auto intro!: order_trans[OF dist_triangle2 add_mono] intro: less_imp_le
   648         simp: bounded_any_center[where a=undefined])
   649   then show ?thesis using assms
   650     by (auto simp: bounded_any_center[where a=undefined] dest!: eventually_happens)
   651 qed
   652 
   653 lemma uniformly_convergent_add:
   654   "uniformly_convergent_on A f \<Longrightarrow> uniformly_convergent_on A g\<Longrightarrow>
   655       uniformly_convergent_on A (\<lambda>k x. f k x + g k x :: 'a :: {real_normed_algebra})"
   656   unfolding uniformly_convergent_on_def by (blast dest: uniform_limit_add)
   657 
   658 lemma uniformly_convergent_minus:
   659   "uniformly_convergent_on A f \<Longrightarrow> uniformly_convergent_on A g\<Longrightarrow>
   660       uniformly_convergent_on A (\<lambda>k x. f k x - g k x :: 'a :: {real_normed_algebra})"
   661   unfolding uniformly_convergent_on_def by (blast dest: uniform_limit_minus)
   662 
   663 lemma uniformly_convergent_mult:
   664   "uniformly_convergent_on A f \<Longrightarrow>
   665       uniformly_convergent_on A (\<lambda>k x. c * f k x :: 'a :: {real_normed_algebra})"
   666   unfolding uniformly_convergent_on_def
   667   by (blast dest: bounded_linear_uniform_limit_intros(13))
   668 
   669 subsection\<open>Power series and uniform convergence\<close>
   670 
   671 proposition powser_uniformly_convergent:
   672   fixes a :: "nat \<Rightarrow> 'a::{real_normed_div_algebra,banach}"
   673   assumes "r < conv_radius a"
   674   shows "uniformly_convergent_on (cball \<xi> r) (\<lambda>n x. \<Sum>i<n. a i * (x - \<xi>) ^ i)"
   675 proof (cases "0 \<le> r")
   676   case True
   677   then have *: "summable (\<lambda>n. norm (a n) * r ^ n)"
   678     using abs_summable_in_conv_radius [of "of_real r" a] assms
   679     by (simp add: norm_mult norm_power)
   680   show ?thesis
   681     by (simp add: weierstrass_m_test'_ev [OF _ *] norm_mult norm_power
   682               mult_left_mono power_mono dist_norm norm_minus_commute)
   683 next
   684   case False then show ?thesis by (simp add: not_le)
   685 qed
   686 
   687 lemma powser_uniform_limit:
   688   fixes a :: "nat \<Rightarrow> 'a::{real_normed_div_algebra,banach}"
   689   assumes "r < conv_radius a"
   690   shows "uniform_limit (cball \<xi> r) (\<lambda>n x. \<Sum>i<n. a i * (x - \<xi>) ^ i) (\<lambda>x. suminf (\<lambda>i. a i * (x - \<xi>) ^ i)) sequentially"
   691 using powser_uniformly_convergent [OF assms]
   692 by (simp add: Uniform_Limit.uniformly_convergent_uniform_limit_iff Series.suminf_eq_lim)
   693 
   694 lemma powser_continuous_suminf:
   695   fixes a :: "nat \<Rightarrow> 'a::{real_normed_div_algebra,banach}"
   696   assumes "r < conv_radius a"
   697   shows "continuous_on (cball \<xi> r) (\<lambda>x. suminf (\<lambda>i. a i * (x - \<xi>) ^ i))"
   698 apply (rule uniform_limit_theorem [OF _ powser_uniform_limit])
   699 apply (rule eventuallyI continuous_intros assms)+
   700 apply (simp add:)
   701 done
   702 
   703 lemma powser_continuous_sums:
   704   fixes a :: "nat \<Rightarrow> 'a::{real_normed_div_algebra,banach}"
   705   assumes r: "r < conv_radius a"
   706       and sm: "\<And>x. x \<in> cball \<xi> r \<Longrightarrow> (\<lambda>n. a n * (x - \<xi>) ^ n) sums (f x)"
   707   shows "continuous_on (cball \<xi> r) f"
   708 apply (rule continuous_on_cong [THEN iffD1, OF refl _ powser_continuous_suminf [OF r]])
   709 using sm sums_unique by fastforce
   710 
   711 end
   712