src/HOL/Series.thy
author wenzelm
Mon Aug 31 21:28:08 2015 +0200 (2015-08-31)
changeset 61070 b72a990adfe2
parent 60867 86e7560e07d0
child 61531 ab2e862263e7
permissions -rw-r--r--
prefer symbols;
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
wenzelm@60758
    10
section \<open>Infinite Series\<close>
paulson@10751
    11
nipkow@15131
    12
theory Series
hoelzl@59712
    13
imports Limits Inequalities
hoelzl@59712
    14
begin 
nipkow@15561
    15
wenzelm@60758
    16
subsection \<open>Definition of infinite summability\<close>
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
wenzelm@60758
    33
subsection \<open>Infinite summability on topological monoids\<close>
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@58729
    48
  unfolding sums_def by simp
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@58729
    87
       (simp add: eq atLeast0LessThan 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
lp15@59613
   128
lemma sums_unique2:
lp15@59613
   129
  fixes a b :: "'a::{comm_monoid_add,t2_space}"
lp15@59613
   130
  shows "f sums a \<Longrightarrow> f sums b \<Longrightarrow> a = b"
lp15@59613
   131
by (simp add: sums_iff)
lp15@59613
   132
hoelzl@56193
   133
lemma suminf_finite:
hoelzl@56193
   134
  assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@56193
   135
  shows "suminf f = (\<Sum>n\<in>N. f n)"
hoelzl@56193
   136
  using sums_finite[OF assms, THEN sums_unique] by simp
hoelzl@56193
   137
hoelzl@56193
   138
end
avigad@16819
   139
hoelzl@41970
   140
lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
hoelzl@56193
   141
  by (rule sums_zero [THEN sums_unique, symmetric])
avigad@16819
   142
hoelzl@56213
   143
wenzelm@60758
   144
subsection \<open>Infinite summability on ordered, topological monoids\<close>
hoelzl@56213
   145
hoelzl@56213
   146
lemma sums_le:
hoelzl@56213
   147
  fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@56213
   148
  shows "\<forall>n. f n \<le> g n \<Longrightarrow> f sums s \<Longrightarrow> g sums t \<Longrightarrow> s \<le> t"
hoelzl@56213
   149
  by (rule LIMSEQ_le) (auto intro: setsum_mono simp: sums_def)
hoelzl@56213
   150
hoelzl@56193
   151
context
hoelzl@56193
   152
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@56193
   153
begin
paulson@14416
   154
hoelzl@56213
   155
lemma suminf_le: "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
hoelzl@56213
   156
  by (auto dest: sums_summable intro: sums_le)
hoelzl@56213
   157
hoelzl@56213
   158
lemma setsum_le_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> setsum f {..<n} \<le> suminf f"
hoelzl@56213
   159
  by (rule sums_le[OF _ sums_If_finite_set summable_sums]) auto
hoelzl@56213
   160
hoelzl@56213
   161
lemma suminf_nonneg: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 \<le> suminf f"
hoelzl@56213
   162
  using setsum_le_suminf[of 0] by simp
hoelzl@56213
   163
hoelzl@56213
   164
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
   165
  using
hoelzl@56213
   166
    setsum_le_suminf[of "Suc i"]
hoelzl@56213
   167
    add_strict_increasing[of "f i" "setsum f {..<n}" "setsum f {..<i}"]
hoelzl@56213
   168
    setsum_mono2[of "{..<i}" "{..<n}" f]
hoelzl@56213
   169
  by (auto simp: less_imp_le ac_simps)
hoelzl@56213
   170
hoelzl@56213
   171
lemma setsum_less_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 < f m \<Longrightarrow> setsum f {..<n} < suminf f"
hoelzl@56213
   172
  using setsum_less_suminf2[of n n] by (simp add: less_imp_le)
hoelzl@56213
   173
hoelzl@56213
   174
lemma suminf_pos2: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < f i \<Longrightarrow> 0 < suminf f"
hoelzl@56213
   175
  using setsum_less_suminf2[of 0 i] by simp
hoelzl@56213
   176
hoelzl@56213
   177
lemma suminf_pos: "summable f \<Longrightarrow> \<forall>n. 0 < f n \<Longrightarrow> 0 < suminf f"
hoelzl@56213
   178
  using suminf_pos2[of 0] by (simp add: less_imp_le)
hoelzl@56213
   179
hoelzl@56213
   180
lemma suminf_le_const: "summable f \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
hoelzl@56213
   181
  by (metis LIMSEQ_le_const2 summable_LIMSEQ)
paulson@14416
   182
hoelzl@56193
   183
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
   184
proof
hoelzl@50999
   185
  assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
hoelzl@50999
   186
  then have f: "(\<lambda>n. \<Sum>i<n. f i) ----> 0"
hoelzl@56213
   187
    using summable_LIMSEQ[of f] by simp
hoelzl@56213
   188
  then have "\<And>i. (\<Sum>n\<in>{i}. f n) \<le> 0"
hoelzl@56213
   189
  proof (rule LIMSEQ_le_const)
hoelzl@50999
   190
    fix i show "\<exists>N. \<forall>n\<ge>N. (\<Sum>n\<in>{i}. f n) \<le> setsum f {..<n}"
hoelzl@50999
   191
      using pos by (intro exI[of _ "Suc i"] allI impI setsum_mono2) auto
hoelzl@50999
   192
  qed
hoelzl@50999
   193
  with pos show "\<forall>n. f n = 0"
hoelzl@50999
   194
    by (auto intro!: antisym)
hoelzl@56193
   195
qed (metis suminf_zero fun_eq_iff)
hoelzl@56193
   196
hoelzl@56213
   197
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
   198
  using setsum_le_suminf[of 0] suminf_eq_zero_iff by (simp add: less_le)
hoelzl@56193
   199
hoelzl@56193
   200
end
hoelzl@56193
   201
hoelzl@56213
   202
lemma summableI_nonneg_bounded:
hoelzl@56213
   203
  fixes f:: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology, conditionally_complete_linorder}"
hoelzl@56213
   204
  assumes pos[simp]: "\<And>n. 0 \<le> f n" and le: "\<And>n. (\<Sum>i<n. f i) \<le> x"
hoelzl@56213
   205
  shows "summable f"
hoelzl@56213
   206
  unfolding summable_def sums_def[abs_def]
hoelzl@56213
   207
proof (intro exI order_tendstoI)
hoelzl@56213
   208
  have [simp, intro]: "bdd_above (range (\<lambda>n. \<Sum>i<n. f i))"
hoelzl@56213
   209
    using le by (auto simp: bdd_above_def)
hoelzl@56213
   210
  { fix a assume "a < (SUP n. \<Sum>i<n. f i)"
hoelzl@56213
   211
    then obtain n where "a < (\<Sum>i<n. f i)"
hoelzl@56213
   212
      by (auto simp add: less_cSUP_iff)
hoelzl@56213
   213
    then have "\<And>m. n \<le> m \<Longrightarrow> a < (\<Sum>i<m. f i)"
hoelzl@56213
   214
      by (rule less_le_trans) (auto intro!: setsum_mono2)
hoelzl@56213
   215
    then show "eventually (\<lambda>n. a < (\<Sum>i<n. f i)) sequentially"
hoelzl@56213
   216
      by (auto simp: eventually_sequentially) }
hoelzl@56213
   217
  { fix a assume "(SUP n. \<Sum>i<n. f i) < a"
hoelzl@56213
   218
    moreover have "\<And>n. (\<Sum>i<n. f i) \<le> (SUP n. \<Sum>i<n. f i)"
hoelzl@56213
   219
      by (auto intro: cSUP_upper)
hoelzl@56213
   220
    ultimately show "eventually (\<lambda>n. (\<Sum>i<n. f i) < a) sequentially"
hoelzl@56213
   221
      by (auto intro: le_less_trans simp: eventually_sequentially) }
hoelzl@56213
   222
qed
hoelzl@56213
   223
wenzelm@60758
   224
subsection \<open>Infinite summability on real normed vector spaces\<close>
hoelzl@56193
   225
hoelzl@56193
   226
lemma sums_Suc_iff:
hoelzl@56193
   227
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56193
   228
  shows "(\<lambda>n. f (Suc n)) sums s \<longleftrightarrow> f sums (s + f 0)"
hoelzl@56193
   229
proof -
hoelzl@56193
   230
  have "f sums (s + f 0) \<longleftrightarrow> (\<lambda>i. \<Sum>j<Suc i. f j) ----> s + f 0"
hoelzl@56193
   231
    by (subst LIMSEQ_Suc_iff) (simp add: sums_def)
hoelzl@56193
   232
  also have "\<dots> \<longleftrightarrow> (\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
haftmann@57418
   233
    by (simp add: ac_simps setsum.reindex image_iff lessThan_Suc_eq_insert_0)
hoelzl@56193
   234
  also have "\<dots> \<longleftrightarrow> (\<lambda>n. f (Suc n)) sums s"
hoelzl@56193
   235
  proof
hoelzl@56193
   236
    assume "(\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
hoelzl@56193
   237
    with tendsto_add[OF this tendsto_const, of "- f 0"]
hoelzl@56193
   238
    show "(\<lambda>i. f (Suc i)) sums s"
hoelzl@56193
   239
      by (simp add: sums_def)
hoelzl@58729
   240
  qed (auto intro: tendsto_add simp: sums_def)
hoelzl@56193
   241
  finally show ?thesis ..
hoelzl@50999
   242
qed
hoelzl@50999
   243
hoelzl@56193
   244
context
hoelzl@56193
   245
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56193
   246
begin
hoelzl@56193
   247
hoelzl@56193
   248
lemma sums_add: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n + g n) sums (a + b)"
haftmann@57418
   249
  unfolding sums_def by (simp add: setsum.distrib tendsto_add)
hoelzl@56193
   250
hoelzl@56193
   251
lemma summable_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n + g n)"
hoelzl@56193
   252
  unfolding summable_def by (auto intro: sums_add)
hoelzl@56193
   253
hoelzl@56193
   254
lemma suminf_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f + suminf g = (\<Sum>n. f n + g n)"
hoelzl@56193
   255
  by (intro sums_unique sums_add summable_sums)
hoelzl@56193
   256
hoelzl@56193
   257
lemma sums_diff: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n - g n) sums (a - b)"
hoelzl@56193
   258
  unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
hoelzl@56193
   259
hoelzl@56193
   260
lemma summable_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n - g n)"
hoelzl@56193
   261
  unfolding summable_def by (auto intro: sums_diff)
hoelzl@56193
   262
hoelzl@56193
   263
lemma suminf_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f - suminf g = (\<Sum>n. f n - g n)"
hoelzl@56193
   264
  by (intro sums_unique sums_diff summable_sums)
hoelzl@56193
   265
hoelzl@56193
   266
lemma sums_minus: "f sums a \<Longrightarrow> (\<lambda>n. - f n) sums (- a)"
hoelzl@56193
   267
  unfolding sums_def by (simp add: setsum_negf tendsto_minus)
hoelzl@56193
   268
hoelzl@56193
   269
lemma summable_minus: "summable f \<Longrightarrow> summable (\<lambda>n. - f n)"
hoelzl@56193
   270
  unfolding summable_def by (auto intro: sums_minus)
huffman@20692
   271
hoelzl@56193
   272
lemma suminf_minus: "summable f \<Longrightarrow> (\<Sum>n. - f n) = - (\<Sum>n. f n)"
hoelzl@56193
   273
  by (intro sums_unique [symmetric] sums_minus summable_sums)
hoelzl@56193
   274
hoelzl@56193
   275
lemma sums_Suc: "(\<lambda> n. f (Suc n)) sums l \<Longrightarrow> f sums (l + f 0)"
hoelzl@56193
   276
  by (simp add: sums_Suc_iff)
hoelzl@56193
   277
hoelzl@56193
   278
lemma sums_iff_shift: "(\<lambda>i. f (i + n)) sums s \<longleftrightarrow> f sums (s + (\<Sum>i<n. f i))"
hoelzl@56193
   279
proof (induct n arbitrary: s)
hoelzl@56193
   280
  case (Suc n)
hoelzl@56193
   281
  moreover have "(\<lambda>i. f (Suc i + n)) sums s \<longleftrightarrow> (\<lambda>i. f (i + n)) sums (s + f n)"
hoelzl@56193
   282
    by (subst sums_Suc_iff) simp
hoelzl@56193
   283
  ultimately show ?case
hoelzl@56193
   284
    by (simp add: ac_simps)
hoelzl@56193
   285
qed simp
huffman@20692
   286
hoelzl@56193
   287
lemma summable_iff_shift: "summable (\<lambda>n. f (n + k)) \<longleftrightarrow> summable f"
hoelzl@56193
   288
  by (metis diff_add_cancel summable_def sums_iff_shift[abs_def])
hoelzl@56193
   289
hoelzl@56193
   290
lemma sums_split_initial_segment: "f sums s \<Longrightarrow> (\<lambda>i. f (i + n)) sums (s - (\<Sum>i<n. f i))"
hoelzl@56193
   291
  by (simp add: sums_iff_shift)
hoelzl@56193
   292
hoelzl@56193
   293
lemma summable_ignore_initial_segment: "summable f \<Longrightarrow> summable (\<lambda>n. f(n + k))"
hoelzl@56193
   294
  by (simp add: summable_iff_shift)
hoelzl@56193
   295
hoelzl@56193
   296
lemma suminf_minus_initial_segment: "summable f \<Longrightarrow> (\<Sum>n. f (n + k)) = (\<Sum>n. f n) - (\<Sum>i<k. f i)"
hoelzl@56193
   297
  by (rule sums_unique[symmetric]) (auto simp: sums_iff_shift)
hoelzl@56193
   298
hoelzl@56193
   299
lemma suminf_split_initial_segment: "summable f \<Longrightarrow> suminf f = (\<Sum>n. f(n + k)) + (\<Sum>i<k. f i)"
hoelzl@56193
   300
  by (auto simp add: suminf_minus_initial_segment)
huffman@20692
   301
hoelzl@56193
   302
lemma suminf_exist_split: 
hoelzl@56193
   303
  fixes r :: real assumes "0 < r" and "summable f"
hoelzl@56193
   304
  shows "\<exists>N. \<forall>n\<ge>N. norm (\<Sum>i. f (i + n)) < r"
hoelzl@56193
   305
proof -
wenzelm@60758
   306
  from LIMSEQ_D[OF summable_LIMSEQ[OF \<open>summable f\<close>] \<open>0 < r\<close>]
hoelzl@56193
   307
  obtain N :: nat where "\<forall> n \<ge> N. norm (setsum f {..<n} - suminf f) < r" by auto
hoelzl@56193
   308
  thus ?thesis
wenzelm@60758
   309
    by (auto simp: norm_minus_commute suminf_minus_initial_segment[OF \<open>summable f\<close>])
hoelzl@56193
   310
qed
hoelzl@56193
   311
hoelzl@56193
   312
lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
hoelzl@56193
   313
  apply (drule summable_iff_convergent [THEN iffD1])
hoelzl@56193
   314
  apply (drule convergent_Cauchy)
hoelzl@56193
   315
  apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
hoelzl@56193
   316
  apply (drule_tac x="r" in spec, safe)
hoelzl@56193
   317
  apply (rule_tac x="M" in exI, safe)
hoelzl@56193
   318
  apply (drule_tac x="Suc n" in spec, simp)
hoelzl@56193
   319
  apply (drule_tac x="n" in spec, simp)
hoelzl@56193
   320
  done
hoelzl@56193
   321
hoelzl@56193
   322
end
hoelzl@56193
   323
lp15@59613
   324
lemma summable_minus_iff:
lp15@59613
   325
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
lp15@59613
   326
  shows "summable (\<lambda>n. - f n) \<longleftrightarrow> summable f"
wenzelm@60758
   327
  by (auto dest: summable_minus) --\<open>used two ways, hence must be outside the context above\<close>
lp15@59613
   328
lp15@59613
   329
hoelzl@57025
   330
context
hoelzl@57025
   331
  fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::real_normed_vector" and I :: "'i set"
hoelzl@57025
   332
begin
hoelzl@57025
   333
hoelzl@57025
   334
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
   335
  by (induct I rule: infinite_finite_induct) (auto intro!: sums_add)
hoelzl@57025
   336
hoelzl@57025
   337
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
   338
  using sums_unique[OF sums_setsum, OF summable_sums] by simp
hoelzl@57025
   339
hoelzl@57025
   340
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
   341
  using sums_summable[OF sums_setsum[OF summable_sums]] .
hoelzl@57025
   342
hoelzl@57025
   343
end
hoelzl@57025
   344
hoelzl@56193
   345
lemma (in bounded_linear) sums: "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
hoelzl@56193
   346
  unfolding sums_def by (drule tendsto, simp only: setsum)
hoelzl@56193
   347
hoelzl@56193
   348
lemma (in bounded_linear) summable: "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
hoelzl@56193
   349
  unfolding summable_def by (auto intro: sums)
hoelzl@56193
   350
hoelzl@56193
   351
lemma (in bounded_linear) suminf: "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
hoelzl@56193
   352
  by (intro sums_unique sums summable_sums)
hoelzl@56193
   353
hoelzl@56193
   354
lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
hoelzl@56193
   355
lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
hoelzl@56193
   356
lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
hoelzl@56193
   357
hoelzl@57275
   358
lemmas sums_scaleR_left = bounded_linear.sums[OF bounded_linear_scaleR_left]
hoelzl@57275
   359
lemmas summable_scaleR_left = bounded_linear.summable[OF bounded_linear_scaleR_left]
hoelzl@57275
   360
lemmas suminf_scaleR_left = bounded_linear.suminf[OF bounded_linear_scaleR_left]
hoelzl@57275
   361
hoelzl@57275
   362
lemmas sums_scaleR_right = bounded_linear.sums[OF bounded_linear_scaleR_right]
hoelzl@57275
   363
lemmas summable_scaleR_right = bounded_linear.summable[OF bounded_linear_scaleR_right]
hoelzl@57275
   364
lemmas suminf_scaleR_right = bounded_linear.suminf[OF bounded_linear_scaleR_right]
hoelzl@57275
   365
wenzelm@60758
   366
subsection \<open>Infinite summability on real normed algebras\<close>
hoelzl@56213
   367
hoelzl@56193
   368
context
hoelzl@56193
   369
  fixes f :: "nat \<Rightarrow> 'a::real_normed_algebra"
hoelzl@56193
   370
begin
hoelzl@56193
   371
hoelzl@56193
   372
lemma sums_mult: "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
hoelzl@56193
   373
  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
hoelzl@56193
   374
hoelzl@56193
   375
lemma summable_mult: "summable f \<Longrightarrow> summable (\<lambda>n. c * f n)"
hoelzl@56193
   376
  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
hoelzl@56193
   377
hoelzl@56193
   378
lemma suminf_mult: "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
hoelzl@56193
   379
  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
hoelzl@56193
   380
hoelzl@56193
   381
lemma sums_mult2: "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
hoelzl@56193
   382
  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
hoelzl@56193
   383
hoelzl@56193
   384
lemma summable_mult2: "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
hoelzl@56193
   385
  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
hoelzl@56193
   386
hoelzl@56193
   387
lemma suminf_mult2: "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
hoelzl@56193
   388
  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
hoelzl@56193
   389
hoelzl@56193
   390
end
hoelzl@56193
   391
wenzelm@60758
   392
subsection \<open>Infinite summability on real normed fields\<close>
hoelzl@56213
   393
hoelzl@56193
   394
context
hoelzl@56193
   395
  fixes c :: "'a::real_normed_field"
hoelzl@56193
   396
begin
hoelzl@56193
   397
hoelzl@56193
   398
lemma sums_divide: "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
hoelzl@56193
   399
  by (rule bounded_linear.sums [OF bounded_linear_divide])
hoelzl@56193
   400
hoelzl@56193
   401
lemma summable_divide: "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
hoelzl@56193
   402
  by (rule bounded_linear.summable [OF bounded_linear_divide])
hoelzl@56193
   403
hoelzl@56193
   404
lemma suminf_divide: "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
hoelzl@56193
   405
  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
paulson@14416
   406
wenzelm@60758
   407
text\<open>Sum of a geometric progression.\<close>
paulson@14416
   408
hoelzl@56193
   409
lemma geometric_sums: "norm c < 1 \<Longrightarrow> (\<lambda>n. c^n) sums (1 / (1 - c))"
huffman@20692
   410
proof -
hoelzl@56193
   411
  assume less_1: "norm c < 1"
hoelzl@56193
   412
  hence neq_1: "c \<noteq> 1" by auto
hoelzl@56193
   413
  hence neq_0: "c - 1 \<noteq> 0" by simp
hoelzl@56193
   414
  from less_1 have lim_0: "(\<lambda>n. c^n) ----> 0"
huffman@20692
   415
    by (rule LIMSEQ_power_zero)
hoelzl@56193
   416
  hence "(\<lambda>n. c ^ n / (c - 1) - 1 / (c - 1)) ----> 0 / (c - 1) - 1 / (c - 1)"
huffman@44568
   417
    using neq_0 by (intro tendsto_intros)
hoelzl@56193
   418
  hence "(\<lambda>n. (c ^ n - 1) / (c - 1)) ----> 1 / (1 - c)"
huffman@20692
   419
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
hoelzl@56193
   420
  thus "(\<lambda>n. c ^ n) sums (1 / (1 - c))"
huffman@20692
   421
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   422
qed
huffman@20692
   423
hoelzl@56193
   424
lemma summable_geometric: "norm c < 1 \<Longrightarrow> summable (\<lambda>n. c^n)"
hoelzl@56193
   425
  by (rule geometric_sums [THEN sums_summable])
paulson@14416
   426
hoelzl@56193
   427
lemma suminf_geometric: "norm c < 1 \<Longrightarrow> suminf (\<lambda>n. c^n) = 1 / (1 - c)"
hoelzl@56193
   428
  by (rule sums_unique[symmetric]) (rule geometric_sums)
hoelzl@56193
   429
hoelzl@56193
   430
end
paulson@33271
   431
paulson@33271
   432
lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
paulson@33271
   433
proof -
paulson@33271
   434
  have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
paulson@33271
   435
    by auto
paulson@33271
   436
  have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
lp15@59741
   437
    by (simp add: mult.commute)
huffman@44282
   438
  thus ?thesis using sums_divide [OF 2, of 2]
paulson@33271
   439
    by simp
paulson@33271
   440
qed
paulson@33271
   441
wenzelm@60758
   442
subsection \<open>Infinite summability on Banach spaces\<close>
hoelzl@56213
   443
wenzelm@60758
   444
text\<open>Cauchy-type criterion for convergence of series (c.f. Harrison)\<close>
paulson@15085
   445
hoelzl@56193
   446
lemma summable_Cauchy:
hoelzl@56193
   447
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   448
  shows "summable f \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. norm (setsum f {m..<n}) < e)"
hoelzl@56193
   449
  apply (simp only: summable_iff_convergent Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
hoelzl@56193
   450
  apply (drule spec, drule (1) mp)
hoelzl@56193
   451
  apply (erule exE, rule_tac x="M" in exI, clarify)
hoelzl@56193
   452
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   453
  apply (frule (1) order_trans)
hoelzl@56193
   454
  apply (drule_tac x="n" in spec, drule (1) mp)
hoelzl@56193
   455
  apply (drule_tac x="m" in spec, drule (1) mp)
hoelzl@56193
   456
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   457
  apply (drule spec, drule (1) mp)
hoelzl@56193
   458
  apply (erule exE, rule_tac x="N" in exI, clarify)
hoelzl@56193
   459
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   460
  apply (subst norm_minus_commute)
hoelzl@56193
   461
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   462
  done
paulson@14416
   463
hoelzl@56193
   464
context
hoelzl@56193
   465
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   466
begin  
hoelzl@56193
   467
wenzelm@60758
   468
text\<open>Absolute convergence imples normal convergence\<close>
huffman@20689
   469
hoelzl@56194
   470
lemma summable_norm_cancel: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
hoelzl@56193
   471
  apply (simp only: summable_Cauchy, safe)
hoelzl@56193
   472
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   473
  apply (rule_tac x="N" in exI, safe)
hoelzl@56193
   474
  apply (drule_tac x="m" in spec, safe)
hoelzl@56193
   475
  apply (rule order_le_less_trans [OF norm_setsum])
hoelzl@56193
   476
  apply (rule order_le_less_trans [OF abs_ge_self])
hoelzl@56193
   477
  apply simp
hoelzl@50999
   478
  done
paulson@32707
   479
hoelzl@56193
   480
lemma summable_norm: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
hoelzl@56193
   481
  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel summable_LIMSEQ norm_setsum)
hoelzl@56193
   482
wenzelm@60758
   483
text \<open>Comparison tests\<close>
paulson@14416
   484
hoelzl@56194
   485
lemma summable_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable f"
hoelzl@56193
   486
  apply (simp add: summable_Cauchy, safe)
hoelzl@56193
   487
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   488
  apply (rule_tac x = "N + Na" in exI, safe)
hoelzl@56193
   489
  apply (rotate_tac 2)
hoelzl@56193
   490
  apply (drule_tac x = m in spec)
hoelzl@56193
   491
  apply (auto, rotate_tac 2, drule_tac x = n in spec)
hoelzl@56193
   492
  apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
hoelzl@56193
   493
  apply (rule norm_setsum)
hoelzl@56193
   494
  apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
hoelzl@56193
   495
  apply (auto intro: setsum_mono simp add: abs_less_iff)
hoelzl@56193
   496
  done
hoelzl@56193
   497
lp15@56217
   498
(*A better argument order*)
lp15@56217
   499
lemma summable_comparison_test': "summable g \<Longrightarrow> (\<And>n. n \<ge> N \<Longrightarrow> norm(f n) \<le> g n) \<Longrightarrow> summable f"
hoelzl@56369
   500
  by (rule summable_comparison_test) auto
lp15@56217
   501
wenzelm@60758
   502
subsection \<open>The Ratio Test\<close>
paulson@15085
   503
hoelzl@56193
   504
lemma summable_ratio_test: 
hoelzl@56193
   505
  assumes "c < 1" "\<And>n. n \<ge> N \<Longrightarrow> norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   506
  shows "summable f"
hoelzl@56193
   507
proof cases
hoelzl@56193
   508
  assume "0 < c"
hoelzl@56193
   509
  show "summable f"
hoelzl@56193
   510
  proof (rule summable_comparison_test)
hoelzl@56193
   511
    show "\<exists>N'. \<forall>n\<ge>N'. norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   512
    proof (intro exI allI impI)
hoelzl@56193
   513
      fix n assume "N \<le> n" then show "norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   514
      proof (induct rule: inc_induct)
hoelzl@56193
   515
        case (step m)
hoelzl@56193
   516
        moreover have "norm (f (Suc m)) / c ^ Suc m * c ^ n \<le> norm (f m) / c ^ m * c ^ n"
wenzelm@60758
   517
          using \<open>0 < c\<close> \<open>c < 1\<close> assms(2)[OF \<open>N \<le> m\<close>] by (simp add: field_simps)
hoelzl@56193
   518
        ultimately show ?case by simp
wenzelm@60758
   519
      qed (insert \<open>0 < c\<close>, simp)
hoelzl@56193
   520
    qed
hoelzl@56193
   521
    show "summable (\<lambda>n. norm (f N) / c ^ N * c ^ n)"
wenzelm@60758
   522
      using \<open>0 < c\<close> \<open>c < 1\<close> by (intro summable_mult summable_geometric) simp
hoelzl@56193
   523
  qed
hoelzl@56193
   524
next
hoelzl@56193
   525
  assume c: "\<not> 0 < c"
hoelzl@56193
   526
  { fix n assume "n \<ge> N"
hoelzl@56193
   527
    then have "norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   528
      by fact
hoelzl@56193
   529
    also have "\<dots> \<le> 0"
hoelzl@56193
   530
      using c by (simp add: not_less mult_nonpos_nonneg)
hoelzl@56193
   531
    finally have "f (Suc n) = 0"
hoelzl@56193
   532
      by auto }
hoelzl@56193
   533
  then show "summable f"
hoelzl@56194
   534
    by (intro sums_summable[OF sums_finite, of "{.. Suc N}"]) (auto simp: not_le Suc_less_eq2)
lp15@56178
   535
qed
lp15@56178
   536
hoelzl@56193
   537
end
paulson@14416
   538
wenzelm@60758
   539
text\<open>Relations among convergence and absolute convergence for power series.\<close>
hoelzl@56369
   540
hoelzl@56369
   541
lemma abel_lemma:
hoelzl@56369
   542
  fixes a :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56369
   543
  assumes r: "0 \<le> r" and r0: "r < r0" and M: "\<And>n. norm (a n) * r0^n \<le> M"
hoelzl@56369
   544
    shows "summable (\<lambda>n. norm (a n) * r^n)"
hoelzl@56369
   545
proof (rule summable_comparison_test')
hoelzl@56369
   546
  show "summable (\<lambda>n. M * (r / r0) ^ n)"
hoelzl@56369
   547
    using assms 
hoelzl@56369
   548
    by (auto simp add: summable_mult summable_geometric)
hoelzl@56369
   549
next
hoelzl@56369
   550
  fix n
hoelzl@56369
   551
  show "norm (norm (a n) * r ^ n) \<le> M * (r / r0) ^ n"
hoelzl@56369
   552
    using r r0 M [of n]
haftmann@60867
   553
    apply (auto simp add: abs_mult field_simps)
hoelzl@56369
   554
    apply (cases "r=0", simp)
hoelzl@56369
   555
    apply (cases n, auto)
hoelzl@56369
   556
    done
hoelzl@56369
   557
qed
hoelzl@56369
   558
hoelzl@56369
   559
wenzelm@60758
   560
text\<open>Summability of geometric series for real algebras\<close>
huffman@23084
   561
huffman@23084
   562
lemma complete_algebra_summable_geometric:
haftmann@31017
   563
  fixes x :: "'a::{real_normed_algebra_1,banach}"
huffman@23084
   564
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@23084
   565
proof (rule summable_comparison_test)
huffman@23084
   566
  show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
huffman@23084
   567
    by (simp add: norm_power_ineq)
huffman@23084
   568
  show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
huffman@23084
   569
    by (simp add: summable_geometric)
huffman@23084
   570
qed
huffman@23084
   571
wenzelm@60758
   572
subsection \<open>Cauchy Product Formula\<close>
huffman@23111
   573
wenzelm@60758
   574
text \<open>
wenzelm@54703
   575
  Proof based on Analysis WebNotes: Chapter 07, Class 41
wenzelm@54703
   576
  @{url "http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm"}
wenzelm@60758
   577
\<close>
huffman@23111
   578
huffman@23111
   579
lemma Cauchy_product_sums:
huffman@23111
   580
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   581
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   582
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   583
  shows "(\<lambda>k. \<Sum>i\<le>k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
huffman@23111
   584
proof -
hoelzl@56193
   585
  let ?S1 = "\<lambda>n::nat. {..<n} \<times> {..<n}"
huffman@23111
   586
  let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
huffman@23111
   587
  have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
huffman@23111
   588
  have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
huffman@23111
   589
  have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
huffman@23111
   590
  have finite_S1: "\<And>n. finite (?S1 n)" by simp
huffman@23111
   591
  with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
huffman@23111
   592
huffman@23111
   593
  let ?g = "\<lambda>(i,j). a i * b j"
huffman@23111
   594
  let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
nipkow@56536
   595
  have f_nonneg: "\<And>x. 0 \<le> ?f x" by (auto)
huffman@23111
   596
  hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
huffman@23111
   597
    unfolding real_norm_def
huffman@23111
   598
    by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
huffman@23111
   599
hoelzl@56193
   600
  have "(\<lambda>n. (\<Sum>k<n. a k) * (\<Sum>k<n. b k)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
hoelzl@56193
   601
    by (intro tendsto_mult summable_LIMSEQ summable_norm_cancel [OF a] summable_norm_cancel [OF b])
huffman@23111
   602
  hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
haftmann@57418
   603
    by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
huffman@23111
   604
hoelzl@56193
   605
  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
   606
    using a b by (intro tendsto_mult summable_LIMSEQ)
huffman@23111
   607
  hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
haftmann@57418
   608
    by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
huffman@23111
   609
  hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   610
    by (rule convergentI)
huffman@23111
   611
  hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   612
    by (rule convergent_Cauchy)
huffman@36657
   613
  have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
huffman@36657
   614
  proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
huffman@23111
   615
    fix r :: real
huffman@23111
   616
    assume r: "0 < r"
huffman@23111
   617
    from CauchyD [OF Cauchy r] obtain N
huffman@23111
   618
    where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
huffman@23111
   619
    hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
huffman@23111
   620
      by (simp only: setsum_diff finite_S1 S1_mono)
huffman@23111
   621
    hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
huffman@23111
   622
      by (simp only: norm_setsum_f)
huffman@23111
   623
    show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
huffman@23111
   624
    proof (intro exI allI impI)
huffman@23111
   625
      fix n assume "2 * N \<le> n"
huffman@23111
   626
      hence n: "N \<le> n div 2" by simp
huffman@23111
   627
      have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
huffman@23111
   628
        by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
huffman@23111
   629
                  Diff_mono subset_refl S1_le_S2)
huffman@23111
   630
      also have "\<dots> < r"
huffman@23111
   631
        using n div_le_dividend by (rule N)
huffman@23111
   632
      finally show "setsum ?f (?S1 n - ?S2 n) < r" .
huffman@23111
   633
    qed
huffman@23111
   634
  qed
huffman@36657
   635
  hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
huffman@36657
   636
    apply (rule Zfun_le [rule_format])
huffman@23111
   637
    apply (simp only: norm_setsum_f)
huffman@23111
   638
    apply (rule order_trans [OF norm_setsum setsum_mono])
huffman@23111
   639
    apply (auto simp add: norm_mult_ineq)
huffman@23111
   640
    done
huffman@23111
   641
  hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
huffman@36660
   642
    unfolding tendsto_Zfun_iff diff_0_right
huffman@36657
   643
    by (simp only: setsum_diff finite_S1 S2_le_S1)
huffman@23111
   644
huffman@23111
   645
  with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
lp15@60141
   646
    by (rule Lim_transform2)
huffman@23111
   647
  thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
huffman@23111
   648
qed
huffman@23111
   649
huffman@23111
   650
lemma Cauchy_product:
huffman@23111
   651
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   652
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   653
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   654
  shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i\<le>k. a i * b (k - i))"
hoelzl@56213
   655
  using a b
hoelzl@56213
   656
  by (rule Cauchy_product_sums [THEN sums_unique])
hoelzl@56213
   657
wenzelm@60758
   658
subsection \<open>Series on @{typ real}s\<close>
hoelzl@56213
   659
hoelzl@56213
   660
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
   661
  by (rule summable_comparison_test) auto
hoelzl@56213
   662
hoelzl@56213
   663
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
   664
  by (rule summable_comparison_test) auto
hoelzl@56213
   665
hoelzl@56213
   666
lemma summable_rabs_cancel: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> summable f"
hoelzl@56213
   667
  by (rule summable_norm_cancel) simp
hoelzl@56213
   668
hoelzl@56213
   669
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
   670
  by (fold real_norm_def) (rule summable_norm)
huffman@23111
   671
hoelzl@59000
   672
lemma summable_power_series:
hoelzl@59000
   673
  fixes z :: real
hoelzl@59000
   674
  assumes le_1: "\<And>i. f i \<le> 1" and nonneg: "\<And>i. 0 \<le> f i" and z: "0 \<le> z" "z < 1"
hoelzl@59000
   675
  shows "summable (\<lambda>i. f i * z^i)"
hoelzl@59000
   676
proof (rule summable_comparison_test[OF _ summable_geometric])
hoelzl@59000
   677
  show "norm z < 1" using z by (auto simp: less_imp_le)
hoelzl@59000
   678
  show "\<And>n. \<exists>N. \<forall>na\<ge>N. norm (f na * z ^ na) \<le> z ^ na"
hoelzl@59000
   679
    using z by (auto intro!: exI[of _ 0] mult_left_le_one_le simp: abs_mult nonneg power_abs less_imp_le le_1)
hoelzl@59000
   680
qed
hoelzl@59000
   681
Andreas@59025
   682
lemma
Andreas@59025
   683
   fixes f :: "nat \<Rightarrow> real"
Andreas@59025
   684
   assumes "summable f"
Andreas@59025
   685
   and "inj g"
Andreas@59025
   686
   and pos: "!!x. 0 \<le> f x"
Andreas@59025
   687
   shows summable_reindex: "summable (f o g)"
Andreas@59025
   688
   and suminf_reindex_mono: "suminf (f o g) \<le> suminf f"
Andreas@59025
   689
   and suminf_reindex: "(\<And>x. x \<notin> range g \<Longrightarrow> f x = 0) \<Longrightarrow> suminf (f \<circ> g) = suminf f"
Andreas@59025
   690
proof -
Andreas@59025
   691
  from \<open>inj g\<close> have [simp]: "\<And>A. inj_on g A" by(rule subset_inj_on) simp
Andreas@59025
   692
Andreas@59025
   693
  have smaller: "\<forall>n. (\<Sum>i<n. (f \<circ> g) i) \<le> suminf f"
Andreas@59025
   694
  proof
Andreas@59025
   695
    fix n
Andreas@59025
   696
    have "\<forall> n' \<in> (g ` {..<n}). n' < Suc (Max (g ` {..<n}))" 
Andreas@59025
   697
      by(metis Max_ge finite_imageI finite_lessThan not_le not_less_eq)
Andreas@59025
   698
    then obtain m where n: "\<And>n'. n' < n \<Longrightarrow> g n' < m" by blast
Andreas@59025
   699
Andreas@59025
   700
    have "(\<Sum>i<n. f (g i)) = setsum f (g ` {..<n})"
Andreas@59025
   701
      by (simp add: setsum.reindex)
Andreas@59025
   702
    also have "\<dots> \<le> (\<Sum>i<m. f i)"
Andreas@59025
   703
      by (rule setsum_mono3) (auto simp add: pos n[rule_format])
Andreas@59025
   704
    also have "\<dots> \<le> suminf f"
wenzelm@60758
   705
      using \<open>summable f\<close> 
Andreas@59025
   706
      by (rule setsum_le_suminf) (simp add: pos)
Andreas@59025
   707
    finally show "(\<Sum>i<n. (f \<circ>  g) i) \<le> suminf f" by simp
Andreas@59025
   708
  qed
Andreas@59025
   709
Andreas@59025
   710
  have "incseq (\<lambda>n. \<Sum>i<n. (f \<circ> g) i)"
Andreas@59025
   711
    by (rule incseq_SucI) (auto simp add: pos)
Andreas@59025
   712
  then obtain  L where L: "(\<lambda> n. \<Sum>i<n. (f \<circ> g) i) ----> L"
Andreas@59025
   713
    using smaller by(rule incseq_convergent)
Andreas@59025
   714
  hence "(f \<circ> g) sums L" by (simp add: sums_def)
Andreas@59025
   715
  thus "summable (f o g)" by (auto simp add: sums_iff)
Andreas@59025
   716
Andreas@59025
   717
  hence "(\<lambda>n. \<Sum>i<n. (f \<circ> g) i) ----> suminf (f \<circ> g)"
Andreas@59025
   718
    by(rule summable_LIMSEQ)
Andreas@59025
   719
  thus le: "suminf (f \<circ> g) \<le> suminf f"
Andreas@59025
   720
    by(rule LIMSEQ_le_const2)(blast intro: smaller[rule_format])
Andreas@59025
   721
Andreas@59025
   722
  assume f: "\<And>x. x \<notin> range g \<Longrightarrow> f x = 0"
Andreas@59025
   723
Andreas@59025
   724
  from \<open>summable f\<close> have "suminf f \<le> suminf (f \<circ> g)"
Andreas@59025
   725
  proof(rule suminf_le_const)
Andreas@59025
   726
    fix n
Andreas@59025
   727
    have "\<forall> n' \<in> (g -` {..<n}). n' < Suc (Max (g -` {..<n}))"
Andreas@59025
   728
      by(auto intro: Max_ge simp add: finite_vimageI less_Suc_eq_le)
Andreas@59025
   729
    then obtain m where n: "\<And>n'. g n' < n \<Longrightarrow> n' < m" by blast
Andreas@59025
   730
Andreas@59025
   731
    have "(\<Sum>i<n. f i) = (\<Sum>i\<in>{..<n} \<inter> range g. f i)"
Andreas@59025
   732
      using f by(auto intro: setsum.mono_neutral_cong_right)
Andreas@59025
   733
    also have "\<dots> = (\<Sum>i\<in>g -` {..<n}. (f \<circ> g) i)"
Andreas@59025
   734
      by(rule setsum.reindex_cong[where l=g])(auto)
Andreas@59025
   735
    also have "\<dots> \<le> (\<Sum>i<m. (f \<circ> g) i)"
Andreas@59025
   736
      by(rule setsum_mono3)(auto simp add: pos n)
Andreas@59025
   737
    also have "\<dots> \<le> suminf (f \<circ> g)"
Andreas@59025
   738
      using \<open>summable (f o g)\<close>
Andreas@59025
   739
      by(rule setsum_le_suminf)(simp add: pos)
Andreas@59025
   740
    finally show "setsum f {..<n} \<le> suminf (f \<circ> g)" .
Andreas@59025
   741
  qed
Andreas@59025
   742
  with le show "suminf (f \<circ> g) = suminf f" by(rule antisym)
Andreas@59025
   743
qed
Andreas@59025
   744
paulson@14416
   745
end