
hoelzl@42147: (*  Title:      HOL/Probability/Infinite_Product_Measure.thy
hoelzl@42147:     Author:     Johannes Hölzl, TU München
hoelzl@42147: *)
hoelzl@42147: 
hoelzl@42147: header {*Infinite Product Measure*}
hoelzl@42147: 
hoelzl@42147: theory Infinite_Product_Measure
immler@50039:   imports Probability_Measure Caratheodory Projective_Family
hoelzl@42147: begin
hoelzl@42147: 
hoelzl@47694: lemma (in product_prob_space) emeasure_PiM_emb_not_empty:
hoelzl@47694:   assumes X: "J \<noteq> {}" "J \<subseteq> I" "finite J" "\<forall>i\<in>J. X i \<in> sets (M i)"
wenzelm@53015:   shows "emeasure (Pi\<^sub>M I M) (emb I J (Pi\<^sub>E J X)) = emeasure (Pi\<^sub>M J M) (Pi\<^sub>E J X)"
hoelzl@42147: proof cases
hoelzl@47694:   assume "finite I" with X show ?thesis by simp
hoelzl@42147: next
wenzelm@53015:   let ?\<Omega> = "\<Pi>\<^sub>E i\<in>I. space (M i)"
hoelzl@42147:   let ?G = generator
hoelzl@42147:   assume "\<not> finite I"
hoelzl@45777:   then have I_not_empty: "I \<noteq> {}" by auto
hoelzl@47694:   interpret G!: algebra ?\<Omega> generator by (rule algebra_generator) fact
wenzelm@50252:   note mu_G_mono =
wenzelm@50252:     G.additive_increasing[OF positive_mu_G[OF I_not_empty] additive_mu_G[OF I_not_empty],
wenzelm@50252:       THEN increasingD]
wenzelm@50252:   write mu_G  ("\<mu>G")
hoelzl@42147: 
hoelzl@47694:   { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> ?G"
hoelzl@42147: 
hoelzl@42147:     from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
hoelzl@42147:       by (metis rev_finite_subset subsetI)
hoelzl@42147:     moreover from Z guess K' X' by (rule generatorE)
hoelzl@42147:     moreover def K \<equiv> "insert k K'"
hoelzl@42147:     moreover def X \<equiv> "emb K K' X'"
wenzelm@53015:     ultimately have K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "X \<in> sets (Pi\<^sub>M K M)" "Z = emb I K X"
wenzelm@53015:       "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = emeasure (Pi\<^sub>M K M) X"
hoelzl@42147:       by (auto simp: subset_insertI)
wenzelm@53015:     let ?M = "\<lambda>y. (\<lambda>x. merge J (K - J) (y, x)) -` emb (J \<union> K) K X \<inter> space (Pi\<^sub>M (K - J) M)"
wenzelm@53015:     { fix y assume y: "y \<in> space (Pi\<^sub>M J M)"
hoelzl@42147:       note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
hoelzl@42147:       moreover
wenzelm@53015:       have **: "?M y \<in> sets (Pi\<^sub>M (K - J) M)"
hoelzl@42147:         using J K y by (intro merge_sets) auto
hoelzl@42147:       ultimately
wenzelm@53015:       have ***: "((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^sub>M I M)) \<in> ?G"
hoelzl@42147:         using J K by (intro generatorI) auto
wenzelm@53015:       have "\<mu>G ((\<lambda>x. merge J (I - J) (y, x)) -` emb I K X \<inter> space (Pi\<^sub>M I M)) = emeasure (Pi\<^sub>M (K - J) M) (?M y)"
wenzelm@50252:         unfolding * using K J by (subst mu_G_eq[OF _ _ _ **]) auto
hoelzl@42147:       note * ** *** this }
hoelzl@42147:     note merge_in_G = this
hoelzl@42147: 
hoelzl@42147:     have "finite (K - J)" using K by auto
hoelzl@42147: 
hoelzl@42147:     interpret J: finite_product_prob_space M J by default fact+
hoelzl@42147:     interpret KmJ: finite_product_prob_space M "K - J" by default fact+
hoelzl@42147: 
wenzelm@53015:     have "\<mu>G Z = emeasure (Pi\<^sub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
hoelzl@42147:       using K J by simp
wenzelm@53015:     also have "\<dots> = (\<integral>\<^sup>+ x. emeasure (Pi\<^sub>M (K - J) M) (?M x) \<partial>Pi\<^sub>M J M)"
hoelzl@47694:       using K J by (subst emeasure_fold_integral) auto
wenzelm@53015:     also have "\<dots> = (\<integral>\<^sup>+ y. \<mu>G ((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^sub>M I M)) \<partial>Pi\<^sub>M J M)"
wenzelm@53015:       (is "_ = (\<integral>\<^sup>+x. \<mu>G (?MZ x) \<partial>Pi\<^sub>M J M)")
hoelzl@56996:     proof (intro nn_integral_cong)
wenzelm@53015:       fix x assume x: "x \<in> space (Pi\<^sub>M J M)"
hoelzl@42147:       with K merge_in_G(2)[OF this]
wenzelm@53015:       show "emeasure (Pi\<^sub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
wenzelm@50252:         unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst mu_G_eq) auto
hoelzl@42147:     qed
wenzelm@53015:     finally have fold: "\<mu>G Z = (\<integral>\<^sup>+x. \<mu>G (?MZ x) \<partial>Pi\<^sub>M J M)" .
hoelzl@42147: 
wenzelm@53015:     { fix x assume x: "x \<in> space (Pi\<^sub>M J M)"
hoelzl@42147:       then have "\<mu>G (?MZ x) \<le> 1"
hoelzl@42147:         unfolding merge_in_G(4)[OF x] `Z = emb I K X`
hoelzl@42147:         by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
hoelzl@42147:     note le_1 = this
hoelzl@42147: 
wenzelm@53015:     let ?q = "\<lambda>y. \<mu>G ((\<lambda>x. merge J (I - J) (y,x)) -` Z \<inter> space (Pi\<^sub>M I M))"
wenzelm@53015:     have "?q \<in> borel_measurable (Pi\<^sub>M J M)"
hoelzl@42147:       unfolding `Z = emb I K X` using J K merge_in_G(3)
wenzelm@50252:       by (simp add: merge_in_G  mu_G_eq emeasure_fold_measurable cong: measurable_cong)
hoelzl@42147:     note this fold le_1 merge_in_G(3) }
hoelzl@42147:   note fold = this
hoelzl@42147: 
hoelzl@47694:   have "\<exists>\<mu>. (\<forall>s\<in>?G. \<mu> s = \<mu>G s) \<and> measure_space ?\<Omega> (sigma_sets ?\<Omega> ?G) \<mu>"
wenzelm@50252:   proof (rule G.caratheodory_empty_continuous[OF positive_mu_G additive_mu_G])
hoelzl@47694:     fix A assume "A \<in> ?G"
hoelzl@42147:     with generatorE guess J X . note JX = this
hoelzl@50000:     interpret JK: finite_product_prob_space M J by default fact+ 
wenzelm@46898:     from JX show "\<mu>G A \<noteq> \<infinity>" by simp
hoelzl@42147:   next
hoelzl@47694:     fix A assume A: "range A \<subseteq> ?G" "decseq A" "(\<Inter>i. A i) = {}"
hoelzl@42147:     then have "decseq (\<lambda>i. \<mu>G (A i))"
wenzelm@50252:       by (auto intro!: mu_G_mono simp: decseq_def)
hoelzl@42147:     moreover
hoelzl@42147:     have "(INF i. \<mu>G (A i)) = 0"
hoelzl@42147:     proof (rule ccontr)
hoelzl@42147:       assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
hoelzl@42147:       moreover have "0 \<le> ?a"
wenzelm@50252:         using A positive_mu_G[OF I_not_empty] by (auto intro!: INF_greatest simp: positive_def)
hoelzl@42147:       ultimately have "0 < ?a" by auto
hoelzl@42147: 
wenzelm@53015:       have "\<forall>n. \<exists>J X. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I \<and> X \<in> sets (Pi\<^sub>M J M) \<and> A n = emb I J X \<and> \<mu>G (A n) = emeasure (limP J M (\<lambda>J. (Pi\<^sub>M J M))) X"
hoelzl@42147:         using A by (intro allI generator_Ex) auto
wenzelm@53015:       then obtain J' X' where J': "\<And>n. J' n \<noteq> {}" "\<And>n. finite (J' n)" "\<And>n. J' n \<subseteq> I" "\<And>n. X' n \<in> sets (Pi\<^sub>M (J' n) M)"
hoelzl@42147:         and A': "\<And>n. A n = emb I (J' n) (X' n)"
hoelzl@42147:         unfolding choice_iff by blast
hoelzl@42147:       moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
hoelzl@42147:       moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
wenzelm@53015:       ultimately have J: "\<And>n. J n \<noteq> {}" "\<And>n. finite (J n)" "\<And>n. J n \<subseteq> I" "\<And>n. X n \<in> sets (Pi\<^sub>M (J n) M)"
hoelzl@42147:         by auto
hoelzl@47694:       with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> ?G"
hoelzl@47694:         unfolding J_def X_def by (subst prod_emb_trans) (insert A, auto)
hoelzl@42147: 
hoelzl@42147:       have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
hoelzl@42147:         unfolding J_def by force
hoelzl@42147: 
hoelzl@42147:       interpret J: finite_product_prob_space M "J i" for i by default fact+
hoelzl@42147: 
hoelzl@42147:       have a_le_1: "?a \<le> 1"
wenzelm@50252:         using mu_G_spec[of "J 0" "A 0" "X 0"] J A_eq
hoelzl@44928:         by (auto intro!: INF_lower2[of 0] J.measure_le_1)
hoelzl@42147: 
wenzelm@53015:       let ?M = "\<lambda>K Z y. (\<lambda>x. merge K (I - K) (y, x)) -` Z \<inter> space (Pi\<^sub>M I M)"
hoelzl@42147: 
hoelzl@47694:       { fix Z k assume Z: "range Z \<subseteq> ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
hoelzl@47694:         then have Z_sets: "\<And>n. Z n \<in> ?G" by auto
hoelzl@42147:         fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
hoelzl@42147:         interpret J': finite_product_prob_space M J' by default fact+
hoelzl@42147: 
wenzelm@46731:         let ?q = "\<lambda>n y. \<mu>G (?M J' (Z n) y)"
wenzelm@53015:         let ?Q = "\<lambda>n. ?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^sub>M J' M)"
hoelzl@42147:         { fix n
wenzelm@53015:           have "?q n \<in> borel_measurable (Pi\<^sub>M J' M)"
hoelzl@42147:             using Z J' by (intro fold(1)) auto
wenzelm@53015:           then have "?Q n \<in> sets (Pi\<^sub>M J' M)"
hoelzl@42147:             by (rule measurable_sets) auto }
hoelzl@42147:         note Q_sets = this
hoelzl@42147: 
wenzelm@53015:         have "?a / 2^(k+1) \<le> (INF n. emeasure (Pi\<^sub>M J' M) (?Q n))"
hoelzl@44928:         proof (intro INF_greatest)
hoelzl@42147:           fix n
hoelzl@42147:           have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
wenzelm@53015:           also have "\<dots> \<le> (\<integral>\<^sup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^sub>M J' M)"
hoelzl@47694:             unfolding fold(2)[OF J' `Z n \<in> ?G`]
hoelzl@56996:           proof (intro nn_integral_mono)
wenzelm@53015:             fix x assume x: "x \<in> space (Pi\<^sub>M J' M)"
hoelzl@42147:             then have "?q n x \<le> 1 + 0"
hoelzl@42147:               using J' Z fold(3) Z_sets by auto
hoelzl@42147:             also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
hoelzl@42147:               using `0 < ?a` by (intro add_mono) auto
hoelzl@42147:             finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
hoelzl@42147:             with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
hoelzl@42147:               by (auto split: split_indicator simp del: power_Suc)
hoelzl@42147:           qed
wenzelm@53015:           also have "\<dots> = emeasure (Pi\<^sub>M J' M) (?Q n) + ?a / 2^(k+1)"
hoelzl@47694:             using `0 \<le> ?a` Q_sets J'.emeasure_space_1
hoelzl@56996:             by (subst nn_integral_add) auto
wenzelm@53015:           finally show "?a / 2^(k+1) \<le> emeasure (Pi\<^sub>M J' M) (?Q n)" using `?a \<le> 1`
wenzelm@53015:             by (cases rule: ereal2_cases[of ?a "emeasure (Pi\<^sub>M J' M) (?Q n)"])
hoelzl@42147:                (auto simp: field_simps)
hoelzl@42147:         qed
wenzelm@53015:         also have "\<dots> = emeasure (Pi\<^sub>M J' M) (\<Inter>n. ?Q n)"
hoelzl@47694:         proof (intro INF_emeasure_decseq)
wenzelm@53015:           show "range ?Q \<subseteq> sets (Pi\<^sub>M J' M)" using Q_sets by auto
hoelzl@42147:           show "decseq ?Q"
hoelzl@42147:             unfolding decseq_def
hoelzl@42147:           proof (safe intro!: vimageI[OF refl])
hoelzl@42147:             fix m n :: nat assume "m \<le> n"
wenzelm@53015:             fix x assume x: "x \<in> space (Pi\<^sub>M J' M)"
hoelzl@42147:             assume "?a / 2^(k+1) \<le> ?q n x"
hoelzl@42147:             also have "?q n x \<le> ?q m x"
wenzelm@50252:             proof (rule mu_G_mono)
hoelzl@42147:               from fold(4)[OF J', OF Z_sets x]
hoelzl@47694:               show "?M J' (Z n) x \<in> ?G" "?M J' (Z m) x \<in> ?G" by auto
hoelzl@42147:               show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
hoelzl@42147:                 using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
hoelzl@42147:             qed
hoelzl@42147:             finally show "?a / 2^(k+1) \<le> ?q m x" .
hoelzl@42147:           qed
hoelzl@47694:         qed simp
hoelzl@42147:         finally have "(\<Inter>n. ?Q n) \<noteq> {}"
hoelzl@42147:           using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
wenzelm@53015:         then have "\<exists>w\<in>space (Pi\<^sub>M J' M). \<forall>n. ?a / 2 ^ (k + 1) \<le> ?q n w" by auto }
hoelzl@42147:       note Ex_w = this
hoelzl@42147: 
wenzelm@46731:       let ?q = "\<lambda>k n y. \<mu>G (?M (J k) (A n) y)"
hoelzl@42147: 
hoelzl@44928:       have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_lower)
hoelzl@42147:       from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
hoelzl@42147: 
wenzelm@46731:       let ?P =
wenzelm@53015:         "\<lambda>k wk w. w \<in> space (Pi\<^sub>M (J (Suc k)) M) \<and> restrict w (J k) = wk \<and>
wenzelm@46731:           (\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n w)"
blanchet@55415:       def w \<equiv> "rec_nat w0 (\<lambda>k wk. Eps (?P k wk))"
hoelzl@42147: 
wenzelm@53015:       { fix k have w: "w k \<in> space (Pi\<^sub>M (J k) M) \<and>
hoelzl@42147:           (\<forall>n. ?a / 2 ^ (k + 1) \<le> ?q k n (w k)) \<and> (k \<noteq> 0 \<longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1))"
hoelzl@42147:         proof (induct k)
hoelzl@42147:           case 0 with w0 show ?case
blanchet@55642:             unfolding w_def nat.rec(1) by auto
hoelzl@42147:         next
hoelzl@42147:           case (Suc k)
wenzelm@53015:           then have wk: "w k \<in> space (Pi\<^sub>M (J k) M)" by auto
hoelzl@42147:           have "\<exists>w'. ?P k (w k) w'"
hoelzl@42147:           proof cases
hoelzl@42147:             assume [simp]: "J k = J (Suc k)"
hoelzl@42147:             show ?thesis
hoelzl@42147:             proof (intro exI[of _ "w k"] conjI allI)
hoelzl@42147:               fix n
hoelzl@42147:               have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
hoelzl@42147:                 using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
hoelzl@42147:               also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
hoelzl@42147:               finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
hoelzl@42147:             next
wenzelm@53015:               show "w k \<in> space (Pi\<^sub>M (J (Suc k)) M)"
hoelzl@42147:                 using Suc by simp
hoelzl@42147:               then show "restrict (w k) (J k) = w k"
hoelzl@47694:                 by (simp add: extensional_restrict space_PiM)
hoelzl@42147:             qed
hoelzl@42147:           next
hoelzl@42147:             assume "J k \<noteq> J (Suc k)"
hoelzl@42147:             with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
hoelzl@47694:             have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> ?G"
hoelzl@42147:               "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
hoelzl@42147:               "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
hoelzl@42147:               using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
hoelzl@42147:               by (auto simp: decseq_def)
hoelzl@42147:             from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
wenzelm@53015:             obtain w' where w': "w' \<in> space (Pi\<^sub>M ?D M)"
hoelzl@42147:               "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
hoelzl@49780:             let ?w = "merge (J k) ?D (w k, w')"
hoelzl@49780:             have [simp]: "\<And>x. merge (J k) (I - J k) (w k, merge ?D (I - ?D) (w', x)) =
hoelzl@49780:               merge (J (Suc k)) (I - (J (Suc k))) (?w, x)"
hoelzl@42147:               using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
hoelzl@42147:               by (auto intro!: ext split: split_merge)
hoelzl@42147:             have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
hoelzl@42147:               using w'(1) J(3)[of "Suc k"]
hoelzl@47694:               by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+
hoelzl@42147:             show ?thesis
hoelzl@42147:               using w' J_mono[of k "Suc k"] wk unfolding *
hoelzl@50123:               by (intro exI[of _ ?w])
hoelzl@50123:                  (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM PiE_iff)
hoelzl@42147:           qed
hoelzl@42147:           then have "?P k (w k) (w (Suc k))"
blanchet@55642:             unfolding w_def nat.rec(2) unfolding w_def[symmetric]
hoelzl@42147:             by (rule someI_ex)
hoelzl@42147:           then show ?case by auto
hoelzl@42147:         qed
hoelzl@42147:         moreover
wenzelm@53374:         from w have "w k \<in> space (Pi\<^sub>M (J k) M)" by auto
hoelzl@42147:         moreover
hoelzl@42147:         from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
hoelzl@42147:         then have "?M (J k) (A k) (w k) \<noteq> {}"
wenzelm@50252:           using positive_mu_G[OF I_not_empty, unfolded positive_def] `0 < ?a` `?a \<le> 1`
hoelzl@42147:           by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147:         then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
hoelzl@49780:         then have "merge (J k) (I - J k) (w k, x) \<in> A k" by auto
hoelzl@42147:         then have "\<exists>x\<in>A k. restrict x (J k) = w k"
wenzelm@53015:           using `w k \<in> space (Pi\<^sub>M (J k) M)`
hoelzl@47694:           by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM)
wenzelm@53015:         ultimately have "w k \<in> space (Pi\<^sub>M (J k) M)"
hoelzl@42147:           "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147:           "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
hoelzl@42147:           by auto }
hoelzl@42147:       note w = this
hoelzl@42147: 
hoelzl@42147:       { fix k l i assume "k \<le> l" "i \<in> J k"
hoelzl@42147:         { fix l have "w k i = w (k + l) i"
hoelzl@42147:           proof (induct l)
hoelzl@42147:             case (Suc l)
hoelzl@42147:             from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
hoelzl@42147:             with w(3)[of "k + Suc l"]
hoelzl@42147:             have "w (k + l) i = w (k + Suc l) i"
hoelzl@42147:               by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
hoelzl@42147:             with Suc show ?case by simp
hoelzl@42147:           qed simp }
hoelzl@42147:         from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
hoelzl@42147:       note w_mono = this
hoelzl@42147: 
hoelzl@42147:       def w' \<equiv> "\<lambda>i. if i \<in> (\<Union>k. J k) then w (LEAST k. i \<in> J k) i else if i \<in> I then (SOME x. x \<in> space (M i)) else undefined"
hoelzl@42147:       { fix i k assume k: "i \<in> J k"
hoelzl@42147:         have "w k i = w (LEAST k. i \<in> J k) i"
hoelzl@42147:           by (intro w_mono Least_le k LeastI[of _ k])
hoelzl@42147:         then have "w' i = w k i"
hoelzl@42147:           unfolding w'_def using k by auto }
hoelzl@42147:       note w'_eq = this
hoelzl@42147:       have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
hoelzl@42147:         using J by (auto simp: w'_def)
hoelzl@42147:       have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
hoelzl@42147:         using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
hoelzl@42147:       { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
hoelzl@47694:           using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq space_PiM)+ }
hoelzl@42147:       note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
hoelzl@42147: 
wenzelm@53015:       have w': "w' \<in> space (Pi\<^sub>M I M)"
hoelzl@47694:         using w(1) by (auto simp add: Pi_iff extensional_def space_PiM)
hoelzl@42147: 
hoelzl@42147:       { fix n
hoelzl@50123:         have "restrict w' (J n) = w n" using w(1)[of n]
hoelzl@50123:           by (auto simp add: fun_eq_iff space_PiM)
hoelzl@42147:         with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
hoelzl@47694:         then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: prod_emb_def space_PiM) }
hoelzl@42147:       then have "w' \<in> (\<Inter>i. A i)" by auto
hoelzl@42147:       with `(\<Inter>i. A i) = {}` show False by auto
hoelzl@42147:     qed
hoelzl@42147:     ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
hoelzl@51351:       using LIMSEQ_INF[of "\<lambda>i. \<mu>G (A i)"] by simp
hoelzl@45777:   qed fact+
hoelzl@45777:   then guess \<mu> .. note \<mu> = this
hoelzl@45777:   show ?thesis
hoelzl@47694:   proof (subst emeasure_extend_measure_Pair[OF PiM_def, of I M \<mu> J X])
hoelzl@47694:     from assms show "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))"
hoelzl@47694:       by (simp add: Pi_iff)
hoelzl@47694:   next
hoelzl@47694:     fix J X assume J: "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))"
wenzelm@53015:     then show "emb I J (Pi\<^sub>E J X) \<in> Pow (\<Pi>\<^sub>E i\<in>I. space (M i))"
immler@50244:       by (auto simp: Pi_iff prod_emb_def dest: sets.sets_into_space)
wenzelm@53015:     have "emb I J (Pi\<^sub>E J X) \<in> generator"
hoelzl@50003:       using J `I \<noteq> {}` by (intro generatorI') (auto simp: Pi_iff)
wenzelm@53015:     then have "\<mu> (emb I J (Pi\<^sub>E J X)) = \<mu>G (emb I J (Pi\<^sub>E J X))"
hoelzl@47694:       using \<mu> by simp
hoelzl@47694:     also have "\<dots> = (\<Prod> j\<in>J. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
wenzelm@50252:       using J  `I \<noteq> {}` by (subst mu_G_spec[OF _ _ _ refl]) (auto simp: emeasure_PiM Pi_iff)
hoelzl@47694:     also have "\<dots> = (\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}.
hoelzl@47694:       if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
haftmann@57418:       using J `I \<noteq> {}` by (intro setprod.mono_neutral_right) (auto simp: M.emeasure_space_1)
wenzelm@53015:     finally show "\<mu> (emb I J (Pi\<^sub>E J X)) = \<dots>" .
hoelzl@47694:   next
hoelzl@47694:     let ?F = "\<lambda>j. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j))"
hoelzl@47694:     have "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) = (\<Prod>j\<in>J. ?F j)"
haftmann@57418:       using X `I \<noteq> {}` by (intro setprod.mono_neutral_right) (auto simp: M.emeasure_space_1)
hoelzl@47694:     then show "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) =
wenzelm@53015:       emeasure (Pi\<^sub>M J M) (Pi\<^sub>E J X)"
hoelzl@47694:       using X by (auto simp add: emeasure_PiM) 
hoelzl@47694:   next
wenzelm@53015:     show "positive (sets (Pi\<^sub>M I M)) \<mu>" "countably_additive (sets (Pi\<^sub>M I M)) \<mu>"
hoelzl@49804:       using \<mu> unfolding sets_PiM_generator by (auto simp: measure_space_def)
hoelzl@42147:   qed
hoelzl@42147: qed
hoelzl@42147: 
wenzelm@53015: sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^sub>M I M"
hoelzl@42257: proof
wenzelm@53015:   show "emeasure (Pi\<^sub>M I M) (space (Pi\<^sub>M I M)) = 1"
hoelzl@47694:   proof cases
hoelzl@47694:     assume "I = {}" then show ?thesis by (simp add: space_PiM_empty)
hoelzl@47694:   next
hoelzl@47694:     assume "I \<noteq> {}"
wenzelm@53374:     then obtain i where i: "i \<in> I" by auto
wenzelm@53374:     then have "emb I {i} (\<Pi>\<^sub>E i\<in>{i}. space (M i)) = (space (Pi\<^sub>M I M))"
hoelzl@47694:       by (auto simp: prod_emb_def space_PiM)
wenzelm@53374:     with i show ?thesis
hoelzl@47694:       using emeasure_PiM_emb_not_empty[of "{i}" "\<lambda>i. space (M i)"]
hoelzl@47694:       by (simp add: emeasure_PiM emeasure_space_1)
hoelzl@47694:   qed
hoelzl@42257: qed
hoelzl@42257: 
hoelzl@47694: lemma (in product_prob_space) emeasure_PiM_emb:
hoelzl@47694:   assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
wenzelm@53015:   shows "emeasure (Pi\<^sub>M I M) (emb I J (Pi\<^sub>E J X)) = (\<Prod> i\<in>J. emeasure (M i) (X i))"
hoelzl@47694: proof cases
hoelzl@47694:   assume "J = {}"
wenzelm@53015:   moreover have "emb I {} {\<lambda>x. undefined} = space (Pi\<^sub>M I M)"
hoelzl@47694:     by (auto simp: space_PiM prod_emb_def)
hoelzl@47694:   ultimately show ?thesis
hoelzl@47694:     by (simp add: space_PiM_empty P.emeasure_space_1)
hoelzl@47694: next
hoelzl@47694:   assume "J \<noteq> {}" with X show ?thesis
hoelzl@47694:     by (subst emeasure_PiM_emb_not_empty) (auto simp: emeasure_PiM)
hoelzl@42257: qed
hoelzl@42257: 
hoelzl@50000: lemma (in product_prob_space) emeasure_PiM_Collect:
hoelzl@50000:   assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
wenzelm@53015:   shows "emeasure (Pi\<^sub>M I M) {x\<in>space (Pi\<^sub>M I M). \<forall>i\<in>J. x i \<in> X i} = (\<Prod> i\<in>J. emeasure (M i) (X i))"
hoelzl@50000: proof -
wenzelm@53015:   have "{x\<in>space (Pi\<^sub>M I M). \<forall>i\<in>J. x i \<in> X i} = emb I J (Pi\<^sub>E J X)"
hoelzl@50000:     unfolding prod_emb_def using assms by (auto simp: space_PiM Pi_iff)
hoelzl@50000:   with emeasure_PiM_emb[OF assms] show ?thesis by simp
hoelzl@50000: qed
hoelzl@50000: 
hoelzl@50000: lemma (in product_prob_space) emeasure_PiM_Collect_single:
hoelzl@50000:   assumes X: "i \<in> I" "A \<in> sets (M i)"
wenzelm@53015:   shows "emeasure (Pi\<^sub>M I M) {x\<in>space (Pi\<^sub>M I M). x i \<in> A} = emeasure (M i) A"
hoelzl@50000:   using emeasure_PiM_Collect[of "{i}" "\<lambda>i. A"] assms
hoelzl@50000:   by simp
hoelzl@50000: 
hoelzl@47694: lemma (in product_prob_space) measure_PiM_emb:
hoelzl@47694:   assumes "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
wenzelm@53015:   shows "measure (PiM I M) (emb I J (Pi\<^sub>E J X)) = (\<Prod> i\<in>J. measure (M i) (X i))"
hoelzl@47694:   using emeasure_PiM_emb[OF assms]
hoelzl@47694:   unfolding emeasure_eq_measure M.emeasure_eq_measure by (simp add: setprod_ereal)
hoelzl@42865: 
hoelzl@50000: lemma sets_Collect_single':
hoelzl@50000:   "i \<in> I \<Longrightarrow> {x\<in>space (M i). P x} \<in> sets (M i) \<Longrightarrow> {x\<in>space (PiM I M). P (x i)} \<in> sets (PiM I M)"
hoelzl@50000:   using sets_Collect_single[of i I "{x\<in>space (M i). P x}" M]
hoelzl@50123:   by (simp add: space_PiM PiE_iff cong: conj_cong)
hoelzl@50000: 
hoelzl@47694: lemma (in finite_product_prob_space) finite_measure_PiM_emb:
wenzelm@53015:   "(\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> measure (PiM I M) (Pi\<^sub>E I A) = (\<Prod>i\<in>I. measure (M i) (A i))"
immler@50244:   using measure_PiM_emb[of I A] finite_index prod_emb_PiE_same_index[OF sets.sets_into_space, of I A M]
hoelzl@47694:   by auto
hoelzl@42865: 
hoelzl@50000: lemma (in product_prob_space) PiM_component:
hoelzl@50000:   assumes "i \<in> I"
hoelzl@50000:   shows "distr (PiM I M) (M i) (\<lambda>\<omega>. \<omega> i) = M i"
hoelzl@50000: proof (rule measure_eqI[symmetric])
hoelzl@50000:   fix A assume "A \<in> sets (M i)"
hoelzl@50000:   moreover have "((\<lambda>\<omega>. \<omega> i) -` A \<inter> space (PiM I M)) = {x\<in>space (PiM I M). x i \<in> A}"
hoelzl@50000:     by auto
hoelzl@50000:   ultimately show "emeasure (M i) A = emeasure (distr (PiM I M) (M i) (\<lambda>\<omega>. \<omega> i)) A"
hoelzl@50000:     by (auto simp: `i\<in>I` emeasure_distr measurable_component_singleton emeasure_PiM_Collect_single)
hoelzl@50000: qed simp
hoelzl@50000: 
hoelzl@50000: lemma (in product_prob_space) PiM_eq:
hoelzl@50000:   assumes "I \<noteq> {}"
hoelzl@50000:   assumes "sets M' = sets (PiM I M)"
hoelzl@50000:   assumes eq: "\<And>J F. finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>j. j \<in> J \<Longrightarrow> F j \<in> sets (M j)) \<Longrightarrow>
wenzelm@53015:     emeasure M' (prod_emb I M J (\<Pi>\<^sub>E j\<in>J. F j)) = (\<Prod>j\<in>J. emeasure (M j) (F j))"
hoelzl@50000:   shows "M' = (PiM I M)"
hoelzl@50000: proof (rule measure_eqI_generator_eq[symmetric, OF Int_stable_prod_algebra prod_algebra_sets_into_space])
wenzelm@53015:   show "sets (PiM I M) = sigma_sets (\<Pi>\<^sub>E i\<in>I. space (M i)) (prod_algebra I M)"
hoelzl@50000:     by (rule sets_PiM)
wenzelm@53015:   then show "sets M' = sigma_sets (\<Pi>\<^sub>E i\<in>I. space (M i)) (prod_algebra I M)"
hoelzl@50000:     unfolding `sets M' = sets (PiM I M)` by simp
hoelzl@50000: 
hoelzl@50000:   def i \<equiv> "SOME i. i \<in> I"
hoelzl@50000:   with `I \<noteq> {}` have i: "i \<in> I"
hoelzl@50000:     by (auto intro: someI_ex)
hoelzl@50000: 
wenzelm@53015:   def A \<equiv> "\<lambda>n::nat. prod_emb I M {i} (\<Pi>\<^sub>E j\<in>{i}. space (M i))"
hoelzl@50000:   then show "range A \<subseteq> prod_algebra I M"
hoelzl@50000:     by (auto intro!: prod_algebraI i)
hoelzl@50000: 
hoelzl@50000:   have A_eq: "\<And>i. A i = space (PiM I M)"
hoelzl@50000:     by (auto simp: prod_emb_def space_PiM Pi_iff A_def i)
wenzelm@53015:   show "(\<Union>i. A i) = (\<Pi>\<^sub>E i\<in>I. space (M i))"
hoelzl@50000:     unfolding A_eq by (auto simp: space_PiM)
hoelzl@50000:   show "\<And>i. emeasure (PiM I M) (A i) \<noteq> \<infinity>"
hoelzl@50000:     unfolding A_eq P.emeasure_space_1 by simp
hoelzl@50000: next
hoelzl@50000:   fix X assume X: "X \<in> prod_algebra I M"
hoelzl@50000:   then obtain J E where X: "X = prod_emb I M J (PIE j:J. E j)"
hoelzl@50000:     and J: "finite J" "J \<subseteq> I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets (M j)"
hoelzl@50000:     by (force elim!: prod_algebraE)
hoelzl@50000:   from eq[OF J] have "emeasure M' X = (\<Prod>j\<in>J. emeasure (M j) (E j))"
hoelzl@50000:     by (simp add: X)
hoelzl@50000:   also have "\<dots> = emeasure (PiM I M) X"
hoelzl@50000:     unfolding X using J by (intro emeasure_PiM_emb[symmetric]) auto
hoelzl@50000:   finally show "emeasure (PiM I M) X = emeasure M' X" ..
hoelzl@50000: qed
hoelzl@50000: 
hoelzl@42257: subsection {* Sequence space *}
hoelzl@42257: 
hoelzl@50000: definition comb_seq :: "nat \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a)" where
hoelzl@50000:   "comb_seq i \<omega> \<omega>' j = (if j < i then \<omega> j else \<omega>' (j - i))"
hoelzl@50000: 
hoelzl@50000: lemma split_comb_seq: "P (comb_seq i \<omega> \<omega>' j) \<longleftrightarrow> (j < i \<longrightarrow> P (\<omega> j)) \<and> (\<forall>k. j = i + k \<longrightarrow> P (\<omega>' k))"
hoelzl@50000:   by (auto simp: comb_seq_def not_less)
hoelzl@50000: 
hoelzl@50000: lemma split_comb_seq_asm: "P (comb_seq i \<omega> \<omega>' j) \<longleftrightarrow> \<not> ((j < i \<and> \<not> P (\<omega> j)) \<or> (\<exists>k. j = i + k \<and> \<not> P (\<omega>' k)))"
hoelzl@50000:   by (auto simp: comb_seq_def)
hoelzl@42257: 
hoelzl@50099: lemma measurable_comb_seq:
wenzelm@53015:   "(\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') \<in> measurable ((\<Pi>\<^sub>M i\<in>UNIV. M) \<Otimes>\<^sub>M (\<Pi>\<^sub>M i\<in>UNIV. M)) (\<Pi>\<^sub>M i\<in>UNIV. M)"
hoelzl@50000: proof (rule measurable_PiM_single)
wenzelm@53015:   show "(\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') \<in> space ((\<Pi>\<^sub>M i\<in>UNIV. M) \<Otimes>\<^sub>M (\<Pi>\<^sub>M i\<in>UNIV. M)) \<rightarrow> (UNIV \<rightarrow>\<^sub>E space M)"
hoelzl@50123:     by (auto simp: space_pair_measure space_PiM PiE_iff split: split_comb_seq)
hoelzl@50000:   fix j :: nat and A assume A: "A \<in> sets M"
blanchet@55414:   then have *: "{\<omega> \<in> space ((\<Pi>\<^sub>M i\<in>UNIV. M) \<Otimes>\<^sub>M (\<Pi>\<^sub>M i\<in>UNIV. M)). case_prod (comb_seq i) \<omega> j \<in> A} =
wenzelm@53015:     (if j < i then {\<omega> \<in> space (\<Pi>\<^sub>M i\<in>UNIV. M). \<omega> j \<in> A} \<times> space (\<Pi>\<^sub>M i\<in>UNIV. M)
wenzelm@53015:               else space (\<Pi>\<^sub>M i\<in>UNIV. M) \<times> {\<omega> \<in> space (\<Pi>\<^sub>M i\<in>UNIV. M). \<omega> (j - i) \<in> A})"
immler@50244:     by (auto simp: space_PiM space_pair_measure comb_seq_def dest: sets.sets_into_space)
blanchet@55414:   show "{\<omega> \<in> space ((\<Pi>\<^sub>M i\<in>UNIV. M) \<Otimes>\<^sub>M (\<Pi>\<^sub>M i\<in>UNIV. M)). case_prod (comb_seq i) \<omega> j \<in> A} \<in> sets ((\<Pi>\<^sub>M i\<in>UNIV. M) \<Otimes>\<^sub>M (\<Pi>\<^sub>M i\<in>UNIV. M))"
hoelzl@50000:     unfolding * by (auto simp: A intro!: sets_Collect_single)
hoelzl@50000: qed
hoelzl@50000: 
hoelzl@50099: lemma measurable_comb_seq'[measurable (raw)]:
wenzelm@53015:   assumes f: "f \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)" and g: "g \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
wenzelm@53015:   shows "(\<lambda>x. comb_seq i (f x) (g x)) \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
hoelzl@50000:   using measurable_compose[OF measurable_Pair[OF f g] measurable_comb_seq] by simp
hoelzl@50000: 
hoelzl@50099: lemma comb_seq_0: "comb_seq 0 \<omega> \<omega>' = \<omega>'"
hoelzl@50099:   by (auto simp add: comb_seq_def)
hoelzl@50099: 
blanchet@55415: lemma comb_seq_Suc: "comb_seq (Suc n) \<omega> \<omega>' = comb_seq n \<omega> (case_nat (\<omega> n) \<omega>')"
hoelzl@50099:   by (auto simp add: comb_seq_def not_less less_Suc_eq le_imp_diff_is_add intro!: ext split: nat.split)
hoelzl@50099: 
blanchet@55415: lemma comb_seq_Suc_0[simp]: "comb_seq (Suc 0) \<omega> = case_nat (\<omega> 0)"
hoelzl@50099:   by (intro ext) (simp add: comb_seq_Suc comb_seq_0)
hoelzl@50099: 
hoelzl@50099: lemma comb_seq_less: "i < n \<Longrightarrow> comb_seq n \<omega> \<omega>' i = \<omega> i"
hoelzl@50099:   by (auto split: split_comb_seq)
hoelzl@50099: 
hoelzl@50099: lemma comb_seq_add: "comb_seq n \<omega> \<omega>' (i + n) = \<omega>' i"
hoelzl@50099:   by (auto split: nat.split split_comb_seq)
hoelzl@50099: 
blanchet@55415: lemma case_nat_comb_seq: "case_nat s' (comb_seq n \<omega> \<omega>') (i + n) = case_nat (case_nat s' \<omega> n) \<omega>' i"
hoelzl@50099:   by (auto split: nat.split split_comb_seq)
hoelzl@50099: 
blanchet@55415: lemma case_nat_comb_seq':
blanchet@55415:   "case_nat s (comb_seq i \<omega> \<omega>') = comb_seq (Suc i) (case_nat s \<omega>) \<omega>'"
hoelzl@50099:   by (auto split: split_comb_seq nat.split)
hoelzl@50099: 
hoelzl@50000: locale sequence_space = product_prob_space "\<lambda>i. M" "UNIV :: nat set" for M
hoelzl@50000: begin
hoelzl@50000: 
wenzelm@53015: abbreviation "S \<equiv> \<Pi>\<^sub>M i\<in>UNIV::nat set. M"
hoelzl@50000: 
hoelzl@50000: lemma infprod_in_sets[intro]:
hoelzl@50000:   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets M"
hoelzl@50000:   shows "Pi UNIV E \<in> sets S"
hoelzl@42257: proof -
wenzelm@53015:   have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^sub>E j\<in>{..i}. E j))"
immler@50244:     using E E[THEN sets.sets_into_space]
hoelzl@47694:     by (auto simp: prod_emb_def Pi_iff extensional_def) blast
hoelzl@47694:   with E show ?thesis by auto
hoelzl@42257: qed
hoelzl@42257: 
hoelzl@50000: lemma measure_PiM_countable:
hoelzl@50000:   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets M"
hoelzl@50000:   shows "(\<lambda>n. \<Prod>i\<le>n. measure M (E i)) ----> measure S (Pi UNIV E)"
hoelzl@42257: proof -
wenzelm@53015:   let ?E = "\<lambda>n. emb UNIV {..n} (Pi\<^sub>E {.. n} E)"
hoelzl@50000:   have "\<And>n. (\<Prod>i\<le>n. measure M (E i)) = measure S (?E n)"
hoelzl@47694:     using E by (simp add: measure_PiM_emb)
hoelzl@42257:   moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
immler@50244:     using E E[THEN sets.sets_into_space]
hoelzl@47694:     by (auto simp: prod_emb_def extensional_def Pi_iff) blast
hoelzl@50000:   moreover have "range ?E \<subseteq> sets S"
hoelzl@42257:     using E by auto
hoelzl@42257:   moreover have "decseq ?E"
hoelzl@47694:     by (auto simp: prod_emb_def Pi_iff decseq_def)
hoelzl@42257:   ultimately show ?thesis
hoelzl@47694:     by (simp add: finite_Lim_measure_decseq)
hoelzl@42257: qed
hoelzl@42257: 
hoelzl@50000: lemma nat_eq_diff_eq: 
hoelzl@50000:   fixes a b c :: nat
hoelzl@50000:   shows "c \<le> b \<Longrightarrow> a = b - c \<longleftrightarrow> a + c = b"
hoelzl@50000:   by auto
hoelzl@50000: 
hoelzl@50000: lemma PiM_comb_seq:
wenzelm@53015:   "distr (S \<Otimes>\<^sub>M S) S (\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') = S" (is "?D = _")
hoelzl@50000: proof (rule PiM_eq)
hoelzl@50000:   let ?I = "UNIV::nat set" and ?M = "\<lambda>n. M"
hoelzl@50000:   let "distr _ _ ?f" = "?D"
hoelzl@50000: 
hoelzl@50000:   fix J E assume J: "finite J" "J \<subseteq> ?I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets M"
wenzelm@53015:   let ?X = "prod_emb ?I ?M J (\<Pi>\<^sub>E j\<in>J. E j)"
hoelzl@50000:   have "\<And>j x. j \<in> J \<Longrightarrow> x \<in> E j \<Longrightarrow> x \<in> space M"
immler@50244:     using J(3)[THEN sets.sets_into_space] by (auto simp: space_PiM Pi_iff subset_eq)
wenzelm@53015:   with J have "?f -` ?X \<inter> space (S \<Otimes>\<^sub>M S) =
hoelzl@50000:     (prod_emb ?I ?M (J \<inter> {..<i}) (PIE j:J \<inter> {..<i}. E j)) \<times>
hoelzl@50000:     (prod_emb ?I ?M ((op + i) -` J) (PIE j:(op + i) -` J. E (i + j)))" (is "_ = ?E \<times> ?F")
hoelzl@50123:    by (auto simp: space_pair_measure space_PiM prod_emb_def all_conj_distrib PiE_iff
hoelzl@50000:                split: split_comb_seq split_comb_seq_asm)
wenzelm@53015:   then have "emeasure ?D ?X = emeasure (S \<Otimes>\<^sub>M S) (?E \<times> ?F)"
hoelzl@50000:     by (subst emeasure_distr[OF measurable_comb_seq])
hoelzl@50000:        (auto intro!: sets_PiM_I simp: split_beta' J)
hoelzl@50000:   also have "\<dots> = emeasure S ?E * emeasure S ?F"
hoelzl@50000:     using J by (intro P.emeasure_pair_measure_Times)  (auto intro!: sets_PiM_I finite_vimageI simp: inj_on_def)
hoelzl@50000:   also have "emeasure S ?F = (\<Prod>j\<in>(op + i) -` J. emeasure M (E (i + j)))"
hoelzl@50000:     using J by (intro emeasure_PiM_emb) (simp_all add: finite_vimageI inj_on_def)
hoelzl@50000:   also have "\<dots> = (\<Prod>j\<in>J - (J \<inter> {..<i}). emeasure M (E j))"
haftmann@57418:     by (rule setprod.reindex_cong [of "\<lambda>x. x - i"])
hoelzl@50000:        (auto simp: image_iff Bex_def not_less nat_eq_diff_eq ac_simps cong: conj_cong intro!: inj_onI)
hoelzl@50000:   also have "emeasure S ?E = (\<Prod>j\<in>J \<inter> {..<i}. emeasure M (E j))"
hoelzl@50000:     using J by (intro emeasure_PiM_emb) simp_all
hoelzl@50000:   also have "(\<Prod>j\<in>J \<inter> {..<i}. emeasure M (E j)) * (\<Prod>j\<in>J - (J \<inter> {..<i}). emeasure M (E j)) = (\<Prod>j\<in>J. emeasure M (E j))"
haftmann@57512:     by (subst mult.commute) (auto simp: J setprod.subset_diff[symmetric])
hoelzl@50000:   finally show "emeasure ?D ?X = (\<Prod>j\<in>J. emeasure M (E j))" .
hoelzl@50000: qed simp_all
hoelzl@50000: 
hoelzl@50000: lemma PiM_iter:
blanchet@55415:   "distr (M \<Otimes>\<^sub>M S) S (\<lambda>(s, \<omega>). case_nat s \<omega>) = S" (is "?D = _")
hoelzl@50000: proof (rule PiM_eq)
hoelzl@50000:   let ?I = "UNIV::nat set" and ?M = "\<lambda>n. M"
hoelzl@50000:   let "distr _ _ ?f" = "?D"
hoelzl@50000: 
hoelzl@50000:   fix J E assume J: "finite J" "J \<subseteq> ?I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets M"
hoelzl@50000:   let ?X = "prod_emb ?I ?M J (PIE j:J. E j)"
hoelzl@50000:   have "\<And>j x. j \<in> J \<Longrightarrow> x \<in> E j \<Longrightarrow> x \<in> space M"
immler@50244:     using J(3)[THEN sets.sets_into_space] by (auto simp: space_PiM Pi_iff subset_eq)
wenzelm@53015:   with J have "?f -` ?X \<inter> space (M \<Otimes>\<^sub>M S) = (if 0 \<in> J then E 0 else space M) \<times>
hoelzl@50000:     (prod_emb ?I ?M (Suc -` J) (PIE j:Suc -` J. E (Suc j)))" (is "_ = ?E \<times> ?F")
hoelzl@50123:    by (auto simp: space_pair_measure space_PiM PiE_iff prod_emb_def all_conj_distrib
hoelzl@50000:       split: nat.split nat.split_asm)
wenzelm@53015:   then have "emeasure ?D ?X = emeasure (M \<Otimes>\<^sub>M S) (?E \<times> ?F)"
hoelzl@50099:     by (subst emeasure_distr)
hoelzl@50000:        (auto intro!: sets_PiM_I simp: split_beta' J)
hoelzl@50000:   also have "\<dots> = emeasure M ?E * emeasure S ?F"
hoelzl@50000:     using J by (intro P.emeasure_pair_measure_Times) (auto intro!: sets_PiM_I finite_vimageI)
hoelzl@50000:   also have "emeasure S ?F = (\<Prod>j\<in>Suc -` J. emeasure M (E (Suc j)))"
hoelzl@50000:     using J by (intro emeasure_PiM_emb) (simp_all add: finite_vimageI)
hoelzl@50000:   also have "\<dots> = (\<Prod>j\<in>J - {0}. emeasure M (E j))"
haftmann@57418:     by (rule setprod.reindex_cong [of "\<lambda>x. x - 1"])
hoelzl@50000:        (auto simp: image_iff Bex_def not_less nat_eq_diff_eq ac_simps cong: conj_cong intro!: inj_onI)
hoelzl@50000:   also have "emeasure M ?E * (\<Prod>j\<in>J - {0}. emeasure M (E j)) = (\<Prod>j\<in>J. emeasure M (E j))"
hoelzl@50000:     by (auto simp: M.emeasure_space_1 setprod.remove J)
hoelzl@50000:   finally show "emeasure ?D ?X = (\<Prod>j\<in>J. emeasure M (E j))" .
hoelzl@50000: qed simp_all
hoelzl@50000: 
hoelzl@50000: end
hoelzl@50000: 
hoelzl@42147: end



