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