src/HOL/Series.thy
author blanchet
Thu Sep 11 18:54:36 2014 +0200 (2014-09-11)
changeset 58306 117ba6cbe414
parent 57418 6ab1c7cb0b8d
child 58729 e8ecc79aee43
permissions -rw-r--r--
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
     1 (*  Title       : Series.thy
     2     Author      : Jacques D. Fleuriot
     3     Copyright   : 1998  University of Cambridge
     4 
     5 Converted to Isar and polished by lcp
     6 Converted to setsum and polished yet more by TNN
     7 Additional contributions by Jeremy Avigad
     8 *)
     9 
    10 header {* Infinite Series *}
    11 
    12 theory Series
    13 imports Limits
    14 begin
    15 
    16 subsection {* Definition of infinite summability *}
    17 
    18 definition
    19   sums :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a \<Rightarrow> bool"
    20   (infixr "sums" 80)
    21 where
    22   "f sums s \<longleftrightarrow> (\<lambda>n. \<Sum>i<n. f i) ----> s"
    23 
    24 definition summable :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> bool" where
    25    "summable f \<longleftrightarrow> (\<exists>s. f sums s)"
    26 
    27 definition
    28   suminf :: "(nat \<Rightarrow> 'a::{topological_space, comm_monoid_add}) \<Rightarrow> 'a"
    29   (binder "\<Sum>" 10)
    30 where
    31   "suminf f = (THE s. f sums s)"
    32 
    33 subsection {* Infinite summability on topological monoids *}
    34 
    35 lemma sums_subst[trans]: "f = g \<Longrightarrow> g sums z \<Longrightarrow> f sums z"
    36   by simp
    37 
    38 lemma sums_summable: "f sums l \<Longrightarrow> summable f"
    39   by (simp add: sums_def summable_def, blast)
    40 
    41 lemma summable_iff_convergent: "summable f \<longleftrightarrow> convergent (\<lambda>n. \<Sum>i<n. f i)"
    42   by (simp add: summable_def sums_def convergent_def)
    43 
    44 lemma suminf_eq_lim: "suminf f = lim (\<lambda>n. \<Sum>i<n. f i)"
    45   by (simp add: suminf_def sums_def lim_def)
    46 
    47 lemma sums_zero[simp, intro]: "(\<lambda>n. 0) sums 0"
    48   unfolding sums_def by (simp add: tendsto_const)
    49 
    50 lemma summable_zero[simp, intro]: "summable (\<lambda>n. 0)"
    51   by (rule sums_zero [THEN sums_summable])
    52 
    53 lemma sums_group: "f sums s \<Longrightarrow> 0 < k \<Longrightarrow> (\<lambda>n. setsum f {n * k ..< n * k + k}) sums s"
    54   apply (simp only: sums_def setsum_nat_group tendsto_def eventually_sequentially)
    55   apply safe
    56   apply (erule_tac x=S in allE)
    57   apply safe
    58   apply (rule_tac x="N" in exI, safe)
    59   apply (drule_tac x="n*k" in spec)
    60   apply (erule mp)
    61   apply (erule order_trans)
    62   apply simp
    63   done
    64 
    65 lemma sums_finite:
    66   assumes [simp]: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
    67   shows "f sums (\<Sum>n\<in>N. f n)"
    68 proof -
    69   { fix n
    70     have "setsum f {..<n + Suc (Max N)} = setsum f N"
    71     proof cases
    72       assume "N = {}"
    73       with f have "f = (\<lambda>x. 0)" by auto
    74       then show ?thesis by simp
    75     next
    76       assume [simp]: "N \<noteq> {}"
    77       show ?thesis
    78       proof (safe intro!: setsum.mono_neutral_right f)
    79         fix i assume "i \<in> N"
    80         then have "i \<le> Max N" by simp
    81         then show "i < n + Suc (Max N)" by simp
    82       qed
    83     qed }
    84   note eq = this
    85   show ?thesis unfolding sums_def
    86     by (rule LIMSEQ_offset[of _ "Suc (Max N)"])
    87        (simp add: eq atLeast0LessThan tendsto_const del: add_Suc_right)
    88 qed
    89 
    90 lemma summable_finite: "finite N \<Longrightarrow> (\<And>n. n \<notin> N \<Longrightarrow> f n = 0) \<Longrightarrow> summable f"
    91   by (rule sums_summable) (rule sums_finite)
    92 
    93 lemma sums_If_finite_set: "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 0) sums (\<Sum>r\<in>A. f r)"
    94   using sums_finite[of A "(\<lambda>r. if r \<in> A then f r else 0)"] by simp
    95 
    96 lemma summable_If_finite_set[simp, intro]: "finite A \<Longrightarrow> summable (\<lambda>r. if r \<in> A then f r else 0)"
    97   by (rule sums_summable) (rule sums_If_finite_set)
    98 
    99 lemma sums_If_finite: "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 0) sums (\<Sum>r | P r. f r)"
   100   using sums_If_finite_set[of "{r. P r}"] by simp
   101 
   102 lemma summable_If_finite[simp, intro]: "finite {r. P r} \<Longrightarrow> summable (\<lambda>r. if P r then f r else 0)"
   103   by (rule sums_summable) (rule sums_If_finite)
   104 
   105 lemma sums_single: "(\<lambda>r. if r = i then f r else 0) sums f i"
   106   using sums_If_finite[of "\<lambda>r. r = i"] by simp
   107 
   108 lemma summable_single[simp, intro]: "summable (\<lambda>r. if r = i then f r else 0)"
   109   by (rule sums_summable) (rule sums_single)
   110 
   111 context
   112   fixes f :: "nat \<Rightarrow> 'a::{t2_space, comm_monoid_add}"
   113 begin
   114 
   115 lemma summable_sums[intro]: "summable f \<Longrightarrow> f sums (suminf f)"
   116   by (simp add: summable_def sums_def suminf_def)
   117      (metis convergent_LIMSEQ_iff convergent_def lim_def)
   118 
   119 lemma summable_LIMSEQ: "summable f \<Longrightarrow> (\<lambda>n. \<Sum>i<n. f i) ----> suminf f"
   120   by (rule summable_sums [unfolded sums_def])
   121 
   122 lemma sums_unique: "f sums s \<Longrightarrow> s = suminf f"
   123   by (metis limI suminf_eq_lim sums_def)
   124 
   125 lemma sums_iff: "f sums x \<longleftrightarrow> summable f \<and> (suminf f = x)"
   126   by (metis summable_sums sums_summable sums_unique)
   127 
   128 lemma suminf_finite:
   129   assumes N: "finite N" and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 0"
   130   shows "suminf f = (\<Sum>n\<in>N. f n)"
   131   using sums_finite[OF assms, THEN sums_unique] by simp
   132 
   133 end
   134 
   135 lemma suminf_zero[simp]: "suminf (\<lambda>n. 0::'a::{t2_space, comm_monoid_add}) = 0"
   136   by (rule sums_zero [THEN sums_unique, symmetric])
   137 
   138 
   139 subsection {* Infinite summability on ordered, topological monoids *}
   140 
   141 lemma sums_le:
   142   fixes f g :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
   143   shows "\<forall>n. f n \<le> g n \<Longrightarrow> f sums s \<Longrightarrow> g sums t \<Longrightarrow> s \<le> t"
   144   by (rule LIMSEQ_le) (auto intro: setsum_mono simp: sums_def)
   145 
   146 context
   147   fixes f :: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology}"
   148 begin
   149 
   150 lemma suminf_le: "\<lbrakk>\<forall>n. f n \<le> g n; summable f; summable g\<rbrakk> \<Longrightarrow> suminf f \<le> suminf g"
   151   by (auto dest: sums_summable intro: sums_le)
   152 
   153 lemma setsum_le_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> setsum f {..<n} \<le> suminf f"
   154   by (rule sums_le[OF _ sums_If_finite_set summable_sums]) auto
   155 
   156 lemma suminf_nonneg: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 \<le> suminf f"
   157   using setsum_le_suminf[of 0] by simp
   158 
   159 lemma setsum_less_suminf2: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 \<le> f m \<Longrightarrow> n \<le> i \<Longrightarrow> 0 < f i \<Longrightarrow> setsum f {..<n} < suminf f"
   160   using
   161     setsum_le_suminf[of "Suc i"]
   162     add_strict_increasing[of "f i" "setsum f {..<n}" "setsum f {..<i}"]
   163     setsum_mono2[of "{..<i}" "{..<n}" f]
   164   by (auto simp: less_imp_le ac_simps)
   165 
   166 lemma setsum_less_suminf: "summable f \<Longrightarrow> \<forall>m\<ge>n. 0 < f m \<Longrightarrow> setsum f {..<n} < suminf f"
   167   using setsum_less_suminf2[of n n] by (simp add: less_imp_le)
   168 
   169 lemma suminf_pos2: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < f i \<Longrightarrow> 0 < suminf f"
   170   using setsum_less_suminf2[of 0 i] by simp
   171 
   172 lemma suminf_pos: "summable f \<Longrightarrow> \<forall>n. 0 < f n \<Longrightarrow> 0 < suminf f"
   173   using suminf_pos2[of 0] by (simp add: less_imp_le)
   174 
   175 lemma suminf_le_const: "summable f \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> x) \<Longrightarrow> suminf f \<le> x"
   176   by (metis LIMSEQ_le_const2 summable_LIMSEQ)
   177 
   178 lemma suminf_eq_zero_iff: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> suminf f = 0 \<longleftrightarrow> (\<forall>n. f n = 0)"
   179 proof
   180   assume "summable f" "suminf f = 0" and pos: "\<forall>n. 0 \<le> f n"
   181   then have f: "(\<lambda>n. \<Sum>i<n. f i) ----> 0"
   182     using summable_LIMSEQ[of f] by simp
   183   then have "\<And>i. (\<Sum>n\<in>{i}. f n) \<le> 0"
   184   proof (rule LIMSEQ_le_const)
   185     fix i show "\<exists>N. \<forall>n\<ge>N. (\<Sum>n\<in>{i}. f n) \<le> setsum f {..<n}"
   186       using pos by (intro exI[of _ "Suc i"] allI impI setsum_mono2) auto
   187   qed
   188   with pos show "\<forall>n. f n = 0"
   189     by (auto intro!: antisym)
   190 qed (metis suminf_zero fun_eq_iff)
   191 
   192 lemma suminf_pos_iff: "summable f \<Longrightarrow> \<forall>n. 0 \<le> f n \<Longrightarrow> 0 < suminf f \<longleftrightarrow> (\<exists>i. 0 < f i)"
   193   using setsum_le_suminf[of 0] suminf_eq_zero_iff by (simp add: less_le)
   194 
   195 end
   196 
   197 lemma summableI_nonneg_bounded:
   198   fixes f:: "nat \<Rightarrow> 'a::{ordered_comm_monoid_add, linorder_topology, conditionally_complete_linorder}"
   199   assumes pos[simp]: "\<And>n. 0 \<le> f n" and le: "\<And>n. (\<Sum>i<n. f i) \<le> x"
   200   shows "summable f"
   201   unfolding summable_def sums_def[abs_def]
   202 proof (intro exI order_tendstoI)
   203   have [simp, intro]: "bdd_above (range (\<lambda>n. \<Sum>i<n. f i))"
   204     using le by (auto simp: bdd_above_def)
   205   { fix a assume "a < (SUP n. \<Sum>i<n. f i)"
   206     then obtain n where "a < (\<Sum>i<n. f i)"
   207       by (auto simp add: less_cSUP_iff)
   208     then have "\<And>m. n \<le> m \<Longrightarrow> a < (\<Sum>i<m. f i)"
   209       by (rule less_le_trans) (auto intro!: setsum_mono2)
   210     then show "eventually (\<lambda>n. a < (\<Sum>i<n. f i)) sequentially"
   211       by (auto simp: eventually_sequentially) }
   212   { fix a assume "(SUP n. \<Sum>i<n. f i) < a"
   213     moreover have "\<And>n. (\<Sum>i<n. f i) \<le> (SUP n. \<Sum>i<n. f i)"
   214       by (auto intro: cSUP_upper)
   215     ultimately show "eventually (\<lambda>n. (\<Sum>i<n. f i) < a) sequentially"
   216       by (auto intro: le_less_trans simp: eventually_sequentially) }
   217 qed
   218 
   219 subsection {* Infinite summability on real normed vector spaces *}
   220 
   221 lemma sums_Suc_iff:
   222   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
   223   shows "(\<lambda>n. f (Suc n)) sums s \<longleftrightarrow> f sums (s + f 0)"
   224 proof -
   225   have "f sums (s + f 0) \<longleftrightarrow> (\<lambda>i. \<Sum>j<Suc i. f j) ----> s + f 0"
   226     by (subst LIMSEQ_Suc_iff) (simp add: sums_def)
   227   also have "\<dots> \<longleftrightarrow> (\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
   228     by (simp add: ac_simps setsum.reindex image_iff lessThan_Suc_eq_insert_0)
   229   also have "\<dots> \<longleftrightarrow> (\<lambda>n. f (Suc n)) sums s"
   230   proof
   231     assume "(\<lambda>i. (\<Sum>j<i. f (Suc j)) + f 0) ----> s + f 0"
   232     with tendsto_add[OF this tendsto_const, of "- f 0"]
   233     show "(\<lambda>i. f (Suc i)) sums s"
   234       by (simp add: sums_def)
   235   qed (auto intro: tendsto_add tendsto_const simp: sums_def)
   236   finally show ?thesis ..
   237 qed
   238 
   239 context
   240   fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
   241 begin
   242 
   243 lemma sums_add: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n + g n) sums (a + b)"
   244   unfolding sums_def by (simp add: setsum.distrib tendsto_add)
   245 
   246 lemma summable_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n + g n)"
   247   unfolding summable_def by (auto intro: sums_add)
   248 
   249 lemma suminf_add: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f + suminf g = (\<Sum>n. f n + g n)"
   250   by (intro sums_unique sums_add summable_sums)
   251 
   252 lemma sums_diff: "f sums a \<Longrightarrow> g sums b \<Longrightarrow> (\<lambda>n. f n - g n) sums (a - b)"
   253   unfolding sums_def by (simp add: setsum_subtractf tendsto_diff)
   254 
   255 lemma summable_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. f n - g n)"
   256   unfolding summable_def by (auto intro: sums_diff)
   257 
   258 lemma suminf_diff: "summable f \<Longrightarrow> summable g \<Longrightarrow> suminf f - suminf g = (\<Sum>n. f n - g n)"
   259   by (intro sums_unique sums_diff summable_sums)
   260 
   261 lemma sums_minus: "f sums a \<Longrightarrow> (\<lambda>n. - f n) sums (- a)"
   262   unfolding sums_def by (simp add: setsum_negf tendsto_minus)
   263 
   264 lemma summable_minus: "summable f \<Longrightarrow> summable (\<lambda>n. - f n)"
   265   unfolding summable_def by (auto intro: sums_minus)
   266 
   267 lemma suminf_minus: "summable f \<Longrightarrow> (\<Sum>n. - f n) = - (\<Sum>n. f n)"
   268   by (intro sums_unique [symmetric] sums_minus summable_sums)
   269 
   270 lemma sums_Suc: "(\<lambda> n. f (Suc n)) sums l \<Longrightarrow> f sums (l + f 0)"
   271   by (simp add: sums_Suc_iff)
   272 
   273 lemma sums_iff_shift: "(\<lambda>i. f (i + n)) sums s \<longleftrightarrow> f sums (s + (\<Sum>i<n. f i))"
   274 proof (induct n arbitrary: s)
   275   case (Suc n)
   276   moreover have "(\<lambda>i. f (Suc i + n)) sums s \<longleftrightarrow> (\<lambda>i. f (i + n)) sums (s + f n)"
   277     by (subst sums_Suc_iff) simp
   278   ultimately show ?case
   279     by (simp add: ac_simps)
   280 qed simp
   281 
   282 lemma summable_iff_shift: "summable (\<lambda>n. f (n + k)) \<longleftrightarrow> summable f"
   283   by (metis diff_add_cancel summable_def sums_iff_shift[abs_def])
   284 
   285 lemma sums_split_initial_segment: "f sums s \<Longrightarrow> (\<lambda>i. f (i + n)) sums (s - (\<Sum>i<n. f i))"
   286   by (simp add: sums_iff_shift)
   287 
   288 lemma summable_ignore_initial_segment: "summable f \<Longrightarrow> summable (\<lambda>n. f(n + k))"
   289   by (simp add: summable_iff_shift)
   290 
   291 lemma suminf_minus_initial_segment: "summable f \<Longrightarrow> (\<Sum>n. f (n + k)) = (\<Sum>n. f n) - (\<Sum>i<k. f i)"
   292   by (rule sums_unique[symmetric]) (auto simp: sums_iff_shift)
   293 
   294 lemma suminf_split_initial_segment: "summable f \<Longrightarrow> suminf f = (\<Sum>n. f(n + k)) + (\<Sum>i<k. f i)"
   295   by (auto simp add: suminf_minus_initial_segment)
   296 
   297 lemma suminf_exist_split: 
   298   fixes r :: real assumes "0 < r" and "summable f"
   299   shows "\<exists>N. \<forall>n\<ge>N. norm (\<Sum>i. f (i + n)) < r"
   300 proof -
   301   from LIMSEQ_D[OF summable_LIMSEQ[OF `summable f`] `0 < r`]
   302   obtain N :: nat where "\<forall> n \<ge> N. norm (setsum f {..<n} - suminf f) < r" by auto
   303   thus ?thesis
   304     by (auto simp: norm_minus_commute suminf_minus_initial_segment[OF `summable f`])
   305 qed
   306 
   307 lemma summable_LIMSEQ_zero: "summable f \<Longrightarrow> f ----> 0"
   308   apply (drule summable_iff_convergent [THEN iffD1])
   309   apply (drule convergent_Cauchy)
   310   apply (simp only: Cauchy_iff LIMSEQ_iff, safe)
   311   apply (drule_tac x="r" in spec, safe)
   312   apply (rule_tac x="M" in exI, safe)
   313   apply (drule_tac x="Suc n" in spec, simp)
   314   apply (drule_tac x="n" in spec, simp)
   315   done
   316 
   317 end
   318 
   319 context
   320   fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::real_normed_vector" and I :: "'i set"
   321 begin
   322 
   323 lemma sums_setsum: "(\<And>i. i \<in> I \<Longrightarrow> (f i) sums (x i)) \<Longrightarrow> (\<lambda>n. \<Sum>i\<in>I. f i n) sums (\<Sum>i\<in>I. x i)"
   324   by (induct I rule: infinite_finite_induct) (auto intro!: sums_add)
   325 
   326 lemma suminf_setsum: "(\<And>i. i \<in> I \<Longrightarrow> summable (f i)) \<Longrightarrow> (\<Sum>n. \<Sum>i\<in>I. f i n) = (\<Sum>i\<in>I. \<Sum>n. f i n)"
   327   using sums_unique[OF sums_setsum, OF summable_sums] by simp
   328 
   329 lemma summable_setsum: "(\<And>i. i \<in> I \<Longrightarrow> summable (f i)) \<Longrightarrow> summable (\<lambda>n. \<Sum>i\<in>I. f i n)"
   330   using sums_summable[OF sums_setsum[OF summable_sums]] .
   331 
   332 end
   333 
   334 lemma (in bounded_linear) sums: "(\<lambda>n. X n) sums a \<Longrightarrow> (\<lambda>n. f (X n)) sums (f a)"
   335   unfolding sums_def by (drule tendsto, simp only: setsum)
   336 
   337 lemma (in bounded_linear) summable: "summable (\<lambda>n. X n) \<Longrightarrow> summable (\<lambda>n. f (X n))"
   338   unfolding summable_def by (auto intro: sums)
   339 
   340 lemma (in bounded_linear) suminf: "summable (\<lambda>n. X n) \<Longrightarrow> f (\<Sum>n. X n) = (\<Sum>n. f (X n))"
   341   by (intro sums_unique sums summable_sums)
   342 
   343 lemmas sums_of_real = bounded_linear.sums [OF bounded_linear_of_real]
   344 lemmas summable_of_real = bounded_linear.summable [OF bounded_linear_of_real]
   345 lemmas suminf_of_real = bounded_linear.suminf [OF bounded_linear_of_real]
   346 
   347 lemmas sums_scaleR_left = bounded_linear.sums[OF bounded_linear_scaleR_left]
   348 lemmas summable_scaleR_left = bounded_linear.summable[OF bounded_linear_scaleR_left]
   349 lemmas suminf_scaleR_left = bounded_linear.suminf[OF bounded_linear_scaleR_left]
   350 
   351 lemmas sums_scaleR_right = bounded_linear.sums[OF bounded_linear_scaleR_right]
   352 lemmas summable_scaleR_right = bounded_linear.summable[OF bounded_linear_scaleR_right]
   353 lemmas suminf_scaleR_right = bounded_linear.suminf[OF bounded_linear_scaleR_right]
   354 
   355 subsection {* Infinite summability on real normed algebras *}
   356 
   357 context
   358   fixes f :: "nat \<Rightarrow> 'a::real_normed_algebra"
   359 begin
   360 
   361 lemma sums_mult: "f sums a \<Longrightarrow> (\<lambda>n. c * f n) sums (c * a)"
   362   by (rule bounded_linear.sums [OF bounded_linear_mult_right])
   363 
   364 lemma summable_mult: "summable f \<Longrightarrow> summable (\<lambda>n. c * f n)"
   365   by (rule bounded_linear.summable [OF bounded_linear_mult_right])
   366 
   367 lemma suminf_mult: "summable f \<Longrightarrow> suminf (\<lambda>n. c * f n) = c * suminf f"
   368   by (rule bounded_linear.suminf [OF bounded_linear_mult_right, symmetric])
   369 
   370 lemma sums_mult2: "f sums a \<Longrightarrow> (\<lambda>n. f n * c) sums (a * c)"
   371   by (rule bounded_linear.sums [OF bounded_linear_mult_left])
   372 
   373 lemma summable_mult2: "summable f \<Longrightarrow> summable (\<lambda>n. f n * c)"
   374   by (rule bounded_linear.summable [OF bounded_linear_mult_left])
   375 
   376 lemma suminf_mult2: "summable f \<Longrightarrow> suminf f * c = (\<Sum>n. f n * c)"
   377   by (rule bounded_linear.suminf [OF bounded_linear_mult_left])
   378 
   379 end
   380 
   381 subsection {* Infinite summability on real normed fields *}
   382 
   383 context
   384   fixes c :: "'a::real_normed_field"
   385 begin
   386 
   387 lemma sums_divide: "f sums a \<Longrightarrow> (\<lambda>n. f n / c) sums (a / c)"
   388   by (rule bounded_linear.sums [OF bounded_linear_divide])
   389 
   390 lemma summable_divide: "summable f \<Longrightarrow> summable (\<lambda>n. f n / c)"
   391   by (rule bounded_linear.summable [OF bounded_linear_divide])
   392 
   393 lemma suminf_divide: "summable f \<Longrightarrow> suminf (\<lambda>n. f n / c) = suminf f / c"
   394   by (rule bounded_linear.suminf [OF bounded_linear_divide, symmetric])
   395 
   396 text{*Sum of a geometric progression.*}
   397 
   398 lemma geometric_sums: "norm c < 1 \<Longrightarrow> (\<lambda>n. c^n) sums (1 / (1 - c))"
   399 proof -
   400   assume less_1: "norm c < 1"
   401   hence neq_1: "c \<noteq> 1" by auto
   402   hence neq_0: "c - 1 \<noteq> 0" by simp
   403   from less_1 have lim_0: "(\<lambda>n. c^n) ----> 0"
   404     by (rule LIMSEQ_power_zero)
   405   hence "(\<lambda>n. c ^ n / (c - 1) - 1 / (c - 1)) ----> 0 / (c - 1) - 1 / (c - 1)"
   406     using neq_0 by (intro tendsto_intros)
   407   hence "(\<lambda>n. (c ^ n - 1) / (c - 1)) ----> 1 / (1 - c)"
   408     by (simp add: nonzero_minus_divide_right [OF neq_0] diff_divide_distrib)
   409   thus "(\<lambda>n. c ^ n) sums (1 / (1 - c))"
   410     by (simp add: sums_def geometric_sum neq_1)
   411 qed
   412 
   413 lemma summable_geometric: "norm c < 1 \<Longrightarrow> summable (\<lambda>n. c^n)"
   414   by (rule geometric_sums [THEN sums_summable])
   415 
   416 lemma suminf_geometric: "norm c < 1 \<Longrightarrow> suminf (\<lambda>n. c^n) = 1 / (1 - c)"
   417   by (rule sums_unique[symmetric]) (rule geometric_sums)
   418 
   419 end
   420 
   421 lemma power_half_series: "(\<lambda>n. (1/2::real)^Suc n) sums 1"
   422 proof -
   423   have 2: "(\<lambda>n. (1/2::real)^n) sums 2" using geometric_sums [of "1/2::real"]
   424     by auto
   425   have "(\<lambda>n. (1/2::real)^Suc n) = (\<lambda>n. (1 / 2) ^ n / 2)"
   426     by simp
   427   thus ?thesis using sums_divide [OF 2, of 2]
   428     by simp
   429 qed
   430 
   431 subsection {* Infinite summability on Banach spaces *}
   432 
   433 text{*Cauchy-type criterion for convergence of series (c.f. Harrison)*}
   434 
   435 lemma summable_Cauchy:
   436   fixes f :: "nat \<Rightarrow> 'a::banach"
   437   shows "summable f \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m\<ge>N. \<forall>n. norm (setsum f {m..<n}) < e)"
   438   apply (simp only: summable_iff_convergent Cauchy_convergent_iff [symmetric] Cauchy_iff, safe)
   439   apply (drule spec, drule (1) mp)
   440   apply (erule exE, rule_tac x="M" in exI, clarify)
   441   apply (rule_tac x="m" and y="n" in linorder_le_cases)
   442   apply (frule (1) order_trans)
   443   apply (drule_tac x="n" in spec, drule (1) mp)
   444   apply (drule_tac x="m" in spec, drule (1) mp)
   445   apply (simp_all add: setsum_diff [symmetric])
   446   apply (drule spec, drule (1) mp)
   447   apply (erule exE, rule_tac x="N" in exI, clarify)
   448   apply (rule_tac x="m" and y="n" in linorder_le_cases)
   449   apply (subst norm_minus_commute)
   450   apply (simp_all add: setsum_diff [symmetric])
   451   done
   452 
   453 context
   454   fixes f :: "nat \<Rightarrow> 'a::banach"
   455 begin  
   456 
   457 text{*Absolute convergence imples normal convergence*}
   458 
   459 lemma summable_norm_cancel: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> summable f"
   460   apply (simp only: summable_Cauchy, safe)
   461   apply (drule_tac x="e" in spec, safe)
   462   apply (rule_tac x="N" in exI, safe)
   463   apply (drule_tac x="m" in spec, safe)
   464   apply (rule order_le_less_trans [OF norm_setsum])
   465   apply (rule order_le_less_trans [OF abs_ge_self])
   466   apply simp
   467   done
   468 
   469 lemma summable_norm: "summable (\<lambda>n. norm (f n)) \<Longrightarrow> norm (suminf f) \<le> (\<Sum>n. norm (f n))"
   470   by (auto intro: LIMSEQ_le tendsto_norm summable_norm_cancel summable_LIMSEQ norm_setsum)
   471 
   472 text {* Comparison tests *}
   473 
   474 lemma summable_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable f"
   475   apply (simp add: summable_Cauchy, safe)
   476   apply (drule_tac x="e" in spec, safe)
   477   apply (rule_tac x = "N + Na" in exI, safe)
   478   apply (rotate_tac 2)
   479   apply (drule_tac x = m in spec)
   480   apply (auto, rotate_tac 2, drule_tac x = n in spec)
   481   apply (rule_tac y = "\<Sum>k=m..<n. norm (f k)" in order_le_less_trans)
   482   apply (rule norm_setsum)
   483   apply (rule_tac y = "setsum g {m..<n}" in order_le_less_trans)
   484   apply (auto intro: setsum_mono simp add: abs_less_iff)
   485   done
   486 
   487 (*A better argument order*)
   488 lemma summable_comparison_test': "summable g \<Longrightarrow> (\<And>n. n \<ge> N \<Longrightarrow> norm(f n) \<le> g n) \<Longrightarrow> summable f"
   489   by (rule summable_comparison_test) auto
   490 
   491 subsection {* The Ratio Test*}
   492 
   493 lemma summable_ratio_test: 
   494   assumes "c < 1" "\<And>n. n \<ge> N \<Longrightarrow> norm (f (Suc n)) \<le> c * norm (f n)"
   495   shows "summable f"
   496 proof cases
   497   assume "0 < c"
   498   show "summable f"
   499   proof (rule summable_comparison_test)
   500     show "\<exists>N'. \<forall>n\<ge>N'. norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
   501     proof (intro exI allI impI)
   502       fix n assume "N \<le> n" then show "norm (f n) \<le> (norm (f N) / (c ^ N)) * c ^ n"
   503       proof (induct rule: inc_induct)
   504         case (step m)
   505         moreover have "norm (f (Suc m)) / c ^ Suc m * c ^ n \<le> norm (f m) / c ^ m * c ^ n"
   506           using `0 < c` `c < 1` assms(2)[OF `N \<le> m`] by (simp add: field_simps)
   507         ultimately show ?case by simp
   508       qed (insert `0 < c`, simp)
   509     qed
   510     show "summable (\<lambda>n. norm (f N) / c ^ N * c ^ n)"
   511       using `0 < c` `c < 1` by (intro summable_mult summable_geometric) simp
   512   qed
   513 next
   514   assume c: "\<not> 0 < c"
   515   { fix n assume "n \<ge> N"
   516     then have "norm (f (Suc n)) \<le> c * norm (f n)"
   517       by fact
   518     also have "\<dots> \<le> 0"
   519       using c by (simp add: not_less mult_nonpos_nonneg)
   520     finally have "f (Suc n) = 0"
   521       by auto }
   522   then show "summable f"
   523     by (intro sums_summable[OF sums_finite, of "{.. Suc N}"]) (auto simp: not_le Suc_less_eq2)
   524 qed
   525 
   526 end
   527 
   528 text{*Relations among convergence and absolute convergence for power series.*}
   529 
   530 lemma abel_lemma:
   531   fixes a :: "nat \<Rightarrow> 'a::real_normed_vector"
   532   assumes r: "0 \<le> r" and r0: "r < r0" and M: "\<And>n. norm (a n) * r0^n \<le> M"
   533     shows "summable (\<lambda>n. norm (a n) * r^n)"
   534 proof (rule summable_comparison_test')
   535   show "summable (\<lambda>n. M * (r / r0) ^ n)"
   536     using assms 
   537     by (auto simp add: summable_mult summable_geometric)
   538 next
   539   fix n
   540   show "norm (norm (a n) * r ^ n) \<le> M * (r / r0) ^ n"
   541     using r r0 M [of n]
   542     apply (auto simp add: abs_mult field_simps power_divide)
   543     apply (cases "r=0", simp)
   544     apply (cases n, auto)
   545     done
   546 qed
   547 
   548 
   549 text{*Summability of geometric series for real algebras*}
   550 
   551 lemma complete_algebra_summable_geometric:
   552   fixes x :: "'a::{real_normed_algebra_1,banach}"
   553   shows "norm x < 1 \<Longrightarrow> summable (\<lambda>n. x ^ n)"
   554 proof (rule summable_comparison_test)
   555   show "\<exists>N. \<forall>n\<ge>N. norm (x ^ n) \<le> norm x ^ n"
   556     by (simp add: norm_power_ineq)
   557   show "norm x < 1 \<Longrightarrow> summable (\<lambda>n. norm x ^ n)"
   558     by (simp add: summable_geometric)
   559 qed
   560 
   561 subsection {* Cauchy Product Formula *}
   562 
   563 text {*
   564   Proof based on Analysis WebNotes: Chapter 07, Class 41
   565   @{url "http://www.math.unl.edu/~webnotes/classes/class41/prp77.htm"}
   566 *}
   567 
   568 lemma setsum_triangle_reindex:
   569   fixes n :: nat
   570   shows "(\<Sum>(i,j)\<in>{(i,j). i+j < n}. f i j) = (\<Sum>k<n. \<Sum>i\<le>k. f i (k - i))"
   571   apply (simp add: setsum.Sigma)
   572   apply (rule setsum.reindex_bij_witness[where j="\<lambda>(i, j). (i+j, i)" and i="\<lambda>(k, i). (i, k - i)"])
   573   apply auto
   574   done
   575 
   576 lemma Cauchy_product_sums:
   577   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
   578   assumes a: "summable (\<lambda>k. norm (a k))"
   579   assumes b: "summable (\<lambda>k. norm (b k))"
   580   shows "(\<lambda>k. \<Sum>i\<le>k. a i * b (k - i)) sums ((\<Sum>k. a k) * (\<Sum>k. b k))"
   581 proof -
   582   let ?S1 = "\<lambda>n::nat. {..<n} \<times> {..<n}"
   583   let ?S2 = "\<lambda>n::nat. {(i,j). i + j < n}"
   584   have S1_mono: "\<And>m n. m \<le> n \<Longrightarrow> ?S1 m \<subseteq> ?S1 n" by auto
   585   have S2_le_S1: "\<And>n. ?S2 n \<subseteq> ?S1 n" by auto
   586   have S1_le_S2: "\<And>n. ?S1 (n div 2) \<subseteq> ?S2 n" by auto
   587   have finite_S1: "\<And>n. finite (?S1 n)" by simp
   588   with S2_le_S1 have finite_S2: "\<And>n. finite (?S2 n)" by (rule finite_subset)
   589 
   590   let ?g = "\<lambda>(i,j). a i * b j"
   591   let ?f = "\<lambda>(i,j). norm (a i) * norm (b j)"
   592   have f_nonneg: "\<And>x. 0 \<le> ?f x" by (auto)
   593   hence norm_setsum_f: "\<And>A. norm (setsum ?f A) = setsum ?f A"
   594     unfolding real_norm_def
   595     by (simp only: abs_of_nonneg setsum_nonneg [rule_format])
   596 
   597   have "(\<lambda>n. (\<Sum>k<n. a k) * (\<Sum>k<n. b k)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
   598     by (intro tendsto_mult summable_LIMSEQ summable_norm_cancel [OF a] summable_norm_cancel [OF b])
   599   hence 1: "(\<lambda>n. setsum ?g (?S1 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
   600     by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
   601 
   602   have "(\<lambda>n. (\<Sum>k<n. norm (a k)) * (\<Sum>k<n. norm (b k))) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
   603     using a b by (intro tendsto_mult summable_LIMSEQ)
   604   hence "(\<lambda>n. setsum ?f (?S1 n)) ----> (\<Sum>k. norm (a k)) * (\<Sum>k. norm (b k))"
   605     by (simp only: setsum_product setsum.Sigma [rule_format] finite_lessThan)
   606   hence "convergent (\<lambda>n. setsum ?f (?S1 n))"
   607     by (rule convergentI)
   608   hence Cauchy: "Cauchy (\<lambda>n. setsum ?f (?S1 n))"
   609     by (rule convergent_Cauchy)
   610   have "Zfun (\<lambda>n. setsum ?f (?S1 n - ?S2 n)) sequentially"
   611   proof (rule ZfunI, simp only: eventually_sequentially norm_setsum_f)
   612     fix r :: real
   613     assume r: "0 < r"
   614     from CauchyD [OF Cauchy r] obtain N
   615     where "\<forall>m\<ge>N. \<forall>n\<ge>N. norm (setsum ?f (?S1 m) - setsum ?f (?S1 n)) < r" ..
   616     hence "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> norm (setsum ?f (?S1 m - ?S1 n)) < r"
   617       by (simp only: setsum_diff finite_S1 S1_mono)
   618     hence N: "\<And>m n. \<lbrakk>N \<le> n; n \<le> m\<rbrakk> \<Longrightarrow> setsum ?f (?S1 m - ?S1 n) < r"
   619       by (simp only: norm_setsum_f)
   620     show "\<exists>N. \<forall>n\<ge>N. setsum ?f (?S1 n - ?S2 n) < r"
   621     proof (intro exI allI impI)
   622       fix n assume "2 * N \<le> n"
   623       hence n: "N \<le> n div 2" by simp
   624       have "setsum ?f (?S1 n - ?S2 n) \<le> setsum ?f (?S1 n - ?S1 (n div 2))"
   625         by (intro setsum_mono2 finite_Diff finite_S1 f_nonneg
   626                   Diff_mono subset_refl S1_le_S2)
   627       also have "\<dots> < r"
   628         using n div_le_dividend by (rule N)
   629       finally show "setsum ?f (?S1 n - ?S2 n) < r" .
   630     qed
   631   qed
   632   hence "Zfun (\<lambda>n. setsum ?g (?S1 n - ?S2 n)) sequentially"
   633     apply (rule Zfun_le [rule_format])
   634     apply (simp only: norm_setsum_f)
   635     apply (rule order_trans [OF norm_setsum setsum_mono])
   636     apply (auto simp add: norm_mult_ineq)
   637     done
   638   hence 2: "(\<lambda>n. setsum ?g (?S1 n) - setsum ?g (?S2 n)) ----> 0"
   639     unfolding tendsto_Zfun_iff diff_0_right
   640     by (simp only: setsum_diff finite_S1 S2_le_S1)
   641 
   642   with 1 have "(\<lambda>n. setsum ?g (?S2 n)) ----> (\<Sum>k. a k) * (\<Sum>k. b k)"
   643     by (rule LIMSEQ_diff_approach_zero2)
   644   thus ?thesis by (simp only: sums_def setsum_triangle_reindex)
   645 qed
   646 
   647 lemma Cauchy_product:
   648   fixes a b :: "nat \<Rightarrow> 'a::{real_normed_algebra,banach}"
   649   assumes a: "summable (\<lambda>k. norm (a k))"
   650   assumes b: "summable (\<lambda>k. norm (b k))"
   651   shows "(\<Sum>k. a k) * (\<Sum>k. b k) = (\<Sum>k. \<Sum>i\<le>k. a i * b (k - i))"
   652   using a b
   653   by (rule Cauchy_product_sums [THEN sums_unique])
   654 
   655 subsection {* Series on @{typ real}s *}
   656 
   657 lemma summable_norm_comparison_test: "\<exists>N. \<forall>n\<ge>N. norm (f n) \<le> g n \<Longrightarrow> summable g \<Longrightarrow> summable (\<lambda>n. norm (f n))"
   658   by (rule summable_comparison_test) auto
   659 
   660 lemma summable_rabs_comparison_test: "\<lbrakk>\<exists>N. \<forall>n\<ge>N. \<bar>f n\<bar> \<le> g n; summable g\<rbrakk> \<Longrightarrow> summable (\<lambda>n. \<bar>f n :: real\<bar>)"
   661   by (rule summable_comparison_test) auto
   662 
   663 lemma summable_rabs_cancel: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> summable f"
   664   by (rule summable_norm_cancel) simp
   665 
   666 lemma summable_rabs: "summable (\<lambda>n. \<bar>f n :: real\<bar>) \<Longrightarrow> \<bar>suminf f\<bar> \<le> (\<Sum>n. \<bar>f n\<bar>)"
   667   by (fold real_norm_def) (rule summable_norm)
   668 
   669 end