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