src/HOL/Hyperreal/Series.thy
author huffman
Tue May 29 18:31:30 2007 +0200 (2007-05-29)
changeset 23121 5feeb93b3ba8
parent 23119 0082459a255b
child 23127 56ee8105c002
permissions -rw-r--r--
cleaned up some proofs
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
huffman@21141
    13
imports SEQ
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
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
avigad@16819
    81
(*
avigad@16819
    82
lemma sumr_from_1_from_0: "0 < n ==>
avigad@16819
    83
      (\<Sum>n=Suc 0 ..< Suc n. if even(n) then 0 else
avigad@16819
    84
             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n =
avigad@16819
    85
      (\<Sum>n=0..<Suc n. if even(n) then 0 else
avigad@16819
    86
             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n"
avigad@16819
    87
by (rule_tac n1 = 1 in sumr_split_add [THEN subst], auto)
avigad@16819
    88
*)
paulson@14416
    89
paulson@14416
    90
subsection{* Infinite Sums, by the Properties of Limits*}
paulson@14416
    91
paulson@14416
    92
(*----------------------
paulson@14416
    93
   suminf is the sum   
paulson@14416
    94
 ---------------------*)
paulson@14416
    95
lemma sums_summable: "f sums l ==> summable f"
paulson@14416
    96
by (simp add: sums_def summable_def, blast)
paulson@14416
    97
paulson@14416
    98
lemma summable_sums: "summable f ==> f sums (suminf f)"
huffman@20688
    99
apply (simp add: summable_def suminf_def sums_def)
huffman@20688
   100
apply (blast intro: theI LIMSEQ_unique)
paulson@14416
   101
done
paulson@14416
   102
paulson@14416
   103
lemma summable_sumr_LIMSEQ_suminf: 
nipkow@15539
   104
     "summable f ==> (%n. setsum f {0..<n}) ----> (suminf f)"
huffman@20688
   105
by (rule summable_sums [unfolded sums_def])
paulson@14416
   106
paulson@14416
   107
(*-------------------
paulson@14416
   108
    sum is unique                    
paulson@14416
   109
 ------------------*)
paulson@14416
   110
lemma sums_unique: "f sums s ==> (s = suminf f)"
paulson@14416
   111
apply (frule sums_summable [THEN summable_sums])
paulson@14416
   112
apply (auto intro!: LIMSEQ_unique simp add: sums_def)
paulson@14416
   113
done
paulson@14416
   114
avigad@16819
   115
lemma sums_split_initial_segment: "f sums s ==> 
avigad@16819
   116
  (%n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
avigad@16819
   117
  apply (unfold sums_def);
avigad@16819
   118
  apply (simp add: sumr_offset); 
avigad@16819
   119
  apply (rule LIMSEQ_diff_const)
avigad@16819
   120
  apply (rule LIMSEQ_ignore_initial_segment)
avigad@16819
   121
  apply assumption
avigad@16819
   122
done
avigad@16819
   123
avigad@16819
   124
lemma summable_ignore_initial_segment: "summable f ==> 
avigad@16819
   125
    summable (%n. f(n + k))"
avigad@16819
   126
  apply (unfold summable_def)
avigad@16819
   127
  apply (auto intro: sums_split_initial_segment)
avigad@16819
   128
done
avigad@16819
   129
avigad@16819
   130
lemma suminf_minus_initial_segment: "summable f ==>
avigad@16819
   131
    suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
avigad@16819
   132
  apply (frule summable_ignore_initial_segment)
avigad@16819
   133
  apply (rule sums_unique [THEN sym])
avigad@16819
   134
  apply (frule summable_sums)
avigad@16819
   135
  apply (rule sums_split_initial_segment)
avigad@16819
   136
  apply auto
avigad@16819
   137
done
avigad@16819
   138
avigad@16819
   139
lemma suminf_split_initial_segment: "summable f ==> 
avigad@16819
   140
    suminf f = (SUM i = 0..< k. f i) + suminf (%n. f(n + k))"
avigad@16819
   141
by (auto simp add: suminf_minus_initial_segment)
avigad@16819
   142
paulson@14416
   143
lemma series_zero: 
nipkow@15539
   144
     "(\<forall>m. n \<le> m --> f(m) = 0) ==> f sums (setsum f {0..<n})"
nipkow@15537
   145
apply (simp add: sums_def LIMSEQ_def diff_minus[symmetric], safe)
paulson@14416
   146
apply (rule_tac x = n in exI)
nipkow@15542
   147
apply (clarsimp simp add:setsum_diff[symmetric] cong:setsum_ivl_cong)
paulson@14416
   148
done
paulson@14416
   149
huffman@23121
   150
lemma sums_zero: "(\<lambda>n. 0) sums 0"
huffman@23121
   151
unfolding sums_def by (simp add: LIMSEQ_const)
nipkow@15539
   152
huffman@23121
   153
lemma summable_zero: "summable (\<lambda>n. 0)"
huffman@23121
   154
by (rule sums_zero [THEN sums_summable])
avigad@16819
   155
huffman@23121
   156
lemma suminf_zero: "suminf (\<lambda>n. 0) = 0"
huffman@23121
   157
by (rule sums_zero [THEN sums_unique, symmetric])
avigad@16819
   158
  
huffman@23119
   159
lemma (in bounded_linear) sums:
huffman@23119
   160
  "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
huffman@23119
   161
unfolding sums_def by (drule LIMSEQ, simp only: setsum)
huffman@23119
   162
huffman@23119
   163
lemma (in bounded_linear) summable:
huffman@23119
   164
  "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
huffman@23119
   165
unfolding summable_def by (auto intro: sums)
huffman@23119
   166
huffman@23119
   167
lemma (in bounded_linear) suminf:
huffman@23119
   168
  "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
huffman@23121
   169
by (intro sums_unique sums summable_sums)
huffman@23119
   170
huffman@20692
   171
lemma sums_mult:
huffman@20692
   172
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   173
  shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
huffman@23121
   174
by (rule bounded_linear_mult_right.sums)
paulson@14416
   175
huffman@20692
   176
lemma summable_mult:
huffman@20692
   177
  fixes c :: "'a::real_normed_algebra"
huffman@23121
   178
  shows "summable f \<Longrightarrow> summable (%n. c * f n)"
huffman@23121
   179
by (rule bounded_linear_mult_right.summable)
avigad@16819
   180
huffman@20692
   181
lemma suminf_mult:
huffman@20692
   182
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   183
  shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f";
huffman@23121
   184
by (rule bounded_linear_mult_right.suminf [symmetric])
avigad@16819
   185
huffman@20692
   186
lemma sums_mult2:
huffman@20692
   187
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   188
  shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
huffman@23121
   189
by (rule bounded_linear_mult_left.sums)
avigad@16819
   190
huffman@20692
   191
lemma summable_mult2:
huffman@20692
   192
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   193
  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
huffman@23121
   194
by (rule bounded_linear_mult_left.summable)
avigad@16819
   195
huffman@20692
   196
lemma suminf_mult2:
huffman@20692
   197
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   198
  shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
huffman@23121
   199
by (rule bounded_linear_mult_left.suminf)
avigad@16819
   200
huffman@20692
   201
lemma sums_divide:
huffman@20692
   202
  fixes c :: "'a::real_normed_field"
huffman@20692
   203
  shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
huffman@23121
   204
by (rule bounded_linear_divide.sums)
paulson@14416
   205
huffman@20692
   206
lemma summable_divide:
huffman@20692
   207
  fixes c :: "'a::real_normed_field"
huffman@20692
   208
  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
huffman@23121
   209
by (rule bounded_linear_divide.summable)
avigad@16819
   210
huffman@20692
   211
lemma suminf_divide:
huffman@20692
   212
  fixes c :: "'a::real_normed_field"
huffman@20692
   213
  shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
huffman@23121
   214
by (rule bounded_linear_divide.suminf [symmetric])
avigad@16819
   215
huffman@23121
   216
lemma sums_add: "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) sums (a + b)"
huffman@23121
   217
unfolding sums_def by (simp add: setsum_addf LIMSEQ_add)
avigad@16819
   218
huffman@23121
   219
lemma summable_add: "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n + Y n)"
huffman@23121
   220
unfolding summable_def by (auto intro: sums_add)
avigad@16819
   221
avigad@16819
   222
lemma suminf_add:
huffman@23121
   223
  "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X + suminf Y = (\<Sum>n. X n + Y n)"
huffman@23121
   224
by (intro sums_unique sums_add summable_sums)
paulson@14416
   225
huffman@23121
   226
lemma sums_diff: "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) sums (a - b)"
huffman@23121
   227
unfolding sums_def by (simp add: setsum_subtractf LIMSEQ_diff)
huffman@23121
   228
huffman@23121
   229
lemma summable_diff: "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n - Y n)"
huffman@23121
   230
unfolding summable_def by (auto intro: sums_diff)
paulson@14416
   231
paulson@14416
   232
lemma suminf_diff:
huffman@23121
   233
  "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X - suminf Y = (\<Sum>n. X n - Y n)"
huffman@23121
   234
by (intro sums_unique sums_diff summable_sums)
paulson@14416
   235
huffman@23121
   236
lemma sums_minus: "X sums a ==> (\<lambda>n. - X n) sums (- a)"
huffman@23121
   237
unfolding sums_def by (simp add: setsum_negf LIMSEQ_minus)
avigad@16819
   238
huffman@23121
   239
lemma summable_minus: "summable X \<Longrightarrow> summable (\<lambda>n. - X n)"
huffman@23121
   240
unfolding summable_def by (auto intro: sums_minus)
avigad@16819
   241
huffman@23121
   242
lemma suminf_minus: "summable X \<Longrightarrow> (\<Sum>n. - X n) = - (\<Sum>n. X n)"
huffman@23121
   243
by (intro sums_unique [symmetric] sums_minus summable_sums)
paulson@14416
   244
paulson@14416
   245
lemma sums_group:
nipkow@15539
   246
     "[|summable f; 0 < k |] ==> (%n. setsum f {n*k..<n*k+k}) sums (suminf f)"
paulson@14416
   247
apply (drule summable_sums)
huffman@20692
   248
apply (simp only: sums_def sumr_group)
huffman@20692
   249
apply (unfold LIMSEQ_def, safe)
huffman@20692
   250
apply (drule_tac x="r" in spec, safe)
huffman@20692
   251
apply (rule_tac x="no" in exI, safe)
huffman@20692
   252
apply (drule_tac x="n*k" in spec)
huffman@20692
   253
apply (erule mp)
huffman@20692
   254
apply (erule order_trans)
huffman@20692
   255
apply simp
paulson@14416
   256
done
paulson@14416
   257
paulson@15085
   258
text{*A summable series of positive terms has limit that is at least as
paulson@15085
   259
great as any partial sum.*}
paulson@14416
   260
huffman@20692
   261
lemma series_pos_le:
huffman@20692
   262
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   263
  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
paulson@14416
   264
apply (drule summable_sums)
paulson@14416
   265
apply (simp add: sums_def)
nipkow@15539
   266
apply (cut_tac k = "setsum f {0..<n}" in LIMSEQ_const)
nipkow@15539
   267
apply (erule LIMSEQ_le, blast)
huffman@20692
   268
apply (rule_tac x="n" in exI, clarify)
nipkow@15539
   269
apply (rule setsum_mono2)
nipkow@15539
   270
apply auto
paulson@14416
   271
done
paulson@14416
   272
paulson@14416
   273
lemma series_pos_less:
huffman@20692
   274
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   275
  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
huffman@20692
   276
apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
huffman@20692
   277
apply simp
huffman@20692
   278
apply (erule series_pos_le)
huffman@20692
   279
apply (simp add: order_less_imp_le)
huffman@20692
   280
done
huffman@20692
   281
huffman@20692
   282
lemma suminf_gt_zero:
huffman@20692
   283
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   284
  shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
huffman@20692
   285
by (drule_tac n="0" in series_pos_less, simp_all)
huffman@20692
   286
huffman@20692
   287
lemma suminf_ge_zero:
huffman@20692
   288
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   289
  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
huffman@20692
   290
by (drule_tac n="0" in series_pos_le, simp_all)
huffman@20692
   291
huffman@20692
   292
lemma sumr_pos_lt_pair:
huffman@20692
   293
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   294
  shows "\<lbrakk>summable f;
huffman@20692
   295
        \<forall>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
huffman@20692
   296
      \<Longrightarrow> setsum f {0..<k} < suminf f"
huffman@20692
   297
apply (subst suminf_split_initial_segment [where k="k"])
huffman@20692
   298
apply assumption
huffman@20692
   299
apply simp
huffman@20692
   300
apply (drule_tac k="k" in summable_ignore_initial_segment)
huffman@20692
   301
apply (drule_tac k="Suc (Suc 0)" in sums_group, simp)
huffman@20692
   302
apply simp
huffman@20692
   303
apply (frule sums_unique)
huffman@20692
   304
apply (drule sums_summable)
huffman@20692
   305
apply simp
huffman@20692
   306
apply (erule suminf_gt_zero)
huffman@20692
   307
apply (simp add: add_ac)
paulson@14416
   308
done
paulson@14416
   309
paulson@15085
   310
text{*Sum of a geometric progression.*}
paulson@14416
   311
ballarin@17149
   312
lemmas sumr_geometric = geometric_sum [where 'a = real]
paulson@14416
   313
huffman@20692
   314
lemma geometric_sums:
huffman@22719
   315
  fixes x :: "'a::{real_normed_field,recpower}"
huffman@20692
   316
  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) sums (1 / (1 - x))"
huffman@20692
   317
proof -
huffman@20692
   318
  assume less_1: "norm x < 1"
huffman@20692
   319
  hence neq_1: "x \<noteq> 1" by auto
huffman@20692
   320
  hence neq_0: "x - 1 \<noteq> 0" by simp
huffman@20692
   321
  from less_1 have lim_0: "(\<lambda>n. x ^ n) ----> 0"
huffman@20692
   322
    by (rule LIMSEQ_power_zero)
huffman@22719
   323
  hence "(\<lambda>n. x ^ n / (x - 1) - 1 / (x - 1)) ----> 0 / (x - 1) - 1 / (x - 1)"
huffman@20692
   324
    using neq_0 by (intro LIMSEQ_divide LIMSEQ_diff LIMSEQ_const)
huffman@20692
   325
  hence "(\<lambda>n. (x ^ n - 1) / (x - 1)) ----> 1 / (1 - x)"
huffman@20692
   326
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
huffman@20692
   327
  thus "(\<lambda>n. x ^ n) sums (1 / (1 - x))"
huffman@20692
   328
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   329
qed
huffman@20692
   330
huffman@20692
   331
lemma summable_geometric:
huffman@22719
   332
  fixes x :: "'a::{real_normed_field,recpower}"
huffman@20692
   333
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@20692
   334
by (rule geometric_sums [THEN sums_summable])
paulson@14416
   335
paulson@15085
   336
text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
paulson@15085
   337
nipkow@15539
   338
lemma summable_convergent_sumr_iff:
nipkow@15539
   339
 "summable f = convergent (%n. setsum f {0..<n})"
paulson@14416
   340
by (simp add: summable_def sums_def convergent_def)
paulson@14416
   341
huffman@20689
   342
lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
huffman@20689
   343
apply (drule summable_convergent_sumr_iff [THEN iffD1])
huffman@20692
   344
apply (drule convergent_Cauchy)
huffman@20689
   345
apply (simp only: Cauchy_def LIMSEQ_def, safe)
huffman@20689
   346
apply (drule_tac x="r" in spec, safe)
huffman@20689
   347
apply (rule_tac x="M" in exI, safe)
huffman@20689
   348
apply (drule_tac x="Suc n" in spec, simp)
huffman@20689
   349
apply (drule_tac x="n" in spec, simp)
huffman@20689
   350
done
huffman@20689
   351
paulson@14416
   352
lemma summable_Cauchy:
huffman@20848
   353
     "summable (f::nat \<Rightarrow> 'a::banach) =  
huffman@20848
   354
      (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. norm (setsum f {m..<n}) < e)"
huffman@20848
   355
apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_def, safe)
huffman@20410
   356
apply (drule spec, drule (1) mp)
huffman@20410
   357
apply (erule exE, rule_tac x="M" in exI, clarify)
huffman@20410
   358
apply (rule_tac x="m" and y="n" in linorder_le_cases)
huffman@20410
   359
apply (frule (1) order_trans)
huffman@20410
   360
apply (drule_tac x="n" in spec, drule (1) mp)
huffman@20410
   361
apply (drule_tac x="m" in spec, drule (1) mp)
huffman@20410
   362
apply (simp add: setsum_diff [symmetric])
huffman@20410
   363
apply simp
huffman@20410
   364
apply (drule spec, drule (1) mp)
huffman@20410
   365
apply (erule exE, rule_tac x="N" in exI, clarify)
huffman@20410
   366
apply (rule_tac x="m" and y="n" in linorder_le_cases)
huffman@20552
   367
apply (subst norm_minus_commute)
huffman@20410
   368
apply (simp add: setsum_diff [symmetric])
huffman@20410
   369
apply (simp add: setsum_diff [symmetric])
paulson@14416
   370
done
paulson@14416
   371
paulson@15085
   372
text{*Comparison test*}
paulson@15085
   373
huffman@20692
   374
lemma norm_setsum:
huffman@20692
   375
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@20692
   376
  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
huffman@20692
   377
apply (case_tac "finite A")
huffman@20692
   378
apply (erule finite_induct)
huffman@20692
   379
apply simp
huffman@20692
   380
apply simp
huffman@20692
   381
apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
huffman@20692
   382
apply simp
huffman@20692
   383
done
huffman@20692
   384
paulson@14416
   385
lemma summable_comparison_test:
huffman@20848
   386
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   387
  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
huffman@20692
   388
apply (simp add: summable_Cauchy, safe)
huffman@20692
   389
apply (drule_tac x="e" in spec, safe)
huffman@20692
   390
apply (rule_tac x = "N + Na" in exI, safe)
paulson@14416
   391
apply (rotate_tac 2)
paulson@14416
   392
apply (drule_tac x = m in spec)
paulson@14416
   393
apply (auto, rotate_tac 2, drule_tac x = n in spec)
huffman@20848
   394
apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
huffman@20848
   395
apply (rule norm_setsum)
nipkow@15539
   396
apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
huffman@22998
   397
apply (auto intro: setsum_mono simp add: abs_less_iff)
paulson@14416
   398
done
paulson@14416
   399
huffman@20848
   400
lemma summable_norm_comparison_test:
huffman@20848
   401
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   402
  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk>
huffman@20848
   403
         \<Longrightarrow> summable (\<lambda>n. norm (f n))"
huffman@20848
   404
apply (rule summable_comparison_test)
huffman@20848
   405
apply (auto)
huffman@20848
   406
done
huffman@20848
   407
paulson@14416
   408
lemma summable_rabs_comparison_test:
huffman@20692
   409
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   410
  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
   411
apply (rule summable_comparison_test)
nipkow@15543
   412
apply (auto)
paulson@14416
   413
done
paulson@14416
   414
huffman@23084
   415
text{*Summability of geometric series for real algebras*}
huffman@23084
   416
huffman@23084
   417
lemma complete_algebra_summable_geometric:
huffman@23084
   418
  fixes x :: "'a::{real_normed_algebra_1,banach,recpower}"
huffman@23084
   419
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@23084
   420
proof (rule summable_comparison_test)
huffman@23084
   421
  show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
huffman@23084
   422
    by (simp add: norm_power_ineq)
huffman@23084
   423
  show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
huffman@23084
   424
    by (simp add: summable_geometric)
huffman@23084
   425
qed
huffman@23084
   426
paulson@15085
   427
text{*Limit comparison property for series (c.f. jrh)*}
paulson@15085
   428
paulson@14416
   429
lemma summable_le:
huffman@20692
   430
  fixes f g :: "nat \<Rightarrow> real"
huffman@20692
   431
  shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
paulson@14416
   432
apply (drule summable_sums)+
huffman@20692
   433
apply (simp only: sums_def, erule (1) LIMSEQ_le)
paulson@14416
   434
apply (rule exI)
nipkow@15539
   435
apply (auto intro!: setsum_mono)
paulson@14416
   436
done
paulson@14416
   437
paulson@14416
   438
lemma summable_le2:
huffman@20692
   439
  fixes f g :: "nat \<Rightarrow> real"
huffman@20692
   440
  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
   441
apply (subgoal_tac "summable f")
huffman@20848
   442
apply (auto intro!: summable_le)
huffman@22998
   443
apply (simp add: abs_le_iff)
huffman@20848
   444
apply (rule_tac g="g" in summable_comparison_test, simp_all)
paulson@14416
   445
done
paulson@14416
   446
kleing@19106
   447
(* specialisation for the common 0 case *)
kleing@19106
   448
lemma suminf_0_le:
kleing@19106
   449
  fixes f::"nat\<Rightarrow>real"
kleing@19106
   450
  assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
kleing@19106
   451
  shows "0 \<le> suminf f"
kleing@19106
   452
proof -
kleing@19106
   453
  let ?g = "(\<lambda>n. (0::real))"
kleing@19106
   454
  from gt0 have "\<forall>n. ?g n \<le> f n" by simp
kleing@19106
   455
  moreover have "summable ?g" by (rule summable_zero)
kleing@19106
   456
  moreover from sm have "summable f" .
kleing@19106
   457
  ultimately have "suminf ?g \<le> suminf f" by (rule summable_le)
kleing@19106
   458
  then show "0 \<le> suminf f" by (simp add: suminf_zero)
kleing@19106
   459
qed 
kleing@19106
   460
kleing@19106
   461
paulson@15085
   462
text{*Absolute convergence imples normal convergence*}
huffman@20848
   463
lemma summable_norm_cancel:
huffman@20848
   464
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   465
  shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
huffman@20692
   466
apply (simp only: summable_Cauchy, safe)
huffman@20692
   467
apply (drule_tac x="e" in spec, safe)
huffman@20692
   468
apply (rule_tac x="N" in exI, safe)
huffman@20692
   469
apply (drule_tac x="m" in spec, safe)
huffman@20848
   470
apply (rule order_le_less_trans [OF norm_setsum])
huffman@20848
   471
apply (rule order_le_less_trans [OF abs_ge_self])
huffman@20692
   472
apply simp
paulson@14416
   473
done
paulson@14416
   474
huffman@20848
   475
lemma summable_rabs_cancel:
huffman@20848
   476
  fixes f :: "nat \<Rightarrow> real"
huffman@20848
   477
  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
huffman@20848
   478
by (rule summable_norm_cancel, simp)
huffman@20848
   479
paulson@15085
   480
text{*Absolute convergence of series*}
huffman@20848
   481
lemma summable_norm:
huffman@20848
   482
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   483
  shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
huffman@20848
   484
by (auto intro: LIMSEQ_le LIMSEQ_norm summable_norm_cancel
huffman@20848
   485
                summable_sumr_LIMSEQ_suminf norm_setsum)
huffman@20848
   486
paulson@14416
   487
lemma summable_rabs:
huffman@20692
   488
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   489
  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
huffman@20848
   490
by (fold real_norm_def, rule summable_norm)
paulson@14416
   491
paulson@14416
   492
subsection{* The Ratio Test*}
paulson@14416
   493
huffman@20848
   494
lemma norm_ratiotest_lemma:
huffman@22852
   495
  fixes x y :: "'a::real_normed_vector"
huffman@20848
   496
  shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
huffman@20848
   497
apply (subgoal_tac "norm x \<le> 0", simp)
huffman@20848
   498
apply (erule order_trans)
huffman@20848
   499
apply (simp add: mult_le_0_iff)
huffman@20848
   500
done
huffman@20848
   501
paulson@14416
   502
lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
huffman@20848
   503
by (erule norm_ratiotest_lemma, simp)
paulson@14416
   504
paulson@14416
   505
lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
paulson@14416
   506
apply (drule le_imp_less_or_eq)
paulson@14416
   507
apply (auto dest: less_imp_Suc_add)
paulson@14416
   508
done
paulson@14416
   509
paulson@14416
   510
lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
paulson@14416
   511
by (auto simp add: le_Suc_ex)
paulson@14416
   512
paulson@14416
   513
(*All this trouble just to get 0<c *)
paulson@14416
   514
lemma ratio_test_lemma2:
huffman@20848
   515
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   516
  shows "\<lbrakk>\<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
paulson@14416
   517
apply (simp (no_asm) add: linorder_not_le [symmetric])
paulson@14416
   518
apply (simp add: summable_Cauchy)
nipkow@15543
   519
apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
nipkow@15543
   520
 prefer 2
nipkow@15543
   521
 apply clarify
nipkow@15543
   522
 apply(erule_tac x = "n - 1" in allE)
nipkow@15543
   523
 apply (simp add:diff_Suc split:nat.splits)
huffman@20848
   524
 apply (blast intro: norm_ratiotest_lemma)
paulson@14416
   525
apply (rule_tac x = "Suc N" in exI, clarify)
nipkow@15543
   526
apply(simp cong:setsum_ivl_cong)
paulson@14416
   527
done
paulson@14416
   528
paulson@14416
   529
lemma ratio_test:
huffman@20848
   530
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   531
  shows "\<lbrakk>c < 1; \<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> summable f"
paulson@14416
   532
apply (frule ratio_test_lemma2, auto)
huffman@20848
   533
apply (rule_tac g = "%n. (norm (f N) / (c ^ N))*c ^ n" 
paulson@15234
   534
       in summable_comparison_test)
paulson@14416
   535
apply (rule_tac x = N in exI, safe)
paulson@14416
   536
apply (drule le_Suc_ex_iff [THEN iffD1])
huffman@22959
   537
apply (auto simp add: power_add field_power_not_zero)
nipkow@15539
   538
apply (induct_tac "na", auto)
huffman@20848
   539
apply (rule_tac y = "c * norm (f (N + n))" in order_trans)
paulson@14416
   540
apply (auto intro: mult_right_mono simp add: summable_def)
paulson@14416
   541
apply (simp add: mult_ac)
huffman@20848
   542
apply (rule_tac x = "norm (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
paulson@15234
   543
apply (rule sums_divide) 
paulson@15234
   544
apply (rule sums_mult) 
paulson@15234
   545
apply (auto intro!: geometric_sums)
paulson@14416
   546
done
paulson@14416
   547
huffman@23111
   548
subsection {* Cauchy Product Formula *}
huffman@23111
   549
huffman@23111
   550
(* Proof based on Analysis WebNotes: Chapter 07, Class 41
huffman@23111
   551
http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm *)
huffman@23111
   552
huffman@23111
   553
lemma setsum_triangle_reindex:
huffman@23111
   554
  fixes n :: nat
huffman@23111
   555
  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
   556
proof -
huffman@23111
   557
  have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
huffman@23111
   558
    (\<Sum>(k, i)\<in>(SIGMA k:{0..<n}. {0..k}). f i (k - i))"
huffman@23111
   559
  proof (rule setsum_reindex_cong)
huffman@23111
   560
    show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{0..<n}. {0..k})"
huffman@23111
   561
      by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
huffman@23111
   562
    show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{0..<n}. {0..k})"
huffman@23111
   563
      by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
huffman@23111
   564
    show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
huffman@23111
   565
      by clarify
huffman@23111
   566
  qed
huffman@23111
   567
  thus ?thesis by (simp add: setsum_Sigma)
huffman@23111
   568
qed
huffman@23111
   569
huffman@23111
   570
lemma Cauchy_product_sums:
huffman@23111
   571
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   572
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   573
  assumes b: "summable (\<lambda>k. norm (b k))"
huffman@23111
   574
  shows "(\<lambda>k. \<Sum>i=0..k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
huffman@23111
   575
proof -
huffman@23111
   576
  let ?S1 = "\<lambda>n::nat. {0..<n} \<times> {0..<n}"
huffman@23111
   577
  let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
huffman@23111
   578
  have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
huffman@23111
   579
  have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
huffman@23111
   580
  have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
huffman@23111
   581
  have finite_S1: "\<And>n. finite (?S1 n)" by simp
huffman@23111
   582
  with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
huffman@23111
   583
huffman@23111
   584
  let ?g = "\<lambda>(i,j). a i * b j"
huffman@23111
   585
  let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
huffman@23111
   586
  have f_nonneg: "\<And>x. 0 \<le> ?f x"
huffman@23111
   587
    by (auto simp add: mult_nonneg_nonneg)
huffman@23111
   588
  hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
huffman@23111
   589
    unfolding real_norm_def
huffman@23111
   590
    by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
huffman@23111
   591
huffman@23111
   592
  have "(\<lambda>n. (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k))
huffman@23111
   593
           ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   594
    by (intro LIMSEQ_mult summable_sumr_LIMSEQ_suminf
huffman@23111
   595
        summable_norm_cancel [OF a] summable_norm_cancel [OF b])
huffman@23111
   596
  hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   597
    by (simp only: setsum_product setsum_Sigma [rule_format]
huffman@23111
   598
                   finite_atLeastLessThan)
huffman@23111
   599
huffman@23111
   600
  have "(\<lambda>n. (\<Sum>k=0..<n. norm (a k)) * (\<Sum>k=0..<n. norm (b k)))
huffman@23111
   601
       ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
huffman@23111
   602
    using a b by (intro LIMSEQ_mult summable_sumr_LIMSEQ_suminf)
huffman@23111
   603
  hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
huffman@23111
   604
    by (simp only: setsum_product setsum_Sigma [rule_format]
huffman@23111
   605
                   finite_atLeastLessThan)
huffman@23111
   606
  hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   607
    by (rule convergentI)
huffman@23111
   608
  hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   609
    by (rule convergent_Cauchy)
huffman@23111
   610
  have "Zseq (\<lambda>n. setsum ?f (?S1 n - ?S2 n))"
huffman@23111
   611
  proof (rule ZseqI, simp only: norm_setsum_f)
huffman@23111
   612
    fix r :: real
huffman@23111
   613
    assume r: "0 < r"
huffman@23111
   614
    from CauchyD [OF Cauchy r] obtain N
huffman@23111
   615
    where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
huffman@23111
   616
    hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
huffman@23111
   617
      by (simp only: setsum_diff finite_S1 S1_mono)
huffman@23111
   618
    hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
huffman@23111
   619
      by (simp only: norm_setsum_f)
huffman@23111
   620
    show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
huffman@23111
   621
    proof (intro exI allI impI)
huffman@23111
   622
      fix n assume "2 * N \<le> n"
huffman@23111
   623
      hence n: "N \<le> n div 2" by simp
huffman@23111
   624
      have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
huffman@23111
   625
        by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
huffman@23111
   626
                  Diff_mono subset_refl S1_le_S2)
huffman@23111
   627
      also have "\<dots> < r"
huffman@23111
   628
        using n div_le_dividend by (rule N)
huffman@23111
   629
      finally show "setsum ?f (?S1 n - ?S2 n) < r" .
huffman@23111
   630
    qed
huffman@23111
   631
  qed
huffman@23111
   632
  hence "Zseq (\<lambda>n. setsum ?g (?S1 n - ?S2 n))"
huffman@23111
   633
    apply (rule Zseq_le [rule_format])
huffman@23111
   634
    apply (simp only: norm_setsum_f)
huffman@23111
   635
    apply (rule order_trans [OF norm_setsum setsum_mono])
huffman@23111
   636
    apply (auto simp add: norm_mult_ineq)
huffman@23111
   637
    done
huffman@23111
   638
  hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
huffman@23111
   639
    by (simp only: LIMSEQ_Zseq_iff setsum_diff finite_S1 S2_le_S1 diff_0_right)
huffman@23111
   640
huffman@23111
   641
  with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   642
    by (rule LIMSEQ_diff_approach_zero2)
huffman@23111
   643
  thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
huffman@23111
   644
qed
huffman@23111
   645
huffman@23111
   646
lemma Cauchy_product:
huffman@23111
   647
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   648
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   649
  assumes b: "summable (\<lambda>k. norm (b k))"
huffman@23111
   650
  shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i=0..k. a i * b (k - i))"
huffman@23111
   651
by (rule Cauchy_product_sums [THEN sums_unique])
huffman@23111
   652
paulson@14416
   653
end