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