src/HOL/Analysis/Infinite_Products.thy
 author paulson Sun Jun 03 15:22:30 2018 +0100 (13 months ago) changeset 68361 20375f232f3b parent 68138 c738f40e88d4 child 68424 02e5a44ffe7d permissions -rw-r--r--
infinite product material
     1 (*File:      HOL/Analysis/Infinite_Product.thy

     2   Author:    Manuel Eberl & LC Paulson

     3

     4   Basic results about convergence and absolute convergence of infinite products

     5   and their connection to summability.

     6 *)

     7 section \<open>Infinite Products\<close>

     8 theory Infinite_Products

     9   imports Complex_Main

    10 begin

    11

    12 lemma sum_le_prod:

    13   fixes f :: "'a \<Rightarrow> 'b :: linordered_semidom"

    14   assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0"

    15   shows   "sum f A \<le> (\<Prod>x\<in>A. 1 + f x)"

    16   using assms

    17 proof (induction A rule: infinite_finite_induct)

    18   case (insert x A)

    19   from insert.hyps have "sum f A + f x * (\<Prod>x\<in>A. 1) \<le> (\<Prod>x\<in>A. 1 + f x) + f x * (\<Prod>x\<in>A. 1 + f x)"

    20     by (intro add_mono insert mult_left_mono prod_mono) (auto intro: insert.prems)

    21   with insert.hyps show ?case by (simp add: algebra_simps)

    22 qed simp_all

    23

    24 lemma prod_le_exp_sum:

    25   fixes f :: "'a \<Rightarrow> real"

    26   assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0"

    27   shows   "prod (\<lambda>x. 1 + f x) A \<le> exp (sum f A)"

    28   using assms

    29 proof (induction A rule: infinite_finite_induct)

    30   case (insert x A)

    31   have "(1 + f x) * (\<Prod>x\<in>A. 1 + f x) \<le> exp (f x) * exp (sum f A)"

    32     using insert.prems by (intro mult_mono insert prod_nonneg exp_ge_add_one_self) auto

    33   with insert.hyps show ?case by (simp add: algebra_simps exp_add)

    34 qed simp_all

    35

    36 lemma lim_ln_1_plus_x_over_x_at_0: "(\<lambda>x::real. ln (1 + x) / x) \<midarrow>0\<rightarrow> 1"

    37 proof (rule lhopital)

    38   show "(\<lambda>x::real. ln (1 + x)) \<midarrow>0\<rightarrow> 0"

    39     by (rule tendsto_eq_intros refl | simp)+

    40   have "eventually (\<lambda>x::real. x \<in> {-1/2<..<1/2}) (nhds 0)"

    41     by (rule eventually_nhds_in_open) auto

    42   hence *: "eventually (\<lambda>x::real. x \<in> {-1/2<..<1/2}) (at 0)"

    43     by (rule filter_leD [rotated]) (simp_all add: at_within_def)

    44   show "eventually (\<lambda>x::real. ((\<lambda>x. ln (1 + x)) has_field_derivative inverse (1 + x)) (at x)) (at 0)"

    45     using * by eventually_elim (auto intro!: derivative_eq_intros simp: field_simps)

    46   show "eventually (\<lambda>x::real. ((\<lambda>x. x) has_field_derivative 1) (at x)) (at 0)"

    47     using * by eventually_elim (auto intro!: derivative_eq_intros simp: field_simps)

    48   show "\<forall>\<^sub>F x in at 0. x \<noteq> 0" by (auto simp: at_within_def eventually_inf_principal)

    49   show "(\<lambda>x::real. inverse (1 + x) / 1) \<midarrow>0\<rightarrow> 1"

    50     by (rule tendsto_eq_intros refl | simp)+

    51 qed auto

    52

    53 definition raw_has_prod :: "[nat \<Rightarrow> 'a::{t2_space, comm_semiring_1}, nat, 'a] \<Rightarrow> bool"

    54   where "raw_has_prod f M p \<equiv> (\<lambda>n. \<Prod>i\<le>n. f (i+M)) \<longlonglongrightarrow> p \<and> p \<noteq> 0"

    55

    56 text\<open>The nonzero and zero cases, as in \emph{Complex Analysis} by Joseph Bak and Donald J.Newman, page 241\<close>

    57 definition has_prod :: "(nat \<Rightarrow> 'a::{t2_space, comm_semiring_1}) \<Rightarrow> 'a \<Rightarrow> bool" (infixr "has'_prod" 80)

    58   where "f has_prod p \<equiv> raw_has_prod f 0 p \<or> (\<exists>i q. p = 0 \<and> f i = 0 \<and> raw_has_prod f (Suc i) q)"

    59

    60 definition convergent_prod :: "(nat \<Rightarrow> 'a :: {t2_space,comm_semiring_1}) \<Rightarrow> bool" where

    61   "convergent_prod f \<equiv> \<exists>M p. raw_has_prod f M p"

    62

    63 definition prodinf :: "(nat \<Rightarrow> 'a::{t2_space, comm_semiring_1}) \<Rightarrow> 'a"

    64     (binder "\<Prod>" 10)

    65   where "prodinf f = (THE p. f has_prod p)"

    66

    67 lemmas prod_defs = raw_has_prod_def has_prod_def convergent_prod_def prodinf_def

    68

    69 lemma has_prod_subst[trans]: "f = g \<Longrightarrow> g has_prod z \<Longrightarrow> f has_prod z"

    70   by simp

    71

    72 lemma has_prod_cong: "(\<And>n. f n = g n) \<Longrightarrow> f has_prod c \<longleftrightarrow> g has_prod c"

    73   by presburger

    74

    75 lemma raw_has_prod_nonzero [simp]: "\<not> raw_has_prod f M 0"

    76   by (simp add: raw_has_prod_def)

    77

    78 lemma raw_has_prod_eq_0:

    79   fixes f :: "nat \<Rightarrow> 'a::{semidom,t2_space}"

    80   assumes p: "raw_has_prod f m p" and i: "f i = 0" "i \<ge> m"

    81   shows "p = 0"

    82 proof -

    83   have eq0: "(\<Prod>k\<le>n. f (k+m)) = 0" if "i - m \<le> n" for n

    84   proof -

    85     have "\<exists>k\<le>n. f (k + m) = 0"

    86       using i that by auto

    87     then show ?thesis

    88       by auto

    89   qed

    90   have "(\<lambda>n. \<Prod>i\<le>n. f (i + m)) \<longlonglongrightarrow> 0"

    91     by (rule LIMSEQ_offset [where k = "i-m"]) (simp add: eq0)

    92     with p show ?thesis

    93       unfolding raw_has_prod_def

    94     using LIMSEQ_unique by blast

    95 qed

    96

    97 lemma has_prod_0_iff: "f has_prod 0 \<longleftrightarrow> (\<exists>i. f i = 0 \<and> (\<exists>p. raw_has_prod f (Suc i) p))"

    98   by (simp add: has_prod_def)

    99

   100 lemma has_prod_unique2:

   101   fixes f :: "nat \<Rightarrow> 'a::{semidom,t2_space}"

   102   assumes "f has_prod a" "f has_prod b" shows "a = b"

   103   using assms

   104   by (auto simp: has_prod_def raw_has_prod_eq_0) (meson raw_has_prod_def sequentially_bot tendsto_unique)

   105

   106 lemma has_prod_unique:

   107   fixes f :: "nat \<Rightarrow> 'a :: {semidom,t2_space}"

   108   shows "f has_prod s \<Longrightarrow> s = prodinf f"

   109   by (simp add: has_prod_unique2 prodinf_def the_equality)

   110

   111 lemma convergent_prod_altdef:

   112   fixes f :: "nat \<Rightarrow> 'a :: {t2_space,comm_semiring_1}"

   113   shows "convergent_prod f \<longleftrightarrow> (\<exists>M L. (\<forall>n\<ge>M. f n \<noteq> 0) \<and> (\<lambda>n. \<Prod>i\<le>n. f (i+M)) \<longlonglongrightarrow> L \<and> L \<noteq> 0)"

   114 proof

   115   assume "convergent_prod f"

   116   then obtain M L where *: "(\<lambda>n. \<Prod>i\<le>n. f (i+M)) \<longlonglongrightarrow> L" "L \<noteq> 0"

   117     by (auto simp: prod_defs)

   118   have "f i \<noteq> 0" if "i \<ge> M" for i

   119   proof

   120     assume "f i = 0"

   121     have **: "eventually (\<lambda>n. (\<Prod>i\<le>n. f (i+M)) = 0) sequentially"

   122       using eventually_ge_at_top[of "i - M"]

   123     proof eventually_elim

   124       case (elim n)

   125       with \<open>f i = 0\<close> and \<open>i \<ge> M\<close> show ?case

   126         by (auto intro!: bexI[of _ "i - M"] prod_zero)

   127     qed

   128     have "(\<lambda>n. (\<Prod>i\<le>n. f (i+M))) \<longlonglongrightarrow> 0"

   129       unfolding filterlim_iff

   130       by (auto dest!: eventually_nhds_x_imp_x intro!: eventually_mono[OF **])

   131     from tendsto_unique[OF _ this *(1)] and *(2)

   132       show False by simp

   133   qed

   134   with * show "(\<exists>M L. (\<forall>n\<ge>M. f n \<noteq> 0) \<and> (\<lambda>n. \<Prod>i\<le>n. f (i+M)) \<longlonglongrightarrow> L \<and> L \<noteq> 0)"

   135     by blast

   136 qed (auto simp: prod_defs)

   137

   138 definition abs_convergent_prod :: "(nat \<Rightarrow> _) \<Rightarrow> bool" where

   139   "abs_convergent_prod f \<longleftrightarrow> convergent_prod (\<lambda>i. 1 + norm (f i - 1))"

   140

   141 lemma abs_convergent_prodI:

   142   assumes "convergent (\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1))"

   143   shows   "abs_convergent_prod f"

   144 proof -

   145   from assms obtain L where L: "(\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1)) \<longlonglongrightarrow> L"

   146     by (auto simp: convergent_def)

   147   have "L \<ge> 1"

   148   proof (rule tendsto_le)

   149     show "eventually (\<lambda>n. (\<Prod>i\<le>n. 1 + norm (f i - 1)) \<ge> 1) sequentially"

   150     proof (intro always_eventually allI)

   151       fix n

   152       have "(\<Prod>i\<le>n. 1 + norm (f i - 1)) \<ge> (\<Prod>i\<le>n. 1)"

   153         by (intro prod_mono) auto

   154       thus "(\<Prod>i\<le>n. 1 + norm (f i - 1)) \<ge> 1" by simp

   155     qed

   156   qed (use L in simp_all)

   157   hence "L \<noteq> 0" by auto

   158   with L show ?thesis unfolding abs_convergent_prod_def prod_defs

   159     by (intro exI[of _ "0::nat"] exI[of _ L]) auto

   160 qed

   161

   162 lemma

   163   fixes f :: "nat \<Rightarrow> 'a :: {topological_semigroup_mult,t2_space,idom}"

   164   assumes "convergent_prod f"

   165   shows   convergent_prod_imp_convergent: "convergent (\<lambda>n. \<Prod>i\<le>n. f i)"

   166     and   convergent_prod_to_zero_iff:    "(\<lambda>n. \<Prod>i\<le>n. f i) \<longlonglongrightarrow> 0 \<longleftrightarrow> (\<exists>i. f i = 0)"

   167 proof -

   168   from assms obtain M L

   169     where M: "\<And>n. n \<ge> M \<Longrightarrow> f n \<noteq> 0" and "(\<lambda>n. \<Prod>i\<le>n. f (i + M)) \<longlonglongrightarrow> L" and "L \<noteq> 0"

   170     by (auto simp: convergent_prod_altdef)

   171   note this(2)

   172   also have "(\<lambda>n. \<Prod>i\<le>n. f (i + M)) = (\<lambda>n. \<Prod>i=M..M+n. f i)"

   173     by (intro ext prod.reindex_bij_witness[of _ "\<lambda>n. n - M" "\<lambda>n. n + M"]) auto

   174   finally have "(\<lambda>n. (\<Prod>i<M. f i) * (\<Prod>i=M..M+n. f i)) \<longlonglongrightarrow> (\<Prod>i<M. f i) * L"

   175     by (intro tendsto_mult tendsto_const)

   176   also have "(\<lambda>n. (\<Prod>i<M. f i) * (\<Prod>i=M..M+n. f i)) = (\<lambda>n. (\<Prod>i\<in>{..<M}\<union>{M..M+n}. f i))"

   177     by (subst prod.union_disjoint) auto

   178   also have "(\<lambda>n. {..<M} \<union> {M..M+n}) = (\<lambda>n. {..n+M})" by auto

   179   finally have lim: "(\<lambda>n. prod f {..n}) \<longlonglongrightarrow> prod f {..<M} * L"

   180     by (rule LIMSEQ_offset)

   181   thus "convergent (\<lambda>n. \<Prod>i\<le>n. f i)"

   182     by (auto simp: convergent_def)

   183

   184   show "(\<lambda>n. \<Prod>i\<le>n. f i) \<longlonglongrightarrow> 0 \<longleftrightarrow> (\<exists>i. f i = 0)"

   185   proof

   186     assume "\<exists>i. f i = 0"

   187     then obtain i where "f i = 0" by auto

   188     moreover with M have "i < M" by (cases "i < M") auto

   189     ultimately have "(\<Prod>i<M. f i) = 0" by auto

   190     with lim show "(\<lambda>n. \<Prod>i\<le>n. f i) \<longlonglongrightarrow> 0" by simp

   191   next

   192     assume "(\<lambda>n. \<Prod>i\<le>n. f i) \<longlonglongrightarrow> 0"

   193     from tendsto_unique[OF _ this lim] and \<open>L \<noteq> 0\<close>

   194     show "\<exists>i. f i = 0" by auto

   195   qed

   196 qed

   197

   198 lemma convergent_prod_iff_nz_lim:

   199   fixes f :: "nat \<Rightarrow> 'a :: {topological_semigroup_mult,t2_space,idom}"

   200   assumes "\<And>i. f i \<noteq> 0"

   201   shows "convergent_prod f \<longleftrightarrow> (\<exists>L. (\<lambda>n. \<Prod>i\<le>n. f i) \<longlonglongrightarrow> L \<and> L \<noteq> 0)"

   202     (is "?lhs \<longleftrightarrow> ?rhs")

   203 proof

   204   assume ?lhs then show ?rhs

   205     using assms convergentD convergent_prod_imp_convergent convergent_prod_to_zero_iff by blast

   206 next

   207   assume ?rhs then show ?lhs

   208     unfolding prod_defs

   209     by (rule_tac x=0 in exI) auto

   210 qed

   211

   212 lemma convergent_prod_iff_convergent:

   213   fixes f :: "nat \<Rightarrow> 'a :: {topological_semigroup_mult,t2_space,idom}"

   214   assumes "\<And>i. f i \<noteq> 0"

   215   shows "convergent_prod f \<longleftrightarrow> convergent (\<lambda>n. \<Prod>i\<le>n. f i) \<and> lim (\<lambda>n. \<Prod>i\<le>n. f i) \<noteq> 0"

   216   by (force simp: convergent_prod_iff_nz_lim assms convergent_def limI)

   217

   218

   219 lemma abs_convergent_prod_altdef:

   220   fixes f :: "nat \<Rightarrow> 'a :: {one,real_normed_vector}"

   221   shows  "abs_convergent_prod f \<longleftrightarrow> convergent (\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1))"

   222 proof

   223   assume "abs_convergent_prod f"

   224   thus "convergent (\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1))"

   225     by (auto simp: abs_convergent_prod_def intro!: convergent_prod_imp_convergent)

   226 qed (auto intro: abs_convergent_prodI)

   227

   228 lemma weierstrass_prod_ineq:

   229   fixes f :: "'a \<Rightarrow> real"

   230   assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<in> {0..1}"

   231   shows   "1 - sum f A \<le> (\<Prod>x\<in>A. 1 - f x)"

   232   using assms

   233 proof (induction A rule: infinite_finite_induct)

   234   case (insert x A)

   235   from insert.hyps and insert.prems

   236     have "1 - sum f A + f x * (\<Prod>x\<in>A. 1 - f x) \<le> (\<Prod>x\<in>A. 1 - f x) + f x * (\<Prod>x\<in>A. 1)"

   237     by (intro insert.IH add_mono mult_left_mono prod_mono) auto

   238   with insert.hyps show ?case by (simp add: algebra_simps)

   239 qed simp_all

   240

   241 lemma norm_prod_minus1_le_prod_minus1:

   242   fixes f :: "nat \<Rightarrow> 'a :: {real_normed_div_algebra,comm_ring_1}"

   243   shows "norm (prod (\<lambda>n. 1 + f n) A - 1) \<le> prod (\<lambda>n. 1 + norm (f n)) A - 1"

   244 proof (induction A rule: infinite_finite_induct)

   245   case (insert x A)

   246   from insert.hyps have

   247     "norm ((\<Prod>n\<in>insert x A. 1 + f n) - 1) =

   248        norm ((\<Prod>n\<in>A. 1 + f n) - 1 + f x * (\<Prod>n\<in>A. 1 + f n))"

   249     by (simp add: algebra_simps)

   250   also have "\<dots> \<le> norm ((\<Prod>n\<in>A. 1 + f n) - 1) + norm (f x * (\<Prod>n\<in>A. 1 + f n))"

   251     by (rule norm_triangle_ineq)

   252   also have "norm (f x * (\<Prod>n\<in>A. 1 + f n)) = norm (f x) * (\<Prod>x\<in>A. norm (1 + f x))"

   253     by (simp add: prod_norm norm_mult)

   254   also have "(\<Prod>x\<in>A. norm (1 + f x)) \<le> (\<Prod>x\<in>A. norm (1::'a) + norm (f x))"

   255     by (intro prod_mono norm_triangle_ineq ballI conjI) auto

   256   also have "norm (1::'a) = 1" by simp

   257   also note insert.IH

   258   also have "(\<Prod>n\<in>A. 1 + norm (f n)) - 1 + norm (f x) * (\<Prod>x\<in>A. 1 + norm (f x)) =

   259              (\<Prod>n\<in>insert x A. 1 + norm (f n)) - 1"

   260     using insert.hyps by (simp add: algebra_simps)

   261   finally show ?case by - (simp_all add: mult_left_mono)

   262 qed simp_all

   263

   264 lemma convergent_prod_imp_ev_nonzero:

   265   fixes f :: "nat \<Rightarrow> 'a :: {t2_space,comm_semiring_1}"

   266   assumes "convergent_prod f"

   267   shows   "eventually (\<lambda>n. f n \<noteq> 0) sequentially"

   268   using assms by (auto simp: eventually_at_top_linorder convergent_prod_altdef)

   269

   270 lemma convergent_prod_imp_LIMSEQ:

   271   fixes f :: "nat \<Rightarrow> 'a :: {real_normed_field}"

   272   assumes "convergent_prod f"

   273   shows   "f \<longlonglongrightarrow> 1"

   274 proof -

   275   from assms obtain M L where L: "(\<lambda>n. \<Prod>i\<le>n. f (i+M)) \<longlonglongrightarrow> L" "\<And>n. n \<ge> M \<Longrightarrow> f n \<noteq> 0" "L \<noteq> 0"

   276     by (auto simp: convergent_prod_altdef)

   277   hence L': "(\<lambda>n. \<Prod>i\<le>Suc n. f (i+M)) \<longlonglongrightarrow> L" by (subst filterlim_sequentially_Suc)

   278   have "(\<lambda>n. (\<Prod>i\<le>Suc n. f (i+M)) / (\<Prod>i\<le>n. f (i+M))) \<longlonglongrightarrow> L / L"

   279     using L L' by (intro tendsto_divide) simp_all

   280   also from L have "L / L = 1" by simp

   281   also have "(\<lambda>n. (\<Prod>i\<le>Suc n. f (i+M)) / (\<Prod>i\<le>n. f (i+M))) = (\<lambda>n. f (n + Suc M))"

   282     using assms L by (auto simp: fun_eq_iff atMost_Suc)

   283   finally show ?thesis by (rule LIMSEQ_offset)

   284 qed

   285

   286 lemma abs_convergent_prod_imp_summable:

   287   fixes f :: "nat \<Rightarrow> 'a :: real_normed_div_algebra"

   288   assumes "abs_convergent_prod f"

   289   shows "summable (\<lambda>i. norm (f i - 1))"

   290 proof -

   291   from assms have "convergent (\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1))"

   292     unfolding abs_convergent_prod_def by (rule convergent_prod_imp_convergent)

   293   then obtain L where L: "(\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1)) \<longlonglongrightarrow> L"

   294     unfolding convergent_def by blast

   295   have "convergent (\<lambda>n. \<Sum>i\<le>n. norm (f i - 1))"

   296   proof (rule Bseq_monoseq_convergent)

   297     have "eventually (\<lambda>n. (\<Prod>i\<le>n. 1 + norm (f i - 1)) < L + 1) sequentially"

   298       using L(1) by (rule order_tendstoD) simp_all

   299     hence "\<forall>\<^sub>F x in sequentially. norm (\<Sum>i\<le>x. norm (f i - 1)) \<le> L + 1"

   300     proof eventually_elim

   301       case (elim n)

   302       have "norm (\<Sum>i\<le>n. norm (f i - 1)) = (\<Sum>i\<le>n. norm (f i - 1))"

   303         unfolding real_norm_def by (intro abs_of_nonneg sum_nonneg) simp_all

   304       also have "\<dots> \<le> (\<Prod>i\<le>n. 1 + norm (f i - 1))" by (rule sum_le_prod) auto

   305       also have "\<dots> < L + 1" by (rule elim)

   306       finally show ?case by simp

   307     qed

   308     thus "Bseq (\<lambda>n. \<Sum>i\<le>n. norm (f i - 1))" by (rule BfunI)

   309   next

   310     show "monoseq (\<lambda>n. \<Sum>i\<le>n. norm (f i - 1))"

   311       by (rule mono_SucI1) auto

   312   qed

   313   thus "summable (\<lambda>i. norm (f i - 1))" by (simp add: summable_iff_convergent')

   314 qed

   315

   316 lemma summable_imp_abs_convergent_prod:

   317   fixes f :: "nat \<Rightarrow> 'a :: real_normed_div_algebra"

   318   assumes "summable (\<lambda>i. norm (f i - 1))"

   319   shows   "abs_convergent_prod f"

   320 proof (intro abs_convergent_prodI Bseq_monoseq_convergent)

   321   show "monoseq (\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1))"

   322     by (intro mono_SucI1)

   323        (auto simp: atMost_Suc algebra_simps intro!: mult_nonneg_nonneg prod_nonneg)

   324 next

   325   show "Bseq (\<lambda>n. \<Prod>i\<le>n. 1 + norm (f i - 1))"

   326   proof (rule Bseq_eventually_mono)

   327     show "eventually (\<lambda>n. norm (\<Prod>i\<le>n. 1 + norm (f i - 1)) \<le>

   328             norm (exp (\<Sum>i\<le>n. norm (f i - 1)))) sequentially"

   329       by (intro always_eventually allI) (auto simp: abs_prod exp_sum intro!: prod_mono)

   330   next

   331     from assms have "(\<lambda>n. \<Sum>i\<le>n. norm (f i - 1)) \<longlonglongrightarrow> (\<Sum>i. norm (f i - 1))"

   332       using sums_def_le by blast

   333     hence "(\<lambda>n. exp (\<Sum>i\<le>n. norm (f i - 1))) \<longlonglongrightarrow> exp (\<Sum>i. norm (f i - 1))"

   334       by (rule tendsto_exp)

   335     hence "convergent (\<lambda>n. exp (\<Sum>i\<le>n. norm (f i - 1)))"

   336       by (rule convergentI)

   337     thus "Bseq (\<lambda>n. exp (\<Sum>i\<le>n. norm (f i - 1)))"

   338       by (rule convergent_imp_Bseq)

   339   qed

   340 qed

   341

   342 lemma abs_convergent_prod_conv_summable:

   343   fixes f :: "nat \<Rightarrow> 'a :: real_normed_div_algebra"

   344   shows "abs_convergent_prod f \<longleftrightarrow> summable (\<lambda>i. norm (f i - 1))"

   345   by (blast intro: abs_convergent_prod_imp_summable summable_imp_abs_convergent_prod)

   346

   347 lemma abs_convergent_prod_imp_LIMSEQ:

   348   fixes f :: "nat \<Rightarrow> 'a :: {comm_ring_1,real_normed_div_algebra}"

   349   assumes "abs_convergent_prod f"

   350   shows   "f \<longlonglongrightarrow> 1"

   351 proof -

   352   from assms have "summable (\<lambda>n. norm (f n - 1))"

   353     by (rule abs_convergent_prod_imp_summable)

   354   from summable_LIMSEQ_zero[OF this] have "(\<lambda>n. f n - 1) \<longlonglongrightarrow> 0"

   355     by (simp add: tendsto_norm_zero_iff)

   356   from tendsto_add[OF this tendsto_const[of 1]] show ?thesis by simp

   357 qed

   358

   359 lemma abs_convergent_prod_imp_ev_nonzero:

   360   fixes f :: "nat \<Rightarrow> 'a :: {comm_ring_1,real_normed_div_algebra}"

   361   assumes "abs_convergent_prod f"

   362   shows   "eventually (\<lambda>n. f n \<noteq> 0) sequentially"

   363 proof -

   364   from assms have "f \<longlonglongrightarrow> 1"

   365     by (rule abs_convergent_prod_imp_LIMSEQ)

   366   hence "eventually (\<lambda>n. dist (f n) 1 < 1) at_top"

   367     by (auto simp: tendsto_iff)

   368   thus ?thesis by eventually_elim auto

   369 qed

   370

   371 lemma convergent_prod_offset:

   372   assumes "convergent_prod (\<lambda>n. f (n + m))"

   373   shows   "convergent_prod f"

   374 proof -

   375   from assms obtain M L where "(\<lambda>n. \<Prod>k\<le>n. f (k + (M + m))) \<longlonglongrightarrow> L" "L \<noteq> 0"

   376     by (auto simp: prod_defs add.assoc)

   377   thus "convergent_prod f"

   378     unfolding prod_defs by blast

   379 qed

   380

   381 lemma abs_convergent_prod_offset:

   382   assumes "abs_convergent_prod (\<lambda>n. f (n + m))"

   383   shows   "abs_convergent_prod f"

   384   using assms unfolding abs_convergent_prod_def by (rule convergent_prod_offset)

   385

   386 lemma raw_has_prod_ignore_initial_segment:

   387   fixes f :: "nat \<Rightarrow> 'a :: real_normed_field"

   388   assumes "raw_has_prod f M p" "N \<ge> M"

   389   obtains q where  "raw_has_prod f N q"

   390 proof -

   391   have p: "(\<lambda>n. \<Prod>k\<le>n. f (k + M)) \<longlonglongrightarrow> p" and "p \<noteq> 0"

   392     using assms by (auto simp: raw_has_prod_def)

   393   then have nz: "\<And>n. n \<ge> M \<Longrightarrow> f n \<noteq> 0"

   394     using assms by (auto simp: raw_has_prod_eq_0)

   395   define C where "C = (\<Prod>k<N-M. f (k + M))"

   396   from nz have [simp]: "C \<noteq> 0"

   397     by (auto simp: C_def)

   398

   399   from p have "(\<lambda>i. \<Prod>k\<le>i + (N-M). f (k + M)) \<longlonglongrightarrow> p"

   400     by (rule LIMSEQ_ignore_initial_segment)

   401   also have "(\<lambda>i. \<Prod>k\<le>i + (N-M). f (k + M)) = (\<lambda>n. C * (\<Prod>k\<le>n. f (k + N)))"

   402   proof (rule ext, goal_cases)

   403     case (1 n)

   404     have "{..n+(N-M)} = {..<(N-M)} \<union> {(N-M)..n+(N-M)}" by auto

   405     also have "(\<Prod>k\<in>\<dots>. f (k + M)) = C * (\<Prod>k=(N-M)..n+(N-M). f (k + M))"

   406       unfolding C_def by (rule prod.union_disjoint) auto

   407     also have "(\<Prod>k=(N-M)..n+(N-M). f (k + M)) = (\<Prod>k\<le>n. f (k + (N-M) + M))"

   408       by (intro ext prod.reindex_bij_witness[of _ "\<lambda>k. k + (N-M)" "\<lambda>k. k - (N-M)"]) auto

   409     finally show ?case

   410       using \<open>N \<ge> M\<close> by (simp add: add_ac)

   411   qed

   412   finally have "(\<lambda>n. C * (\<Prod>k\<le>n. f (k + N)) / C) \<longlonglongrightarrow> p / C"

   413     by (intro tendsto_divide tendsto_const) auto

   414   hence "(\<lambda>n. \<Prod>k\<le>n. f (k + N)) \<longlonglongrightarrow> p / C" by simp

   415   moreover from \<open>p \<noteq> 0\<close> have "p / C \<noteq> 0" by simp

   416   ultimately show ?thesis

   417     using raw_has_prod_def that by blast

   418 qed

   419

   420 corollary convergent_prod_ignore_initial_segment:

   421   fixes f :: "nat \<Rightarrow> 'a :: real_normed_field"

   422   assumes "convergent_prod f"

   423   shows   "convergent_prod (\<lambda>n. f (n + m))"

   424   using assms

   425   unfolding convergent_prod_def

   426   apply clarify

   427   apply (erule_tac N="M+m" in raw_has_prod_ignore_initial_segment)

   428   apply (auto simp add: raw_has_prod_def add_ac)

   429   done

   430

   431 corollary convergent_prod_ignore_nonzero_segment:

   432   fixes f :: "nat \<Rightarrow> 'a :: real_normed_field"

   433   assumes f: "convergent_prod f" and nz: "\<And>i. i \<ge> M \<Longrightarrow> f i \<noteq> 0"

   434   shows "\<exists>p. raw_has_prod f M p"

   435   using convergent_prod_ignore_initial_segment [OF f]

   436   by (metis convergent_LIMSEQ_iff convergent_prod_iff_convergent le_add_same_cancel2 nz prod_defs(1) zero_order(1))

   437

   438 corollary abs_convergent_prod_ignore_initial_segment:

   439   assumes "abs_convergent_prod f"

   440   shows   "abs_convergent_prod (\<lambda>n. f (n + m))"

   441   using assms unfolding abs_convergent_prod_def

   442   by (rule convergent_prod_ignore_initial_segment)

   443

   444 lemma abs_convergent_prod_imp_convergent_prod:

   445   fixes f :: "nat \<Rightarrow> 'a :: {real_normed_div_algebra,complete_space,comm_ring_1}"

   446   assumes "abs_convergent_prod f"

   447   shows   "convergent_prod f"

   448 proof -

   449   from assms have "eventually (\<lambda>n. f n \<noteq> 0) sequentially"

   450     by (rule abs_convergent_prod_imp_ev_nonzero)

   451   then obtain N where N: "f n \<noteq> 0" if "n \<ge> N" for n

   452     by (auto simp: eventually_at_top_linorder)

   453   let ?P = "\<lambda>n. \<Prod>i\<le>n. f (i + N)" and ?Q = "\<lambda>n. \<Prod>i\<le>n. 1 + norm (f (i + N) - 1)"

   454

   455   have "Cauchy ?P"

   456   proof (rule CauchyI', goal_cases)

   457     case (1 \<epsilon>)

   458     from assms have "abs_convergent_prod (\<lambda>n. f (n + N))"

   459       by (rule abs_convergent_prod_ignore_initial_segment)

   460     hence "Cauchy ?Q"

   461       unfolding abs_convergent_prod_def

   462       by (intro convergent_Cauchy convergent_prod_imp_convergent)

   463     from CauchyD[OF this 1] obtain M where M: "norm (?Q m - ?Q n) < \<epsilon>" if "m \<ge> M" "n \<ge> M" for m n

   464       by blast

   465     show ?case

   466     proof (rule exI[of _ M], safe, goal_cases)

   467       case (1 m n)

   468       have "dist (?P m) (?P n) = norm (?P n - ?P m)"

   469         by (simp add: dist_norm norm_minus_commute)

   470       also from 1 have "{..n} = {..m} \<union> {m<..n}" by auto

   471       hence "norm (?P n - ?P m) = norm (?P m * (\<Prod>k\<in>{m<..n}. f (k + N)) - ?P m)"

   472         by (subst prod.union_disjoint [symmetric]) (auto simp: algebra_simps)

   473       also have "\<dots> = norm (?P m * ((\<Prod>k\<in>{m<..n}. f (k + N)) - 1))"

   474         by (simp add: algebra_simps)

   475       also have "\<dots> = (\<Prod>k\<le>m. norm (f (k + N))) * norm ((\<Prod>k\<in>{m<..n}. f (k + N)) - 1)"

   476         by (simp add: norm_mult prod_norm)

   477       also have "\<dots> \<le> ?Q m * ((\<Prod>k\<in>{m<..n}. 1 + norm (f (k + N) - 1)) - 1)"

   478         using norm_prod_minus1_le_prod_minus1[of "\<lambda>k. f (k + N) - 1" "{m<..n}"]

   479               norm_triangle_ineq[of 1 "f k - 1" for k]

   480         by (intro mult_mono prod_mono ballI conjI norm_prod_minus1_le_prod_minus1 prod_nonneg) auto

   481       also have "\<dots> = ?Q m * (\<Prod>k\<in>{m<..n}. 1 + norm (f (k + N) - 1)) - ?Q m"

   482         by (simp add: algebra_simps)

   483       also have "?Q m * (\<Prod>k\<in>{m<..n}. 1 + norm (f (k + N) - 1)) =

   484                    (\<Prod>k\<in>{..m}\<union>{m<..n}. 1 + norm (f (k + N) - 1))"

   485         by (rule prod.union_disjoint [symmetric]) auto

   486       also from 1 have "{..m}\<union>{m<..n} = {..n}" by auto

   487       also have "?Q n - ?Q m \<le> norm (?Q n - ?Q m)" by simp

   488       also from 1 have "\<dots> < \<epsilon>" by (intro M) auto

   489       finally show ?case .

   490     qed

   491   qed

   492   hence conv: "convergent ?P" by (rule Cauchy_convergent)

   493   then obtain L where L: "?P \<longlonglongrightarrow> L"

   494     by (auto simp: convergent_def)

   495

   496   have "L \<noteq> 0"

   497   proof

   498     assume [simp]: "L = 0"

   499     from tendsto_norm[OF L] have limit: "(\<lambda>n. \<Prod>k\<le>n. norm (f (k + N))) \<longlonglongrightarrow> 0"

   500       by (simp add: prod_norm)

   501

   502     from assms have "(\<lambda>n. f (n + N)) \<longlonglongrightarrow> 1"

   503       by (intro abs_convergent_prod_imp_LIMSEQ abs_convergent_prod_ignore_initial_segment)

   504     hence "eventually (\<lambda>n. norm (f (n + N) - 1) < 1) sequentially"

   505       by (auto simp: tendsto_iff dist_norm)

   506     then obtain M0 where M0: "norm (f (n + N) - 1) < 1" if "n \<ge> M0" for n

   507       by (auto simp: eventually_at_top_linorder)

   508

   509     {

   510       fix M assume M: "M \<ge> M0"

   511       with M0 have M: "norm (f (n + N) - 1) < 1" if "n \<ge> M" for n using that by simp

   512

   513       have "(\<lambda>n. \<Prod>k\<le>n. 1 - norm (f (k+M+N) - 1)) \<longlonglongrightarrow> 0"

   514       proof (rule tendsto_sandwich)

   515         show "eventually (\<lambda>n. (\<Prod>k\<le>n. 1 - norm (f (k+M+N) - 1)) \<ge> 0) sequentially"

   516           using M by (intro always_eventually prod_nonneg allI ballI) (auto intro: less_imp_le)

   517         have "norm (1::'a) - norm (f (i + M + N) - 1) \<le> norm (f (i + M + N))" for i

   518           using norm_triangle_ineq3[of "f (i + M + N)" 1] by simp

   519         thus "eventually (\<lambda>n. (\<Prod>k\<le>n. 1 - norm (f (k+M+N) - 1)) \<le> (\<Prod>k\<le>n. norm (f (k+M+N)))) at_top"

   520           using M by (intro always_eventually allI prod_mono ballI conjI) (auto intro: less_imp_le)

   521

   522         define C where "C = (\<Prod>k<M. norm (f (k + N)))"

   523         from N have [simp]: "C \<noteq> 0" by (auto simp: C_def)

   524         from L have "(\<lambda>n. norm (\<Prod>k\<le>n+M. f (k + N))) \<longlonglongrightarrow> 0"

   525           by (intro LIMSEQ_ignore_initial_segment) (simp add: tendsto_norm_zero_iff)

   526         also have "(\<lambda>n. norm (\<Prod>k\<le>n+M. f (k + N))) = (\<lambda>n. C * (\<Prod>k\<le>n. norm (f (k + M + N))))"

   527         proof (rule ext, goal_cases)

   528           case (1 n)

   529           have "{..n+M} = {..<M} \<union> {M..n+M}" by auto

   530           also have "norm (\<Prod>k\<in>\<dots>. f (k + N)) = C * norm (\<Prod>k=M..n+M. f (k + N))"

   531             unfolding C_def by (subst prod.union_disjoint) (auto simp: norm_mult prod_norm)

   532           also have "(\<Prod>k=M..n+M. f (k + N)) = (\<Prod>k\<le>n. f (k + N + M))"

   533             by (intro prod.reindex_bij_witness[of _ "\<lambda>i. i + M" "\<lambda>i. i - M"]) auto

   534           finally show ?case by (simp add: add_ac prod_norm)

   535         qed

   536         finally have "(\<lambda>n. C * (\<Prod>k\<le>n. norm (f (k + M + N))) / C) \<longlonglongrightarrow> 0 / C"

   537           by (intro tendsto_divide tendsto_const) auto

   538         thus "(\<lambda>n. \<Prod>k\<le>n. norm (f (k + M + N))) \<longlonglongrightarrow> 0" by simp

   539       qed simp_all

   540

   541       have "1 - (\<Sum>i. norm (f (i + M + N) - 1)) \<le> 0"

   542       proof (rule tendsto_le)

   543         show "eventually (\<lambda>n. 1 - (\<Sum>k\<le>n. norm (f (k+M+N) - 1)) \<le>

   544                                 (\<Prod>k\<le>n. 1 - norm (f (k+M+N) - 1))) at_top"

   545           using M by (intro always_eventually allI weierstrass_prod_ineq) (auto intro: less_imp_le)

   546         show "(\<lambda>n. \<Prod>k\<le>n. 1 - norm (f (k+M+N) - 1)) \<longlonglongrightarrow> 0" by fact

   547         show "(\<lambda>n. 1 - (\<Sum>k\<le>n. norm (f (k + M + N) - 1)))

   548                   \<longlonglongrightarrow> 1 - (\<Sum>i. norm (f (i + M + N) - 1))"

   549           by (intro tendsto_intros summable_LIMSEQ' summable_ignore_initial_segment

   550                 abs_convergent_prod_imp_summable assms)

   551       qed simp_all

   552       hence "(\<Sum>i. norm (f (i + M + N) - 1)) \<ge> 1" by simp

   553       also have "\<dots> + (\<Sum>i<M. norm (f (i + N) - 1)) = (\<Sum>i. norm (f (i + N) - 1))"

   554         by (intro suminf_split_initial_segment [symmetric] summable_ignore_initial_segment

   555               abs_convergent_prod_imp_summable assms)

   556       finally have "1 + (\<Sum>i<M. norm (f (i + N) - 1)) \<le> (\<Sum>i. norm (f (i + N) - 1))" by simp

   557     } note * = this

   558

   559     have "1 + (\<Sum>i. norm (f (i + N) - 1)) \<le> (\<Sum>i. norm (f (i + N) - 1))"

   560     proof (rule tendsto_le)

   561       show "(\<lambda>M. 1 + (\<Sum>i<M. norm (f (i + N) - 1))) \<longlonglongrightarrow> 1 + (\<Sum>i. norm (f (i + N) - 1))"

   562         by (intro tendsto_intros summable_LIMSEQ summable_ignore_initial_segment

   563                 abs_convergent_prod_imp_summable assms)

   564       show "eventually (\<lambda>M. 1 + (\<Sum>i<M. norm (f (i + N) - 1)) \<le> (\<Sum>i. norm (f (i + N) - 1))) at_top"

   565         using eventually_ge_at_top[of M0] by eventually_elim (use * in auto)

   566     qed simp_all

   567     thus False by simp

   568   qed

   569   with L show ?thesis by (auto simp: prod_defs)

   570 qed

   571

   572 lemma raw_has_prod_cases:

   573   fixes f :: "nat \<Rightarrow> 'a :: {idom,topological_semigroup_mult,t2_space}"

   574   assumes "raw_has_prod f M p"

   575   obtains i where "i<M" "f i = 0" | p where "raw_has_prod f 0 p"

   576 proof -

   577   have "(\<lambda>n. \<Prod>i\<le>n. f (i + M)) \<longlonglongrightarrow> p" "p \<noteq> 0"

   578     using assms unfolding raw_has_prod_def by blast+

   579   then have "(\<lambda>n. prod f {..<M} * (\<Prod>i\<le>n. f (i + M))) \<longlonglongrightarrow> prod f {..<M} * p"

   580     by (metis tendsto_mult_left)

   581   moreover have "prod f {..<M} * (\<Prod>i\<le>n. f (i + M)) = prod f {..n+M}" for n

   582   proof -

   583     have "{..n+M} = {..<M} \<union> {M..n+M}"

   584       by auto

   585     then have "prod f {..n+M} = prod f {..<M} * prod f {M..n+M}"

   586       by simp (subst prod.union_disjoint; force)

   587     also have "\<dots> = prod f {..<M} * (\<Prod>i\<le>n. f (i + M))"

   588       by (metis (mono_tags, lifting) add.left_neutral atMost_atLeast0 prod_shift_bounds_cl_nat_ivl)

   589     finally show ?thesis by metis

   590   qed

   591   ultimately have "(\<lambda>n. prod f {..n}) \<longlonglongrightarrow> prod f {..<M} * p"

   592     by (auto intro: LIMSEQ_offset [where k=M])

   593   then have "raw_has_prod f 0 (prod f {..<M} * p)" if "\<forall>i<M. f i \<noteq> 0"

   594     using \<open>p \<noteq> 0\<close> assms that by (auto simp: raw_has_prod_def)

   595   then show thesis

   596     using that by blast

   597 qed

   598

   599 corollary convergent_prod_offset_0:

   600   fixes f :: "nat \<Rightarrow> 'a :: {idom,topological_semigroup_mult,t2_space}"

   601   assumes "convergent_prod f" "\<And>i. f i \<noteq> 0"

   602   shows "\<exists>p. raw_has_prod f 0 p"

   603   using assms convergent_prod_def raw_has_prod_cases by blast

   604

   605 lemma prodinf_eq_lim:

   606   fixes f :: "nat \<Rightarrow> 'a :: {idom,topological_semigroup_mult,t2_space}"

   607   assumes "convergent_prod f" "\<And>i. f i \<noteq> 0"

   608   shows "prodinf f = lim (\<lambda>n. \<Prod>i\<le>n. f i)"

   609   using assms convergent_prod_offset_0 [OF assms]

   610   by (simp add: prod_defs lim_def) (metis (no_types) assms(1) convergent_prod_to_zero_iff)

   611

   612 lemma has_prod_one[simp, intro]: "(\<lambda>n. 1) has_prod 1"

   613   unfolding prod_defs by auto

   614

   615 lemma convergent_prod_one[simp, intro]: "convergent_prod (\<lambda>n. 1)"

   616   unfolding prod_defs by auto

   617

   618 lemma prodinf_cong: "(\<And>n. f n = g n) \<Longrightarrow> prodinf f = prodinf g"

   619   by presburger

   620

   621 lemma convergent_prod_cong:

   622   fixes f g :: "nat \<Rightarrow> 'a::{field,topological_semigroup_mult,t2_space}"

   623   assumes ev: "eventually (\<lambda>x. f x = g x) sequentially" and f: "\<And>i. f i \<noteq> 0" and g: "\<And>i. g i \<noteq> 0"

   624   shows "convergent_prod f = convergent_prod g"

   625 proof -

   626   from assms obtain N where N: "\<forall>n\<ge>N. f n = g n"

   627     by (auto simp: eventually_at_top_linorder)

   628   define C where "C = (\<Prod>k<N. f k / g k)"

   629   with g have "C \<noteq> 0"

   630     by (simp add: f)

   631   have *: "eventually (\<lambda>n. prod f {..n} = C * prod g {..n}) sequentially"

   632     using eventually_ge_at_top[of N]

   633   proof eventually_elim

   634     case (elim n)

   635     then have "{..n} = {..<N} \<union> {N..n}"

   636       by auto

   637     also have "prod f \<dots> = prod f {..<N} * prod f {N..n}"

   638       by (intro prod.union_disjoint) auto

   639     also from N have "prod f {N..n} = prod g {N..n}"

   640       by (intro prod.cong) simp_all

   641     also have "prod f {..<N} * prod g {N..n} = C * (prod g {..<N} * prod g {N..n})"

   642       unfolding C_def by (simp add: g prod_dividef)

   643     also have "prod g {..<N} * prod g {N..n} = prod g ({..<N} \<union> {N..n})"

   644       by (intro prod.union_disjoint [symmetric]) auto

   645     also from elim have "{..<N} \<union> {N..n} = {..n}"

   646       by auto

   647     finally show "prod f {..n} = C * prod g {..n}" .

   648   qed

   649   then have cong: "convergent (\<lambda>n. prod f {..n}) = convergent (\<lambda>n. C * prod g {..n})"

   650     by (rule convergent_cong)

   651   show ?thesis

   652   proof

   653     assume cf: "convergent_prod f"

   654     then have "\<not> (\<lambda>n. prod g {..n}) \<longlonglongrightarrow> 0"

   655       using tendsto_mult_left * convergent_prod_to_zero_iff f filterlim_cong by fastforce

   656     then show "convergent_prod g"

   657       by (metis convergent_mult_const_iff \<open>C \<noteq> 0\<close> cong cf convergent_LIMSEQ_iff convergent_prod_iff_convergent convergent_prod_imp_convergent g)

   658   next

   659     assume cg: "convergent_prod g"

   660     have "\<exists>a. C * a \<noteq> 0 \<and> (\<lambda>n. prod g {..n}) \<longlonglongrightarrow> a"

   661       by (metis (no_types) \<open>C \<noteq> 0\<close> cg convergent_prod_iff_nz_lim divide_eq_0_iff g nonzero_mult_div_cancel_right)

   662     then show "convergent_prod f"

   663       using "*" tendsto_mult_left filterlim_cong

   664       by (fastforce simp add: convergent_prod_iff_nz_lim f)

   665   qed

   666 qed

   667

   668 lemma has_prod_finite:

   669   fixes f :: "nat \<Rightarrow> 'a::{semidom,t2_space}"

   670   assumes [simp]: "finite N"

   671     and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 1"

   672   shows "f has_prod (\<Prod>n\<in>N. f n)"

   673 proof -

   674   have eq: "prod f {..n + Suc (Max N)} = prod f N" for n

   675   proof (rule prod.mono_neutral_right)

   676     show "N \<subseteq> {..n + Suc (Max N)}"

   677       by (auto simp: le_Suc_eq trans_le_add2)

   678     show "\<forall>i\<in>{..n + Suc (Max N)} - N. f i = 1"

   679       using f by blast

   680   qed auto

   681   show ?thesis

   682   proof (cases "\<forall>n\<in>N. f n \<noteq> 0")

   683     case True

   684     then have "prod f N \<noteq> 0"

   685       by simp

   686     moreover have "(\<lambda>n. prod f {..n}) \<longlonglongrightarrow> prod f N"

   687       by (rule LIMSEQ_offset[of _ "Suc (Max N)"]) (simp add: eq atLeast0LessThan del: add_Suc_right)

   688     ultimately show ?thesis

   689       by (simp add: raw_has_prod_def has_prod_def)

   690   next

   691     case False

   692     then obtain k where "k \<in> N" "f k = 0"

   693       by auto

   694     let ?Z = "{n \<in> N. f n = 0}"

   695     have maxge: "Max ?Z \<ge> n" if "f n = 0" for n

   696       using Max_ge [of ?Z] \<open>finite N\<close> \<open>f n = 0\<close>

   697       by (metis (mono_tags) Collect_mem_eq f finite_Collect_conjI mem_Collect_eq zero_neq_one)

   698     let ?q = "prod f {Suc (Max ?Z)..Max N}"

   699     have [simp]: "?q \<noteq> 0"

   700       using maxge Suc_n_not_le_n le_trans by force

   701     have eq: "(\<Prod>i\<le>n + Max N. f (Suc (i + Max ?Z))) = ?q" for n

   702     proof -

   703       have "(\<Prod>i\<le>n + Max N. f (Suc (i + Max ?Z))) = prod f {Suc (Max ?Z)..n + Max N + Suc (Max ?Z)}"

   704       proof (rule prod.reindex_cong [where l = "\<lambda>i. i + Suc (Max ?Z)", THEN sym])

   705         show "{Suc (Max ?Z)..n + Max N + Suc (Max ?Z)} = (\<lambda>i. i + Suc (Max ?Z))  {..n + Max N}"

   706           using le_Suc_ex by fastforce

   707       qed (auto simp: inj_on_def)

   708       also have "\<dots> = ?q"

   709         by (rule prod.mono_neutral_right)

   710            (use Max.coboundedI [OF \<open>finite N\<close>] f in \<open>force+\<close>)

   711       finally show ?thesis .

   712     qed

   713     have q: "raw_has_prod f (Suc (Max ?Z)) ?q"

   714     proof (simp add: raw_has_prod_def)

   715       show "(\<lambda>n. \<Prod>i\<le>n. f (Suc (i + Max ?Z))) \<longlonglongrightarrow> ?q"

   716         by (rule LIMSEQ_offset[of _ "(Max N)"]) (simp add: eq)

   717     qed

   718     show ?thesis

   719       unfolding has_prod_def

   720     proof (intro disjI2 exI conjI)

   721       show "prod f N = 0"

   722         using \<open>f k = 0\<close> \<open>k \<in> N\<close> \<open>finite N\<close> prod_zero by blast

   723       show "f (Max ?Z) = 0"

   724         using Max_in [of ?Z] \<open>finite N\<close> \<open>f k = 0\<close> \<open>k \<in> N\<close> by auto

   725     qed (use q in auto)

   726   qed

   727 qed

   728

   729 corollary has_prod_0:

   730   fixes f :: "nat \<Rightarrow> 'a::{semidom,t2_space}"

   731   assumes "\<And>n. f n = 1"

   732   shows "f has_prod 1"

   733   by (simp add: assms has_prod_cong)

   734

   735 lemma prodinf_zero[simp]: "prodinf (\<lambda>n. 1::'a::real_normed_field) = 1"

   736   using has_prod_unique by force

   737

   738 lemma convergent_prod_finite:

   739   fixes f :: "nat \<Rightarrow> 'a::{idom,t2_space}"

   740   assumes "finite N" "\<And>n. n \<notin> N \<Longrightarrow> f n = 1"

   741   shows "convergent_prod f"

   742 proof -

   743   have "\<exists>n p. raw_has_prod f n p"

   744     using assms has_prod_def has_prod_finite by blast

   745   then show ?thesis

   746     by (simp add: convergent_prod_def)

   747 qed

   748

   749 lemma has_prod_If_finite_set:

   750   fixes f :: "nat \<Rightarrow> 'a::{idom,t2_space}"

   751   shows "finite A \<Longrightarrow> (\<lambda>r. if r \<in> A then f r else 1) has_prod (\<Prod>r\<in>A. f r)"

   752   using has_prod_finite[of A "(\<lambda>r. if r \<in> A then f r else 1)"]

   753   by simp

   754

   755 lemma has_prod_If_finite:

   756   fixes f :: "nat \<Rightarrow> 'a::{idom,t2_space}"

   757   shows "finite {r. P r} \<Longrightarrow> (\<lambda>r. if P r then f r else 1) has_prod (\<Prod>r | P r. f r)"

   758   using has_prod_If_finite_set[of "{r. P r}"] by simp

   759

   760 lemma convergent_prod_If_finite_set[simp, intro]:

   761   fixes f :: "nat \<Rightarrow> 'a::{idom,t2_space}"

   762   shows "finite A \<Longrightarrow> convergent_prod (\<lambda>r. if r \<in> A then f r else 1)"

   763   by (simp add: convergent_prod_finite)

   764

   765 lemma convergent_prod_If_finite[simp, intro]:

   766   fixes f :: "nat \<Rightarrow> 'a::{idom,t2_space}"

   767   shows "finite {r. P r} \<Longrightarrow> convergent_prod (\<lambda>r. if P r then f r else 1)"

   768   using convergent_prod_def has_prod_If_finite has_prod_def by fastforce

   769

   770 lemma has_prod_single:

   771   fixes f :: "nat \<Rightarrow> 'a::{idom,t2_space}"

   772   shows "(\<lambda>r. if r = i then f r else 1) has_prod f i"

   773   using has_prod_If_finite[of "\<lambda>r. r = i"] by simp

   774

   775 context

   776   fixes f :: "nat \<Rightarrow> 'a :: real_normed_field"

   777 begin

   778

   779 lemma convergent_prod_imp_has_prod:

   780   assumes "convergent_prod f"

   781   shows "\<exists>p. f has_prod p"

   782 proof -

   783   obtain M p where p: "raw_has_prod f M p"

   784     using assms convergent_prod_def by blast

   785   then have "p \<noteq> 0"

   786     using raw_has_prod_nonzero by blast

   787   with p have fnz: "f i \<noteq> 0" if "i \<ge> M" for i

   788     using raw_has_prod_eq_0 that by blast

   789   define C where "C = (\<Prod>n<M. f n)"

   790   show ?thesis

   791   proof (cases "\<forall>n\<le>M. f n \<noteq> 0")

   792     case True

   793     then have "C \<noteq> 0"

   794       by (simp add: C_def)

   795     then show ?thesis

   796       by (meson True assms convergent_prod_offset_0 fnz has_prod_def nat_le_linear)

   797   next

   798     case False

   799     let ?N = "GREATEST n. f n = 0"

   800     have 0: "f ?N = 0"

   801       using fnz False

   802       by (metis (mono_tags, lifting) GreatestI_ex_nat nat_le_linear)

   803     have "f i \<noteq> 0" if "i > ?N" for i

   804       by (metis (mono_tags, lifting) Greatest_le_nat fnz leD linear that)

   805     then have "\<exists>p. raw_has_prod f (Suc ?N) p"

   806       using assms by (auto simp: intro!: convergent_prod_ignore_nonzero_segment)

   807     then show ?thesis

   808       unfolding has_prod_def using 0 by blast

   809   qed

   810 qed

   811

   812 lemma convergent_prod_has_prod [intro]:

   813   shows "convergent_prod f \<Longrightarrow> f has_prod (prodinf f)"

   814   unfolding prodinf_def

   815   by (metis convergent_prod_imp_has_prod has_prod_unique theI')

   816

   817 lemma convergent_prod_LIMSEQ:

   818   shows "convergent_prod f \<Longrightarrow> (\<lambda>n. \<Prod>i\<le>n. f i) \<longlonglongrightarrow> prodinf f"

   819   by (metis convergent_LIMSEQ_iff convergent_prod_has_prod convergent_prod_imp_convergent

   820       convergent_prod_to_zero_iff raw_has_prod_eq_0 has_prod_def prodinf_eq_lim zero_le)

   821

   822 lemma has_prod_iff: "f has_prod x \<longleftrightarrow> convergent_prod f \<and> prodinf f = x"

   823 proof

   824   assume "f has_prod x"

   825   then show "convergent_prod f \<and> prodinf f = x"

   826     apply safe

   827     using convergent_prod_def has_prod_def apply blast

   828     using has_prod_unique by blast

   829 qed auto

   830

   831 lemma convergent_prod_has_prod_iff: "convergent_prod f \<longleftrightarrow> f has_prod prodinf f"

   832   by (auto simp: has_prod_iff convergent_prod_has_prod)

   833

   834 lemma prodinf_finite:

   835   assumes N: "finite N"

   836     and f: "\<And>n. n \<notin> N \<Longrightarrow> f n = 1"

   837   shows "prodinf f = (\<Prod>n\<in>N. f n)"

   838   using has_prod_finite[OF assms, THEN has_prod_unique] by simp

   839

   840 end

   841

   842 subsection \<open>Infinite products on ordered, topological monoids\<close>

   843

   844 lemma LIMSEQ_prod_0:

   845   fixes f :: "nat \<Rightarrow> 'a::{semidom,topological_space}"

   846   assumes "f i = 0"

   847   shows "(\<lambda>n. prod f {..n}) \<longlonglongrightarrow> 0"

   848 proof (subst tendsto_cong)

   849   show "\<forall>\<^sub>F n in sequentially. prod f {..n} = 0"

   850   proof

   851     show "prod f {..n} = 0" if "n \<ge> i" for n

   852       using that assms by auto

   853   qed

   854 qed auto

   855

   856 lemma LIMSEQ_prod_nonneg:

   857   fixes f :: "nat \<Rightarrow> 'a::{linordered_semidom,linorder_topology}"

   858   assumes 0: "\<And>n. 0 \<le> f n" and a: "(\<lambda>n. prod f {..n}) \<longlonglongrightarrow> a"

   859   shows "a \<ge> 0"

   860   by (simp add: "0" prod_nonneg LIMSEQ_le_const [OF a])

   861

   862

   863 context

   864   fixes f :: "nat \<Rightarrow> 'a::{linordered_semidom,linorder_topology}"

   865 begin

   866

   867 lemma has_prod_le:

   868   assumes f: "f has_prod a" and g: "g has_prod b" and le: "\<And>n. 0 \<le> f n \<and> f n \<le> g n"

   869   shows "a \<le> b"

   870 proof (cases "a=0 \<or> b=0")

   871   case True

   872   then show ?thesis

   873   proof

   874     assume [simp]: "a=0"

   875     have "b \<ge> 0"

   876     proof (rule LIMSEQ_prod_nonneg)

   877       show "(\<lambda>n. prod g {..n}) \<longlonglongrightarrow> b"

   878         using g by (auto simp: has_prod_def raw_has_prod_def LIMSEQ_prod_0)

   879     qed (use le order_trans in auto)

   880     then show ?thesis

   881       by auto

   882   next

   883     assume [simp]: "b=0"

   884     then obtain i where "g i = 0"

   885       using g by (auto simp: prod_defs)

   886     then have "f i = 0"

   887       using antisym le by force

   888     then have "a=0"

   889       using f by (auto simp: prod_defs LIMSEQ_prod_0 LIMSEQ_unique)

   890     then show ?thesis

   891       by auto

   892   qed

   893 next

   894   case False

   895   then show ?thesis

   896     using assms

   897     unfolding has_prod_def raw_has_prod_def

   898     by (force simp: LIMSEQ_prod_0 intro!: LIMSEQ_le prod_mono)

   899 qed

   900

   901 lemma prodinf_le:

   902   assumes f: "f has_prod a" and g: "g has_prod b" and le: "\<And>n. 0 \<le> f n \<and> f n \<le> g n"

   903   shows "prodinf f \<le> prodinf g"

   904   using has_prod_le [OF assms] has_prod_unique f g  by blast

   905

   906 end

   907

   908

   909 lemma prod_le_prodinf:

   910   fixes f :: "nat \<Rightarrow> 'a::{linordered_idom,linorder_topology}"

   911   assumes "f has_prod a" "\<And>i. 0 \<le> f i" "\<And>i. i\<ge>n \<Longrightarrow> 1 \<le> f i"

   912   shows "prod f {..<n} \<le> prodinf f"

   913   by(rule has_prod_le[OF has_prod_If_finite_set]) (use assms has_prod_unique in auto)

   914

   915 lemma prodinf_nonneg:

   916   fixes f :: "nat \<Rightarrow> 'a::{linordered_idom,linorder_topology}"

   917   assumes "f has_prod a" "\<And>i. 1 \<le> f i"

   918   shows "1 \<le> prodinf f"

   919   using prod_le_prodinf[of f a 0] assms

   920   by (metis order_trans prod_ge_1 zero_le_one)

   921

   922 lemma prodinf_le_const:

   923   fixes f :: "nat \<Rightarrow> real"

   924   assumes "convergent_prod f" "\<And>n. prod f {..<n} \<le> x"

   925   shows "prodinf f \<le> x"

   926   by (metis lessThan_Suc_atMost assms convergent_prod_LIMSEQ LIMSEQ_le_const2)

   927

   928 lemma prodinf_eq_one_iff:

   929   fixes f :: "nat \<Rightarrow> real"

   930   assumes f: "convergent_prod f" and ge1: "\<And>n. 1 \<le> f n"

   931   shows "prodinf f = 1 \<longleftrightarrow> (\<forall>n. f n = 1)"

   932 proof

   933   assume "prodinf f = 1"

   934   then have "(\<lambda>n. \<Prod>i<n. f i) \<longlonglongrightarrow> 1"

   935     using convergent_prod_LIMSEQ[of f] assms by (simp add: LIMSEQ_lessThan_iff_atMost)

   936   then have "\<And>i. (\<Prod>n\<in>{i}. f n) \<le> 1"

   937   proof (rule LIMSEQ_le_const)

   938     have "1 \<le> prod f n" for n

   939       by (simp add: ge1 prod_ge_1)

   940     have "prod f {..<n} = 1" for n

   941       by (metis \<open>\<And>n. 1 \<le> prod f n\<close> \<open>prodinf f = 1\<close> antisym f convergent_prod_has_prod ge1 order_trans prod_le_prodinf zero_le_one)

   942     then have "(\<Prod>n\<in>{i}. f n) \<le> prod f {..<n}" if "n \<ge> Suc i" for i n

   943       by (metis mult.left_neutral order_refl prod.cong prod.neutral_const prod_lessThan_Suc)

   944     then show "\<exists>N. \<forall>n\<ge>N. (\<Prod>n\<in>{i}. f n) \<le> prod f {..<n}" for i

   945       by blast

   946   qed

   947   with ge1 show "\<forall>n. f n = 1"

   948     by (auto intro!: antisym)

   949 qed (metis prodinf_zero fun_eq_iff)

   950

   951 lemma prodinf_pos_iff:

   952   fixes f :: "nat \<Rightarrow> real"

   953   assumes "convergent_prod f" "\<And>n. 1 \<le> f n"

   954   shows "1 < prodinf f \<longleftrightarrow> (\<exists>i. 1 < f i)"

   955   using prod_le_prodinf[of f 1] prodinf_eq_one_iff

   956   by (metis convergent_prod_has_prod assms less_le prodinf_nonneg)

   957

   958 lemma less_1_prodinf2:

   959   fixes f :: "nat \<Rightarrow> real"

   960   assumes "convergent_prod f" "\<And>n. 1 \<le> f n" "1 < f i"

   961   shows "1 < prodinf f"

   962 proof -

   963   have "1 < (\<Prod>n<Suc i. f n)"

   964     using assms  by (intro less_1_prod2[where i=i]) auto

   965   also have "\<dots> \<le> prodinf f"

   966     by (intro prod_le_prodinf) (use assms order_trans zero_le_one in \<open>blast+\<close>)

   967   finally show ?thesis .

   968 qed

   969

   970 lemma less_1_prodinf:

   971   fixes f :: "nat \<Rightarrow> real"

   972   shows "\<lbrakk>convergent_prod f; \<And>n. 1 < f n\<rbrakk> \<Longrightarrow> 1 < prodinf f"

   973   by (intro less_1_prodinf2[where i=1]) (auto intro: less_imp_le)

   974

   975 lemma prodinf_nonzero:

   976   fixes f :: "nat \<Rightarrow> 'a :: {idom,topological_semigroup_mult,t2_space}"

   977   assumes "convergent_prod f" "\<And>i. f i \<noteq> 0"

   978   shows "prodinf f \<noteq> 0"

   979   by (metis assms convergent_prod_offset_0 has_prod_unique raw_has_prod_def has_prod_def)

   980

   981 lemma less_0_prodinf:

   982   fixes f :: "nat \<Rightarrow> real"

   983   assumes f: "convergent_prod f" and 0: "\<And>i. f i > 0"

   984   shows "0 < prodinf f"

   985 proof -

   986   have "prodinf f \<noteq> 0"

   987     by (metis assms less_irrefl prodinf_nonzero)

   988   moreover have "0 < (\<Prod>n<i. f n)" for i

   989     by (simp add: 0 prod_pos)

   990   then have "prodinf f \<ge> 0"

   991     using convergent_prod_LIMSEQ [OF f] LIMSEQ_prod_nonneg 0 less_le by blast

   992   ultimately show ?thesis

   993     by auto

   994 qed

   995

   996 lemma prod_less_prodinf2:

   997   fixes f :: "nat \<Rightarrow> real"

   998   assumes f: "convergent_prod f" and 1: "\<And>m. m\<ge>n \<Longrightarrow> 1 \<le> f m" and 0: "\<And>m. 0 < f m" and i: "n \<le> i" "1 < f i"

   999   shows "prod f {..<n} < prodinf f"

  1000 proof -

  1001   have "prod f {..<n} \<le> prod f {..<i}"

  1002     by (rule prod_mono2) (use assms less_le in auto)

  1003   then have "prod f {..<n} < f i * prod f {..<i}"

  1004     using mult_less_le_imp_less[of 1 "f i" "prod f {..<n}" "prod f {..<i}"] assms

  1005     by (simp add: prod_pos)

  1006   moreover have "prod f {..<Suc i} \<le> prodinf f"

  1007     using prod_le_prodinf[of f _ "Suc i"]

  1008     by (meson "0" "1" Suc_leD convergent_prod_has_prod f \<open>n \<le> i\<close> le_trans less_eq_real_def)

  1009   ultimately show ?thesis

  1010     by (metis le_less_trans mult.commute not_le prod_lessThan_Suc)

  1011 qed

  1012

  1013 lemma prod_less_prodinf:

  1014   fixes f :: "nat \<Rightarrow> real"

  1015   assumes f: "convergent_prod f" and 1: "\<And>m. m\<ge>n \<Longrightarrow> 1 < f m" and 0: "\<And>m. 0 < f m"

  1016   shows "prod f {..<n} < prodinf f"

  1017   by (meson "0" "1" f le_less prod_less_prodinf2)

  1018

  1019 lemma raw_has_prodI_bounded:

  1020   fixes f :: "nat \<Rightarrow> real"

  1021   assumes pos: "\<And>n. 1 \<le> f n"

  1022     and le: "\<And>n. (\<Prod>i<n. f i) \<le> x"

  1023   shows "\<exists>p. raw_has_prod f 0 p"

  1024   unfolding raw_has_prod_def add_0_right

  1025 proof (rule exI LIMSEQ_incseq_SUP conjI)+

  1026   show "bdd_above (range (\<lambda>n. prod f {..n}))"

  1027     by (metis bdd_aboveI2 le lessThan_Suc_atMost)

  1028   then have "(SUP i. prod f {..i}) > 0"

  1029     by (metis UNIV_I cSUP_upper less_le_trans pos prod_pos zero_less_one)

  1030   then show "(SUP i. prod f {..i}) \<noteq> 0"

  1031     by auto

  1032   show "incseq (\<lambda>n. prod f {..n})"

  1033     using pos order_trans [OF zero_le_one] by (auto simp: mono_def intro!: prod_mono2)

  1034 qed

  1035

  1036 lemma convergent_prodI_nonneg_bounded:

  1037   fixes f :: "nat \<Rightarrow> real"

  1038   assumes "\<And>n. 1 \<le> f n" "\<And>n. (\<Prod>i<n. f i) \<le> x"

  1039   shows "convergent_prod f"

  1040   using convergent_prod_def raw_has_prodI_bounded [OF assms] by blast

  1041

  1042

  1043 subsection \<open>Infinite products on topological monoids\<close>

  1044

  1045 context

  1046   fixes f g :: "nat \<Rightarrow> 'a::{t2_space,topological_semigroup_mult,idom}"

  1047 begin

  1048

  1049 lemma raw_has_prod_mult: "\<lbrakk>raw_has_prod f M a; raw_has_prod g M b\<rbrakk> \<Longrightarrow> raw_has_prod (\<lambda>n. f n * g n) M (a * b)"

  1050   by (force simp add: prod.distrib tendsto_mult raw_has_prod_def)

  1051

  1052 lemma has_prod_mult_nz: "\<lbrakk>f has_prod a; g has_prod b; a \<noteq> 0; b \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>n. f n * g n) has_prod (a * b)"

  1053   by (simp add: raw_has_prod_mult has_prod_def)

  1054

  1055 end

  1056

  1057

  1058 context

  1059   fixes f g :: "nat \<Rightarrow> 'a::real_normed_field"

  1060 begin

  1061

  1062 lemma has_prod_mult:

  1063   assumes f: "f has_prod a" and g: "g has_prod b"

  1064   shows "(\<lambda>n. f n * g n) has_prod (a * b)"

  1065   using f [unfolded has_prod_def]

  1066 proof (elim disjE exE conjE)

  1067   assume f0: "raw_has_prod f 0 a"

  1068   show ?thesis

  1069     using g [unfolded has_prod_def]

  1070   proof (elim disjE exE conjE)

  1071     assume g0: "raw_has_prod g 0 b"

  1072     with f0 show ?thesis

  1073       by (force simp add: has_prod_def prod.distrib tendsto_mult raw_has_prod_def)

  1074   next

  1075     fix j q

  1076     assume "b = 0" and "g j = 0" and q: "raw_has_prod g (Suc j) q"

  1077     obtain p where p: "raw_has_prod f (Suc j) p"

  1078       using f0 raw_has_prod_ignore_initial_segment by blast

  1079     then have "Ex (raw_has_prod (\<lambda>n. f n * g n) (Suc j))"

  1080       using q raw_has_prod_mult by blast

  1081     then show ?thesis

  1082       using \<open>b = 0\<close> \<open>g j = 0\<close> has_prod_0_iff by fastforce

  1083   qed

  1084 next

  1085   fix i p

  1086   assume "a = 0" and "f i = 0" and p: "raw_has_prod f (Suc i) p"

  1087   show ?thesis

  1088     using g [unfolded has_prod_def]

  1089   proof (elim disjE exE conjE)

  1090     assume g0: "raw_has_prod g 0 b"

  1091     obtain q where q: "raw_has_prod g (Suc i) q"

  1092       using g0 raw_has_prod_ignore_initial_segment by blast

  1093     then have "Ex (raw_has_prod (\<lambda>n. f n * g n) (Suc i))"

  1094       using raw_has_prod_mult p by blast

  1095     then show ?thesis

  1096       using \<open>a = 0\<close> \<open>f i = 0\<close> has_prod_0_iff by fastforce

  1097   next

  1098     fix j q

  1099     assume "b = 0" and "g j = 0" and q: "raw_has_prod g (Suc j) q"

  1100     obtain p' where p': "raw_has_prod f (Suc (max i j)) p'"

  1101       by (metis raw_has_prod_ignore_initial_segment max_Suc_Suc max_def p)

  1102     moreover

  1103     obtain q' where q': "raw_has_prod g (Suc (max i j)) q'"

  1104       by (metis raw_has_prod_ignore_initial_segment max.cobounded2 max_Suc_Suc q)

  1105     ultimately show ?thesis

  1106       using \<open>b = 0\<close> by (simp add: has_prod_def) (metis \<open>f i = 0\<close> \<open>g j = 0\<close> raw_has_prod_mult max_def)

  1107   qed

  1108 qed

  1109

  1110 lemma convergent_prod_mult:

  1111   assumes f: "convergent_prod f" and g: "convergent_prod g"

  1112   shows "convergent_prod (\<lambda>n. f n * g n)"

  1113   unfolding convergent_prod_def

  1114 proof -

  1115   obtain M p N q where p: "raw_has_prod f M p" and q: "raw_has_prod g N q"

  1116     using convergent_prod_def f g by blast+

  1117   then obtain p' q' where p': "raw_has_prod f (max M N) p'" and q': "raw_has_prod g (max M N) q'"

  1118     by (meson raw_has_prod_ignore_initial_segment max.cobounded1 max.cobounded2)

  1119   then show "\<exists>M p. raw_has_prod (\<lambda>n. f n * g n) M p"

  1120     using raw_has_prod_mult by blast

  1121 qed

  1122

  1123 lemma prodinf_mult: "convergent_prod f \<Longrightarrow> convergent_prod g \<Longrightarrow> prodinf f * prodinf g = (\<Prod>n. f n * g n)"

  1124   by (intro has_prod_unique has_prod_mult convergent_prod_has_prod)

  1125

  1126 end

  1127

  1128 context

  1129   fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::real_normed_field"

  1130     and I :: "'i set"

  1131 begin

  1132

  1133 lemma has_prod_prod: "(\<And>i. i \<in> I \<Longrightarrow> (f i) has_prod (x i)) \<Longrightarrow> (\<lambda>n. \<Prod>i\<in>I. f i n) has_prod (\<Prod>i\<in>I. x i)"

  1134   by (induct I rule: infinite_finite_induct) (auto intro!: has_prod_mult)

  1135

  1136 lemma prodinf_prod: "(\<And>i. i \<in> I \<Longrightarrow> convergent_prod (f i)) \<Longrightarrow> (\<Prod>n. \<Prod>i\<in>I. f i n) = (\<Prod>i\<in>I. \<Prod>n. f i n)"

  1137   using has_prod_unique[OF has_prod_prod, OF convergent_prod_has_prod] by simp

  1138

  1139 lemma convergent_prod_prod: "(\<And>i. i \<in> I \<Longrightarrow> convergent_prod (f i)) \<Longrightarrow> convergent_prod (\<lambda>n. \<Prod>i\<in>I. f i n)"

  1140   using convergent_prod_has_prod_iff has_prod_prod prodinf_prod by force

  1141

  1142 end

  1143

  1144 subsection \<open>Infinite summability on real normed vector spaces\<close>

  1145

  1146 context

  1147   fixes f :: "nat \<Rightarrow> 'a::real_normed_field"

  1148 begin

  1149

  1150 lemma raw_has_prod_Suc_iff: "raw_has_prod f M (a * f M) \<longleftrightarrow> raw_has_prod (\<lambda>n. f (Suc n)) M a \<and> f M \<noteq> 0"

  1151 proof -

  1152   have "raw_has_prod f M (a * f M) \<longleftrightarrow> (\<lambda>i. \<Prod>j\<le>Suc i. f (j+M)) \<longlonglongrightarrow> a * f M \<and> a * f M \<noteq> 0"

  1153     by (subst LIMSEQ_Suc_iff) (simp add: raw_has_prod_def)

  1154   also have "\<dots> \<longleftrightarrow> (\<lambda>i. (\<Prod>j\<le>i. f (Suc j + M)) * f M) \<longlonglongrightarrow> a * f M \<and> a * f M \<noteq> 0"

  1155     by (simp add: ac_simps atMost_Suc_eq_insert_0 image_Suc_atMost prod_atLeast1_atMost_eq lessThan_Suc_atMost)

  1156   also have "\<dots> \<longleftrightarrow> raw_has_prod (\<lambda>n. f (Suc n)) M a \<and> f M \<noteq> 0"

  1157   proof safe

  1158     assume tends: "(\<lambda>i. (\<Prod>j\<le>i. f (Suc j + M)) * f M) \<longlonglongrightarrow> a * f M" and 0: "a * f M \<noteq> 0"

  1159     with tendsto_divide[OF tends tendsto_const, of "f M"]

  1160     show "raw_has_prod (\<lambda>n. f (Suc n)) M a"

  1161       by (simp add: raw_has_prod_def)

  1162   qed (auto intro: tendsto_mult_right simp:  raw_has_prod_def)

  1163   finally show ?thesis .

  1164 qed

  1165

  1166 lemma has_prod_Suc_iff:

  1167   assumes "f 0 \<noteq> 0" shows "(\<lambda>n. f (Suc n)) has_prod a \<longleftrightarrow> f has_prod (a * f 0)"

  1168 proof (cases "a = 0")

  1169   case True

  1170   then show ?thesis

  1171   proof (simp add: has_prod_def, safe)

  1172     fix i x

  1173     assume "f (Suc i) = 0" and "raw_has_prod (\<lambda>n. f (Suc n)) (Suc i) x"

  1174     then obtain y where "raw_has_prod f (Suc (Suc i)) y"

  1175       by (metis (no_types) raw_has_prod_eq_0 Suc_n_not_le_n raw_has_prod_Suc_iff raw_has_prod_ignore_initial_segment raw_has_prod_nonzero linear)

  1176     then show "\<exists>i. f i = 0 \<and> Ex (raw_has_prod f (Suc i))"

  1177       using \<open>f (Suc i) = 0\<close> by blast

  1178   next

  1179     fix i x

  1180     assume "f i = 0" and x: "raw_has_prod f (Suc i) x"

  1181     then obtain j where j: "i = Suc j"

  1182       by (metis assms not0_implies_Suc)

  1183     moreover have "\<exists> y. raw_has_prod (\<lambda>n. f (Suc n)) i y"

  1184       using x by (auto simp: raw_has_prod_def)

  1185     then show "\<exists>i. f (Suc i) = 0 \<and> Ex (raw_has_prod (\<lambda>n. f (Suc n)) (Suc i))"

  1186       using \<open>f i = 0\<close> j by blast

  1187   qed

  1188 next

  1189   case False

  1190   then show ?thesis

  1191     by (auto simp: has_prod_def raw_has_prod_Suc_iff assms)

  1192 qed

  1193

  1194 lemma convergent_prod_Suc_iff:

  1195   assumes "\<And>k. f k \<noteq> 0" shows "convergent_prod (\<lambda>n. f (Suc n)) = convergent_prod f"

  1196 proof

  1197   assume "convergent_prod f"

  1198   then have "f has_prod prodinf f"

  1199     by (rule convergent_prod_has_prod)

  1200   moreover have "prodinf f \<noteq> 0"

  1201     by (simp add: \<open>convergent_prod f\<close> assms prodinf_nonzero)

  1202   ultimately have "(\<lambda>n. f (Suc n)) has_prod (prodinf f * inverse (f 0))"

  1203     by (simp add: has_prod_Suc_iff inverse_eq_divide assms)

  1204   then show "convergent_prod (\<lambda>n. f (Suc n))"

  1205     using has_prod_iff by blast

  1206 next

  1207   assume "convergent_prod (\<lambda>n. f (Suc n))"

  1208   then show "convergent_prod f"

  1209     using assms convergent_prod_def raw_has_prod_Suc_iff by blast

  1210 qed

  1211

  1212 lemma raw_has_prod_inverse:

  1213   assumes "raw_has_prod f M a" shows "raw_has_prod (\<lambda>n. inverse (f n)) M (inverse a)"

  1214   using assms unfolding raw_has_prod_def by (auto dest: tendsto_inverse simp: prod_inversef [symmetric])

  1215

  1216 lemma has_prod_inverse:

  1217   assumes "f has_prod a" shows "(\<lambda>n. inverse (f n)) has_prod (inverse a)"

  1218 using assms raw_has_prod_inverse unfolding has_prod_def by auto

  1219

  1220 lemma convergent_prod_inverse:

  1221   assumes "convergent_prod f"

  1222   shows "convergent_prod (\<lambda>n. inverse (f n))"

  1223   using assms unfolding convergent_prod_def  by (blast intro: raw_has_prod_inverse elim: )

  1224

  1225 end

  1226

  1227 context (* Separate contexts are necessary to allow general use of the results above, here. *)

  1228   fixes f :: "nat \<Rightarrow> 'a::real_normed_field"

  1229 begin

  1230

  1231 lemma raw_has_prod_Suc_iff': "raw_has_prod f M a \<longleftrightarrow> raw_has_prod (\<lambda>n. f (Suc n)) M (a / f M) \<and> f M \<noteq> 0"

  1232   by (metis raw_has_prod_eq_0 add.commute add.left_neutral raw_has_prod_Suc_iff raw_has_prod_nonzero le_add1 nonzero_mult_div_cancel_right times_divide_eq_left)

  1233

  1234 lemma has_prod_divide: "f has_prod a \<Longrightarrow> g has_prod b \<Longrightarrow> (\<lambda>n. f n / g n) has_prod (a / b)"

  1235   unfolding divide_inverse by (intro has_prod_inverse has_prod_mult)

  1236

  1237 lemma convergent_prod_divide:

  1238   assumes f: "convergent_prod f" and g: "convergent_prod g"

  1239   shows "convergent_prod (\<lambda>n. f n / g n)"

  1240   using f g has_prod_divide has_prod_iff by blast

  1241

  1242 lemma prodinf_divide: "convergent_prod f \<Longrightarrow> convergent_prod g \<Longrightarrow> prodinf f / prodinf g = (\<Prod>n. f n / g n)"

  1243   by (intro has_prod_unique has_prod_divide convergent_prod_has_prod)

  1244

  1245 lemma prodinf_inverse: "convergent_prod f \<Longrightarrow> (\<Prod>n. inverse (f n)) = inverse (\<Prod>n. f n)"

  1246   by (intro has_prod_unique [symmetric] has_prod_inverse convergent_prod_has_prod)

  1247

  1248 lemma has_prod_iff_shift:

  1249   assumes "\<And>i. i < n \<Longrightarrow> f i \<noteq> 0"

  1250   shows "(\<lambda>i. f (i + n)) has_prod a \<longleftrightarrow> f has_prod (a * (\<Prod>i<n. f i))"

  1251   using assms

  1252 proof (induct n arbitrary: a)

  1253   case 0

  1254   then show ?case by simp

  1255 next

  1256   case (Suc n)

  1257   then have "(\<lambda>i. f (Suc i + n)) has_prod a \<longleftrightarrow> (\<lambda>i. f (i + n)) has_prod (a * f n)"

  1258     by (subst has_prod_Suc_iff) auto

  1259   with Suc show ?case

  1260     by (simp add: ac_simps)

  1261 qed

  1262

  1263 corollary has_prod_iff_shift':

  1264   assumes "\<And>i. i < n \<Longrightarrow> f i \<noteq> 0"

  1265   shows "(\<lambda>i. f (i + n)) has_prod (a / (\<Prod>i<n. f i)) \<longleftrightarrow> f has_prod a"

  1266   by (simp add: assms has_prod_iff_shift)

  1267

  1268 lemma has_prod_one_iff_shift:

  1269   assumes "\<And>i. i < n \<Longrightarrow> f i = 1"

  1270   shows "(\<lambda>i. f (i+n)) has_prod a \<longleftrightarrow> (\<lambda>i. f i) has_prod a"

  1271   by (simp add: assms has_prod_iff_shift)

  1272

  1273 lemma convergent_prod_iff_shift:

  1274   shows "convergent_prod (\<lambda>i. f (i + n)) \<longleftrightarrow> convergent_prod f"

  1275   apply safe

  1276   using convergent_prod_offset apply blast

  1277   using convergent_prod_ignore_initial_segment convergent_prod_def by blast

  1278

  1279 lemma has_prod_split_initial_segment:

  1280   assumes "f has_prod a" "\<And>i. i < n \<Longrightarrow> f i \<noteq> 0"

  1281   shows "(\<lambda>i. f (i + n)) has_prod (a / (\<Prod>i<n. f i))"

  1282   using assms has_prod_iff_shift' by blast

  1283

  1284 lemma prodinf_divide_initial_segment:

  1285   assumes "convergent_prod f" "\<And>i. i < n \<Longrightarrow> f i \<noteq> 0"

  1286   shows "(\<Prod>i. f (i + n)) = (\<Prod>i. f i) / (\<Prod>i<n. f i)"

  1287   by (rule has_prod_unique[symmetric]) (auto simp: assms has_prod_iff_shift)

  1288

  1289 lemma prodinf_split_initial_segment:

  1290   assumes "convergent_prod f" "\<And>i. i < n \<Longrightarrow> f i \<noteq> 0"

  1291   shows "prodinf f = (\<Prod>i. f (i + n)) * (\<Prod>i<n. f i)"

  1292   by (auto simp add: assms prodinf_divide_initial_segment)

  1293

  1294 lemma prodinf_split_head:

  1295   assumes "convergent_prod f" "f 0 \<noteq> 0"

  1296   shows "(\<Prod>n. f (Suc n)) = prodinf f / f 0"

  1297   using prodinf_split_initial_segment[of 1] assms by simp

  1298

  1299 end

  1300

  1301 context (* Separate contexts are necessary to allow general use of the results above, here. *)

  1302   fixes f :: "nat \<Rightarrow> 'a::real_normed_field"

  1303 begin

  1304

  1305 lemma convergent_prod_inverse_iff: "convergent_prod (\<lambda>n. inverse (f n)) \<longleftrightarrow> convergent_prod f"

  1306   by (auto dest: convergent_prod_inverse)

  1307

  1308 lemma convergent_prod_const_iff:

  1309   fixes c :: "'a :: {real_normed_field}"

  1310   shows "convergent_prod (\<lambda>_. c) \<longleftrightarrow> c = 1"

  1311 proof

  1312   assume "convergent_prod (\<lambda>_. c)"

  1313   then show "c = 1"

  1314     using convergent_prod_imp_LIMSEQ LIMSEQ_unique by blast

  1315 next

  1316   assume "c = 1"

  1317   then show "convergent_prod (\<lambda>_. c)"

  1318     by auto

  1319 qed

  1320

  1321 lemma has_prod_power: "f has_prod a \<Longrightarrow> (\<lambda>i. f i ^ n) has_prod (a ^ n)"

  1322   by (induction n) (auto simp: has_prod_mult)

  1323

  1324 lemma convergent_prod_power: "convergent_prod f \<Longrightarrow> convergent_prod (\<lambda>i. f i ^ n)"

  1325   by (induction n) (auto simp: convergent_prod_mult)

  1326

  1327 lemma prodinf_power: "convergent_prod f \<Longrightarrow> prodinf (\<lambda>i. f i ^ n) = prodinf f ^ n"

  1328   by (metis has_prod_unique convergent_prod_imp_has_prod has_prod_power)

  1329

  1330 end

  1331

  1332 end
`