src/HOL/Series.thy
author paulson
Mon Oct 05 17:27:46 2009 +0100 (2009-10-05)
changeset 32877 6f09346c7c08
parent 32707 836ec9d0a0c8
child 33271 7be66dee1a5a
permissions -rw-r--r--
New lemmas connected with the reals and infinite series
     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 [trans]: "f=g ==> g sums z ==> f sums z"
    36   by simp
    37 
    38 lemma sumr_diff_mult_const:
    39  "setsum f {0..<n} - (real n*r) = setsum (%i. f i - r) {0..<n::nat}"
    40 by (simp add: diff_minus setsum_addf real_of_nat_def)
    41 
    42 lemma real_setsum_nat_ivl_bounded:
    43      "(!!p. p < n \<Longrightarrow> f(p) \<le> K)
    44       \<Longrightarrow> setsum f {0..<n::nat} \<le> real n * K"
    45 using setsum_bounded[where A = "{0..<n}"]
    46 by (auto simp:real_of_nat_def)
    47 
    48 (* Generalize from real to some algebraic structure? *)
    49 lemma sumr_minus_one_realpow_zero [simp]:
    50   "(\<Sum>i=0..<2*n. (-1) ^ Suc i) = (0::real)"
    51 by (induct "n", auto)
    52 
    53 (* FIXME this is an awful lemma! *)
    54 lemma sumr_one_lb_realpow_zero [simp]:
    55   "(\<Sum>n=Suc 0..<n. f(n) * (0::real) ^ n) = 0"
    56 by (rule setsum_0', simp)
    57 
    58 lemma sumr_group:
    59      "(\<Sum>m=0..<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {0 ..< n * k}"
    60 apply (subgoal_tac "k = 0 | 0 < k", auto)
    61 apply (induct "n")
    62 apply (simp_all add: setsum_add_nat_ivl add_commute)
    63 done
    64 
    65 lemma sumr_offset3:
    66   "setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)) + setsum f {0..<k}"
    67 apply (subst setsum_shift_bounds_nat_ivl [symmetric])
    68 apply (simp add: setsum_add_nat_ivl add_commute)
    69 done
    70 
    71 lemma sumr_offset:
    72   fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
    73   shows "(\<Sum>m=0..<n. f(m+k)) = setsum f {0..<n+k} - setsum f {0..<k}"
    74 by (simp add: sumr_offset3)
    75 
    76 lemma sumr_offset2:
    77  "\<forall>f. (\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
    78 by (simp add: sumr_offset)
    79 
    80 lemma sumr_offset4:
    81   "\<forall>n f. setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
    82 by (clarify, rule sumr_offset3)
    83 
    84 (*
    85 lemma sumr_from_1_from_0: "0 < n ==>
    86       (\<Sum>n=Suc 0 ..< Suc n. if even(n) then 0 else
    87              ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n =
    88       (\<Sum>n=0..<Suc n. if even(n) then 0 else
    89              ((- 1) ^ ((n - (Suc 0)) div 2))/(real (fact n))) * a ^ n"
    90 by (rule_tac n1 = 1 in sumr_split_add [THEN subst], auto)
    91 *)
    92 
    93 subsection{* Infinite Sums, by the Properties of Limits*}
    94 
    95 (*----------------------
    96    suminf is the sum   
    97  ---------------------*)
    98 lemma sums_summable: "f sums l ==> summable f"
    99 by (simp add: sums_def summable_def, blast)
   100 
   101 lemma summable_sums: "summable f ==> f sums (suminf f)"
   102 apply (simp add: summable_def suminf_def sums_def)
   103 apply (blast intro: theI LIMSEQ_unique)
   104 done
   105 
   106 lemma summable_sumr_LIMSEQ_suminf: 
   107      "summable f ==> (%n. setsum f {0..<n}) ----> (suminf f)"
   108 by (rule summable_sums [unfolded sums_def])
   109 
   110 lemma suminf_eq_lim: "suminf f = lim (%n. setsum f {0..<n})"
   111   by (simp add: suminf_def sums_def lim_def) 
   112 
   113 (*-------------------
   114     sum is unique                    
   115  ------------------*)
   116 lemma sums_unique: "f sums s ==> (s = suminf f)"
   117 apply (frule sums_summable [THEN summable_sums])
   118 apply (auto intro!: LIMSEQ_unique simp add: sums_def)
   119 done
   120 
   121 lemma sums_iff: "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
   122   by (metis summable_sums sums_summable sums_unique)
   123 
   124 lemma sums_split_initial_segment: "f sums s ==> 
   125   (%n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
   126   apply (unfold sums_def);
   127   apply (simp add: sumr_offset); 
   128   apply (rule LIMSEQ_diff_const)
   129   apply (rule LIMSEQ_ignore_initial_segment)
   130   apply assumption
   131 done
   132 
   133 lemma summable_ignore_initial_segment: "summable f ==> 
   134     summable (%n. f(n + k))"
   135   apply (unfold summable_def)
   136   apply (auto intro: sums_split_initial_segment)
   137 done
   138 
   139 lemma suminf_minus_initial_segment: "summable f ==>
   140     suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
   141   apply (frule summable_ignore_initial_segment)
   142   apply (rule sums_unique [THEN sym])
   143   apply (frule summable_sums)
   144   apply (rule sums_split_initial_segment)
   145   apply auto
   146 done
   147 
   148 lemma suminf_split_initial_segment: "summable f ==> 
   149     suminf f = (SUM i = 0..< k. f i) + suminf (%n. f(n + k))"
   150 by (auto simp add: suminf_minus_initial_segment)
   151 
   152 lemma suminf_exist_split: fixes r :: real assumes "0 < r" and "summable a"
   153   shows "\<exists> N. \<forall> n \<ge> N. \<bar> \<Sum> i. a (i + n) \<bar> < r"
   154 proof -
   155   from LIMSEQ_D[OF summable_sumr_LIMSEQ_suminf[OF `summable a`] `0 < r`]
   156   obtain N :: nat where "\<forall> n \<ge> N. norm (setsum a {0..<n} - suminf a) < r" by auto
   157   thus ?thesis unfolding suminf_minus_initial_segment[OF `summable a` refl] abs_minus_commute real_norm_def
   158     by auto
   159 qed
   160 
   161 lemma sums_Suc: assumes sumSuc: "(\<lambda> n. f (Suc n)) sums l" shows "f sums (l + f 0)"
   162 proof -
   163   from sumSuc[unfolded sums_def]
   164   have "(\<lambda>i. \<Sum>n = Suc 0..<Suc i. f n) ----> l" unfolding setsum_reindex[OF inj_Suc] image_Suc_atLeastLessThan[symmetric] comp_def .
   165   from LIMSEQ_add_const[OF this, where b="f 0"] 
   166   have "(\<lambda>i. \<Sum>n = 0..<Suc i. f n) ----> l + f 0" unfolding add_commute setsum_head_upt_Suc[OF zero_less_Suc] .
   167   thus ?thesis unfolding sums_def by (rule LIMSEQ_imp_Suc)
   168 qed
   169 
   170 lemma series_zero: 
   171      "(\<forall>m. n \<le> m --> f(m) = 0) ==> f sums (setsum f {0..<n})"
   172 apply (simp add: sums_def LIMSEQ_iff diff_minus[symmetric], safe)
   173 apply (rule_tac x = n in exI)
   174 apply (clarsimp simp add:setsum_diff[symmetric] cong:setsum_ivl_cong)
   175 done
   176 
   177 lemma sums_zero: "(\<lambda>n. 0) sums 0"
   178 unfolding sums_def by (simp add: LIMSEQ_const)
   179 
   180 lemma summable_zero: "summable (\<lambda>n. 0)"
   181 by (rule sums_zero [THEN sums_summable])
   182 
   183 lemma suminf_zero: "suminf (\<lambda>n. 0) = 0"
   184 by (rule sums_zero [THEN sums_unique, symmetric])
   185   
   186 lemma (in bounded_linear) sums:
   187   "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
   188 unfolding sums_def by (drule LIMSEQ, simp only: setsum)
   189 
   190 lemma (in bounded_linear) summable:
   191   "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
   192 unfolding summable_def by (auto intro: sums)
   193 
   194 lemma (in bounded_linear) suminf:
   195   "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
   196 by (intro sums_unique sums summable_sums)
   197 
   198 lemma sums_mult:
   199   fixes c :: "'a::real_normed_algebra"
   200   shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
   201 by (rule mult_right.sums)
   202 
   203 lemma summable_mult:
   204   fixes c :: "'a::real_normed_algebra"
   205   shows "summable f \<Longrightarrow> summable (%n. c * f n)"
   206 by (rule mult_right.summable)
   207 
   208 lemma suminf_mult:
   209   fixes c :: "'a::real_normed_algebra"
   210   shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f";
   211 by (rule mult_right.suminf [symmetric])
   212 
   213 lemma sums_mult2:
   214   fixes c :: "'a::real_normed_algebra"
   215   shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
   216 by (rule mult_left.sums)
   217 
   218 lemma summable_mult2:
   219   fixes c :: "'a::real_normed_algebra"
   220   shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
   221 by (rule mult_left.summable)
   222 
   223 lemma suminf_mult2:
   224   fixes c :: "'a::real_normed_algebra"
   225   shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
   226 by (rule mult_left.suminf)
   227 
   228 lemma sums_divide:
   229   fixes c :: "'a::real_normed_field"
   230   shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
   231 by (rule divide.sums)
   232 
   233 lemma summable_divide:
   234   fixes c :: "'a::real_normed_field"
   235   shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
   236 by (rule divide.summable)
   237 
   238 lemma suminf_divide:
   239   fixes c :: "'a::real_normed_field"
   240   shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
   241 by (rule divide.suminf [symmetric])
   242 
   243 lemma sums_add: "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) sums (a + b)"
   244 unfolding sums_def by (simp add: setsum_addf LIMSEQ_add)
   245 
   246 lemma summable_add: "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n + Y n)"
   247 unfolding summable_def by (auto intro: sums_add)
   248 
   249 lemma suminf_add:
   250   "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X + suminf Y = (\<Sum>n. X n + Y n)"
   251 by (intro sums_unique sums_add summable_sums)
   252 
   253 lemma sums_diff: "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) sums (a - b)"
   254 unfolding sums_def by (simp add: setsum_subtractf LIMSEQ_diff)
   255 
   256 lemma summable_diff: "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n - Y n)"
   257 unfolding summable_def by (auto intro: sums_diff)
   258 
   259 lemma suminf_diff:
   260   "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X - suminf Y = (\<Sum>n. X n - Y n)"
   261 by (intro sums_unique sums_diff summable_sums)
   262 
   263 lemma sums_minus: "X sums a ==> (\<lambda>n. - X n) sums (- a)"
   264 unfolding sums_def by (simp add: setsum_negf LIMSEQ_minus)
   265 
   266 lemma summable_minus: "summable X \<Longrightarrow> summable (\<lambda>n. - X n)"
   267 unfolding summable_def by (auto intro: sums_minus)
   268 
   269 lemma suminf_minus: "summable X \<Longrightarrow> (\<Sum>n. - X n) = - (\<Sum>n. X n)"
   270 by (intro sums_unique [symmetric] sums_minus summable_sums)
   271 
   272 lemma sums_group:
   273      "[|summable f; 0 < k |] ==> (%n. setsum f {n*k..<n*k+k}) sums (suminf f)"
   274 apply (drule summable_sums)
   275 apply (simp only: sums_def sumr_group)
   276 apply (unfold LIMSEQ_iff, safe)
   277 apply (drule_tac x="r" in spec, safe)
   278 apply (rule_tac x="no" in exI, safe)
   279 apply (drule_tac x="n*k" in spec)
   280 apply (erule mp)
   281 apply (erule order_trans)
   282 apply simp
   283 done
   284 
   285 text{*A summable series of positive terms has limit that is at least as
   286 great as any partial sum.*}
   287 
   288 lemma series_pos_le:
   289   fixes f :: "nat \<Rightarrow> real"
   290   shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
   291 apply (drule summable_sums)
   292 apply (simp add: sums_def)
   293 apply (cut_tac k = "setsum f {0..<n}" in LIMSEQ_const)
   294 apply (erule LIMSEQ_le, blast)
   295 apply (rule_tac x="n" in exI, clarify)
   296 apply (rule setsum_mono2)
   297 apply auto
   298 done
   299 
   300 lemma series_pos_less:
   301   fixes f :: "nat \<Rightarrow> real"
   302   shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
   303 apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
   304 apply simp
   305 apply (erule series_pos_le)
   306 apply (simp add: order_less_imp_le)
   307 done
   308 
   309 lemma suminf_gt_zero:
   310   fixes f :: "nat \<Rightarrow> real"
   311   shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
   312 by (drule_tac n="0" in series_pos_less, simp_all)
   313 
   314 lemma suminf_ge_zero:
   315   fixes f :: "nat \<Rightarrow> real"
   316   shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
   317 by (drule_tac n="0" in series_pos_le, simp_all)
   318 
   319 lemma sumr_pos_lt_pair:
   320   fixes f :: "nat \<Rightarrow> real"
   321   shows "\<lbrakk>summable f;
   322         \<forall>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
   323       \<Longrightarrow> setsum f {0..<k} < suminf f"
   324 unfolding One_nat_def
   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}"
   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}"
   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_iff LIMSEQ_iff, 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 suminf_le:
   381   fixes x :: real
   382   shows "summable f \<Longrightarrow> (!!n. setsum f {0..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
   383   by (simp add: summable_convergent_sumr_iff suminf_eq_lim lim_le) 
   384 
   385 lemma summable_Cauchy:
   386      "summable (f::nat \<Rightarrow> 'a::banach) =  
   387       (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. norm (setsum f {m..<n}) < e)"
   388 apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
   389 apply (drule spec, drule (1) mp)
   390 apply (erule exE, rule_tac x="M" in exI, clarify)
   391 apply (rule_tac x="m" and y="n" in linorder_le_cases)
   392 apply (frule (1) order_trans)
   393 apply (drule_tac x="n" in spec, drule (1) mp)
   394 apply (drule_tac x="m" in spec, drule (1) mp)
   395 apply (simp add: setsum_diff [symmetric])
   396 apply simp
   397 apply (drule spec, drule (1) mp)
   398 apply (erule exE, rule_tac x="N" in exI, clarify)
   399 apply (rule_tac x="m" and y="n" in linorder_le_cases)
   400 apply (subst norm_minus_commute)
   401 apply (simp add: setsum_diff [symmetric])
   402 apply (simp add: setsum_diff [symmetric])
   403 done
   404 
   405 text{*Comparison test*}
   406 
   407 lemma norm_setsum:
   408   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
   409   shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
   410 apply (case_tac "finite A")
   411 apply (erule finite_induct)
   412 apply simp
   413 apply simp
   414 apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
   415 apply simp
   416 done
   417 
   418 lemma summable_comparison_test:
   419   fixes f :: "nat \<Rightarrow> 'a::banach"
   420   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
   421 apply (simp add: summable_Cauchy, safe)
   422 apply (drule_tac x="e" in spec, safe)
   423 apply (rule_tac x = "N + Na" in exI, safe)
   424 apply (rotate_tac 2)
   425 apply (drule_tac x = m in spec)
   426 apply (auto, rotate_tac 2, drule_tac x = n in spec)
   427 apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
   428 apply (rule norm_setsum)
   429 apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
   430 apply (auto intro: setsum_mono simp add: abs_less_iff)
   431 done
   432 
   433 lemma summable_norm_comparison_test:
   434   fixes f :: "nat \<Rightarrow> 'a::banach"
   435   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk>
   436          \<Longrightarrow> summable (\<lambda>n. norm (f n))"
   437 apply (rule summable_comparison_test)
   438 apply (auto)
   439 done
   440 
   441 lemma summable_rabs_comparison_test:
   442   fixes f :: "nat \<Rightarrow> real"
   443   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>)"
   444 apply (rule summable_comparison_test)
   445 apply (auto)
   446 done
   447 
   448 text{*Summability of geometric series for real algebras*}
   449 
   450 lemma complete_algebra_summable_geometric:
   451   fixes x :: "'a::{real_normed_algebra_1,banach}"
   452   shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
   453 proof (rule summable_comparison_test)
   454   show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
   455     by (simp add: norm_power_ineq)
   456   show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
   457     by (simp add: summable_geometric)
   458 qed
   459 
   460 text{*Limit comparison property for series (c.f. jrh)*}
   461 
   462 lemma summable_le:
   463   fixes f g :: "nat \<Rightarrow> real"
   464   shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
   465 apply (drule summable_sums)+
   466 apply (simp only: sums_def, erule (1) LIMSEQ_le)
   467 apply (rule exI)
   468 apply (auto intro!: setsum_mono)
   469 done
   470 
   471 lemma summable_le2:
   472   fixes f g :: "nat \<Rightarrow> real"
   473   shows "\<lbrakk>\<forall>n. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f \<and> suminf f \<le> suminf g"
   474 apply (subgoal_tac "summable f")
   475 apply (auto intro!: summable_le)
   476 apply (simp add: abs_le_iff)
   477 apply (rule_tac g="g" in summable_comparison_test, simp_all)
   478 done
   479 
   480 (* specialisation for the common 0 case *)
   481 lemma suminf_0_le:
   482   fixes f::"nat\<Rightarrow>real"
   483   assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
   484   shows "0 \<le> suminf f"
   485 proof -
   486   let ?g = "(\<lambda>n. (0::real))"
   487   from gt0 have "\<forall>n. ?g n \<le> f n" by simp
   488   moreover have "summable ?g" by (rule summable_zero)
   489   moreover from sm have "summable f" .
   490   ultimately have "suminf ?g \<le> suminf f" by (rule summable_le)
   491   then show "0 \<le> suminf f" by (simp add: suminf_zero)
   492 qed 
   493 
   494 
   495 text{*Absolute convergence imples normal convergence*}
   496 lemma summable_norm_cancel:
   497   fixes f :: "nat \<Rightarrow> 'a::banach"
   498   shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
   499 apply (simp only: summable_Cauchy, safe)
   500 apply (drule_tac x="e" in spec, safe)
   501 apply (rule_tac x="N" in exI, safe)
   502 apply (drule_tac x="m" in spec, safe)
   503 apply (rule order_le_less_trans [OF norm_setsum])
   504 apply (rule order_le_less_trans [OF abs_ge_self])
   505 apply simp
   506 done
   507 
   508 lemma summable_rabs_cancel:
   509   fixes f :: "nat \<Rightarrow> real"
   510   shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
   511 by (rule summable_norm_cancel, simp)
   512 
   513 text{*Absolute convergence of series*}
   514 lemma summable_norm:
   515   fixes f :: "nat \<Rightarrow> 'a::banach"
   516   shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
   517 by (auto intro: LIMSEQ_le LIMSEQ_norm summable_norm_cancel
   518                 summable_sumr_LIMSEQ_suminf norm_setsum)
   519 
   520 lemma summable_rabs:
   521   fixes f :: "nat \<Rightarrow> real"
   522   shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
   523 by (fold real_norm_def, rule summable_norm)
   524 
   525 subsection{* The Ratio Test*}
   526 
   527 lemma norm_ratiotest_lemma:
   528   fixes x y :: "'a::real_normed_vector"
   529   shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
   530 apply (subgoal_tac "norm x \<le> 0", simp)
   531 apply (erule order_trans)
   532 apply (simp add: mult_le_0_iff)
   533 done
   534 
   535 lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
   536 by (erule norm_ratiotest_lemma, simp)
   537 
   538 lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
   539 apply (drule le_imp_less_or_eq)
   540 apply (auto dest: less_imp_Suc_add)
   541 done
   542 
   543 lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
   544 by (auto simp add: le_Suc_ex)
   545 
   546 (*All this trouble just to get 0<c *)
   547 lemma ratio_test_lemma2:
   548   fixes f :: "nat \<Rightarrow> 'a::banach"
   549   shows "\<lbrakk>\<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
   550 apply (simp (no_asm) add: linorder_not_le [symmetric])
   551 apply (simp add: summable_Cauchy)
   552 apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
   553  prefer 2
   554  apply clarify
   555  apply(erule_tac x = "n - Suc 0" in allE)
   556  apply (simp add:diff_Suc split:nat.splits)
   557  apply (blast intro: norm_ratiotest_lemma)
   558 apply (rule_tac x = "Suc N" in exI, clarify)
   559 apply(simp cong:setsum_ivl_cong)
   560 done
   561 
   562 lemma ratio_test:
   563   fixes f :: "nat \<Rightarrow> 'a::banach"
   564   shows "\<lbrakk>c < 1; \<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> summable f"
   565 apply (frule ratio_test_lemma2, auto)
   566 apply (rule_tac g = "%n. (norm (f N) / (c ^ N))*c ^ n" 
   567        in summable_comparison_test)
   568 apply (rule_tac x = N in exI, safe)
   569 apply (drule le_Suc_ex_iff [THEN iffD1])
   570 apply (auto simp add: power_add field_power_not_zero)
   571 apply (induct_tac "na", auto)
   572 apply (rule_tac y = "c * norm (f (N + n))" in order_trans)
   573 apply (auto intro: mult_right_mono simp add: summable_def)
   574 apply (rule_tac x = "norm (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
   575 apply (rule sums_divide) 
   576 apply (rule sums_mult)
   577 apply (auto intro!: geometric_sums)
   578 done
   579 
   580 subsection {* Cauchy Product Formula *}
   581 
   582 (* Proof based on Analysis WebNotes: Chapter 07, Class 41
   583 http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm *)
   584 
   585 lemma setsum_triangle_reindex:
   586   fixes n :: nat
   587   shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k=0..<n. \<Sum>i=0..k. f i (k - i))"
   588 proof -
   589   have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
   590     (\<Sum>(k, i)\<in>(SIGMA k:{0..<n}. {0..k}). f i (k - i))"
   591   proof (rule setsum_reindex_cong)
   592     show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{0..<n}. {0..k})"
   593       by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
   594     show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{0..<n}. {0..k})"
   595       by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
   596     show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
   597       by clarify
   598   qed
   599   thus ?thesis by (simp add: setsum_Sigma)
   600 qed
   601 
   602 lemma Cauchy_product_sums:
   603   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
   604   assumes a: "summable (\<lambda>k. norm (a k))"
   605   assumes b: "summable (\<lambda>k. norm (b k))"
   606   shows "(\<lambda>k. \<Sum>i=0..k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
   607 proof -
   608   let ?S1 = "\<lambda>n::nat. {0..<n} \<times> {0..<n}"
   609   let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
   610   have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
   611   have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
   612   have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
   613   have finite_S1: "\<And>n. finite (?S1 n)" by simp
   614   with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
   615 
   616   let ?g = "\<lambda>(i,j). a i * b j"
   617   let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
   618   have f_nonneg: "\<And>x. 0 \<le> ?f x"
   619     by (auto simp add: mult_nonneg_nonneg)
   620   hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
   621     unfolding real_norm_def
   622     by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
   623 
   624   have "(\<lambda>n. (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k))
   625            ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
   626     by (intro LIMSEQ_mult summable_sumr_LIMSEQ_suminf
   627         summable_norm_cancel [OF a] summable_norm_cancel [OF b])
   628   hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
   629     by (simp only: setsum_product setsum_Sigma [rule_format]
   630                    finite_atLeastLessThan)
   631 
   632   have "(\<lambda>n. (\<Sum>k=0..<n. norm (a k)) * (\<Sum>k=0..<n. norm (b k)))
   633        ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
   634     using a b by (intro LIMSEQ_mult summable_sumr_LIMSEQ_suminf)
   635   hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
   636     by (simp only: setsum_product setsum_Sigma [rule_format]
   637                    finite_atLeastLessThan)
   638   hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
   639     by (rule convergentI)
   640   hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
   641     by (rule convergent_Cauchy)
   642   have "Zseq (\<lambda>n. setsum ?f (?S1 n - ?S2 n))"
   643   proof (rule ZseqI, simp only: norm_setsum_f)
   644     fix r :: real
   645     assume r: "0 < r"
   646     from CauchyD [OF Cauchy r] obtain N
   647     where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
   648     hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
   649       by (simp only: setsum_diff finite_S1 S1_mono)
   650     hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
   651       by (simp only: norm_setsum_f)
   652     show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
   653     proof (intro exI allI impI)
   654       fix n assume "2 * N \<le> n"
   655       hence n: "N \<le> n div 2" by simp
   656       have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
   657         by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
   658                   Diff_mono subset_refl S1_le_S2)
   659       also have "\<dots> < r"
   660         using n div_le_dividend by (rule N)
   661       finally show "setsum ?f (?S1 n - ?S2 n) < r" .
   662     qed
   663   qed
   664   hence "Zseq (\<lambda>n. setsum ?g (?S1 n - ?S2 n))"
   665     apply (rule Zseq_le [rule_format])
   666     apply (simp only: norm_setsum_f)
   667     apply (rule order_trans [OF norm_setsum setsum_mono])
   668     apply (auto simp add: norm_mult_ineq)
   669     done
   670   hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
   671     by (simp only: LIMSEQ_Zseq_iff setsum_diff finite_S1 S2_le_S1 diff_0_right)
   672 
   673   with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
   674     by (rule LIMSEQ_diff_approach_zero2)
   675   thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
   676 qed
   677 
   678 lemma Cauchy_product:
   679   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
   680   assumes a: "summable (\<lambda>k. norm (a k))"
   681   assumes b: "summable (\<lambda>k. norm (b k))"
   682   shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i=0..k. a i * b (k - i))"
   683 using a b
   684 by (rule Cauchy_product_sums [THEN sums_unique])
   685 
   686 end