src/HOL/Analysis/Sigma_Algebra.thy
changeset 67962 0acdcd8f4ba1
parent 67399 eab6ce8368fa
child 67982 7643b005b29a
equal deleted inserted replaced
67961:9c31678d2139 67962:0acdcd8f4ba1
     3     Author:     Johannes Hölzl, TU München
     3     Author:     Johannes Hölzl, TU München
     4     Plus material from the Hurd/Coble measure theory development,
     4     Plus material from the Hurd/Coble measure theory development,
     5     translated by Lawrence Paulson.
     5     translated by Lawrence Paulson.
     6 *)
     6 *)
     7 
     7 
     8 section \<open>Describing measurable sets\<close>
     8 section \<open>Sigma Algebra\<close>
     9 
     9 
    10 theory Sigma_Algebra
    10 theory Sigma_Algebra
    11 imports
    11 imports
    12   Complex_Main
    12   Complex_Main
    13   "HOL-Library.Countable_Set"
    13   "HOL-Library.Countable_Set"
    25   subsets of the universe. A sigma algebra is such a set that has
    25   subsets of the universe. A sigma algebra is such a set that has
    26   three very natural and desirable properties.\<close>
    26   three very natural and desirable properties.\<close>
    27 
    27 
    28 subsection \<open>Families of sets\<close>
    28 subsection \<open>Families of sets\<close>
    29 
    29 
    30 locale subset_class =
    30 locale%important subset_class =
    31   fixes \<Omega> :: "'a set" and M :: "'a set set"
    31   fixes \<Omega> :: "'a set" and M :: "'a set set"
    32   assumes space_closed: "M \<subseteq> Pow \<Omega>"
    32   assumes space_closed: "M \<subseteq> Pow \<Omega>"
    33 
    33 
    34 lemma (in subset_class) sets_into_space: "x \<in> M \<Longrightarrow> x \<subseteq> \<Omega>"
    34 lemma (in subset_class) sets_into_space: "x \<in> M \<Longrightarrow> x \<subseteq> \<Omega>"
    35   by (metis PowD contra_subsetD space_closed)
    35   by (metis PowD contra_subsetD space_closed)
    36 
    36 
    37 subsubsection \<open>Semiring of sets\<close>
    37 subsubsection \<open>Semiring of sets\<close>
    38 
    38 
    39 locale semiring_of_sets = subset_class +
    39 locale%important semiring_of_sets = subset_class +
    40   assumes empty_sets[iff]: "{} \<in> M"
    40   assumes empty_sets[iff]: "{} \<in> M"
    41   assumes Int[intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<inter> b \<in> M"
    41   assumes Int[intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<inter> b \<in> M"
    42   assumes Diff_cover:
    42   assumes Diff_cover:
    43     "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> \<exists>C\<subseteq>M. finite C \<and> disjoint C \<and> a - b = \<Union>C"
    43     "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> \<exists>C\<subseteq>M. finite C \<and> disjoint C \<and> a - b = \<Union>C"
    44 
    44 
    69   have "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} = (\<Inter>i\<in>S. {x\<in>\<Omega>. P i x})"
    69   have "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} = (\<Inter>i\<in>S. {x\<in>\<Omega>. P i x})"
    70     using \<open>S \<noteq> {}\<close> by auto
    70     using \<open>S \<noteq> {}\<close> by auto
    71   with assms show ?thesis by auto
    71   with assms show ?thesis by auto
    72 qed
    72 qed
    73 
    73 
    74 locale ring_of_sets = semiring_of_sets +
    74 subsubsection \<open>Ring of sets\<close>
       
    75 
       
    76 locale%important ring_of_sets = semiring_of_sets +
    75   assumes Un [intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<union> b \<in> M"
    77   assumes Un [intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<union> b \<in> M"
    76 
    78 
    77 lemma (in ring_of_sets) finite_Union [intro]:
    79 lemma (in ring_of_sets) finite_Union [intro]:
    78   "finite X \<Longrightarrow> X \<subseteq> M \<Longrightarrow> \<Union>X \<in> M"
    80   "finite X \<Longrightarrow> X \<subseteq> M \<Longrightarrow> \<Union>X \<in> M"
    79   by (induct set: finite) (auto simp add: Un)
    81   by (induct set: finite) (auto simp add: Un)
   133   have "{x\<in>\<Omega>. \<exists>i\<in>S. P i x} = (\<Union>i\<in>S. {x\<in>\<Omega>. P i x})"
   135   have "{x\<in>\<Omega>. \<exists>i\<in>S. P i x} = (\<Union>i\<in>S. {x\<in>\<Omega>. P i x})"
   134     by auto
   136     by auto
   135   with assms show ?thesis by auto
   137   with assms show ?thesis by auto
   136 qed
   138 qed
   137 
   139 
   138 locale algebra = ring_of_sets +
   140 subsubsection \<open>Algebra of sets\<close>
       
   141 
       
   142 locale%important algebra = ring_of_sets +
   139   assumes top [iff]: "\<Omega> \<in> M"
   143   assumes top [iff]: "\<Omega> \<in> M"
   140 
   144 
   141 lemma (in algebra) compl_sets [intro]:
   145 lemma (in algebra) compl_sets [intro]:
   142   "a \<in> M \<Longrightarrow> \<Omega> - a \<in> M"
   146   "a \<in> M \<Longrightarrow> \<Omega> - a \<in> M"
   143   by auto
   147   by auto
   144 
   148 
   145 lemma algebra_iff_Un:
   149 lemma%important algebra_iff_Un:
   146   "algebra \<Omega> M \<longleftrightarrow>
   150   "algebra \<Omega> M \<longleftrightarrow>
   147     M \<subseteq> Pow \<Omega> \<and>
   151     M \<subseteq> Pow \<Omega> \<and>
   148     {} \<in> M \<and>
   152     {} \<in> M \<and>
   149     (\<forall>a \<in> M. \<Omega> - a \<in> M) \<and>
   153     (\<forall>a \<in> M. \<Omega> - a \<in> M) \<and>
   150     (\<forall>a \<in> M. \<forall> b \<in> M. a \<union> b \<in> M)" (is "_ \<longleftrightarrow> ?Un")
   154     (\<forall>a \<in> M. \<forall> b \<in> M. a \<union> b \<in> M)" (is "_ \<longleftrightarrow> ?Un")
   151 proof
   155 proof%unimportant
   152   assume "algebra \<Omega> M"
   156   assume "algebra \<Omega> M"
   153   then interpret algebra \<Omega> M .
   157   then interpret algebra \<Omega> M .
   154   show ?Un using sets_into_space by auto
   158   show ?Un using sets_into_space by auto
   155 next
   159 next
   156   assume ?Un
   160   assume ?Un
   167       using a b  \<open>?Un\<close> by auto
   171       using a b  \<open>?Un\<close> by auto
   168   qed
   172   qed
   169   show "algebra \<Omega> M" proof qed fact
   173   show "algebra \<Omega> M" proof qed fact
   170 qed
   174 qed
   171 
   175 
   172 lemma algebra_iff_Int:
   176 lemma%important algebra_iff_Int:
   173      "algebra \<Omega> M \<longleftrightarrow>
   177      "algebra \<Omega> M \<longleftrightarrow>
   174        M \<subseteq> Pow \<Omega> & {} \<in> M &
   178        M \<subseteq> Pow \<Omega> & {} \<in> M &
   175        (\<forall>a \<in> M. \<Omega> - a \<in> M) &
   179        (\<forall>a \<in> M. \<Omega> - a \<in> M) &
   176        (\<forall>a \<in> M. \<forall> b \<in> M. a \<inter> b \<in> M)" (is "_ \<longleftrightarrow> ?Int")
   180        (\<forall>a \<in> M. \<forall> b \<in> M. a \<inter> b \<in> M)" (is "_ \<longleftrightarrow> ?Int")
   177 proof
   181 proof%unimportant
   178   assume "algebra \<Omega> M"
   182   assume "algebra \<Omega> M"
   179   then interpret algebra \<Omega> M .
   183   then interpret algebra \<Omega> M .
   180   show ?Int using sets_into_space by auto
   184   show ?Int using sets_into_space by auto
   181 next
   185 next
   182   assume ?Int
   186   assume ?Int
   212 
   216 
   213 lemma algebra_single_set:
   217 lemma algebra_single_set:
   214   "X \<subseteq> S \<Longrightarrow> algebra S { {}, X, S - X, S }"
   218   "X \<subseteq> S \<Longrightarrow> algebra S { {}, X, S - X, S }"
   215   by (auto simp: algebra_iff_Int)
   219   by (auto simp: algebra_iff_Int)
   216 
   220 
   217 subsubsection \<open>Restricted algebras\<close>
   221 subsubsection%unimportant \<open>Restricted algebras\<close>
   218 
   222 
   219 abbreviation (in algebra)
   223 abbreviation (in algebra)
   220   "restricted_space A \<equiv> ((\<inter>) A) ` M"
   224   "restricted_space A \<equiv> ((\<inter>) A) ` M"
   221 
   225 
   222 lemma (in algebra) restricted_algebra:
   226 lemma (in algebra) restricted_algebra:
   223   assumes "A \<in> M" shows "algebra A (restricted_space A)"
   227   assumes "A \<in> M" shows "algebra A (restricted_space A)"
   224   using assms by (auto simp: algebra_iff_Int)
   228   using assms by (auto simp: algebra_iff_Int)
   225 
   229 
   226 subsubsection \<open>Sigma Algebras\<close>
   230 subsubsection \<open>Sigma Algebras\<close>
   227 
   231 
   228 locale sigma_algebra = algebra +
   232 locale%important sigma_algebra = algebra +
   229   assumes countable_nat_UN [intro]: "\<And>A. range A \<subseteq> M \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
   233   assumes countable_nat_UN [intro]: "\<And>A. range A \<subseteq> M \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
   230 
   234 
   231 lemma (in algebra) is_sigma_algebra:
   235 lemma (in algebra) is_sigma_algebra:
   232   assumes "finite M"
   236   assumes "finite M"
   233   shows "sigma_algebra \<Omega> M"
   237   shows "sigma_algebra \<Omega> M"
   421 lemma sigma_algebra_single_set:
   425 lemma sigma_algebra_single_set:
   422   assumes "X \<subseteq> S"
   426   assumes "X \<subseteq> S"
   423   shows "sigma_algebra S { {}, X, S - X, S }"
   427   shows "sigma_algebra S { {}, X, S - X, S }"
   424   using algebra.is_sigma_algebra[OF algebra_single_set[OF \<open>X \<subseteq> S\<close>]] by simp
   428   using algebra.is_sigma_algebra[OF algebra_single_set[OF \<open>X \<subseteq> S\<close>]] by simp
   425 
   429 
   426 subsubsection \<open>Binary Unions\<close>
   430 subsubsection%unimportant \<open>Binary Unions\<close>
   427 
   431 
   428 definition binary :: "'a \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a"
   432 definition binary :: "'a \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a"
   429   where "binary a b =  (\<lambda>x. b)(0 := a)"
   433   where "binary a b =  (\<lambda>x. b)(0 := a)"
   430 
   434 
   431 lemma range_binary_eq: "range(binary a b) = {a,b}"
   435 lemma range_binary_eq: "range(binary a b) = {a,b}"
   445   by (auto simp add: range_binary_eq sigma_algebra_def sigma_algebra_axioms_def
   449   by (auto simp add: range_binary_eq sigma_algebra_def sigma_algebra_axioms_def
   446          algebra_iff_Un Un_range_binary)
   450          algebra_iff_Un Un_range_binary)
   447 
   451 
   448 subsubsection \<open>Initial Sigma Algebra\<close>
   452 subsubsection \<open>Initial Sigma Algebra\<close>
   449 
   453 
   450 text \<open>Sigma algebras can naturally be created as the closure of any set of
   454 text%important \<open>Sigma algebras can naturally be created as the closure of any set of
   451   M with regard to the properties just postulated.\<close>
   455   M with regard to the properties just postulated.\<close>
   452 
   456 
   453 inductive_set sigma_sets :: "'a set \<Rightarrow> 'a set set \<Rightarrow> 'a set set"
   457 inductive_set%important sigma_sets :: "'a set \<Rightarrow> 'a set set \<Rightarrow> 'a set set"
   454   for sp :: "'a set" and A :: "'a set set"
   458   for sp :: "'a set" and A :: "'a set set"
   455   where
   459   where
   456     Basic[intro, simp]: "a \<in> A \<Longrightarrow> a \<in> sigma_sets sp A"
   460     Basic[intro, simp]: "a \<in> A \<Longrightarrow> a \<in> sigma_sets sp A"
   457   | Empty: "{} \<in> sigma_sets sp A"
   461   | Empty: "{} \<in> sigma_sets sp A"
   458   | Compl: "a \<in> sigma_sets sp A \<Longrightarrow> sp - a \<in> sigma_sets sp A"
   462   | Compl: "a \<in> sigma_sets sp A \<Longrightarrow> sp - a \<in> sigma_sets sp A"
   794   hence "(\<Union>i. disjointed A i) \<in> M"
   798   hence "(\<Union>i. disjointed A i) \<in> M"
   795     by (simp add: algebra.range_disjointed_sets'[of \<Omega>] M A disjoint_family_disjointed)
   799     by (simp add: algebra.range_disjointed_sets'[of \<Omega>] M A disjoint_family_disjointed)
   796   thus "(\<Union>i::nat. A i) \<in> M" by (simp add: UN_disjointed_eq)
   800   thus "(\<Union>i::nat. A i) \<in> M" by (simp add: UN_disjointed_eq)
   797 qed
   801 qed
   798 
   802 
   799 subsubsection \<open>Ring generated by a semiring\<close>
   803 subsubsection%unimportant \<open>Ring generated by a semiring\<close>
   800 
   804 
   801 definition (in semiring_of_sets)
   805 definition (in semiring_of_sets)
   802   "generated_ring = { \<Union>C | C. C \<subseteq> M \<and> finite C \<and> disjoint C }"
   806   "generated_ring = { \<Union>C | C. C \<subseteq> M \<and> finite C \<and> disjoint C }"
   803 
   807 
   804 lemma (in semiring_of_sets) generated_ringE[elim?]:
   808 lemma (in semiring_of_sets) generated_ringE[elim?]:
   925     using space_closed by (rule sigma_algebra_sigma_sets)
   929     using space_closed by (rule sigma_algebra_sigma_sets)
   926   show "sigma_sets \<Omega> generated_ring \<subseteq> sigma_sets \<Omega> M"
   930   show "sigma_sets \<Omega> generated_ring \<subseteq> sigma_sets \<Omega> M"
   927     by (blast intro!: sigma_sets_mono elim: generated_ringE)
   931     by (blast intro!: sigma_sets_mono elim: generated_ringE)
   928 qed (auto intro!: generated_ringI_Basic sigma_sets_mono)
   932 qed (auto intro!: generated_ringI_Basic sigma_sets_mono)
   929 
   933 
   930 subsubsection \<open>A Two-Element Series\<close>
   934 subsubsection%unimportant \<open>A Two-Element Series\<close>
   931 
   935 
   932 definition binaryset :: "'a set \<Rightarrow> 'a set \<Rightarrow> nat \<Rightarrow> 'a set"
   936 definition binaryset :: "'a set \<Rightarrow> 'a set \<Rightarrow> nat \<Rightarrow> 'a set"
   933   where "binaryset A B = (\<lambda>x. {})(0 := A, Suc 0 := B)"
   937   where "binaryset A B = (\<lambda>x. {})(0 := A, Suc 0 := B)"
   934 
   938 
   935 lemma range_binaryset_eq: "range(binaryset A B) = {A,B,{}}"
   939 lemma range_binaryset_eq: "range(binaryset A B) = {A,B,{}}"
   941 lemma UN_binaryset_eq: "(\<Union>i. binaryset A B i) = A \<union> B"
   945 lemma UN_binaryset_eq: "(\<Union>i. binaryset A B i) = A \<union> B"
   942   by (simp add: range_binaryset_eq cong del: strong_SUP_cong)
   946   by (simp add: range_binaryset_eq cong del: strong_SUP_cong)
   943 
   947 
   944 subsubsection \<open>Closed CDI\<close>
   948 subsubsection \<open>Closed CDI\<close>
   945 
   949 
   946 definition closed_cdi where
   950 definition%important closed_cdi where
   947   "closed_cdi \<Omega> M \<longleftrightarrow>
   951   "closed_cdi \<Omega> M \<longleftrightarrow>
   948    M \<subseteq> Pow \<Omega> &
   952    M \<subseteq> Pow \<Omega> &
   949    (\<forall>s \<in> M. \<Omega> - s \<in> M) &
   953    (\<forall>s \<in> M. \<Omega> - s \<in> M) &
   950    (\<forall>A. (range A \<subseteq> M) & (A 0 = {}) & (\<forall>n. A n \<subseteq> A (Suc n)) \<longrightarrow>
   954    (\<forall>A. (range A \<subseteq> M) & (A 0 = {}) & (\<forall>n. A n \<subseteq> A (Suc n)) \<longrightarrow>
   951         (\<Union>i. A i) \<in> M) &
   955         (\<Union>i. A i) \<in> M) &
  1175     by blast
  1179     by blast
  1176 qed
  1180 qed
  1177 
  1181 
  1178 subsubsection \<open>Dynkin systems\<close>
  1182 subsubsection \<open>Dynkin systems\<close>
  1179 
  1183 
  1180 locale dynkin_system = subset_class +
  1184 locale%important dynkin_system = subset_class +
  1181   assumes space: "\<Omega> \<in> M"
  1185   assumes space: "\<Omega> \<in> M"
  1182     and   compl[intro!]: "\<And>A. A \<in> M \<Longrightarrow> \<Omega> - A \<in> M"
  1186     and   compl[intro!]: "\<And>A. A \<in> M \<Longrightarrow> \<Omega> - A \<in> M"
  1183     and   UN[intro!]: "\<And>A. disjoint_family A \<Longrightarrow> range A \<subseteq> M
  1187     and   UN[intro!]: "\<And>A. disjoint_family A \<Longrightarrow> range A \<subseteq> M
  1184                            \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
  1188                            \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
  1185 
  1189 
  1237   show ?thesis using sets_into_space by (fastforce intro!: dynkin_systemI)
  1241   show ?thesis using sets_into_space by (fastforce intro!: dynkin_systemI)
  1238 qed
  1242 qed
  1239 
  1243 
  1240 subsubsection "Intersection sets systems"
  1244 subsubsection "Intersection sets systems"
  1241 
  1245 
  1242 definition "Int_stable M \<longleftrightarrow> (\<forall> a \<in> M. \<forall> b \<in> M. a \<inter> b \<in> M)"
  1246 definition%important "Int_stable M \<longleftrightarrow> (\<forall> a \<in> M. \<forall> b \<in> M. a \<inter> b \<in> M)"
  1243 
  1247 
  1244 lemma (in algebra) Int_stable: "Int_stable M"
  1248 lemma (in algebra) Int_stable: "Int_stable M"
  1245   unfolding Int_stable_def by auto
  1249   unfolding Int_stable_def by auto
  1246 
  1250 
  1247 lemma Int_stableI_image:
  1251 lemma Int_stableI_image:
  1277   qed auto
  1281   qed auto
  1278 qed
  1282 qed
  1279 
  1283 
  1280 subsubsection "Smallest Dynkin systems"
  1284 subsubsection "Smallest Dynkin systems"
  1281 
  1285 
  1282 definition dynkin where
  1286 definition%important dynkin where
  1283   "dynkin \<Omega> M =  (\<Inter>{D. dynkin_system \<Omega> D \<and> M \<subseteq> D})"
  1287   "dynkin \<Omega> M =  (\<Inter>{D. dynkin_system \<Omega> D \<and> M \<subseteq> D})"
  1284 
  1288 
  1285 lemma dynkin_system_dynkin:
  1289 lemma dynkin_system_dynkin:
  1286   assumes "M \<subseteq> Pow (\<Omega>)"
  1290   assumes "M \<subseteq> Pow (\<Omega>)"
  1287   shows "dynkin_system \<Omega> (dynkin \<Omega> M)"
  1291   shows "dynkin_system \<Omega> (dynkin \<Omega> M)"
  1424     using assms by (auto simp: dynkin_def)
  1428     using assms by (auto simp: dynkin_def)
  1425 qed
  1429 qed
  1426 
  1430 
  1427 subsubsection \<open>Induction rule for intersection-stable generators\<close>
  1431 subsubsection \<open>Induction rule for intersection-stable generators\<close>
  1428 
  1432 
  1429 text \<open>The reason to introduce Dynkin-systems is the following induction rules for $\sigma$-algebras
  1433 text%important \<open>The reason to introduce Dynkin-systems is the following induction rules for $\sigma$-algebras
  1430 generated by a generator closed under intersection.\<close>
  1434 generated by a generator closed under intersection.\<close>
  1431 
  1435 
  1432 lemma sigma_sets_induct_disjoint[consumes 3, case_names basic empty compl union]:
  1436 lemma%important sigma_sets_induct_disjoint[consumes 3, case_names basic empty compl union]:
  1433   assumes "Int_stable G"
  1437   assumes "Int_stable G"
  1434     and closed: "G \<subseteq> Pow \<Omega>"
  1438     and closed: "G \<subseteq> Pow \<Omega>"
  1435     and A: "A \<in> sigma_sets \<Omega> G"
  1439     and A: "A \<in> sigma_sets \<Omega> G"
  1436   assumes basic: "\<And>A. A \<in> G \<Longrightarrow> P A"
  1440   assumes basic: "\<And>A. A \<in> G \<Longrightarrow> P A"
  1437     and empty: "P {}"
  1441     and empty: "P {}"
  1438     and compl: "\<And>A. A \<in> sigma_sets \<Omega> G \<Longrightarrow> P A \<Longrightarrow> P (\<Omega> - A)"
  1442     and compl: "\<And>A. A \<in> sigma_sets \<Omega> G \<Longrightarrow> P A \<Longrightarrow> P (\<Omega> - A)"
  1439     and union: "\<And>A. disjoint_family A \<Longrightarrow> range A \<subseteq> sigma_sets \<Omega> G \<Longrightarrow> (\<And>i. P (A i)) \<Longrightarrow> P (\<Union>i::nat. A i)"
  1443     and union: "\<And>A. disjoint_family A \<Longrightarrow> range A \<subseteq> sigma_sets \<Omega> G \<Longrightarrow> (\<And>i. P (A i)) \<Longrightarrow> P (\<Union>i::nat. A i)"
  1440   shows "P A"
  1444   shows "P A"
  1441 proof -
  1445 proof%unimportant -
  1442   let ?D = "{ A \<in> sigma_sets \<Omega> G. P A }"
  1446   let ?D = "{ A \<in> sigma_sets \<Omega> G. P A }"
  1443   interpret sigma_algebra \<Omega> "sigma_sets \<Omega> G"
  1447   interpret sigma_algebra \<Omega> "sigma_sets \<Omega> G"
  1444     using closed by (rule sigma_algebra_sigma_sets)
  1448     using closed by (rule sigma_algebra_sigma_sets)
  1445   from compl[OF _ empty] closed have space: "P \<Omega>" by simp
  1449   from compl[OF _ empty] closed have space: "P \<Omega>" by simp
  1446   interpret dynkin_system \<Omega> ?D
  1450   interpret dynkin_system \<Omega> ?D
  1450   with A show ?thesis by auto
  1454   with A show ?thesis by auto
  1451 qed
  1455 qed
  1452 
  1456 
  1453 subsection \<open>Measure type\<close>
  1457 subsection \<open>Measure type\<close>
  1454 
  1458 
  1455 definition positive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
  1459 definition%important positive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
  1456   "positive M \<mu> \<longleftrightarrow> \<mu> {} = 0"
  1460   "positive M \<mu> \<longleftrightarrow> \<mu> {} = 0"
  1457 
  1461 
  1458 definition countably_additive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
  1462 definition%important countably_additive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
  1459   "countably_additive M f \<longleftrightarrow> (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow>
  1463   "countably_additive M f \<longleftrightarrow> (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow>
  1460     (\<Sum>i. f (A i)) = f (\<Union>i. A i))"
  1464     (\<Sum>i. f (A i)) = f (\<Union>i. A i))"
  1461 
  1465 
  1462 definition measure_space :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
  1466 definition%important measure_space :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
  1463   "measure_space \<Omega> A \<mu> \<longleftrightarrow> sigma_algebra \<Omega> A \<and> positive A \<mu> \<and> countably_additive A \<mu>"
  1467   "measure_space \<Omega> A \<mu> \<longleftrightarrow> sigma_algebra \<Omega> A \<and> positive A \<mu> \<and> countably_additive A \<mu>"
  1464 
  1468 
  1465 typedef 'a measure = "{(\<Omega>::'a set, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu> }"
  1469 typedef%important 'a measure = "{(\<Omega>::'a set, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu> }"
  1466 proof
  1470 proof%unimportant
  1467   have "sigma_algebra UNIV {{}, UNIV}"
  1471   have "sigma_algebra UNIV {{}, UNIV}"
  1468     by (auto simp: sigma_algebra_iff2)
  1472     by (auto simp: sigma_algebra_iff2)
  1469   then show "(UNIV, {{}, UNIV}, \<lambda>A. 0) \<in> {(\<Omega>, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu>} "
  1473   then show "(UNIV, {{}, UNIV}, \<lambda>A. 0) \<in> {(\<Omega>, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu>} "
  1470     by (auto simp: measure_space_def positive_def countably_additive_def)
  1474     by (auto simp: measure_space_def positive_def countably_additive_def)
  1471 qed
  1475 qed
  1472 
  1476 
  1473 definition space :: "'a measure \<Rightarrow> 'a set" where
  1477 definition%important space :: "'a measure \<Rightarrow> 'a set" where
  1474   "space M = fst (Rep_measure M)"
  1478   "space M = fst (Rep_measure M)"
  1475 
  1479 
  1476 definition sets :: "'a measure \<Rightarrow> 'a set set" where
  1480 definition%important sets :: "'a measure \<Rightarrow> 'a set set" where
  1477   "sets M = fst (snd (Rep_measure M))"
  1481   "sets M = fst (snd (Rep_measure M))"
  1478 
  1482 
  1479 definition emeasure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> ennreal" where
  1483 definition%important emeasure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> ennreal" where
  1480   "emeasure M = snd (snd (Rep_measure M))"
  1484   "emeasure M = snd (snd (Rep_measure M))"
  1481 
  1485 
  1482 definition measure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> real" where
  1486 definition%important measure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> real" where
  1483   "measure M A = enn2real (emeasure M A)"
  1487   "measure M A = enn2real (emeasure M A)"
  1484 
  1488 
  1485 declare [[coercion sets]]
  1489 declare [[coercion sets]]
  1486 
  1490 
  1487 declare [[coercion measure]]
  1491 declare [[coercion measure]]
  1492   by (cases M) (auto simp: space_def sets_def emeasure_def Abs_measure_inverse)
  1496   by (cases M) (auto simp: space_def sets_def emeasure_def Abs_measure_inverse)
  1493 
  1497 
  1494 interpretation sets: sigma_algebra "space M" "sets M" for M :: "'a measure"
  1498 interpretation sets: sigma_algebra "space M" "sets M" for M :: "'a measure"
  1495   using measure_space[of M] by (auto simp: measure_space_def)
  1499   using measure_space[of M] by (auto simp: measure_space_def)
  1496 
  1500 
  1497 definition measure_of :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> 'a measure" where
  1501 definition%important measure_of :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> 'a measure" where
  1498   "measure_of \<Omega> A \<mu> = Abs_measure (\<Omega>, if A \<subseteq> Pow \<Omega> then sigma_sets \<Omega> A else {{}, \<Omega>},
  1502   "measure_of \<Omega> A \<mu> = Abs_measure (\<Omega>, if A \<subseteq> Pow \<Omega> then sigma_sets \<Omega> A else {{}, \<Omega>},
  1499     \<lambda>a. if a \<in> sigma_sets \<Omega> A \<and> measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> then \<mu> a else 0)"
  1503     \<lambda>a. if a \<in> sigma_sets \<Omega> A \<and> measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> then \<mu> a else 0)"
  1500 
  1504 
  1501 abbreviation "sigma \<Omega> A \<equiv> measure_of \<Omega> A (\<lambda>x. 0)"
  1505 abbreviation "sigma \<Omega> A \<equiv> measure_of \<Omega> A (\<lambda>x. 0)"
  1502 
  1506 
  1627   by (metis Pow_empty Sup_bot_conv(1) cSup_singleton empty_iff
  1631   by (metis Pow_empty Sup_bot_conv(1) cSup_singleton empty_iff
  1628             sets.sigma_sets_eq sets.space_closed sigma_sets_top subset_singletonD)
  1632             sets.sigma_sets_eq sets.space_closed sigma_sets_top subset_singletonD)
  1629 
  1633 
  1630 subsubsection \<open>Constructing simple @{typ "'a measure"}\<close>
  1634 subsubsection \<open>Constructing simple @{typ "'a measure"}\<close>
  1631 
  1635 
  1632 lemma emeasure_measure_of:
  1636 lemma%important emeasure_measure_of:
  1633   assumes M: "M = measure_of \<Omega> A \<mu>"
  1637   assumes M: "M = measure_of \<Omega> A \<mu>"
  1634   assumes ms: "A \<subseteq> Pow \<Omega>" "positive (sets M) \<mu>" "countably_additive (sets M) \<mu>"
  1638   assumes ms: "A \<subseteq> Pow \<Omega>" "positive (sets M) \<mu>" "countably_additive (sets M) \<mu>"
  1635   assumes X: "X \<in> sets M"
  1639   assumes X: "X \<in> sets M"
  1636   shows "emeasure M X = \<mu> X"
  1640   shows "emeasure M X = \<mu> X"
  1637 proof -
  1641 proof%unimportant -
  1638   interpret sigma_algebra \<Omega> "sigma_sets \<Omega> A" by (rule sigma_algebra_sigma_sets) fact
  1642   interpret sigma_algebra \<Omega> "sigma_sets \<Omega> A" by (rule sigma_algebra_sigma_sets) fact
  1639   have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
  1643   have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
  1640     using ms M by (simp add: measure_space_def sigma_algebra_sigma_sets)
  1644     using ms M by (simp add: measure_space_def sigma_algebra_sigma_sets)
  1641   thus ?thesis using X ms
  1645   thus ?thesis using X ms
  1642     by(simp add: M emeasure_measure_of_conv sets_measure_of_conv)
  1646     by(simp add: M emeasure_measure_of_conv sets_measure_of_conv)
  1709   shows "sigma \<Omega> M = sigma \<Omega> N"
  1713   shows "sigma \<Omega> M = sigma \<Omega> N"
  1710   by (rule measure_eqI) (simp_all add: emeasure_sigma)
  1714   by (rule measure_eqI) (simp_all add: emeasure_sigma)
  1711 
  1715 
  1712 subsubsection \<open>Measurable functions\<close>
  1716 subsubsection \<open>Measurable functions\<close>
  1713 
  1717 
  1714 definition measurable :: "'a measure \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) set" (infixr "\<rightarrow>\<^sub>M" 60) where
  1718 definition%important measurable :: "'a measure \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) set" (infixr "\<rightarrow>\<^sub>M" 60) where
  1715   "measurable A B = {f \<in> space A \<rightarrow> space B. \<forall>y \<in> sets B. f -` y \<inter> space A \<in> sets A}"
  1719   "measurable A B = {f \<in> space A \<rightarrow> space B. \<forall>y \<in> sets B. f -` y \<inter> space A \<in> sets A}"
  1716 
  1720 
  1717 lemma measurableI:
  1721 lemma measurableI:
  1718   "(\<And>x. x \<in> space M \<Longrightarrow> f x \<in> space N) \<Longrightarrow> (\<And>A. A \<in> sets N \<Longrightarrow> f -` A \<inter> space M \<in> sets M) \<Longrightarrow>
  1722   "(\<And>x. x \<in> space M \<Longrightarrow> f x \<in> space N) \<Longrightarrow> (\<And>A. A \<in> sets N \<Longrightarrow> f -` A \<inter> space M \<in> sets M) \<Longrightarrow>
  1719     f \<in> measurable M N"
  1723     f \<in> measurable M N"
  1871     measurable (measure_of \<Omega> M \<mu>) N \<subseteq> measurable (measure_of \<Omega> M' \<mu>') N"
  1875     measurable (measure_of \<Omega> M \<mu>) N \<subseteq> measurable (measure_of \<Omega> M' \<mu>') N"
  1872   using measure_of_subset[of M' \<Omega> M] by (auto simp add: measurable_def)
  1876   using measure_of_subset[of M' \<Omega> M] by (auto simp add: measurable_def)
  1873 
  1877 
  1874 subsubsection \<open>Counting space\<close>
  1878 subsubsection \<open>Counting space\<close>
  1875 
  1879 
  1876 definition count_space :: "'a set \<Rightarrow> 'a measure" where
  1880 definition%important count_space :: "'a set \<Rightarrow> 'a measure" where
  1877   "count_space \<Omega> = measure_of \<Omega> (Pow \<Omega>) (\<lambda>A. if finite A then of_nat (card A) else \<infinity>)"
  1881   "count_space \<Omega> = measure_of \<Omega> (Pow \<Omega>) (\<lambda>A. if finite A then of_nat (card A) else \<infinity>)"
  1878 
  1882 
  1879 lemma
  1883 lemma
  1880   shows space_count_space[simp]: "space (count_space \<Omega>) = \<Omega>"
  1884   shows space_count_space[simp]: "space (count_space \<Omega>) = \<Omega>"
  1881     and sets_count_space[simp]: "sets (count_space \<Omega>) = Pow \<Omega>"
  1885     and sets_count_space[simp]: "sets (count_space \<Omega>) = Pow \<Omega>"
  1947 
  1951 
  1948 lemma measurable_empty_iff:
  1952 lemma measurable_empty_iff:
  1949   "space N = {} \<Longrightarrow> f \<in> measurable M N \<longleftrightarrow> space M = {}"
  1953   "space N = {} \<Longrightarrow> f \<in> measurable M N \<longleftrightarrow> space M = {}"
  1950   by (auto simp add: measurable_def Pi_iff)
  1954   by (auto simp add: measurable_def Pi_iff)
  1951 
  1955 
  1952 subsubsection \<open>Extend measure\<close>
  1956 subsubsection%unimportant \<open>Extend measure\<close>
  1953 
  1957 
  1954 definition "extend_measure \<Omega> I G \<mu> =
  1958 definition "extend_measure \<Omega> I G \<mu> =
  1955   (if (\<exists>\<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>') \<and> \<not> (\<forall>i\<in>I. \<mu> i = 0)
  1959   (if (\<exists>\<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>') \<and> \<not> (\<forall>i\<in>I. \<mu> i = 0)
  1956       then measure_of \<Omega> (G`I) (SOME \<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>')
  1960       then measure_of \<Omega> (G`I) (SOME \<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>')
  1957       else measure_of \<Omega> (G`I) (\<lambda>_. 0))"
  1961       else measure_of \<Omega> (G`I) (\<lambda>_. 0))"
  2009   using emeasure_extend_measure[OF M _ _ ms(2,3), of "(i,j)"] eq ms(1) \<open>I i j\<close>
  2013   using emeasure_extend_measure[OF M _ _ ms(2,3), of "(i,j)"] eq ms(1) \<open>I i j\<close>
  2010   by (auto simp: subset_eq)
  2014   by (auto simp: subset_eq)
  2011 
  2015 
  2012 subsection \<open>The smallest $\sigma$-algebra regarding a function\<close>
  2016 subsection \<open>The smallest $\sigma$-algebra regarding a function\<close>
  2013 
  2017 
  2014 definition
  2018 definition%important
  2015   "vimage_algebra X f M = sigma X {f -` A \<inter> X | A. A \<in> sets M}"
  2019   "vimage_algebra X f M = sigma X {f -` A \<inter> X | A. A \<in> sets M}"
  2016 
  2020 
  2017 lemma space_vimage_algebra[simp]: "space (vimage_algebra X f M) = X"
  2021 lemma space_vimage_algebra[simp]: "space (vimage_algebra X f M) = X"
  2018   unfolding vimage_algebra_def by (rule space_measure_of) auto
  2022   unfolding vimage_algebra_def by (rule space_measure_of) auto
  2019 
  2023