src/HOL/Hyperreal/Series.thy
author ballarin
Fri Aug 26 10:01:06 2005 +0200 (2005-08-26)
changeset 17149 e2b19c92ef51
parent 16819 00d8f9300d13
child 19106 6e6b5b1fdc06
permissions -rw-r--r--
Lemmas on dvd, power and finite summation added or strengthened.
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
nipkow@15539
    16
declare atLeastLessThan_iff[iff]
nipkow@15561
    17
declare setsum_op_ivl_Suc[simp]
paulson@10751
    18
paulson@10751
    19
constdefs
nipkow@15543
    20
   sums  :: "(nat => real) => real => bool"     (infixr "sums" 80)
nipkow@15536
    21
   "f sums s  == (%n. setsum f {0..<n}) ----> s"
paulson@10751
    22
paulson@14416
    23
   summable :: "(nat=>real) => bool"
paulson@14416
    24
   "summable f == (\<exists>s. f sums s)"
paulson@14416
    25
paulson@14416
    26
   suminf   :: "(nat=>real) => real"
nipkow@15539
    27
   "suminf f == SOME s. f sums s"
paulson@14416
    28
nipkow@15546
    29
syntax
nipkow@15546
    30
  "_suminf" :: "idt => real => real"    ("\<Sum>_. _" [0, 10] 10)
nipkow@15546
    31
translations
nipkow@15546
    32
  "\<Sum>i. b" == "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"
paulson@15251
    53
apply (induct "n")
paulson@14416
    54
apply (case_tac [2] "n", auto)
paulson@14416
    55
done
paulson@14416
    56
nipkow@15543
    57
lemma sumr_group:
nipkow@15539
    58
     "(\<Sum>m=0..<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {0 ..< n * k}"
nipkow@15543
    59
apply (subgoal_tac "k = 0 | 0 < k", auto)
paulson@15251
    60
apply (induct "n")
nipkow@15539
    61
apply (simp_all add: setsum_add_nat_ivl add_commute)
paulson@14416
    62
done
nipkow@15539
    63
avigad@16819
    64
(* FIXME generalize? *)
avigad@16819
    65
lemma sumr_offset:
avigad@16819
    66
 "(\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
avigad@16819
    67
by (induct "n", auto)
avigad@16819
    68
avigad@16819
    69
lemma sumr_offset2:
avigad@16819
    70
 "\<forall>f. (\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
avigad@16819
    71
by (induct "n", auto)
avigad@16819
    72
avigad@16819
    73
lemma sumr_offset3:
avigad@16819
    74
  "setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
avigad@16819
    75
by (simp  add: sumr_offset)
avigad@16819
    76
avigad@16819
    77
lemma sumr_offset4:
avigad@16819
    78
 "\<forall>n f. setsum f {0::nat..<n+k} =
avigad@16819
    79
        (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
avigad@16819
    80
by (simp add: sumr_offset)
avigad@16819
    81
avigad@16819
    82
(*
avigad@16819
    83
lemma sumr_from_1_from_0: "0 < n ==>
avigad@16819
    84
      (\<Sum>n=Suc 0 ..< Suc n. if even(n) then 0 else
avigad@16819
    85
             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n =
avigad@16819
    86
      (\<Sum>n=0..<Suc n. if even(n) then 0 else
avigad@16819
    87
             ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n"
avigad@16819
    88
by (rule_tac n1 = 1 in sumr_split_add [THEN subst], auto)
avigad@16819
    89
*)
paulson@14416
    90
paulson@14416
    91
subsection{* Infinite Sums, by the Properties of Limits*}
paulson@14416
    92
paulson@14416
    93
(*----------------------
paulson@14416
    94
   suminf is the sum   
paulson@14416
    95
 ---------------------*)
paulson@14416
    96
lemma sums_summable: "f sums l ==> summable f"
paulson@14416
    97
by (simp add: sums_def summable_def, blast)
paulson@14416
    98
paulson@14416
    99
lemma summable_sums: "summable f ==> f sums (suminf f)"
paulson@14416
   100
apply (simp add: summable_def suminf_def)
paulson@14416
   101
apply (blast intro: someI2)
paulson@14416
   102
done
paulson@14416
   103
paulson@14416
   104
lemma summable_sumr_LIMSEQ_suminf: 
nipkow@15539
   105
     "summable f ==> (%n. setsum f {0..<n}) ----> (suminf f)"
paulson@14416
   106
apply (simp add: summable_def suminf_def sums_def)
paulson@14416
   107
apply (blast intro: someI2)
paulson@14416
   108
done
paulson@14416
   109
paulson@14416
   110
(*-------------------
paulson@14416
   111
    sum is unique                    
paulson@14416
   112
 ------------------*)
paulson@14416
   113
lemma sums_unique: "f sums s ==> (s = suminf f)"
paulson@14416
   114
apply (frule sums_summable [THEN summable_sums])
paulson@14416
   115
apply (auto intro!: LIMSEQ_unique simp add: sums_def)
paulson@14416
   116
done
paulson@14416
   117
avigad@16819
   118
lemma sums_split_initial_segment: "f sums s ==> 
avigad@16819
   119
  (%n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
avigad@16819
   120
  apply (unfold sums_def);
avigad@16819
   121
  apply (simp add: sumr_offset); 
avigad@16819
   122
  apply (rule LIMSEQ_diff_const)
avigad@16819
   123
  apply (rule LIMSEQ_ignore_initial_segment)
avigad@16819
   124
  apply assumption
avigad@16819
   125
done
avigad@16819
   126
avigad@16819
   127
lemma summable_ignore_initial_segment: "summable f ==> 
avigad@16819
   128
    summable (%n. f(n + k))"
avigad@16819
   129
  apply (unfold summable_def)
avigad@16819
   130
  apply (auto intro: sums_split_initial_segment)
avigad@16819
   131
done
avigad@16819
   132
avigad@16819
   133
lemma suminf_minus_initial_segment: "summable f ==>
avigad@16819
   134
    suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
avigad@16819
   135
  apply (frule summable_ignore_initial_segment)
avigad@16819
   136
  apply (rule sums_unique [THEN sym])
avigad@16819
   137
  apply (frule summable_sums)
avigad@16819
   138
  apply (rule sums_split_initial_segment)
avigad@16819
   139
  apply auto
avigad@16819
   140
done
avigad@16819
   141
avigad@16819
   142
lemma suminf_split_initial_segment: "summable f ==> 
avigad@16819
   143
    suminf f = (SUM i = 0..< k. f i) + suminf (%n. f(n + k))"
avigad@16819
   144
by (auto simp add: suminf_minus_initial_segment)
avigad@16819
   145
paulson@14416
   146
lemma series_zero: 
nipkow@15539
   147
     "(\<forall>m. n \<le> m --> f(m) = 0) ==> f sums (setsum f {0..<n})"
nipkow@15537
   148
apply (simp add: sums_def LIMSEQ_def diff_minus[symmetric], safe)
paulson@14416
   149
apply (rule_tac x = n in exI)
nipkow@15542
   150
apply (clarsimp simp add:setsum_diff[symmetric] cong:setsum_ivl_cong)
paulson@14416
   151
done
paulson@14416
   152
avigad@16819
   153
lemma sums_zero: "(%n. 0) sums 0";
avigad@16819
   154
  apply (unfold sums_def);
avigad@16819
   155
  apply simp;
avigad@16819
   156
  apply (rule LIMSEQ_const);
avigad@16819
   157
done;
nipkow@15539
   158
avigad@16819
   159
lemma summable_zero: "summable (%n. 0)";
avigad@16819
   160
  apply (rule sums_summable);
avigad@16819
   161
  apply (rule sums_zero);
avigad@16819
   162
done;
avigad@16819
   163
avigad@16819
   164
lemma suminf_zero: "suminf (%n. 0) = 0";
avigad@16819
   165
  apply (rule sym);
avigad@16819
   166
  apply (rule sums_unique);
avigad@16819
   167
  apply (rule sums_zero);
avigad@16819
   168
done;
avigad@16819
   169
  
avigad@16819
   170
lemma sums_mult: "f sums a ==> (%n. c * f n) sums (c * a)"
nipkow@15536
   171
by (auto simp add: sums_def setsum_mult [symmetric]
paulson@14416
   172
         intro!: LIMSEQ_mult intro: LIMSEQ_const)
paulson@14416
   173
avigad@16819
   174
lemma summable_mult: "summable f ==> summable (%n. c * f n)";
avigad@16819
   175
  apply (unfold summable_def);
avigad@16819
   176
  apply (auto intro: sums_mult);
avigad@16819
   177
done;
avigad@16819
   178
avigad@16819
   179
lemma suminf_mult: "summable f ==> suminf (%n. c * f n) = c * suminf f";
avigad@16819
   180
  apply (rule sym);
avigad@16819
   181
  apply (rule sums_unique);
avigad@16819
   182
  apply (rule sums_mult);
avigad@16819
   183
  apply (erule summable_sums);
avigad@16819
   184
done;
avigad@16819
   185
avigad@16819
   186
lemma sums_mult2: "f sums a ==> (%n. f n * c) sums (a * c)"
avigad@16819
   187
apply (subst mult_commute)
avigad@16819
   188
apply (subst mult_commute);back;
avigad@16819
   189
apply (erule sums_mult)
avigad@16819
   190
done
avigad@16819
   191
avigad@16819
   192
lemma summable_mult2: "summable f ==> summable (%n. f n * c)"
avigad@16819
   193
  apply (unfold summable_def)
avigad@16819
   194
  apply (auto intro: sums_mult2)
avigad@16819
   195
done
avigad@16819
   196
avigad@16819
   197
lemma suminf_mult2: "summable f ==> suminf f * c = (\<Sum>n. f n * c)"
avigad@16819
   198
by (auto intro!: sums_unique sums_mult summable_sums simp add: mult_commute)
avigad@16819
   199
avigad@16819
   200
lemma sums_divide: "f sums a ==> (%n. (f n)/c) sums (a/c)"
paulson@14416
   201
by (simp add: real_divide_def sums_mult mult_commute [of _ "inverse c"])
paulson@14416
   202
avigad@16819
   203
lemma summable_divide: "summable f ==> summable (%n. (f n) / c)";
avigad@16819
   204
  apply (unfold summable_def);
avigad@16819
   205
  apply (auto intro: sums_divide);
avigad@16819
   206
done;
avigad@16819
   207
avigad@16819
   208
lemma suminf_divide: "summable f ==> suminf (%n. (f n) / c) = (suminf f) / c";
avigad@16819
   209
  apply (rule sym);
avigad@16819
   210
  apply (rule sums_unique);
avigad@16819
   211
  apply (rule sums_divide);
avigad@16819
   212
  apply (erule summable_sums);
avigad@16819
   213
done;
avigad@16819
   214
avigad@16819
   215
lemma sums_add: "[| x sums x0; y sums y0 |] ==> (%n. x n + y n) sums (x0+y0)"
avigad@16819
   216
by (auto simp add: sums_def setsum_addf intro: LIMSEQ_add)
avigad@16819
   217
avigad@16819
   218
lemma summable_add: "summable f ==> summable g ==> summable (%x. f x + g x)";
avigad@16819
   219
  apply (unfold summable_def);
avigad@16819
   220
  apply clarify;
avigad@16819
   221
  apply (rule exI);
avigad@16819
   222
  apply (erule sums_add);
avigad@16819
   223
  apply assumption;
avigad@16819
   224
done;
avigad@16819
   225
avigad@16819
   226
lemma suminf_add:
avigad@16819
   227
     "[| summable f; summable g |]   
avigad@16819
   228
      ==> suminf f + suminf g  = (\<Sum>n. f n + g n)"
avigad@16819
   229
by (auto intro!: sums_add sums_unique summable_sums)
avigad@16819
   230
paulson@14416
   231
lemma sums_diff: "[| x sums x0; y sums y0 |] ==> (%n. x n - y n) sums (x0-y0)"
nipkow@15536
   232
by (auto simp add: sums_def setsum_subtractf intro: LIMSEQ_diff)
paulson@14416
   233
avigad@16819
   234
lemma summable_diff: "summable f ==> summable g ==> summable (%x. f x - g x)";
avigad@16819
   235
  apply (unfold summable_def);
avigad@16819
   236
  apply clarify;
avigad@16819
   237
  apply (rule exI);
avigad@16819
   238
  apply (erule sums_diff);
avigad@16819
   239
  apply assumption;
avigad@16819
   240
done;
paulson@14416
   241
paulson@14416
   242
lemma suminf_diff:
paulson@14416
   243
     "[| summable f; summable g |]   
nipkow@15546
   244
      ==> suminf f - suminf g  = (\<Sum>n. f n - g n)"
paulson@14416
   245
by (auto intro!: sums_diff sums_unique summable_sums)
paulson@14416
   246
avigad@16819
   247
lemma sums_minus: "f sums s ==> (%x. - f x) sums (- s)";
avigad@16819
   248
  by (simp add: sums_def setsum_negf LIMSEQ_minus);
avigad@16819
   249
avigad@16819
   250
lemma summable_minus: "summable f ==> summable (%x. - f x)";
avigad@16819
   251
  by (auto simp add: summable_def intro: sums_minus);
avigad@16819
   252
avigad@16819
   253
lemma suminf_minus: "summable f ==> suminf (%x. - f x) = - (suminf f)";
avigad@16819
   254
  apply (rule sym);
avigad@16819
   255
  apply (rule sums_unique);
avigad@16819
   256
  apply (rule sums_minus);
avigad@16819
   257
  apply (erule summable_sums);
avigad@16819
   258
done;
paulson@14416
   259
paulson@14416
   260
lemma sums_group:
nipkow@15539
   261
     "[|summable f; 0 < k |] ==> (%n. setsum f {n*k..<n*k+k}) sums (suminf f)"
paulson@14416
   262
apply (drule summable_sums)
nipkow@15543
   263
apply (auto simp add: sums_def LIMSEQ_def sumr_group)
paulson@14416
   264
apply (drule_tac x = r in spec, safe)
paulson@14416
   265
apply (rule_tac x = no in exI, safe)
paulson@14416
   266
apply (drule_tac x = "n*k" in spec)
paulson@14416
   267
apply (auto dest!: not_leE)
paulson@14416
   268
apply (drule_tac j = no in less_le_trans, auto)
paulson@14416
   269
done
paulson@14416
   270
paulson@14416
   271
lemma sumr_pos_lt_pair_lemma:
nipkow@15539
   272
  "[|\<forall>d. - f (n + (d + d)) < (f (Suc (n + (d + d))) :: real) |]
nipkow@15539
   273
   ==> setsum f {0..<n+Suc(Suc 0)} \<le> setsum f {0..<Suc(Suc 0) * Suc no + n}"
paulson@15251
   274
apply (induct "no", auto)
paulson@15251
   275
apply (drule_tac x = "Suc no" in spec)
nipkow@15539
   276
apply (simp add: add_ac)
nipkow@16733
   277
(* FIXME why does simp require a separate step to prove the (pure arithmetic)
nipkow@16733
   278
   left-over? With del cong: strong_setsum_cong it works!
nipkow@16733
   279
*)
nipkow@16733
   280
apply simp
paulson@14416
   281
done
paulson@10751
   282
paulson@10751
   283
paulson@14416
   284
lemma sumr_pos_lt_pair:
paulson@15234
   285
     "[|summable f; 
paulson@15234
   286
        \<forall>d. 0 < (f(n + (Suc(Suc 0) * d))) + f(n + ((Suc(Suc 0) * d) + 1))|]  
nipkow@15539
   287
      ==> setsum f {0..<n} < suminf f"
paulson@14416
   288
apply (drule summable_sums)
paulson@14416
   289
apply (auto simp add: sums_def LIMSEQ_def)
paulson@15234
   290
apply (drule_tac x = "f (n) + f (n + 1)" in spec)
paulson@15085
   291
apply (auto iff: real_0_less_add_iff)
paulson@15085
   292
   --{*legacy proof: not necessarily better!*}
paulson@14416
   293
apply (rule_tac [2] ccontr, drule_tac [2] linorder_not_less [THEN iffD1])
paulson@14416
   294
apply (frule_tac [2] no=no in sumr_pos_lt_pair_lemma) 
paulson@14416
   295
apply (drule_tac x = 0 in spec, simp)
paulson@14416
   296
apply (rotate_tac 1, drule_tac x = "Suc (Suc 0) * (Suc no) + n" in spec)
paulson@14416
   297
apply (safe, simp)
nipkow@15539
   298
apply (subgoal_tac "suminf f + (f (n) + f (n + 1)) \<le>
nipkow@15539
   299
 setsum f {0 ..< Suc (Suc 0) * (Suc no) + n}")
nipkow@15539
   300
apply (rule_tac [2] y = "setsum f {0..<n+ Suc (Suc 0)}" in order_trans)
paulson@14416
   301
prefer 3 apply assumption
nipkow@15539
   302
apply (rule_tac [2] y = "setsum f {0..<n} + (f (n) + f (n + 1))" in order_trans)
paulson@14416
   303
apply simp_all 
nipkow@15539
   304
apply (subgoal_tac "suminf f \<le> setsum f {0..< Suc (Suc 0) * (Suc no) + n}")
paulson@14416
   305
apply (rule_tac [2] y = "suminf f + (f (n) + f (n + 1))" in order_trans)
nipkow@15539
   306
prefer 3 apply simp
paulson@14416
   307
apply (drule_tac [2] x = 0 in spec)
paulson@14416
   308
 prefer 2 apply simp 
nipkow@15539
   309
apply (subgoal_tac "0 \<le> setsum f {0 ..< Suc (Suc 0) * Suc no + n} + - suminf f")
nipkow@15539
   310
apply (simp add: abs_if)
paulson@14416
   311
apply (auto simp add: linorder_not_less [symmetric])
paulson@14416
   312
done
paulson@14416
   313
paulson@15085
   314
text{*A summable series of positive terms has limit that is at least as
paulson@15085
   315
great as any partial sum.*}
paulson@14416
   316
paulson@14416
   317
lemma series_pos_le: 
nipkow@15539
   318
     "[| summable f; \<forall>m \<ge> n. 0 \<le> f(m) |] ==> setsum f {0..<n} \<le> suminf f"
paulson@14416
   319
apply (drule summable_sums)
paulson@14416
   320
apply (simp add: sums_def)
nipkow@15539
   321
apply (cut_tac k = "setsum f {0..<n}" in LIMSEQ_const)
nipkow@15539
   322
apply (erule LIMSEQ_le, blast)
nipkow@15539
   323
apply (rule_tac x = n in exI, clarify)
nipkow@15539
   324
apply (rule setsum_mono2)
nipkow@15539
   325
apply auto
paulson@14416
   326
done
paulson@14416
   327
paulson@14416
   328
lemma series_pos_less:
nipkow@15539
   329
     "[| summable f; \<forall>m \<ge> n. 0 < f(m) |] ==> setsum f {0..<n} < suminf f"
nipkow@15539
   330
apply (rule_tac y = "setsum f {0..<Suc n}" in order_less_le_trans)
paulson@14416
   331
apply (rule_tac [2] series_pos_le, auto)
paulson@14416
   332
apply (drule_tac x = m in spec, auto)
paulson@14416
   333
done
paulson@14416
   334
paulson@15085
   335
text{*Sum of a geometric progression.*}
paulson@14416
   336
ballarin@17149
   337
lemmas sumr_geometric = geometric_sum [where 'a = real]
paulson@14416
   338
paulson@14416
   339
lemma geometric_sums: "abs(x) < 1 ==> (%n. x ^ n) sums (1/(1 - x))"
paulson@14416
   340
apply (case_tac "x = 1")
paulson@15234
   341
apply (auto dest!: LIMSEQ_rabs_realpow_zero2 
paulson@15234
   342
        simp add: sumr_geometric sums_def diff_minus add_divide_distrib)
paulson@14416
   343
apply (subgoal_tac "1 / (1 + -x) = 0/ (x - 1) + - 1/ (x - 1) ")
paulson@14416
   344
apply (erule ssubst)
paulson@14416
   345
apply (rule LIMSEQ_add, rule LIMSEQ_divide)
paulson@15234
   346
apply (auto intro: LIMSEQ_const simp add: diff_minus minus_divide_right LIMSEQ_rabs_realpow_zero2)
paulson@14416
   347
done
paulson@14416
   348
paulson@15085
   349
text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
paulson@15085
   350
nipkow@15539
   351
lemma summable_convergent_sumr_iff:
nipkow@15539
   352
 "summable f = convergent (%n. setsum f {0..<n})"
paulson@14416
   353
by (simp add: summable_def sums_def convergent_def)
paulson@14416
   354
paulson@14416
   355
lemma summable_Cauchy:
paulson@14416
   356
     "summable f =  
nipkow@15539
   357
      (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. abs(setsum f {m..<n}) < e)"
nipkow@15537
   358
apply (auto simp add: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_def diff_minus[symmetric])
nipkow@15539
   359
apply (drule_tac [!] spec, auto)
paulson@14416
   360
apply (rule_tac x = M in exI)
paulson@14416
   361
apply (rule_tac [2] x = N in exI, auto)
paulson@14416
   362
apply (cut_tac [!] m = m and n = n in less_linear, auto)
paulson@14416
   363
apply (frule le_less_trans [THEN less_imp_le], assumption)
nipkow@15360
   364
apply (drule_tac x = n in spec, simp)
paulson@14416
   365
apply (drule_tac x = m in spec)
nipkow@15539
   366
apply(simp add: setsum_diff[symmetric])
nipkow@15537
   367
apply(subst abs_minus_commute)
nipkow@15539
   368
apply(simp add: setsum_diff[symmetric])
nipkow@15539
   369
apply(simp add: setsum_diff[symmetric])
paulson@14416
   370
done
paulson@14416
   371
paulson@15085
   372
text{*Comparison test*}
paulson@15085
   373
paulson@14416
   374
lemma summable_comparison_test:
nipkow@15360
   375
     "[| \<exists>N. \<forall>n \<ge> N. abs(f n) \<le> g n; summable g |] ==> summable f"
paulson@14416
   376
apply (auto simp add: summable_Cauchy)
paulson@14416
   377
apply (drule spec, auto)
paulson@14416
   378
apply (rule_tac x = "N + Na" in exI, auto)
paulson@14416
   379
apply (rotate_tac 2)
paulson@14416
   380
apply (drule_tac x = m in spec)
paulson@14416
   381
apply (auto, rotate_tac 2, drule_tac x = n in spec)
nipkow@15539
   382
apply (rule_tac y = "\<Sum>k=m..<n. abs(f k)" in order_le_less_trans)
nipkow@15536
   383
apply (rule setsum_abs)
nipkow@15539
   384
apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
nipkow@15539
   385
apply (auto intro: setsum_mono simp add: abs_interval_iff)
paulson@14416
   386
done
paulson@14416
   387
paulson@14416
   388
lemma summable_rabs_comparison_test:
nipkow@15360
   389
     "[| \<exists>N. \<forall>n \<ge> N. abs(f n) \<le> g n; summable g |] 
paulson@14416
   390
      ==> summable (%k. abs (f k))"
paulson@14416
   391
apply (rule summable_comparison_test)
nipkow@15543
   392
apply (auto)
paulson@14416
   393
done
paulson@14416
   394
paulson@15085
   395
text{*Limit comparison property for series (c.f. jrh)*}
paulson@15085
   396
paulson@14416
   397
lemma summable_le:
paulson@14416
   398
     "[|\<forall>n. f n \<le> g n; summable f; summable g |] ==> suminf f \<le> suminf g"
paulson@14416
   399
apply (drule summable_sums)+
paulson@14416
   400
apply (auto intro!: LIMSEQ_le simp add: sums_def)
paulson@14416
   401
apply (rule exI)
nipkow@15539
   402
apply (auto intro!: setsum_mono)
paulson@14416
   403
done
paulson@14416
   404
paulson@14416
   405
lemma summable_le2:
paulson@14416
   406
     "[|\<forall>n. abs(f n) \<le> g n; summable g |]  
paulson@14416
   407
      ==> summable f & suminf f \<le> suminf g"
paulson@14416
   408
apply (auto intro: summable_comparison_test intro!: summable_le)
paulson@14416
   409
apply (simp add: abs_le_interval_iff)
paulson@14416
   410
done
paulson@14416
   411
paulson@15085
   412
text{*Absolute convergence imples normal convergence*}
paulson@14416
   413
lemma summable_rabs_cancel: "summable (%n. abs (f n)) ==> summable f"
nipkow@15536
   414
apply (auto simp add: summable_Cauchy)
paulson@14416
   415
apply (drule spec, auto)
paulson@14416
   416
apply (rule_tac x = N in exI, auto)
paulson@14416
   417
apply (drule spec, auto)
nipkow@15539
   418
apply (rule_tac y = "\<Sum>n=m..<n. abs(f n)" in order_le_less_trans)
nipkow@15536
   419
apply (auto)
paulson@14416
   420
done
paulson@14416
   421
paulson@15085
   422
text{*Absolute convergence of series*}
paulson@14416
   423
lemma summable_rabs:
nipkow@15546
   424
     "summable (%n. abs (f n)) ==> abs(suminf f) \<le> (\<Sum>n. abs(f n))"
nipkow@15536
   425
by (auto intro: LIMSEQ_le LIMSEQ_imp_rabs summable_rabs_cancel summable_sumr_LIMSEQ_suminf)
paulson@14416
   426
paulson@14416
   427
paulson@14416
   428
subsection{* The Ratio Test*}
paulson@14416
   429
paulson@14416
   430
lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
paulson@14416
   431
apply (drule order_le_imp_less_or_eq, auto)
paulson@14416
   432
apply (subgoal_tac "0 \<le> c * abs y")
paulson@14416
   433
apply (simp add: zero_le_mult_iff, arith)
paulson@14416
   434
done
paulson@14416
   435
paulson@14416
   436
lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
paulson@14416
   437
apply (drule le_imp_less_or_eq)
paulson@14416
   438
apply (auto dest: less_imp_Suc_add)
paulson@14416
   439
done
paulson@14416
   440
paulson@14416
   441
lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
paulson@14416
   442
by (auto simp add: le_Suc_ex)
paulson@14416
   443
paulson@14416
   444
(*All this trouble just to get 0<c *)
paulson@14416
   445
lemma ratio_test_lemma2:
nipkow@15360
   446
     "[| \<forall>n \<ge> N. abs(f(Suc n)) \<le> c*abs(f n) |]  
paulson@14416
   447
      ==> 0 < c | summable f"
paulson@14416
   448
apply (simp (no_asm) add: linorder_not_le [symmetric])
paulson@14416
   449
apply (simp add: summable_Cauchy)
nipkow@15543
   450
apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
nipkow@15543
   451
 prefer 2
nipkow@15543
   452
 apply clarify
nipkow@15543
   453
 apply(erule_tac x = "n - 1" in allE)
nipkow@15543
   454
 apply (simp add:diff_Suc split:nat.splits)
nipkow@15543
   455
 apply (blast intro: rabs_ratiotest_lemma)
paulson@14416
   456
apply (rule_tac x = "Suc N" in exI, clarify)
nipkow@15543
   457
apply(simp cong:setsum_ivl_cong)
paulson@14416
   458
done
paulson@14416
   459
paulson@14416
   460
lemma ratio_test:
nipkow@15360
   461
     "[| c < 1; \<forall>n \<ge> N. abs(f(Suc n)) \<le> c*abs(f n) |]  
paulson@14416
   462
      ==> summable f"
paulson@14416
   463
apply (frule ratio_test_lemma2, auto)
paulson@15234
   464
apply (rule_tac g = "%n. (abs (f N) / (c ^ N))*c ^ n" 
paulson@15234
   465
       in summable_comparison_test)
paulson@14416
   466
apply (rule_tac x = N in exI, safe)
paulson@14416
   467
apply (drule le_Suc_ex_iff [THEN iffD1])
paulson@14416
   468
apply (auto simp add: power_add realpow_not_zero)
nipkow@15539
   469
apply (induct_tac "na", auto)
paulson@14416
   470
apply (rule_tac y = "c*abs (f (N + n))" in order_trans)
paulson@14416
   471
apply (auto intro: mult_right_mono simp add: summable_def)
paulson@14416
   472
apply (simp add: mult_ac)
paulson@15234
   473
apply (rule_tac x = "abs (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
paulson@15234
   474
apply (rule sums_divide) 
paulson@15234
   475
apply (rule sums_mult) 
paulson@15234
   476
apply (auto intro!: geometric_sums)
paulson@14416
   477
done
paulson@14416
   478
paulson@14416
   479
paulson@15085
   480
text{*Differentiation of finite sum*}
paulson@14416
   481
paulson@14416
   482
lemma DERIV_sumr [rule_format (no_asm)]:
paulson@14416
   483
     "(\<forall>r. m \<le> r & r < (m + n) --> DERIV (%x. f r x) x :> (f' r x))  
nipkow@15539
   484
      --> DERIV (%x. \<Sum>n=m..<n::nat. f n x) x :> (\<Sum>r=m..<n. f' r x)"
paulson@15251
   485
apply (induct "n")
paulson@14416
   486
apply (auto intro: DERIV_add)
paulson@14416
   487
done
paulson@14416
   488
paulson@14416
   489
ML
paulson@14416
   490
{*
paulson@14416
   491
val sums_def = thm"sums_def";
paulson@14416
   492
val summable_def = thm"summable_def";
paulson@14416
   493
val suminf_def = thm"suminf_def";
paulson@14416
   494
paulson@14416
   495
val sumr_minus_one_realpow_zero = thm "sumr_minus_one_realpow_zero";
paulson@14416
   496
val sumr_one_lb_realpow_zero = thm "sumr_one_lb_realpow_zero";
paulson@14416
   497
val sumr_group = thm "sumr_group";
paulson@14416
   498
val sums_summable = thm "sums_summable";
paulson@14416
   499
val summable_sums = thm "summable_sums";
paulson@14416
   500
val summable_sumr_LIMSEQ_suminf = thm "summable_sumr_LIMSEQ_suminf";
paulson@14416
   501
val sums_unique = thm "sums_unique";
paulson@14416
   502
val series_zero = thm "series_zero";
paulson@14416
   503
val sums_mult = thm "sums_mult";
paulson@14416
   504
val sums_divide = thm "sums_divide";
paulson@14416
   505
val sums_diff = thm "sums_diff";
paulson@14416
   506
val suminf_mult = thm "suminf_mult";
paulson@14416
   507
val suminf_mult2 = thm "suminf_mult2";
paulson@14416
   508
val suminf_diff = thm "suminf_diff";
paulson@14416
   509
val sums_minus = thm "sums_minus";
paulson@14416
   510
val sums_group = thm "sums_group";
paulson@14416
   511
val sumr_pos_lt_pair_lemma = thm "sumr_pos_lt_pair_lemma";
paulson@14416
   512
val sumr_pos_lt_pair = thm "sumr_pos_lt_pair";
paulson@14416
   513
val series_pos_le = thm "series_pos_le";
paulson@14416
   514
val series_pos_less = thm "series_pos_less";
paulson@14416
   515
val sumr_geometric = thm "sumr_geometric";
paulson@14416
   516
val geometric_sums = thm "geometric_sums";
paulson@14416
   517
val summable_convergent_sumr_iff = thm "summable_convergent_sumr_iff";
paulson@14416
   518
val summable_Cauchy = thm "summable_Cauchy";
paulson@14416
   519
val summable_comparison_test = thm "summable_comparison_test";
paulson@14416
   520
val summable_rabs_comparison_test = thm "summable_rabs_comparison_test";
paulson@14416
   521
val summable_le = thm "summable_le";
paulson@14416
   522
val summable_le2 = thm "summable_le2";
paulson@14416
   523
val summable_rabs_cancel = thm "summable_rabs_cancel";
paulson@14416
   524
val summable_rabs = thm "summable_rabs";
paulson@14416
   525
val rabs_ratiotest_lemma = thm "rabs_ratiotest_lemma";
paulson@14416
   526
val le_Suc_ex = thm "le_Suc_ex";
paulson@14416
   527
val le_Suc_ex_iff = thm "le_Suc_ex_iff";
paulson@14416
   528
val ratio_test_lemma2 = thm "ratio_test_lemma2";
paulson@14416
   529
val ratio_test = thm "ratio_test";
paulson@14416
   530
val DERIV_sumr = thm "DERIV_sumr";
paulson@14416
   531
*}
paulson@14416
   532
paulson@14416
   533
end