src/HOL/Series.thy
 author huffman Tue Feb 24 11:12:58 2009 -0800 (2009-02-24) changeset 30082 43c5b7bfc791 parent 29803 c56a5571f60a child 30649 57753e0ec1d4 permissions -rw-r--r--
make more proofs work whether or not One_nat_def is a simp rule
```     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 suminf_exist_split: fixes r :: real assumes "0 < r" and "summable a"
```
```   144   shows "\<exists> N. \<forall> n \<ge> N. \<bar> \<Sum> i. a (i + n) \<bar> < r"
```
```   145 proof -
```
```   146   from LIMSEQ_D[OF summable_sumr_LIMSEQ_suminf[OF `summable a`] `0 < r`]
```
```   147   obtain N :: nat where "\<forall> n \<ge> N. norm (setsum a {0..<n} - suminf a) < r" by auto
```
```   148   thus ?thesis unfolding suminf_minus_initial_segment[OF `summable a` refl] abs_minus_commute real_norm_def
```
```   149     by auto
```
```   150 qed
```
```   151
```
```   152 lemma sums_Suc: assumes sumSuc: "(\<lambda> n. f (Suc n)) sums l" shows "f sums (l + f 0)"
```
```   153 proof -
```
```   154   from sumSuc[unfolded sums_def]
```
```   155   have "(\<lambda>i. \<Sum>n = Suc 0..<Suc i. f n) ----> l" unfolding setsum_reindex[OF inj_Suc] image_Suc_atLeastLessThan[symmetric] comp_def .
```
```   156   from LIMSEQ_add_const[OF this, where b="f 0"]
```
```   157   have "(\<lambda>i. \<Sum>n = 0..<Suc i. f n) ----> l + f 0" unfolding add_commute setsum_head_upt_Suc[OF zero_less_Suc] .
```
```   158   thus ?thesis unfolding sums_def by (rule LIMSEQ_imp_Suc)
```
```   159 qed
```
```   160
```
```   161 lemma series_zero:
```
```   162      "(\<forall>m. n \<le> m --> f(m) = 0) ==> f sums (setsum f {0..<n})"
```
```   163 apply (simp add: sums_def LIMSEQ_def diff_minus[symmetric], safe)
```
```   164 apply (rule_tac x = n in exI)
```
```   165 apply (clarsimp simp add:setsum_diff[symmetric] cong:setsum_ivl_cong)
```
```   166 done
```
```   167
```
```   168 lemma sums_zero: "(\<lambda>n. 0) sums 0"
```
```   169 unfolding sums_def by (simp add: LIMSEQ_const)
```
```   170
```
```   171 lemma summable_zero: "summable (\<lambda>n. 0)"
```
```   172 by (rule sums_zero [THEN sums_summable])
```
```   173
```
```   174 lemma suminf_zero: "suminf (\<lambda>n. 0) = 0"
```
```   175 by (rule sums_zero [THEN sums_unique, symmetric])
```
```   176
```
```   177 lemma (in bounded_linear) sums:
```
```   178   "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
```
```   179 unfolding sums_def by (drule LIMSEQ, simp only: setsum)
```
```   180
```
```   181 lemma (in bounded_linear) summable:
```
```   182   "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
```
```   183 unfolding summable_def by (auto intro: sums)
```
```   184
```
```   185 lemma (in bounded_linear) suminf:
```
```   186   "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
```
```   187 by (intro sums_unique sums summable_sums)
```
```   188
```
```   189 lemma sums_mult:
```
```   190   fixes c :: "'a::real_normed_algebra"
```
```   191   shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
```
```   192 by (rule mult_right.sums)
```
```   193
```
```   194 lemma summable_mult:
```
```   195   fixes c :: "'a::real_normed_algebra"
```
```   196   shows "summable f \<Longrightarrow> summable (%n. c * f n)"
```
```   197 by (rule mult_right.summable)
```
```   198
```
```   199 lemma suminf_mult:
```
```   200   fixes c :: "'a::real_normed_algebra"
```
```   201   shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f";
```
```   202 by (rule mult_right.suminf [symmetric])
```
```   203
```
```   204 lemma sums_mult2:
```
```   205   fixes c :: "'a::real_normed_algebra"
```
```   206   shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
```
```   207 by (rule mult_left.sums)
```
```   208
```
```   209 lemma summable_mult2:
```
```   210   fixes c :: "'a::real_normed_algebra"
```
```   211   shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
```
```   212 by (rule mult_left.summable)
```
```   213
```
```   214 lemma suminf_mult2:
```
```   215   fixes c :: "'a::real_normed_algebra"
```
```   216   shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
```
```   217 by (rule mult_left.suminf)
```
```   218
```
```   219 lemma sums_divide:
```
```   220   fixes c :: "'a::real_normed_field"
```
```   221   shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
```
```   222 by (rule divide.sums)
```
```   223
```
```   224 lemma summable_divide:
```
```   225   fixes c :: "'a::real_normed_field"
```
```   226   shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
```
```   227 by (rule divide.summable)
```
```   228
```
```   229 lemma suminf_divide:
```
```   230   fixes c :: "'a::real_normed_field"
```
```   231   shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
```
```   232 by (rule divide.suminf [symmetric])
```
```   233
```
```   234 lemma sums_add: "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) sums (a + b)"
```
```   235 unfolding sums_def by (simp add: setsum_addf LIMSEQ_add)
```
```   236
```
```   237 lemma summable_add: "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n + Y n)"
```
```   238 unfolding summable_def by (auto intro: sums_add)
```
```   239
```
```   240 lemma suminf_add:
```
```   241   "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X + suminf Y = (\<Sum>n. X n + Y n)"
```
```   242 by (intro sums_unique sums_add summable_sums)
```
```   243
```
```   244 lemma sums_diff: "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) sums (a - b)"
```
```   245 unfolding sums_def by (simp add: setsum_subtractf LIMSEQ_diff)
```
```   246
```
```   247 lemma summable_diff: "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n - Y n)"
```
```   248 unfolding summable_def by (auto intro: sums_diff)
```
```   249
```
```   250 lemma suminf_diff:
```
```   251   "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X - suminf Y = (\<Sum>n. X n - Y n)"
```
```   252 by (intro sums_unique sums_diff summable_sums)
```
```   253
```
```   254 lemma sums_minus: "X sums a ==> (\<lambda>n. - X n) sums (- a)"
```
```   255 unfolding sums_def by (simp add: setsum_negf LIMSEQ_minus)
```
```   256
```
```   257 lemma summable_minus: "summable X \<Longrightarrow> summable (\<lambda>n. - X n)"
```
```   258 unfolding summable_def by (auto intro: sums_minus)
```
```   259
```
```   260 lemma suminf_minus: "summable X \<Longrightarrow> (\<Sum>n. - X n) = - (\<Sum>n. X n)"
```
```   261 by (intro sums_unique [symmetric] sums_minus summable_sums)
```
```   262
```
```   263 lemma sums_group:
```
```   264      "[|summable f; 0 < k |] ==> (%n. setsum f {n*k..<n*k+k}) sums (suminf f)"
```
```   265 apply (drule summable_sums)
```
```   266 apply (simp only: sums_def sumr_group)
```
```   267 apply (unfold LIMSEQ_def, safe)
```
```   268 apply (drule_tac x="r" in spec, safe)
```
```   269 apply (rule_tac x="no" in exI, safe)
```
```   270 apply (drule_tac x="n*k" in spec)
```
```   271 apply (erule mp)
```
```   272 apply (erule order_trans)
```
```   273 apply simp
```
```   274 done
```
```   275
```
```   276 text{*A summable series of positive terms has limit that is at least as
```
```   277 great as any partial sum.*}
```
```   278
```
```   279 lemma series_pos_le:
```
```   280   fixes f :: "nat \<Rightarrow> real"
```
```   281   shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
```
```   282 apply (drule summable_sums)
```
```   283 apply (simp add: sums_def)
```
```   284 apply (cut_tac k = "setsum f {0..<n}" in LIMSEQ_const)
```
```   285 apply (erule LIMSEQ_le, blast)
```
```   286 apply (rule_tac x="n" in exI, clarify)
```
```   287 apply (rule setsum_mono2)
```
```   288 apply auto
```
```   289 done
```
```   290
```
```   291 lemma series_pos_less:
```
```   292   fixes f :: "nat \<Rightarrow> real"
```
```   293   shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
```
```   294 apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
```
```   295 apply simp
```
```   296 apply (erule series_pos_le)
```
```   297 apply (simp add: order_less_imp_le)
```
```   298 done
```
```   299
```
```   300 lemma suminf_gt_zero:
```
```   301   fixes f :: "nat \<Rightarrow> real"
```
```   302   shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
```
```   303 by (drule_tac n="0" in series_pos_less, simp_all)
```
```   304
```
```   305 lemma suminf_ge_zero:
```
```   306   fixes f :: "nat \<Rightarrow> real"
```
```   307   shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
```
```   308 by (drule_tac n="0" in series_pos_le, simp_all)
```
```   309
```
```   310 lemma sumr_pos_lt_pair:
```
```   311   fixes f :: "nat \<Rightarrow> real"
```
```   312   shows "\<lbrakk>summable f;
```
```   313         \<forall>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
```
```   314       \<Longrightarrow> setsum f {0..<k} < suminf f"
```
```   315 unfolding One_nat_def
```
```   316 apply (subst suminf_split_initial_segment [where k="k"])
```
```   317 apply assumption
```
```   318 apply simp
```
```   319 apply (drule_tac k="k" in summable_ignore_initial_segment)
```
```   320 apply (drule_tac k="Suc (Suc 0)" in sums_group, simp)
```
```   321 apply simp
```
```   322 apply (frule sums_unique)
```
```   323 apply (drule sums_summable)
```
```   324 apply simp
```
```   325 apply (erule suminf_gt_zero)
```
```   326 apply (simp add: add_ac)
```
```   327 done
```
```   328
```
```   329 text{*Sum of a geometric progression.*}
```
```   330
```
```   331 lemmas sumr_geometric = geometric_sum [where 'a = real]
```
```   332
```
```   333 lemma geometric_sums:
```
```   334   fixes x :: "'a::{real_normed_field,recpower}"
```
```   335   shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) sums (1 / (1 - x))"
```
```   336 proof -
```
```   337   assume less_1: "norm x < 1"
```
```   338   hence neq_1: "x \<noteq> 1" by auto
```
```   339   hence neq_0: "x - 1 \<noteq> 0" by simp
```
```   340   from less_1 have lim_0: "(\<lambda>n. x ^ n) ----> 0"
```
```   341     by (rule LIMSEQ_power_zero)
```
```   342   hence "(\<lambda>n. x ^ n / (x - 1) - 1 / (x - 1)) ----> 0 / (x - 1) - 1 / (x - 1)"
```
```   343     using neq_0 by (intro LIMSEQ_divide LIMSEQ_diff LIMSEQ_const)
```
```   344   hence "(\<lambda>n. (x ^ n - 1) / (x - 1)) ----> 1 / (1 - x)"
```
```   345     by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
```
```   346   thus "(\<lambda>n. x ^ n) sums (1 / (1 - x))"
```
```   347     by (simp add: sums_def geometric_sum neq_1)
```
```   348 qed
```
```   349
```
```   350 lemma summable_geometric:
```
```   351   fixes x :: "'a::{real_normed_field,recpower}"
```
```   352   shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
```
```   353 by (rule geometric_sums [THEN sums_summable])
```
```   354
```
```   355 text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
```
```   356
```
```   357 lemma summable_convergent_sumr_iff:
```
```   358  "summable f = convergent (%n. setsum f {0..<n})"
```
```   359 by (simp add: summable_def sums_def convergent_def)
```
```   360
```
```   361 lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
```
```   362 apply (drule summable_convergent_sumr_iff [THEN iffD1])
```
```   363 apply (drule convergent_Cauchy)
```
```   364 apply (simp only: Cauchy_def LIMSEQ_def, safe)
```
```   365 apply (drule_tac x="r" in spec, safe)
```
```   366 apply (rule_tac x="M" in exI, safe)
```
```   367 apply (drule_tac x="Suc n" in spec, simp)
```
```   368 apply (drule_tac x="n" in spec, simp)
```
```   369 done
```
```   370
```
```   371 lemma summable_Cauchy:
```
```   372      "summable (f::nat \<Rightarrow> 'a::banach) =
```
```   373       (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. norm (setsum f {m..<n}) < e)"
```
```   374 apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_def, safe)
```
```   375 apply (drule spec, drule (1) mp)
```
```   376 apply (erule exE, rule_tac x="M" in exI, clarify)
```
```   377 apply (rule_tac x="m" and y="n" in linorder_le_cases)
```
```   378 apply (frule (1) order_trans)
```
```   379 apply (drule_tac x="n" in spec, drule (1) mp)
```
```   380 apply (drule_tac x="m" in spec, drule (1) mp)
```
```   381 apply (simp add: setsum_diff [symmetric])
```
```   382 apply simp
```
```   383 apply (drule spec, drule (1) mp)
```
```   384 apply (erule exE, rule_tac x="N" in exI, clarify)
```
```   385 apply (rule_tac x="m" and y="n" in linorder_le_cases)
```
```   386 apply (subst norm_minus_commute)
```
```   387 apply (simp add: setsum_diff [symmetric])
```
```   388 apply (simp add: setsum_diff [symmetric])
```
```   389 done
```
```   390
```
```   391 text{*Comparison test*}
```
```   392
```
```   393 lemma norm_setsum:
```
```   394   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
```
```   395   shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
```
```   396 apply (case_tac "finite A")
```
```   397 apply (erule finite_induct)
```
```   398 apply simp
```
```   399 apply simp
```
```   400 apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
```
```   401 apply simp
```
```   402 done
```
```   403
```
```   404 lemma summable_comparison_test:
```
```   405   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   406   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
```
```   407 apply (simp add: summable_Cauchy, safe)
```
```   408 apply (drule_tac x="e" in spec, safe)
```
```   409 apply (rule_tac x = "N + Na" in exI, safe)
```
```   410 apply (rotate_tac 2)
```
```   411 apply (drule_tac x = m in spec)
```
```   412 apply (auto, rotate_tac 2, drule_tac x = n in spec)
```
```   413 apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
```
```   414 apply (rule norm_setsum)
```
```   415 apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
```
```   416 apply (auto intro: setsum_mono simp add: abs_less_iff)
```
```   417 done
```
```   418
```
```   419 lemma summable_norm_comparison_test:
```
```   420   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   421   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk>
```
```   422          \<Longrightarrow> summable (\<lambda>n. norm (f n))"
```
```   423 apply (rule summable_comparison_test)
```
```   424 apply (auto)
```
```   425 done
```
```   426
```
```   427 lemma summable_rabs_comparison_test:
```
```   428   fixes f :: "nat \<Rightarrow> real"
```
```   429   shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. \<bar>f n\<bar>)"
```
```   430 apply (rule summable_comparison_test)
```
```   431 apply (auto)
```
```   432 done
```
```   433
```
```   434 text{*Summability of geometric series for real algebras*}
```
```   435
```
```   436 lemma complete_algebra_summable_geometric:
```
```   437   fixes x :: "'a::{real_normed_algebra_1,banach,recpower}"
```
```   438   shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
```
```   439 proof (rule summable_comparison_test)
```
```   440   show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
```
```   441     by (simp add: norm_power_ineq)
```
```   442   show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
```
```   443     by (simp add: summable_geometric)
```
```   444 qed
```
```   445
```
```   446 text{*Limit comparison property for series (c.f. jrh)*}
```
```   447
```
```   448 lemma summable_le:
```
```   449   fixes f g :: "nat \<Rightarrow> real"
```
```   450   shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
```
```   451 apply (drule summable_sums)+
```
```   452 apply (simp only: sums_def, erule (1) LIMSEQ_le)
```
```   453 apply (rule exI)
```
```   454 apply (auto intro!: setsum_mono)
```
```   455 done
```
```   456
```
```   457 lemma summable_le2:
```
```   458   fixes f g :: "nat \<Rightarrow> real"
```
```   459   shows "\<lbrakk>\<forall>n. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f \<and> suminf f \<le> suminf g"
```
```   460 apply (subgoal_tac "summable f")
```
```   461 apply (auto intro!: summable_le)
```
```   462 apply (simp add: abs_le_iff)
```
```   463 apply (rule_tac g="g" in summable_comparison_test, simp_all)
```
```   464 done
```
```   465
```
```   466 (* specialisation for the common 0 case *)
```
```   467 lemma suminf_0_le:
```
```   468   fixes f::"nat\<Rightarrow>real"
```
```   469   assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
```
```   470   shows "0 \<le> suminf f"
```
```   471 proof -
```
```   472   let ?g = "(\<lambda>n. (0::real))"
```
```   473   from gt0 have "\<forall>n. ?g n \<le> f n" by simp
```
```   474   moreover have "summable ?g" by (rule summable_zero)
```
```   475   moreover from sm have "summable f" .
```
```   476   ultimately have "suminf ?g \<le> suminf f" by (rule summable_le)
```
```   477   then show "0 \<le> suminf f" by (simp add: suminf_zero)
```
```   478 qed
```
```   479
```
```   480
```
```   481 text{*Absolute convergence imples normal convergence*}
```
```   482 lemma summable_norm_cancel:
```
```   483   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   484   shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
```
```   485 apply (simp only: summable_Cauchy, safe)
```
```   486 apply (drule_tac x="e" in spec, safe)
```
```   487 apply (rule_tac x="N" in exI, safe)
```
```   488 apply (drule_tac x="m" in spec, safe)
```
```   489 apply (rule order_le_less_trans [OF norm_setsum])
```
```   490 apply (rule order_le_less_trans [OF abs_ge_self])
```
```   491 apply simp
```
```   492 done
```
```   493
```
```   494 lemma summable_rabs_cancel:
```
```   495   fixes f :: "nat \<Rightarrow> real"
```
```   496   shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
```
```   497 by (rule summable_norm_cancel, simp)
```
```   498
```
```   499 text{*Absolute convergence of series*}
```
```   500 lemma summable_norm:
```
```   501   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   502   shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
```
```   503 by (auto intro: LIMSEQ_le LIMSEQ_norm summable_norm_cancel
```
```   504                 summable_sumr_LIMSEQ_suminf norm_setsum)
```
```   505
```
```   506 lemma summable_rabs:
```
```   507   fixes f :: "nat \<Rightarrow> real"
```
```   508   shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
```
```   509 by (fold real_norm_def, rule summable_norm)
```
```   510
```
```   511 subsection{* The Ratio Test*}
```
```   512
```
```   513 lemma norm_ratiotest_lemma:
```
```   514   fixes x y :: "'a::real_normed_vector"
```
```   515   shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
```
```   516 apply (subgoal_tac "norm x \<le> 0", simp)
```
```   517 apply (erule order_trans)
```
```   518 apply (simp add: mult_le_0_iff)
```
```   519 done
```
```   520
```
```   521 lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
```
```   522 by (erule norm_ratiotest_lemma, simp)
```
```   523
```
```   524 lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
```
```   525 apply (drule le_imp_less_or_eq)
```
```   526 apply (auto dest: less_imp_Suc_add)
```
```   527 done
```
```   528
```
```   529 lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
```
```   530 by (auto simp add: le_Suc_ex)
```
```   531
```
```   532 (*All this trouble just to get 0<c *)
```
```   533 lemma ratio_test_lemma2:
```
```   534   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   535   shows "\<lbrakk>\<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
```
```   536 apply (simp (no_asm) add: linorder_not_le [symmetric])
```
```   537 apply (simp add: summable_Cauchy)
```
```   538 apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
```
```   539  prefer 2
```
```   540  apply clarify
```
```   541  apply(erule_tac x = "n - Suc 0" in allE)
```
```   542  apply (simp add:diff_Suc split:nat.splits)
```
```   543  apply (blast intro: norm_ratiotest_lemma)
```
```   544 apply (rule_tac x = "Suc N" in exI, clarify)
```
```   545 apply(simp cong:setsum_ivl_cong)
```
```   546 done
```
```   547
```
```   548 lemma ratio_test:
```
```   549   fixes f :: "nat \<Rightarrow> 'a::banach"
```
```   550   shows "\<lbrakk>c < 1; \<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> summable f"
```
```   551 apply (frule ratio_test_lemma2, auto)
```
```   552 apply (rule_tac g = "%n. (norm (f N) / (c ^ N))*c ^ n"
```
```   553        in summable_comparison_test)
```
```   554 apply (rule_tac x = N in exI, safe)
```
```   555 apply (drule le_Suc_ex_iff [THEN iffD1])
```
```   556 apply (auto simp add: power_add field_power_not_zero)
```
```   557 apply (induct_tac "na", auto)
```
```   558 apply (rule_tac y = "c * norm (f (N + n))" in order_trans)
```
```   559 apply (auto intro: mult_right_mono simp add: summable_def)
```
```   560 apply (simp add: mult_ac)
```
```   561 apply (rule_tac x = "norm (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
```
```   562 apply (rule sums_divide)
```
```   563 apply (rule sums_mult)
```
```   564 apply (auto intro!: geometric_sums)
```
```   565 done
```
```   566
```
```   567 subsection {* Cauchy Product Formula *}
```
```   568
```
```   569 (* Proof based on Analysis WebNotes: Chapter 07, Class 41
```
```   570 http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm *)
```
```   571
```
```   572 lemma setsum_triangle_reindex:
```
```   573   fixes n :: nat
```
```   574   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))"
```
```   575 proof -
```
```   576   have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
```
```   577     (\<Sum>(k, i)\<in>(SIGMA k:{0..<n}. {0..k}). f i (k - i))"
```
```   578   proof (rule setsum_reindex_cong)
```
```   579     show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{0..<n}. {0..k})"
```
```   580       by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
```
```   581     show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{0..<n}. {0..k})"
```
```   582       by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
```
```   583     show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
```
```   584       by clarify
```
```   585   qed
```
```   586   thus ?thesis by (simp add: setsum_Sigma)
```
```   587 qed
```
```   588
```
```   589 lemma Cauchy_product_sums:
```
```   590   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
```
```   591   assumes a: "summable (\<lambda>k. norm (a k))"
```
```   592   assumes b: "summable (\<lambda>k. norm (b k))"
```
```   593   shows "(\<lambda>k. \<Sum>i=0..k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
```
```   594 proof -
```
```   595   let ?S1 = "\<lambda>n::nat. {0..<n} \<times> {0..<n}"
```
```   596   let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
```
```   597   have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
```
```   598   have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
```
```   599   have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
```
```   600   have finite_S1: "\<And>n. finite (?S1 n)" by simp
```
```   601   with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
```
```   602
```
```   603   let ?g = "\<lambda>(i,j). a i * b j"
```
```   604   let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
```
```   605   have f_nonneg: "\<And>x. 0 \<le> ?f x"
```
```   606     by (auto simp add: mult_nonneg_nonneg)
```
```   607   hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
```
```   608     unfolding real_norm_def
```
```   609     by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
```
```   610
```
```   611   have "(\<lambda>n. (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k))
```
```   612            ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
```
```   613     by (intro LIMSEQ_mult summable_sumr_LIMSEQ_suminf
```
```   614         summable_norm_cancel [OF a] summable_norm_cancel [OF b])
```
```   615   hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
```
```   616     by (simp only: setsum_product setsum_Sigma [rule_format]
```
```   617                    finite_atLeastLessThan)
```
```   618
```
```   619   have "(\<lambda>n. (\<Sum>k=0..<n. norm (a k)) * (\<Sum>k=0..<n. norm (b k)))
```
```   620        ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
```
```   621     using a b by (intro LIMSEQ_mult summable_sumr_LIMSEQ_suminf)
```
```   622   hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
```
```   623     by (simp only: setsum_product setsum_Sigma [rule_format]
```
```   624                    finite_atLeastLessThan)
```
```   625   hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
```
```   626     by (rule convergentI)
```
```   627   hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
```
```   628     by (rule convergent_Cauchy)
```
```   629   have "Zseq (\<lambda>n. setsum ?f (?S1 n - ?S2 n))"
```
```   630   proof (rule ZseqI, simp only: norm_setsum_f)
```
```   631     fix r :: real
```
```   632     assume r: "0 < r"
```
```   633     from CauchyD [OF Cauchy r] obtain N
```
```   634     where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
```
```   635     hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
```
```   636       by (simp only: setsum_diff finite_S1 S1_mono)
```
```   637     hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
```
```   638       by (simp only: norm_setsum_f)
```
```   639     show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
```
```   640     proof (intro exI allI impI)
```
```   641       fix n assume "2 * N \<le> n"
```
```   642       hence n: "N \<le> n div 2" by simp
```
```   643       have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
```
```   644         by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
```
```   645                   Diff_mono subset_refl S1_le_S2)
```
```   646       also have "\<dots> < r"
```
```   647         using n div_le_dividend by (rule N)
```
```   648       finally show "setsum ?f (?S1 n - ?S2 n) < r" .
```
```   649     qed
```
```   650   qed
```
```   651   hence "Zseq (\<lambda>n. setsum ?g (?S1 n - ?S2 n))"
```
```   652     apply (rule Zseq_le [rule_format])
```
```   653     apply (simp only: norm_setsum_f)
```
```   654     apply (rule order_trans [OF norm_setsum setsum_mono])
```
```   655     apply (auto simp add: norm_mult_ineq)
```
```   656     done
```
```   657   hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
```
```   658     by (simp only: LIMSEQ_Zseq_iff setsum_diff finite_S1 S2_le_S1 diff_0_right)
```
```   659
```
```   660   with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
```
```   661     by (rule LIMSEQ_diff_approach_zero2)
```
```   662   thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
```
```   663 qed
```
```   664
```
```   665 lemma Cauchy_product:
```
```   666   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
```
```   667   assumes a: "summable (\<lambda>k. norm (a k))"
```
```   668   assumes b: "summable (\<lambda>k. norm (b k))"
```
```   669   shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i=0..k. a i * b (k - i))"
```
```   670 using a b
```
```   671 by (rule Cauchy_product_sums [THEN sums_unique])
```
```   672
```
```   673 end
```