src/HOL/Series.thy
author haftmann
Sun Sep 21 16:56:11 2014 +0200 (2014-09-21)
changeset 58410 6d46ad54a2ab
parent 57418 6ab1c7cb0b8d
child 58729 e8ecc79aee43
permissions -rw-r--r--
explicit separation of signed and unsigned numerals using existing lexical categories num and xnum
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
haftmann@57418
    78
      proof (safe intro!: setsum.mono_neutral_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"
haftmann@57418
   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)"
haftmann@57418
   244
  unfolding sums_def by (simp add: setsum.distrib 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@57025
   319
context
hoelzl@57025
   320
  fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::real_normed_vector" and I :: "'i set"
hoelzl@57025
   321
begin
hoelzl@57025
   322
hoelzl@57025
   323
lemma sums_setsum: "(\<And>i. i \<in> I \<Longrightarrow> (f i) sums (x i)) \<Longrightarrow> (\<lambda>n. \<Sum>i\<in>I. f i n) sums (\<Sum>i\<in>I. x i)"
hoelzl@57025
   324
  by (induct I rule: infinite_finite_induct) (auto intro!: sums_add)
hoelzl@57025
   325
hoelzl@57025
   326
lemma suminf_setsum: "(\<And>i. i \<in> I \<Longrightarrow> summable (f i)) \<Longrightarrow> (\<Sum>n. \<Sum>i\<in>I. f i n) = (\<Sum>i\<in>I. \<Sum>n. f i n)"
hoelzl@57025
   327
  using sums_unique[OF sums_setsum, OF summable_sums] by simp
hoelzl@57025
   328
hoelzl@57025
   329
lemma summable_setsum: "(\<And>i. i \<in> I \<Longrightarrow> summable (f i)) \<Longrightarrow> summable (\<lambda>n. \<Sum>i\<in>I. f i n)"
hoelzl@57025
   330
  using sums_summable[OF sums_setsum[OF summable_sums]] .
hoelzl@57025
   331
hoelzl@57025
   332
end
hoelzl@57025
   333
hoelzl@56193
   334
lemma (in bounded_linear) sums: "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
hoelzl@56193
   335
  unfolding sums_def by (drule tendsto, simp only: setsum)
hoelzl@56193
   336
hoelzl@56193
   337
lemma (in bounded_linear) summable: "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
hoelzl@56193
   338
  unfolding summable_def by (auto intro: sums)
hoelzl@56193
   339
hoelzl@56193
   340
lemma (in bounded_linear) suminf: "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
hoelzl@56193
   341
  by (intro sums_unique sums summable_sums)
hoelzl@56193
   342
hoelzl@56193
   343
lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
hoelzl@56193
   344
lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
hoelzl@56193
   345
lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
hoelzl@56193
   346
hoelzl@57275
   347
lemmas sums_scaleR_left = bounded_linear.sums[OF bounded_linear_scaleR_left]
hoelzl@57275
   348
lemmas summable_scaleR_left = bounded_linear.summable[OF bounded_linear_scaleR_left]
hoelzl@57275
   349
lemmas suminf_scaleR_left = bounded_linear.suminf[OF bounded_linear_scaleR_left]
hoelzl@57275
   350
hoelzl@57275
   351
lemmas sums_scaleR_right = bounded_linear.sums[OF bounded_linear_scaleR_right]
hoelzl@57275
   352
lemmas summable_scaleR_right = bounded_linear.summable[OF bounded_linear_scaleR_right]
hoelzl@57275
   353
lemmas suminf_scaleR_right = bounded_linear.suminf[OF bounded_linear_scaleR_right]
hoelzl@57275
   354
hoelzl@56213
   355
subsection {* Infinite summability on real normed algebras *}
hoelzl@56213
   356
hoelzl@56193
   357
context
hoelzl@56193
   358
  fixes f :: "nat \<Rightarrow> 'a::real_normed_algebra"
hoelzl@56193
   359
begin
hoelzl@56193
   360
hoelzl@56193
   361
lemma sums_mult: "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
hoelzl@56193
   362
  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
hoelzl@56193
   363
hoelzl@56193
   364
lemma summable_mult: "summable f \<Longrightarrow> summable (\<lambda>n. c * f n)"
hoelzl@56193
   365
  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
hoelzl@56193
   366
hoelzl@56193
   367
lemma suminf_mult: "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
hoelzl@56193
   368
  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
hoelzl@56193
   369
hoelzl@56193
   370
lemma sums_mult2: "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
hoelzl@56193
   371
  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
hoelzl@56193
   372
hoelzl@56193
   373
lemma summable_mult2: "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
hoelzl@56193
   374
  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
hoelzl@56193
   375
hoelzl@56193
   376
lemma suminf_mult2: "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
hoelzl@56193
   377
  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
hoelzl@56193
   378
hoelzl@56193
   379
end
hoelzl@56193
   380
hoelzl@56213
   381
subsection {* Infinite summability on real normed fields *}
hoelzl@56213
   382
hoelzl@56193
   383
context
hoelzl@56193
   384
  fixes c :: "'a::real_normed_field"
hoelzl@56193
   385
begin
hoelzl@56193
   386
hoelzl@56193
   387
lemma sums_divide: "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
hoelzl@56193
   388
  by (rule bounded_linear.sums [OF bounded_linear_divide])
hoelzl@56193
   389
hoelzl@56193
   390
lemma summable_divide: "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
hoelzl@56193
   391
  by (rule bounded_linear.summable [OF bounded_linear_divide])
hoelzl@56193
   392
hoelzl@56193
   393
lemma suminf_divide: "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
hoelzl@56193
   394
  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
paulson@14416
   395
paulson@15085
   396
text{*Sum of a geometric progression.*}
paulson@14416
   397
hoelzl@56193
   398
lemma geometric_sums: "norm c < 1 \<Longrightarrow> (\<lambda>n. c^n) sums (1 / (1 - c))"
huffman@20692
   399
proof -
hoelzl@56193
   400
  assume less_1: "norm c < 1"
hoelzl@56193
   401
  hence neq_1: "c \<noteq> 1" by auto
hoelzl@56193
   402
  hence neq_0: "c - 1 \<noteq> 0" by simp
hoelzl@56193
   403
  from less_1 have lim_0: "(\<lambda>n. c^n) ----> 0"
huffman@20692
   404
    by (rule LIMSEQ_power_zero)
hoelzl@56193
   405
  hence "(\<lambda>n. c ^ n / (c - 1) - 1 / (c - 1)) ----> 0 / (c - 1) - 1 / (c - 1)"
huffman@44568
   406
    using neq_0 by (intro tendsto_intros)
hoelzl@56193
   407
  hence "(\<lambda>n. (c ^ n - 1) / (c - 1)) ----> 1 / (1 - c)"
huffman@20692
   408
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
hoelzl@56193
   409
  thus "(\<lambda>n. c ^ n) sums (1 / (1 - c))"
huffman@20692
   410
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   411
qed
huffman@20692
   412
hoelzl@56193
   413
lemma summable_geometric: "norm c < 1 \<Longrightarrow> summable (\<lambda>n. c^n)"
hoelzl@56193
   414
  by (rule geometric_sums [THEN sums_summable])
paulson@14416
   415
hoelzl@56193
   416
lemma suminf_geometric: "norm c < 1 \<Longrightarrow> suminf (\<lambda>n. c^n) = 1 / (1 - c)"
hoelzl@56193
   417
  by (rule sums_unique[symmetric]) (rule geometric_sums)
hoelzl@56193
   418
hoelzl@56193
   419
end
paulson@33271
   420
paulson@33271
   421
lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
paulson@33271
   422
proof -
paulson@33271
   423
  have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
paulson@33271
   424
    by auto
paulson@33271
   425
  have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
paulson@33271
   426
    by simp
huffman@44282
   427
  thus ?thesis using sums_divide [OF 2, of 2]
paulson@33271
   428
    by simp
paulson@33271
   429
qed
paulson@33271
   430
hoelzl@56213
   431
subsection {* Infinite summability on Banach spaces *}
hoelzl@56213
   432
paulson@15085
   433
text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
paulson@15085
   434
hoelzl@56193
   435
lemma summable_Cauchy:
hoelzl@56193
   436
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   437
  shows "summable f \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. norm (setsum f {m..<n}) < e)"
hoelzl@56193
   438
  apply (simp only: summable_iff_convergent Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
hoelzl@56193
   439
  apply (drule spec, drule (1) mp)
hoelzl@56193
   440
  apply (erule exE, rule_tac x="M" in exI, clarify)
hoelzl@56193
   441
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   442
  apply (frule (1) order_trans)
hoelzl@56193
   443
  apply (drule_tac x="n" in spec, drule (1) mp)
hoelzl@56193
   444
  apply (drule_tac x="m" in spec, drule (1) mp)
hoelzl@56193
   445
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   446
  apply (drule spec, drule (1) mp)
hoelzl@56193
   447
  apply (erule exE, rule_tac x="N" in exI, clarify)
hoelzl@56193
   448
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   449
  apply (subst norm_minus_commute)
hoelzl@56193
   450
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   451
  done
paulson@14416
   452
hoelzl@56193
   453
context
hoelzl@56193
   454
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   455
begin  
hoelzl@56193
   456
hoelzl@56193
   457
text{*Absolute convergence imples normal convergence*}
huffman@20689
   458
hoelzl@56194
   459
lemma summable_norm_cancel: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
hoelzl@56193
   460
  apply (simp only: summable_Cauchy, safe)
hoelzl@56193
   461
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   462
  apply (rule_tac x="N" in exI, safe)
hoelzl@56193
   463
  apply (drule_tac x="m" in spec, safe)
hoelzl@56193
   464
  apply (rule order_le_less_trans [OF norm_setsum])
hoelzl@56193
   465
  apply (rule order_le_less_trans [OF abs_ge_self])
hoelzl@56193
   466
  apply simp
hoelzl@50999
   467
  done
paulson@32707
   468
hoelzl@56193
   469
lemma summable_norm: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
hoelzl@56193
   470
  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel summable_LIMSEQ norm_setsum)
hoelzl@56193
   471
hoelzl@56193
   472
text {* Comparison tests *}
paulson@14416
   473
hoelzl@56194
   474
lemma summable_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable f"
hoelzl@56193
   475
  apply (simp add: summable_Cauchy, safe)
hoelzl@56193
   476
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   477
  apply (rule_tac x = "N + Na" in exI, safe)
hoelzl@56193
   478
  apply (rotate_tac 2)
hoelzl@56193
   479
  apply (drule_tac x = m in spec)
hoelzl@56193
   480
  apply (auto, rotate_tac 2, drule_tac x = n in spec)
hoelzl@56193
   481
  apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
hoelzl@56193
   482
  apply (rule norm_setsum)
hoelzl@56193
   483
  apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
hoelzl@56193
   484
  apply (auto intro: setsum_mono simp add: abs_less_iff)
hoelzl@56193
   485
  done
hoelzl@56193
   486
lp15@56217
   487
(*A better argument order*)
lp15@56217
   488
lemma summable_comparison_test': "summable g \<Longrightarrow> (\<And>n. n \<ge> N \<Longrightarrow> norm(f n) \<le> g n) \<Longrightarrow> summable f"
hoelzl@56369
   489
  by (rule summable_comparison_test) auto
lp15@56217
   490
hoelzl@56193
   491
subsection {* The Ratio Test*}
paulson@15085
   492
hoelzl@56193
   493
lemma summable_ratio_test: 
hoelzl@56193
   494
  assumes "c < 1" "\<And>n. n \<ge> N \<Longrightarrow> norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   495
  shows "summable f"
hoelzl@56193
   496
proof cases
hoelzl@56193
   497
  assume "0 < c"
hoelzl@56193
   498
  show "summable f"
hoelzl@56193
   499
  proof (rule summable_comparison_test)
hoelzl@56193
   500
    show "\<exists>N'. \<forall>n\<ge>N'. norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   501
    proof (intro exI allI impI)
hoelzl@56193
   502
      fix n assume "N \<le> n" then show "norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   503
      proof (induct rule: inc_induct)
hoelzl@56193
   504
        case (step m)
hoelzl@56193
   505
        moreover have "norm (f (Suc m)) / c ^ Suc m * c ^ n \<le> norm (f m) / c ^ m * c ^ n"
hoelzl@56193
   506
          using `0 < c` `c < 1` assms(2)[OF `N \<le> m`] by (simp add: field_simps)
hoelzl@56193
   507
        ultimately show ?case by simp
hoelzl@56193
   508
      qed (insert `0 < c`, simp)
hoelzl@56193
   509
    qed
hoelzl@56193
   510
    show "summable (\<lambda>n. norm (f N) / c ^ N * c ^ n)"
hoelzl@56193
   511
      using `0 < c` `c < 1` by (intro summable_mult summable_geometric) simp
hoelzl@56193
   512
  qed
hoelzl@56193
   513
next
hoelzl@56193
   514
  assume c: "\<not> 0 < c"
hoelzl@56193
   515
  { fix n assume "n \<ge> N"
hoelzl@56193
   516
    then have "norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   517
      by fact
hoelzl@56193
   518
    also have "\<dots> \<le> 0"
hoelzl@56193
   519
      using c by (simp add: not_less mult_nonpos_nonneg)
hoelzl@56193
   520
    finally have "f (Suc n) = 0"
hoelzl@56193
   521
      by auto }
hoelzl@56193
   522
  then show "summable f"
hoelzl@56194
   523
    by (intro sums_summable[OF sums_finite, of "{.. Suc N}"]) (auto simp: not_le Suc_less_eq2)
lp15@56178
   524
qed
lp15@56178
   525
hoelzl@56193
   526
end
paulson@14416
   527
hoelzl@56369
   528
text{*Relations among convergence and absolute convergence for power series.*}
hoelzl@56369
   529
hoelzl@56369
   530
lemma abel_lemma:
hoelzl@56369
   531
  fixes a :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56369
   532
  assumes r: "0 \<le> r" and r0: "r < r0" and M: "\<And>n. norm (a n) * r0^n \<le> M"
hoelzl@56369
   533
    shows "summable (\<lambda>n. norm (a n) * r^n)"
hoelzl@56369
   534
proof (rule summable_comparison_test')
hoelzl@56369
   535
  show "summable (\<lambda>n. M * (r / r0) ^ n)"
hoelzl@56369
   536
    using assms 
hoelzl@56369
   537
    by (auto simp add: summable_mult summable_geometric)
hoelzl@56369
   538
next
hoelzl@56369
   539
  fix n
hoelzl@56369
   540
  show "norm (norm (a n) * r ^ n) \<le> M * (r / r0) ^ n"
hoelzl@56369
   541
    using r r0 M [of n]
hoelzl@56369
   542
    apply (auto simp add: abs_mult field_simps power_divide)
hoelzl@56369
   543
    apply (cases "r=0", simp)
hoelzl@56369
   544
    apply (cases n, auto)
hoelzl@56369
   545
    done
hoelzl@56369
   546
qed
hoelzl@56369
   547
hoelzl@56369
   548
huffman@23084
   549
text{*Summability of geometric series for real algebras*}
huffman@23084
   550
huffman@23084
   551
lemma complete_algebra_summable_geometric:
haftmann@31017
   552
  fixes x :: "'a::{real_normed_algebra_1,banach}"
huffman@23084
   553
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@23084
   554
proof (rule summable_comparison_test)
huffman@23084
   555
  show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
huffman@23084
   556
    by (simp add: norm_power_ineq)
huffman@23084
   557
  show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
huffman@23084
   558
    by (simp add: summable_geometric)
huffman@23084
   559
qed
huffman@23084
   560
huffman@23111
   561
subsection {* Cauchy Product Formula *}
huffman@23111
   562
wenzelm@54703
   563
text {*
wenzelm@54703
   564
  Proof based on Analysis WebNotes: Chapter 07, Class 41
wenzelm@54703
   565
  @{url "http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm"}
wenzelm@54703
   566
*}
huffman@23111
   567
huffman@23111
   568
lemma setsum_triangle_reindex:
huffman@23111
   569
  fixes n :: nat
hoelzl@56213
   570
  shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k<n. \<Sum>i\<le>k. f i (k - i))"
haftmann@57418
   571
  apply (simp add: setsum.Sigma)
hoelzl@57129
   572
  apply (rule setsum.reindex_bij_witness[where j="\<lambda>(i, j). (i+j, i)" and i="\<lambda>(k, i). (i, k - i)"])
hoelzl@57129
   573
  apply auto
hoelzl@57129
   574
  done
huffman@23111
   575
huffman@23111
   576
lemma Cauchy_product_sums:
huffman@23111
   577
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   578
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   579
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   580
  shows "(\<lambda>k. \<Sum>i\<le>k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
huffman@23111
   581
proof -
hoelzl@56193
   582
  let ?S1 = "\<lambda>n::nat. {..<n} \<times> {..<n}"
huffman@23111
   583
  let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
huffman@23111
   584
  have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
huffman@23111
   585
  have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
huffman@23111
   586
  have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
huffman@23111
   587
  have finite_S1: "\<And>n. finite (?S1 n)" by simp
huffman@23111
   588
  with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
huffman@23111
   589
huffman@23111
   590
  let ?g = "\<lambda>(i,j). a i * b j"
huffman@23111
   591
  let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
nipkow@56536
   592
  have f_nonneg: "\<And>x. 0 \<le> ?f x" by (auto)
huffman@23111
   593
  hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
huffman@23111
   594
    unfolding real_norm_def
huffman@23111
   595
    by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
huffman@23111
   596
hoelzl@56193
   597
  have "(\<lambda>n. (\<Sum>k<n. a k) * (\<Sum>k<n. b k)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
hoelzl@56193
   598
    by (intro tendsto_mult summable_LIMSEQ summable_norm_cancel [OF a] summable_norm_cancel [OF b])
huffman@23111
   599
  hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
haftmann@57418
   600
    by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
huffman@23111
   601
hoelzl@56193
   602
  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
   603
    using a b by (intro tendsto_mult summable_LIMSEQ)
huffman@23111
   604
  hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
haftmann@57418
   605
    by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
huffman@23111
   606
  hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   607
    by (rule convergentI)
huffman@23111
   608
  hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   609
    by (rule convergent_Cauchy)
huffman@36657
   610
  have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
huffman@36657
   611
  proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
huffman@23111
   612
    fix r :: real
huffman@23111
   613
    assume r: "0 < r"
huffman@23111
   614
    from CauchyD [OF Cauchy r] obtain N
huffman@23111
   615
    where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
huffman@23111
   616
    hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
huffman@23111
   617
      by (simp only: setsum_diff finite_S1 S1_mono)
huffman@23111
   618
    hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
huffman@23111
   619
      by (simp only: norm_setsum_f)
huffman@23111
   620
    show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
huffman@23111
   621
    proof (intro exI allI impI)
huffman@23111
   622
      fix n assume "2 * N \<le> n"
huffman@23111
   623
      hence n: "N \<le> n div 2" by simp
huffman@23111
   624
      have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
huffman@23111
   625
        by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
huffman@23111
   626
                  Diff_mono subset_refl S1_le_S2)
huffman@23111
   627
      also have "\<dots> < r"
huffman@23111
   628
        using n div_le_dividend by (rule N)
huffman@23111
   629
      finally show "setsum ?f (?S1 n - ?S2 n) < r" .
huffman@23111
   630
    qed
huffman@23111
   631
  qed
huffman@36657
   632
  hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
huffman@36657
   633
    apply (rule Zfun_le [rule_format])
huffman@23111
   634
    apply (simp only: norm_setsum_f)
huffman@23111
   635
    apply (rule order_trans [OF norm_setsum setsum_mono])
huffman@23111
   636
    apply (auto simp add: norm_mult_ineq)
huffman@23111
   637
    done
huffman@23111
   638
  hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
huffman@36660
   639
    unfolding tendsto_Zfun_iff diff_0_right
huffman@36657
   640
    by (simp only: setsum_diff finite_S1 S2_le_S1)
huffman@23111
   641
huffman@23111
   642
  with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
huffman@23111
   643
    by (rule LIMSEQ_diff_approach_zero2)
huffman@23111
   644
  thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
huffman@23111
   645
qed
huffman@23111
   646
huffman@23111
   647
lemma Cauchy_product:
huffman@23111
   648
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   649
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   650
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   651
  shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i\<le>k. a i * b (k - i))"
hoelzl@56213
   652
  using a b
hoelzl@56213
   653
  by (rule Cauchy_product_sums [THEN sums_unique])
hoelzl@56213
   654
hoelzl@56213
   655
subsection {* Series on @{typ real}s *}
hoelzl@56213
   656
hoelzl@56213
   657
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
   658
  by (rule summable_comparison_test) auto
hoelzl@56213
   659
hoelzl@56213
   660
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
   661
  by (rule summable_comparison_test) auto
hoelzl@56213
   662
hoelzl@56213
   663
lemma summable_rabs_cancel: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> summable f"
hoelzl@56213
   664
  by (rule summable_norm_cancel) simp
hoelzl@56213
   665
hoelzl@56213
   666
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
   667
  by (fold real_norm_def) (rule summable_norm)
huffman@23111
   668
paulson@14416
   669
end