src/HOL/Probability/Infinite_Product_Measure.thy
changeset 42147 61d5d50ca74c
child 42148 d596e7bb251f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Probability/Infinite_Product_Measure.thy	Tue Mar 29 14:27:41 2011 +0200
     1.3 @@ -0,0 +1,753 @@
     1.4 +(*  Title:      HOL/Probability/Infinite_Product_Measure.thy
     1.5 +    Author:     Johannes Hölzl, TU München
     1.6 +*)
     1.7 +
     1.8 +header {*Infinite Product Measure*}
     1.9 +
    1.10 +theory Infinite_Product_Measure
    1.11 +  imports Probability_Space
    1.12 +begin
    1.13 +
    1.14 +lemma restrict_extensional_sub[intro]: "A \<subseteq> B \<Longrightarrow> restrict f A \<in> extensional B"
    1.15 +  unfolding restrict_def extensional_def by auto
    1.16 +
    1.17 +lemma restrict_restrict[simp]: "restrict (restrict f A) B = restrict f (A \<inter> B)"
    1.18 +  unfolding restrict_def by (simp add: fun_eq_iff)
    1.19 +
    1.20 +lemma split_merge: "P (merge I x J 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)"
    1.21 +  unfolding merge_def by auto
    1.22 +
    1.23 +lemma extensional_merge_sub: "I \<union> J \<subseteq> K \<Longrightarrow> merge I x J y \<in> extensional K"
    1.24 +  unfolding merge_def extensional_def by auto
    1.25 +
    1.26 +lemma injective_vimage_restrict:
    1.27 +  assumes J: "J \<subseteq> I"
    1.28 +  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> {}"
    1.29 +  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)"
    1.30 +  shows "A = B"
    1.31 +proof  (intro set_eqI)
    1.32 +  fix x
    1.33 +  from ne obtain y where y: "\<And>i. i \<in> I \<Longrightarrow> y i \<in> S i" by auto
    1.34 +  have "J \<inter> (I - J) = {}" by auto
    1.35 +  show "x \<in> A \<longleftrightarrow> x \<in> B"
    1.36 +  proof cases
    1.37 +    assume x: "x \<in> (\<Pi>\<^isub>E i\<in>J. S i)"
    1.38 +    have "x \<in> A \<longleftrightarrow> merge J x (I - J) y \<in> (\<lambda>x. restrict x J) -` A \<inter> (\<Pi>\<^isub>E i\<in>I. S i)"
    1.39 +      using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub split: split_merge)
    1.40 +    then show "x \<in> A \<longleftrightarrow> x \<in> B"
    1.41 +      using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub eq split: split_merge)
    1.42 +  next
    1.43 +    assume "x \<notin> (\<Pi>\<^isub>E i\<in>J. S i)" with sets show "x \<in> A \<longleftrightarrow> x \<in> B" by auto
    1.44 +  qed
    1.45 +qed
    1.46 +
    1.47 +locale product_prob_space =
    1.48 +  fixes M :: "'i \<Rightarrow> ('a,'b) measure_space_scheme" and I :: "'i set"
    1.49 +  assumes prob_spaces: "\<And>i. prob_space (M i)"
    1.50 +  and I_not_empty: "I \<noteq> {}"
    1.51 +
    1.52 +locale finite_product_prob_space = product_prob_space M I
    1.53 +  for M :: "'i \<Rightarrow> ('a,'b) measure_space_scheme" and I :: "'i set" +
    1.54 +  assumes finite_index'[intro]: "finite I"
    1.55 +
    1.56 +sublocale product_prob_space \<subseteq> M: prob_space "M i" for i
    1.57 +  by (rule prob_spaces)
    1.58 +
    1.59 +sublocale product_prob_space \<subseteq> product_sigma_finite
    1.60 +  by default
    1.61 +
    1.62 +sublocale finite_product_prob_space \<subseteq> finite_product_sigma_finite
    1.63 +  by default (fact finite_index')
    1.64 +
    1.65 +sublocale finite_product_prob_space \<subseteq> prob_space "Pi\<^isub>M I M"
    1.66 +proof
    1.67 +  show "measure P (space P) = 1"
    1.68 +    by (simp add: measure_times measure_space_1 setprod_1)
    1.69 +qed
    1.70 +
    1.71 +lemma (in product_prob_space) measure_preserving_restrict:
    1.72 +  assumes "J \<noteq> {}" "J \<subseteq> K" "finite K"
    1.73 +  shows "(\<lambda>f. restrict f J) \<in> measure_preserving (\<Pi>\<^isub>M i\<in>K. M i) (\<Pi>\<^isub>M i\<in>J. M i)" (is "?R \<in> _")
    1.74 +proof -
    1.75 +  interpret K: finite_product_prob_space M K
    1.76 +    by default (insert assms, auto)
    1.77 +  have J: "J \<noteq> {}" "finite J" using assms by (auto simp add: finite_subset)
    1.78 +  interpret J: finite_product_prob_space M J
    1.79 +    by default (insert J, auto)
    1.80 +  from J.sigma_finite_pairs guess F .. note F = this
    1.81 +  then have [simp,intro]: "\<And>k i. k \<in> J \<Longrightarrow> F k i \<in> sets (M k)"
    1.82 +    by auto
    1.83 +  let "?F i" = "\<Pi>\<^isub>E k\<in>J. F k i"
    1.84 +  let ?J = "product_algebra_generator J M \<lparr> measure := measure (Pi\<^isub>M J M) \<rparr>"
    1.85 +  have "?R \<in> measure_preserving (\<Pi>\<^isub>M i\<in>K. M i) (sigma ?J)"
    1.86 +  proof (rule K.measure_preserving_Int_stable)
    1.87 +    show "Int_stable ?J"
    1.88 +      by (auto simp: Int_stable_def product_algebra_generator_def PiE_Int)
    1.89 +    show "range ?F \<subseteq> sets ?J" "incseq ?F" "(\<Union>i. ?F i) = space ?J"
    1.90 +      using F by auto
    1.91 +    show "\<And>i. measure ?J (?F i) \<noteq> \<infinity>"
    1.92 +      using F by (simp add: J.measure_times setprod_PInf)
    1.93 +    have "measure_space (Pi\<^isub>M J M)" by default
    1.94 +    then show "measure_space (sigma ?J)"
    1.95 +      by (simp add: product_algebra_def sigma_def)
    1.96 +    show "?R \<in> measure_preserving (Pi\<^isub>M K M) ?J"
    1.97 +    proof (simp add: measure_preserving_def measurable_def product_algebra_generator_def del: vimage_Int,
    1.98 +           safe intro!: restrict_extensional)
    1.99 +      fix x k assume "k \<in> J" "x \<in> (\<Pi> i\<in>K. space (M i))"
   1.100 +      then show "x k \<in> space (M k)" using `J \<subseteq> K` by auto
   1.101 +    next
   1.102 +      fix E assume "E \<in> (\<Pi> i\<in>J. sets (M i))"
   1.103 +      then have E: "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets (M j)" by auto
   1.104 +      then have *: "?R -` Pi\<^isub>E J E \<inter> (\<Pi>\<^isub>E i\<in>K. space (M i)) = (\<Pi>\<^isub>E i\<in>K. if i \<in> J then E i else space (M i))"
   1.105 +        (is "?X = Pi\<^isub>E K ?M")
   1.106 +        using `J \<subseteq> K` sets_into_space by (auto simp: Pi_iff split: split_if_asm) blast+
   1.107 +      with E show "?X \<in> sets (Pi\<^isub>M K M)"
   1.108 +        by (auto intro!: product_algebra_generatorI)
   1.109 +      have "measure (Pi\<^isub>M J M) (Pi\<^isub>E J E) = (\<Prod>i\<in>J. measure (M i) (?M i))"
   1.110 +        using E by (simp add: J.measure_times)
   1.111 +      also have "\<dots> = measure (Pi\<^isub>M K M) ?X"
   1.112 +        unfolding * using E `finite K` `J \<subseteq> K`
   1.113 +        by (auto simp: K.measure_times M.measure_space_1
   1.114 +                 cong del: setprod_cong
   1.115 +                 intro!: setprod_mono_one_left)
   1.116 +      finally show "measure (Pi\<^isub>M J M) (Pi\<^isub>E J E) = measure (Pi\<^isub>M K M) ?X" .
   1.117 +    qed
   1.118 +  qed
   1.119 +  then show ?thesis
   1.120 +    by (simp add: product_algebra_def sigma_def)
   1.121 +qed
   1.122 +
   1.123 +lemma (in product_prob_space) measurable_restrict:
   1.124 +  assumes *: "J \<noteq> {}" "J \<subseteq> K" "finite K"
   1.125 +  shows "(\<lambda>f. restrict f J) \<in> measurable (\<Pi>\<^isub>M i\<in>K. M i) (\<Pi>\<^isub>M i\<in>J. M i)"
   1.126 +  using measure_preserving_restrict[OF *]
   1.127 +  by (rule measure_preservingD2)
   1.128 +
   1.129 +definition (in product_prob_space)
   1.130 +  "emb J K X = (\<lambda>x. restrict x K) -` X \<inter> space (Pi\<^isub>M J M)"
   1.131 +
   1.132 +lemma (in product_prob_space) emb_trans[simp]:
   1.133 +  "J \<subseteq> K \<Longrightarrow> K \<subseteq> L \<Longrightarrow> emb L K (emb K J X) = emb L J X"
   1.134 +  by (auto simp add: Int_absorb1 emb_def)
   1.135 +
   1.136 +lemma (in product_prob_space) emb_empty[simp]:
   1.137 +  "emb K J {} = {}"
   1.138 +  by (simp add: emb_def)
   1.139 +
   1.140 +lemma (in product_prob_space) emb_Pi:
   1.141 +  assumes "X \<in> (\<Pi> j\<in>J. sets (M j))" "J \<subseteq> K"
   1.142 +  shows "emb K J (Pi\<^isub>E J X) = (\<Pi>\<^isub>E i\<in>K. if i \<in> J then X i else space (M i))"
   1.143 +  using assms space_closed
   1.144 +  by (auto simp: emb_def Pi_iff split: split_if_asm) blast+
   1.145 +
   1.146 +lemma (in product_prob_space) emb_injective:
   1.147 +  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)"
   1.148 +  assumes "emb L J X = emb L J Y"
   1.149 +  shows "X = Y"
   1.150 +proof -
   1.151 +  interpret J: finite_product_sigma_finite M J by default fact
   1.152 +  show "X = Y"
   1.153 +  proof (rule injective_vimage_restrict)
   1.154 +    show "X \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))" "Y \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))"
   1.155 +      using J.sets_into_space sets by auto
   1.156 +    have "\<forall>i\<in>L. \<exists>x. x \<in> space (M i)"
   1.157 +      using M.not_empty by auto
   1.158 +    from bchoice[OF this]
   1.159 +    show "(\<Pi>\<^isub>E i\<in>L. space (M i)) \<noteq> {}" by auto
   1.160 +    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))"
   1.161 +      using `emb L J X = emb L J Y` by (simp add: emb_def)
   1.162 +  qed fact
   1.163 +qed
   1.164 +
   1.165 +lemma (in product_prob_space) emb_id:
   1.166 +  "B \<subseteq> (\<Pi>\<^isub>E i\<in>L. space (M i)) \<Longrightarrow> emb L L B = B"
   1.167 +  by (auto simp: emb_def Pi_iff subset_eq extensional_restrict)
   1.168 +
   1.169 +lemma (in product_prob_space) emb_simps:
   1.170 +  shows "emb L K (A \<union> B) = emb L K A \<union> emb L K B"
   1.171 +    and "emb L K (A \<inter> B) = emb L K A \<inter> emb L K B"
   1.172 +    and "emb L K (A - B) = emb L K A - emb L K B"
   1.173 +  by (auto simp: emb_def)
   1.174 +
   1.175 +lemma (in product_prob_space) measurable_emb[intro,simp]:
   1.176 +  assumes *: "J \<noteq> {}" "J \<subseteq> L" "finite L" "X \<in> sets (Pi\<^isub>M J M)"
   1.177 +  shows "emb L J X \<in> sets (Pi\<^isub>M L M)"
   1.178 +  using measurable_restrict[THEN measurable_sets, OF *] by (simp add: emb_def)
   1.179 +
   1.180 +lemma (in product_prob_space) measure_emb[intro,simp]:
   1.181 +  assumes *: "J \<noteq> {}" "J \<subseteq> L" "finite L" "X \<in> sets (Pi\<^isub>M J M)"
   1.182 +  shows "measure (Pi\<^isub>M L M) (emb L J X) = measure (Pi\<^isub>M J M) X"
   1.183 +  using measure_preserving_restrict[THEN measure_preservingD, OF *]
   1.184 +  by (simp add: emb_def)
   1.185 +
   1.186 +definition (in product_prob_space) generator :: "('i \<Rightarrow> 'a) measure_space" where
   1.187 +  "generator = \<lparr>
   1.188 +    space = (\<Pi>\<^isub>E i\<in>I. space (M i)),
   1.189 +    sets = (\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` sets (Pi\<^isub>M J M)),
   1.190 +    measure = undefined
   1.191 +  \<rparr>"
   1.192 +
   1.193 +lemma (in product_prob_space) generatorI:
   1.194 +  "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> sets generator"
   1.195 +  unfolding generator_def by auto
   1.196 +
   1.197 +lemma (in product_prob_space) generatorI':
   1.198 +  "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> emb I J X \<in> sets generator"
   1.199 +  unfolding generator_def by auto
   1.200 +
   1.201 +lemma (in product_sigma_finite)
   1.202 +  assumes "I \<inter> J = {}" "finite I" "finite J" and A: "A \<in> sets (Pi\<^isub>M (I \<union> J) M)"
   1.203 +  shows measure_fold_integral:
   1.204 +    "measure (Pi\<^isub>M (I \<union> J) M) A = (\<integral>\<^isup>+x. measure (Pi\<^isub>M J M) (merge I x J -` A \<inter> space (Pi\<^isub>M J M)) \<partial>Pi\<^isub>M I M)" (is ?I)
   1.205 +    and measure_fold_measurable:
   1.206 +    "(\<lambda>x. measure (Pi\<^isub>M J M) (merge I x J -` A \<inter> space (Pi\<^isub>M J M))) \<in> borel_measurable (Pi\<^isub>M I M)" (is ?B)
   1.207 +proof -
   1.208 +  interpret I: finite_product_sigma_finite M I by default fact
   1.209 +  interpret J: finite_product_sigma_finite M J by default fact
   1.210 +  interpret IJ: pair_sigma_finite I.P J.P ..
   1.211 +  show ?I
   1.212 +    unfolding measure_fold[OF assms]
   1.213 +    apply (subst IJ.pair_measure_alt)
   1.214 +    apply (intro measurable_sets[OF _ A] measurable_merge assms)
   1.215 +    apply (auto simp: vimage_compose[symmetric] comp_def space_pair_measure
   1.216 +      intro!: I.positive_integral_cong)
   1.217 +    done
   1.218 +
   1.219 +  have "(\<lambda>(x, y). merge I x J y) -` A \<inter> space (I.P \<Otimes>\<^isub>M J.P) \<in> sets (I.P \<Otimes>\<^isub>M J.P)"
   1.220 +    by (intro measurable_sets[OF _ A] measurable_merge assms)
   1.221 +  from IJ.measure_cut_measurable_fst[OF this]
   1.222 +  show ?B
   1.223 +    apply (auto simp: vimage_compose[symmetric] comp_def space_pair_measure)
   1.224 +    apply (subst (asm) measurable_cong)
   1.225 +    apply auto
   1.226 +    done
   1.227 +qed
   1.228 +
   1.229 +lemma (in prob_space) measure_le_1: "X \<in> sets M \<Longrightarrow> \<mu> X \<le> 1"
   1.230 +  unfolding measure_space_1[symmetric]
   1.231 +  using sets_into_space
   1.232 +  by (intro measure_mono) auto
   1.233 +
   1.234 +definition (in product_prob_space)
   1.235 +  "\<mu>G A =
   1.236 +    (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 = measure (Pi\<^isub>M J M) X))"
   1.237 +
   1.238 +lemma (in product_prob_space) \<mu>G_spec:
   1.239 +  assumes J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
   1.240 +  shows "\<mu>G A = measure (Pi\<^isub>M J M) X"
   1.241 +  unfolding \<mu>G_def
   1.242 +proof (intro the_equality allI impI ballI)
   1.243 +  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)"
   1.244 +  have "measure (Pi\<^isub>M K M) Y = measure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) K Y)"
   1.245 +    using K J by simp
   1.246 +  also have "emb (K \<union> J) K Y = emb (K \<union> J) J X"
   1.247 +    using K J by (simp add: emb_injective[of "K \<union> J" I])
   1.248 +  also have "measure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) J X) = measure (Pi\<^isub>M J M) X"
   1.249 +    using K J by simp
   1.250 +  finally show "measure (Pi\<^isub>M J M) X = measure (Pi\<^isub>M K M) Y" ..
   1.251 +qed (insert J, force)
   1.252 +
   1.253 +lemma (in product_prob_space) \<mu>G_eq:
   1.254 +  "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) = measure (Pi\<^isub>M J M) X"
   1.255 +  by (intro \<mu>G_spec) auto
   1.256 +
   1.257 +lemma (in product_prob_space) generator_Ex:
   1.258 +  assumes *: "A \<in> sets generator"
   1.259 +  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 = measure (Pi\<^isub>M J M) X"
   1.260 +proof -
   1.261 +  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)"
   1.262 +    unfolding generator_def by auto
   1.263 +  with \<mu>G_spec[OF this] show ?thesis by auto
   1.264 +qed
   1.265 +
   1.266 +lemma (in product_prob_space) generatorE:
   1.267 +  assumes A: "A \<in> sets generator"
   1.268 +  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 = measure (Pi\<^isub>M J M) X"
   1.269 +proof -
   1.270 +  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"
   1.271 +    "\<mu>G A = measure (Pi\<^isub>M J M) X" by auto
   1.272 +  then show thesis by (intro that) auto
   1.273 +qed
   1.274 +
   1.275 +lemma (in product_prob_space) merge_sets:
   1.276 +  assumes "finite J" "finite K" "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)"
   1.277 +  shows "merge J x K -` A \<inter> space (Pi\<^isub>M K M) \<in> sets (Pi\<^isub>M K M)"
   1.278 +proof -
   1.279 +  interpret J: finite_product_sigma_algebra M J by default fact
   1.280 +  interpret K: finite_product_sigma_algebra M K by default fact
   1.281 +  interpret JK: pair_sigma_algebra J.P K.P ..
   1.282 +
   1.283 +  from JK.measurable_cut_fst[OF
   1.284 +    measurable_merge[THEN measurable_sets, OF `J \<inter> K = {}`], OF A, of x] x
   1.285 +  show ?thesis
   1.286 +      by (simp add: space_pair_measure comp_def vimage_compose[symmetric])
   1.287 +qed
   1.288 +
   1.289 +lemma (in product_prob_space) merge_emb:
   1.290 +  assumes "K \<subseteq> I" "J \<subseteq> I" and y: "y \<in> space (Pi\<^isub>M J M)"
   1.291 +  shows "(merge J y (I - J) -` emb I K X \<inter> space (Pi\<^isub>M I M)) =
   1.292 +    emb I (K - J) (merge J y (K - J) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M))"
   1.293 +proof -
   1.294 +  have [simp]: "\<And>x J K L. merge J y K (restrict x L) = merge J y (K \<inter> L) x"
   1.295 +    by (auto simp: restrict_def merge_def)
   1.296 +  have [simp]: "\<And>x J K L. restrict (merge J y K x) L = merge (J \<inter> L) y (K \<inter> L) x"
   1.297 +    by (auto simp: restrict_def merge_def)
   1.298 +  have [simp]: "(I - J) \<inter> K = K - J" using `K \<subseteq> I` `J \<subseteq> I` by auto
   1.299 +  have [simp]: "(K - J) \<inter> (K \<union> J) = K - J" by auto
   1.300 +  have [simp]: "(K - J) \<inter> K = K - J" by auto
   1.301 +  from y `K \<subseteq> I` `J \<subseteq> I` show ?thesis
   1.302 +    by (simp split: split_merge add: emb_def Pi_iff extensional_merge_sub set_eq_iff) auto
   1.303 +qed
   1.304 +
   1.305 +definition (in product_prob_space) infprod_algebra :: "('i \<Rightarrow> 'a) measure_space" where
   1.306 +  "infprod_algebra = sigma generator \<lparr> measure :=
   1.307 +    (SOME \<mu>. (\<forall>s\<in>sets generator. \<mu> s = \<mu>G s) \<and>
   1.308 +       measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>)\<rparr>"
   1.309 +
   1.310 +syntax
   1.311 +  "_PiP"  :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3PIP _:_./ _)" 10)
   1.312 +
   1.313 +syntax (xsymbols)
   1.314 +  "_PiP" :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3\<Pi>\<^isub>P _\<in>_./ _)"   10)
   1.315 +
   1.316 +syntax (HTML output)
   1.317 +  "_PiP" :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3\<Pi>\<^isub>P _\<in>_./ _)"   10)
   1.318 +
   1.319 +abbreviation
   1.320 +  "Pi\<^isub>P I M \<equiv> product_prob_space.infprod_algebra M I"
   1.321 +
   1.322 +translations
   1.323 +  "PIP x:I. M" == "CONST Pi\<^isub>P I (%x. M)"
   1.324 +
   1.325 +sublocale product_prob_space \<subseteq> G: algebra generator
   1.326 +proof
   1.327 +  let ?G = generator
   1.328 +  show "sets ?G \<subseteq> Pow (space ?G)"
   1.329 +    by (auto simp: generator_def emb_def)
   1.330 +  from I_not_empty
   1.331 +  obtain i where "i \<in> I" by auto
   1.332 +  then show "{} \<in> sets ?G"
   1.333 +    by (auto intro!: exI[of _ "{i}"] image_eqI[where x="\<lambda>i. {}"]
   1.334 +      simp: product_algebra_def sigma_def sigma_sets.Empty generator_def emb_def)
   1.335 +  from `i \<in> I` show "space ?G \<in> sets ?G"
   1.336 +    by (auto intro!: exI[of _ "{i}"] image_eqI[where x="Pi\<^isub>E {i} (\<lambda>i. space (M i))"]
   1.337 +      simp: generator_def emb_def)
   1.338 +  fix A assume "A \<in> sets ?G"
   1.339 +  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"
   1.340 +    by (auto simp: generator_def)
   1.341 +  fix B assume "B \<in> sets ?G"
   1.342 +  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"
   1.343 +    by (auto simp: generator_def)
   1.344 +  let ?RA = "emb (JA \<union> JB) JA XA"
   1.345 +  let ?RB = "emb (JA \<union> JB) JB XB"
   1.346 +  interpret JAB: finite_product_sigma_algebra M "JA \<union> JB"
   1.347 +    by default (insert XA XB, auto)
   1.348 +  have *: "A - B = emb I (JA \<union> JB) (?RA - ?RB)" "A \<union> B = emb I (JA \<union> JB) (?RA \<union> ?RB)"
   1.349 +    using XA A XB B by (auto simp: emb_simps)
   1.350 +  then show "A - B \<in> sets ?G" "A \<union> B \<in> sets ?G"
   1.351 +    using XA XB by (auto intro!: generatorI')
   1.352 +qed
   1.353 +
   1.354 +lemma (in product_prob_space) positive_\<mu>G: "positive generator \<mu>G"
   1.355 +proof (intro positive_def[THEN iffD2] conjI ballI)
   1.356 +  from generatorE[OF G.empty_sets] guess J X . note this[simp]
   1.357 +  interpret J: finite_product_sigma_finite M J by default fact
   1.358 +  have "X = {}"
   1.359 +    by (rule emb_injective[of J I]) simp_all
   1.360 +  then show "\<mu>G {} = 0" by simp
   1.361 +next
   1.362 +  fix A assume "A \<in> sets generator"
   1.363 +  from generatorE[OF this] guess J X . note this[simp]
   1.364 +  interpret J: finite_product_sigma_finite M J by default fact
   1.365 +  show "0 \<le> \<mu>G A" by simp
   1.366 +qed
   1.367 +
   1.368 +lemma (in product_prob_space) additive_\<mu>G: "additive generator \<mu>G"
   1.369 +proof (intro additive_def[THEN iffD2] ballI impI)
   1.370 +  fix A assume "A \<in> sets generator" with generatorE guess J X . note J = this
   1.371 +  fix B assume "B \<in> sets generator" with generatorE guess K Y . note K = this
   1.372 +  assume "A \<inter> B = {}"
   1.373 +  have JK: "J \<union> K \<noteq> {}" "J \<union> K \<subseteq> I" "finite (J \<union> K)"
   1.374 +    using J K by auto
   1.375 +  interpret JK: finite_product_sigma_finite M "J \<union> K" by default fact
   1.376 +  have JK_disj: "emb (J \<union> K) J X \<inter> emb (J \<union> K) K Y = {}"
   1.377 +    apply (rule emb_injective[of "J \<union> K" I])
   1.378 +    apply (insert `A \<inter> B = {}` JK J K)
   1.379 +    apply (simp_all add: JK.Int emb_simps)
   1.380 +    done
   1.381 +  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)"
   1.382 +    using J K by simp_all
   1.383 +  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))"
   1.384 +    by (simp add: emb_simps)
   1.385 +  also have "\<dots> = measure (Pi\<^isub>M (J \<union> K) M) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y)"
   1.386 +    using JK J(1, 4) K(1, 4) by (simp add: \<mu>G_eq JK.Un)
   1.387 +  also have "\<dots> = \<mu>G A + \<mu>G B"
   1.388 +    using J K JK_disj by (simp add: JK.measure_additive[symmetric])
   1.389 +  finally show "\<mu>G (A \<union> B) = \<mu>G A + \<mu>G B" .
   1.390 +qed
   1.391 +
   1.392 +lemma (in product_prob_space) finite_index_eq_finite_product:
   1.393 +  assumes "finite I"
   1.394 +  shows "sets (sigma generator) = sets (Pi\<^isub>M I M)"
   1.395 +proof safe
   1.396 +  interpret I: finite_product_sigma_algebra M I by default fact
   1.397 +  have [simp]: "space generator = space (Pi\<^isub>M I M)"
   1.398 +    by (simp add: generator_def product_algebra_def)
   1.399 +  { fix A assume "A \<in> sets (sigma generator)"
   1.400 +    then show "A \<in> sets I.P" unfolding sets_sigma
   1.401 +    proof induct
   1.402 +      case (Basic A)
   1.403 +      from generatorE[OF this] guess J X . note J = this
   1.404 +      with `finite I` have "emb I J X \<in> sets I.P" by auto
   1.405 +      with `emb I J X = A` show "A \<in> sets I.P" by simp
   1.406 +    qed auto }
   1.407 +  { fix A assume "A \<in> sets I.P"
   1.408 +    moreover with I.sets_into_space have "emb I I A = A" by (intro emb_id) auto
   1.409 +    ultimately show "A \<in> sets (sigma generator)"
   1.410 +      using `finite I` I_not_empty unfolding sets_sigma
   1.411 +      by (intro sigma_sets.Basic generatorI[of I A]) auto }
   1.412 +qed
   1.413 +
   1.414 +lemma (in product_prob_space) extend_\<mu>G:
   1.415 +  "\<exists>\<mu>. (\<forall>s\<in>sets generator. \<mu> s = \<mu>G s) \<and>
   1.416 +       measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>"
   1.417 +proof cases
   1.418 +  assume "finite I"
   1.419 +  interpret I: finite_product_sigma_finite M I by default fact
   1.420 +  show ?thesis
   1.421 +  proof (intro exI[of _ "measure (Pi\<^isub>M I M)"] ballI conjI)
   1.422 +    fix A assume "A \<in> sets generator"
   1.423 +    from generatorE[OF this] guess J X . note J = this
   1.424 +    from J(1-4) `finite I` show "measure I.P A = \<mu>G A"
   1.425 +      unfolding J(6)
   1.426 +      by (subst J(5)[symmetric]) (simp add: measure_emb)
   1.427 +  next
   1.428 +    have [simp]: "space generator = space (Pi\<^isub>M I M)"
   1.429 +      by (simp add: generator_def product_algebra_def)
   1.430 +    have "\<lparr>space = space generator, sets = sets (sigma generator), measure = measure I.P\<rparr>
   1.431 +      = I.P" (is "?P = _")
   1.432 +      by (auto intro!: measure_space.equality simp: finite_index_eq_finite_product[OF `finite I`])
   1.433 +    then show "measure_space ?P" by simp default
   1.434 +  qed
   1.435 +next
   1.436 +  let ?G = generator
   1.437 +  assume "\<not> finite I"
   1.438 +  note \<mu>G_mono =
   1.439 +    G.additive_increasing[OF positive_\<mu>G additive_\<mu>G, THEN increasingD]
   1.440 +
   1.441 +  { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> sets ?G"
   1.442 +
   1.443 +    from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
   1.444 +      by (metis rev_finite_subset subsetI)
   1.445 +    moreover from Z guess K' X' by (rule generatorE)
   1.446 +    moreover def K \<equiv> "insert k K'"
   1.447 +    moreover def X \<equiv> "emb K K' X'"
   1.448 +    ultimately have K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "X \<in> sets (Pi\<^isub>M K M)" "Z = emb I K X"
   1.449 +      "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = measure (Pi\<^isub>M K M) X"
   1.450 +      by (auto simp: subset_insertI)
   1.451 +
   1.452 +    let "?M y" = "merge J y (K - J) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M)"
   1.453 +    { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
   1.454 +      note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
   1.455 +      moreover
   1.456 +      have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
   1.457 +        using J K y by (intro merge_sets) auto
   1.458 +      ultimately
   1.459 +      have ***: "(merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> sets ?G"
   1.460 +        using J K by (intro generatorI) auto
   1.461 +      have "\<mu>G (merge J y (I - J) -` emb I K X \<inter> space (Pi\<^isub>M I M)) = measure (Pi\<^isub>M (K - J) M) (?M y)"
   1.462 +        unfolding * using K J by (subst \<mu>G_eq[OF _ _ _ **]) auto
   1.463 +      note * ** *** this }
   1.464 +    note merge_in_G = this
   1.465 +
   1.466 +    have "finite (K - J)" using K by auto
   1.467 +
   1.468 +    interpret J: finite_product_prob_space M J by default fact+
   1.469 +    interpret KmJ: finite_product_prob_space M "K - J" by default fact+
   1.470 +
   1.471 +    have "\<mu>G Z = measure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
   1.472 +      using K J by simp
   1.473 +    also have "\<dots> = (\<integral>\<^isup>+ x. measure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
   1.474 +      using K J by (subst measure_fold_integral) auto
   1.475 +    also have "\<dots> = (\<integral>\<^isup>+ y. \<mu>G (merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M)) \<partial>Pi\<^isub>M J M)"
   1.476 +      (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
   1.477 +    proof (intro J.positive_integral_cong)
   1.478 +      fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   1.479 +      with K merge_in_G(2)[OF this]
   1.480 +      show "measure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
   1.481 +        unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst \<mu>G_eq) auto
   1.482 +    qed
   1.483 +    finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
   1.484 +
   1.485 +    { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   1.486 +      then have "\<mu>G (?MZ x) \<le> 1"
   1.487 +        unfolding merge_in_G(4)[OF x] `Z = emb I K X`
   1.488 +        by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
   1.489 +    note le_1 = this
   1.490 +
   1.491 +    let "?q y" = "\<mu>G (merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M))"
   1.492 +    have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
   1.493 +      unfolding `Z = emb I K X` using J K merge_in_G(3)
   1.494 +      by (simp add: merge_in_G  \<mu>G_eq measure_fold_measurable
   1.495 +               del: space_product_algebra cong: measurable_cong)
   1.496 +    note this fold le_1 merge_in_G(3) }
   1.497 +  note fold = this
   1.498 +
   1.499 +  show ?thesis
   1.500 +  proof (rule G.caratheodory_empty_continuous[OF positive_\<mu>G additive_\<mu>G])
   1.501 +    fix A assume "A \<in> sets ?G"
   1.502 +    with generatorE guess J X . note JX = this
   1.503 +    interpret JK: finite_product_prob_space M J by default fact+
   1.504 +    with JX show "\<mu>G A \<noteq> \<infinity>" by simp
   1.505 +  next
   1.506 +    fix A assume A: "range A \<subseteq> sets ?G" "decseq A" "(\<Inter>i. A i) = {}"
   1.507 +    then have "decseq (\<lambda>i. \<mu>G (A i))"
   1.508 +      by (auto intro!: \<mu>G_mono simp: decseq_def)
   1.509 +    moreover
   1.510 +    have "(INF i. \<mu>G (A i)) = 0"
   1.511 +    proof (rule ccontr)
   1.512 +      assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
   1.513 +      moreover have "0 \<le> ?a"
   1.514 +        using A positive_\<mu>G by (auto intro!: le_INFI simp: positive_def)
   1.515 +      ultimately have "0 < ?a" by auto
   1.516 +
   1.517 +      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) = measure (Pi\<^isub>M J M) X"
   1.518 +        using A by (intro allI generator_Ex) auto
   1.519 +      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)"
   1.520 +        and A': "\<And>n. A n = emb I (J' n) (X' n)"
   1.521 +        unfolding choice_iff by blast
   1.522 +      moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
   1.523 +      moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
   1.524 +      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)"
   1.525 +        by auto
   1.526 +      with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> sets ?G"
   1.527 +        unfolding J_def X_def by (subst emb_trans) (insert A, auto)
   1.528 +
   1.529 +      have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
   1.530 +        unfolding J_def by force
   1.531 +
   1.532 +      interpret J: finite_product_prob_space M "J i" for i by default fact+
   1.533 +
   1.534 +      have a_le_1: "?a \<le> 1"
   1.535 +        using \<mu>G_spec[of "J 0" "A 0" "X 0"] J A_eq
   1.536 +        by (auto intro!: INF_leI2[of 0] J.measure_le_1)
   1.537 +
   1.538 +      let "?M K Z y" = "merge K y (I - K) -` Z \<inter> space (Pi\<^isub>M I M)"
   1.539 +
   1.540 +      { fix Z k assume Z: "range Z \<subseteq> sets ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
   1.541 +        then have Z_sets: "\<And>n. Z n \<in> sets ?G" by auto
   1.542 +        fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
   1.543 +        interpret J': finite_product_prob_space M J' by default fact+
   1.544 +
   1.545 +        let "?q n y" = "\<mu>G (?M J' (Z n) y)"
   1.546 +        let "?Q n" = "?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
   1.547 +        { fix n
   1.548 +          have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
   1.549 +            using Z J' by (intro fold(1)) auto
   1.550 +          then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
   1.551 +            by (rule measurable_sets) auto }
   1.552 +        note Q_sets = this
   1.553 +
   1.554 +        have "?a / 2^(k+1) \<le> (INF n. measure (Pi\<^isub>M J' M) (?Q n))"
   1.555 +        proof (intro le_INFI)
   1.556 +          fix n
   1.557 +          have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
   1.558 +          also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
   1.559 +            unfolding fold(2)[OF J' `Z n \<in> sets ?G`]
   1.560 +          proof (intro J'.positive_integral_mono)
   1.561 +            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   1.562 +            then have "?q n x \<le> 1 + 0"
   1.563 +              using J' Z fold(3) Z_sets by auto
   1.564 +            also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
   1.565 +              using `0 < ?a` by (intro add_mono) auto
   1.566 +            finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
   1.567 +            with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
   1.568 +              by (auto split: split_indicator simp del: power_Suc)
   1.569 +          qed
   1.570 +          also have "\<dots> = measure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
   1.571 +            using `0 \<le> ?a` Q_sets J'.measure_space_1
   1.572 +            by (subst J'.positive_integral_add) auto
   1.573 +          finally show "?a / 2^(k+1) \<le> measure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
   1.574 +            by (cases rule: extreal2_cases[of ?a "measure (Pi\<^isub>M J' M) (?Q n)"])
   1.575 +               (auto simp: field_simps)
   1.576 +        qed
   1.577 +        also have "\<dots> = measure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
   1.578 +        proof (intro J'.continuity_from_above)
   1.579 +          show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
   1.580 +          show "decseq ?Q"
   1.581 +            unfolding decseq_def
   1.582 +          proof (safe intro!: vimageI[OF refl])
   1.583 +            fix m n :: nat assume "m \<le> n"
   1.584 +            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   1.585 +            assume "?a / 2^(k+1) \<le> ?q n x"
   1.586 +            also have "?q n x \<le> ?q m x"
   1.587 +            proof (rule \<mu>G_mono)
   1.588 +              from fold(4)[OF J', OF Z_sets x]
   1.589 +              show "?M J' (Z n) x \<in> sets ?G" "?M J' (Z m) x \<in> sets ?G" by auto
   1.590 +              show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
   1.591 +                using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
   1.592 +            qed
   1.593 +            finally show "?a / 2^(k+1) \<le> ?q m x" .
   1.594 +          qed
   1.595 +        qed (intro J'.finite_measure Q_sets)
   1.596 +        finally have "(\<Inter>n. ?Q n) \<noteq> {}"
   1.597 +          using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   1.598 +        then have "\<exists>w\<in>space (Pi\<^isub>M J' M). \<forall>n. ?a / 2 ^ (k + 1) \<le> ?q n w" by auto }
   1.599 +      note Ex_w = this
   1.600 +
   1.601 +      let "?q k n y" = "\<mu>G (?M (J k) (A n) y)"
   1.602 +
   1.603 +      have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_leI)
   1.604 +      from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
   1.605 +
   1.606 +      let "?P k wk w" =
   1.607 +        "w \<in> space (Pi\<^isub>M (J (Suc k)) M) \<and> restrict w (J k) = wk \<and> (\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n w)"
   1.608 +      def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
   1.609 +
   1.610 +      { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
   1.611 +          (\<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))"
   1.612 +        proof (induct k)
   1.613 +          case 0 with w0 show ?case
   1.614 +            unfolding w_def nat_rec_0 by auto
   1.615 +        next
   1.616 +          case (Suc k)
   1.617 +          then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   1.618 +          have "\<exists>w'. ?P k (w k) w'"
   1.619 +          proof cases
   1.620 +            assume [simp]: "J k = J (Suc k)"
   1.621 +            show ?thesis
   1.622 +            proof (intro exI[of _ "w k"] conjI allI)
   1.623 +              fix n
   1.624 +              have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
   1.625 +                using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
   1.626 +              also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
   1.627 +              finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
   1.628 +            next
   1.629 +              show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
   1.630 +                using Suc by simp
   1.631 +              then show "restrict (w k) (J k) = w k"
   1.632 +                by (simp add: extensional_restrict)
   1.633 +            qed
   1.634 +          next
   1.635 +            assume "J k \<noteq> J (Suc k)"
   1.636 +            with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
   1.637 +            have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> sets ?G"
   1.638 +              "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
   1.639 +              "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
   1.640 +              using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
   1.641 +              by (auto simp: decseq_def)
   1.642 +            from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
   1.643 +            obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
   1.644 +              "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
   1.645 +            let ?w = "merge (J k) (w k) ?D w'"
   1.646 +            have [simp]: "\<And>x. merge (J k) (w k) (I - J k) (merge ?D w' (I - ?D) x) =
   1.647 +              merge (J (Suc k)) ?w (I - (J (Suc k))) x"
   1.648 +              using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
   1.649 +              by (auto intro!: ext split: split_merge)
   1.650 +            have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
   1.651 +              using w'(1) J(3)[of "Suc k"]
   1.652 +              by (auto split: split_merge intro!: extensional_merge_sub) force+
   1.653 +            show ?thesis
   1.654 +              apply (rule exI[of _ ?w])
   1.655 +              using w' J_mono[of k "Suc k"] wk unfolding *
   1.656 +              apply (auto split: split_merge intro!: extensional_merge_sub ext)
   1.657 +              apply (force simp: extensional_def)
   1.658 +              done
   1.659 +          qed
   1.660 +          then have "?P k (w k) (w (Suc k))"
   1.661 +            unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
   1.662 +            by (rule someI_ex)
   1.663 +          then show ?case by auto
   1.664 +        qed
   1.665 +        moreover
   1.666 +        then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   1.667 +        moreover
   1.668 +        from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
   1.669 +        then have "?M (J k) (A k) (w k) \<noteq> {}"
   1.670 +          using positive_\<mu>G[unfolded positive_def] `0 < ?a` `?a \<le> 1`
   1.671 +          by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   1.672 +        then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
   1.673 +        then have "merge (J k) (w k) (I - J k) x \<in> A k" by auto
   1.674 +        then have "\<exists>x\<in>A k. restrict x (J k) = w k"
   1.675 +          using `w k \<in> space (Pi\<^isub>M (J k) M)`
   1.676 +          by (intro rev_bexI) (auto intro!: ext simp: extensional_def)
   1.677 +        ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
   1.678 +          "\<exists>x\<in>A k. restrict x (J k) = w k"
   1.679 +          "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
   1.680 +          by auto }
   1.681 +      note w = this
   1.682 +
   1.683 +      { fix k l i assume "k \<le> l" "i \<in> J k"
   1.684 +        { fix l have "w k i = w (k + l) i"
   1.685 +          proof (induct l)
   1.686 +            case (Suc l)
   1.687 +            from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
   1.688 +            with w(3)[of "k + Suc l"]
   1.689 +            have "w (k + l) i = w (k + Suc l) i"
   1.690 +              by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
   1.691 +            with Suc show ?case by simp
   1.692 +          qed simp }
   1.693 +        from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
   1.694 +      note w_mono = this
   1.695 +
   1.696 +      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"
   1.697 +      { fix i k assume k: "i \<in> J k"
   1.698 +        have "w k i = w (LEAST k. i \<in> J k) i"
   1.699 +          by (intro w_mono Least_le k LeastI[of _ k])
   1.700 +        then have "w' i = w k i"
   1.701 +          unfolding w'_def using k by auto }
   1.702 +      note w'_eq = this
   1.703 +      have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
   1.704 +        using J by (auto simp: w'_def)
   1.705 +      have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
   1.706 +        using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
   1.707 +      { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
   1.708 +          using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq)+ }
   1.709 +      note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
   1.710 +
   1.711 +      have w': "w' \<in> space (Pi\<^isub>M I M)"
   1.712 +        using w(1) by (auto simp add: Pi_iff extensional_def)
   1.713 +
   1.714 +      { fix n
   1.715 +        have "restrict w' (J n) = w n" using w(1)
   1.716 +          by (auto simp add: fun_eq_iff restrict_def Pi_iff extensional_def)
   1.717 +        with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
   1.718 +        then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: emb_def) }
   1.719 +      then have "w' \<in> (\<Inter>i. A i)" by auto
   1.720 +      with `(\<Inter>i. A i) = {}` show False by auto
   1.721 +    qed
   1.722 +    ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
   1.723 +      using LIMSEQ_extreal_INFI[of "\<lambda>i. \<mu>G (A i)"] by simp
   1.724 +  qed
   1.725 +qed
   1.726 +
   1.727 +lemma (in product_prob_space) infprod_spec:
   1.728 +  shows "(\<forall>s\<in>sets generator. measure (Pi\<^isub>P I M) s = \<mu>G s) \<and> measure_space (Pi\<^isub>P I M)"
   1.729 +proof -
   1.730 +  let ?P = "\<lambda>\<mu>. (\<forall>A\<in>sets generator. \<mu> A = \<mu>G A) \<and>
   1.731 +       measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>"
   1.732 +  have **: "measure infprod_algebra = (SOME \<mu>. ?P \<mu>)"
   1.733 +    unfolding infprod_algebra_def by simp
   1.734 +  have *: "Pi\<^isub>P I M = \<lparr>space = space generator, sets = sets (sigma generator), measure = measure (Pi\<^isub>P I M)\<rparr>"
   1.735 +    unfolding infprod_algebra_def by auto
   1.736 +  show ?thesis
   1.737 +    apply (subst (2) *)
   1.738 +    apply (unfold **)
   1.739 +    apply (rule someI_ex[where P="?P"])
   1.740 +    apply (rule extend_\<mu>G)
   1.741 +    done
   1.742 +qed
   1.743 +
   1.744 +sublocale product_prob_space \<subseteq> measure_space "Pi\<^isub>P I M"
   1.745 +  using infprod_spec by auto
   1.746 +
   1.747 +lemma (in product_prob_space) measure_infprod_emb:
   1.748 +  assumes "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)"
   1.749 +  shows "measure (Pi\<^isub>P I M) (emb I J X) = measure (Pi\<^isub>M J M) X"
   1.750 +proof -
   1.751 +  have "emb I J X \<in> sets generator"
   1.752 +    using assms by (rule generatorI')
   1.753 +  with \<mu>G_eq[OF assms] infprod_spec show ?thesis by auto
   1.754 +qed
   1.755 +
   1.756 +end
   1.757 \ No newline at end of file