src/HOL/Series.thy
author paulson <lp15@cam.ac.uk>
Wed Mar 19 17:06:02 2014 +0000 (2014-03-19)
changeset 56217 dc429a5b13c4
parent 56213 e5720d3c18f0
child 56369 2704ca85be98
permissions -rw-r--r--
Some rationalisation of basic lemmas
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
hoelzl@56213
    10
header {* Infinite Series *}
paulson@10751
    11
nipkow@15131
    12
theory Series
hoelzl@51528
    13
imports Limits
nipkow@15131
    14
begin
nipkow@15561
    15
hoelzl@56213
    16
subsection {* Definition of infinite summability *}
hoelzl@56213
    17
hoelzl@56193
    18
definition
hoelzl@56193
    19
  sums :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a \<Rightarrow> bool"
hoelzl@56193
    20
  (infixr "sums" 80)
hoelzl@56193
    21
where
hoelzl@56193
    22
  "f sums s \<longleftrightarrow> (\<lambda>n. \<Sum>i<n. f i) ----> s"
paulson@14416
    23
hoelzl@56193
    24
definition summable :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> bool" where
hoelzl@56193
    25
   "summable f \<longleftrightarrow> (\<exists>s. f sums s)"
hoelzl@56193
    26
hoelzl@56193
    27
definition
hoelzl@56193
    28
  suminf :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a"
hoelzl@56193
    29
  (binder "\<Sum>" 10)
hoelzl@56193
    30
where
hoelzl@56193
    31
  "suminf f = (THE s. f sums s)"
hoelzl@56193
    32
hoelzl@56213
    33
subsection {* Infinite summability on topological monoids *}
hoelzl@56213
    34
hoelzl@56193
    35
lemma sums_subst[trans]: "f = g \<Longrightarrow> g sums z \<Longrightarrow> f sums z"
hoelzl@56193
    36
  by simp
hoelzl@56193
    37
hoelzl@56193
    38
lemma sums_summable: "f sums l \<Longrightarrow> summable f"
hoelzl@41970
    39
  by (simp add: sums_def summable_def, blast)
paulson@14416
    40
hoelzl@56193
    41
lemma summable_iff_convergent: "summable f \<longleftrightarrow> convergent (\<lambda>n. \<Sum>i<n. f i)"
hoelzl@56193
    42
  by (simp add: summable_def sums_def convergent_def)
paulson@14416
    43
hoelzl@56193
    44
lemma suminf_eq_lim: "suminf f = lim (\<lambda>n. \<Sum>i<n. f i)"
hoelzl@41970
    45
  by (simp add: suminf_def sums_def lim_def)
paulson@32707
    46
hoelzl@56213
    47
lemma sums_zero[simp, intro]: "(\<lambda>n. 0) sums 0"
hoelzl@56213
    48
  unfolding sums_def by (simp add: tendsto_const)
hoelzl@56213
    49
hoelzl@56213
    50
lemma summable_zero[simp, intro]: "summable (\<lambda>n. 0)"
hoelzl@56213
    51
  by (rule sums_zero [THEN sums_summable])
hoelzl@56213
    52
hoelzl@56213
    53
lemma sums_group: "f sums s \<Longrightarrow> 0 < k \<Longrightarrow> (\<lambda>n. setsum f {n * k ..< n * k + k}) sums s"
hoelzl@56213
    54
  apply (simp only: sums_def setsum_nat_group tendsto_def eventually_sequentially)
hoelzl@56213
    55
  apply safe
hoelzl@56213
    56
  apply (erule_tac x=S in allE)
hoelzl@56213
    57
  apply safe
hoelzl@56213
    58
  apply (rule_tac x="N" in exI, safe)
hoelzl@56213
    59
  apply (drule_tac x="n*k" in spec)
hoelzl@56213
    60
  apply (erule mp)
hoelzl@56213
    61
  apply (erule order_trans)
hoelzl@56213
    62
  apply simp
hoelzl@56213
    63
  done
hoelzl@56213
    64
hoelzl@47761
    65
lemma sums_finite:
hoelzl@56193
    66
  assumes [simp]: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@47761
    67
  shows "f sums (\<Sum>n\<in>N. f n)"
hoelzl@47761
    68
proof -
hoelzl@47761
    69
  { fix n
hoelzl@47761
    70
    have "setsum f {..<n + Suc (Max N)} = setsum f N"
hoelzl@47761
    71
    proof cases
hoelzl@47761
    72
      assume "N = {}"
hoelzl@47761
    73
      with f have "f = (\<lambda>x. 0)" by auto
hoelzl@47761
    74
      then show ?thesis by simp
hoelzl@47761
    75
    next
hoelzl@47761
    76
      assume [simp]: "N \<noteq> {}"
hoelzl@47761
    77
      show ?thesis
hoelzl@47761
    78
      proof (safe intro!: setsum_mono_zero_right f)
hoelzl@47761
    79
        fix i assume "i \<in> N"
hoelzl@47761
    80
        then have "i \<le> Max N" by simp
hoelzl@47761
    81
        then show "i < n + Suc (Max N)" by simp
hoelzl@47761
    82
      qed
hoelzl@47761
    83
    qed }
hoelzl@47761
    84
  note eq = this
hoelzl@47761
    85
  show ?thesis unfolding sums_def
hoelzl@47761
    86
    by (rule LIMSEQ_offset[of _ "Suc (Max N)"])
hoelzl@47761
    87
       (simp add: eq atLeast0LessThan tendsto_const del: add_Suc_right)
hoelzl@47761
    88
qed
hoelzl@47761
    89
hoelzl@56213
    90
lemma summable_finite: "finite N \<Longrightarrow> (\<And>n. n \<notin> N \<Longrightarrow> f n = 0) \<Longrightarrow> summable f"
hoelzl@56213
    91
  by (rule sums_summable) (rule sums_finite)
hoelzl@56213
    92
hoelzl@56193
    93
lemma sums_If_finite_set: "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 0) sums (\<Sum>r\<in>A. f r)"
hoelzl@47761
    94
  using sums_finite[of A "(\<lambda>r. if r \<in> A then f r else 0)"] by simp
hoelzl@47761
    95
hoelzl@56213
    96
lemma summable_If_finite_set[simp, intro]: "finite A \<Longrightarrow> summable (\<lambda>r. if r \<in> A then f r else 0)"
hoelzl@56213
    97
  by (rule sums_summable) (rule sums_If_finite_set)
hoelzl@56213
    98
hoelzl@56193
    99
lemma sums_If_finite: "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 0) sums (\<Sum>r | P r. f r)"
hoelzl@56193
   100
  using sums_If_finite_set[of "{r. P r}"] by simp
avigad@16819
   101
hoelzl@56213
   102
lemma summable_If_finite[simp, intro]: "finite {r. P r} \<Longrightarrow> summable (\<lambda>r. if P r then f r else 0)"
hoelzl@56213
   103
  by (rule sums_summable) (rule sums_If_finite)
hoelzl@56213
   104
hoelzl@56193
   105
lemma sums_single: "(\<lambda>r. if r = i then f r else 0) sums f i"
hoelzl@56193
   106
  using sums_If_finite[of "\<lambda>r. r = i"] by simp
hoelzl@29803
   107
hoelzl@56213
   108
lemma summable_single[simp, intro]: "summable (\<lambda>r. if r = i then f r else 0)"
hoelzl@56213
   109
  by (rule sums_summable) (rule sums_single)
hoelzl@56193
   110
hoelzl@56193
   111
context
hoelzl@56193
   112
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
hoelzl@56193
   113
begin
hoelzl@56193
   114
hoelzl@56193
   115
lemma summable_sums[intro]: "summable f \<Longrightarrow> f sums (suminf f)"
hoelzl@56193
   116
  by (simp add: summable_def sums_def suminf_def)
hoelzl@56193
   117
     (metis convergent_LIMSEQ_iff convergent_def lim_def)
hoelzl@56193
   118
hoelzl@56193
   119
lemma summable_LIMSEQ: "summable f \<Longrightarrow> (\<lambda>n. \<Sum>i<n. f i) ----> suminf f"
hoelzl@56193
   120
  by (rule summable_sums [unfolded sums_def])
hoelzl@56193
   121
hoelzl@56193
   122
lemma sums_unique: "f sums s \<Longrightarrow> s = suminf f"
hoelzl@56193
   123
  by (metis limI suminf_eq_lim sums_def)
hoelzl@56193
   124
hoelzl@56193
   125
lemma sums_iff: "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
hoelzl@56193
   126
  by (metis summable_sums sums_summable sums_unique)
hoelzl@56193
   127
hoelzl@56193
   128
lemma suminf_finite:
hoelzl@56193
   129
  assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@56193
   130
  shows "suminf f = (\<Sum>n\<in>N. f n)"
hoelzl@56193
   131
  using sums_finite[OF assms, THEN sums_unique] by simp
hoelzl@56193
   132
hoelzl@56193
   133
end
avigad@16819
   134
hoelzl@41970
   135
lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
hoelzl@56193
   136
  by (rule sums_zero [THEN sums_unique, symmetric])
avigad@16819
   137
hoelzl@56213
   138
hoelzl@56213
   139
subsection {* Infinite summability on ordered, topological monoids *}
hoelzl@56213
   140
hoelzl@56213
   141
lemma sums_le:
hoelzl@56213
   142
  fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@56213
   143
  shows "\<forall>n. f n \<le> g n \<Longrightarrow> f sums s \<Longrightarrow> g sums t \<Longrightarrow> s \<le> t"
hoelzl@56213
   144
  by (rule LIMSEQ_le) (auto intro: setsum_mono simp: sums_def)
hoelzl@56213
   145
hoelzl@56193
   146
context
hoelzl@56193
   147
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@56193
   148
begin
paulson@14416
   149
hoelzl@56213
   150
lemma suminf_le: "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
hoelzl@56213
   151
  by (auto dest: sums_summable intro: sums_le)
hoelzl@56213
   152
hoelzl@56213
   153
lemma setsum_le_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> setsum f {..<n} \<le> suminf f"
hoelzl@56213
   154
  by (rule sums_le[OF _ sums_If_finite_set summable_sums]) auto
hoelzl@56213
   155
hoelzl@56213
   156
lemma suminf_nonneg: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 \<le> suminf f"
hoelzl@56213
   157
  using setsum_le_suminf[of 0] by simp
hoelzl@56213
   158
hoelzl@56213
   159
lemma setsum_less_suminf2: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> n \<le> i \<Longrightarrow> 0 < f i \<Longrightarrow> setsum f {..<n} < suminf f"
hoelzl@56213
   160
  using
hoelzl@56213
   161
    setsum_le_suminf[of "Suc i"]
hoelzl@56213
   162
    add_strict_increasing[of "f i" "setsum f {..<n}" "setsum f {..<i}"]
hoelzl@56213
   163
    setsum_mono2[of "{..<i}" "{..<n}" f]
hoelzl@56213
   164
  by (auto simp: less_imp_le ac_simps)
hoelzl@56213
   165
hoelzl@56213
   166
lemma setsum_less_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 < f m \<Longrightarrow> setsum f {..<n} < suminf f"
hoelzl@56213
   167
  using setsum_less_suminf2[of n n] by (simp add: less_imp_le)
hoelzl@56213
   168
hoelzl@56213
   169
lemma suminf_pos2: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < f i \<Longrightarrow> 0 < suminf f"
hoelzl@56213
   170
  using setsum_less_suminf2[of 0 i] by simp
hoelzl@56213
   171
hoelzl@56213
   172
lemma suminf_pos: "summable f \<Longrightarrow> \<forall>n. 0 < f n \<Longrightarrow> 0 < suminf f"
hoelzl@56213
   173
  using suminf_pos2[of 0] by (simp add: less_imp_le)
hoelzl@56213
   174
hoelzl@56213
   175
lemma suminf_le_const: "summable f \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
hoelzl@56213
   176
  by (metis LIMSEQ_le_const2 summable_LIMSEQ)
paulson@14416
   177
hoelzl@56193
   178
lemma suminf_eq_zero_iff: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> suminf f = 0 \<longleftrightarrow> (\<forall>n. f n = 0)"
hoelzl@50999
   179
proof
hoelzl@50999
   180
  assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
hoelzl@50999
   181
  then have f: "(\<lambda>n. \<Sum>i<n. f i) ----> 0"
hoelzl@56213
   182
    using summable_LIMSEQ[of f] by simp
hoelzl@56213
   183
  then have "\<And>i. (\<Sum>n\<in>{i}. f n) \<le> 0"
hoelzl@56213
   184
  proof (rule LIMSEQ_le_const)
hoelzl@50999
   185
    fix i show "\<exists>N. \<forall>n\<ge>N. (\<Sum>n\<in>{i}. f n) \<le> setsum f {..<n}"
hoelzl@50999
   186
      using pos by (intro exI[of _ "Suc i"] allI impI setsum_mono2) auto
hoelzl@50999
   187
  qed
hoelzl@50999
   188
  with pos show "\<forall>n. f n = 0"
hoelzl@50999
   189
    by (auto intro!: antisym)
hoelzl@56193
   190
qed (metis suminf_zero fun_eq_iff)
hoelzl@56193
   191
hoelzl@56213
   192
lemma suminf_pos_iff: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
hoelzl@56213
   193
  using setsum_le_suminf[of 0] suminf_eq_zero_iff by (simp add: less_le)
hoelzl@56193
   194
hoelzl@56193
   195
end
hoelzl@56193
   196
hoelzl@56213
   197
lemma summableI_nonneg_bounded:
hoelzl@56213
   198
  fixes f:: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology, conditionally_complete_linorder}"
hoelzl@56213
   199
  assumes pos[simp]: "\<And>n. 0 \<le> f n" and le: "\<And>n. (\<Sum>i<n. f i) \<le> x"
hoelzl@56213
   200
  shows "summable f"
hoelzl@56213
   201
  unfolding summable_def sums_def[abs_def]
hoelzl@56213
   202
proof (intro exI order_tendstoI)
hoelzl@56213
   203
  have [simp, intro]: "bdd_above (range (\<lambda>n. \<Sum>i<n. f i))"
hoelzl@56213
   204
    using le by (auto simp: bdd_above_def)
hoelzl@56213
   205
  { fix a assume "a < (SUP n. \<Sum>i<n. f i)"
hoelzl@56213
   206
    then obtain n where "a < (\<Sum>i<n. f i)"
hoelzl@56213
   207
      by (auto simp add: less_cSUP_iff)
hoelzl@56213
   208
    then have "\<And>m. n \<le> m \<Longrightarrow> a < (\<Sum>i<m. f i)"
hoelzl@56213
   209
      by (rule less_le_trans) (auto intro!: setsum_mono2)
hoelzl@56213
   210
    then show "eventually (\<lambda>n. a < (\<Sum>i<n. f i)) sequentially"
hoelzl@56213
   211
      by (auto simp: eventually_sequentially) }
hoelzl@56213
   212
  { fix a assume "(SUP n. \<Sum>i<n. f i) < a"
hoelzl@56213
   213
    moreover have "\<And>n. (\<Sum>i<n. f i) \<le> (SUP n. \<Sum>i<n. f i)"
hoelzl@56213
   214
      by (auto intro: cSUP_upper)
hoelzl@56213
   215
    ultimately show "eventually (\<lambda>n. (\<Sum>i<n. f i) < a) sequentially"
hoelzl@56213
   216
      by (auto intro: le_less_trans simp: eventually_sequentially) }
hoelzl@56213
   217
qed
hoelzl@56213
   218
hoelzl@56213
   219
subsection {* Infinite summability on real normed vector spaces *}
hoelzl@56193
   220
hoelzl@56193
   221
lemma sums_Suc_iff:
hoelzl@56193
   222
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56193
   223
  shows "(\<lambda>n. f (Suc n)) sums s \<longleftrightarrow> f sums (s + f 0)"
hoelzl@56193
   224
proof -
hoelzl@56193
   225
  have "f sums (s + f 0) \<longleftrightarrow> (\<lambda>i. \<Sum>j<Suc i. f j) ----> s + f 0"
hoelzl@56193
   226
    by (subst LIMSEQ_Suc_iff) (simp add: sums_def)
hoelzl@56193
   227
  also have "\<dots> \<longleftrightarrow> (\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
hoelzl@56193
   228
    by (simp add: ac_simps setsum_reindex image_iff lessThan_Suc_eq_insert_0)
hoelzl@56193
   229
  also have "\<dots> \<longleftrightarrow> (\<lambda>n. f (Suc n)) sums s"
hoelzl@56193
   230
  proof
hoelzl@56193
   231
    assume "(\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
hoelzl@56193
   232
    with tendsto_add[OF this tendsto_const, of "- f 0"]
hoelzl@56193
   233
    show "(\<lambda>i. f (Suc i)) sums s"
hoelzl@56193
   234
      by (simp add: sums_def)
hoelzl@56193
   235
  qed (auto intro: tendsto_add tendsto_const simp: sums_def)
hoelzl@56193
   236
  finally show ?thesis ..
hoelzl@50999
   237
qed
hoelzl@50999
   238
hoelzl@56193
   239
context
hoelzl@56193
   240
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56193
   241
begin
hoelzl@56193
   242
hoelzl@56193
   243
lemma sums_add: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n + g n) sums (a + b)"
hoelzl@56193
   244
  unfolding sums_def by (simp add: setsum_addf tendsto_add)
hoelzl@56193
   245
hoelzl@56193
   246
lemma summable_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n + g n)"
hoelzl@56193
   247
  unfolding summable_def by (auto intro: sums_add)
hoelzl@56193
   248
hoelzl@56193
   249
lemma suminf_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f + suminf g = (\<Sum>n. f n + g n)"
hoelzl@56193
   250
  by (intro sums_unique sums_add summable_sums)
hoelzl@56193
   251
hoelzl@56193
   252
lemma sums_diff: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n - g n) sums (a - b)"
hoelzl@56193
   253
  unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
hoelzl@56193
   254
hoelzl@56193
   255
lemma summable_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n - g n)"
hoelzl@56193
   256
  unfolding summable_def by (auto intro: sums_diff)
hoelzl@56193
   257
hoelzl@56193
   258
lemma suminf_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f - suminf g = (\<Sum>n. f n - g n)"
hoelzl@56193
   259
  by (intro sums_unique sums_diff summable_sums)
hoelzl@56193
   260
hoelzl@56193
   261
lemma sums_minus: "f sums a \<Longrightarrow> (\<lambda>n. - f n) sums (- a)"
hoelzl@56193
   262
  unfolding sums_def by (simp add: setsum_negf tendsto_minus)
hoelzl@56193
   263
hoelzl@56193
   264
lemma summable_minus: "summable f \<Longrightarrow> summable (\<lambda>n. - f n)"
hoelzl@56193
   265
  unfolding summable_def by (auto intro: sums_minus)
huffman@20692
   266
hoelzl@56193
   267
lemma suminf_minus: "summable f \<Longrightarrow> (\<Sum>n. - f n) = - (\<Sum>n. f n)"
hoelzl@56193
   268
  by (intro sums_unique [symmetric] sums_minus summable_sums)
hoelzl@56193
   269
hoelzl@56193
   270
lemma sums_Suc: "(\<lambda> n. f (Suc n)) sums l \<Longrightarrow> f sums (l + f 0)"
hoelzl@56193
   271
  by (simp add: sums_Suc_iff)
hoelzl@56193
   272
hoelzl@56193
   273
lemma sums_iff_shift: "(\<lambda>i. f (i + n)) sums s \<longleftrightarrow> f sums (s + (\<Sum>i<n. f i))"
hoelzl@56193
   274
proof (induct n arbitrary: s)
hoelzl@56193
   275
  case (Suc n)
hoelzl@56193
   276
  moreover have "(\<lambda>i. f (Suc i + n)) sums s \<longleftrightarrow> (\<lambda>i. f (i + n)) sums (s + f n)"
hoelzl@56193
   277
    by (subst sums_Suc_iff) simp
hoelzl@56193
   278
  ultimately show ?case
hoelzl@56193
   279
    by (simp add: ac_simps)
hoelzl@56193
   280
qed simp
huffman@20692
   281
hoelzl@56193
   282
lemma summable_iff_shift: "summable (\<lambda>n. f (n + k)) \<longleftrightarrow> summable f"
hoelzl@56193
   283
  by (metis diff_add_cancel summable_def sums_iff_shift[abs_def])
hoelzl@56193
   284
hoelzl@56193
   285
lemma sums_split_initial_segment: "f sums s \<Longrightarrow> (\<lambda>i. f (i + n)) sums (s - (\<Sum>i<n. f i))"
hoelzl@56193
   286
  by (simp add: sums_iff_shift)
hoelzl@56193
   287
hoelzl@56193
   288
lemma summable_ignore_initial_segment: "summable f \<Longrightarrow> summable (\<lambda>n. f(n + k))"
hoelzl@56193
   289
  by (simp add: summable_iff_shift)
hoelzl@56193
   290
hoelzl@56193
   291
lemma suminf_minus_initial_segment: "summable f \<Longrightarrow> (\<Sum>n. f (n + k)) = (\<Sum>n. f n) - (\<Sum>i<k. f i)"
hoelzl@56193
   292
  by (rule sums_unique[symmetric]) (auto simp: sums_iff_shift)
hoelzl@56193
   293
hoelzl@56193
   294
lemma suminf_split_initial_segment: "summable f \<Longrightarrow> suminf f = (\<Sum>n. f(n + k)) + (\<Sum>i<k. f i)"
hoelzl@56193
   295
  by (auto simp add: suminf_minus_initial_segment)
huffman@20692
   296
hoelzl@56193
   297
lemma suminf_exist_split: 
hoelzl@56193
   298
  fixes r :: real assumes "0 < r" and "summable f"
hoelzl@56193
   299
  shows "\<exists>N. \<forall>n\<ge>N. norm (\<Sum>i. f (i + n)) < r"
hoelzl@56193
   300
proof -
hoelzl@56193
   301
  from LIMSEQ_D[OF summable_LIMSEQ[OF `summable f`] `0 < r`]
hoelzl@56193
   302
  obtain N :: nat where "\<forall> n \<ge> N. norm (setsum f {..<n} - suminf f) < r" by auto
hoelzl@56193
   303
  thus ?thesis
hoelzl@56193
   304
    by (auto simp: norm_minus_commute suminf_minus_initial_segment[OF `summable f`])
hoelzl@56193
   305
qed
hoelzl@56193
   306
hoelzl@56193
   307
lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
hoelzl@56193
   308
  apply (drule summable_iff_convergent [THEN iffD1])
hoelzl@56193
   309
  apply (drule convergent_Cauchy)
hoelzl@56193
   310
  apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
hoelzl@56193
   311
  apply (drule_tac x="r" in spec, safe)
hoelzl@56193
   312
  apply (rule_tac x="M" in exI, safe)
hoelzl@56193
   313
  apply (drule_tac x="Suc n" in spec, simp)
hoelzl@56193
   314
  apply (drule_tac x="n" in spec, simp)
hoelzl@56193
   315
  done
hoelzl@56193
   316
hoelzl@56193
   317
end
hoelzl@56193
   318
hoelzl@56193
   319
lemma (in bounded_linear) sums: "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
hoelzl@56193
   320
  unfolding sums_def by (drule tendsto, simp only: setsum)
hoelzl@56193
   321
hoelzl@56193
   322
lemma (in bounded_linear) summable: "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
hoelzl@56193
   323
  unfolding summable_def by (auto intro: sums)
hoelzl@56193
   324
hoelzl@56193
   325
lemma (in bounded_linear) suminf: "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
hoelzl@56193
   326
  by (intro sums_unique sums summable_sums)
hoelzl@56193
   327
hoelzl@56193
   328
lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
hoelzl@56193
   329
lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
hoelzl@56193
   330
lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
hoelzl@56193
   331
hoelzl@56213
   332
subsection {* Infinite summability on real normed algebras *}
hoelzl@56213
   333
hoelzl@56193
   334
context
hoelzl@56193
   335
  fixes f :: "nat \<Rightarrow> 'a::real_normed_algebra"
hoelzl@56193
   336
begin
hoelzl@56193
   337
hoelzl@56193
   338
lemma sums_mult: "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
hoelzl@56193
   339
  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
hoelzl@56193
   340
hoelzl@56193
   341
lemma summable_mult: "summable f \<Longrightarrow> summable (\<lambda>n. c * f n)"
hoelzl@56193
   342
  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
hoelzl@56193
   343
hoelzl@56193
   344
lemma suminf_mult: "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
hoelzl@56193
   345
  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
hoelzl@56193
   346
hoelzl@56193
   347
lemma sums_mult2: "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
hoelzl@56193
   348
  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
hoelzl@56193
   349
hoelzl@56193
   350
lemma summable_mult2: "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
hoelzl@56193
   351
  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
hoelzl@56193
   352
hoelzl@56193
   353
lemma suminf_mult2: "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
hoelzl@56193
   354
  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
hoelzl@56193
   355
hoelzl@56193
   356
end
hoelzl@56193
   357
hoelzl@56213
   358
subsection {* Infinite summability on real normed fields *}
hoelzl@56213
   359
hoelzl@56193
   360
context
hoelzl@56193
   361
  fixes c :: "'a::real_normed_field"
hoelzl@56193
   362
begin
hoelzl@56193
   363
hoelzl@56193
   364
lemma sums_divide: "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
hoelzl@56193
   365
  by (rule bounded_linear.sums [OF bounded_linear_divide])
hoelzl@56193
   366
hoelzl@56193
   367
lemma summable_divide: "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
hoelzl@56193
   368
  by (rule bounded_linear.summable [OF bounded_linear_divide])
hoelzl@56193
   369
hoelzl@56193
   370
lemma suminf_divide: "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
hoelzl@56193
   371
  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
paulson@14416
   372
paulson@15085
   373
text{*Sum of a geometric progression.*}
paulson@14416
   374
hoelzl@56193
   375
lemma geometric_sums: "norm c < 1 \<Longrightarrow> (\<lambda>n. c^n) sums (1 / (1 - c))"
huffman@20692
   376
proof -
hoelzl@56193
   377
  assume less_1: "norm c < 1"
hoelzl@56193
   378
  hence neq_1: "c \<noteq> 1" by auto
hoelzl@56193
   379
  hence neq_0: "c - 1 \<noteq> 0" by simp
hoelzl@56193
   380
  from less_1 have lim_0: "(\<lambda>n. c^n) ----> 0"
huffman@20692
   381
    by (rule LIMSEQ_power_zero)
hoelzl@56193
   382
  hence "(\<lambda>n. c ^ n / (c - 1) - 1 / (c - 1)) ----> 0 / (c - 1) - 1 / (c - 1)"
huffman@44568
   383
    using neq_0 by (intro tendsto_intros)
hoelzl@56193
   384
  hence "(\<lambda>n. (c ^ n - 1) / (c - 1)) ----> 1 / (1 - c)"
huffman@20692
   385
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
hoelzl@56193
   386
  thus "(\<lambda>n. c ^ n) sums (1 / (1 - c))"
huffman@20692
   387
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   388
qed
huffman@20692
   389
hoelzl@56193
   390
lemma summable_geometric: "norm c < 1 \<Longrightarrow> summable (\<lambda>n. c^n)"
hoelzl@56193
   391
  by (rule geometric_sums [THEN sums_summable])
paulson@14416
   392
hoelzl@56193
   393
lemma suminf_geometric: "norm c < 1 \<Longrightarrow> suminf (\<lambda>n. c^n) = 1 / (1 - c)"
hoelzl@56193
   394
  by (rule sums_unique[symmetric]) (rule geometric_sums)
hoelzl@56193
   395
hoelzl@56193
   396
end
paulson@33271
   397
paulson@33271
   398
lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
paulson@33271
   399
proof -
paulson@33271
   400
  have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
paulson@33271
   401
    by auto
paulson@33271
   402
  have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
paulson@33271
   403
    by simp
huffman@44282
   404
  thus ?thesis using sums_divide [OF 2, of 2]
paulson@33271
   405
    by simp
paulson@33271
   406
qed
paulson@33271
   407
hoelzl@56213
   408
subsection {* Infinite summability on Banach spaces *}
hoelzl@56213
   409
paulson@15085
   410
text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
paulson@15085
   411
hoelzl@56193
   412
lemma summable_Cauchy:
hoelzl@56193
   413
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   414
  shows "summable f \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. norm (setsum f {m..<n}) < e)"
hoelzl@56193
   415
  apply (simp only: summable_iff_convergent Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
hoelzl@56193
   416
  apply (drule spec, drule (1) mp)
hoelzl@56193
   417
  apply (erule exE, rule_tac x="M" in exI, clarify)
hoelzl@56193
   418
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   419
  apply (frule (1) order_trans)
hoelzl@56193
   420
  apply (drule_tac x="n" in spec, drule (1) mp)
hoelzl@56193
   421
  apply (drule_tac x="m" in spec, drule (1) mp)
hoelzl@56193
   422
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   423
  apply (drule spec, drule (1) mp)
hoelzl@56193
   424
  apply (erule exE, rule_tac x="N" in exI, clarify)
hoelzl@56193
   425
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   426
  apply (subst norm_minus_commute)
hoelzl@56193
   427
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   428
  done
paulson@14416
   429
hoelzl@56193
   430
context
hoelzl@56193
   431
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   432
begin  
hoelzl@56193
   433
hoelzl@56193
   434
text{*Absolute convergence imples normal convergence*}
huffman@20689
   435
hoelzl@56194
   436
lemma summable_norm_cancel: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
hoelzl@56193
   437
  apply (simp only: summable_Cauchy, safe)
hoelzl@56193
   438
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   439
  apply (rule_tac x="N" in exI, safe)
hoelzl@56193
   440
  apply (drule_tac x="m" in spec, safe)
hoelzl@56193
   441
  apply (rule order_le_less_trans [OF norm_setsum])
hoelzl@56193
   442
  apply (rule order_le_less_trans [OF abs_ge_self])
hoelzl@56193
   443
  apply simp
hoelzl@50999
   444
  done
paulson@32707
   445
hoelzl@56193
   446
lemma summable_norm: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
hoelzl@56193
   447
  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel summable_LIMSEQ norm_setsum)
hoelzl@56193
   448
hoelzl@56193
   449
text {* Comparison tests *}
paulson@14416
   450
hoelzl@56194
   451
lemma summable_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable f"
hoelzl@56193
   452
  apply (simp add: summable_Cauchy, safe)
hoelzl@56193
   453
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   454
  apply (rule_tac x = "N + Na" in exI, safe)
hoelzl@56193
   455
  apply (rotate_tac 2)
hoelzl@56193
   456
  apply (drule_tac x = m in spec)
hoelzl@56193
   457
  apply (auto, rotate_tac 2, drule_tac x = n in spec)
hoelzl@56193
   458
  apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
hoelzl@56193
   459
  apply (rule norm_setsum)
hoelzl@56193
   460
  apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
hoelzl@56193
   461
  apply (auto intro: setsum_mono simp add: abs_less_iff)
hoelzl@56193
   462
  done
hoelzl@56193
   463
lp15@56217
   464
(*A better argument order*)
lp15@56217
   465
lemma summable_comparison_test': "summable g \<Longrightarrow> (\<And>n. n \<ge> N \<Longrightarrow> norm(f n) \<le> g n) \<Longrightarrow> summable f"
lp15@56217
   466
by (rule summable_comparison_test) auto
lp15@56217
   467
hoelzl@56193
   468
subsection {* The Ratio Test*}
paulson@15085
   469
hoelzl@56193
   470
lemma summable_ratio_test: 
hoelzl@56193
   471
  assumes "c < 1" "\<And>n. n \<ge> N \<Longrightarrow> norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   472
  shows "summable f"
hoelzl@56193
   473
proof cases
hoelzl@56193
   474
  assume "0 < c"
hoelzl@56193
   475
  show "summable f"
hoelzl@56193
   476
  proof (rule summable_comparison_test)
hoelzl@56193
   477
    show "\<exists>N'. \<forall>n\<ge>N'. norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   478
    proof (intro exI allI impI)
hoelzl@56193
   479
      fix n assume "N \<le> n" then show "norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   480
      proof (induct rule: inc_induct)
hoelzl@56193
   481
        case (step m)
hoelzl@56193
   482
        moreover have "norm (f (Suc m)) / c ^ Suc m * c ^ n \<le> norm (f m) / c ^ m * c ^ n"
hoelzl@56193
   483
          using `0 < c` `c < 1` assms(2)[OF `N \<le> m`] by (simp add: field_simps)
hoelzl@56193
   484
        ultimately show ?case by simp
hoelzl@56193
   485
      qed (insert `0 < c`, simp)
hoelzl@56193
   486
    qed
hoelzl@56193
   487
    show "summable (\<lambda>n. norm (f N) / c ^ N * c ^ n)"
hoelzl@56193
   488
      using `0 < c` `c < 1` by (intro summable_mult summable_geometric) simp
hoelzl@56193
   489
  qed
hoelzl@56193
   490
next
hoelzl@56193
   491
  assume c: "\<not> 0 < c"
hoelzl@56193
   492
  { fix n assume "n \<ge> N"
hoelzl@56193
   493
    then have "norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   494
      by fact
hoelzl@56193
   495
    also have "\<dots> \<le> 0"
hoelzl@56193
   496
      using c by (simp add: not_less mult_nonpos_nonneg)
hoelzl@56193
   497
    finally have "f (Suc n) = 0"
hoelzl@56193
   498
      by auto }
hoelzl@56193
   499
  then show "summable f"
hoelzl@56194
   500
    by (intro sums_summable[OF sums_finite, of "{.. Suc N}"]) (auto simp: not_le Suc_less_eq2)
lp15@56178
   501
qed
lp15@56178
   502
hoelzl@56193
   503
end
paulson@14416
   504
huffman@23084
   505
text{*Summability of geometric series for real algebras*}
huffman@23084
   506
huffman@23084
   507
lemma complete_algebra_summable_geometric:
haftmann@31017
   508
  fixes x :: "'a::{real_normed_algebra_1,banach}"
huffman@23084
   509
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@23084
   510
proof (rule summable_comparison_test)
huffman@23084
   511
  show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
huffman@23084
   512
    by (simp add: norm_power_ineq)
huffman@23084
   513
  show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
huffman@23084
   514
    by (simp add: summable_geometric)
huffman@23084
   515
qed
huffman@23084
   516
huffman@23111
   517
subsection {* Cauchy Product Formula *}
huffman@23111
   518
wenzelm@54703
   519
text {*
wenzelm@54703
   520
  Proof based on Analysis WebNotes: Chapter 07, Class 41
wenzelm@54703
   521
  @{url "http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm"}
wenzelm@54703
   522
*}
huffman@23111
   523
huffman@23111
   524
lemma setsum_triangle_reindex:
huffman@23111
   525
  fixes n :: nat
hoelzl@56213
   526
  shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k<n. \<Sum>i\<le>k. f i (k - i))"
huffman@23111
   527
proof -
huffman@23111
   528
  have "(\<Sum>(i, j)\<in>{(i, j). i + j < n}. f i j) =
hoelzl@56213
   529
    (\<Sum>(k, i)\<in>(SIGMA k:{..<n}. {..k}). f i (k - i))"
huffman@23111
   530
  proof (rule setsum_reindex_cong)
hoelzl@56213
   531
    show "inj_on (\<lambda>(k,i). (i, k - i)) (SIGMA k:{..<n}. {..k})"
huffman@23111
   532
      by (rule inj_on_inverseI [where g="\<lambda>(i,j). (i+j, i)"], auto)
hoelzl@56213
   533
    show "{(i,j). i + j < n} = (\<lambda>(k,i). (i, k - i)) ` (SIGMA k:{..<n}. {..k})"
huffman@23111
   534
      by (safe, rule_tac x="(a+b,a)" in image_eqI, auto)
huffman@23111
   535
    show "\<And>a. (\<lambda>(k, i). f i (k - i)) a = split f ((\<lambda>(k, i). (i, k - i)) a)"
huffman@23111
   536
      by clarify
huffman@23111
   537
  qed
huffman@23111
   538
  thus ?thesis by (simp add: setsum_Sigma)
huffman@23111
   539
qed
huffman@23111
   540
huffman@23111
   541
lemma Cauchy_product_sums:
huffman@23111
   542
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   543
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   544
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   545
  shows "(\<lambda>k. \<Sum>i\<le>k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
huffman@23111
   546
proof -
hoelzl@56193
   547
  let ?S1 = "\<lambda>n::nat. {..<n} \<times> {..<n}"
huffman@23111
   548
  let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
huffman@23111
   549
  have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
huffman@23111
   550
  have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
huffman@23111
   551
  have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
huffman@23111
   552
  have finite_S1: "\<And>n. finite (?S1 n)" by simp
huffman@23111
   553
  with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
huffman@23111
   554
huffman@23111
   555
  let ?g = "\<lambda>(i,j). a i * b j"
huffman@23111
   556
  let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
huffman@23111
   557
  have f_nonneg: "\<And>x. 0 \<le> ?f x"
huffman@23111
   558
    by (auto simp add: mult_nonneg_nonneg)
huffman@23111
   559
  hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
huffman@23111
   560
    unfolding real_norm_def
huffman@23111
   561
    by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
huffman@23111
   562
hoelzl@56193
   563
  have "(\<lambda>n. (\<Sum>k<n. a k) * (\<Sum>k<n. b k)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
hoelzl@56193
   564
    by (intro tendsto_mult summable_LIMSEQ summable_norm_cancel [OF a] summable_norm_cancel [OF b])
huffman@23111
   565
  hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
hoelzl@56193
   566
    by (simp only: setsum_product setsum_Sigma [rule_format] finite_lessThan)
huffman@23111
   567
hoelzl@56193
   568
  have "(\<lambda>n. (\<Sum>k<n. norm (a k)) * (\<Sum>k<n. norm (b k))) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
hoelzl@56193
   569
    using a b by (intro tendsto_mult summable_LIMSEQ)
huffman@23111
   570
  hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
hoelzl@56193
   571
    by (simp only: setsum_product setsum_Sigma [rule_format] finite_lessThan)
huffman@23111
   572
  hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   573
    by (rule convergentI)
huffman@23111
   574
  hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   575
    by (rule convergent_Cauchy)
huffman@36657
   576
  have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
huffman@36657
   577
  proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
huffman@23111
   578
    fix r :: real
huffman@23111
   579
    assume r: "0 < r"
huffman@23111
   580
    from CauchyD [OF Cauchy r] obtain N
huffman@23111
   581
    where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
huffman@23111
   582
    hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
huffman@23111
   583
      by (simp only: setsum_diff finite_S1 S1_mono)
huffman@23111
   584
    hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
huffman@23111
   585
      by (simp only: norm_setsum_f)
huffman@23111
   586
    show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
huffman@23111
   587
    proof (intro exI allI impI)
huffman@23111
   588
      fix n assume "2 * N \<le> n"
huffman@23111
   589
      hence n: "N \<le> n div 2" by simp
huffman@23111
   590
      have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
huffman@23111
   591
        by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
huffman@23111
   592
                  Diff_mono subset_refl S1_le_S2)
huffman@23111
   593
      also have "\<dots> < r"
huffman@23111
   594
        using n div_le_dividend by (rule N)
huffman@23111
   595
      finally show "setsum ?f (?S1 n - ?S2 n) < r" .
huffman@23111
   596
    qed
huffman@23111
   597
  qed
huffman@36657
   598
  hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
huffman@36657
   599
    apply (rule Zfun_le [rule_format])
huffman@23111
   600
    apply (simp only: norm_setsum_f)
huffman@23111
   601
    apply (rule order_trans [OF norm_setsum setsum_mono])
huffman@23111
   602
    apply (auto simp add: norm_mult_ineq)
huffman@23111
   603
    done
huffman@23111
   604
  hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
huffman@36660
   605
    unfolding tendsto_Zfun_iff diff_0_right
huffman@36657
   606
    by (simp only: setsum_diff finite_S1 S2_le_S1)
huffman@23111
   607
huffman@23111
   608
  with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   609
    by (rule LIMSEQ_diff_approach_zero2)
huffman@23111
   610
  thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
huffman@23111
   611
qed
huffman@23111
   612
huffman@23111
   613
lemma Cauchy_product:
huffman@23111
   614
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   615
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   616
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   617
  shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i\<le>k. a i * b (k - i))"
hoelzl@56213
   618
  using a b
hoelzl@56213
   619
  by (rule Cauchy_product_sums [THEN sums_unique])
hoelzl@56213
   620
hoelzl@56213
   621
subsection {* Series on @{typ real}s *}
hoelzl@56213
   622
hoelzl@56213
   623
lemma summable_norm_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. norm (f n))"
hoelzl@56213
   624
  by (rule summable_comparison_test) auto
hoelzl@56213
   625
hoelzl@56213
   626
lemma summable_rabs_comparison_test: "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. \<bar>f n :: real\<bar>)"
hoelzl@56213
   627
  by (rule summable_comparison_test) auto
hoelzl@56213
   628
hoelzl@56213
   629
lemma summable_rabs_cancel: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> summable f"
hoelzl@56213
   630
  by (rule summable_norm_cancel) simp
hoelzl@56213
   631
hoelzl@56213
   632
lemma summable_rabs: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
hoelzl@56213
   633
  by (fold real_norm_def) (rule summable_norm)
huffman@23111
   634
paulson@14416
   635
end