src/HOL/Probability/Infinite_Product_Measure.thy
author hoelzl
Wed Oct 10 12:12:37 2012 +0200 (2012-10-10)
changeset 49804 ace9b5a83e60
parent 49784 5e5b2da42a69
child 50000 cfe8ee8a1371
permissions -rw-r--r--
infprod generator works also with empty index set
     1 (*  Title:      HOL/Probability/Infinite_Product_Measure.thy
     2     Author:     Johannes Hölzl, TU München
     3 *)
     4 
     5 header {*Infinite Product Measure*}
     6 
     7 theory Infinite_Product_Measure
     8   imports Probability_Measure Caratheodory
     9 begin
    10 
    11 lemma restrict_extensional_sub[intro]: "A \<subseteq> B \<Longrightarrow> restrict f A \<in> extensional B"
    12   unfolding restrict_def extensional_def by auto
    13 
    14 lemma restrict_restrict[simp]: "restrict (restrict f A) B = restrict f (A \<inter> B)"
    15   unfolding restrict_def by (simp add: fun_eq_iff)
    16 
    17 lemma split_merge: "P (merge I J (x,y) i) \<longleftrightarrow> (i \<in> I \<longrightarrow> P (x i)) \<and> (i \<in> J - I \<longrightarrow> P (y i)) \<and> (i \<notin> I \<union> J \<longrightarrow> P undefined)"
    18   unfolding merge_def by auto
    19 
    20 lemma extensional_merge_sub: "I \<union> J \<subseteq> K \<Longrightarrow> merge I J (x, y) \<in> extensional K"
    21   unfolding merge_def extensional_def by auto
    22 
    23 lemma injective_vimage_restrict:
    24   assumes J: "J \<subseteq> I"
    25   and sets: "A \<subseteq> (\<Pi>\<^isub>E i\<in>J. S i)" "B \<subseteq> (\<Pi>\<^isub>E i\<in>J. S i)" and ne: "(\<Pi>\<^isub>E i\<in>I. S i) \<noteq> {}"
    26   and eq: "(\<lambda>x. restrict x J) -` A \<inter> (\<Pi>\<^isub>E i\<in>I. S i) = (\<lambda>x. restrict x J) -` B \<inter> (\<Pi>\<^isub>E i\<in>I. S i)"
    27   shows "A = B"
    28 proof  (intro set_eqI)
    29   fix x
    30   from ne obtain y where y: "\<And>i. i \<in> I \<Longrightarrow> y i \<in> S i" by auto
    31   have "J \<inter> (I - J) = {}" by auto
    32   show "x \<in> A \<longleftrightarrow> x \<in> B"
    33   proof cases
    34     assume x: "x \<in> (\<Pi>\<^isub>E i\<in>J. S i)"
    35     have "x \<in> A \<longleftrightarrow> merge J (I - J) (x,y) \<in> (\<lambda>x. restrict x J) -` A \<inter> (\<Pi>\<^isub>E i\<in>I. S i)"
    36       using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub split: split_merge)
    37     then show "x \<in> A \<longleftrightarrow> x \<in> B"
    38       using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub eq split: split_merge)
    39   next
    40     assume "x \<notin> (\<Pi>\<^isub>E i\<in>J. S i)" with sets show "x \<in> A \<longleftrightarrow> x \<in> B" by auto
    41   qed
    42 qed
    43 
    44 lemma prod_algebraI_finite:
    45   "finite I \<Longrightarrow> (\<forall>i\<in>I. E i \<in> sets (M i)) \<Longrightarrow> (Pi\<^isub>E I E) \<in> prod_algebra I M"
    46   using prod_algebraI[of I I E M] prod_emb_PiE_same_index[of I E M, OF sets_into_space] by simp
    47 
    48 lemma Int_stable_PiE: "Int_stable {Pi\<^isub>E J E | E. \<forall>i\<in>I. E i \<in> sets (M i)}"
    49 proof (safe intro!: Int_stableI)
    50   fix E F assume "\<forall>i\<in>I. E i \<in> sets (M i)" "\<forall>i\<in>I. F i \<in> sets (M i)"
    51   then show "\<exists>G. Pi\<^isub>E J E \<inter> Pi\<^isub>E J F = Pi\<^isub>E J G \<and> (\<forall>i\<in>I. G i \<in> sets (M i))"
    52     by (auto intro!: exI[of _ "\<lambda>i. E i \<inter> F i"])
    53 qed
    54 
    55 lemma prod_emb_trans[simp]:
    56   "J \<subseteq> K \<Longrightarrow> K \<subseteq> L \<Longrightarrow> prod_emb L M K (prod_emb K M J X) = prod_emb L M J X"
    57   by (auto simp add: Int_absorb1 prod_emb_def)
    58 
    59 lemma prod_emb_Pi:
    60   assumes "X \<in> (\<Pi> j\<in>J. sets (M j))" "J \<subseteq> K"
    61   shows "prod_emb K M J (Pi\<^isub>E J X) = (\<Pi>\<^isub>E i\<in>K. if i \<in> J then X i else space (M i))"
    62   using assms space_closed
    63   by (auto simp: prod_emb_def Pi_iff split: split_if_asm) blast+
    64 
    65 lemma prod_emb_id:
    66   "B \<subseteq> (\<Pi>\<^isub>E i\<in>L. space (M i)) \<Longrightarrow> prod_emb L M L B = B"
    67   by (auto simp: prod_emb_def Pi_iff subset_eq extensional_restrict)
    68 
    69 lemma measurable_prod_emb[intro, simp]:
    70   "J \<subseteq> L \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> prod_emb L M J X \<in> sets (Pi\<^isub>M L M)"
    71   unfolding prod_emb_def space_PiM[symmetric]
    72   by (auto intro!: measurable_sets measurable_restrict measurable_component_singleton)
    73 
    74 lemma measurable_restrict_subset: "J \<subseteq> L \<Longrightarrow> (\<lambda>f. restrict f J) \<in> measurable (Pi\<^isub>M L M) (Pi\<^isub>M J M)"
    75   by (intro measurable_restrict measurable_component_singleton) auto
    76 
    77 lemma (in product_prob_space) distr_restrict:
    78   assumes "J \<noteq> {}" "J \<subseteq> K" "finite K"
    79   shows "(\<Pi>\<^isub>M i\<in>J. M i) = distr (\<Pi>\<^isub>M i\<in>K. M i) (\<Pi>\<^isub>M i\<in>J. M i) (\<lambda>f. restrict f J)" (is "?P = ?D")
    80 proof (rule measure_eqI_generator_eq)
    81   have "finite J" using `J \<subseteq> K` `finite K` by (auto simp add: finite_subset)
    82   interpret J: finite_product_prob_space M J proof qed fact
    83   interpret K: finite_product_prob_space M K proof qed fact
    84 
    85   let ?J = "{Pi\<^isub>E J E | E. \<forall>i\<in>J. E i \<in> sets (M i)}"
    86   let ?F = "\<lambda>i. \<Pi>\<^isub>E k\<in>J. space (M k)"
    87   let ?\<Omega> = "(\<Pi>\<^isub>E k\<in>J. space (M k))"
    88   show "Int_stable ?J"
    89     by (rule Int_stable_PiE)
    90   show "range ?F \<subseteq> ?J" "(\<Union>i. ?F i) = ?\<Omega>"
    91     using `finite J` by (auto intro!: prod_algebraI_finite)
    92   { fix i show "emeasure ?P (?F i) \<noteq> \<infinity>" by simp }
    93   show "?J \<subseteq> Pow ?\<Omega>" by (auto simp: Pi_iff dest: sets_into_space)
    94   show "sets (\<Pi>\<^isub>M i\<in>J. M i) = sigma_sets ?\<Omega> ?J" "sets ?D = sigma_sets ?\<Omega> ?J"
    95     using `finite J` by (simp_all add: sets_PiM prod_algebra_eq_finite Pi_iff)
    96   
    97   fix X assume "X \<in> ?J"
    98   then obtain E where [simp]: "X = Pi\<^isub>E J E" and E: "\<forall>i\<in>J. E i \<in> sets (M i)" by auto
    99   with `finite J` have X: "X \<in> sets (Pi\<^isub>M J M)" by auto
   100 
   101   have "emeasure ?P X = (\<Prod> i\<in>J. emeasure (M i) (E i))"
   102     using E by (simp add: J.measure_times)
   103   also have "\<dots> = (\<Prod> i\<in>J. emeasure (M i) (if i \<in> J then E i else space (M i)))"
   104     by simp
   105   also have "\<dots> = (\<Prod> i\<in>K. emeasure (M i) (if i \<in> J then E i else space (M i)))"
   106     using `finite K` `J \<subseteq> K`
   107     by (intro setprod_mono_one_left) (auto simp: M.emeasure_space_1)
   108   also have "\<dots> = emeasure (Pi\<^isub>M K M) (\<Pi>\<^isub>E i\<in>K. if i \<in> J then E i else space (M i))"
   109     using E by (simp add: K.measure_times)
   110   also have "(\<Pi>\<^isub>E i\<in>K. if i \<in> J then E i else space (M i)) = (\<lambda>f. restrict f J) -` Pi\<^isub>E J E \<inter> (\<Pi>\<^isub>E i\<in>K. space (M i))"
   111     using `J \<subseteq> K` sets_into_space E by (force simp:  Pi_iff split: split_if_asm)
   112   finally show "emeasure (Pi\<^isub>M J M) X = emeasure ?D X"
   113     using X `J \<subseteq> K` apply (subst emeasure_distr)
   114     by (auto intro!: measurable_restrict_subset simp: space_PiM)
   115 qed
   116 
   117 abbreviation (in product_prob_space)
   118   "emb L K X \<equiv> prod_emb L M K X"
   119 
   120 lemma (in product_prob_space) emeasure_prod_emb[simp]:
   121   assumes L: "J \<noteq> {}" "J \<subseteq> L" "finite L" and X: "X \<in> sets (Pi\<^isub>M J M)"
   122   shows "emeasure (Pi\<^isub>M L M) (emb L J X) = emeasure (Pi\<^isub>M J M) X"
   123   by (subst distr_restrict[OF L])
   124      (simp add: prod_emb_def space_PiM emeasure_distr measurable_restrict_subset L X)
   125 
   126 lemma (in product_prob_space) prod_emb_injective:
   127   assumes "J \<noteq> {}" "J \<subseteq> L" "finite J" and sets: "X \<in> sets (Pi\<^isub>M J M)" "Y \<in> sets (Pi\<^isub>M J M)"
   128   assumes "prod_emb L M J X = prod_emb L M J Y"
   129   shows "X = Y"
   130 proof (rule injective_vimage_restrict)
   131   show "X \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))" "Y \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))"
   132     using sets[THEN sets_into_space] by (auto simp: space_PiM)
   133   have "\<forall>i\<in>L. \<exists>x. x \<in> space (M i)"
   134       using M.not_empty by auto
   135   from bchoice[OF this]
   136   show "(\<Pi>\<^isub>E i\<in>L. space (M i)) \<noteq> {}" by auto
   137   show "(\<lambda>x. restrict x J) -` X \<inter> (\<Pi>\<^isub>E i\<in>L. space (M i)) = (\<lambda>x. restrict x J) -` Y \<inter> (\<Pi>\<^isub>E i\<in>L. space (M i))"
   138     using `prod_emb L M J X = prod_emb L M J Y` by (simp add: prod_emb_def)
   139 qed fact
   140 
   141 definition (in product_prob_space) generator :: "('i \<Rightarrow> 'a) set set" where
   142   "generator = (\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` sets (Pi\<^isub>M J M))"
   143 
   144 lemma (in product_prob_space) generatorI':
   145   "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> emb I J X \<in> generator"
   146   unfolding generator_def by auto
   147 
   148 lemma (in product_prob_space) algebra_generator:
   149   assumes "I \<noteq> {}" shows "algebra (\<Pi>\<^isub>E i\<in>I. space (M i)) generator" (is "algebra ?\<Omega> ?G")
   150   unfolding algebra_def algebra_axioms_def ring_of_sets_iff
   151 proof (intro conjI ballI)
   152   let ?G = generator
   153   show "?G \<subseteq> Pow ?\<Omega>"
   154     by (auto simp: generator_def prod_emb_def)
   155   from `I \<noteq> {}` obtain i where "i \<in> I" by auto
   156   then show "{} \<in> ?G"
   157     by (auto intro!: exI[of _ "{i}"] image_eqI[where x="\<lambda>i. {}"]
   158              simp: sigma_sets.Empty generator_def prod_emb_def)
   159   from `i \<in> I` show "?\<Omega> \<in> ?G"
   160     by (auto intro!: exI[of _ "{i}"] image_eqI[where x="Pi\<^isub>E {i} (\<lambda>i. space (M i))"]
   161              simp: generator_def prod_emb_def)
   162   fix A assume "A \<in> ?G"
   163   then obtain JA XA where XA: "JA \<noteq> {}" "finite JA" "JA \<subseteq> I" "XA \<in> sets (Pi\<^isub>M JA M)" and A: "A = emb I JA XA"
   164     by (auto simp: generator_def)
   165   fix B assume "B \<in> ?G"
   166   then obtain JB XB where XB: "JB \<noteq> {}" "finite JB" "JB \<subseteq> I" "XB \<in> sets (Pi\<^isub>M JB M)" and B: "B = emb I JB XB"
   167     by (auto simp: generator_def)
   168   let ?RA = "emb (JA \<union> JB) JA XA"
   169   let ?RB = "emb (JA \<union> JB) JB XB"
   170   have *: "A - B = emb I (JA \<union> JB) (?RA - ?RB)" "A \<union> B = emb I (JA \<union> JB) (?RA \<union> ?RB)"
   171     using XA A XB B by auto
   172   show "A - B \<in> ?G" "A \<union> B \<in> ?G"
   173     unfolding * using XA XB by (safe intro!: generatorI') auto
   174 qed
   175 
   176 lemma (in product_prob_space) sets_PiM_generator:
   177   "sets (PiM I M) = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) generator"
   178 proof cases
   179   assume "I = {}" then show ?thesis
   180     unfolding generator_def
   181     by (auto simp: sets_PiM_empty sigma_sets_empty_eq cong: conj_cong)
   182 next
   183   assume "I \<noteq> {}"
   184   show ?thesis
   185   proof
   186     show "sets (Pi\<^isub>M I M) \<subseteq> sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) generator"
   187       unfolding sets_PiM
   188     proof (safe intro!: sigma_sets_subseteq)
   189       fix A assume "A \<in> prod_algebra I M" with `I \<noteq> {}` show "A \<in> generator"
   190         by (auto intro!: generatorI' elim!: prod_algebraE)
   191     qed
   192   qed (auto simp: generator_def space_PiM[symmetric] intro!: sigma_sets_subset)
   193 qed
   194 
   195 
   196 lemma (in product_prob_space) generatorI:
   197   "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> A = emb I J X \<Longrightarrow> A \<in> generator"
   198   unfolding generator_def by auto
   199 
   200 definition (in product_prob_space)
   201   "\<mu>G A =
   202     (THE x. \<forall>J. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> J \<subseteq> I \<longrightarrow> (\<forall>X\<in>sets (Pi\<^isub>M J M). A = emb I J X \<longrightarrow> x = emeasure (Pi\<^isub>M J M) X))"
   203 
   204 lemma (in product_prob_space) \<mu>G_spec:
   205   assumes J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
   206   shows "\<mu>G A = emeasure (Pi\<^isub>M J M) X"
   207   unfolding \<mu>G_def
   208 proof (intro the_equality allI impI ballI)
   209   fix K Y assume K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "A = emb I K Y" "Y \<in> sets (Pi\<^isub>M K M)"
   210   have "emeasure (Pi\<^isub>M K M) Y = emeasure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) K Y)"
   211     using K J by simp
   212   also have "emb (K \<union> J) K Y = emb (K \<union> J) J X"
   213     using K J by (simp add: prod_emb_injective[of "K \<union> J" I])
   214   also have "emeasure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) J X) = emeasure (Pi\<^isub>M J M) X"
   215     using K J by simp
   216   finally show "emeasure (Pi\<^isub>M J M) X = emeasure (Pi\<^isub>M K M) Y" ..
   217 qed (insert J, force)
   218 
   219 lemma (in product_prob_space) \<mu>G_eq:
   220   "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> \<mu>G (emb I J X) = emeasure (Pi\<^isub>M J M) X"
   221   by (intro \<mu>G_spec) auto
   222 
   223 lemma (in product_prob_space) generator_Ex:
   224   assumes *: "A \<in> generator"
   225   shows "\<exists>J X. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I \<and> X \<in> sets (Pi\<^isub>M J M) \<and> A = emb I J X \<and> \<mu>G A = emeasure (Pi\<^isub>M J M) X"
   226 proof -
   227   from * obtain J X where J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
   228     unfolding generator_def by auto
   229   with \<mu>G_spec[OF this] show ?thesis by auto
   230 qed
   231 
   232 lemma (in product_prob_space) generatorE:
   233   assumes A: "A \<in> generator"
   234   obtains J X where "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)" "emb I J X = A" "\<mu>G A = emeasure (Pi\<^isub>M J M) X"
   235 proof -
   236   from generator_Ex[OF A] obtain X J where "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)" "emb I J X = A"
   237     "\<mu>G A = emeasure (Pi\<^isub>M J M) X" by auto
   238   then show thesis by (intro that) auto
   239 qed
   240 
   241 lemma (in product_prob_space) merge_sets:
   242   assumes "J \<inter> K = {}" and A: "A \<in> sets (Pi\<^isub>M (J \<union> K) M)" and x: "x \<in> space (Pi\<^isub>M J M)"
   243   shows "(\<lambda>y. merge J K (x,y)) -` A \<inter> space (Pi\<^isub>M K M) \<in> sets (Pi\<^isub>M K M)"
   244   by (rule measurable_sets[OF _ A] measurable_compose[OF measurable_Pair measurable_merge]  
   245            measurable_const x measurable_ident)+
   246 
   247 lemma (in product_prob_space) merge_emb:
   248   assumes "K \<subseteq> I" "J \<subseteq> I" and y: "y \<in> space (Pi\<^isub>M J M)"
   249   shows "((\<lambda>x. merge J (I - J) (y, x)) -` emb I K X \<inter> space (Pi\<^isub>M I M)) =
   250     emb I (K - J) ((\<lambda>x. merge J (K - J) (y, x)) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M))"
   251 proof -
   252   have [simp]: "\<And>x J K L. merge J K (y, restrict x L) = merge J (K \<inter> L) (y, x)"
   253     by (auto simp: restrict_def merge_def)
   254   have [simp]: "\<And>x J K L. restrict (merge J K (y, x)) L = merge (J \<inter> L) (K \<inter> L) (y, x)"
   255     by (auto simp: restrict_def merge_def)
   256   have [simp]: "(I - J) \<inter> K = K - J" using `K \<subseteq> I` `J \<subseteq> I` by auto
   257   have [simp]: "(K - J) \<inter> (K \<union> J) = K - J" by auto
   258   have [simp]: "(K - J) \<inter> K = K - J" by auto
   259   from y `K \<subseteq> I` `J \<subseteq> I` show ?thesis
   260     by (simp split: split_merge add: prod_emb_def Pi_iff extensional_merge_sub set_eq_iff space_PiM)
   261        auto
   262 qed
   263 
   264 lemma (in product_prob_space) positive_\<mu>G: 
   265   assumes "I \<noteq> {}"
   266   shows "positive generator \<mu>G"
   267 proof -
   268   interpret G!: algebra "\<Pi>\<^isub>E i\<in>I. space (M i)" generator by (rule algebra_generator) fact
   269   show ?thesis
   270   proof (intro positive_def[THEN iffD2] conjI ballI)
   271     from generatorE[OF G.empty_sets] guess J X . note this[simp]
   272     interpret J: finite_product_sigma_finite M J by default fact
   273     have "X = {}"
   274       by (rule prod_emb_injective[of J I]) simp_all
   275     then show "\<mu>G {} = 0" by simp
   276   next
   277     fix A assume "A \<in> generator"
   278     from generatorE[OF this] guess J X . note this[simp]
   279     interpret J: finite_product_sigma_finite M J by default fact
   280     show "0 \<le> \<mu>G A" by (simp add: emeasure_nonneg)
   281   qed
   282 qed
   283 
   284 lemma (in product_prob_space) additive_\<mu>G: 
   285   assumes "I \<noteq> {}"
   286   shows "additive generator \<mu>G"
   287 proof -
   288   interpret G!: algebra "\<Pi>\<^isub>E i\<in>I. space (M i)" generator by (rule algebra_generator) fact
   289   show ?thesis
   290   proof (intro additive_def[THEN iffD2] ballI impI)
   291     fix A assume "A \<in> generator" with generatorE guess J X . note J = this
   292     fix B assume "B \<in> generator" with generatorE guess K Y . note K = this
   293     assume "A \<inter> B = {}"
   294     have JK: "J \<union> K \<noteq> {}" "J \<union> K \<subseteq> I" "finite (J \<union> K)"
   295       using J K by auto
   296     interpret JK: finite_product_sigma_finite M "J \<union> K" by default fact
   297     have JK_disj: "emb (J \<union> K) J X \<inter> emb (J \<union> K) K Y = {}"
   298       apply (rule prod_emb_injective[of "J \<union> K" I])
   299       apply (insert `A \<inter> B = {}` JK J K)
   300       apply (simp_all add: Int prod_emb_Int)
   301       done
   302     have AB: "A = emb I (J \<union> K) (emb (J \<union> K) J X)" "B = emb I (J \<union> K) (emb (J \<union> K) K Y)"
   303       using J K by simp_all
   304     then have "\<mu>G (A \<union> B) = \<mu>G (emb I (J \<union> K) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y))"
   305       by simp
   306     also have "\<dots> = emeasure (Pi\<^isub>M (J \<union> K) M) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y)"
   307       using JK J(1, 4) K(1, 4) by (simp add: \<mu>G_eq Un del: prod_emb_Un)
   308     also have "\<dots> = \<mu>G A + \<mu>G B"
   309       using J K JK_disj by (simp add: plus_emeasure[symmetric])
   310     finally show "\<mu>G (A \<union> B) = \<mu>G A + \<mu>G B" .
   311   qed
   312 qed
   313 
   314 lemma (in product_prob_space) emeasure_PiM_emb_not_empty:
   315   assumes X: "J \<noteq> {}" "J \<subseteq> I" "finite J" "\<forall>i\<in>J. X i \<in> sets (M i)"
   316   shows "emeasure (Pi\<^isub>M I M) (emb I J (Pi\<^isub>E J X)) = emeasure (Pi\<^isub>M J M) (Pi\<^isub>E J X)"
   317 proof cases
   318   assume "finite I" with X show ?thesis by simp
   319 next
   320   let ?\<Omega> = "\<Pi>\<^isub>E i\<in>I. space (M i)"
   321   let ?G = generator
   322   assume "\<not> finite I"
   323   then have I_not_empty: "I \<noteq> {}" by auto
   324   interpret G!: algebra ?\<Omega> generator by (rule algebra_generator) fact
   325   note \<mu>G_mono =
   326     G.additive_increasing[OF positive_\<mu>G[OF I_not_empty] additive_\<mu>G[OF I_not_empty], THEN increasingD]
   327 
   328   { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> ?G"
   329 
   330     from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
   331       by (metis rev_finite_subset subsetI)
   332     moreover from Z guess K' X' by (rule generatorE)
   333     moreover def K \<equiv> "insert k K'"
   334     moreover def X \<equiv> "emb K K' X'"
   335     ultimately have K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "X \<in> sets (Pi\<^isub>M K M)" "Z = emb I K X"
   336       "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = emeasure (Pi\<^isub>M K M) X"
   337       by (auto simp: subset_insertI)
   338 
   339     let ?M = "\<lambda>y. (\<lambda>x. merge J (K - J) (y, x)) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M)"
   340     { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
   341       note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
   342       moreover
   343       have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
   344         using J K y by (intro merge_sets) auto
   345       ultimately
   346       have ***: "((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> ?G"
   347         using J K by (intro generatorI) auto
   348       have "\<mu>G ((\<lambda>x. merge J (I - J) (y, x)) -` emb I K X \<inter> space (Pi\<^isub>M I M)) = emeasure (Pi\<^isub>M (K - J) M) (?M y)"
   349         unfolding * using K J by (subst \<mu>G_eq[OF _ _ _ **]) auto
   350       note * ** *** this }
   351     note merge_in_G = this
   352 
   353     have "finite (K - J)" using K by auto
   354 
   355     interpret J: finite_product_prob_space M J by default fact+
   356     interpret KmJ: finite_product_prob_space M "K - J" by default fact+
   357 
   358     have "\<mu>G Z = emeasure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
   359       using K J by simp
   360     also have "\<dots> = (\<integral>\<^isup>+ x. emeasure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
   361       using K J by (subst emeasure_fold_integral) auto
   362     also have "\<dots> = (\<integral>\<^isup>+ y. \<mu>G ((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)) \<partial>Pi\<^isub>M J M)"
   363       (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
   364     proof (intro positive_integral_cong)
   365       fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   366       with K merge_in_G(2)[OF this]
   367       show "emeasure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
   368         unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst \<mu>G_eq) auto
   369     qed
   370     finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
   371 
   372     { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   373       then have "\<mu>G (?MZ x) \<le> 1"
   374         unfolding merge_in_G(4)[OF x] `Z = emb I K X`
   375         by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
   376     note le_1 = this
   377 
   378     let ?q = "\<lambda>y. \<mu>G ((\<lambda>x. merge J (I - J) (y,x)) -` Z \<inter> space (Pi\<^isub>M I M))"
   379     have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
   380       unfolding `Z = emb I K X` using J K merge_in_G(3)
   381       by (simp add: merge_in_G  \<mu>G_eq emeasure_fold_measurable cong: measurable_cong)
   382     note this fold le_1 merge_in_G(3) }
   383   note fold = this
   384 
   385   have "\<exists>\<mu>. (\<forall>s\<in>?G. \<mu> s = \<mu>G s) \<and> measure_space ?\<Omega> (sigma_sets ?\<Omega> ?G) \<mu>"
   386   proof (rule G.caratheodory_empty_continuous[OF positive_\<mu>G additive_\<mu>G])
   387     fix A assume "A \<in> ?G"
   388     with generatorE guess J X . note JX = this
   389     interpret JK: finite_product_prob_space M J by default fact+
   390     from JX show "\<mu>G A \<noteq> \<infinity>" by simp
   391   next
   392     fix A assume A: "range A \<subseteq> ?G" "decseq A" "(\<Inter>i. A i) = {}"
   393     then have "decseq (\<lambda>i. \<mu>G (A i))"
   394       by (auto intro!: \<mu>G_mono simp: decseq_def)
   395     moreover
   396     have "(INF i. \<mu>G (A i)) = 0"
   397     proof (rule ccontr)
   398       assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
   399       moreover have "0 \<le> ?a"
   400         using A positive_\<mu>G[OF I_not_empty] by (auto intro!: INF_greatest simp: positive_def)
   401       ultimately have "0 < ?a" by auto
   402 
   403       have "\<forall>n. \<exists>J X. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I \<and> X \<in> sets (Pi\<^isub>M J M) \<and> A n = emb I J X \<and> \<mu>G (A n) = emeasure (Pi\<^isub>M J M) X"
   404         using A by (intro allI generator_Ex) auto
   405       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\<^isub>M (J' n) M)"
   406         and A': "\<And>n. A n = emb I (J' n) (X' n)"
   407         unfolding choice_iff by blast
   408       moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
   409       moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
   410       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\<^isub>M (J n) M)"
   411         by auto
   412       with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> ?G"
   413         unfolding J_def X_def by (subst prod_emb_trans) (insert A, auto)
   414 
   415       have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
   416         unfolding J_def by force
   417 
   418       interpret J: finite_product_prob_space M "J i" for i by default fact+
   419 
   420       have a_le_1: "?a \<le> 1"
   421         using \<mu>G_spec[of "J 0" "A 0" "X 0"] J A_eq
   422         by (auto intro!: INF_lower2[of 0] J.measure_le_1)
   423 
   424       let ?M = "\<lambda>K Z y. (\<lambda>x. merge K (I - K) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)"
   425 
   426       { fix Z k assume Z: "range Z \<subseteq> ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
   427         then have Z_sets: "\<And>n. Z n \<in> ?G" by auto
   428         fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
   429         interpret J': finite_product_prob_space M J' by default fact+
   430 
   431         let ?q = "\<lambda>n y. \<mu>G (?M J' (Z n) y)"
   432         let ?Q = "\<lambda>n. ?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
   433         { fix n
   434           have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
   435             using Z J' by (intro fold(1)) auto
   436           then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
   437             by (rule measurable_sets) auto }
   438         note Q_sets = this
   439 
   440         have "?a / 2^(k+1) \<le> (INF n. emeasure (Pi\<^isub>M J' M) (?Q n))"
   441         proof (intro INF_greatest)
   442           fix n
   443           have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
   444           also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
   445             unfolding fold(2)[OF J' `Z n \<in> ?G`]
   446           proof (intro positive_integral_mono)
   447             fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   448             then have "?q n x \<le> 1 + 0"
   449               using J' Z fold(3) Z_sets by auto
   450             also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
   451               using `0 < ?a` by (intro add_mono) auto
   452             finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
   453             with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
   454               by (auto split: split_indicator simp del: power_Suc)
   455           qed
   456           also have "\<dots> = emeasure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
   457             using `0 \<le> ?a` Q_sets J'.emeasure_space_1
   458             by (subst positive_integral_add) auto
   459           finally show "?a / 2^(k+1) \<le> emeasure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
   460             by (cases rule: ereal2_cases[of ?a "emeasure (Pi\<^isub>M J' M) (?Q n)"])
   461                (auto simp: field_simps)
   462         qed
   463         also have "\<dots> = emeasure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
   464         proof (intro INF_emeasure_decseq)
   465           show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
   466           show "decseq ?Q"
   467             unfolding decseq_def
   468           proof (safe intro!: vimageI[OF refl])
   469             fix m n :: nat assume "m \<le> n"
   470             fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   471             assume "?a / 2^(k+1) \<le> ?q n x"
   472             also have "?q n x \<le> ?q m x"
   473             proof (rule \<mu>G_mono)
   474               from fold(4)[OF J', OF Z_sets x]
   475               show "?M J' (Z n) x \<in> ?G" "?M J' (Z m) x \<in> ?G" by auto
   476               show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
   477                 using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
   478             qed
   479             finally show "?a / 2^(k+1) \<le> ?q m x" .
   480           qed
   481         qed simp
   482         finally have "(\<Inter>n. ?Q n) \<noteq> {}"
   483           using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   484         then have "\<exists>w\<in>space (Pi\<^isub>M J' M). \<forall>n. ?a / 2 ^ (k + 1) \<le> ?q n w" by auto }
   485       note Ex_w = this
   486 
   487       let ?q = "\<lambda>k n y. \<mu>G (?M (J k) (A n) y)"
   488 
   489       have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_lower)
   490       from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
   491 
   492       let ?P =
   493         "\<lambda>k wk w. w \<in> space (Pi\<^isub>M (J (Suc k)) M) \<and> restrict w (J k) = wk \<and>
   494           (\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n w)"
   495       def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
   496 
   497       { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
   498           (\<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))"
   499         proof (induct k)
   500           case 0 with w0 show ?case
   501             unfolding w_def nat_rec_0 by auto
   502         next
   503           case (Suc k)
   504           then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   505           have "\<exists>w'. ?P k (w k) w'"
   506           proof cases
   507             assume [simp]: "J k = J (Suc k)"
   508             show ?thesis
   509             proof (intro exI[of _ "w k"] conjI allI)
   510               fix n
   511               have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
   512                 using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
   513               also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
   514               finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
   515             next
   516               show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
   517                 using Suc by simp
   518               then show "restrict (w k) (J k) = w k"
   519                 by (simp add: extensional_restrict space_PiM)
   520             qed
   521           next
   522             assume "J k \<noteq> J (Suc k)"
   523             with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
   524             have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> ?G"
   525               "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
   526               "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
   527               using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
   528               by (auto simp: decseq_def)
   529             from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
   530             obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
   531               "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
   532             let ?w = "merge (J k) ?D (w k, w')"
   533             have [simp]: "\<And>x. merge (J k) (I - J k) (w k, merge ?D (I - ?D) (w', x)) =
   534               merge (J (Suc k)) (I - (J (Suc k))) (?w, x)"
   535               using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
   536               by (auto intro!: ext split: split_merge)
   537             have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
   538               using w'(1) J(3)[of "Suc k"]
   539               by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+
   540             show ?thesis
   541               apply (rule exI[of _ ?w])
   542               using w' J_mono[of k "Suc k"] wk unfolding *
   543               apply (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM)
   544               apply (force simp: extensional_def)
   545               done
   546           qed
   547           then have "?P k (w k) (w (Suc k))"
   548             unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
   549             by (rule someI_ex)
   550           then show ?case by auto
   551         qed
   552         moreover
   553         then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   554         moreover
   555         from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
   556         then have "?M (J k) (A k) (w k) \<noteq> {}"
   557           using positive_\<mu>G[OF I_not_empty, unfolded positive_def] `0 < ?a` `?a \<le> 1`
   558           by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   559         then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
   560         then have "merge (J k) (I - J k) (w k, x) \<in> A k" by auto
   561         then have "\<exists>x\<in>A k. restrict x (J k) = w k"
   562           using `w k \<in> space (Pi\<^isub>M (J k) M)`
   563           by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM)
   564         ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
   565           "\<exists>x\<in>A k. restrict x (J k) = w k"
   566           "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
   567           by auto }
   568       note w = this
   569 
   570       { fix k l i assume "k \<le> l" "i \<in> J k"
   571         { fix l have "w k i = w (k + l) i"
   572           proof (induct l)
   573             case (Suc l)
   574             from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
   575             with w(3)[of "k + Suc l"]
   576             have "w (k + l) i = w (k + Suc l) i"
   577               by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
   578             with Suc show ?case by simp
   579           qed simp }
   580         from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
   581       note w_mono = this
   582 
   583       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"
   584       { fix i k assume k: "i \<in> J k"
   585         have "w k i = w (LEAST k. i \<in> J k) i"
   586           by (intro w_mono Least_le k LeastI[of _ k])
   587         then have "w' i = w k i"
   588           unfolding w'_def using k by auto }
   589       note w'_eq = this
   590       have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
   591         using J by (auto simp: w'_def)
   592       have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
   593         using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
   594       { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
   595           using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq space_PiM)+ }
   596       note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
   597 
   598       have w': "w' \<in> space (Pi\<^isub>M I M)"
   599         using w(1) by (auto simp add: Pi_iff extensional_def space_PiM)
   600 
   601       { fix n
   602         have "restrict w' (J n) = w n" using w(1)
   603           by (auto simp add: fun_eq_iff restrict_def Pi_iff extensional_def space_PiM)
   604         with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
   605         then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: prod_emb_def space_PiM) }
   606       then have "w' \<in> (\<Inter>i. A i)" by auto
   607       with `(\<Inter>i. A i) = {}` show False by auto
   608     qed
   609     ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
   610       using LIMSEQ_ereal_INFI[of "\<lambda>i. \<mu>G (A i)"] by simp
   611   qed fact+
   612   then guess \<mu> .. note \<mu> = this
   613   show ?thesis
   614   proof (subst emeasure_extend_measure_Pair[OF PiM_def, of I M \<mu> J X])
   615     from assms show "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))"
   616       by (simp add: Pi_iff)
   617   next
   618     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))"
   619     then show "emb I J (Pi\<^isub>E J X) \<in> Pow (\<Pi>\<^isub>E i\<in>I. space (M i))"
   620       by (auto simp: Pi_iff prod_emb_def dest: sets_into_space)
   621     have "emb I J (Pi\<^isub>E J X) \<in> generator"
   622       using J `I \<noteq> {}` by (intro generatorI') auto
   623     then have "\<mu> (emb I J (Pi\<^isub>E J X)) = \<mu>G (emb I J (Pi\<^isub>E J X))"
   624       using \<mu> by simp
   625     also have "\<dots> = (\<Prod> j\<in>J. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
   626       using J  `I \<noteq> {}` by (subst \<mu>G_spec[OF _ _ _ refl]) (auto simp: emeasure_PiM Pi_iff)
   627     also have "\<dots> = (\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}.
   628       if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
   629       using J `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
   630     finally show "\<mu> (emb I J (Pi\<^isub>E J X)) = \<dots>" .
   631   next
   632     let ?F = "\<lambda>j. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j))"
   633     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)"
   634       using X `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
   635     then show "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) =
   636       emeasure (Pi\<^isub>M J M) (Pi\<^isub>E J X)"
   637       using X by (auto simp add: emeasure_PiM) 
   638   next
   639     show "positive (sets (Pi\<^isub>M I M)) \<mu>" "countably_additive (sets (Pi\<^isub>M I M)) \<mu>"
   640       using \<mu> unfolding sets_PiM_generator by (auto simp: measure_space_def)
   641   qed
   642 qed
   643 
   644 sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^isub>M I M"
   645 proof
   646   show "emeasure (Pi\<^isub>M I M) (space (Pi\<^isub>M I M)) = 1"
   647   proof cases
   648     assume "I = {}" then show ?thesis by (simp add: space_PiM_empty)
   649   next
   650     assume "I \<noteq> {}"
   651     then obtain i where "i \<in> I" by auto
   652     moreover then have "emb I {i} (\<Pi>\<^isub>E i\<in>{i}. space (M i)) = (space (Pi\<^isub>M I M))"
   653       by (auto simp: prod_emb_def space_PiM)
   654     ultimately show ?thesis
   655       using emeasure_PiM_emb_not_empty[of "{i}" "\<lambda>i. space (M i)"]
   656       by (simp add: emeasure_PiM emeasure_space_1)
   657   qed
   658 qed
   659 
   660 lemma (in product_prob_space) emeasure_PiM_emb:
   661   assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
   662   shows "emeasure (Pi\<^isub>M I M) (emb I J (Pi\<^isub>E J X)) = (\<Prod> i\<in>J. emeasure (M i) (X i))"
   663 proof cases
   664   assume "J = {}"
   665   moreover have "emb I {} {\<lambda>x. undefined} = space (Pi\<^isub>M I M)"
   666     by (auto simp: space_PiM prod_emb_def)
   667   ultimately show ?thesis
   668     by (simp add: space_PiM_empty P.emeasure_space_1)
   669 next
   670   assume "J \<noteq> {}" with X show ?thesis
   671     by (subst emeasure_PiM_emb_not_empty) (auto simp: emeasure_PiM)
   672 qed
   673 
   674 lemma (in product_prob_space) measure_PiM_emb:
   675   assumes "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
   676   shows "measure (PiM I M) (emb I J (Pi\<^isub>E J X)) = (\<Prod> i\<in>J. measure (M i) (X i))"
   677   using emeasure_PiM_emb[OF assms]
   678   unfolding emeasure_eq_measure M.emeasure_eq_measure by (simp add: setprod_ereal)
   679 
   680 lemma (in finite_product_prob_space) finite_measure_PiM_emb:
   681   "(\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> measure (PiM I M) (Pi\<^isub>E I A) = (\<Prod>i\<in>I. measure (M i) (A i))"
   682   using measure_PiM_emb[of I A] finite_index prod_emb_PiE_same_index[OF sets_into_space, of I A M]
   683   by auto
   684 
   685 subsection {* Sequence space *}
   686 
   687 locale sequence_space = product_prob_space M "UNIV :: nat set" for M
   688 
   689 lemma (in sequence_space) infprod_in_sets[intro]:
   690   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
   691   shows "Pi UNIV E \<in> sets (Pi\<^isub>M UNIV M)"
   692 proof -
   693   have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^isub>E j\<in>{..i}. E j))"
   694     using E E[THEN sets_into_space]
   695     by (auto simp: prod_emb_def Pi_iff extensional_def) blast
   696   with E show ?thesis by auto
   697 qed
   698 
   699 lemma (in sequence_space) measure_PiM_countable:
   700   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
   701   shows "(\<lambda>n. \<Prod>i\<le>n. measure (M i) (E i)) ----> measure (Pi\<^isub>M UNIV M) (Pi UNIV E)"
   702 proof -
   703   let ?E = "\<lambda>n. emb UNIV {..n} (Pi\<^isub>E {.. n} E)"
   704   have "\<And>n. (\<Prod>i\<le>n. measure (M i) (E i)) = measure (Pi\<^isub>M UNIV M) (?E n)"
   705     using E by (simp add: measure_PiM_emb)
   706   moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
   707     using E E[THEN sets_into_space]
   708     by (auto simp: prod_emb_def extensional_def Pi_iff) blast
   709   moreover have "range ?E \<subseteq> sets (Pi\<^isub>M UNIV M)"
   710     using E by auto
   711   moreover have "decseq ?E"
   712     by (auto simp: prod_emb_def Pi_iff decseq_def)
   713   ultimately show ?thesis
   714     by (simp add: finite_Lim_measure_decseq)
   715 qed
   716 
   717 end