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