merged
authorhoelzl
Thu, 02 Dec 2010 15:32:48 +0100
changeset 40876 e2929572d5c7
parent 40868 177cd660abb7 (current diff)
parent 40875 9a9d33f6fb46 (diff)
child 40877 9e1136e8bb1f
child 40881 e84f82418e09
merged
--- a/src/HOL/Complete_Lattice.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Complete_Lattice.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -172,6 +172,18 @@
   "(\<And>m. m \<in> B \<Longrightarrow> \<exists>n\<in>A. f n \<le> g m) \<Longrightarrow> (INF n:A. f n) \<le> (INF n:B. g n)"
   by (force intro!: Inf_mono simp: INFI_def)
 
+lemma SUP_subset:  "A \<subseteq> B \<Longrightarrow> SUPR A f \<le> SUPR B f"
+  by (intro SUP_mono) auto
+
+lemma INF_subset:  "A \<subseteq> B \<Longrightarrow> INFI B f \<le> INFI A f"
+  by (intro INF_mono) auto
+
+lemma SUP_commute: "(SUP i:A. SUP j:B. f i j) = (SUP j:B. SUP i:A. f i j)"
+  by (iprover intro: SUP_leI le_SUPI order_trans antisym)
+
+lemma INF_commute: "(INF i:A. INF j:B. f i j) = (INF j:B. INF i:A. f i j)"
+  by (iprover intro: INF_leI le_INFI order_trans antisym)
+
 end
 
 lemma less_Sup_iff:
@@ -184,6 +196,16 @@
   shows "Inf S < a \<longleftrightarrow> (\<exists>x\<in>S. x < a)"
   unfolding not_le[symmetric] le_Inf_iff by auto
 
+lemma less_SUP_iff:
+  fixes a :: "'a::{complete_lattice,linorder}"
+  shows "a < (SUP i:A. f i) \<longleftrightarrow> (\<exists>x\<in>A. a < f x)"
+  unfolding SUPR_def less_Sup_iff by auto
+
+lemma INF_less_iff:
+  fixes a :: "'a::{complete_lattice,linorder}"
+  shows "(INF i:A. f i) < a \<longleftrightarrow> (\<exists>x\<in>A. f x < a)"
+  unfolding INFI_def Inf_less_iff by auto
+
 subsection {* @{typ bool} and @{typ "_ \<Rightarrow> _"} as complete lattice *}
 
 instantiation bool :: complete_lattice
--- a/src/HOL/Probability/Borel_Space.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Borel_Space.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -6,12 +6,6 @@
   imports Sigma_Algebra Positive_Infinite_Real Multivariate_Analysis
 begin
 
-lemma (in sigma_algebra) sets_sigma_subset:
-  assumes "space N = space M"
-  assumes "sets N \<subseteq> sets M"
-  shows "sets (sigma N) \<subseteq> sets M"
-  by (unfold assms sets_sigma, rule sigma_sets_subset, rule assms)
-
 lemma LIMSEQ_max:
   "u ----> (x::real) \<Longrightarrow> (\<lambda>i. max (u i) 0) ----> max x 0"
   by (fastsimp intro!: LIMSEQ_I dest!: LIMSEQ_D)
@@ -612,13 +606,10 @@
   then show ?thesis by (intro sets_sigma_subset) auto
 qed
 
-lemma algebra_eqI: assumes "sets A = sets (B::'a algebra)" "space A = space B"
-  shows "A = B" using assms by auto
-
 lemma borel_eq_atMost:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> a. {.. a::'a\<Colon>ordered_euclidean_space})\<rparr>)"
     (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using halfspace_le_span_atMost halfspace_span_halfspace_le open_span_halfspace
     by auto
@@ -629,7 +620,7 @@
 lemma borel_eq_atLeastAtMost:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a :: 'a\<Colon>ordered_euclidean_space, b). {a .. b})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using atMost_span_atLeastAtMost halfspace_le_span_atMost
       halfspace_span_halfspace_le open_span_halfspace
@@ -641,7 +632,7 @@
 lemma borel_eq_greaterThan:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a :: 'a\<Colon>ordered_euclidean_space). {a <..})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using halfspace_le_span_greaterThan
       halfspace_span_halfspace_le open_span_halfspace
@@ -653,7 +644,7 @@
 lemma borel_eq_lessThan:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a :: 'a\<Colon>ordered_euclidean_space). {..< a})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using halfspace_le_span_lessThan
       halfspace_span_halfspace_ge open_span_halfspace
@@ -665,7 +656,7 @@
 lemma borel_eq_greaterThanLessThan:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, b). {a <..< (b :: 'a \<Colon> ordered_euclidean_space)})\<rparr>)"
     (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets ?SIGMA \<subseteq> sets borel"
     by (rule borel.sets_sigma_subset) auto
   show "sets borel \<subseteq> sets ?SIGMA"
@@ -686,7 +677,7 @@
 lemma borel_eq_halfspace_le:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x$$i \<le> a})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using open_span_halfspace halfspace_span_halfspace_le by auto
   show "sets ?SIGMA \<subseteq> sets borel"
@@ -696,7 +687,7 @@
 lemma borel_eq_halfspace_less:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x$$i < a})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using open_span_halfspace .
   show "sets ?SIGMA \<subseteq> sets borel"
@@ -706,7 +697,7 @@
 lemma borel_eq_halfspace_gt:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. a < x$$i})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using halfspace_le_span_halfspace_gt open_span_halfspace halfspace_span_halfspace_le by auto
   show "sets ?SIGMA \<subseteq> sets borel"
@@ -716,7 +707,7 @@
 lemma borel_eq_halfspace_ge:
   "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. a \<le> x$$i})\<rparr>)"
    (is "_ = ?SIGMA")
-proof (rule algebra_eqI, rule antisym)
+proof (intro algebra.equality antisym)
   show "sets borel \<subseteq> sets ?SIGMA"
     using halfspace_span_halfspace_ge open_span_halfspace by auto
   show "sets ?SIGMA \<subseteq> sets borel"
@@ -1025,7 +1016,6 @@
   then obtain T x where T: "open T" "Real ` (T \<inter> {0..}) = B - {\<omega>}" and
     x: "\<omega> \<in> B \<Longrightarrow> 0 \<le> x" "\<omega> \<in> B \<Longrightarrow> {Real x <..} \<subseteq> B"
     unfolding open_pinfreal_def by blast
-
   have "Real -` B = Real -` (B - {\<omega>})" by auto
   also have "\<dots> = Real -` (Real ` (T \<inter> {0..}))" using T by simp
   also have "\<dots> = (if 0 \<in> T then T \<union> {.. 0} else T \<inter> {0..})"
@@ -1231,12 +1221,10 @@
   hence **: "\<forall>a. {x\<in>space M. f x < a} \<in> sets M"
     unfolding less_eq_le_pinfreal_measurable
     unfolding greater_eq_le_measurable .
-
   show "f \<in> borel_measurable M" unfolding borel_measurable_pinfreal_eq_real borel_measurable_iff_greater
   proof safe
     have "f -` {\<omega>} \<inter> space M = space M - {x\<in>space M. f x < \<omega>}" by auto
     then show \<omega>: "f -` {\<omega>} \<inter> space M \<in> sets M" using ** by auto
-
     fix a
     have "{w \<in> space M. a < real (f w)} =
       (if 0 \<le> a then {w\<in>space M. Real a < f w} - (f -` {\<omega>} \<inter> space M) else space M)"
@@ -1367,14 +1355,14 @@
     by induct auto
 qed (simp add: borel_measurable_const)
 
-lemma (in sigma_algebra) borel_measurable_pinfreal_min[intro, simp]:
+lemma (in sigma_algebra) borel_measurable_pinfreal_min[simp, intro]:
   fixes f g :: "'a \<Rightarrow> pinfreal"
   assumes "f \<in> borel_measurable M"
   assumes "g \<in> borel_measurable M"
   shows "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
   using assms unfolding min_def by (auto intro!: measurable_If)
 
-lemma (in sigma_algebra) borel_measurable_pinfreal_max[intro]:
+lemma (in sigma_algebra) borel_measurable_pinfreal_max[simp, intro]:
   fixes f g :: "'a \<Rightarrow> pinfreal"
   assumes "f \<in> borel_measurable M"
   and "g \<in> borel_measurable M"
@@ -1421,7 +1409,7 @@
     using assms by auto
 qed
 
-lemma (in sigma_algebra) borel_measurable_psuminf:
+lemma (in sigma_algebra) borel_measurable_psuminf[simp, intro]:
   assumes "\<And>i. f i \<in> borel_measurable M"
   shows "(\<lambda>x. (\<Sum>\<^isub>\<infinity> i. f i x)) \<in> borel_measurable M"
   using assms unfolding psuminf_def
@@ -1437,7 +1425,6 @@
 proof -
   let "?pu x i" = "max (u i x) 0"
   let "?nu x i" = "max (- u i x) 0"
-
   { fix x assume x: "x \<in> space M"
     have "(?pu x) ----> max (u' x) 0"
       "(?nu x) ----> max (- u' x) 0"
@@ -1447,10 +1434,8 @@
       "(SUP n. INF m. Real (- u (n + m) x)) = Real (- u' x)"
       by (simp_all add: Real_max'[symmetric]) }
   note eq = this
-
   have *: "\<And>x. real (Real (u' x)) - real (Real (- u' x)) = u' x"
     by auto
-
   have "(SUP n. INF m. (\<lambda>x. Real (u (n + m) x))) \<in> borel_measurable M"
        "(SUP n. INF m. (\<lambda>x. Real (- u (n + m) x))) \<in> borel_measurable M"
     using u by (auto intro: borel_measurable_SUP borel_measurable_INF borel_measurable_Real)
--- a/src/HOL/Probability/Complete_Measure.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Complete_Measure.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -189,56 +189,13 @@
   qed
 qed
 
-lemma (in sigma_algebra) simple_functionD':
-  assumes "simple_function f"
-  shows "f -` {x} \<inter> space M \<in> sets M"
-proof cases
-  assume "x \<in> f`space M" from simple_functionD(2)[OF assms this] show ?thesis .
-next
-  assume "x \<notin> f`space M" then have "f -` {x} \<inter> space M = {}" by auto
-  then show ?thesis by auto
-qed
-
-lemma (in sigma_algebra) simple_function_If:
-  assumes sf: "simple_function f" "simple_function g" and A: "A \<in> sets M"
-  shows "simple_function (\<lambda>x. if x \<in> A then f x else g x)" (is "simple_function ?IF")
-proof -
-  def F \<equiv> "\<lambda>x. f -` {x} \<inter> space M" and G \<equiv> "\<lambda>x. g -` {x} \<inter> space M"
-  show ?thesis unfolding simple_function_def
-  proof safe
-    have "?IF ` space M \<subseteq> f ` space M \<union> g ` space M" by auto
-    from finite_subset[OF this] assms
-    show "finite (?IF ` space M)" unfolding simple_function_def by auto
-  next
-    fix x assume "x \<in> space M"
-    then have *: "?IF -` {?IF x} \<inter> space M = (if x \<in> A
-      then ((F (f x) \<inter> A) \<union> (G (f x) - (G (f x) \<inter> A)))
-      else ((F (g x) \<inter> A) \<union> (G (g x) - (G (g x) \<inter> A))))"
-      using sets_into_space[OF A] by (auto split: split_if_asm simp: G_def F_def)
-    have [intro]: "\<And>x. F x \<in> sets M" "\<And>x. G x \<in> sets M"
-      unfolding F_def G_def using sf[THEN simple_functionD'] by auto
-    show "?IF -` {?IF x} \<inter> space M \<in> sets M" unfolding * using A by auto
-  qed
-qed
-
-lemma (in measure_space) null_sets_finite_UN:
-  assumes "finite S" "\<And>i. i \<in> S \<Longrightarrow> A i \<in> null_sets"
-  shows "(\<Union>i\<in>S. A i) \<in> null_sets"
-proof (intro CollectI conjI)
-  show "(\<Union>i\<in>S. A i) \<in> sets M" using assms by (intro finite_UN) auto
-  have "\<mu> (\<Union>i\<in>S. A i) \<le> (\<Sum>i\<in>S. \<mu> (A i))"
-    using assms by (intro measure_finitely_subadditive) auto
-  then show "\<mu> (\<Union>i\<in>S. A i) = 0"
-    using assms by auto
-qed
-
 lemma (in completeable_measure_space) completion_ex_simple_function:
   assumes f: "completion.simple_function f"
   shows "\<exists>f'. simple_function f' \<and> (AE x. f x = f' x)"
 proof -
   let "?F x" = "f -` {x} \<inter> space M"
   have F: "\<And>x. ?F x \<in> sets completion" and fin: "finite (f`space M)"
-    using completion.simple_functionD'[OF f]
+    using completion.simple_functionD[OF f]
       completion.simple_functionD[OF f] by simp_all
   have "\<forall>x. \<exists>N. N \<in> null_sets \<and> null_part (?F x) \<subseteq> N"
     using F null_part by auto
--- a/src/HOL/Probability/Lebesgue_Integration.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Lebesgue_Integration.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -6,20 +6,6 @@
 imports Measure Borel_Space
 begin
 
-lemma image_set_cong:
-  assumes A: "\<And>x. x \<in> A \<Longrightarrow> \<exists>y\<in>B. f x = g y"
-  assumes B: "\<And>y. y \<in> B \<Longrightarrow> \<exists>x\<in>A. g y = f x"
-  shows "f ` A = g ` B"
-proof safe
-  fix x assume "x \<in> A"
-  with A obtain y where "f x = g y" "y \<in> B" by auto
-  then show "f x \<in> g ` B" by auto
-next
-  fix y assume "y \<in> B"
-  with B obtain x where "g y = f x" "x \<in> A" by auto
-  then show "g y \<in> f ` A" by auto
-qed
-
 lemma sums_If_finite:
   assumes finite: "finite {r. P r}"
   shows "(\<lambda>r. if P r then f r else 0) sums (\<Sum>r\<in>{r. P r}. f r)" (is "?F sums _")
@@ -57,9 +43,15 @@
 
 lemma (in sigma_algebra) simple_functionD:
   assumes "simple_function g"
-  shows "finite (g ` space M)"
-  "x \<in> g ` space M \<Longrightarrow> g -` {x} \<inter> space M \<in> sets M"
-  using assms unfolding simple_function_def by auto
+  shows "finite (g ` space M)" and "g -` X \<inter> space M \<in> sets M"
+proof -
+  show "finite (g ` space M)"
+    using assms unfolding simple_function_def by auto
+  have "g -` X \<inter> space M = g -` (X \<inter> g`space M) \<inter> space M" by auto
+  also have "\<dots> = (\<Union>x\<in>X \<inter> g`space M. g-`{x} \<inter> space M)" by auto
+  finally show "g -` X \<inter> space M \<in> sets M" using assms
+    by (auto intro!: finite_UN simp del: UN_simps simp: simple_function_def)
+qed
 
 lemma (in sigma_algebra) simple_function_indicator_representation:
   fixes f ::"'a \<Rightarrow> pinfreal"
@@ -516,9 +508,7 @@
 proof -
   interpret v: measure_space M \<nu>
     by (rule measure_space_cong) fact
-  have "\<And>x. x \<in> space M \<Longrightarrow> f -` {f x} \<inter> space M \<in> sets M"
-    using `simple_function f`[THEN simple_functionD(2)] by auto
-  with assms show ?thesis
+  from simple_functionD[OF `simple_function f`] assms show ?thesis
     unfolding simple_integral_def v.simple_integral_def
     by (auto intro!: setsum_cong)
 qed
@@ -629,6 +619,28 @@
     by (auto simp: setsum_right_distrib field_simps intro!: setsum_cong)
 qed
 
+lemma (in sigma_algebra) simple_function_If:
+  assumes sf: "simple_function f" "simple_function g" and A: "A \<in> sets M"
+  shows "simple_function (\<lambda>x. if x \<in> A then f x else g x)" (is "simple_function ?IF")
+proof -
+  def F \<equiv> "\<lambda>x. f -` {x} \<inter> space M" and G \<equiv> "\<lambda>x. g -` {x} \<inter> space M"
+  show ?thesis unfolding simple_function_def
+  proof safe
+    have "?IF ` space M \<subseteq> f ` space M \<union> g ` space M" by auto
+    from finite_subset[OF this] assms
+    show "finite (?IF ` space M)" unfolding simple_function_def by auto
+  next
+    fix x assume "x \<in> space M"
+    then have *: "?IF -` {?IF x} \<inter> space M = (if x \<in> A
+      then ((F (f x) \<inter> A) \<union> (G (f x) - (G (f x) \<inter> A)))
+      else ((F (g x) \<inter> A) \<union> (G (g x) - (G (g x) \<inter> A))))"
+      using sets_into_space[OF A] by (auto split: split_if_asm simp: G_def F_def)
+    have [intro]: "\<And>x. F x \<in> sets M" "\<And>x. G x \<in> sets M"
+      unfolding F_def G_def using sf[THEN simple_functionD(2)] by auto
+    show "?IF -` {?IF x} \<inter> space M \<in> sets M" unfolding * using A by auto
+  qed
+qed
+
 lemma (in measure_space) simple_integral_mono_AE:
   assumes "simple_function f" and "simple_function g"
   and mono: "AE x. f x \<le> g x"
@@ -652,8 +664,8 @@
       obtain N where N: "{x\<in>space M. \<not> f x \<le> g x} \<subseteq> N" "N \<in> sets M" "\<mu> N = 0"
         using mono by (auto elim!: AE_E)
       have "?S x \<subseteq> N" using N `x \<in> space M` False by auto
-      moreover have "?S x \<in> sets M" using assms `x \<in> space M`
-        by (rule_tac Int) (auto intro!: simple_functionD(2))
+      moreover have "?S x \<in> sets M" using assms
+        by (rule_tac Int) (auto intro!: simple_functionD)
       ultimately have "\<mu> (?S x) \<le> \<mu> N"
         using `N \<in> sets M` by (auto intro!: measure_mono)
       then show ?thesis using `\<mu> N = 0` by auto
@@ -831,8 +843,67 @@
 section "Continuous posititve integration"
 
 definition (in measure_space)
+  "positive_integral f = SUPR {g. simple_function g \<and> g \<le> f} simple_integral"
+
+lemma (in measure_space) positive_integral_alt:
   "positive_integral f =
-    (SUP g : {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g`space M}. simple_integral g)"
+    (SUPR {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g`space M} simple_integral)" (is "_ = ?alt")
+proof (rule antisym SUP_leI)
+  show "positive_integral f \<le> ?alt" unfolding positive_integral_def
+  proof (safe intro!: SUP_leI)
+    fix g assume g: "simple_function g" "g \<le> f"
+    let ?G = "g -` {\<omega>} \<inter> space M"
+    show "simple_integral g \<le>
+      SUPR {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g ` space M} simple_integral"
+      (is "simple_integral g \<le> SUPR ?A simple_integral")
+    proof cases
+      let ?g = "\<lambda>x. indicator (space M - ?G) x * g x"
+      have g': "simple_function ?g"
+        using g by (auto intro: simple_functionD)
+      moreover
+      assume "\<mu> ?G = 0"
+      then have "AE x. g x = ?g x" using g
+        by (intro AE_I[where N="?G"])
+           (auto intro: simple_functionD simp: indicator_def)
+      with g(1) g' have "simple_integral g = simple_integral ?g"
+        by (rule simple_integral_cong_AE)
+      moreover have "?g \<le> g" by (auto simp: le_fun_def indicator_def)
+      from this `g \<le> f` have "?g \<le> f" by (rule order_trans)
+      moreover have "\<omega> \<notin> ?g ` space M"
+        by (auto simp: indicator_def split: split_if_asm)
+      ultimately show ?thesis by (auto intro!: le_SUPI)
+    next
+      assume "\<mu> ?G \<noteq> 0"
+      then have "?G \<noteq> {}" by auto
+      then have "\<omega> \<in> g`space M" by force
+      then have "space M \<noteq> {}" by auto
+      have "SUPR ?A simple_integral = \<omega>"
+      proof (intro SUP_\<omega>[THEN iffD2] allI impI)
+        fix x assume "x < \<omega>"
+        then guess n unfolding less_\<omega>_Ex_of_nat .. note n = this
+        then have "0 < n" by (intro neq0_conv[THEN iffD1] notI) simp
+        let ?g = "\<lambda>x. (of_nat n / (if \<mu> ?G = \<omega> then 1 else \<mu> ?G)) * indicator ?G x"
+        show "\<exists>i\<in>?A. x < simple_integral i"
+        proof (intro bexI impI CollectI conjI)
+          show "simple_function ?g" using g
+            by (auto intro!: simple_functionD simple_function_add)
+          have "?g \<le> g" by (auto simp: le_fun_def indicator_def)
+          from this g(2) show "?g \<le> f" by (rule order_trans)
+          show "\<omega> \<notin> ?g ` space M"
+            using `\<mu> ?G \<noteq> 0` by (auto simp: indicator_def split: split_if_asm)
+          have "x < (of_nat n / (if \<mu> ?G = \<omega> then 1 else \<mu> ?G)) * \<mu> ?G"
+            using n `\<mu> ?G \<noteq> 0` `0 < n`
+            by (auto simp: pinfreal_noteq_omega_Ex field_simps)
+          also have "\<dots> = simple_integral ?g" using g `space M \<noteq> {}`
+            by (subst simple_integral_indicator)
+               (auto simp: image_constant ac_simps dest: simple_functionD)
+          finally show "x < simple_integral ?g" .
+        qed
+      qed
+      then show ?thesis by simp
+    qed
+  qed
+qed (auto intro!: SUP_subset simp: positive_integral_def)
 
 lemma (in measure_space) positive_integral_cong_measure:
   assumes "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = \<mu> A"
@@ -849,7 +920,7 @@
 lemma (in measure_space) positive_integral_alt1:
   "positive_integral f =
     (SUP g : {g. simple_function g \<and> (\<forall>x\<in>space M. g x \<le> f x \<and> g x \<noteq> \<omega>)}. simple_integral g)"
-  unfolding positive_integral_def SUPR_def
+  unfolding positive_integral_alt SUPR_def
 proof (safe intro!: arg_cong[where f=Sup])
   fix g let ?g = "\<lambda>x. if x \<in> space M then g x else f x"
   assume "simple_function g" "\<forall>x\<in>space M. g x \<le> f x \<and> g x \<noteq> \<omega>"
@@ -866,75 +937,6 @@
     by auto
 qed
 
-lemma (in measure_space) positive_integral_alt:
-  "positive_integral f =
-    (SUP g : {g. simple_function g \<and> g \<le> f}. simple_integral g)"
-  apply(rule order_class.antisym) unfolding positive_integral_def 
-  apply(rule SUPR_subset) apply blast apply(rule SUPR_mono_lim)
-proof safe fix u assume u:"simple_function u" and uf:"u \<le> f"
-  let ?u = "\<lambda>n x. if u x = \<omega> then Real (real (n::nat)) else u x"
-  have su:"\<And>n. simple_function (?u n)" using simple_function_compose1[OF u] .
-  show "\<exists>b. \<forall>n. b n \<in> {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g ` space M} \<and>
-    (\<lambda>n. simple_integral (b n)) ----> simple_integral u"
-    apply(rule_tac x="?u" in exI, safe) apply(rule su)
-  proof- fix n::nat have "?u n \<le> u" unfolding le_fun_def by auto
-    also note uf finally show "?u n \<le> f" .
-    let ?s = "{x \<in> space M. u x = \<omega>}"
-    show "(\<lambda>n. simple_integral (?u n)) ----> simple_integral u"
-    proof(cases "\<mu> ?s = 0")
-      case True have *:"\<And>n. {x\<in>space M. ?u n x \<noteq> u x} = {x\<in>space M. u x = \<omega>}" by auto 
-      have *:"\<And>n. simple_integral (?u n) = simple_integral u"
-        apply(rule simple_integral_cong'[OF su u]) unfolding * True ..
-      show ?thesis unfolding * by auto 
-    next case False note m0=this
-      have s:"{x \<in> space M. u x = \<omega>} \<in> sets M" using u  by (auto simp: borel_measurable_simple_function)
-      have "\<omega> = simple_integral (\<lambda>x. \<omega> * indicator {x\<in>space M. u x = \<omega>} x)"
-        apply(subst simple_integral_mult) using s
-        unfolding simple_integral_indicator_only[OF s] using False by auto
-      also have "... \<le> simple_integral u"
-        apply (rule simple_integral_mono)
-        apply (rule simple_function_mult)
-        apply (rule simple_function_const)
-        apply(rule ) prefer 3 apply(subst indicator_def)
-        using s u by auto
-      finally have *:"simple_integral u = \<omega>" by auto
-      show ?thesis unfolding * Lim_omega_pos
-      proof safe case goal1
-        from real_arch_simple[of "B / real (\<mu> ?s)"] guess N0 .. note N=this
-        def N \<equiv> "Suc N0" have N:"real N \<ge> B / real (\<mu> ?s)" "N > 0"
-          unfolding N_def using N by auto
-        show ?case apply-apply(rule_tac x=N in exI,safe) 
-        proof- case goal1
-          have "Real B \<le> Real (real N) * \<mu> ?s"
-          proof(cases "\<mu> ?s = \<omega>")
-            case True thus ?thesis using `B>0` N by auto
-          next case False
-            have *:"B \<le> real N * real (\<mu> ?s)" 
-              using N(1) apply-apply(subst (asm) pos_divide_le_eq)
-              apply rule using m0 False by auto
-            show ?thesis apply(subst Real_real'[THEN sym,OF False])
-              apply(subst pinfreal_times,subst if_P) defer
-              apply(subst pinfreal_less_eq,subst if_P) defer
-              using * N `B>0` by(auto intro: mult_nonneg_nonneg)
-          qed
-          also have "... \<le> Real (real n) * \<mu> ?s"
-            apply(rule mult_right_mono) using goal1 by auto
-          also have "... = simple_integral (\<lambda>x. Real (real n) * indicator ?s x)" 
-            apply(subst simple_integral_mult) apply(rule simple_function_indicator[OF s])
-            unfolding simple_integral_indicator_only[OF s] ..
-          also have "... \<le> simple_integral (\<lambda>x. if u x = \<omega> then Real (real n) else u x)"
-            apply(rule simple_integral_mono) apply(rule simple_function_mult)
-            apply(rule simple_function_const)
-            apply(rule simple_function_indicator) apply(rule s su)+ by auto
-          finally show ?case .
-        qed qed qed
-    fix x assume x:"\<omega> = (if u x = \<omega> then Real (real n) else u x)" "x \<in> space M"
-    hence "u x = \<omega>" apply-apply(rule ccontr) by auto
-    hence "\<omega> = Real (real n)" using x by auto
-    thus False by auto
-  qed
-qed
-
 lemma (in measure_space) positive_integral_cong:
   assumes "\<And>x. x \<in> space M \<Longrightarrow> f x = g x"
   shows "positive_integral f = positive_integral g"
@@ -947,7 +949,7 @@
 lemma (in measure_space) positive_integral_eq_simple_integral:
   assumes "simple_function f"
   shows "positive_integral f = simple_integral f"
-  unfolding positive_integral_alt
+  unfolding positive_integral_def
 proof (safe intro!: pinfreal_SUPI)
   fix g assume "simple_function g" "g \<le> f"
   with assms show "simple_integral g \<le> simple_integral f"
@@ -1008,6 +1010,12 @@
   shows "positive_integral u \<le> positive_integral v"
   using mono by (auto intro!: AE_cong positive_integral_mono_AE)
 
+lemma image_set_cong:
+  assumes A: "\<And>x. x \<in> A \<Longrightarrow> \<exists>y\<in>B. f x = g y"
+  assumes B: "\<And>y. y \<in> B \<Longrightarrow> \<exists>x\<in>A. g y = f x"
+  shows "f ` A = g ` B"
+  using assms by blast
+
 lemma (in measure_space) positive_integral_vimage:
   fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
   assumes f: "bij_betw f S (space M)"
@@ -1020,14 +1028,12 @@
   from assms have inv: "bij_betw (the_inv_into S f) (space M) S"
     by (rule bij_betw_the_inv_into)
   then have inv_fun: "the_inv_into S f \<in> space M \<rightarrow> S" unfolding bij_betw_def by auto
-
   have surj: "f`S = space M"
     using f unfolding bij_betw_def by simp
   have inj: "inj_on f S"
     using f unfolding bij_betw_def by simp
   have inv_f: "\<And>x. x \<in> space M \<Longrightarrow> f (the_inv_into S f x) = x"
     using f_the_inv_into_f[of f S] f unfolding bij_betw_def by auto
-
   from simple_integral_vimage[OF assms, symmetric]
   have *: "simple_integral = T.simple_integral \<circ> (\<lambda>g. g \<circ> f)" by (simp add: comp_def)
   show ?thesis
@@ -1181,7 +1187,7 @@
       by (auto intro!: SUP_leI positive_integral_mono)
   next
     show "positive_integral u \<le> (SUP i. positive_integral (f i))"
-      unfolding positive_integral_def[of u]
+      unfolding positive_integral_alt[of u]
       by (auto intro!: SUP_leI positive_integral_SUP_approx[OF assms])
   qed
 qed
@@ -1194,7 +1200,6 @@
 proof -
   have "?u \<in> borel_measurable M"
     using borel_measurable_SUP[of _ f] assms by (simp add: SUPR_fun_expand)
-
   show ?thesis
   proof (rule antisym)
     show "(SUP j. positive_integral (f j)) \<le> positive_integral ?u"
@@ -1205,9 +1210,10 @@
       using assms by (simp cong: measurable_cong)
     moreover have iso: "rf \<up> ru" using assms unfolding rf_def ru_def
       unfolding isoton_def SUPR_fun_expand le_fun_def fun_eq_iff
+      using SUP_const[OF UNIV_not_empty]
       by (auto simp: restrict_def le_fun_def SUPR_fun_expand fun_eq_iff)
     ultimately have "positive_integral ru \<le> (SUP i. positive_integral (rf i))"
-      unfolding positive_integral_def[of ru]
+      unfolding positive_integral_alt[of ru]
       by (auto simp: le_fun_def intro!: SUP_leI positive_integral_SUP_approx)
     then show "positive_integral ?u \<le> (SUP i. positive_integral (f i))"
       unfolding ru_def rf_def by (simp cong: positive_integral_cong)
@@ -1523,19 +1529,18 @@
     apply (rule arg_cong[where f=Sup])
   proof (auto simp add: image_iff simple_integral_restricted[OF `A \<in> sets M`])
     fix g assume "simple_function (\<lambda>x. g x * indicator A x)"
-      "g \<le> f" "\<forall>x\<in>A. \<omega> \<noteq> g x"
-    then show "\<exists>x. simple_function x \<and> x \<le> (\<lambda>x. f x * indicator A x) \<and> (\<forall>y\<in>space M. \<omega> \<noteq> x y) \<and>
+      "g \<le> f"
+    then show "\<exists>x. simple_function x \<and> x \<le> (\<lambda>x. f x * indicator A x) \<and>
       simple_integral (\<lambda>x. g x * indicator A x) = simple_integral x"
       apply (rule_tac exI[of _ "\<lambda>x. g x * indicator A x"])
       by (auto simp: indicator_def le_fun_def)
   next
     fix g assume g: "simple_function g" "g \<le> (\<lambda>x. f x * indicator A x)"
-      "\<forall>x\<in>space M. \<omega> \<noteq> g x"
     then have *: "(\<lambda>x. g x * indicator A x) = g"
       "\<And>x. g x * indicator A x = g x"
       "\<And>x. g x \<le> f x"
       by (auto simp: le_fun_def fun_eq_iff indicator_def split: split_if_asm)
-    from g show "\<exists>x. simple_function (\<lambda>xa. x xa * indicator A xa) \<and> x \<le> f \<and> (\<forall>xa\<in>A. \<omega> \<noteq> x xa) \<and>
+    from g show "\<exists>x. simple_function (\<lambda>xa. x xa * indicator A xa) \<and> x \<le> f \<and>
       simple_integral g = simple_integral (\<lambda>xa. x xa * indicator A xa)"
       using `A \<in> sets M`[THEN sets_into_space]
       apply (rule_tac exI[of _ "\<lambda>x. g x * indicator A x"])
@@ -2299,7 +2304,7 @@
 qed
 
 lemma (in finite_measure_space) simple_function_finite[simp, intro]: "simple_function f"
-  unfolding simple_function_def sets_eq_Pow using finite_space by auto
+  unfolding simple_function_def using finite_space by auto
 
 lemma (in finite_measure_space) borel_measurable_finite[intro, simp]: "f \<in> borel_measurable M"
   by (auto intro: borel_measurable_simple_function)
@@ -2310,7 +2315,7 @@
   have *: "positive_integral f = positive_integral (\<lambda>x. \<Sum>y\<in>space M. f y * indicator {y} x)"
     by (auto intro!: positive_integral_cong simp add: indicator_def if_distrib setsum_cases[OF finite_space])
   show ?thesis unfolding * using borel_measurable_finite[of f]
-    by (simp add: positive_integral_setsum positive_integral_cmult_indicator sets_eq_Pow)
+    by (simp add: positive_integral_setsum positive_integral_cmult_indicator)
 qed
 
 lemma (in finite_measure_space) integral_finite_singleton:
@@ -2322,9 +2327,9 @@
     "positive_integral (\<lambda>x. Real (- f x)) = (\<Sum>x \<in> space M. Real (- f x) * \<mu> {x})"
     unfolding positive_integral_finite_eq_setsum by auto
   show "integrable f" using finite_space finite_measure
-    by (simp add: setsum_\<omega> integrable_def sets_eq_Pow)
+    by (simp add: setsum_\<omega> integrable_def)
   show ?I using finite_measure
-    apply (simp add: integral_def sets_eq_Pow real_of_pinfreal_setsum[symmetric]
+    apply (simp add: integral_def real_of_pinfreal_setsum[symmetric]
       real_of_pinfreal_mult[symmetric] setsum_subtractf[symmetric])
     by (rule setsum_cong) (simp_all split: split_if)
 qed
--- a/src/HOL/Probability/Lebesgue_Measure.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Lebesgue_Measure.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -4,89 +4,6 @@
   imports Product_Measure Gauge_Measure Complete_Measure
 begin
 
-lemma (in complete_lattice) SUP_pair:
-  "(SUP i:A. SUP j:B. f i j) = (SUP p:A\<times>B. (\<lambda> (i, j). f i j) p)" (is "?l = ?r")
-proof (intro antisym SUP_leI)
-  fix i j assume "i \<in> A" "j \<in> B"
-  then have "(case (i,j) of (i,j) \<Rightarrow> f i j) \<le> ?r"
-    by (intro SUPR_upper) auto
-  then show "f i j \<le> ?r" by auto
-next
-  fix p assume "p \<in> A \<times> B"
-  then obtain i j where "p = (i,j)" "i \<in> A" "j \<in> B" by auto
-  have "f i j \<le> (SUP j:B. f i j)" using `j \<in> B` by (intro SUPR_upper)
-  also have "(SUP j:B. f i j) \<le> ?l" using `i \<in> A` by (intro SUPR_upper)
-  finally show "(case p of (i, j) \<Rightarrow> f i j) \<le> ?l" using `p = (i,j)` by simp
-qed
-
-lemma (in complete_lattice) SUP_surj_compose:
-  assumes *: "f`A = B" shows "SUPR A (g \<circ> f) = SUPR B g"
-  unfolding SUPR_def unfolding *[symmetric]
-  by (simp add: image_compose)
-
-lemma (in complete_lattice) SUP_swap:
-  "(SUP i:A. SUP j:B. f i j) = (SUP j:B. SUP i:A. f i j)"
-proof -
-  have *: "(\<lambda>(i,j). (j,i)) ` (B \<times> A) = A \<times> B" by auto
-  show ?thesis
-    unfolding SUP_pair SUP_surj_compose[symmetric, OF *]
-    by (auto intro!: arg_cong[where f=Sup] image_eqI simp: comp_def SUPR_def)
-qed
-
-lemma SUP_\<omega>: "(SUP i:A. f i) = \<omega> \<longleftrightarrow> (\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)"
-proof
-  assume *: "(SUP i:A. f i) = \<omega>"
-  show "(\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)" unfolding *[symmetric]
-  proof (intro allI impI)
-    fix x assume "x < SUPR A f" then show "\<exists>i\<in>A. x < f i"
-      unfolding less_SUP_iff by auto
-  qed
-next
-  assume *: "\<forall>x<\<omega>. \<exists>i\<in>A. x < f i"
-  show "(SUP i:A. f i) = \<omega>"
-  proof (rule pinfreal_SUPI)
-    fix y assume **: "\<And>i. i \<in> A \<Longrightarrow> f i \<le> y"
-    show "\<omega> \<le> y"
-    proof cases
-      assume "y < \<omega>"
-      from *[THEN spec, THEN mp, OF this]
-      obtain i where "i \<in> A" "\<not> (f i \<le> y)" by auto
-      with ** show ?thesis by auto
-    qed auto
-  qed auto
-qed
-
-lemma psuminf_commute:
-  shows "(\<Sum>\<^isub>\<infinity> i j. f i j) = (\<Sum>\<^isub>\<infinity> j i. f i j)"
-proof -
-  have "(SUP n. \<Sum> i < n. SUP m. \<Sum> j < m. f i j) = (SUP n. SUP m. \<Sum> i < n. \<Sum> j < m. f i j)"
-    apply (subst SUPR_pinfreal_setsum)
-    by auto
-  also have "\<dots> = (SUP m n. \<Sum> j < m. \<Sum> i < n. f i j)"
-    apply (subst SUP_swap)
-    apply (subst setsum_commute)
-    by auto
-  also have "\<dots> = (SUP m. \<Sum> j < m. SUP n. \<Sum> i < n. f i j)"
-    apply (subst SUPR_pinfreal_setsum)
-    by auto
-  finally show ?thesis
-    unfolding psuminf_def by auto
-qed
-
-lemma psuminf_SUP_eq:
-  assumes "\<And>n i. f n i \<le> f (Suc n) i"
-  shows "(\<Sum>\<^isub>\<infinity> i. SUP n::nat. f n i) = (SUP n::nat. \<Sum>\<^isub>\<infinity> i. f n i)"
-proof -
-  { fix n :: nat
-    have "(\<Sum>i<n. SUP k. f k i) = (SUP k. \<Sum>i<n. f k i)"
-      using assms by (auto intro!: SUPR_pinfreal_setsum[symmetric]) }
-  note * = this
-  show ?thesis
-    unfolding psuminf_def
-    unfolding *
-    apply (subst SUP_swap) ..
-qed
-
 subsection {* Standard Cubes *}
 
 definition cube :: "nat \<Rightarrow> 'a::ordered_euclidean_space set" where
@@ -838,20 +755,6 @@
   qed
 qed
 
-lemma Real_mult_nonneg: assumes "x \<ge> 0" "y \<ge> 0"
-  shows "Real (x * y) = Real x * Real y" using assms by auto
-
-lemma Real_setprod: assumes "\<forall>x\<in>A. f x \<ge> 0" shows "Real (setprod f A) = setprod (\<lambda>x. Real (f x)) A"
-proof(cases "finite A")
-  case True thus ?thesis using assms
-  proof(induct A) case (insert x A)
-    have "0 \<le> setprod f A" apply(rule setprod_nonneg) using insert by auto
-    thus ?case unfolding setprod_insert[OF insert(1-2)] apply-
-      apply(subst Real_mult_nonneg) prefer 3 apply(subst insert(3)[THEN sym])
-      using insert by auto
-  qed auto
-qed auto
-
 lemma e2p_Int:"e2p ` A \<inter> e2p ` B = e2p ` (A \<inter> B)" (is "?L = ?R")
   apply(rule image_Int[THEN sym]) using bij_euclidean_component
   unfolding bij_betw_def by auto
--- a/src/HOL/Probability/Measure.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Measure.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -651,27 +651,6 @@
 
 abbreviation (in measure_space) "null_sets \<equiv> {N\<in>sets M. \<mu> N = 0}"
 
-definition (in measure_space)
-  almost_everywhere :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "AE " 10) where
-  "almost_everywhere P \<longleftrightarrow> (\<exists>N\<in>null_sets. { x \<in> space M. \<not> P x } \<subseteq> N)"
-
-lemma (in measure_space) AE_I':
-  "N \<in> null_sets \<Longrightarrow> {x\<in>space M. \<not> P x} \<subseteq> N \<Longrightarrow> (AE x. P x)"
-  unfolding almost_everywhere_def by auto
-
-lemma (in measure_space) AE_iff_null_set:
-  assumes "{x\<in>space M. \<not> P x} \<in> sets M" (is "?P \<in> sets M")
-  shows "(AE x. P x) \<longleftrightarrow> {x\<in>space M. \<not> P x} \<in> null_sets"
-proof
-  assume "AE x. P x" then obtain N where N: "N \<in> sets M" "?P \<subseteq> N" "\<mu> N = 0"
-    unfolding almost_everywhere_def by auto
-  moreover have "\<mu> ?P \<le> \<mu> N"
-    using assms N(1,2) by (auto intro: measure_mono)
-  ultimately show "?P \<in> null_sets" using assms by auto
-next
-  assume "?P \<in> null_sets" with assms show "AE x. P x" by (auto intro: AE_I')
-qed
-
 lemma (in measure_space) null_sets_Un[intro]:
   assumes "N \<in> null_sets" "N' \<in> null_sets"
   shows "N \<union> N' \<in> null_sets"
@@ -703,6 +682,17 @@
     using assms by auto
 qed
 
+lemma (in measure_space) null_sets_finite_UN:
+  assumes "finite S" "\<And>i. i \<in> S \<Longrightarrow> A i \<in> null_sets"
+  shows "(\<Union>i\<in>S. A i) \<in> null_sets"
+proof (intro CollectI conjI)
+  show "(\<Union>i\<in>S. A i) \<in> sets M" using assms by (intro finite_UN) auto
+  have "\<mu> (\<Union>i\<in>S. A i) \<le> (\<Sum>i\<in>S. \<mu> (A i))"
+    using assms by (intro measure_finitely_subadditive) auto
+  then show "\<mu> (\<Union>i\<in>S. A i) = 0"
+    using assms by auto
+qed
+
 lemma (in measure_space) null_set_Int1:
   assumes "B \<in> null_sets" "A \<in> sets M" shows "A \<inter> B \<in> null_sets"
 using assms proof (intro CollectI conjI)
@@ -741,6 +731,29 @@
     by (subst measure_additive[symmetric]) auto
 qed
 
+section "Formalise almost everywhere"
+
+definition (in measure_space)
+  almost_everywhere :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "AE " 10) where
+  "almost_everywhere P \<longleftrightarrow> (\<exists>N\<in>null_sets. { x \<in> space M. \<not> P x } \<subseteq> N)"
+
+lemma (in measure_space) AE_I':
+  "N \<in> null_sets \<Longrightarrow> {x\<in>space M. \<not> P x} \<subseteq> N \<Longrightarrow> (AE x. P x)"
+  unfolding almost_everywhere_def by auto
+
+lemma (in measure_space) AE_iff_null_set:
+  assumes "{x\<in>space M. \<not> P x} \<in> sets M" (is "?P \<in> sets M")
+  shows "(AE x. P x) \<longleftrightarrow> {x\<in>space M. \<not> P x} \<in> null_sets"
+proof
+  assume "AE x. P x" then obtain N where N: "N \<in> sets M" "?P \<subseteq> N" "\<mu> N = 0"
+    unfolding almost_everywhere_def by auto
+  moreover have "\<mu> ?P \<le> \<mu> N"
+    using assms N(1,2) by (auto intro: measure_mono)
+  ultimately show "?P \<in> null_sets" using assms by auto
+next
+  assume "?P \<in> null_sets" with assms show "AE x. P x" by (auto intro: AE_I')
+qed
+
 lemma (in measure_space) AE_True[intro, simp]: "AE x. True"
   unfolding almost_everywhere_def by auto
 
@@ -1409,7 +1422,7 @@
     show "\<mu> {x} \<noteq> \<omega>" by (auto simp: insert_absorb[OF *] Diff_subset) }
 qed
 
-sublocale finite_measure_space < finite_measure
+sublocale finite_measure_space \<subseteq> finite_measure
 proof
   show "\<mu> (space M) \<noteq> \<omega>"
     unfolding sum_over_space[symmetric] setsum_\<omega>
--- a/src/HOL/Probability/Positive_Infinite_Real.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Positive_Infinite_Real.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -6,14 +6,6 @@
   imports Complex_Main Nat_Bijection Multivariate_Analysis
 begin
 
-lemma range_const[simp]: "range (\<lambda>x. c) = {c}" by auto
-
-lemma (in complete_lattice) SUPR_const[simp]: "(SUP i. c) = c"
-  unfolding SUPR_def by simp
-
-lemma (in complete_lattice) INFI_const[simp]: "(INF i. c) = c"
-  unfolding INFI_def by simp
-
 lemma (in complete_lattice) Sup_start:
   assumes *: "\<And>x. f x \<le> f 0"
   shows "(SUP n. f n) = f 0"
@@ -94,6 +86,26 @@
   ultimately show ?thesis by simp
 qed
 
+lemma (in complete_lattice) lim_INF_le_lim_SUP:
+  fixes f :: "nat \<Rightarrow> 'a"
+  shows "(SUP n. INF m. f (n + m)) \<le> (INF n. SUP m. f (n + m))"
+proof (rule SUP_leI, rule le_INFI)
+  fix i j show "(INF m. f (i + m)) \<le> (SUP m. f (j + m))"
+  proof (cases rule: le_cases)
+    assume "i \<le> j"
+    have "(INF m. f (i + m)) \<le> f (i + (j - i))" by (rule INF_leI) simp
+    also have "\<dots> = f (j + 0)" using `i \<le> j` by auto
+    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
+    finally show ?thesis .
+  next
+    assume "j \<le> i"
+    have "(INF m. f (i + m)) \<le> f (i + 0)" by (rule INF_leI) simp
+    also have "\<dots> = f (j + (i - j))" using `j \<le> i` by auto
+    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
+    finally show ?thesis .
+  qed
+qed
+
 text {*
 
 We introduce the the positive real numbers as needed for measure theory.
@@ -348,6 +360,20 @@
 lemma real_of_pinfreal_mult: "real X * real Y = real (X * Y :: pinfreal)"
   by (cases X, cases Y) (auto simp: zero_le_mult_iff)
 
+lemma Real_mult_nonneg: assumes "x \<ge> 0" "y \<ge> 0"
+  shows "Real (x * y) = Real x * Real y" using assms by auto
+
+lemma Real_setprod: assumes "\<forall>x\<in>A. f x \<ge> 0" shows "Real (setprod f A) = setprod (\<lambda>x. Real (f x)) A"
+proof(cases "finite A")
+  case True thus ?thesis using assms
+  proof(induct A) case (insert x A)
+    have "0 \<le> setprod f A" apply(rule setprod_nonneg) using insert by auto
+    thus ?case unfolding setprod_insert[OF insert(1-2)] apply-
+      apply(subst Real_mult_nonneg) prefer 3 apply(subst insert(3)[THEN sym])
+      using insert by auto
+  qed auto
+qed auto
+
 subsection "@{typ pinfreal} is a linear order"
 
 instantiation pinfreal :: linorder
@@ -549,6 +575,14 @@
 lemma pinfreal_of_nat[simp]: "of_nat m = Real (real m)"
   by (induct m) (auto simp: real_of_nat_Suc one_pinfreal_def simp del: Real_1)
 
+lemma less_\<omega>_Ex_of_nat: "x < \<omega> \<longleftrightarrow> (\<exists>n. x < of_nat n)"
+proof safe
+  assume "x < \<omega>"
+  then obtain r where "0 \<le> r" "x = Real r" by (cases x) auto
+  moreover obtain n where "r < of_nat n" using ex_less_of_nat by auto
+  ultimately show "\<exists>n. x < of_nat n" by (auto simp: real_eq_of_nat)
+qed auto
+
 lemma real_of_pinfreal_mono:
   fixes a b :: pinfreal
   assumes "b \<noteq> \<omega>" "a \<le> b"
@@ -831,6 +865,29 @@
   qed simp
 qed simp
 
+lemma SUP_\<omega>: "(SUP i:A. f i) = \<omega> \<longleftrightarrow> (\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)"
+proof
+  assume *: "(SUP i:A. f i) = \<omega>"
+  show "(\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)" unfolding *[symmetric]
+  proof (intro allI impI)
+    fix x assume "x < SUPR A f" then show "\<exists>i\<in>A. x < f i"
+      unfolding less_SUP_iff by auto
+  qed
+next
+  assume *: "\<forall>x<\<omega>. \<exists>i\<in>A. x < f i"
+  show "(SUP i:A. f i) = \<omega>"
+  proof (rule pinfreal_SUPI)
+    fix y assume **: "\<And>i. i \<in> A \<Longrightarrow> f i \<le> y"
+    show "\<omega> \<le> y"
+    proof cases
+      assume "y < \<omega>"
+      from *[THEN spec, THEN mp, OF this]
+      obtain i where "i \<in> A" "\<not> (f i \<le> y)" by auto
+      with ** show ?thesis by auto
+    qed auto
+  qed auto
+qed
+
 subsubsection {* Equivalence between @{text "f ----> x"} and @{text SUP} on @{typ pinfreal} *}
 
 lemma monoseq_monoI: "mono f \<Longrightarrow> monoseq f"
@@ -1241,7 +1298,6 @@
   have [intro, simp]: "\<And>A. inj_on f A" using `bij f` unfolding bij_def by (auto intro: subset_inj_on)
   have f[intro, simp]: "\<And>x. f (inv f x) = x"
     using `bij f` unfolding bij_def by (auto intro: surj_f_inv_f)
-
   show ?thesis
   proof (rule psuminf_equality)
     fix n
@@ -1266,49 +1322,6 @@
   qed
 qed
 
-lemma psuminf_2dimen:
-  fixes f:: "nat * nat \<Rightarrow> pinfreal"
-  assumes fsums: "\<And>m. g m = (\<Sum>\<^isub>\<infinity> n. f (m,n))"
-  shows "psuminf (f \<circ> prod_decode) = psuminf g"
-proof (rule psuminf_equality)
-  fix n :: nat
-  let ?P = "prod_decode ` {..<n}"
-  have "setsum (f \<circ> prod_decode) {..<n} = setsum f ?P"
-    by (auto simp: setsum_reindex inj_prod_decode)
-  also have "\<dots> \<le> setsum f ({..Max (fst ` ?P)} \<times> {..Max (snd ` ?P)})"
-  proof (safe intro!: setsum_mono3 Max_ge image_eqI)
-    fix a b x assume "(a, b) = prod_decode x"
-    from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)"
-      by simp_all
-  qed simp_all
-  also have "\<dots> = (\<Sum>m\<le>Max (fst ` ?P). (\<Sum>n\<le>Max (snd ` ?P). f (m,n)))"
-    unfolding setsum_cartesian_product by simp
-  also have "\<dots> \<le> (\<Sum>m\<le>Max (fst ` ?P). g m)"
-    by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc
-        simp: fsums lessThan_Suc_atMost[symmetric])
-  also have "\<dots> \<le> psuminf g"
-    by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc
-        simp: lessThan_Suc_atMost[symmetric])
-  finally show "setsum (f \<circ> prod_decode) {..<n} \<le> psuminf g" .
-next
-  fix y assume *: "\<And>n. setsum (f \<circ> prod_decode) {..<n} \<le> y"
-  have g: "g = (\<lambda>m. \<Sum>\<^isub>\<infinity> n. f (m,n))" unfolding fsums[symmetric] ..
-  show "psuminf g \<le> y" unfolding g
-  proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound)
-    fix N M :: nat
-    let ?P = "{..<N} \<times> {..<M}"
-    let ?M = "Max (prod_encode ` ?P)"
-    have "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> (\<Sum>(m, n)\<in>?P. f (m, n))"
-      unfolding setsum_commute[of _ _ "{..<M}"] unfolding setsum_cartesian_product ..
-    also have "\<dots> \<le> (\<Sum>(m,n)\<in>(prod_decode ` {..?M}). f (m, n))"
-      by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]])
-    also have "\<dots> \<le> y" using *[of "Suc ?M"]
-      by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex
-               inj_prod_decode del: setsum_lessThan_Suc)
-    finally show "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> y" .
-  qed
-qed
-
 lemma pinfreal_mult_less_right:
   assumes "b * a < c * a" "0 < a" "a < \<omega>"
   shows "b < c"
@@ -1384,6 +1397,80 @@
   qed simp
 qed simp
 
+lemma psuminf_SUP_eq:
+  assumes "\<And>n i. f n i \<le> f (Suc n) i"
+  shows "(\<Sum>\<^isub>\<infinity> i. SUP n::nat. f n i) = (SUP n::nat. \<Sum>\<^isub>\<infinity> i. f n i)"
+proof -
+  { fix n :: nat
+    have "(\<Sum>i<n. SUP k. f k i) = (SUP k. \<Sum>i<n. f k i)"
+      using assms by (auto intro!: SUPR_pinfreal_setsum[symmetric]) }
+  note * = this
+  show ?thesis
+    unfolding psuminf_def
+    unfolding *
+    apply (subst SUP_commute) ..
+qed
+
+lemma psuminf_commute:
+  shows "(\<Sum>\<^isub>\<infinity> i j. f i j) = (\<Sum>\<^isub>\<infinity> j i. f i j)"
+proof -
+  have "(SUP n. \<Sum> i < n. SUP m. \<Sum> j < m. f i j) = (SUP n. SUP m. \<Sum> i < n. \<Sum> j < m. f i j)"
+    apply (subst SUPR_pinfreal_setsum)
+    by auto
+  also have "\<dots> = (SUP m n. \<Sum> j < m. \<Sum> i < n. f i j)"
+    apply (subst SUP_commute)
+    apply (subst setsum_commute)
+    by auto
+  also have "\<dots> = (SUP m. \<Sum> j < m. SUP n. \<Sum> i < n. f i j)"
+    apply (subst SUPR_pinfreal_setsum)
+    by auto
+  finally show ?thesis
+    unfolding psuminf_def by auto
+qed
+
+lemma psuminf_2dimen:
+  fixes f:: "nat * nat \<Rightarrow> pinfreal"
+  assumes fsums: "\<And>m. g m = (\<Sum>\<^isub>\<infinity> n. f (m,n))"
+  shows "psuminf (f \<circ> prod_decode) = psuminf g"
+proof (rule psuminf_equality)
+  fix n :: nat
+  let ?P = "prod_decode ` {..<n}"
+  have "setsum (f \<circ> prod_decode) {..<n} = setsum f ?P"
+    by (auto simp: setsum_reindex inj_prod_decode)
+  also have "\<dots> \<le> setsum f ({..Max (fst ` ?P)} \<times> {..Max (snd ` ?P)})"
+  proof (safe intro!: setsum_mono3 Max_ge image_eqI)
+    fix a b x assume "(a, b) = prod_decode x"
+    from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)"
+      by simp_all
+  qed simp_all
+  also have "\<dots> = (\<Sum>m\<le>Max (fst ` ?P). (\<Sum>n\<le>Max (snd ` ?P). f (m,n)))"
+    unfolding setsum_cartesian_product by simp
+  also have "\<dots> \<le> (\<Sum>m\<le>Max (fst ` ?P). g m)"
+    by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc
+        simp: fsums lessThan_Suc_atMost[symmetric])
+  also have "\<dots> \<le> psuminf g"
+    by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc
+        simp: lessThan_Suc_atMost[symmetric])
+  finally show "setsum (f \<circ> prod_decode) {..<n} \<le> psuminf g" .
+next
+  fix y assume *: "\<And>n. setsum (f \<circ> prod_decode) {..<n} \<le> y"
+  have g: "g = (\<lambda>m. \<Sum>\<^isub>\<infinity> n. f (m,n))" unfolding fsums[symmetric] ..
+  show "psuminf g \<le> y" unfolding g
+  proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound)
+    fix N M :: nat
+    let ?P = "{..<N} \<times> {..<M}"
+    let ?M = "Max (prod_encode ` ?P)"
+    have "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> (\<Sum>(m, n)\<in>?P. f (m, n))"
+      unfolding setsum_commute[of _ _ "{..<M}"] unfolding setsum_cartesian_product ..
+    also have "\<dots> \<le> (\<Sum>(m,n)\<in>(prod_decode ` {..?M}). f (m, n))"
+      by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]])
+    also have "\<dots> \<le> y" using *[of "Suc ?M"]
+      by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex
+               inj_prod_decode del: setsum_lessThan_Suc)
+    finally show "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> y" .
+  qed
+qed
+
 lemma Real_max:
   assumes "x \<ge> 0" "y \<ge> 0"
   shows "Real (max x y) = max (Real x) (Real y)"
@@ -2076,20 +2163,6 @@
 lemma real_Real_max:"real (Real x) = max x 0"
   unfolding real_Real by auto
 
-lemma (in complete_lattice) SUPR_upper:
-  "x \<in> A \<Longrightarrow> f x \<le> SUPR A f"
-  unfolding SUPR_def apply(rule Sup_upper) by auto
-
-lemma (in complete_lattice) SUPR_subset:
-  assumes "A \<subseteq> B" shows "SUPR A f \<le> SUPR B f"
-  apply(rule SUP_leI) apply(rule SUPR_upper) using assms by auto
-
-lemma (in complete_lattice) SUPR_mono:
-  assumes "\<forall>a\<in>A. \<exists>b\<in>B. f b \<ge> f a"
-  shows "SUPR A f \<le> SUPR B f"
-  unfolding SUPR_def apply(rule Sup_mono)
-  using assms by auto
-
 lemma Sup_lim:
   assumes "\<forall>n. b n \<in> s" "b ----> (a::pinfreal)"
   shows "a \<le> Sup s"
@@ -2161,11 +2234,6 @@
       unfolding Real_real using om by auto
   qed qed
 
-lemma less_SUP_iff:
-  fixes a :: pinfreal
-  shows "(a < (SUP i:A. f i)) \<longleftrightarrow> (\<exists>x\<in>A. a < f x)"
-  unfolding SUPR_def less_Sup_iff by auto
-
 lemma Sup_mono_lim:
   assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> b ----> (a::pinfreal)"
   shows "Sup A \<le> Sup B"
@@ -2371,26 +2439,6 @@
   shows "a \<le> a - b \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> a \<noteq> \<omega> \<Longrightarrow> b = 0"
   by (cases a, cases b, auto split: split_if_asm)
 
-lemma lim_INF_le_lim_SUP:
-  fixes f :: "nat \<Rightarrow> pinfreal"
-  shows "(SUP n. INF m. f (n + m)) \<le> (INF n. SUP m. f (n + m))"
-proof (rule complete_lattice_class.SUP_leI, rule complete_lattice_class.le_INFI)
-  fix i j show "(INF m. f (i + m)) \<le> (SUP m. f (j + m))"
-  proof (cases rule: le_cases)
-    assume "i \<le> j"
-    have "(INF m. f (i + m)) \<le> f (i + (j - i))" by (rule INF_leI) simp
-    also have "\<dots> = f (j + 0)" using `i \<le> j` by auto
-    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
-    finally show ?thesis .
-  next
-    assume "j \<le> i"
-    have "(INF m. f (i + m)) \<le> f (i + 0)" by (rule INF_leI) simp
-    also have "\<dots> = f (j + (i - j))" using `j \<le> i` by auto
-    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
-    finally show ?thesis .
-  qed
-qed
-
 lemma lim_INF_eq_lim_SUP:
   fixes X :: "nat \<Rightarrow> real"
   assumes "\<And>i. 0 \<le> X i" and "0 \<le> x"
@@ -2707,4 +2755,21 @@
 
 lemma lessThan_0_Empty: "{..< 0 :: pinfreal} = {}" by auto
 
+lemma real_of_pinfreal_inverse[simp]:
+  fixes X :: pinfreal
+  shows "real (inverse X) = 1 / real X"
+  by (cases X) (auto simp: inverse_eq_divide)
+
+lemma real_of_pinfreal_le_0[simp]: "real (X :: pinfreal) \<le> 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
+  by (cases X) auto
+
+lemma real_of_pinfreal_less_0[simp]: "\<not> (real (X :: pinfreal) < 0)"
+  by (cases X) auto
+
+lemma abs_real_of_pinfreal[simp]: "\<bar>real (X :: pinfreal)\<bar> = real X"
+  by simp
+
+lemma zero_less_real_of_pinfreal: "0 < real (X :: pinfreal) \<longleftrightarrow> X \<noteq> 0 \<and> X \<noteq> \<omega>"
+  by (cases X) auto
+
 end
--- a/src/HOL/Probability/Product_Measure.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Product_Measure.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -2,28 +2,6 @@
 imports Lebesgue_Integration
 begin
 
-lemma in_sigma[intro, simp]: "A \<in> sets M \<Longrightarrow> A \<in> sets (sigma M)"
-  unfolding sigma_def by (auto intro!: sigma_sets.Basic)
-
-lemma (in sigma_algebra) sigma_eq[simp]: "sigma M = M"
-  unfolding sigma_def sigma_sets_eq by simp
-
-lemma vimage_algebra_sigma:
-  assumes E: "sets E \<subseteq> Pow (space E)"
-    and f: "f \<in> space F \<rightarrow> space E"
-    and "\<And>A. A \<in> sets F \<Longrightarrow> A \<in> (\<lambda>X. f -` X \<inter> space F) ` sets E"
-    and "\<And>A. A \<in> sets E \<Longrightarrow> f -` A \<inter> space F \<in> sets F"
-  shows "sigma_algebra.vimage_algebra (sigma E) (space F) f = sigma F"
-proof -
-  interpret sigma_algebra "sigma E"
-    using assms by (intro sigma_algebra_sigma) auto
-  have eq: "sets F = (\<lambda>X. f -` X \<inter> space F) ` sets E"
-    using assms by auto
-  show "vimage_algebra (space F) f = sigma F"
-    unfolding vimage_algebra_def using assms
-    by (simp add: sigma_def eq sigma_sets_vimage)
-qed
-
 lemma times_Int_times: "A \<times> B \<inter> C \<times> D = (A \<inter> C) \<times> (B \<inter> D)"
   by auto
 
@@ -786,13 +764,10 @@
       positive_integral f"
 proof -
   interpret Q: pair_sigma_finite M2 \<mu>2 M1 \<mu>1 by default
-
   have s: "\<And>x y. (case (x, y) of (x, y) \<Rightarrow> f (y, x)) = f (y, x)" by simp
   have t: "(\<lambda>x. f (case x of (x, y) \<Rightarrow> (y, x))) = (\<lambda>(x, y). f (y, x))" by (auto simp: fun_eq_iff)
-
   have bij: "bij_betw (\<lambda>(x, y). (y, x)) (space M2 \<times> space M1) (space P)"
     by (auto intro!: inj_onI simp: space_pair_algebra bij_betw_def)
-
   note pair_sigma_algebra_measurable[OF f]
   from Q.positive_integral_fst_measurable[OF this]
   have "M2.positive_integral (\<lambda>y. M1.positive_integral (\<lambda>x. f (x, y))) =
@@ -890,7 +865,7 @@
 
 lemma (in finite_product_sigma_algebra) P_empty:
   "I = {} \<Longrightarrow> P = \<lparr> space = {\<lambda>k. undefined}, sets = { {}, {\<lambda>k. undefined} }\<rparr>"
-  unfolding product_algebra_def by (simp add: sigma_def)
+  unfolding product_algebra_def by (simp add: sigma_def image_constant)
 
 lemma (in finite_product_sigma_algebra) in_P[simp, intro]:
   "\<lbrakk> \<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i) \<rbrakk> \<Longrightarrow> Pi\<^isub>E I A \<in> sets P"
@@ -930,7 +905,6 @@
     using E1 E2 by (auto simp add: pair_algebra_def)
   interpret E: sigma_algebra ?E unfolding pair_algebra_def
     using E1 E2 by (intro sigma_algebra_sigma) auto
-
   { fix A assume "A \<in> sets E1"
     then have "fst -` A \<inter> space ?E = A \<times> (\<Union>i. S2 i)"
       using E1 2 unfolding isoton_def pair_algebra_def by auto
@@ -954,7 +928,6 @@
     "fst \<in> measurable ?E (sigma E1) \<and> snd \<in> measurable ?E (sigma E2)"
     using E1 E2 by (subst (1 2) E.measurable_iff_sigma)
                    (auto simp: pair_algebra_def sets_sigma)
-
   { fix A B assume A: "A \<in> sets (sigma E1)" and B: "B \<in> sets (sigma E2)"
     with proj have "fst -` A \<inter> space ?E \<in> sets ?E" "snd -` B \<inter> space ?E \<in> sets ?E"
       unfolding measurable_def by simp_all
@@ -966,7 +939,6 @@
     by (intro E.sigma_sets_subset) (auto simp add: pair_algebra_def sets_sigma)
   then have subset: "sets ?S \<subseteq> sets ?E"
     by (simp add: sets_sigma pair_algebra_def)
-
   have "sets ?S = sets ?E"
   proof (intro set_eqI iffI)
     fix A assume "A \<in> sets ?E" then show "A \<in> sets ?S"
@@ -1286,7 +1258,7 @@
     by (auto intro!: exI[of _ "\<lambda>A. if A = {} then 0 else 1"] sigma_algebra_sigma
                      sigma_algebra.finite_additivity_sufficient
              simp add: positive_def additive_def sets_sigma sigma_finite_measure_def
-                       sigma_finite_measure_axioms_def)
+                       sigma_finite_measure_axioms_def image_constant)
 next
   case (insert i I)
   interpret finite_product_sigma_finite M \<mu> I by default fact
@@ -1304,7 +1276,6 @@
     unfolding product_singleton_vimage_algebra_eq[OF `i \<notin> I` `finite I`, symmetric]
     using bij_betw_restrict_I_i[OF `i \<notin> I`, of M]
     by (intro P.measure_space_isomorphic) auto
-
   show ?case
   proof (intro exI[of _ ?\<nu>] conjI ballI)
     { fix A assume A: "A \<in> (\<Pi> i\<in>insert i I. sets (M i))"
@@ -1322,7 +1293,6 @@
         apply fastsimp
         using `i \<notin> I` `finite I` prod[of A] by (auto simp: ac_simps) }
     note product = this
-
     show "sigma_finite_measure I'.P ?\<nu>"
     proof
       from I'.sigma_finite_pairs guess F :: "'i \<Rightarrow> nat \<Rightarrow> 'a set" ..
@@ -1395,7 +1365,7 @@
   have "\<And>A. measure (Pi\<^isub>E {} A) = 1"
     using assms by (subst measure_times) auto
   then show ?thesis
-    unfolding positive_integral_alt simple_function_def simple_integral_def_raw
+    unfolding positive_integral_def simple_function_def simple_integral_def_raw
   proof (simp add: P_empty, intro antisym)
     show "f (\<lambda>k. undefined) \<le> (SUP f:{g. g \<le> f}. f (\<lambda>k. undefined))"
       by (intro le_SUPI) auto
@@ -1455,17 +1425,13 @@
   have "finite (I \<union> J)" using fin by auto
   interpret IJ: finite_product_sigma_finite M \<mu> "I \<union> J" by default fact
   interpret P: pair_sigma_finite I.P I.measure J.P J.measure by default
-
   let ?f = "\<lambda>x. ((\<lambda>i\<in>I. x i), (\<lambda>i\<in>J. x i))"
-
   have P_borel: "(\<lambda>x. f (case x of (x, y) \<Rightarrow> merge I x J y)) \<in> borel_measurable P.P"
     by (subst product_product_vimage_algebra_eq[OF IJ fin, symmetric])
        (auto simp: space_pair_algebra intro!: IJ.measurable_vimage f)
-
   have split_f_image[simp]: "\<And>F. ?f ` (Pi\<^isub>E (I \<union> J) F) = (Pi\<^isub>E I F) \<times> (Pi\<^isub>E J F)"
     apply auto apply (rule_tac x="merge I a J b" in image_eqI)
     by (auto dest: extensional_restrict)
-
   have "IJ.positive_integral f =  IJ.positive_integral (\<lambda>x. f (restrict x (I \<union> J)))"
     by (auto intro!: IJ.positive_integral_cong arg_cong[where f=f] dest!: extensional_restrict)
   also have "\<dots> = I.positive_integral (\<lambda>x. J.positive_integral (\<lambda>y. f (merge I x J y)))"
--- a/src/HOL/Probability/Radon_Nikodym.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Radon_Nikodym.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -69,6 +69,8 @@
   qed
 qed
 
+subsection "Absolutely continuous"
+
 definition (in measure_space)
   "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: pinfreal))"
 
@@ -111,6 +113,14 @@
   finally show "\<nu> N = 0" .
 qed
 
+lemma (in measure_space) density_is_absolutely_continuous:
+  assumes "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
+  shows "absolutely_continuous \<nu>"
+  using assms unfolding absolutely_continuous_def
+  by (simp add: positive_integral_null_set)
+
+subsection "Existence of the Radon-Nikodym derivative"
+
 lemma (in finite_measure) Radon_Nikodym_aux_epsilon:
   fixes e :: real assumes "0 < e"
   assumes "finite_measure M s"
@@ -120,21 +130,17 @@
 proof -
   let "?d A" = "real (\<mu> A) - real (s A)"
   interpret M': finite_measure M s by fact
-
   let "?A A" = "if (\<forall>B\<in>sets M. B \<subseteq> space M - A \<longrightarrow> -e < ?d B)
     then {}
     else (SOME B. B \<in> sets M \<and> B \<subseteq> space M - A \<and> ?d B \<le> -e)"
   def A \<equiv> "\<lambda>n. ((\<lambda>B. B \<union> ?A B) ^^ n) {}"
-
   have A_simps[simp]:
     "A 0 = {}"
     "\<And>n. A (Suc n) = (A n \<union> ?A (A n))" unfolding A_def by simp_all
-
   { fix A assume "A \<in> sets M"
     have "?A A \<in> sets M"
       by (auto intro!: someI2[of _ _ "\<lambda>A. A \<in> sets M"] simp: not_less) }
   note A'_in_sets = this
-
   { fix n have "A n \<in> sets M"
     proof (induct n)
       case (Suc n) thus "A (Suc n) \<in> sets M"
@@ -142,7 +148,6 @@
     qed (simp add: A_def) }
   note A_in_sets = this
   hence "range A \<subseteq> sets M" by auto
-
   { fix n B
     assume Ex: "\<exists>B. B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> -e"
     hence False: "\<not> (\<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B)" by (auto simp: not_less)
@@ -156,7 +161,6 @@
       finally show "?d (A n \<union> B) \<le> ?d (A n) - e" .
     qed }
   note dA_epsilon = this
-
   { fix n have "?d (A (Suc n)) \<le> ?d (A n)"
     proof (cases "\<exists>B. B\<in>sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e")
       case True from dA_epsilon[OF this] show ?thesis using `0 < e` by simp
@@ -166,7 +170,6 @@
       thus ?thesis by simp
     qed }
   note dA_mono = this
-
   show ?thesis
   proof (cases "\<exists>n. \<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B")
     case True then obtain n where B: "\<And>B. \<lbrakk> B \<in> sets M; B \<subseteq> space M - A n\<rbrakk> \<Longrightarrow> -e < ?d B" by blast
@@ -220,11 +223,8 @@
 proof -
   let "?d A" = "real (\<mu> A) - real (s A)"
   let "?P A B n" = "A \<in> sets M \<and> A \<subseteq> B \<and> ?d B \<le> ?d A \<and> (\<forall>C\<in>sets M. C \<subseteq> A \<longrightarrow> - 1 / real (Suc n) < ?d C)"
-
   interpret M': finite_measure M s by fact
-
   let "?r S" = "restricted_space S"
-
   { fix S n
     assume S: "S \<in> sets M"
     hence **: "\<And>X. X \<in> op \<inter> S ` sets M \<longleftrightarrow> X \<in> sets M \<and> X \<subseteq> S" by auto
@@ -242,11 +242,9 @@
     qed
     hence "\<exists>A. ?P A S n" by auto }
   note Ex_P = this
-
   def A \<equiv> "nat_rec (space M) (\<lambda>n A. SOME B. ?P B A n)"
   have A_Suc: "\<And>n. A (Suc n) = (SOME B. ?P B (A n) n)" by (simp add: A_def)
   have A_0[simp]: "A 0 = space M" unfolding A_def by simp
-
   { fix i have "A i \<in> sets M" unfolding A_def
     proof (induct i)
       case (Suc i)
@@ -254,19 +252,15 @@
         by (rule someI2_ex) simp
     qed simp }
   note A_in_sets = this
-
   { fix n have "?P (A (Suc n)) (A n) n"
       using Ex_P[OF A_in_sets] unfolding A_Suc
       by (rule someI2_ex) simp }
   note P_A = this
-
   have "range A \<subseteq> sets M" using A_in_sets by auto
-
   have A_mono: "\<And>i. A (Suc i) \<subseteq> A i" using P_A by simp
   have mono_dA: "mono (\<lambda>i. ?d (A i))" using P_A by (simp add: mono_iff_le_Suc)
   have epsilon: "\<And>C i. \<lbrakk> C \<in> sets M; C \<subseteq> A (Suc i) \<rbrakk> \<Longrightarrow> - 1 / real (Suc i) < ?d C"
       using P_A by auto
-
   show ?thesis
   proof (safe intro!: bexI[of _ "\<Inter>i. A i"])
     show "(\<Inter>i. A i) \<in> sets M" using A_in_sets by auto
@@ -298,24 +292,19 @@
   shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
 proof -
   interpret M': finite_measure M \<nu> using assms(1) .
-
   def G \<equiv> "{g \<in> borel_measurable M. \<forall>A\<in>sets M. positive_integral (\<lambda>x. g x * indicator A x) \<le> \<nu> A}"
   have "(\<lambda>x. 0) \<in> G" unfolding G_def by auto
   hence "G \<noteq> {}" by auto
-
   { fix f g assume f: "f \<in> G" and g: "g \<in> G"
     have "(\<lambda>x. max (g x) (f x)) \<in> G" (is "?max \<in> G") unfolding G_def
     proof safe
       show "?max \<in> borel_measurable M" using f g unfolding G_def by auto
-
       let ?A = "{x \<in> space M. f x \<le> g x}"
       have "?A \<in> sets M" using f g unfolding G_def by auto
-
       fix A assume "A \<in> sets M"
       hence sets: "?A \<inter> A \<in> sets M" "(space M - ?A) \<inter> A \<in> sets M" using `?A \<in> sets M` by auto
       have union: "((?A \<inter> A) \<union> ((space M - ?A) \<inter> A)) = A"
         using sets_into_space[OF `A \<in> sets M`] by auto
-
       have "\<And>x. x \<in> space M \<Longrightarrow> max (g x) (f x) * indicator A x =
         g x * indicator (?A \<inter> A) x + f x * indicator ((space M - ?A) \<inter> A) x"
         by (auto simp: indicator_def max_def)
@@ -331,14 +320,12 @@
       finally show "positive_integral (\<lambda>x. max (g x) (f x) * indicator A x) \<le> \<nu> A" .
     qed }
   note max_in_G = this
-
   { fix f g assume  "f \<up> g" and f: "\<And>i. f i \<in> G"
     have "g \<in> G" unfolding G_def
     proof safe
       from `f \<up> g` have [simp]: "g = (SUP i. f i)" unfolding isoton_def by simp
       have f_borel: "\<And>i. f i \<in> borel_measurable M" using f unfolding G_def by simp
       thus "g \<in> borel_measurable M" by (auto intro!: borel_measurable_SUP)
-
       fix A assume "A \<in> sets M"
       hence "\<And>i. (\<lambda>x. f i x * indicator A x) \<in> borel_measurable M"
         using f_borel by (auto intro!: borel_measurable_indicator)
@@ -350,7 +337,6 @@
         using f `A \<in> sets M` unfolding G_def by (auto intro!: SUP_leI)
     qed }
   note SUP_in_G = this
-
   let ?y = "SUP g : G. positive_integral g"
   have "?y \<le> \<nu> (space M)" unfolding G_def
   proof (safe intro!: SUP_leI)
@@ -385,7 +371,6 @@
   hence isoton_g: "?g \<up> f" by (simp add: isoton_def le_fun_def f_def)
   from SUP_in_G[OF this g_in_G] have "f \<in> G" .
   hence [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
-
   have "(\<lambda>i. positive_integral (?g i)) \<up> positive_integral f"
     using isoton_g g_in_G by (auto intro!: positive_integral_isoton simp: G_def f_def)
   hence "positive_integral f = (SUP i. positive_integral (?g i))"
@@ -398,9 +383,7 @@
       by (auto intro!: SUP_mono positive_integral_mono Max_ge)
   qed
   finally have int_f_eq_y: "positive_integral f = ?y" .
-
   let "?t A" = "\<nu> A - positive_integral (\<lambda>x. f x * indicator A x)"
-
   have "finite_measure M ?t"
   proof
     show "?t {} = 0" by simp
@@ -435,9 +418,7 @@
     qed
   qed
   then interpret M: finite_measure M ?t .
-
   have ac: "absolutely_continuous ?t" using `absolutely_continuous \<nu>` unfolding absolutely_continuous_def by auto
-
   have upper_bound: "\<forall>A\<in>sets M. ?t A \<le> 0"
   proof (rule ccontr)
     assume "\<not> ?thesis"
@@ -460,7 +441,6 @@
     ultimately have b: "b \<noteq> 0" "b \<noteq> \<omega>"
       using M'.finite_measure_of_space
       by (auto simp: pinfreal_inverse_eq_0 finite_measure_of_space)
-
     have "finite_measure M (\<lambda>A. b * \<mu> A)" (is "finite_measure M ?b")
     proof
       show "?b {} = 0" by simp
@@ -469,7 +449,6 @@
         unfolding countably_additive_def psuminf_cmult_right
         using measure_countably_additive by auto
     qed
-
     from M.Radon_Nikodym_aux[OF this]
     obtain A0 where "A0 \<in> sets M" and
       space_less_A0: "real (?t (space M)) - real (b * \<mu> (space M)) \<le> real (?t A0) - real (b * \<mu> A0)" and
@@ -479,9 +458,7 @@
         using M'.finite_measure b finite_measure
         by (cases "b * \<mu> B", cases "?t B") (auto simp: field_simps) }
     note bM_le_t = this
-
     let "?f0 x" = "f x + b * indicator A0 x"
-
     { fix A assume A: "A \<in> sets M"
       hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
       have "positive_integral (\<lambda>x. ?f0 x  * indicator A x) =
@@ -492,7 +469,6 @@
         using `A0 \<in> sets M` `A \<inter> A0 \<in> sets M` A
         by (simp add: borel_measurable_indicator positive_integral_add positive_integral_cmult_indicator) }
     note f0_eq = this
-
     { fix A assume A: "A \<in> sets M"
       hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
       have f_le_v: "positive_integral (\<lambda>x. f x * indicator A x) \<le> \<nu> A"
@@ -511,18 +487,15 @@
       finally have "positive_integral (\<lambda>x. ?f0 x * indicator A x) \<le> \<nu> A" . }
     hence "?f0 \<in> G" using `A0 \<in> sets M` unfolding G_def
       by (auto intro!: borel_measurable_indicator borel_measurable_pinfreal_add borel_measurable_pinfreal_times)
-
     have real: "?t (space M) \<noteq> \<omega>" "?t A0 \<noteq> \<omega>"
       "b * \<mu> (space M) \<noteq> \<omega>" "b * \<mu> A0 \<noteq> \<omega>"
       using `A0 \<in> sets M` b
         finite_measure[of A0] M.finite_measure[of A0]
         finite_measure_of_space M.finite_measure_of_space
       by auto
-
     have int_f_finite: "positive_integral f \<noteq> \<omega>"
       using M'.finite_measure_of_space pos_t unfolding pinfreal_zero_less_diff_iff
       by (auto cong: positive_integral_cong)
-
     have "?t (space M) > b * \<mu> (space M)" unfolding b_def
       apply (simp add: field_simps)
       apply (subst mult_assoc[symmetric])
@@ -539,18 +512,15 @@
     hence "0 < \<mu> A0" using ac unfolding absolutely_continuous_def
       using `A0 \<in> sets M` by auto
     hence "0 < b * \<mu> A0" using b by auto
-
     from int_f_finite this
     have "?y + 0 < positive_integral f + b * \<mu> A0" unfolding int_f_eq_y
       by (rule pinfreal_less_add)
     also have "\<dots> = positive_integral ?f0" using f0_eq[OF top] `A0 \<in> sets M` sets_into_space
       by (simp cong: positive_integral_cong)
     finally have "?y < positive_integral ?f0" by simp
-
     moreover from `?f0 \<in> G` have "positive_integral ?f0 \<le> ?y" by (auto intro!: le_SUPI)
     ultimately show False by auto
   qed
-
   show ?thesis
   proof (safe intro!: bexI[of _ f])
     fix A assume "A\<in>sets M"
@@ -575,10 +545,8 @@
   interpret v: measure_space M \<nu> by fact
   let ?Q = "{Q\<in>sets M. \<nu> Q \<noteq> \<omega>}"
   let ?a = "SUP Q:?Q. \<mu> Q"
-
   have "{} \<in> ?Q" using v.empty_measure by auto
   then have Q_not_empty: "?Q \<noteq> {}" by blast
-
   have "?a \<le> \<mu> (space M)" using sets_into_space
     by (auto intro!: SUP_leI measure_mono top)
   then have "?a \<noteq> \<omega>" using finite_measure_of_space
@@ -596,9 +564,7 @@
     show "range ?O \<subseteq> sets M" using Q' by (auto intro!: finite_UN)
     show "\<And>i. ?O i \<subseteq> ?O (Suc i)" by fastsimp
   qed
-
   have Q'_sets: "\<And>i. Q' i \<in> sets M" using Q' by auto
-
   have O_sets: "\<And>i. ?O i \<in> sets M"
      using Q' by (auto intro!: finite_UN Un)
   then have O_in_G: "\<And>i. ?O i \<in> ?Q"
@@ -611,7 +577,6 @@
     finally show "\<nu> (?O i) \<noteq> \<omega>" unfolding pinfreal_less_\<omega> by auto
   qed auto
   have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastsimp
-
   have a_eq: "?a = \<mu> (\<Union>i. ?O i)" unfolding Union[symmetric]
   proof (rule antisym)
     show "?a \<le> (SUP i. \<mu> (?O i))" unfolding a_Lim
@@ -625,14 +590,11 @@
         using O_in_G[of i] by (auto intro!: exI[of _ "?O i"])
     qed
   qed
-
   let "?O_0" = "(\<Union>i. ?O i)"
   have "?O_0 \<in> sets M" using Q' by auto
-
   def Q \<equiv> "\<lambda>i. case i of 0 \<Rightarrow> Q' 0 | Suc n \<Rightarrow> ?O (Suc n) - ?O n"
   { fix i have "Q i \<in> sets M" unfolding Q_def using Q'[of 0] by (cases i) (auto intro: O_sets) }
   note Q_sets = this
-
   show ?thesis
   proof (intro bexI exI conjI ballI impI allI)
     show "disjoint_family Q"
@@ -640,7 +602,6 @@
         split: nat.split_asm)
     show "range Q \<subseteq> sets M"
       using Q_sets by auto
-
     { fix A assume A: "A \<in> sets M" "A \<subseteq> space M - ?O_0"
       show "\<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<omega>"
       proof (rule disjCI, simp)
@@ -677,7 +638,6 @@
           with `\<mu> A \<noteq> 0` show ?thesis by auto
         qed
       qed }
-
     { fix i show "\<nu> (Q i) \<noteq> \<omega>"
       proof (cases i)
         case 0 then show ?thesis
@@ -688,9 +648,7 @@
           using `?O n \<in> ?Q` `?O (Suc n) \<in> ?Q` O_mono
           using v.measure_Diff[of "?O n" "?O (Suc n)"] by auto
       qed }
-
     show "space M - ?O_0 \<in> sets M" using Q'_sets by auto
-
     { fix j have "(\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q i)"
       proof (induct j)
         case 0 then show ?case by (simp add: Q_def)
@@ -713,7 +671,6 @@
   shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
 proof -
   interpret v: measure_space M \<nu> by fact
-
   from split_space_into_finite_sets_and_rest[OF assms]
   obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
     where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
@@ -721,7 +678,6 @@
     and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<omega>"
     and Q_fin: "\<And>i. \<nu> (Q i) \<noteq> \<omega>" by force
   from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
-
   have "\<forall>i. \<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
     \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f x * indicator (Q i \<inter> A) x))"
   proof
@@ -729,7 +685,6 @@
     have indicator_eq: "\<And>f x A. (f x :: pinfreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
       = (f x * indicator (Q i) x) * indicator A x"
       unfolding indicator_def by auto
-
     have fm: "finite_measure (restricted_space (Q i)) \<mu>"
       (is "finite_measure ?R \<mu>") by (rule restricted_finite_measure[OF Q_sets[of i]])
     then interpret R: finite_measure ?R .
@@ -843,12 +798,6 @@
 
 section "Uniqueness of densities"
 
-lemma (in measure_space) density_is_absolutely_continuous:
-  assumes "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
-  shows "absolutely_continuous \<nu>"
-  using assms unfolding absolutely_continuous_def
-  by (simp add: positive_integral_null_set)
-
 lemma (in measure_space) finite_density_unique:
   assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
   and fin: "positive_integral f < \<omega>"
@@ -973,19 +922,16 @@
     using h_borel by (rule measure_space_density)
   interpret h: finite_measure M "\<lambda>A. positive_integral (\<lambda>x. h x * indicator A x)"
     by default (simp cong: positive_integral_cong add: fin)
-
   interpret f: measure_space M "\<lambda>A. positive_integral (\<lambda>x. f x * indicator A x)"
     using borel(1) by (rule measure_space_density)
   interpret f': measure_space M "\<lambda>A. positive_integral (\<lambda>x. f' x * indicator A x)"
     using borel(2) by (rule measure_space_density)
-
   { fix A assume "A \<in> sets M"
     then have " {x \<in> space M. h x \<noteq> 0 \<and> indicator A x \<noteq> (0::pinfreal)} = A"
       using pos sets_into_space by (force simp: indicator_def)
     then have "positive_integral (\<lambda>xa. h xa * indicator A xa) = 0 \<longleftrightarrow> A \<in> null_sets"
       using h_borel `A \<in> sets M` by (simp add: positive_integral_0_iff) }
   note h_null_sets = this
-
   { fix A assume "A \<in> sets M"
     have "positive_integral (\<lambda>x. h x * (f x * indicator A x)) =
       f.positive_integral (\<lambda>x. h x * indicator A x)"
@@ -1101,7 +1047,7 @@
   qed
 qed
 
-section "Radon Nikodym derivative"
+section "Radon-Nikodym derivative"
 
 definition (in sigma_finite_measure)
   "RN_deriv \<nu> \<equiv> SOME f. f \<in> borel_measurable M \<and>
--- a/src/HOL/Probability/Sigma_Algebra.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Probability/Sigma_Algebra.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -397,6 +397,18 @@
     by (auto intro: sigma_sets.Empty sigma_sets_top)
 qed
 
+lemma (in sigma_algebra) sets_sigma_subset:
+  assumes "space N = space M"
+  assumes "sets N \<subseteq> sets M"
+  shows "sets (sigma N) \<subseteq> sets M"
+  by (unfold assms sets_sigma, rule sigma_sets_subset, rule assms)
+
+lemma in_sigma[intro, simp]: "A \<in> sets M \<Longrightarrow> A \<in> sets (sigma M)"
+  unfolding sigma_def by (auto intro!: sigma_sets.Basic)
+
+lemma (in sigma_algebra) sigma_eq[simp]: "sigma M = M"
+  unfolding sigma_def sigma_sets_eq by simp
+
 section {* Measurable functions *}
 
 definition
@@ -859,6 +871,22 @@
   qed
 qed
 
+lemma vimage_algebra_sigma:
+  assumes E: "sets E \<subseteq> Pow (space E)"
+    and f: "f \<in> space F \<rightarrow> space E"
+    and "\<And>A. A \<in> sets F \<Longrightarrow> A \<in> (\<lambda>X. f -` X \<inter> space F) ` sets E"
+    and "\<And>A. A \<in> sets E \<Longrightarrow> f -` A \<inter> space F \<in> sets F"
+  shows "sigma_algebra.vimage_algebra (sigma E) (space F) f = sigma F"
+proof -
+  interpret sigma_algebra "sigma E"
+    using assms by (intro sigma_algebra_sigma) auto
+  have eq: "sets F = (\<lambda>X. f -` X \<inter> space F) ` sets E"
+    using assms by auto
+  show "vimage_algebra (space F) f = sigma F"
+    unfolding vimage_algebra_def using assms
+    by (simp add: sigma_def eq sigma_sets_vimage)
+qed
+
 section {* Conditional space *}
 
 definition (in algebra)
@@ -1149,7 +1177,6 @@
 
 section {* Dynkin systems *}
 
-
 locale dynkin_system =
   fixes M :: "'a algebra"
   assumes space_closed: "sets M \<subseteq> Pow (space M)"
--- a/src/HOL/Set.thy	Thu Dec 02 14:56:16 2010 +0100
+++ b/src/HOL/Set.thy	Thu Dec 02 15:32:48 2010 +0100
@@ -882,7 +882,6 @@
 lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
   by blast
 
-
 subsubsection {* Some rules with @{text "if"} *}
 
 text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}