src/HOL/Hyperreal/Series.thy
author paulson
Thu Feb 26 17:08:23 2004 +0100 (2004-02-26)
changeset 14416 1f256287d4f0
parent 12018 ec054019c910
child 15003 6145dd7538d7
permissions -rw-r--r--
converted Hyperreal/Series to Isar script
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
paulson@10751
     6
*) 
paulson@10751
     7
paulson@14416
     8
header{*Finite Summation and Infinite Series*}
paulson@10751
     9
paulson@14416
    10
theory Series = SEQ + Lim:
paulson@10751
    11
paulson@10751
    12
consts sumr :: "[nat,nat,(nat=>real)] => real"
paulson@10751
    13
primrec
paulson@14416
    14
   sumr_0:   "sumr m 0 f = 0"
paulson@14416
    15
   sumr_Suc: "sumr m (Suc n) f = (if n < m then 0 else sumr m n f + f(n))"
paulson@10751
    16
paulson@10751
    17
constdefs
paulson@14416
    18
   sums  :: "[nat=>real,real] => bool"     (infixr "sums" 80)
paulson@10751
    19
   "f sums s  == (%n. sumr 0 n f) ----> s"
paulson@10751
    20
paulson@14416
    21
   summable :: "(nat=>real) => bool"
paulson@14416
    22
   "summable f == (\<exists>s. f sums s)"
paulson@14416
    23
paulson@14416
    24
   suminf   :: "(nat=>real) => real"
paulson@14416
    25
   "suminf f == (@s. f sums s)"
paulson@14416
    26
paulson@14416
    27
paulson@14416
    28
lemma sumr_Suc_zero [simp]: "sumr (Suc n) n f = 0"
paulson@14416
    29
by (induct_tac "n", auto)
paulson@14416
    30
paulson@14416
    31
lemma sumr_eq_bounds [simp]: "sumr m m f = 0"
paulson@14416
    32
by (induct_tac "m", auto)
paulson@14416
    33
paulson@14416
    34
lemma sumr_Suc_eq [simp]: "sumr m (Suc m) f = f(m)"
paulson@14416
    35
by auto
paulson@14416
    36
paulson@14416
    37
lemma sumr_add_lbound_zero [simp]: "sumr (m+k) k f = 0"
paulson@14416
    38
by (induct_tac "k", auto)
paulson@14416
    39
paulson@14416
    40
lemma sumr_add: "sumr m n f + sumr m n g = sumr m n (%n. f n + g n)"
paulson@14416
    41
apply (induct_tac "n")
paulson@14416
    42
apply (simp_all add: add_ac)
paulson@14416
    43
done
paulson@14416
    44
paulson@14416
    45
lemma sumr_mult: "r * sumr m n f = sumr m n (%n. r * f n)"
paulson@14416
    46
apply (induct_tac "n")
paulson@14416
    47
apply (simp_all add: right_distrib)
paulson@14416
    48
done
paulson@14416
    49
paulson@14416
    50
lemma sumr_split_add [rule_format]:
paulson@14416
    51
     "n < p --> sumr 0 n f + sumr n p f = sumr 0 p f"
paulson@14416
    52
apply (induct_tac "p", auto)
paulson@14416
    53
apply (rename_tac k) 
paulson@14416
    54
apply (subgoal_tac "n=k", auto) 
paulson@14416
    55
done
paulson@14416
    56
paulson@14416
    57
lemma sumr_split_add_minus: "n < p ==> sumr 0 p f + - sumr 0 n f = sumr n p f"
paulson@14416
    58
apply (drule_tac f1 = f in sumr_split_add [symmetric])
paulson@14416
    59
apply (simp add: add_ac)
paulson@14416
    60
done
paulson@14416
    61
paulson@14416
    62
lemma sumr_split_add2 [rule_format]:
paulson@14416
    63
     "0 < n --> n < p --> sumr (Suc 0) n f + sumr n p f = sumr (Suc 0) p f"
paulson@14416
    64
apply (induct_tac "p", auto) 
paulson@14416
    65
apply (rename_tac k) 
paulson@14416
    66
apply (subgoal_tac "n=k", auto)
paulson@14416
    67
done
paulson@14416
    68
paulson@14416
    69
lemma sumr_split_add3:
paulson@14416
    70
     "[| 0<n; n \<le> p |] ==> sumr (Suc 0) n f + sumr n p f = sumr (Suc 0) p f"
paulson@14416
    71
apply (drule le_imp_less_or_eq, auto)
paulson@14416
    72
apply (blast intro: sumr_split_add2)
paulson@14416
    73
done
paulson@14416
    74
paulson@14416
    75
lemma sumr_rabs: "abs(sumr m n f) \<le> sumr m n (%i. abs(f i))"
paulson@14416
    76
apply (induct_tac "n")
paulson@14416
    77
apply (auto intro: abs_triangle_ineq [THEN order_trans] add_right_mono)
paulson@14416
    78
done
paulson@14416
    79
paulson@14416
    80
lemma sumr_fun_eq [rule_format (no_asm)]:
paulson@14416
    81
     "(\<forall>r. m \<le> r & r < n --> f r = g r) --> sumr m n f = sumr m n g"
paulson@14416
    82
by (induct_tac "n", auto)
paulson@14416
    83
paulson@14416
    84
lemma sumr_const [simp]: "sumr 0 n (%i. r) = real n * r"
paulson@14416
    85
apply (induct_tac "n")
paulson@14416
    86
apply (simp_all add: left_distrib real_of_nat_zero real_of_nat_Suc)
paulson@14416
    87
done
paulson@14416
    88
paulson@14416
    89
lemma sumr_add_mult_const:
paulson@14416
    90
     "sumr 0 n f + -(real n * r) = sumr 0 n (%i. f i + -r)"
paulson@14416
    91
by (simp only: sumr_add [symmetric] minus_mult_right, simp)
paulson@14416
    92
paulson@14416
    93
lemma sumr_diff_mult_const: "sumr 0 n f - (real n*r) = sumr 0 n (%i. f i - r)"
paulson@14416
    94
by (simp add: real_diff_def sumr_add_mult_const)
paulson@14416
    95
paulson@14416
    96
lemma sumr_less_bounds_zero [rule_format, simp]: "n < m --> sumr m n f = 0"
paulson@14416
    97
apply (induct_tac "n")
paulson@14416
    98
apply (auto dest: less_imp_le)
paulson@14416
    99
done
paulson@14416
   100
paulson@14416
   101
lemma sumr_minus: "sumr m n (%i. - f i) = - sumr m n f"
paulson@14416
   102
apply (induct_tac "n")
paulson@14416
   103
apply (case_tac [2] "Suc n \<le> m", simp_all)
paulson@14416
   104
done
paulson@14416
   105
paulson@14416
   106
lemma sumr_shift_bounds: "sumr (m+k) (n+k) f = sumr m n (%i. f(i + k))"
paulson@14416
   107
by (induct_tac "n", auto)
paulson@14416
   108
paulson@14416
   109
lemma sumr_minus_one_realpow_zero [simp]: "sumr 0 (2*n) (%i. (-1) ^ Suc i) = 0"
paulson@14416
   110
by (induct_tac "n", auto)
paulson@14416
   111
paulson@14416
   112
lemma Suc_diff_n: "m < Suc n ==> Suc n - m = Suc (n - m)"
paulson@14416
   113
by (drule less_imp_Suc_add, auto)
paulson@14416
   114
paulson@14416
   115
lemma sumr_interval_const [rule_format (no_asm)]:
paulson@14416
   116
     "(\<forall>n. m \<le> Suc n --> f n = r) --> m \<le> k --> sumr m k f = (real(k-m) * r)"
paulson@14416
   117
apply (induct_tac "k", auto) 
paulson@14416
   118
apply (drule_tac x = n in spec)
paulson@14416
   119
apply (auto dest!: le_imp_less_or_eq)
paulson@14416
   120
apply (simp (no_asm_simp) add: left_distrib Suc_diff_n real_of_nat_Suc)
paulson@14416
   121
done
paulson@14416
   122
paulson@14416
   123
lemma sumr_interval_const2 [rule_format (no_asm)]:
paulson@14416
   124
     "(\<forall>n. m \<le> n --> f n = r) --> m \<le> k  
paulson@14416
   125
      --> sumr m k f = (real (k - m) * r)"
paulson@14416
   126
apply (induct_tac "k", auto) 
paulson@14416
   127
apply (drule_tac x = n in spec)
paulson@14416
   128
apply (auto dest!: le_imp_less_or_eq)
paulson@14416
   129
apply (simp (no_asm_simp) add: Suc_diff_n left_distrib real_of_nat_Suc)
paulson@14416
   130
done
paulson@14416
   131
paulson@14416
   132
lemma sumr_le [rule_format (no_asm)]:
paulson@14416
   133
     "(\<forall>n. m \<le> n --> 0 \<le> f n) --> m < k --> sumr 0 m f \<le> sumr 0 k f"
paulson@14416
   134
apply (induct_tac "k")
paulson@14416
   135
apply (auto simp add: less_Suc_eq_le)
paulson@14416
   136
apply (drule_tac [!] x = n in spec, safe)
paulson@14416
   137
apply (drule le_imp_less_or_eq, safe)
paulson@14416
   138
apply (drule_tac [2] a = "sumr 0 m f" in add_mono)
paulson@14416
   139
apply (drule_tac a = "sumr 0 m f" in order_refl [THEN add_mono], auto)
paulson@14416
   140
done
paulson@14416
   141
paulson@14416
   142
lemma sumr_le2 [rule_format (no_asm)]:
paulson@14416
   143
     "(\<forall>r. m \<le> r & r < n --> f r \<le> g r) --> sumr m n f \<le> sumr m n g"
paulson@14416
   144
apply (induct_tac "n")
paulson@14416
   145
apply (auto intro: add_mono simp add: le_def)
paulson@14416
   146
done
paulson@14416
   147
paulson@14416
   148
lemma sumr_ge_zero [rule_format (no_asm)]: "(\<forall>n. 0 \<le> f n) --> 0 \<le> sumr m n f"
paulson@14416
   149
apply (induct_tac "n", auto)
paulson@14416
   150
apply (drule_tac x = n in spec, arith)
paulson@14416
   151
done
paulson@14416
   152
paulson@14416
   153
lemma sumr_ge_zero2 [rule_format (no_asm)]:
paulson@14416
   154
     "(\<forall>n. m \<le> n --> 0 \<le> f n) --> 0 \<le> sumr m n f"
paulson@14416
   155
apply (induct_tac "n", auto)
paulson@14416
   156
apply (drule_tac x = n in spec, arith)
paulson@14416
   157
done
paulson@14416
   158
paulson@14416
   159
lemma sumr_rabs_ge_zero [iff]: "0 \<le> sumr m n (%n. abs (f n))"
paulson@14416
   160
by (induct_tac "n", auto, arith)
paulson@10751
   161
paulson@14416
   162
lemma rabs_sumr_rabs_cancel [simp]:
paulson@14416
   163
     "abs (sumr m n (%n. abs (f n))) = (sumr m n (%n. abs (f n)))"
paulson@14416
   164
apply (induct_tac "n")
paulson@14416
   165
apply (auto, arith)
paulson@14416
   166
done
paulson@14416
   167
paulson@14416
   168
lemma sumr_zero [rule_format]:
paulson@14416
   169
     "\<forall>n. N \<le> n --> f n = 0 ==> N \<le> m --> sumr m n f = 0"
paulson@14416
   170
by (induct_tac "n", auto)
paulson@14416
   171
paulson@14416
   172
lemma Suc_le_imp_diff_ge2:
paulson@14416
   173
     "[|\<forall>n. N \<le> n --> f (Suc n) = 0; Suc N \<le> m|] ==> sumr m n f = 0"
paulson@14416
   174
apply (rule sumr_zero) 
paulson@14416
   175
apply (case_tac "n", auto)
paulson@14416
   176
done
paulson@14416
   177
paulson@14416
   178
lemma sumr_one_lb_realpow_zero [simp]: "sumr (Suc 0) n (%n. f(n) * 0 ^ n) = 0"
paulson@14416
   179
apply (induct_tac "n")
paulson@14416
   180
apply (case_tac [2] "n", auto)
paulson@14416
   181
done
paulson@14416
   182
paulson@14416
   183
lemma sumr_diff: "sumr m n f - sumr m n g = sumr m n (%n. f n - g n)"
paulson@14416
   184
by (simp add: diff_minus sumr_add [symmetric] sumr_minus)
paulson@14416
   185
paulson@14416
   186
lemma sumr_subst [rule_format (no_asm)]:
paulson@14416
   187
     "(\<forall>p. m \<le> p & p < m+n --> (f p = g p)) --> sumr m n f = sumr m n g"
paulson@14416
   188
by (induct_tac "n", auto)
paulson@14416
   189
paulson@14416
   190
lemma sumr_bound [rule_format (no_asm)]:
paulson@14416
   191
     "(\<forall>p. m \<le> p & p < m + n --> (f(p) \<le> K))  
paulson@14416
   192
      --> (sumr m (m + n) f \<le> (real n * K))"
paulson@14416
   193
apply (induct_tac "n")
paulson@14416
   194
apply (auto intro: add_mono simp add: left_distrib real_of_nat_Suc)
paulson@14416
   195
done
paulson@14416
   196
paulson@14416
   197
lemma sumr_bound2 [rule_format (no_asm)]:
paulson@14416
   198
     "(\<forall>p. 0 \<le> p & p < n --> (f(p) \<le> K))  
paulson@14416
   199
      --> (sumr 0 n f \<le> (real n * K))"
paulson@14416
   200
apply (induct_tac "n")
paulson@14416
   201
apply (auto intro: add_mono simp add: left_distrib real_of_nat_Suc)
paulson@14416
   202
done
paulson@14416
   203
paulson@14416
   204
lemma sumr_group [simp]:
paulson@14416
   205
     "sumr 0 n (%m. sumr (m * k) (m*k + k) f) = sumr 0 (n * k) f"
paulson@14416
   206
apply (subgoal_tac "k = 0 | 0 < k", auto)
paulson@14416
   207
apply (induct_tac "n")
paulson@14416
   208
apply (simp_all add: sumr_split_add add_commute)
paulson@14416
   209
done
paulson@14416
   210
paulson@14416
   211
subsection{* Infinite Sums, by the Properties of Limits*}
paulson@14416
   212
paulson@14416
   213
(*----------------------
paulson@14416
   214
   suminf is the sum   
paulson@14416
   215
 ---------------------*)
paulson@14416
   216
lemma sums_summable: "f sums l ==> summable f"
paulson@14416
   217
by (simp add: sums_def summable_def, blast)
paulson@14416
   218
paulson@14416
   219
lemma summable_sums: "summable f ==> f sums (suminf f)"
paulson@14416
   220
apply (simp add: summable_def suminf_def)
paulson@14416
   221
apply (blast intro: someI2)
paulson@14416
   222
done
paulson@14416
   223
paulson@14416
   224
lemma summable_sumr_LIMSEQ_suminf: 
paulson@14416
   225
     "summable f ==> (%n. sumr 0 n f) ----> (suminf f)"
paulson@14416
   226
apply (simp add: summable_def suminf_def sums_def)
paulson@14416
   227
apply (blast intro: someI2)
paulson@14416
   228
done
paulson@14416
   229
paulson@14416
   230
(*-------------------
paulson@14416
   231
    sum is unique                    
paulson@14416
   232
 ------------------*)
paulson@14416
   233
lemma sums_unique: "f sums s ==> (s = suminf f)"
paulson@14416
   234
apply (frule sums_summable [THEN summable_sums])
paulson@14416
   235
apply (auto intro!: LIMSEQ_unique simp add: sums_def)
paulson@14416
   236
done
paulson@14416
   237
paulson@14416
   238
(*
paulson@14416
   239
Goalw [sums_def,LIMSEQ_def] 
paulson@14416
   240
     "(\<forall>m. n \<le> Suc m --> f(m) = 0) ==> f sums (sumr 0 n f)"
paulson@14416
   241
by safe
paulson@14416
   242
by (res_inst_tac [("x","n")] exI 1);
paulson@14416
   243
by (safe THEN ftac le_imp_less_or_eq 1)
paulson@14416
   244
by safe
paulson@14416
   245
by (dres_inst_tac [("f","f")] sumr_split_add_minus 1);
paulson@14416
   246
by (ALLGOALS (Asm_simp_tac));
paulson@14416
   247
by (dtac (conjI RS sumr_interval_const) 1);
paulson@14416
   248
by Auto_tac
paulson@14416
   249
qed "series_zero";
paulson@14416
   250
next one was called series_zero2
paulson@14416
   251
**********************)
paulson@14416
   252
paulson@14416
   253
lemma series_zero: 
paulson@14416
   254
     "(\<forall>m. n \<le> m --> f(m) = 0) ==> f sums (sumr 0 n f)"
paulson@14416
   255
apply (simp add: sums_def LIMSEQ_def, safe)
paulson@14416
   256
apply (rule_tac x = n in exI)
paulson@14416
   257
apply (safe, frule le_imp_less_or_eq, safe)
paulson@14416
   258
apply (drule_tac f = f in sumr_split_add_minus, simp_all)
paulson@14416
   259
apply (drule sumr_interval_const2, auto)
paulson@14416
   260
done
paulson@14416
   261
paulson@14416
   262
lemma sums_mult: "x sums x0 ==> (%n. c * x(n)) sums (c * x0)"
paulson@14416
   263
by (auto simp add: sums_def sumr_mult [symmetric]
paulson@14416
   264
         intro!: LIMSEQ_mult intro: LIMSEQ_const)
paulson@14416
   265
paulson@14416
   266
lemma sums_divide: "x sums x' ==> (%n. x(n)/c) sums (x'/c)"
paulson@14416
   267
by (simp add: real_divide_def sums_mult mult_commute [of _ "inverse c"])
paulson@14416
   268
paulson@14416
   269
lemma sums_diff: "[| x sums x0; y sums y0 |] ==> (%n. x n - y n) sums (x0-y0)"
paulson@14416
   270
by (auto simp add: sums_def sumr_diff [symmetric] intro: LIMSEQ_diff)
paulson@14416
   271
paulson@14416
   272
lemma suminf_mult: "summable f ==> suminf f * c = suminf(%n. f n * c)"
paulson@14416
   273
by (auto intro!: sums_unique sums_mult summable_sums simp add: mult_commute)
paulson@14416
   274
paulson@14416
   275
lemma suminf_mult2: "summable f ==> c * suminf f  = suminf(%n. c * f n)"
paulson@14416
   276
by (auto intro!: sums_unique sums_mult summable_sums)
paulson@14416
   277
paulson@14416
   278
lemma suminf_diff:
paulson@14416
   279
     "[| summable f; summable g |]   
paulson@14416
   280
      ==> suminf f - suminf g  = suminf(%n. f n - g n)"
paulson@14416
   281
by (auto intro!: sums_diff sums_unique summable_sums)
paulson@14416
   282
paulson@14416
   283
lemma sums_minus: "x sums x0 ==> (%n. - x n) sums - x0"
paulson@14416
   284
by (auto simp add: sums_def intro!: LIMSEQ_minus simp add: sumr_minus)
paulson@14416
   285
paulson@14416
   286
lemma sums_group:
paulson@14416
   287
     "[|summable f; 0 < k |] ==> (%n. sumr (n*k) (n*k + k) f) sums (suminf f)"
paulson@14416
   288
apply (drule summable_sums)
paulson@14416
   289
apply (auto simp add: sums_def LIMSEQ_def)
paulson@14416
   290
apply (drule_tac x = r in spec, safe)
paulson@14416
   291
apply (rule_tac x = no in exI, safe)
paulson@14416
   292
apply (drule_tac x = "n*k" in spec)
paulson@14416
   293
apply (auto dest!: not_leE)
paulson@14416
   294
apply (drule_tac j = no in less_le_trans, auto)
paulson@14416
   295
done
paulson@14416
   296
paulson@14416
   297
lemma sumr_pos_lt_pair_lemma:
paulson@14416
   298
     "[|\<forall>d. - f (n + (d + d)) < f (Suc (n + (d + d)))|]
paulson@14416
   299
      ==> sumr 0 (n + Suc (Suc 0)) f \<le> sumr 0 (Suc (Suc 0) * Suc no + n) f"
paulson@14416
   300
apply (induct_tac "no", simp)
paulson@14416
   301
apply (rule_tac y = "sumr 0 (Suc (Suc 0) * (Suc na) +n) f" in order_trans)
paulson@14416
   302
apply assumption
paulson@14416
   303
apply (drule_tac x = "Suc na" in spec)
paulson@14416
   304
apply (simp add: add_ac) 
paulson@14416
   305
done
paulson@10751
   306
paulson@10751
   307
paulson@14416
   308
lemma sumr_pos_lt_pair:
paulson@14416
   309
     "[|summable f; \<forall>d. 0 < (f(n + (Suc(Suc 0) * d))) + f(n + ((Suc(Suc 0) * d) + 1))|]  
paulson@14416
   310
      ==> sumr 0 n f < suminf f"
paulson@14416
   311
apply (drule summable_sums)
paulson@14416
   312
apply (auto simp add: sums_def LIMSEQ_def)
paulson@14416
   313
apply (drule_tac x = "f (n) + f (n + 1) " in spec)
paulson@14416
   314
apply auto
paulson@14416
   315
apply (rule_tac [2] ccontr, drule_tac [2] linorder_not_less [THEN iffD1])
paulson@14416
   316
apply (frule_tac [2] no=no in sumr_pos_lt_pair_lemma) 
paulson@14416
   317
apply (drule_tac x = 0 in spec, simp)
paulson@14416
   318
apply (rotate_tac 1, drule_tac x = "Suc (Suc 0) * (Suc no) + n" in spec)
paulson@14416
   319
apply (safe, simp)
paulson@14416
   320
apply (subgoal_tac "suminf f + (f (n) + f (n + 1)) \<le> sumr 0 (Suc (Suc 0) * (Suc no) + n) f")
paulson@14416
   321
apply (rule_tac [2] y = "sumr 0 (n+ Suc (Suc 0)) f" in order_trans)
paulson@14416
   322
prefer 3 apply assumption
paulson@14416
   323
apply (rule_tac [2] y = "sumr 0 n f + (f (n) + f (n + 1))" in order_trans)
paulson@14416
   324
apply simp_all 
paulson@14416
   325
apply (subgoal_tac "suminf f \<le> sumr 0 (Suc (Suc 0) * (Suc no) + n) f")
paulson@14416
   326
apply (rule_tac [2] y = "suminf f + (f (n) + f (n + 1))" in order_trans)
paulson@14416
   327
prefer 3 apply simp 
paulson@14416
   328
apply (drule_tac [2] x = 0 in spec)
paulson@14416
   329
 prefer 2 apply simp 
paulson@14416
   330
apply (subgoal_tac "0 \<le> sumr 0 (Suc (Suc 0) * Suc no + n) f + - suminf f")
paulson@14416
   331
apply (simp add: abs_if) 
paulson@14416
   332
apply (auto simp add: linorder_not_less [symmetric])
paulson@14416
   333
done
paulson@14416
   334
paulson@14416
   335
paulson@14416
   336
paulson@14416
   337
(*-----------------------------------------------------------------
paulson@14416
   338
   Summable series of positive terms has limit >= any partial sum 
paulson@14416
   339
 ----------------------------------------------------------------*)
paulson@14416
   340
lemma series_pos_le: 
paulson@14416
   341
     "[| summable f; \<forall>m. n \<le> m --> 0 \<le> f(m) |] ==> sumr 0 n f \<le> suminf f"
paulson@14416
   342
apply (drule summable_sums)
paulson@14416
   343
apply (simp add: sums_def)
paulson@14416
   344
apply (cut_tac k = "sumr 0 n f" in LIMSEQ_const)
paulson@14416
   345
apply (erule LIMSEQ_le, blast) 
paulson@14416
   346
apply (rule_tac x = n in exI, clarify) 
paulson@14416
   347
apply (drule le_imp_less_or_eq)
paulson@14416
   348
apply (auto intro: sumr_le)
paulson@14416
   349
done
paulson@14416
   350
paulson@14416
   351
lemma series_pos_less:
paulson@14416
   352
     "[| summable f; \<forall>m. n \<le> m --> 0 < f(m) |] ==> sumr 0 n f < suminf f"
paulson@14416
   353
apply (rule_tac y = "sumr 0 (Suc n) f" in order_less_le_trans)
paulson@14416
   354
apply (rule_tac [2] series_pos_le, auto)
paulson@14416
   355
apply (drule_tac x = m in spec, auto)
paulson@14416
   356
done
paulson@14416
   357
paulson@14416
   358
(*-------------------------------------------------------------------
paulson@14416
   359
                    sum of geometric progression                 
paulson@14416
   360
 -------------------------------------------------------------------*)
paulson@14416
   361
paulson@14416
   362
lemma sumr_geometric: "x ~= 1 ==> sumr 0 n (%n. x ^ n) = (x ^ n - 1) / (x - 1)"
paulson@14416
   363
apply (induct_tac "n", auto)
paulson@14416
   364
apply (rule_tac c1 = "x - 1" in real_mult_right_cancel [THEN iffD1])
paulson@14416
   365
apply (auto simp add: real_mult_assoc left_distrib)
paulson@14416
   366
apply (simp add: right_distrib real_diff_def real_mult_commute)
paulson@14416
   367
done
paulson@14416
   368
paulson@14416
   369
lemma geometric_sums: "abs(x) < 1 ==> (%n. x ^ n) sums (1/(1 - x))"
paulson@14416
   370
apply (case_tac "x = 1")
paulson@14416
   371
apply (auto dest!: LIMSEQ_rabs_realpow_zero2 simp add: sumr_geometric sums_def real_diff_def add_divide_distrib)
paulson@14416
   372
apply (subgoal_tac "1 / (1 + -x) = 0/ (x - 1) + - 1/ (x - 1) ")
paulson@14416
   373
apply (erule ssubst)
paulson@14416
   374
apply (rule LIMSEQ_add, rule LIMSEQ_divide)
paulson@14416
   375
apply (auto intro: LIMSEQ_const simp add: real_diff_def minus_divide_right LIMSEQ_rabs_realpow_zero2)
paulson@14416
   376
done
paulson@14416
   377
paulson@14416
   378
(*-------------------------------------------------------------------
paulson@14416
   379
    Cauchy-type criterion for convergence of series (c.f. Harrison)
paulson@14416
   380
 -------------------------------------------------------------------*)
paulson@14416
   381
lemma summable_convergent_sumr_iff: "summable f = convergent (%n. sumr 0 n f)"
paulson@14416
   382
by (simp add: summable_def sums_def convergent_def)
paulson@14416
   383
paulson@14416
   384
lemma summable_Cauchy:
paulson@14416
   385
     "summable f =  
paulson@14416
   386
      (\<forall>e. 0 < e --> (\<exists>N. \<forall>m n. N \<le> m --> abs(sumr m n f) < e))"
paulson@14416
   387
apply (auto simp add: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_def)
paulson@14416
   388
apply (drule_tac [!] spec, auto) 
paulson@14416
   389
apply (rule_tac x = M in exI)
paulson@14416
   390
apply (rule_tac [2] x = N in exI, auto)
paulson@14416
   391
apply (cut_tac [!] m = m and n = n in less_linear, auto)
paulson@14416
   392
apply (frule le_less_trans [THEN less_imp_le], assumption)
paulson@14416
   393
apply (drule_tac x = n in spec)
paulson@14416
   394
apply (drule_tac x = m in spec)
paulson@14416
   395
apply (auto intro: abs_minus_add_cancel [THEN subst]
paulson@14416
   396
            simp add: sumr_split_add_minus abs_minus_add_cancel)
paulson@14416
   397
done
paulson@14416
   398
paulson@14416
   399
(*-------------------------------------------------------------------
paulson@14416
   400
     Terms of a convergent series tend to zero
paulson@14416
   401
     > Goalw [LIMSEQ_def] "summable f ==> f ----> 0"
paulson@14416
   402
     Proved easily in HSeries after proving nonstandard case.
paulson@14416
   403
 -------------------------------------------------------------------*)
paulson@14416
   404
(*-------------------------------------------------------------------
paulson@14416
   405
                    Comparison test
paulson@14416
   406
 -------------------------------------------------------------------*)
paulson@14416
   407
lemma summable_comparison_test:
paulson@14416
   408
     "[| \<exists>N. \<forall>n. N \<le> n --> abs(f n) \<le> g n; summable g |] ==> summable f"
paulson@14416
   409
apply (auto simp add: summable_Cauchy)
paulson@14416
   410
apply (drule spec, auto)
paulson@14416
   411
apply (rule_tac x = "N + Na" in exI, auto)
paulson@14416
   412
apply (rotate_tac 2)
paulson@14416
   413
apply (drule_tac x = m in spec)
paulson@14416
   414
apply (auto, rotate_tac 2, drule_tac x = n in spec)
paulson@14416
   415
apply (rule_tac y = "sumr m n (%k. abs (f k))" in order_le_less_trans)
paulson@14416
   416
apply (rule sumr_rabs)
paulson@14416
   417
apply (rule_tac y = "sumr m n g" in order_le_less_trans)
paulson@14416
   418
apply (auto intro: sumr_le2 simp add: abs_interval_iff)
paulson@14416
   419
done
paulson@14416
   420
paulson@14416
   421
lemma summable_rabs_comparison_test:
paulson@14416
   422
     "[| \<exists>N. \<forall>n. N \<le> n --> abs(f n) \<le> g n; summable g |] 
paulson@14416
   423
      ==> summable (%k. abs (f k))"
paulson@14416
   424
apply (rule summable_comparison_test)
paulson@14416
   425
apply (auto simp add: abs_idempotent)
paulson@14416
   426
done
paulson@14416
   427
paulson@14416
   428
(*------------------------------------------------------------------*)
paulson@14416
   429
(*       Limit comparison property for series (c.f. jrh)            *)
paulson@14416
   430
(*------------------------------------------------------------------*)
paulson@14416
   431
lemma summable_le:
paulson@14416
   432
     "[|\<forall>n. f n \<le> g n; summable f; summable g |] ==> suminf f \<le> suminf g"
paulson@14416
   433
apply (drule summable_sums)+
paulson@14416
   434
apply (auto intro!: LIMSEQ_le simp add: sums_def)
paulson@14416
   435
apply (rule exI)
paulson@14416
   436
apply (auto intro!: sumr_le2)
paulson@14416
   437
done
paulson@14416
   438
paulson@14416
   439
lemma summable_le2:
paulson@14416
   440
     "[|\<forall>n. abs(f n) \<le> g n; summable g |]  
paulson@14416
   441
      ==> summable f & suminf f \<le> suminf g"
paulson@14416
   442
apply (auto intro: summable_comparison_test intro!: summable_le)
paulson@14416
   443
apply (simp add: abs_le_interval_iff)
paulson@14416
   444
done
paulson@14416
   445
paulson@14416
   446
(*-------------------------------------------------------------------
paulson@14416
   447
         Absolute convergence imples normal convergence
paulson@14416
   448
 -------------------------------------------------------------------*)
paulson@14416
   449
lemma summable_rabs_cancel: "summable (%n. abs (f n)) ==> summable f"
paulson@14416
   450
apply (auto simp add: sumr_rabs summable_Cauchy)
paulson@14416
   451
apply (drule spec, auto)
paulson@14416
   452
apply (rule_tac x = N in exI, auto)
paulson@14416
   453
apply (drule spec, auto)
paulson@14416
   454
apply (rule_tac y = "sumr m n (%n. abs (f n))" in order_le_less_trans)
paulson@14416
   455
apply (auto intro: sumr_rabs)
paulson@14416
   456
done
paulson@14416
   457
paulson@14416
   458
(*-------------------------------------------------------------------
paulson@14416
   459
         Absolute convergence of series
paulson@14416
   460
 -------------------------------------------------------------------*)
paulson@14416
   461
lemma summable_rabs:
paulson@14416
   462
     "summable (%n. abs (f n)) ==> abs(suminf f) \<le> suminf (%n. abs(f n))"
paulson@14416
   463
by (auto intro: LIMSEQ_le LIMSEQ_imp_rabs summable_rabs_cancel summable_sumr_LIMSEQ_suminf sumr_rabs)
paulson@14416
   464
paulson@14416
   465
paulson@14416
   466
subsection{* The Ratio Test*}
paulson@14416
   467
paulson@14416
   468
lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
paulson@14416
   469
apply (drule order_le_imp_less_or_eq, auto)
paulson@14416
   470
apply (subgoal_tac "0 \<le> c * abs y")
paulson@14416
   471
apply (simp add: zero_le_mult_iff, arith)
paulson@14416
   472
done
paulson@14416
   473
paulson@14416
   474
lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
paulson@14416
   475
apply (drule le_imp_less_or_eq)
paulson@14416
   476
apply (auto dest: less_imp_Suc_add)
paulson@14416
   477
done
paulson@14416
   478
paulson@14416
   479
lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
paulson@14416
   480
by (auto simp add: le_Suc_ex)
paulson@14416
   481
paulson@14416
   482
(*All this trouble just to get 0<c *)
paulson@14416
   483
lemma ratio_test_lemma2:
paulson@14416
   484
     "[| \<forall>n. N \<le> n --> abs(f(Suc n)) \<le> c*abs(f n) |]  
paulson@14416
   485
      ==> 0 < c | summable f"
paulson@14416
   486
apply (simp (no_asm) add: linorder_not_le [symmetric])
paulson@14416
   487
apply (simp add: summable_Cauchy)
paulson@14416
   488
apply (safe, subgoal_tac "\<forall>n. N \<le> n --> f (Suc n) = 0")
paulson@14416
   489
prefer 2 apply (blast intro: rabs_ratiotest_lemma)
paulson@14416
   490
apply (rule_tac x = "Suc N" in exI, clarify)
paulson@14416
   491
apply (drule_tac n=n in Suc_le_imp_diff_ge2, auto) 
paulson@14416
   492
done
paulson@14416
   493
paulson@14416
   494
lemma ratio_test:
paulson@14416
   495
     "[| c < 1; \<forall>n. N \<le> n --> abs(f(Suc n)) \<le> c*abs(f n) |]  
paulson@14416
   496
      ==> summable f"
paulson@14416
   497
apply (frule ratio_test_lemma2, auto)
paulson@14416
   498
apply (rule_tac g = "%n. (abs (f N) / (c ^ N))*c ^ n" in summable_comparison_test)
paulson@14416
   499
apply (rule_tac x = N in exI, safe)
paulson@14416
   500
apply (drule le_Suc_ex_iff [THEN iffD1])
paulson@14416
   501
apply (auto simp add: power_add realpow_not_zero)
paulson@14416
   502
apply (induct_tac "na", auto)
paulson@14416
   503
apply (rule_tac y = "c*abs (f (N + n))" in order_trans)
paulson@14416
   504
apply (auto intro: mult_right_mono simp add: summable_def)
paulson@14416
   505
apply (simp add: mult_ac)
paulson@14416
   506
apply (rule_tac x = "abs (f N) * (1/ (1 - c)) / (c ^ N) " in exI)
paulson@14416
   507
apply (rule sums_divide)
paulson@14416
   508
apply (rule sums_mult)
paulson@14416
   509
apply (auto intro!: sums_mult geometric_sums simp add: real_abs_def)
paulson@14416
   510
done
paulson@14416
   511
paulson@14416
   512
paulson@14416
   513
(*--------------------------------------------------------------------------*)
paulson@14416
   514
(* Differentiation of finite sum                                            *)
paulson@14416
   515
(*--------------------------------------------------------------------------*)
paulson@14416
   516
paulson@14416
   517
lemma DERIV_sumr [rule_format (no_asm)]:
paulson@14416
   518
     "(\<forall>r. m \<le> r & r < (m + n) --> DERIV (%x. f r x) x :> (f' r x))  
paulson@14416
   519
      --> DERIV (%x. sumr m n (%n. f n x)) x :> sumr m n (%r. f' r x)"
paulson@14416
   520
apply (induct_tac "n")
paulson@14416
   521
apply (auto intro: DERIV_add)
paulson@14416
   522
done
paulson@14416
   523
paulson@14416
   524
ML
paulson@14416
   525
{*
paulson@14416
   526
val sumr_0 = thm"sumr_0";
paulson@14416
   527
val sumr_Suc = thm"sumr_Suc";
paulson@14416
   528
val sums_def = thm"sums_def";
paulson@14416
   529
val summable_def = thm"summable_def";
paulson@14416
   530
val suminf_def = thm"suminf_def";
paulson@14416
   531
paulson@14416
   532
val sumr_Suc_zero = thm "sumr_Suc_zero";
paulson@14416
   533
val sumr_eq_bounds = thm "sumr_eq_bounds";
paulson@14416
   534
val sumr_Suc_eq = thm "sumr_Suc_eq";
paulson@14416
   535
val sumr_add_lbound_zero = thm "sumr_add_lbound_zero";
paulson@14416
   536
val sumr_add = thm "sumr_add";
paulson@14416
   537
val sumr_mult = thm "sumr_mult";
paulson@14416
   538
val sumr_split_add = thm "sumr_split_add";
paulson@14416
   539
val sumr_split_add_minus = thm "sumr_split_add_minus";
paulson@14416
   540
val sumr_split_add2 = thm "sumr_split_add2";
paulson@14416
   541
val sumr_split_add3 = thm "sumr_split_add3";
paulson@14416
   542
val sumr_rabs = thm "sumr_rabs";
paulson@14416
   543
val sumr_fun_eq = thm "sumr_fun_eq";
paulson@14416
   544
val sumr_const = thm "sumr_const";
paulson@14416
   545
val sumr_add_mult_const = thm "sumr_add_mult_const";
paulson@14416
   546
val sumr_diff_mult_const = thm "sumr_diff_mult_const";
paulson@14416
   547
val sumr_less_bounds_zero = thm "sumr_less_bounds_zero";
paulson@14416
   548
val sumr_minus = thm "sumr_minus";
paulson@14416
   549
val sumr_shift_bounds = thm "sumr_shift_bounds";
paulson@14416
   550
val sumr_minus_one_realpow_zero = thm "sumr_minus_one_realpow_zero";
paulson@14416
   551
val Suc_diff_n = thm "Suc_diff_n";
paulson@14416
   552
val sumr_interval_const = thm "sumr_interval_const";
paulson@14416
   553
val sumr_interval_const2 = thm "sumr_interval_const2";
paulson@14416
   554
val sumr_le = thm "sumr_le";
paulson@14416
   555
val sumr_le2 = thm "sumr_le2";
paulson@14416
   556
val sumr_ge_zero = thm "sumr_ge_zero";
paulson@14416
   557
val sumr_ge_zero2 = thm "sumr_ge_zero2";
paulson@14416
   558
val sumr_rabs_ge_zero = thm "sumr_rabs_ge_zero";
paulson@14416
   559
val rabs_sumr_rabs_cancel = thm "rabs_sumr_rabs_cancel";
paulson@14416
   560
val sumr_zero = thm "sumr_zero";
paulson@14416
   561
val Suc_le_imp_diff_ge2 = thm "Suc_le_imp_diff_ge2";
paulson@14416
   562
val sumr_one_lb_realpow_zero = thm "sumr_one_lb_realpow_zero";
paulson@14416
   563
val sumr_diff = thm "sumr_diff";
paulson@14416
   564
val sumr_subst = thm "sumr_subst";
paulson@14416
   565
val sumr_bound = thm "sumr_bound";
paulson@14416
   566
val sumr_bound2 = thm "sumr_bound2";
paulson@14416
   567
val sumr_group = thm "sumr_group";
paulson@14416
   568
val sums_summable = thm "sums_summable";
paulson@14416
   569
val summable_sums = thm "summable_sums";
paulson@14416
   570
val summable_sumr_LIMSEQ_suminf = thm "summable_sumr_LIMSEQ_suminf";
paulson@14416
   571
val sums_unique = thm "sums_unique";
paulson@14416
   572
val series_zero = thm "series_zero";
paulson@14416
   573
val sums_mult = thm "sums_mult";
paulson@14416
   574
val sums_divide = thm "sums_divide";
paulson@14416
   575
val sums_diff = thm "sums_diff";
paulson@14416
   576
val suminf_mult = thm "suminf_mult";
paulson@14416
   577
val suminf_mult2 = thm "suminf_mult2";
paulson@14416
   578
val suminf_diff = thm "suminf_diff";
paulson@14416
   579
val sums_minus = thm "sums_minus";
paulson@14416
   580
val sums_group = thm "sums_group";
paulson@14416
   581
val sumr_pos_lt_pair_lemma = thm "sumr_pos_lt_pair_lemma";
paulson@14416
   582
val sumr_pos_lt_pair = thm "sumr_pos_lt_pair";
paulson@14416
   583
val series_pos_le = thm "series_pos_le";
paulson@14416
   584
val series_pos_less = thm "series_pos_less";
paulson@14416
   585
val sumr_geometric = thm "sumr_geometric";
paulson@14416
   586
val geometric_sums = thm "geometric_sums";
paulson@14416
   587
val summable_convergent_sumr_iff = thm "summable_convergent_sumr_iff";
paulson@14416
   588
val summable_Cauchy = thm "summable_Cauchy";
paulson@14416
   589
val summable_comparison_test = thm "summable_comparison_test";
paulson@14416
   590
val summable_rabs_comparison_test = thm "summable_rabs_comparison_test";
paulson@14416
   591
val summable_le = thm "summable_le";
paulson@14416
   592
val summable_le2 = thm "summable_le2";
paulson@14416
   593
val summable_rabs_cancel = thm "summable_rabs_cancel";
paulson@14416
   594
val summable_rabs = thm "summable_rabs";
paulson@14416
   595
val rabs_ratiotest_lemma = thm "rabs_ratiotest_lemma";
paulson@14416
   596
val le_Suc_ex = thm "le_Suc_ex";
paulson@14416
   597
val le_Suc_ex_iff = thm "le_Suc_ex_iff";
paulson@14416
   598
val ratio_test_lemma2 = thm "ratio_test_lemma2";
paulson@14416
   599
val ratio_test = thm "ratio_test";
paulson@14416
   600
val DERIV_sumr = thm "DERIV_sumr";
paulson@14416
   601
*}
paulson@14416
   602
paulson@14416
   603
end