author huffman
Fri Aug 19 14:17:28 2011 -0700 (2011-08-19)
changeset 44311 42c5cbf68052
parent 43920 cedb5cb948fd
child 44928 7ef6505bde7f
permissions -rw-r--r--
Transcendental.thy: add tendsto_intros lemmas;
new isCont theorems;
simplify some proofs.
     1 (*  Title:      HOL/Probability/Infinite_Product_Measure.thy
     2     Author:     Johannes Hölzl, TU München
     3 *)
     5 header {*Infinite Product Measure*}
     7 theory Infinite_Product_Measure
     8   imports Probability_Measure
     9 begin
    11 lemma restrict_extensional_sub[intro]: "A \<subseteq> B \<Longrightarrow> restrict f A \<in> extensional B"
    12   unfolding restrict_def extensional_def by auto
    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)
    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
    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
    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
    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> {}"
    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"
    53 sublocale product_prob_space \<subseteq> M: prob_space "M i" for i
    54   by (rule prob_spaces)
    56 sublocale product_prob_space \<subseteq> product_sigma_finite
    57   by default
    59 sublocale finite_product_prob_space \<subseteq> finite_product_sigma_finite
    60   by default (fact finite_index')
    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
    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
   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)
   126 definition (in product_prob_space)
   127   "emb J K X = (\<lambda>x. restrict x K) -` X \<inter> space (Pi\<^isub>M J M)"
   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)
   133 lemma (in product_prob_space) emb_empty[simp]:
   134   "emb K J {} = {}"
   135   by (simp add: emb_def)
   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+
   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
   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)
   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)
   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)
   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)
   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>"
   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
   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
   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
   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
   226 definition (in product_prob_space)
   227   "\<mu>G A =
   228     (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))"
   230 lemma (in product_prob_space) \<mu>G_spec:
   231   assumes J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
   232   shows "\<mu>G A = measure (Pi\<^isub>M J M) X"
   233   unfolding \<mu>G_def
   234 proof (intro the_equality allI impI ballI)
   235   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)"
   236   have "measure (Pi\<^isub>M K M) Y = measure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) K Y)"
   237     using K J by simp
   238   also have "emb (K \<union> J) K Y = emb (K \<union> J) J X"
   239     using K J by (simp add: emb_injective[of "K \<union> J" I])
   240   also have "measure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) J X) = measure (Pi\<^isub>M J M) X"
   241     using K J by simp
   242   finally show "measure (Pi\<^isub>M J M) X = measure (Pi\<^isub>M K M) Y" ..
   243 qed (insert J, force)
   245 lemma (in product_prob_space) \<mu>G_eq:
   246   "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"
   247   by (intro \<mu>G_spec) auto
   249 lemma (in product_prob_space) generator_Ex:
   250   assumes *: "A \<in> sets generator"
   251   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"
   252 proof -
   253   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)"
   254     unfolding generator_def by auto
   255   with \<mu>G_spec[OF this] show ?thesis by auto
   256 qed
   258 lemma (in product_prob_space) generatorE:
   259   assumes A: "A \<in> sets generator"
   260   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"
   261 proof -
   262   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"
   263     "\<mu>G A = measure (Pi\<^isub>M J M) X" by auto
   264   then show thesis by (intro that) auto
   265 qed
   267 lemma (in product_prob_space) merge_sets:
   268   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)"
   269   shows "merge J x K -` A \<inter> space (Pi\<^isub>M K M) \<in> sets (Pi\<^isub>M K M)"
   270 proof -
   271   interpret J: finite_product_sigma_algebra M J by default fact
   272   interpret K: finite_product_sigma_algebra M K by default fact
   273   interpret JK: pair_sigma_algebra J.P K.P ..
   275   from JK.measurable_cut_fst[OF
   276     measurable_merge[THEN measurable_sets, OF `J \<inter> K = {}`], OF A, of x] x
   277   show ?thesis
   278       by (simp add: space_pair_measure comp_def vimage_compose[symmetric])
   279 qed
   281 lemma (in product_prob_space) merge_emb:
   282   assumes "K \<subseteq> I" "J \<subseteq> I" and y: "y \<in> space (Pi\<^isub>M J M)"
   283   shows "(merge J y (I - J) -` emb I K X \<inter> space (Pi\<^isub>M I M)) =
   284     emb I (K - J) (merge J y (K - J) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M))"
   285 proof -
   286   have [simp]: "\<And>x J K L. merge J y K (restrict x L) = merge J y (K \<inter> L) x"
   287     by (auto simp: restrict_def merge_def)
   288   have [simp]: "\<And>x J K L. restrict (merge J y K x) L = merge (J \<inter> L) y (K \<inter> L) x"
   289     by (auto simp: restrict_def merge_def)
   290   have [simp]: "(I - J) \<inter> K = K - J" using `K \<subseteq> I` `J \<subseteq> I` by auto
   291   have [simp]: "(K - J) \<inter> (K \<union> J) = K - J" by auto
   292   have [simp]: "(K - J) \<inter> K = K - J" by auto
   293   from y `K \<subseteq> I` `J \<subseteq> I` show ?thesis
   294     by (simp split: split_merge add: emb_def Pi_iff extensional_merge_sub set_eq_iff) auto
   295 qed
   297 definition (in product_prob_space) infprod_algebra :: "('i \<Rightarrow> 'a) measure_space" where
   298   "infprod_algebra = sigma generator \<lparr> measure :=
   299     (SOME \<mu>. (\<forall>s\<in>sets generator. \<mu> s = \<mu>G s) \<and>
   300        measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>)\<rparr>"
   302 syntax
   303   "_PiP"  :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3PIP _:_./ _)" 10)
   305 syntax (xsymbols)
   306   "_PiP" :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3\<Pi>\<^isub>P _\<in>_./ _)"   10)
   308 syntax (HTML output)
   309   "_PiP" :: "[pttrn, 'i set, ('b, 'd) measure_space_scheme] => ('i => 'b, 'd) measure_space_scheme"  ("(3\<Pi>\<^isub>P _\<in>_./ _)"   10)
   311 abbreviation
   312   "Pi\<^isub>P I M \<equiv> product_prob_space.infprod_algebra M I"
   314 translations
   315   "PIP x:I. M" == "CONST Pi\<^isub>P I (%x. M)"
   317 sublocale product_prob_space \<subseteq> G!: algebra generator
   318 proof
   319   let ?G = generator
   320   show "sets ?G \<subseteq> Pow (space ?G)"
   321     by (auto simp: generator_def emb_def)
   322   from I_not_empty
   323   obtain i where "i \<in> I" by auto
   324   then show "{} \<in> sets ?G"
   325     by (auto intro!: exI[of _ "{i}"] image_eqI[where x="\<lambda>i. {}"]
   326       simp: product_algebra_def sigma_def sigma_sets.Empty generator_def emb_def)
   327   from `i \<in> I` show "space ?G \<in> sets ?G"
   328     by (auto intro!: exI[of _ "{i}"] image_eqI[where x="Pi\<^isub>E {i} (\<lambda>i. space (M i))"]
   329       simp: generator_def emb_def)
   330   fix A assume "A \<in> sets ?G"
   331   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"
   332     by (auto simp: generator_def)
   333   fix B assume "B \<in> sets ?G"
   334   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"
   335     by (auto simp: generator_def)
   336   let ?RA = "emb (JA \<union> JB) JA XA"
   337   let ?RB = "emb (JA \<union> JB) JB XB"
   338   interpret JAB: finite_product_sigma_algebra M "JA \<union> JB"
   339     by default (insert XA XB, auto)
   340   have *: "A - B = emb I (JA \<union> JB) (?RA - ?RB)" "A \<union> B = emb I (JA \<union> JB) (?RA \<union> ?RB)"
   341     using XA A XB B by (auto simp: emb_simps)
   342   then show "A - B \<in> sets ?G" "A \<union> B \<in> sets ?G"
   343     using XA XB by (auto intro!: generatorI')
   344 qed
   346 lemma (in product_prob_space) positive_\<mu>G: "positive generator \<mu>G"
   347 proof (intro positive_def[THEN iffD2] conjI ballI)
   348   from generatorE[OF G.empty_sets] guess J X . note this[simp]
   349   interpret J: finite_product_sigma_finite M J by default fact
   350   have "X = {}"
   351     by (rule emb_injective[of J I]) simp_all
   352   then show "\<mu>G {} = 0" by simp
   353 next
   354   fix A assume "A \<in> sets generator"
   355   from generatorE[OF this] guess J X . note this[simp]
   356   interpret J: finite_product_sigma_finite M J by default fact
   357   show "0 \<le> \<mu>G A" by simp
   358 qed
   360 lemma (in product_prob_space) additive_\<mu>G: "additive generator \<mu>G"
   361 proof (intro additive_def[THEN iffD2] ballI impI)
   362   fix A assume "A \<in> sets generator" with generatorE guess J X . note J = this
   363   fix B assume "B \<in> sets generator" with generatorE guess K Y . note K = this
   364   assume "A \<inter> B = {}"
   365   have JK: "J \<union> K \<noteq> {}" "J \<union> K \<subseteq> I" "finite (J \<union> K)"
   366     using J K by auto
   367   interpret JK: finite_product_sigma_finite M "J \<union> K" by default fact
   368   have JK_disj: "emb (J \<union> K) J X \<inter> emb (J \<union> K) K Y = {}"
   369     apply (rule emb_injective[of "J \<union> K" I])
   370     apply (insert `A \<inter> B = {}` JK J K)
   371     apply (simp_all add: JK.Int emb_simps)
   372     done
   373   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)"
   374     using J K by simp_all
   375   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))"
   376     by (simp add: emb_simps)
   377   also have "\<dots> = measure (Pi\<^isub>M (J \<union> K) M) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y)"
   378     using JK J(1, 4) K(1, 4) by (simp add: \<mu>G_eq JK.Un)
   379   also have "\<dots> = \<mu>G A + \<mu>G B"
   380     using J K JK_disj by (simp add: JK.measure_additive[symmetric])
   381   finally show "\<mu>G (A \<union> B) = \<mu>G A + \<mu>G B" .
   382 qed
   384 lemma (in product_prob_space) finite_index_eq_finite_product:
   385   assumes "finite I"
   386   shows "sets (sigma generator) = sets (Pi\<^isub>M I M)"
   387 proof safe
   388   interpret I: finite_product_sigma_algebra M I by default fact
   389   have [simp]: "space generator = space (Pi\<^isub>M I M)"
   390     by (simp add: generator_def product_algebra_def)
   391   { fix A assume "A \<in> sets (sigma generator)"
   392     then show "A \<in> sets I.P" unfolding sets_sigma
   393     proof induct
   394       case (Basic A)
   395       from generatorE[OF this] guess J X . note J = this
   396       with `finite I` have "emb I J X \<in> sets I.P" by auto
   397       with `emb I J X = A` show "A \<in> sets I.P" by simp
   398     qed auto }
   399   { fix A assume "A \<in> sets I.P"
   400     moreover with I.sets_into_space have "emb I I A = A" by (intro emb_id) auto
   401     ultimately show "A \<in> sets (sigma generator)"
   402       using `finite I` I_not_empty unfolding sets_sigma
   403       by (intro sigma_sets.Basic generatorI[of I A]) auto }
   404 qed
   406 lemma (in product_prob_space) extend_\<mu>G:
   407   "\<exists>\<mu>. (\<forall>s\<in>sets generator. \<mu> s = \<mu>G s) \<and>
   408        measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>"
   409 proof cases
   410   assume "finite I"
   411   interpret I: finite_product_sigma_finite M I by default fact
   412   show ?thesis
   413   proof (intro exI[of _ "measure (Pi\<^isub>M I M)"] ballI conjI)
   414     fix A assume "A \<in> sets generator"
   415     from generatorE[OF this] guess J X . note J = this
   416     from J(1-4) `finite I` show "measure I.P A = \<mu>G A"
   417       unfolding J(6)
   418       by (subst J(5)[symmetric]) (simp add: measure_emb)
   419   next
   420     have [simp]: "space generator = space (Pi\<^isub>M I M)"
   421       by (simp add: generator_def product_algebra_def)
   422     have "\<lparr>space = space generator, sets = sets (sigma generator), measure = measure I.P\<rparr>
   423       = I.P" (is "?P = _")
   424       by (auto intro!: measure_space.equality simp: finite_index_eq_finite_product[OF `finite I`])
   425     then show "measure_space ?P" by simp default
   426   qed
   427 next
   428   let ?G = generator
   429   assume "\<not> finite I"
   430   note \<mu>G_mono =
   431     G.additive_increasing[OF positive_\<mu>G additive_\<mu>G, THEN increasingD]
   433   { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> sets ?G"
   435     from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
   436       by (metis rev_finite_subset subsetI)
   437     moreover from Z guess K' X' by (rule generatorE)
   438     moreover def K \<equiv> "insert k K'"
   439     moreover def X \<equiv> "emb K K' X'"
   440     ultimately have K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "X \<in> sets (Pi\<^isub>M K M)" "Z = emb I K X"
   441       "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = measure (Pi\<^isub>M K M) X"
   442       by (auto simp: subset_insertI)
   444     let "?M y" = "merge J y (K - J) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M)"
   445     { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
   446       note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
   447       moreover
   448       have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
   449         using J K y by (intro merge_sets) auto
   450       ultimately
   451       have ***: "(merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> sets ?G"
   452         using J K by (intro generatorI) auto
   453       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)"
   454         unfolding * using K J by (subst \<mu>G_eq[OF _ _ _ **]) auto
   455       note * ** *** this }
   456     note merge_in_G = this
   458     have "finite (K - J)" using K by auto
   460     interpret J: finite_product_prob_space M J by default fact+
   461     interpret KmJ: finite_product_prob_space M "K - J" by default fact+
   463     have "\<mu>G Z = measure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
   464       using K J by simp
   465     also have "\<dots> = (\<integral>\<^isup>+ x. measure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
   466       using K J by (subst measure_fold_integral) auto
   467     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)"
   468       (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
   469     proof (intro J.positive_integral_cong)
   470       fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   471       with K merge_in_G(2)[OF this]
   472       show "measure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
   473         unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst \<mu>G_eq) auto
   474     qed
   475     finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
   477     { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
   478       then have "\<mu>G (?MZ x) \<le> 1"
   479         unfolding merge_in_G(4)[OF x] `Z = emb I K X`
   480         by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
   481     note le_1 = this
   483     let "?q y" = "\<mu>G (merge J y (I - J) -` Z \<inter> space (Pi\<^isub>M I M))"
   484     have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
   485       unfolding `Z = emb I K X` using J K merge_in_G(3)
   486       by (simp add: merge_in_G  \<mu>G_eq measure_fold_measurable
   487                del: space_product_algebra cong: measurable_cong)
   488     note this fold le_1 merge_in_G(3) }
   489   note fold = this
   491   show ?thesis
   492   proof (rule G.caratheodory_empty_continuous[OF positive_\<mu>G additive_\<mu>G])
   493     fix A assume "A \<in> sets ?G"
   494     with generatorE guess J X . note JX = this
   495     interpret JK: finite_product_prob_space M J by default fact+
   496     with JX show "\<mu>G A \<noteq> \<infinity>" by simp
   497   next
   498     fix A assume A: "range A \<subseteq> sets ?G" "decseq A" "(\<Inter>i. A i) = {}"
   499     then have "decseq (\<lambda>i. \<mu>G (A i))"
   500       by (auto intro!: \<mu>G_mono simp: decseq_def)
   501     moreover
   502     have "(INF i. \<mu>G (A i)) = 0"
   503     proof (rule ccontr)
   504       assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
   505       moreover have "0 \<le> ?a"
   506         using A positive_\<mu>G by (auto intro!: le_INFI simp: positive_def)
   507       ultimately have "0 < ?a" by auto
   509       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"
   510         using A by (intro allI generator_Ex) auto
   511       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)"
   512         and A': "\<And>n. A n = emb I (J' n) (X' n)"
   513         unfolding choice_iff by blast
   514       moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
   515       moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
   516       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)"
   517         by auto
   518       with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> sets ?G"
   519         unfolding J_def X_def by (subst emb_trans) (insert A, auto)
   521       have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
   522         unfolding J_def by force
   524       interpret J: finite_product_prob_space M "J i" for i by default fact+
   526       have a_le_1: "?a \<le> 1"
   527         using \<mu>G_spec[of "J 0" "A 0" "X 0"] J A_eq
   528         by (auto intro!: INF_leI2[of 0] J.measure_le_1)
   530       let "?M K Z y" = "merge K y (I - K) -` Z \<inter> space (Pi\<^isub>M I M)"
   532       { fix Z k assume Z: "range Z \<subseteq> sets ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
   533         then have Z_sets: "\<And>n. Z n \<in> sets ?G" by auto
   534         fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
   535         interpret J': finite_product_prob_space M J' by default fact+
   537         let "?q n y" = "\<mu>G (?M J' (Z n) y)"
   538         let "?Q n" = "?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
   539         { fix n
   540           have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
   541             using Z J' by (intro fold(1)) auto
   542           then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
   543             by (rule measurable_sets) auto }
   544         note Q_sets = this
   546         have "?a / 2^(k+1) \<le> (INF n. measure (Pi\<^isub>M J' M) (?Q n))"
   547         proof (intro le_INFI)
   548           fix n
   549           have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
   550           also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
   551             unfolding fold(2)[OF J' `Z n \<in> sets ?G`]
   552           proof (intro J'.positive_integral_mono)
   553             fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   554             then have "?q n x \<le> 1 + 0"
   555               using J' Z fold(3) Z_sets by auto
   556             also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
   557               using `0 < ?a` by (intro add_mono) auto
   558             finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
   559             with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
   560               by (auto split: split_indicator simp del: power_Suc)
   561           qed
   562           also have "\<dots> = measure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
   563             using `0 \<le> ?a` Q_sets J'.measure_space_1
   564             by (subst J'.positive_integral_add) auto
   565           finally show "?a / 2^(k+1) \<le> measure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
   566             by (cases rule: ereal2_cases[of ?a "measure (Pi\<^isub>M J' M) (?Q n)"])
   567                (auto simp: field_simps)
   568         qed
   569         also have "\<dots> = measure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
   570         proof (intro J'.continuity_from_above)
   571           show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
   572           show "decseq ?Q"
   573             unfolding decseq_def
   574           proof (safe intro!: vimageI[OF refl])
   575             fix m n :: nat assume "m \<le> n"
   576             fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
   577             assume "?a / 2^(k+1) \<le> ?q n x"
   578             also have "?q n x \<le> ?q m x"
   579             proof (rule \<mu>G_mono)
   580               from fold(4)[OF J', OF Z_sets x]
   581               show "?M J' (Z n) x \<in> sets ?G" "?M J' (Z m) x \<in> sets ?G" by auto
   582               show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
   583                 using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
   584             qed
   585             finally show "?a / 2^(k+1) \<le> ?q m x" .
   586           qed
   587         qed (intro J'.finite_measure Q_sets)
   588         finally have "(\<Inter>n. ?Q n) \<noteq> {}"
   589           using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   590         then have "\<exists>w\<in>space (Pi\<^isub>M J' M). \<forall>n. ?a / 2 ^ (k + 1) \<le> ?q n w" by auto }
   591       note Ex_w = this
   593       let "?q k n y" = "\<mu>G (?M (J k) (A n) y)"
   595       have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_leI)
   596       from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
   598       let "?P k wk w" =
   599         "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)"
   600       def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
   602       { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
   603           (\<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))"
   604         proof (induct k)
   605           case 0 with w0 show ?case
   606             unfolding w_def nat_rec_0 by auto
   607         next
   608           case (Suc k)
   609           then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   610           have "\<exists>w'. ?P k (w k) w'"
   611           proof cases
   612             assume [simp]: "J k = J (Suc k)"
   613             show ?thesis
   614             proof (intro exI[of _ "w k"] conjI allI)
   615               fix n
   616               have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
   617                 using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
   618               also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
   619               finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
   620             next
   621               show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
   622                 using Suc by simp
   623               then show "restrict (w k) (J k) = w k"
   624                 by (simp add: extensional_restrict)
   625             qed
   626           next
   627             assume "J k \<noteq> J (Suc k)"
   628             with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
   629             have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> sets ?G"
   630               "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
   631               "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
   632               using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
   633               by (auto simp: decseq_def)
   634             from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
   635             obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
   636               "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
   637             let ?w = "merge (J k) (w k) ?D w'"
   638             have [simp]: "\<And>x. merge (J k) (w k) (I - J k) (merge ?D w' (I - ?D) x) =
   639               merge (J (Suc k)) ?w (I - (J (Suc k))) x"
   640               using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
   641               by (auto intro!: ext split: split_merge)
   642             have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
   643               using w'(1) J(3)[of "Suc k"]
   644               by (auto split: split_merge intro!: extensional_merge_sub) force+
   645             show ?thesis
   646               apply (rule exI[of _ ?w])
   647               using w' J_mono[of k "Suc k"] wk unfolding *
   648               apply (auto split: split_merge intro!: extensional_merge_sub ext)
   649               apply (force simp: extensional_def)
   650               done
   651           qed
   652           then have "?P k (w k) (w (Suc k))"
   653             unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
   654             by (rule someI_ex)
   655           then show ?case by auto
   656         qed
   657         moreover
   658         then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
   659         moreover
   660         from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
   661         then have "?M (J k) (A k) (w k) \<noteq> {}"
   662           using positive_\<mu>G[unfolded positive_def] `0 < ?a` `?a \<le> 1`
   663           by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
   664         then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
   665         then have "merge (J k) (w k) (I - J k) x \<in> A k" by auto
   666         then have "\<exists>x\<in>A k. restrict x (J k) = w k"
   667           using `w k \<in> space (Pi\<^isub>M (J k) M)`
   668           by (intro rev_bexI) (auto intro!: ext simp: extensional_def)
   669         ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
   670           "\<exists>x\<in>A k. restrict x (J k) = w k"
   671           "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
   672           by auto }
   673       note w = this
   675       { fix k l i assume "k \<le> l" "i \<in> J k"
   676         { fix l have "w k i = w (k + l) i"
   677           proof (induct l)
   678             case (Suc l)
   679             from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
   680             with w(3)[of "k + Suc l"]
   681             have "w (k + l) i = w (k + Suc l) i"
   682               by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
   683             with Suc show ?case by simp
   684           qed simp }
   685         from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
   686       note w_mono = this
   688       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"
   689       { fix i k assume k: "i \<in> J k"
   690         have "w k i = w (LEAST k. i \<in> J k) i"
   691           by (intro w_mono Least_le k LeastI[of _ k])
   692         then have "w' i = w k i"
   693           unfolding w'_def using k by auto }
   694       note w'_eq = this
   695       have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
   696         using J by (auto simp: w'_def)
   697       have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
   698         using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
   699       { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
   700           using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq)+ }
   701       note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
   703       have w': "w' \<in> space (Pi\<^isub>M I M)"
   704         using w(1) by (auto simp add: Pi_iff extensional_def)
   706       { fix n
   707         have "restrict w' (J n) = w n" using w(1)
   708           by (auto simp add: fun_eq_iff restrict_def Pi_iff extensional_def)
   709         with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
   710         then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: emb_def) }
   711       then have "w' \<in> (\<Inter>i. A i)" by auto
   712       with `(\<Inter>i. A i) = {}` show False by auto
   713     qed
   714     ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
   715       using LIMSEQ_ereal_INFI[of "\<lambda>i. \<mu>G (A i)"] by simp
   716   qed
   717 qed
   719 lemma (in product_prob_space) infprod_spec:
   720   shows "(\<forall>s\<in>sets generator. measure (Pi\<^isub>P I M) s = \<mu>G s) \<and> measure_space (Pi\<^isub>P I M)"
   721 proof -
   722   let ?P = "\<lambda>\<mu>. (\<forall>A\<in>sets generator. \<mu> A = \<mu>G A) \<and>
   723        measure_space \<lparr>space = space generator, sets = sets (sigma generator), measure = \<mu>\<rparr>"
   724   have **: "measure infprod_algebra = (SOME \<mu>. ?P \<mu>)"
   725     unfolding infprod_algebra_def by simp
   726   have *: "Pi\<^isub>P I M = \<lparr>space = space generator, sets = sets (sigma generator), measure = measure (Pi\<^isub>P I M)\<rparr>"
   727     unfolding infprod_algebra_def by auto
   728   show ?thesis
   729     apply (subst (2) *)
   730     apply (unfold **)
   731     apply (rule someI_ex[where P="?P"])
   732     apply (rule extend_\<mu>G)
   733     done
   734 qed
   736 sublocale product_prob_space \<subseteq> P: measure_space "Pi\<^isub>P I M"
   737   using infprod_spec by auto
   739 lemma (in product_prob_space) measure_infprod_emb:
   740   assumes "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)"
   741   shows "\<mu> (emb I J X) = measure (Pi\<^isub>M J M) X"
   742 proof -
   743   have "emb I J X \<in> sets generator"
   744     using assms by (rule generatorI')
   745   with \<mu>G_eq[OF assms] infprod_spec show ?thesis by auto
   746 qed
   748 sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^isub>P I M"
   749 proof
   750   obtain i where "i \<in> I" using I_not_empty by auto
   751   interpret i: finite_product_sigma_finite M "{i}" by default auto
   752   let ?X = "\<Pi>\<^isub>E i\<in>{i}. space (M i)"
   753   have "?X \<in> sets (Pi\<^isub>M {i} M)"
   754     by auto
   755   from measure_infprod_emb[OF _ _ _ this] `i \<in> I`
   756   have "\<mu> (emb I {i} ?X) = measure (M i) (space (M i))"
   757     by (simp add: i.measure_times)
   758   also have "emb I {i} ?X = space (Pi\<^isub>P I M)"
   759     using `i \<in> I` by (auto simp: emb_def infprod_algebra_def generator_def)
   760   finally show "\<mu> (space (Pi\<^isub>P I M)) = 1"
   761     using M.measure_space_1 by simp
   762 qed
   764 lemma (in product_prob_space) measurable_component:
   765   assumes "i \<in> I"
   766   shows "(\<lambda>x. x i) \<in> measurable (Pi\<^isub>P I M) (M i)"
   767 proof (unfold measurable_def, safe)
   768   fix x assume "x \<in> space (Pi\<^isub>P I M)"
   769   then show "x i \<in> space (M i)"
   770     using `i \<in> I` by (auto simp: infprod_algebra_def generator_def)
   771 next
   772   fix A assume "A \<in> sets (M i)"
   773   with `i \<in> I` have
   774     "(\<Pi>\<^isub>E x \<in> {i}. A) \<in> sets (Pi\<^isub>M {i} M)"
   775     "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) = emb I {i} (\<Pi>\<^isub>E x \<in> {i}. A)"
   776     by (auto simp: infprod_algebra_def generator_def emb_def)
   777   from generatorI[OF _ _ _ this] `i \<in> I`
   778   show "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) \<in> sets (Pi\<^isub>P I M)"
   779     unfolding infprod_algebra_def by auto
   780 qed
   782 lemma (in product_prob_space) emb_in_infprod_algebra[intro]:
   783   fixes J assumes J: "finite J" "J \<subseteq> I" and X: "X \<in> sets (Pi\<^isub>M J M)"
   784   shows "emb I J X \<in> sets (\<Pi>\<^isub>P i\<in>I. M i)"
   785 proof cases
   786   assume "J = {}"
   787   with X have "emb I J X = space (\<Pi>\<^isub>P i\<in>I. M i) \<or> emb I J X = {}"
   788     by (auto simp: emb_def infprod_algebra_def generator_def
   789                    product_algebra_def product_algebra_generator_def image_constant sigma_def)
   790   then show ?thesis by auto
   791 next
   792   assume "J \<noteq> {}"
   793   show ?thesis unfolding infprod_algebra_def
   794     by simp (intro in_sigma generatorI'  `J \<noteq> {}` J X)
   795 qed
   797 lemma (in product_prob_space) finite_measure_infprod_emb:
   798   assumes "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)"
   799   shows "\<mu>' (emb I J X) = finite_measure.\<mu>' (Pi\<^isub>M J M) X"
   800 proof -
   801   interpret J: finite_product_prob_space M J by default fact+
   802   from assms have "emb I J X \<in> sets (Pi\<^isub>P I M)" by auto
   803   with assms show "\<mu>' (emb I J X) = J.\<mu>' X"
   804     unfolding \<mu>'_def J.\<mu>'_def
   805     unfolding measure_infprod_emb[OF assms]
   806     by auto
   807 qed
   809 lemma (in finite_product_prob_space) finite_measure_times:
   810   assumes "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)"
   811   shows "\<mu>' (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu>' i (A i))"
   812   using assms
   813   unfolding \<mu>'_def M.\<mu>'_def
   814   by (subst measure_times[OF assms])
   815      (auto simp: finite_measure_eq M.finite_measure_eq setprod_ereal)
   817 lemma (in product_prob_space) finite_measure_infprod_emb_Pi:
   818   assumes J: "finite J" "J \<subseteq> I" "\<And>j. j \<in> J \<Longrightarrow> X j \<in> sets (M j)"
   819   shows "\<mu>' (emb I J (Pi\<^isub>E J X)) = (\<Prod>j\<in>J. M.\<mu>' j (X j))"
   820 proof cases
   821   assume "J = {}"
   822   then have "emb I J (Pi\<^isub>E J X) = space infprod_algebra"
   823     by (auto simp: infprod_algebra_def generator_def sigma_def emb_def)
   824   then show ?thesis using `J = {}` prob_space by simp
   825 next
   826   assume "J \<noteq> {}"
   827   interpret J: finite_product_prob_space M J by default fact+
   828   have "(\<Prod>i\<in>J. M.\<mu>' i (X i)) = J.\<mu>' (Pi\<^isub>E J X)"
   829     using J `J \<noteq> {}` by (subst J.finite_measure_times) auto
   830   also have "\<dots> = \<mu>' (emb I J (Pi\<^isub>E J X))"
   831     using J `J \<noteq> {}` by (intro finite_measure_infprod_emb[symmetric]) auto
   832   finally show ?thesis by simp
   833 qed
   835 lemma sigma_sets_mono: assumes "A \<subseteq> sigma_sets X B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
   836 proof
   837   fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
   838     by induct (insert `A \<subseteq> sigma_sets X B`, auto intro: sigma_sets.intros)
   839 qed
   841 lemma sigma_sets_mono': assumes "A \<subseteq> B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
   842 proof
   843   fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
   844     by induct (insert `A \<subseteq> B`, auto intro: sigma_sets.intros)
   845 qed
   847 lemma sigma_sets_superset_generator: "A \<subseteq> sigma_sets X A"
   848   by (auto intro: sigma_sets.Basic)
   850 lemma (in product_prob_space) infprod_algebra_alt:
   851   "Pi\<^isub>P I M = sigma \<lparr> space = space (Pi\<^isub>P I M),
   852     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))),
   853     measure = measure (Pi\<^isub>P I M) \<rparr>"
   854   (is "_ = sigma \<lparr> space = ?O, sets = ?M, measure = ?m \<rparr>")
   855 proof (rule measure_space.equality)
   856   let ?G = "\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` sets (Pi\<^isub>M J M)"
   857   have "sigma_sets ?O ?M = sigma_sets ?O ?G"
   858   proof (intro equalityI sigma_sets_mono UN_least)
   859     fix J assume J: "J \<in> {J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}"
   860     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
   861     also have "\<dots> \<subseteq> ?G" using J by (rule UN_upper)
   862     also have "\<dots> \<subseteq> sigma_sets ?O ?G" by (rule sigma_sets_superset_generator)
   863     finally show "emb I J ` Pi\<^isub>E J ` (\<Pi> i\<in>J. sets (M i)) \<subseteq> sigma_sets ?O ?G" .
   864     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)))"
   865       by (simp add: sets_sigma product_algebra_generator_def product_algebra_def)
   866     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)))"
   867       using J M.sets_into_space
   868       by (auto simp: emb_def_raw intro!: sigma_sets_vimage[symmetric]) blast
   869     also have "\<dots> \<subseteq> sigma_sets (space (Pi\<^isub>M I M)) ?M"
   870       using J by (intro sigma_sets_mono') auto
   871     finally show "emb I J ` sets (Pi\<^isub>M J M) \<subseteq> sigma_sets ?O ?M"
   872       by (simp add: infprod_algebra_def generator_def)
   873   qed
   874   then show "sets (Pi\<^isub>P I M) = sets (sigma \<lparr> space = ?O, sets = ?M, measure = ?m \<rparr>)"
   875     by (simp_all add: infprod_algebra_def generator_def sets_sigma)
   876 qed simp_all
   878 lemma (in product_prob_space) infprod_algebra_alt2:
   879   "Pi\<^isub>P I M = sigma \<lparr> space = space (Pi\<^isub>P I M),
   880     sets = (\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (M i)),
   881     measure = measure (Pi\<^isub>P I M) \<rparr>"
   882   (is "_ = ?S")
   883 proof (rule measure_space.equality)
   884   let "sigma \<lparr> space = ?O, sets = ?A, \<dots> = _ \<rparr>" = ?S
   885   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)))"
   886   have "sets (Pi\<^isub>P I M) = sigma_sets ?O ?G"
   887     by (subst infprod_algebra_alt) (simp add: sets_sigma)
   888   also have "\<dots> = sigma_sets ?O ?A"
   889   proof (intro equalityI sigma_sets_mono subsetI)
   890     interpret A: sigma_algebra ?S
   891       by (rule sigma_algebra_sigma) auto
   892     fix A assume "A \<in> ?G"
   893     then obtain J B where "finite J" "J \<noteq> {}" "J \<subseteq> I" "A = emb I J (Pi\<^isub>E J B)"
   894         and B: "\<And>i. i \<in> J \<Longrightarrow> B i \<in> sets (M i)"
   895       by auto
   896     then have A: "A = (\<Inter>j\<in>J. (\<lambda>x. x j) -` (B j) \<inter> space (Pi\<^isub>P I M))"
   897       by (auto simp: emb_def infprod_algebra_def generator_def Pi_iff)
   898     { fix j assume "j\<in>J"
   899       with `J \<subseteq> I` have "j \<in> I" by auto
   900       with `j \<in> J` B have "(\<lambda>x. x j) -` (B j) \<inter> space (Pi\<^isub>P I M) \<in> sets ?S"
   901         by (auto simp: sets_sigma intro: sigma_sets.Basic) }
   902     with `finite J` `J \<noteq> {}` have "A \<in> sets ?S"
   903       unfolding A by (intro A.finite_INT) auto
   904     then show "A \<in> sigma_sets ?O ?A" by (simp add: sets_sigma)
   905   next
   906     fix A assume "A \<in> ?A"
   907     then obtain i B where i: "i \<in> I" "B \<in> sets (M i)"
   908         and "A = (\<lambda>x. x i) -` B \<inter> space (Pi\<^isub>P I M)"
   909       by auto
   910     then have "A = emb I {i} (Pi\<^isub>E {i} (\<lambda>_. B))"
   911       by (auto simp: emb_def infprod_algebra_def generator_def Pi_iff)
   912     with i show "A \<in> sigma_sets ?O ?G"
   913       by (intro sigma_sets.Basic UN_I[where a="{i}"]) auto
   914   qed
   915   also have "\<dots> = sets ?S"
   916     by (simp add: sets_sigma)
   917   finally show "sets (Pi\<^isub>P I M) = sets ?S" .
   918 qed simp_all
   920 lemma (in product_prob_space) measurable_into_infprod_algebra:
   921   assumes "sigma_algebra N"
   922   assumes f: "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. f x i) \<in> measurable N (M i)"
   923   assumes ext: "\<And>x. x \<in> space N \<Longrightarrow> f x \<in> extensional I"
   924   shows "f \<in> measurable N (Pi\<^isub>P I M)"
   925 proof -
   926   interpret N: sigma_algebra N by fact
   927   have f_in: "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. f x i) \<in> space N \<rightarrow> space (M i)"
   928     using f by (auto simp: measurable_def)
   929   { fix i A assume i: "i \<in> I" "A \<in> sets (M i)"
   930     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"
   931       using f_in ext by (auto simp: infprod_algebra_def generator_def)
   932     also have "\<dots> \<in> sets N"
   933       by (rule measurable_sets f i)+
   934     finally have "f -` (\<lambda>x. x i) -` A \<inter> f -` space infprod_algebra \<inter> space N \<in> sets N" . }
   935   with f_in ext show ?thesis
   936     by (subst infprod_algebra_alt2)
   937        (auto intro!: N.measurable_sigma simp: Pi_iff infprod_algebra_def generator_def)
   938 qed
   940 lemma (in product_prob_space) measurable_singleton_infprod:
   941   assumes "i \<in> I"
   942   shows "(\<lambda>x. x i) \<in> measurable (Pi\<^isub>P I M) (M i)"
   943 proof (unfold measurable_def, intro CollectI conjI ballI)
   944   show "(\<lambda>x. x i) \<in> space (Pi\<^isub>P I M) \<rightarrow> space (M i)"
   945     using M.sets_into_space `i \<in> I`
   946     by (auto simp: infprod_algebra_def generator_def)
   947   fix A assume "A \<in> sets (M i)"
   948   have "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) = emb I {i} (\<Pi>\<^isub>E _\<in>{i}. A)"
   949     by (auto simp: infprod_algebra_def generator_def emb_def)
   950   also have "\<dots> \<in> sets (Pi\<^isub>P I M)"
   951     using `i \<in> I` `A \<in> sets (M i)`
   952     by (intro emb_in_infprod_algebra product_algebraI) auto
   953   finally show "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M) \<in> sets (Pi\<^isub>P I M)" .
   954 qed
   956 lemma (in product_prob_space) sigma_product_algebra_sigma_eq:
   957   assumes M: "\<And>i. i \<in> I \<Longrightarrow> M i = sigma (E i)"
   958   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))"
   959 proof -
   960   let ?E = "(\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (E i))"
   961   let ?M = "(\<Union>i\<in>I. (\<lambda>A. (\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>P I M)) ` sets (M i))"
   962   { fix i A assume "i\<in>I" "A \<in> sets (E i)"
   963     then have "A \<in> sets (M i)" using M by auto
   964     then have "A \<in> Pow (space (M i))" using M.sets_into_space by auto
   965     then have "A \<in> Pow (space (E i))" using M[OF `i \<in> I`] by auto }
   966   moreover
   967   have "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. x i) \<in> space infprod_algebra \<rightarrow> space (E i)"
   968     by (auto simp: M infprod_algebra_def generator_def Pi_iff)
   969   ultimately have "sigma_sets (space (Pi\<^isub>P I M)) ?M \<subseteq> sigma_sets (space (Pi\<^isub>P I M)) ?E"
   970     apply (intro sigma_sets_mono UN_least)
   971     apply (simp add: sets_sigma M)
   972     apply (subst sigma_sets_vimage[symmetric])
   973     apply (auto intro!: sigma_sets_mono')
   974     done
   975   moreover have "sigma_sets (space (Pi\<^isub>P I M)) ?E \<subseteq> sigma_sets (space (Pi\<^isub>P I M)) ?M"
   976     by (intro sigma_sets_mono') (auto simp: M)
   977   ultimately show ?thesis
   978     by (subst infprod_algebra_alt2) (auto simp: sets_sigma)
   979 qed
   981 lemma (in product_prob_space) Int_proj_eq_emb:
   982   assumes "J \<noteq> {}" "J \<subseteq> I"
   983   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)"
   984   using assms by (auto simp: infprod_algebra_def generator_def emb_def Pi_iff)
   986 lemma (in product_prob_space) emb_insert:
   987   "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)) =
   988     emb I (insert i J) (Pi\<^isub>E (insert i J) (f(i := A)))"
   989   by (auto simp: emb_def Pi_iff infprod_algebra_def generator_def split: split_if_asm)
   991 subsection {* Sequence space *}
   993 locale sequence_space = product_prob_space M "UNIV :: nat set" for M
   995 lemma (in sequence_space) infprod_in_sets[intro]:
   996   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
   997   shows "Pi UNIV E \<in> sets (Pi\<^isub>P UNIV M)"
   998 proof -
   999   have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^isub>E j\<in>{..i}. E j))"
  1000     using E E[THEN M.sets_into_space]
  1001     by (auto simp: emb_def Pi_iff extensional_def) blast
  1002   with E show ?thesis
  1003     by (auto intro: emb_in_infprod_algebra)
  1004 qed
  1006 lemma (in sequence_space) measure_infprod:
  1007   fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
  1008   shows "(\<lambda>n. \<Prod>i\<le>n. M.\<mu>' i (E i)) ----> \<mu>' (Pi UNIV E)"
  1009 proof -
  1010   let "?E n" = "emb UNIV {..n} (Pi\<^isub>E {.. n} E)"
  1011   { fix n :: nat
  1012     interpret n: finite_product_prob_space M "{..n}" by default auto
  1013     have "(\<Prod>i\<le>n. M.\<mu>' i (E i)) = n.\<mu>' (Pi\<^isub>E {.. n} E)"
  1014       using E by (subst n.finite_measure_times) auto
  1015     also have "\<dots> = \<mu>' (?E n)"
  1016       using E by (intro finite_measure_infprod_emb[symmetric]) auto
  1017     finally have "(\<Prod>i\<le>n. M.\<mu>' i (E i)) = \<mu>' (?E n)" . }
  1018   moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
  1019     using E E[THEN M.sets_into_space]
  1020     by (auto simp: emb_def extensional_def Pi_iff) blast
  1021   moreover have "range ?E \<subseteq> sets (Pi\<^isub>P UNIV M)"
  1022     using E by auto
  1023   moreover have "decseq ?E"
  1024     by (auto simp: emb_def Pi_iff decseq_def)
  1025   ultimately show ?thesis
  1026     by (simp add: finite_continuity_from_above)
  1027 qed
  1029 end