# HG changeset patch # User desharna # Date 1633616897 -7200 # Node ID fd5f62176987041396115c9a8554c8f5458089b2 # Parent 6424c54157d94cd157567438f1a376c23d625223# Parent 409ca22dee4c6f0f485fc30661671254f4a72360 merged diff -r 6424c54157d9 -r fd5f62176987 CONTRIBUTORS --- a/CONTRIBUTORS Thu Oct 07 10:16:52 2021 +0200 +++ b/CONTRIBUTORS Thu Oct 07 16:28:17 2021 +0200 @@ -16,6 +16,11 @@ * July .. September 2021: Jasmin Blanchette, Martin Desharnais Various improvements to Sledgehammer. +* September 2021: Dominique Unruh + New theory of infinite sums (HOL-Analysis/Infinite_Sum), + ordering of complex numbers (HOL-Library/Complex_Order), + and products of uniform spaces (in HOL-Analysis/Product_Vector). + * July 2021: Florian Haftmann Further consolidation of bit operations and word types. diff -r 6424c54157d9 -r fd5f62176987 NEWS --- a/NEWS Thu Oct 07 10:16:52 2021 +0200 +++ b/NEWS Thu Oct 07 16:28:17 2021 +0200 @@ -144,6 +144,15 @@ *** HOL *** +* Theory "HOL-Analysis.Infinite_Sum": new theory for infinite sums with +a more general definition than the existing theory Infinite_Set_Sum. +(Infinite_Set_Sum contains theorems relating the two definitions.) + +* Theory "HOL-Analysis.Product_Vector": Instantiation of the product of +uniform spaces as a uniform space. Minor INCOMPATIBILITY: the old +definition "uniformity_prod_def" is available as a derived fact +"uniformity_dist". + * Theorems "antisym" and "eq_iff" in class "order" have been renamed to "order.antisym" and "order.eq_iff", to coexist locally with "antisym" and "eq_iff" from locale "ordering". INCOMPATIBILITY: significant @@ -232,6 +241,9 @@ multiset_inter_count ~> count_inter_mset sup_subset_mset_count ~> count_union_mset +* Theory "HOL-Library.Complex_Order": Defines less, less_eq on complex +numbers. Not imported by default. + * Theory "HOL-Library.Multiset": syntax precendence for membership operations has been adjusted to match the corresponding precendences on sets. Rare INCOMPATIBILITY. diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Analysis/Analysis.thy --- a/src/HOL/Analysis/Analysis.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Analysis/Analysis.thy Thu Oct 07 16:28:17 2021 +0200 @@ -34,6 +34,7 @@ Product_Topology Lindelof_Spaces Infinite_Products + Infinite_Sum Infinite_Set_Sum Polytope Jordan_Curve diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Analysis/Infinite_Set_Sum.thy --- a/src/HOL/Analysis/Infinite_Set_Sum.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Analysis/Infinite_Set_Sum.thy Thu Oct 07 16:28:17 2021 +0200 @@ -7,9 +7,12 @@ section \Sums over Infinite Sets\ theory Infinite_Set_Sum - imports Set_Integral + imports Set_Integral Infinite_Sum begin +text \Conflicting notation from \<^theory>\HOL-Analysis.Infinite_Sum\\ +no_notation Infinite_Sum.abs_summable_on (infixr "abs'_summable'_on" 46) + (* TODO Move *) lemma sets_eq_countable: assumes "countable A" "space M = A" "\x. x \ A \ {x} \ sets M" @@ -865,4 +868,518 @@ (auto simp: infsetsum_cmult_left infsetsum_cmult_right) qed +lemma abs_summable_finite_sumsI: + assumes "\F. finite F \ F\S \ sum (\x. norm (f x)) F \ B" + shows "f abs_summable_on S" +proof - + have main: "f abs_summable_on S \ infsetsum (\x. norm (f x)) S \ B" if \B \ 0\ and \S \ {}\ + proof - + define M normf where "M = count_space S" and "normf x = ennreal (norm (f x))" for x + have "sum normf F \ ennreal B" + if "finite F" and "F \ S" and + "\F. finite F \ F \ S \ (\i\F. ennreal (norm (f i))) \ ennreal B" and + "ennreal 0 \ ennreal B" for F + using that unfolding normf_def[symmetric] by simp + hence normf_B: "finite F \ F\S \ sum normf F \ ennreal B" for F + using assms[THEN ennreal_leI] + by auto + have "integral\<^sup>S M g \ B" if "simple_function M g" and "g \ normf" for g + proof - + define gS where "gS = g ` S" + have "finite gS" + using that unfolding gS_def M_def simple_function_count_space by simp + have "gS \ {}" unfolding gS_def using \S \ {}\ by auto + define part where "part r = g -` {r} \ S" for r + have r_finite: "r < \" if "r : gS" for r + using \g \ normf\ that unfolding gS_def le_fun_def normf_def apply auto + using ennreal_less_top neq_top_trans top.not_eq_extremum by blast + define B' where "B' r = (SUP F\{F. finite F \ F\part r}. sum normf F)" for r + have B'fin: "B' r < \" for r + proof - + have "B' r \ (SUP F\{F. finite F \ F\part r}. sum normf F)" + unfolding B'_def + by (metis (mono_tags, lifting) SUP_least SUP_upper) + also have "\ \ B" + using normf_B unfolding part_def + by (metis (no_types, lifting) Int_subset_iff SUP_least mem_Collect_eq) + also have "\ < \" + by simp + finally show ?thesis by simp + qed + have sumB': "sum B' gS \ ennreal B + \" if "\>0" for \ + proof - + define N \N where "N = card gS" and "\N = \ / N" + have "N > 0" + unfolding N_def using \gS\{}\ \finite gS\ + by (simp add: card_gt_0_iff) + from \N_def that have "\N > 0" + by (simp add: ennreal_of_nat_eq_real_of_nat ennreal_zero_less_divide) + have c1: "\y. B' r \ sum normf y + \N \ finite y \ y \ part r" + if "B' r = 0" for r + using that by auto + have c2: "\y. B' r \ sum normf y + \N \ finite y \ y \ part r" if "B' r \ 0" for r + proof- + have "B' r - \N < B' r" + using B'fin \0 < \N\ ennreal_between that by fastforce + have "B' r - \N < Sup (sum normf ` {F. finite F \ F \ part r}) \ + \F. B' r - \N \ sum normf F \ finite F \ F \ part r" + by (metis (no_types, lifting) leD le_cases less_SUP_iff mem_Collect_eq) + hence "B' r - \N < B' r \ \F. B' r - \N \ sum normf F \ finite F \ F \ part r" + by (subst (asm) (2) B'_def) + then obtain F where "B' r - \N \ sum normf F" and "finite F" and "F \ part r" + using \B' r - \N < B' r\ by auto + thus "\F. B' r \ sum normf F + \N \ finite F \ F \ part r" + by (metis add.commute ennreal_minus_le_iff) + qed + have "\x. \y. B' x \ sum normf y + \N \ + finite y \ y \ part x" + using c1 c2 + by blast + hence "\F. \x. B' x \ sum normf (F x) + \N \ finite (F x) \ F x \ part x" + by metis + then obtain F where F: "sum normf (F r) + \N \ B' r" and Ffin: "finite (F r)" and Fpartr: "F r \ part r" for r + using atomize_elim by auto + have w1: "finite gS" + by (simp add: \finite gS\) + have w2: "\i\gS. finite (F i)" + by (simp add: Ffin) + have False + if "\r. F r \ g -` {r} \ F r \ S" + and "i \ gS" and "j \ gS" and "i \ j" and "x \ F i" and "x \ F j" + for i j x + by (metis subsetD that(1) that(4) that(5) that(6) vimage_singleton_eq) + hence w3: "\i\gS. \j\gS. i \ j \ F i \ F j = {}" + using Fpartr[unfolded part_def] by auto + have w4: "sum normf (\ (F ` gS)) + \ = sum normf (\ (F ` gS)) + \" + by simp + have "sum B' gS \ (\r\gS. sum normf (F r) + \N)" + using F by (simp add: sum_mono) + also have "\ = (\r\gS. sum normf (F r)) + (\r\gS. \N)" + by (simp add: sum.distrib) + also have "\ = (\r\gS. sum normf (F r)) + (card gS * \N)" + by auto + also have "\ = (\r\gS. sum normf (F r)) + \" + unfolding \N_def N_def[symmetric] using \N>0\ + by (simp add: ennreal_times_divide mult.commute mult_divide_eq_ennreal) + also have "\ = sum normf (\ (F ` gS)) + \" + using w1 w2 w3 w4 + by (subst sum.UNION_disjoint[symmetric]) + also have "\ \ B + \" + using \finite gS\ normf_B add_right_mono Ffin Fpartr unfolding part_def + by (simp add: \gS \ {}\ cSUP_least) + finally show ?thesis + by auto + qed + hence sumB': "sum B' gS \ B" + using ennreal_le_epsilon ennreal_less_zero_iff by blast + have "\r. \y. r \ gS \ B' r = ennreal y" + using B'fin less_top_ennreal by auto + hence "\B''. \r. r \ gS \ B' r = ennreal (B'' r)" + by (rule_tac choice) + then obtain B'' where B'': "B' r = ennreal (B'' r)" if "r \ gS" for r + by atomize_elim + have cases[case_names zero finite infinite]: "P" if "r=0 \ P" and "finite (part r) \ P" + and "infinite (part r) \ r\0 \ P" for P r + using that by metis + have emeasure_B': "r * emeasure M (part r) \ B' r" if "r : gS" for r + proof (cases rule:cases[of r]) + case zero + thus ?thesis by simp + next + case finite + have s1: "sum g F \ sum normf F" + if "F \ {F. finite F \ F \ part r}" + for F + using \g \ normf\ + by (simp add: le_fun_def sum_mono) + + have "r * of_nat (card (part r)) = r * (\x\part r. 1)" by simp + also have "\ = (\x\part r. r)" + using mult.commute by auto + also have "\ = (\x\part r. g x)" + unfolding part_def by auto + also have "\ \ (SUP F\{F. finite F \ F\part r}. sum g F)" + using finite + by (simp add: Sup_upper) + also have "\ \ B' r" + unfolding B'_def + using s1 SUP_subset_mono by blast + finally have "r * of_nat (card (part r)) \ B' r" by assumption + thus ?thesis + unfolding M_def + using part_def finite by auto + next + case infinite + from r_finite[OF \r : gS\] obtain r' where r': "r = ennreal r'" + using ennreal_cases by auto + with infinite have "r' > 0" + using ennreal_less_zero_iff not_gr_zero by blast + obtain N::nat where N:"N > B / r'" and "real N > 0" apply atomize_elim + using reals_Archimedean2 + by (metis less_trans linorder_neqE_linordered_idom) + obtain F where "finite F" and "card F = N" and "F \ part r" + using infinite(1) infinite_arbitrarily_large by blast + from \F \ part r\ have "F \ S" unfolding part_def by simp + have "B < r * N" + unfolding r' ennreal_of_nat_eq_real_of_nat + using N \0 < r'\ \B \ 0\ r' + by (metis enn2real_ennreal enn2real_less_iff ennreal_less_top ennreal_mult' less_le mult_less_cancel_left_pos nonzero_mult_div_cancel_left times_divide_eq_right) + also have "r * N = (\x\F. r)" + using \card F = N\ by (simp add: mult.commute) + also have "(\x\F. r) = (\x\F. g x)" + using \F \ part r\ part_def sum.cong subsetD by fastforce + also have "(\x\F. g x) \ (\x\F. ennreal (norm (f x)))" + by (metis (mono_tags, lifting) \g \ normf\ \normf \ \x. ennreal (norm (f x))\ le_fun_def + sum_mono) + also have "(\x\F. ennreal (norm (f x))) \ B" + using \F \ S\ \finite F\ \normf \ \x. ennreal (norm (f x))\ normf_B by blast + finally have "B < B" by auto + thus ?thesis by simp + qed + + have "integral\<^sup>S M g = (\r \ gS. r * emeasure M (part r))" + unfolding simple_integral_def gS_def M_def part_def by simp + also have "\ \ (\r \ gS. B' r)" + by (simp add: emeasure_B' sum_mono) + also have "\ \ B" + using sumB' by blast + finally show ?thesis by assumption + qed + hence int_leq_B: "integral\<^sup>N M normf \ B" + unfolding nn_integral_def by (metis (no_types, lifting) SUP_least mem_Collect_eq) + hence "integral\<^sup>N M normf < \" + using le_less_trans by fastforce + hence "integrable M f" + unfolding M_def normf_def by (rule integrableI_bounded[rotated], simp) + hence v1: "f abs_summable_on S" + unfolding abs_summable_on_def M_def by simp + + have "(\x. norm (f x)) abs_summable_on S" + using v1 Infinite_Set_Sum.abs_summable_on_norm_iff[where A = S and f = f] + by auto + moreover have "0 \ norm (f x)" + if "x \ S" for x + by simp + moreover have "(\\<^sup>+ x. ennreal (norm (f x)) \count_space S) \ ennreal B" + using M_def \normf \ \x. ennreal (norm (f x))\ int_leq_B by auto + ultimately have "ennreal (\\<^sub>ax\S. norm (f x)) \ ennreal B" + by (simp add: nn_integral_conv_infsetsum) + hence v2: "(\\<^sub>ax\S. norm (f x)) \ B" + by (subst ennreal_le_iff[symmetric], simp add: assms \B \ 0\) + show ?thesis + using v1 v2 by auto + qed + then show "f abs_summable_on S" + by (metis abs_summable_on_finite assms empty_subsetI finite.emptyI sum_clauses(1)) +qed + + +lemma infsetsum_nonneg_is_SUPREMUM_ennreal: + fixes f :: "'a \ real" + assumes summable: "f abs_summable_on A" + and fnn: "\x. x\A \ f x \ 0" + shows "ennreal (infsetsum f A) = (SUP F\{F. finite F \ F \ A}. (ennreal (sum f F)))" +proof - + have sum_F_A: "sum f F \ infsetsum f A" + if "F \ {F. finite F \ F \ A}" + for F + proof- + from that have "finite F" and "F \ A" by auto + from \finite F\ have "sum f F = infsetsum f F" by auto + also have "\ \ infsetsum f A" + proof (rule infsetsum_mono_neutral_left) + show "f abs_summable_on F" + by (simp add: \finite F\) + show "f abs_summable_on A" + by (simp add: local.summable) + show "f x \ f x" + if "x \ F" + for x :: 'a + by simp + show "F \ A" + by (simp add: \F \ A\) + show "0 \ f x" + if "x \ A - F" + for x :: 'a + using that fnn by auto + qed + finally show ?thesis by assumption + qed + hence geq: "ennreal (infsetsum f A) \ (SUP F\{G. finite G \ G \ A}. (ennreal (sum f F)))" + by (meson SUP_least ennreal_leI) + + define fe where "fe x = ennreal (f x)" for x + + have sum_f_int: "infsetsum f A = \\<^sup>+ x. fe x \(count_space A)" + unfolding infsetsum_def fe_def + proof (rule nn_integral_eq_integral [symmetric]) + show "integrable (count_space A) f" + using abs_summable_on_def local.summable by blast + show "AE x in count_space A. 0 \ f x" + using fnn by auto + qed + also have "\ = (SUP g \ {g. finite (g`A) \ g \ fe}. integral\<^sup>S (count_space A) g)" + unfolding nn_integral_def simple_function_count_space by simp + also have "\ \ (SUP F\{F. finite F \ F \ A}. (ennreal (sum f F)))" + proof (rule Sup_least) + fix x assume "x \ integral\<^sup>S (count_space A) ` {g. finite (g ` A) \ g \ fe}" + then obtain g where xg: "x = integral\<^sup>S (count_space A) g" and fin_gA: "finite (g`A)" + and g_fe: "g \ fe" by auto + define F where "F = {z:A. g z \ 0}" + hence "F \ A" by simp + + have fin: "finite {z:A. g z = t}" if "t \ 0" for t + proof (rule ccontr) + assume inf: "infinite {z:A. g z = t}" + hence tgA: "t \ g ` A" + by (metis (mono_tags, lifting) image_eqI not_finite_existsD) + have "x = (\x \ g ` A. x * emeasure (count_space A) (g -` {x} \ A))" + unfolding xg simple_integral_def space_count_space by simp + also have "\ \ (\x \ {t}. x * emeasure (count_space A) (g -` {x} \ A))" (is "_ \ \") + proof (rule sum_mono2) + show "finite (g ` A)" + by (simp add: fin_gA) + show "{t} \ g ` A" + by (simp add: tgA) + show "0 \ b * emeasure (count_space A) (g -` {b} \ A)" + if "b \ g ` A - {t}" + for b :: ennreal + using that + by simp + qed + also have "\ = t * emeasure (count_space A) (g -` {t} \ A)" + by auto + also have "\ = t * \" + proof (subst emeasure_count_space_infinite) + show "g -` {t} \ A \ A" + by simp + have "{a \ A. g a = t} = {a \ g -` {t}. a \ A}" + by auto + thus "infinite (g -` {t} \ A)" + by (metis (full_types) Int_def inf) + show "t * \ = t * \" + by simp + qed + also have "\ = \" using \t \ 0\ + by (simp add: ennreal_mult_eq_top_iff) + finally have x_inf: "x = \" + using neq_top_trans by auto + have "x = integral\<^sup>S (count_space A) g" by (fact xg) + also have "\ = integral\<^sup>N (count_space A) g" + by (simp add: fin_gA nn_integral_eq_simple_integral) + also have "\ \ integral\<^sup>N (count_space A) fe" + using g_fe + by (simp add: le_funD nn_integral_mono) + also have "\ < \" + by (metis sum_f_int ennreal_less_top infinity_ennreal_def) + finally have x_fin: "x < \" by simp + from x_inf x_fin show False by simp + qed + have F: "F = (\t\g`A-{0}. {z\A. g z = t})" + unfolding F_def by auto + hence "finite F" + unfolding F using fin_gA fin by auto + have "x = integral\<^sup>N (count_space A) g" + unfolding xg + by (simp add: fin_gA nn_integral_eq_simple_integral) + also have "\ = set_nn_integral (count_space UNIV) A g" + by (simp add: nn_integral_restrict_space[symmetric] restrict_count_space) + also have "\ = set_nn_integral (count_space UNIV) F g" + proof - + have "\a. g a * (if a \ {a \ A. g a \ 0} then 1 else 0) = g a * (if a \ A then 1 else 0)" + by auto + hence "(\\<^sup>+ a. g a * (if a \ A then 1 else 0) \count_space UNIV) + = (\\<^sup>+ a. g a * (if a \ {a \ A. g a \ 0} then 1 else 0) \count_space UNIV)" + by presburger + thus ?thesis unfolding F_def indicator_def + using mult.right_neutral mult_zero_right nn_integral_cong + by (simp add: of_bool_def) + qed + also have "\ = integral\<^sup>N (count_space F) g" + by (simp add: nn_integral_restrict_space[symmetric] restrict_count_space) + also have "\ = sum g F" + using \finite F\ by (rule nn_integral_count_space_finite) + also have "sum g F \ sum fe F" + using g_fe unfolding le_fun_def + by (simp add: sum_mono) + also have "\ \ (SUP F \ {G. finite G \ G \ A}. (sum fe F))" + using \finite F\ \F\A\ + by (simp add: SUP_upper) + also have "\ = (SUP F \ {F. finite F \ F \ A}. (ennreal (sum f F)))" + proof (rule SUP_cong [OF refl]) + have "finite x \ x \ A \ (\x\x. ennreal (f x)) = ennreal (sum f x)" + for x + by (metis fnn subsetCE sum_ennreal) + thus "sum fe x = ennreal (sum f x)" + if "x \ {G. finite G \ G \ A}" + for x :: "'a set" + using that unfolding fe_def by auto + qed + finally show "x \ \" by simp + qed + finally have leq: "ennreal (infsetsum f A) \ (SUP F\{F. finite F \ F \ A}. (ennreal (sum f F)))" + by assumption + from leq geq show ?thesis by simp +qed + +lemma infsetsum_nonneg_is_SUPREMUM_ereal: + fixes f :: "'a \ real" + assumes summable: "f abs_summable_on A" + and fnn: "\x. x\A \ f x \ 0" + shows "ereal (infsetsum f A) = (SUP F\{F. finite F \ F \ A}. (ereal (sum f F)))" +proof - + have "ereal (infsetsum f A) = enn2ereal (ennreal (infsetsum f A))" + by (simp add: fnn infsetsum_nonneg) + also have "\ = enn2ereal (SUP F\{F. finite F \ F \ A}. ennreal (sum f F))" + apply (subst infsetsum_nonneg_is_SUPREMUM_ennreal) + using fnn by (auto simp add: local.summable) + also have "\ = (SUP F\{F. finite F \ F \ A}. (ereal (sum f F)))" + proof (simp add: image_def Sup_ennreal.rep_eq) + have "0 \ Sup {y. \x. (\xa. finite xa \ xa \ A \ x = ennreal (sum f xa)) \ + y = enn2ereal x}" + by (metis (mono_tags, lifting) Sup_upper empty_subsetI ennreal_0 finite.emptyI + mem_Collect_eq sum.empty zero_ennreal.rep_eq) + moreover have "Sup {y. \x. (\y. finite y \ y \ A \ x = ennreal (sum f y)) \ + y = enn2ereal x} = Sup {y. \x. finite x \ x \ A \ y = ereal (sum f x)}" + using enn2ereal_ennreal fnn in_mono sum_nonneg Collect_cong + by smt + ultimately show "max 0 (Sup {y. \x. (\xa. finite xa \ xa \ A \ x + = ennreal (sum f xa)) \ y = enn2ereal x}) + = Sup {y. \x. finite x \ x \ A \ y = ereal (sum f x)}" + by linarith + qed + finally show ?thesis + by simp +qed + + +text \The following theorem relates \<^const>\Infinite_Set_Sum.abs_summable_on\ with \<^const>\Infinite_Sum.abs_summable_on\. + Note that while this theorem expresses an equivalence, the notion on the lhs is more general + nonetheless because it applies to a wider range of types. (The rhs requires second-countable + Banach spaces while the lhs is well-defined on arbitrary real vector spaces.)\ + +lemma abs_summable_equivalent: \Infinite_Sum.abs_summable_on f A \ f abs_summable_on A\ +proof (rule iffI) + define n where \n x = norm (f x)\ for x + assume \n summable_on A\ + then have \sum n F \ infsum n A\ if \finite F\ and \F\A\ for F + using that by (auto simp flip: infsum_finite simp: n_def[abs_def] intro!: infsum_mono_neutral) + + then show \f abs_summable_on A\ + by (auto intro!: abs_summable_finite_sumsI simp: n_def) +next + define n where \n x = norm (f x)\ for x + assume \f abs_summable_on A\ + then have \n abs_summable_on A\ + by (simp add: \f abs_summable_on A\ n_def) + then have \sum n F \ infsetsum n A\ if \finite F\ and \F\A\ for F + using that by (auto simp flip: infsetsum_finite simp: n_def[abs_def] intro!: infsetsum_mono_neutral) + then show \n summable_on A\ + apply (rule_tac pos_summable_on) + by (auto simp add: n_def bdd_above_def) +qed + +lemma infsetsum_infsum: + assumes "f abs_summable_on A" + shows "infsetsum f A = infsum f A" +proof - + have conv_sum_norm[simp]: "(\x. norm (f x)) summable_on A" + using abs_summable_equivalent assms by blast + have "norm (infsetsum f A - infsum f A) \ \" if "\>0" for \ + proof - + define \ where "\ = \/2" + with that have [simp]: "\ > 0" by simp + obtain F1 where F1A: "F1 \ A" and finF1: "finite F1" and leq_eps: "infsetsum (\x. norm (f x)) (A-F1) \ \" + proof - + have sum_SUP: "ereal (infsetsum (\x. norm (f x)) A) = (SUP F\{F. finite F \ F \ A}. ereal (sum (\x. norm (f x)) F))" + (is "_ = ?SUP") + apply (rule infsetsum_nonneg_is_SUPREMUM_ereal) + using assms by auto + + have "(SUP F\{F. finite F \ F \ A}. ereal (\x\F. norm (f x))) - ereal \ + < (SUP i\{F. finite F \ F \ A}. ereal (\x\i. norm (f x)))" + using \\>0\ + by (metis diff_strict_left_mono diff_zero ereal_less_eq(3) ereal_minus(1) not_le sum_SUP) + then obtain F where "F\{F. finite F \ F \ A}" and "ereal (sum (\x. norm (f x)) F) > ?SUP - ereal (\)" + by (meson less_SUP_iff) + + hence "sum (\x. norm (f x)) F > infsetsum (\x. norm (f x)) A - (\)" + unfolding sum_SUP[symmetric] by auto + hence "\ > infsetsum (\x. norm (f x)) (A-F)" + proof (subst infsetsum_Diff) + show "(\x. norm (f x)) abs_summable_on A" + if "(\\<^sub>ax\A. norm (f x)) - \ < (\x\F. norm (f x))" + using that + by (simp add: assms) + show "F \ A" + if "(\\<^sub>ax\A. norm (f x)) - \ < (\x\F. norm (f x))" + using that \F \ {F. finite F \ F \ A}\ by blast + show "(\\<^sub>ax\A. norm (f x)) - (\\<^sub>ax\F. norm (f x)) < \" + if "(\\<^sub>ax\A. norm (f x)) - \ < (\x\F. norm (f x))" + using that \F \ {F. finite F \ F \ A}\ by auto + qed + thus ?thesis using that + apply atomize_elim + using \F \ {F. finite F \ F \ A}\ less_imp_le by blast + qed + obtain F2 where F2A: "F2 \ A" and finF2: "finite F2" + and dist: "dist (sum (\x. norm (f x)) F2) (infsum (\x. norm (f x)) A) \ \" + apply atomize_elim + by (metis \0 < \\ conv_sum_norm infsum_finite_approximation) + have leq_eps': "infsum (\x. norm (f x)) (A-F2) \ \" + apply (subst infsum_Diff) + using finF2 F2A dist by (auto simp: dist_norm) + define F where "F = F1 \ F2" + have FA: "F \ A" and finF: "finite F" + unfolding F_def using F1A F2A finF1 finF2 by auto + + have "(\\<^sub>ax\A - (F1 \ F2). norm (f x)) \ (\\<^sub>ax\A - F1. norm (f x))" + apply (rule infsetsum_mono_neutral_left) + using abs_summable_on_subset assms by fastforce+ + hence leq_eps: "infsetsum (\x. norm (f x)) (A-F) \ \" + unfolding F_def + using leq_eps by linarith + have "infsum (\x. norm (f x)) (A - (F1 \ F2)) + \ infsum (\x. norm (f x)) (A - F2)" + apply (rule infsum_mono_neutral) + using finF by (auto simp add: finF2 summable_on_cofin_subset F_def) + hence leq_eps': "infsum (\x. norm (f x)) (A-F) \ \" + unfolding F_def + by (rule order.trans[OF _ leq_eps']) + have "norm (infsetsum f A - infsetsum f F) = norm (infsetsum f (A-F))" + apply (subst infsetsum_Diff [symmetric]) + by (auto simp: FA assms) + also have "\ \ infsetsum (\x. norm (f x)) (A-F)" + using norm_infsetsum_bound by blast + also have "\ \ \" + using leq_eps by simp + finally have diff1: "norm (infsetsum f A - infsetsum f F) \ \" + by assumption + have "norm (infsum f A - infsum f F) = norm (infsum f (A-F))" + apply (subst infsum_Diff [symmetric]) + by (auto simp: assms abs_summable_summable finF FA) + also have "\ \ infsum (\x. norm (f x)) (A-F)" + by (simp add: finF summable_on_cofin_subset norm_infsum_bound) + also have "\ \ \" + using leq_eps' by simp + finally have diff2: "norm (infsum f A - infsum f F) \ \" + by assumption + + have x1: "infsetsum f F = infsum f F" + using finF by simp + have "norm (infsetsum f A - infsum f A) \ norm (infsetsum f A - infsetsum f F) + norm (infsum f A - infsum f F)" + apply (rule_tac norm_diff_triangle_le) + apply auto + by (simp_all add: x1 norm_minus_commute) + also have "\ \ \" + using diff1 diff2 \_def by linarith + finally show ?thesis + by assumption + qed + hence "norm (infsetsum f A - infsum f A) = 0" + by (meson antisym_conv1 dense_ge norm_not_less_zero) + thus ?thesis + by auto +qed + end diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Analysis/Infinite_Sum.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Analysis/Infinite_Sum.thy Thu Oct 07 16:28:17 2021 +0200 @@ -0,0 +1,1977 @@ +(* + Title: HOL/Analysis/Infinite_Sum.thy + Author: Dominique Unruh, University of Tartu + + A theory of sums over possible infinite sets. +*) + +section \Infinite sums\ +\<^latex>\\label{section:Infinite_Sum}\ + +text \In this theory, we introduce the definition of infinite sums, i.e., sums ranging over an +infinite, potentially uncountable index set with no particular ordering. +(This is different from series. Those are sums indexed by natural numbers, +and the order of the index set matters.) + +Our definition is quite standard: $s:=\sum_{x\in A} f(x)$ is the limit of finite sums $s_F:=\sum_{x\in F} f(x)$ for increasing $F$. +That is, $s$ is the limit of the net $s_F$ where $F$ are finite subsets of $A$ ordered by inclusion. +We believe that this is the standard definition for such sums. +See, e.g., Definition 4.11 in \cite{conway2013course}. +This definition is quite general: it is well-defined whenever $f$ takes values in some +commutative monoid endowed with a Hausdorff topology. +(Examples are reals, complex numbers, normed vector spaces, and more.)\ + +theory Infinite_Sum + imports + "HOL-Analysis.Elementary_Topology" + "HOL-Library.Extended_Nonnegative_Real" + "HOL-Library.Complex_Order" +begin + +subsection \Definition and syntax\ + +definition has_sum :: \('a \ 'b :: {comm_monoid_add, topological_space}) \ 'a set \ 'b \ bool\ where + \has_sum f A x \ (sum f \ x) (finite_subsets_at_top A)\ + +definition summable_on :: "('a \ 'b::{comm_monoid_add, topological_space}) \ 'a set \ bool" (infixr "summable'_on" 46) where + "f summable_on A \ (\x. has_sum f A x)" + +definition infsum :: "('a \ 'b::{comm_monoid_add,t2_space}) \ 'a set \ 'b" where + "infsum f A = (if f summable_on A then Lim (finite_subsets_at_top A) (sum f) else 0)" + +abbreviation abs_summable_on :: "('a \ 'b::real_normed_vector) \ 'a set \ bool" (infixr "abs'_summable'_on" 46) where + "f abs_summable_on A \ (\x. norm (f x)) summable_on A" + +syntax (ASCII) + "_infsum" :: "pttrn \ 'a set \ 'b \ 'b::topological_comm_monoid_add" ("(3INFSUM (_/:_)./ _)" [0, 51, 10] 10) +syntax + "_infsum" :: "pttrn \ 'a set \ 'b \ 'b::topological_comm_monoid_add" ("(2\\<^sub>\(_/\_)./ _)" [0, 51, 10] 10) +translations \ \Beware of argument permutation!\ + "\\<^sub>\i\A. b" \ "CONST infsum (\i. b) A" + +syntax (ASCII) + "_univinfsum" :: "pttrn \ 'a \ 'a" ("(3INFSUM _./ _)" [0, 10] 10) +syntax + "_univinfsum" :: "pttrn \ 'a \ 'a" ("(2\\<^sub>\_./ _)" [0, 10] 10) +translations + "\\<^sub>\x. t" \ "CONST infsum (\x. t) (CONST UNIV)" + +syntax (ASCII) + "_qinfsum" :: "pttrn \ bool \ 'a \ 'a" ("(3INFSUM _ |/ _./ _)" [0, 0, 10] 10) +syntax + "_qinfsum" :: "pttrn \ bool \ 'a \ 'a" ("(2\\<^sub>\_ | (_)./ _)" [0, 0, 10] 10) +translations + "\\<^sub>\x|P. t" => "CONST infsum (\x. t) {x. P}" + +print_translation \ +let + fun sum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) $ Abs (y, Ty, P)] = + if x <> y then raise Match + else + let + val x' = Syntax_Trans.mark_bound_body (x, Tx); + val t' = subst_bound (x', t); + val P' = subst_bound (x', P); + in + Syntax.const @{syntax_const "_qinfsum"} $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t' + end + | sum_tr' _ = raise Match; +in [(@{const_syntax infsum}, K sum_tr')] end +\ + +subsection \General properties\ + +lemma infsumI: + fixes f g :: \'a \ 'b::{comm_monoid_add, t2_space}\ + assumes \has_sum f A x\ + shows \infsum f A = x\ + by (metis assms finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim) + +lemma infsum_eqI: + fixes f g :: \'a \ 'b::{comm_monoid_add, t2_space}\ + assumes \x = y\ + assumes \has_sum f A x\ + assumes \has_sum g B y\ + shows \infsum f A = infsum g B\ + by (metis assms(1) assms(2) assms(3) finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim) + +lemma infsum_eqI': + fixes f g :: \'a \ 'b::{comm_monoid_add, t2_space}\ + assumes \\x. has_sum f A x \ has_sum g B x\ + shows \infsum f A = infsum g B\ + by (metis assms infsum_def infsum_eqI summable_on_def) + +lemma infsum_not_exists: + fixes f :: \'a \ 'b::{comm_monoid_add, t2_space}\ + assumes \\ f summable_on A\ + shows \infsum f A = 0\ + by (simp add: assms infsum_def) + +lemma has_sum_cong_neutral: + fixes f g :: \'a \ 'b::{comm_monoid_add, topological_space}\ + assumes \\x. x\T-S \ g x = 0\ + assumes \\x. x\S-T \ f x = 0\ + assumes \\x. x\S\T \ f x = g x\ + shows "has_sum f S x \ has_sum g T x" +proof - + have \eventually P (filtermap (sum f) (finite_subsets_at_top S)) + = eventually P (filtermap (sum g) (finite_subsets_at_top T))\ for P + proof + assume \eventually P (filtermap (sum f) (finite_subsets_at_top S))\ + then obtain F0 where \finite F0\ and \F0 \ S\ and F0_P: \\F. finite F \ F \ S \ F \ F0 \ P (sum f F)\ + by (metis (no_types, lifting) eventually_filtermap eventually_finite_subsets_at_top) + define F0' where \F0' = F0 \ T\ + have [simp]: \finite F0'\ \F0' \ T\ + by (simp_all add: F0'_def \finite F0\) + have \P (sum g F)\ if \finite F\ \F \ T\ \F \ F0'\ for F + proof - + have \P (sum f ((F\S) \ (F0\S)))\ + apply (rule F0_P) + using \F0 \ S\ \finite F0\ that by auto + also have \sum f ((F\S) \ (F0\S)) = sum g F\ + apply (rule sum.mono_neutral_cong) + using that \finite F0\ F0'_def assms by auto + finally show ?thesis + by - + qed + with \F0' \ T\ \finite F0'\ show \eventually P (filtermap (sum g) (finite_subsets_at_top T))\ + by (metis (no_types, lifting) eventually_filtermap eventually_finite_subsets_at_top) + next + assume \eventually P (filtermap (sum g) (finite_subsets_at_top T))\ + then obtain F0 where \finite F0\ and \F0 \ T\ and F0_P: \\F. finite F \ F \ T \ F \ F0 \ P (sum g F)\ + by (metis (no_types, lifting) eventually_filtermap eventually_finite_subsets_at_top) + define F0' where \F0' = F0 \ S\ + have [simp]: \finite F0'\ \F0' \ S\ + by (simp_all add: F0'_def \finite F0\) + have \P (sum f F)\ if \finite F\ \F \ S\ \F \ F0'\ for F + proof - + have \P (sum g ((F\T) \ (F0\T)))\ + apply (rule F0_P) + using \F0 \ T\ \finite F0\ that by auto + also have \sum g ((F\T) \ (F0\T)) = sum f F\ + apply (rule sum.mono_neutral_cong) + using that \finite F0\ F0'_def assms by auto + finally show ?thesis + by - + qed + with \F0' \ S\ \finite F0'\ show \eventually P (filtermap (sum f) (finite_subsets_at_top S))\ + by (metis (no_types, lifting) eventually_filtermap eventually_finite_subsets_at_top) + qed + + then have tendsto_x: "(sum f \ x) (finite_subsets_at_top S) \ (sum g \ x) (finite_subsets_at_top T)" for x + by (simp add: le_filter_def filterlim_def) + + then show ?thesis + by (simp add: has_sum_def) +qed + +lemma summable_on_cong_neutral: + fixes f g :: \'a \ 'b::{comm_monoid_add, topological_space}\ + assumes \\x. x\T-S \ g x = 0\ + assumes \\x. x\S-T \ f x = 0\ + assumes \\x. x\S\T \ f x = g x\ + shows "f summable_on S \ g summable_on T" + using has_sum_cong_neutral[of T S g f, OF assms] + by (simp add: summable_on_def) + +lemma infsum_cong_neutral: + fixes f g :: \'a \ 'b::{comm_monoid_add, t2_space}\ + assumes \\x. x\T-S \ g x = 0\ + assumes \\x. x\S-T \ f x = 0\ + assumes \\x. x\S\T \ f x = g x\ + shows \infsum f S = infsum g T\ + apply (rule infsum_eqI') + using assms by (rule has_sum_cong_neutral) + +lemma has_sum_cong: + assumes "\x. x\A \ f x = g x" + shows "has_sum f A x \ has_sum g A x" + by (smt (verit, best) DiffE IntD2 assms has_sum_cong_neutral) + +lemma summable_on_cong: + assumes "\x. x\A \ f x = g x" + shows "f summable_on A \ g summable_on A" + by (metis assms summable_on_def has_sum_cong) + +lemma infsum_cong: + assumes "\x. x\A \ f x = g x" + shows "infsum f A = infsum g A" + using assms infsum_eqI' has_sum_cong by blast + +lemma summable_on_cofin_subset: + fixes f :: "'a \ 'b::topological_ab_group_add" + assumes "f summable_on A" and [simp]: "finite F" + shows "f summable_on (A - F)" +proof - + from assms(1) obtain x where lim_f: "(sum f \ x) (finite_subsets_at_top A)" + unfolding summable_on_def has_sum_def by auto + define F' where "F' = F\A" + with assms have "finite F'" and "A-F = A-F'" + by auto + have "filtermap ((\)F') (finite_subsets_at_top (A-F)) + \ finite_subsets_at_top A" + proof (rule filter_leI) + fix P assume "eventually P (finite_subsets_at_top A)" + then obtain X where [simp]: "finite X" and XA: "X \ A" + and P: "\Y. finite Y \ X \ Y \ Y \ A \ P Y" + unfolding eventually_finite_subsets_at_top by auto + define X' where "X' = X-F" + hence [simp]: "finite X'" and [simp]: "X' \ A-F" + using XA by auto + hence "finite Y \ X' \ Y \ Y \ A - F \ P (F' \ Y)" for Y + using P XA unfolding X'_def using F'_def \finite F'\ by blast + thus "eventually P (filtermap ((\) F') (finite_subsets_at_top (A - F)))" + unfolding eventually_filtermap eventually_finite_subsets_at_top + by (rule_tac x=X' in exI, simp) + qed + with lim_f have "(sum f \ x) (filtermap ((\)F') (finite_subsets_at_top (A-F)))" + using tendsto_mono by blast + have "((\G. sum f (F' \ G)) \ x) (finite_subsets_at_top (A - F))" + if "((sum f \ (\) F') \ x) (finite_subsets_at_top (A - F))" + using that unfolding o_def by auto + hence "((\G. sum f (F' \ G)) \ x) (finite_subsets_at_top (A-F))" + using tendsto_compose_filtermap [symmetric] + by (simp add: \(sum f \ x) (filtermap ((\) F') (finite_subsets_at_top (A - F)))\ + tendsto_compose_filtermap) + have "\Y. finite Y \ Y \ A - F \ sum f (F' \ Y) = sum f F' + sum f Y" + by (metis Diff_disjoint Int_Diff \A - F = A - F'\ \finite F'\ inf.orderE sum.union_disjoint) + hence "\\<^sub>F x in finite_subsets_at_top (A - F). sum f (F' \ x) = sum f F' + sum f x" + unfolding eventually_finite_subsets_at_top + using exI [where x = "{}"] + by (simp add: \\P. P {} \ \x. P x\) + hence "((\G. sum f F' + sum f G) \ x) (finite_subsets_at_top (A-F))" + using tendsto_cong [THEN iffD1 , rotated] + \((\G. sum f (F' \ G)) \ x) (finite_subsets_at_top (A - F))\ by fastforce + hence "((\G. sum f F' + sum f G) \ sum f F' + (x-sum f F')) (finite_subsets_at_top (A-F))" + by simp + hence "(sum f \ x - sum f F') (finite_subsets_at_top (A-F))" + using tendsto_add_const_iff by blast + thus "f summable_on (A - F)" + unfolding summable_on_def has_sum_def by auto +qed + +lemma + fixes f :: "'a \ 'b::{topological_ab_group_add}" + assumes \has_sum f B b\ and \has_sum f A a\ and AB: "A \ B" + shows has_sum_Diff: "has_sum f (B - A) (b - a)" +proof - + have finite_subsets1: + "finite_subsets_at_top (B - A) \ filtermap (\F. F - A) (finite_subsets_at_top B)" + proof (rule filter_leI) + fix P assume "eventually P (filtermap (\F. F - A) (finite_subsets_at_top B))" + then obtain X where "finite X" and "X \ B" + and P: "finite Y \ X \ Y \ Y \ B \ P (Y - A)" for Y + unfolding eventually_filtermap eventually_finite_subsets_at_top by auto + + hence "finite (X-A)" and "X-A \ B - A" + by auto + moreover have "finite Y \ X-A \ Y \ Y \ B - A \ P Y" for Y + using P[where Y="Y\X"] \finite X\ \X \ B\ + by (metis Diff_subset Int_Diff Un_Diff finite_Un inf.orderE le_sup_iff sup.orderE sup_ge2) + ultimately show "eventually P (finite_subsets_at_top (B - A))" + unfolding eventually_finite_subsets_at_top by meson + qed + have finite_subsets2: + "filtermap (\F. F \ A) (finite_subsets_at_top B) \ finite_subsets_at_top A" + apply (rule filter_leI) + using assms unfolding eventually_filtermap eventually_finite_subsets_at_top + by (metis Int_subset_iff finite_Int inf_le2 subset_trans) + + from assms(1) have limB: "(sum f \ b) (finite_subsets_at_top B)" + using has_sum_def by auto + from assms(2) have limA: "(sum f \ a) (finite_subsets_at_top A)" + using has_sum_def by blast + have "((\F. sum f (F\A)) \ a) (finite_subsets_at_top B)" + proof (subst asm_rl [of "(\F. sum f (F\A)) = sum f o (\F. F\A)"]) + show "(\F. sum f (F \ A)) = sum f \ (\F. F \ A)" + unfolding o_def by auto + show "((sum f \ (\F. F \ A)) \ a) (finite_subsets_at_top B)" + unfolding o_def + using tendsto_compose_filtermap finite_subsets2 limA tendsto_mono + \(\F. sum f (F \ A)) = sum f \ (\F. F \ A)\ by fastforce + qed + + with limB have "((\F. sum f F - sum f (F\A)) \ b - a) (finite_subsets_at_top B)" + using tendsto_diff by blast + have "sum f X - sum f (X \ A) = sum f (X - A)" if "finite X" and "X \ B" for X :: "'a set" + using that by (metis add_diff_cancel_left' sum.Int_Diff) + hence "\\<^sub>F x in finite_subsets_at_top B. sum f x - sum f (x \ A) = sum f (x - A)" + by (rule eventually_finite_subsets_at_top_weakI) + hence "((\F. sum f (F-A)) \ b - a) (finite_subsets_at_top B)" + using tendsto_cong [THEN iffD1 , rotated] + \((\F. sum f F - sum f (F \ A)) \ b - a) (finite_subsets_at_top B)\ by fastforce + hence "(sum f \ b - a) (filtermap (\F. F-A) (finite_subsets_at_top B))" + by (subst tendsto_compose_filtermap[symmetric], simp add: o_def) + hence limBA: "(sum f \ b - a) (finite_subsets_at_top (B-A))" + apply (rule tendsto_mono[rotated]) + by (rule finite_subsets1) + thus ?thesis + by (simp add: has_sum_def) +qed + + +lemma + fixes f :: "'a \ 'b::{topological_ab_group_add}" + assumes "f summable_on B" and "f summable_on A" and "A \ B" + shows summable_on_Diff: "f summable_on (B-A)" + by (meson assms summable_on_def has_sum_Diff) + +lemma + fixes f :: "'a \ 'b::{topological_ab_group_add,t2_space}" + assumes "f summable_on B" and "f summable_on A" and AB: "A \ B" + shows infsum_Diff: "infsum f (B - A) = infsum f B - infsum f A" + by (smt (z3) AB assms(1) assms(2) finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_Diff has_sum_def tendsto_Lim) + +lemma has_sum_mono_neutral: + fixes f :: "'a\'b::{ordered_comm_monoid_add,linorder_topology}" + (* Does this really require a linorder topology? (Instead of order topology.) *) + assumes \has_sum f A a\ and "has_sum g B b" + assumes \\x. x \ A\B \ f x \ g x\ + assumes \\x. x \ A-B \ f x \ 0\ + assumes \\x. x \ B-A \ g x \ 0\ + shows "a \ b" +proof - + define f' g' where \f' x = (if x \ A then f x else 0)\ and \g' x = (if x \ B then g x else 0)\ for x + have [simp]: \f summable_on A\ \g summable_on B\ + using assms(1,2) summable_on_def by auto + have \has_sum f' (A\B) a\ + apply (subst has_sum_cong_neutral[where g=f and T=A]) + by (auto simp: f'_def assms(1)) + then have f'_lim: \(sum f' \ a) (finite_subsets_at_top (A\B))\ + by (meson has_sum_def) + have \has_sum g' (A\B) b\ + apply (subst has_sum_cong_neutral[where g=g and T=B]) + by (auto simp: g'_def assms(2)) + then have g'_lim: \(sum g' \ b) (finite_subsets_at_top (A\B))\ + using has_sum_def by blast + + have *: \\\<^sub>F x in finite_subsets_at_top (A \ B). sum f' x \ sum g' x\ + apply (rule eventually_finite_subsets_at_top_weakI) + apply (rule sum_mono) + using assms by (auto simp: f'_def g'_def) + show ?thesis + apply (rule tendsto_le) + using * g'_lim f'_lim by auto +qed + +lemma infsum_mono_neutral: + fixes f :: "'a\'b::{ordered_comm_monoid_add,linorder_topology}" + assumes "f summable_on A" and "g summable_on B" + assumes \\x. x \ A\B \ f x \ g x\ + assumes \\x. x \ A-B \ f x \ 0\ + assumes \\x. x \ B-A \ g x \ 0\ + shows "infsum f A \ infsum g B" + apply (rule has_sum_mono_neutral[of f A _ g B _]) + using assms apply auto + by (metis finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim)+ + +lemma has_sum_mono: + fixes f :: "'a\'b::{ordered_comm_monoid_add,linorder_topology}" + assumes "has_sum f A x" and "has_sum g A y" + assumes \\x. x \ A \ f x \ g x\ + shows "x \ y" + apply (rule has_sum_mono_neutral) + using assms by auto + +lemma infsum_mono: + fixes f :: "'a\'b::{ordered_comm_monoid_add,linorder_topology}" + assumes "f summable_on A" and "g summable_on A" + assumes \\x. x \ A \ f x \ g x\ + shows "infsum f A \ infsum g A" + apply (rule infsum_mono_neutral) + using assms by auto + +lemma has_sum_finite[simp]: + assumes "finite F" + shows "has_sum f F (sum f F)" + using assms + by (auto intro: tendsto_Lim simp: finite_subsets_at_top_finite infsum_def has_sum_def principal_eq_bot_iff) + +lemma summable_on_finite[simp]: + fixes f :: \'a \ 'b::{comm_monoid_add,topological_space}\ + assumes "finite F" + shows "f summable_on F" + using assms summable_on_def has_sum_finite by blast + +lemma infsum_finite[simp]: + assumes "finite F" + shows "infsum f F = sum f F" + using assms by (auto intro: tendsto_Lim simp: finite_subsets_at_top_finite infsum_def principal_eq_bot_iff) + +lemma has_sum_finite_approximation: + fixes f :: "'a \ 'b::{comm_monoid_add,metric_space}" + assumes "has_sum f A x" and "\ > 0" + shows "\F. finite F \ F \ A \ dist (sum f F) x \ \" +proof - + have "(sum f \ x) (finite_subsets_at_top A)" + by (meson assms(1) has_sum_def) + hence *: "\\<^sub>F F in (finite_subsets_at_top A). dist (sum f F) x < \" + using assms(2) by (rule tendstoD) + show ?thesis + by (smt (verit) * eventually_finite_subsets_at_top order_refl) +qed + +lemma infsum_finite_approximation: + fixes f :: "'a \ 'b::{comm_monoid_add,metric_space}" + assumes "f summable_on A" and "\ > 0" + shows "\F. finite F \ F \ A \ dist (sum f F) (infsum f A) \ \" + by (metis assms(1) assms(2) finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_finite_approximation has_sum_def tendsto_Lim) + +lemma abs_summable_summable: + fixes f :: \'a \ 'b :: banach\ + assumes \f abs_summable_on A\ + shows \f summable_on A\ +proof - + from assms obtain L where lim: \(sum (\x. norm (f x)) \ L) (finite_subsets_at_top A)\ + unfolding has_sum_def summable_on_def by blast + then have *: \cauchy_filter (filtermap (sum (\x. norm (f x))) (finite_subsets_at_top A))\ + by (auto intro!: nhds_imp_cauchy_filter simp: filterlim_def) + have \\P. eventually P (finite_subsets_at_top A) \ + (\F F'. P F \ P F' \ dist (sum f F) (sum f F') < e)\ if \e>0\ for e + proof - + define d P where \d = e/4\ and \P F \ finite F \ F \ A \ dist (sum (\x. norm (f x)) F) L < d\ for F + then have \d > 0\ + by (simp add: d_def that) + have ev_P: \eventually P (finite_subsets_at_top A)\ + using lim + by (auto simp add: P_def[abs_def] \0 < d\ eventually_conj_iff eventually_finite_subsets_at_top_weakI tendsto_iff) + + moreover have \dist (sum f F1) (sum f F2) < e\ if \P F1\ and \P F2\ for F1 F2 + proof - + from ev_P + obtain F' where \finite F'\ and \F' \ A\ and P_sup_F': \finite F \ F \ F' \ F \ A \ P F\ for F + apply atomize_elim by (simp add: eventually_finite_subsets_at_top) + define F where \F = F' \ F1 \ F2\ + have \finite F\ and \F \ A\ + using F_def P_def[abs_def] that \finite F'\ \F' \ A\ by auto + have dist_F: \dist (sum (\x. norm (f x)) F) L < d\ + by (metis F_def \F \ A\ P_def P_sup_F' \finite F\ le_supE order_refl) + + from dist_F have \dist (sum (\x. norm (f x)) F) (sum (\x. norm (f x)) F2) < 2*d\ + by (smt (z3) P_def dist_norm real_norm_def that(2)) + then have \norm (sum (\x. norm (f x)) (F-F2)) < 2*d\ + unfolding dist_norm + by (metis F_def \finite F\ sum_diff sup_commute sup_ge1) + then have \norm (sum f (F-F2)) < 2*d\ + by (smt (verit, ccfv_threshold) real_norm_def sum_norm_le) + then have dist_F_F2: \dist (sum f F) (sum f F2) < 2*d\ + by (metis F_def \finite F\ dist_norm sum_diff sup_commute sup_ge1) + + from dist_F have \dist (sum (\x. norm (f x)) F) (sum (\x. norm (f x)) F1) < 2*d\ + by (smt (z3) P_def dist_norm real_norm_def that(1)) + then have \norm (sum (\x. norm (f x)) (F-F1)) < 2*d\ + unfolding dist_norm + by (metis F_def \finite F\ inf_sup_ord(3) order_trans sum_diff sup_ge2) + then have \norm (sum f (F-F1)) < 2*d\ + by (smt (verit, ccfv_threshold) real_norm_def sum_norm_le) + then have dist_F_F1: \dist (sum f F) (sum f F1) < 2*d\ + by (metis F_def \finite F\ dist_norm inf_sup_ord(3) le_supE sum_diff) + + from dist_F_F2 dist_F_F1 show \dist (sum f F1) (sum f F2) < e\ + unfolding d_def apply auto + by (meson dist_triangle_half_r less_divide_eq_numeral1(1)) + qed + then show ?thesis + using ev_P by blast + qed + then have \cauchy_filter (filtermap (sum f) (finite_subsets_at_top A))\ + by (simp add: cauchy_filter_metric_filtermap) + then obtain L' where \(sum f \ L') (finite_subsets_at_top A)\ + apply atomize_elim unfolding filterlim_def + apply (rule complete_uniform[where S=UNIV, simplified, THEN iffD1, rule_format]) + apply (auto simp add: filtermap_bot_iff) + by (meson Cauchy_convergent UNIV_I complete_def convergent_def) + then show ?thesis + using summable_on_def has_sum_def by blast +qed + +text \The converse of @{thm [source] abs_summable_summable} does not hold: + Consider the Hilbert space of square-summable sequences. + Let $e_i$ denote the sequence with 1 in the $i$th position and 0 elsewhere. + Let $f(i) := e_i/i$ for $i\geq1$. We have \<^term>\\ f abs_summable_on UNIV\ because $\lVert f(i)\rVert=1/i$ + and thus the sum over $\lVert f(i)\rVert$ diverges. On the other hand, we have \<^term>\f summable_on UNIV\; + the limit is the sequence with $1/i$ in the $i$th position. + + (We have not formalized this separating example here because to the best of our knowledge, + this Hilbert space has not been formalized in Isabelle/HOL yet.)\ + +lemma norm_has_sum_bound: + fixes f :: "'b \ 'a::real_normed_vector" + and A :: "'b set" + assumes "has_sum (\x. norm (f x)) A n" + assumes "has_sum f A a" + shows "norm a \ n" +proof - + have "norm a \ n + \" if "\>0" for \ + proof- + have "\F. norm (a - sum f F) \ \ \ finite F \ F \ A" + using has_sum_finite_approximation[where A=A and f=f and \="\"] assms \0 < \\ + by (metis dist_commute dist_norm) + then obtain F where "norm (a - sum f F) \ \" + and "finite F" and "F \ A" + by (simp add: atomize_elim) + hence "norm a \ norm (sum f F) + \" + by (smt norm_triangle_sub) + also have "\ \ sum (\x. norm (f x)) F + \" + using norm_sum by auto + also have "\ \ n + \" + apply (rule add_right_mono) + apply (rule has_sum_mono_neutral[where A=F and B=A and f=\\x. norm (f x)\ and g=\\x. norm (f x)\]) + using \finite F\ \F \ A\ assms by auto + finally show ?thesis + by assumption + qed + thus ?thesis + using linordered_field_class.field_le_epsilon by blast +qed + +lemma norm_infsum_bound: + fixes f :: "'b \ 'a::real_normed_vector" + and A :: "'b set" + assumes "f abs_summable_on A" + shows "norm (infsum f A) \ infsum (\x. norm (f x)) A" +proof (cases "f summable_on A") + case True + show ?thesis + apply (rule norm_has_sum_bound[where A=A and f=f and a=\infsum f A\ and n=\infsum (\x. norm (f x)) A\]) + using assms True + by (metis finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim)+ +next + case False + obtain t where t_def: "(sum (\x. norm (f x)) \ t) (finite_subsets_at_top A)" + using assms unfolding summable_on_def has_sum_def by blast + have sumpos: "sum (\x. norm (f x)) X \ 0" + for X + by (simp add: sum_nonneg) + have tgeq0:"t \ 0" + proof(rule ccontr) + define S::"real set" where "S = {s. s < 0}" + assume "\ 0 \ t" + hence "t < 0" by simp + hence "t \ S" + unfolding S_def by blast + moreover have "open S" + proof- + have "closed {s::real. s \ 0}" + using Elementary_Topology.closed_sequential_limits[where S = "{s::real. s \ 0}"] + by (metis Lim_bounded2 mem_Collect_eq) + moreover have "{s::real. s \ 0} = UNIV - S" + unfolding S_def by auto + ultimately have "closed (UNIV - S)" + by simp + thus ?thesis + by (simp add: Compl_eq_Diff_UNIV open_closed) + qed + ultimately have "\\<^sub>F X in finite_subsets_at_top A. (\x\X. norm (f x)) \ S" + using t_def unfolding tendsto_def by blast + hence "\X. (\x\X. norm (f x)) \ S" + by (metis (no_types, lifting) eventually_mono filterlim_iff finite_subsets_at_top_neq_bot tendsto_Lim) + then obtain X where "(\x\X. norm (f x)) \ S" + by blast + hence "(\x\X. norm (f x)) < 0" + unfolding S_def by auto + thus False using sumpos by smt + qed + have "\!h. (sum (\x. norm (f x)) \ h) (finite_subsets_at_top A)" + using t_def finite_subsets_at_top_neq_bot tendsto_unique by blast + hence "t = (Topological_Spaces.Lim (finite_subsets_at_top A) (sum (\x. norm (f x))))" + using t_def unfolding Topological_Spaces.Lim_def + by (metis the_equality) + hence "Lim (finite_subsets_at_top A) (sum (\x. norm (f x))) \ 0" + using tgeq0 by blast + thus ?thesis unfolding infsum_def + using False by auto +qed + +lemma has_sum_infsum[simp]: + assumes \f summable_on S\ + shows \has_sum f S (infsum f S)\ + using assms by (auto simp: summable_on_def infsum_def has_sum_def tendsto_Lim) + +lemma infsum_tendsto: + assumes \f summable_on S\ + shows \((\F. sum f F) \ infsum f S) (finite_subsets_at_top S)\ + using assms by (simp flip: has_sum_def) + + +lemma has_sum_0: + assumes \\x. x\M \ f x = 0\ + shows \has_sum f M 0\ + unfolding has_sum_def + apply (subst tendsto_cong[where g=\\_. 0\]) + apply (rule eventually_finite_subsets_at_top_weakI) + using assms by (auto simp add: subset_iff) + +lemma summable_on_0: + assumes \\x. x\M \ f x = 0\ + shows \f summable_on M\ + using assms summable_on_def has_sum_0 by blast + +lemma infsum_0: + assumes \\x. x\M \ f x = 0\ + shows \infsum f M = 0\ + by (metis assms finite_subsets_at_top_neq_bot infsum_def has_sum_0 has_sum_def tendsto_Lim) + +text \Variants of @{thm [source] infsum_0} etc. suitable as simp-rules\ +lemma infsum_0_simp[simp]: \infsum (\_. 0) M = 0\ + by (simp_all add: infsum_0) +lemma summable_on_0_simp[simp]: \(\_. 0) summable_on M\ + by (simp_all add: summable_on_0) +lemma has_sum_0_simp[simp]: \has_sum (\_. 0) M 0\ + by (simp_all add: has_sum_0) + + +lemma has_sum_add: + fixes f g :: "'a \ 'b::{topological_comm_monoid_add}" + assumes \has_sum f A a\ + assumes \has_sum g A b\ + shows \has_sum (\x. f x + g x) A (a + b)\ +proof - + from assms have lim_f: \(sum f \ a) (finite_subsets_at_top A)\ + and lim_g: \(sum g \ b) (finite_subsets_at_top A)\ + by (simp_all add: has_sum_def) + then have lim: \(sum (\x. f x + g x) \ a + b) (finite_subsets_at_top A)\ + unfolding sum.distrib by (rule tendsto_add) + then show ?thesis + by (simp_all add: has_sum_def) +qed + +lemma summable_on_add: + fixes f g :: "'a \ 'b::{topological_comm_monoid_add}" + assumes \f summable_on A\ + assumes \g summable_on A\ + shows \(\x. f x + g x) summable_on A\ + by (metis (full_types) assms(1) assms(2) summable_on_def has_sum_add) + +lemma infsum_add: + fixes f g :: "'a \ 'b::{topological_comm_monoid_add, t2_space}" + assumes \f summable_on A\ + assumes \g summable_on A\ + shows \infsum (\x. f x + g x) A = infsum f A + infsum g A\ +proof - + have \has_sum (\x. f x + g x) A (infsum f A + infsum g A)\ + by (simp add: assms(1) assms(2) has_sum_add) + then show ?thesis + by (smt (z3) finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim) +qed + + +lemma has_sum_Un_disjoint: + fixes f :: "'a \ 'b::topological_comm_monoid_add" + assumes "has_sum f A a" + assumes "has_sum f B b" + assumes disj: "A \ B = {}" + shows \has_sum f (A \ B) (a + b)\ +proof - + define fA fB where \fA x = (if x \ A then f x else 0)\ + and \fB x = (if x \ A then f x else 0)\ for x + have fA: \has_sum fA (A \ B) a\ + apply (subst has_sum_cong_neutral[where T=A and g=f]) + using assms by (auto simp: fA_def) + have fB: \has_sum fB (A \ B) b\ + apply (subst has_sum_cong_neutral[where T=B and g=f]) + using assms by (auto simp: fB_def) + have fAB: \f x = fA x + fB x\ for x + unfolding fA_def fB_def by simp + show ?thesis + unfolding fAB + using fA fB by (rule has_sum_add) +qed + +lemma summable_on_Un_disjoint: + fixes f :: "'a \ 'b::topological_comm_monoid_add" + assumes "f summable_on A" + assumes "f summable_on B" + assumes disj: "A \ B = {}" + shows \f summable_on (A \ B)\ + by (meson assms(1) assms(2) disj summable_on_def has_sum_Un_disjoint) + +lemma infsum_Un_disjoint: + fixes f :: "'a \ 'b::{topological_comm_monoid_add, t2_space}" + assumes "f summable_on A" + assumes "f summable_on B" + assumes disj: "A \ B = {}" + shows \infsum f (A \ B) = infsum f A + infsum f B\ + by (smt (verit, ccfv_threshold) assms(1) assms(2) disj finite_subsets_at_top_neq_bot summable_on_def has_sum_Un_disjoint has_sum_def has_sum_infsum tendsto_Lim) + + +text \The following lemma indeed needs a complete space (as formalized by the premise \<^term>\complete UNIV\). + The following two counterexamples show this: + \begin{itemize} + \item Consider the real vector space $V$ of sequences with finite support, and with the $\ell_2$-norm (sum of squares). + Let $e_i$ denote the sequence with a $1$ at position $i$. + Let $f : \mathbb Z \to V$ be defined as $f(n) := e_{\lvert n\rvert} / n$ (with $f(0) := 0$). + We have that $\sum_{n\in\mathbb Z} f(n) = 0$ (it even converges absolutely). + But $\sum_{n\in\mathbb N} f(n)$ does not exist (it would converge against a sequence with infinite support). + + \item Let $f$ be a positive rational valued function such that $\sum_{x\in B} f(x)$ is $\sqrt 2$ and $\sum_{x\in A} f(x)$ is 1 (over the reals, with $A\subseteq B$). + Then $\sum_{x\in B} f(x)$ does not exist over the rationals. But $\sum_{x\in A} f(x)$ exists. + \end{itemize} + + The lemma also requires uniform continuity of the addition. And example of a topological group with continuous + but not uniformly continuous addition would be the positive reals with the usual multiplication as the addition. + We do not know whether the lemma would also hold for such topological groups.\ + +lemma summable_on_subset: + fixes A B and f :: \'a \ 'b::{ab_group_add, uniform_space}\ + assumes \complete (UNIV :: 'b set)\ + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'b,y). x+y)\ + assumes \f summable_on A\ + assumes \B \ A\ + shows \f summable_on B\ +proof - + from \f summable_on A\ + obtain S where \(sum f \ S) (finite_subsets_at_top A)\ (is \(sum f \ S) ?filter_A\) + using summable_on_def has_sum_def by blast + then have cauchy_fA: \cauchy_filter (filtermap (sum f) (finite_subsets_at_top A))\ (is \cauchy_filter ?filter_fA\) + by (auto intro!: nhds_imp_cauchy_filter simp: filterlim_def) + + let ?filter_fB = \filtermap (sum f) (finite_subsets_at_top B)\ + + have \cauchy_filter (filtermap (sum f) (finite_subsets_at_top B))\ + proof (unfold cauchy_filter_def, rule filter_leI) + fix E :: \('b\'b) \ bool\ assume \eventually E uniformity\ + then obtain E' where \eventually E' uniformity\ and E'E'E: \E' (x, y) \ E' (y, z) \ E (x, z)\ for x y z + using uniformity_trans by blast + from plus_cont[simplified uniformly_continuous_on_uniformity filterlim_def le_filter_def, rule_format, + OF \eventually E' uniformity\] + obtain D where \eventually D uniformity\ and DE: \D (x, y) \ E' (x+c, y+c)\ for x y c + apply atomize_elim + by (auto simp: case_prod_beta eventually_filtermap uniformity_prod_def + eventually_prod_same uniformity_refl) + with cauchy_fA have \eventually D (?filter_fA \\<^sub>F ?filter_fA)\ + unfolding cauchy_filter_def le_filter_def by simp + then obtain P1 P2 where ev_P1: \eventually (\F. P1 (sum f F)) ?filter_A\ and ev_P2: \eventually (\F. P2 (sum f F)) ?filter_A\ + and P1P2E: \P1 x \ P2 y \ D (x, y)\ for x y + unfolding eventually_prod_filter eventually_filtermap + by auto + from ev_P1 obtain F1 where \finite F1\ and \F1 \ A\ and \\F. F\F1 \ finite F \ F\A \ P1 (sum f F)\ + by (metis eventually_finite_subsets_at_top) + from ev_P2 obtain F2 where \finite F2\ and \F2 \ A\ and \\F. F\F2 \ finite F \ F\A \ P2 (sum f F)\ + by (metis eventually_finite_subsets_at_top) + define F0 F0A F0B where \F0 \ F1 \ F2\ and \F0A \ F0 - B\ and \F0B \ F0 \ B\ + have [simp]: \finite F0\ \F0 \ A\ + apply (simp add: F0_def \finite F1\ \finite F2\) + by (simp add: F0_def \F1 \ A\ \F2 \ A\) + have [simp]: \finite F0A\ + by (simp add: F0A_def) + have \\F1 F2. F1\F0 \ F2\F0 \ finite F1 \ finite F2 \ F1\A \ F2\A \ D (sum f F1, sum f F2)\ + by (simp add: F0_def P1P2E \\F. F1 \ F \ finite F \ F \ A \ P1 (sum f F)\ \\F. F2 \ F \ finite F \ F \ A \ P2 (sum f F)\) + then have \\F1 F2. F1\F0B \ F2\F0B \ finite F1 \ finite F2 \ F1\B \ F2\B \ + D (sum f (F1 \ F0A), sum f (F2 \ F0A))\ + by (smt (verit) Diff_Diff_Int Diff_subset_conv F0A_def F0B_def \F0 \ A\ \finite F0A\ assms(4) finite_UnI sup.absorb_iff1 sup.mono sup_commute) + then have \\F1 F2. F1\F0B \ F2\F0B \ finite F1 \ finite F2 \ F1\B \ F2\B \ + D (sum f F1 + sum f F0A, sum f F2 + sum f F0A)\ + by (metis Diff_disjoint F0A_def \finite F0A\ inf.absorb_iff1 inf_assoc inf_bot_right sum.union_disjoint) + then have *: \\F1 F2. F1\F0B \ F2\F0B \ finite F1 \ finite F2 \ F1\B \ F2\B \ + E' (sum f F1, sum f F2)\ + using DE[where c=\- sum f F0A\] + apply auto by (metis add.commute add_diff_cancel_left') + show \eventually E (?filter_fB \\<^sub>F ?filter_fB)\ + apply (subst eventually_prod_filter) + apply (rule exI[of _ \\x. E' (x, sum f F0B)\]) + apply (rule exI[of _ \\x. E' (sum f F0B, x)\]) + apply (auto simp: eventually_filtermap) + using * apply (metis (no_types, lifting) F0B_def Int_lower2 \finite F0\ eventually_finite_subsets_at_top finite_Int order_refl) + using * apply (metis (no_types, lifting) F0B_def Int_lower2 \finite F0\ eventually_finite_subsets_at_top finite_Int order_refl) + using E'E'E by auto + qed + + then obtain x where \filtermap (sum f) (finite_subsets_at_top B) \ nhds x\ + apply atomize_elim + apply (rule complete_uniform[where S=UNIV, THEN iffD1, rule_format, simplified]) + using assms by (auto simp add: filtermap_bot_iff) + + then have \(sum f \ x) (finite_subsets_at_top B)\ + by (auto simp: filterlim_def) + then show ?thesis + by (auto simp: summable_on_def has_sum_def) +qed + +text \A special case of @{thm [source] summable_on_subset} for Banach spaces with less premises.\ + +lemma summable_on_subset_banach: + fixes A B and f :: \'a \ 'b::banach\ + assumes \f summable_on A\ + assumes \B \ A\ + shows \f summable_on B\ + apply (rule summable_on_subset) + using assms apply auto + by (metis Cauchy_convergent UNIV_I complete_def convergent_def) + +lemma has_sum_empty[simp]: \has_sum f {} 0\ + by (meson ex_in_conv has_sum_0) + +lemma summable_on_empty[simp]: \f summable_on {}\ + by auto + +lemma infsum_empty[simp]: \infsum f {} = 0\ + by simp + +lemma sum_has_sum: + fixes f :: "'a \ 'b::topological_comm_monoid_add" + assumes finite: \finite A\ + assumes conv: \\a. a \ A \ has_sum f (B a) (s a)\ + assumes disj: \\a a'. a\A \ a'\A \ a\a' \ B a \ B a' = {}\ + shows \has_sum f (\a\A. B a) (sum s A)\ + using assms +proof (insert finite conv disj, induction) + case empty + then show ?case + by simp +next + case (insert x A) + have \has_sum f (B x) (s x)\ + by (simp add: insert.prems) + moreover have IH: \has_sum f (\a\A. B a) (sum s A)\ + using insert by simp + ultimately have \has_sum f (B x \ (\a\A. B a)) (s x + sum s A)\ + apply (rule has_sum_Un_disjoint) + using insert by auto + then show ?case + using insert.hyps by auto +qed + + +lemma summable_on_finite_union_disjoint: + fixes f :: "'a \ 'b::topological_comm_monoid_add" + assumes finite: \finite A\ + assumes conv: \\a. a \ A \ f summable_on (B a)\ + assumes disj: \\a a'. a\A \ a'\A \ a\a' \ B a \ B a' = {}\ + shows \f summable_on (\a\A. B a)\ + using finite conv disj apply induction by (auto intro!: summable_on_Un_disjoint) + +lemma sum_infsum: + fixes f :: "'a \ 'b::{topological_comm_monoid_add, t2_space}" + assumes finite: \finite A\ + assumes conv: \\a. a \ A \ f summable_on (B a)\ + assumes disj: \\a a'. a\A \ a'\A \ a\a' \ B a \ B a' = {}\ + shows \sum (\a. infsum f (B a)) A = infsum f (\a\A. B a)\ + using sum_has_sum[of A f B \\a. infsum f (B a)\] + using assms apply auto + by (metis finite_subsets_at_top_neq_bot infsum_def summable_on_def has_sum_def tendsto_Lim) + +text \The lemmas \infsum_comm_additive_general\ and \infsum_comm_additive\ (and variants) below both state that the infinite sum commutes with + a continuous additive function. \infsum_comm_additive_general\ is stated more for more general type classes + at the expense of a somewhat less compact formulation of the premises. + E.g., by avoiding the constant \<^const>\additive\ which introduces an additional sort constraint + (group instead of monoid). For example, extended reals (\<^typ>\ereal\, \<^typ>\ennreal\) are not covered + by \infsum_comm_additive\.\ + + +lemma has_sum_comm_additive_general: + fixes f :: \'b :: {comm_monoid_add,topological_space} \ 'c :: {comm_monoid_add,topological_space}\ + assumes f_sum: \\F. finite F \ F \ S \ sum (f o g) F = f (sum g F)\ + \ \Not using \<^const>\additive\ because it would add sort constraint \<^class>\ab_group_add\\ + assumes cont: \f \x\ f x\ + \ \For \<^class>\t2_space\, this is equivalent to \isCont f x\ by @{thm [source] isCont_def}.\ + assumes infsum: \has_sum g S x\ + shows \has_sum (f o g) S (f x)\ +proof - + have \(sum g \ x) (finite_subsets_at_top S)\ + using infsum has_sum_def by blast + then have \((f o sum g) \ f x) (finite_subsets_at_top S)\ + apply (rule tendsto_compose_at) + using assms by auto + then have \(sum (f o g) \ f x) (finite_subsets_at_top S)\ + apply (rule tendsto_cong[THEN iffD1, rotated]) + using f_sum by fastforce + then show \has_sum (f o g) S (f x)\ + using has_sum_def by blast +qed + +lemma summable_on_comm_additive_general: + fixes f :: \'b :: {comm_monoid_add,topological_space} \ 'c :: {comm_monoid_add,topological_space}\ + assumes \\F. finite F \ F \ S \ sum (f o g) F = f (sum g F)\ + \ \Not using \<^const>\additive\ because it would add sort constraint \<^class>\ab_group_add\\ + assumes \\x. has_sum g S x \ f \x\ f x\ + \ \For \<^class>\t2_space\, this is equivalent to \isCont f x\ by @{thm [source] isCont_def}.\ + assumes \g summable_on S\ + shows \(f o g) summable_on S\ + by (meson assms summable_on_def has_sum_comm_additive_general has_sum_def infsum_tendsto) + +lemma infsum_comm_additive_general: + fixes f :: \'b :: {comm_monoid_add,t2_space} \ 'c :: {comm_monoid_add,t2_space}\ + assumes f_sum: \\F. finite F \ F \ S \ sum (f o g) F = f (sum g F)\ + \ \Not using \<^const>\additive\ because it would add sort constraint \<^class>\ab_group_add\\ + assumes \isCont f (infsum g S)\ + assumes \g summable_on S\ + shows \infsum (f o g) S = f (infsum g S)\ + by (smt (verit) assms(2) assms(3) continuous_within f_sum finite_subsets_at_top_neq_bot summable_on_comm_additive_general has_sum_comm_additive_general has_sum_def has_sum_infsum tendsto_Lim) + +lemma has_sum_comm_additive: + fixes f :: \'b :: {ab_group_add,topological_space} \ 'c :: {ab_group_add,topological_space}\ + assumes \additive f\ + assumes \f \x\ f x\ + \ \For \<^class>\t2_space\, this is equivalent to \isCont f x\ by @{thm [source] isCont_def}.\ + assumes infsum: \has_sum g S x\ + shows \has_sum (f o g) S (f x)\ + by (smt (verit, best) additive.sum assms(1) assms(2) comp_eq_dest_lhs continuous_within finite_subsets_at_top_neq_bot infsum summable_on_def has_sum_comm_additive_general has_sum_def has_sum_infsum sum.cong tendsto_Lim) + +lemma summable_on_comm_additive: + fixes f :: \'b :: {ab_group_add,t2_space} \ 'c :: {ab_group_add,topological_space}\ + assumes \additive f\ + assumes \isCont f (infsum g S)\ + assumes \g summable_on S\ + shows \(f o g) summable_on S\ + by (meson assms(1) assms(2) assms(3) summable_on_def has_sum_comm_additive has_sum_infsum isContD) + +lemma infsum_comm_additive: + fixes f :: \'b :: {ab_group_add,t2_space} \ 'c :: {ab_group_add,t2_space}\ + assumes \additive f\ + assumes \isCont f (infsum g S)\ + assumes \g summable_on S\ + shows \infsum (f o g) S = f (infsum g S)\ + by (rule infsum_comm_additive_general; auto simp: assms additive.sum) + + +lemma pos_has_sum: + fixes f :: \'a \ 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\ + assumes \\x. x\A \ f x \ 0\ + assumes \bdd_above (sum f ` {F. F\A \ finite F})\ + shows \has_sum f A (SUP F\{F. finite F \ F\A}. sum f F)\ +proof - + have \(sum f \ (SUP F\{F. finite F \ F\A}. sum f F)) (finite_subsets_at_top A)\ + proof (rule order_tendstoI) + fix a assume \a < (SUP F\{F. finite F \ F\A}. sum f F)\ + then obtain F where \a < sum f F\ and \finite F\ and \F \ A\ + by (metis (mono_tags, lifting) Collect_cong Collect_empty_eq assms(2) empty_subsetI finite.emptyI less_cSUP_iff mem_Collect_eq) + show \\\<^sub>F x in finite_subsets_at_top A. a < sum f x\ + unfolding eventually_finite_subsets_at_top + apply (rule exI[of _ F]) + using \a < sum f F\ and \finite F\ and \F \ A\ + apply auto + by (smt (verit, best) Diff_iff assms(1) less_le_trans subset_iff sum_mono2) + next + fix a assume \(SUP F\{F. finite F \ F\A}. sum f F) < a\ + then have \sum f F < a\ if \F\A\ and \finite F\ for F + by (smt (verit, best) Collect_cong antisym_conv assms(2) cSUP_upper dual_order.trans le_less_linear less_le mem_Collect_eq that(1) that(2)) + then show \\\<^sub>F x in finite_subsets_at_top A. sum f x < a\ + by (rule eventually_finite_subsets_at_top_weakI) + qed + then show ?thesis + using has_sum_def by blast +qed + +lemma pos_summable_on: + fixes f :: \'a \ 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\ + assumes \\x. x\A \ f x \ 0\ + assumes \bdd_above (sum f ` {F. F\A \ finite F})\ + shows \f summable_on A\ + using assms(1) assms(2) summable_on_def pos_has_sum by blast + + +lemma pos_infsum: + fixes f :: \'a \ 'b :: {conditionally_complete_linorder, ordered_comm_monoid_add, linorder_topology}\ + assumes \\x. x\A \ f x \ 0\ + assumes \bdd_above (sum f ` {F. F\A \ finite F})\ + shows \infsum f A = (SUP F\{F. finite F \ F\A}. sum f F)\ + using assms by (auto intro!: infsumI pos_has_sum) + +lemma pos_has_sum_complete: + fixes f :: \'a \ 'b :: {complete_linorder, ordered_comm_monoid_add, linorder_topology}\ + assumes \\x. x\A \ f x \ 0\ + shows \has_sum f A (SUP F\{F. finite F \ F\A}. sum f F)\ + using assms pos_has_sum by blast + +lemma pos_summable_on_complete: + fixes f :: \'a \ 'b :: {complete_linorder, ordered_comm_monoid_add, linorder_topology}\ + assumes \\x. x\A \ f x \ 0\ + shows \f summable_on A\ + using assms pos_summable_on by blast + +lemma pos_infsum_complete: + fixes f :: \'a \ 'b :: {complete_linorder, ordered_comm_monoid_add, linorder_topology}\ + assumes \\x. x\A \ f x \ 0\ + shows \infsum f A = (SUP F\{F. finite F \ F\A}. sum f F)\ + using assms pos_infsum by blast + +lemma has_sum_nonneg: + fixes f :: "'a \ 'b::{ordered_comm_monoid_add,linorder_topology}" + assumes "has_sum f M a" + and "\x. x \ M \ 0 \ f x" + shows "a \ 0" + by (metis (no_types, lifting) DiffD1 assms(1) assms(2) empty_iff has_sum_0 has_sum_mono_neutral order_refl) + +lemma infsum_nonneg: + fixes f :: "'a \ 'b::{ordered_comm_monoid_add,linorder_topology}" + assumes "f summable_on M" + and "\x. x \ M \ 0 \ f x" + shows "infsum f M \ 0" (is "?lhs \ _") + by (metis assms infsum_0_simp summable_on_0_simp infsum_mono) + +lemma has_sum_reindex: + assumes \inj_on h A\ + shows \has_sum g (h ` A) x \ has_sum (g \ h) A x\ +proof - + have \has_sum g (h ` A) x \ (sum g \ x) (finite_subsets_at_top (h ` A))\ + by (simp add: has_sum_def) + also have \\ \ ((\F. sum g (h ` F)) \ x) (finite_subsets_at_top A)\ + apply (subst filtermap_image_finite_subsets_at_top[symmetric]) + using assms by (auto simp: filterlim_def filtermap_filtermap) + also have \\ \ (sum (g \ h) \ x) (finite_subsets_at_top A)\ + apply (rule tendsto_cong) + apply (rule eventually_finite_subsets_at_top_weakI) + apply (rule sum.reindex) + using assms subset_inj_on by blast + also have \\ \ has_sum (g \ h) A x\ + by (simp add: has_sum_def) + finally show ?thesis + by - +qed + + +lemma summable_on_reindex: + assumes \inj_on h A\ + shows \g summable_on (h ` A) \ (g \ h) summable_on A\ + by (simp add: assms summable_on_def has_sum_reindex) + +lemma infsum_reindex: + assumes \inj_on h A\ + shows \infsum g (h ` A) = infsum (g \ h) A\ + by (metis (no_types, opaque_lifting) assms finite_subsets_at_top_neq_bot infsum_def summable_on_reindex has_sum_def has_sum_infsum has_sum_reindex tendsto_Lim) + + +lemma sum_uniformity: + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'b::{uniform_space,comm_monoid_add},y). x+y)\ + assumes \eventually E uniformity\ + obtains D where \eventually D uniformity\ + and \\M::'a set. \f f' :: 'a \ 'b. card M \ n \ (\m\M. D (f m, f' m)) \ E (sum f M, sum f' M)\ +proof (atomize_elim, insert \eventually E uniformity\, induction n arbitrary: E rule:nat_induct) + case 0 + then show ?case + by (metis card_eq_0_iff equals0D le_zero_eq sum.infinite sum.not_neutral_contains_not_neutral uniformity_refl) +next + case (Suc n) + from plus_cont[unfolded uniformly_continuous_on_uniformity filterlim_def le_filter_def, rule_format, OF Suc.prems] + obtain D1 D2 where \eventually D1 uniformity\ and \eventually D2 uniformity\ + and D1D2E: \D1 (x, y) \ D2 (x', y') \ E (x + x', y + y')\ for x y x' y' + apply atomize_elim + by (auto simp: eventually_prod_filter case_prod_beta uniformity_prod_def eventually_filtermap) + + from Suc.IH[OF \eventually D2 uniformity\] + obtain D3 where \eventually D3 uniformity\ and D3: \card M \ n \ (\m\M. D3 (f m, f' m)) \ D2 (sum f M, sum f' M)\ + for M :: \'a set\ and f f' + by metis + + define D where \D x \ D1 x \ D3 x\ for x + have \eventually D uniformity\ + using D_def \eventually D1 uniformity\ \eventually D3 uniformity\ eventually_elim2 by blast + + have \E (sum f M, sum f' M)\ + if \card M \ Suc n\ and DM: \\m\M. D (f m, f' m)\ + for M :: \'a set\ and f f' + proof (cases \card M = 0\) + case True + then show ?thesis + by (metis Suc.prems card_eq_0_iff sum.empty sum.infinite uniformity_refl) + next + case False + with \card M \ Suc n\ obtain N x where \card N \ n\ and \x \ N\ and \M = insert x N\ + by (metis card_Suc_eq less_Suc_eq_0_disj less_Suc_eq_le) + + from DM have \\m. m\N \ D (f m, f' m)\ + using \M = insert x N\ by blast + with D3[OF \card N \ n\] + have D2_N: \D2 (sum f N, sum f' N)\ + using D_def by blast + + from DM + have \D (f x, f' x)\ + using \M = insert x N\ by blast + then have \D1 (f x, f' x)\ + by (simp add: D_def) + + with D2_N + have \E (f x + sum f N, f' x + sum f' N)\ + using D1D2E by presburger + + then show \E (sum f M, sum f' M)\ + by (metis False \M = insert x N\ \x \ N\ card.infinite finite_insert sum.insert) + qed + with \eventually D uniformity\ + show ?case + by auto +qed + +lemma has_sum_Sigma: + fixes A :: "'a set" and B :: "'a \ 'b set" + and f :: \'a \ 'b \ 'c::{comm_monoid_add,uniform_space}\ + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'c,y). x+y)\ + assumes summableAB: "has_sum f (Sigma A B) a" + assumes summableB: \\x. x\A \ has_sum (\y. f (x, y)) (B x) (b x)\ + shows "has_sum b A a" +proof - + define F FB FA where \F = finite_subsets_at_top (Sigma A B)\ and \FB x = finite_subsets_at_top (B x)\ + and \FA = finite_subsets_at_top A\ for x + + from summableB + have sum_b: \(sum (\y. f (x, y)) \ b x) (FB x)\ if \x \ A\ for x + using FB_def[abs_def] has_sum_def that by auto + from summableAB + have sum_S: \(sum f \ a) F\ + using F_def has_sum_def by blast + + have finite_proj: \finite {b| b. (a,b) \ H}\ if \finite H\ for H :: \('a\'b) set\ and a + apply (subst asm_rl[of \{b| b. (a,b) \ H} = snd ` {ab. ab \ H \ fst ab = a}\]) + by (auto simp: image_iff that) + + have \(sum b \ a) FA\ + proof (rule tendsto_iff_uniformity[THEN iffD2, rule_format]) + fix E :: \('c \ 'c) \ bool\ + assume \eventually E uniformity\ + then obtain D where D_uni: \eventually D uniformity\ and DDE': \\x y z. D (x, y) \ D (y, z) \ E (x, z)\ + by (metis (no_types, lifting) \eventually E uniformity\ uniformity_transE) + from sum_S obtain G where \finite G\ and \G \ Sigma A B\ + and G_sum: \G \ H \ H \ Sigma A B \ finite H \ D (sum f H, a)\ for H + unfolding tendsto_iff_uniformity + by (metis (mono_tags, lifting) D_uni F_def eventually_finite_subsets_at_top) + have \finite (fst ` G)\ and \fst ` G \ A\ + using \finite G\ \G \ Sigma A B\ by auto + thm uniformity_prod_def + define Ga where \Ga a = {b. (a,b) \ G}\ for a + have Ga_fin: \finite (Ga a)\ and Ga_B: \Ga a \ B a\ for a + using \finite G\ \G \ Sigma A B\ finite_proj by (auto simp: Ga_def finite_proj) + + have \E (sum b M, a)\ if \M \ fst ` G\ and \finite M\ and \M \ A\ for M + proof - + define FMB where \FMB = finite_subsets_at_top (Sigma M B)\ + have \eventually (\H. D (\a\M. b a, \(a,b)\H. f (a,b))) FMB\ + proof - + obtain D' where D'_uni: \eventually D' uniformity\ + and \card M' \ card M \ (\m\M'. D' (g m, g' m)) \ D (sum g M', sum g' M')\ + for M' :: \'a set\ and g g' + apply (rule sum_uniformity[OF plus_cont \eventually D uniformity\, where n=\card M\]) + by auto + then have D'_sum_D: \(\m\M. D' (g m, g' m)) \ D (sum g M, sum g' M)\ for g g' + by auto + + obtain Ha where \Ha a \ Ga a\ and Ha_fin: \finite (Ha a)\ and Ha_B: \Ha a \ B a\ + and D'_sum_Ha: \Ha a \ L \ L \ B a \ finite L \ D' (b a, sum (\b. f (a,b)) L)\ if \a \ A\ for a L + proof - + from sum_b[unfolded tendsto_iff_uniformity, rule_format, OF _ D'_uni[THEN uniformity_sym]] + obtain Ha0 where \finite (Ha0 a)\ and \Ha0 a \ B a\ + and \Ha0 a \ L \ L \ B a \ finite L \ D' (b a, sum (\b. f (a,b)) L)\ if \a \ A\ for a L + unfolding FB_def eventually_finite_subsets_at_top apply auto by metis + moreover define Ha where \Ha a = Ha0 a \ Ga a\ for a + ultimately show ?thesis + using that[where Ha=Ha] + using Ga_fin Ga_B by auto + qed + + have \D (\a\M. b a, \(a,b)\H. f (a,b))\ if \finite H\ and \H \ Sigma M B\ and \H \ Sigma M Ha\ for H + proof - + define Ha' where \Ha' a = {b| b. (a,b) \ H}\ for a + have [simp]: \finite (Ha' a)\ and [simp]: \Ha' a \ Ha a\ and [simp]: \Ha' a \ B a\ if \a \ M\ for a + unfolding Ha'_def using \finite H\ \H \ Sigma M B\ \Sigma M Ha \ H\ that finite_proj by auto + have \Sigma M Ha' = H\ + using that by (auto simp: Ha'_def) + then have *: \(\(a,b)\H. f (a,b)) = (\a\M. \b\Ha' a. f (a,b))\ + apply (subst sum.Sigma) + using \finite M\ by auto + have \D' (b a, sum (\b. f (a,b)) (Ha' a))\ if \a \ M\ for a + apply (rule D'_sum_Ha) + using that \M \ A\ by auto + then have \D (\a\M. b a, \a\M. sum (\b. f (a,b)) (Ha' a))\ + by (rule_tac D'_sum_D, auto) + with * show ?thesis + by auto + qed + moreover have \Sigma M Ha \ Sigma M B\ + using Ha_B \M \ A\ by auto + ultimately show ?thesis + apply (simp add: FMB_def eventually_finite_subsets_at_top) + by (metis Ha_fin finite_SigmaI subsetD that(2) that(3)) + qed + moreover have \eventually (\H. D (\(a,b)\H. f (a,b), a)) FMB\ + unfolding FMB_def eventually_finite_subsets_at_top + apply (rule exI[of _ G]) + using \G \ Sigma A B\ \finite G\ that G_sum apply auto + by (smt (z3) Sigma_Un_distrib1 dual_order.trans subset_Un_eq) + ultimately have \\\<^sub>F x in FMB. E (sum b M, a)\ + by (smt (verit, best) DDE' eventually_elim2) + then show \E (sum b M, a)\ + apply (rule eventually_const[THEN iffD1, rotated]) + using FMB_def by force + qed + then show \\\<^sub>F x in FA. E (sum b x, a)\ + using \finite (fst ` G)\ and \fst ` G \ A\ + by (auto intro!: exI[of _ \fst ` G\] simp add: FA_def eventually_finite_subsets_at_top) + qed + then show ?thesis + by (simp add: FA_def has_sum_def) +qed + +lemma summable_on_Sigma: + fixes A :: "'a set" and B :: "'a \ 'b set" + and f :: \'a \ 'b \ 'c::{comm_monoid_add, t2_space, uniform_space}\ + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'c,y). x+y)\ + assumes summableAB: "(\(x,y). f x y) summable_on (Sigma A B)" + assumes summableB: \\x. x\A \ (f x) summable_on (B x)\ + shows \(\x. infsum (f x) (B x)) summable_on A\ +proof - + from summableAB obtain a where a: \has_sum (\(x,y). f x y) (Sigma A B) a\ + using has_sum_infsum by blast + from summableB have b: \\x. x\A \ has_sum (f x) (B x) (infsum (f x) (B x))\ + by (auto intro!: has_sum_infsum) + show ?thesis + using plus_cont a b + by (auto intro: has_sum_Sigma[where f=\\(x,y). f x y\, simplified] simp: summable_on_def) +qed + +lemma infsum_Sigma: + fixes A :: "'a set" and B :: "'a \ 'b set" + and f :: \'a \ 'b \ 'c::{comm_monoid_add, t2_space, uniform_space}\ + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'c,y). x+y)\ + assumes summableAB: "f summable_on (Sigma A B)" + assumes summableB: \\x. x\A \ (\y. f (x, y)) summable_on (B x)\ + shows "infsum f (Sigma A B) = infsum (\x. infsum (\y. f (x, y)) (B x)) A" +proof - + from summableAB have a: \has_sum f (Sigma A B) (infsum f (Sigma A B))\ + using has_sum_infsum by blast + from summableB have b: \\x. x\A \ has_sum (\y. f (x, y)) (B x) (infsum (\y. f (x, y)) (B x))\ + by (auto intro!: has_sum_infsum) + show ?thesis + using plus_cont a b by (auto intro: infsumI[symmetric] has_sum_Sigma simp: summable_on_def) +qed + +lemma infsum_Sigma': + fixes A :: "'a set" and B :: "'a \ 'b set" + and f :: \'a \ 'b \ 'c::{comm_monoid_add, t2_space, uniform_space}\ + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'c,y). x+y)\ + assumes summableAB: "(\(x,y). f x y) summable_on (Sigma A B)" + assumes summableB: \\x. x\A \ (f x) summable_on (B x)\ + shows \infsum (\x. infsum (f x) (B x)) A = infsum (\(x,y). f x y) (Sigma A B)\ + using infsum_Sigma[of \\(x,y). f x y\ A B] + using assms by auto + +text \A special case of @{thm [source] infsum_Sigma} etc. for Banach spaces. It has less premises.\ +lemma + fixes A :: "'a set" and B :: "'a \ 'b set" + and f :: \'a \ 'b \ 'c::banach\ + assumes [simp]: "(\(x,y). f x y) summable_on (Sigma A B)" + shows infsum_Sigma'_banach: \infsum (\x. infsum (f x) (B x)) A = infsum (\(x,y). f x y) (Sigma A B)\ (is ?thesis1) + and summable_on_Sigma_banach: \(\x. infsum (f x) (B x)) summable_on A\ (is ?thesis2) +proof - + have [simp]: \(f x) summable_on (B x)\ if \x \ A\ for x + proof - + from assms + have \(\(x,y). f x y) summable_on (Pair x ` B x)\ + by (meson image_subset_iff summable_on_subset_banach mem_Sigma_iff that) + then have \((\(x,y). f x y) o Pair x) summable_on (B x)\ + apply (rule_tac summable_on_reindex[THEN iffD1]) + by (simp add: inj_on_def) + then show ?thesis + by (auto simp: o_def) + qed + show ?thesis1 + apply (rule infsum_Sigma') + by auto + show ?thesis2 + apply (rule summable_on_Sigma) + by auto +qed + +lemma infsum_Sigma_banach: + fixes A :: "'a set" and B :: "'a \ 'b set" + and f :: \'a \ 'b \ 'c::banach\ + assumes [simp]: "f summable_on (Sigma A B)" + shows \infsum (\x. infsum (\y. f (x,y)) (B x)) A = infsum f (Sigma A B)\ + by (smt (verit, best) SigmaE assms infsum_Sigma'_banach infsum_cong summable_on_cong old.prod.case) + +lemma infsum_swap: + fixes A :: "'a set" and B :: "'b set" + fixes f :: "'a \ 'b \ 'c::{comm_monoid_add,t2_space,uniform_space}" + assumes plus_cont: \uniformly_continuous_on UNIV (\(x::'c,y). x+y)\ + assumes \(\(x, y). f x y) summable_on (A \ B)\ + assumes \\a. a\A \ (f a) summable_on B\ + assumes \\b. b\B \ (\a. f a b) summable_on A\ + shows \infsum (\x. infsum (\y. f x y) B) A = infsum (\y. infsum (\x. f x y) A) B\ +proof - + have [simp]: \(\(x, y). f y x) summable_on (B \ A)\ + apply (subst product_swap[symmetric]) + apply (subst summable_on_reindex) + using assms by (auto simp: o_def) + have \infsum (\x. infsum (\y. f x y) B) A = infsum (\(x,y). f x y) (A \ B)\ + apply (subst infsum_Sigma) + using assms by auto + also have \\ = infsum (\(x,y). f y x) (B \ A)\ + apply (subst product_swap[symmetric]) + apply (subst infsum_reindex) + using assms by (auto simp: o_def) + also have \\ = infsum (\y. infsum (\x. f x y) A) B\ + apply (subst infsum_Sigma) + using assms by auto + finally show ?thesis + by - +qed + +lemma infsum_swap_banach: + fixes A :: "'a set" and B :: "'b set" + fixes f :: "'a \ 'b \ 'c::banach" + assumes \(\(x, y). f x y) summable_on (A \ B)\ + shows "infsum (\x. infsum (\y. f x y) B) A = infsum (\y. infsum (\x. f x y) A) B" +proof - + have [simp]: \(\(x, y). f y x) summable_on (B \ A)\ + apply (subst product_swap[symmetric]) + apply (subst summable_on_reindex) + using assms by (auto simp: o_def) + have \infsum (\x. infsum (\y. f x y) B) A = infsum (\(x,y). f x y) (A \ B)\ + apply (subst infsum_Sigma'_banach) + using assms by auto + also have \\ = infsum (\(x,y). f y x) (B \ A)\ + apply (subst product_swap[symmetric]) + apply (subst infsum_reindex) + using assms by (auto simp: o_def) + also have \\ = infsum (\y. infsum (\x. f x y) A) B\ + apply (subst infsum_Sigma'_banach) + using assms by auto + finally show ?thesis + by - +qed + +lemma infsum_0D: + fixes f :: "'a \ 'b::{topological_ab_group_add,ordered_ab_group_add,linorder_topology}" + assumes "infsum f A \ 0" + and abs_sum: "f summable_on A" + and nneg: "\x. x \ A \ f x \ 0" + and "x \ A" + shows "f x = 0" +proof (rule ccontr) + assume \f x \ 0\ + have ex: \f summable_on (A-{x})\ + apply (rule summable_on_cofin_subset) + using assms by auto + then have pos: \infsum f (A - {x}) \ 0\ + apply (rule infsum_nonneg) + using nneg by auto + + have [trans]: \x \ y \ y > z \ x > z\ for x y z :: 'b by auto + + have \infsum f A = infsum f (A-{x}) + infsum f {x}\ + apply (subst infsum_Un_disjoint[symmetric]) + using assms ex apply auto by (metis insert_absorb) + also have \\ \ infsum f {x}\ (is \_ \ \\) + using pos apply (rule add_increasing) by simp + also have \\ = f x\ (is \_ = \\) + apply (subst infsum_finite) by auto + also have \\ > 0\ + using \f x \ 0\ assms(4) nneg by fastforce + finally show False + using assms by auto +qed + +lemma has_sum_0D: + fixes f :: "'a \ 'b::{topological_ab_group_add,ordered_ab_group_add,linorder_topology}" + assumes "has_sum f A a" \a \ 0\ + and nneg: "\x. x \ A \ f x \ 0" + and "x \ A" + shows "f x = 0" + by (metis assms(1) assms(2) assms(4) infsumI infsum_0D summable_on_def nneg) + +lemma has_sum_cmult_left: + fixes f :: "'a \ 'b :: {topological_semigroup_mult, semiring_0}" + assumes \has_sum f A a\ + shows "has_sum (\x. f x * c) A (a * c)" +proof - + from assms have \(sum f \ a) (finite_subsets_at_top A)\ + using has_sum_def by blast + then have \((\F. sum f F * c) \ a * c) (finite_subsets_at_top A)\ + by (simp add: tendsto_mult_right) + then have \(sum (\x. f x * c) \ a * c) (finite_subsets_at_top A)\ + apply (rule tendsto_cong[THEN iffD1, rotated]) + apply (rule eventually_finite_subsets_at_top_weakI) + using sum_distrib_right by blast + then show ?thesis + using infsumI has_sum_def by blast +qed + +lemma infsum_cmult_left: + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" + assumes \c \ 0 \ f summable_on A\ + shows "infsum (\x. f x * c) A = infsum f A * c" +proof (cases \c=0\) + case True + then show ?thesis by auto +next + case False + then have \has_sum f A (infsum f A)\ + by (simp add: assms) + then show ?thesis + by (auto intro!: infsumI has_sum_cmult_left) +qed + +lemma summable_on_cmult_left: + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" + assumes \f summable_on A\ + shows "(\x. f x * c) summable_on A" + using assms summable_on_def has_sum_cmult_left by blast + +lemma has_sum_cmult_right: + fixes f :: "'a \ 'b :: {topological_semigroup_mult, semiring_0}" + assumes \has_sum f A a\ + shows "has_sum (\x. c * f x) A (c * a)" +proof - + from assms have \(sum f \ a) (finite_subsets_at_top A)\ + using has_sum_def by blast + then have \((\F. c * sum f F) \ c * a) (finite_subsets_at_top A)\ + by (simp add: tendsto_mult_left) + then have \(sum (\x. c * f x) \ c * a) (finite_subsets_at_top A)\ + apply (rule tendsto_cong[THEN iffD1, rotated]) + apply (rule eventually_finite_subsets_at_top_weakI) + using sum_distrib_left by blast + then show ?thesis + using infsumI has_sum_def by blast +qed + +lemma infsum_cmult_right: + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" + assumes \c \ 0 \ f summable_on A\ + shows \infsum (\x. c * f x) A = c * infsum f A\ +proof (cases \c=0\) + case True + then show ?thesis by auto +next + case False + then have \has_sum f A (infsum f A)\ + by (simp add: assms) + then show ?thesis + by (auto intro!: infsumI has_sum_cmult_right) +qed + +lemma summable_on_cmult_right: + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, semiring_0}" + assumes \f summable_on A\ + shows "(\x. c * f x) summable_on A" + using assms summable_on_def has_sum_cmult_right by blast + +lemma summable_on_cmult_left': + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, division_ring}" + assumes \c \ 0\ + shows "(\x. f x * c) summable_on A \ f summable_on A" +proof + assume \f summable_on A\ + then show \(\x. f x * c) summable_on A\ + by (rule summable_on_cmult_left) +next + assume \(\x. f x * c) summable_on A\ + then have \(\x. f x * c * inverse c) summable_on A\ + by (rule summable_on_cmult_left) + then show \f summable_on A\ + by (metis (no_types, lifting) assms summable_on_cong mult.assoc mult.right_neutral right_inverse) +qed + +lemma summable_on_cmult_right': + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, division_ring}" + assumes \c \ 0\ + shows "(\x. c * f x) summable_on A \ f summable_on A" +proof + assume \f summable_on A\ + then show \(\x. c * f x) summable_on A\ + by (rule summable_on_cmult_right) +next + assume \(\x. c * f x) summable_on A\ + then have \(\x. inverse c * (c * f x)) summable_on A\ + by (rule summable_on_cmult_right) + then show \f summable_on A\ + by (metis (no_types, lifting) assms summable_on_cong left_inverse mult.assoc mult.left_neutral) +qed + +lemma infsum_cmult_left': + fixes f :: "'a \ 'b :: {t2_space, topological_semigroup_mult, division_ring}" + shows "infsum (\x. f x * c) A = infsum f A * c" +proof (cases \c \ 0 \ f summable_on A\) + case True + then show ?thesis + apply (rule_tac infsum_cmult_left) by auto +next + case False + note asm = False + then show ?thesis + proof (cases \c=0\) + case True + then show ?thesis by auto + next + case False + with asm have nex: \\ f summable_on A\ + by simp + moreover have nex': \\ (\x. f x * c) summable_on A\ + using asm False apply (subst summable_on_cmult_left') by auto + ultimately show ?thesis + unfolding infsum_def by simp + qed +qed + +lemma infsum_cmult_right': + fixes f :: "'a \ 'b :: {t2_space,topological_semigroup_mult,division_ring}" + shows "infsum (\x. c * f x) A = c * infsum f A" +proof (cases \c \ 0 \ f summable_on A\) + case True + then show ?thesis + apply (rule_tac infsum_cmult_right) by auto +next + case False + note asm = False + then show ?thesis + proof (cases \c=0\) + case True + then show ?thesis by auto + next + case False + with asm have nex: \\ f summable_on A\ + by simp + moreover have nex': \\ (\x. c * f x) summable_on A\ + using asm False apply (subst summable_on_cmult_right') by auto + ultimately show ?thesis + unfolding infsum_def by simp + qed +qed + + +lemma has_sum_constant[simp]: + assumes \finite F\ + shows \has_sum (\_. c) F (of_nat (card F) * c)\ + by (metis assms has_sum_finite sum_constant) + +lemma infsum_constant[simp]: + assumes \finite F\ + shows \infsum (\_. c) F = of_nat (card F) * c\ + apply (subst infsum_finite[OF assms]) by simp + +lemma infsum_diverge_constant: + \ \This probably does not really need all of \<^class>\archimedean_field\ but Isabelle/HOL + has no type class such as, e.g., "archimedean ring".\ + fixes c :: \'a::{archimedean_field, comm_monoid_add, linorder_topology, topological_semigroup_mult}\ + assumes \infinite A\ and \c \ 0\ + shows \\ (\_. c) summable_on A\ +proof (rule notI) + assume \(\_. c) summable_on A\ + then have \(\_. inverse c * c) summable_on A\ + by (rule summable_on_cmult_right) + then have [simp]: \(\_. 1::'a) summable_on A\ + using assms by auto + have \infsum (\_. 1) A \ d\ for d :: 'a + proof - + obtain n :: nat where \of_nat n \ d\ + by (meson real_arch_simple) + from assms + obtain F where \F \ A\ and \finite F\ and \card F = n\ + by (meson infinite_arbitrarily_large) + note \d \ of_nat n\ + also have \of_nat n = infsum (\_. 1::'a) F\ + by (simp add: \card F = n\ \finite F\) + also have \\ \ infsum (\_. 1::'a) A\ + apply (rule infsum_mono_neutral) + using \finite F\ \F \ A\ by auto + finally show ?thesis + by - + qed + then show False + by (meson linordered_field_no_ub not_less) +qed + +lemma has_sum_constant_archimedean[simp]: + \ \This probably does not really need all of \<^class>\archimedean_field\ but Isabelle/HOL + has no type class such as, e.g., "archimedean ring".\ + fixes c :: \'a::{archimedean_field, comm_monoid_add, linorder_topology, topological_semigroup_mult}\ + shows \infsum (\_. c) A = of_nat (card A) * c\ + apply (cases \finite A\) + apply simp + apply (cases \c = 0\) + apply simp + by (simp add: infsum_diverge_constant infsum_not_exists) + +lemma has_sum_uminus: + fixes f :: \'a \ 'b::topological_ab_group_add\ + shows \has_sum (\x. - f x) A a \ has_sum f A (- a)\ + by (auto simp add: sum_negf[abs_def] tendsto_minus_cancel_left has_sum_def) + +lemma summable_on_uminus: + fixes f :: \'a \ 'b::topological_ab_group_add\ + shows\(\x. - f x) summable_on A \ f summable_on A\ + by (metis summable_on_def has_sum_uminus verit_minus_simplify(4)) + +lemma infsum_uminus: + fixes f :: \'a \ 'b::{topological_ab_group_add, t2_space}\ + shows \infsum (\x. - f x) A = - infsum f A\ + by (metis (full_types) add.inverse_inverse add.inverse_neutral infsumI infsum_def has_sum_infsum has_sum_uminus) + +subsection \Extended reals and nats\ + +lemma summable_on_ennreal[simp]: \(f::_ \ ennreal) summable_on S\ + apply (rule pos_summable_on_complete) by simp + +lemma summable_on_enat[simp]: \(f::_ \ enat) summable_on S\ + apply (rule pos_summable_on_complete) by simp + +lemma has_sum_superconst_infinite_ennreal: + fixes f :: \'a \ ennreal\ + assumes geqb: \\x. x \ S \ f x \ b\ + assumes b: \b > 0\ + assumes \infinite S\ + shows "has_sum f S \" +proof - + have \(sum f \ \) (finite_subsets_at_top S)\ + proof (rule order_tendstoI[rotated], simp) + fix y :: ennreal assume \y < \\ + then have \y / b < \\ + by (metis b ennreal_divide_eq_top_iff gr_implies_not_zero infinity_ennreal_def top.not_eq_extremum) + then obtain F where \finite F\ and \F \ S\ and cardF: \card F > y / b\ + using \infinite S\ + by (metis ennreal_Ex_less_of_nat infinite_arbitrarily_large infinity_ennreal_def) + moreover have \sum f Y > y\ if \finite Y\ and \F \ Y\ and \Y \ S\ for Y + proof - + have \y < b * card F\ + by (metis \y < \\ b cardF divide_less_ennreal ennreal_mult_eq_top_iff gr_implies_not_zero infinity_ennreal_def mult.commute top.not_eq_extremum) + also have \\ \ b * card Y\ + by (meson b card_mono less_imp_le mult_left_mono of_nat_le_iff that(1) that(2)) + also have \\ = sum (\_. b) Y\ + by (simp add: mult.commute) + also have \\ \ sum f Y\ + using geqb by (meson subset_eq sum_mono that(3)) + finally show ?thesis + by - + qed + ultimately show \\\<^sub>F x in finite_subsets_at_top S. y < sum f x\ + unfolding eventually_finite_subsets_at_top + by auto + qed + then show ?thesis + by (simp add: has_sum_def) +qed + +lemma infsum_superconst_infinite_ennreal: + fixes f :: \'a \ ennreal\ + assumes \\x. x \ S \ f x \ b\ + assumes \b > 0\ + assumes \infinite S\ + shows "infsum f S = \" + using assms infsumI has_sum_superconst_infinite_ennreal by blast + +lemma infsum_superconst_infinite_ereal: + fixes f :: \'a \ ereal\ + assumes geqb: \\x. x \ S \ f x \ b\ + assumes b: \b > 0\ + assumes \infinite S\ + shows "infsum f S = \" +proof - + obtain b' where b': \e2ennreal b' = b\ and \b' > 0\ + using b by blast + have *: \infsum (e2ennreal o f) S = \\ + apply (rule infsum_superconst_infinite_ennreal[where b=b']) + using assms \b' > 0\ b' e2ennreal_mono apply auto + by (metis dual_order.strict_iff_order enn2ereal_e2ennreal le_less_linear zero_ennreal_def) + have \infsum f S = infsum (enn2ereal o (e2ennreal o f)) S\ + by (smt (verit, best) b comp_apply dual_order.trans enn2ereal_e2ennreal geqb infsum_cong less_imp_le) + also have \\ = enn2ereal \\ + apply (subst infsum_comm_additive_general) + using * by (auto simp: continuous_at_enn2ereal) + also have \\ = \\ + by simp + finally show ?thesis + by - +qed + +lemma has_sum_superconst_infinite_ereal: + fixes f :: \'a \ ereal\ + assumes \\x. x \ S \ f x \ b\ + assumes \b > 0\ + assumes \infinite S\ + shows "has_sum f S \" + by (metis Infty_neq_0(1) assms infsum_def has_sum_infsum infsum_superconst_infinite_ereal) + +lemma infsum_superconst_infinite_enat: + fixes f :: \'a \ enat\ + assumes geqb: \\x. x \ S \ f x \ b\ + assumes b: \b > 0\ + assumes \infinite S\ + shows "infsum f S = \" +proof - + have \ennreal_of_enat (infsum f S) = infsum (ennreal_of_enat o f) S\ + apply (rule infsum_comm_additive_general[symmetric]) + by auto + also have \\ = \\ + by (metis assms(3) b comp_apply ennreal_of_enat_0 ennreal_of_enat_inj ennreal_of_enat_le_iff geqb infsum_superconst_infinite_ennreal not_gr_zero) + also have \\ = ennreal_of_enat \\ + by simp + finally show ?thesis + by (rule ennreal_of_enat_inj[THEN iffD1]) +qed + +lemma has_sum_superconst_infinite_enat: + fixes f :: \'a \ enat\ + assumes \\x. x \ S \ f x \ b\ + assumes \b > 0\ + assumes \infinite S\ + shows "has_sum f S \" + by (metis assms i0_lb has_sum_infsum infsum_superconst_infinite_enat pos_summable_on_complete) + +text \This lemma helps to relate a real-valued infsum to a supremum over extended nonnegative reals.\ + +lemma infsum_nonneg_is_SUPREMUM_ennreal: + fixes f :: "'a \ real" + assumes summable: "f summable_on A" + and fnn: "\x. x\A \ f x \ 0" + shows "ennreal (infsum f A) = (SUP F\{F. finite F \ F \ A}. (ennreal (sum f F)))" +proof - + have \ennreal (infsum f A) = infsum (ennreal o f) A\ + apply (rule infsum_comm_additive_general[symmetric]) + apply (subst sum_ennreal[symmetric]) + using assms by auto + also have \\ = (SUP F\{F. finite F \ F \ A}. (ennreal (sum f F)))\ + apply (subst pos_infsum_complete, simp) + apply (rule SUP_cong, blast) + apply (subst sum_ennreal[symmetric]) + using fnn by auto + finally show ?thesis + by - +qed + +text \This lemma helps to related a real-valued infsum to a supremum over extended reals.\ + +lemma infsum_nonneg_is_SUPREMUM_ereal: + fixes f :: "'a \ real" + assumes summable: "f summable_on A" + and fnn: "\x. x\A \ f x \ 0" + shows "ereal (infsum f A) = (SUP F\{F. finite F \ F \ A}. (ereal (sum f F)))" +proof - + have \ereal (infsum f A) = infsum (ereal o f) A\ + apply (rule infsum_comm_additive_general[symmetric]) + using assms by auto + also have \\ = (SUP F\{F. finite F \ F \ A}. (ereal (sum f F)))\ + apply (subst pos_infsum_complete) + by (simp_all add: assms)[2] + finally show ?thesis + by - +qed + + +subsection \Real numbers\ + +text \Most lemmas in the general property section already apply to real numbers. + A few ones that are specific to reals are given here.\ + +lemma infsum_nonneg_is_SUPREMUM_real: + fixes f :: "'a \ real" + assumes summable: "f summable_on A" + and fnn: "\x. x\A \ f x \ 0" + shows "infsum f A = (SUP F\{F. finite F \ F \ A}. (sum f F))" +proof - + have "ereal (infsum f A) = (SUP F\{F. finite F \ F \ A}. (ereal (sum f F)))" + using assms by (rule infsum_nonneg_is_SUPREMUM_ereal) + also have "\ = ereal (SUP F\{F. finite F \ F \ A}. (sum f F))" + proof (subst ereal_SUP) + show "\SUP a\{F. finite F \ F \ A}. ereal (sum f a)\ \ \" + using calculation by fastforce + show "(SUP F\{F. finite F \ F \ A}. ereal (sum f F)) = (SUP a\{F. finite F \ F \ A}. ereal (sum f a))" + by simp + qed + finally show ?thesis by simp +qed + + +lemma has_sum_nonneg_SUPREMUM_real: + fixes f :: "'a \ real" + assumes "f summable_on A" and "\x. x\A \ f x \ 0" + shows "has_sum f A (SUP F\{F. finite F \ F \ A}. (sum f F))" + by (metis (mono_tags, lifting) assms has_sum_infsum infsum_nonneg_is_SUPREMUM_real) + + +lemma summable_on_iff_abs_summable_on_real: + fixes f :: \'a \ real\ + shows \f summable_on A \ f abs_summable_on A\ +proof (rule iffI) + assume \f summable_on A\ + define n A\<^sub>p A\<^sub>n + where \n x = norm (f x)\ and \A\<^sub>p = {x\A. f x \ 0}\ and \A\<^sub>n = {x\A. f x < 0}\ for x + have [simp]: \A\<^sub>p \ A\<^sub>n = A\ \A\<^sub>p \ A\<^sub>n = {}\ + by (auto simp: A\<^sub>p_def A\<^sub>n_def) + from \f summable_on A\ have [simp]: \f summable_on A\<^sub>p\ \f summable_on A\<^sub>n\ + using A\<^sub>p_def A\<^sub>n_def summable_on_subset_banach by fastforce+ + then have [simp]: \n summable_on A\<^sub>p\ + apply (subst summable_on_cong[where g=f]) + by (simp_all add: A\<^sub>p_def n_def) + moreover have [simp]: \n summable_on A\<^sub>n\ + apply (subst summable_on_cong[where g=\\x. - f x\]) + apply (simp add: A\<^sub>n_def n_def[abs_def]) + by (simp add: summable_on_uminus) + ultimately have [simp]: \n summable_on (A\<^sub>p \ A\<^sub>n)\ + apply (rule summable_on_Un_disjoint) by simp + then show \n summable_on A\ + by simp +next + show \f abs_summable_on A \ f summable_on A\ + using abs_summable_summable by blast +qed + +subsection \Complex numbers\ + +lemma has_sum_cnj_iff[simp]: + fixes f :: \'a \ complex\ + shows \has_sum (\x. cnj (f x)) M (cnj a) \ has_sum f M a\ + by (simp add: has_sum_def lim_cnj del: cnj_sum add: cnj_sum[symmetric, abs_def, of f]) + +lemma summable_on_cnj_iff[simp]: + "(\i. cnj (f i)) summable_on A \ f summable_on A" + by (metis complex_cnj_cnj summable_on_def has_sum_cnj_iff) + +lemma infsum_cnj[simp]: \infsum (\x. cnj (f x)) M = cnj (infsum f M)\ + by (metis complex_cnj_zero infsumI has_sum_cnj_iff infsum_def summable_on_cnj_iff has_sum_infsum) + +lemma infsum_Re: + assumes "f summable_on M" + shows "infsum (\x. Re (f x)) M = Re (infsum f M)" + apply (rule infsum_comm_additive[where f=Re, unfolded o_def]) + using assms by (auto intro!: additive.intro) + +lemma has_sum_Re: + assumes "has_sum f M a" + shows "has_sum (\x. Re (f x)) M (Re a)" + apply (rule has_sum_comm_additive[where f=Re, unfolded o_def]) + using assms by (auto intro!: additive.intro tendsto_Re) + +lemma summable_on_Re: + assumes "f summable_on M" + shows "(\x. Re (f x)) summable_on M" + apply (rule summable_on_comm_additive[where f=Re, unfolded o_def]) + using assms by (auto intro!: additive.intro) + +lemma infsum_Im: + assumes "f summable_on M" + shows "infsum (\x. Im (f x)) M = Im (infsum f M)" + apply (rule infsum_comm_additive[where f=Im, unfolded o_def]) + using assms by (auto intro!: additive.intro) + +lemma has_sum_Im: + assumes "has_sum f M a" + shows "has_sum (\x. Im (f x)) M (Im a)" + apply (rule has_sum_comm_additive[where f=Im, unfolded o_def]) + using assms by (auto intro!: additive.intro tendsto_Im) + +lemma summable_on_Im: + assumes "f summable_on M" + shows "(\x. Im (f x)) summable_on M" + apply (rule summable_on_comm_additive[where f=Im, unfolded o_def]) + using assms by (auto intro!: additive.intro) + +lemma infsum_0D_complex: + fixes f :: "'a \ complex" + assumes "infsum f A \ 0" + and abs_sum: "f summable_on A" + and nneg: "\x. x \ A \ f x \ 0" + and "x \ A" + shows "f x = 0" +proof - + have \Im (f x) = 0\ + apply (rule infsum_0D[where A=A]) + using assms + by (auto simp add: infsum_Im summable_on_Im less_eq_complex_def) + moreover have \Re (f x) = 0\ + apply (rule infsum_0D[where A=A]) + using assms by (auto simp add: summable_on_Re infsum_Re less_eq_complex_def) + ultimately show ?thesis + by (simp add: complex_eqI) +qed + +lemma has_sum_0D_complex: + fixes f :: "'a \ complex" + assumes "has_sum f A a" and \a \ 0\ + and "\x. x \ A \ f x \ 0" and "x \ A" + shows "f x = 0" + by (metis assms infsumI infsum_0D_complex summable_on_def) + +text \The lemma @{thm [source] infsum_mono_neutral} above applies to various linear ordered monoids such as the reals but not to the complex numbers. + Thus we have a separate corollary for those:\ + +lemma infsum_mono_neutral_complex: + fixes f :: "'a \ complex" + assumes [simp]: "f summable_on A" + and [simp]: "g summable_on B" + assumes \\x. x \ A\B \ f x \ g x\ + assumes \\x. x \ A-B \ f x \ 0\ + assumes \\x. x \ B-A \ g x \ 0\ + shows \infsum f A \ infsum g B\ +proof - + have \infsum (\x. Re (f x)) A \ infsum (\x. Re (g x)) B\ + apply (rule infsum_mono_neutral) + using assms(3-5) by (auto simp add: summable_on_Re less_eq_complex_def) + then have Re: \Re (infsum f A) \ Re (infsum g B)\ + by (metis assms(1-2) infsum_Re) + have \infsum (\x. Im (f x)) A = infsum (\x. Im (g x)) B\ + apply (rule infsum_cong_neutral) + using assms(3-5) by (auto simp add: summable_on_Re less_eq_complex_def) + then have Im: \Im (infsum f A) = Im (infsum g B)\ + by (metis assms(1-2) infsum_Im) + from Re Im show ?thesis + by (auto simp: less_eq_complex_def) +qed + +lemma infsum_mono_complex: + \ \For \<^typ>\real\, @{thm [source] infsum_mono} can be used. + But \<^typ>\complex\ does not have the right typeclass.\ + fixes f g :: "'a \ complex" + assumes f_sum: "f summable_on A" and g_sum: "g summable_on A" + assumes leq: "\x. x \ A \ f x \ g x" + shows "infsum f A \ infsum g A" + by (metis DiffE IntD1 f_sum g_sum infsum_mono_neutral_complex leq) + + +lemma infsum_nonneg_complex: + fixes f :: "'a \ complex" + assumes "f summable_on M" + and "\x. x \ M \ 0 \ f x" + shows "infsum f M \ 0" (is "?lhs \ _") + by (metis assms(1) assms(2) infsum_0_simp summable_on_0_simp infsum_mono_complex) + +lemma infsum_cmod: + assumes "f summable_on M" + and fnn: "\x. x \ M \ 0 \ f x" + shows "infsum (\x. cmod (f x)) M = cmod (infsum f M)" +proof - + have \complex_of_real (infsum (\x. cmod (f x)) M) = infsum (\x. complex_of_real (cmod (f x))) M\ + apply (rule infsum_comm_additive[symmetric, unfolded o_def]) + apply auto + apply (simp add: additive.intro) + by (smt (verit, best) assms(1) cmod_eq_Re fnn summable_on_Re summable_on_cong less_eq_complex_def zero_complex.simps(1) zero_complex.simps(2)) + also have \\ = infsum f M\ + apply (rule infsum_cong) + using fnn + using cmod_eq_Re complex_is_Real_iff less_eq_complex_def by force + finally show ?thesis + by (metis abs_of_nonneg infsum_def le_less_trans norm_ge_zero norm_infsum_bound norm_of_real not_le order_refl) +qed + + +lemma summable_on_iff_abs_summable_on_complex: + fixes f :: \'a \ complex\ + shows \f summable_on A \ f abs_summable_on A\ +proof (rule iffI) + assume \f summable_on A\ + define i r ni nr n where \i x = Im (f x)\ and \r x = Re (f x)\ + and \ni x = norm (i x)\ and \nr x = norm (r x)\ and \n x = norm (f x)\ for x + from \f summable_on A\ have \i summable_on A\ + by (simp add: i_def[abs_def] summable_on_Im) + then have [simp]: \ni summable_on A\ + using ni_def[abs_def] summable_on_iff_abs_summable_on_real by force + + from \f summable_on A\ have \r summable_on A\ + by (simp add: r_def[abs_def] summable_on_Re) + then have [simp]: \nr summable_on A\ + by (metis nr_def summable_on_cong summable_on_iff_abs_summable_on_real) + + have n_sum: \n x \ nr x + ni x\ for x + by (simp add: n_def nr_def ni_def r_def i_def cmod_le) + + have *: \(\x. nr x + ni x) summable_on A\ + apply (rule summable_on_add) by auto + show \n summable_on A\ + apply (rule pos_summable_on) + apply (simp add: n_def) + apply (rule bdd_aboveI[where M=\infsum (\x. nr x + ni x) A\]) + using * n_sum by (auto simp flip: infsum_finite simp: ni_def[abs_def] nr_def[abs_def] intro!: infsum_mono_neutral) +next + show \f abs_summable_on A \ f summable_on A\ + using abs_summable_summable by blast +qed + +end diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Analysis/Product_Vector.thy --- a/src/HOL/Analysis/Product_Vector.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Analysis/Product_Vector.thy Thu Oct 07 16:28:17 2021 +0200 @@ -1,5 +1,6 @@ (* Title: HOL/Analysis/Product_Vector.thy Author: Brian Huffman + Dominique Unruh, University of Tartu *) section \Cartesian Products as Vector Spaces\ @@ -122,15 +123,149 @@ instance .. end -instantiation\<^marker>\tag unimportant\ prod :: (metric_space, metric_space) uniformity_dist -begin +instantiation\<^marker>\tag unimportant\ prod :: (uniformity, uniformity) uniformity begin + +definition [code del]: \(uniformity :: (('a \ 'b) \ ('a \ 'b)) filter) = + filtermap (\((x1,x2),(y1,y2)). ((x1,y1),(x2,y2))) (uniformity \\<^sub>F uniformity)\ + +instance.. +end -definition [code del]: - "(uniformity :: (('a \ 'b) \ ('a \ 'b)) filter) = - (INF e\{0 <..}. principal {(x, y). dist x y < e})" +instantiation\<^marker>\tag unimportant\ prod :: (uniform_space, uniform_space) uniform_space begin +instance +proof standard + fix U :: \('a \ 'b) set\ + show \open U \ (\x\U. \\<^sub>F (x', y) in uniformity. x' = x \ y \ U)\ + proof (intro iffI ballI) + fix x assume \open U\ and \x \ U\ + then obtain A B where \open A\ \open B\ \x \ A\B\ \A\B \ U\ + by (metis open_prod_elim) + define UA where \UA = (\(x'::'a,y). x' = fst x \ y \ A)\ + from \open A\ \x \ A\B\ + have \eventually UA uniformity\ + unfolding open_uniformity UA_def by auto + define UB where \UB = (\(x'::'b,y). x' = snd x \ y \ B)\ + from \open A\ \open B\ \x \ A\B\ + have \eventually UA uniformity\ \eventually UB uniformity\ + unfolding open_uniformity UA_def UB_def by auto + then have \\\<^sub>F ((x'1, y1), (x'2, y2)) in uniformity \\<^sub>F uniformity. (x'1,x'2) = x \ (y1,y2) \ U\ + apply (auto intro!: exI[of _ UA] exI[of _ UB] simp add: eventually_prod_filter) + using \A\B \ U\ by (auto simp: UA_def UB_def) + then show \\\<^sub>F (x', y) in uniformity. x' = x \ y \ U\ + by (simp add: uniformity_prod_def eventually_filtermap case_prod_unfold) + next + assume asm: \\x\U. \\<^sub>F (x', y) in uniformity. x' = x \ y \ U\ + show \open U\ + proof (unfold open_prod_def, intro ballI) + fix x assume \x \ U\ + with asm have \\\<^sub>F (x', y) in uniformity. x' = x \ y \ U\ + by auto + then have \\\<^sub>F ((x'1, y1), (x'2, y2)) in uniformity \\<^sub>F uniformity. (x'1,x'2) = x \ (y1,y2) \ U\ + by (simp add: uniformity_prod_def eventually_filtermap case_prod_unfold) + then obtain UA UB where \eventually UA uniformity\ and \eventually UB uniformity\ + and UA_UB_U: \UA (a1, a2) \ UB (b1, b2) \ (a1, b1) = x \ (a2, b2) \ U\ for a1 a2 b1 b2 + apply atomize_elim by (simp add: case_prod_beta eventually_prod_filter) + have \eventually (\a. UA (fst x, a)) (nhds (fst x))\ + using \eventually UA uniformity\ eventually_mono eventually_nhds_uniformity by fastforce + then obtain A where \open A\ and A_UA: \A \ {a. UA (fst x, a)}\ and \fst x \ A\ + by (metis (mono_tags, lifting) eventually_nhds mem_Collect_eq subsetI) + have \eventually (\b. UB (snd x, b)) (nhds (snd x))\ + using \eventually UB uniformity\ eventually_mono eventually_nhds_uniformity by fastforce + then obtain B where \open B\ and B_UB: \B \ {b. UB (snd x, b)}\ and \snd x \ B\ + by (metis (mono_tags, lifting) eventually_nhds mem_Collect_eq subsetI) + have \x \ A \ B\ + by (simp add: \fst x \ A\ \snd x \ B\ mem_Times_iff) + have \A \ B \ U\ + using A_UA B_UB UA_UB_U by fastforce + show \\A B. open A \ open B \ x \ A \ B \ A \ B \ U\ + using \A \ B \ U\ \open A\ \open B\ \x \ A \ B\ by auto + qed + qed +next + show \eventually E uniformity \ E (x, x)\ for E and x :: \'a \ 'b\ + apply (simp add: uniformity_prod_def eventually_filtermap case_prod_unfold eventually_prod_filter) + by (metis surj_pair uniformity_refl) +next + show \eventually E uniformity \ \\<^sub>F (x::'a\'b, y) in uniformity. E (y, x)\ for E + apply (simp only: uniformity_prod_def eventually_filtermap case_prod_unfold eventually_prod_filter) + apply (erule exE, erule exE, rename_tac Pf Pg) + apply (rule_tac x=\\(x,y). Pf (y,x)\ in exI) + apply (rule_tac x=\\(x,y). Pg (y,x)\ in exI) + by (auto simp add: uniformity_sym) +next + show \\D. eventually D uniformity \ (\x y z. D (x::'a\'b, y) \ D (y, z) \ E (x, z))\ + if \eventually E uniformity\ for E + proof - + from that + obtain EA EB where \eventually EA uniformity\ and \eventually EB uniformity\ + and EA_EB_E: \EA (a1, a2) \ EB (b1, b2) \ E ((a1, b1), (a2, b2))\ for a1 a2 b1 b2 + by (auto simp add: uniformity_prod_def eventually_filtermap case_prod_unfold eventually_prod_filter) + obtain DA where \eventually DA uniformity\ and DA_EA: \DA (x,y) \ DA (y,z) \ EA (x,z)\ for x y z + using \eventually EA uniformity\ uniformity_transE by blast + obtain DB where \eventually DB uniformity\ and DB_EB: \DB (x,y) \ DB (y,z) \ EB (x,z)\ for x y z + using \eventually EB uniformity\ uniformity_transE by blast + define D where \D = (\((a1,b1),(a2,b2)). DA (a1,a2) \ DB (b1,b2))\ + have \eventually D uniformity\ + using \eventually DA uniformity\ \eventually DB uniformity\ + by (auto simp add: uniformity_prod_def eventually_filtermap case_prod_unfold eventually_prod_filter D_def) + moreover have \D ((a1, b1), (a2, b2)) \ D ((a2, b2), (a3, b3)) \ E ((a1, b1), (a3, b3))\ for a1 b1 a2 b2 a3 b3 + using DA_EA DB_EB D_def EA_EB_E by blast + ultimately show ?thesis + by auto + qed +qed +end +instantiation\<^marker>\tag unimportant\ prod :: (metric_space, metric_space) uniformity_dist begin instance - by standard (rule uniformity_prod_def) +proof + show \uniformity = (INF e\{0 <..}. principal {(x::'a\'b, y). dist x y < e})\ + proof (subst filter_eq_iff, intro allI iffI) + fix P :: \('a \ 'b) \ ('a \ 'b) \ bool\ + + have 1: \\e\{0<..}. + {(x,y). dist x y < e} \ {(x,y). dist x y < a} \ + {(x,y). dist x y < e} \ {(x,y). dist x y < b}\ if \a>0\ \b>0\ for a b + apply (rule bexI[of _ \min a b\]) + using that by auto + have 2: \mono (\P. eventually (\x. P (Q x)) F)\ for F :: \'z filter\ and Q :: \'z \ 'y\ + unfolding mono_def using eventually_mono le_funD by fastforce + have \\\<^sub>F ((x1::'a,y1),(x2::'b,y2)) in uniformity \\<^sub>F uniformity. dist x1 y1 < e/2 \ dist x2 y2 < e/2\ if \e>0\ for e + by (auto intro!: eventually_prodI exI[of _ \e/2\] simp: case_prod_unfold eventually_uniformity_metric that) + then have 3: \\\<^sub>F ((x1::'a,y1),(x2::'b,y2)) in uniformity \\<^sub>F uniformity. dist (x1,x2) (y1,y2) < e\ if \e>0\ for e + apply (rule eventually_rev_mp) + by (auto intro!: that eventuallyI simp: case_prod_unfold dist_prod_def sqrt_sum_squares_half_less) + show \eventually P (INF e\{0<..}. principal {(x, y). dist x y < e}) \ eventually P uniformity\ + apply (subst (asm) eventually_INF_base) + using 1 3 apply (auto simp: uniformity_prod_def case_prod_unfold eventually_filtermap 2 eventually_principal) + by (smt (verit, best) eventually_mono) + next + fix P :: \('a \ 'b) \ ('a \ 'b) \ bool\ + assume \eventually P uniformity\ + then obtain P1 P2 where \eventually P1 uniformity\ \eventually P2 uniformity\ + and P1P2P: \P1 (x1, y1) \ P2 (x2, y2) \ P ((x1, x2), (y1, y2))\ for x1 y1 x2 y2 + by (auto simp: eventually_filtermap case_prod_beta eventually_prod_filter uniformity_prod_def) + from \eventually P1 uniformity\ obtain e1 where \e1>0\ and e1P1: \dist x y < e1 \ P1 (x,y)\ for x y + using eventually_uniformity_metric by blast + from \eventually P2 uniformity\ obtain e2 where \e2>0\ and e2P2: \dist x y < e2 \ P2 (x,y)\ for x y + using eventually_uniformity_metric by blast + define e where \e = min e1 e2\ + have \e > 0\ + using \0 < e1\ \0 < e2\ e_def by auto + have \dist (x1,x2) (y1,y2) < e \ dist x1 y1 < e1\ for x1 y1 :: 'a and x2 y2 :: 'b + unfolding dist_prod_def e_def apply auto + by (smt (verit, best) real_sqrt_sum_squares_ge1) + moreover have \dist (x1,x2) (y1,y2) < e \ dist x2 y2 < e2\ for x1 y1 :: 'a and x2 y2 :: 'b + unfolding dist_prod_def e_def apply auto + by (smt (verit, best) real_sqrt_sum_squares_ge1) + ultimately have *: \dist (x1,x2) (y1,y2) < e \ P ((x1, x2), (y1, y2))\ for x1 y1 x2 y2 + using e1P1 e2P2 P1P2P by auto + + show \eventually P (INF e\{0<..}. principal {(x, y). dist x y < e})\ + apply (rule eventually_INF1[where i=e]) + using \e > 0\ * by (auto simp: eventually_principal) + qed +qed end declare uniformity_Abort[where 'a="'a :: metric_space \ 'b :: metric_space", code] @@ -221,24 +356,21 @@ ultimately show "\A B. open A \ open B \ x \ A \ B \ A \ B \ S" by fast qed qed - show "open S = (\x\S. \\<^sub>F (x', y) in uniformity. x' = x \ y \ S)" - unfolding * eventually_uniformity_metric - by (simp del: split_paired_All add: dist_prod_def dist_commute) qed end declare [[code abort: "dist::('a::metric_space*'b::metric_space)\('a*'b) \ real"]] -lemma Cauchy_fst: "Cauchy X \ Cauchy (\n. fst (X n))" +lemma Cauchy_fst: "Cauchy X \ Cauchy (\n. fst (X n :: 'a::metric_space \ 'b::metric_space))" unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_fst_le]) -lemma Cauchy_snd: "Cauchy X \ Cauchy (\n. snd (X n))" +lemma Cauchy_snd: "Cauchy X \ Cauchy (\n. snd (X n :: 'a::metric_space \ 'b::metric_space))" unfolding Cauchy_def by (fast elim: le_less_trans [OF dist_snd_le]) lemma Cauchy_Pair: assumes "Cauchy X" and "Cauchy Y" - shows "Cauchy (\n. (X n, Y n))" + shows "Cauchy (\n. (X n :: 'a::metric_space, Y n :: 'a::metric_space))" proof (rule metric_CauchyI) fix r :: real assume "0 < r" hence "0 < r / sqrt 2" (is "0 < ?s") by simp @@ -251,6 +383,56 @@ then show "\n0. \m\n0. \n\n0. dist (X m, Y m) (X n, Y n) < r" .. qed +text \Analogue to @{thm [source] uniformly_continuous_on_def} for two-argument functions.\ +lemma uniformly_continuous_on_prod_metric: + fixes f :: \('a::metric_space \ 'b::metric_space) \ 'c::metric_space\ + shows \uniformly_continuous_on (S\T) f \ (\e>0. \d>0. \x\S. \y\S. \x'\T. \y'\T. dist x y < d \ dist x' y' < d \ dist (f (x, x')) (f (y, y')) < e)\ +proof (unfold uniformly_continuous_on_def, intro iffI impI allI) + fix e :: real + assume \e > 0\ and \\e>0. \d>0. \x\S. \y\S. \x'\T. \y'\T. dist x y < d \ dist x' y' < d \ dist (f (x, x')) (f (y, y')) < e\ + then obtain d where \d > 0\ + and d: \\x\S. \y\S. \x'\T. \y'\T. dist x y < d \ dist x' y' < d \ dist (f (x, x')) (f (y, y')) < e\ + by auto + show \\d>0. \x\S\T. \y\S\T. dist y x < d \ dist (f y) (f x) < e\ + apply (rule exI[of _ d]) + using \d>0\ d[rule_format] apply auto + by (smt (verit, del_insts) dist_fst_le dist_snd_le fst_conv snd_conv) +next + fix e :: real + assume \e > 0\ and \\e>0. \d>0. \x\S\T. \x'\S\T. dist x' x < d \ dist (f x') (f x) < e\ + then obtain d where \d > 0\ and d: \\x\S\T. \x'\S\T. dist x' x < d \ dist (f x') (f x) < e\ + by auto + show \\d>0. \x\S. \y\S. \x'\T. \y'\T. dist x y < d \ dist x' y' < d \ dist (f (x, x')) (f (y, y')) < e\ + proof (intro exI conjI impI ballI) + from \d > 0\ show \d / 2 > 0\ by auto + fix x y x' y' + assume [simp]: \x \ S\ \y \ S\ \x' \ T\ \y' \ T\ + assume \dist x y < d / 2\ and \dist x' y' < d / 2\ + then have \dist (x, x') (y, y') < d\ + by (simp add: dist_Pair_Pair sqrt_sum_squares_half_less) + with d show \dist (f (x, x')) (f (y, y')) < e\ + by auto + qed +qed + +text \Analogue to @{thm [source] isUCont_def} for two-argument functions.\ +lemma isUCont_prod_metric: + fixes f :: \('a::metric_space \ 'b::metric_space) \ 'c::metric_space\ + shows \isUCont f \ (\e>0. \d>0. \x. \y. \x'. \y'. dist x y < d \ dist x' y' < d \ dist (f (x, x')) (f (y, y')) < e)\ + using uniformly_continuous_on_prod_metric[of UNIV UNIV] + by auto + +text \This logically belong with the real vector spaces by we only have the necessary lemmas now.\ +lemma isUCont_plus[simp]: + shows \isUCont (\(x::'a::real_normed_vector,y). x+y)\ +proof (rule isUCont_prod_metric[THEN iffD2], intro allI impI, simp) + fix e :: real assume \0 < e\ + show \\d>0. \x y :: 'a. dist x y < d \ (\x' y'. dist x' y' < d \ dist (x + x') (y + y') < e)\ + apply (rule exI[of _ \e/2\]) + using \0 < e\ apply auto + by (smt (verit, ccfv_SIG) dist_add_cancel dist_add_cancel2 dist_commute dist_triangle_lt) +qed + subsection \Product is a Complete Metric Space\ instance\<^marker>\tag important\ prod :: (complete_space, complete_space) complete_space diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Analysis/document/root.bib --- a/src/HOL/Analysis/document/root.bib Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Analysis/document/root.bib Thu Oct 07 16:28:17 2021 +0200 @@ -23,4 +23,12 @@ bibsource = {dblp computer science bibliography, https://dblp.org} } +@book{conway2013course, + title={A course in functional analysis}, + author={Conway, John B}, + volume={96}, + year={2013}, + publisher={Springer Science \& Business Media} +} + @misc{dummy} diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Complex_Analysis/Winding_Numbers.thy --- a/src/HOL/Complex_Analysis/Winding_Numbers.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Complex_Analysis/Winding_Numbers.thy Thu Oct 07 16:28:17 2021 +0200 @@ -529,7 +529,7 @@ fixes z::complex assumes \: "valid_path \" and z: "z \ path_image \" and 1: "Re (winding_number \ z) \ 1" and w: "w \ z" - shows "\a::real. 0 < a \ z + a*(w - z) \ path_image \" + shows "\a::real. 0 < a \ z + of_real a * (w - z) \ path_image \" proof - have [simp]: "\x. 0 \ x \ x \ 1 \ \ x \ z" using z by (auto simp: path_image_def) @@ -582,7 +582,7 @@ fixes z::complex assumes \: "valid_path \" and z: "z \ path_image \" and "\Re (winding_number \ z)\ \ 1" and w: "w \ z" - shows "\a::real. 0 < a \ z + a*(w - z) \ path_image \" + shows "\a::real. 0 < a \ z + of_real a * (w - z) \ path_image \" proof - { assume "Re (winding_number \ z) \ - 1" then have "Re (winding_number (reversepath \) z) \ 1" @@ -591,7 +591,7 @@ using \ valid_path_imp_reverse by auto moreover have "z \ path_image (reversepath \)" by (simp add: z) - ultimately have "\a::real. 0 < a \ z + a*(w - z) \ path_image (reversepath \)" + ultimately have "\a::real. 0 < a \ z + of_real a * (w - z) \ path_image (reversepath \)" using winding_number_pos_meets w by blast then have ?thesis by simp @@ -605,7 +605,7 @@ fixes z::complex shows "\valid_path \; z \ path_image \; w \ z; - \a::real. 0 < a \ z + a*(w - z) \ path_image \\ + \a::real. 0 < a \ z + of_real a * (w - z) \ path_image \\ \ Re(winding_number \ z) < 1" by (auto simp: not_less dest: winding_number_big_meets) @@ -1736,7 +1736,7 @@ ultimately have pa_subset_pm_kde: "path_image ?q \ closed_segment (a - kde) (a + kde) \ {a - kde, a + kde}" by (auto simp: path_image_join assms) - have ge_kde1: "\y. x = a + y \ y \ kde" if x: "x \ closed_segment (a + kde) (a + e)" for x + have ge_kde1: "\y. x = a + of_real y \ y \ kde" if x: "x \ closed_segment (a + kde) (a + e)" for x proof - obtain u where "0 \ u" "u \ 1" and u: "x = (1 - u) *\<^sub>R (a + kde) + u *\<^sub>R (a + e)" using x by (auto simp: in_segment) @@ -1747,7 +1747,7 @@ ultimately show ?thesis by blast qed - have ge_kde2: "\y. x = a + y \ y \ -kde" if x: "x \ closed_segment (a - d) (a - kde)" for x + have ge_kde2: "\y. x = a + of_real y \ y \ -kde" if x: "x \ closed_segment (a - d) (a - kde)" for x proof - obtain u where "0 \ u" "u \ 1" and u: "x = (1 - u) *\<^sub>R (a - d) + u *\<^sub>R (a - kde)" using x by (auto simp: in_segment) diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Library/Complex_Order.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Library/Complex_Order.thy Thu Oct 07 16:28:17 2021 +0200 @@ -0,0 +1,39 @@ +(* + Title: HOL/Library/Complex_Order.thy + Author: Dominique Unruh, University of Tartu + + Instantiation of complex numbers as an ordered set. +*) + +theory Complex_Order + imports Complex_Main +begin + +instantiation complex :: order begin + +definition \x < y \ Re x < Re y \ Im x = Im y\ +definition \x \ y \ Re x \ Re y \ Im x = Im y\ + +instance + apply standard + by (auto simp: less_complex_def less_eq_complex_def complex_eq_iff) +end + +lemma nonnegative_complex_is_real: \(x::complex) \ 0 \ x \ \\ + by (simp add: complex_is_Real_iff less_eq_complex_def) + +lemma complex_is_real_iff_compare0: \(x::complex) \ \ \ x \ 0 \ x \ 0\ + using complex_is_Real_iff less_eq_complex_def by auto + +instance complex :: ordered_comm_ring + apply standard + by (auto simp: less_complex_def less_eq_complex_def complex_eq_iff mult_left_mono mult_right_mono) + +instance complex :: ordered_real_vector + apply standard + by (auto simp: less_complex_def less_eq_complex_def mult_left_mono mult_right_mono) + +instance complex :: ordered_cancel_comm_semiring + by standard + +end diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Library/Extended_Nonnegative_Real.thy --- a/src/HOL/Library/Extended_Nonnegative_Real.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Library/Extended_Nonnegative_Real.thy Thu Oct 07 16:28:17 2021 +0200 @@ -1173,6 +1173,17 @@ lemma ennreal_of_enat_eSuc[simp]: "ennreal_of_enat (eSuc x) = 1 + ennreal_of_enat x" by (cases x) (auto simp: eSuc_enat) +(* Contributed by Dominique Unruh *) +lemma ennreal_of_enat_plus[simp]: \ennreal_of_enat (a+b) = ennreal_of_enat a + ennreal_of_enat b\ + apply (induction a) + apply auto + by (smt (z3) add.commute add.right_neutral enat.exhaust enat.simps(4) enat.simps(5) ennreal_add_left_cancel ennreal_of_enat_def infinity_ennreal_def of_nat_add of_nat_eq_enat plus_enat_simps(2)) + +(* Contributed by Dominique Unruh *) +lemma sum_ennreal_of_enat[simp]: "(\i\I. ennreal_of_enat (f i)) = ennreal_of_enat (sum f I)" + apply (induction I rule: infinite_finite_induct) + by (auto simp: sum_nonneg) + subsection \Topology on \<^typ>\ennreal\\ lemma enn2ereal_Iio: "enn2ereal -` {.. a then {..< e2ennreal a} else {})" @@ -1657,6 +1668,60 @@ apply (auto simp del: sup_ereal_def simp add: sup_INF) done +(* Contributed by Dominique Unruh *) +lemma isCont_ennreal[simp]: \isCont ennreal x\ + apply (auto intro!: sequentially_imp_eventually_within simp: continuous_within tendsto_def) + by (metis tendsto_def tendsto_ennrealI) + +(* Contributed by Dominique Unruh *) +lemma isCont_ennreal_of_enat[simp]: \isCont ennreal_of_enat x\ +proof - + have continuous_at_open: + \ \Copied lemma from \<^session>\HOL-Analysis\ to avoid dependency.\ + "continuous (at x) f \ (\t. open t \ f x \ t --> (\s. open s \ x \ s \ (\x' \ s. (f x') \ t)))" for f :: \enat \ 'z::topological_space\ + unfolding continuous_within_topological [of x UNIV f] + unfolding imp_conjL + by (intro all_cong imp_cong ex_cong conj_cong refl) auto + show ?thesis + proof (subst continuous_at_open, intro allI impI, cases \x = \\) + case True + + fix t assume \open t \ ennreal_of_enat x \ t\ + then have \\y<\. {y <.. \} \ t\ + apply (rule_tac open_left[where y=0]) + by (auto simp: True) + then obtain y where \{y<..} \ t\ and \y \ \\ + apply atomize_elim + apply (auto simp: greaterThanAtMost_def) + by (metis atMost_iff inf.orderE subsetI top.not_eq_extremum top_greatest) + + from \y \ \\ + obtain x' where x'y: \ennreal_of_enat x' > y\ and \x' \ \\ + by (metis enat.simps(3) ennreal_Ex_less_of_nat ennreal_of_enat_enat infinity_ennreal_def top.not_eq_extremum) + define s where \s = {x'<..}\ + have \open s\ + by (simp add: s_def) + moreover have \x \ s\ + by (simp add: \x' \ \\ s_def True) + moreover have \ennreal_of_enat z \ t\ if \z \ s\ for z + by (metis x'y \{y<..} \ t\ ennreal_of_enat_le_iff greaterThan_iff le_less_trans less_imp_le not_less s_def subsetD that) + ultimately show \\s. open s \ x \ s \ (\z\s. ennreal_of_enat z \ t)\ + by auto + next + case False + fix t assume asm: \open t \ ennreal_of_enat x \ t\ + define s where \s = {x}\ + have \open s\ + using False open_enat_iff s_def by blast + moreover have \x \ s\ + using s_def by auto + moreover have \ennreal_of_enat z \ t\ if \z \ s\ for z + using asm s_def that by blast + ultimately show \\s. open s \ x \ s \ (\z\s. ennreal_of_enat z \ t)\ + by auto + qed +qed + subsection \Approximation lemmas\ lemma INF_approx_ennreal: diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Limits.thy --- a/src/HOL/Limits.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Limits.thy Thu Oct 07 16:28:17 2021 +0200 @@ -1000,7 +1000,7 @@ unfolding tendsto_iff by simp lemma tendsto_add_const_iff: - "((\x. c + f x :: 'a::real_normed_vector) \ c + d) F \ (f \ d) F" + "((\x. c + f x :: 'a::topological_group_add) \ c + d) F \ (f \ d) F" using tendsto_add[OF tendsto_const[of c], of f d] and tendsto_add[OF tendsto_const[of "-c"], of "\x. c + f x" "c + d"] by auto diff -r 6424c54157d9 -r fd5f62176987 src/HOL/ROOT --- a/src/HOL/ROOT Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/ROOT Thu Oct 07 16:28:17 2021 +0200 @@ -76,6 +76,7 @@ Code_Real_Approx_By_Float Code_Target_Numeral Code_Target_Numeral_Float + Complex_Order DAList DAList_Multiset RBT_Mapping diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Real_Vector_Spaces.thy --- a/src/HOL/Real_Vector_Spaces.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Real_Vector_Spaces.thy Thu Oct 07 16:28:17 2021 +0200 @@ -1781,6 +1781,38 @@ by auto qed (auto intro!: exI[of _ "{y. dist x y < e}" for e] open_ball simp: dist_commute) +(* Contributed by Dominique Unruh *) +lemma tendsto_iff_uniformity: + \ \More general analogus of \tendsto_iff\ below. Applies to all uniform spaces, not just metric ones.\ + fixes l :: \'b :: uniform_space\ + shows \(f \ l) F \ (\E. eventually E uniformity \ (\\<^sub>F x in F. E (f x, l)))\ +proof (intro iffI allI impI) + fix E :: \('b \ 'b) \ bool\ + assume \(f \ l) F\ and \eventually E uniformity\ + from \eventually E uniformity\ + have \eventually (\(x, y). E (y, x)) uniformity\ + by (simp add: uniformity_sym) + then have \\\<^sub>F (y, x) in uniformity. y = l \ E (x, y)\ + using eventually_mono by fastforce + with \(f \ l) F\ have \eventually (\x. E (x ,l)) (filtermap f F)\ + by (simp add: filterlim_def le_filter_def eventually_nhds_uniformity) + then show \\\<^sub>F x in F. E (f x, l)\ + by (simp add: eventually_filtermap) +next + assume assm: \\E. eventually E uniformity \ (\\<^sub>F x in F. E (f x, l))\ + have \eventually P (filtermap f F)\ if \\\<^sub>F (x, y) in uniformity. x = l \ P y\ for P + proof - + from that have \\\<^sub>F (y, x) in uniformity. x = l \ P y\ + using uniformity_sym[where E=\\(x,y). x=l \ P y\] by auto + with assm have \\\<^sub>F x in F. P (f x)\ + by auto + then show ?thesis + by (auto simp: eventually_filtermap) + qed + then show \(f \ l) F\ + by (simp add: filterlim_def le_filter_def eventually_nhds_uniformity) +qed + lemma (in metric_space) tendsto_iff: "(f \ l) F \ (\e>0. eventually (\x. dist (f x) l < e) F)" unfolding nhds_metric filterlim_INF filterlim_principal by auto @@ -2186,6 +2218,52 @@ done +setup \Sign.add_const_constraint (\<^const_name>\dist\, SOME \<^typ>\'a::dist \ 'a \ real\)\ + +(* Contributed by Dominique Unruh *) +lemma cauchy_filter_metric: + fixes F :: "'a::{uniformity_dist,uniform_space} filter" + shows "cauchy_filter F \ (\e. e>0 \ (\P. eventually P F \ (\x y. P x \ P y \ dist x y < e)))" +proof (unfold cauchy_filter_def le_filter_def, auto) + assume assm: \\e>0. \P. eventually P F \ (\x y. P x \ P y \ dist x y < e)\ + then show \eventually P uniformity \ eventually P (F \\<^sub>F F)\ for P + apply (auto simp: eventually_uniformity_metric) + using eventually_prod_same by blast +next + fix e :: real + assume \e > 0\ + assume asm: \\P. eventually P uniformity \ eventually P (F \\<^sub>F F)\ + + define P where \P \ \(x,y :: 'a). dist x y < e\ + with asm \e > 0\ have \eventually P (F \\<^sub>F F)\ + by (metis case_prod_conv eventually_uniformity_metric) + then + show \\P. eventually P F \ (\x y. P x \ P y \ dist x y < e)\ + by (auto simp add: eventually_prod_same P_def) +qed + +(* Contributed by Dominique Unruh *) +lemma cauchy_filter_metric_filtermap: + fixes f :: "'a \ 'b::{uniformity_dist,uniform_space}" + shows "cauchy_filter (filtermap f F) \ (\e. e>0 \ (\P. eventually P F \ (\x y. P x \ P y \ dist (f x) (f y) < e)))" +proof (subst cauchy_filter_metric, intro iffI allI impI) + assume \\e>0. \P. eventually P (filtermap f F) \ (\x y. P x \ P y \ dist x y < e)\ + then show \e>0 \ \P. eventually P F \ (\x y. P x \ P y \ dist (f x) (f y) < e)\ for e + unfolding eventually_filtermap by blast +next + assume asm: \\e>0. \P. eventually P F \ (\x y. P x \ P y \ dist (f x) (f y) < e)\ + fix e::real assume \e > 0\ + then obtain P where \eventually P F\ and PPe: \P x \ P y \ dist (f x) (f y) < e\ for x y + using asm by blast + + show \\P. eventually P (filtermap f F) \ (\x y. P x \ P y \ dist x y < e)\ + apply (rule exI[of _ \\x. \y. P y \ x = f y\]) + using PPe \eventually P F\ apply (auto simp: eventually_filtermap) + by (smt (verit, ccfv_SIG) eventually_elim2) +qed + +setup \Sign.add_const_constraint (\<^const_name>\dist\, SOME \<^typ>\'a::metric_space \ 'a \ real\)\ + subsubsection \Cauchy Sequences are Convergent\ (* TODO: update to uniform_space *) diff -r 6424c54157d9 -r fd5f62176987 src/HOL/Topological_Spaces.thy --- a/src/HOL/Topological_Spaces.thy Thu Oct 07 10:16:52 2021 +0200 +++ b/src/HOL/Topological_Spaces.thy Thu Oct 07 16:28:17 2021 +0200 @@ -788,6 +788,11 @@ lemma tendsto_eventually: "eventually (\x. f x = l) net \ ((\x. f x) \ l) net" by (rule topological_tendstoI) (auto elim: eventually_mono) +(* Contributed by Dominique Unruh *) +lemma tendsto_principal_singleton[simp]: + shows "(f \ f x) (principal {x})" + unfolding tendsto_def eventually_principal by simp + end lemma (in topological_space) filterlim_within_subset: @@ -3438,7 +3443,6 @@ end - subsubsection \Uniformly continuous functions\ definition uniformly_continuous_on :: "'a set \ ('a::uniform_space \ 'b::uniform_space) \ bool"