src/HOL/Hyperreal/Series.thy
author wenzelm
Thu Sep 28 23:42:43 2006 +0200 (2006-09-28)
changeset 20770 2c583720436e
parent 20692 6df83a636e67
child 20792 add17d26151b
permissions -rw-r--r--
fixed translations: CONST;
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
nipkow@15140
    13
imports SEQ Lim
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"
huffman@20692
    18
     (infixr "sums" 80)
wenzelm@19765
    19
   "f sums s = (%n. setsum f {0..<n}) ----> s"
paulson@10751
    20
huffman@20692
    21
   summable :: "(nat \<Rightarrow> 'a::real_normed_vector) \<Rightarrow> bool"
wenzelm@19765
    22
   "summable f = (\<exists>s. f sums s)"
paulson@14416
    23
huffman@20692
    24
   suminf   :: "(nat \<Rightarrow> 'a::real_normed_vector) \<Rightarrow> 'a"
huffman@20688
    25
   "suminf f = (THE s. f sums s)"
paulson@14416
    26
nipkow@15546
    27
syntax
huffman@20692
    28
  "_suminf" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a" ("\<Sum>_. _" [0, 10] 10)
nipkow@15546
    29
translations
wenzelm@20770
    30
  "\<Sum>i. b" == "CONST suminf (%i. b)"
nipkow@15546
    31
paulson@14416
    32
nipkow@15539
    33
lemma sumr_diff_mult_const:
nipkow@15539
    34
 "setsum f {0..<n} - (real n*r) = setsum (%i. f i - r) {0..<n::nat}"
nipkow@15536
    35
by (simp add: diff_minus setsum_addf real_of_nat_def)
nipkow@15536
    36
nipkow@15542
    37
lemma real_setsum_nat_ivl_bounded:
nipkow@15542
    38
     "(!!p. p < n \<Longrightarrow> f(p) \<le> K)
nipkow@15542
    39
      \<Longrightarrow> setsum f {0..<n::nat} \<le> real n * K"
nipkow@15542
    40
using setsum_bounded[where A = "{0..<n}"]
nipkow@15542
    41
by (auto simp:real_of_nat_def)
paulson@14416
    42
nipkow@15539
    43
(* Generalize from real to some algebraic structure? *)
nipkow@15539
    44
lemma sumr_minus_one_realpow_zero [simp]:
nipkow@15543
    45
  "(\<Sum>i=0..<2*n. (-1) ^ Suc i) = (0::real)"
paulson@15251
    46
by (induct "n", auto)
paulson@14416
    47
nipkow@15539
    48
(* FIXME this is an awful lemma! *)
nipkow@15539
    49
lemma sumr_one_lb_realpow_zero [simp]:
nipkow@15539
    50
  "(\<Sum>n=Suc 0..<n. f(n) * (0::real) ^ n) = 0"
huffman@20692
    51
by (rule setsum_0', simp)
paulson@14416
    52
nipkow@15543
    53
lemma sumr_group:
nipkow@15539
    54
     "(\<Sum>m=0..<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {0 ..< n * k}"
nipkow@15543
    55
apply (subgoal_tac "k = 0 | 0 < k", auto)
paulson@15251
    56
apply (induct "n")
nipkow@15539
    57
apply (simp_all add: setsum_add_nat_ivl add_commute)
paulson@14416
    58
done
nipkow@15539
    59
huffman@20692
    60
lemma sumr_offset3:
huffman@20692
    61
  "setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)) + setsum f {0..<k}"
huffman@20692
    62
apply (subst setsum_shift_bounds_nat_ivl [symmetric])
huffman@20692
    63
apply (simp add: setsum_add_nat_ivl add_commute)
huffman@20692
    64
done
huffman@20692
    65
avigad@16819
    66
lemma sumr_offset:
huffman@20692
    67
  fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
huffman@20692
    68
  shows "(\<Sum>m=0..<n. f(m+k)) = setsum f {0..<n+k} - setsum f {0..<k}"
huffman@20692
    69
by (simp add: sumr_offset3)
avigad@16819
    70
avigad@16819
    71
lemma sumr_offset2:
avigad@16819
    72
 "\<forall>f. (\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
huffman@20692
    73
by (simp add: sumr_offset)
avigad@16819
    74
avigad@16819
    75
lemma sumr_offset4:
huffman@20692
    76
  "\<forall>n f. setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
huffman@20692
    77
by (clarify, rule sumr_offset3)
avigad@16819
    78
avigad@16819
    79
(*
avigad@16819
    80
lemma sumr_from_1_from_0: "0 < n ==>
avigad@16819
    81
      (\<Sum>n=Suc 0 ..< Suc n. if even(n) then 0 else
avigad@16819
    82
             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n =
avigad@16819
    83
      (\<Sum>n=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
by (rule_tac n1 = 1 in sumr_split_add [THEN subst], auto)
avigad@16819
    86
*)
paulson@14416
    87
paulson@14416
    88
subsection{* Infinite Sums, by the Properties of Limits*}
paulson@14416
    89
paulson@14416
    90
(*----------------------
paulson@14416
    91
   suminf is the sum   
paulson@14416
    92
 ---------------------*)
paulson@14416
    93
lemma sums_summable: "f sums l ==> summable f"
paulson@14416
    94
by (simp add: sums_def summable_def, blast)
paulson@14416
    95
paulson@14416
    96
lemma summable_sums: "summable f ==> f sums (suminf f)"
huffman@20688
    97
apply (simp add: summable_def suminf_def sums_def)
huffman@20688
    98
apply (blast intro: theI LIMSEQ_unique)
paulson@14416
    99
done
paulson@14416
   100
paulson@14416
   101
lemma summable_sumr_LIMSEQ_suminf: 
nipkow@15539
   102
     "summable f ==> (%n. setsum f {0..<n}) ----> (suminf f)"
huffman@20688
   103
by (rule summable_sums [unfolded sums_def])
paulson@14416
   104
paulson@14416
   105
(*-------------------
paulson@14416
   106
    sum is unique                    
paulson@14416
   107
 ------------------*)
paulson@14416
   108
lemma sums_unique: "f sums s ==> (s = suminf f)"
paulson@14416
   109
apply (frule sums_summable [THEN summable_sums])
paulson@14416
   110
apply (auto intro!: LIMSEQ_unique simp add: sums_def)
paulson@14416
   111
done
paulson@14416
   112
avigad@16819
   113
lemma sums_split_initial_segment: "f sums s ==> 
avigad@16819
   114
  (%n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
avigad@16819
   115
  apply (unfold sums_def);
avigad@16819
   116
  apply (simp add: sumr_offset); 
avigad@16819
   117
  apply (rule LIMSEQ_diff_const)
avigad@16819
   118
  apply (rule LIMSEQ_ignore_initial_segment)
avigad@16819
   119
  apply assumption
avigad@16819
   120
done
avigad@16819
   121
avigad@16819
   122
lemma summable_ignore_initial_segment: "summable f ==> 
avigad@16819
   123
    summable (%n. f(n + k))"
avigad@16819
   124
  apply (unfold summable_def)
avigad@16819
   125
  apply (auto intro: sums_split_initial_segment)
avigad@16819
   126
done
avigad@16819
   127
avigad@16819
   128
lemma suminf_minus_initial_segment: "summable f ==>
avigad@16819
   129
    suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
avigad@16819
   130
  apply (frule summable_ignore_initial_segment)
avigad@16819
   131
  apply (rule sums_unique [THEN sym])
avigad@16819
   132
  apply (frule summable_sums)
avigad@16819
   133
  apply (rule sums_split_initial_segment)
avigad@16819
   134
  apply auto
avigad@16819
   135
done
avigad@16819
   136
avigad@16819
   137
lemma suminf_split_initial_segment: "summable f ==> 
avigad@16819
   138
    suminf f = (SUM i = 0..< k. f i) + suminf (%n. f(n + k))"
avigad@16819
   139
by (auto simp add: suminf_minus_initial_segment)
avigad@16819
   140
paulson@14416
   141
lemma series_zero: 
nipkow@15539
   142
     "(\<forall>m. n \<le> m --> f(m) = 0) ==> f sums (setsum f {0..<n})"
nipkow@15537
   143
apply (simp add: sums_def LIMSEQ_def diff_minus[symmetric], safe)
paulson@14416
   144
apply (rule_tac x = n in exI)
nipkow@15542
   145
apply (clarsimp simp add:setsum_diff[symmetric] cong:setsum_ivl_cong)
paulson@14416
   146
done
paulson@14416
   147
avigad@16819
   148
lemma sums_zero: "(%n. 0) sums 0";
avigad@16819
   149
  apply (unfold sums_def);
avigad@16819
   150
  apply simp;
avigad@16819
   151
  apply (rule LIMSEQ_const);
avigad@16819
   152
done;
nipkow@15539
   153
avigad@16819
   154
lemma summable_zero: "summable (%n. 0)";
avigad@16819
   155
  apply (rule sums_summable);
avigad@16819
   156
  apply (rule sums_zero);
avigad@16819
   157
done;
avigad@16819
   158
avigad@16819
   159
lemma suminf_zero: "suminf (%n. 0) = 0";
avigad@16819
   160
  apply (rule sym);
avigad@16819
   161
  apply (rule sums_unique);
avigad@16819
   162
  apply (rule sums_zero);
avigad@16819
   163
done;
avigad@16819
   164
  
huffman@20692
   165
lemma sums_mult:
huffman@20692
   166
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   167
  shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
ballarin@19279
   168
by (auto simp add: sums_def setsum_right_distrib [symmetric]
paulson@14416
   169
         intro!: LIMSEQ_mult intro: LIMSEQ_const)
paulson@14416
   170
huffman@20692
   171
lemma summable_mult:
huffman@20692
   172
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   173
  shows "summable f \<Longrightarrow> summable (%n. c * f n)";
avigad@16819
   174
  apply (unfold summable_def);
avigad@16819
   175
  apply (auto intro: sums_mult);
avigad@16819
   176
done;
avigad@16819
   177
huffman@20692
   178
lemma suminf_mult:
huffman@20692
   179
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   180
  shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f";
avigad@16819
   181
  apply (rule sym);
avigad@16819
   182
  apply (rule sums_unique);
avigad@16819
   183
  apply (rule sums_mult);
avigad@16819
   184
  apply (erule summable_sums);
avigad@16819
   185
done;
avigad@16819
   186
huffman@20692
   187
lemma sums_mult2:
huffman@20692
   188
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   189
  shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
huffman@20692
   190
by (auto simp add: sums_def setsum_left_distrib [symmetric]
huffman@20692
   191
         intro!: LIMSEQ_mult LIMSEQ_const)
avigad@16819
   192
huffman@20692
   193
lemma summable_mult2:
huffman@20692
   194
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   195
  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
avigad@16819
   196
  apply (unfold summable_def)
avigad@16819
   197
  apply (auto intro: sums_mult2)
avigad@16819
   198
done
avigad@16819
   199
huffman@20692
   200
lemma suminf_mult2:
huffman@20692
   201
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   202
  shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
huffman@20692
   203
by (auto intro!: sums_unique sums_mult2 summable_sums)
avigad@16819
   204
huffman@20692
   205
lemma sums_divide:
huffman@20692
   206
  fixes c :: "'a::real_normed_field"
huffman@20692
   207
  shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
huffman@20692
   208
by (simp add: divide_inverse sums_mult2)
paulson@14416
   209
huffman@20692
   210
lemma summable_divide:
huffman@20692
   211
  fixes c :: "'a::real_normed_field"
huffman@20692
   212
  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
avigad@16819
   213
  apply (unfold summable_def);
avigad@16819
   214
  apply (auto intro: sums_divide);
avigad@16819
   215
done;
avigad@16819
   216
huffman@20692
   217
lemma suminf_divide:
huffman@20692
   218
  fixes c :: "'a::real_normed_field"
huffman@20692
   219
  shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
avigad@16819
   220
  apply (rule sym);
avigad@16819
   221
  apply (rule sums_unique);
avigad@16819
   222
  apply (rule sums_divide);
avigad@16819
   223
  apply (erule summable_sums);
avigad@16819
   224
done;
avigad@16819
   225
avigad@16819
   226
lemma sums_add: "[| x sums x0; y sums y0 |] ==> (%n. x n + y n) sums (x0+y0)"
avigad@16819
   227
by (auto simp add: sums_def setsum_addf intro: LIMSEQ_add)
avigad@16819
   228
avigad@16819
   229
lemma summable_add: "summable f ==> summable g ==> summable (%x. f x + g x)";
avigad@16819
   230
  apply (unfold summable_def);
avigad@16819
   231
  apply clarify;
avigad@16819
   232
  apply (rule exI);
avigad@16819
   233
  apply (erule sums_add);
avigad@16819
   234
  apply assumption;
avigad@16819
   235
done;
avigad@16819
   236
avigad@16819
   237
lemma suminf_add:
avigad@16819
   238
     "[| summable f; summable g |]   
avigad@16819
   239
      ==> suminf f + suminf g  = (\<Sum>n. f n + g n)"
avigad@16819
   240
by (auto intro!: sums_add sums_unique summable_sums)
avigad@16819
   241
paulson@14416
   242
lemma sums_diff: "[| x sums x0; y sums y0 |] ==> (%n. x n - y n) sums (x0-y0)"
nipkow@15536
   243
by (auto simp add: sums_def setsum_subtractf intro: LIMSEQ_diff)
paulson@14416
   244
avigad@16819
   245
lemma summable_diff: "summable f ==> summable g ==> summable (%x. f x - g x)";
avigad@16819
   246
  apply (unfold summable_def);
avigad@16819
   247
  apply clarify;
avigad@16819
   248
  apply (rule exI);
avigad@16819
   249
  apply (erule sums_diff);
avigad@16819
   250
  apply assumption;
avigad@16819
   251
done;
paulson@14416
   252
paulson@14416
   253
lemma suminf_diff:
paulson@14416
   254
     "[| summable f; summable g |]   
nipkow@15546
   255
      ==> suminf f - suminf g  = (\<Sum>n. f n - g n)"
paulson@14416
   256
by (auto intro!: sums_diff sums_unique summable_sums)
paulson@14416
   257
avigad@16819
   258
lemma sums_minus: "f sums s ==> (%x. - f x) sums (- s)";
avigad@16819
   259
  by (simp add: sums_def setsum_negf LIMSEQ_minus);
avigad@16819
   260
avigad@16819
   261
lemma summable_minus: "summable f ==> summable (%x. - f x)";
avigad@16819
   262
  by (auto simp add: summable_def intro: sums_minus);
avigad@16819
   263
avigad@16819
   264
lemma suminf_minus: "summable f ==> suminf (%x. - f x) = - (suminf f)";
avigad@16819
   265
  apply (rule sym);
avigad@16819
   266
  apply (rule sums_unique);
avigad@16819
   267
  apply (rule sums_minus);
avigad@16819
   268
  apply (erule summable_sums);
avigad@16819
   269
done;
paulson@14416
   270
paulson@14416
   271
lemma sums_group:
nipkow@15539
   272
     "[|summable f; 0 < k |] ==> (%n. setsum f {n*k..<n*k+k}) sums (suminf f)"
paulson@14416
   273
apply (drule summable_sums)
huffman@20692
   274
apply (simp only: sums_def sumr_group)
huffman@20692
   275
apply (unfold LIMSEQ_def, safe)
huffman@20692
   276
apply (drule_tac x="r" in spec, safe)
huffman@20692
   277
apply (rule_tac x="no" in exI, safe)
huffman@20692
   278
apply (drule_tac x="n*k" in spec)
huffman@20692
   279
apply (erule mp)
huffman@20692
   280
apply (erule order_trans)
huffman@20692
   281
apply simp
paulson@14416
   282
done
paulson@14416
   283
paulson@15085
   284
text{*A summable series of positive terms has limit that is at least as
paulson@15085
   285
great as any partial sum.*}
paulson@14416
   286
huffman@20692
   287
lemma series_pos_le:
huffman@20692
   288
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   289
  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
paulson@14416
   290
apply (drule summable_sums)
paulson@14416
   291
apply (simp add: sums_def)
nipkow@15539
   292
apply (cut_tac k = "setsum f {0..<n}" in LIMSEQ_const)
nipkow@15539
   293
apply (erule LIMSEQ_le, blast)
huffman@20692
   294
apply (rule_tac x="n" in exI, clarify)
nipkow@15539
   295
apply (rule setsum_mono2)
nipkow@15539
   296
apply auto
paulson@14416
   297
done
paulson@14416
   298
paulson@14416
   299
lemma series_pos_less:
huffman@20692
   300
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   301
  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
huffman@20692
   302
apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
huffman@20692
   303
apply simp
huffman@20692
   304
apply (erule series_pos_le)
huffman@20692
   305
apply (simp add: order_less_imp_le)
huffman@20692
   306
done
huffman@20692
   307
huffman@20692
   308
lemma suminf_gt_zero:
huffman@20692
   309
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   310
  shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
huffman@20692
   311
by (drule_tac n="0" in series_pos_less, simp_all)
huffman@20692
   312
huffman@20692
   313
lemma suminf_ge_zero:
huffman@20692
   314
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   315
  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
huffman@20692
   316
by (drule_tac n="0" in series_pos_le, simp_all)
huffman@20692
   317
huffman@20692
   318
lemma sumr_pos_lt_pair:
huffman@20692
   319
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   320
  shows "\<lbrakk>summable f;
huffman@20692
   321
        \<forall>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
huffman@20692
   322
      \<Longrightarrow> setsum f {0..<k} < suminf f"
huffman@20692
   323
apply (subst suminf_split_initial_segment [where k="k"])
huffman@20692
   324
apply assumption
huffman@20692
   325
apply simp
huffman@20692
   326
apply (drule_tac k="k" in summable_ignore_initial_segment)
huffman@20692
   327
apply (drule_tac k="Suc (Suc 0)" in sums_group, simp)
huffman@20692
   328
apply simp
huffman@20692
   329
apply (frule sums_unique)
huffman@20692
   330
apply (drule sums_summable)
huffman@20692
   331
apply simp
huffman@20692
   332
apply (erule suminf_gt_zero)
huffman@20692
   333
apply (simp add: add_ac)
paulson@14416
   334
done
paulson@14416
   335
paulson@15085
   336
text{*Sum of a geometric progression.*}
paulson@14416
   337
ballarin@17149
   338
lemmas sumr_geometric = geometric_sum [where 'a = real]
paulson@14416
   339
huffman@20692
   340
lemma geometric_sums:
huffman@20692
   341
  fixes x :: "'a::{real_normed_field,recpower,division_by_zero}"
huffman@20692
   342
  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) sums (1 / (1 - x))"
huffman@20692
   343
proof -
huffman@20692
   344
  assume less_1: "norm x < 1"
huffman@20692
   345
  hence neq_1: "x \<noteq> 1" by auto
huffman@20692
   346
  hence neq_0: "x - 1 \<noteq> 0" by simp
huffman@20692
   347
  from less_1 have lim_0: "(\<lambda>n. x ^ n) ----> 0"
huffman@20692
   348
    by (rule LIMSEQ_power_zero)
huffman@20692
   349
  hence "(\<lambda>n. x ^ n / (x - 1) - 1 / (x - 1)) ----> 0 / (x - 1) - 1 / (x
huffman@20692
   350
- 1)"
huffman@20692
   351
    using neq_0 by (intro LIMSEQ_divide LIMSEQ_diff LIMSEQ_const)
huffman@20692
   352
  hence "(\<lambda>n. (x ^ n - 1) / (x - 1)) ----> 1 / (1 - x)"
huffman@20692
   353
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
huffman@20692
   354
  thus "(\<lambda>n. x ^ n) sums (1 / (1 - x))"
huffman@20692
   355
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   356
qed
huffman@20692
   357
huffman@20692
   358
lemma summable_geometric:
huffman@20692
   359
  fixes x :: "'a::{real_normed_field,recpower,division_by_zero}"
huffman@20692
   360
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@20692
   361
by (rule geometric_sums [THEN sums_summable])
paulson@14416
   362
paulson@15085
   363
text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
paulson@15085
   364
nipkow@15539
   365
lemma summable_convergent_sumr_iff:
nipkow@15539
   366
 "summable f = convergent (%n. setsum f {0..<n})"
paulson@14416
   367
by (simp add: summable_def sums_def convergent_def)
paulson@14416
   368
huffman@20689
   369
lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
huffman@20689
   370
apply (drule summable_convergent_sumr_iff [THEN iffD1])
huffman@20692
   371
apply (drule convergent_Cauchy)
huffman@20689
   372
apply (simp only: Cauchy_def LIMSEQ_def, safe)
huffman@20689
   373
apply (drule_tac x="r" in spec, safe)
huffman@20689
   374
apply (rule_tac x="M" in exI, safe)
huffman@20689
   375
apply (drule_tac x="Suc n" in spec, simp)
huffman@20689
   376
apply (drule_tac x="n" in spec, simp)
huffman@20689
   377
done
huffman@20689
   378
paulson@14416
   379
lemma summable_Cauchy:
huffman@20692
   380
     "summable (f::nat \<Rightarrow> real) =  
nipkow@15539
   381
      (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. abs(setsum f {m..<n}) < e)"
huffman@20410
   382
apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_def diff_minus [symmetric], safe)
huffman@20410
   383
apply (drule spec, drule (1) mp)
huffman@20410
   384
apply (erule exE, rule_tac x="M" in exI, clarify)
huffman@20410
   385
apply (rule_tac x="m" and y="n" in linorder_le_cases)
huffman@20410
   386
apply (frule (1) order_trans)
huffman@20410
   387
apply (drule_tac x="n" in spec, drule (1) mp)
huffman@20410
   388
apply (drule_tac x="m" in spec, drule (1) mp)
huffman@20410
   389
apply (simp add: setsum_diff [symmetric])
huffman@20410
   390
apply simp
huffman@20410
   391
apply (drule spec, drule (1) mp)
huffman@20410
   392
apply (erule exE, rule_tac x="N" in exI, clarify)
huffman@20410
   393
apply (rule_tac x="m" and y="n" in linorder_le_cases)
huffman@20552
   394
apply (subst norm_minus_commute)
huffman@20410
   395
apply (simp add: setsum_diff [symmetric])
huffman@20410
   396
apply (simp add: setsum_diff [symmetric])
paulson@14416
   397
done
paulson@14416
   398
paulson@15085
   399
text{*Comparison test*}
paulson@15085
   400
huffman@20692
   401
lemma norm_setsum:
huffman@20692
   402
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@20692
   403
  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
huffman@20692
   404
apply (case_tac "finite A")
huffman@20692
   405
apply (erule finite_induct)
huffman@20692
   406
apply simp
huffman@20692
   407
apply simp
huffman@20692
   408
apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
huffman@20692
   409
apply simp
huffman@20692
   410
done
huffman@20692
   411
paulson@14416
   412
lemma summable_comparison_test:
huffman@20692
   413
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   414
  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
huffman@20692
   415
apply (simp add: summable_Cauchy, safe)
huffman@20692
   416
apply (drule_tac x="e" in spec, safe)
huffman@20692
   417
apply (rule_tac x = "N + Na" in exI, safe)
paulson@14416
   418
apply (rotate_tac 2)
paulson@14416
   419
apply (drule_tac x = m in spec)
paulson@14416
   420
apply (auto, rotate_tac 2, drule_tac x = n in spec)
nipkow@15539
   421
apply (rule_tac y = "\<Sum>k=m..<n. abs(f k)" in order_le_less_trans)
nipkow@15536
   422
apply (rule setsum_abs)
nipkow@15539
   423
apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
nipkow@15539
   424
apply (auto intro: setsum_mono simp add: abs_interval_iff)
paulson@14416
   425
done
paulson@14416
   426
paulson@14416
   427
lemma summable_rabs_comparison_test:
huffman@20692
   428
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   429
  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
   430
apply (rule summable_comparison_test)
nipkow@15543
   431
apply (auto)
paulson@14416
   432
done
paulson@14416
   433
paulson@15085
   434
text{*Limit comparison property for series (c.f. jrh)*}
paulson@15085
   435
paulson@14416
   436
lemma summable_le:
huffman@20692
   437
  fixes f g :: "nat \<Rightarrow> real"
huffman@20692
   438
  shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
paulson@14416
   439
apply (drule summable_sums)+
huffman@20692
   440
apply (simp only: sums_def, erule (1) LIMSEQ_le)
paulson@14416
   441
apply (rule exI)
nipkow@15539
   442
apply (auto intro!: setsum_mono)
paulson@14416
   443
done
paulson@14416
   444
paulson@14416
   445
lemma summable_le2:
huffman@20692
   446
  fixes f g :: "nat \<Rightarrow> real"
huffman@20692
   447
  shows "\<lbrakk>\<forall>n. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f \<and> suminf f \<le> suminf g"
paulson@14416
   448
apply (auto intro: summable_comparison_test intro!: summable_le)
paulson@14416
   449
apply (simp add: abs_le_interval_iff)
paulson@14416
   450
done
paulson@14416
   451
kleing@19106
   452
(* specialisation for the common 0 case *)
kleing@19106
   453
lemma suminf_0_le:
kleing@19106
   454
  fixes f::"nat\<Rightarrow>real"
kleing@19106
   455
  assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
kleing@19106
   456
  shows "0 \<le> suminf f"
kleing@19106
   457
proof -
kleing@19106
   458
  let ?g = "(\<lambda>n. (0::real))"
kleing@19106
   459
  from gt0 have "\<forall>n. ?g n \<le> f n" by simp
kleing@19106
   460
  moreover have "summable ?g" by (rule summable_zero)
kleing@19106
   461
  moreover from sm have "summable f" .
kleing@19106
   462
  ultimately have "suminf ?g \<le> suminf f" by (rule summable_le)
kleing@19106
   463
  then show "0 \<le> suminf f" by (simp add: suminf_zero)
kleing@19106
   464
qed 
kleing@19106
   465
kleing@19106
   466
paulson@15085
   467
text{*Absolute convergence imples normal convergence*}
huffman@20692
   468
lemma summable_rabs_cancel:
huffman@20692
   469
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   470
  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
huffman@20692
   471
apply (simp only: summable_Cauchy, safe)
huffman@20692
   472
apply (drule_tac x="e" in spec, safe)
huffman@20692
   473
apply (rule_tac x="N" in exI, safe)
huffman@20692
   474
apply (drule_tac x="m" in spec, safe)
huffman@20692
   475
apply (rule order_le_less_trans [OF setsum_abs])
huffman@20692
   476
apply simp
paulson@14416
   477
done
paulson@14416
   478
paulson@15085
   479
text{*Absolute convergence of series*}
paulson@14416
   480
lemma summable_rabs:
huffman@20692
   481
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   482
  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
nipkow@15536
   483
by (auto intro: LIMSEQ_le LIMSEQ_imp_rabs summable_rabs_cancel summable_sumr_LIMSEQ_suminf)
paulson@14416
   484
paulson@14416
   485
paulson@14416
   486
subsection{* The Ratio Test*}
paulson@14416
   487
paulson@14416
   488
lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
paulson@14416
   489
apply (drule order_le_imp_less_or_eq, auto)
paulson@14416
   490
apply (subgoal_tac "0 \<le> c * abs y")
paulson@14416
   491
apply (simp add: zero_le_mult_iff, arith)
paulson@14416
   492
done
paulson@14416
   493
paulson@14416
   494
lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
paulson@14416
   495
apply (drule le_imp_less_or_eq)
paulson@14416
   496
apply (auto dest: less_imp_Suc_add)
paulson@14416
   497
done
paulson@14416
   498
paulson@14416
   499
lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
paulson@14416
   500
by (auto simp add: le_Suc_ex)
paulson@14416
   501
paulson@14416
   502
(*All this trouble just to get 0<c *)
paulson@14416
   503
lemma ratio_test_lemma2:
huffman@20692
   504
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   505
  shows "\<lbrakk>\<forall>n\<ge>N. \<bar>f (Suc n)\<bar> \<le> c * \<bar>f n\<bar>\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
paulson@14416
   506
apply (simp (no_asm) add: linorder_not_le [symmetric])
paulson@14416
   507
apply (simp add: summable_Cauchy)
nipkow@15543
   508
apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
nipkow@15543
   509
 prefer 2
nipkow@15543
   510
 apply clarify
nipkow@15543
   511
 apply(erule_tac x = "n - 1" in allE)
nipkow@15543
   512
 apply (simp add:diff_Suc split:nat.splits)
nipkow@15543
   513
 apply (blast intro: rabs_ratiotest_lemma)
paulson@14416
   514
apply (rule_tac x = "Suc N" in exI, clarify)
nipkow@15543
   515
apply(simp cong:setsum_ivl_cong)
paulson@14416
   516
done
paulson@14416
   517
paulson@14416
   518
lemma ratio_test:
huffman@20692
   519
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   520
  shows "\<lbrakk>c < 1; \<forall>n\<ge>N. \<bar>f (Suc n)\<bar> \<le> c * \<bar>f n\<bar>\<rbrakk> \<Longrightarrow> summable f"
paulson@14416
   521
apply (frule ratio_test_lemma2, auto)
paulson@15234
   522
apply (rule_tac g = "%n. (abs (f N) / (c ^ N))*c ^ n" 
paulson@15234
   523
       in summable_comparison_test)
paulson@14416
   524
apply (rule_tac x = N in exI, safe)
paulson@14416
   525
apply (drule le_Suc_ex_iff [THEN iffD1])
paulson@14416
   526
apply (auto simp add: power_add realpow_not_zero)
nipkow@15539
   527
apply (induct_tac "na", auto)
paulson@14416
   528
apply (rule_tac y = "c*abs (f (N + n))" in order_trans)
paulson@14416
   529
apply (auto intro: mult_right_mono simp add: summable_def)
paulson@14416
   530
apply (simp add: mult_ac)
paulson@15234
   531
apply (rule_tac x = "abs (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
paulson@15234
   532
apply (rule sums_divide) 
paulson@15234
   533
apply (rule sums_mult) 
paulson@15234
   534
apply (auto intro!: geometric_sums)
paulson@14416
   535
done
paulson@14416
   536
paulson@14416
   537
paulson@15085
   538
text{*Differentiation of finite sum*}
paulson@14416
   539
paulson@14416
   540
lemma DERIV_sumr [rule_format (no_asm)]:
paulson@14416
   541
     "(\<forall>r. m \<le> r & r < (m + n) --> DERIV (%x. f r x) x :> (f' r x))  
nipkow@15539
   542
      --> DERIV (%x. \<Sum>n=m..<n::nat. f n x) x :> (\<Sum>r=m..<n. f' r x)"
paulson@15251
   543
apply (induct "n")
paulson@14416
   544
apply (auto intro: DERIV_add)
paulson@14416
   545
done
paulson@14416
   546
paulson@14416
   547
end