prefer p2e before e2p; use measure_unique_Int_stable_vimage;
authorhoelzl
Fri, 04 Feb 2011 14:16:55 +0100
changeset 41706 a207a858d1f6
parent 41705 1100512e16d8
child 41707 a10f0a1cae41
prefer p2e before e2p; use measure_unique_Int_stable_vimage;
src/HOL/Probability/Lebesgue_Measure.thy
src/HOL/Probability/Measure.thy
src/HOL/Probability/Product_Measure.thy
--- a/src/HOL/Probability/Lebesgue_Measure.thy	Fri Feb 04 14:16:55 2011 +0100
+++ b/src/HOL/Probability/Lebesgue_Measure.thy	Fri Feb 04 14:16:55 2011 +0100
@@ -48,6 +48,8 @@
 lemma Pi_iff: "f \<in> Pi I X \<longleftrightarrow> (\<forall>i\<in>I. f i \<in> X i)"
   unfolding Pi_def by auto
 
+subsection {* Lebesgue measure *}
+
 definition lebesgue :: "'a::ordered_euclidean_space measure_space" where
   "lebesgue = \<lparr> space = UNIV,
     sets = {A. \<forall>n. (indicator A :: 'a \<Rightarrow> real) integrable_on cube n},
@@ -498,6 +500,8 @@
   then show ?thesis by auto
 qed auto
 
+subsection {* Lebesgue-Borel measure *}
+
 definition "lborel = lebesgue \<lparr> sets := sets borel \<rparr>"
 
 lemma
@@ -544,6 +548,8 @@
     by auto
 qed
 
+subsection {* Lebesgue integrable implies Gauge integrable *}
+
 lemma simple_function_has_integral:
   fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
   assumes f:"simple_function lebesgue f"
@@ -734,13 +740,7 @@
   apply(rule borel.borel_measurableI)
   using continuous_open_preimage[OF assms] unfolding vimage_def by auto
 
-lemma (in measure_space) integral_monotone_convergence_pos':
-  assumes i: "\<And>i. integrable M (f i)" and mono: "\<And>x. mono (\<lambda>n. f n x)"
-  and pos: "\<And>x i. 0 \<le> f i x"
-  and lim: "\<And>x. (\<lambda>i. f i x) ----> u x"
-  and ilim: "(\<lambda>i. integral\<^isup>L M (f i)) ----> x"
-  shows "integrable M u \<and> integral\<^isup>L M u = x"
-  using integral_monotone_convergence_pos[OF assms] by auto
+subsection {* Equivalence between product spaces and euclidean spaces *}
 
 definition e2p :: "'a::ordered_euclidean_space \<Rightarrow> (nat \<Rightarrow> real)" where
   "e2p x = (\<lambda>i\<in>{..<DIM('a)}. x$$i)"
@@ -756,21 +756,6 @@
   "p2e (e2p x) = (x::'a::ordered_euclidean_space)"
   by (auto simp: euclidean_eq[where 'a='a] p2e_def e2p_def)
 
-declare restrict_extensional[intro]
-
-lemma e2p_extensional[intro]:"e2p (y::'a::ordered_euclidean_space) \<in> extensional {..<DIM('a)}"
-  unfolding e2p_def by auto
-
-lemma e2p_image_vimage: fixes A::"'a::ordered_euclidean_space set"
-  shows "e2p ` A = p2e -` A \<inter> extensional {..<DIM('a)}"
-proof(rule set_eqI,rule)
-  fix x assume "x \<in> e2p ` A" then guess y unfolding image_iff .. note y=this
-  show "x \<in> p2e -` A \<inter> extensional {..<DIM('a)}"
-    apply safe apply(rule vimageI[OF _ y(1)]) unfolding y p2e_e2p by auto
-next fix x assume "x \<in> p2e -` A \<inter> extensional {..<DIM('a)}"
-  thus "x \<in> e2p ` A" unfolding image_iff apply(rule_tac x="p2e x" in bexI) apply(subst e2p_p2e) by auto
-qed
-
 interpretation lborel_product: product_sigma_finite "\<lambda>x. lborel::real measure_space"
   by default
 
@@ -843,107 +828,65 @@
   then show "p2e -` A \<inter> space ?P \<in> sets ?P" by auto
 qed simp
 
-lemma inj_e2p[intro, simp]: "inj e2p"
-proof (intro inj_onI conjI allI impI euclidean_eq[where 'a='a, THEN iffD2])
-  fix x y ::'a and i assume "e2p x = e2p y" "i < DIM('a)"
-  then show "x $$ i= y $$ i"
-    by (auto simp: e2p_def restrict_def fun_eq_iff elim!: allE[where x=i])
-qed
-
-lemma e2p_Int:"e2p ` A \<inter> e2p ` B = e2p ` (A \<inter> B)" (is "?L = ?R")
-  by (auto simp: image_Int[THEN sym])
+lemma Int_stable_cuboids:
+  fixes x::"'a::ordered_euclidean_space"
+  shows "Int_stable \<lparr>space = UNIV, sets = range (\<lambda>(a, b::'a). {a..b})\<rparr>"
+  by (auto simp: inter_interval Int_stable_def)
 
-lemma Int_stable_cuboids: fixes x::"'a::ordered_euclidean_space"
-  shows "Int_stable \<lparr>space = UNIV, sets = range (\<lambda>(a, b::'a). e2p ` {a..b})\<rparr>"
-  unfolding Int_stable_def algebra.select_convs
-proof safe fix a b x y::'a
-  have *:"e2p ` {a..b} \<inter> e2p ` {x..y} =
-    (\<lambda>(a, b). e2p ` {a..b}) (\<chi>\<chi> i. max (a $$ i) (x $$ i), \<chi>\<chi> i. min (b $$ i) (y $$ i)::'a)"
-    unfolding e2p_Int inter_interval by auto
-  show "e2p ` {a..b} \<inter> e2p ` {x..y} \<in> range (\<lambda>(a, b). e2p ` {a..b::'a})" unfolding *
-    apply(rule range_eqI) ..
-qed
-
-lemma Int_stable_cuboids': fixes x::"'a::ordered_euclidean_space"
-  shows "Int_stable \<lparr>space = UNIV, sets = range (\<lambda>(a, b::'a). {a..b})\<rparr>"
-  unfolding Int_stable_def algebra.select_convs
-  apply safe unfolding inter_interval by auto
-
-lemma lmeasure_measure_eq_borel_prod:
+lemma lborel_eq_lborel_space:
   fixes A :: "('a::ordered_euclidean_space) set"
   assumes "A \<in> sets borel"
-  shows "lebesgue.\<mu> A = lborel_space.\<mu> TYPE('a) (e2p ` A)" (is "_ = ?m A")
-proof (rule measure_unique_Int_stable[where X=A and A=cube])
-  show "Int_stable \<lparr> space = UNIV :: 'a set, sets = range (\<lambda>(a,b). {a..b}) \<rparr>"
-    (is "Int_stable ?E" ) using Int_stable_cuboids' .
-  have [simp]: "sigma ?E = borel" using borel_eq_atLeastAtMost ..
-  show "\<And>i. lebesgue.\<mu> (cube i) \<noteq> \<omega>" unfolding cube_def by auto
-  show "\<And>X. X \<in> sets ?E \<Longrightarrow> lebesgue.\<mu> X = ?m X"
-  proof- case goal1 then obtain a b where X:"X = {a..b}" by auto
-    { presume *:"X \<noteq> {} \<Longrightarrow> ?case"
-      show ?case apply(cases,rule *,assumption) by auto }
-    def XX \<equiv> "\<lambda>i. {a $$ i .. b $$ i}" assume  "X \<noteq> {}"  note X' = this[unfolded X interval_ne_empty]
-    have *:"Pi\<^isub>E {..<DIM('a)} XX = e2p ` X" apply(rule set_eqI)
-    proof fix x assume "x \<in> Pi\<^isub>E {..<DIM('a)} XX"
-      thus "x \<in> e2p ` X" unfolding image_iff apply(rule_tac x="\<chi>\<chi> i. x i" in bexI)
-        unfolding Pi_def extensional_def e2p_def restrict_def X mem_interval XX_def by rule auto
-    next fix x assume "x \<in> e2p ` X" then guess y unfolding image_iff .. note y = this
-      show "x \<in> Pi\<^isub>E {..<DIM('a)} XX" unfolding y using y(1)
-        unfolding Pi_def extensional_def e2p_def restrict_def X mem_interval XX_def by auto
-    qed
-    have "lebesgue.\<mu> X = (\<Prod>x<DIM('a). Real (b $$ x - a $$ x))"  using X' apply- unfolding X
-      unfolding lmeasure_atLeastAtMost content_closed_interval apply(subst Real_setprod) by auto
-    also have "... = (\<Prod>i<DIM('a). lebesgue.\<mu> (XX i))" apply(rule setprod_cong2)
-      unfolding XX_def lmeasure_atLeastAtMost apply(subst content_real) using X' by auto
-    also have "... = ?m X" unfolding *[THEN sym]
-      apply(rule lborel_space.measure_times[symmetric]) unfolding XX_def by auto
-    finally show ?case .
-  qed
+  shows "lborel.\<mu> A = lborel_space.\<mu> TYPE('a) (p2e -` A \<inter> (space (lborel_space.P TYPE('a))))"
+    (is "_ = measure ?P (?T A)")
+proof (rule measure_unique_Int_stable_vimage)
+  show "measure_space ?P" by default
+  show "measure_space lborel" by default
+
+  let ?E = "\<lparr> space = UNIV :: 'a set, sets = range (\<lambda>(a,b). {a..b}) \<rparr>"
+  show "Int_stable ?E" using Int_stable_cuboids .
+  show "range cube \<subseteq> sets ?E" unfolding cube_def_raw by auto
+  { fix x have "\<exists>n. x \<in> cube n" using mem_big_cube[of x] by fastsimp }
+  then show "cube \<up> space ?E" by (intro isotoneI cube_subset_Suc) auto
+  { fix i show "lborel.\<mu> (cube i) \<noteq> \<omega>" unfolding cube_def by auto }
+  show "A \<in> sets (sigma ?E)" "sets (sigma ?E) = sets lborel" "space ?E = space lborel"
+    using assms by (simp_all add: borel_eq_atLeastAtMost)
 
-  show "range cube \<subseteq> sets \<lparr>space = UNIV, sets = range (\<lambda>(a, b). {a..b})\<rparr>"
-    unfolding cube_def_raw by auto
-  have "\<And>x. \<exists>xa. x \<in> cube xa" apply(rule_tac x=x in mem_big_cube) by fastsimp
-  thus "cube \<up> space \<lparr>space = UNIV, sets = range (\<lambda>(a, b). {a..b})\<rparr>"
-    apply-apply(rule isotoneI) apply(rule cube_subset_Suc) by auto
-  show "A \<in> sets (sigma ?E)" using assms by simp
-  have "measure_space lborel" by default
-  then show "measure_space \<lparr> space = space ?E, sets = sets (sigma ?E), measure = measure lebesgue\<rparr>"
-    unfolding lebesgue_def lborel_def by simp
-  let ?M = "\<lparr> space = space ?E, sets = sets (sigma ?E), measure = ?m \<rparr>"
-  show "measure_space ?M"
-  proof (rule lborel_space.measure_space_vimage)
-    show "sigma_algebra ?M" by (rule lborel.sigma_algebra_cong) auto
-    show "p2e \<in> measurable (\<Pi>\<^isub>M i\<in>{..<DIM('a)}. lborel) ?M"
-      using measurable_p2e unfolding measurable_def by auto
-    fix A :: "'a set" assume "A \<in> sets ?M"
-    show "measure ?M A = lborel_space.\<mu> TYPE('a) (p2e -` A \<inter> space (\<Pi>\<^isub>M i\<in>{..<DIM('a)}. lborel))"
-      by (simp add: e2p_image_vimage)
-  qed
-qed simp
+  show "p2e \<in> measurable ?P (lborel :: 'a measure_space)"
+    using measurable_p2e unfolding measurable_def by simp
+  { fix X assume "X \<in> sets ?E"
+    then obtain a b where X[simp]: "X = {a .. b}" by auto
+    have *: "?T X = (\<Pi>\<^isub>E i\<in>{..<DIM('a)}. {a $$ i .. b $$ i})"
+      by (auto simp: Pi_iff eucl_le[where 'a='a] p2e_def)
+    show "lborel.\<mu> X = measure ?P (?T X)"
+    proof cases
+      assume "X \<noteq> {}"
+      then have "a \<le> b"
+        by (simp add: interval_ne_empty eucl_le[where 'a='a])
+      then have "lborel.\<mu> X = (\<Prod>x<DIM('a). lborel.\<mu> {a $$ x .. b $$ x})"
+        by (auto simp: content_closed_interval eucl_le[where 'a='a]
+                 intro!: Real_setprod )
+      also have "\<dots> = measure ?P (?T X)"
+        unfolding * by (subst lborel_space.measure_times) auto
+      finally show ?thesis .
+    qed simp }
+qed
 
-lemma range_e2p:"range (e2p::'a::ordered_euclidean_space \<Rightarrow> _) = extensional {..<DIM('a)}"
-  unfolding e2p_def_raw
-  apply auto
-  by (rule_tac x="\<chi>\<chi> i. x i" in image_eqI) (auto simp: fun_eq_iff extensional_def)
+lemma lebesgue_eq_lborel_space_in_borel:
+  fixes A :: "('a::ordered_euclidean_space) set"
+  assumes A: "A \<in> sets borel"
+  shows "lebesgue.\<mu> A = lborel_space.\<mu> TYPE('a) (p2e -` A \<inter> (space (lborel_space.P TYPE('a))))"
+  using lborel_eq_lborel_space[OF A] by simp
 
 lemma borel_fubini_positiv_integral:
   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> pextreal"
   assumes f: "f \<in> borel_measurable borel"
   shows "integral\<^isup>P lborel f = \<integral>\<^isup>+x. f (p2e x) \<partial>(lborel_space.P TYPE('a))"
-proof (rule lborel.positive_integral_vimage[symmetric, of _ "e2p :: 'a \<Rightarrow> _" "(\<lambda>x. f (p2e x))", unfolded p2e_e2p])
-  show "(e2p :: 'a \<Rightarrow> _) \<in> measurable borel (lborel_space.P TYPE('a))" by (rule measurable_e2p)
-  show "sigma_algebra (lborel_space.P TYPE('a))" by default
-  from measurable_comp[OF measurable_p2e f]
-  show "(\<lambda>x. f (p2e x)) \<in> borel_measurable (lborel_space.P TYPE('a))" by (simp add: comp_def)
-  let "?L A" = "lebesgue.\<mu> ((e2p::'a \<Rightarrow> (nat \<Rightarrow> real)) -` A \<inter> UNIV)"
-  fix A :: "(nat \<Rightarrow> real) set" assume "A \<in> sets (lborel_space.P TYPE('a))"
-  then have A: "(e2p::'a \<Rightarrow> (nat \<Rightarrow> real)) -` A \<inter> space borel \<in> sets borel"
-    by (rule measurable_sets[OF measurable_e2p])
-  have [simp]: "A \<inter> extensional {..<DIM('a)} = A"
-    using `A \<in> sets (lborel_space.P TYPE('a))`[THEN lborel_space.sets_into_space] by auto
-  show "lborel_space.\<mu> TYPE('a) A = ?L A"
-    using lmeasure_measure_eq_borel_prod[OF A] by (simp add: range_e2p)
-qed
+proof (rule lborel_space.positive_integral_vimage[OF _ _ _ lborel_eq_lborel_space])
+  show "sigma_algebra lborel" by default
+  show "p2e \<in> measurable (lborel_space.P TYPE('a)) (lborel :: 'a measure_space)"
+       "f \<in> borel_measurable lborel"
+    using measurable_p2e f by (simp_all add: measurable_def)
+qed simp
 
 lemma borel_fubini_integrable:
   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
@@ -967,19 +910,13 @@
   then have "f \<in> borel_measurable borel"
     by (simp cong: measurable_cong)
   ultimately show "integrable lborel f"
-    by (simp add: comp_def borel_fubini_positiv_integral integrable_def)
+    by (simp add: borel_fubini_positiv_integral integrable_def)
 qed
 
 lemma borel_fubini:
   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   assumes f: "f \<in> borel_measurable borel"
   shows "integral\<^isup>L lborel f = \<integral>x. f (p2e x) \<partial>(lborel_space.P TYPE('a))"
-proof -
-  have 1:"(\<lambda>x. Real (f x)) \<in> borel_measurable borel" using f by auto
-  have 2:"(\<lambda>x. Real (- f x)) \<in> borel_measurable borel" using f by auto
-  show ?thesis unfolding lebesgue_integral_def
-    unfolding borel_fubini_positiv_integral[OF 1] borel_fubini_positiv_integral[OF 2]
-    unfolding o_def ..
-qed
+  using f by (simp add: borel_fubini_positiv_integral lebesgue_integral_def)
 
 end
--- a/src/HOL/Probability/Measure.thy	Fri Feb 04 14:16:55 2011 +0100
+++ b/src/HOL/Probability/Measure.thy	Fri Feb 04 14:16:55 2011 +0100
@@ -624,6 +624,59 @@
   ultimately show ?thesis by (simp add: isoton_def)
 qed
 
+lemma (in measure_space) measure_space_vimage:
+  fixes M' :: "('c, 'd) measure_space_scheme"
+  assumes T: "sigma_algebra M'" "T \<in> measurable M M'"
+    and \<nu>: "\<And>A. A \<in> sets M' \<Longrightarrow> measure M' A = \<mu> (T -` A \<inter> space M)"
+  shows "measure_space M'"
+proof -
+  interpret M': sigma_algebra M' by fact
+  show ?thesis
+  proof
+    show "measure M' {} = 0" using \<nu>[of "{}"] by simp
+
+    show "countably_additive M' (measure M')"
+    proof (intro countably_additiveI)
+      fix A :: "nat \<Rightarrow> 'c set" assume "range A \<subseteq> sets M'" "disjoint_family A"
+      then have A: "\<And>i. A i \<in> sets M'" "(\<Union>i. A i) \<in> sets M'" by auto
+      then have *: "range (\<lambda>i. T -` (A i) \<inter> space M) \<subseteq> sets M"
+        using `T \<in> measurable M M'` by (auto simp: measurable_def)
+      moreover have "(\<Union>i. T -`  A i \<inter> space M) \<in> sets M"
+        using * by blast
+      moreover have **: "disjoint_family (\<lambda>i. T -` A i \<inter> space M)"
+        using `disjoint_family A` by (auto simp: disjoint_family_on_def)
+      ultimately show "(\<Sum>\<^isub>\<infinity> i. measure M' (A i)) = measure M' (\<Union>i. A i)"
+        using measure_countably_additive[OF _ **] A
+        by (auto simp: comp_def vimage_UN \<nu>)
+    qed
+  qed
+qed
+
+lemma measure_unique_Int_stable_vimage:
+  fixes A :: "nat \<Rightarrow> 'a set"
+  assumes E: "Int_stable E"
+  and A: "range A \<subseteq> sets E" "A \<up> space E" "\<And>i. measure M (A i) \<noteq> \<omega>"
+  and N: "measure_space N" "T \<in> measurable N M"
+  and M: "measure_space M" "sets (sigma E) = sets M" "space E = space M"
+  and eq: "\<And>X. X \<in> sets E \<Longrightarrow> measure M X = measure N (T -` X \<inter> space N)"
+  assumes X: "X \<in> sets (sigma E)"
+  shows "measure M X = measure N (T -` X \<inter> space N)"
+proof (rule measure_unique_Int_stable[OF E A(1,2) _ _ eq _ X])
+  interpret M: measure_space M by fact
+  interpret N: measure_space N by fact
+  let "?T X" = "T -` X \<inter> space N"
+  show "measure_space \<lparr>space = space E, sets = sets (sigma E), measure = measure M\<rparr>"
+    by (rule M.measure_space_cong) (auto simp: M)
+  show "measure_space \<lparr>space = space E, sets = sets (sigma E), measure = \<lambda>X. measure N (?T X)\<rparr>" (is "measure_space ?E")
+  proof (rule N.measure_space_vimage)
+    show "sigma_algebra ?E"
+      by (rule M.sigma_algebra_cong) (auto simp: M)
+    show "T \<in> measurable N ?E"
+      using `T \<in> measurable N M` by (auto simp: M measurable_def)
+  qed simp
+  show "\<And>i. M.\<mu> (A i) \<noteq> \<omega>" by fact
+qed
+
 section "@{text \<mu>}-null sets"
 
 abbreviation (in measure_space) "null_sets \<equiv> {N\<in>sets M. \<mu> N = 0}"
@@ -836,34 +889,6 @@
   qed
 qed
 
-lemma (in measure_space) measure_space_vimage:
-  fixes M' :: "('c, 'd) measure_space_scheme"
-  assumes T: "sigma_algebra M'" "T \<in> measurable M M'"
-    and \<nu>: "\<And>A. A \<in> sets M' \<Longrightarrow> measure M' A = \<mu> (T -` A \<inter> space M)"
-  shows "measure_space M'"
-proof -
-  interpret M': sigma_algebra M' by fact
-  show ?thesis
-  proof
-    show "measure M' {} = 0" using \<nu>[of "{}"] by simp
-
-    show "countably_additive M' (measure M')"
-    proof (intro countably_additiveI)
-      fix A :: "nat \<Rightarrow> 'c set" assume "range A \<subseteq> sets M'" "disjoint_family A"
-      then have A: "\<And>i. A i \<in> sets M'" "(\<Union>i. A i) \<in> sets M'" by auto
-      then have *: "range (\<lambda>i. T -` (A i) \<inter> space M) \<subseteq> sets M"
-        using `T \<in> measurable M M'` by (auto simp: measurable_def)
-      moreover have "(\<Union>i. T -`  A i \<inter> space M) \<in> sets M"
-        using * by blast
-      moreover have **: "disjoint_family (\<lambda>i. T -` A i \<inter> space M)"
-        using `disjoint_family A` by (auto simp: disjoint_family_on_def)
-      ultimately show "(\<Sum>\<^isub>\<infinity> i. measure M' (A i)) = measure M' (\<Union>i. A i)"
-        using measure_countably_additive[OF _ **] A
-        by (auto simp: comp_def vimage_UN \<nu>)
-    qed
-  qed
-qed
-
 lemma (in measure_space) measure_space_subalgebra:
   assumes "sigma_algebra N" and [simp]: "sets N \<subseteq> sets M" "space N = space M"
   and measure[simp]: "\<And>X. X \<in> sets N \<Longrightarrow> measure N X = measure M X"
--- a/src/HOL/Probability/Product_Measure.thy	Fri Feb 04 14:16:55 2011 +0100
+++ b/src/HOL/Probability/Product_Measure.thy	Fri Feb 04 14:16:55 2011 +0100
@@ -734,48 +734,37 @@
 qed
 
 lemma (in pair_sigma_finite) pair_measure_alt2:
-  assumes "A \<in> sets P"
+  assumes A: "A \<in> sets P"
   shows "\<mu> A = (\<integral>\<^isup>+y. M1.\<mu> ((\<lambda>x. (x, y)) -` A) \<partial>M2)"
     (is "_ = ?\<nu> A")
 proof -
+  interpret Q: pair_sigma_finite M2 M1 by default
   from sigma_finite_up_in_pair_measure_generator guess F :: "nat \<Rightarrow> ('a \<times> 'b) set" .. note F = this
   have [simp]: "\<And>m. \<lparr> space = space E, sets = sets (sigma E), measure = m \<rparr> = P\<lparr> measure := m \<rparr>"
     unfolding pair_measure_def by simp
-  show ?thesis
-  proof (rule measure_unique_Int_stable[where \<nu>="?\<nu>", OF Int_stable_pair_measure_generator], simp_all)
-    show "range F \<subseteq> sets E" "F \<up> space E" "\<And>i. \<mu> (F i) \<noteq> \<omega>" "A \<in> sets (sigma E)"
+
+  have "\<mu> A = Q.\<mu> ((\<lambda>(y, x). (x, y)) -` A \<inter> space Q.P)"
+  proof (rule measure_unique_Int_stable_vimage[OF Int_stable_pair_measure_generator])
+    show "measure_space P" "measure_space Q.P" by default
+    show "(\<lambda>(y, x). (x, y)) \<in> measurable Q.P P" by (rule Q.pair_sigma_algebra_swap_measurable)
+    show "sets (sigma E) = sets P" "space E = space P" "A \<in> sets (sigma E)"
+      using assms unfolding pair_measure_def by auto
+    show "range F \<subseteq> sets E" "F \<up> space E" "\<And>i. \<mu> (F i) \<noteq> \<omega>"
       using F `A \<in> sets P` by (auto simp: pair_measure_def)
-    show "measure_space P" by default
-    interpret Q: pair_sigma_finite M2 M1 by default
-    have P: "sigma_algebra (P\<lparr> measure := ?\<nu>\<rparr>)"
-      by (intro sigma_algebra_cong) auto
-    show "measure_space (P\<lparr> measure := ?\<nu>\<rparr>)"
-      apply (rule Q.measure_space_vimage[OF P])
-      apply (simp_all)
-      apply (rule Q.pair_sigma_algebra_swap_measurable)
-    proof -
-      fix A assume "A \<in> sets P"
-      from sets_swap[OF this]
-      show "(\<integral>\<^isup>+ y. M1.\<mu> ((\<lambda>x. (x, y)) -` A) \<partial>M2) = Q.\<mu> ((\<lambda>(x, y). (y, x)) -` A \<inter> space (M2 \<Otimes>\<^isub>M M1))"
-        using sets_into_space[OF `A \<in> sets P`]
-        by (auto simp add: Q.pair_measure_alt space_pair_measure
-                 intro!: M2.positive_integral_cong arg_cong[where f="M1.\<mu>"])
-    qed
     fix X assume "X \<in> sets E"
-    then obtain A B where X: "X = A \<times> B" and AB: "A \<in> sets M1" "B \<in> sets M2"
+    then obtain A B where X[simp]: "X = A \<times> B" and AB: "A \<in> sets M1" "B \<in> sets M2"
       unfolding pair_measure_def pair_measure_generator_def by auto
-    show "\<mu> X = ?\<nu> X"
-    proof -
-      from AB have "?\<nu> (A \<times> B) = (\<integral>\<^isup>+y. M1.\<mu> A * indicator B y \<partial>M2)"
-        by (auto intro!: M2.positive_integral_cong)
-      with AB show ?thesis
-        unfolding pair_measure_times[OF AB] X
-        by (simp add: M2.positive_integral_cmult_indicator ac_simps)
-    qed
+    then have "(\<lambda>(y, x). (x, y)) -` X \<inter> space Q.P = B \<times> A"
+      using M1.sets_into_space M2.sets_into_space by (auto simp: space_pair_measure)
+    then show "\<mu> X = Q.\<mu> ((\<lambda>(y, x). (x, y)) -` X \<inter> space Q.P)"
+      using AB by (simp add: pair_measure_times Q.pair_measure_times ac_simps)
   qed
+  then show ?thesis
+    using sets_into_space[OF A] Q.pair_measure_alt[OF sets_swap[OF A]]
+    by (auto simp add: Q.pair_measure_alt space_pair_measure
+             intro!: M2.positive_integral_cong arg_cong[where f="M1.\<mu>"])
 qed
 
-
 lemma pair_sigma_algebra_sigma:
   assumes 1: "S1 \<up> (space E1)" "range S1 \<subseteq> sets E1" and E1: "sets E1 \<subseteq> Pow (space E1)"
   assumes 2: "S2 \<up> (space E2)" "range S2 \<subseteq> sets E2" and E2: "sets E2 \<subseteq> Pow (space E2)"
@@ -1559,8 +1548,8 @@
 lemma (in product_sigma_finite) measure_fold:
   assumes IJ[simp]: "I \<inter> J = {}" and fin: "finite I" "finite J"
   assumes A: "A \<in> sets (Pi\<^isub>M (I \<union> J) M)"
-  shows "measure (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M) ((\<lambda>(x,y). merge I x J y) -` A \<inter> space (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M)) =
-   measure (Pi\<^isub>M (I \<union> J) M) A"
+  shows "measure (Pi\<^isub>M (I \<union> J) M) A =
+    measure (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M) ((\<lambda>(x,y). merge I x J y) -` A \<inter> space (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M))"
 proof -
   interpret I: finite_product_sigma_finite M I by default fact
   interpret J: finite_product_sigma_finite M J by default fact
@@ -1575,10 +1564,12 @@
        "\<And>k. \<forall>i\<in>I\<union>J. \<mu> i (F i k) \<noteq> \<omega>"
     by auto
   let ?F = "\<lambda>k. \<Pi>\<^isub>E i\<in>I \<union> J. F i k"
-  show "P.\<mu> (?X A) = IJ.\<mu> A"
-  proof (rule measure_unique_Int_stable[where X=A])
-    show "A \<in> sets (sigma IJ.G)"
+  show "IJ.\<mu> A = P.\<mu> (?X A)"
+  proof (rule measure_unique_Int_stable_vimage)
+    show "measure_space IJ.P" "measure_space P.P" by default
+    show "sets (sigma IJ.G) = sets IJ.P" "space IJ.G = space IJ.P" "A \<in> sets (sigma IJ.G)"
       using A unfolding product_algebra_def by auto
+  next
     show "Int_stable IJ.G"
       by (simp add: PiE_Int Int_stable_def product_algebra_def
                     product_algebra_generator_def)
@@ -1587,25 +1578,17 @@
       by (simp add: image_subset_iff product_algebra_def
                     product_algebra_generator_def)
     show "?F \<up> space IJ.G " using F(2) by simp
-    have "measure_space IJ.P" by fact
-    also have "IJ.P = \<lparr> space = space IJ.G, sets = sets (sigma IJ.G), measure = IJ.\<mu> \<rparr>"
-      by (simp add: product_algebra_def)
-    finally show "measure_space \<dots>" .
-    let ?P = "\<lparr> space = space IJ.G, sets = sets (sigma IJ.G),
-                measure = \<lambda>A. P.\<mu> (?X A)\<rparr>"
-    have *: "?P = (sigma IJ.G \<lparr> measure := \<lambda>A. P.\<mu> (?X A) \<rparr>)"
-      by auto
-    have "sigma_algebra (sigma IJ.G \<lparr> measure := \<lambda>A. P.\<mu> (?X A) \<rparr>)"
-      by (rule IJ.sigma_algebra_cong) (auto simp: product_algebra_def)
-    then show "measure_space ?P" unfolding *
-      using measurable_merge[OF `I \<inter> J = {}`]
-      by (auto intro!: P.measure_space_vimage simp add: product_algebra_def)
+    show "\<And>k. IJ.\<mu> (?F k) \<noteq> \<omega>"
+      using `finite I` F
+      by (subst IJ.measure_times) (auto simp add: setprod_\<omega>)
+    show "?g \<in> measurable P.P IJ.P"
+      using IJ by (rule measurable_merge)
   next
     fix A assume "A \<in> sets IJ.G"
-    then obtain F where A[simp]: "A = Pi\<^isub>E (I \<union> J) F"
+    then obtain F where A: "A = Pi\<^isub>E (I \<union> J) F"
       and F: "\<And>i. i \<in> I \<union> J \<Longrightarrow> F i \<in> sets (M i)"
       by (auto simp: product_algebra_generator_def)
-    then have "?X A = (Pi\<^isub>E I F \<times> Pi\<^isub>E J F)"
+    then have X: "?X A = (Pi\<^isub>E I F \<times> Pi\<^isub>E J F)"
       using sets_into_space by (auto simp: space_pair_measure) blast+
     then have "P.\<mu> (?X A) = (\<Prod>i\<in>I. \<mu> i (F i)) * (\<Prod>i\<in>J. \<mu> i (F i))"
       using `finite J` `finite I` F
@@ -1615,16 +1598,7 @@
     also have "\<dots> = IJ.\<mu> A"
       using `finite J` `finite I` F unfolding A
       by (intro IJ.measure_times[symmetric]) auto
-    finally show "P.\<mu> (?X A) = IJ.\<mu> A" .
-  next
-    fix k
-    have k: "\<And>i. i \<in> I \<union> J \<Longrightarrow> F i k \<in> sets (M i)" using F by auto
-    then have "?X (?F k) = (\<Pi>\<^isub>E i\<in>I. F i k) \<times> (\<Pi>\<^isub>E i\<in>J. F i k)"
-      using sets_into_space by (auto simp: space_pair_measure) blast+
-    with k have "P.\<mu> (?X (?F k)) = (\<Prod>i\<in>I. \<mu> i (F i k)) * (\<Prod>i\<in>J. \<mu> i (F i k))"
-     by (simp add: P.pair_measure_times I.measure_times J.measure_times)
-    then show "P.\<mu> (?X (?F k)) \<noteq> \<omega>"
-      using `finite I` F by (simp add: setprod_\<omega>)
+    finally show "IJ.\<mu> A = P.\<mu> (?X A)" by (rule sym)
   qed
 qed
 
@@ -1751,7 +1725,7 @@
     have 1: "sigma_algebra IJ.P" by default
     have 2: "?M \<in> measurable P.P IJ.P" using measurable_merge[OF IJ] .
     have 3: "\<And>A. A \<in> sets IJ.P \<Longrightarrow> IJ.\<mu> A = P.\<mu> (?M -` A \<inter> space P.P)"
-      by (rule measure_fold[OF IJ fin, symmetric])
+      by (rule measure_fold[OF IJ fin])
     have 4: "integrable (Pi\<^isub>M (I \<union> J) M) f" by fact
     show "integrable P.P ?f"
       by (rule P.integral_vimage[where f=f, OF 1 2 3 4])