src/HOL/Analysis/Infinite_Sum.thy
changeset 77357 e65d8ee80811
parent 76999 ff203584b36e
child 77359 bfb1acc9855e
equal deleted inserted replaced
77352:c6e2c7887d47 77357:e65d8ee80811
    92   fixes f g :: \<open>'a \<Rightarrow> 'b::{comm_monoid_add, t2_space}\<close>
    92   fixes f g :: \<open>'a \<Rightarrow> 'b::{comm_monoid_add, t2_space}\<close>
    93   assumes \<open>x = y\<close>
    93   assumes \<open>x = y\<close>
    94   assumes \<open>has_sum f A x\<close>
    94   assumes \<open>has_sum f A x\<close>
    95   assumes \<open>has_sum g B y\<close>
    95   assumes \<open>has_sum g B y\<close>
    96   shows \<open>infsum f A = infsum g B\<close>
    96   shows \<open>infsum f A = infsum g B\<close>
    97   by (metis assms(1) assms(2) assms(3) finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim)
    97   using assms infsumI by blast
    98 
    98 
    99 lemma infsum_eqI':
    99 lemma infsum_eqI':
   100   fixes f g :: \<open>'a \<Rightarrow> 'b::{comm_monoid_add, t2_space}\<close>
   100   fixes f g :: \<open>'a \<Rightarrow> 'b::{comm_monoid_add, t2_space}\<close>
   101   assumes \<open>\<And>x. has_sum f A x \<longleftrightarrow> has_sum g B x\<close>
   101   assumes \<open>\<And>x. has_sum f A x \<longleftrightarrow> has_sum g B x\<close>
   102   shows \<open>infsum f A = infsum g B\<close>
   102   shows \<open>infsum f A = infsum g B\<close>
   112   using infsumI summable_on_def by blast
   112   using infsumI summable_on_def by blast
   113 
   113 
   114 lemma has_sum_infsum[simp]:
   114 lemma has_sum_infsum[simp]:
   115   assumes \<open>f summable_on S\<close>
   115   assumes \<open>f summable_on S\<close>
   116   shows \<open>has_sum f S (infsum f S)\<close>
   116   shows \<open>has_sum f S (infsum f S)\<close>
   117   using assms by (auto simp: summable_on_def infsum_def has_sum_def tendsto_Lim)
   117   using assms summable_iff_has_sum_infsum by blast
   118 
   118 
   119 lemma has_sum_cong_neutral:
   119 lemma has_sum_cong_neutral:
   120   fixes f g :: \<open>'a \<Rightarrow> 'b::{comm_monoid_add, topological_space}\<close>
   120   fixes f g :: \<open>'a \<Rightarrow> 'b::{comm_monoid_add, topological_space}\<close>
   121   assumes \<open>\<And>x. x\<in>T-S \<Longrightarrow> g x = 0\<close>
   121   assumes \<open>\<And>x. x\<in>T-S \<Longrightarrow> g x = 0\<close>
   122   assumes \<open>\<And>x. x\<in>S-T \<Longrightarrow> f x = 0\<close>
   122   assumes \<open>\<And>x. x\<in>S-T \<Longrightarrow> f x = 0\<close>
   355   assumes "f summable_on A" and "g summable_on B"
   355   assumes "f summable_on A" and "g summable_on B"
   356   assumes \<open>\<And>x. x \<in> A\<inter>B \<Longrightarrow> f x \<le> g x\<close>
   356   assumes \<open>\<And>x. x \<in> A\<inter>B \<Longrightarrow> f x \<le> g x\<close>
   357   assumes \<open>\<And>x. x \<in> A-B \<Longrightarrow> f x \<le> 0\<close>
   357   assumes \<open>\<And>x. x \<in> A-B \<Longrightarrow> f x \<le> 0\<close>
   358   assumes \<open>\<And>x. x \<in> B-A \<Longrightarrow> g x \<ge> 0\<close>
   358   assumes \<open>\<And>x. x \<in> B-A \<Longrightarrow> g x \<ge> 0\<close>
   359   shows "infsum f A \<le> infsum g B"
   359   shows "infsum f A \<le> infsum g B"
   360   by (rule has_sum_mono_neutral[of f A _ g B _]) (use assms in \<open>auto intro: has_sum_infsum\<close>)
   360   by (smt (verit, best) assms has_sum_infsum has_sum_mono_neutral)
   361 
   361 
   362 lemma has_sum_mono:
   362 lemma has_sum_mono:
   363   fixes f :: "'a\<Rightarrow>'b::{ordered_comm_monoid_add,linorder_topology}"
   363   fixes f :: "'a\<Rightarrow>'b::{ordered_comm_monoid_add,linorder_topology}"
   364   assumes "has_sum f A x" and "has_sum g A y"
   364   assumes "has_sum f A x" and "has_sum g A y"
   365   assumes \<open>\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x\<close>
   365   assumes \<open>\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x\<close>
   386   using assms summable_on_def has_sum_finite by blast
   386   using assms summable_on_def has_sum_finite by blast
   387 
   387 
   388 lemma infsum_finite[simp]:
   388 lemma infsum_finite[simp]:
   389   assumes "finite F"
   389   assumes "finite F"
   390   shows "infsum f F = sum f F"
   390   shows "infsum f F = sum f F"
   391   using assms by (auto intro: tendsto_Lim simp: finite_subsets_at_top_finite infsum_def principal_eq_bot_iff)
   391   by (simp add: assms infsumI)
   392 
   392 
   393 lemma has_sum_finite_approximation:
   393 lemma has_sum_finite_approximation:
   394   fixes f :: "'a \<Rightarrow> 'b::{comm_monoid_add,metric_space}"
   394   fixes f :: "'a \<Rightarrow> 'b::{comm_monoid_add,metric_space}"
   395   assumes "has_sum f A x" and "\<epsilon> > 0"
   395   assumes "has_sum f A x" and "\<epsilon> > 0"
   396   shows "\<exists>F. finite F \<and> F \<subseteq> A \<and> dist (sum f F) x \<le> \<epsilon>"
   396   shows "\<exists>F. finite F \<and> F \<subseteq> A \<and> dist (sum f F) x \<le> \<epsilon>"
   543     assume "\<not> 0 \<le> t"
   543     assume "\<not> 0 \<le> t"
   544     hence "t < 0" by simp
   544     hence "t < 0" by simp
   545     hence "t \<in> S"
   545     hence "t \<in> S"
   546       unfolding S_def by blast
   546       unfolding S_def by blast
   547     moreover have "open S"
   547     moreover have "open S"
   548     proof-
   548       by (metis S_def lessThan_def open_real_lessThan)
   549       have "closed {s::real. s \<ge> 0}"
       
   550         using Elementary_Topology.closed_sequential_limits[where S = "{s::real. s \<ge> 0}"]
       
   551         by (metis Lim_bounded2 mem_Collect_eq)
       
   552       moreover have "{s::real. s \<ge> 0} = UNIV - S"
       
   553         unfolding S_def by auto
       
   554       ultimately have "closed (UNIV - S)"
       
   555         by simp
       
   556       thus ?thesis
       
   557         by (simp add: Compl_eq_Diff_UNIV open_closed) 
       
   558     qed
       
   559     ultimately have "\<forall>\<^sub>F X in finite_subsets_at_top A. (\<Sum>x\<in>X. norm (f x)) \<in> S"
   549     ultimately have "\<forall>\<^sub>F X in finite_subsets_at_top A. (\<Sum>x\<in>X. norm (f x)) \<in> S"
   560       using t_def unfolding tendsto_def by blast
   550       using t_def unfolding tendsto_def by blast
   561     hence "\<exists>X. (\<Sum>x\<in>X. norm (f x)) \<in> S"
   551     hence "\<exists>X. (\<Sum>x\<in>X. norm (f x)) \<in> S"
   562       by (metis (no_types, lifting) eventually_mono filterlim_iff finite_subsets_at_top_neq_bot tendsto_Lim)
   552       by (metis (no_types, lifting) eventually_mono filterlim_iff finite_subsets_at_top_neq_bot tendsto_Lim)
   563     then obtain X where "(\<Sum>x\<in>X. norm (f x)) \<in> S"
   553     then obtain X where "(\<Sum>x\<in>X. norm (f x)) \<in> S"
   578 qed
   568 qed
   579 
   569 
   580 lemma infsum_tendsto:
   570 lemma infsum_tendsto:
   581   assumes \<open>f summable_on S\<close>
   571   assumes \<open>f summable_on S\<close>
   582   shows \<open>((\<lambda>F. sum f F) \<longlongrightarrow> infsum f S) (finite_subsets_at_top S)\<close>
   572   shows \<open>((\<lambda>F. sum f F) \<longlongrightarrow> infsum f S) (finite_subsets_at_top S)\<close>
   583   using assms by (simp flip: has_sum_def)
   573   using assms has_sum_def has_sum_infsum by blast
   584 
   574 
   585 lemma has_sum_0: 
   575 lemma has_sum_0: 
   586   assumes \<open>\<And>x. x\<in>M \<Longrightarrow> f x = 0\<close>
   576   assumes \<open>\<And>x. x\<in>M \<Longrightarrow> f x = 0\<close>
   587   shows \<open>has_sum f M 0\<close>
   577   shows \<open>has_sum f M 0\<close>
   588   by (metis assms finite.intros(1) has_sum_cong has_sum_cong_neutral has_sum_finite sum.neutral_const)
   578   by (metis assms finite.intros(1) has_sum_cong has_sum_cong_neutral has_sum_finite sum.neutral_const)
   598   by (metis assms finite_subsets_at_top_neq_bot infsum_def has_sum_0 has_sum_def tendsto_Lim)
   588   by (metis assms finite_subsets_at_top_neq_bot infsum_def has_sum_0 has_sum_def tendsto_Lim)
   599 
   589 
   600 text \<open>Variants of @{thm [source] infsum_0} etc. suitable as simp-rules\<close>
   590 text \<open>Variants of @{thm [source] infsum_0} etc. suitable as simp-rules\<close>
   601 lemma infsum_0_simp[simp]: \<open>infsum (\<lambda>_. 0) M = 0\<close>
   591 lemma infsum_0_simp[simp]: \<open>infsum (\<lambda>_. 0) M = 0\<close>
   602   by (simp_all add: infsum_0)
   592   by (simp_all add: infsum_0)
       
   593 
   603 lemma summable_on_0_simp[simp]: \<open>(\<lambda>_. 0) summable_on M\<close>
   594 lemma summable_on_0_simp[simp]: \<open>(\<lambda>_. 0) summable_on M\<close>
   604   by (simp_all add: summable_on_0)
   595   by (simp_all add: summable_on_0)
       
   596 
   605 lemma has_sum_0_simp[simp]: \<open>has_sum (\<lambda>_. 0) M 0\<close>
   597 lemma has_sum_0_simp[simp]: \<open>has_sum (\<lambda>_. 0) M 0\<close>
   606   by (simp_all add: has_sum_0)
   598   by (simp_all add: has_sum_0)
   607 
   599 
   608 
   600 
   609 lemma has_sum_add:
   601 lemma has_sum_add:
   624 lemma summable_on_add:
   616 lemma summable_on_add:
   625   fixes f g :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add}"
   617   fixes f g :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add}"
   626   assumes \<open>f summable_on A\<close>
   618   assumes \<open>f summable_on A\<close>
   627   assumes \<open>g summable_on A\<close>
   619   assumes \<open>g summable_on A\<close>
   628   shows \<open>(\<lambda>x. f x + g x) summable_on A\<close>
   620   shows \<open>(\<lambda>x. f x + g x) summable_on A\<close>
   629   by (metis (full_types) assms(1) assms(2) summable_on_def has_sum_add)
   621   by (metis (full_types) assms summable_on_def has_sum_add)
   630 
   622 
   631 lemma infsum_add:
   623 lemma infsum_add:
   632   fixes f g :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add, t2_space}"
   624   fixes f g :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add, t2_space}"
   633   assumes \<open>f summable_on A\<close>
   625   assumes \<open>f summable_on A\<close>
   634   assumes \<open>g summable_on A\<close>
   626   assumes \<open>g summable_on A\<close>
   635   shows \<open>infsum (\<lambda>x. f x + g x) A = infsum f A + infsum g A\<close>
   627   shows \<open>infsum (\<lambda>x. f x + g x) A = infsum f A + infsum g A\<close>
   636 proof -
   628 proof -
   637   have \<open>has_sum (\<lambda>x. f x + g x) A (infsum f A + infsum g A)\<close>
   629   have \<open>has_sum (\<lambda>x. f x + g x) A (infsum f A + infsum g A)\<close>
   638     by (simp add: assms(1) assms(2) has_sum_add)
   630     by (simp add: assms has_sum_add)
   639   then show ?thesis
   631   then show ?thesis
   640     using infsumI by blast
   632     using infsumI by blast
   641 qed
   633 qed
   642 
   634 
   643 
   635 
   665   fixes f :: "'a \<Rightarrow> 'b::topological_comm_monoid_add"
   657   fixes f :: "'a \<Rightarrow> 'b::topological_comm_monoid_add"
   666   assumes "f summable_on A"
   658   assumes "f summable_on A"
   667   assumes "f summable_on B"
   659   assumes "f summable_on B"
   668   assumes disj: "A \<inter> B = {}"
   660   assumes disj: "A \<inter> B = {}"
   669   shows \<open>f summable_on (A \<union> B)\<close>
   661   shows \<open>f summable_on (A \<union> B)\<close>
   670   by (meson assms(1) assms(2) disj summable_on_def has_sum_Un_disjoint)
   662   by (meson assms disj summable_on_def has_sum_Un_disjoint)
   671 
   663 
   672 lemma infsum_Un_disjoint:
   664 lemma infsum_Un_disjoint:
   673   fixes f :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add, t2_space}"
   665   fixes f :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add, t2_space}"
   674   assumes "f summable_on A"
   666   assumes "f summable_on A"
   675   assumes "f summable_on B"
   667   assumes "f summable_on B"
   680 lemma norm_summable_imp_has_sum:
   672 lemma norm_summable_imp_has_sum:
   681   fixes f :: "nat \<Rightarrow> 'a :: banach"
   673   fixes f :: "nat \<Rightarrow> 'a :: banach"
   682   assumes "summable (\<lambda>n. norm (f n))" and "f sums S"
   674   assumes "summable (\<lambda>n. norm (f n))" and "f sums S"
   683   shows   "has_sum f (UNIV :: nat set) S"
   675   shows   "has_sum f (UNIV :: nat set) S"
   684   unfolding has_sum_def tendsto_iff eventually_finite_subsets_at_top
   676   unfolding has_sum_def tendsto_iff eventually_finite_subsets_at_top
   685 proof (safe, goal_cases)
   677 proof clarsimp
   686   case (1 \<epsilon>)
   678   fix \<epsilon>::real 
   687   from assms(1) obtain S' where S': "(\<lambda>n. norm (f n)) sums S'"
   679   assume "\<epsilon> > 0"
       
   680   from assms obtain S' where S': "(\<lambda>n. norm (f n)) sums S'"
   688     by (auto simp: summable_def)
   681     by (auto simp: summable_def)
   689   with 1 obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> \<bar>S' - (\<Sum>i<n. norm (f i))\<bar> < \<epsilon>"
   682   with \<open>\<epsilon> > 0\<close> obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> \<bar>S' - (\<Sum>i<n. norm (f i))\<bar> < \<epsilon>"
   690     by (auto simp: tendsto_iff eventually_at_top_linorder sums_def dist_norm abs_minus_commute)
   683     by (auto simp: tendsto_iff eventually_at_top_linorder sums_def dist_norm abs_minus_commute)
   691   
   684   have "dist (sum f Y) S < \<epsilon>" if "finite Y" "{..<N} \<subseteq> Y" for Y
   692   show ?case
   685   proof -
   693   proof (rule exI[of _ "{..<N}"], safe, goal_cases)
   686     from that have "(\<lambda>n. if n \<in> Y then 0 else f n) sums (S - sum f Y)"
   694     case (2 Y)
       
   695     from 2 have "(\<lambda>n. if n \<in> Y then 0 else f n) sums (S - sum f Y)"
       
   696       by (intro sums_If_finite_set'[OF \<open>f sums S\<close>]) (auto simp: sum_negf)
   687       by (intro sums_If_finite_set'[OF \<open>f sums S\<close>]) (auto simp: sum_negf)
   697     hence "S - sum f Y = (\<Sum>n. if n \<in> Y then 0 else f n)"
   688     hence "S - sum f Y = (\<Sum>n. if n \<in> Y then 0 else f n)"
   698       by (simp add: sums_iff)
   689       by (simp add: sums_iff)
   699     also have "norm \<dots> \<le> (\<Sum>n. norm (if n \<in> Y then 0 else f n))"
   690     also have "norm \<dots> \<le> (\<Sum>n. norm (if n \<in> Y then 0 else f n))"
   700       by (rule summable_norm[OF summable_comparison_test'[OF assms(1)]]) auto
   691       by (rule summable_norm[OF summable_comparison_test'[OF assms(1)]]) auto
   701     also have "\<dots> \<le> (\<Sum>n. if n < N then 0 else norm (f n))"
   692     also have "\<dots> \<le> (\<Sum>n. if n < N then 0 else norm (f n))"
   702       using 2 by (intro suminf_le summable_comparison_test'[OF assms(1)]) auto
   693       using that by (intro suminf_le summable_comparison_test'[OF assms(1)]) auto
   703     also have "(\<lambda>n. if n \<in> {..<N} then 0 else norm (f n)) sums (S' - (\<Sum>i<N. norm (f i)))" 
   694     also have "(\<lambda>n. if n \<in> {..<N} then 0 else norm (f n)) sums (S' - (\<Sum>i<N. norm (f i)))" 
   704       by (intro sums_If_finite_set'[OF S']) (auto simp: sum_negf)
   695       by (intro sums_If_finite_set'[OF S']) (auto simp: sum_negf)
   705     hence "(\<Sum>n. if n < N then 0 else norm (f n)) = S' - (\<Sum>i<N. norm (f i))"
   696     hence "(\<Sum>n. if n < N then 0 else norm (f n)) = S' - (\<Sum>i<N. norm (f i))"
   706       by (simp add: sums_iff)
   697       by (simp add: sums_iff)
   707     also have "S' - (\<Sum>i<N. norm (f i)) \<le> \<bar>S' - (\<Sum>i<N. norm (f i))\<bar>" by simp
   698     also have "S' - (\<Sum>i<N. norm (f i)) \<le> \<bar>S' - (\<Sum>i<N. norm (f i))\<bar>" by simp
   708     also have "\<dots> < \<epsilon>" by (rule N) auto
   699     also have "\<dots> < \<epsilon>" by (rule N) auto
   709     finally show ?case by (simp add: dist_norm norm_minus_commute)
   700     finally show ?thesis by (simp add: dist_norm norm_minus_commute)
   710   qed auto
   701   qed
       
   702   then show "\<exists>X. finite X \<and> (\<forall>Y. finite Y \<and> X \<subseteq> Y \<longrightarrow> dist (sum f Y) S < \<epsilon>)"
       
   703     by (meson finite_lessThan subset_UNIV)
   711 qed
   704 qed
   712 
   705 
   713 lemma norm_summable_imp_summable_on:
   706 lemma norm_summable_imp_summable_on:
   714   fixes f :: "nat \<Rightarrow> 'a :: banach"
   707   fixes f :: "nat \<Rightarrow> 'a :: banach"
   715   assumes "summable (\<lambda>n. norm (f n))"
   708   assumes "summable (\<lambda>n. norm (f n))"
   732 
   725 
   733   The lemma also requires uniform continuity of the addition. And example of a topological group with continuous 
   726   The lemma also requires uniform continuity of the addition. And example of a topological group with continuous 
   734   but not uniformly continuous addition would be the positive reals with the usual multiplication as the addition.
   727   but not uniformly continuous addition would be the positive reals with the usual multiplication as the addition.
   735   We do not know whether the lemma would also hold for such topological groups.\<close>
   728   We do not know whether the lemma would also hold for such topological groups.\<close>
   736 
   729 
   737 lemma summable_on_subset:
   730 lemma summable_on_subset_aux:
   738   fixes A B and f :: \<open>'a \<Rightarrow> 'b::{ab_group_add, uniform_space}\<close>
   731   fixes A B and f :: \<open>'a \<Rightarrow> 'b::{ab_group_add, uniform_space}\<close>
   739   assumes \<open>complete (UNIV :: 'b set)\<close>
   732   assumes \<open>complete (UNIV :: 'b set)\<close>
   740   assumes plus_cont: \<open>uniformly_continuous_on UNIV (\<lambda>(x::'b,y). x+y)\<close>
   733   assumes plus_cont: \<open>uniformly_continuous_on UNIV (\<lambda>(x::'b,y). x+y)\<close>
   741   assumes \<open>f summable_on A\<close>
   734   assumes \<open>f summable_on A\<close>
   742   assumes \<open>B \<subseteq> A\<close>
   735   assumes \<open>B \<subseteq> A\<close>
   811     by (auto simp: filterlim_def)
   804     by (auto simp: filterlim_def)
   812   then show ?thesis
   805   then show ?thesis
   813     by (auto simp: summable_on_def has_sum_def)
   806     by (auto simp: summable_on_def has_sum_def)
   814 qed
   807 qed
   815 
   808 
   816 text \<open>A special case of @{thm [source] summable_on_subset} for Banach spaces with less premises.\<close>
   809 text \<open>A special case of @{thm [source] summable_on_subset_aux} for Banach spaces with fewer premises.\<close>
   817 
   810 
   818 lemma summable_on_subset_banach:
   811 lemma summable_on_subset_banach:
   819   fixes A B and f :: \<open>'a \<Rightarrow> 'b::banach\<close>
   812   fixes A B and f :: \<open>'a \<Rightarrow> 'b::banach\<close>
   820   assumes \<open>f summable_on A\<close>
   813   assumes \<open>f summable_on A\<close>
   821   assumes \<open>B \<subseteq> A\<close>
   814   assumes \<open>B \<subseteq> A\<close>
   822   shows \<open>f summable_on B\<close>
   815   shows \<open>f summable_on B\<close>
   823   by (rule summable_on_subset[OF _ _ assms])
   816   by (rule summable_on_subset_aux[OF _ _ assms])
   824      (auto simp: complete_def convergent_def dest!: Cauchy_convergent)
   817      (auto simp: complete_def convergent_def dest!: Cauchy_convergent)
   825 
   818 
   826 lemma has_sum_empty[simp]: \<open>has_sum f {} 0\<close>
   819 lemma has_sum_empty[simp]: \<open>has_sum f {} 0\<close>
   827   by (meson ex_in_conv has_sum_0)
   820   by (meson ex_in_conv has_sum_0)
   828 
   821 
   832 lemma infsum_empty[simp]: \<open>infsum f {} = 0\<close>
   825 lemma infsum_empty[simp]: \<open>infsum f {} = 0\<close>
   833   by simp
   826   by simp
   834 
   827 
   835 lemma sum_has_sum:
   828 lemma sum_has_sum:
   836   fixes f :: "'a \<Rightarrow> 'b::topological_comm_monoid_add"
   829   fixes f :: "'a \<Rightarrow> 'b::topological_comm_monoid_add"
   837   assumes finite: \<open>finite A\<close>
   830   assumes \<open>finite A\<close>
   838   assumes conv: \<open>\<And>a. a \<in> A \<Longrightarrow> has_sum f (B a) (s a)\<close>
   831   assumes \<open>\<And>a. a \<in> A \<Longrightarrow> has_sum f (B a) (s a)\<close>
   839   assumes disj: \<open>\<And>a a'. a\<in>A \<Longrightarrow> a'\<in>A \<Longrightarrow> a\<noteq>a' \<Longrightarrow> B a \<inter> B a' = {}\<close>
   832   assumes \<open>\<And>a a'. a\<in>A \<Longrightarrow> a'\<in>A \<Longrightarrow> a\<noteq>a' \<Longrightarrow> B a \<inter> B a' = {}\<close>
   840   shows \<open>has_sum f (\<Union>a\<in>A. B a) (sum s A)\<close>
   833   shows \<open>has_sum f (\<Union>a\<in>A. B a) (sum s A)\<close>
   841   using assms finite conv 
   834   using assms 
   842 proof (induction)
   835 proof (induction)
   843   case empty
   836   case empty
   844   then show ?case 
   837   then show ?case 
   845     by simp
   838     by simp
   846 next
   839 next
   860   fixes f :: "'a \<Rightarrow> 'b::topological_comm_monoid_add"
   853   fixes f :: "'a \<Rightarrow> 'b::topological_comm_monoid_add"
   861   assumes finite: \<open>finite A\<close>
   854   assumes finite: \<open>finite A\<close>
   862   assumes conv: \<open>\<And>a. a \<in> A \<Longrightarrow> f summable_on (B a)\<close>
   855   assumes conv: \<open>\<And>a. a \<in> A \<Longrightarrow> f summable_on (B a)\<close>
   863   assumes disj: \<open>\<And>a a'. a\<in>A \<Longrightarrow> a'\<in>A \<Longrightarrow> a\<noteq>a' \<Longrightarrow> B a \<inter> B a' = {}\<close>
   856   assumes disj: \<open>\<And>a a'. a\<in>A \<Longrightarrow> a'\<in>A \<Longrightarrow> a\<noteq>a' \<Longrightarrow> B a \<inter> B a' = {}\<close>
   864   shows \<open>f summable_on (\<Union>a\<in>A. B a)\<close>
   857   shows \<open>f summable_on (\<Union>a\<in>A. B a)\<close>
   865   using finite conv disj by induction (auto intro!: summable_on_Un_disjoint)
   858   using sum_has_sum [of A f B] assms unfolding summable_on_def by metis
   866 
   859 
   867 lemma sum_infsum:
   860 lemma sum_infsum:
   868   fixes f :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add, t2_space}"
   861   fixes f :: "'a \<Rightarrow> 'b::{topological_comm_monoid_add, t2_space}"
   869   assumes finite: \<open>finite A\<close>
   862   assumes finite: \<open>finite A\<close>
   870   assumes conv: \<open>\<And>a. a \<in> A \<Longrightarrow> f summable_on (B a)\<close>
   863   assumes conv: \<open>\<And>a. a \<in> A \<Longrightarrow> f summable_on (B a)\<close>
   871   assumes disj: \<open>\<And>a a'. a\<in>A \<Longrightarrow> a'\<in>A \<Longrightarrow> a\<noteq>a' \<Longrightarrow> B a \<inter> B a' = {}\<close>
   864   assumes disj: \<open>\<And>a a'. a\<in>A \<Longrightarrow> a'\<in>A \<Longrightarrow> a\<noteq>a' \<Longrightarrow> B a \<inter> B a' = {}\<close>
   872   shows \<open>sum (\<lambda>a. infsum f (B a)) A = infsum f (\<Union>a\<in>A. B a)\<close>
   865   shows \<open>sum (\<lambda>a. infsum f (B a)) A = infsum f (\<Union>a\<in>A. B a)\<close>
   873   by (rule sym, rule infsumI)
   866   by (metis (no_types, lifting) assms has_sum_infsum infsumI sum_has_sum[of A f B \<open>\<lambda>a. infsum f (B a)\<close>])
   874      (use sum_has_sum[of A f B \<open>\<lambda>a. infsum f (B a)\<close>] assms in auto)
       
   875 
   867 
   876 text \<open>The lemmas \<open>infsum_comm_additive_general\<close> and \<open>infsum_comm_additive\<close> (and variants) below both state that the infinite sum commutes with
   868 text \<open>The lemmas \<open>infsum_comm_additive_general\<close> and \<open>infsum_comm_additive\<close> (and variants) below both state that the infinite sum commutes with
   877   a continuous additive function. \<open>infsum_comm_additive_general\<close> is stated more for more general type classes
   869   a continuous additive function. \<open>infsum_comm_additive_general\<close> is stated more for more general type classes
   878   at the expense of a somewhat less compact formulation of the premises.
   870   at the expense of a somewhat less compact formulation of the premises.
   879   E.g., by avoiding the constant \<^const>\<open>additive\<close> which introduces an additional sort constraint
   871   E.g., by avoiding the constant \<^const>\<open>additive\<close> which introduces an additional sort constraint
   935   fixes f :: \<open>'b :: {ab_group_add,t2_space} \<Rightarrow> 'c :: {ab_group_add,topological_space}\<close>
   927   fixes f :: \<open>'b :: {ab_group_add,t2_space} \<Rightarrow> 'c :: {ab_group_add,topological_space}\<close>
   936   assumes \<open>additive f\<close>
   928   assumes \<open>additive f\<close>
   937   assumes \<open>isCont f (infsum g S)\<close>
   929   assumes \<open>isCont f (infsum g S)\<close>
   938   assumes \<open>g summable_on S\<close>
   930   assumes \<open>g summable_on S\<close>
   939   shows \<open>(f \<circ> g) summable_on S\<close>
   931   shows \<open>(f \<circ> g) summable_on S\<close>
   940   by (meson assms(1) assms(2) assms(3) summable_on_def has_sum_comm_additive has_sum_infsum isContD)
   932   by (meson assms summable_on_def has_sum_comm_additive has_sum_infsum isContD)
   941 
   933 
   942 lemma infsum_comm_additive:
   934 lemma infsum_comm_additive:
   943   fixes f :: \<open>'b :: {ab_group_add,t2_space} \<Rightarrow> 'c :: {ab_group_add,t2_space}\<close>
   935   fixes f :: \<open>'b :: {ab_group_add,t2_space} \<Rightarrow> 'c :: {ab_group_add,t2_space}\<close>
   944   assumes \<open>additive f\<close>
   936   assumes \<open>additive f\<close>
   945   assumes \<open>isCont f (infsum g S)\<close>
   937   assumes \<open>isCont f (infsum g S)\<close>
   956   have \<open>(sum f \<longlongrightarrow> (SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F)) (finite_subsets_at_top A)\<close>
   948   have \<open>(sum f \<longlongrightarrow> (SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F)) (finite_subsets_at_top A)\<close>
   957   proof (rule order_tendstoI)
   949   proof (rule order_tendstoI)
   958     fix a assume \<open>a < (SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F)\<close>
   950     fix a assume \<open>a < (SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F)\<close>
   959     then obtain F where \<open>a < sum f F\<close> and \<open>finite F\<close> and \<open>F \<subseteq> A\<close>
   951     then obtain F where \<open>a < sum f F\<close> and \<open>finite F\<close> and \<open>F \<subseteq> A\<close>
   960       by (metis (mono_tags, lifting) Collect_cong Collect_empty_eq assms(2) empty_subsetI finite.emptyI less_cSUP_iff mem_Collect_eq)
   952       by (metis (mono_tags, lifting) Collect_cong Collect_empty_eq assms(2) empty_subsetI finite.emptyI less_cSUP_iff mem_Collect_eq)
   961     show \<open>\<forall>\<^sub>F x in finite_subsets_at_top A. a < sum f x\<close>
   953     have "\<And>Y. \<lbrakk>finite Y; F \<subseteq> Y; Y \<subseteq> A\<rbrakk> \<Longrightarrow> a < sum f Y"
   962       unfolding eventually_finite_subsets_at_top
   954       by (meson DiffE \<open>a < sum f F\<close> assms(1) less_le_trans subset_iff sum_mono2)
   963     proof (rule exI[of _ F], safe)
   955     then show \<open>\<forall>\<^sub>F x in finite_subsets_at_top A. a < sum f x\<close>
   964       fix Y assume Y: "finite Y" "F \<subseteq> Y" "Y \<subseteq> A"
   956       by (metis \<open>F \<subseteq> A\<close> \<open>finite F\<close> eventually_finite_subsets_at_top)
   965       have "a < sum f F"
       
   966         by fact
       
   967       also have "\<dots> \<le> sum f Y"
       
   968         using assms Y by (intro sum_mono2) auto
       
   969       finally show "a < sum f Y" .
       
   970     qed (use \<open>finite F\<close> \<open>F \<subseteq> A\<close> in auto)
       
   971   next
   957   next
   972     fix a assume *: \<open>(SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F) < a\<close>
   958     fix a assume *: \<open>(SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F) < a\<close>
   973     have \<open>sum f F < a\<close> if \<open>F\<subseteq>A\<close> and \<open>finite F\<close> for F
   959     have \<open>sum f F < a\<close> if \<open>F\<subseteq>A\<close> and \<open>finite F\<close> for F
   974     proof -
   960     proof -
   975       have "sum f F \<le> (SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F)"
   961       have "sum f F \<le> (SUP F\<in>{F. finite F \<and> F\<subseteq>A}. sum f F)"
   988 lemma nonneg_bdd_above_summable_on:
   974 lemma nonneg_bdd_above_summable_on:
   989   fixes f :: \<open>'a \<Rightarrow> 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\<close>
   975   fixes f :: \<open>'a \<Rightarrow> 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\<close>
   990   assumes \<open>\<And>x. x\<in>A \<Longrightarrow> f x \<ge> 0\<close>
   976   assumes \<open>\<And>x. x\<in>A \<Longrightarrow> f x \<ge> 0\<close>
   991   assumes \<open>bdd_above (sum f ` {F. F\<subseteq>A \<and> finite F})\<close>
   977   assumes \<open>bdd_above (sum f ` {F. F\<subseteq>A \<and> finite F})\<close>
   992   shows \<open>f summable_on A\<close>
   978   shows \<open>f summable_on A\<close>
   993   using assms(1) assms(2) summable_on_def nonneg_bdd_above_has_sum by blast
   979   using assms summable_on_def nonneg_bdd_above_has_sum by blast
   994 
   980 
   995 lemma nonneg_bdd_above_infsum:
   981 lemma nonneg_bdd_above_infsum:
   996   fixes f :: \<open>'a \<Rightarrow> 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\<close>
   982   fixes f :: \<open>'a \<Rightarrow> 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\<close>
   997   assumes \<open>\<And>x. x\<in>A \<Longrightarrow> f x \<ge> 0\<close>
   983   assumes \<open>\<And>x. x\<in>A \<Longrightarrow> f x \<ge> 0\<close>
   998   assumes \<open>bdd_above (sum f ` {F. F\<subseteq>A \<and> finite F})\<close>
   984   assumes \<open>bdd_above (sum f ` {F. F\<subseteq>A \<and> finite F})\<close>
  1020 lemma has_sum_nonneg:
  1006 lemma has_sum_nonneg:
  1021   fixes f :: "'a \<Rightarrow> 'b::{ordered_comm_monoid_add,linorder_topology}"
  1007   fixes f :: "'a \<Rightarrow> 'b::{ordered_comm_monoid_add,linorder_topology}"
  1022   assumes "has_sum f M a"
  1008   assumes "has_sum f M a"
  1023     and "\<And>x. x \<in> M \<Longrightarrow> 0 \<le> f x"
  1009     and "\<And>x. x \<in> M \<Longrightarrow> 0 \<le> f x"
  1024   shows "a \<ge> 0"
  1010   shows "a \<ge> 0"
  1025   by (metis (no_types, lifting) DiffD1 assms(1) assms(2) empty_iff has_sum_0 has_sum_mono_neutral order_refl)
  1011   by (metis (no_types, lifting) DiffD1 assms empty_iff has_sum_0 has_sum_mono_neutral order_refl)
  1026 
  1012 
  1027 lemma infsum_nonneg:
  1013 lemma infsum_nonneg:
  1028   fixes f :: "'a \<Rightarrow> 'b::{ordered_comm_monoid_add,linorder_topology}"
  1014   fixes f :: "'a \<Rightarrow> 'b::{ordered_comm_monoid_add,linorder_topology}"
  1029   assumes "\<And>x. x \<in> M \<Longrightarrow> 0 \<le> f x"
  1015   assumes "\<And>x. x \<in> M \<Longrightarrow> 0 \<le> f x"
  1030   shows "infsum f M \<ge> 0" (is "?lhs \<ge> _")
  1016   shows "infsum f M \<ge> 0" (is "?lhs \<ge> _")
  1440 qed
  1426 qed
  1441 
  1427 
  1442 lemma nonneg_has_sum_le_0D:
  1428 lemma nonneg_has_sum_le_0D:
  1443   fixes f :: "'a \<Rightarrow> 'b::{topological_ab_group_add,ordered_ab_group_add,linorder_topology}"
  1429   fixes f :: "'a \<Rightarrow> 'b::{topological_ab_group_add,ordered_ab_group_add,linorder_topology}"
  1444   assumes "has_sum f A a" \<open>a \<le> 0\<close>
  1430   assumes "has_sum f A a" \<open>a \<le> 0\<close>
  1445     and nneg: "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0"
  1431     and "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0"
  1446     and "x \<in> A"
  1432     and "x \<in> A"
  1447   shows "f x = 0"
  1433   shows "f x = 0"
  1448   by (metis assms(1) assms(2) assms(4) infsumI nonneg_infsum_le_0D summable_on_def nneg)
  1434   by (metis assms infsumI nonneg_infsum_le_0D summable_on_def)
  1449 
  1435 
  1450 lemma has_sum_cmult_left:
  1436 lemma has_sum_cmult_left:
  1451   fixes f :: "'a \<Rightarrow> 'b :: {topological_semigroup_mult, semiring_0}"
  1437   fixes f :: "'a \<Rightarrow> 'b :: {topological_semigroup_mult, semiring_0}"
  1452   assumes \<open>has_sum f A a\<close>
  1438   assumes \<open>has_sum f A a\<close>
  1453   shows "has_sum (\<lambda>x. f x * c) A (a * c)"
  1439   shows "has_sum (\<lambda>x. f x * c) A (a * c)"
  1626 lemma infsum_le_finite_sums:
  1612 lemma infsum_le_finite_sums:
  1627   fixes b :: \<open>'a::{comm_monoid_add,topological_space,linorder_topology}\<close>
  1613   fixes b :: \<open>'a::{comm_monoid_add,topological_space,linorder_topology}\<close>
  1628   assumes \<open>f summable_on A\<close>
  1614   assumes \<open>f summable_on A\<close>
  1629   assumes \<open>\<And>F. finite F \<Longrightarrow> F \<subseteq> A \<Longrightarrow> sum f F \<le> b\<close>
  1615   assumes \<open>\<And>F. finite F \<Longrightarrow> F \<subseteq> A \<Longrightarrow> sum f F \<le> b\<close>
  1630   shows \<open>infsum f A \<le> b\<close>
  1616   shows \<open>infsum f A \<le> b\<close>
  1631   by (meson assms(1) assms(2) has_sum_infsum has_sum_le_finite_sums)
  1617   by (meson assms has_sum_infsum has_sum_le_finite_sums)
  1632 
  1618 
  1633 
  1619 
  1634 lemma summable_on_scaleR_left [intro]:
  1620 lemma summable_on_scaleR_left [intro]:
  1635   fixes c :: \<open>'a :: real_normed_vector\<close>
  1621   fixes c :: \<open>'a :: real_normed_vector\<close>
  1636   assumes "c \<noteq> 0 \<Longrightarrow> f summable_on A"
  1622   assumes "c \<noteq> 0 \<Longrightarrow> f summable_on A"
  1702 
  1688 
  1703 lemma infsum_Un_Int:
  1689 lemma infsum_Un_Int:
  1704   fixes f :: "'a \<Rightarrow> 'b::{topological_ab_group_add, t2_space}"
  1690   fixes f :: "'a \<Rightarrow> 'b::{topological_ab_group_add, t2_space}"
  1705   assumes "f summable_on A - B" "f summable_on B - A" \<open>f summable_on A \<inter> B\<close>
  1691   assumes "f summable_on A - B" "f summable_on B - A" \<open>f summable_on A \<inter> B\<close>
  1706   shows   "infsum f (A \<union> B) = infsum f A + infsum f B - infsum f (A \<inter> B)"
  1692   shows   "infsum f (A \<union> B) = infsum f A + infsum f B - infsum f (A \<inter> B)"
  1707 
  1693 proof -
  1708 proof -
  1694   obtain \<open>f summable_on A\<close> \<open>f summable_on B\<close>
  1709   have \<open>f summable_on A\<close>
  1695     using assms by (metis Int_Diff_Un Int_Diff_disjoint inf_commute summable_on_Un_disjoint)
  1710     using assms by (metis Diff_Diff_Int Diff_disjoint Un_Diff_Int summable_on_Un_disjoint)
  1696   then have \<open>infsum f (A \<union> B) = infsum f A + infsum f (B - A)\<close>
  1711   have \<open>infsum f (A \<union> B) = infsum f A + infsum f (B - A)\<close>
  1697     using assms(2) infsum_Un_disjoint by fastforce
  1712     by (metis Diff_disjoint Un_Diff_cancel \<open>f summable_on A\<close> assms(2) infsum_Un_disjoint)
  1698   moreover have \<open>infsum f (B - A) = infsum f B - infsum f (A \<inter> B)\<close>
  1713   moreover have \<open>infsum f (B - A \<union> A \<inter> B) = infsum f (B - A) + infsum f (A \<inter> B)\<close>
  1699     using assms by (metis Diff_Int2 Un_Int_eq(2) \<open>f summable_on B\<close> inf_le2 infsum_Diff)
  1714     using assms by (metis Int_Diff_disjoint inf_commute infsum_Un_disjoint)
       
  1715   ultimately show ?thesis
  1700   ultimately show ?thesis
  1716     by (metis Un_Diff_Int add_diff_cancel_right' add_diff_eq inf_commute)
  1701     by auto
  1717 qed
  1702 qed
  1718 
  1703 
  1719 lemma inj_combinator':
  1704 lemma inj_combinator':
  1720   assumes "x \<notin> F"
  1705   assumes "x \<notin> F"
  1721   shows \<open>inj_on (\<lambda>(g, y). g(x := y)) (Pi\<^sub>E F B \<times> B x)\<close>
  1706   shows \<open>inj_on (\<lambda>(g, y). g(x := y)) (Pi\<^sub>E F B \<times> B x)\<close>
  1806   have inj: \<open>inj_on (\<lambda>(g, y). g(x := y)) (Pi\<^sub>E A B \<times> B x)\<close>
  1791   have inj: \<open>inj_on (\<lambda>(g, y). g(x := y)) (Pi\<^sub>E A B \<times> B x)\<close>
  1807     using \<open>x \<notin> A\<close> by (rule inj_combinator')
  1792     using \<open>x \<notin> A\<close> by (rule inj_combinator')
  1808 
  1793 
  1809   define s where \<open>s x = infsum (\<lambda>y. norm (f x y)) (B x)\<close> for x
  1794   define s where \<open>s x = infsum (\<lambda>y. norm (f x y)) (B x)\<close> for x
  1810 
  1795 
  1811   have *: \<open>(\<Sum>p\<in>P. norm (\<Prod>x\<in>F. f x (p x))) \<le> prod s F\<close> 
  1796   have \<open>(\<Sum>p\<in>P. norm (\<Prod>x\<in>F. f x (p x))) \<le> prod s F\<close> 
  1812     if P: \<open>P \<subseteq> Pi\<^sub>E F B\<close> and [simp]: \<open>finite P\<close> \<open>finite F\<close> 
  1797     if P: \<open>P \<subseteq> Pi\<^sub>E F B\<close> and [simp]: \<open>finite P\<close> \<open>finite F\<close> 
  1813       and sum: \<open>\<And>x. x \<in> F \<Longrightarrow> f x abs_summable_on B x\<close> for P F
  1798       and sum: \<open>\<And>x. x \<in> F \<Longrightarrow> f x abs_summable_on B x\<close> for P F
  1814   proof -
  1799   proof -
  1815     define B' where \<open>B' x = {p x| p. p\<in>P}\<close> for x
  1800     define B' where \<open>B' x = {p x| p. p\<in>P}\<close> for x
  1816     have fin_B'[simp]: \<open>finite (B' x)\<close> for x
  1801     have fin_B'[simp]: \<open>finite (B' x)\<close> for x
  1832     proof (use \<open>finite F\<close> in induction)
  1817     proof (use \<open>finite F\<close> in induction)
  1833       case empty
  1818       case empty
  1834       then show ?case by simp
  1819       then show ?case by simp
  1835     next
  1820     next
  1836       case (insert x F)
  1821       case (insert x F)
  1837       have aux: \<open>a = b \<Longrightarrow> c * a = c * b\<close> for a b c :: real
       
  1838         by auto
       
  1839       have inj: \<open>inj_on (\<lambda>(g, y). g(x := y)) (Pi\<^sub>E F B' \<times> B' x)\<close>
  1822       have inj: \<open>inj_on (\<lambda>(g, y). g(x := y)) (Pi\<^sub>E F B' \<times> B' x)\<close>
  1840         by (simp add: inj_combinator' insert.hyps)
  1823         by (simp add: inj_combinator' insert.hyps)
  1841       then have \<open>(\<Sum>p\<in>Pi\<^sub>E (insert x F) B'. \<Prod>x\<in>insert x F. norm (f x (p x)))
  1824       then have \<open>(\<Sum>p\<in>Pi\<^sub>E (insert x F) B'. \<Prod>x\<in>insert x F. norm (f x (p x)))
  1842          =  (\<Sum>(p,y)\<in>Pi\<^sub>E F B' \<times> B' x. \<Prod>x'\<in>insert x F. norm (f x' ((p(x := y)) x')))\<close>
  1825          =  (\<Sum>(p,y)\<in>Pi\<^sub>E F B' \<times> B' x. \<Prod>x'\<in>insert x F. norm (f x' ((p(x := y)) x')))\<close>
  1843         by (simp add: pi sum.reindex case_prod_unfold)
  1826         by (simp add: pi sum.reindex case_prod_unfold)
  1844       also have \<open>\<dots> = (\<Sum>(p,y)\<in>Pi\<^sub>E F B' \<times> B' x. norm (f x y) * (\<Prod>x'\<in>F. norm (f x' ((p(x := y)) x'))))\<close>
       
  1845         using insert.hyps by auto
       
  1846       also have \<open>\<dots> = (\<Sum>(p, y)\<in>Pi\<^sub>E F B' \<times> B' x. norm (f x y) * (\<Prod>x'\<in>F. norm (f x' (p x'))))\<close>
  1827       also have \<open>\<dots> = (\<Sum>(p, y)\<in>Pi\<^sub>E F B' \<times> B' x. norm (f x y) * (\<Prod>x'\<in>F. norm (f x' (p x'))))\<close>
  1847         by (smt (verit) fun_upd_apply insert.hyps(2) prod.cong split_def sum.cong)
  1828         by (smt (verit, del_insts) fun_upd_apply insert.hyps prod.cong prod.insert split_def sum.cong)
  1848       also have \<open>\<dots> = (\<Sum>y\<in>B' x. norm (f x y)) * (\<Sum>p\<in>Pi\<^sub>E F B'. \<Prod>x'\<in>F. norm (f x' (p x')))\<close>
  1829       also have \<open>\<dots> = (\<Sum>y\<in>B' x. norm (f x y)) * (\<Sum>p\<in>Pi\<^sub>E F B'. \<Prod>x'\<in>F. norm (f x' (p x')))\<close>
  1849         by (simp add: sum_product sum.swap [of _ "Pi\<^sub>E F B'"] sum.cartesian_product)
  1830         by (simp add: sum_product sum.swap [of _ "Pi\<^sub>E F B'"] sum.cartesian_product)
  1850       also have \<open>\<dots> = (\<Sum>y\<in>B' x. norm (f x y)) * (\<Prod>x\<in>F. \<Sum>y\<in>B' x. norm (f x y))\<close>
       
  1851         by (simp add: insert.IH)
       
  1852       also have \<open>\<dots> = (\<Prod>x\<in>insert x F. \<Sum>y\<in>B' x. norm (f x y))\<close>
  1831       also have \<open>\<dots> = (\<Prod>x\<in>insert x F. \<Sum>y\<in>B' x. norm (f x y))\<close>
  1853         using insert.hyps(1) insert.hyps(2) by force
  1832         using insert by force
  1854       finally show ?case .
  1833       finally show ?case .
  1855     qed
  1834     qed
  1856     also have \<open>\<dots> = (\<Prod>x\<in>F. \<Sum>\<^sub>\<infinity>y\<in>B' x. norm (f x y))\<close>
       
  1857       by auto
       
  1858     also have \<open>\<dots> \<le> (\<Prod>x\<in>F. s x)\<close>
  1835     also have \<open>\<dots> \<le> (\<Prod>x\<in>F. s x)\<close>
  1859       using s_bound by (simp add: prod_mono sum_nonneg)
  1836       using s_bound by (simp add: prod_mono sum_nonneg)
  1860     finally show ?thesis .
  1837     finally show ?thesis .
  1861   qed
  1838   qed
  1862   have "bdd_above
  1839   then have "bdd_above
  1863      (sum (\<lambda>g. norm (\<Prod>x\<in>insert x A. f x (g x))) ` {F. F \<subseteq> Pi\<^sub>E (insert x A) B \<and> finite F})"
  1840      (sum (\<lambda>g. norm (\<Prod>x\<in>insert x A. f x (g x))) ` {F. F \<subseteq> Pi\<^sub>E (insert x A) B \<and> finite F})"
  1864     apply (rule bdd_aboveI)
  1841     using insert.hyps insert.prems by (intro bdd_aboveI) blast
  1865     using * insert.hyps insert.prems by blast
       
  1866   then have \<open>(\<lambda>g. \<Prod>x\<in>insert x A. f x (g x)) abs_summable_on Pi\<^sub>E (insert x A) B\<close>
  1842   then have \<open>(\<lambda>g. \<Prod>x\<in>insert x A. f x (g x)) abs_summable_on Pi\<^sub>E (insert x A) B\<close>
  1867     using nonneg_bdd_above_summable_on
  1843     using nonneg_bdd_above_summable_on
  1868     by (metis (mono_tags, lifting) Collect_cong norm_ge_zero)
  1844     by (metis (mono_tags, lifting) Collect_cong norm_ge_zero)
  1869   also have \<open>Pi\<^sub>E (insert x A) B = (\<lambda>(g,y). g(x:=y)) ` (Pi\<^sub>E A B \<times> B x)\<close>
  1845   also have \<open>Pi\<^sub>E (insert x A) B = (\<lambda>(g,y). g(x:=y)) ` (Pi\<^sub>E A B \<times> B x)\<close>
  1870     by (simp only: pi)
  1846     by (simp only: pi)
  1879   finally have summable2: \<open>(\<lambda>(p, y). f x y * (\<Prod>x'\<in>A. f x' (p x'))) abs_summable_on Pi\<^sub>E A B \<times> B x\<close> .
  1855   finally have summable2: \<open>(\<lambda>(p, y). f x y * (\<Prod>x'\<in>A. f x' (p x'))) abs_summable_on Pi\<^sub>E A B \<times> B x\<close> .
  1880 
  1856 
  1881   have \<open>(\<Sum>\<^sub>\<infinity>g\<in>Pi\<^sub>E (insert x A) B. \<Prod>x\<in>insert x A. f x (g x))
  1857   have \<open>(\<Sum>\<^sub>\<infinity>g\<in>Pi\<^sub>E (insert x A) B. \<Prod>x\<in>insert x A. f x (g x))
  1882      = (\<Sum>\<^sub>\<infinity>(p,y)\<in>Pi\<^sub>E A B \<times> B x. \<Prod>x'\<in>insert x A. f x' ((p(x:=y)) x'))\<close>
  1858      = (\<Sum>\<^sub>\<infinity>(p,y)\<in>Pi\<^sub>E A B \<times> B x. \<Prod>x'\<in>insert x A. f x' ((p(x:=y)) x'))\<close>
  1883     using inj by (simp add: pi infsum_reindex o_def case_prod_unfold)
  1859     using inj by (simp add: pi infsum_reindex o_def case_prod_unfold)
  1884   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>(p,y) \<in> Pi\<^sub>E A B \<times> B x. f x y * (\<Prod>x'\<in>A. f x' ((p(x:=y)) x')))\<close>
       
  1885     using insert.hyps by auto
       
  1886   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>(p,y) \<in> Pi\<^sub>E A B \<times> B x. f x y * (\<Prod>x'\<in>A. f x' (p x')))\<close>
  1860   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>(p,y) \<in> Pi\<^sub>E A B \<times> B x. f x y * (\<Prod>x'\<in>A. f x' (p x')))\<close>
  1887     using prod by presburger
  1861     using prod insert.hyps by auto
  1888   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>p\<in>Pi\<^sub>E A B. \<Sum>\<^sub>\<infinity>y\<in>B x. f x y * (\<Prod>x'\<in>A. f x' (p x')))\<close>
  1862   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>p\<in>Pi\<^sub>E A B. \<Sum>\<^sub>\<infinity>y\<in>B x. f x y * (\<Prod>x'\<in>A. f x' (p x')))\<close>
  1889     using abs_summable_summable infsum_Sigma'_banach summable2 by fastforce
  1863     using abs_summable_summable infsum_Sigma'_banach summable2 by fastforce
  1890   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>y\<in>B x. f x y) * (\<Sum>\<^sub>\<infinity>p\<in>Pi\<^sub>E A B. \<Prod>x'\<in>A. f x' (p x'))\<close>
  1864   also have \<open>\<dots> = (\<Sum>\<^sub>\<infinity>y\<in>B x. f x y) * (\<Sum>\<^sub>\<infinity>p\<in>Pi\<^sub>E A B. \<Prod>x'\<in>A. f x' (p x'))\<close>
  1891     by (smt (verit, best) infsum_cmult_left' infsum_cmult_right' infsum_cong)
  1865     by (smt (verit, best) infsum_cmult_left' infsum_cmult_right' infsum_cong)
  1892   also have \<open>\<dots> = (\<Prod>x\<in>insert x A. infsum (f x) (B x))\<close>
  1866   finally show ?case
  1893     by (simp add: insert)
  1867     by (simp add: insert)
  1894   finally show ?case
       
  1895     by simp
       
  1896 qed
  1868 qed
  1897 
  1869 
  1898 
  1870 
  1899 
  1871 
  1900 subsection \<open>Absolute convergence\<close>
  1872 subsection \<open>Absolute convergence\<close>
  1953   fixes f :: \<open>'a \<Rightarrow> real\<close>
  1925   fixes f :: \<open>'a \<Rightarrow> real\<close>
  1954   shows \<open>f summable_on A \<longleftrightarrow> f abs_summable_on A\<close>
  1926   shows \<open>f summable_on A \<longleftrightarrow> f abs_summable_on A\<close>
  1955 proof (rule iffI)
  1927 proof (rule iffI)
  1956   assume \<open>f summable_on A\<close>
  1928   assume \<open>f summable_on A\<close>
  1957   define n A\<^sub>p A\<^sub>n
  1929   define n A\<^sub>p A\<^sub>n
  1958     where \<open>n x = norm (f x)\<close> and \<open>A\<^sub>p = {x\<in>A. f x \<ge> 0}\<close> and \<open>A\<^sub>n = {x\<in>A. f x < 0}\<close> for x
  1930     where \<open>n \<equiv> \<lambda>x. norm (f x)\<close> and \<open>A\<^sub>p = {x\<in>A. f x \<ge> 0}\<close> and \<open>A\<^sub>n = {x\<in>A. f x < 0}\<close> for x
  1959   have A: \<open>A\<^sub>p \<union> A\<^sub>n = A\<close> \<open>A\<^sub>p \<inter> A\<^sub>n = {}\<close>
  1931   have A: \<open>A\<^sub>p \<union> A\<^sub>n = A\<close> \<open>A\<^sub>p \<inter> A\<^sub>n = {}\<close>
  1960     by (auto simp: A\<^sub>p_def A\<^sub>n_def)
  1932     by (auto simp: A\<^sub>p_def A\<^sub>n_def)
  1961   from \<open>f summable_on A\<close> have \<open>f summable_on A\<^sub>p\<close> \<open>f summable_on A\<^sub>n\<close>
  1933   from \<open>f summable_on A\<close> have \<open>f summable_on A\<^sub>p\<close> \<open>f summable_on A\<^sub>n\<close>
  1962     using A\<^sub>p_def A\<^sub>n_def summable_on_subset_banach by fastforce+
  1934     using A\<^sub>p_def A\<^sub>n_def summable_on_subset_banach by fastforce+
  1963   then have \<open>n summable_on A\<^sub>p\<close>
  1935   then have \<open>n summable_on A\<^sub>p\<close>
  2024     have \<open>sum (\<lambda>x. norm (f x)) F \<le> sum (\<lambda>x. norm (g x)) F\<close>
  1996     have \<open>sum (\<lambda>x. norm (f x)) F \<le> sum (\<lambda>x. norm (g x)) F\<close>
  2025       using assms F by (intro sum_mono) auto
  1997       using assms F by (intro sum_mono) auto
  2026     also have \<open>\<dots> = infsum (\<lambda>x. norm (g x)) F\<close>
  1998     also have \<open>\<dots> = infsum (\<lambda>x. norm (g x)) F\<close>
  2027       using F by simp
  1999       using F by simp
  2028     also have \<open>\<dots> \<le> infsum (\<lambda>x. norm (g x)) A\<close>
  2000     also have \<open>\<dots> \<le> infsum (\<lambda>x. norm (g x)) A\<close>
  2029     proof (rule infsum_mono_neutral)
  2001       by (smt (verit) F assms(1) infsum_mono2 mem_Collect_eq norm_ge_zero summable_on_subset_banach)
  2030       show "g abs_summable_on F"
       
  2031         by (rule summable_on_subset_banach[OF assms(1)]) (use F in auto)
       
  2032     qed (use F assms in auto)
       
  2033     finally show "(\<Sum>x\<in>F. norm (f x)) \<le> (\<Sum>\<^sub>\<infinity>x\<in>A. norm (g x))" .
  2002     finally show "(\<Sum>x\<in>F. norm (f x)) \<le> (\<Sum>\<^sub>\<infinity>x\<in>A. norm (g x))" .
  2034   qed
  2003   qed
  2035 qed auto
  2004 qed auto
  2036 
  2005 
  2037 lemma abs_summable_iff_bdd_above:
  2006 lemma abs_summable_iff_bdd_above:
  2082   qed
  2051   qed
  2083 qed auto
  2052 qed auto
  2084 
  2053 
  2085 subsection \<open>Extended reals and nats\<close>
  2054 subsection \<open>Extended reals and nats\<close>
  2086 
  2055 
  2087 lemma summable_on_ennreal[simp]: \<open>(f::_ \<Rightarrow> ennreal) summable_on S\<close>
  2056 lemma summable_on_ennreal[simp]: \<open>(f::_ \<Rightarrow> ennreal) summable_on S\<close> and summable_on_enat[simp]: \<open>(f::_ \<Rightarrow> enat) summable_on S\<close>
  2088   by (rule nonneg_summable_on_complete) simp
  2057   by (simp_all add: nonneg_summable_on_complete)
  2089 
       
  2090 lemma summable_on_enat[simp]: \<open>(f::_ \<Rightarrow> enat) summable_on S\<close>
       
  2091   by (rule nonneg_summable_on_complete) simp
       
  2092 
  2058 
  2093 lemma has_sum_superconst_infinite_ennreal:
  2059 lemma has_sum_superconst_infinite_ennreal:
  2094   fixes f :: \<open>'a \<Rightarrow> ennreal\<close>
  2060   fixes f :: \<open>'a \<Rightarrow> ennreal\<close>
  2095   assumes geqb: \<open>\<And>x. x \<in> S \<Longrightarrow> f x \<ge> b\<close>
  2061   assumes geqb: \<open>\<And>x. x \<in> S \<Longrightarrow> f x \<ge> b\<close>
  2096   assumes b: \<open>b > 0\<close>
  2062   assumes b: \<open>b > 0\<close>
  2097   assumes \<open>infinite S\<close>
  2063   assumes \<open>infinite S\<close>
  2098   shows "has_sum f S \<infinity>"
  2064   shows "has_sum f S \<infinity>"
  2099 proof -
  2065 proof -
  2100   have \<open>(sum f \<longlongrightarrow> \<infinity>) (finite_subsets_at_top S)\<close>
  2066   have \<open>(sum f \<longlongrightarrow> \<infinity>) (finite_subsets_at_top S)\<close>
  2101   proof (rule order_tendstoI[rotated], simp)
  2067   proof (rule order_tendstoI)
  2102     fix y :: ennreal assume \<open>y < \<infinity>\<close>
  2068     fix y :: ennreal assume \<open>y < \<infinity>\<close>
  2103     then have \<open>y / b < \<infinity>\<close>
  2069     then have \<open>y / b < \<infinity>\<close> \<open>y < top\<close>
  2104       by (metis b ennreal_divide_eq_top_iff gr_implies_not_zero infinity_ennreal_def top.not_eq_extremum)
  2070       using b ennreal_divide_eq_top_iff top.not_eq_extremum by force+
  2105     then obtain F where \<open>finite F\<close> and \<open>F \<subseteq> S\<close> and cardF: \<open>card F > y / b\<close>
  2071     then obtain F where \<open>finite F\<close> and \<open>F \<subseteq> S\<close> and cardF: \<open>card F > y / b\<close>
  2106       using \<open>infinite S\<close>
  2072       using \<open>infinite S\<close>
  2107       by (metis ennreal_Ex_less_of_nat infinite_arbitrarily_large infinity_ennreal_def)
  2073       by (metis ennreal_Ex_less_of_nat infinite_arbitrarily_large infinity_ennreal_def)
  2108     moreover have \<open>sum f Y > y\<close> if \<open>finite Y\<close> and \<open>F \<subseteq> Y\<close> and \<open>Y \<subseteq> S\<close> for Y
  2074     moreover have \<open>sum f Y > y\<close> if \<open>finite Y\<close> and \<open>F \<subseteq> Y\<close> and \<open>Y \<subseteq> S\<close> for Y
  2109     proof -
  2075     proof -
  2110       have \<open>y < b * card F\<close>
  2076       have \<open>y < b * card F\<close>
  2111         by (metis \<open>y < \<infinity>\<close> b cardF divide_less_ennreal ennreal_mult_eq_top_iff gr_implies_not_zero infinity_ennreal_def mult.commute top.not_eq_extremum)
  2077         by (metis b \<open>y < top\<close> cardF divide_less_ennreal ennreal_mult_eq_top_iff gr_implies_not_zero mult.commute top.not_eq_extremum)
  2112       also have \<open>\<dots> \<le> b * card Y\<close>
  2078       also have \<open>\<dots> \<le> b * card Y\<close>
  2113         by (meson b card_mono less_imp_le mult_left_mono of_nat_le_iff that(1) that(2))
  2079         by (meson b card_mono less_imp_le mult_left_mono of_nat_le_iff that)
  2114       also have \<open>\<dots> = sum (\<lambda>_. b) Y\<close>
  2080       also have \<open>\<dots> = sum (\<lambda>_. b) Y\<close>
  2115         by (simp add: mult.commute)
  2081         by (simp add: mult.commute)
  2116       also have \<open>\<dots> \<le> sum f Y\<close>
  2082       also have \<open>\<dots> \<le> sum f Y\<close>
  2117         using geqb by (meson subset_eq sum_mono that(3))
  2083         using geqb by (meson subset_eq sum_mono that(3))
  2118       finally show ?thesis .
  2084       finally show ?thesis .
  2119     qed
  2085     qed
  2120     ultimately show \<open>\<forall>\<^sub>F x in finite_subsets_at_top S. y < sum f x\<close>
  2086     ultimately show \<open>\<forall>\<^sub>F x in finite_subsets_at_top S. y < sum f x\<close>
  2121       unfolding eventually_finite_subsets_at_top 
  2087       unfolding eventually_finite_subsets_at_top 
  2122       by auto
  2088       by auto
  2123   qed
  2089   qed auto
  2124   then show ?thesis
  2090   then show ?thesis
  2125     by (simp add: has_sum_def)
  2091     by (simp add: has_sum_def)
  2126 qed
  2092 qed
  2127 
  2093 
  2128 lemma infsum_superconst_infinite_ennreal:
  2094 lemma infsum_superconst_infinite_ennreal:
  2149     using assms b'
  2115     using assms b'
  2150     by (intro infsum_superconst_infinite_ennreal[where b=b']) (auto intro!: e2ennreal_mono)
  2116     by (intro infsum_superconst_infinite_ennreal[where b=b']) (auto intro!: e2ennreal_mono)
  2151   have \<open>infsum f S = infsum (enn2ereal \<circ> (e2ennreal \<circ> f)) S\<close>
  2117   have \<open>infsum f S = infsum (enn2ereal \<circ> (e2ennreal \<circ> f)) S\<close>
  2152     using geqb b by (intro infsum_cong) (fastforce simp: enn2ereal_e2ennreal)
  2118     using geqb b by (intro infsum_cong) (fastforce simp: enn2ereal_e2ennreal)
  2153   also have \<open>\<dots> = enn2ereal \<infinity>\<close>
  2119   also have \<open>\<dots> = enn2ereal \<infinity>\<close>
  2154     using * by (simp add: infsum_comm_additive_general continuous_at_enn2ereal)
  2120     using * by (simp add: infsum_comm_additive_general continuous_at_enn2ereal nonneg_summable_on_complete)
  2155   also have \<open>\<dots> = \<infinity>\<close>
  2121   also have \<open>\<dots> = \<infinity>\<close>
  2156     by simp
  2122     by simp
  2157   finally show ?thesis .
  2123   finally show ?thesis .
  2158 qed
  2124 qed
  2159 
  2125 
  2427   fixes f :: \<open>'a \<Rightarrow> complex\<close>
  2393   fixes f :: \<open>'a \<Rightarrow> complex\<close>
  2428   assumes \<open>f summable_on A\<close>
  2394   assumes \<open>f summable_on A\<close>
  2429   shows \<open>countable {x\<in>A. f x \<noteq> 0}\<close>
  2395   shows \<open>countable {x\<in>A. f x \<noteq> 0}\<close>
  2430   using abs_summable_countable assms summable_on_iff_abs_summable_on_complex by blast
  2396   using abs_summable_countable assms summable_on_iff_abs_summable_on_complex by blast
  2431 
  2397 
       
  2398 abbreviation has_sum' (infixr "has'_sum" 46) where
       
  2399   "(f has_sum S) A \<equiv> Infinite_Sum.has_sum f A S"
       
  2400 
       
  2401 
       
  2402 
       
  2403 (* TODO: figure all this out *)
       
  2404 inductive (in topological_space) convergent_filter :: "'a filter \<Rightarrow> bool" where
       
  2405   "F \<le> nhds x \<Longrightarrow> convergent_filter F"
       
  2406 
       
  2407 lemma (in topological_space) convergent_filter_iff: "convergent_filter F \<longleftrightarrow> (\<exists>x. F \<le> nhds x)"
       
  2408   by (auto simp: convergent_filter.simps)
       
  2409 
       
  2410 lemma (in uniform_space) cauchy_filter_mono:
       
  2411   "cauchy_filter F \<Longrightarrow> F' \<le> F \<Longrightarrow> cauchy_filter F'"
       
  2412   unfolding cauchy_filter_def by (meson dual_order.trans prod_filter_mono)
       
  2413 
       
  2414 lemma (in uniform_space) convergent_filter_cauchy: 
       
  2415   assumes "convergent_filter F"
       
  2416   shows   "cauchy_filter F"
       
  2417   using assms cauchy_filter_mono nhds_imp_cauchy_filter[OF order.refl]
       
  2418   by (auto simp: convergent_filter_iff)
       
  2419 
       
  2420 lemma (in topological_space) convergent_filter_bot [simp, intro]: "convergent_filter bot"
       
  2421   by (simp add: convergent_filter_iff)
       
  2422 
       
  2423 
       
  2424 
       
  2425 class complete_uniform_space = uniform_space +
       
  2426   assumes cauchy_filter_convergent': "cauchy_filter (F :: 'a filter) \<Longrightarrow> F \<noteq> bot \<Longrightarrow> convergent_filter F"
       
  2427 
       
  2428 lemma (in complete_uniform_space)
       
  2429   cauchy_filter_convergent: "cauchy_filter (F :: 'a filter) \<Longrightarrow> convergent_filter F"
       
  2430   using cauchy_filter_convergent'[of F] by (cases "F = bot") auto
       
  2431 
       
  2432 lemma (in complete_uniform_space) convergent_filter_iff_cauchy:
       
  2433   "convergent_filter F \<longleftrightarrow> cauchy_filter F"
       
  2434   using convergent_filter_cauchy cauchy_filter_convergent by blast
       
  2435 
       
  2436 definition countably_generated_filter :: "'a filter \<Rightarrow> bool" where
       
  2437   "countably_generated_filter F \<longleftrightarrow> (\<exists>U :: nat \<Rightarrow> 'a set. F = (INF (n::nat). principal (U n)))"
       
  2438 
       
  2439 lemma countably_generated_filter_has_antimono_basis:
       
  2440   assumes "countably_generated_filter F"
       
  2441   obtains B :: "nat \<Rightarrow> 'a set"
       
  2442   where "antimono B" and "F = (INF n. principal (B n))" and
       
  2443         "\<And>P. eventually P F \<longleftrightarrow> (\<exists>i. \<forall>x\<in>B i. P x)"
       
  2444 proof -
       
  2445   from assms obtain B where B: "F = (INF (n::nat). principal (B n))"
       
  2446     unfolding countably_generated_filter_def by blast
       
  2447 
       
  2448   define B' where "B' = (\<lambda>n. \<Inter>k\<le>n. B k)"
       
  2449   have "antimono B'"
       
  2450     unfolding decseq_def B'_def by force
       
  2451 
       
  2452   have "(INF n. principal (B' n)) = (INF n. INF k\<in>{..n}. principal (B k))"
       
  2453     unfolding B'_def by (intro INF_cong refl INF_principal_finite [symmetric]) auto
       
  2454   also have "\<dots> = (INF (n::nat). principal (B n))"
       
  2455     apply (intro antisym)
       
  2456     apply (meson INF_lower INF_mono atMost_iff order_refl)
       
  2457     apply (meson INF_greatest INF_lower UNIV_I)
       
  2458     done
       
  2459   also have "\<dots> = F"
       
  2460     by (simp add: B)
       
  2461   finally have F: "F = (INF n. principal (B' n))" ..
       
  2462 
       
  2463   moreover have "eventually P F \<longleftrightarrow> (\<exists>i. eventually P (principal (B' i)))" for P
       
  2464     unfolding F using \<open>antimono B'\<close>
       
  2465     apply (subst eventually_INF_base)
       
  2466       apply (auto simp: decseq_def)
       
  2467     by (meson nat_le_linear)
       
  2468   ultimately show ?thesis
       
  2469     using \<open>antimono B'\<close> that[of B'] unfolding eventually_principal by blast
       
  2470 qed
       
  2471 
       
  2472 lemma (in uniform_space) cauchy_filter_iff:
       
  2473   "cauchy_filter F \<longleftrightarrow> (\<forall>P. eventually P uniformity \<longrightarrow> (\<exists>X. eventually (\<lambda>x. x \<in> X) F \<and> (\<forall>z\<in>X\<times>X. P z)))" 
       
  2474   unfolding cauchy_filter_def le_filter_def
       
  2475   apply auto
       
  2476    apply (smt (z3) eventually_mono eventually_prod_same mem_Collect_eq)
       
  2477   using eventually_prod_same by blast                            
       
  2478 
       
  2479 lemma (in uniform_space) controlled_sequences_convergent_imp_complete_aux_sequence:
       
  2480   fixes U :: "nat \<Rightarrow> ('a \<times> 'a) set"
       
  2481   fixes F :: "'a filter"
       
  2482   assumes "cauchy_filter F" "F \<noteq> bot"
       
  2483   assumes "\<And>n. eventually (\<lambda>z. z \<in> U n) uniformity"
       
  2484   obtains g G where
       
  2485     "antimono G" "\<And>n. g n \<in> G n"
       
  2486     "\<And>n. eventually (\<lambda>x. x \<in> G n) F" "\<And>n. G n \<times> G n \<subseteq> U n"
       
  2487 proof -
       
  2488   have "\<exists>C. eventually (\<lambda>x. x \<in> C) F \<and> C \<times> C \<subseteq> U n" for n
       
  2489     using assms(1) assms(3)[of n] unfolding cauchy_filter_iff by blast
       
  2490   then obtain G where G: "\<And>n. eventually (\<lambda>x. x \<in> G n) F" "\<And>n. G n \<times> G n \<subseteq> U n"
       
  2491     by metis
       
  2492   define G' where "G' = (\<lambda>n. \<Inter>k\<le>n. G k)"
       
  2493   have 1: "eventually (\<lambda>x. x \<in> G' n) F" for n
       
  2494     using G by (auto simp: G'_def intro: eventually_ball_finite)
       
  2495   have 2: "G' n \<times> G' n \<subseteq> U n" for n
       
  2496     using G unfolding G'_def by fast
       
  2497   have 3: "antimono G'"
       
  2498     unfolding G'_def decseq_def by force
       
  2499 
       
  2500   have "\<exists>g. g \<in> G' n" for n
       
  2501     using 1 assms(2) eventually_happens' by auto
       
  2502   then obtain g where g: "\<And>n. g n \<in> G' n"
       
  2503     by metis
       
  2504   from g 1 2 3 that[of G' g] show ?thesis
       
  2505     by metis
       
  2506 qed
       
  2507 
       
  2508 definition lift_filter :: "('a set \<Rightarrow> 'b filter) \<Rightarrow> 'a filter \<Rightarrow> 'b filter" where
       
  2509   "lift_filter f F = (INF X\<in>{X. eventually (\<lambda>x. x \<in> X) F}. f X)"
       
  2510 
       
  2511 lemma lift_filter_top [simp]: "lift_filter g top = g UNIV"
       
  2512 proof -
       
  2513   have "{X. \<forall>x::'b. x \<in> X} = {UNIV}"
       
  2514     by auto
       
  2515   thus ?thesis
       
  2516     by (simp add: lift_filter_def)
       
  2517 qed
       
  2518 
       
  2519 lemma eventually_lift_filter_iff:
       
  2520   assumes "mono g"
       
  2521   shows   "eventually P (lift_filter g F) \<longleftrightarrow> (\<exists>X. eventually (\<lambda>x. x \<in> X) F \<and> eventually P (g X))"
       
  2522   unfolding lift_filter_def
       
  2523 proof (subst eventually_INF_base, goal_cases)
       
  2524   case 1
       
  2525   thus ?case by (auto intro: exI[of _ UNIV])
       
  2526 next
       
  2527   case (2 X Y)
       
  2528   thus ?case
       
  2529     by (auto intro!: exI[of _ "X \<inter> Y"] eventually_conj monoD[OF assms])
       
  2530 qed auto
       
  2531 
       
  2532 lemma lift_filter_le:
       
  2533   assumes "eventually (\<lambda>x. x \<in> X) F" "g X \<le> F'"
       
  2534   shows   "lift_filter g F \<le> F'"
       
  2535   unfolding lift_filter_def
       
  2536   by (rule INF_lower2[of X _ g F', OF _ assms(2)]) (use assms(1) in auto)
       
  2537 
       
  2538 definition lift_filter' :: "('a set \<Rightarrow> 'b set) \<Rightarrow> 'a filter \<Rightarrow> 'b filter" where
       
  2539   "lift_filter' f F = lift_filter (principal \<circ> f) F"
       
  2540 
       
  2541 lemma lift_filter'_top [simp]: "lift_filter' g top = principal (g UNIV)"
       
  2542   by (simp add: lift_filter'_def)
       
  2543 
       
  2544 lemma eventually_lift_filter'_iff:
       
  2545   assumes "mono g"
       
  2546   shows   "eventually P (lift_filter' g F) \<longleftrightarrow> (\<exists>X. eventually (\<lambda>x. x \<in> X) F \<and> (\<forall>x\<in>g X. P x))"
       
  2547   unfolding lift_filter'_def using assms
       
  2548   by (subst eventually_lift_filter_iff) (auto simp: mono_def eventually_principal)
       
  2549 
       
  2550 lemma lift_filter'_le:
       
  2551   assumes "eventually (\<lambda>x. x \<in> X) F" "principal (g X) \<le> F'"
       
  2552   shows   "lift_filter' g F \<le> F'"
       
  2553   unfolding lift_filter'_def using assms
       
  2554   by (intro lift_filter_le[where X = X]) auto
       
  2555 
       
  2556 
       
  2557 lemma (in uniform_space) comp_uniformity_le_uniformity:
       
  2558   "lift_filter' (\<lambda>X. X O X) uniformity \<le> uniformity"
       
  2559   unfolding le_filter_def
       
  2560 proof safe
       
  2561   fix P assume P: "eventually P uniformity"
       
  2562   have [simp]: "mono (\<lambda>X::('a \<times> 'a) set. X O X)"
       
  2563     by (intro monoI) auto
       
  2564   from P obtain P' where P': "eventually P' uniformity " "(\<And>x y z. P' (x, y) \<Longrightarrow> P' (y, z) \<Longrightarrow> P (x, z))"
       
  2565     using uniformity_transE by blast
       
  2566   show "eventually P (lift_filter' (\<lambda>X. X O X) uniformity)"
       
  2567     by (auto simp: eventually_lift_filter'_iff intro!: exI[of _ "{x. P' x}"] P')
       
  2568 qed
       
  2569 
       
  2570 lemma (in uniform_space) comp_mem_uniformity_sets:
       
  2571   assumes "eventually (\<lambda>z. z \<in> X) uniformity"
       
  2572   obtains Y where "eventually (\<lambda>z. z \<in> Y) uniformity" "Y O Y \<subseteq> X"
       
  2573 proof -
       
  2574   have [simp]: "mono (\<lambda>X::('a \<times> 'a) set. X O X)"
       
  2575     by (intro monoI) auto
       
  2576   have "eventually (\<lambda>z. z \<in> X) (lift_filter' (\<lambda>X. X O X) uniformity)"
       
  2577     using assms comp_uniformity_le_uniformity using filter_leD by blast
       
  2578   thus ?thesis using that
       
  2579     by (auto simp: eventually_lift_filter'_iff)
       
  2580 qed
       
  2581 
       
  2582 lemma (in uniform_space) le_nhds_of_cauchy_adhp_aux:
       
  2583   assumes "\<And>P. eventually P uniformity \<Longrightarrow> (\<exists>X. eventually (\<lambda>y. y \<in> X) F \<and> (\<forall>z\<in>X \<times> X. P z) \<and> (\<exists>y. P (x, y) \<and> y \<in> X))"
       
  2584   shows   "F \<le> nhds x"
       
  2585   unfolding le_filter_def
       
  2586 proof safe
       
  2587   fix P assume "eventually P (nhds x)"
       
  2588   hence "\<forall>\<^sub>F z in uniformity. z \<in> {z. fst z = x \<longrightarrow> P (snd z)}"
       
  2589     by (simp add: eventually_nhds_uniformity case_prod_unfold)
       
  2590   then obtain Y where Y: "\<forall>\<^sub>F z in uniformity. z \<in> Y" "Y O Y \<subseteq> {z. fst z = x \<longrightarrow> P (snd z)}"
       
  2591     using comp_mem_uniformity_sets by blast
       
  2592   obtain X y where Xy: "eventually (\<lambda>y. y \<in> X) F" "X\<times>X \<subseteq> Y" "(x, y) \<in> Y" "y \<in> X"
       
  2593     using assms[OF Y(1)] by blast
       
  2594   have *: "P x" if "x \<in> X" for x
       
  2595     using Y(2) Xy(2-4) that unfolding relcomp_unfold by force  
       
  2596   show "eventually P F"
       
  2597     by (rule eventually_mono[OF Xy(1)]) (use * in auto)
       
  2598 qed
       
  2599 
       
  2600 lemma (in uniform_space) eventually_uniformity_imp_nhds:
       
  2601   assumes "eventually P uniformity"
       
  2602   shows   "eventually (\<lambda>y. P (x, y)) (nhds x)"
       
  2603   using assms unfolding eventually_nhds_uniformity by (elim eventually_mono) auto
       
  2604 
       
  2605 lemma (in uniform_space) controlled_sequences_convergent_imp_complete_aux:
       
  2606   fixes U :: "nat \<Rightarrow> ('a \<times> 'a) set"
       
  2607   assumes gen: "countably_generated_filter (uniformity :: ('a \<times> 'a) filter)"
       
  2608   assumes U: "\<And>n. eventually (\<lambda>z. z \<in> U n) uniformity"
       
  2609   assumes conv: "\<And>(u :: nat \<Rightarrow> 'a). (\<And>N m n. N \<le> m \<Longrightarrow> N \<le> n \<Longrightarrow> (u m, u n) \<in> U N) \<Longrightarrow> convergent u"
       
  2610   assumes "cauchy_filter F"
       
  2611   shows   "convergent_filter F"
       
  2612 proof (cases "F = bot")
       
  2613   case False
       
  2614   note F = \<open>cauchy_filter F\<close> \<open>F \<noteq> bot\<close>
       
  2615   from gen obtain B :: "nat \<Rightarrow> ('a \<times> 'a) set" where B:
       
  2616     "antimono B" "uniformity = (INF n. principal (B n))"
       
  2617     "\<And>P. eventually P uniformity \<longleftrightarrow> (\<exists>i. \<forall>x\<in>B i. P x)"
       
  2618     using countably_generated_filter_has_antimono_basis by blast
       
  2619 
       
  2620   have ev_B: "eventually (\<lambda>z. z \<in> B n) uniformity" for n
       
  2621     by (subst B(3)) auto
       
  2622   hence ev_B': "eventually (\<lambda>z. z \<in> B n \<inter> U n) uniformity" for n
       
  2623     using U by (auto intro: eventually_conj)
       
  2624 
       
  2625   obtain g G where gG: "antimono G" "\<And>n. g n \<in> G n"
       
  2626     "\<And>n. eventually (\<lambda>x. x \<in> G n) F" "\<And>n. G n \<times> G n \<subseteq> B n \<inter> U n"
       
  2627     using controlled_sequences_convergent_imp_complete_aux_sequence[of F "\<lambda>n. B n \<inter> U n", OF F ev_B']
       
  2628     by metis
       
  2629 
       
  2630   have "convergent g"
       
  2631   proof (rule conv)
       
  2632     fix N m n :: nat
       
  2633     assume mn: "N \<le> m" "N \<le> n"
       
  2634     have "(g m, g n) \<in> G m \<times> G n"
       
  2635       using gG by auto
       
  2636     also from mn have "\<dots> \<subseteq> G N \<times> G N"
       
  2637       by (intro Sigma_mono gG antimonoD[OF gG(1)])
       
  2638     also have "\<dots> \<subseteq> U N"
       
  2639       using gG by blast
       
  2640     finally show "(g m, g n) \<in> U N" .
       
  2641   qed
       
  2642   then obtain L where G: "g \<longlonglongrightarrow> L"
       
  2643     unfolding convergent_def by blast
       
  2644 
       
  2645   have "F \<le> nhds L"
       
  2646   proof (rule le_nhds_of_cauchy_adhp_aux)
       
  2647     fix P :: "'a \<times> 'a \<Rightarrow> bool"
       
  2648     assume P: "eventually P uniformity"
       
  2649     hence "eventually (\<lambda>n. \<forall>x\<in>B n. P x) sequentially"
       
  2650       using \<open>antimono B\<close> unfolding B(3) eventually_sequentially decseq_def by blast
       
  2651     moreover have "eventually (\<lambda>n. P (L, g n)) sequentially"
       
  2652       using P eventually_compose_filterlim eventually_uniformity_imp_nhds G by blast
       
  2653     ultimately have "eventually (\<lambda>n. (\<forall>x\<in>B n. P x) \<and> P (L, g n)) sequentially"
       
  2654       by eventually_elim auto
       
  2655     then obtain n where n: "\<forall>x\<in>B n. P x" "P (L, g n)"
       
  2656       unfolding eventually_at_top_linorder by blast
       
  2657 
       
  2658     have "eventually (\<lambda>y. y \<in> G n) F" "\<forall>z\<in>G n \<times> G n. P z"  "g n \<in> G n" "P (L, g n)"
       
  2659       using n gG by blast+
       
  2660     thus "\<exists>X. (\<forall>\<^sub>F y in F. y \<in> X) \<and> (\<forall>z\<in>X \<times> X. P z) \<and> (\<exists>y. P (L, y) \<and> y \<in> X)"
       
  2661       by blast      
       
  2662   qed
       
  2663   thus "convergent_filter F"
       
  2664     by (auto simp: convergent_filter_iff)
       
  2665 qed auto
       
  2666 
       
  2667 theorem (in uniform_space) controlled_sequences_convergent_imp_complete:
       
  2668   fixes U :: "nat \<Rightarrow> ('a \<times> 'a) set"
       
  2669   assumes gen: "countably_generated_filter (uniformity :: ('a \<times> 'a) filter)"
       
  2670   assumes U: "\<And>n. eventually (\<lambda>z. z \<in> U n) uniformity"
       
  2671   assumes conv: "\<And>(u :: nat \<Rightarrow> 'a). (\<And>N m n. N \<le> m \<Longrightarrow> N \<le> n \<Longrightarrow> (u m, u n) \<in> U N) \<Longrightarrow> convergent u"
       
  2672   shows "class.complete_uniform_space open uniformity"
       
  2673   by unfold_locales (use assms controlled_sequences_convergent_imp_complete_aux in blast)
       
  2674 
       
  2675 lemma filtermap_prod_filter: "filtermap (map_prod f g) (F \<times>\<^sub>F G) = filtermap f F \<times>\<^sub>F filtermap g G"
       
  2676 proof (intro antisym)
       
  2677   show "filtermap (map_prod f g) (F \<times>\<^sub>F G) \<le> filtermap f F \<times>\<^sub>F filtermap g G"
       
  2678     by (auto simp: le_filter_def eventually_filtermap eventually_prod_filter)
       
  2679 next
       
  2680   show "filtermap f F \<times>\<^sub>F filtermap g G \<le> filtermap (map_prod f g) (F \<times>\<^sub>F G)"
       
  2681     unfolding le_filter_def
       
  2682   proof safe
       
  2683     fix P assume P: "eventually P (filtermap (map_prod f g) (F \<times>\<^sub>F G))"
       
  2684     then obtain Pf Pg where *: "eventually Pf F" "eventually Pg G" "\<forall>x. Pf x \<longrightarrow> (\<forall>y. Pg y \<longrightarrow> P (f x, g y))"
       
  2685       by (auto simp: eventually_filtermap eventually_prod_filter)
       
  2686 
       
  2687     define Pf' where "Pf' = (\<lambda>x. \<exists>y. x = f y \<and> Pf y)"
       
  2688     define Pg' where "Pg' = (\<lambda>x. \<exists>y. x = g y \<and> Pg y)"
       
  2689 
       
  2690     from *(1) have "\<forall>\<^sub>F x in F. Pf' (f x)"
       
  2691       by eventually_elim (auto simp: Pf'_def)
       
  2692     moreover from *(2) have "\<forall>\<^sub>F x in G. Pg' (g x)"
       
  2693       by eventually_elim (auto simp: Pg'_def)
       
  2694     moreover have "(\<forall>x y. Pf' x \<longrightarrow> Pg' y \<longrightarrow> P (x, y))"
       
  2695       using *(3) by (auto simp: Pf'_def Pg'_def)
       
  2696     ultimately show "eventually P (filtermap f F \<times>\<^sub>F filtermap g G)"
       
  2697       unfolding eventually_prod_filter eventually_filtermap
       
  2698       by blast
       
  2699   qed
       
  2700 qed
       
  2701       
       
  2702 
       
  2703 lemma (in uniform_space) Cauchy_seq_iff_tendsto:
       
  2704   "Cauchy f \<longleftrightarrow> filterlim (map_prod f f) uniformity (at_top \<times>\<^sub>F at_top)"
       
  2705   unfolding Cauchy_uniform cauchy_filter_def filterlim_def filtermap_prod_filter ..
       
  2706 
       
  2707 theorem (in uniform_space) controlled_seq_imp_Cauchy_seq:
       
  2708   fixes U :: "nat \<Rightarrow> ('a \<times> 'a) set"
       
  2709   assumes U: "\<And>P. eventually P uniformity \<Longrightarrow> (\<exists>n. \<forall>x\<in>U n. P x)"
       
  2710   assumes controlled: "\<And>N m n. N \<le> m \<Longrightarrow> N \<le> n \<Longrightarrow> (f m, f n) \<in> U N"
       
  2711   shows   "Cauchy f"
       
  2712   unfolding Cauchy_seq_iff_tendsto
       
  2713 proof -
       
  2714   show "filterlim (map_prod f f) uniformity (sequentially \<times>\<^sub>F sequentially)"
       
  2715     unfolding filterlim_def le_filter_def
       
  2716   proof safe
       
  2717     fix P :: "'a \<times> 'a \<Rightarrow> bool"
       
  2718     assume P: "eventually P uniformity"
       
  2719     from U[OF this] obtain N where N: "\<forall>x\<in>U N. P x"
       
  2720       by blast
       
  2721 
       
  2722     show "eventually P (filtermap (map_prod f f) (sequentially \<times>\<^sub>F sequentially))"
       
  2723       unfolding eventually_filtermap eventually_prod_sequentially
       
  2724       by (rule exI[of _ N]) (use controlled N in \<open>auto simp: map_prod_def\<close>)
       
  2725   qed
       
  2726 qed
       
  2727 
       
  2728 lemma (in uniform_space) Cauchy_seq_convergent_imp_complete_aux:
       
  2729   fixes U :: "nat \<Rightarrow> ('a \<times> 'a) set"
       
  2730   assumes gen: "countably_generated_filter (uniformity :: ('a \<times> 'a) filter)"
       
  2731   assumes conv: "\<And>(u :: nat \<Rightarrow> 'a). Cauchy u \<Longrightarrow> convergent u"
       
  2732   assumes "cauchy_filter F"
       
  2733   shows   "convergent_filter F"
       
  2734 proof -
       
  2735   from gen obtain B :: "nat \<Rightarrow> ('a \<times> 'a) set" where B:
       
  2736     "antimono B" "uniformity = (INF n. principal (B n))"
       
  2737     "\<And>P. eventually P uniformity \<longleftrightarrow> (\<exists>i. \<forall>x\<in>B i. P x)"
       
  2738     using countably_generated_filter_has_antimono_basis by blast
       
  2739 
       
  2740   show ?thesis
       
  2741   proof (rule controlled_sequences_convergent_imp_complete_aux[where U = B])
       
  2742     show "\<forall>\<^sub>F z in uniformity. z \<in> B n" for n
       
  2743       unfolding B(3) by blast
       
  2744   next
       
  2745     fix f :: "nat \<Rightarrow> 'a"
       
  2746     assume f: "\<And>N m n. N \<le> m \<Longrightarrow> N \<le> n \<Longrightarrow> (f m, f n) \<in> B N"
       
  2747     have "Cauchy f" using f B
       
  2748       by (intro controlled_seq_imp_Cauchy_seq[where U = B]) auto
       
  2749     with conv show "convergent f"
       
  2750       by simp
       
  2751   qed fact+
       
  2752 qed
       
  2753 
       
  2754 theorem (in uniform_space) Cauchy_seq_convergent_imp_complete:
       
  2755   fixes U :: "nat \<Rightarrow> ('a \<times> 'a) set"
       
  2756   assumes gen: "countably_generated_filter (uniformity :: ('a \<times> 'a) filter)"
       
  2757   assumes conv: "\<And>(u :: nat \<Rightarrow> 'a). Cauchy u \<Longrightarrow> convergent u"
       
  2758   shows   "class.complete_uniform_space open uniformity"
       
  2759   by unfold_locales (use assms Cauchy_seq_convergent_imp_complete_aux in blast)
       
  2760 
       
  2761 lemma (in metric_space) countably_generated_uniformity:
       
  2762   "countably_generated_filter uniformity"
       
  2763 proof -
       
  2764   have "(INF e\<in>{0<..}. principal {(x, y). dist (x::'a) y < e}) =
       
  2765         (INF n\<in>UNIV. principal {(x, y). dist x y < 1 / real (Suc n)})" (is "?F = ?G")
       
  2766     unfolding uniformity_dist
       
  2767   proof (intro antisym)
       
  2768     have "?G = (INF e\<in>(\<lambda>n. 1 / real (Suc n)) ` UNIV. principal {(x, y). dist x y < e})"
       
  2769       by (simp add: image_image)
       
  2770     also have "\<dots> \<ge> ?F"
       
  2771       by (intro INF_superset_mono) auto
       
  2772     finally show "?F \<le> ?G" .
       
  2773   next
       
  2774     show "?G \<le> ?F"
       
  2775       unfolding le_filter_def
       
  2776     proof safe
       
  2777       fix P assume "eventually P ?F"
       
  2778       then obtain \<epsilon> where \<epsilon>: "\<epsilon> > 0" "eventually P (principal {(x, y). dist x y < \<epsilon>})"
       
  2779       proof (subst (asm) eventually_INF_base, goal_cases)
       
  2780         case (2 \<epsilon>1 \<epsilon>2)
       
  2781         thus ?case
       
  2782           by (intro bexI[of _ "min \<epsilon>1 \<epsilon>2"]) auto
       
  2783       qed auto
       
  2784       from \<open>\<epsilon> > 0\<close> obtain n where n: "1 / real (Suc n) < \<epsilon>"
       
  2785         using nat_approx_posE by blast
       
  2786       have "eventually P (principal {(x, y). dist x y < 1 / real (Suc n)})"
       
  2787         using \<epsilon>(2) n by (auto simp: eventually_principal)
       
  2788       thus "eventually P ?G"
       
  2789         by (intro eventually_INF1) auto
       
  2790     qed
       
  2791   qed
       
  2792   thus "countably_generated_filter uniformity"
       
  2793     unfolding countably_generated_filter_def uniformity_dist by fast
       
  2794 qed
       
  2795 
       
  2796 subclass (in complete_space) complete_uniform_space
       
  2797 proof (rule Cauchy_seq_convergent_imp_complete)
       
  2798   show "convergent f" if "Cauchy f" for f
       
  2799     using Cauchy_convergent that by blast
       
  2800 qed (fact countably_generated_uniformity)
       
  2801 
       
  2802 lemma (in complete_uniform_space) complete_UNIV_cuspace [intro]: "complete UNIV"
       
  2803   unfolding complete_uniform using cauchy_filter_convergent
       
  2804   by (auto simp: convergent_filter.simps)
       
  2805 
       
  2806 
       
  2807 
       
  2808 lemma norm_infsum_le:
       
  2809   assumes "(f has_sum S) X"
       
  2810   assumes "(g has_sum T) X"
       
  2811   assumes "\<And>x. x \<in> X \<Longrightarrow> norm (f x) \<le> g x"
       
  2812   shows   "norm S \<le> T"
       
  2813 proof (rule tendsto_le)
       
  2814   show "((\<lambda>Y. norm (\<Sum>x\<in>Y. f x)) \<longlongrightarrow> norm S) (finite_subsets_at_top X)"
       
  2815     using assms(1) unfolding has_sum_def by (intro tendsto_norm)
       
  2816   show "((\<lambda>Y. \<Sum>x\<in>Y. g x) \<longlongrightarrow> T) (finite_subsets_at_top X)"
       
  2817     using assms(2) unfolding has_sum_def .
       
  2818   show "\<forall>\<^sub>F x in finite_subsets_at_top X. norm (sum f x) \<le> (\<Sum>x\<in>x. g x)"
       
  2819     by (rule eventually_finite_subsets_at_top_weakI) (auto intro!: sum_norm_le assms)
       
  2820 qed auto
       
  2821 
       
  2822 (*
       
  2823 lemma summable_on_Sigma:
       
  2824   fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set"
       
  2825     and f :: \<open>'a \<Rightarrow> 'b \<Rightarrow> 'c::{comm_monoid_add, t2_space, uniform_space}\<close>
       
  2826   assumes plus_cont: \<open>uniformly_continuous_on UNIV (\<lambda>(x::'c,y). x+y)\<close>
       
  2827   assumes summableAB: "(\<lambda>(x,y). f x y) summable_on (Sigma A B)"
       
  2828   assumes summableB: \<open>\<And>x. x\<in>A \<Longrightarrow> (f x) summable_on (B x)\<close>
       
  2829   shows \<open>(\<lambda>x. infsum (f x) (B x)) summable_on A\<close>
       
  2830 *)
       
  2831 
       
  2832 lemma has_sum_imp_summable: "(f has_sum S) A \<Longrightarrow> f summable_on A"
       
  2833   by (auto simp: summable_on_def)
       
  2834 
       
  2835 lemma has_sum_reindex_bij_betw:
       
  2836   assumes "bij_betw g A B"
       
  2837   shows   "((\<lambda>x. f (g x)) has_sum S) A = (f has_sum S) B"
       
  2838 proof -
       
  2839   have "((\<lambda>x. f (g x)) has_sum S) A \<longleftrightarrow> (f has_sum S) (g ` A)"
       
  2840     by (subst has_sum_reindex) (use assms in \<open>auto dest: bij_betw_imp_inj_on simp: o_def\<close>)
       
  2841   also have "g ` A = B"
       
  2842     using assms bij_betw_imp_surj_on by blast
       
  2843   finally show ?thesis .
       
  2844 qed
       
  2845 
       
  2846 lemma has_sum_reindex_bij_witness:
       
  2847   assumes "\<And>a. a \<in> S \<Longrightarrow> i (j a) = a"
       
  2848   assumes "\<And>a. a \<in> S \<Longrightarrow> j a \<in> T"
       
  2849   assumes "\<And>b. b \<in> T \<Longrightarrow> j (i b) = b"
       
  2850   assumes "\<And>b. b \<in> T \<Longrightarrow> i b \<in> S"
       
  2851   assumes "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a"
       
  2852   assumes "s = s'"
       
  2853   shows   "(g has_sum s) S = (h has_sum s') T"
       
  2854 proof -
       
  2855   have bij:"bij_betw j S T"
       
  2856     using assms by (intro bij_betwI[of _ _ _ i]) auto
       
  2857   have "(h has_sum s') T \<longleftrightarrow> ((\<lambda>a. h (j a)) has_sum s) S"
       
  2858     using has_sum_reindex_bij_betw[OF bij, of h] assms by simp
       
  2859   also have "\<dots> \<longleftrightarrow> (g has_sum s) S"
       
  2860     by (intro has_sum_cong) (use assms in auto)
       
  2861   finally show ?thesis ..
       
  2862 qed
       
  2863 
       
  2864 
       
  2865 
       
  2866 lemma has_sum_homomorphism:
       
  2867   assumes "(f has_sum S) A" "h 0 = 0" "\<And>a b. h (a + b) = h a + h b" "continuous_on UNIV h"
       
  2868   shows   "((\<lambda>x. h (f x)) has_sum (h S)) A"
       
  2869 proof -
       
  2870   have "sum (h \<circ> f) X = h (sum f X)" for X
       
  2871     by (induction X rule: infinite_finite_induct) (simp_all add: assms)
       
  2872   hence sum_h: "sum (h \<circ> f) = h \<circ> sum f"
       
  2873     by (intro ext) auto
       
  2874   have "((h \<circ> f) has_sum h S) A"
       
  2875     unfolding has_sum_def sum_h unfolding o_def
       
  2876     by (rule continuous_on_tendsto_compose[OF assms(4)])
       
  2877        (use assms in \<open>auto simp: has_sum_def\<close>)
       
  2878   thus ?thesis
       
  2879     by (simp add: o_def)
       
  2880 qed
       
  2881 
       
  2882 lemma summable_on_homomorphism:
       
  2883   assumes "f summable_on A" "h 0 = 0" "\<And>a b. h (a + b) = h a + h b" "continuous_on UNIV h"
       
  2884   shows   "(\<lambda>x. h (f x)) summable_on A"
       
  2885 proof -
       
  2886   from assms(1) obtain S where "(f has_sum S) A"
       
  2887     by (auto simp: summable_on_def)
       
  2888   hence "((\<lambda>x. h (f x)) has_sum h S) A"
       
  2889     by (rule has_sum_homomorphism) (use assms in auto)
       
  2890   thus ?thesis
       
  2891     by (auto simp: summable_on_def)
       
  2892 qed
       
  2893 
       
  2894 lemma infsum_homomorphism_strong:
       
  2895   fixes h :: "'a :: {t2_space, topological_comm_monoid_add} \<Rightarrow>
       
  2896                 'b :: {t2_space, topological_comm_monoid_add}"
       
  2897   assumes "(\<lambda>x. h (f x)) summable_on A \<longleftrightarrow> f summable_on A"
       
  2898   assumes "h 0 = 0" "\<And>a b. h (a + b) = h a + h b" "continuous_on UNIV h"
       
  2899   assumes "\<And>S. (f has_sum S) A \<Longrightarrow> ((\<lambda>x. h (f x)) has_sum (h S)) A"
       
  2900   shows   "infsum (\<lambda>x. h (f x)) A = h (infsum f A)"
       
  2901 proof (cases "f summable_on A")
       
  2902   case False
       
  2903   thus ?thesis by (simp add: infsum_def assms)
       
  2904 next
       
  2905   case True
       
  2906   then obtain S where "(f has_sum S) A" by (auto simp: summable_on_def)
       
  2907   moreover from this have "((\<lambda>x. h (f x)) has_sum (h S)) A" by (rule assms)
       
  2908   ultimately show ?thesis by (simp add: infsumI)
       
  2909 qed
       
  2910 
       
  2911 lemma has_sum_bounded_linear:
       
  2912   assumes "bounded_linear h" and "(f has_sum S) A"
       
  2913   shows "((\<lambda>x. h (f x)) has_sum h S) A"
       
  2914 proof -
       
  2915   interpret bounded_linear h by fact
       
  2916   from assms(2) show ?thesis
       
  2917     by (rule has_sum_homomorphism) (auto simp: add intro!: continuous_on)
       
  2918 qed
       
  2919 
       
  2920 lemma summable_on_bounded_linear:
       
  2921   assumes "bounded_linear h" and "f summable_on A"
       
  2922   shows "(\<lambda>x. h (f x)) summable_on A"
       
  2923 proof -
       
  2924   interpret bounded_linear h by fact
       
  2925   from assms(2) show ?thesis
       
  2926     by (rule summable_on_homomorphism) (auto simp: add intro!: continuous_on)
       
  2927 qed
       
  2928 
       
  2929 lemma summable_on_bounded_linear_iff:
       
  2930   assumes "bounded_linear h" and "bounded_linear h'" and "\<And>x. h' (h x) = x"
       
  2931   shows "(\<lambda>x. h (f x)) summable_on A \<longleftrightarrow> f summable_on A"
       
  2932   by (auto dest: assms(1,2)[THEN summable_on_bounded_linear] simp: assms(3))
       
  2933 
       
  2934 lemma infsum_bounded_linear_strong:
       
  2935   fixes h :: "'a :: real_normed_vector \<Rightarrow> 'b :: real_normed_vector"
       
  2936   assumes "(\<lambda>x. h (f x)) summable_on A \<longleftrightarrow> f summable_on A"
       
  2937   assumes "bounded_linear h"
       
  2938   shows   "infsum (\<lambda>x. h (f x)) A = h (infsum f A)"
       
  2939 proof -
       
  2940   interpret bounded_linear h by fact
       
  2941   show ?thesis
       
  2942     by (rule infsum_homomorphism_strong)
       
  2943        (insert assms, auto intro: add continuous_on has_sum_bounded_linear)
       
  2944 qed
       
  2945 
       
  2946 lemma infsum_bounded_linear_strong':
       
  2947   fixes mult :: "'c :: zero \<Rightarrow> 'a :: real_normed_vector \<Rightarrow> 'b :: real_normed_vector"
       
  2948   assumes "c \<noteq> 0 \<Longrightarrow> (\<lambda>x. mult c (f x)) summable_on A \<longleftrightarrow> f summable_on A"
       
  2949   assumes "bounded_linear (mult c)"
       
  2950   assumes [simp]: "\<And>x. mult 0 x = 0"
       
  2951   shows   "infsum (\<lambda>x. mult c (f x)) A = mult c (infsum f A)"
       
  2952   using assms(1,2) by (cases "c = 0") (auto intro: infsum_bounded_linear_strong)
       
  2953 
       
  2954 lemma has_sum_of_nat: "(f has_sum S) A \<Longrightarrow> ((\<lambda>x. of_nat (f x)) has_sum of_nat S) A"
       
  2955   by (erule has_sum_homomorphism) (auto intro!: continuous_intros)
       
  2956 
       
  2957 lemma has_sum_of_int: "(f has_sum S) A \<Longrightarrow> ((\<lambda>x. of_int (f x)) has_sum of_int S) A"
       
  2958   by (erule has_sum_homomorphism) (auto intro!: continuous_intros)
       
  2959 
       
  2960 lemma summable_on_of_nat: "f summable_on A \<Longrightarrow> (\<lambda>x. of_nat (f x)) summable_on A"
       
  2961   by (erule summable_on_homomorphism) (auto intro!: continuous_intros)
       
  2962 
       
  2963 lemma summable_on_of_int: "f summable_on A \<Longrightarrow> (\<lambda>x. of_int (f x)) summable_on A"
       
  2964   by (erule summable_on_homomorphism) (auto intro!: continuous_intros)
       
  2965 
       
  2966 lemma summable_on_discrete_iff:
       
  2967   fixes f :: "'a \<Rightarrow> 'b :: {discrete_topology, topological_comm_monoid_add, cancel_comm_monoid_add}"
       
  2968   shows "f summable_on A \<longleftrightarrow> finite {x\<in>A. f x \<noteq> 0}"
       
  2969 proof
       
  2970   assume *: "finite {x\<in>A. f x \<noteq> 0}"
       
  2971   hence "f summable_on {x\<in>A. f x \<noteq> 0}"
       
  2972     by (rule summable_on_finite)
       
  2973   also have "?this \<longleftrightarrow> f summable_on A"
       
  2974     by (intro summable_on_cong_neutral) auto
       
  2975   finally show "f summable_on A" .
       
  2976 next
       
  2977   assume "f summable_on A"
       
  2978   then obtain S where "(f has_sum S) A"
       
  2979     by (auto simp: summable_on_def)
       
  2980   hence "\<forall>\<^sub>F x in finite_subsets_at_top A. sum f x = S"
       
  2981     unfolding has_sum_def tendsto_discrete .
       
  2982   then obtain X where X: "finite X" "X \<subseteq> A" "\<And>Y. finite Y \<Longrightarrow> X \<subseteq> Y \<Longrightarrow> Y \<subseteq> A \<Longrightarrow> sum f Y = S"
       
  2983     unfolding eventually_finite_subsets_at_top by metis
       
  2984   have "{x\<in>A. f x \<noteq> 0} \<subseteq> X"
       
  2985   proof
       
  2986     fix x assume x: "x \<in> {x\<in>A. f x \<noteq> 0}"
       
  2987     show "x \<in> X"
       
  2988     proof (rule ccontr)
       
  2989       assume [simp]: "x \<notin> X"
       
  2990       have "sum f (insert x X) = S"
       
  2991         using X(1,2) x by (intro X) auto
       
  2992       also have "sum f (insert x X) = f x + sum f X"
       
  2993         using X(1) by (subst sum.insert) auto
       
  2994       also have "sum f X = S"
       
  2995         by (intro X order.refl)
       
  2996       finally have "f x = 0"
       
  2997         by simp
       
  2998       with x show False
       
  2999         by auto
       
  3000     qed
       
  3001   qed
       
  3002   thus "finite {x\<in>A. f x \<noteq> 0}"
       
  3003     using X(1) finite_subset by blast
       
  3004 qed
       
  3005 
       
  3006 lemma has_sum_imp_sums: "(f has_sum S) (UNIV :: nat set) \<Longrightarrow> f sums S"
       
  3007   unfolding sums_def has_sum_def by (rule filterlim_compose[OF _ filterlim_lessThan_at_top])
       
  3008 
       
  3009 lemma summable_on_imp_summable: "f summable_on (UNIV :: nat set) \<Longrightarrow> summable f"
       
  3010   unfolding summable_on_def summable_def by (auto dest: has_sum_imp_sums)
       
  3011 
       
  3012 lemma summable_on_UNIV_nonneg_real_iff:
       
  3013   assumes "\<And>n. f n \<ge> (0 :: real)"
       
  3014   shows   "f summable_on UNIV \<longleftrightarrow> summable f"
       
  3015   using assms by (auto intro: norm_summable_imp_summable_on summable_on_imp_summable)
       
  3016 
       
  3017 lemma summable_on_imp_bounded_partial_sums:
       
  3018   fixes f :: "_ \<Rightarrow> 'a :: {topological_comm_monoid_add, linorder_topology}"
       
  3019   assumes f: "f summable_on A"
       
  3020   shows   "\<exists>C. eventually (\<lambda>X. sum f X \<le> C) (finite_subsets_at_top A)"
       
  3021 proof -
       
  3022   from assms obtain S where S: "(sum f \<longlongrightarrow> S) (finite_subsets_at_top A)"
       
  3023     unfolding summable_on_def has_sum_def by blast
       
  3024   show ?thesis
       
  3025   proof (cases "\<exists>C. C > S")
       
  3026     case True
       
  3027     then obtain C where C: "C > S"
       
  3028       by blast
       
  3029     have "\<forall>\<^sub>F X in finite_subsets_at_top A. sum f X < C"
       
  3030       using S C by (rule order_tendstoD(2))
       
  3031     hence "\<forall>\<^sub>F X in finite_subsets_at_top A. sum f X \<le> C"
       
  3032       by (rule eventually_mono) auto
       
  3033     thus ?thesis by blast
       
  3034   next
       
  3035     case False
       
  3036     hence "\<forall>\<^sub>F X in finite_subsets_at_top A. sum f X \<le> S"
       
  3037       by (auto simp: not_less)
       
  3038     thus ?thesis by blast
       
  3039   qed
       
  3040 qed
       
  3041 
       
  3042 lemma has_sum_mono':
       
  3043   fixes S S' :: "'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add}"
       
  3044   assumes "(f has_sum S) A" "(f has_sum S') B" "A \<subseteq> B" "\<And>x. x \<in> B - A \<Longrightarrow> f x \<ge> 0"
       
  3045   shows   "S \<le> S'"
       
  3046 proof (rule has_sum_mono)
       
  3047   show "(f has_sum S') B" by fact
       
  3048   have "(f has_sum S) A \<longleftrightarrow> ((\<lambda>x. if x \<in> A then f x else 0) has_sum S) B"
       
  3049     by (rule has_sum_cong_neutral) (use assms in auto)
       
  3050   thus "((\<lambda>x. if x \<in> A then f x else 0) has_sum S) B"
       
  3051     using assms(1) by blast
       
  3052 qed (insert assms, auto)
       
  3053 
       
  3054 
       
  3055 context
       
  3056   assumes "SORT_CONSTRAINT('a :: {topological_comm_monoid_add, order_topology,
       
  3057              ordered_comm_monoid_add, conditionally_complete_linorder})"
       
  3058 begin
       
  3059 
       
  3060 text \<open>
       
  3061   Any family of non-negative numbers with bounded partial sums is summable, and the sum
       
  3062   is simply the supremum of the partial sums.
       
  3063 \<close>
       
  3064 lemma nonneg_bounded_partial_sums_imp_has_sum_SUP:
       
  3065   assumes nonneg: "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> (0::'a)"
       
  3066       and bound:  "eventually (\<lambda>X. sum f X \<le> C) (finite_subsets_at_top A)"
       
  3067   shows   "(f has_sum (SUP X\<in>{X. X \<subseteq> A \<and> finite X}. sum f X)) A"
       
  3068 proof -
       
  3069   from bound obtain X0
       
  3070     where X0: "X0 \<subseteq> A" "finite X0" "\<And>X. X0 \<subseteq> X \<Longrightarrow> X \<subseteq> A \<Longrightarrow> finite X \<Longrightarrow> sum f X \<le> C"
       
  3071     by (force simp: eventually_finite_subsets_at_top)
       
  3072   have bound': "sum f X \<le> C" if "X \<subseteq> A" "finite X" for X
       
  3073   proof -
       
  3074     have "sum f X \<le> sum f (X \<union> X0)"
       
  3075       using that X0(1,2) assms(1) by (intro sum_mono2) auto
       
  3076     also have "\<dots> \<le> C" using X0(1,2) that by (intro X0) auto
       
  3077     finally show ?thesis .
       
  3078   qed
       
  3079   hence bdd: "bdd_above (sum f ` {X. X \<subseteq> A \<and> finite X})"
       
  3080     by (auto simp: bdd_above_def)
       
  3081 
       
  3082   show ?thesis unfolding has_sum_def
       
  3083   proof (rule increasing_tendsto)
       
  3084     show "\<forall>\<^sub>F X in finite_subsets_at_top A. sum f X \<le> Sup (sum f ` {X. X \<subseteq> A \<and> finite X})"
       
  3085       by (intro eventually_finite_subsets_at_top_weakI cSUP_upper[OF _ bdd]) auto
       
  3086   next
       
  3087     fix y assume "y < Sup (sum f ` {X. X \<subseteq> A \<and> finite X})"
       
  3088     then obtain X where X: "X \<subseteq> A" "finite X" "y < sum f X"
       
  3089       by (subst (asm) less_cSUP_iff[OF _ bdd]) auto
       
  3090     from X have "eventually (\<lambda>X'. X \<subseteq> X' \<and> X' \<subseteq> A \<and> finite X') (finite_subsets_at_top A)"
       
  3091       by (auto simp: eventually_finite_subsets_at_top)
       
  3092     thus "eventually (\<lambda>X'. y < sum f X') (finite_subsets_at_top A)"
       
  3093     proof eventually_elim
       
  3094       case (elim X')
       
  3095       note \<open>y < sum f X\<close>
       
  3096       also have "sum f X \<le> sum f X'"
       
  3097         using nonneg elim by (intro sum_mono2) auto
       
  3098       finally show ?case .
       
  3099     qed
       
  3100   qed
       
  3101 qed
       
  3102 
       
  3103 lemma nonneg_bounded_partial_sums_imp_summable_on:
       
  3104   assumes nonneg: "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> (0::'a)"
       
  3105       and bound:  "eventually (\<lambda>X. sum f X \<le> C) (finite_subsets_at_top A)"
       
  3106   shows   "f summable_on A"
       
  3107   using nonneg_bounded_partial_sums_imp_has_sum_SUP[OF assms] by (auto simp: summable_on_def)
       
  3108 
  2432 end
  3109 end
  2433 
  3110 
       
  3111 context
       
  3112   assumes "SORT_CONSTRAINT('a :: {topological_comm_monoid_add, linorder_topology,
       
  3113              ordered_comm_monoid_add, conditionally_complete_linorder})"
       
  3114 begin
       
  3115 
       
  3116 lemma summable_on_comparison_test:
       
  3117   assumes "f summable_on A" and "\<And>x. x \<in> A \<Longrightarrow> g x \<le> f x" and "\<And>x. x \<in> A \<Longrightarrow> (0::'a) \<le> g x"
       
  3118   shows   "g summable_on A"
       
  3119 proof -
       
  3120   obtain C where C: "\<forall>\<^sub>F X in finite_subsets_at_top A. sum f X \<le> C"
       
  3121     using summable_on_imp_bounded_partial_sums [of f]
       
  3122     using assms(1) by presburger
       
  3123   show ?thesis
       
  3124   proof (rule nonneg_bounded_partial_sums_imp_summable_on)
       
  3125     show "\<forall>\<^sub>F X in finite_subsets_at_top A. sum g X \<le> C"
       
  3126       using C assms 
       
  3127       unfolding eventually_finite_subsets_at_top
       
  3128       by (smt (verit, ccfv_SIG) order_trans subsetD sum_mono)
       
  3129   qed (use assms in auto)
       
  3130 qed
       
  3131 
       
  3132 end
       
  3133 
       
  3134 
       
  3135 
       
  3136 lemma summable_on_subset:
       
  3137   fixes f :: "_ \<Rightarrow> 'a :: {uniform_topological_group_add, topological_comm_monoid_add, ab_group_add, complete_uniform_space}"
       
  3138   assumes "f summable_on A" "B \<subseteq> A"
       
  3139   shows "f summable_on B"
       
  3140   by (rule summable_on_subset_aux[OF _ _ assms]) (auto simp: uniformly_continuous_add)
       
  3141 
       
  3142 lemma summable_on_union:
       
  3143   fixes f :: "_ \<Rightarrow> 'a :: {uniform_topological_group_add, topological_comm_monoid_add, ab_group_add, complete_uniform_space}"
       
  3144   assumes "f summable_on A" "f summable_on B"
       
  3145   shows "f summable_on (A \<union> B)"
       
  3146 proof -
       
  3147   have "f summable_on (A \<union> (B - A))"
       
  3148     by (intro summable_on_Un_disjoint[OF assms(1) summable_on_subset[OF assms(2)]]) auto
       
  3149   also have "A \<union> (B - A) = A \<union> B"
       
  3150     by blast
       
  3151   finally show ?thesis .
       
  3152 qed
       
  3153 
       
  3154 lemma summable_on_insert_iff:
       
  3155   fixes f :: "_ \<Rightarrow> 'a :: {uniform_topological_group_add, topological_comm_monoid_add, ab_group_add, complete_uniform_space}"
       
  3156   shows "f summable_on insert x A \<longleftrightarrow> f summable_on A"
       
  3157   using summable_on_union[of f A "{x}"] by (auto intro: summable_on_subset)
       
  3158 
       
  3159 lemma has_sum_finiteI: "finite A \<Longrightarrow> S = sum f A \<Longrightarrow> (f has_sum S) A"
       
  3160   using has_sum_finite by blast
       
  3161 
       
  3162 lemma has_sum_insert:
       
  3163   fixes f :: "'a \<Rightarrow> 'b :: topological_comm_monoid_add"
       
  3164   assumes "x \<notin> A" and "(f has_sum S) A"
       
  3165   shows   "(f has_sum (f x + S)) (insert x A)"
       
  3166 proof -
       
  3167   have "(f has_sum (f x + S)) ({x} \<union> A)"
       
  3168     using assms by (intro has_sum_Un_disjoint) (auto intro: has_sum_finiteI)
       
  3169   thus ?thesis by simp
       
  3170 qed
       
  3171 
       
  3172 lemma infsum_insert:
       
  3173   fixes f :: "_ \<Rightarrow> 'a :: {topological_comm_monoid_add, t2_space}"
       
  3174   assumes "f summable_on A" "a \<notin> A"
       
  3175   shows   "infsum f (insert a A) = f a + infsum f A"
       
  3176   by (meson assms has_sum_insert infsumI summable_iff_has_sum_infsum)
       
  3177 
       
  3178 lemma has_sum_SigmaD:
       
  3179   fixes f :: "'b \<times> 'c \<Rightarrow> 'a :: {topological_comm_monoid_add,t3_space}"
       
  3180   assumes sum1: "(f has_sum S) (Sigma A B)"
       
  3181   assumes sum2: "\<And>x. x \<in> A \<Longrightarrow> ((\<lambda>y. f (x, y)) has_sum g x) (B x)"
       
  3182   shows   "(g has_sum S) A"
       
  3183   unfolding has_sum_def tendsto_def eventually_finite_subsets_at_top
       
  3184 proof (safe, goal_cases)
       
  3185   case (1 X)
       
  3186   with nhds_closed[of S X] obtain X'
       
  3187     where X': "S \<in> X'" "closed X'" "X' \<subseteq> X" "eventually (\<lambda>y. y \<in> X') (nhds S)" by blast
       
  3188   from X'(4) obtain X'' where X'': "S \<in> X''" "open X''" "X'' \<subseteq> X'"
       
  3189     by (auto simp: eventually_nhds)
       
  3190   with sum1 obtain Y :: "('b \<times> 'c) set"
       
  3191     where Y: "Y \<subseteq> Sigma A B" "finite Y"
       
  3192              "\<And>Z. Y \<subseteq> Z \<Longrightarrow> Z \<subseteq> Sigma A B \<Longrightarrow> finite Z \<Longrightarrow> sum f Z \<in> X''"
       
  3193     unfolding has_sum_def tendsto_def eventually_finite_subsets_at_top by force
       
  3194   define Y1 :: "'b set" where "Y1 = fst ` Y"
       
  3195   from Y have Y1: "Y1 \<subseteq> A" by (auto simp: Y1_def)
       
  3196   define Y2 :: "'b \<Rightarrow> 'c set" where "Y2 = (\<lambda>x. {y. (x, y) \<in> Y})"
       
  3197   have Y2: "finite (Y2 x)" "Y2 x \<subseteq> B x" if "x \<in> A" for x
       
  3198     using that Y(1,2) unfolding Y2_def
       
  3199     by (force simp: image_iff intro: finite_subset[of _ "snd ` Y"])+
       
  3200 
       
  3201   show ?case
       
  3202   proof (rule exI[of _ Y1], safe, goal_cases)
       
  3203     case (3 Z)
       
  3204     define H where "H = (INF x\<in>Z. filtercomap (\<lambda>p. p x) (finite_subsets_at_top (B x)))"
       
  3205     
       
  3206     have "sum g Z \<in> X'"
       
  3207     proof (rule Lim_in_closed_set)
       
  3208       show "closed X'" by fact
       
  3209     next
       
  3210       show "((\<lambda>B'. sum (\<lambda>x. sum (\<lambda>y. f (x, y)) (B' x)) Z) \<longlongrightarrow> sum g Z) H"
       
  3211         unfolding H_def
       
  3212       proof (intro tendsto_sum filterlim_INF')
       
  3213         fix x assume x: "x \<in> Z"
       
  3214         with 3 have "x \<in> A" by auto
       
  3215         from sum2[OF this] have "(sum (\<lambda>y. f (x, y)) \<longlongrightarrow> g x) (finite_subsets_at_top (B x))"
       
  3216           by (simp add: has_sum_def)
       
  3217         thus "((\<lambda>B'. sum (\<lambda>y. f (x, y)) (B' x)) \<longlongrightarrow> g x)
       
  3218                  (filtercomap (\<lambda>p. p x) (finite_subsets_at_top (B x)))"
       
  3219           by (rule filterlim_compose[OF _ filterlim_filtercomap])
       
  3220       qed auto
       
  3221     next
       
  3222       show "\<forall>\<^sub>F h in H. sum (\<lambda>x. sum (\<lambda>y. f (x, y)) (h x)) Z \<in> X'"
       
  3223         unfolding H_def
       
  3224       proof (subst eventually_INF_finite[OF \<open>finite Z\<close>], rule exI, safe)
       
  3225         fix x assume x: "x \<in> Z"
       
  3226         hence x': "x \<in> A" using 3 by auto
       
  3227         show "eventually (\<lambda>h. finite (h x) \<and> Y2 x \<subseteq> h x \<and> h x \<subseteq> B x)
       
  3228                 (filtercomap (\<lambda>p. p x) (finite_subsets_at_top (B x)))" using 3 Y2[OF x']
       
  3229           by (intro eventually_filtercomapI)
       
  3230              (auto simp: eventually_finite_subsets_at_top intro: exI[of _ "Y2 x"])
       
  3231       next
       
  3232         fix h
       
  3233         assume *: "\<forall>x\<in>Z. finite (h x) \<and> Y2 x \<subseteq> h x \<and> h x \<subseteq> B x"
       
  3234         hence "sum (\<lambda>x. sum (\<lambda>y. f (x, y)) (h x)) Z = sum f (Sigma Z h)"
       
  3235           using \<open>finite Z\<close> by (subst sum.Sigma) auto
       
  3236         also have "\<dots> \<in> X''"
       
  3237           using * 3 Y(1,2) by (intro Y; force simp: Y1_def Y2_def)
       
  3238         also have "X'' \<subseteq> X'" by fact
       
  3239         finally show "sum (\<lambda>x. sum (\<lambda>y. f (x, y)) (h x)) Z \<in> X'" .
       
  3240       qed
       
  3241     next
       
  3242       have "H = (INF x\<in>SIGMA x:Z. {X. finite X \<and> X \<subseteq> B x}.
       
  3243                   principal {y. finite (y (fst x)) \<and> snd x \<subseteq> y (fst x) \<and> y (fst x) \<subseteq> B (fst x)})"
       
  3244         unfolding H_def finite_subsets_at_top_def filtercomap_INF filtercomap_principal
       
  3245         by (simp add: INF_Sigma)
       
  3246       also have "\<dots> \<noteq> bot"
       
  3247       proof (rule INF_filter_not_bot, subst INF_principal_finite, goal_cases)
       
  3248         case (2 X)
       
  3249         define H' where
       
  3250           "H' = (\<Inter>x\<in>X. {y. finite (y (fst x)) \<and> snd x \<subseteq> y (fst x) \<and> y (fst x) \<subseteq> B (fst x)})"
       
  3251         from 2 have "(\<lambda>x. \<Union>(y,Y)\<in>X. if x = y then Y else {}) \<in> H'"
       
  3252           by (force split: if_splits simp: H'_def)
       
  3253         hence "H' \<noteq> {}" by blast
       
  3254         thus "principal H' \<noteq> bot" by (simp add: principal_eq_bot_iff)
       
  3255       qed
       
  3256       finally show "H \<noteq> bot" .
       
  3257     qed
       
  3258     also have "X' \<subseteq> X" by fact
       
  3259     finally show "sum g Z \<in> X" .
       
  3260   qed (insert Y(1,2), auto simp: Y1_def)
       
  3261 qed
       
  3262 
       
  3263 lemma has_sum_unique:
       
  3264   fixes f :: "_ \<Rightarrow> 'a :: {topological_comm_monoid_add, t2_space}"
       
  3265   assumes "(f has_sum x) A" "(f has_sum y) A"
       
  3266   shows "x = y"
       
  3267   using assms unfolding has_sum_def using tendsto_unique finite_subsets_at_top_neq_bot by blast
       
  3268 
       
  3269 lemma has_sum_SigmaI:
       
  3270   fixes f :: "_ \<Rightarrow> 'a :: {topological_comm_monoid_add, t3_space}"
       
  3271   assumes f: "\<And>x. x \<in> A \<Longrightarrow> ((\<lambda>y. f (x, y)) has_sum g x) (B x)"
       
  3272   assumes g: "(g has_sum S) A"
       
  3273   assumes summable: "f summable_on Sigma A B"
       
  3274   shows   "(f has_sum S) (Sigma A B)"
       
  3275 proof -
       
  3276   from summable obtain S' where S': "(f has_sum S') (Sigma A B)"
       
  3277     using summable_on_def by blast
       
  3278   have "(g has_sum S') A"
       
  3279     by (rule has_sum_SigmaD[OF S' f])
       
  3280   with g  S' show ?thesis
       
  3281     using has_sum_unique by blast
       
  3282 qed
       
  3283 
       
  3284 lemma summable_on_SigmaD1:
       
  3285   fixes f :: "_ \<Rightarrow> _ \<Rightarrow> 'a :: {complete_uniform_space, uniform_topological_group_add, ab_group_add, topological_comm_monoid_add}"
       
  3286   assumes f: "(\<lambda>(x,y). f x y) summable_on Sigma A B"
       
  3287   assumes x: "x \<in> A"
       
  3288   shows   "f x summable_on B x"
       
  3289 proof -
       
  3290   have "(\<lambda>(x,y). f x y) summable_on Sigma {x} B"
       
  3291     using f by (rule summable_on_subset) (use x in auto)
       
  3292   also have "?this \<longleftrightarrow> ((\<lambda>y. f x y) \<circ> snd) summable_on Sigma {x} B"
       
  3293     by (intro summable_on_cong) auto
       
  3294   also have "\<dots> \<longleftrightarrow> (\<lambda>y. f x y) summable_on snd ` Sigma {x} B"
       
  3295     by (intro summable_on_reindex [symmetric] inj_onI) auto
       
  3296   also have "snd ` Sigma {x} B = B x"
       
  3297     by (force simp: Sigma_def)
       
  3298   finally show ?thesis .
       
  3299 qed
       
  3300 
       
  3301 lemma has_sum_swap:
       
  3302   "(f has_sum S) (A \<times> B) \<longleftrightarrow> ((\<lambda>(x,y). f (y,x)) has_sum S) (B \<times> A)"
       
  3303 proof -
       
  3304   have "bij_betw (\<lambda>(x,y). (y,x)) (B \<times> A) (A \<times> B)"
       
  3305     by (rule bij_betwI[of _ _ _ "\<lambda>(x,y). (y,x)"]) auto
       
  3306   from has_sum_reindex_bij_betw[OF this, where f = f] show ?thesis
       
  3307     by (simp add: case_prod_unfold)
       
  3308 qed
       
  3309 
       
  3310 
       
  3311 lemma summable_on_swap:
       
  3312   "f summable_on (A \<times> B) \<longleftrightarrow> (\<lambda>(x,y). f (y,x)) summable_on (B \<times> A)"
       
  3313 proof -
       
  3314   have "bij_betw (\<lambda>(x,y). (y,x)) (B \<times> A) (A \<times> B)"
       
  3315     by (rule bij_betwI[of _ _ _ "\<lambda>(x,y). (y,x)"]) auto
       
  3316   from summable_on_reindex_bij_betw[OF this, where f = f] show ?thesis
       
  3317     by (simp add: case_prod_unfold)
       
  3318 qed
       
  3319 
       
  3320 lemma has_sum_cmult_right_iff:
       
  3321   fixes c :: "'a :: {topological_semigroup_mult, field}"
       
  3322   assumes "c \<noteq> 0"
       
  3323   shows   "((\<lambda>x. c * f x) has_sum S) A \<longleftrightarrow> (f has_sum (S / c)) A"
       
  3324   using has_sum_cmult_right[of f A "S/c" c]
       
  3325         has_sum_cmult_right[of "\<lambda>x. c * f x" A S "inverse c"] assms
       
  3326   by (auto simp: field_simps)
       
  3327 
       
  3328 lemma has_sum_cmult_left_iff:
       
  3329   fixes c :: "'a :: {topological_semigroup_mult, field}"
       
  3330   assumes "c \<noteq> 0"
       
  3331   shows   "((\<lambda>x. f x * c) has_sum S) A \<longleftrightarrow> (f has_sum (S / c)) A"
       
  3332   by (smt (verit, best) assms has_sum_cmult_right_iff has_sum_cong mult.commute)
       
  3333 
       
  3334 lemma finite_nonzero_values_imp_summable_on:
       
  3335   assumes "finite {x\<in>X. f x \<noteq> 0}"
       
  3336   shows   "f summable_on X"
       
  3337 proof -
       
  3338   have "f summable_on {x\<in>X. f x \<noteq> 0}"
       
  3339     by (intro summable_on_finite assms)
       
  3340   also have "?this \<longleftrightarrow> f summable_on X"
       
  3341     by (intro summable_on_cong_neutral) auto
       
  3342   finally show ?thesis .
       
  3343 qed
       
  3344 
       
  3345 lemma summable_on_of_int_iff:
       
  3346   "(\<lambda>x::'a. of_int (f x) :: 'b :: real_normed_algebra_1) summable_on A \<longleftrightarrow> f summable_on A"
       
  3347 proof
       
  3348   assume "f summable_on A"
       
  3349   thus "(\<lambda>x. of_int (f x)) summable_on A"
       
  3350     by (rule summable_on_homomorphism) auto
       
  3351 next
       
  3352   assume "(\<lambda>x. of_int (f x) :: 'b) summable_on A"
       
  3353   then obtain S where "((\<lambda>x. of_int (f x) :: 'b) has_sum S) A"
       
  3354     by (auto simp: summable_on_def)
       
  3355   hence "(sum (\<lambda>x. of_int (f x) :: 'b) \<longlongrightarrow> S) (finite_subsets_at_top A)"
       
  3356     unfolding has_sum_def .
       
  3357   moreover have "1 / 2 > (0 :: real)"
       
  3358     by auto
       
  3359   ultimately have "eventually (\<lambda>X. dist (sum (\<lambda>x. of_int (f x) :: 'b) X) S < 1/2)
       
  3360                      (finite_subsets_at_top A)"
       
  3361     unfolding tendsto_iff by blast
       
  3362   then obtain X where X: "finite X" "X \<subseteq> A"
       
  3363      "\<And>Y. finite Y \<Longrightarrow> X \<subseteq> Y \<Longrightarrow> Y \<subseteq> A \<Longrightarrow> dist (sum (\<lambda>x. of_int (f x)) Y) S < 1/2"
       
  3364     unfolding eventually_finite_subsets_at_top by metis
       
  3365 
       
  3366   have X': "sum f Y = sum f X" if "finite Y" "X \<subseteq> Y" "Y \<subseteq> A" for Y
       
  3367   proof -
       
  3368     have "dist (sum (\<lambda>x. of_int (f x)) X) S < 1 / 2"
       
  3369       by (intro X) auto
       
  3370     moreover have "dist (sum (\<lambda>x. of_int (f x)) Y) S < 1 / 2"
       
  3371       by (intro X that)
       
  3372     ultimately have "dist (sum (\<lambda>x. of_int (f x)) X) (sum (\<lambda>x. of_int (f x) :: 'b) Y) <
       
  3373                        1 / 2 + 1 / 2"
       
  3374       using dist_triangle_less_add by blast
       
  3375     thus ?thesis
       
  3376       by (simp add: dist_norm flip: of_int_sum of_int_diff)
       
  3377   qed
       
  3378 
       
  3379   have "{x\<in>A. f x \<noteq> 0} \<subseteq> X"
       
  3380   proof (rule ccontr)
       
  3381     assume "\<not>{x\<in>A. f x \<noteq> 0} \<subseteq> X"
       
  3382     then obtain x where x: "x \<in> A" "f x \<noteq> 0" "x \<notin> X"
       
  3383       by blast
       
  3384     have "sum f (insert x X) = sum f X"
       
  3385       using x X by (intro X') auto
       
  3386     also have "sum f (insert x X) = f x + sum f X"
       
  3387       using x X by auto
       
  3388     finally show False
       
  3389       using x by auto
       
  3390   qed
       
  3391   with \<open>finite X\<close> have "finite {x\<in>A. f x \<noteq> 0}"
       
  3392     using finite_subset by blast
       
  3393   thus "f summable_on A"
       
  3394     by (rule finite_nonzero_values_imp_summable_on)
       
  3395 qed
       
  3396 
       
  3397 lemma summable_on_of_nat_iff:
       
  3398   "(\<lambda>x::'a. of_nat (f x) :: 'b :: real_normed_algebra_1) summable_on A \<longleftrightarrow> f summable_on A"
       
  3399 proof
       
  3400   assume "f summable_on A"
       
  3401   thus "(\<lambda>x. of_nat (f x) :: 'b) summable_on A"
       
  3402     by (rule summable_on_homomorphism) auto
       
  3403 next
       
  3404   assume "(\<lambda>x. of_nat (f x) :: 'b) summable_on A"
       
  3405   hence "(\<lambda>x. of_int (int (f x)) :: 'b) summable_on A"
       
  3406     by simp
       
  3407   also have "?this \<longleftrightarrow> (\<lambda>x. int (f x)) summable_on A"
       
  3408     by (rule summable_on_of_int_iff)
       
  3409   also have "\<dots> \<longleftrightarrow> finite {x\<in>A. f x \<noteq> 0}"
       
  3410     by (simp add: summable_on_discrete_iff)
       
  3411   also have "\<dots> \<longleftrightarrow> f summable_on A"
       
  3412     by (simp add: summable_on_discrete_iff)
       
  3413   finally show "f summable_on A" .
       
  3414 qed
       
  3415 
       
  3416 lemma infsum_of_nat:
       
  3417   "infsum (\<lambda>x::'a. of_nat (f x) :: 'b :: {real_normed_algebra_1}) A = of_nat (infsum f A)"
       
  3418   by (rule infsum_homomorphism_strong)
       
  3419      (auto simp: summable_on_of_nat has_sum_of_nat summable_on_of_nat_iff)
       
  3420 
       
  3421 lemma infsum_of_int:
       
  3422   "infsum (\<lambda>x::'a. of_int (f x) :: 'b :: {real_normed_algebra_1}) A = of_int (infsum f A)"
       
  3423   by (rule infsum_homomorphism_strong)
       
  3424      (auto simp: summable_on_of_nat has_sum_of_int summable_on_of_int_iff)
       
  3425 
       
  3426 
       
  3427 lemma summable_on_SigmaI:
       
  3428   fixes f :: "_ \<Rightarrow> 'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add,
       
  3429                           conditionally_complete_linorder}"
       
  3430   assumes f: "\<And>x. x \<in> A \<Longrightarrow> ((\<lambda>y. f (x, y)) has_sum g x) (B x)"
       
  3431   assumes g: "g summable_on A"
       
  3432   assumes f_nonneg: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> B x \<Longrightarrow> f (x, y) \<ge> (0 :: 'a)"
       
  3433   shows   "f summable_on Sigma A B"
       
  3434 proof -
       
  3435   have g_nonneg: "g x \<ge> 0" if "x \<in> A" for x
       
  3436     using f by (rule has_sum_nonneg) (use f_nonneg that in auto)
       
  3437   obtain C where C: "eventually (\<lambda>X. sum g X \<le> C) (finite_subsets_at_top A)"
       
  3438     using summable_on_imp_bounded_partial_sums[OF g] by blast
       
  3439 
       
  3440   have sum_g_le: "sum g X \<le> C" if X: "finite X" "X \<subseteq> A" for X
       
  3441   proof -
       
  3442     from C obtain X' where X':
       
  3443       "finite X'" "X' \<subseteq> A" "\<And>Y. finite Y \<Longrightarrow> X' \<subseteq> Y \<Longrightarrow> Y \<subseteq> A \<Longrightarrow> sum g Y \<le> C"
       
  3444       unfolding eventually_finite_subsets_at_top by metis
       
  3445     have "sum g X \<le> sum g (X \<union> X')"
       
  3446       using X X'(1,2) by (intro sum_mono2 g_nonneg) auto
       
  3447     also have "\<dots> \<le> C"
       
  3448       using X X'(1,2) by (intro X'(3)) auto
       
  3449     finally show ?thesis .
       
  3450   qed
       
  3451 
       
  3452   have "sum f Y \<le> C" if Y: "finite Y" "Y \<subseteq> Sigma A B" for Y
       
  3453   proof -
       
  3454     define Y1 and Y2 where "Y1 = fst ` Y" and "Y2 = (\<lambda>x. snd ` {z\<in>Y. fst z = x})"
       
  3455     have Y12: "Y = Sigma Y1 Y2"
       
  3456       unfolding Y1_def Y2_def by force
       
  3457     have [intro]: "finite Y1" "\<And>x. x \<in> Y1 \<Longrightarrow> finite (Y2 x)"
       
  3458       using Y unfolding Y1_def Y2_def by auto
       
  3459     have Y12_subset: "Y1 \<subseteq> A" "\<And>x. Y2 x \<subseteq> B x"
       
  3460       using Y by (auto simp: Y1_def Y2_def)
       
  3461 
       
  3462     have "sum f Y = sum f (Sigma Y1 Y2)"
       
  3463       by (simp add: Y12)
       
  3464     also have "\<dots> = (\<Sum>x\<in>Y1. \<Sum>y\<in>Y2 x. f (x, y))"
       
  3465       by (subst sum.Sigma) auto
       
  3466     also have "\<dots> \<le> (\<Sum>x\<in>Y1. g x)"
       
  3467     proof (rule sum_mono)
       
  3468       fix x assume x: "x \<in> Y1"
       
  3469       show "(\<Sum>y\<in>Y2 x. f (x, y)) \<le> g x"
       
  3470       proof (rule has_sum_mono')
       
  3471         show "((\<lambda>y. f (x, y)) has_sum (\<Sum>y\<in>Y2 x. f (x, y))) (Y2 x)"
       
  3472           using x by (intro has_sum_finite) auto
       
  3473         show "((\<lambda>y. f (x, y)) has_sum g x) (B x)"
       
  3474           by (rule f) (use x Y12_subset in auto)
       
  3475         show "f (x, y) \<ge> 0" if "y \<in> B x - Y2 x" for y
       
  3476           using x that Y12_subset by (intro f_nonneg) auto
       
  3477       qed (use Y12_subset in auto)
       
  3478     qed
       
  3479     also have "\<dots> \<le> C"
       
  3480       using Y12_subset by (intro sum_g_le) auto
       
  3481     finally show ?thesis .
       
  3482   qed
       
  3483 
       
  3484   hence "\<forall>\<^sub>F X in finite_subsets_at_top (Sigma A B). sum f X \<le> C"
       
  3485     unfolding eventually_finite_subsets_at_top by auto
       
  3486   thus ?thesis
       
  3487     by (intro nonneg_bounded_partial_sums_imp_summable_on[where C = C])
       
  3488        (use f_nonneg in auto)
       
  3489 qed
       
  3490 
       
  3491 lemma summable_on_UnionI:
       
  3492   fixes f :: "_ \<Rightarrow> 'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add,
       
  3493                           conditionally_complete_linorder}"
       
  3494   assumes f: "\<And>x. x \<in> A \<Longrightarrow> (f has_sum g x) (B x)"
       
  3495   assumes g: "g summable_on A"
       
  3496   assumes f_nonneg: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> B x \<Longrightarrow> f y \<ge> (0 :: 'a)"
       
  3497   assumes disj: "disjoint_family_on B A"
       
  3498   shows   "f summable_on (\<Union>x\<in>A. B x)"
       
  3499 proof -
       
  3500   have "f \<circ> snd summable_on Sigma A B"
       
  3501     using assms by (intro summable_on_SigmaI[where g = g]) auto
       
  3502   also have "?this \<longleftrightarrow> f summable_on (snd ` Sigma A B)" using assms
       
  3503     by (subst summable_on_reindex; force simp: disjoint_family_on_def inj_on_def)
       
  3504   also have "snd ` (Sigma A B) = (\<Union>x\<in>A. B x)"
       
  3505     by force
       
  3506   finally show ?thesis .
       
  3507 qed
       
  3508 
       
  3509 lemma summable_on_SigmaD:
       
  3510   fixes f :: "'a \<times> 'b \<Rightarrow> 'c :: {topological_comm_monoid_add,t3_space}"
       
  3511   assumes sum1: "f summable_on (Sigma A B)"
       
  3512   assumes sum2: "\<And>x. x \<in> A \<Longrightarrow> (\<lambda>y. f (x, y)) summable_on (B x)"
       
  3513   shows   "(\<lambda>x. infsum (\<lambda>y. f (x, y)) (B x)) summable_on A"
       
  3514 proof -
       
  3515   from sum1 have 1: "(f has_sum infsum f (Sigma A B)) (Sigma A B)"
       
  3516     using has_sum_infsum by blast
       
  3517   have 2: "((\<lambda>y. f (x, y)) has_sum infsum (\<lambda>y. f (x, y)) (B x)) (B x)"
       
  3518     if "x \<in> A" for x using sum2[OF that] by simp
       
  3519   from has_sum_SigmaD[OF 1 2] show ?thesis
       
  3520     using has_sum_imp_summable by blast
       
  3521 qed
       
  3522 
       
  3523 lemma summable_on_UnionD:
       
  3524   fixes f :: "'a \<Rightarrow> 'c :: {topological_comm_monoid_add,t3_space}"
       
  3525   assumes sum1: "f summable_on (\<Union>x\<in>A. B x)"
       
  3526   assumes sum2: "\<And>x. x \<in> A \<Longrightarrow> f summable_on (B x)"
       
  3527   assumes disj: "disjoint_family_on B A"
       
  3528   shows   "(\<lambda>x. infsum f (B x)) summable_on A"
       
  3529 proof -
       
  3530   have "(\<Union>x\<in>A. B x) = snd ` Sigma A B"
       
  3531     by (force simp: Sigma_def)
       
  3532   with sum1 have "f summable_on (snd ` Sigma A B)"
       
  3533     by simp
       
  3534   also have "?this \<longleftrightarrow> (f \<circ> snd) summable_on (Sigma A B)"
       
  3535     using disj by (intro summable_on_reindex inj_onI) (force simp: disjoint_family_on_def)
       
  3536   finally show "(\<lambda>x. infsum f (B x)) summable_on A"
       
  3537     using summable_on_SigmaD[of "f \<circ> snd" A B] sum2 by simp
       
  3538 qed
       
  3539 
       
  3540 lemma summable_on_Union_iff:
       
  3541   fixes f :: "_ \<Rightarrow> 'a :: {linorder_topology, ordered_comm_monoid_add, topological_comm_monoid_add,
       
  3542                           conditionally_complete_linorder, t3_space}"
       
  3543   assumes f: "\<And>x. x \<in> A \<Longrightarrow> (f has_sum g x) (B x)"
       
  3544   assumes f_nonneg: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> B x \<Longrightarrow> f y \<ge> 0"
       
  3545   assumes disj: "disjoint_family_on B A"
       
  3546   shows   "f summable_on (\<Union>x\<in>A. B x) \<longleftrightarrow> g summable_on A"
       
  3547 proof
       
  3548   assume "g summable_on A"
       
  3549   thus "f summable_on (\<Union>x\<in>A. B x)"
       
  3550     using summable_on_UnionI[of A f B g] assms by auto
       
  3551 next
       
  3552   assume "f summable_on (\<Union>x\<in>A. B x)"
       
  3553   hence "(\<lambda>x. infsum f (B x)) summable_on A"
       
  3554     using assms by (intro summable_on_UnionD) (auto dest: has_sum_imp_summable)
       
  3555   also have "?this \<longleftrightarrow> g summable_on A"
       
  3556     using assms by (intro summable_on_cong) (auto simp: infsumI)
       
  3557   finally show "g summable_on A" .
       
  3558 qed
       
  3559 
       
  3560 lemma has_sum_Sigma':
       
  3561   fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set"
       
  3562     and f :: \<open>'a \<times> 'b \<Rightarrow> 'c::{comm_monoid_add,uniform_space,uniform_topological_group_add}\<close>
       
  3563   assumes summableAB: "(f has_sum a) (Sigma A B)"
       
  3564   assumes summableB: \<open>\<And>x. x\<in>A \<Longrightarrow> ((\<lambda>y. f (x, y)) has_sum (b x)) (B x)\<close>
       
  3565   shows "(b has_sum a) A"
       
  3566   by (intro has_sum_Sigma[OF _ assms] uniformly_continuous_add)
       
  3567 
       
  3568 lemma abs_summable_on_comparison_test':
       
  3569   assumes "g summable_on A"
       
  3570   assumes "\<And>x. x \<in> A \<Longrightarrow> norm (f x) \<le> g x"
       
  3571   shows   "(\<lambda>x. norm (f x)) summable_on A"
       
  3572 proof (rule Infinite_Sum.abs_summable_on_comparison_test)
       
  3573   have "g summable_on A \<longleftrightarrow> (\<lambda>x. norm (g x)) summable_on A"
       
  3574   proof (rule summable_on_cong)
       
  3575     fix x assume "x \<in> A"
       
  3576     have "0 \<le> norm (f x)"
       
  3577       by simp
       
  3578     also have "\<dots> \<le> g x"
       
  3579       by (rule assms) fact
       
  3580     finally show "g x = norm (g x)"
       
  3581       by simp
       
  3582   qed
       
  3583   with assms show "(\<lambda>x. norm (g x)) summable_on A" by blast
       
  3584 next
       
  3585   fix x assume "x \<in> A"
       
  3586   have "norm (f x) \<le> g x"
       
  3587     by (intro assms) fact
       
  3588   also have "\<dots> \<le> norm (g x)"
       
  3589     by simp
       
  3590   finally show "norm (f x) \<le> norm (g x)" .
       
  3591 qed
       
  3592 
       
  3593 lemma has_sum_geometric_from_1:
       
  3594   fixes z :: "'a :: {real_normed_field, banach}"
       
  3595   assumes "norm z < 1"
       
  3596   shows   "((\<lambda>n. z ^ n) has_sum (z / (1 - z))) {1..}"
       
  3597 proof -
       
  3598   have [simp]: "z \<noteq> 1"
       
  3599     using assms by auto
       
  3600   have "(\<lambda>n. z ^ Suc n) sums (1 / (1 - z) - 1)"
       
  3601     using geometric_sums[of z] assms by (subst sums_Suc_iff) auto
       
  3602   also have "1 / (1 - z) - 1 = z / (1 - z)"
       
  3603     by (auto simp: field_simps)
       
  3604   finally have "(\<lambda>n. z ^ Suc n) sums (z / (1 - z))" .
       
  3605   moreover have "summable (\<lambda>n. norm (z ^ Suc n))"
       
  3606     using assms
       
  3607     by (subst summable_Suc_iff) (auto simp: norm_power intro!: summable_geometric)
       
  3608   ultimately have "((\<lambda>n. z ^ Suc n) has_sum (z / (1 - z))) UNIV"
       
  3609     by (intro norm_summable_imp_has_sum)
       
  3610   also have "?this \<longleftrightarrow> ?thesis"
       
  3611     by (intro has_sum_reindex_bij_witness[of _ "\<lambda>n. n-1" "\<lambda>n. n+1"]) auto
       
  3612   finally show ?thesis .
       
  3613 qed 
       
  3614 
       
  3615 lemma has_sum_divide_const:
       
  3616   fixes f :: "'a \<Rightarrow> 'b :: {topological_semigroup_mult, field, semiring_0}"
       
  3617   shows "(f has_sum S) A \<Longrightarrow> ((\<lambda>x. f x / c) has_sum (S / c)) A"
       
  3618   using has_sum_cmult_right[of f A S "inverse c"] by (simp add: field_simps)
       
  3619 
       
  3620 lemma has_sum_uminusI:
       
  3621   fixes f :: "'a \<Rightarrow> 'b :: {topological_semigroup_mult, ring_1}"
       
  3622   shows "(f has_sum S) A \<Longrightarrow> ((\<lambda>x. -f x) has_sum (-S)) A"
       
  3623   using has_sum_cmult_right[of f A S "-1"] by simp
       
  3624 
       
  3625 end
       
  3626