src/HOL/Probability/Infinite_Product_Measure.thy
author hoelzl
Tue May 17 12:24:48 2011 +0200 (2011-05-17)
changeset 42865 36353d913424
parent 42257 08d717c82828
child 42866 b0746bd57a41
permissions -rw-r--r--
add some lemmas for infinite product measure
     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
     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 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)"
    18   unfolding merge_def by auto
    19 
    20 lemma extensional_merge_sub: "I \<union> J \<subseteq> K \<Longrightarrow> merge I x J 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 x (I - J) 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 locale product_prob_space =
    45   fixes M :: "'i \<Rightarrow> ('a,'b) measure_space_scheme" and I :: "'i set"
    46   assumes prob_spaces: "\<And>i. prob_space (M i)"
    47   and I_not_empty: "I \<noteq> {}"
    48 
    49 locale finite_product_prob_space = product_prob_space M I
    50   for M :: "'i \<Rightarrow> ('a,'b) measure_space_scheme" and I :: "'i set" +
    51   assumes finite_index'[intro]: "finite I"
    52 
    53 sublocale product_prob_space \<subseteq> M: prob_space "M i" for i
    54   by (rule prob_spaces)
    55 
    56 sublocale product_prob_space \<subseteq> product_sigma_finite
    57   by default
    58 
    59 sublocale finite_product_prob_space \<subseteq> finite_product_sigma_finite
    60   by default (fact finite_index')
    61 
    62 sublocale finite_product_prob_space \<subseteq> prob_space "Pi\<^isub>M I M"
    63 proof
    64   show "measure P (space P) = 1"
    65     by (simp add: measure_times measure_space_1 setprod_1)
    66 qed
    67 
    68 lemma (in product_prob_space) measure_preserving_restrict:
    69   assumes "J \<noteq> {}" "J \<subseteq> K" "finite K"
    70   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> _")
    71 proof -
    72   interpret K: finite_product_prob_space M K
    73     by default (insert assms, auto)
    74   have J: "J \<noteq> {}" "finite J" using assms by (auto simp add: finite_subset)
    75   interpret J: finite_product_prob_space M J
    76     by default (insert J, auto)
    77   from J.sigma_finite_pairs guess F .. note F = this
    78   then have [simp,intro]: "\<And>k i. k \<in> J \<Longrightarrow> F k i \<in> sets (M k)"
    79     by auto
    80   let "?F i" = "\<Pi>\<^isub>E k\<in>J. F k i"
    81   let ?J = "product_algebra_generator J M \<lparr> measure := measure (Pi\<^isub>M J M) \<rparr>"
    82   have "?R \<in> measure_preserving (\<Pi>\<^isub>M i\<in>K. M i) (sigma ?J)"
    83   proof (rule K.measure_preserving_Int_stable)
    84     show "Int_stable ?J"
    85       by (auto simp: Int_stable_def product_algebra_generator_def PiE_Int)
    86     show "range ?F \<subseteq> sets ?J" "incseq ?F" "(\<Union>i. ?F i) = space ?J"
    87       using F by auto
    88     show "\<And>i. measure ?J (?F i) \<noteq> \<infinity>"
    89       using F by (simp add: J.measure_times setprod_PInf)
    90     have "measure_space (Pi\<^isub>M J M)" by default
    91     then show "measure_space (sigma ?J)"
    92       by (simp add: product_algebra_def sigma_def)
    93     show "?R \<in> measure_preserving (Pi\<^isub>M K M) ?J"
    94     proof (simp add: measure_preserving_def measurable_def product_algebra_generator_def del: vimage_Int,
    95            safe intro!: restrict_extensional)
    96       fix x k assume "k \<in> J" "x \<in> (\<Pi> i\<in>K. space (M i))"
    97       then show "x k \<in> space (M k)" using `J \<subseteq> K` by auto
    98     next
    99       fix E assume "E \<in> (\<Pi> i\<in>J. sets (M i))"
   100       then have E: "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets (M j)" by auto
   101       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))"
   102         (is "?X = Pi\<^isub>E K ?M")
   103         using `J \<subseteq> K` sets_into_space by (auto simp: Pi_iff split: split_if_asm) blast+
   104       with E show "?X \<in> sets (Pi\<^isub>M K M)"
   105         by (auto intro!: product_algebra_generatorI)
   106       have "measure (Pi\<^isub>M J M) (Pi\<^isub>E J E) = (\<Prod>i\<in>J. measure (M i) (?M i))"
   107         using E by (simp add: J.measure_times)
   108       also have "\<dots> = measure (Pi\<^isub>M K M) ?X"
   109         unfolding * using E `finite K` `J \<subseteq> K`
   110         by (auto simp: K.measure_times M.measure_space_1
   111                  cong del: setprod_cong
   112                  intro!: setprod_mono_one_left)
   113       finally show "measure (Pi\<^isub>M J M) (Pi\<^isub>E J E) = measure (Pi\<^isub>M K M) ?X" .
   114     qed
   115   qed
   116   then show ?thesis
   117     by (simp add: product_algebra_def sigma_def)
   118 qed
   119 
   120 lemma (in product_prob_space) measurable_restrict:
   121   assumes *: "J \<noteq> {}" "J \<subseteq> K" "finite K"
   122   shows "(\<lambda>f. restrict f J) \<in> measurable (\<Pi>\<^isub>M i\<in>K. M i) (\<Pi>\<^isub>M i\<in>J. M i)"
   123   using measure_preserving_restrict[OF *]
   124   by (rule measure_preservingD2)
   125 
   126 definition (in product_prob_space)
   127   "emb J K X = (\<lambda>x. restrict x K) -` X \<inter> space (Pi\<^isub>M J M)"
   128 
   129 lemma (in product_prob_space) emb_trans[simp]:
   130   "J \<subseteq> K \<Longrightarrow> K \<subseteq> L \<Longrightarrow> emb L K (emb K J X) = emb L J X"
   131   by (auto simp add: Int_absorb1 emb_def)
   132 
   133 lemma (in product_prob_space) emb_empty[simp]:
   134   "emb K J {} = {}"
   135   by (simp add: emb_def)
   136 
   137 lemma (in product_prob_space) emb_Pi:
   138   assumes "X \<in> (\<Pi> j\<in>J. sets (M j))" "J \<subseteq> K"
   139   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))"
   140   using assms space_closed
   141   by (auto simp: emb_def Pi_iff split: split_if_asm) blast+
   142 
   143 lemma (in product_prob_space) emb_injective:
   144   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)"
   145   assumes "emb L J X = emb L J Y"
   146   shows "X = Y"
   147 proof -
   148   interpret J: finite_product_sigma_finite M J by default fact
   149   show "X = Y"
   150   proof (rule injective_vimage_restrict)
   151     show "X \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))" "Y \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))"
   152       using J.sets_into_space sets by auto
   153     have "\<forall>i\<in>L. \<exists>x. x \<in> space (M i)"
   154       using M.not_empty by auto
   155     from bchoice[OF this]
   156     show "(\<Pi>\<^isub>E i\<in>L. space (M i)) \<noteq> {}" by auto
   157     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))"
   158       using `emb L J X = emb L J Y` by (simp add: emb_def)
   159   qed fact
   160 qed
   161 
   162 lemma (in product_prob_space) emb_id:
   163   "B \<subseteq> (\<Pi>\<^isub>E i\<in>L. space (M i)) \<Longrightarrow> emb L L B = B"
   164   by (auto simp: emb_def Pi_iff subset_eq extensional_restrict)
   165 
   166 lemma (in product_prob_space) emb_simps:
   167   shows "emb L K (A \<union> B) = emb L K A \<union> emb L K B"
   168     and "emb L K (A \<inter> B) = emb L K A \<inter> emb L K B"
   169     and "emb L K (A - B) = emb L K A - emb L K B"
   170   by (auto simp: emb_def)
   171 
   172 lemma (in product_prob_space) measurable_emb[intro,simp]:
   173   assumes *: "J \<noteq> {}" "J \<subseteq> L" "finite L" "X \<in> sets (Pi\<^isub>M J M)"
   174   shows "emb L J X \<in> sets (Pi\<^isub>M L M)"
   175   using measurable_restrict[THEN measurable_sets, OF *] by (simp add: emb_def)
   176 
   177 lemma (in product_prob_space) measure_emb[intro,simp]:
   178   assumes *: "J \<noteq> {}" "J \<subseteq> L" "finite L" "X \<in> sets (Pi\<^isub>M J M)"
   179   shows "measure (Pi\<^isub>M L M) (emb L J X) = measure (Pi\<^isub>M J M) X"
   180   using measure_preserving_restrict[THEN measure_preservingD, OF *]
   181   by (simp add: emb_def)
   182 
   183 definition (in product_prob_space) generator :: "('i \<Rightarrow> 'a) measure_space" where
   184   "generator = \<lparr>
   185     space = (\<Pi>\<^isub>E i\<in>I. space (M i)),
   186     sets = (\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` sets (Pi\<^isub>M J M)),
   187     measure = undefined
   188   \<rparr>"
   189 
   190 lemma (in product_prob_space) generatorI:
   191   "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"
   192   unfolding generator_def by auto
   193 
   194 lemma (in product_prob_space) generatorI':
   195   "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"
   196   unfolding generator_def by auto
   197 
   198 lemma (in product_sigma_finite)
   199   assumes "I \<inter> J = {}" "finite I" "finite J" and A: "A \<in> sets (Pi\<^isub>M (I \<union> J) M)"
   200   shows measure_fold_integral:
   201     "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)
   202     and measure_fold_measurable:
   203     "(\<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)
   204 proof -
   205   interpret I: finite_product_sigma_finite M I by default fact
   206   interpret J: finite_product_sigma_finite M J by default fact
   207   interpret IJ: pair_sigma_finite I.P J.P ..
   208   show ?I
   209     unfolding measure_fold[OF assms]
   210     apply (subst IJ.pair_measure_alt)
   211     apply (intro measurable_sets[OF _ A] measurable_merge assms)
   212     apply (auto simp: vimage_compose[symmetric] comp_def space_pair_measure
   213       intro!: I.positive_integral_cong)
   214     done
   215 
   216   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)"
   217     by (intro measurable_sets[OF _ A] measurable_merge assms)
   218   from IJ.measure_cut_measurable_fst[OF this]
   219   show ?B
   220     apply (auto simp: vimage_compose[symmetric] comp_def space_pair_measure)
   221     apply (subst (asm) measurable_cong)
   222     apply auto
   223     done
   224 qed
   225 
   226 lemma (in prob_space) measure_le_1: "X \<in> sets M \<Longrightarrow> \<mu> X \<le> 1"
   227   unfolding measure_space_1[symmetric]
   228   using sets_into_space
   229   by (intro measure_mono) auto
   230 
   231 definition (in product_prob_space)
   232   "\<mu>G A =
   233     (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))"
   234 
   235 lemma (in product_prob_space) \<mu>G_spec:
   236   assumes J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
   237   shows "\<mu>G A = measure (Pi\<^isub>M J M) X"
   238   unfolding \<mu>G_def
   239 proof (intro the_equality allI impI ballI)
   240   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)"
   241   have "measure (Pi\<^isub>M K M) Y = measure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) K Y)"
   242     using K J by simp
   243   also have "emb (K \<union> J) K Y = emb (K \<union> J) J X"
   244     using K J by (simp add: emb_injective[of "K \<union> J" I])
   245   also have "measure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) J X) = measure (Pi\<^isub>M J M) X"
   246     using K J by simp
   247   finally show "measure (Pi\<^isub>M J M) X = measure (Pi\<^isub>M K M) Y" ..
   248 qed (insert J, force)
   249 
   250 lemma (in product_prob_space) \<mu>G_eq:
   251   "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"
   252   by (intro \<mu>G_spec) auto
   253 
   254 lemma (in product_prob_space) generator_Ex:
   255   assumes *: "A \<in> sets generator"
   256   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"
   257 proof -
   258   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)"
   259     unfolding generator_def by auto
   260   with \<mu>G_spec[OF this] show ?thesis by auto
   261 qed
   262 
   263 lemma (in product_prob_space) generatorE:
   264   assumes A: "A \<in> sets generator"
   265   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"
   266 proof -
   267   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"
   268     "\<mu>G A = measure (Pi\<^isub>M J M) X" by auto
   269   then show thesis by (intro that) auto
   270 qed
   271 
   272 lemma (in product_prob_space) merge_sets:
   273   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)"
   274   shows "merge J x K -` A \<inter> space (Pi\<^isub>M K M) \<in> sets (Pi\<^isub>M K M)"
   275 proof -
   276   interpret J: finite_product_sigma_algebra M J by default fact
   277   interpret K: finite_product_sigma_algebra M K by default fact
   278   interpret JK: pair_sigma_algebra J.P K.P ..
   279 
   280   from JK.measurable_cut_fst[OF
   281     measurable_merge[THEN measurable_sets, OF `J \<inter> K = {}`], OF A, of x] x
   282   show ?thesis
   283       by (simp add: space_pair_measure comp_def vimage_compose[symmetric])
   284 qed
   285 
   286 lemma (in product_prob_space) merge_emb:
   287   assumes "K \<subseteq> I" "J \<subseteq> I" and y: "y \<in> space (Pi\<^isub>M J M)"
   288   shows "(merge J y (I - J) -` emb I K X \<inter> space (Pi\<^isub>M I M)) =
   289     emb I (K - J) (merge J y (K - J) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M))"
   290 proof -
   291   have [simp]: "\<And>x J K L. merge J y K (restrict x L) = merge J y (K \<inter> L) x"
   292     by (auto simp: restrict_def merge_def)
   293   have [simp]: "\<And>x J K L. restrict (merge J y K x) L = merge (J \<inter> L) y (K \<inter> L) x"
   294     by (auto simp: restrict_def merge_def)
   295   have [simp]: "(I - J) \<inter> K = K - J" using `K \<subseteq> I` `J \<subseteq> I` by auto
   296   have [simp]: "(K - J) \<inter> (K \<union> J) = K - J" by auto
   297   have [simp]: "(K - J) \<inter> K = K - J" by auto
   298   from y `K \<subseteq> I` `J \<subseteq> I` show ?thesis
   299     by (simp split: split_merge add: emb_def Pi_iff extensional_merge_sub set_eq_iff) auto
   300 qed
   301 
   302 definition (in product_prob_space) infprod_algebra :: "('i \<Rightarrow> 'a) measure_space" where
   303   "infprod_algebra = sigma generator \<lparr> measure :=
   304     (SOME \<mu>. (\<forall>s\<in>sets generator. \<mu> s = \<mu>G s) \<and>
   305        measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>)\<rparr>"
   306 
   307 syntax
   308   "_PiP"  :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3PIP _:_./ _)" 10)
   309 
   310 syntax (xsymbols)
   311   "_PiP" :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3\<Pi>\<^isub>P _\<in>_./ _)"   10)
   312 
   313 syntax (HTML output)
   314   "_PiP" :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3\<Pi>\<^isub>P _\<in>_./ _)"   10)
   315 
   316 abbreviation
   317   "Pi\<^isub>P I M \<equiv> product_prob_space.infprod_algebra M I"
   318 
   319 translations
   320   "PIP x:I. M" == "CONST Pi\<^isub>P I (%x. M)"
   321 
   322 sublocale product_prob_space \<subseteq> G!: algebra generator
   323 proof
   324   let ?G = generator
   325   show "sets ?G \<subseteq> Pow (space ?G)"
   326     by (auto simp: generator_def emb_def)
   327   from I_not_empty
   328   obtain i where "i \<in> I" by auto
   329   then show "{} \<in> sets ?G"
   330     by (auto intro!: exI[of _ "{i}"] image_eqI[where x="\<lambda>i. {}"]
   331       simp: product_algebra_def sigma_def sigma_sets.Empty generator_def emb_def)
   332   from `i \<in> I` show "space ?G \<in> sets ?G"
   333     by (auto intro!: exI[of _ "{i}"] image_eqI[where x="Pi\<^isub>E {i} (\<lambda>i. space (M i))"]
   334       simp: generator_def emb_def)
   335   fix A assume "A \<in> sets ?G"
   336   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"
   337     by (auto simp: generator_def)
   338   fix B assume "B \<in> sets ?G"
   339   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"
   340     by (auto simp: generator_def)
   341   let ?RA = "emb (JA \<union> JB) JA XA"
   342   let ?RB = "emb (JA \<union> JB) JB XB"
   343   interpret JAB: finite_product_sigma_algebra M "JA \<union> JB"
   344     by default (insert XA XB, auto)
   345   have *: "A - B = emb I (JA \<union> JB) (?RA - ?RB)" "A \<union> B = emb I (JA \<union> JB) (?RA \<union> ?RB)"
   346     using XA A XB B by (auto simp: emb_simps)
   347   then show "A - B \<in> sets ?G" "A \<union> B \<in> sets ?G"
   348     using XA XB by (auto intro!: generatorI')
   349 qed
   350 
   351 lemma (in product_prob_space) positive_\<mu>G: "positive generator \<mu>G"
   352 proof (intro positive_def[THEN iffD2] conjI ballI)
   353   from generatorE[OF G.empty_sets] guess J X . note this[simp]
   354   interpret J: finite_product_sigma_finite M J by default fact
   355   have "X = {}"
   356     by (rule emb_injective[of J I]) simp_all
   357   then show "\<mu>G {} = 0" by simp
   358 next
   359   fix A assume "A \<in> sets generator"
   360   from generatorE[OF this] guess J X . note this[simp]
   361   interpret J: finite_product_sigma_finite M J by default fact
   362   show "0 \<le> \<mu>G A" by simp
   363 qed
   364 
   365 lemma (in product_prob_space) additive_\<mu>G: "additive generator \<mu>G"
   366 proof (intro additive_def[THEN iffD2] ballI impI)
   367   fix A assume "A \<in> sets generator" with generatorE guess J X . note J = this
   368   fix B assume "B \<in> sets generator" with generatorE guess K Y . note K = this
   369   assume "A \<inter> B = {}"
   370   have JK: "J \<union> K \<noteq> {}" "J \<union> K \<subseteq> I" "finite (J \<union> K)"
   371     using J K by auto
   372   interpret JK: finite_product_sigma_finite M "J \<union> K" by default fact
   373   have JK_disj: "emb (J \<union> K) J X \<inter> emb (J \<union> K) K Y = {}"
   374     apply (rule emb_injective[of "J \<union> K" I])
   375     apply (insert `A \<inter> B = {}` JK J K)
   376     apply (simp_all add: JK.Int emb_simps)
   377     done
   378   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)"
   379     using J K by simp_all
   380   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))"
   381     by (simp add: emb_simps)
   382   also have "\<dots> = measure (Pi\<^isub>M (J \<union> K) M) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y)"
   383     using JK J(1, 4) K(1, 4) by (simp add: \<mu>G_eq JK.Un)
   384   also have "\<dots> = \<mu>G A + \<mu>G B"
   385     using J K JK_disj by (simp add: JK.measure_additive[symmetric])
   386   finally show "\<mu>G (A \<union> B) = \<mu>G A + \<mu>G B" .
   387 qed
   388 
   389 lemma (in product_prob_space) finite_index_eq_finite_product:
   390   assumes "finite I"
   391   shows "sets (sigma generator) = sets (Pi\<^isub>M I M)"
   392 proof safe
   393   interpret I: finite_product_sigma_algebra M I by default fact
   394   have [simp]: "space generator = space (Pi\<^isub>M I M)"
   395     by (simp add: generator_def product_algebra_def)
   396   { fix A assume "A \<in> sets (sigma generator)"
   397     then show "A \<in> sets I.P" unfolding sets_sigma
   398     proof induct
   399       case (Basic A)
   400       from generatorE[OF this] guess J X . note J = this
   401       with `finite I` have "emb I J X \<in> sets I.P" by auto
   402       with `emb I J X = A` show "A \<in> sets I.P" by simp
   403     qed auto }
   404   { fix A assume "A \<in> sets I.P"
   405     moreover with I.sets_into_space have "emb I I A = A" by (intro emb_id) auto
   406     ultimately show "A \<in> sets (sigma generator)"
   407       using `finite I` I_not_empty unfolding sets_sigma
   408       by (intro sigma_sets.Basic generatorI[of I A]) auto }
   409 qed
   410 
   411 lemma (in product_prob_space) extend_\<mu>G:
   412   "\<exists>\<mu>. (\<forall>s\<in>sets generator. \<mu> s = \<mu>G s) \<and>
   413        measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>"
   414 proof cases
   415   assume "finite I"
   416   interpret I: finite_product_sigma_finite M I by default fact
   417   show ?thesis
   418   proof (intro exI[of _ "measure (Pi\<^isub>M I M)"] ballI conjI)
   419     fix A assume "A \<in> sets generator"
   420     from generatorE[OF this] guess J X . note J = this
   421     from J(1-4) `finite I` show "measure I.P A = \<mu>G A"
   422       unfolding J(6)
   423       by (subst J(5)[symmetric]) (simp add: measure_emb)
   424   next
   425     have [simp]: "space generator = space (Pi\<^isub>M I M)"
   426       by (simp add: generator_def product_algebra_def)
   427     have "\<lparr>space = space generator, sets = sets (sigma generator), measure = measure I.P\<rparr>
   428       = I.P" (is "?P = _")
   429       by (auto intro!: measure_space.equality simp: finite_index_eq_finite_product[OF `finite I`])
   430     then show "measure_space ?P" by simp default
   431   qed
   432 next
   433   let ?G = generator
   434   assume "\<not> finite I"
   435   note \<mu>G_mono =
   436     G.additive_increasing[OF positive_\<mu>G additive_\<mu>G, THEN increasingD]
   437 
   438   { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> sets ?G"
   439 
   440     from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
   441       by (metis rev_finite_subset subsetI)
   442     moreover from Z guess K' X' by (rule generatorE)
   443     moreover def K \<equiv> "insert k K'"
   444     moreover def X \<equiv> "emb K K' X'"
   445     ultimately have K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "X \<in> sets (Pi\<^isub>M K M)" "Z = emb I K X"
   446       "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = measure (Pi\<^isub>M K M) X"
   447       by (auto simp: subset_insertI)
   448 
   449     let "?M y" = "merge J y (K - J) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M)"
   450     { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
   451       note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
   452       moreover
   453       have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
   454         using J K y by (intro merge_sets) auto
   455       ultimately
   456       have ***: "(merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> sets ?G"
   457         using J K by (intro generatorI) auto
   458       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)"
   459         unfolding * using K J by (subst \<mu>G_eq[OF _ _ _ **]) auto
   460       note * ** *** this }
   461     note merge_in_G = this
   462 
   463     have "finite (K - J)" using K by auto
   464 
   465     interpret J: finite_product_prob_space M J by default fact+
   466     interpret KmJ: finite_product_prob_space M "K - J" by default fact+
   467 
   468     have "\<mu>G Z = measure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
   469       using K J by simp
   470     also have "\<dots> = (\<integral>\<^isup>+ x. measure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
   471       using K J by (subst measure_fold_integral) auto
   472     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)"
   473       (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
   474     proof (intro J.positive_integral_cong)
   475       fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   476       with K merge_in_G(2)[OF this]
   477       show "measure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
   478         unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst \<mu>G_eq) auto
   479     qed
   480     finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
   481 
   482     { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   483       then have "\<mu>G (?MZ x) \<le> 1"
   484         unfolding merge_in_G(4)[OF x] `Z = emb I K X`
   485         by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
   486     note le_1 = this
   487 
   488     let "?q y" = "\<mu>G (merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M))"
   489     have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
   490       unfolding `Z = emb I K X` using J K merge_in_G(3)
   491       by (simp add: merge_in_G  \<mu>G_eq measure_fold_measurable
   492                del: space_product_algebra cong: measurable_cong)
   493     note this fold le_1 merge_in_G(3) }
   494   note fold = this
   495 
   496   show ?thesis
   497   proof (rule G.caratheodory_empty_continuous[OF positive_\<mu>G additive_\<mu>G])
   498     fix A assume "A \<in> sets ?G"
   499     with generatorE guess J X . note JX = this
   500     interpret JK: finite_product_prob_space M J by default fact+
   501     with JX show "\<mu>G A \<noteq> \<infinity>" by simp
   502   next
   503     fix A assume A: "range A \<subseteq> sets ?G" "decseq A" "(\<Inter>i. A i) = {}"
   504     then have "decseq (\<lambda>i. \<mu>G (A i))"
   505       by (auto intro!: \<mu>G_mono simp: decseq_def)
   506     moreover
   507     have "(INF i. \<mu>G (A i)) = 0"
   508     proof (rule ccontr)
   509       assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
   510       moreover have "0 \<le> ?a"
   511         using A positive_\<mu>G by (auto intro!: le_INFI simp: positive_def)
   512       ultimately have "0 < ?a" by auto
   513 
   514       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"
   515         using A by (intro allI generator_Ex) auto
   516       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)"
   517         and A': "\<And>n. A n = emb I (J' n) (X' n)"
   518         unfolding choice_iff by blast
   519       moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
   520       moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
   521       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)"
   522         by auto
   523       with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> sets ?G"
   524         unfolding J_def X_def by (subst emb_trans) (insert A, auto)
   525 
   526       have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
   527         unfolding J_def by force
   528 
   529       interpret J: finite_product_prob_space M "J i" for i by default fact+
   530 
   531       have a_le_1: "?a \<le> 1"
   532         using \<mu>G_spec[of "J 0" "A 0" "X 0"] J A_eq
   533         by (auto intro!: INF_leI2[of 0] J.measure_le_1)
   534 
   535       let "?M K Z y" = "merge K y (I - K) -` Z \<inter> space (Pi\<^isub>M I M)"
   536 
   537       { fix Z k assume Z: "range Z \<subseteq> sets ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
   538         then have Z_sets: "\<And>n. Z n \<in> sets ?G" by auto
   539         fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
   540         interpret J': finite_product_prob_space M J' by default fact+
   541 
   542         let "?q n y" = "\<mu>G (?M J' (Z n) y)"
   543         let "?Q n" = "?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
   544         { fix n
   545           have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
   546             using Z J' by (intro fold(1)) auto
   547           then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
   548             by (rule measurable_sets) auto }
   549         note Q_sets = this
   550 
   551         have "?a / 2^(k+1) \<le> (INF n. measure (Pi\<^isub>M J' M) (?Q n))"
   552         proof (intro le_INFI)
   553           fix n
   554           have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
   555           also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
   556             unfolding fold(2)[OF J' `Z n \<in> sets ?G`]
   557           proof (intro J'.positive_integral_mono)
   558             fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   559             then have "?q n x \<le> 1 + 0"
   560               using J' Z fold(3) Z_sets by auto
   561             also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
   562               using `0 < ?a` by (intro add_mono) auto
   563             finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
   564             with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
   565               by (auto split: split_indicator simp del: power_Suc)
   566           qed
   567           also have "\<dots> = measure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
   568             using `0 \<le> ?a` Q_sets J'.measure_space_1
   569             by (subst J'.positive_integral_add) auto
   570           finally show "?a / 2^(k+1) \<le> measure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
   571             by (cases rule: extreal2_cases[of ?a "measure (Pi\<^isub>M J' M) (?Q n)"])
   572                (auto simp: field_simps)
   573         qed
   574         also have "\<dots> = measure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
   575         proof (intro J'.continuity_from_above)
   576           show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
   577           show "decseq ?Q"
   578             unfolding decseq_def
   579           proof (safe intro!: vimageI[OF refl])
   580             fix m n :: nat assume "m \<le> n"
   581             fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   582             assume "?a / 2^(k+1) \<le> ?q n x"
   583             also have "?q n x \<le> ?q m x"
   584             proof (rule \<mu>G_mono)
   585               from fold(4)[OF J', OF Z_sets x]
   586               show "?M J' (Z n) x \<in> sets ?G" "?M J' (Z m) x \<in> sets ?G" by auto
   587               show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
   588                 using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
   589             qed
   590             finally show "?a / 2^(k+1) \<le> ?q m x" .
   591           qed
   592         qed (intro J'.finite_measure Q_sets)
   593         finally have "(\<Inter>n. ?Q n) \<noteq> {}"
   594           using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   595         then have "\<exists>w\<in>space (Pi\<^isub>M J' M). \<forall>n. ?a / 2 ^ (k + 1) \<le> ?q n w" by auto }
   596       note Ex_w = this
   597 
   598       let "?q k n y" = "\<mu>G (?M (J k) (A n) y)"
   599 
   600       have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_leI)
   601       from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
   602 
   603       let "?P k wk w" =
   604         "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)"
   605       def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
   606 
   607       { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
   608           (\<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))"
   609         proof (induct k)
   610           case 0 with w0 show ?case
   611             unfolding w_def nat_rec_0 by auto
   612         next
   613           case (Suc k)
   614           then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   615           have "\<exists>w'. ?P k (w k) w'"
   616           proof cases
   617             assume [simp]: "J k = J (Suc k)"
   618             show ?thesis
   619             proof (intro exI[of _ "w k"] conjI allI)
   620               fix n
   621               have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
   622                 using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
   623               also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
   624               finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
   625             next
   626               show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
   627                 using Suc by simp
   628               then show "restrict (w k) (J k) = w k"
   629                 by (simp add: extensional_restrict)
   630             qed
   631           next
   632             assume "J k \<noteq> J (Suc k)"
   633             with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
   634             have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> sets ?G"
   635               "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
   636               "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
   637               using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
   638               by (auto simp: decseq_def)
   639             from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
   640             obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
   641               "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
   642             let ?w = "merge (J k) (w k) ?D w'"
   643             have [simp]: "\<And>x. merge (J k) (w k) (I - J k) (merge ?D w' (I - ?D) x) =
   644               merge (J (Suc k)) ?w (I - (J (Suc k))) x"
   645               using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
   646               by (auto intro!: ext split: split_merge)
   647             have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
   648               using w'(1) J(3)[of "Suc k"]
   649               by (auto split: split_merge intro!: extensional_merge_sub) force+
   650             show ?thesis
   651               apply (rule exI[of _ ?w])
   652               using w' J_mono[of k "Suc k"] wk unfolding *
   653               apply (auto split: split_merge intro!: extensional_merge_sub ext)
   654               apply (force simp: extensional_def)
   655               done
   656           qed
   657           then have "?P k (w k) (w (Suc k))"
   658             unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
   659             by (rule someI_ex)
   660           then show ?case by auto
   661         qed
   662         moreover
   663         then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   664         moreover
   665         from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
   666         then have "?M (J k) (A k) (w k) \<noteq> {}"
   667           using positive_\<mu>G[unfolded positive_def] `0 < ?a` `?a \<le> 1`
   668           by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   669         then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
   670         then have "merge (J k) (w k) (I - J k) x \<in> A k" by auto
   671         then have "\<exists>x\<in>A k. restrict x (J k) = w k"
   672           using `w k \<in> space (Pi\<^isub>M (J k) M)`
   673           by (intro rev_bexI) (auto intro!: ext simp: extensional_def)
   674         ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
   675           "\<exists>x\<in>A k. restrict x (J k) = w k"
   676           "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
   677           by auto }
   678       note w = this
   679 
   680       { fix k l i assume "k \<le> l" "i \<in> J k"
   681         { fix l have "w k i = w (k + l) i"
   682           proof (induct l)
   683             case (Suc l)
   684             from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
   685             with w(3)[of "k + Suc l"]
   686             have "w (k + l) i = w (k + Suc l) i"
   687               by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
   688             with Suc show ?case by simp
   689           qed simp }
   690         from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
   691       note w_mono = this
   692 
   693       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"
   694       { fix i k assume k: "i \<in> J k"
   695         have "w k i = w (LEAST k. i \<in> J k) i"
   696           by (intro w_mono Least_le k LeastI[of _ k])
   697         then have "w' i = w k i"
   698           unfolding w'_def using k by auto }
   699       note w'_eq = this
   700       have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
   701         using J by (auto simp: w'_def)
   702       have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
   703         using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
   704       { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
   705           using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq)+ }
   706       note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
   707 
   708       have w': "w' \<in> space (Pi\<^isub>M I M)"
   709         using w(1) by (auto simp add: Pi_iff extensional_def)
   710 
   711       { fix n
   712         have "restrict w' (J n) = w n" using w(1)
   713           by (auto simp add: fun_eq_iff restrict_def Pi_iff extensional_def)
   714         with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
   715         then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: emb_def) }
   716       then have "w' \<in> (\<Inter>i. A i)" by auto
   717       with `(\<Inter>i. A i) = {}` show False by auto
   718     qed
   719     ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
   720       using LIMSEQ_extreal_INFI[of "\<lambda>i. \<mu>G (A i)"] by simp
   721   qed
   722 qed
   723 
   724 lemma (in product_prob_space) infprod_spec:
   725   shows "(\<forall>s\<in>sets generator. measure (Pi\<^isub>P I M) s = \<mu>G s) \<and> measure_space (Pi\<^isub>P I M)"
   726 proof -
   727   let ?P = "\<lambda>\<mu>. (\<forall>A\<in>sets generator. \<mu> A = \<mu>G A) \<and>
   728        measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>"
   729   have **: "measure infprod_algebra = (SOME \<mu>. ?P \<mu>)"
   730     unfolding infprod_algebra_def by simp
   731   have *: "Pi\<^isub>P I M = \<lparr>space = space generator, sets = sets (sigma generator), measure = measure (Pi\<^isub>P I M)\<rparr>"
   732     unfolding infprod_algebra_def by auto
   733   show ?thesis
   734     apply (subst (2) *)
   735     apply (unfold **)
   736     apply (rule someI_ex[where P="?P"])
   737     apply (rule extend_\<mu>G)
   738     done
   739 qed
   740 
   741 sublocale product_prob_space \<subseteq> P: measure_space "Pi\<^isub>P I M"
   742   using infprod_spec by auto
   743 
   744 lemma (in product_prob_space) measure_infprod_emb:
   745   assumes "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)"
   746   shows "\<mu> (emb I J X) = measure (Pi\<^isub>M J M) X"
   747 proof -
   748   have "emb I J X \<in> sets generator"
   749     using assms by (rule generatorI')
   750   with \<mu>G_eq[OF assms] infprod_spec show ?thesis by auto
   751 qed
   752 
   753 sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^isub>P I M"
   754 proof
   755   obtain i where "i \<in> I" using I_not_empty by auto
   756   interpret i: finite_product_sigma_finite M "{i}" by default auto
   757   let ?X = "\<Pi>\<^isub>E i\<in>{i}. space (M i)"
   758   have "?X \<in> sets (Pi\<^isub>M {i} M)"
   759     by auto
   760   from measure_infprod_emb[OF _ _ _ this] `i \<in> I`
   761   have "\<mu> (emb I {i} ?X) = measure (M i) (space (M i))"
   762     by (simp add: i.measure_times)
   763   also have "emb I {i} ?X = space (Pi\<^isub>P I M)"
   764     using `i \<in> I` by (auto simp: emb_def infprod_algebra_def generator_def)
   765   finally show "\<mu> (space (Pi\<^isub>P I M)) = 1"
   766     using M.measure_space_1 by simp
   767 qed
   768 
   769 lemma (in product_prob_space) measurable_component:
   770   assumes "i \<in> I"
   771   shows "(\<lambda>x. x i) \<in> measurable (Pi\<^isub>P I M) (M i)"
   772 proof (unfold measurable_def, safe)
   773   fix x assume "x \<in> space (Pi\<^isub>P I M)"
   774   then show "x i \<in> space (M i)"
   775     using `i \<in> I` by (auto simp: infprod_algebra_def generator_def)
   776 next
   777   fix A assume "A \<in> sets (M i)"
   778   with `i \<in> I` have
   779     "(\<Pi>\<^isub>E x \<in> {i}. A) \<in> sets (Pi\<^isub>M {i} M)"
   780     "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) = emb I {i} (\<Pi>\<^isub>E x \<in> {i}. A)"
   781     by (auto simp: infprod_algebra_def generator_def emb_def)
   782   from generatorI[OF _ _ _ this] `i \<in> I`
   783   show "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) \<in> sets (Pi\<^isub>P I M)"
   784     unfolding infprod_algebra_def by auto
   785 qed
   786 
   787 lemma (in product_prob_space) emb_in_infprod_algebra[intro]:
   788   fixes J assumes J: "finite J" "J \<subseteq> I" and X: "X \<in> sets (Pi\<^isub>M J M)"
   789   shows "emb I J X \<in> sets (\<Pi>\<^isub>P i\<in>I. M i)"
   790 proof cases
   791   assume "J = {}"
   792   with X have "emb I J X = space (\<Pi>\<^isub>P i\<in>I. M i) \<or> emb I J X = {}"
   793     by (auto simp: emb_def infprod_algebra_def generator_def
   794                    product_algebra_def product_algebra_generator_def image_constant sigma_def)
   795   then show ?thesis by auto
   796 next
   797   assume "J \<noteq> {}"
   798   show ?thesis unfolding infprod_algebra_def
   799     by simp (intro in_sigma generatorI'  `J \<noteq> {}` J X)
   800 qed
   801 
   802 lemma (in product_prob_space) finite_measure_infprod_emb:
   803   assumes "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)"
   804   shows "\<mu>' (emb I J X) = finite_measure.\<mu>' (Pi\<^isub>M J M) X"
   805 proof -
   806   interpret J: finite_product_prob_space M J by default fact+
   807   from assms have "emb I J X \<in> sets (Pi\<^isub>P I M)" by auto
   808   with assms show "\<mu>' (emb I J X) = J.\<mu>' X"
   809     unfolding \<mu>'_def J.\<mu>'_def
   810     unfolding measure_infprod_emb[OF assms]
   811     by auto
   812 qed
   813 
   814 lemma (in finite_product_prob_space) finite_measure_times:
   815   assumes "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)"
   816   shows "\<mu>' (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu>' i (A i))"
   817   using assms
   818   unfolding \<mu>'_def M.\<mu>'_def
   819   by (subst measure_times[OF assms])
   820      (auto simp: finite_measure_eq M.finite_measure_eq setprod_extreal)
   821 
   822 lemma (in product_prob_space) finite_measure_infprod_emb_Pi:
   823   assumes J: "finite J" "J \<subseteq> I" "\<And>j. j \<in> J \<Longrightarrow> X j \<in> sets (M j)"
   824   shows "\<mu>' (emb I J (Pi\<^isub>E J X)) = (\<Prod>j\<in>J. M.\<mu>' j (X j))"
   825 proof cases
   826   assume "J = {}"
   827   then have "emb I J (Pi\<^isub>E J X) = space infprod_algebra"
   828     by (auto simp: infprod_algebra_def generator_def sigma_def emb_def)
   829   then show ?thesis using `J = {}` prob_space by simp
   830 next
   831   assume "J \<noteq> {}"
   832   interpret J: finite_product_prob_space M J by default fact+
   833   have "(\<Prod>i\<in>J. M.\<mu>' i (X i)) = J.\<mu>' (Pi\<^isub>E J X)"
   834     using J `J \<noteq> {}` by (subst J.finite_measure_times) auto
   835   also have "\<dots> = \<mu>' (emb I J (Pi\<^isub>E J X))"
   836     using J `J \<noteq> {}` by (intro finite_measure_infprod_emb[symmetric]) auto
   837   finally show ?thesis by simp
   838 qed
   839 
   840 lemma sigma_sets_mono: assumes "A \<subseteq> sigma_sets X B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
   841 proof
   842   fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
   843     by induct (insert `A \<subseteq> sigma_sets X B`, auto intro: sigma_sets.intros)
   844 qed
   845 
   846 lemma sigma_sets_mono': assumes "A \<subseteq> B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
   847 proof
   848   fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
   849     by induct (insert `A \<subseteq> B`, auto intro: sigma_sets.intros)
   850 qed
   851 
   852 lemma sigma_sets_subseteq: "A \<subseteq> sigma_sets X A"
   853   by (auto intro: sigma_sets.Basic)
   854 
   855 lemma (in product_prob_space) infprod_algebra_alt:
   856   "Pi\<^isub>P I M = sigma \<lparr> space = space (Pi\<^isub>P I M),
   857     sets = (\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` Pi\<^isub>E J ` (\<Pi> i \<in> J. sets (M i))),
   858     measure = measure (Pi\<^isub>P I M) \<rparr>"
   859   (is "_ = sigma \<lparr> space = ?O, sets = ?M, measure = ?m \<rparr>")
   860 proof (rule measure_space.equality)
   861   let ?G = "\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` sets (Pi\<^isub>M J M)"
   862   have "sigma_sets ?O ?M = sigma_sets ?O ?G"
   863   proof (intro equalityI sigma_sets_mono UN_least)
   864     fix J assume J: "J \<in> {J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}"
   865     have "emb I J ` Pi\<^isub>E J ` (\<Pi> i\<in>J. sets (M i)) \<subseteq> emb I J ` sets (Pi\<^isub>M J M)" by auto
   866     also have "\<dots> \<subseteq> ?G" using J by (rule UN_upper)
   867     also have "\<dots> \<subseteq> sigma_sets ?O ?G" by (rule sigma_sets_subseteq)
   868     finally show "emb I J ` Pi\<^isub>E J ` (\<Pi> i\<in>J. sets (M i)) \<subseteq> sigma_sets ?O ?G" .
   869     have "emb I J ` sets (Pi\<^isub>M J M) = emb I J ` sigma_sets (space (Pi\<^isub>M J M)) (Pi\<^isub>E J ` (\<Pi> i \<in> J. sets (M i)))"
   870       by (simp add: sets_sigma product_algebra_generator_def product_algebra_def)
   871     also have "\<dots> = sigma_sets (space (Pi\<^isub>M I M)) (emb I J ` Pi\<^isub>E J ` (\<Pi> i \<in> J. sets (M i)))"
   872       using J M.sets_into_space
   873       by (auto simp: emb_def_raw intro!: sigma_sets_vimage[symmetric]) blast
   874     also have "\<dots> \<subseteq> sigma_sets (space (Pi\<^isub>M I M)) ?M"
   875       using J by (intro sigma_sets_mono') auto
   876     finally show "emb I J ` sets (Pi\<^isub>M J M) \<subseteq> sigma_sets ?O ?M"
   877       by (simp add: infprod_algebra_def generator_def)
   878   qed
   879   then show "sets (Pi\<^isub>P I M) = sets (sigma \<lparr> space = ?O, sets = ?M, measure = ?m \<rparr>)"
   880     by (simp_all add: infprod_algebra_def generator_def sets_sigma)
   881 qed simp_all
   882 
   883 lemma (in product_prob_space) infprod_algebra_alt2:
   884   "Pi\<^isub>P I M = sigma \<lparr> space = space (Pi\<^isub>P I M),
   885     sets = (\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (M i)),
   886     measure = measure (Pi\<^isub>P I M) \<rparr>"
   887   (is "_ = ?S")
   888 proof (rule measure_space.equality)
   889   let "sigma \<lparr> space = ?O, sets = ?A, \<dots> = _ \<rparr>" = ?S
   890   let ?G = "(\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` Pi\<^isub>E J ` (\<Pi> i \<in> J. sets (M i)))"
   891   have "sets (Pi\<^isub>P I M) = sigma_sets ?O ?G"
   892     by (subst infprod_algebra_alt) (simp add: sets_sigma)
   893   also have "\<dots> = sigma_sets ?O ?A"
   894   proof (intro equalityI sigma_sets_mono subsetI)
   895     interpret A: sigma_algebra ?S
   896       by (rule sigma_algebra_sigma) auto
   897     fix A assume "A \<in> ?G"
   898     then obtain J B where "finite J" "J \<noteq> {}" "J \<subseteq> I" "A = emb I J (Pi\<^isub>E J B)"
   899         and B: "\<And>i. i \<in> J \<Longrightarrow> B i \<in> sets (M i)"
   900       by auto
   901     then have A: "A = (\<Inter>j\<in>J. (\<lambda>x. x j) -` (B j) \<inter> space (Pi\<^isub>P I M))"
   902       by (auto simp: emb_def infprod_algebra_def generator_def Pi_iff)
   903     { fix j assume "j\<in>J"
   904       with `J \<subseteq> I` have "j \<in> I" by auto
   905       with `j \<in> J` B have "(\<lambda>x. x j) -` (B j) \<inter> space (Pi\<^isub>P I M) \<in> sets ?S"
   906         by (auto simp: sets_sigma intro: sigma_sets.Basic) }
   907     with `finite J` `J \<noteq> {}` have "A \<in> sets ?S"
   908       unfolding A by (intro A.finite_INT) auto
   909     then show "A \<in> sigma_sets ?O ?A" by (simp add: sets_sigma)
   910   next
   911     fix A assume "A \<in> ?A"
   912     then obtain i B where i: "i \<in> I" "B \<in> sets (M i)"
   913         and "A = (\<lambda>x. x i) -` B \<inter> space (Pi\<^isub>P I M)"
   914       by auto
   915     then have "A = emb I {i} (Pi\<^isub>E {i} (\<lambda>_. B))"
   916       by (auto simp: emb_def infprod_algebra_def generator_def Pi_iff)
   917     with i show "A \<in> sigma_sets ?O ?G"
   918       by (intro sigma_sets.Basic UN_I[where a="{i}"]) auto
   919   qed
   920   finally show "sets (Pi\<^isub>P I M) = sets ?S"
   921     by (simp add: sets_sigma)
   922 qed simp_all
   923 
   924 lemma (in product_prob_space) measurable_into_infprod_algebra:
   925   assumes "sigma_algebra N"
   926   assumes f: "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. f x i) \<in> measurable N (M i)"
   927   assumes ext: "\<And>x. x \<in> space N \<Longrightarrow> f x \<in> extensional I"
   928   shows "f \<in> measurable N (Pi\<^isub>P I M)"
   929 proof -
   930   interpret N: sigma_algebra N by fact
   931   have f_in: "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. f x i) \<in> space N \<rightarrow> space (M i)"
   932     using f by (auto simp: measurable_def)
   933   { fix i A assume i: "i \<in> I" "A \<in> sets (M i)"
   934     then have "f -` (\<lambda>x. x i) -` A \<inter> f -` space infprod_algebra \<inter> space N = (\<lambda>x. f x i) -` A \<inter> space N"
   935       using f_in ext by (auto simp: infprod_algebra_def generator_def)
   936     also have "\<dots> \<in> sets N"
   937       by (rule measurable_sets f i)+
   938     finally have "f -` (\<lambda>x. x i) -` A \<inter> f -` space infprod_algebra \<inter> space N \<in> sets N" . }
   939   with f_in ext show ?thesis
   940     by (subst infprod_algebra_alt2)
   941        (auto intro!: N.measurable_sigma simp: Pi_iff infprod_algebra_def generator_def)
   942 qed
   943 
   944 lemma (in product_prob_space) measurable_singleton_infprod:
   945   assumes "i \<in> I"
   946   shows "(\<lambda>x. x i) \<in> measurable (Pi\<^isub>P I M) (M i)"
   947 proof (unfold measurable_def, intro CollectI conjI ballI)
   948   show "(\<lambda>x. x i) \<in> space (Pi\<^isub>P I M) \<rightarrow> space (M i)"
   949     using M.sets_into_space `i \<in> I`
   950     by (auto simp: infprod_algebra_def generator_def)
   951   fix A assume "A \<in> sets (M i)"
   952   have "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) = emb I {i} (\<Pi>\<^isub>E _\<in>{i}. A)"
   953     by (auto simp: infprod_algebra_def generator_def emb_def)
   954   also have "\<dots> \<in> sets (Pi\<^isub>P I M)"
   955     using `i \<in> I` `A \<in> sets (M i)`
   956     by (intro emb_in_infprod_algebra product_algebraI) auto
   957   finally show "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) \<in> sets (Pi\<^isub>P I M)" .
   958 qed
   959 
   960 lemma (in product_prob_space) sigma_product_algebra_sigma_eq:
   961   assumes M: "\<And>i. i \<in> I \<Longrightarrow> M i = sigma (E i)"
   962   shows "sets (Pi\<^isub>P I M) = sigma_sets (space (Pi\<^isub>P I M)) (\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (E i))"
   963 proof -
   964   let ?E = "(\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (E i))"
   965   let ?M = "(\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (M i))"
   966   { fix i A assume "i\<in>I" "A \<in> sets (E i)"
   967     then have "A \<in> sets (M i)" using M by auto
   968     then have "A \<in> Pow (space (M i))" using M.sets_into_space by auto
   969     then have "A \<in> Pow (space (E i))" using M[OF `i \<in> I`] by auto }
   970   moreover
   971   have "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. x i) \<in> space infprod_algebra \<rightarrow> space (E i)"
   972     by (auto simp: M infprod_algebra_def generator_def Pi_iff)
   973   ultimately have "sigma_sets (space (Pi\<^isub>P I M)) ?M \<subseteq> sigma_sets (space (Pi\<^isub>P I M)) ?E"
   974     apply (intro sigma_sets_mono UN_least)
   975     apply (simp add: sets_sigma M)
   976     apply (subst sigma_sets_vimage[symmetric])
   977     apply (auto intro!: sigma_sets_mono')
   978     done
   979   moreover have "sigma_sets (space (Pi\<^isub>P I M)) ?E \<subseteq> sigma_sets (space (Pi\<^isub>P I M)) ?M"
   980     by (intro sigma_sets_mono') (auto simp: M)
   981   ultimately show ?thesis
   982     by (subst infprod_algebra_alt2) (auto simp: sets_sigma)
   983 qed
   984 
   985 lemma (in product_prob_space) Int_proj_eq_emb:
   986   assumes "J \<noteq> {}" "J \<subseteq> I"
   987   shows "(\<Inter>i\<in>J. (\<lambda>x. x i) -` A i \<inter> space (Pi\<^isub>P I M)) = emb I J (Pi\<^isub>E J A)"
   988   using assms by (auto simp: infprod_algebra_def generator_def emb_def Pi_iff)
   989 
   990 lemma (in product_prob_space) emb_insert:
   991   "i \<notin> J \<Longrightarrow> emb I J (Pi\<^isub>E J f) \<inter> ((\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) =
   992     emb I (insert i J) (Pi\<^isub>E (insert i J) (f(i := A)))"
   993   by (auto simp: emb_def Pi_iff infprod_algebra_def generator_def split: split_if_asm)
   994 
   995 subsection {* Sequence space *}
   996 
   997 locale sequence_space = product_prob_space M "UNIV :: nat set" for M
   998 
   999 lemma (in sequence_space) infprod_in_sets[intro]:
  1000   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
  1001   shows "Pi UNIV E \<in> sets (Pi\<^isub>P UNIV M)"
  1002 proof -
  1003   have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^isub>E j\<in>{..i}. E j))"
  1004     using E E[THEN M.sets_into_space]
  1005     by (auto simp: emb_def Pi_iff extensional_def) blast
  1006   with E show ?thesis
  1007     by (auto intro: emb_in_infprod_algebra)
  1008 qed
  1009 
  1010 lemma (in sequence_space) measure_infprod:
  1011   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
  1012   shows "(\<lambda>n. \<Prod>i\<le>n. M.\<mu>' i (E i)) ----> \<mu>' (Pi UNIV E)"
  1013 proof -
  1014   let "?E n" = "emb UNIV {..n} (Pi\<^isub>E {.. n} E)"
  1015   { fix n :: nat
  1016     interpret n: finite_product_prob_space M "{..n}" by default auto
  1017     have "(\<Prod>i\<le>n. M.\<mu>' i (E i)) = n.\<mu>' (Pi\<^isub>E {.. n} E)"
  1018       using E by (subst n.finite_measure_times) auto
  1019     also have "\<dots> = \<mu>' (?E n)"
  1020       using E by (intro finite_measure_infprod_emb[symmetric]) auto
  1021     finally have "(\<Prod>i\<le>n. M.\<mu>' i (E i)) = \<mu>' (?E n)" . }
  1022   moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
  1023     using E E[THEN M.sets_into_space]
  1024     by (auto simp: emb_def extensional_def Pi_iff) blast
  1025   moreover have "range ?E \<subseteq> sets (Pi\<^isub>P UNIV M)"
  1026     using E by auto
  1027   moreover have "decseq ?E"
  1028     by (auto simp: emb_def Pi_iff decseq_def)
  1029   ultimately show ?thesis
  1030     by (simp add: finite_continuity_from_above)
  1031 qed
  1032 
  1033 end