src/HOL/Probability/Finite_Product_Measure.thy
changeset 62975 1d066f6ab25d
parent 62390 842917225d56
child 63040 eb4ddd18d635
equal deleted inserted replaced
62974:f17602cbf76a 62975:1d066f6ab25d
   114 subsubsection \<open>Products\<close>
   114 subsubsection \<open>Products\<close>
   115 
   115 
   116 definition prod_emb where
   116 definition prod_emb where
   117   "prod_emb I M K X = (\<lambda>x. restrict x K) -` X \<inter> (PIE i:I. space (M i))"
   117   "prod_emb I M K X = (\<lambda>x. restrict x K) -` X \<inter> (PIE i:I. space (M i))"
   118 
   118 
   119 lemma prod_emb_iff: 
   119 lemma prod_emb_iff:
   120   "f \<in> prod_emb I M K X \<longleftrightarrow> f \<in> extensional I \<and> (restrict f K \<in> X) \<and> (\<forall>i\<in>I. f i \<in> space (M i))"
   120   "f \<in> prod_emb I M K X \<longleftrightarrow> f \<in> extensional I \<and> (restrict f K \<in> X) \<and> (\<forall>i\<in>I. f i \<in> space (M i))"
   121   unfolding prod_emb_def PiE_def by auto
   121   unfolding prod_emb_def PiE_def by auto
   122 
   122 
   123 lemma
   123 lemma
   124   shows prod_emb_empty[simp]: "prod_emb M L K {} = {}"
   124   shows prod_emb_empty[simp]: "prod_emb M L K {} = {}"
   178   shows "extend_measure \<Omega> I G \<mu> = extend_measure \<Omega>' I' G' \<mu>'"
   178   shows "extend_measure \<Omega> I G \<mu> = extend_measure \<Omega>' I' G' \<mu>'"
   179   unfolding extend_measure_def by (auto simp add: assms)
   179   unfolding extend_measure_def by (auto simp add: assms)
   180 
   180 
   181 lemma Pi_cong_sets:
   181 lemma Pi_cong_sets:
   182     "\<lbrakk>I = J; \<And>x. x \<in> I \<Longrightarrow> M x = N x\<rbrakk> \<Longrightarrow> Pi I M = Pi J N"
   182     "\<lbrakk>I = J; \<And>x. x \<in> I \<Longrightarrow> M x = N x\<rbrakk> \<Longrightarrow> Pi I M = Pi J N"
   183   unfolding Pi_def by auto 
   183   unfolding Pi_def by auto
   184 
   184 
   185 lemma PiM_cong:
   185 lemma PiM_cong:
   186   assumes "I = J" "\<And>x. x \<in> I \<Longrightarrow> M x = N x"
   186   assumes "I = J" "\<And>x. x \<in> I \<Longrightarrow> M x = N x"
   187   shows "PiM I M = PiM J N"
   187   shows "PiM I M = PiM J N"
   188   unfolding PiM_def
   188   unfolding PiM_def
   195   have "\<And>K. K \<subseteq> J \<Longrightarrow> (\<Pi> j\<in>K. sets (M j)) = (\<Pi> j\<in>K. sets (N j))"
   195   have "\<And>K. K \<subseteq> J \<Longrightarrow> (\<Pi> j\<in>K. sets (M j)) = (\<Pi> j\<in>K. sets (N j))"
   196     using assms by (intro Pi_cong_sets) auto
   196     using assms by (intro Pi_cong_sets) auto
   197   thus ?case by (auto simp: assms)
   197   thus ?case by (auto simp: assms)
   198 next
   198 next
   199   case 3
   199   case 3
   200   show ?case using assms 
   200   show ?case using assms
   201     by (intro ext) (auto simp: prod_emb_def dest: PiE_mem)
   201     by (intro ext) (auto simp: prod_emb_def dest: PiE_mem)
   202 next
   202 next
   203   case (4 x)
   203   case (4 x)
   204   thus ?case using assms 
   204   thus ?case using assms
   205     by (auto intro!: setprod.cong split: if_split_asm)
   205     by (auto intro!: setprod.cong split: if_split_asm)
   206 qed
   206 qed
   207 
   207 
   208 
   208 
   209 lemma prod_algebra_sets_into_space:
   209 lemma prod_algebra_sets_into_space:
   249 qed
   249 qed
   250 
   250 
   251 lemma prod_algebraE:
   251 lemma prod_algebraE:
   252   assumes A: "A \<in> prod_algebra I M"
   252   assumes A: "A \<in> prod_algebra I M"
   253   obtains J E where "A = prod_emb I M J (PIE j:J. E j)"
   253   obtains J E where "A = prod_emb I M J (PIE j:J. E j)"
   254     "finite J" "J \<noteq> {} \<or> I = {}" "J \<subseteq> I" "\<And>i. i \<in> J \<Longrightarrow> E i \<in> sets (M i)" 
   254     "finite J" "J \<noteq> {} \<or> I = {}" "J \<subseteq> I" "\<And>i. i \<in> J \<Longrightarrow> E i \<in> sets (M i)"
   255   using A by (auto simp: prod_algebra_def)
   255   using A by (auto simp: prod_algebra_def)
   256 
   256 
   257 lemma prod_algebraE_all:
   257 lemma prod_algebraE_all:
   258   assumes A: "A \<in> prod_algebra I M"
   258   assumes A: "A \<in> prod_algebra I M"
   259   obtains E where "A = Pi\<^sub>E I E" "E \<in> (\<Pi> i\<in>I. sets (M i))"
   259   obtains E where "A = Pi\<^sub>E I E" "E \<in> (\<Pi> i\<in>I. sets (M i))"
   274 proof (unfold Int_stable_def, safe)
   274 proof (unfold Int_stable_def, safe)
   275   fix A assume "A \<in> prod_algebra I M"
   275   fix A assume "A \<in> prod_algebra I M"
   276   from prod_algebraE[OF this] guess J E . note A = this
   276   from prod_algebraE[OF this] guess J E . note A = this
   277   fix B assume "B \<in> prod_algebra I M"
   277   fix B assume "B \<in> prod_algebra I M"
   278   from prod_algebraE[OF this] guess K F . note B = this
   278   from prod_algebraE[OF this] guess K F . note B = this
   279   have "A \<inter> B = prod_emb I M (J \<union> K) (\<Pi>\<^sub>E i\<in>J \<union> K. (if i \<in> J then E i else space (M i)) \<inter> 
   279   have "A \<inter> B = prod_emb I M (J \<union> K) (\<Pi>\<^sub>E i\<in>J \<union> K. (if i \<in> J then E i else space (M i)) \<inter>
   280       (if i \<in> K then F i else space (M i)))"
   280       (if i \<in> K then F i else space (M i)))"
   281     unfolding A B using A(2,3,4) A(5)[THEN sets.sets_into_space] B(2,3,4)
   281     unfolding A B using A(2,3,4) A(5)[THEN sets.sets_into_space] B(2,3,4)
   282       B(5)[THEN sets.sets_into_space]
   282       B(5)[THEN sets.sets_into_space]
   283     apply (subst (1 2 3) prod_emb_PiE)
   283     apply (subst (1 2 3) prod_emb_PiE)
   284     apply (simp_all add: subset_eq PiE_Int)
   284     apply (simp_all add: subset_eq PiE_Int)
   377       using X \<open>I \<noteq> {}\<close> by (intro R.finite_INT sigma_sets.Basic) auto
   377       using X \<open>I \<noteq> {}\<close> by (intro R.finite_INT sigma_sets.Basic) auto
   378     finally show "A \<in> sigma_sets ?\<Omega> ?R" .
   378     finally show "A \<in> sigma_sets ?\<Omega> ?R" .
   379   qed
   379   qed
   380 next
   380 next
   381   fix A assume "A \<in> ?R"
   381   fix A assume "A \<in> ?R"
   382   then obtain i B where A: "A = {f\<in>\<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> B}" "i \<in> I" "B \<in> sets (M i)" 
   382   then obtain i B where A: "A = {f\<in>\<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> B}" "i \<in> I" "B \<in> sets (M i)"
   383     by auto
   383     by auto
   384   then have "A = prod_emb I M {i} (\<Pi>\<^sub>E i\<in>{i}. B)"
   384   then have "A = prod_emb I M {i} (\<Pi>\<^sub>E i\<in>{i}. B)"
   385      by (auto simp: prod_emb_def)
   385      by (auto simp: prod_emb_def)
   386   also have "\<dots> \<in> sigma_sets ?\<Omega> (prod_algebra I M)"
   386   also have "\<dots> \<in> sigma_sets ?\<Omega> (prod_algebra I M)"
   387     using A by (intro sigma_sets.Basic prod_algebraI) auto
   387     using A by (intro sigma_sets.Basic prod_algebraI) auto
   407   assumes E: "\<And>i. i \<in> I \<Longrightarrow> E i \<subseteq> Pow (\<Omega> i)"
   407   assumes E: "\<And>i. i \<in> I \<Longrightarrow> E i \<subseteq> Pow (\<Omega> i)"
   408   assumes J: "\<And>j. j \<in> J \<Longrightarrow> finite j" "\<Union>J = I"
   408   assumes J: "\<And>j. j \<in> J \<Longrightarrow> finite j" "\<Union>J = I"
   409   defines "P \<equiv> {{f\<in>(\<Pi>\<^sub>E i\<in>I. \<Omega> i). \<forall>i\<in>j. f i \<in> A i} | A j. j \<in> J \<and> A \<in> Pi j E}"
   409   defines "P \<equiv> {{f\<in>(\<Pi>\<^sub>E i\<in>I. \<Omega> i). \<forall>i\<in>j. f i \<in> A i} | A j. j \<in> J \<and> A \<in> Pi j E}"
   410   shows "sets (\<Pi>\<^sub>M i\<in>I. sigma (\<Omega> i) (E i)) = sets (sigma (\<Pi>\<^sub>E i\<in>I. \<Omega> i) P)"
   410   shows "sets (\<Pi>\<^sub>M i\<in>I. sigma (\<Omega> i) (E i)) = sets (sigma (\<Pi>\<^sub>E i\<in>I. \<Omega> i) P)"
   411 proof cases
   411 proof cases
   412   assume "I = {}" 
   412   assume "I = {}"
   413   with \<open>\<Union>J = I\<close> have "P = {{\<lambda>_. undefined}} \<or> P = {}"
   413   with \<open>\<Union>J = I\<close> have "P = {{\<lambda>_. undefined}} \<or> P = {}"
   414     by (auto simp: P_def)
   414     by (auto simp: P_def)
   415   with \<open>I = {}\<close> show ?thesis
   415   with \<open>I = {}\<close> show ?thesis
   416     by (auto simp add: sets_PiM_empty sigma_sets_empty_eq)
   416     by (auto simp add: sets_PiM_empty sigma_sets_empty_eq)
   417 next
   417 next
   418   let ?F = "\<lambda>i. {(\<lambda>x. x i) -` A \<inter> Pi\<^sub>E I \<Omega> |A. A \<in> E i}"
   418   let ?F = "\<lambda>i. {(\<lambda>x. x i) -` A \<inter> Pi\<^sub>E I \<Omega> |A. A \<in> E i}"
   419   assume "I \<noteq> {}"
   419   assume "I \<noteq> {}"
   420   then have "sets (Pi\<^sub>M I (\<lambda>i. sigma (\<Omega> i) (E i))) = 
   420   then have "sets (Pi\<^sub>M I (\<lambda>i. sigma (\<Omega> i) (E i))) =
   421       sets (\<Squnion>\<^sub>\<sigma> i\<in>I. vimage_algebra (\<Pi>\<^sub>E i\<in>I. \<Omega> i) (\<lambda>x. x i) (sigma (\<Omega> i) (E i)))"
   421       sets (\<Squnion>\<^sub>\<sigma> i\<in>I. vimage_algebra (\<Pi>\<^sub>E i\<in>I. \<Omega> i) (\<lambda>x. x i) (sigma (\<Omega> i) (E i)))"
   422     by (subst sets_PiM_eq_proj) (auto simp: space_measure_of_conv)
   422     by (subst sets_PiM_eq_proj) (auto simp: space_measure_of_conv)
   423   also have "\<dots> = sets (\<Squnion>\<^sub>\<sigma> i\<in>I. sigma (Pi\<^sub>E I \<Omega>) (?F i))"
   423   also have "\<dots> = sets (\<Squnion>\<^sub>\<sigma> i\<in>I. sigma (Pi\<^sub>E I \<Omega>) (?F i))"
   424     using E by (intro SUP_sigma_cong arg_cong[where f=sets] vimage_algebra_sigma) auto
   424     using E by (intro SUP_sigma_cong arg_cong[where f=sets] vimage_algebra_sigma) auto
   425   also have "\<dots> = sets (sigma (Pi\<^sub>E I \<Omega>) (\<Union>i\<in>I. ?F i))"
   425   also have "\<dots> = sets (sigma (Pi\<^sub>E I \<Omega>) (\<Union>i\<in>I. ?F i))"
   518 qed
   518 qed
   519 
   519 
   520 lemma measurable_PiM:
   520 lemma measurable_PiM:
   521   assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
   521   assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
   522   assumes sets: "\<And>X J. J \<noteq> {} \<or> I = {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)) \<Longrightarrow>
   522   assumes sets: "\<And>X J. J \<noteq> {} \<or> I = {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)) \<Longrightarrow>
   523     f -` prod_emb I M J (Pi\<^sub>E J X) \<inter> space N \<in> sets N" 
   523     f -` prod_emb I M J (Pi\<^sub>E J X) \<inter> space N \<in> sets N"
   524   shows "f \<in> measurable N (PiM I M)"
   524   shows "f \<in> measurable N (PiM I M)"
   525   using sets_PiM prod_algebra_sets_into_space space
   525   using sets_PiM prod_algebra_sets_into_space space
   526 proof (rule measurable_sigma_sets)
   526 proof (rule measurable_sigma_sets)
   527   fix A assume "A \<in> prod_algebra I M"
   527   fix A assume "A \<in> prod_algebra I M"
   528   from prod_algebraE[OF this] guess J X .
   528   from prod_algebraE[OF this] guess J X .
   530 qed
   530 qed
   531 
   531 
   532 lemma measurable_PiM_Collect:
   532 lemma measurable_PiM_Collect:
   533   assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
   533   assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
   534   assumes sets: "\<And>X J. J \<noteq> {} \<or> I = {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)) \<Longrightarrow>
   534   assumes sets: "\<And>X J. J \<noteq> {} \<or> I = {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)) \<Longrightarrow>
   535     {\<omega>\<in>space N. \<forall>i\<in>J. f \<omega> i \<in> X i} \<in> sets N" 
   535     {\<omega>\<in>space N. \<forall>i\<in>J. f \<omega> i \<in> X i} \<in> sets N"
   536   shows "f \<in> measurable N (PiM I M)"
   536   shows "f \<in> measurable N (PiM I M)"
   537   using sets_PiM prod_algebra_sets_into_space space
   537   using sets_PiM prod_algebra_sets_into_space space
   538 proof (rule measurable_sigma_sets)
   538 proof (rule measurable_sigma_sets)
   539   fix A assume "A \<in> prod_algebra I M"
   539   fix A assume "A \<in> prod_algebra I M"
   540   from prod_algebraE[OF this] guess J X . note X = this
   540   from prod_algebraE[OF this] guess J X . note X = this
   544   finally show "f -` A \<inter> space N \<in> sets N" .
   544   finally show "f -` A \<inter> space N \<in> sets N" .
   545 qed
   545 qed
   546 
   546 
   547 lemma measurable_PiM_single:
   547 lemma measurable_PiM_single:
   548   assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
   548   assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
   549   assumes sets: "\<And>A i. i \<in> I \<Longrightarrow> A \<in> sets (M i) \<Longrightarrow> {\<omega> \<in> space N. f \<omega> i \<in> A} \<in> sets N" 
   549   assumes sets: "\<And>A i. i \<in> I \<Longrightarrow> A \<in> sets (M i) \<Longrightarrow> {\<omega> \<in> space N. f \<omega> i \<in> A} \<in> sets N"
   550   shows "f \<in> measurable N (PiM I M)"
   550   shows "f \<in> measurable N (PiM I M)"
   551   using sets_PiM_single
   551   using sets_PiM_single
   552 proof (rule measurable_sigma_sets)
   552 proof (rule measurable_sigma_sets)
   553   fix A assume "A \<in> {{f \<in> \<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> A} |i A. i \<in> I \<and> A \<in> sets (M i)}"
   553   fix A assume "A \<in> {{f \<in> \<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> A} |i A. i \<in> I \<and> A \<in> sets (M i)}"
   554   then obtain B i where "A = {f \<in> \<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> B}" and B: "i \<in> I" "B \<in> sets (M i)"
   554   then obtain B i where "A = {f \<in> \<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> B}" and B: "i \<in> I" "B \<in> sets (M i)"
   600 lemma measurable_case_nat[measurable (raw)]:
   600 lemma measurable_case_nat[measurable (raw)]:
   601   assumes [measurable (raw)]: "i = 0 \<Longrightarrow> f \<in> measurable M N"
   601   assumes [measurable (raw)]: "i = 0 \<Longrightarrow> f \<in> measurable M N"
   602     "\<And>j. i = Suc j \<Longrightarrow> (\<lambda>x. g x j) \<in> measurable M N"
   602     "\<And>j. i = Suc j \<Longrightarrow> (\<lambda>x. g x j) \<in> measurable M N"
   603   shows "(\<lambda>x. case_nat (f x) (g x) i) \<in> measurable M N"
   603   shows "(\<lambda>x. case_nat (f x) (g x) i) \<in> measurable M N"
   604   by (cases i) simp_all
   604   by (cases i) simp_all
   605  
   605 
   606 lemma measurable_case_nat'[measurable (raw)]:
   606 lemma measurable_case_nat'[measurable (raw)]:
   607   assumes fg[measurable]: "f \<in> measurable N M" "g \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
   607   assumes fg[measurable]: "f \<in> measurable N M" "g \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
   608   shows "(\<lambda>x. case_nat (f x) (g x)) \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
   608   shows "(\<lambda>x. case_nat (f x) (g x)) \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
   609   using fg[THEN measurable_space]
   609   using fg[THEN measurable_space]
   610   by (auto intro!: measurable_PiM_single' simp add: space_PiM PiE_iff split: nat.split)
   610   by (auto intro!: measurable_PiM_single' simp add: space_PiM PiE_iff split: nat.split)
   664     by auto
   664     by auto
   665   then show "{\<omega> \<in> space N. (\<lambda>i\<in>I. X i \<omega>) i \<in> A} \<in> sets N"
   665   then show "{\<omega> \<in> space N. (\<lambda>i\<in>I. X i \<omega>) i \<in> A} \<in> sets N"
   666     using A X by (auto intro!: measurable_sets)
   666     using A X by (auto intro!: measurable_sets)
   667 qed (insert X, auto simp add: PiE_def dest: measurable_space)
   667 qed (insert X, auto simp add: PiE_def dest: measurable_space)
   668 
   668 
   669 lemma measurable_abs_UNIV: 
   669 lemma measurable_abs_UNIV:
   670   "(\<And>n. (\<lambda>\<omega>. f n \<omega>) \<in> measurable M (N n)) \<Longrightarrow> (\<lambda>\<omega> n. f n \<omega>) \<in> measurable M (PiM UNIV N)"
   670   "(\<And>n. (\<lambda>\<omega>. f n \<omega>) \<in> measurable M (N n)) \<Longrightarrow> (\<lambda>\<omega> n. f n \<omega>) \<in> measurable M (PiM UNIV N)"
   671   by (intro measurable_PiM_single) (auto dest: measurable_space)
   671   by (intro measurable_PiM_single) (auto dest: measurable_space)
   672 
   672 
   673 lemma measurable_restrict_subset: "J \<subseteq> L \<Longrightarrow> (\<lambda>f. restrict f J) \<in> measurable (Pi\<^sub>M L M) (Pi\<^sub>M J M)"
   673 lemma measurable_restrict_subset: "J \<subseteq> L \<Longrightarrow> (\<lambda>f. restrict f J) \<in> measurable (Pi\<^sub>M L M) (Pi\<^sub>M J M)"
   674   by (intro measurable_restrict measurable_component_singleton) auto
   674   by (intro measurable_restrict measurable_component_singleton) auto
   703   shows "X = {}"
   703   shows "X = {}"
   704 proof safe
   704 proof safe
   705   fix x assume "x \<in> X"
   705   fix x assume "x \<in> X"
   706   obtain \<omega> where "\<omega> \<in> space (PiM I M)"
   706   obtain \<omega> where "\<omega> \<in> space (PiM I M)"
   707     using ne by blast
   707     using ne by blast
   708   from merge_in_prod_emb[OF this \<open>x\<in>X\<close> X J] * show "x \<in> {}" by auto 
   708   from merge_in_prod_emb[OF this \<open>x\<in>X\<close> X J] * show "x \<in> {}" by auto
   709 qed
   709 qed
   710 
   710 
   711 lemma sets_in_Pi_aux:
   711 lemma sets_in_Pi_aux:
   712   "finite I \<Longrightarrow> (\<And>j. j \<in> I \<Longrightarrow> {x\<in>space (M j). x \<in> F j} \<in> sets (M j)) \<Longrightarrow>
   712   "finite I \<Longrightarrow> (\<And>j. j \<in> I \<Longrightarrow> {x\<in>space (M j). x \<in> F j} \<in> sets (M j)) \<Longrightarrow>
   713   {x\<in>space (PiM I M). x \<in> Pi I F} \<in> sets (PiM I M)"
   713   {x\<in>space (PiM I M). x \<in> Pi I F} \<in> sets (PiM I M)"
   773     and K: "\<And>i. K i = prod_emb I M (J i) (X i)"
   773     and K: "\<And>i. K i = prod_emb I M (J i) (X i)"
   774     by (metis Union.IH)
   774     by (metis Union.IH)
   775   show ?case
   775   show ?case
   776   proof (intro exI[of _ "\<Union>i. J i"] bexI[of _ "\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i)"] conjI)
   776   proof (intro exI[of _ "\<Union>i. J i"] bexI[of _ "\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i)"] conjI)
   777     show "(\<Union>i. J i) \<subseteq> I" "countable (\<Union>i. J i)" using J by auto
   777     show "(\<Union>i. J i) \<subseteq> I" "countable (\<Union>i. J i)" using J by auto
   778     with J show "UNION UNIV K = prod_emb I M (\<Union>i. J i) (\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i))" 
   778     with J show "UNION UNIV K = prod_emb I M (\<Union>i. J i) (\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i))"
   779       by (simp add: K[abs_def] SUP_upper)
   779       by (simp add: K[abs_def] SUP_upper)
   780   qed(auto intro: X)
   780   qed(auto intro: X)
   781 qed
   781 qed
   782 
   782 
   783 lemma measure_eqI_PiM_finite:
   783 lemma measure_eqI_PiM_finite:
   865   qed
   865   qed
   866 qed
   866 qed
   867 
   867 
   868 lemma emeasure_PiM_empty[simp]: "emeasure (PiM {} M) {\<lambda>_. undefined} = 1"
   868 lemma emeasure_PiM_empty[simp]: "emeasure (PiM {} M) {\<lambda>_. undefined} = 1"
   869 proof -
   869 proof -
   870   let ?\<mu> = "\<lambda>A. if A = {} then 0 else (1::ereal)"
   870   let ?\<mu> = "\<lambda>A. if A = {} then 0 else (1::ennreal)"
   871   have "emeasure (Pi\<^sub>M {} M) (prod_emb {} M {} (\<Pi>\<^sub>E i\<in>{}. {})) = 1"
   871   have "emeasure (Pi\<^sub>M {} M) (prod_emb {} M {} (\<Pi>\<^sub>E i\<in>{}. {})) = 1"
   872   proof (subst emeasure_extend_measure_Pair[OF PiM_def])
   872   proof (subst emeasure_extend_measure_Pair[OF PiM_def])
   873     show "positive (PiM {} M) ?\<mu>"
   873     show "positive (PiM {} M) ?\<mu>"
   874       by (auto simp: positive_def)
   874       by (auto simp: positive_def)
   875     show "countably_additive (PiM {} M) ?\<mu>"
   875     show "countably_additive (PiM {} M) ?\<mu>"
   881   finally show ?thesis
   881   finally show ?thesis
   882     by simp
   882     by simp
   883 qed
   883 qed
   884 
   884 
   885 lemma PiM_empty: "PiM {} M = count_space {\<lambda>_. undefined}"
   885 lemma PiM_empty: "PiM {} M = count_space {\<lambda>_. undefined}"
   886   by (rule measure_eqI) (auto simp add: sets_PiM_empty one_ereal_def)
   886   by (rule measure_eqI) (auto simp add: sets_PiM_empty)
   887 
   887 
   888 lemma (in product_sigma_finite) emeasure_PiM:
   888 lemma (in product_sigma_finite) emeasure_PiM:
   889   "finite I \<Longrightarrow> (\<And>i. i\<in>I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> emeasure (PiM I M) (Pi\<^sub>E I A) = (\<Prod>i\<in>I. emeasure (M i) (A i))"
   889   "finite I \<Longrightarrow> (\<And>i. i\<in>I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> emeasure (PiM I M) (Pi\<^sub>E I A) = (\<Prod>i\<in>I. emeasure (M i) (A i))"
   890 proof (induct I arbitrary: A rule: finite_induct)
   890 proof (induct I arbitrary: A rule: finite_induct)
   891   case (insert i I)
   891   case (insert i I)
   954   proof (rule measure_eqI_PiM_finite[OF I refl P, symmetric])
   954   proof (rule measure_eqI_PiM_finite[OF I refl P, symmetric])
   955     show "(\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> (Pi\<^sub>M I M) (Pi\<^sub>E I A) = P (Pi\<^sub>E I A)" for A
   955     show "(\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> (Pi\<^sub>M I M) (Pi\<^sub>E I A) = P (Pi\<^sub>E I A)" for A
   956       by (simp add: eq emeasure_PiM)
   956       by (simp add: eq emeasure_PiM)
   957     def A \<equiv> "\<lambda>n. \<Pi>\<^sub>E i\<in>I. C i n"
   957     def A \<equiv> "\<lambda>n. \<Pi>\<^sub>E i\<in>I. C i n"
   958     with C show "range A \<subseteq> prod_algebra I M" "\<And>i. emeasure (Pi\<^sub>M I M) (A i) \<noteq> \<infinity>" "(\<Union>i. A i) = space (PiM I M)"
   958     with C show "range A \<subseteq> prod_algebra I M" "\<And>i. emeasure (Pi\<^sub>M I M) (A i) \<noteq> \<infinity>" "(\<Union>i. A i) = space (PiM I M)"
   959       by (auto intro!: prod_algebraI_finite simp: emeasure_PiM subset_eq setprod_PInf emeasure_nonneg)
   959       by (auto intro!: prod_algebraI_finite simp: emeasure_PiM subset_eq ennreal_setprod_eq_top)
   960   qed
   960   qed
   961 qed
   961 qed
   962 
   962 
   963 lemma (in product_sigma_finite) sigma_finite: 
   963 lemma (in product_sigma_finite) sigma_finite:
   964   assumes "finite I"
   964   assumes "finite I"
   965   shows "sigma_finite_measure (PiM I M)"
   965   shows "sigma_finite_measure (PiM I M)"
   966 proof
   966 proof
   967   interpret finite_product_sigma_finite M I by standard fact
   967   interpret finite_product_sigma_finite M I by standard fact
   968 
   968 
   973   moreover have "(\<Union>(PiE I ` PiE I F)) = space (Pi\<^sub>M I M)"
   973   moreover have "(\<Union>(PiE I ` PiE I F)) = space (Pi\<^sub>M I M)"
   974     using in_space by (auto simp: space_PiM PiE_iff intro!: PiE_choice[THEN iffD2])
   974     using in_space by (auto simp: space_PiM PiE_iff intro!: PiE_choice[THEN iffD2])
   975   ultimately show "\<exists>A. countable A \<and> A \<subseteq> sets (Pi\<^sub>M I M) \<and> \<Union>A = space (Pi\<^sub>M I M) \<and> (\<forall>a\<in>A. emeasure (Pi\<^sub>M I M) a \<noteq> \<infinity>)"
   975   ultimately show "\<exists>A. countable A \<and> A \<subseteq> sets (Pi\<^sub>M I M) \<and> \<Union>A = space (Pi\<^sub>M I M) \<and> (\<forall>a\<in>A. emeasure (Pi\<^sub>M I M) a \<noteq> \<infinity>)"
   976     by (intro exI[of _ "PiE I ` PiE I F"])
   976     by (intro exI[of _ "PiE I ` PiE I F"])
   977        (auto intro!: countable_PiE sets_PiM_I_finite
   977        (auto intro!: countable_PiE sets_PiM_I_finite
   978              simp: PiE_iff emeasure_PiM finite_index setprod_PInf emeasure_nonneg)
   978              simp: PiE_iff emeasure_PiM finite_index ennreal_setprod_eq_top)
   979 qed
   979 qed
   980 
   980 
   981 sublocale finite_product_sigma_finite \<subseteq> sigma_finite_measure "Pi\<^sub>M I M"
   981 sublocale finite_product_sigma_finite \<subseteq> sigma_finite_measure "Pi\<^sub>M I M"
   982   using sigma_finite[OF finite_index] .
   982   using sigma_finite[OF finite_index] .
   983 
   983 
  1005        (auto simp: * J.emeasure_pair_measure_Times I.measure_times J.measure_times setprod.union_disjoint)
  1005        (auto simp: * J.emeasure_pair_measure_Times I.measure_times J.measure_times setprod.union_disjoint)
  1006 qed (insert fin, simp_all)
  1006 qed (insert fin, simp_all)
  1007 
  1007 
  1008 lemma (in product_sigma_finite) product_nn_integral_fold:
  1008 lemma (in product_sigma_finite) product_nn_integral_fold:
  1009   assumes IJ: "I \<inter> J = {}" "finite I" "finite J"
  1009   assumes IJ: "I \<inter> J = {}" "finite I" "finite J"
  1010   and f: "f \<in> borel_measurable (Pi\<^sub>M (I \<union> J) M)"
  1010   and f[measurable]: "f \<in> borel_measurable (Pi\<^sub>M (I \<union> J) M)"
  1011   shows "integral\<^sup>N (Pi\<^sub>M (I \<union> J) M) f =
  1011   shows "integral\<^sup>N (Pi\<^sub>M (I \<union> J) M) f =
  1012     (\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f (merge I J (x, y)) \<partial>(Pi\<^sub>M J M)) \<partial>(Pi\<^sub>M I M))"
  1012     (\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f (merge I J (x, y)) \<partial>(Pi\<^sub>M J M)) \<partial>(Pi\<^sub>M I M))"
  1013 proof -
  1013 proof -
  1014   interpret I: finite_product_sigma_finite M I by standard fact
  1014   interpret I: finite_product_sigma_finite M I by standard fact
  1015   interpret J: finite_product_sigma_finite M J by standard fact
  1015   interpret J: finite_product_sigma_finite M J by standard fact
  1016   interpret P: pair_sigma_finite "Pi\<^sub>M I M" "Pi\<^sub>M J M" by standard
  1016   interpret P: pair_sigma_finite "Pi\<^sub>M I M" "Pi\<^sub>M J M" by standard
  1017   have P_borel: "(\<lambda>x. f (merge I J x)) \<in> borel_measurable (Pi\<^sub>M I M \<Otimes>\<^sub>M Pi\<^sub>M J M)"
  1017   have P_borel: "(\<lambda>x. f (merge I J x)) \<in> borel_measurable (Pi\<^sub>M I M \<Otimes>\<^sub>M Pi\<^sub>M J M)"
  1018     using measurable_comp[OF measurable_merge f] by (simp add: comp_def)
  1018     using measurable_comp[OF measurable_merge f] by (simp add: comp_def)
  1019   show ?thesis
  1019   show ?thesis
  1020     apply (subst distr_merge[OF IJ, symmetric])
  1020     apply (subst distr_merge[OF IJ, symmetric])
  1021     apply (subst nn_integral_distr[OF measurable_merge f])
  1021     apply (subst nn_integral_distr[OF measurable_merge])
       
  1022     apply measurable []
  1022     apply (subst J.nn_integral_fst[symmetric, OF P_borel])
  1023     apply (subst J.nn_integral_fst[symmetric, OF P_borel])
  1023     apply simp
  1024     apply simp
  1024     done
  1025     done
  1025 qed
  1026 qed
  1026 
  1027 
  1082   apply (rule sigma_finite[OF I(1)])
  1083   apply (rule sigma_finite[OF I(1)])
  1083   apply measurable
  1084   apply measurable
  1084   done
  1085   done
  1085 
  1086 
  1086 lemma (in product_sigma_finite) product_nn_integral_setprod:
  1087 lemma (in product_sigma_finite) product_nn_integral_setprod:
  1087   fixes f :: "'i \<Rightarrow> 'a \<Rightarrow> ereal"
  1088   assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable (M i)"
  1088   assumes "finite I" and borel: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable (M i)"
       
  1089   and pos: "\<And>i x. i \<in> I \<Longrightarrow> 0 \<le> f i x"
       
  1090   shows "(\<integral>\<^sup>+ x. (\<Prod>i\<in>I. f i (x i)) \<partial>Pi\<^sub>M I M) = (\<Prod>i\<in>I. integral\<^sup>N (M i) (f i))"
  1089   shows "(\<integral>\<^sup>+ x. (\<Prod>i\<in>I. f i (x i)) \<partial>Pi\<^sub>M I M) = (\<Prod>i\<in>I. integral\<^sup>N (M i) (f i))"
  1091 using assms proof induct
  1090 using assms proof (induction I)
  1092   case (insert i I)
  1091   case (insert i I)
       
  1092   note insert.prems[measurable]
  1093   note \<open>finite I\<close>[intro, simp]
  1093   note \<open>finite I\<close>[intro, simp]
  1094   interpret I: finite_product_sigma_finite M I by standard auto
  1094   interpret I: finite_product_sigma_finite M I by standard auto
  1095   have *: "\<And>x y. (\<Prod>j\<in>I. f j (if j = i then y else x j)) = (\<Prod>j\<in>I. f j (x j))"
  1095   have *: "\<And>x y. (\<Prod>j\<in>I. f j (if j = i then y else x j)) = (\<Prod>j\<in>I. f j (x j))"
  1096     using insert by (auto intro!: setprod.cong)
  1096     using insert by (auto intro!: setprod.cong)
  1097   have prod: "\<And>J. J \<subseteq> insert i I \<Longrightarrow> (\<lambda>x. (\<Prod>i\<in>J. f i (x i))) \<in> borel_measurable (Pi\<^sub>M J M)"
  1097   have prod: "\<And>J. J \<subseteq> insert i I \<Longrightarrow> (\<lambda>x. (\<Prod>i\<in>J. f i (x i))) \<in> borel_measurable (Pi\<^sub>M J M)"
  1098     using sets.sets_into_space insert
  1098     using sets.sets_into_space insert
  1099     by (intro borel_measurable_ereal_setprod
  1099     by (intro borel_measurable_setprod_ennreal
  1100               measurable_comp[OF measurable_component_singleton, unfolded comp_def])
  1100               measurable_comp[OF measurable_component_singleton, unfolded comp_def])
  1101        auto
  1101        auto
  1102   then show ?case
  1102   then show ?case
  1103     apply (simp add: product_nn_integral_insert[OF insert(1,2) prod])
  1103     apply (simp add: product_nn_integral_insert[OF insert(1,2)])
  1104     apply (simp add: insert(2-) * pos borel setprod_ereal_pos nn_integral_multc)
  1104     apply (simp add: insert(2-) * nn_integral_multc)
  1105     apply (subst nn_integral_cmult)
  1105     apply (subst nn_integral_cmult)
  1106     apply (auto simp add: pos borel insert(2-) setprod_ereal_pos nn_integral_nonneg)
  1106     apply (auto simp add: insert(2-))
  1107     done
  1107     done
  1108 qed (simp add: space_PiM)
  1108 qed (simp add: space_PiM)
  1109 
  1109 
  1110 lemma (in product_sigma_finite) product_nn_integral_pair:
  1110 lemma (in product_sigma_finite) product_nn_integral_pair:
  1111   assumes [measurable]: "case_prod f \<in> borel_measurable (M x \<Otimes>\<^sub>M M y)"
  1111   assumes [measurable]: "case_prod f \<in> borel_measurable (M x \<Otimes>\<^sub>M M y)"