src/HOL/Series.thy
author wenzelm
Wed May 25 11:49:40 2016 +0200 (2016-05-25)
changeset 63145 703edebd1d92
parent 63040 eb4ddd18d635
child 63365 5340fb6633d0
permissions -rw-r--r--
isabelle update_cartouches -c -t;
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
lp15@61609
    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
wenzelm@61969
    22
  "f sums s \<longleftrightarrow> (\<lambda>n. \<Sum>i<n. f i) \<longlonglongrightarrow> 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
paulson@62087
    33
lemma sums_def': "f sums s \<longleftrightarrow> (\<lambda>n. \<Sum>i = 0..n. f i) \<longlonglongrightarrow> s"
paulson@62087
    34
  apply (simp add: sums_def)
paulson@62087
    35
  apply (subst LIMSEQ_Suc_iff [symmetric])
paulson@62087
    36
  apply (simp only: lessThan_Suc_atMost atLeast0AtMost)
paulson@62087
    37
  done
paulson@62087
    38
wenzelm@60758
    39
subsection \<open>Infinite summability on topological monoids\<close>
hoelzl@56213
    40
hoelzl@56193
    41
lemma sums_subst[trans]: "f = g \<Longrightarrow> g sums z \<Longrightarrow> f sums z"
hoelzl@56193
    42
  by simp
hoelzl@56193
    43
eberlm@61531
    44
lemma sums_cong: "(\<And>n. f n = g n) \<Longrightarrow> f sums c \<longleftrightarrow> g sums c"
eberlm@61531
    45
  by (drule ext) simp
eberlm@61531
    46
hoelzl@56193
    47
lemma sums_summable: "f sums l \<Longrightarrow> summable f"
hoelzl@41970
    48
  by (simp add: sums_def summable_def, blast)
paulson@14416
    49
hoelzl@56193
    50
lemma summable_iff_convergent: "summable f \<longleftrightarrow> convergent (\<lambda>n. \<Sum>i<n. f i)"
hoelzl@56193
    51
  by (simp add: summable_def sums_def convergent_def)
paulson@14416
    52
eberlm@61531
    53
lemma summable_iff_convergent':
eberlm@61531
    54
  "summable f \<longleftrightarrow> convergent (\<lambda>n. setsum f {..n})"
lp15@61609
    55
  by (simp_all only: summable_iff_convergent convergent_def
eberlm@61531
    56
        lessThan_Suc_atMost [symmetric] LIMSEQ_Suc_iff[of "\<lambda>n. setsum f {..<n}"])
eberlm@61531
    57
hoelzl@56193
    58
lemma suminf_eq_lim: "suminf f = lim (\<lambda>n. \<Sum>i<n. f i)"
hoelzl@41970
    59
  by (simp add: suminf_def sums_def lim_def)
paulson@32707
    60
hoelzl@56213
    61
lemma sums_zero[simp, intro]: "(\<lambda>n. 0) sums 0"
hoelzl@58729
    62
  unfolding sums_def by simp
hoelzl@56213
    63
hoelzl@56213
    64
lemma summable_zero[simp, intro]: "summable (\<lambda>n. 0)"
hoelzl@56213
    65
  by (rule sums_zero [THEN sums_summable])
hoelzl@56213
    66
hoelzl@56213
    67
lemma sums_group: "f sums s \<Longrightarrow> 0 < k \<Longrightarrow> (\<lambda>n. setsum f {n * k ..< n * k + k}) sums s"
hoelzl@56213
    68
  apply (simp only: sums_def setsum_nat_group tendsto_def eventually_sequentially)
hoelzl@56213
    69
  apply safe
hoelzl@56213
    70
  apply (erule_tac x=S in allE)
hoelzl@56213
    71
  apply safe
hoelzl@56213
    72
  apply (rule_tac x="N" in exI, safe)
hoelzl@56213
    73
  apply (drule_tac x="n*k" in spec)
hoelzl@56213
    74
  apply (erule mp)
hoelzl@56213
    75
  apply (erule order_trans)
hoelzl@56213
    76
  apply simp
hoelzl@56213
    77
  done
hoelzl@56213
    78
eberlm@61531
    79
lemma suminf_cong: "(\<And>n. f n = g n) \<Longrightarrow> suminf f = suminf g"
eberlm@61531
    80
  by (rule arg_cong[of f g], rule ext) simp
eberlm@61531
    81
eberlm@61531
    82
lemma summable_cong:
eberlm@61531
    83
  assumes "eventually (\<lambda>x. f x = (g x :: 'a :: real_normed_vector)) sequentially"
eberlm@61531
    84
  shows   "summable f = summable g"
eberlm@61531
    85
proof -
eberlm@61531
    86
  from assms obtain N where N: "\<forall>n\<ge>N. f n = g n" by (auto simp: eventually_at_top_linorder)
wenzelm@63040
    87
  define C where "C = (\<Sum>k<N. f k - g k)"
lp15@61609
    88
  from eventually_ge_at_top[of N]
eberlm@61531
    89
    have "eventually (\<lambda>n. setsum f {..<n} = C + setsum g {..<n}) sequentially"
eberlm@61531
    90
  proof eventually_elim
eberlm@61531
    91
    fix n assume n: "n \<ge> N"
eberlm@61531
    92
    from n have "{..<n} = {..<N} \<union> {N..<n}" by auto
eberlm@61531
    93
    also have "setsum f ... = setsum f {..<N} + setsum f {N..<n}"
eberlm@61531
    94
      by (intro setsum.union_disjoint) auto
eberlm@61531
    95
    also from N have "setsum f {N..<n} = setsum g {N..<n}" by (intro setsum.cong) simp_all
lp15@61609
    96
    also have "setsum f {..<N} + setsum g {N..<n} = C + (setsum g {..<N} + setsum g {N..<n})"
eberlm@61531
    97
      unfolding C_def by (simp add: algebra_simps setsum_subtractf)
eberlm@61531
    98
    also have "setsum g {..<N} + setsum g {N..<n} = setsum g ({..<N} \<union> {N..<n})"
eberlm@61531
    99
      by (intro setsum.union_disjoint [symmetric]) auto
eberlm@61531
   100
    also from n have "{..<N} \<union> {N..<n} = {..<n}" by auto
eberlm@61531
   101
    finally show "setsum f {..<n} = C + setsum g {..<n}" .
eberlm@61531
   102
  qed
eberlm@61531
   103
  from convergent_cong[OF this] show ?thesis
eberlm@61531
   104
    by (simp add: summable_iff_convergent convergent_add_const_iff)
eberlm@61531
   105
qed
eberlm@61531
   106
hoelzl@47761
   107
lemma sums_finite:
hoelzl@56193
   108
  assumes [simp]: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@47761
   109
  shows "f sums (\<Sum>n\<in>N. f n)"
hoelzl@47761
   110
proof -
hoelzl@47761
   111
  { fix n
hoelzl@47761
   112
    have "setsum f {..<n + Suc (Max N)} = setsum f N"
hoelzl@47761
   113
    proof cases
hoelzl@47761
   114
      assume "N = {}"
hoelzl@47761
   115
      with f have "f = (\<lambda>x. 0)" by auto
hoelzl@47761
   116
      then show ?thesis by simp
hoelzl@47761
   117
    next
hoelzl@47761
   118
      assume [simp]: "N \<noteq> {}"
hoelzl@47761
   119
      show ?thesis
haftmann@57418
   120
      proof (safe intro!: setsum.mono_neutral_right f)
hoelzl@47761
   121
        fix i assume "i \<in> N"
hoelzl@47761
   122
        then have "i \<le> Max N" by simp
hoelzl@47761
   123
        then show "i < n + Suc (Max N)" by simp
hoelzl@47761
   124
      qed
hoelzl@47761
   125
    qed }
hoelzl@47761
   126
  note eq = this
hoelzl@47761
   127
  show ?thesis unfolding sums_def
hoelzl@47761
   128
    by (rule LIMSEQ_offset[of _ "Suc (Max N)"])
hoelzl@58729
   129
       (simp add: eq atLeast0LessThan del: add_Suc_right)
hoelzl@47761
   130
qed
hoelzl@47761
   131
lp15@62217
   132
corollary sums_0:
lp15@62217
   133
   "(\<And>n. f n = 0) \<Longrightarrow> (f sums 0)"
lp15@62217
   134
    by (metis (no_types) finite.emptyI setsum.empty sums_finite)
lp15@62217
   135
hoelzl@56213
   136
lemma summable_finite: "finite N \<Longrightarrow> (\<And>n. n \<notin> N \<Longrightarrow> f n = 0) \<Longrightarrow> summable f"
hoelzl@56213
   137
  by (rule sums_summable) (rule sums_finite)
hoelzl@56213
   138
hoelzl@56193
   139
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
   140
  using sums_finite[of A "(\<lambda>r. if r \<in> A then f r else 0)"] by simp
hoelzl@47761
   141
hoelzl@56213
   142
lemma summable_If_finite_set[simp, intro]: "finite A \<Longrightarrow> summable (\<lambda>r. if r \<in> A then f r else 0)"
hoelzl@56213
   143
  by (rule sums_summable) (rule sums_If_finite_set)
hoelzl@56213
   144
hoelzl@56193
   145
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
   146
  using sums_If_finite_set[of "{r. P r}"] by simp
avigad@16819
   147
hoelzl@56213
   148
lemma summable_If_finite[simp, intro]: "finite {r. P r} \<Longrightarrow> summable (\<lambda>r. if P r then f r else 0)"
hoelzl@56213
   149
  by (rule sums_summable) (rule sums_If_finite)
hoelzl@56213
   150
hoelzl@56193
   151
lemma sums_single: "(\<lambda>r. if r = i then f r else 0) sums f i"
hoelzl@56193
   152
  using sums_If_finite[of "\<lambda>r. r = i"] by simp
hoelzl@29803
   153
hoelzl@56213
   154
lemma summable_single[simp, intro]: "summable (\<lambda>r. if r = i then f r else 0)"
hoelzl@56213
   155
  by (rule sums_summable) (rule sums_single)
hoelzl@56193
   156
hoelzl@56193
   157
context
hoelzl@56193
   158
  fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
hoelzl@56193
   159
begin
hoelzl@56193
   160
hoelzl@56193
   161
lemma summable_sums[intro]: "summable f \<Longrightarrow> f sums (suminf f)"
hoelzl@56193
   162
  by (simp add: summable_def sums_def suminf_def)
hoelzl@56193
   163
     (metis convergent_LIMSEQ_iff convergent_def lim_def)
hoelzl@56193
   164
wenzelm@61969
   165
lemma summable_LIMSEQ: "summable f \<Longrightarrow> (\<lambda>n. \<Sum>i<n. f i) \<longlonglongrightarrow> suminf f"
hoelzl@56193
   166
  by (rule summable_sums [unfolded sums_def])
hoelzl@56193
   167
hoelzl@56193
   168
lemma sums_unique: "f sums s \<Longrightarrow> s = suminf f"
hoelzl@56193
   169
  by (metis limI suminf_eq_lim sums_def)
hoelzl@56193
   170
hoelzl@56193
   171
lemma sums_iff: "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
hoelzl@56193
   172
  by (metis summable_sums sums_summable sums_unique)
hoelzl@56193
   173
lp15@61609
   174
lemma summable_sums_iff:
eberlm@61531
   175
  "summable (f :: nat \<Rightarrow> 'a :: {comm_monoid_add,t2_space}) \<longleftrightarrow> f sums suminf f"
eberlm@61531
   176
  by (auto simp: sums_iff summable_sums)
eberlm@61531
   177
lp15@59613
   178
lemma sums_unique2:
lp15@59613
   179
  fixes a b :: "'a::{comm_monoid_add,t2_space}"
lp15@59613
   180
  shows "f sums a \<Longrightarrow> f sums b \<Longrightarrow> a = b"
lp15@59613
   181
by (simp add: sums_iff)
lp15@59613
   182
hoelzl@56193
   183
lemma suminf_finite:
hoelzl@56193
   184
  assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
hoelzl@56193
   185
  shows "suminf f = (\<Sum>n\<in>N. f n)"
hoelzl@56193
   186
  using sums_finite[OF assms, THEN sums_unique] by simp
hoelzl@56193
   187
hoelzl@56193
   188
end
avigad@16819
   189
hoelzl@41970
   190
lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
hoelzl@56193
   191
  by (rule sums_zero [THEN sums_unique, symmetric])
avigad@16819
   192
hoelzl@56213
   193
wenzelm@60758
   194
subsection \<open>Infinite summability on ordered, topological monoids\<close>
hoelzl@56213
   195
hoelzl@56213
   196
lemma sums_le:
hoelzl@56213
   197
  fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@56213
   198
  shows "\<forall>n. f n \<le> g n \<Longrightarrow> f sums s \<Longrightarrow> g sums t \<Longrightarrow> s \<le> t"
hoelzl@56213
   199
  by (rule LIMSEQ_le) (auto intro: setsum_mono simp: sums_def)
hoelzl@56213
   200
hoelzl@56193
   201
context
hoelzl@56193
   202
  fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
hoelzl@56193
   203
begin
paulson@14416
   204
hoelzl@56213
   205
lemma suminf_le: "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
hoelzl@56213
   206
  by (auto dest: sums_summable intro: sums_le)
hoelzl@56213
   207
hoelzl@56213
   208
lemma setsum_le_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> setsum f {..<n} \<le> suminf f"
hoelzl@56213
   209
  by (rule sums_le[OF _ sums_If_finite_set summable_sums]) auto
hoelzl@56213
   210
hoelzl@56213
   211
lemma suminf_nonneg: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 \<le> suminf f"
hoelzl@56213
   212
  using setsum_le_suminf[of 0] by simp
hoelzl@56213
   213
hoelzl@56213
   214
lemma suminf_le_const: "summable f \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
hoelzl@56213
   215
  by (metis LIMSEQ_le_const2 summable_LIMSEQ)
paulson@14416
   216
hoelzl@56193
   217
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
   218
proof
hoelzl@50999
   219
  assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
wenzelm@61969
   220
  then have f: "(\<lambda>n. \<Sum>i<n. f i) \<longlonglongrightarrow> 0"
hoelzl@56213
   221
    using summable_LIMSEQ[of f] by simp
hoelzl@56213
   222
  then have "\<And>i. (\<Sum>n\<in>{i}. f n) \<le> 0"
hoelzl@56213
   223
  proof (rule LIMSEQ_le_const)
hoelzl@50999
   224
    fix i show "\<exists>N. \<forall>n\<ge>N. (\<Sum>n\<in>{i}. f n) \<le> setsum f {..<n}"
hoelzl@50999
   225
      using pos by (intro exI[of _ "Suc i"] allI impI setsum_mono2) auto
hoelzl@50999
   226
  qed
hoelzl@50999
   227
  with pos show "\<forall>n. f n = 0"
hoelzl@50999
   228
    by (auto intro!: antisym)
hoelzl@56193
   229
qed (metis suminf_zero fun_eq_iff)
hoelzl@56193
   230
hoelzl@62377
   231
lemma suminf_pos_iff:
hoelzl@62377
   232
  "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
hoelzl@62377
   233
  using setsum_le_suminf[of 0] suminf_eq_zero_iff by (simp add: less_le)
hoelzl@62377
   234
hoelzl@62377
   235
lemma suminf_pos2:
hoelzl@62377
   236
  assumes "summable f" "\<forall>n. 0 \<le> f n" "0 < f i"
hoelzl@62377
   237
  shows "0 < suminf f"
hoelzl@62377
   238
proof -
hoelzl@62377
   239
  have "0 < (\<Sum>n<Suc i. f n)"
hoelzl@62377
   240
    using assms by (intro setsum_pos2[where i=i]) auto
hoelzl@62377
   241
  also have "\<dots> \<le> suminf f"
hoelzl@62377
   242
    using assms by (intro setsum_le_suminf) auto
hoelzl@62377
   243
  finally show ?thesis .
hoelzl@62377
   244
qed
hoelzl@62377
   245
hoelzl@62377
   246
lemma suminf_pos: "summable f \<Longrightarrow> \<forall>n. 0 < f n \<Longrightarrow> 0 < suminf f"
hoelzl@62377
   247
  by (intro suminf_pos2[where i=0]) (auto intro: less_imp_le)
hoelzl@62377
   248
hoelzl@62376
   249
end
hoelzl@62376
   250
hoelzl@62376
   251
context
hoelzl@62376
   252
  fixes f :: "nat \<Rightarrow> 'a::{ordered_cancel_comm_monoid_add, linorder_topology}"
hoelzl@62376
   253
begin
hoelzl@62376
   254
hoelzl@62376
   255
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@62376
   256
  using
hoelzl@62376
   257
    setsum_le_suminf[of f "Suc i"]
hoelzl@62376
   258
    add_strict_increasing[of "f i" "setsum f {..<n}" "setsum f {..<i}"]
hoelzl@62376
   259
    setsum_mono2[of "{..<i}" "{..<n}" f]
hoelzl@62376
   260
  by (auto simp: less_imp_le ac_simps)
hoelzl@62376
   261
hoelzl@62376
   262
lemma setsum_less_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 < f m \<Longrightarrow> setsum f {..<n} < suminf f"
hoelzl@62376
   263
  using setsum_less_suminf2[of n n] by (simp add: less_imp_le)
hoelzl@62376
   264
hoelzl@56193
   265
end
hoelzl@56193
   266
hoelzl@56213
   267
lemma summableI_nonneg_bounded:
hoelzl@56213
   268
  fixes f:: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology, conditionally_complete_linorder}"
hoelzl@56213
   269
  assumes pos[simp]: "\<And>n. 0 \<le> f n" and le: "\<And>n. (\<Sum>i<n. f i) \<le> x"
hoelzl@56213
   270
  shows "summable f"
hoelzl@56213
   271
  unfolding summable_def sums_def[abs_def]
hoelzl@62377
   272
proof (rule exI LIMSEQ_incseq_SUP)+
hoelzl@62377
   273
  show "bdd_above (range (\<lambda>n. setsum f {..<n}))"
hoelzl@56213
   274
    using le by (auto simp: bdd_above_def)
hoelzl@62377
   275
  show "incseq (\<lambda>n. setsum f {..<n})"
hoelzl@62377
   276
    by (auto simp: mono_def intro!: setsum_mono2)
hoelzl@56213
   277
qed
hoelzl@56213
   278
hoelzl@62377
   279
lemma summableI[intro, simp]:
hoelzl@62377
   280
  fixes f:: "nat \<Rightarrow> 'a::{canonically_ordered_monoid_add, linorder_topology, complete_linorder}"
hoelzl@62377
   281
  shows "summable f"
hoelzl@62377
   282
  by (intro summableI_nonneg_bounded[where x=top] zero_le top_greatest)
hoelzl@62377
   283
hoelzl@62368
   284
subsection \<open>Infinite summability on topological monoids\<close>
hoelzl@62368
   285
hoelzl@62368
   286
lemma Zero_notin_Suc: "0 \<notin> Suc ` A"
hoelzl@62368
   287
  by auto
hoelzl@62368
   288
hoelzl@62368
   289
context
hoelzl@62368
   290
  fixes f g :: "nat \<Rightarrow> 'a :: {t2_space, topological_comm_monoid_add}"
hoelzl@62368
   291
begin
hoelzl@62368
   292
hoelzl@62368
   293
lemma sums_Suc:
hoelzl@62368
   294
  assumes "(\<lambda>n. f (Suc n)) sums l" shows "f sums (l + f 0)"
hoelzl@62368
   295
proof  -
hoelzl@62368
   296
  have "(\<lambda>n. (\<Sum>i<n. f (Suc i)) + f 0) \<longlonglongrightarrow> l + f 0"
hoelzl@62368
   297
    using assms by (auto intro!: tendsto_add simp: sums_def)
hoelzl@62368
   298
  moreover have "(\<Sum>i<n. f (Suc i)) + f 0 = (\<Sum>i<Suc n. f i)" for n
hoelzl@62368
   299
    unfolding lessThan_Suc_eq_insert_0 by (simp add: Zero_notin_Suc ac_simps setsum.reindex)
hoelzl@62368
   300
  ultimately show ?thesis
hoelzl@62368
   301
    by (auto simp add: sums_def simp del: setsum_lessThan_Suc intro: LIMSEQ_Suc_iff[THEN iffD1])
hoelzl@62368
   302
qed
hoelzl@62368
   303
hoelzl@62368
   304
lemma sums_add: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n + g n) sums (a + b)"
hoelzl@62368
   305
  unfolding sums_def by (simp add: setsum.distrib tendsto_add)
hoelzl@62368
   306
hoelzl@62368
   307
lemma summable_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n + g n)"
hoelzl@62368
   308
  unfolding summable_def by (auto intro: sums_add)
hoelzl@62368
   309
hoelzl@62368
   310
lemma suminf_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f + suminf g = (\<Sum>n. f n + g n)"
hoelzl@62368
   311
  by (intro sums_unique sums_add summable_sums)
hoelzl@62368
   312
hoelzl@62368
   313
end
hoelzl@62368
   314
hoelzl@62368
   315
context
hoelzl@62368
   316
  fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::{t2_space, topological_comm_monoid_add}" and I :: "'i set"
hoelzl@62368
   317
begin
hoelzl@62368
   318
hoelzl@62368
   319
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@62368
   320
  by (induct I rule: infinite_finite_induct) (auto intro!: sums_add)
hoelzl@62368
   321
hoelzl@62368
   322
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@62368
   323
  using sums_unique[OF sums_setsum, OF summable_sums] by simp
hoelzl@62368
   324
hoelzl@62368
   325
lemma summable_setsum: "(\<And>i. i \<in> I \<Longrightarrow> summable (f i)) \<Longrightarrow> summable (\<lambda>n. \<Sum>i\<in>I. f i n)"
hoelzl@62368
   326
  using sums_summable[OF sums_setsum[OF summable_sums]] .
hoelzl@62368
   327
hoelzl@62368
   328
end
eberlm@61531
   329
wenzelm@60758
   330
subsection \<open>Infinite summability on real normed vector spaces\<close>
hoelzl@56193
   331
hoelzl@62368
   332
context
hoelzl@56193
   333
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@62368
   334
begin
hoelzl@62368
   335
hoelzl@62368
   336
lemma sums_Suc_iff: "(\<lambda>n. f (Suc n)) sums s \<longleftrightarrow> f sums (s + f 0)"
hoelzl@56193
   337
proof -
wenzelm@61969
   338
  have "f sums (s + f 0) \<longleftrightarrow> (\<lambda>i. \<Sum>j<Suc i. f j) \<longlonglongrightarrow> s + f 0"
hoelzl@56193
   339
    by (subst LIMSEQ_Suc_iff) (simp add: sums_def)
wenzelm@61969
   340
  also have "\<dots> \<longleftrightarrow> (\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) \<longlonglongrightarrow> s + f 0"
haftmann@57418
   341
    by (simp add: ac_simps setsum.reindex image_iff lessThan_Suc_eq_insert_0)
hoelzl@56193
   342
  also have "\<dots> \<longleftrightarrow> (\<lambda>n. f (Suc n)) sums s"
hoelzl@56193
   343
  proof
wenzelm@61969
   344
    assume "(\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) \<longlonglongrightarrow> s + f 0"
hoelzl@56193
   345
    with tendsto_add[OF this tendsto_const, of "- f 0"]
hoelzl@56193
   346
    show "(\<lambda>i. f (Suc i)) sums s"
hoelzl@56193
   347
      by (simp add: sums_def)
hoelzl@58729
   348
  qed (auto intro: tendsto_add simp: sums_def)
hoelzl@56193
   349
  finally show ?thesis ..
hoelzl@50999
   350
qed
hoelzl@50999
   351
hoelzl@62368
   352
lemma summable_Suc_iff: "summable (\<lambda>n. f (Suc n)) = summable f"
eberlm@61531
   353
proof
eberlm@61531
   354
  assume "summable f"
eberlm@61531
   355
  hence "f sums suminf f" by (rule summable_sums)
eberlm@61531
   356
  hence "(\<lambda>n. f (Suc n)) sums (suminf f - f 0)" by (simp add: sums_Suc_iff)
eberlm@61531
   357
  thus "summable (\<lambda>n. f (Suc n))" unfolding summable_def by blast
eberlm@61531
   358
qed (auto simp: sums_Suc_iff summable_def)
eberlm@61531
   359
lp15@62381
   360
lemma sums_Suc_imp: "f 0 = 0 \<Longrightarrow> (\<lambda>n. f (Suc n)) sums s \<Longrightarrow> (\<lambda>n. f n) sums s"
lp15@62381
   361
  using sums_Suc_iff by simp
lp15@62381
   362
hoelzl@62368
   363
end
hoelzl@62368
   364
wenzelm@63145
   365
context \<comment>\<open>Separate contexts are necessary to allow general use of the results above, here.\<close>
hoelzl@56193
   366
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56193
   367
begin
hoelzl@56193
   368
hoelzl@56193
   369
lemma sums_diff: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n - g n) sums (a - b)"
hoelzl@56193
   370
  unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
hoelzl@56193
   371
hoelzl@56193
   372
lemma summable_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n - g n)"
hoelzl@56193
   373
  unfolding summable_def by (auto intro: sums_diff)
hoelzl@56193
   374
hoelzl@56193
   375
lemma suminf_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f - suminf g = (\<Sum>n. f n - g n)"
hoelzl@56193
   376
  by (intro sums_unique sums_diff summable_sums)
hoelzl@56193
   377
hoelzl@56193
   378
lemma sums_minus: "f sums a \<Longrightarrow> (\<lambda>n. - f n) sums (- a)"
hoelzl@56193
   379
  unfolding sums_def by (simp add: setsum_negf tendsto_minus)
hoelzl@56193
   380
hoelzl@56193
   381
lemma summable_minus: "summable f \<Longrightarrow> summable (\<lambda>n. - f n)"
hoelzl@56193
   382
  unfolding summable_def by (auto intro: sums_minus)
huffman@20692
   383
hoelzl@56193
   384
lemma suminf_minus: "summable f \<Longrightarrow> (\<Sum>n. - f n) = - (\<Sum>n. f n)"
hoelzl@56193
   385
  by (intro sums_unique [symmetric] sums_minus summable_sums)
hoelzl@56193
   386
hoelzl@56193
   387
lemma sums_iff_shift: "(\<lambda>i. f (i + n)) sums s \<longleftrightarrow> f sums (s + (\<Sum>i<n. f i))"
hoelzl@56193
   388
proof (induct n arbitrary: s)
hoelzl@56193
   389
  case (Suc n)
hoelzl@56193
   390
  moreover have "(\<lambda>i. f (Suc i + n)) sums s \<longleftrightarrow> (\<lambda>i. f (i + n)) sums (s + f n)"
hoelzl@56193
   391
    by (subst sums_Suc_iff) simp
hoelzl@56193
   392
  ultimately show ?case
hoelzl@56193
   393
    by (simp add: ac_simps)
hoelzl@56193
   394
qed simp
huffman@20692
   395
lp15@62379
   396
corollary sums_iff_shift': "(\<lambda>i. f (i + n)) sums (s - (\<Sum>i<n. f i)) \<longleftrightarrow> f sums s"
lp15@62379
   397
  by (simp add: sums_iff_shift)
lp15@62379
   398
lp15@62381
   399
lemma sums_zero_iff_shift:
lp15@62381
   400
  assumes "\<And>i. i < n \<Longrightarrow> f i = 0"
lp15@62381
   401
  shows "(\<lambda>i. f (i+n)) sums s \<longleftrightarrow> (\<lambda>i. f i) sums s"
lp15@62381
   402
by (simp add: assms sums_iff_shift)
lp15@62381
   403
hoelzl@56193
   404
lemma summable_iff_shift: "summable (\<lambda>n. f (n + k)) \<longleftrightarrow> summable f"
hoelzl@56193
   405
  by (metis diff_add_cancel summable_def sums_iff_shift[abs_def])
hoelzl@56193
   406
hoelzl@56193
   407
lemma sums_split_initial_segment: "f sums s \<Longrightarrow> (\<lambda>i. f (i + n)) sums (s - (\<Sum>i<n. f i))"
hoelzl@56193
   408
  by (simp add: sums_iff_shift)
hoelzl@56193
   409
hoelzl@56193
   410
lemma summable_ignore_initial_segment: "summable f \<Longrightarrow> summable (\<lambda>n. f(n + k))"
hoelzl@56193
   411
  by (simp add: summable_iff_shift)
hoelzl@56193
   412
hoelzl@56193
   413
lemma suminf_minus_initial_segment: "summable f \<Longrightarrow> (\<Sum>n. f (n + k)) = (\<Sum>n. f n) - (\<Sum>i<k. f i)"
hoelzl@56193
   414
  by (rule sums_unique[symmetric]) (auto simp: sums_iff_shift)
hoelzl@56193
   415
hoelzl@56193
   416
lemma suminf_split_initial_segment: "summable f \<Longrightarrow> suminf f = (\<Sum>n. f(n + k)) + (\<Sum>i<k. f i)"
hoelzl@56193
   417
  by (auto simp add: suminf_minus_initial_segment)
huffman@20692
   418
eberlm@61531
   419
lemma suminf_split_head: "summable f \<Longrightarrow> (\<Sum>n. f (Suc n)) = suminf f - f 0"
eberlm@61531
   420
  using suminf_split_initial_segment[of 1] by simp
eberlm@61531
   421
lp15@61609
   422
lemma suminf_exist_split:
hoelzl@56193
   423
  fixes r :: real assumes "0 < r" and "summable f"
hoelzl@56193
   424
  shows "\<exists>N. \<forall>n\<ge>N. norm (\<Sum>i. f (i + n)) < r"
hoelzl@56193
   425
proof -
wenzelm@60758
   426
  from LIMSEQ_D[OF summable_LIMSEQ[OF \<open>summable f\<close>] \<open>0 < r\<close>]
hoelzl@56193
   427
  obtain N :: nat where "\<forall> n \<ge> N. norm (setsum f {..<n} - suminf f) < r" by auto
hoelzl@56193
   428
  thus ?thesis
wenzelm@60758
   429
    by (auto simp: norm_minus_commute suminf_minus_initial_segment[OF \<open>summable f\<close>])
hoelzl@56193
   430
qed
hoelzl@56193
   431
wenzelm@61969
   432
lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f \<longlonglongrightarrow> 0"
hoelzl@56193
   433
  apply (drule summable_iff_convergent [THEN iffD1])
hoelzl@56193
   434
  apply (drule convergent_Cauchy)
hoelzl@56193
   435
  apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
hoelzl@56193
   436
  apply (drule_tac x="r" in spec, safe)
hoelzl@56193
   437
  apply (rule_tac x="M" in exI, safe)
hoelzl@56193
   438
  apply (drule_tac x="Suc n" in spec, simp)
hoelzl@56193
   439
  apply (drule_tac x="n" in spec, simp)
hoelzl@56193
   440
  done
hoelzl@56193
   441
hoelzl@62368
   442
lemma summable_imp_convergent: "summable f \<Longrightarrow> convergent f"
eberlm@61531
   443
  by (force dest!: summable_LIMSEQ_zero simp: convergent_def)
eberlm@61531
   444
hoelzl@62368
   445
lemma summable_imp_Bseq: "summable f \<Longrightarrow> Bseq f"
eberlm@61531
   446
  by (simp add: convergent_imp_Bseq summable_imp_convergent)
eberlm@61531
   447
hoelzl@56193
   448
end
hoelzl@56193
   449
lp15@59613
   450
lemma summable_minus_iff:
lp15@59613
   451
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
lp15@59613
   452
  shows "summable (\<lambda>n. - f n) \<longleftrightarrow> summable f"
wenzelm@61799
   453
  by (auto dest: summable_minus) \<comment>\<open>used two ways, hence must be outside the context above\<close>
lp15@59613
   454
hoelzl@56193
   455
lemma (in bounded_linear) sums: "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
hoelzl@56193
   456
  unfolding sums_def by (drule tendsto, simp only: setsum)
hoelzl@56193
   457
hoelzl@56193
   458
lemma (in bounded_linear) summable: "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
hoelzl@56193
   459
  unfolding summable_def by (auto intro: sums)
hoelzl@56193
   460
hoelzl@56193
   461
lemma (in bounded_linear) suminf: "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
hoelzl@56193
   462
  by (intro sums_unique sums summable_sums)
hoelzl@56193
   463
hoelzl@56193
   464
lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
hoelzl@56193
   465
lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
hoelzl@56193
   466
lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
hoelzl@56193
   467
hoelzl@57275
   468
lemmas sums_scaleR_left = bounded_linear.sums[OF bounded_linear_scaleR_left]
hoelzl@57275
   469
lemmas summable_scaleR_left = bounded_linear.summable[OF bounded_linear_scaleR_left]
hoelzl@57275
   470
lemmas suminf_scaleR_left = bounded_linear.suminf[OF bounded_linear_scaleR_left]
hoelzl@57275
   471
hoelzl@57275
   472
lemmas sums_scaleR_right = bounded_linear.sums[OF bounded_linear_scaleR_right]
hoelzl@57275
   473
lemmas summable_scaleR_right = bounded_linear.summable[OF bounded_linear_scaleR_right]
hoelzl@57275
   474
lemmas suminf_scaleR_right = bounded_linear.suminf[OF bounded_linear_scaleR_right]
hoelzl@57275
   475
eberlm@61531
   476
lemma summable_const_iff: "summable (\<lambda>_. c) \<longleftrightarrow> (c :: 'a :: real_normed_vector) = 0"
eberlm@61531
   477
proof -
eberlm@61531
   478
  {
eberlm@61531
   479
    assume "c \<noteq> 0"
eberlm@61531
   480
    hence "filterlim (\<lambda>n. of_nat n * norm c) at_top sequentially"
eberlm@61531
   481
      by (subst mult.commute)
eberlm@61531
   482
         (auto intro!: filterlim_tendsto_pos_mult_at_top filterlim_real_sequentially)
eberlm@61531
   483
    hence "\<not>convergent (\<lambda>n. norm (\<Sum>k<n. c))"
lp15@61609
   484
      by (intro filterlim_at_infinity_imp_not_convergent filterlim_at_top_imp_at_infinity)
eberlm@61531
   485
         (simp_all add: setsum_constant_scaleR)
eberlm@61531
   486
    hence "\<not>summable (\<lambda>_. c)" unfolding summable_iff_convergent using convergent_norm by blast
eberlm@61531
   487
  }
eberlm@61531
   488
  thus ?thesis by auto
eberlm@61531
   489
qed
eberlm@61531
   490
eberlm@61531
   491
wenzelm@60758
   492
subsection \<open>Infinite summability on real normed algebras\<close>
hoelzl@56213
   493
hoelzl@56193
   494
context
hoelzl@56193
   495
  fixes f :: "nat \<Rightarrow> 'a::real_normed_algebra"
hoelzl@56193
   496
begin
hoelzl@56193
   497
hoelzl@56193
   498
lemma sums_mult: "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
hoelzl@56193
   499
  by (rule bounded_linear.sums [OF bounded_linear_mult_right])
hoelzl@56193
   500
hoelzl@56193
   501
lemma summable_mult: "summable f \<Longrightarrow> summable (\<lambda>n. c * f n)"
hoelzl@56193
   502
  by (rule bounded_linear.summable [OF bounded_linear_mult_right])
hoelzl@56193
   503
hoelzl@56193
   504
lemma suminf_mult: "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
hoelzl@56193
   505
  by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
hoelzl@56193
   506
hoelzl@56193
   507
lemma sums_mult2: "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
hoelzl@56193
   508
  by (rule bounded_linear.sums [OF bounded_linear_mult_left])
hoelzl@56193
   509
hoelzl@56193
   510
lemma summable_mult2: "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
hoelzl@56193
   511
  by (rule bounded_linear.summable [OF bounded_linear_mult_left])
hoelzl@56193
   512
hoelzl@56193
   513
lemma suminf_mult2: "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
hoelzl@56193
   514
  by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
hoelzl@56193
   515
hoelzl@56193
   516
end
hoelzl@56193
   517
eberlm@61531
   518
lemma sums_mult_iff:
eberlm@61531
   519
  assumes "c \<noteq> 0"
eberlm@61531
   520
  shows   "(\<lambda>n. c * f n :: 'a :: {real_normed_algebra,field}) sums (c * d) \<longleftrightarrow> f sums d"
eberlm@61531
   521
  using sums_mult[of f d c] sums_mult[of "\<lambda>n. c * f n" "c * d" "inverse c"]
eberlm@61531
   522
  by (force simp: field_simps assms)
eberlm@61531
   523
eberlm@61531
   524
lemma sums_mult2_iff:
eberlm@61531
   525
  assumes "c \<noteq> (0 :: 'a :: {real_normed_algebra, field})"
eberlm@61531
   526
  shows   "(\<lambda>n. f n * c) sums (d * c) \<longleftrightarrow> f sums d"
eberlm@61531
   527
  using sums_mult_iff[OF assms, of f d] by (simp add: mult.commute)
eberlm@61531
   528
eberlm@61531
   529
lemma sums_of_real_iff:
eberlm@61531
   530
  "(\<lambda>n. of_real (f n) :: 'a :: real_normed_div_algebra) sums of_real c \<longleftrightarrow> f sums c"
eberlm@61531
   531
  by (simp add: sums_def of_real_setsum[symmetric] tendsto_of_real_iff del: of_real_setsum)
eberlm@61531
   532
eberlm@61531
   533
wenzelm@60758
   534
subsection \<open>Infinite summability on real normed fields\<close>
hoelzl@56213
   535
hoelzl@56193
   536
context
hoelzl@56193
   537
  fixes c :: "'a::real_normed_field"
hoelzl@56193
   538
begin
hoelzl@56193
   539
hoelzl@56193
   540
lemma sums_divide: "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
hoelzl@56193
   541
  by (rule bounded_linear.sums [OF bounded_linear_divide])
hoelzl@56193
   542
hoelzl@56193
   543
lemma summable_divide: "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
hoelzl@56193
   544
  by (rule bounded_linear.summable [OF bounded_linear_divide])
hoelzl@56193
   545
hoelzl@56193
   546
lemma suminf_divide: "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
hoelzl@56193
   547
  by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
paulson@14416
   548
lp15@62379
   549
lemma sums_mult_D: "\<lbrakk>(\<lambda>n. c * f n) sums a; c \<noteq> 0\<rbrakk> \<Longrightarrow> f sums (a/c)"
lp15@62379
   550
  using sums_mult_iff by fastforce
lp15@62379
   551
lp15@62379
   552
lemma summable_mult_D: "\<lbrakk>summable (\<lambda>n. c * f n); c \<noteq> 0\<rbrakk> \<Longrightarrow> summable f"
lp15@62379
   553
  by (auto dest: summable_divide)
lp15@62379
   554
wenzelm@60758
   555
text\<open>Sum of a geometric progression.\<close>
paulson@14416
   556
hoelzl@56193
   557
lemma geometric_sums: "norm c < 1 \<Longrightarrow> (\<lambda>n. c^n) sums (1 / (1 - c))"
huffman@20692
   558
proof -
hoelzl@56193
   559
  assume less_1: "norm c < 1"
hoelzl@56193
   560
  hence neq_1: "c \<noteq> 1" by auto
hoelzl@56193
   561
  hence neq_0: "c - 1 \<noteq> 0" by simp
wenzelm@61969
   562
  from less_1 have lim_0: "(\<lambda>n. c^n) \<longlonglongrightarrow> 0"
huffman@20692
   563
    by (rule LIMSEQ_power_zero)
wenzelm@61969
   564
  hence "(\<lambda>n. c ^ n / (c - 1) - 1 / (c - 1)) \<longlonglongrightarrow> 0 / (c - 1) - 1 / (c - 1)"
huffman@44568
   565
    using neq_0 by (intro tendsto_intros)
wenzelm@61969
   566
  hence "(\<lambda>n. (c ^ n - 1) / (c - 1)) \<longlonglongrightarrow> 1 / (1 - c)"
huffman@20692
   567
    by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
hoelzl@56193
   568
  thus "(\<lambda>n. c ^ n) sums (1 / (1 - c))"
huffman@20692
   569
    by (simp add: sums_def geometric_sum neq_1)
huffman@20692
   570
qed
huffman@20692
   571
hoelzl@56193
   572
lemma summable_geometric: "norm c < 1 \<Longrightarrow> summable (\<lambda>n. c^n)"
hoelzl@56193
   573
  by (rule geometric_sums [THEN sums_summable])
paulson@14416
   574
hoelzl@56193
   575
lemma suminf_geometric: "norm c < 1 \<Longrightarrow> suminf (\<lambda>n. c^n) = 1 / (1 - c)"
hoelzl@56193
   576
  by (rule sums_unique[symmetric]) (rule geometric_sums)
hoelzl@56193
   577
eberlm@61531
   578
lemma summable_geometric_iff: "summable (\<lambda>n. c ^ n) \<longleftrightarrow> norm c < 1"
eberlm@61531
   579
proof
eberlm@61531
   580
  assume "summable (\<lambda>n. c ^ n :: 'a :: real_normed_field)"
wenzelm@61969
   581
  hence "(\<lambda>n. norm c ^ n) \<longlonglongrightarrow> 0"
eberlm@61531
   582
    by (simp add: norm_power [symmetric] tendsto_norm_zero_iff summable_LIMSEQ_zero)
eberlm@61531
   583
  from order_tendstoD(2)[OF this zero_less_one] obtain n where "norm c ^ n < 1"
eberlm@61531
   584
    by (auto simp: eventually_at_top_linorder)
eberlm@61531
   585
  thus "norm c < 1" using one_le_power[of "norm c" n] by (cases "norm c \<ge> 1") (linarith, simp)
eberlm@61531
   586
qed (rule summable_geometric)
lp15@61609
   587
hoelzl@56193
   588
end
paulson@33271
   589
paulson@33271
   590
lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
paulson@33271
   591
proof -
paulson@33271
   592
  have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
paulson@33271
   593
    by auto
paulson@33271
   594
  have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
lp15@59741
   595
    by (simp add: mult.commute)
huffman@44282
   596
  thus ?thesis using sums_divide [OF 2, of 2]
paulson@33271
   597
    by simp
paulson@33271
   598
qed
paulson@33271
   599
eberlm@61531
   600
eberlm@61531
   601
subsection \<open>Telescoping\<close>
eberlm@61531
   602
eberlm@61531
   603
lemma telescope_sums:
wenzelm@61969
   604
  assumes "f \<longlonglongrightarrow> (c :: 'a :: real_normed_vector)"
eberlm@61531
   605
  shows   "(\<lambda>n. f (Suc n) - f n) sums (c - f 0)"
eberlm@61531
   606
  unfolding sums_def
eberlm@61531
   607
proof (subst LIMSEQ_Suc_iff [symmetric])
eberlm@61531
   608
  have "(\<lambda>n. \<Sum>k<Suc n. f (Suc k) - f k) = (\<lambda>n. f (Suc n) - f 0)"
eberlm@61531
   609
    by (simp add: lessThan_Suc_atMost atLeast0AtMost [symmetric] setsum_Suc_diff)
wenzelm@61969
   610
  also have "\<dots> \<longlonglongrightarrow> c - f 0" by (intro tendsto_diff LIMSEQ_Suc[OF assms] tendsto_const)
wenzelm@61969
   611
  finally show "(\<lambda>n. \<Sum>n<Suc n. f (Suc n) - f n) \<longlonglongrightarrow> c - f 0" .
eberlm@61531
   612
qed
eberlm@61531
   613
eberlm@61531
   614
lemma telescope_sums':
wenzelm@61969
   615
  assumes "f \<longlonglongrightarrow> (c :: 'a :: real_normed_vector)"
eberlm@61531
   616
  shows   "(\<lambda>n. f n - f (Suc n)) sums (f 0 - c)"
eberlm@61531
   617
  using sums_minus[OF telescope_sums[OF assms]] by (simp add: algebra_simps)
eberlm@61531
   618
eberlm@61531
   619
lemma telescope_summable:
wenzelm@61969
   620
  assumes "f \<longlonglongrightarrow> (c :: 'a :: real_normed_vector)"
eberlm@61531
   621
  shows   "summable (\<lambda>n. f (Suc n) - f n)"
eberlm@61531
   622
  using telescope_sums[OF assms] by (simp add: sums_iff)
eberlm@61531
   623
eberlm@61531
   624
lemma telescope_summable':
wenzelm@61969
   625
  assumes "f \<longlonglongrightarrow> (c :: 'a :: real_normed_vector)"
eberlm@61531
   626
  shows   "summable (\<lambda>n. f n - f (Suc n))"
eberlm@61531
   627
  using summable_minus[OF telescope_summable[OF assms]] by (simp add: algebra_simps)
eberlm@61531
   628
eberlm@61531
   629
wenzelm@60758
   630
subsection \<open>Infinite summability on Banach spaces\<close>
hoelzl@56213
   631
wenzelm@60758
   632
text\<open>Cauchy-type criterion for convergence of series (c.f. Harrison)\<close>
paulson@15085
   633
hoelzl@56193
   634
lemma summable_Cauchy:
hoelzl@56193
   635
  fixes f :: "nat \<Rightarrow> 'a::banach"
hoelzl@56193
   636
  shows "summable f \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. norm (setsum f {m..<n}) < e)"
hoelzl@56193
   637
  apply (simp only: summable_iff_convergent Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
hoelzl@56193
   638
  apply (drule spec, drule (1) mp)
hoelzl@56193
   639
  apply (erule exE, rule_tac x="M" in exI, clarify)
hoelzl@56193
   640
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   641
  apply (frule (1) order_trans)
hoelzl@56193
   642
  apply (drule_tac x="n" in spec, drule (1) mp)
hoelzl@56193
   643
  apply (drule_tac x="m" in spec, drule (1) mp)
hoelzl@56193
   644
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   645
  apply (drule spec, drule (1) mp)
hoelzl@56193
   646
  apply (erule exE, rule_tac x="N" in exI, clarify)
hoelzl@56193
   647
  apply (rule_tac x="m" and y="n" in linorder_le_cases)
hoelzl@56193
   648
  apply (subst norm_minus_commute)
hoelzl@56193
   649
  apply (simp_all add: setsum_diff [symmetric])
hoelzl@56193
   650
  done
paulson@14416
   651
hoelzl@56193
   652
context
hoelzl@56193
   653
  fixes f :: "nat \<Rightarrow> 'a::banach"
eberlm@61531
   654
begin
hoelzl@56193
   655
wenzelm@60758
   656
text\<open>Absolute convergence imples normal convergence\<close>
huffman@20689
   657
hoelzl@56194
   658
lemma summable_norm_cancel: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
hoelzl@56193
   659
  apply (simp only: summable_Cauchy, safe)
hoelzl@56193
   660
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   661
  apply (rule_tac x="N" in exI, safe)
hoelzl@56193
   662
  apply (drule_tac x="m" in spec, safe)
hoelzl@56193
   663
  apply (rule order_le_less_trans [OF norm_setsum])
hoelzl@56193
   664
  apply (rule order_le_less_trans [OF abs_ge_self])
hoelzl@56193
   665
  apply simp
hoelzl@50999
   666
  done
paulson@32707
   667
hoelzl@56193
   668
lemma summable_norm: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
hoelzl@56193
   669
  by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel summable_LIMSEQ norm_setsum)
hoelzl@56193
   670
wenzelm@60758
   671
text \<open>Comparison tests\<close>
paulson@14416
   672
hoelzl@56194
   673
lemma summable_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable f"
hoelzl@56193
   674
  apply (simp add: summable_Cauchy, safe)
hoelzl@56193
   675
  apply (drule_tac x="e" in spec, safe)
hoelzl@56193
   676
  apply (rule_tac x = "N + Na" in exI, safe)
hoelzl@56193
   677
  apply (rotate_tac 2)
hoelzl@56193
   678
  apply (drule_tac x = m in spec)
hoelzl@56193
   679
  apply (auto, rotate_tac 2, drule_tac x = n in spec)
hoelzl@56193
   680
  apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
hoelzl@56193
   681
  apply (rule norm_setsum)
hoelzl@56193
   682
  apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
hoelzl@56193
   683
  apply (auto intro: setsum_mono simp add: abs_less_iff)
hoelzl@56193
   684
  done
hoelzl@56193
   685
eberlm@61531
   686
lemma summable_comparison_test_ev:
eberlm@61531
   687
  shows "eventually (\<lambda>n. norm (f n) \<le> g n) sequentially \<Longrightarrow> summable g \<Longrightarrow> summable f"
eberlm@61531
   688
  by (rule summable_comparison_test) (auto simp: eventually_at_top_linorder)
eberlm@61531
   689
lp15@56217
   690
(*A better argument order*)
lp15@56217
   691
lemma summable_comparison_test': "summable g \<Longrightarrow> (\<And>n. n \<ge> N \<Longrightarrow> norm(f n) \<le> g n) \<Longrightarrow> summable f"
hoelzl@56369
   692
  by (rule summable_comparison_test) auto
lp15@56217
   693
wenzelm@60758
   694
subsection \<open>The Ratio Test\<close>
paulson@15085
   695
lp15@61609
   696
lemma summable_ratio_test:
hoelzl@56193
   697
  assumes "c < 1" "\<And>n. n \<ge> N \<Longrightarrow> norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   698
  shows "summable f"
hoelzl@56193
   699
proof cases
hoelzl@56193
   700
  assume "0 < c"
hoelzl@56193
   701
  show "summable f"
hoelzl@56193
   702
  proof (rule summable_comparison_test)
hoelzl@56193
   703
    show "\<exists>N'. \<forall>n\<ge>N'. norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   704
    proof (intro exI allI impI)
hoelzl@56193
   705
      fix n assume "N \<le> n" then show "norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
hoelzl@56193
   706
      proof (induct rule: inc_induct)
hoelzl@56193
   707
        case (step m)
hoelzl@56193
   708
        moreover have "norm (f (Suc m)) / c ^ Suc m * c ^ n \<le> norm (f m) / c ^ m * c ^ n"
wenzelm@60758
   709
          using \<open>0 < c\<close> \<open>c < 1\<close> assms(2)[OF \<open>N \<le> m\<close>] by (simp add: field_simps)
hoelzl@56193
   710
        ultimately show ?case by simp
wenzelm@60758
   711
      qed (insert \<open>0 < c\<close>, simp)
hoelzl@56193
   712
    qed
hoelzl@56193
   713
    show "summable (\<lambda>n. norm (f N) / c ^ N * c ^ n)"
wenzelm@60758
   714
      using \<open>0 < c\<close> \<open>c < 1\<close> by (intro summable_mult summable_geometric) simp
hoelzl@56193
   715
  qed
hoelzl@56193
   716
next
hoelzl@56193
   717
  assume c: "\<not> 0 < c"
hoelzl@56193
   718
  { fix n assume "n \<ge> N"
hoelzl@56193
   719
    then have "norm (f (Suc n)) \<le> c * norm (f n)"
hoelzl@56193
   720
      by fact
hoelzl@56193
   721
    also have "\<dots> \<le> 0"
hoelzl@56193
   722
      using c by (simp add: not_less mult_nonpos_nonneg)
hoelzl@56193
   723
    finally have "f (Suc n) = 0"
hoelzl@56193
   724
      by auto }
hoelzl@56193
   725
  then show "summable f"
hoelzl@56194
   726
    by (intro sums_summable[OF sums_finite, of "{.. Suc N}"]) (auto simp: not_le Suc_less_eq2)
lp15@56178
   727
qed
lp15@56178
   728
hoelzl@56193
   729
end
paulson@14416
   730
wenzelm@60758
   731
text\<open>Relations among convergence and absolute convergence for power series.\<close>
hoelzl@56369
   732
paulson@62087
   733
lemma Abel_lemma:
hoelzl@56369
   734
  fixes a :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@56369
   735
  assumes r: "0 \<le> r" and r0: "r < r0" and M: "\<And>n. norm (a n) * r0^n \<le> M"
hoelzl@56369
   736
    shows "summable (\<lambda>n. norm (a n) * r^n)"
hoelzl@56369
   737
proof (rule summable_comparison_test')
hoelzl@56369
   738
  show "summable (\<lambda>n. M * (r / r0) ^ n)"
lp15@61609
   739
    using assms
hoelzl@56369
   740
    by (auto simp add: summable_mult summable_geometric)
hoelzl@56369
   741
next
hoelzl@56369
   742
  fix n
hoelzl@56369
   743
  show "norm (norm (a n) * r ^ n) \<le> M * (r / r0) ^ n"
hoelzl@56369
   744
    using r r0 M [of n]
haftmann@60867
   745
    apply (auto simp add: abs_mult field_simps)
hoelzl@56369
   746
    apply (cases "r=0", simp)
hoelzl@56369
   747
    apply (cases n, auto)
hoelzl@56369
   748
    done
hoelzl@56369
   749
qed
hoelzl@56369
   750
hoelzl@56369
   751
wenzelm@60758
   752
text\<open>Summability of geometric series for real algebras\<close>
huffman@23084
   753
huffman@23084
   754
lemma complete_algebra_summable_geometric:
haftmann@31017
   755
  fixes x :: "'a::{real_normed_algebra_1,banach}"
huffman@23084
   756
  shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
huffman@23084
   757
proof (rule summable_comparison_test)
huffman@23084
   758
  show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
huffman@23084
   759
    by (simp add: norm_power_ineq)
huffman@23084
   760
  show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
huffman@23084
   761
    by (simp add: summable_geometric)
huffman@23084
   762
qed
huffman@23084
   763
wenzelm@60758
   764
subsection \<open>Cauchy Product Formula\<close>
huffman@23111
   765
wenzelm@60758
   766
text \<open>
wenzelm@54703
   767
  Proof based on Analysis WebNotes: Chapter 07, Class 41
wenzelm@54703
   768
  @{url "http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm"}
wenzelm@60758
   769
\<close>
huffman@23111
   770
huffman@23111
   771
lemma Cauchy_product_sums:
huffman@23111
   772
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   773
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   774
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   775
  shows "(\<lambda>k. \<Sum>i\<le>k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
huffman@23111
   776
proof -
hoelzl@56193
   777
  let ?S1 = "\<lambda>n::nat. {..<n} \<times> {..<n}"
huffman@23111
   778
  let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
huffman@23111
   779
  have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
huffman@23111
   780
  have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
huffman@23111
   781
  have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
huffman@23111
   782
  have finite_S1: "\<And>n. finite (?S1 n)" by simp
huffman@23111
   783
  with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
huffman@23111
   784
huffman@23111
   785
  let ?g = "\<lambda>(i,j). a i * b j"
huffman@23111
   786
  let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
nipkow@56536
   787
  have f_nonneg: "\<And>x. 0 \<le> ?f x" by (auto)
huffman@23111
   788
  hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
huffman@23111
   789
    unfolding real_norm_def
huffman@23111
   790
    by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
huffman@23111
   791
wenzelm@61969
   792
  have "(\<lambda>n. (\<Sum>k<n. a k) * (\<Sum>k<n. b k)) \<longlonglongrightarrow> (\<Sum>k. a k) * (\<Sum>k. b k)"
hoelzl@56193
   793
    by (intro tendsto_mult summable_LIMSEQ summable_norm_cancel [OF a] summable_norm_cancel [OF b])
wenzelm@61969
   794
  hence 1: "(\<lambda>n. setsum ?g (?S1 n)) \<longlonglongrightarrow> (\<Sum>k. a k) * (\<Sum>k. b k)"
haftmann@57418
   795
    by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
huffman@23111
   796
wenzelm@61969
   797
  have "(\<lambda>n. (\<Sum>k<n. norm (a k)) * (\<Sum>k<n. norm (b k))) \<longlonglongrightarrow> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
hoelzl@56193
   798
    using a b by (intro tendsto_mult summable_LIMSEQ)
wenzelm@61969
   799
  hence "(\<lambda>n. setsum ?f (?S1 n)) \<longlonglongrightarrow> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
haftmann@57418
   800
    by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
huffman@23111
   801
  hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   802
    by (rule convergentI)
huffman@23111
   803
  hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
huffman@23111
   804
    by (rule convergent_Cauchy)
huffman@36657
   805
  have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
huffman@36657
   806
  proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
huffman@23111
   807
    fix r :: real
huffman@23111
   808
    assume r: "0 < r"
huffman@23111
   809
    from CauchyD [OF Cauchy r] obtain N
huffman@23111
   810
    where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
huffman@23111
   811
    hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
huffman@23111
   812
      by (simp only: setsum_diff finite_S1 S1_mono)
huffman@23111
   813
    hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
huffman@23111
   814
      by (simp only: norm_setsum_f)
huffman@23111
   815
    show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
huffman@23111
   816
    proof (intro exI allI impI)
huffman@23111
   817
      fix n assume "2 * N \<le> n"
huffman@23111
   818
      hence n: "N \<le> n div 2" by simp
huffman@23111
   819
      have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
huffman@23111
   820
        by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
huffman@23111
   821
                  Diff_mono subset_refl S1_le_S2)
huffman@23111
   822
      also have "\<dots> < r"
huffman@23111
   823
        using n div_le_dividend by (rule N)
huffman@23111
   824
      finally show "setsum ?f (?S1 n - ?S2 n) < r" .
huffman@23111
   825
    qed
huffman@23111
   826
  qed
huffman@36657
   827
  hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
huffman@36657
   828
    apply (rule Zfun_le [rule_format])
huffman@23111
   829
    apply (simp only: norm_setsum_f)
huffman@23111
   830
    apply (rule order_trans [OF norm_setsum setsum_mono])
huffman@23111
   831
    apply (auto simp add: norm_mult_ineq)
huffman@23111
   832
    done
wenzelm@61969
   833
  hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) \<longlonglongrightarrow> 0"
huffman@36660
   834
    unfolding tendsto_Zfun_iff diff_0_right
huffman@36657
   835
    by (simp only: setsum_diff finite_S1 S2_le_S1)
huffman@23111
   836
wenzelm@61969
   837
  with 1 have "(\<lambda>n. setsum ?g (?S2 n)) \<longlonglongrightarrow> (\<Sum>k. a k) * (\<Sum>k. b k)"
lp15@60141
   838
    by (rule Lim_transform2)
huffman@23111
   839
  thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
huffman@23111
   840
qed
huffman@23111
   841
huffman@23111
   842
lemma Cauchy_product:
huffman@23111
   843
  fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
huffman@23111
   844
  assumes a: "summable (\<lambda>k. norm (a k))"
huffman@23111
   845
  assumes b: "summable (\<lambda>k. norm (b k))"
hoelzl@56213
   846
  shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i\<le>k. a i * b (k - i))"
hoelzl@56213
   847
  using a b
hoelzl@56213
   848
  by (rule Cauchy_product_sums [THEN sums_unique])
hoelzl@56213
   849
eberlm@62049
   850
lemma summable_Cauchy_product:
paulson@62087
   851
  assumes "summable (\<lambda>k. norm (a k :: 'a :: {real_normed_algebra,banach}))"
eberlm@62049
   852
          "summable (\<lambda>k. norm (b k))"
eberlm@62049
   853
  shows   "summable (\<lambda>k. \<Sum>i\<le>k. a i * b (k - i))"
paulson@62087
   854
  using Cauchy_product_sums[OF assms] by (simp add: sums_iff)
eberlm@62049
   855
wenzelm@60758
   856
subsection \<open>Series on @{typ real}s\<close>
hoelzl@56213
   857
hoelzl@56213
   858
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
   859
  by (rule summable_comparison_test) auto
hoelzl@56213
   860
hoelzl@56213
   861
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
   862
  by (rule summable_comparison_test) auto
hoelzl@56213
   863
hoelzl@56213
   864
lemma summable_rabs_cancel: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> summable f"
hoelzl@56213
   865
  by (rule summable_norm_cancel) simp
hoelzl@56213
   866
hoelzl@56213
   867
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
   868
  by (fold real_norm_def) (rule summable_norm)
huffman@23111
   869
eberlm@61531
   870
lemma summable_zero_power [simp]: "summable (\<lambda>n. 0 ^ n :: 'a :: {comm_ring_1,topological_space})"
eberlm@61531
   871
proof -
eberlm@61531
   872
  have "(\<lambda>n. 0 ^ n :: 'a) = (\<lambda>n. if n = 0 then 0^0 else 0)" by (intro ext) (simp add: zero_power)
eberlm@61531
   873
  moreover have "summable \<dots>" by simp
eberlm@61531
   874
  ultimately show ?thesis by simp
eberlm@61531
   875
qed
eberlm@61531
   876
eberlm@61531
   877
lemma summable_zero_power' [simp]: "summable (\<lambda>n. f n * 0 ^ n :: 'a :: {ring_1,topological_space})"
eberlm@61531
   878
proof -
lp15@61609
   879
  have "(\<lambda>n. f n * 0 ^ n :: 'a) = (\<lambda>n. if n = 0 then f 0 * 0^0 else 0)"
eberlm@61531
   880
    by (intro ext) (simp add: zero_power)
eberlm@61531
   881
  moreover have "summable \<dots>" by simp
eberlm@61531
   882
  ultimately show ?thesis by simp
eberlm@61531
   883
qed
eberlm@61531
   884
hoelzl@59000
   885
lemma summable_power_series:
hoelzl@59000
   886
  fixes z :: real
hoelzl@59000
   887
  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
   888
  shows "summable (\<lambda>i. f i * z^i)"
hoelzl@59000
   889
proof (rule summable_comparison_test[OF _ summable_geometric])
hoelzl@59000
   890
  show "norm z < 1" using z by (auto simp: less_imp_le)
hoelzl@59000
   891
  show "\<And>n. \<exists>N. \<forall>na\<ge>N. norm (f na * z ^ na) \<le> z ^ na"
hoelzl@59000
   892
    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
   893
qed
hoelzl@59000
   894
eberlm@61531
   895
lemma summable_0_powser:
eberlm@61531
   896
  "summable (\<lambda>n. f n * 0 ^ n :: 'a :: real_normed_div_algebra)"
eberlm@61531
   897
proof -
eberlm@61531
   898
  have A: "(\<lambda>n. f n * 0 ^ n) = (\<lambda>n. if n = 0 then f n else 0)"
eberlm@61531
   899
    by (intro ext) auto
eberlm@61531
   900
  thus ?thesis by (subst A) simp_all
eberlm@61531
   901
qed
eberlm@61531
   902
eberlm@61531
   903
lemma summable_powser_split_head:
eberlm@61531
   904
  "summable (\<lambda>n. f (Suc n) * z ^ n :: 'a :: real_normed_div_algebra) = summable (\<lambda>n. f n * z ^ n)"
eberlm@61531
   905
proof -
eberlm@61531
   906
  have "summable (\<lambda>n. f (Suc n) * z ^ n) \<longleftrightarrow> summable (\<lambda>n. f (Suc n) * z ^ Suc n)"
eberlm@61531
   907
  proof
eberlm@61531
   908
    assume "summable (\<lambda>n. f (Suc n) * z ^ n)"
lp15@61609
   909
    from summable_mult2[OF this, of z] show "summable (\<lambda>n. f (Suc n) * z ^ Suc n)"
eberlm@61531
   910
      by (simp add: power_commutes algebra_simps)
eberlm@61531
   911
  next
eberlm@61531
   912
    assume "summable (\<lambda>n. f (Suc n) * z ^ Suc n)"
eberlm@61531
   913
    from summable_mult2[OF this, of "inverse z"] show "summable (\<lambda>n. f (Suc n) * z ^ n)"
eberlm@61531
   914
      by (cases "z \<noteq> 0", subst (asm) power_Suc2) (simp_all add: algebra_simps)
eberlm@61531
   915
  qed
eberlm@61531
   916
  also have "\<dots> \<longleftrightarrow> summable (\<lambda>n. f n * z ^ n)" by (rule summable_Suc_iff)
eberlm@61531
   917
  finally show ?thesis .
eberlm@61531
   918
qed
eberlm@61531
   919
eberlm@61531
   920
lemma powser_split_head:
eberlm@61531
   921
  assumes "summable (\<lambda>n. f n * z ^ n :: 'a :: {real_normed_div_algebra,banach})"
eberlm@61531
   922
  shows   "suminf (\<lambda>n. f n * z ^ n) = f 0 + suminf (\<lambda>n. f (Suc n) * z ^ n) * z"
eberlm@61531
   923
          "suminf (\<lambda>n. f (Suc n) * z ^ n) * z = suminf (\<lambda>n. f n * z ^ n) - f 0"
eberlm@61531
   924
          "summable (\<lambda>n. f (Suc n) * z ^ n)"
eberlm@61531
   925
proof -
eberlm@61531
   926
  from assms show "summable (\<lambda>n. f (Suc n) * z ^ n)" by (subst summable_powser_split_head)
eberlm@61531
   927
lp15@61609
   928
  from suminf_mult2[OF this, of z]
eberlm@61531
   929
    have "(\<Sum>n. f (Suc n) * z ^ n) * z = (\<Sum>n. f (Suc n) * z ^ Suc n)"
eberlm@61531
   930
    by (simp add: power_commutes algebra_simps)
eberlm@61531
   931
  also from assms have "\<dots> = suminf (\<lambda>n. f n * z ^ n) - f 0"
eberlm@61531
   932
    by (subst suminf_split_head) simp_all
eberlm@61531
   933
  finally show "suminf (\<lambda>n. f n * z ^ n) = f 0 + suminf (\<lambda>n. f (Suc n) * z ^ n) * z" by simp
eberlm@61531
   934
  thus "suminf (\<lambda>n. f (Suc n) * z ^ n) * z = suminf (\<lambda>n. f n * z ^ n) - f 0" by simp
eberlm@61531
   935
qed
eberlm@61531
   936
eberlm@61531
   937
lemma summable_partial_sum_bound:
eberlm@61531
   938
  fixes f :: "nat \<Rightarrow> 'a :: banach"
eberlm@61531
   939
  assumes summable: "summable f" and e: "e > (0::real)"
eberlm@61531
   940
  obtains N where "\<And>m n. m \<ge> N \<Longrightarrow> norm (\<Sum>k=m..n. f k) < e"
eberlm@61531
   941
proof -
lp15@61609
   942
  from summable have "Cauchy (\<lambda>n. \<Sum>k<n. f k)"
eberlm@61531
   943
    by (simp add: Cauchy_convergent_iff summable_iff_convergent)
lp15@61609
   944
  from CauchyD[OF this e] obtain N
eberlm@61531
   945
    where N: "\<And>m n. m \<ge> N \<Longrightarrow> n \<ge> N \<Longrightarrow> norm ((\<Sum>k<m. f k) - (\<Sum>k<n. f k)) < e" by blast
eberlm@61531
   946
  {
eberlm@61531
   947
    fix m n :: nat assume m: "m \<ge> N"
eberlm@61531
   948
    have "norm (\<Sum>k=m..n. f k) < e"
eberlm@61531
   949
    proof (cases "n \<ge> m")
eberlm@61531
   950
      assume n: "n \<ge> m"
eberlm@61531
   951
      with m have "norm ((\<Sum>k<Suc n. f k) - (\<Sum>k<m. f k)) < e" by (intro N) simp_all
eberlm@61531
   952
      also from n have "(\<Sum>k<Suc n. f k) - (\<Sum>k<m. f k) = (\<Sum>k=m..n. f k)"
eberlm@61531
   953
        by (subst setsum_diff [symmetric]) (simp_all add: setsum_last_plus)
eberlm@61531
   954
      finally show ?thesis .
eberlm@61531
   955
    qed (insert e, simp_all)
eberlm@61531
   956
  }
eberlm@61531
   957
  thus ?thesis by (rule that)
eberlm@61531
   958
qed
eberlm@61531
   959
lp15@61609
   960
lemma powser_sums_if:
eberlm@61531
   961
  "(\<lambda>n. (if n = m then (1 :: 'a :: {ring_1,topological_space}) else 0) * z^n) sums z^m"
eberlm@61531
   962
proof -
lp15@61609
   963
  have "(\<lambda>n. (if n = m then 1 else 0) * z^n) = (\<lambda>n. if n = m then z^n else 0)"
eberlm@61531
   964
    by (intro ext) auto
eberlm@61531
   965
  thus ?thesis by (simp add: sums_single)
eberlm@61531
   966
qed
eberlm@61531
   967
Andreas@59025
   968
lemma
Andreas@59025
   969
   fixes f :: "nat \<Rightarrow> real"
Andreas@59025
   970
   assumes "summable f"
Andreas@59025
   971
   and "inj g"
hoelzl@62368
   972
   and pos: "\<And>x. 0 \<le> f x"
Andreas@59025
   973
   shows summable_reindex: "summable (f o g)"
Andreas@59025
   974
   and suminf_reindex_mono: "suminf (f o g) \<le> suminf f"
Andreas@59025
   975
   and suminf_reindex: "(\<And>x. x \<notin> range g \<Longrightarrow> f x = 0) \<Longrightarrow> suminf (f \<circ> g) = suminf f"
Andreas@59025
   976
proof -
Andreas@59025
   977
  from \<open>inj g\<close> have [simp]: "\<And>A. inj_on g A" by(rule subset_inj_on) simp
Andreas@59025
   978
Andreas@59025
   979
  have smaller: "\<forall>n. (\<Sum>i<n. (f \<circ> g) i) \<le> suminf f"
Andreas@59025
   980
  proof
Andreas@59025
   981
    fix n
lp15@61609
   982
    have "\<forall> n' \<in> (g ` {..<n}). n' < Suc (Max (g ` {..<n}))"
Andreas@59025
   983
      by(metis Max_ge finite_imageI finite_lessThan not_le not_less_eq)
Andreas@59025
   984
    then obtain m where n: "\<And>n'. n' < n \<Longrightarrow> g n' < m" by blast
Andreas@59025
   985
Andreas@59025
   986
    have "(\<Sum>i<n. f (g i)) = setsum f (g ` {..<n})"
Andreas@59025
   987
      by (simp add: setsum.reindex)
Andreas@59025
   988
    also have "\<dots> \<le> (\<Sum>i<m. f i)"
Andreas@59025
   989
      by (rule setsum_mono3) (auto simp add: pos n[rule_format])
Andreas@59025
   990
    also have "\<dots> \<le> suminf f"
lp15@61609
   991
      using \<open>summable f\<close>
Andreas@59025
   992
      by (rule setsum_le_suminf) (simp add: pos)
Andreas@59025
   993
    finally show "(\<Sum>i<n. (f \<circ>  g) i) \<le> suminf f" by simp
Andreas@59025
   994
  qed
Andreas@59025
   995
Andreas@59025
   996
  have "incseq (\<lambda>n. \<Sum>i<n. (f \<circ> g) i)"
Andreas@59025
   997
    by (rule incseq_SucI) (auto simp add: pos)
wenzelm@61969
   998
  then obtain  L where L: "(\<lambda> n. \<Sum>i<n. (f \<circ> g) i) \<longlonglongrightarrow> L"
Andreas@59025
   999
    using smaller by(rule incseq_convergent)
Andreas@59025
  1000
  hence "(f \<circ> g) sums L" by (simp add: sums_def)
Andreas@59025
  1001
  thus "summable (f o g)" by (auto simp add: sums_iff)
Andreas@59025
  1002
wenzelm@61969
  1003
  hence "(\<lambda>n. \<Sum>i<n. (f \<circ> g) i) \<longlonglongrightarrow> suminf (f \<circ> g)"
Andreas@59025
  1004
    by(rule summable_LIMSEQ)
Andreas@59025
  1005
  thus le: "suminf (f \<circ> g) \<le> suminf f"
Andreas@59025
  1006
    by(rule LIMSEQ_le_const2)(blast intro: smaller[rule_format])
Andreas@59025
  1007
Andreas@59025
  1008
  assume f: "\<And>x. x \<notin> range g \<Longrightarrow> f x = 0"
Andreas@59025
  1009
Andreas@59025
  1010
  from \<open>summable f\<close> have "suminf f \<le> suminf (f \<circ> g)"
Andreas@59025
  1011
  proof(rule suminf_le_const)
Andreas@59025
  1012
    fix n
Andreas@59025
  1013
    have "\<forall> n' \<in> (g -` {..<n}). n' < Suc (Max (g -` {..<n}))"
Andreas@59025
  1014
      by(auto intro: Max_ge simp add: finite_vimageI less_Suc_eq_le)
Andreas@59025
  1015
    then obtain m where n: "\<And>n'. g n' < n \<Longrightarrow> n' < m" by blast
Andreas@59025
  1016
Andreas@59025
  1017
    have "(\<Sum>i<n. f i) = (\<Sum>i\<in>{..<n} \<inter> range g. f i)"
Andreas@59025
  1018
      using f by(auto intro: setsum.mono_neutral_cong_right)
Andreas@59025
  1019
    also have "\<dots> = (\<Sum>i\<in>g -` {..<n}. (f \<circ> g) i)"
Andreas@59025
  1020
      by(rule setsum.reindex_cong[where l=g])(auto)
Andreas@59025
  1021
    also have "\<dots> \<le> (\<Sum>i<m. (f \<circ> g) i)"
Andreas@59025
  1022
      by(rule setsum_mono3)(auto simp add: pos n)
Andreas@59025
  1023
    also have "\<dots> \<le> suminf (f \<circ> g)"
Andreas@59025
  1024
      using \<open>summable (f o g)\<close>
Andreas@59025
  1025
      by(rule setsum_le_suminf)(simp add: pos)
Andreas@59025
  1026
    finally show "setsum f {..<n} \<le> suminf (f \<circ> g)" .
Andreas@59025
  1027
  qed
Andreas@59025
  1028
  with le show "suminf (f \<circ> g) = suminf f" by(rule antisym)
Andreas@59025
  1029
qed
Andreas@59025
  1030
eberlm@61531
  1031
lemma sums_mono_reindex:
eberlm@61531
  1032
  assumes subseq: "subseq g" and zero: "\<And>n. n \<notin> range g \<Longrightarrow> f n = 0"
eberlm@61531
  1033
  shows   "(\<lambda>n. f (g n)) sums c \<longleftrightarrow> f sums c"
eberlm@61531
  1034
unfolding sums_def
eberlm@61531
  1035
proof
wenzelm@61969
  1036
  assume lim: "(\<lambda>n. \<Sum>k<n. f k) \<longlonglongrightarrow> c"
eberlm@61531
  1037
  have "(\<lambda>n. \<Sum>k<n. f (g k)) = (\<lambda>n. \<Sum>k<g n. f k)"
eberlm@61531
  1038
  proof
eberlm@61531
  1039
    fix n :: nat
eberlm@61531
  1040
    from subseq have "(\<Sum>k<n. f (g k)) = (\<Sum>k\<in>g`{..<n}. f k)"
eberlm@61531
  1041
      by (subst setsum.reindex) (auto intro: subseq_imp_inj_on)
eberlm@61531
  1042
    also from subseq have "\<dots> = (\<Sum>k<g n. f k)"
eberlm@61531
  1043
      by (intro setsum.mono_neutral_left ballI zero)
eberlm@61531
  1044
         (auto dest: subseq_strict_mono simp: strict_mono_less strict_mono_less_eq)
eberlm@61531
  1045
    finally show "(\<Sum>k<n. f (g k)) = (\<Sum>k<g n. f k)" .
eberlm@61531
  1046
  qed
wenzelm@61969
  1047
  also from LIMSEQ_subseq_LIMSEQ[OF lim subseq] have "\<dots> \<longlonglongrightarrow> c" unfolding o_def .
wenzelm@61969
  1048
  finally show "(\<lambda>n. \<Sum>k<n. f (g k)) \<longlonglongrightarrow> c" .
eberlm@61531
  1049
next
wenzelm@61969
  1050
  assume lim: "(\<lambda>n. \<Sum>k<n. f (g k)) \<longlonglongrightarrow> c"
wenzelm@63040
  1051
  define g_inv where "g_inv n = (LEAST m. g m \<ge> n)" for n
eberlm@61531
  1052
  from filterlim_subseq[OF subseq] have g_inv_ex: "\<exists>m. g m \<ge> n" for n
eberlm@61531
  1053
    by (auto simp: filterlim_at_top eventually_at_top_linorder)
eberlm@61531
  1054
  hence g_inv: "g (g_inv n) \<ge> n" for n unfolding g_inv_def by (rule LeastI_ex)
lp15@61609
  1055
  have g_inv_least: "m \<ge> g_inv n" if "g m \<ge> n" for m n using that
eberlm@61531
  1056
    unfolding g_inv_def by (rule Least_le)
lp15@61609
  1057
  have g_inv_least': "g m < n" if "m < g_inv n" for m n using that g_inv_least[of n m] by linarith
eberlm@61531
  1058
  have "(\<lambda>n. \<Sum>k<n. f k) = (\<lambda>n. \<Sum>k<g_inv n. f (g k))"
eberlm@61531
  1059
  proof
eberlm@61531
  1060
    fix n :: nat
eberlm@61531
  1061
    {
eberlm@61531
  1062
      fix k assume k: "k \<in> {..<n} - g`{..<g_inv n}"
eberlm@61531
  1063
      have "k \<notin> range g"
eberlm@61531
  1064
      proof (rule notI, elim imageE)
eberlm@61531
  1065
        fix l assume l: "k = g l"
eberlm@61531
  1066
        have "g l < g (g_inv n)" by (rule less_le_trans[OF _ g_inv]) (insert k l, simp_all)
eberlm@61531
  1067
        with subseq have "l < g_inv n" by (simp add: subseq_strict_mono strict_mono_less)
eberlm@61531
  1068
        with k l show False by simp
eberlm@61531
  1069
      qed
eberlm@61531
  1070
      hence "f k = 0" by (rule zero)
eberlm@61531
  1071
    }
eberlm@61531
  1072
    with g_inv_least' g_inv have "(\<Sum>k<n. f k) = (\<Sum>k\<in>g`{..<g_inv n}. f k)"
eberlm@61531
  1073
      by (intro setsum.mono_neutral_right) auto
lp15@61609
  1074
    also from subseq have "\<dots> = (\<Sum>k<g_inv n. f (g k))" using subseq_imp_inj_on
eberlm@61531
  1075
      by (subst setsum.reindex) simp_all
eberlm@61531
  1076
    finally show "(\<Sum>k<n. f k) = (\<Sum>k<g_inv n. f (g k))" .
eberlm@61531
  1077
  qed
eberlm@61531
  1078
  also {
eberlm@61531
  1079
    fix K n :: nat assume "g K \<le> n"
eberlm@61531
  1080
    also have "n \<le> g (g_inv n)" by (rule g_inv)
eberlm@61531
  1081
    finally have "K \<le> g_inv n" using subseq by (simp add: strict_mono_less_eq subseq_strict_mono)
eberlm@61531
  1082
  }
lp15@61609
  1083
  hence "filterlim g_inv at_top sequentially"
eberlm@61531
  1084
    by (auto simp: filterlim_at_top eventually_at_top_linorder)
wenzelm@61969
  1085
  from lim and this have "(\<lambda>n. \<Sum>k<g_inv n. f (g k)) \<longlonglongrightarrow> c" by (rule filterlim_compose)
wenzelm@61969
  1086
  finally show "(\<lambda>n. \<Sum>k<n. f k) \<longlonglongrightarrow> c" .
eberlm@61531
  1087
qed
eberlm@61531
  1088
eberlm@61531
  1089
lemma summable_mono_reindex:
eberlm@61531
  1090
  assumes subseq: "subseq g" and zero: "\<And>n. n \<notin> range g \<Longrightarrow> f n = 0"
eberlm@61531
  1091
  shows   "summable (\<lambda>n. f (g n)) \<longleftrightarrow> summable f"
eberlm@61531
  1092
  using sums_mono_reindex[of g f, OF assms] by (simp add: summable_def)
eberlm@61531
  1093
lp15@61609
  1094
lemma suminf_mono_reindex:
eberlm@61531
  1095
  assumes "subseq g" "\<And>n. n \<notin> range g \<Longrightarrow> f n = (0 :: 'a :: {t2_space,comm_monoid_add})"
eberlm@61531
  1096
  shows   "suminf (\<lambda>n. f (g n)) = suminf f"
eberlm@61531
  1097
proof (cases "summable f")
eberlm@61531
  1098
  case False
eberlm@61531
  1099
  hence "\<not>(\<exists>c. f sums c)" unfolding summable_def by blast
eberlm@61531
  1100
  hence "suminf f = The (\<lambda>_. False)" by (simp add: suminf_def)
eberlm@61531
  1101
  moreover from False have "\<not>summable (\<lambda>n. f (g n))"
eberlm@61531
  1102
    using summable_mono_reindex[of g f, OF assms] by simp
eberlm@61531
  1103
  hence "\<not>(\<exists>c. (\<lambda>n. f (g n)) sums c)" unfolding summable_def by blast
eberlm@61531
  1104
  hence "suminf (\<lambda>n. f (g n)) = The (\<lambda>_. False)" by (simp add: suminf_def)
eberlm@61531
  1105
  ultimately show ?thesis by simp
lp15@61609
  1106
qed (insert sums_mono_reindex[of g f, OF assms] summable_mono_reindex[of g f, OF assms],
eberlm@61531
  1107
     simp_all add: sums_iff)
eberlm@61531
  1108
paulson@14416
  1109
end