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