src/HOL/Series.thy
 author haftmann Fri Sep 13 07:59:50 2013 +0200 (2013-09-13) changeset 53602 0ae3db699a3e parent 51528 66c3a7589de7 child 54230 b1d955791529 permissions -rw-r--r--
tuned proofs
```     1 (*  Title       : Series.thy
```
```     2     Author      : Jacques D. Fleuriot
```
```     3     Copyright   : 1998  University of Cambridge
```
```     4
```
```     5 Converted to Isar and polished by lcp
```
```     6 Converted to setsum and polished yet more by TNN
```
```     7 Additional contributions by Jeremy Avigad
```
```     8 *)
```
```     9
```
```    10 header{*Finite Summation and Infinite Series*}
```
```    11
```
```    12 theory Series
```
```    13 imports Limits
```
```    14 begin
```
```    15
```
```    16 definition
```
```    17    sums  :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a \<Rightarrow> bool"
```
```    18      (infixr "sums" 80) where
```
```    19    "f sums s = (%n. setsum f {0..<n}) ----> s"
```
```    20
```
```    21 definition
```
```    22    summable :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> bool" where
```
```    23    "summable f = (\<exists>s. f sums s)"
```
```    24
```
```    25 definition
```
```    26    suminf   :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a" where
```
```    27    "suminf f = (THE s. f sums s)"
```
```    28
```
```    29 notation suminf (binder "\<Sum>" 10)
```
```    30
```
```    31
```
```    32 lemma [trans]: "f=g ==> g sums z ==> f sums z"
```
```    33   by simp
```
```    34
```
```    35 lemma sumr_diff_mult_const:
```
```    36  "setsum f {0..<n} - (real n*r) = setsum (%i. f i - r) {0..<n::nat}"
```
```    37 by (simp add: diff_minus setsum_addf real_of_nat_def)
```
```    38
```
```    39 lemma real_setsum_nat_ivl_bounded:
```
```    40      "(!!p. p < n \<Longrightarrow> f(p) \<le> K)
```
```    41       \<Longrightarrow> setsum f {0..<n::nat} \<le> real n * K"
```
```    42 using setsum_bounded[where A = "{0..<n}"]
```
```    43 by (auto simp:real_of_nat_def)
```
```    44
```
```    45 (* Generalize from real to some algebraic structure? *)
```
```    46 lemma sumr_minus_one_realpow_zero [simp]:
```
```    47   "(\<Sum>i=0..<2*n. (-1) ^ Suc i) = (0::real)"
```
```    48 by (induct "n", auto)
```
```    49
```
```    50 (* FIXME this is an awful lemma! *)
```
```    51 lemma sumr_one_lb_realpow_zero [simp]:
```
```    52   "(\<Sum>n=Suc 0..<n. f(n) * (0::real) ^ n) = 0"
```
```    53 by (rule setsum_0', simp)
```
```    54
```
```    55 lemma sumr_group:
```
```    56      "(\<Sum>m=0..<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {0 ..< n * k}"
```
```    57 apply (subgoal_tac "k = 0 | 0 < k", auto)
```
```    58 apply (induct "n")
```
```    59 apply (simp_all add: setsum_add_nat_ivl add_commute)
```
```    60 done
```
```    61
```
```    62 lemma sumr_offset3:
```
```    63   "setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)) + setsum f {0..<k}"
```
```    64 apply (subst setsum_shift_bounds_nat_ivl [symmetric])
```
```    65 apply (simp add: setsum_add_nat_ivl add_commute)
```
```    66 done
```
```    67
```
```    68 lemma sumr_offset:
```
```    69   fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
```
```    70   shows "(\<Sum>m=0..<n. f(m+k)) = setsum f {0..<n+k} - setsum f {0..<k}"
```
```    71 by (simp add: sumr_offset3)
```
```    72
```
```    73 lemma sumr_offset2:
```
```    74  "\<forall>f. (\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
```
```    75 by (simp add: sumr_offset)
```
```    76
```
```    77 lemma sumr_offset4:
```
```    78   "\<forall>n f. setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
```
```    79 by (clarify, rule sumr_offset3)
```
```    80
```
```    81 subsection{* Infinite Sums, by the Properties of Limits*}
```
```    82
```
```    83 (*----------------------
```
```    84    suminf is the sum
```
```    85  ---------------------*)
```
```    86 lemma sums_summable: "f sums l ==> summable f"
```
```    87   by (simp add: sums_def summable_def, blast)
```
```    88
```
```    89 lemma summable_sums:
```
```    90   fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
```
```    91   assumes "summable f"
```
```    92   shows "f sums (suminf f)"
```
```    93 proof -
```
```    94   from assms obtain s where s: "(\<lambda>n. setsum f {0..<n}) ----> s"
```
```    95     unfolding summable_def sums_def [abs_def] ..
```
```    96   then show ?thesis unfolding sums_def [abs_def] suminf_def
```
```    97     by (rule theI, auto intro!: tendsto_unique[OF trivial_limit_sequentially])
```
```    98 qed
```
```    99
```
```   100 lemma summable_sumr_LIMSEQ_suminf:
```
```   101   fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
```
```   102   shows "summable f \<Longrightarrow> (\<lambda>n. setsum f {0..<n}) ----> suminf f"
```
```   103 by (rule summable_sums [unfolded sums_def])
```
```   104
```
```   105 lemma suminf_eq_lim: "suminf f = lim (%n. setsum f {0..<n})"
```
```   106   by (simp add: suminf_def sums_def lim_def)
```
```   107
```
```   108 (*-------------------
```
```   109     sum is unique
```
```   110  ------------------*)
```
```   111 lemma sums_unique:
```
```   112   fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
```
```   113   shows "f sums s \<Longrightarrow> (s = suminf f)"
```
```   114 apply (frule sums_summable[THEN summable_sums])
```
```   115 apply (auto intro!: tendsto_unique[OF trivial_limit_sequentially] simp add: sums_def)
```
```   116 done
```
```   117
```
```   118 lemma sums_iff:
```
```   119   fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
```
```   120   shows "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
```
```   121   by (metis summable_sums sums_summable sums_unique)
```
```   122
```
```   123 lemma sums_finite:
```
```   124   assumes [simp]: "finite N"
```
```   125   assumes f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
```
```   126   shows "f sums (\<Sum>n\<in>N. f n)"
```
```   127 proof -
```
```   128   { fix n
```
```   129     have "setsum f {..<n + Suc (Max N)} = setsum f N"
```
```   130     proof cases
```
```   131       assume "N = {}"
```
```   132       with f have "f = (\<lambda>x. 0)" by auto
```
```   133       then show ?thesis by simp
```
```   134     next
```
```   135       assume [simp]: "N \<noteq> {}"
```
```   136       show ?thesis
```
```   137       proof (safe intro!: setsum_mono_zero_right f)
```
```   138         fix i assume "i \<in> N"
```
```   139         then have "i \<le> Max N" by simp
```
```   140         then show "i < n + Suc (Max N)" by simp
```
```   141       qed
```
```   142     qed }
```
```   143   note eq = this
```
```   144   show ?thesis unfolding sums_def
```
```   145     by (rule LIMSEQ_offset[of _ "Suc (Max N)"])
```
```   146        (simp add: eq atLeast0LessThan tendsto_const del: add_Suc_right)
```
```   147 qed
```
```   148
```
```   149 lemma suminf_finite:
```
```   150   fixes f :: "nat \<Rightarrow> 'a::{comm_monoid_add,t2_space}"
```
```   151   assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
```
```   152   shows "suminf f = (\<Sum>n\<in>N. f n)"
```
```   153   using sums_finite[OF assms, THEN sums_unique] by simp
```
```   154
```
```   155 lemma sums_If_finite_set:
```
```   156   "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 0 :: 'a::{comm_monoid_add,t2_space}) sums (\<Sum>r\<in>A. f r)"
```
```   157   using sums_finite[of A "(\<lambda>r. if r \<in> A then f r else 0)"] by simp
```
```   158
```
```   159 lemma sums_If_finite:
```
```   160   "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 0 :: 'a::{comm_monoid_add,t2_space}) sums (\<Sum>r | P r. f r)"
```
```   161   using sums_If_finite_set[of "{r. P r}" f] by simp
```
```   162
```
```   163 lemma sums_single:
```
```   164   "(\<lambda>r. if r = i then f r else 0::'a::{comm_monoid_add,t2_space}) sums f i"
```
```   165   using sums_If_finite[of "\<lambda>r. r = i" f] by simp
```
```   166
```
```   167 lemma sums_split_initial_segment:
```
```   168   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
```
```   169   shows "f sums s ==> (\<lambda>n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
```
```   170   apply (unfold sums_def)
```
```   171   apply (simp add: sumr_offset)
```
```   172   apply (rule tendsto_diff [OF _ tendsto_const])
```
```   173   apply (rule LIMSEQ_ignore_initial_segment)
```
```   174   apply assumption
```
```   175 done
```
```   176
```
```   177 lemma summable_ignore_initial_segment:
```
```   178   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
```
```   179   shows "summable f ==> summable (%n. f(n + k))"
```
```   180   apply (unfold summable_def)
```
```   181   apply (auto intro: sums_split_initial_segment)
```
```   182 done
```
```   183
```
```   184 lemma suminf_minus_initial_segment:
```
```   185   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
```
```   186   shows "summable f ==>
```
```   187     suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
```
```   188   apply (frule summable_ignore_initial_segment)
```
```   189   apply (rule sums_unique [THEN sym])
```
```   190   apply (frule summable_sums)
```
```   191   apply (rule sums_split_initial_segment)
```
```   192   apply auto
```
```   193 done
```
```   194
```
```   195 lemma suminf_split_initial_segment:
```
```   196   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
```
```   197   shows "summable f ==>
```
```   198     suminf f = (SUM i = 0..< k. f i) + (\<Sum>n. f(n + k))"
```
```   199 by (auto simp add: suminf_minus_initial_segment)
```
```   200
```
```   201 lemma suminf_exist_split: fixes r :: real assumes "0 < r" and "summable a"
```
```   202   shows "\<exists> N. \<forall> n \<ge> N. \<bar> \<Sum> i. a (i + n) \<bar> < r"
```
```   203 proof -
```
```   204   from LIMSEQ_D[OF summable_sumr_LIMSEQ_suminf[OF `summable a`] `0 < r`]
```
```   205   obtain N :: nat where "\<forall> n \<ge> N. norm (setsum a {0..<n} - suminf a) < r" by auto
```
```   206   thus ?thesis unfolding suminf_minus_initial_segment[OF `summable a` refl] abs_minus_commute real_norm_def
```
```   207     by auto
```
```   208 qed
```
```   209
```
```   210 lemma sums_Suc:
```
```   211   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
```
```   212   assumes sumSuc: "(\<lambda> n. f (Suc n)) sums l" shows "f sums (l + f 0)"
```
```   213 proof -
```
```   214   from sumSuc[unfolded sums_def]
```
```   215   have "(\<lambda>i. \<Sum>n = Suc 0..<Suc i. f n) ----> l" unfolding setsum_reindex[OF inj_Suc] image_Suc_atLeastLessThan[symmetric] comp_def .
```
```   216   from tendsto_add[OF this tendsto_const, where b="f 0"]
```
```   217   have "(\<lambda>i. \<Sum>n = 0..<Suc i. f n) ----> l + f 0" unfolding add_commute setsum_head_upt_Suc[OF zero_less_Suc] .
```
```   218   thus ?thesis unfolding sums_def by (rule LIMSEQ_imp_Suc)
```
```   219 qed
```
```   220
```
```   221 lemma series_zero:
```
```   222   fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
```
```   223   assumes "\<forall>m. n \<le> m \<longrightarrow> f m = 0"
```
```   224   shows "f sums (setsum f {0..<n})"
```
```   225 proof -
```
```   226   { fix k :: nat have "setsum f {0..<k + n} = setsum f {0..<n}"
```
```   227       using assms by (induct k) auto }
```
```   228   note setsum_const = this
```
```   229   show ?thesis
```
```   230     unfolding sums_def
```
```   231     apply (rule LIMSEQ_offset[of _ n])
```
```   232     unfolding setsum_const
```
```   233     apply (rule tendsto_const)
```
```   234     done
```
```   235 qed
```
```   236
```
```   237 lemma sums_zero[simp, intro]: "(\<lambda>n. 0) sums 0"
```
```   238   unfolding sums_def by (simp add: tendsto_const)
```
```   239
```
```   240 lemma summable_zero[simp, intro]: "summable (\<lambda>n. 0)"
```
```   241 by (rule sums_zero [THEN sums_summable])
```
```   242
```
```   243 lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
```
```   244 by (rule sums_zero [THEN sums_unique, symmetric])
```
```   245
```
```   246 lemma (in bounded_linear) sums:
```
```   247   "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
```
```   248   unfolding sums_def by (drule tendsto, simp only: setsum)
```
```   249
```
```   250 lemma (in bounded_linear) summable:
```
```   251   "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
```
```   252 unfolding summable_def by (auto intro: sums)
```
```   253
```
```   254 lemma (in bounded_linear) suminf:
```
```   255   "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
```
```   256 by (intro sums_unique sums summable_sums)
```
```   257
```
```   258 lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
```
```   259 lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
```
```   260 lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
```
```   261
```
```   262 lemma sums_mult:
```
```   263   fixes c :: "'a::real_normed_algebra"
```
```   264   shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
```
```   265   by (rule bounded_linear.sums [OF bounded_linear_mult_right])
```
```   266
```
```   267 lemma summable_mult:
```
```   268   fixes c :: "'a::real_normed_algebra"
```
```   269   shows "summable f \<Longrightarrow> summable (%n. c * f n)"
```
```   270   by (rule bounded_linear.summable [OF bounded_linear_mult_right])
```
```   271
```
```   272 lemma suminf_mult:
```
```   273   fixes c :: "'a::real_normed_algebra"
```
```   274   shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
```
```   275   by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
```
```   276
```
```   277 lemma sums_mult2:
```
```   278   fixes c :: "'a::real_normed_algebra"
```
```   279   shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
```
```   280   by (rule bounded_linear.sums [OF bounded_linear_mult_left])
```
```   281
```
```   282 lemma summable_mult2:
```
```   283   fixes c :: "'a::real_normed_algebra"
```
```   284   shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
```
```   285   by (rule bounded_linear.summable [OF bounded_linear_mult_left])
```
```   286
```
```   287 lemma suminf_mult2:
```
```   288   fixes c :: "'a::real_normed_algebra"
```
```   289   shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
```
```   290   by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
```
```   291
```
```   292 lemma sums_divide:
```
```   293   fixes c :: "'a::real_normed_field"
```
```   294   shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
```
```   295   by (rule bounded_linear.sums [OF bounded_linear_divide])
```
```   296
```
```   297 lemma summable_divide:
```
```   298   fixes c :: "'a::real_normed_field"
```
```   299   shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
```
```   300   by (rule bounded_linear.summable [OF bounded_linear_divide])
```
```   301
```
```   302 lemma suminf_divide:
```
```   303   fixes c :: "'a::real_normed_field"
```
```   304   shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
```
```   305   by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
```
```   306
```
```   307 lemma sums_add:
```
```   308   fixes a b :: "'a::real_normed_field"
```
```   309   shows "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) sums (a + b)"
```
```   310   unfolding sums_def by (simp add: setsum_addf tendsto_add)
```
```   311
```
```   312 lemma summable_add:
```
```   313   fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   314   shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n + Y n)"
```
```   315 unfolding summable_def by (auto intro: sums_add)
```
```   316
```
```   317 lemma suminf_add:
```
```   318   fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   319   shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X + suminf Y = (\<Sum>n. X n + Y n)"
```
```   320 by (intro sums_unique sums_add summable_sums)
```
```   321
```
```   322 lemma sums_diff:
```
```   323   fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   324   shows "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) sums (a - b)"
```
```   325   unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
```
```   326
```
```   327 lemma summable_diff:
```
```   328   fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   329   shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n - Y n)"
```
```   330 unfolding summable_def by (auto intro: sums_diff)
```
```   331
```
```   332 lemma suminf_diff:
```
```   333   fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   334   shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X - suminf Y = (\<Sum>n. X n - Y n)"
```
```   335 by (intro sums_unique sums_diff summable_sums)
```
```   336
```
```   337 lemma sums_minus:
```
```   338   fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   339   shows "X sums a ==> (\<lambda>n. - X n) sums (- a)"
```
```   340   unfolding sums_def by (simp add: setsum_negf tendsto_minus)
```
```   341
```
```   342 lemma summable_minus:
```
```   343   fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   344   shows "summable X \<Longrightarrow> summable (\<lambda>n. - X n)"
```
```   345 unfolding summable_def by (auto intro: sums_minus)
```
```   346
```
```   347 lemma suminf_minus:
```
```   348   fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   349   shows "summable X \<Longrightarrow> (\<Sum>n. - X n) = - (\<Sum>n. X n)"
```
```   350 by (intro sums_unique [symmetric] sums_minus summable_sums)
```
```   351
```
```   352 lemma sums_group:
```
```   353   fixes f :: "nat \<Rightarrow> 'a::real_normed_field"
```
```   354   shows "\<lbrakk>f sums s; 0 < k\<rbrakk> \<Longrightarrow> (\<lambda>n. setsum f {n*k..<n*k+k}) sums s"
```
```   355 apply (simp only: sums_def sumr_group)
```
```   356 apply (unfold LIMSEQ_iff, safe)
```
```   357 apply (drule_tac x="r" in spec, safe)
```
```   358 apply (rule_tac x="no" in exI, safe)
```
```   359 apply (drule_tac x="n*k" in spec)
```
```   360 apply (erule mp)
```
```   361 apply (erule order_trans)
```
```   362 apply simp
```
```   363 done
```
```   364
```
```   365 text{*A summable series of positive terms has limit that is at least as
```
```   366 great as any partial sum.*}
```
```   367
```
```   368 lemma pos_summable:
```
```   369   fixes f:: "nat \<Rightarrow> real"
```
```   370   assumes pos: "\<And>n. 0 \<le> f n" and le: "\<And>n. setsum f {0..<n} \<le> x"
```
```   371   shows "summable f"
```
```   372 proof -
```
```   373   have "convergent (\<lambda>n. setsum f {0..<n})"
```
```   374     proof (rule Bseq_mono_convergent)
```
```   375       show "Bseq (\<lambda>n. setsum f {0..<n})"
```
```   376         by (intro BseqI'[of _ x]) (auto simp add: setsum_nonneg pos intro: le)
```
```   377     next
```
```   378       show "\<forall>m n. m \<le> n \<longrightarrow> setsum f {0..<m} \<le> setsum f {0..<n}"
```
```   379         by (auto intro: setsum_mono2 pos)
```
```   380     qed
```
```   381   thus ?thesis
```
```   382     by (force simp add: summable_def sums_def convergent_def)
```
```   383 qed
```
```   384
```
```   385 lemma series_pos_le:
```
```   386   fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
```
```   387   shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
```
```   388   apply (drule summable_sums)
```
```   389   apply (simp add: sums_def)
```
```   390   apply (rule LIMSEQ_le_const)
```
```   391   apply assumption
```
```   392   apply (intro exI[of _ n])
```
```   393   apply (auto intro!: setsum_mono2)
```
```   394   done
```
```   395
```
```   396 lemma series_pos_less:
```
```   397   fixes f :: "nat \<Rightarrow> 'a::{ordered_ab_semigroup_add_imp_le, ordered_comm_monoid_add, linorder_topology}"
```
```   398   shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
```
```   399   apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
```
```   400   using add_less_cancel_left [of "setsum f {0..<n}" 0 "f n"]
```
```   401   apply simp
```
```   402   apply (erule series_pos_le)
```
```   403   apply (simp add: order_less_imp_le)
```
```   404   done
```
```   405
```
```   406 lemma suminf_eq_zero_iff:
```
```   407   fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
```
```   408   shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> suminf f = 0 \<longleftrightarrow> (\<forall>n. f n = 0)"
```
```   409 proof
```
```   410   assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
```
```   411   then have "f sums 0"
```
```   412     by (simp add: sums_iff)
```
```   413   then have f: "(\<lambda>n. \<Sum>i<n. f i) ----> 0"
```
```   414     by (simp add: sums_def atLeast0LessThan)
```
```   415   have "\<And>i. (\<Sum>n\<in>{i}. f n) \<le> 0"
```
```   416   proof (rule LIMSEQ_le_const[OF f])
```
```   417     fix i show "\<exists>N. \<forall>n\<ge>N. (\<Sum>n\<in>{i}. f n) \<le> setsum f {..<n}"
```
```   418       using pos by (intro exI[of _ "Suc i"] allI impI setsum_mono2) auto
```
```   419   qed
```
```   420   with pos show "\<forall>n. f n = 0"
```
```   421     by (auto intro!: antisym)
```
```   422 next
```
```   423   assume "\<forall>n. f n = 0"
```
```   424   then have "f = (\<lambda>n. 0)"
```
```   425     by auto
```
```   426   then show "suminf f = 0"
```
```   427     by simp
```
```   428 qed
```
```   429
```
```   430 lemma suminf_gt_zero_iff:
```
```   431   fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
```
```   432   shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
```
```   433   using series_pos_le[of f 0] suminf_eq_zero_iff[of f]
```
```   434   by (simp add: less_le)
```
```   435
```
```   436 lemma suminf_gt_zero:
```
```   437   fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
```
```   438   shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
```
```   439   using suminf_gt_zero_iff[of f] by (simp add: less_imp_le)
```
```   440
```
```   441 lemma suminf_ge_zero:
```
```   442   fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
```
```   443   shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
```
```   444   by (drule_tac n="0" in series_pos_le, simp_all)
```
```   445
```
```   446 lemma sumr_pos_lt_pair:
```
```   447   fixes f :: "nat \<Rightarrow> real"
```
```   448   shows "\<lbrakk>summable f;
```
```   449         \<And>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
```
```   450       \<Longrightarrow> setsum f {0..<k} < suminf f"
```
```   451 unfolding One_nat_def
```
```   452 apply (subst suminf_split_initial_segment [where k="k"])
```
```   453 apply assumption
```
```   454 apply simp
```
```   455 apply (drule_tac k="k" in summable_ignore_initial_segment)
```
```   456 apply (drule_tac k="Suc (Suc 0)" in sums_group [OF summable_sums], simp)
```
```   457 apply simp
```
```   458 apply (frule sums_unique)
```
```   459 apply (drule sums_summable)
```
```   460 apply simp
```
```   461 apply (erule suminf_gt_zero)
```
```   462 apply (simp add: add_ac)
```
```   463 done
```
```   464
```
```   465 text{*Sum of a geometric progression.*}
```
```   466
```
```   467 lemmas sumr_geometric = geometric_sum [where 'a = real]
```
```   468
```
```   469 lemma geometric_sums:
```
```   470   fixes x :: "'a::{real_normed_field}"
```
```   471   shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) sums (1 / (1 - x))"
```
```   472 proof -
```
```   473   assume less_1: "norm x < 1"
```
```   474   hence neq_1: "x \<noteq> 1" by auto
```
```   475   hence neq_0: "x - 1 \<noteq> 0" by simp
```
```   476   from less_1 have lim_0: "(\<lambda>n. x ^ n) ----> 0"
```
```   477     by (rule LIMSEQ_power_zero)
```
```   478   hence "(\<lambda>n. x ^ n / (x - 1) - 1 / (x - 1)) ----> 0 / (x - 1) - 1 / (x - 1)"
```
```   479     using neq_0 by (intro tendsto_intros)
```
```   480   hence "(\<lambda>n. (x ^ n - 1) / (x - 1)) ----> 1 / (1 - x)"
```
```   481     by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
```
```   482   thus "(\<lambda>n. x ^ n) sums (1 / (1 - x))"
```
```   483     by (simp add: sums_def geometric_sum neq_1)
```
```   484 qed
```
```   485
```
```   486 lemma summable_geometric:
```
```   487   fixes x :: "'a::{real_normed_field}"
```
```   488   shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
```
```   489 by (rule geometric_sums [THEN sums_summable])
```
```   490
```
```   491 lemma half: "0 < 1 / (2::'a::linordered_field)"
```
```   492   by simp
```
```   493
```
```   494 lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
```
```   495 proof -
```
```   496   have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
```
```   497     by auto
```
```   498   have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
```
```   499     by simp
```
```   500   thus ?thesis using sums_divide [OF 2, of 2]
```
```   501     by simp
```
```   502 qed
```
```   503
```
```   504 text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
```
```   505
```
```   506 lemma summable_convergent_sumr_iff:
```
```   507  "summable f = convergent (%n. setsum f {0..<n})"
```
```   508 by (simp add: summable_def sums_def convergent_def)
```
```   509
```
```   510 lemma summable_LIMSEQ_zero:
```
```   511   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
```
```   512   shows "summable f \<Longrightarrow> f ----> 0"
```
```   513 apply (drule summable_convergent_sumr_iff [THEN iffD1])
```
```   514 apply (drule convergent_Cauchy)
```
```   515 apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
```
```   516 apply (drule_tac x="r" in spec, safe)
```
```   517 apply (rule_tac x="M" in exI, safe)
```
```   518 apply (drule_tac x="Suc n" in spec, simp)
```
```   519 apply (drule_tac x="n" in spec, simp)
```
```   520 done
```
```   521
```
```   522 lemma suminf_le:
```
```   523   fixes x :: "'a :: {ordered_comm_monoid_add, linorder_topology}"
```
```   524   shows "summable f \<Longrightarrow> (!!n. setsum f {0..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
```
```   525   apply (drule summable_sums)
```
```   526   apply (simp add: sums_def)
```
```   527   apply (rule LIMSEQ_le_const2)
```
```   528   apply assumption
```
```   529   apply auto
```
```   530   done
```
```   531
```
```   532 lemma summable_Cauchy:
```
```   533      "summable (f::nat \<Rightarrow> 'a::banach) =
```
```   534       (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. norm (setsum f {m..<n}) < e)"
```
```   535 apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
```
```   536 apply (drule spec, drule (1) mp)
```
```   537 apply (erule exE, rule_tac x="M" in exI, clarify)
```
```   538 apply (rule_tac x="m" and y="n" in linorder_le_cases)
```
```   539 apply (frule (1) order_trans)
```
```   540 apply (drule_tac x="n" in spec, drule (1) mp)
```
```   541 apply (drule_tac x="m" in spec, drule (1) mp)
```
```   542 apply (simp add: setsum_diff [symmetric])
```
```   543 apply simp
```
```   544 apply (drule spec, drule (1) mp)
```
```   545 apply (erule exE, rule_tac x="N" in exI, clarify)
```
```   546 apply (rule_tac x="m" and y="n" in linorder_le_cases)
```
```   547 apply (subst norm_minus_commute)
```
```   548 apply (simp add: setsum_diff [symmetric])
```
```   549 apply (simp add: setsum_diff [symmetric])
```
```   550 done
```
```   551
```
```   552 text{*Comparison test*}
```
```   553
```
```   554 lemma norm_setsum:
```
```   555   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
```
```   556   shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
```
```   557 apply (case_tac "finite A")
```
```   558 apply (erule finite_induct)
```
```   559 apply simp
```
```   560 apply simp
```
```   561 apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
```
```   562 apply simp
```
```   563 done
```
```   564
```
```   565 lemma summable_comparison_test:
```
```   566   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   567   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
```
```   568 apply (simp add: summable_Cauchy, safe)
```
```   569 apply (drule_tac x="e" in spec, safe)
```
```   570 apply (rule_tac x = "N + Na" in exI, safe)
```
```   571 apply (rotate_tac 2)
```
```   572 apply (drule_tac x = m in spec)
```
```   573 apply (auto, rotate_tac 2, drule_tac x = n in spec)
```
```   574 apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
```
```   575 apply (rule norm_setsum)
```
```   576 apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
```
```   577 apply (auto intro: setsum_mono simp add: abs_less_iff)
```
```   578 done
```
```   579
```
```   580 lemma summable_norm_comparison_test:
```
```   581   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   582   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk>
```
```   583          \<Longrightarrow> summable (\<lambda>n. norm (f n))"
```
```   584 apply (rule summable_comparison_test)
```
```   585 apply (auto)
```
```   586 done
```
```   587
```
```   588 lemma summable_rabs_comparison_test:
```
```   589   fixes f :: "nat \<Rightarrow> real"
```
```   590   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. \<bar>f n\<bar>)"
```
```   591 apply (rule summable_comparison_test)
```
```   592 apply (auto)
```
```   593 done
```
```   594
```
```   595 text{*Summability of geometric series for real algebras*}
```
```   596
```
```   597 lemma complete_algebra_summable_geometric:
```
```   598   fixes x :: "'a::{real_normed_algebra_1,banach}"
```
```   599   shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
```
```   600 proof (rule summable_comparison_test)
```
```   601   show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
```
```   602     by (simp add: norm_power_ineq)
```
```   603   show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
```
```   604     by (simp add: summable_geometric)
```
```   605 qed
```
```   606
```
```   607 text{*Limit comparison property for series (c.f. jrh)*}
```
```   608
```
```   609 lemma summable_le:
```
```   610   fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
```
```   611   shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
```
```   612 apply (drule summable_sums)+
```
```   613 apply (simp only: sums_def, erule (1) LIMSEQ_le)
```
```   614 apply (rule exI)
```
```   615 apply (auto intro!: setsum_mono)
```
```   616 done
```
```   617
```
```   618 lemma summable_le2:
```
```   619   fixes f g :: "nat \<Rightarrow> real"
```
```   620   shows "\<lbrakk>\<forall>n. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f \<and> suminf f \<le> suminf g"
```
```   621 apply (subgoal_tac "summable f")
```
```   622 apply (auto intro!: summable_le)
```
```   623 apply (simp add: abs_le_iff)
```
```   624 apply (rule_tac g="g" in summable_comparison_test, simp_all)
```
```   625 done
```
```   626
```
```   627 (* specialisation for the common 0 case *)
```
```   628 lemma suminf_0_le:
```
```   629   fixes f::"nat\<Rightarrow>real"
```
```   630   assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
```
```   631   shows "0 \<le> suminf f"
```
```   632   using suminf_ge_zero[OF sm gt0] by simp
```
```   633
```
```   634 text{*Absolute convergence imples normal convergence*}
```
```   635 lemma summable_norm_cancel:
```
```   636   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   637   shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
```
```   638 apply (simp only: summable_Cauchy, safe)
```
```   639 apply (drule_tac x="e" in spec, safe)
```
```   640 apply (rule_tac x="N" in exI, safe)
```
```   641 apply (drule_tac x="m" in spec, safe)
```
```   642 apply (rule order_le_less_trans [OF norm_setsum])
```
```   643 apply (rule order_le_less_trans [OF abs_ge_self])
```
```   644 apply simp
```
```   645 done
```
```   646
```
```   647 lemma summable_rabs_cancel:
```
```   648   fixes f :: "nat \<Rightarrow> real"
```
```   649   shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
```
```   650 by (rule summable_norm_cancel, simp)
```
```   651
```
```   652 text{*Absolute convergence of series*}
```
```   653 lemma summable_norm:
```
```   654   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   655   shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
```
```   656   by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel
```
```   657                 summable_sumr_LIMSEQ_suminf norm_setsum)
```
```   658
```
```   659 lemma summable_rabs:
```
```   660   fixes f :: "nat \<Rightarrow> real"
```
```   661   shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
```
```   662 by (fold real_norm_def, rule summable_norm)
```
```   663
```
```   664 subsection{* The Ratio Test*}
```
```   665
```
```   666 lemma norm_ratiotest_lemma:
```
```   667   fixes x y :: "'a::real_normed_vector"
```
```   668   shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
```
```   669 apply (subgoal_tac "norm x \<le> 0", simp)
```
```   670 apply (erule order_trans)
```
```   671 apply (simp add: mult_le_0_iff)
```
```   672 done
```
```   673
```
```   674 lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
```
```   675 by (erule norm_ratiotest_lemma, simp)
```
```   676
```
```   677 (* TODO: MOVE *)
```
```   678 lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
```
```   679 apply (drule le_imp_less_or_eq)
```
```   680 apply (auto dest: less_imp_Suc_add)
```
```   681 done
```
```   682
```
```   683 lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
```
```   684 by (auto simp add: le_Suc_ex)
```
```   685
```
```   686 (*All this trouble just to get 0<c *)
```
```   687 lemma ratio_test_lemma2:
```
```   688   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   689   shows "\<lbrakk>\<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
```
```   690 apply (simp (no_asm) add: linorder_not_le [symmetric])
```
```   691 apply (simp add: summable_Cauchy)
```
```   692 apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
```
```   693  prefer 2
```
```   694  apply clarify
```
```   695  apply(erule_tac x = "n - Suc 0" in allE)
```
```   696  apply (simp add:diff_Suc split:nat.splits)
```
```   697  apply (blast intro: norm_ratiotest_lemma)
```
```   698 apply (rule_tac x = "Suc N" in exI, clarify)
```
```   699 apply(simp cong del: setsum_cong cong: setsum_ivl_cong)
```
```   700 done
```
```   701
```
```   702 lemma ratio_test:
```
```   703   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   704   shows "\<lbrakk>c < 1; \<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> summable f"
```
```   705 apply (frule ratio_test_lemma2, auto)
```
```   706 apply (rule_tac g = "%n. (norm (f N) / (c ^ N))*c ^ n"
```
```   707        in summable_comparison_test)
```
```   708 apply (rule_tac x = N in exI, safe)
```
```   709 apply (drule le_Suc_ex_iff [THEN iffD1])
```
```   710 apply (auto simp add: power_add field_power_not_zero)
```
```   711 apply (induct_tac "na", auto)
```
```   712 apply (rule_tac y = "c * norm (f (N + n))" in order_trans)
```
```   713 apply (auto intro: mult_right_mono simp add: summable_def)
```
```   714 apply (rule_tac x = "norm (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
```
```   715 apply (rule sums_divide)
```
```   716 apply (rule sums_mult)
```
```   717 apply (auto intro!: geometric_sums)
```
```   718 done
```
```   719
```
```   720 subsection {* Cauchy Product Formula *}
```
```   721
```
```   722 (* Proof based on Analysis WebNotes: Chapter 07, Class 41
```
```   723 http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm *)
```
```   724
```
```   725 lemma setsum_triangle_reindex:
```
```   726   fixes n :: nat
```
```   727   shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k=0..<n. \<Sum>i=0..k. f i (k - i))"
```
```   728 proof -
```
```   729   have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
```
```   730     (\<Sum>(k, i)\<in>(SIGMA k:{0..<n}. {0..k}). f i (k - i))"
```
```   731   proof (rule setsum_reindex_cong)
```
```   732     show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{0..<n}. {0..k})"
```
```   733       by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
```
```   734     show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{0..<n}. {0..k})"
```
```   735       by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
```
```   736     show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
```
```   737       by clarify
```
```   738   qed
```
```   739   thus ?thesis by (simp add: setsum_Sigma)
```
```   740 qed
```
```   741
```
```   742 lemma Cauchy_product_sums:
```
```   743   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
```
```   744   assumes a: "summable (\<lambda>k. norm (a k))"
```
```   745   assumes b: "summable (\<lambda>k. norm (b k))"
```
```   746   shows "(\<lambda>k. \<Sum>i=0..k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
```
```   747 proof -
```
```   748   let ?S1 = "\<lambda>n::nat. {0..<n} \<times> {0..<n}"
```
```   749   let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
```
```   750   have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
```
```   751   have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
```
```   752   have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
```
```   753   have finite_S1: "\<And>n. finite (?S1 n)" by simp
```
```   754   with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
```
```   755
```
```   756   let ?g = "\<lambda>(i,j). a i * b j"
```
```   757   let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
```
```   758   have f_nonneg: "\<And>x. 0 \<le> ?f x"
```
```   759     by (auto simp add: mult_nonneg_nonneg)
```
```   760   hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
```
```   761     unfolding real_norm_def
```
```   762     by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
```
```   763
```
```   764   have "(\<lambda>n. (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k))
```
```   765            ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
```
```   766     by (intro tendsto_mult summable_sumr_LIMSEQ_suminf
```
```   767         summable_norm_cancel [OF a] summable_norm_cancel [OF b])
```
```   768   hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
```
```   769     by (simp only: setsum_product setsum_Sigma [rule_format]
```
```   770                    finite_atLeastLessThan)
```
```   771
```
```   772   have "(\<lambda>n. (\<Sum>k=0..<n. norm (a k)) * (\<Sum>k=0..<n. norm (b k)))
```
```   773        ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
```
```   774     using a b by (intro tendsto_mult summable_sumr_LIMSEQ_suminf)
```
```   775   hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
```
```   776     by (simp only: setsum_product setsum_Sigma [rule_format]
```
```   777                    finite_atLeastLessThan)
```
```   778   hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
```
```   779     by (rule convergentI)
```
```   780   hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
```
```   781     by (rule convergent_Cauchy)
```
```   782   have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
```
```   783   proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
```
```   784     fix r :: real
```
```   785     assume r: "0 < r"
```
```   786     from CauchyD [OF Cauchy r] obtain N
```
```   787     where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
```
```   788     hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
```
```   789       by (simp only: setsum_diff finite_S1 S1_mono)
```
```   790     hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
```
```   791       by (simp only: norm_setsum_f)
```
```   792     show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
```
```   793     proof (intro exI allI impI)
```
```   794       fix n assume "2 * N \<le> n"
```
```   795       hence n: "N \<le> n div 2" by simp
```
```   796       have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
```
```   797         by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
```
```   798                   Diff_mono subset_refl S1_le_S2)
```
```   799       also have "\<dots> < r"
```
```   800         using n div_le_dividend by (rule N)
```
```   801       finally show "setsum ?f (?S1 n - ?S2 n) < r" .
```
```   802     qed
```
```   803   qed
```
```   804   hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
```
```   805     apply (rule Zfun_le [rule_format])
```
```   806     apply (simp only: norm_setsum_f)
```
```   807     apply (rule order_trans [OF norm_setsum setsum_mono])
```
```   808     apply (auto simp add: norm_mult_ineq)
```
```   809     done
```
```   810   hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
```
```   811     unfolding tendsto_Zfun_iff diff_0_right
```
```   812     by (simp only: setsum_diff finite_S1 S2_le_S1)
```
```   813
```
```   814   with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
```
```   815     by (rule LIMSEQ_diff_approach_zero2)
```
```   816   thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
```
```   817 qed
```
```   818
```
```   819 lemma Cauchy_product:
```
```   820   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
```
```   821   assumes a: "summable (\<lambda>k. norm (a k))"
```
```   822   assumes b: "summable (\<lambda>k. norm (b k))"
```
```   823   shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i=0..k. a i * b (k - i))"
```
```   824 using a b
```
```   825 by (rule Cauchy_product_sums [THEN sums_unique])
```
```   826
```
```   827 end
```