src/HOL/Analysis/Infinite_Products.thy
 author paulson Fri Jun 15 12:18:06 2018 +0100 (13 months ago) changeset 68452 c027dfbfad30 parent 68426 e0b5f2d14bf9 child 68517 6b5f15387353 permissions -rw-r--r--
more on infinite products. Also subgroup_imp_subset -> subgroup.subset
     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 Topology_Euclidean_Space

    10 begin

    11

    12 subsection\<open>Preliminaries\<close>

    13

    14 lemma sum_le_prod:

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

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

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

    18   using assms

    19 proof (induction A rule: infinite_finite_induct)

    20   case (insert x A)

    21   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)"

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

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

    24 qed simp_all

    25

    26 lemma prod_le_exp_sum:

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

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

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

    30   using assms

    31 proof (induction A rule: infinite_finite_induct)

    32   case (insert x A)

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

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

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

    36 qed simp_all

    37

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

    39 proof (rule lhopital)

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

    41     by (rule tendsto_eq_intros refl | simp)+

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

    43     by (rule eventually_nhds_in_open) auto

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

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

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

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

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

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

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

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

    52     by (rule tendsto_eq_intros refl | simp)+

    53 qed auto

    54

    55 subsection\<open>Definitions and basic properties\<close>

    56

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

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

    59

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

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

    62   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)"

    63

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

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

    66

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

    68     (binder "\<Prod>" 10)

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

    70

    71 lemmas prod_defs = raw_has_prod_def has_prod_def convergent_prod_def prodinf_def

    72

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

    74   by simp

    75

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

    77   by presburger

    78

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

    80   by (simp add: raw_has_prod_def)

    81

    82 lemma raw_has_prod_eq_0:

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

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

    85   shows "p = 0"

    86 proof -

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

    88   proof -

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

    90       using i that by auto

    91     then show ?thesis

    92       by auto

    93   qed

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

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

    96     with p show ?thesis

    97       unfolding raw_has_prod_def

    98     using LIMSEQ_unique by blast

    99 qed

   100

   101 lemma raw_has_prod_Suc:

   102   "raw_has_prod f (Suc M) a \<longleftrightarrow> raw_has_prod (\<lambda>n. f (Suc n)) M a"

   103   unfolding raw_has_prod_def by auto

   104

   105 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))"

   106   by (simp add: has_prod_def)

   107

   108 lemma has_prod_unique2:

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

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

   111   using assms

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

   113

   114 lemma has_prod_unique:

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

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

   117   by (simp add: has_prod_unique2 prodinf_def the_equality)

   118

   119 lemma convergent_prod_altdef:

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

   121   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)"

   122 proof

   123   assume "convergent_prod f"

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

   125     by (auto simp: prod_defs)

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

   127   proof

   128     assume "f i = 0"

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

   130       using eventually_ge_at_top[of "i - M"]

   131     proof eventually_elim

   132       case (elim n)

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

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

   135     qed

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

   137       unfolding filterlim_iff

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

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

   140       show False by simp

   141   qed

   142   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)"

   143     by blast

   144 qed (auto simp: prod_defs)

   145

   146

   147 subsection\<open>Absolutely convergent products\<close>

   148

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

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

   151

   152 lemma abs_convergent_prodI:

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

   154   shows   "abs_convergent_prod f"

   155 proof -

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

   157     by (auto simp: convergent_def)

   158   have "L \<ge> 1"

   159   proof (rule tendsto_le)

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

   161     proof (intro always_eventually allI)

   162       fix n

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

   164         by (intro prod_mono) auto

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

   166     qed

   167   qed (use L in simp_all)

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

   169   with L show ?thesis unfolding abs_convergent_prod_def prod_defs

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

   171 qed

   172

   173 lemma

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

   175   assumes "convergent_prod f"

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

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

   178 proof -

   179   from assms obtain M L

   180     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"

   181     by (auto simp: convergent_prod_altdef)

   182   note this(2)

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

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

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

   186     by (intro tendsto_mult tendsto_const)

   187   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))"

   188     by (subst prod.union_disjoint) auto

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

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

   191     by (rule LIMSEQ_offset)

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

   193     by (auto simp: convergent_def)

   194

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

   196   proof

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

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

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

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

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

   202   next

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

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

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

   206   qed

   207 qed

   208

   209 lemma convergent_prod_iff_nz_lim:

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

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

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

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

   214 proof

   215   assume ?lhs then show ?rhs

   216     using assms convergentD convergent_prod_imp_convergent convergent_prod_to_zero_iff by blast

   217 next

   218   assume ?rhs then show ?lhs

   219     unfolding prod_defs

   220     by (rule_tac x=0 in exI) auto

   221 qed

   222

   223 lemma convergent_prod_iff_convergent:

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

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

   226   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"

   227   by (force simp: convergent_prod_iff_nz_lim assms convergent_def limI)

   228

   229

   230 lemma abs_convergent_prod_altdef:

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

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

   233 proof

   234   assume "abs_convergent_prod f"

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

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

   237 qed (auto intro: abs_convergent_prodI)

   238

   239 lemma weierstrass_prod_ineq:

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

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

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

   243   using assms

   244 proof (induction A rule: infinite_finite_induct)

   245   case (insert x A)

   246   from insert.hyps and insert.prems

   247     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)"

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

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

   250 qed simp_all

   251

   252 lemma norm_prod_minus1_le_prod_minus1:

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

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

   255 proof (induction A rule: infinite_finite_induct)

   256   case (insert x A)

   257   from insert.hyps have

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

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

   260     by (simp add: algebra_simps)

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

   262     by (rule norm_triangle_ineq)

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

   264     by (simp add: prod_norm norm_mult)

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

   266     by (intro prod_mono norm_triangle_ineq ballI conjI) auto

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

   268   also note insert.IH

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

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

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

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

   273 qed simp_all

   274

   275 lemma convergent_prod_imp_ev_nonzero:

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

   277   assumes "convergent_prod f"

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

   279   using assms by (auto simp: eventually_at_top_linorder convergent_prod_altdef)

   280

   281 lemma convergent_prod_imp_LIMSEQ:

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

   283   assumes "convergent_prod f"

   284   shows   "f \<longlonglongrightarrow> 1"

   285 proof -

   286   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"

   287     by (auto simp: convergent_prod_altdef)

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

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

   290     using L L' by (intro tendsto_divide) simp_all

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

   292   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))"

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

   294   finally show ?thesis by (rule LIMSEQ_offset)

   295 qed

   296

   297 lemma abs_convergent_prod_imp_summable:

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

   299   assumes "abs_convergent_prod f"

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

   301 proof -

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

   303     unfolding abs_convergent_prod_def by (rule convergent_prod_imp_convergent)

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

   305     unfolding convergent_def by blast

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

   307   proof (rule Bseq_monoseq_convergent)

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

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

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

   311     proof eventually_elim

   312       case (elim n)

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

   314         unfolding real_norm_def by (intro abs_of_nonneg sum_nonneg) simp_all

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

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

   317       finally show ?case by simp

   318     qed

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

   320   next

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

   322       by (rule mono_SucI1) auto

   323   qed

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

   325 qed

   326

   327 lemma summable_imp_abs_convergent_prod:

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

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

   330   shows   "abs_convergent_prod f"

   331 proof (intro abs_convergent_prodI Bseq_monoseq_convergent)

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

   333     by (intro mono_SucI1)

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

   335 next

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

   337   proof (rule Bseq_eventually_mono)

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

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

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

   341   next

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

   343       using sums_def_le by blast

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

   345       by (rule tendsto_exp)

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

   347       by (rule convergentI)

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

   349       by (rule convergent_imp_Bseq)

   350   qed

   351 qed

   352

   353 lemma abs_convergent_prod_conv_summable:

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

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

   356   by (blast intro: abs_convergent_prod_imp_summable summable_imp_abs_convergent_prod)

   357

   358 lemma abs_convergent_prod_imp_LIMSEQ:

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

   360   assumes "abs_convergent_prod f"

   361   shows   "f \<longlonglongrightarrow> 1"

   362 proof -

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

   364     by (rule abs_convergent_prod_imp_summable)

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

   366     by (simp add: tendsto_norm_zero_iff)

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

   368 qed

   369

   370 lemma abs_convergent_prod_imp_ev_nonzero:

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

   372   assumes "abs_convergent_prod f"

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

   374 proof -

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

   376     by (rule abs_convergent_prod_imp_LIMSEQ)

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

   378     by (auto simp: tendsto_iff)

   379   thus ?thesis by eventually_elim auto

   380 qed

   381

   382 lemma convergent_prod_offset:

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

   384   shows   "convergent_prod f"

   385 proof -

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

   387     by (auto simp: prod_defs add.assoc)

   388   thus "convergent_prod f"

   389     unfolding prod_defs by blast

   390 qed

   391

   392 lemma abs_convergent_prod_offset:

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

   394   shows   "abs_convergent_prod f"

   395   using assms unfolding abs_convergent_prod_def by (rule convergent_prod_offset)

   396

   397 subsection\<open>Ignoring initial segments\<close>

   398

   399 lemma raw_has_prod_ignore_initial_segment:

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

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

   402   obtains q where  "raw_has_prod f N q"

   403 proof -

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

   405     using assms by (auto simp: raw_has_prod_def)

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

   407     using assms by (auto simp: raw_has_prod_eq_0)

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

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

   410     by (auto simp: C_def)

   411

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

   413     by (rule LIMSEQ_ignore_initial_segment)

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

   415   proof (rule ext, goal_cases)

   416     case (1 n)

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

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

   419       unfolding C_def by (rule prod.union_disjoint) auto

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

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

   422     finally show ?case

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

   424   qed

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

   426     by (intro tendsto_divide tendsto_const) auto

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

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

   429   ultimately show ?thesis

   430     using raw_has_prod_def that by blast

   431 qed

   432

   433 corollary convergent_prod_ignore_initial_segment:

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

   435   assumes "convergent_prod f"

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

   437   using assms

   438   unfolding convergent_prod_def

   439   apply clarify

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

   441   apply (auto simp add: raw_has_prod_def add_ac)

   442   done

   443

   444 corollary convergent_prod_ignore_nonzero_segment:

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

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

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

   448   using convergent_prod_ignore_initial_segment [OF f]

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

   450

   451 corollary abs_convergent_prod_ignore_initial_segment:

   452   assumes "abs_convergent_prod f"

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

   454   using assms unfolding abs_convergent_prod_def

   455   by (rule convergent_prod_ignore_initial_segment)

   456

   457 lemma abs_convergent_prod_imp_convergent_prod:

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

   459   assumes "abs_convergent_prod f"

   460   shows   "convergent_prod f"

   461 proof -

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

   463     by (rule abs_convergent_prod_imp_ev_nonzero)

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

   465     by (auto simp: eventually_at_top_linorder)

   466   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)"

   467

   468   have "Cauchy ?P"

   469   proof (rule CauchyI', goal_cases)

   470     case (1 \<epsilon>)

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

   472       by (rule abs_convergent_prod_ignore_initial_segment)

   473     hence "Cauchy ?Q"

   474       unfolding abs_convergent_prod_def

   475       by (intro convergent_Cauchy convergent_prod_imp_convergent)

   476     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

   477       by blast

   478     show ?case

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

   480       case (1 m n)

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

   482         by (simp add: dist_norm norm_minus_commute)

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

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

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

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

   487         by (simp add: algebra_simps)

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

   489         by (simp add: norm_mult prod_norm)

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

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

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

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

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

   495         by (simp add: algebra_simps)

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

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

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

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

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

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

   502       finally show ?case .

   503     qed

   504   qed

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

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

   507     by (auto simp: convergent_def)

   508

   509   have "L \<noteq> 0"

   510   proof

   511     assume [simp]: "L = 0"

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

   513       by (simp add: prod_norm)

   514

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

   516       by (intro abs_convergent_prod_imp_LIMSEQ abs_convergent_prod_ignore_initial_segment)

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

   518       by (auto simp: tendsto_iff dist_norm)

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

   520       by (auto simp: eventually_at_top_linorder)

   521

   522     {

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

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

   525

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

   527       proof (rule tendsto_sandwich)

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

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

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

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

   532         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"

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

   534

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

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

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

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

   539         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))))"

   540         proof (rule ext, goal_cases)

   541           case (1 n)

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

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

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

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

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

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

   548         qed

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

   550           by (intro tendsto_divide tendsto_const) auto

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

   552       qed simp_all

   553

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

   555       proof (rule tendsto_le)

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

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

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

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

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

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

   562           by (intro tendsto_intros summable_LIMSEQ' summable_ignore_initial_segment

   563                 abs_convergent_prod_imp_summable assms)

   564       qed simp_all

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

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

   567         by (intro suminf_split_initial_segment [symmetric] summable_ignore_initial_segment

   568               abs_convergent_prod_imp_summable assms)

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

   570     } note * = this

   571

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

   573     proof (rule tendsto_le)

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

   575         by (intro tendsto_intros summable_LIMSEQ summable_ignore_initial_segment

   576                 abs_convergent_prod_imp_summable assms)

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

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

   579     qed simp_all

   580     thus False by simp

   581   qed

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

   583 qed

   584

   585 subsection\<open>More elementary properties\<close>

   586

   587 lemma raw_has_prod_cases:

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

   589   assumes "raw_has_prod f M p"

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

   591 proof -

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

   593     using assms unfolding raw_has_prod_def by blast+

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

   595     by (metis tendsto_mult_left)

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

   597   proof -

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

   599       by auto

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

   601       by simp (subst prod.union_disjoint; force)

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

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

   604     finally show ?thesis by metis

   605   qed

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

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

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

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

   610   then show thesis

   611     using that by blast

   612 qed

   613

   614 corollary convergent_prod_offset_0:

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

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

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

   618   using assms convergent_prod_def raw_has_prod_cases by blast

   619

   620 lemma prodinf_eq_lim:

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

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

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

   624   using assms convergent_prod_offset_0 [OF assms]

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

   626

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

   628   unfolding prod_defs by auto

   629

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

   631   unfolding prod_defs by auto

   632

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

   634   by presburger

   635

   636 lemma convergent_prod_cong:

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

   638   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"

   639   shows "convergent_prod f = convergent_prod g"

   640 proof -

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

   642     by (auto simp: eventually_at_top_linorder)

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

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

   645     by (simp add: f)

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

   647     using eventually_ge_at_top[of N]

   648   proof eventually_elim

   649     case (elim n)

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

   651       by auto

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

   653       by (intro prod.union_disjoint) auto

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

   655       by (intro prod.cong) simp_all

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

   657       unfolding C_def by (simp add: g prod_dividef)

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

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

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

   661       by auto

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

   663   qed

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

   665     by (rule convergent_cong)

   666   show ?thesis

   667   proof

   668     assume cf: "convergent_prod f"

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

   670       using tendsto_mult_left * convergent_prod_to_zero_iff f filterlim_cong by fastforce

   671     then show "convergent_prod g"

   672       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)

   673   next

   674     assume cg: "convergent_prod g"

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

   676       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)

   677     then show "convergent_prod f"

   678       using "*" tendsto_mult_left filterlim_cong

   679       by (fastforce simp add: convergent_prod_iff_nz_lim f)

   680   qed

   681 qed

   682

   683 lemma has_prod_finite:

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

   685   assumes [simp]: "finite N"

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

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

   688 proof -

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

   690   proof (rule prod.mono_neutral_right)

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

   692       by (auto simp: le_Suc_eq trans_le_add2)

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

   694       using f by blast

   695   qed auto

   696   show ?thesis

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

   698     case True

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

   700       by simp

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

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

   703     ultimately show ?thesis

   704       by (simp add: raw_has_prod_def has_prod_def)

   705   next

   706     case False

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

   708       by auto

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

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

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

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

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

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

   715       using maxge Suc_n_not_le_n le_trans by force

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

   717     proof -

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

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

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

   721           using le_Suc_ex by fastforce

   722       qed (auto simp: inj_on_def)

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

   724         by (rule prod.mono_neutral_right)

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

   726       finally show ?thesis .

   727     qed

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

   729     proof (simp add: raw_has_prod_def)

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

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

   732     qed

   733     show ?thesis

   734       unfolding has_prod_def

   735     proof (intro disjI2 exI conjI)

   736       show "prod f N = 0"

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

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

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

   740     qed (use q in auto)

   741   qed

   742 qed

   743

   744 corollary has_prod_0:

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

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

   747   shows "f has_prod 1"

   748   by (simp add: assms has_prod_cong)

   749

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

   751   using has_prod_unique by force

   752

   753 lemma convergent_prod_finite:

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

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

   756   shows "convergent_prod f"

   757 proof -

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

   759     using assms has_prod_def has_prod_finite by blast

   760   then show ?thesis

   761     by (simp add: convergent_prod_def)

   762 qed

   763

   764 lemma has_prod_If_finite_set:

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

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

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

   768   by simp

   769

   770 lemma has_prod_If_finite:

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

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

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

   774

   775 lemma convergent_prod_If_finite_set[simp, intro]:

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

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

   778   by (simp add: convergent_prod_finite)

   779

   780 lemma convergent_prod_If_finite[simp, intro]:

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

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

   783   using convergent_prod_def has_prod_If_finite has_prod_def by fastforce

   784

   785 lemma has_prod_single:

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

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

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

   789

   790 context

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

   792 begin

   793

   794 lemma convergent_prod_imp_has_prod:

   795   assumes "convergent_prod f"

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

   797 proof -

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

   799     using assms convergent_prod_def by blast

   800   then have "p \<noteq> 0"

   801     using raw_has_prod_nonzero by blast

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

   803     using raw_has_prod_eq_0 that by blast

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

   805   show ?thesis

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

   807     case True

   808     then have "C \<noteq> 0"

   809       by (simp add: C_def)

   810     then show ?thesis

   811       by (meson True assms convergent_prod_offset_0 fnz has_prod_def nat_le_linear)

   812   next

   813     case False

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

   815     have 0: "f ?N = 0"

   816       using fnz False

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

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

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

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

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

   822     then show ?thesis

   823       unfolding has_prod_def using 0 by blast

   824   qed

   825 qed

   826

   827 lemma convergent_prod_has_prod [intro]:

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

   829   unfolding prodinf_def

   830   by (metis convergent_prod_imp_has_prod has_prod_unique theI')

   831

   832 lemma convergent_prod_LIMSEQ:

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

   834   by (metis convergent_LIMSEQ_iff convergent_prod_has_prod convergent_prod_imp_convergent

   835       convergent_prod_to_zero_iff raw_has_prod_eq_0 has_prod_def prodinf_eq_lim zero_le)

   836

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

   838 proof

   839   assume "f has_prod x"

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

   841     apply safe

   842     using convergent_prod_def has_prod_def apply blast

   843     using has_prod_unique by blast

   844 qed auto

   845

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

   847   by (auto simp: has_prod_iff convergent_prod_has_prod)

   848

   849 lemma prodinf_finite:

   850   assumes N: "finite N"

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

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

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

   854

   855 end

   856

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

   858

   859 lemma LIMSEQ_prod_0:

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

   861   assumes "f i = 0"

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

   863 proof (subst tendsto_cong)

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

   865   proof

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

   867       using that assms by auto

   868   qed

   869 qed auto

   870

   871 lemma LIMSEQ_prod_nonneg:

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

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

   874   shows "a \<ge> 0"

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

   876

   877

   878 context

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

   880 begin

   881

   882 lemma has_prod_le:

   883   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"

   884   shows "a \<le> b"

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

   886   case True

   887   then show ?thesis

   888   proof

   889     assume [simp]: "a=0"

   890     have "b \<ge> 0"

   891     proof (rule LIMSEQ_prod_nonneg)

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

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

   894     qed (use le order_trans in auto)

   895     then show ?thesis

   896       by auto

   897   next

   898     assume [simp]: "b=0"

   899     then obtain i where "g i = 0"

   900       using g by (auto simp: prod_defs)

   901     then have "f i = 0"

   902       using antisym le by force

   903     then have "a=0"

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

   905     then show ?thesis

   906       by auto

   907   qed

   908 next

   909   case False

   910   then show ?thesis

   911     using assms

   912     unfolding has_prod_def raw_has_prod_def

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

   914 qed

   915

   916 lemma prodinf_le:

   917   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"

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

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

   920

   921 end

   922

   923

   924 lemma prod_le_prodinf:

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

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

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

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

   929

   930 lemma prodinf_nonneg:

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

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

   933   shows "1 \<le> prodinf f"

   934   using prod_le_prodinf[of f a 0] assms

   935   by (metis order_trans prod_ge_1 zero_le_one)

   936

   937 lemma prodinf_le_const:

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

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

   940   shows "prodinf f \<le> x"

   941   by (metis lessThan_Suc_atMost assms convergent_prod_LIMSEQ LIMSEQ_le_const2)

   942

   943 lemma prodinf_eq_one_iff:

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

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

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

   947 proof

   948   assume "prodinf f = 1"

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

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

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

   952   proof (rule LIMSEQ_le_const)

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

   954       by (simp add: ge1 prod_ge_1)

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

   956       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)

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

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

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

   960       by blast

   961   qed

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

   963     by (auto intro!: antisym)

   964 qed (metis prodinf_zero fun_eq_iff)

   965

   966 lemma prodinf_pos_iff:

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

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

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

   970   using prod_le_prodinf[of f 1] prodinf_eq_one_iff

   971   by (metis convergent_prod_has_prod assms less_le prodinf_nonneg)

   972

   973 lemma less_1_prodinf2:

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

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

   976   shows "1 < prodinf f"

   977 proof -

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

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

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

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

   982   finally show ?thesis .

   983 qed

   984

   985 lemma less_1_prodinf:

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

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

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

   989

   990 lemma prodinf_nonzero:

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

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

   993   shows "prodinf f \<noteq> 0"

   994   by (metis assms convergent_prod_offset_0 has_prod_unique raw_has_prod_def has_prod_def)

   995

   996 lemma less_0_prodinf:

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

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

   999   shows "0 < prodinf f"

  1000 proof -

  1001   have "prodinf f \<noteq> 0"

  1002     by (metis assms less_irrefl prodinf_nonzero)

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

  1004     by (simp add: 0 prod_pos)

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

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

  1007   ultimately show ?thesis

  1008     by auto

  1009 qed

  1010

  1011 lemma prod_less_prodinf2:

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

  1013   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"

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

  1015 proof -

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

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

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

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

  1020     by (simp add: prod_pos)

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

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

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

  1024   ultimately show ?thesis

  1025     by (metis le_less_trans mult.commute not_le prod_lessThan_Suc)

  1026 qed

  1027

  1028 lemma prod_less_prodinf:

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

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

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

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

  1033

  1034 lemma raw_has_prodI_bounded:

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

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

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

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

  1039   unfolding raw_has_prod_def add_0_right

  1040 proof (rule exI LIMSEQ_incseq_SUP conjI)+

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

  1042     by (metis bdd_aboveI2 le lessThan_Suc_atMost)

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

  1044     by (metis UNIV_I cSUP_upper less_le_trans pos prod_pos zero_less_one)

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

  1046     by auto

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

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

  1049 qed

  1050

  1051 lemma convergent_prodI_nonneg_bounded:

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

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

  1054   shows "convergent_prod f"

  1055   using convergent_prod_def raw_has_prodI_bounded [OF assms] by blast

  1056

  1057

  1058 subsection \<open>Infinite products on topological spaces\<close>

  1059

  1060 context

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

  1062 begin

  1063

  1064 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)"

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

  1066

  1067 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)"

  1068   by (simp add: raw_has_prod_mult has_prod_def)

  1069

  1070 end

  1071

  1072

  1073 context

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

  1075 begin

  1076

  1077 lemma has_prod_mult:

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

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

  1080   using f [unfolded has_prod_def]

  1081 proof (elim disjE exE conjE)

  1082   assume f0: "raw_has_prod f 0 a"

  1083   show ?thesis

  1084     using g [unfolded has_prod_def]

  1085   proof (elim disjE exE conjE)

  1086     assume g0: "raw_has_prod g 0 b"

  1087     with f0 show ?thesis

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

  1089   next

  1090     fix j q

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

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

  1093       using f0 raw_has_prod_ignore_initial_segment by blast

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

  1095       using q raw_has_prod_mult by blast

  1096     then show ?thesis

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

  1098   qed

  1099 next

  1100   fix i p

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

  1102   show ?thesis

  1103     using g [unfolded has_prod_def]

  1104   proof (elim disjE exE conjE)

  1105     assume g0: "raw_has_prod g 0 b"

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

  1107       using g0 raw_has_prod_ignore_initial_segment by blast

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

  1109       using raw_has_prod_mult p by blast

  1110     then show ?thesis

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

  1112   next

  1113     fix j q

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

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

  1116       by (metis raw_has_prod_ignore_initial_segment max_Suc_Suc max_def p)

  1117     moreover

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

  1119       by (metis raw_has_prod_ignore_initial_segment max.cobounded2 max_Suc_Suc q)

  1120     ultimately show ?thesis

  1121       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)

  1122   qed

  1123 qed

  1124

  1125 lemma convergent_prod_mult:

  1126   assumes f: "convergent_prod f" and g: "convergent_prod g"

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

  1128   unfolding convergent_prod_def

  1129 proof -

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

  1131     using convergent_prod_def f g by blast+

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

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

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

  1135     using raw_has_prod_mult by blast

  1136 qed

  1137

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

  1139   by (intro has_prod_unique has_prod_mult convergent_prod_has_prod)

  1140

  1141 end

  1142

  1143 context

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

  1145     and I :: "'i set"

  1146 begin

  1147

  1148 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)"

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

  1150

  1151 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)"

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

  1153

  1154 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)"

  1155   using convergent_prod_has_prod_iff has_prod_prod prodinf_prod by force

  1156

  1157 end

  1158

  1159 subsection \<open>Infinite summability on real normed fields\<close>

  1160

  1161 context

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

  1163 begin

  1164

  1165 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"

  1166 proof -

  1167   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"

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

  1169   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"

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

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

  1172   proof safe

  1173     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"

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

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

  1176       by (simp add: raw_has_prod_def)

  1177   qed (auto intro: tendsto_mult_right simp:  raw_has_prod_def)

  1178   finally show ?thesis .

  1179 qed

  1180

  1181 lemma has_prod_Suc_iff:

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

  1183 proof (cases "a = 0")

  1184   case True

  1185   then show ?thesis

  1186   proof (simp add: has_prod_def, safe)

  1187     fix i x

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

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

  1190       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)

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

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

  1193   next

  1194     fix i x

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

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

  1197       by (metis assms not0_implies_Suc)

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

  1199       using x by (auto simp: raw_has_prod_def)

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

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

  1202   qed

  1203 next

  1204   case False

  1205   then show ?thesis

  1206     by (auto simp: has_prod_def raw_has_prod_Suc_iff assms)

  1207 qed

  1208

  1209 lemma convergent_prod_Suc_iff:

  1210   shows "convergent_prod (\<lambda>n. f (Suc n)) = convergent_prod f"

  1211 proof

  1212   assume "convergent_prod f"

  1213   then obtain M L where M_nz:"\<forall>n\<ge>M. f n \<noteq> 0" and

  1214         M_L:"(\<lambda>n. \<Prod>i\<le>n. f (i + M)) \<longlonglongrightarrow> L" and "L \<noteq> 0"

  1215     unfolding convergent_prod_altdef by auto

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

  1217   proof -

  1218     have "(\<lambda>n. \<Prod>i\<in>{0..Suc n}. f (i + M)) \<longlonglongrightarrow> L"

  1219       using M_L

  1220       apply (subst (asm) LIMSEQ_Suc_iff[symmetric])

  1221       using atLeast0AtMost by auto

  1222     then have "(\<lambda>n. f M * (\<Prod>i\<in>{0..n}. f (Suc (i + M)))) \<longlonglongrightarrow> L"

  1223       apply (subst (asm) prod.atLeast0_atMost_Suc_shift)

  1224       by simp

  1225     then have "(\<lambda>n. (\<Prod>i\<in>{0..n}. f (Suc (i + M)))) \<longlonglongrightarrow> L/f M"

  1226       apply (drule_tac tendsto_divide)

  1227       using M_nz[rule_format,of M,simplified] by auto

  1228     then show ?thesis unfolding atLeast0AtMost .

  1229   qed

  1230   then show "convergent_prod (\<lambda>n. f (Suc n))" unfolding convergent_prod_altdef

  1231     apply (rule_tac exI[where x=M])

  1232     apply (rule_tac exI[where x="L/f M"])

  1233     using M_nz \<open>L\<noteq>0\<close> by auto

  1234 next

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

  1236   then obtain M where "\<exists>L. (\<forall>n\<ge>M. f (Suc n) \<noteq> 0) \<and> (\<lambda>n. \<Prod>i\<le>n. f (Suc (i + M))) \<longlonglongrightarrow> L \<and> L \<noteq> 0"

  1237     unfolding convergent_prod_altdef by auto

  1238   then show "convergent_prod f" unfolding convergent_prod_altdef

  1239     apply (rule_tac exI[where x="Suc M"])

  1240     using Suc_le_D by auto

  1241 qed

  1242

  1243 lemma raw_has_prod_inverse:

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

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

  1246

  1247 lemma has_prod_inverse:

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

  1249 using assms raw_has_prod_inverse unfolding has_prod_def by auto

  1250

  1251 lemma convergent_prod_inverse:

  1252   assumes "convergent_prod f"

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

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

  1255

  1256 end

  1257

  1258 context

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

  1260 begin

  1261

  1262 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"

  1263   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)

  1264

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

  1266   unfolding divide_inverse by (intro has_prod_inverse has_prod_mult)

  1267

  1268 lemma convergent_prod_divide:

  1269   assumes f: "convergent_prod f" and g: "convergent_prod g"

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

  1271   using f g has_prod_divide has_prod_iff by blast

  1272

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

  1274   by (intro has_prod_unique has_prod_divide convergent_prod_has_prod)

  1275

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

  1277   by (intro has_prod_unique [symmetric] has_prod_inverse convergent_prod_has_prod)

  1278

  1279 lemma has_prod_Suc_imp:

  1280   assumes "(\<lambda>n. f (Suc n)) has_prod a"

  1281   shows "f has_prod (a * f 0)"

  1282 proof -

  1283   have "f has_prod (a * f 0)" when "raw_has_prod (\<lambda>n. f (Suc n)) 0 a"

  1284     apply (cases "f 0=0")

  1285     using that unfolding has_prod_def raw_has_prod_Suc

  1286     by (auto simp add: raw_has_prod_Suc_iff)

  1287   moreover have "f has_prod (a * f 0)" when

  1288     "(\<exists>i q. a = 0 \<and> f (Suc i) = 0 \<and> raw_has_prod (\<lambda>n. f (Suc n)) (Suc i) q)"

  1289   proof -

  1290     from that

  1291     obtain i q where "a = 0" "f (Suc i) = 0" "raw_has_prod (\<lambda>n. f (Suc n)) (Suc i) q"

  1292       by auto

  1293     then show ?thesis unfolding has_prod_def

  1294       by (auto intro!:exI[where x="Suc i"] simp:raw_has_prod_Suc)

  1295   qed

  1296   ultimately show "f has_prod (a * f 0)" using assms unfolding has_prod_def by auto

  1297 qed

  1298

  1299 lemma has_prod_iff_shift:

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

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

  1302   using assms

  1303 proof (induct n arbitrary: a)

  1304   case 0

  1305   then show ?case by simp

  1306 next

  1307   case (Suc n)

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

  1309     by (subst has_prod_Suc_iff) auto

  1310   with Suc show ?case

  1311     by (simp add: ac_simps)

  1312 qed

  1313

  1314 corollary has_prod_iff_shift':

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

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

  1317   by (simp add: assms has_prod_iff_shift)

  1318

  1319 lemma has_prod_one_iff_shift:

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

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

  1322   by (simp add: assms has_prod_iff_shift)

  1323

  1324 lemma convergent_prod_iff_shift:

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

  1326   apply safe

  1327   using convergent_prod_offset apply blast

  1328   using convergent_prod_ignore_initial_segment convergent_prod_def by blast

  1329

  1330 lemma has_prod_split_initial_segment:

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

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

  1333   using assms has_prod_iff_shift' by blast

  1334

  1335 lemma prodinf_divide_initial_segment:

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

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

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

  1339

  1340 lemma prodinf_split_initial_segment:

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

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

  1343   by (auto simp add: assms prodinf_divide_initial_segment)

  1344

  1345 lemma prodinf_split_head:

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

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

  1348   using prodinf_split_initial_segment[of 1] assms by simp

  1349

  1350 end

  1351

  1352 context

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

  1354 begin

  1355

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

  1357   by (auto dest: convergent_prod_inverse)

  1358

  1359 lemma convergent_prod_const_iff:

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

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

  1362 proof

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

  1364   then show "c = 1"

  1365     using convergent_prod_imp_LIMSEQ LIMSEQ_unique by blast

  1366 next

  1367   assume "c = 1"

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

  1369     by auto

  1370 qed

  1371

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

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

  1374

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

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

  1377

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

  1379   by (metis has_prod_unique convergent_prod_imp_has_prod has_prod_power)

  1380

  1381 end

  1382

  1383

  1384 subsection\<open>Exponentials and logarithms\<close>

  1385

  1386 context

  1387   fixes f :: "nat \<Rightarrow> 'a::{real_normed_field,banach}"

  1388 begin

  1389

  1390 lemma sums_imp_has_prod_exp:

  1391   assumes "f sums s"

  1392   shows "raw_has_prod (\<lambda>i. exp (f i)) 0 (exp s)"

  1393   using assms continuous_on_exp [of UNIV "\<lambda>x::'a. x"]

  1394   using continuous_on_tendsto_compose [of UNIV exp "(\<lambda>n. sum f {..n})" s]

  1395   by (simp add: prod_defs sums_def_le exp_sum)

  1396

  1397 lemma convergent_prod_exp:

  1398   assumes "summable f"

  1399   shows "convergent_prod (\<lambda>i. exp (f i))"

  1400   using sums_imp_has_prod_exp assms unfolding summable_def convergent_prod_def  by blast

  1401

  1402 lemma prodinf_exp:

  1403   assumes "summable f"

  1404   shows "prodinf (\<lambda>i. exp (f i)) = exp (suminf f)"

  1405 proof -

  1406   have "f sums suminf f"

  1407     using assms by blast

  1408   then have "(\<lambda>i. exp (f i)) has_prod exp (suminf f)"

  1409     by (simp add: has_prod_def sums_imp_has_prod_exp)

  1410   then show ?thesis

  1411     by (rule has_prod_unique [symmetric])

  1412 qed

  1413

  1414 end

  1415

  1416 lemma exp_suminf_prodinf_real:

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

  1418   assumes ge0:"\<And>n. f n \<ge> 0" and ac: "abs_convergent_prod (\<lambda>n. exp (f n))"

  1419   shows "prodinf (\<lambda>i. exp (f i)) = exp (suminf f)"

  1420 proof -

  1421   have "summable f"

  1422     using ac unfolding abs_convergent_prod_conv_summable

  1423   proof (elim summable_comparison_test')

  1424     fix n

  1425     show "norm (f n) \<le> norm (exp (f n) - 1)"

  1426       using ge0[of n]

  1427       by (metis abs_of_nonneg add.commute diff_add_cancel diff_ge_0_iff_ge exp_ge_add_one_self

  1428           exp_le_cancel_iff one_le_exp_iff real_norm_def)

  1429   qed

  1430   then show ?thesis

  1431     by (simp add: prodinf_exp)

  1432 qed

  1433

  1434 lemma has_prod_imp_sums_ln_real:

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

  1436   assumes "raw_has_prod f 0 p" and 0: "\<And>x. f x > 0"

  1437   shows "(\<lambda>i. ln (f i)) sums (ln p)"

  1438 proof -

  1439   have "p > 0"

  1440     using assms unfolding prod_defs by (metis LIMSEQ_prod_nonneg less_eq_real_def)

  1441   then show ?thesis

  1442   using assms continuous_on_ln [of "{0<..}" "\<lambda>x. x"]

  1443   using continuous_on_tendsto_compose [of "{0<..}" ln "(\<lambda>n. prod f {..n})" p]

  1444   by (auto simp: prod_defs sums_def_le ln_prod order_tendstoD)

  1445 qed

  1446

  1447 lemma summable_ln_real:

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

  1449   assumes f: "convergent_prod f" and 0: "\<And>x. f x > 0"

  1450   shows "summable (\<lambda>i. ln (f i))"

  1451 proof -

  1452   obtain M p where "raw_has_prod f M p"

  1453     using f convergent_prod_def by blast

  1454   then consider i where "i<M" "f i = 0" | p where "raw_has_prod f 0 p"

  1455     using raw_has_prod_cases by blast

  1456   then show ?thesis

  1457   proof cases

  1458     case 1

  1459     with 0 show ?thesis

  1460       by (metis less_irrefl)

  1461   next

  1462     case 2

  1463     then show ?thesis

  1464       using "0" has_prod_imp_sums_ln_real summable_def by blast

  1465   qed

  1466 qed

  1467

  1468 lemma suminf_ln_real:

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

  1470   assumes f: "convergent_prod f" and 0: "\<And>x. f x > 0"

  1471   shows "suminf (\<lambda>i. ln (f i)) = ln (prodinf f)"

  1472 proof -

  1473   have "f has_prod prodinf f"

  1474     by (simp add: f has_prod_iff)

  1475   then have "raw_has_prod f 0 (prodinf f)"

  1476     by (metis "0" has_prod_def less_irrefl)

  1477   then have "(\<lambda>i. ln (f i)) sums ln (prodinf f)"

  1478     using "0" has_prod_imp_sums_ln_real by blast

  1479   then show ?thesis

  1480     by (rule sums_unique [symmetric])

  1481 qed

  1482

  1483 lemma prodinf_exp_real:

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

  1485   assumes f: "convergent_prod f" and 0: "\<And>x. f x > 0"

  1486   shows "prodinf f = exp (suminf (\<lambda>i. ln (f i)))"

  1487   by (simp add: "0" f less_0_prodinf suminf_ln_real)

  1488

  1489

  1490 subsection\<open>Embeddings from the reals into some complete real normed field\<close>

  1491

  1492 lemma tendsto_eq_of_real_lim:

  1493   assumes "(\<lambda>n. of_real (f n) :: 'a::{complete_space,real_normed_field}) \<longlonglongrightarrow> q"

  1494   shows "q = of_real (lim f)"

  1495 proof -

  1496   have "convergent (\<lambda>n. of_real (f n) :: 'a)"

  1497     using assms convergent_def by blast

  1498   then have "convergent f"

  1499     unfolding convergent_def

  1500     by (simp add: convergent_eq_Cauchy Cauchy_def)

  1501   then show ?thesis

  1502     by (metis LIMSEQ_unique assms convergentD sequentially_bot tendsto_Lim tendsto_of_real)

  1503 qed

  1504

  1505 lemma tendsto_eq_of_real:

  1506   assumes "(\<lambda>n. of_real (f n) :: 'a::{complete_space,real_normed_field}) \<longlonglongrightarrow> q"

  1507   obtains r where "q = of_real r"

  1508   using tendsto_eq_of_real_lim assms by blast

  1509

  1510 lemma has_prod_of_real_iff:

  1511   "(\<lambda>n. of_real (f n) :: 'a::{complete_space,real_normed_field}) has_prod of_real c \<longleftrightarrow> f has_prod c"

  1512   (is "?lhs = ?rhs")

  1513 proof

  1514   assume ?lhs

  1515   then show ?rhs

  1516     apply (auto simp: prod_defs LIMSEQ_prod_0 tendsto_of_real_iff simp flip: of_real_prod)

  1517     using tendsto_eq_of_real

  1518     by (metis of_real_0 tendsto_of_real_iff)

  1519 next

  1520   assume ?rhs

  1521   with tendsto_of_real_iff show ?lhs

  1522     by (fastforce simp: prod_defs simp flip: of_real_prod)

  1523 qed

  1524

  1525 end
`