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