src/HOL/Series.thy
author hoelzl
Fri Mar 22 10:41:43 2013 +0100 (2013-03-22)
changeset 51474 1e9e68247ad1
parent 50999 3de230ed0547
child 51477 2990382dc066
permissions -rw-r--r--
generalize Bfun and Bseq to metric spaces; Bseq is an abbreviation for Bfun
paulson@10751
     1
(*  Title       : Series.thy
paulson@10751
     2
    Author      : Jacques D. Fleuriot
paulson@10751
     3
    Copyright   : 1998  University of Cambridge
paulson@14416
     4
paulson@14416
     5
Converted to Isar and polished by lcp
nipkow@15539
     6
Converted to setsum and polished yet more by TNN
avigad@16819
     7
Additional contributions by Jeremy Avigad
hoelzl@41970
     8
*)
paulson@10751
     9
paulson@14416
    10
header{*Finite Summation and Infinite Series*}
paulson@10751
    11
nipkow@15131
    12
theory Series
paulson@33271
    13
imports SEQ Deriv
nipkow@15131
    14
begin
nipkow@15561
    15
wenzelm@19765
    16
definition
hoelzl@41970
    17
   sums  :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a \<Rightarrow> bool"
wenzelm@21404
    18
     (infixr "sums" 80) where
wenzelm@19765
    19
   "f sums s = (%n. setsum f {0..<n}) ----> s"
paulson@10751
    20
wenzelm@21404
    21
definition
hoelzl@41970
    22
   summable :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> bool" where
wenzelm@19765
    23
   "summable f = (\<exists>s. f sums s)"
paulson@14416
    24
wenzelm@21404
    25
definition
hoelzl@41970
    26
   suminf   :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a" where
huffman@20688
    27
   "suminf f = (THE s. f sums s)"
paulson@14416
    28
huffman@44289
    29
notation suminf (binder "\<Sum>" 10)
nipkow@15546
    30
paulson@14416
    31
paulson@32877
    32
lemma [trans]: "f=g ==> g sums z ==> f sums z"
paulson@32877
    33
  by simp
paulson@32877
    34
nipkow@15539
    35
lemma sumr_diff_mult_const:
nipkow@15539
    36
 "setsum f {0..<n} - (real n*r) = setsum (%i. f i - r) {0..<n::nat}"
nipkow@15536
    37
by (simp add: diff_minus setsum_addf real_of_nat_def)
nipkow@15536
    38
nipkow@15542
    39
lemma real_setsum_nat_ivl_bounded:
nipkow@15542
    40
     "(!!p. p < n \<Longrightarrow> f(p) \<le> K)
nipkow@15542
    41
      \<Longrightarrow> setsum f {0..<n::nat} \<le> real n * K"
nipkow@15542
    42
using setsum_bounded[where A = "{0..<n}"]
nipkow@15542
    43
by (auto simp:real_of_nat_def)
paulson@14416
    44
nipkow@15539
    45
(* Generalize from real to some algebraic structure? *)
nipkow@15539
    46
lemma sumr_minus_one_realpow_zero [simp]:
nipkow@15543
    47
  "(\<Sum>i=0..<2*n. (-1) ^ Suc i) = (0::real)"
paulson@15251
    48
by (induct "n", auto)
paulson@14416
    49
nipkow@15539
    50
(* FIXME this is an awful lemma! *)
nipkow@15539
    51
lemma sumr_one_lb_realpow_zero [simp]:
nipkow@15539
    52
  "(\<Sum>n=Suc 0..<n. f(n) * (0::real) ^ n) = 0"
huffman@20692
    53
by (rule setsum_0', simp)
paulson@14416
    54
nipkow@15543
    55
lemma sumr_group:
nipkow@15539
    56
     "(\<Sum>m=0..<n::nat. setsum f {m * k ..< m*k + k}) = setsum f {0 ..< n * k}"
nipkow@15543
    57
apply (subgoal_tac "k = 0 | 0 < k", auto)
paulson@15251
    58
apply (induct "n")
nipkow@15539
    59
apply (simp_all add: setsum_add_nat_ivl add_commute)
paulson@14416
    60
done
nipkow@15539
    61
huffman@20692
    62
lemma sumr_offset3:
huffman@20692
    63
  "setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)) + setsum f {0..<k}"
huffman@20692
    64
apply (subst setsum_shift_bounds_nat_ivl [symmetric])
huffman@20692
    65
apply (simp add: setsum_add_nat_ivl add_commute)
huffman@20692
    66
done
huffman@20692
    67
avigad@16819
    68
lemma sumr_offset:
huffman@20692
    69
  fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
huffman@20692
    70
  shows "(\<Sum>m=0..<n. f(m+k)) = setsum f {0..<n+k} - setsum f {0..<k}"
huffman@20692
    71
by (simp add: sumr_offset3)
avigad@16819
    72
avigad@16819
    73
lemma sumr_offset2:
avigad@16819
    74
 "\<forall>f. (\<Sum>m=0..<n::nat. f(m+k)::real) = setsum f {0..<n+k} - setsum f {0..<k}"
huffman@20692
    75
by (simp add: sumr_offset)
avigad@16819
    76
avigad@16819
    77
lemma sumr_offset4:
huffman@20692
    78
  "\<forall>n f. setsum f {0::nat..<n+k} = (\<Sum>m=0..<n. f (m+k)::real) + setsum f {0..<k}"
huffman@20692
    79
by (clarify, rule sumr_offset3)
avigad@16819
    80
paulson@14416
    81
subsection{* Infinite Sums, by the Properties of Limits*}
paulson@14416
    82
paulson@14416
    83
(*----------------------
hoelzl@41970
    84
   suminf is the sum
paulson@14416
    85
 ---------------------*)
paulson@14416
    86
lemma sums_summable: "f sums l ==> summable f"
hoelzl@41970
    87
  by (simp add: sums_def summable_def, blast)
paulson@14416
    88
hoelzl@41970
    89
lemma summable_sums:
wenzelm@46904
    90
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
wenzelm@46904
    91
  assumes "summable f"
wenzelm@46904
    92
  shows "f sums (suminf f)"
hoelzl@41970
    93
proof -
wenzelm@46904
    94
  from assms obtain s where s: "(\<lambda>n. setsum f {0..<n}) ----> s"
wenzelm@46904
    95
    unfolding summable_def sums_def [abs_def] ..
wenzelm@46904
    96
  then show ?thesis unfolding sums_def [abs_def] suminf_def
hoelzl@41970
    97
    by (rule theI, auto intro!: tendsto_unique[OF trivial_limit_sequentially])
hoelzl@41970
    98
qed
paulson@14416
    99
hoelzl@41970
   100
lemma summable_sumr_LIMSEQ_suminf:
hoelzl@41970
   101
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
hoelzl@41970
   102
  shows "summable f \<Longrightarrow> (\<lambda>n. setsum f {0..<n}) ----> suminf f"
huffman@20688
   103
by (rule summable_sums [unfolded sums_def])
paulson@14416
   104
paulson@32707
   105
lemma suminf_eq_lim: "suminf f = lim (%n. setsum f {0..<n})"
hoelzl@41970
   106
  by (simp add: suminf_def sums_def lim_def)
paulson@32707
   107
paulson@14416
   108
(*-------------------
hoelzl@41970
   109
    sum is unique
paulson@14416
   110
 ------------------*)
hoelzl@41970
   111
lemma sums_unique:
hoelzl@41970
   112
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
hoelzl@41970
   113
  shows "f sums s \<Longrightarrow> (s = suminf f)"
hoelzl@41970
   114
apply (frule sums_summable[THEN summable_sums])
hoelzl@41970
   115
apply (auto intro!: tendsto_unique[OF trivial_limit_sequentially] simp add: sums_def)
paulson@14416
   116
done
paulson@14416
   117
hoelzl@41970
   118
lemma sums_iff:
hoelzl@41970
   119
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
hoelzl@41970
   120
  shows "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
paulson@32707
   121
  by (metis summable_sums sums_summable sums_unique)
paulson@32707
   122
hoelzl@47761
   123
lemma sums_finite:
hoelzl@47761
   124
  assumes [simp]: "finite N"
hoelzl@47761
   125
  assumes f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@47761
   126
  shows "f sums (\<Sum>n\<in>N. f n)"
hoelzl@47761
   127
proof -
hoelzl@47761
   128
  { fix n
hoelzl@47761
   129
    have "setsum f {..<n + Suc (Max N)} = setsum f N"
hoelzl@47761
   130
    proof cases
hoelzl@47761
   131
      assume "N = {}"
hoelzl@47761
   132
      with f have "f = (\<lambda>x. 0)" by auto
hoelzl@47761
   133
      then show ?thesis by simp
hoelzl@47761
   134
    next
hoelzl@47761
   135
      assume [simp]: "N \<noteq> {}"
hoelzl@47761
   136
      show ?thesis
hoelzl@47761
   137
      proof (safe intro!: setsum_mono_zero_right f)
hoelzl@47761
   138
        fix i assume "i \<in> N"
hoelzl@47761
   139
        then have "i \<le> Max N" by simp
hoelzl@47761
   140
        then show "i < n + Suc (Max N)" by simp
hoelzl@47761
   141
      qed
hoelzl@47761
   142
    qed }
hoelzl@47761
   143
  note eq = this
hoelzl@47761
   144
  show ?thesis unfolding sums_def
hoelzl@47761
   145
    by (rule LIMSEQ_offset[of _ "Suc (Max N)"])
hoelzl@47761
   146
       (simp add: eq atLeast0LessThan tendsto_const del: add_Suc_right)
hoelzl@47761
   147
qed
hoelzl@47761
   148
hoelzl@47761
   149
lemma suminf_finite:
hoelzl@47761
   150
  fixes f :: "nat \<Rightarrow> 'a::{comm_monoid_add,t2_space}"
hoelzl@47761
   151
  assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@47761
   152
  shows "suminf f = (\<Sum>n\<in>N. f n)"
hoelzl@47761
   153
  using sums_finite[OF assms, THEN sums_unique] by simp
hoelzl@47761
   154
hoelzl@47761
   155
lemma sums_If_finite_set:
hoelzl@47761
   156
  "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 0 :: 'a::{comm_monoid_add,t2_space}) sums (\<Sum>r\<in>A. f r)"
hoelzl@47761
   157
  using sums_finite[of A "(\<lambda>r. if r \<in> A then f r else 0)"] by simp
hoelzl@47761
   158
hoelzl@47761
   159
lemma sums_If_finite:
hoelzl@47761
   160
  "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 0 :: 'a::{comm_monoid_add,t2_space}) sums (\<Sum>r | P r. f r)"
hoelzl@47761
   161
  using sums_If_finite_set[of "{r. P r}" f] by simp
hoelzl@47761
   162
hoelzl@47761
   163
lemma sums_single:
hoelzl@47761
   164
  "(\<lambda>r. if r = i then f r else 0::'a::{comm_monoid_add,t2_space}) sums f i"
hoelzl@47761
   165
  using sums_If_finite[of "\<lambda>r. r = i" f] by simp
hoelzl@47761
   166
hoelzl@41970
   167
lemma sums_split_initial_segment:
hoelzl@41970
   168
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@41970
   169
  shows "f sums s ==> (\<lambda>n. f(n + k)) sums (s - (SUM i = 0..< k. f i))"
hoelzl@41970
   170
  apply (unfold sums_def)
hoelzl@41970
   171
  apply (simp add: sumr_offset)
huffman@44710
   172
  apply (rule tendsto_diff [OF _ tendsto_const])
avigad@16819
   173
  apply (rule LIMSEQ_ignore_initial_segment)
avigad@16819
   174
  apply assumption
avigad@16819
   175
done
avigad@16819
   176
hoelzl@41970
   177
lemma summable_ignore_initial_segment:
hoelzl@41970
   178
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@41970
   179
  shows "summable f ==> summable (%n. f(n + k))"
avigad@16819
   180
  apply (unfold summable_def)
avigad@16819
   181
  apply (auto intro: sums_split_initial_segment)
avigad@16819
   182
done
avigad@16819
   183
hoelzl@41970
   184
lemma suminf_minus_initial_segment:
hoelzl@41970
   185
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@41970
   186
  shows "summable f ==>
avigad@16819
   187
    suminf f = s ==> suminf (%n. f(n + k)) = s - (SUM i = 0..< k. f i)"
avigad@16819
   188
  apply (frule summable_ignore_initial_segment)
avigad@16819
   189
  apply (rule sums_unique [THEN sym])
avigad@16819
   190
  apply (frule summable_sums)
avigad@16819
   191
  apply (rule sums_split_initial_segment)
avigad@16819
   192
  apply auto
avigad@16819
   193
done
avigad@16819
   194
hoelzl@41970
   195
lemma suminf_split_initial_segment:
hoelzl@41970
   196
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@41970
   197
  shows "summable f ==>
hoelzl@41970
   198
    suminf f = (SUM i = 0..< k. f i) + (\<Sum>n. f(n + k))"
avigad@16819
   199
by (auto simp add: suminf_minus_initial_segment)
avigad@16819
   200
hoelzl@29803
   201
lemma suminf_exist_split: fixes r :: real assumes "0 < r" and "summable a"
hoelzl@29803
   202
  shows "\<exists> N. \<forall> n \<ge> N. \<bar> \<Sum> i. a (i + n) \<bar> < r"
hoelzl@29803
   203
proof -
hoelzl@29803
   204
  from LIMSEQ_D[OF summable_sumr_LIMSEQ_suminf[OF `summable a`] `0 < r`]
hoelzl@29803
   205
  obtain N :: nat where "\<forall> n \<ge> N. norm (setsum a {0..<n} - suminf a) < r" by auto
hoelzl@29803
   206
  thus ?thesis unfolding suminf_minus_initial_segment[OF `summable a` refl] abs_minus_commute real_norm_def
hoelzl@29803
   207
    by auto
hoelzl@29803
   208
qed
hoelzl@29803
   209
hoelzl@41970
   210
lemma sums_Suc:
hoelzl@41970
   211
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@41970
   212
  assumes sumSuc: "(\<lambda> n. f (Suc n)) sums l" shows "f sums (l + f 0)"
hoelzl@29803
   213
proof -
hoelzl@29803
   214
  from sumSuc[unfolded sums_def]
hoelzl@29803
   215
  have "(\<lambda>i. \<Sum>n = Suc 0..<Suc i. f n) ----> l" unfolding setsum_reindex[OF inj_Suc] image_Suc_atLeastLessThan[symmetric] comp_def .
huffman@44710
   216
  from tendsto_add[OF this tendsto_const, where b="f 0"]
hoelzl@29803
   217
  have "(\<lambda>i. \<Sum>n = 0..<Suc i. f n) ----> l + f 0" unfolding add_commute setsum_head_upt_Suc[OF zero_less_Suc] .
hoelzl@29803
   218
  thus ?thesis unfolding sums_def by (rule LIMSEQ_imp_Suc)
hoelzl@29803
   219
qed
hoelzl@29803
   220
hoelzl@41970
   221
lemma series_zero:
hoelzl@41970
   222
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
hoelzl@41970
   223
  assumes "\<forall>m. n \<le> m \<longrightarrow> f m = 0"
hoelzl@41970
   224
  shows "f sums (setsum f {0..<n})"
hoelzl@41970
   225
proof -
hoelzl@41970
   226
  { fix k :: nat have "setsum f {0..<k + n} = setsum f {0..<n}"
hoelzl@41970
   227
      using assms by (induct k) auto }
hoelzl@41970
   228
  note setsum_const = this
hoelzl@41970
   229
  show ?thesis
hoelzl@41970
   230
    unfolding sums_def
hoelzl@41970
   231
    apply (rule LIMSEQ_offset[of _ n])
hoelzl@41970
   232
    unfolding setsum_const
huffman@44568
   233
    apply (rule tendsto_const)
hoelzl@41970
   234
    done
hoelzl@41970
   235
qed
paulson@14416
   236
hoelzl@41970
   237
lemma sums_zero[simp, intro]: "(\<lambda>n. 0) sums 0"
huffman@44568
   238
  unfolding sums_def by (simp add: tendsto_const)
nipkow@15539
   239
hoelzl@41970
   240
lemma summable_zero[simp, intro]: "summable (\<lambda>n. 0)"
huffman@23121
   241
by (rule sums_zero [THEN sums_summable])
avigad@16819
   242
hoelzl@41970
   243
lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
huffman@23121
   244
by (rule sums_zero [THEN sums_unique, symmetric])
hoelzl@41970
   245
huffman@23119
   246
lemma (in bounded_linear) sums:
huffman@23119
   247
  "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
huffman@44568
   248
  unfolding sums_def by (drule tendsto, simp only: setsum)
huffman@23119
   249
huffman@23119
   250
lemma (in bounded_linear) summable:
huffman@23119
   251
  "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
huffman@23119
   252
unfolding summable_def by (auto intro: sums)
huffman@23119
   253
huffman@23119
   254
lemma (in bounded_linear) suminf:
huffman@23119
   255
  "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
huffman@23121
   256
by (intro sums_unique sums summable_sums)
huffman@23119
   257
huffman@44282
   258
lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
huffman@44282
   259
lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
huffman@44282
   260
lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
huffman@44282
   261
huffman@20692
   262
lemma sums_mult:
huffman@20692
   263
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   264
  shows "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
huffman@44282
   265
  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
paulson@14416
   266
huffman@20692
   267
lemma summable_mult:
huffman@20692
   268
  fixes c :: "'a::real_normed_algebra"
huffman@23121
   269
  shows "summable f \<Longrightarrow> summable (%n. c * f n)"
huffman@44282
   270
  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
avigad@16819
   271
huffman@20692
   272
lemma suminf_mult:
huffman@20692
   273
  fixes c :: "'a::real_normed_algebra"
hoelzl@41970
   274
  shows "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
huffman@44282
   275
  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
avigad@16819
   276
huffman@20692
   277
lemma sums_mult2:
huffman@20692
   278
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   279
  shows "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
huffman@44282
   280
  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
avigad@16819
   281
huffman@20692
   282
lemma summable_mult2:
huffman@20692
   283
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   284
  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
huffman@44282
   285
  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
avigad@16819
   286
huffman@20692
   287
lemma suminf_mult2:
huffman@20692
   288
  fixes c :: "'a::real_normed_algebra"
huffman@20692
   289
  shows "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
huffman@44282
   290
  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
avigad@16819
   291
huffman@20692
   292
lemma sums_divide:
huffman@20692
   293
  fixes c :: "'a::real_normed_field"
huffman@20692
   294
  shows "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
huffman@44282
   295
  by (rule bounded_linear.sums [OF bounded_linear_divide])
paulson@14416
   296
huffman@20692
   297
lemma summable_divide:
huffman@20692
   298
  fixes c :: "'a::real_normed_field"
huffman@20692
   299
  shows "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
huffman@44282
   300
  by (rule bounded_linear.summable [OF bounded_linear_divide])
avigad@16819
   301
huffman@20692
   302
lemma suminf_divide:
huffman@20692
   303
  fixes c :: "'a::real_normed_field"
huffman@20692
   304
  shows "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
huffman@44282
   305
  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
avigad@16819
   306
hoelzl@41970
   307
lemma sums_add:
hoelzl@41970
   308
  fixes a b :: "'a::real_normed_field"
hoelzl@41970
   309
  shows "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) sums (a + b)"
huffman@44568
   310
  unfolding sums_def by (simp add: setsum_addf tendsto_add)
avigad@16819
   311
hoelzl@41970
   312
lemma summable_add:
hoelzl@41970
   313
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   314
  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n + Y n)"
huffman@23121
   315
unfolding summable_def by (auto intro: sums_add)
avigad@16819
   316
avigad@16819
   317
lemma suminf_add:
hoelzl@41970
   318
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   319
  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X + suminf Y = (\<Sum>n. X n + Y n)"
huffman@23121
   320
by (intro sums_unique sums_add summable_sums)
paulson@14416
   321
hoelzl@41970
   322
lemma sums_diff:
hoelzl@41970
   323
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   324
  shows "\<lbrakk>X sums a; Y sums b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) sums (a - b)"
huffman@44568
   325
  unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
huffman@23121
   326
hoelzl@41970
   327
lemma summable_diff:
hoelzl@41970
   328
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   329
  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> summable (\<lambda>n. X n - Y n)"
huffman@23121
   330
unfolding summable_def by (auto intro: sums_diff)
paulson@14416
   331
paulson@14416
   332
lemma suminf_diff:
hoelzl@41970
   333
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   334
  shows "\<lbrakk>summable X; summable Y\<rbrakk> \<Longrightarrow> suminf X - suminf Y = (\<Sum>n. X n - Y n)"
huffman@23121
   335
by (intro sums_unique sums_diff summable_sums)
paulson@14416
   336
hoelzl@41970
   337
lemma sums_minus:
hoelzl@41970
   338
  fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   339
  shows "X sums a ==> (\<lambda>n. - X n) sums (- a)"
huffman@44568
   340
  unfolding sums_def by (simp add: setsum_negf tendsto_minus)
avigad@16819
   341
hoelzl@41970
   342
lemma summable_minus:
hoelzl@41970
   343
  fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   344
  shows "summable X \<Longrightarrow> summable (\<lambda>n. - X n)"
huffman@23121
   345
unfolding summable_def by (auto intro: sums_minus)
avigad@16819
   346
hoelzl@41970
   347
lemma suminf_minus:
hoelzl@41970
   348
  fixes X :: "nat \<Rightarrow> 'a::real_normed_field"
hoelzl@41970
   349
  shows "summable X \<Longrightarrow> (\<Sum>n. - X n) = - (\<Sum>n. X n)"
huffman@23121
   350
by (intro sums_unique [symmetric] sums_minus summable_sums)
paulson@14416
   351
paulson@14416
   352
lemma sums_group:
hoelzl@41970
   353
  fixes f :: "nat \<Rightarrow> 'a::real_normed_field"
huffman@44727
   354
  shows "\<lbrakk>f sums s; 0 < k\<rbrakk> \<Longrightarrow> (\<lambda>n. setsum f {n*k..<n*k+k}) sums s"
huffman@20692
   355
apply (simp only: sums_def sumr_group)
huffman@31336
   356
apply (unfold LIMSEQ_iff, safe)
huffman@20692
   357
apply (drule_tac x="r" in spec, safe)
huffman@20692
   358
apply (rule_tac x="no" in exI, safe)
huffman@20692
   359
apply (drule_tac x="n*k" in spec)
huffman@20692
   360
apply (erule mp)
huffman@20692
   361
apply (erule order_trans)
huffman@20692
   362
apply simp
paulson@14416
   363
done
paulson@14416
   364
paulson@15085
   365
text{*A summable series of positive terms has limit that is at least as
paulson@15085
   366
great as any partial sum.*}
paulson@14416
   367
paulson@33271
   368
lemma pos_summable:
paulson@33271
   369
  fixes f:: "nat \<Rightarrow> real"
hoelzl@50999
   370
  assumes pos: "\<And>n. 0 \<le> f n" and le: "\<And>n. setsum f {0..<n} \<le> x"
paulson@33271
   371
  shows "summable f"
paulson@33271
   372
proof -
hoelzl@41970
   373
  have "convergent (\<lambda>n. setsum f {0..<n})"
paulson@33271
   374
    proof (rule Bseq_mono_convergent)
paulson@33271
   375
      show "Bseq (\<lambda>n. setsum f {0..<n})"
wenzelm@33536
   376
        by (rule f_inc_g_dec_Beq_f [of "(\<lambda>n. setsum f {0..<n})" "\<lambda>n. x"])
hoelzl@41970
   377
           (auto simp add: le pos)
hoelzl@41970
   378
    next
paulson@33271
   379
      show "\<forall>m n. m \<le> n \<longrightarrow> setsum f {0..<m} \<le> setsum f {0..<n}"
hoelzl@41970
   380
        by (auto intro: setsum_mono2 pos)
paulson@33271
   381
    qed
paulson@33271
   382
  then obtain L where "(%n. setsum f {0..<n}) ----> L"
paulson@33271
   383
    by (blast dest: convergentD)
paulson@33271
   384
  thus ?thesis
hoelzl@41970
   385
    by (force simp add: summable_def sums_def)
paulson@33271
   386
qed
paulson@33271
   387
huffman@20692
   388
lemma series_pos_le:
hoelzl@50999
   389
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
huffman@20692
   390
  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 \<le> f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} \<le> suminf f"
hoelzl@50999
   391
  apply (drule summable_sums)
hoelzl@50999
   392
  apply (simp add: sums_def)
hoelzl@50999
   393
  apply (rule LIMSEQ_le_const)
hoelzl@50999
   394
  apply assumption
hoelzl@50999
   395
  apply (intro exI[of _ n])
hoelzl@50999
   396
  apply (auto intro!: setsum_mono2)
hoelzl@50999
   397
  done
paulson@14416
   398
paulson@14416
   399
lemma series_pos_less:
hoelzl@50999
   400
  fixes f :: "nat \<Rightarrow> 'a::{ordered_ab_semigroup_add_imp_le, ordered_comm_monoid_add, linorder_topology}"
huffman@20692
   401
  shows "\<lbrakk>summable f; \<forall>m\<ge>n. 0 < f m\<rbrakk> \<Longrightarrow> setsum f {0..<n} < suminf f"
hoelzl@50999
   402
  apply (rule_tac y="setsum f {0..<Suc n}" in order_less_le_trans)
hoelzl@50999
   403
  using add_less_cancel_left [of "setsum f {0..<n}" 0 "f n"]
hoelzl@50999
   404
  apply simp
hoelzl@50999
   405
  apply (erule series_pos_le)
hoelzl@50999
   406
  apply (simp add: order_less_imp_le)
hoelzl@50999
   407
  done
hoelzl@50999
   408
hoelzl@50999
   409
lemma suminf_eq_zero_iff:
hoelzl@50999
   410
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@50999
   411
  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> suminf f = 0 \<longleftrightarrow> (\<forall>n. f n = 0)"
hoelzl@50999
   412
proof
hoelzl@50999
   413
  assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
hoelzl@50999
   414
  then have "f sums 0"
hoelzl@50999
   415
    by (simp add: sums_iff)
hoelzl@50999
   416
  then have f: "(\<lambda>n. \<Sum>i<n. f i) ----> 0"
hoelzl@50999
   417
    by (simp add: sums_def atLeast0LessThan)
hoelzl@50999
   418
  have "\<And>i. (\<Sum>n\<in>{i}. f n) \<le> 0"
hoelzl@50999
   419
  proof (rule LIMSEQ_le_const[OF f])
hoelzl@50999
   420
    fix i show "\<exists>N. \<forall>n\<ge>N. (\<Sum>n\<in>{i}. f n) \<le> setsum f {..<n}"
hoelzl@50999
   421
      using pos by (intro exI[of _ "Suc i"] allI impI setsum_mono2) auto
hoelzl@50999
   422
  qed
hoelzl@50999
   423
  with pos show "\<forall>n. f n = 0"
hoelzl@50999
   424
    by (auto intro!: antisym)
hoelzl@50999
   425
next
hoelzl@50999
   426
  assume "\<forall>n. f n = 0"
hoelzl@50999
   427
  then have "f = (\<lambda>n. 0)"
hoelzl@50999
   428
    by auto
hoelzl@50999
   429
  then show "suminf f = 0"
hoelzl@50999
   430
    by simp
hoelzl@50999
   431
qed
hoelzl@50999
   432
hoelzl@50999
   433
lemma suminf_gt_zero_iff:
hoelzl@50999
   434
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@50999
   435
  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
hoelzl@50999
   436
  using series_pos_le[of f 0] suminf_eq_zero_iff[of f]
hoelzl@50999
   437
  by (simp add: less_le)
huffman@20692
   438
huffman@20692
   439
lemma suminf_gt_zero:
hoelzl@50999
   440
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
huffman@20692
   441
  shows "\<lbrakk>summable f; \<forall>n. 0 < f n\<rbrakk> \<Longrightarrow> 0 < suminf f"
hoelzl@50999
   442
  using suminf_gt_zero_iff[of f] by (simp add: less_imp_le)
huffman@20692
   443
huffman@20692
   444
lemma suminf_ge_zero:
hoelzl@50999
   445
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
huffman@20692
   446
  shows "\<lbrakk>summable f; \<forall>n. 0 \<le> f n\<rbrakk> \<Longrightarrow> 0 \<le> suminf f"
hoelzl@50999
   447
  by (drule_tac n="0" in series_pos_le, simp_all)
huffman@20692
   448
huffman@20692
   449
lemma sumr_pos_lt_pair:
huffman@20692
   450
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   451
  shows "\<lbrakk>summable f;
huffman@20692
   452
        \<forall>d. 0 < f (k + (Suc(Suc 0) * d)) + f (k + ((Suc(Suc 0) * d) + 1))\<rbrakk>
huffman@20692
   453
      \<Longrightarrow> setsum f {0..<k} < suminf f"
huffman@30082
   454
unfolding One_nat_def
huffman@20692
   455
apply (subst suminf_split_initial_segment [where k="k"])
huffman@20692
   456
apply assumption
huffman@20692
   457
apply simp
huffman@20692
   458
apply (drule_tac k="k" in summable_ignore_initial_segment)
huffman@44727
   459
apply (drule_tac k="Suc (Suc 0)" in sums_group [OF summable_sums], simp)
huffman@20692
   460
apply simp
huffman@20692
   461
apply (frule sums_unique)
huffman@20692
   462
apply (drule sums_summable)
huffman@20692
   463
apply simp
huffman@20692
   464
apply (erule suminf_gt_zero)
huffman@20692
   465
apply (simp add: add_ac)
paulson@14416
   466
done
paulson@14416
   467
paulson@15085
   468
text{*Sum of a geometric progression.*}
paulson@14416
   469
ballarin@17149
   470
lemmas sumr_geometric = geometric_sum [where 'a = real]
paulson@14416
   471
huffman@20692
   472
lemma geometric_sums:
haftmann@31017
   473
  fixes x :: "'a::{real_normed_field}"
huffman@20692
   474
  shows "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) sums (1 / (1 - x))"
huffman@20692
   475
proof -
huffman@20692
   476
  assume less_1: "norm x < 1"
huffman@20692
   477
  hence neq_1: "x \<noteq> 1" by auto
huffman@20692
   478
  hence neq_0: "x - 1 \<noteq> 0" by simp
huffman@20692
   479
  from less_1 have lim_0: "(\<lambda>n. x ^ n) ----> 0"
huffman@20692
   480
    by (rule LIMSEQ_power_zero)
huffman@22719
   481
  hence "(\<lambda>n. x ^ n / (x - 1) - 1 / (x - 1)) ----> 0 / (x - 1) - 1 / (x - 1)"
huffman@44568
   482
    using neq_0 by (intro tendsto_intros)
huffman@20692
   483
  hence "(\<lambda>n. (x ^ n - 1) / (x - 1)) ----> 1 / (1 - x)"
huffman@20692
   484
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
huffman@20692
   485
  thus "(\<lambda>n. x ^ n) sums (1 / (1 - x))"
huffman@20692
   486
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   487
qed
huffman@20692
   488
huffman@20692
   489
lemma summable_geometric:
haftmann@31017
   490
  fixes x :: "'a::{real_normed_field}"
huffman@20692
   491
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@20692
   492
by (rule geometric_sums [THEN sums_summable])
paulson@14416
   493
huffman@47108
   494
lemma half: "0 < 1 / (2::'a::linordered_field)"
huffman@47108
   495
  by simp
paulson@33271
   496
paulson@33271
   497
lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
paulson@33271
   498
proof -
paulson@33271
   499
  have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
paulson@33271
   500
    by auto
paulson@33271
   501
  have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
paulson@33271
   502
    by simp
huffman@44282
   503
  thus ?thesis using sums_divide [OF 2, of 2]
paulson@33271
   504
    by simp
paulson@33271
   505
qed
paulson@33271
   506
paulson@15085
   507
text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
paulson@15085
   508
nipkow@15539
   509
lemma summable_convergent_sumr_iff:
nipkow@15539
   510
 "summable f = convergent (%n. setsum f {0..<n})"
paulson@14416
   511
by (simp add: summable_def sums_def convergent_def)
paulson@14416
   512
hoelzl@41970
   513
lemma summable_LIMSEQ_zero:
huffman@44726
   514
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@41970
   515
  shows "summable f \<Longrightarrow> f ----> 0"
huffman@20689
   516
apply (drule summable_convergent_sumr_iff [THEN iffD1])
huffman@20692
   517
apply (drule convergent_Cauchy)
huffman@31336
   518
apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
huffman@20689
   519
apply (drule_tac x="r" in spec, safe)
huffman@20689
   520
apply (rule_tac x="M" in exI, safe)
huffman@20689
   521
apply (drule_tac x="Suc n" in spec, simp)
huffman@20689
   522
apply (drule_tac x="n" in spec, simp)
huffman@20689
   523
done
huffman@20689
   524
paulson@32707
   525
lemma suminf_le:
hoelzl@50999
   526
  fixes x :: "'a :: {ordered_comm_monoid_add, linorder_topology}"
paulson@32707
   527
  shows "summable f \<Longrightarrow> (!!n. setsum f {0..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
hoelzl@50999
   528
  apply (drule summable_sums)
hoelzl@50999
   529
  apply (simp add: sums_def)
hoelzl@50999
   530
  apply (rule LIMSEQ_le_const2)
hoelzl@50999
   531
  apply assumption
hoelzl@50999
   532
  apply auto
hoelzl@50999
   533
  done
paulson@32707
   534
paulson@14416
   535
lemma summable_Cauchy:
hoelzl@41970
   536
     "summable (f::nat \<Rightarrow> 'a::banach) =
huffman@20848
   537
      (\<forall>e > 0. \<exists>N. \<forall>m \<ge> N. \<forall>n. norm (setsum f {m..<n}) < e)"
huffman@31336
   538
apply (simp only: summable_convergent_sumr_iff Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
huffman@20410
   539
apply (drule spec, drule (1) mp)
huffman@20410
   540
apply (erule exE, rule_tac x="M" in exI, clarify)
huffman@20410
   541
apply (rule_tac x="m" and y="n" in linorder_le_cases)
huffman@20410
   542
apply (frule (1) order_trans)
huffman@20410
   543
apply (drule_tac x="n" in spec, drule (1) mp)
huffman@20410
   544
apply (drule_tac x="m" in spec, drule (1) mp)
huffman@20410
   545
apply (simp add: setsum_diff [symmetric])
huffman@20410
   546
apply simp
huffman@20410
   547
apply (drule spec, drule (1) mp)
huffman@20410
   548
apply (erule exE, rule_tac x="N" in exI, clarify)
huffman@20410
   549
apply (rule_tac x="m" and y="n" in linorder_le_cases)
huffman@20552
   550
apply (subst norm_minus_commute)
huffman@20410
   551
apply (simp add: setsum_diff [symmetric])
huffman@20410
   552
apply (simp add: setsum_diff [symmetric])
paulson@14416
   553
done
paulson@14416
   554
paulson@15085
   555
text{*Comparison test*}
paulson@15085
   556
huffman@20692
   557
lemma norm_setsum:
huffman@20692
   558
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
huffman@20692
   559
  shows "norm (setsum f A) \<le> (\<Sum>i\<in>A. norm (f i))"
huffman@20692
   560
apply (case_tac "finite A")
huffman@20692
   561
apply (erule finite_induct)
huffman@20692
   562
apply simp
huffman@20692
   563
apply simp
huffman@20692
   564
apply (erule order_trans [OF norm_triangle_ineq add_left_mono])
huffman@20692
   565
apply simp
huffman@20692
   566
done
huffman@20692
   567
paulson@14416
   568
lemma summable_comparison_test:
huffman@20848
   569
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   570
  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f"
huffman@20692
   571
apply (simp add: summable_Cauchy, safe)
huffman@20692
   572
apply (drule_tac x="e" in spec, safe)
huffman@20692
   573
apply (rule_tac x = "N + Na" in exI, safe)
paulson@14416
   574
apply (rotate_tac 2)
paulson@14416
   575
apply (drule_tac x = m in spec)
paulson@14416
   576
apply (auto, rotate_tac 2, drule_tac x = n in spec)
huffman@20848
   577
apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
huffman@20848
   578
apply (rule norm_setsum)
nipkow@15539
   579
apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
huffman@22998
   580
apply (auto intro: setsum_mono simp add: abs_less_iff)
paulson@14416
   581
done
paulson@14416
   582
huffman@20848
   583
lemma summable_norm_comparison_test:
huffman@20848
   584
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   585
  shows "\<lbrakk>\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n; summable g\<rbrakk>
huffman@20848
   586
         \<Longrightarrow> summable (\<lambda>n. norm (f n))"
huffman@20848
   587
apply (rule summable_comparison_test)
huffman@20848
   588
apply (auto)
huffman@20848
   589
done
huffman@20848
   590
paulson@14416
   591
lemma summable_rabs_comparison_test:
huffman@20692
   592
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   593
  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>)"
paulson@14416
   594
apply (rule summable_comparison_test)
nipkow@15543
   595
apply (auto)
paulson@14416
   596
done
paulson@14416
   597
huffman@23084
   598
text{*Summability of geometric series for real algebras*}
huffman@23084
   599
huffman@23084
   600
lemma complete_algebra_summable_geometric:
haftmann@31017
   601
  fixes x :: "'a::{real_normed_algebra_1,banach}"
huffman@23084
   602
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@23084
   603
proof (rule summable_comparison_test)
huffman@23084
   604
  show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
huffman@23084
   605
    by (simp add: norm_power_ineq)
huffman@23084
   606
  show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
huffman@23084
   607
    by (simp add: summable_geometric)
huffman@23084
   608
qed
huffman@23084
   609
paulson@15085
   610
text{*Limit comparison property for series (c.f. jrh)*}
paulson@15085
   611
paulson@14416
   612
lemma summable_le:
hoelzl@50999
   613
  fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
huffman@20692
   614
  shows "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
paulson@14416
   615
apply (drule summable_sums)+
huffman@20692
   616
apply (simp only: sums_def, erule (1) LIMSEQ_le)
paulson@14416
   617
apply (rule exI)
nipkow@15539
   618
apply (auto intro!: setsum_mono)
paulson@14416
   619
done
paulson@14416
   620
paulson@14416
   621
lemma summable_le2:
huffman@20692
   622
  fixes f g :: "nat \<Rightarrow> real"
huffman@20692
   623
  shows "\<lbrakk>\<forall>n. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable f \<and> suminf f \<le> suminf g"
huffman@20848
   624
apply (subgoal_tac "summable f")
huffman@20848
   625
apply (auto intro!: summable_le)
huffman@22998
   626
apply (simp add: abs_le_iff)
huffman@20848
   627
apply (rule_tac g="g" in summable_comparison_test, simp_all)
paulson@14416
   628
done
paulson@14416
   629
kleing@19106
   630
(* specialisation for the common 0 case *)
kleing@19106
   631
lemma suminf_0_le:
kleing@19106
   632
  fixes f::"nat\<Rightarrow>real"
kleing@19106
   633
  assumes gt0: "\<forall>n. 0 \<le> f n" and sm: "summable f"
kleing@19106
   634
  shows "0 \<le> suminf f"
hoelzl@50999
   635
  using suminf_ge_zero[OF sm gt0] by simp
kleing@19106
   636
paulson@15085
   637
text{*Absolute convergence imples normal convergence*}
huffman@20848
   638
lemma summable_norm_cancel:
huffman@20848
   639
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   640
  shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
huffman@20692
   641
apply (simp only: summable_Cauchy, safe)
huffman@20692
   642
apply (drule_tac x="e" in spec, safe)
huffman@20692
   643
apply (rule_tac x="N" in exI, safe)
huffman@20692
   644
apply (drule_tac x="m" in spec, safe)
huffman@20848
   645
apply (rule order_le_less_trans [OF norm_setsum])
huffman@20848
   646
apply (rule order_le_less_trans [OF abs_ge_self])
huffman@20692
   647
apply simp
paulson@14416
   648
done
paulson@14416
   649
huffman@20848
   650
lemma summable_rabs_cancel:
huffman@20848
   651
  fixes f :: "nat \<Rightarrow> real"
huffman@20848
   652
  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> summable f"
huffman@20848
   653
by (rule summable_norm_cancel, simp)
huffman@20848
   654
paulson@15085
   655
text{*Absolute convergence of series*}
huffman@20848
   656
lemma summable_norm:
huffman@20848
   657
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   658
  shows "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
huffman@44568
   659
  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel
huffman@20848
   660
                summable_sumr_LIMSEQ_suminf norm_setsum)
huffman@20848
   661
paulson@14416
   662
lemma summable_rabs:
huffman@20692
   663
  fixes f :: "nat \<Rightarrow> real"
huffman@20692
   664
  shows "summable (\<lambda>n. \<bar>f n\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
huffman@20848
   665
by (fold real_norm_def, rule summable_norm)
paulson@14416
   666
paulson@14416
   667
subsection{* The Ratio Test*}
paulson@14416
   668
huffman@20848
   669
lemma norm_ratiotest_lemma:
huffman@22852
   670
  fixes x y :: "'a::real_normed_vector"
huffman@20848
   671
  shows "\<lbrakk>c \<le> 0; norm x \<le> c * norm y\<rbrakk> \<Longrightarrow> x = 0"
huffman@20848
   672
apply (subgoal_tac "norm x \<le> 0", simp)
huffman@20848
   673
apply (erule order_trans)
huffman@20848
   674
apply (simp add: mult_le_0_iff)
huffman@20848
   675
done
huffman@20848
   676
paulson@14416
   677
lemma rabs_ratiotest_lemma: "[| c \<le> 0; abs x \<le> c * abs y |] ==> x = (0::real)"
huffman@20848
   678
by (erule norm_ratiotest_lemma, simp)
paulson@14416
   679
hoelzl@50331
   680
(* TODO: MOVE *)
paulson@14416
   681
lemma le_Suc_ex: "(k::nat) \<le> l ==> (\<exists>n. l = k + n)"
paulson@14416
   682
apply (drule le_imp_less_or_eq)
paulson@14416
   683
apply (auto dest: less_imp_Suc_add)
paulson@14416
   684
done
paulson@14416
   685
paulson@14416
   686
lemma le_Suc_ex_iff: "((k::nat) \<le> l) = (\<exists>n. l = k + n)"
paulson@14416
   687
by (auto simp add: le_Suc_ex)
paulson@14416
   688
paulson@14416
   689
(*All this trouble just to get 0<c *)
paulson@14416
   690
lemma ratio_test_lemma2:
huffman@20848
   691
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   692
  shows "\<lbrakk>\<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> 0 < c \<or> summable f"
paulson@14416
   693
apply (simp (no_asm) add: linorder_not_le [symmetric])
paulson@14416
   694
apply (simp add: summable_Cauchy)
nipkow@15543
   695
apply (safe, subgoal_tac "\<forall>n. N < n --> f (n) = 0")
nipkow@15543
   696
 prefer 2
nipkow@15543
   697
 apply clarify
huffman@30082
   698
 apply(erule_tac x = "n - Suc 0" in allE)
nipkow@15543
   699
 apply (simp add:diff_Suc split:nat.splits)
huffman@20848
   700
 apply (blast intro: norm_ratiotest_lemma)
paulson@14416
   701
apply (rule_tac x = "Suc N" in exI, clarify)
huffman@44710
   702
apply(simp cong del: setsum_cong cong: setsum_ivl_cong)
paulson@14416
   703
done
paulson@14416
   704
paulson@14416
   705
lemma ratio_test:
huffman@20848
   706
  fixes f :: "nat \<Rightarrow> 'a::banach"
huffman@20848
   707
  shows "\<lbrakk>c < 1; \<forall>n\<ge>N. norm (f (Suc n)) \<le> c * norm (f n)\<rbrakk> \<Longrightarrow> summable f"
paulson@14416
   708
apply (frule ratio_test_lemma2, auto)
hoelzl@41970
   709
apply (rule_tac g = "%n. (norm (f N) / (c ^ N))*c ^ n"
paulson@15234
   710
       in summable_comparison_test)
paulson@14416
   711
apply (rule_tac x = N in exI, safe)
paulson@14416
   712
apply (drule le_Suc_ex_iff [THEN iffD1])
huffman@22959
   713
apply (auto simp add: power_add field_power_not_zero)
nipkow@15539
   714
apply (induct_tac "na", auto)
huffman@20848
   715
apply (rule_tac y = "c * norm (f (N + n))" in order_trans)
paulson@14416
   716
apply (auto intro: mult_right_mono simp add: summable_def)
huffman@20848
   717
apply (rule_tac x = "norm (f N) * (1/ (1 - c)) / (c ^ N)" in exI)
hoelzl@41970
   718
apply (rule sums_divide)
haftmann@27108
   719
apply (rule sums_mult)
paulson@15234
   720
apply (auto intro!: geometric_sums)
paulson@14416
   721
done
paulson@14416
   722
huffman@23111
   723
subsection {* Cauchy Product Formula *}
huffman@23111
   724
huffman@23111
   725
(* Proof based on Analysis WebNotes: Chapter 07, Class 41
huffman@23111
   726
http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm *)
huffman@23111
   727
huffman@23111
   728
lemma setsum_triangle_reindex:
huffman@23111
   729
  fixes n :: nat
huffman@23111
   730
  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))"
huffman@23111
   731
proof -
huffman@23111
   732
  have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
huffman@23111
   733
    (\<Sum>(k, i)\<in>(SIGMA k:{0..<n}. {0..k}). f i (k - i))"
huffman@23111
   734
  proof (rule setsum_reindex_cong)
huffman@23111
   735
    show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{0..<n}. {0..k})"
huffman@23111
   736
      by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
huffman@23111
   737
    show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{0..<n}. {0..k})"
huffman@23111
   738
      by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
huffman@23111
   739
    show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
huffman@23111
   740
      by clarify
huffman@23111
   741
  qed
huffman@23111
   742
  thus ?thesis by (simp add: setsum_Sigma)
huffman@23111
   743
qed
huffman@23111
   744
huffman@23111
   745
lemma Cauchy_product_sums:
huffman@23111
   746
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   747
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   748
  assumes b: "summable (\<lambda>k. norm (b k))"
huffman@23111
   749
  shows "(\<lambda>k. \<Sum>i=0..k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
huffman@23111
   750
proof -
huffman@23111
   751
  let ?S1 = "\<lambda>n::nat. {0..<n} \<times> {0..<n}"
huffman@23111
   752
  let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
huffman@23111
   753
  have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
huffman@23111
   754
  have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
huffman@23111
   755
  have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
huffman@23111
   756
  have finite_S1: "\<And>n. finite (?S1 n)" by simp
huffman@23111
   757
  with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
huffman@23111
   758
huffman@23111
   759
  let ?g = "\<lambda>(i,j). a i * b j"
huffman@23111
   760
  let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
huffman@23111
   761
  have f_nonneg: "\<And>x. 0 \<le> ?f x"
huffman@23111
   762
    by (auto simp add: mult_nonneg_nonneg)
huffman@23111
   763
  hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
huffman@23111
   764
    unfolding real_norm_def
huffman@23111
   765
    by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
huffman@23111
   766
huffman@23111
   767
  have "(\<lambda>n. (\<Sum>k=0..<n. a k) * (\<Sum>k=0..<n. b k))
huffman@23111
   768
           ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@44568
   769
    by (intro tendsto_mult summable_sumr_LIMSEQ_suminf
huffman@23111
   770
        summable_norm_cancel [OF a] summable_norm_cancel [OF b])
huffman@23111
   771
  hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   772
    by (simp only: setsum_product setsum_Sigma [rule_format]
huffman@23111
   773
                   finite_atLeastLessThan)
huffman@23111
   774
huffman@23111
   775
  have "(\<lambda>n. (\<Sum>k=0..<n. norm (a k)) * (\<Sum>k=0..<n. norm (b k)))
huffman@23111
   776
       ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
huffman@44568
   777
    using a b by (intro tendsto_mult summable_sumr_LIMSEQ_suminf)
huffman@23111
   778
  hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
huffman@23111
   779
    by (simp only: setsum_product setsum_Sigma [rule_format]
huffman@23111
   780
                   finite_atLeastLessThan)
huffman@23111
   781
  hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   782
    by (rule convergentI)
huffman@23111
   783
  hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   784
    by (rule convergent_Cauchy)
huffman@36657
   785
  have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
huffman@36657
   786
  proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
huffman@23111
   787
    fix r :: real
huffman@23111
   788
    assume r: "0 < r"
huffman@23111
   789
    from CauchyD [OF Cauchy r] obtain N
huffman@23111
   790
    where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
huffman@23111
   791
    hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
huffman@23111
   792
      by (simp only: setsum_diff finite_S1 S1_mono)
huffman@23111
   793
    hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
huffman@23111
   794
      by (simp only: norm_setsum_f)
huffman@23111
   795
    show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
huffman@23111
   796
    proof (intro exI allI impI)
huffman@23111
   797
      fix n assume "2 * N \<le> n"
huffman@23111
   798
      hence n: "N \<le> n div 2" by simp
huffman@23111
   799
      have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
huffman@23111
   800
        by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
huffman@23111
   801
                  Diff_mono subset_refl S1_le_S2)
huffman@23111
   802
      also have "\<dots> < r"
huffman@23111
   803
        using n div_le_dividend by (rule N)
huffman@23111
   804
      finally show "setsum ?f (?S1 n - ?S2 n) < r" .
huffman@23111
   805
    qed
huffman@23111
   806
  qed
huffman@36657
   807
  hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
huffman@36657
   808
    apply (rule Zfun_le [rule_format])
huffman@23111
   809
    apply (simp only: norm_setsum_f)
huffman@23111
   810
    apply (rule order_trans [OF norm_setsum setsum_mono])
huffman@23111
   811
    apply (auto simp add: norm_mult_ineq)
huffman@23111
   812
    done
huffman@23111
   813
  hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
huffman@36660
   814
    unfolding tendsto_Zfun_iff diff_0_right
huffman@36657
   815
    by (simp only: setsum_diff finite_S1 S2_le_S1)
huffman@23111
   816
huffman@23111
   817
  with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   818
    by (rule LIMSEQ_diff_approach_zero2)
huffman@23111
   819
  thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
huffman@23111
   820
qed
huffman@23111
   821
huffman@23111
   822
lemma Cauchy_product:
huffman@23111
   823
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   824
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   825
  assumes b: "summable (\<lambda>k. norm (b k))"
huffman@23111
   826
  shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i=0..k. a i * b (k - i))"
huffman@23441
   827
using a b
huffman@23111
   828
by (rule Cauchy_product_sums [THEN sums_unique])
huffman@23111
   829
paulson@14416
   830
end