src/HOL/Probability/Measure_Space.thy
 author haftmann Fri Jul 04 20:18:47 2014 +0200 (2014-07-04) changeset 57512 cc97b347b301 parent 57447 87429bdecad5 child 58606 9c66f7c541fb permissions -rw-r--r--
reduced name variants for assoc and commute on plus and mult
```     1 (*  Title:      HOL/Probability/Measure_Space.thy
```
```     2     Author:     Lawrence C Paulson
```
```     3     Author:     Johannes Hölzl, TU München
```
```     4     Author:     Armin Heller, TU München
```
```     5 *)
```
```     6
```
```     7 header {* Measure spaces and their properties *}
```
```     8
```
```     9 theory Measure_Space
```
```    10 imports
```
```    11   Measurable Multivariate_Analysis
```
```    12 begin
```
```    13
```
```    14 subsection "Relate extended reals and the indicator function"
```
```    15
```
```    16 lemma suminf_cmult_indicator:
```
```    17   fixes f :: "nat \<Rightarrow> ereal"
```
```    18   assumes "disjoint_family A" "x \<in> A i" "\<And>i. 0 \<le> f i"
```
```    19   shows "(\<Sum>n. f n * indicator (A n) x) = f i"
```
```    20 proof -
```
```    21   have **: "\<And>n. f n * indicator (A n) x = (if n = i then f n else 0 :: ereal)"
```
```    22     using `x \<in> A i` assms unfolding disjoint_family_on_def indicator_def by auto
```
```    23   then have "\<And>n. (\<Sum>j<n. f j * indicator (A j) x) = (if i < n then f i else 0 :: ereal)"
```
```    24     by (auto simp: setsum.If_cases)
```
```    25   moreover have "(SUP n. if i < n then f i else 0) = (f i :: ereal)"
```
```    26   proof (rule SUP_eqI)
```
```    27     fix y :: ereal assume "\<And>n. n \<in> UNIV \<Longrightarrow> (if i < n then f i else 0) \<le> y"
```
```    28     from this[of "Suc i"] show "f i \<le> y" by auto
```
```    29   qed (insert assms, simp)
```
```    30   ultimately show ?thesis using assms
```
```    31     by (subst suminf_ereal_eq_SUP) (auto simp: indicator_def)
```
```    32 qed
```
```    33
```
```    34 lemma suminf_indicator:
```
```    35   assumes "disjoint_family A"
```
```    36   shows "(\<Sum>n. indicator (A n) x :: ereal) = indicator (\<Union>i. A i) x"
```
```    37 proof cases
```
```    38   assume *: "x \<in> (\<Union>i. A i)"
```
```    39   then obtain i where "x \<in> A i" by auto
```
```    40   from suminf_cmult_indicator[OF assms(1), OF `x \<in> A i`, of "\<lambda>k. 1"]
```
```    41   show ?thesis using * by simp
```
```    42 qed simp
```
```    43
```
```    44 text {*
```
```    45   The type for emeasure spaces is already defined in @{theory Sigma_Algebra}, as it is also used to
```
```    46   represent sigma algebras (with an arbitrary emeasure).
```
```    47 *}
```
```    48
```
```    49 subsection "Extend binary sets"
```
```    50
```
```    51 lemma LIMSEQ_binaryset:
```
```    52   assumes f: "f {} = 0"
```
```    53   shows  "(\<lambda>n. \<Sum>i<n. f (binaryset A B i)) ----> f A + f B"
```
```    54 proof -
```
```    55   have "(\<lambda>n. \<Sum>i < Suc (Suc n). f (binaryset A B i)) = (\<lambda>n. f A + f B)"
```
```    56     proof
```
```    57       fix n
```
```    58       show "(\<Sum>i < Suc (Suc n). f (binaryset A B i)) = f A + f B"
```
```    59         by (induct n)  (auto simp add: binaryset_def f)
```
```    60     qed
```
```    61   moreover
```
```    62   have "... ----> f A + f B" by (rule tendsto_const)
```
```    63   ultimately
```
```    64   have "(\<lambda>n. \<Sum>i< Suc (Suc n). f (binaryset A B i)) ----> f A + f B"
```
```    65     by metis
```
```    66   hence "(\<lambda>n. \<Sum>i< n+2. f (binaryset A B i)) ----> f A + f B"
```
```    67     by simp
```
```    68   thus ?thesis by (rule LIMSEQ_offset [where k=2])
```
```    69 qed
```
```    70
```
```    71 lemma binaryset_sums:
```
```    72   assumes f: "f {} = 0"
```
```    73   shows  "(\<lambda>n. f (binaryset A B n)) sums (f A + f B)"
```
```    74     by (simp add: sums_def LIMSEQ_binaryset [where f=f, OF f] atLeast0LessThan)
```
```    75
```
```    76 lemma suminf_binaryset_eq:
```
```    77   fixes f :: "'a set \<Rightarrow> 'b::{comm_monoid_add, t2_space}"
```
```    78   shows "f {} = 0 \<Longrightarrow> (\<Sum>n. f (binaryset A B n)) = f A + f B"
```
```    79   by (metis binaryset_sums sums_unique)
```
```    80
```
```    81 subsection {* Properties of a premeasure @{term \<mu>} *}
```
```    82
```
```    83 text {*
```
```    84   The definitions for @{const positive} and @{const countably_additive} should be here, by they are
```
```    85   necessary to define @{typ "'a measure"} in @{theory Sigma_Algebra}.
```
```    86 *}
```
```    87
```
```    88 definition additive where
```
```    89   "additive M \<mu> \<longleftrightarrow> (\<forall>x\<in>M. \<forall>y\<in>M. x \<inter> y = {} \<longrightarrow> \<mu> (x \<union> y) = \<mu> x + \<mu> y)"
```
```    90
```
```    91 definition increasing where
```
```    92   "increasing M \<mu> \<longleftrightarrow> (\<forall>x\<in>M. \<forall>y\<in>M. x \<subseteq> y \<longrightarrow> \<mu> x \<le> \<mu> y)"
```
```    93
```
```    94 lemma positiveD1: "positive M f \<Longrightarrow> f {} = 0" by (auto simp: positive_def)
```
```    95 lemma positiveD2: "positive M f \<Longrightarrow> A \<in> M \<Longrightarrow> 0 \<le> f A" by (auto simp: positive_def)
```
```    96
```
```    97 lemma positiveD_empty:
```
```    98   "positive M f \<Longrightarrow> f {} = 0"
```
```    99   by (auto simp add: positive_def)
```
```   100
```
```   101 lemma additiveD:
```
```   102   "additive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x \<in> M \<Longrightarrow> y \<in> M \<Longrightarrow> f (x \<union> y) = f x + f y"
```
```   103   by (auto simp add: additive_def)
```
```   104
```
```   105 lemma increasingD:
```
```   106   "increasing M f \<Longrightarrow> x \<subseteq> y \<Longrightarrow> x\<in>M \<Longrightarrow> y\<in>M \<Longrightarrow> f x \<le> f y"
```
```   107   by (auto simp add: increasing_def)
```
```   108
```
```   109 lemma countably_additiveI[case_names countably]:
```
```   110   "(\<And>A. range A \<subseteq> M \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Union>i. A i) \<in> M \<Longrightarrow> (\<Sum>i. f (A i)) = f (\<Union>i. A i))
```
```   111   \<Longrightarrow> countably_additive M f"
```
```   112   by (simp add: countably_additive_def)
```
```   113
```
```   114 lemma (in ring_of_sets) disjointed_additive:
```
```   115   assumes f: "positive M f" "additive M f" and A: "range A \<subseteq> M" "incseq A"
```
```   116   shows "(\<Sum>i\<le>n. f (disjointed A i)) = f (A n)"
```
```   117 proof (induct n)
```
```   118   case (Suc n)
```
```   119   then have "(\<Sum>i\<le>Suc n. f (disjointed A i)) = f (A n) + f (disjointed A (Suc n))"
```
```   120     by simp
```
```   121   also have "\<dots> = f (A n \<union> disjointed A (Suc n))"
```
```   122     using A by (subst f(2)[THEN additiveD]) (auto simp: disjointed_incseq)
```
```   123   also have "A n \<union> disjointed A (Suc n) = A (Suc n)"
```
```   124     using `incseq A` by (auto dest: incseq_SucD simp: disjointed_incseq)
```
```   125   finally show ?case .
```
```   126 qed simp
```
```   127
```
```   128 lemma (in ring_of_sets) additive_sum:
```
```   129   fixes A:: "'i \<Rightarrow> 'a set"
```
```   130   assumes f: "positive M f" and ad: "additive M f" and "finite S"
```
```   131       and A: "A`S \<subseteq> M"
```
```   132       and disj: "disjoint_family_on A S"
```
```   133   shows  "(\<Sum>i\<in>S. f (A i)) = f (\<Union>i\<in>S. A i)"
```
```   134   using `finite S` disj A
```
```   135 proof induct
```
```   136   case empty show ?case using f by (simp add: positive_def)
```
```   137 next
```
```   138   case (insert s S)
```
```   139   then have "A s \<inter> (\<Union>i\<in>S. A i) = {}"
```
```   140     by (auto simp add: disjoint_family_on_def neq_iff)
```
```   141   moreover
```
```   142   have "A s \<in> M" using insert by blast
```
```   143   moreover have "(\<Union>i\<in>S. A i) \<in> M"
```
```   144     using insert `finite S` by auto
```
```   145   ultimately have "f (A s \<union> (\<Union>i\<in>S. A i)) = f (A s) + f(\<Union>i\<in>S. A i)"
```
```   146     using ad UNION_in_sets A by (auto simp add: additive_def)
```
```   147   with insert show ?case using ad disjoint_family_on_mono[of S "insert s S" A]
```
```   148     by (auto simp add: additive_def subset_insertI)
```
```   149 qed
```
```   150
```
```   151 lemma (in ring_of_sets) additive_increasing:
```
```   152   assumes posf: "positive M f" and addf: "additive M f"
```
```   153   shows "increasing M f"
```
```   154 proof (auto simp add: increasing_def)
```
```   155   fix x y
```
```   156   assume xy: "x \<in> M" "y \<in> M" "x \<subseteq> y"
```
```   157   then have "y - x \<in> M" by auto
```
```   158   then have "0 \<le> f (y-x)" using posf[unfolded positive_def] by auto
```
```   159   then have "f x + 0 \<le> f x + f (y-x)" by (intro add_left_mono) auto
```
```   160   also have "... = f (x \<union> (y-x))" using addf
```
```   161     by (auto simp add: additive_def) (metis Diff_disjoint Un_Diff_cancel Diff xy(1,2))
```
```   162   also have "... = f y"
```
```   163     by (metis Un_Diff_cancel Un_absorb1 xy(3))
```
```   164   finally show "f x \<le> f y" by simp
```
```   165 qed
```
```   166
```
```   167 lemma (in ring_of_sets) subadditive:
```
```   168   assumes f: "positive M f" "additive M f" and A: "range A \<subseteq> M" and S: "finite S"
```
```   169   shows "f (\<Union>i\<in>S. A i) \<le> (\<Sum>i\<in>S. f (A i))"
```
```   170 using S
```
```   171 proof (induct S)
```
```   172   case empty thus ?case using f by (auto simp: positive_def)
```
```   173 next
```
```   174   case (insert x F)
```
```   175   hence in_M: "A x \<in> M" "(\<Union> i\<in>F. A i) \<in> M" "(\<Union> i\<in>F. A i) - A x \<in> M" using A by force+
```
```   176   have subs: "(\<Union> i\<in>F. A i) - A x \<subseteq> (\<Union> i\<in>F. A i)" by auto
```
```   177   have "(\<Union> i\<in>(insert x F). A i) = A x \<union> ((\<Union> i\<in>F. A i) - A x)" by auto
```
```   178   hence "f (\<Union> i\<in>(insert x F). A i) = f (A x \<union> ((\<Union> i\<in>F. A i) - A x))"
```
```   179     by simp
```
```   180   also have "\<dots> = f (A x) + f ((\<Union> i\<in>F. A i) - A x)"
```
```   181     using f(2) by (rule additiveD) (insert in_M, auto)
```
```   182   also have "\<dots> \<le> f (A x) + f (\<Union> i\<in>F. A i)"
```
```   183     using additive_increasing[OF f] in_M subs by (auto simp: increasing_def intro: add_left_mono)
```
```   184   also have "\<dots> \<le> f (A x) + (\<Sum>i\<in>F. f (A i))" using insert by (auto intro: add_left_mono)
```
```   185   finally show "f (\<Union> i\<in>(insert x F). A i) \<le> (\<Sum>i\<in>(insert x F). f (A i))" using insert by simp
```
```   186 qed
```
```   187
```
```   188 lemma (in ring_of_sets) countably_additive_additive:
```
```   189   assumes posf: "positive M f" and ca: "countably_additive M f"
```
```   190   shows "additive M f"
```
```   191 proof (auto simp add: additive_def)
```
```   192   fix x y
```
```   193   assume x: "x \<in> M" and y: "y \<in> M" and "x \<inter> y = {}"
```
```   194   hence "disjoint_family (binaryset x y)"
```
```   195     by (auto simp add: disjoint_family_on_def binaryset_def)
```
```   196   hence "range (binaryset x y) \<subseteq> M \<longrightarrow>
```
```   197          (\<Union>i. binaryset x y i) \<in> M \<longrightarrow>
```
```   198          f (\<Union>i. binaryset x y i) = (\<Sum> n. f (binaryset x y n))"
```
```   199     using ca
```
```   200     by (simp add: countably_additive_def)
```
```   201   hence "{x,y,{}} \<subseteq> M \<longrightarrow> x \<union> y \<in> M \<longrightarrow>
```
```   202          f (x \<union> y) = (\<Sum>n. f (binaryset x y n))"
```
```   203     by (simp add: range_binaryset_eq UN_binaryset_eq)
```
```   204   thus "f (x \<union> y) = f x + f y" using posf x y
```
```   205     by (auto simp add: Un suminf_binaryset_eq positive_def)
```
```   206 qed
```
```   207
```
```   208 lemma (in algebra) increasing_additive_bound:
```
```   209   fixes A:: "nat \<Rightarrow> 'a set" and  f :: "'a set \<Rightarrow> ereal"
```
```   210   assumes f: "positive M f" and ad: "additive M f"
```
```   211       and inc: "increasing M f"
```
```   212       and A: "range A \<subseteq> M"
```
```   213       and disj: "disjoint_family A"
```
```   214   shows  "(\<Sum>i. f (A i)) \<le> f \<Omega>"
```
```   215 proof (safe intro!: suminf_bound)
```
```   216   fix N
```
```   217   note disj_N = disjoint_family_on_mono[OF _ disj, of "{..<N}"]
```
```   218   have "(\<Sum>i<N. f (A i)) = f (\<Union>i\<in>{..<N}. A i)"
```
```   219     using A by (intro additive_sum [OF f ad _ _]) (auto simp: disj_N)
```
```   220   also have "... \<le> f \<Omega>" using space_closed A
```
```   221     by (intro increasingD[OF inc] finite_UN) auto
```
```   222   finally show "(\<Sum>i<N. f (A i)) \<le> f \<Omega>" by simp
```
```   223 qed (insert f A, auto simp: positive_def)
```
```   224
```
```   225 lemma (in ring_of_sets) countably_additiveI_finite:
```
```   226   assumes "finite \<Omega>" "positive M \<mu>" "additive M \<mu>"
```
```   227   shows "countably_additive M \<mu>"
```
```   228 proof (rule countably_additiveI)
```
```   229   fix F :: "nat \<Rightarrow> 'a set" assume F: "range F \<subseteq> M" "(\<Union>i. F i) \<in> M" and disj: "disjoint_family F"
```
```   230
```
```   231   have "\<forall>i\<in>{i. F i \<noteq> {}}. \<exists>x. x \<in> F i" by auto
```
```   232   from bchoice[OF this] obtain f where f: "\<And>i. F i \<noteq> {} \<Longrightarrow> f i \<in> F i" by auto
```
```   233
```
```   234   have inj_f: "inj_on f {i. F i \<noteq> {}}"
```
```   235   proof (rule inj_onI, simp)
```
```   236     fix i j a b assume *: "f i = f j" "F i \<noteq> {}" "F j \<noteq> {}"
```
```   237     then have "f i \<in> F i" "f j \<in> F j" using f by force+
```
```   238     with disj * show "i = j" by (auto simp: disjoint_family_on_def)
```
```   239   qed
```
```   240   have "finite (\<Union>i. F i)"
```
```   241     by (metis F(2) assms(1) infinite_super sets_into_space)
```
```   242
```
```   243   have F_subset: "{i. \<mu> (F i) \<noteq> 0} \<subseteq> {i. F i \<noteq> {}}"
```
```   244     by (auto simp: positiveD_empty[OF `positive M \<mu>`])
```
```   245   moreover have fin_not_empty: "finite {i. F i \<noteq> {}}"
```
```   246   proof (rule finite_imageD)
```
```   247     from f have "f`{i. F i \<noteq> {}} \<subseteq> (\<Union>i. F i)" by auto
```
```   248     then show "finite (f`{i. F i \<noteq> {}})"
```
```   249       by (rule finite_subset) fact
```
```   250   qed fact
```
```   251   ultimately have fin_not_0: "finite {i. \<mu> (F i) \<noteq> 0}"
```
```   252     by (rule finite_subset)
```
```   253
```
```   254   have disj_not_empty: "disjoint_family_on F {i. F i \<noteq> {}}"
```
```   255     using disj by (auto simp: disjoint_family_on_def)
```
```   256
```
```   257   from fin_not_0 have "(\<Sum>i. \<mu> (F i)) = (\<Sum>i | \<mu> (F i) \<noteq> 0. \<mu> (F i))"
```
```   258     by (rule suminf_finite) auto
```
```   259   also have "\<dots> = (\<Sum>i | F i \<noteq> {}. \<mu> (F i))"
```
```   260     using fin_not_empty F_subset by (rule setsum.mono_neutral_left) auto
```
```   261   also have "\<dots> = \<mu> (\<Union>i\<in>{i. F i \<noteq> {}}. F i)"
```
```   262     using `positive M \<mu>` `additive M \<mu>` fin_not_empty disj_not_empty F by (intro additive_sum) auto
```
```   263   also have "\<dots> = \<mu> (\<Union>i. F i)"
```
```   264     by (rule arg_cong[where f=\<mu>]) auto
```
```   265   finally show "(\<Sum>i. \<mu> (F i)) = \<mu> (\<Union>i. F i)" .
```
```   266 qed
```
```   267
```
```   268 lemma (in ring_of_sets) countably_additive_iff_continuous_from_below:
```
```   269   assumes f: "positive M f" "additive M f"
```
```   270   shows "countably_additive M f \<longleftrightarrow>
```
```   271     (\<forall>A. range A \<subseteq> M \<longrightarrow> incseq A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow> (\<lambda>i. f (A i)) ----> f (\<Union>i. A i))"
```
```   272   unfolding countably_additive_def
```
```   273 proof safe
```
```   274   assume count_sum: "\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> UNION UNIV A \<in> M \<longrightarrow> (\<Sum>i. f (A i)) = f (UNION UNIV A)"
```
```   275   fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" "incseq A" "(\<Union>i. A i) \<in> M"
```
```   276   then have dA: "range (disjointed A) \<subseteq> M" by (auto simp: range_disjointed_sets)
```
```   277   with count_sum[THEN spec, of "disjointed A"] A(3)
```
```   278   have f_UN: "(\<Sum>i. f (disjointed A i)) = f (\<Union>i. A i)"
```
```   279     by (auto simp: UN_disjointed_eq disjoint_family_disjointed)
```
```   280   moreover have "(\<lambda>n. (\<Sum>i<n. f (disjointed A i))) ----> (\<Sum>i. f (disjointed A i))"
```
```   281     using f(1)[unfolded positive_def] dA
```
```   282     by (auto intro!: summable_LIMSEQ summable_ereal_pos)
```
```   283   from LIMSEQ_Suc[OF this]
```
```   284   have "(\<lambda>n. (\<Sum>i\<le>n. f (disjointed A i))) ----> (\<Sum>i. f (disjointed A i))"
```
```   285     unfolding lessThan_Suc_atMost .
```
```   286   moreover have "\<And>n. (\<Sum>i\<le>n. f (disjointed A i)) = f (A n)"
```
```   287     using disjointed_additive[OF f A(1,2)] .
```
```   288   ultimately show "(\<lambda>i. f (A i)) ----> f (\<Union>i. A i)" by simp
```
```   289 next
```
```   290   assume cont: "\<forall>A. range A \<subseteq> M \<longrightarrow> incseq A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow> (\<lambda>i. f (A i)) ----> f (\<Union>i. A i)"
```
```   291   fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" "disjoint_family A" "(\<Union>i. A i) \<in> M"
```
```   292   have *: "(\<Union>n. (\<Union>i<n. A i)) = (\<Union>i. A i)" by auto
```
```   293   have "(\<lambda>n. f (\<Union>i<n. A i)) ----> f (\<Union>i. A i)"
```
```   294   proof (unfold *[symmetric], intro cont[rule_format])
```
```   295     show "range (\<lambda>i. \<Union> i<i. A i) \<subseteq> M" "(\<Union>i. \<Union> i<i. A i) \<in> M"
```
```   296       using A * by auto
```
```   297   qed (force intro!: incseq_SucI)
```
```   298   moreover have "\<And>n. f (\<Union>i<n. A i) = (\<Sum>i<n. f (A i))"
```
```   299     using A
```
```   300     by (intro additive_sum[OF f, of _ A, symmetric])
```
```   301        (auto intro: disjoint_family_on_mono[where B=UNIV])
```
```   302   ultimately
```
```   303   have "(\<lambda>i. f (A i)) sums f (\<Union>i. A i)"
```
```   304     unfolding sums_def by simp
```
```   305   from sums_unique[OF this]
```
```   306   show "(\<Sum>i. f (A i)) = f (\<Union>i. A i)" by simp
```
```   307 qed
```
```   308
```
```   309 lemma (in ring_of_sets) continuous_from_above_iff_empty_continuous:
```
```   310   assumes f: "positive M f" "additive M f"
```
```   311   shows "(\<forall>A. range A \<subseteq> M \<longrightarrow> decseq A \<longrightarrow> (\<Inter>i. A i) \<in> M \<longrightarrow> (\<forall>i. f (A i) \<noteq> \<infinity>) \<longrightarrow> (\<lambda>i. f (A i)) ----> f (\<Inter>i. A i))
```
```   312      \<longleftrightarrow> (\<forall>A. range A \<subseteq> M \<longrightarrow> decseq A \<longrightarrow> (\<Inter>i. A i) = {} \<longrightarrow> (\<forall>i. f (A i) \<noteq> \<infinity>) \<longrightarrow> (\<lambda>i. f (A i)) ----> 0)"
```
```   313 proof safe
```
```   314   assume cont: "(\<forall>A. range A \<subseteq> M \<longrightarrow> decseq A \<longrightarrow> (\<Inter>i. A i) \<in> M \<longrightarrow> (\<forall>i. f (A i) \<noteq> \<infinity>) \<longrightarrow> (\<lambda>i. f (A i)) ----> f (\<Inter>i. A i))"
```
```   315   fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" "decseq A" "(\<Inter>i. A i) = {}" "\<forall>i. f (A i) \<noteq> \<infinity>"
```
```   316   with cont[THEN spec, of A] show "(\<lambda>i. f (A i)) ----> 0"
```
```   317     using `positive M f`[unfolded positive_def] by auto
```
```   318 next
```
```   319   assume cont: "\<forall>A. range A \<subseteq> M \<longrightarrow> decseq A \<longrightarrow> (\<Inter>i. A i) = {} \<longrightarrow> (\<forall>i. f (A i) \<noteq> \<infinity>) \<longrightarrow> (\<lambda>i. f (A i)) ----> 0"
```
```   320   fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" "decseq A" "(\<Inter>i. A i) \<in> M" "\<forall>i. f (A i) \<noteq> \<infinity>"
```
```   321
```
```   322   have f_mono: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<subseteq> b \<Longrightarrow> f a \<le> f b"
```
```   323     using additive_increasing[OF f] unfolding increasing_def by simp
```
```   324
```
```   325   have decseq_fA: "decseq (\<lambda>i. f (A i))"
```
```   326     using A by (auto simp: decseq_def intro!: f_mono)
```
```   327   have decseq: "decseq (\<lambda>i. A i - (\<Inter>i. A i))"
```
```   328     using A by (auto simp: decseq_def)
```
```   329   then have decseq_f: "decseq (\<lambda>i. f (A i - (\<Inter>i. A i)))"
```
```   330     using A unfolding decseq_def by (auto intro!: f_mono Diff)
```
```   331   have "f (\<Inter>x. A x) \<le> f (A 0)"
```
```   332     using A by (auto intro!: f_mono)
```
```   333   then have f_Int_fin: "f (\<Inter>x. A x) \<noteq> \<infinity>"
```
```   334     using A by auto
```
```   335   { fix i
```
```   336     have "f (A i - (\<Inter>i. A i)) \<le> f (A i)" using A by (auto intro!: f_mono)
```
```   337     then have "f (A i - (\<Inter>i. A i)) \<noteq> \<infinity>"
```
```   338       using A by auto }
```
```   339   note f_fin = this
```
```   340   have "(\<lambda>i. f (A i - (\<Inter>i. A i))) ----> 0"
```
```   341   proof (intro cont[rule_format, OF _ decseq _ f_fin])
```
```   342     show "range (\<lambda>i. A i - (\<Inter>i. A i)) \<subseteq> M" "(\<Inter>i. A i - (\<Inter>i. A i)) = {}"
```
```   343       using A by auto
```
```   344   qed
```
```   345   from INF_Lim_ereal[OF decseq_f this]
```
```   346   have "(INF n. f (A n - (\<Inter>i. A i))) = 0" .
```
```   347   moreover have "(INF n. f (\<Inter>i. A i)) = f (\<Inter>i. A i)"
```
```   348     by auto
```
```   349   ultimately have "(INF n. f (A n - (\<Inter>i. A i)) + f (\<Inter>i. A i)) = 0 + f (\<Inter>i. A i)"
```
```   350     using A(4) f_fin f_Int_fin
```
```   351     by (subst INF_ereal_add) (auto simp: decseq_f)
```
```   352   moreover {
```
```   353     fix n
```
```   354     have "f (A n - (\<Inter>i. A i)) + f (\<Inter>i. A i) = f ((A n - (\<Inter>i. A i)) \<union> (\<Inter>i. A i))"
```
```   355       using A by (subst f(2)[THEN additiveD]) auto
```
```   356     also have "(A n - (\<Inter>i. A i)) \<union> (\<Inter>i. A i) = A n"
```
```   357       by auto
```
```   358     finally have "f (A n - (\<Inter>i. A i)) + f (\<Inter>i. A i) = f (A n)" . }
```
```   359   ultimately have "(INF n. f (A n)) = f (\<Inter>i. A i)"
```
```   360     by simp
```
```   361   with LIMSEQ_INF[OF decseq_fA]
```
```   362   show "(\<lambda>i. f (A i)) ----> f (\<Inter>i. A i)" by simp
```
```   363 qed
```
```   364
```
```   365 lemma (in ring_of_sets) empty_continuous_imp_continuous_from_below:
```
```   366   assumes f: "positive M f" "additive M f" "\<forall>A\<in>M. f A \<noteq> \<infinity>"
```
```   367   assumes cont: "\<forall>A. range A \<subseteq> M \<longrightarrow> decseq A \<longrightarrow> (\<Inter>i. A i) = {} \<longrightarrow> (\<lambda>i. f (A i)) ----> 0"
```
```   368   assumes A: "range A \<subseteq> M" "incseq A" "(\<Union>i. A i) \<in> M"
```
```   369   shows "(\<lambda>i. f (A i)) ----> f (\<Union>i. A i)"
```
```   370 proof -
```
```   371   have "\<forall>A\<in>M. \<exists>x. f A = ereal x"
```
```   372   proof
```
```   373     fix A assume "A \<in> M" with f show "\<exists>x. f A = ereal x"
```
```   374       unfolding positive_def by (cases "f A") auto
```
```   375   qed
```
```   376   from bchoice[OF this] guess f' .. note f' = this[rule_format]
```
```   377   from A have "(\<lambda>i. f ((\<Union>i. A i) - A i)) ----> 0"
```
```   378     by (intro cont[rule_format]) (auto simp: decseq_def incseq_def)
```
```   379   moreover
```
```   380   { fix i
```
```   381     have "f ((\<Union>i. A i) - A i) + f (A i) = f ((\<Union>i. A i) - A i \<union> A i)"
```
```   382       using A by (intro f(2)[THEN additiveD, symmetric]) auto
```
```   383     also have "(\<Union>i. A i) - A i \<union> A i = (\<Union>i. A i)"
```
```   384       by auto
```
```   385     finally have "f' (\<Union>i. A i) - f' (A i) = f' ((\<Union>i. A i) - A i)"
```
```   386       using A by (subst (asm) (1 2 3) f') auto
```
```   387     then have "f ((\<Union>i. A i) - A i) = ereal (f' (\<Union>i. A i) - f' (A i))"
```
```   388       using A f' by auto }
```
```   389   ultimately have "(\<lambda>i. f' (\<Union>i. A i) - f' (A i)) ----> 0"
```
```   390     by (simp add: zero_ereal_def)
```
```   391   then have "(\<lambda>i. f' (A i)) ----> f' (\<Union>i. A i)"
```
```   392     by (rule LIMSEQ_diff_approach_zero2[OF tendsto_const])
```
```   393   then show "(\<lambda>i. f (A i)) ----> f (\<Union>i. A i)"
```
```   394     using A by (subst (1 2) f') auto
```
```   395 qed
```
```   396
```
```   397 lemma (in ring_of_sets) empty_continuous_imp_countably_additive:
```
```   398   assumes f: "positive M f" "additive M f" and fin: "\<forall>A\<in>M. f A \<noteq> \<infinity>"
```
```   399   assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) ----> 0"
```
```   400   shows "countably_additive M f"
```
```   401   using countably_additive_iff_continuous_from_below[OF f]
```
```   402   using empty_continuous_imp_continuous_from_below[OF f fin] cont
```
```   403   by blast
```
```   404
```
```   405 subsection {* Properties of @{const emeasure} *}
```
```   406
```
```   407 lemma emeasure_positive: "positive (sets M) (emeasure M)"
```
```   408   by (cases M) (auto simp: sets_def emeasure_def Abs_measure_inverse measure_space_def)
```
```   409
```
```   410 lemma emeasure_empty[simp, intro]: "emeasure M {} = 0"
```
```   411   using emeasure_positive[of M] by (simp add: positive_def)
```
```   412
```
```   413 lemma emeasure_nonneg[intro!]: "0 \<le> emeasure M A"
```
```   414   using emeasure_notin_sets[of A M] emeasure_positive[of M]
```
```   415   by (cases "A \<in> sets M") (auto simp: positive_def)
```
```   416
```
```   417 lemma emeasure_not_MInf[simp]: "emeasure M A \<noteq> - \<infinity>"
```
```   418   using emeasure_nonneg[of M A] by auto
```
```   419
```
```   420 lemma emeasure_le_0_iff: "emeasure M A \<le> 0 \<longleftrightarrow> emeasure M A = 0"
```
```   421   using emeasure_nonneg[of M A] by auto
```
```   422
```
```   423 lemma emeasure_less_0_iff: "emeasure M A < 0 \<longleftrightarrow> False"
```
```   424   using emeasure_nonneg[of M A] by auto
```
```   425
```
```   426 lemma emeasure_countably_additive: "countably_additive (sets M) (emeasure M)"
```
```   427   by (cases M) (auto simp: sets_def emeasure_def Abs_measure_inverse measure_space_def)
```
```   428
```
```   429 lemma suminf_emeasure:
```
```   430   "range A \<subseteq> sets M \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Sum>i. emeasure M (A i)) = emeasure M (\<Union>i. A i)"
```
```   431   using sets.countable_UN[of A UNIV M] emeasure_countably_additive[of M]
```
```   432   by (simp add: countably_additive_def)
```
```   433
```
```   434 lemma sums_emeasure:
```
```   435   "disjoint_family F \<Longrightarrow> (\<And>i. F i \<in> sets M) \<Longrightarrow> (\<lambda>i. emeasure M (F i)) sums emeasure M (\<Union>i. F i)"
```
```   436   unfolding sums_iff by (intro conjI summable_ereal_pos emeasure_nonneg suminf_emeasure) auto
```
```   437
```
```   438 lemma emeasure_additive: "additive (sets M) (emeasure M)"
```
```   439   by (metis sets.countably_additive_additive emeasure_positive emeasure_countably_additive)
```
```   440
```
```   441 lemma plus_emeasure:
```
```   442   "a \<in> sets M \<Longrightarrow> b \<in> sets M \<Longrightarrow> a \<inter> b = {} \<Longrightarrow> emeasure M a + emeasure M b = emeasure M (a \<union> b)"
```
```   443   using additiveD[OF emeasure_additive] ..
```
```   444
```
```   445 lemma setsum_emeasure:
```
```   446   "F`I \<subseteq> sets M \<Longrightarrow> disjoint_family_on F I \<Longrightarrow> finite I \<Longrightarrow>
```
```   447     (\<Sum>i\<in>I. emeasure M (F i)) = emeasure M (\<Union>i\<in>I. F i)"
```
```   448   by (metis sets.additive_sum emeasure_positive emeasure_additive)
```
```   449
```
```   450 lemma emeasure_mono:
```
```   451   "a \<subseteq> b \<Longrightarrow> b \<in> sets M \<Longrightarrow> emeasure M a \<le> emeasure M b"
```
```   452   by (metis sets.additive_increasing emeasure_additive emeasure_nonneg emeasure_notin_sets
```
```   453             emeasure_positive increasingD)
```
```   454
```
```   455 lemma emeasure_space:
```
```   456   "emeasure M A \<le> emeasure M (space M)"
```
```   457   by (metis emeasure_mono emeasure_nonneg emeasure_notin_sets sets.sets_into_space sets.top)
```
```   458
```
```   459 lemma emeasure_compl:
```
```   460   assumes s: "s \<in> sets M" and fin: "emeasure M s \<noteq> \<infinity>"
```
```   461   shows "emeasure M (space M - s) = emeasure M (space M) - emeasure M s"
```
```   462 proof -
```
```   463   from s have "0 \<le> emeasure M s" by auto
```
```   464   have "emeasure M (space M) = emeasure M (s \<union> (space M - s))" using s
```
```   465     by (metis Un_Diff_cancel Un_absorb1 s sets.sets_into_space)
```
```   466   also have "... = emeasure M s + emeasure M (space M - s)"
```
```   467     by (rule plus_emeasure[symmetric]) (auto simp add: s)
```
```   468   finally have "emeasure M (space M) = emeasure M s + emeasure M (space M - s)" .
```
```   469   then show ?thesis
```
```   470     using fin `0 \<le> emeasure M s`
```
```   471     unfolding ereal_eq_minus_iff by (auto simp: ac_simps)
```
```   472 qed
```
```   473
```
```   474 lemma emeasure_Diff:
```
```   475   assumes finite: "emeasure M B \<noteq> \<infinity>"
```
```   476   and [measurable]: "A \<in> sets M" "B \<in> sets M" and "B \<subseteq> A"
```
```   477   shows "emeasure M (A - B) = emeasure M A - emeasure M B"
```
```   478 proof -
```
```   479   have "0 \<le> emeasure M B" using assms by auto
```
```   480   have "(A - B) \<union> B = A" using `B \<subseteq> A` by auto
```
```   481   then have "emeasure M A = emeasure M ((A - B) \<union> B)" by simp
```
```   482   also have "\<dots> = emeasure M (A - B) + emeasure M B"
```
```   483     by (subst plus_emeasure[symmetric]) auto
```
```   484   finally show "emeasure M (A - B) = emeasure M A - emeasure M B"
```
```   485     unfolding ereal_eq_minus_iff
```
```   486     using finite `0 \<le> emeasure M B` by auto
```
```   487 qed
```
```   488
```
```   489 lemma Lim_emeasure_incseq:
```
```   490   "range A \<subseteq> sets M \<Longrightarrow> incseq A \<Longrightarrow> (\<lambda>i. (emeasure M (A i))) ----> emeasure M (\<Union>i. A i)"
```
```   491   using emeasure_countably_additive
```
```   492   by (auto simp add: sets.countably_additive_iff_continuous_from_below emeasure_positive
```
```   493     emeasure_additive)
```
```   494
```
```   495 lemma incseq_emeasure:
```
```   496   assumes "range B \<subseteq> sets M" "incseq B"
```
```   497   shows "incseq (\<lambda>i. emeasure M (B i))"
```
```   498   using assms by (auto simp: incseq_def intro!: emeasure_mono)
```
```   499
```
```   500 lemma SUP_emeasure_incseq:
```
```   501   assumes A: "range A \<subseteq> sets M" "incseq A"
```
```   502   shows "(SUP n. emeasure M (A n)) = emeasure M (\<Union>i. A i)"
```
```   503   using LIMSEQ_SUP[OF incseq_emeasure, OF A] Lim_emeasure_incseq[OF A]
```
```   504   by (simp add: LIMSEQ_unique)
```
```   505
```
```   506 lemma decseq_emeasure:
```
```   507   assumes "range B \<subseteq> sets M" "decseq B"
```
```   508   shows "decseq (\<lambda>i. emeasure M (B i))"
```
```   509   using assms by (auto simp: decseq_def intro!: emeasure_mono)
```
```   510
```
```   511 lemma INF_emeasure_decseq:
```
```   512   assumes A: "range A \<subseteq> sets M" and "decseq A"
```
```   513   and finite: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
```
```   514   shows "(INF n. emeasure M (A n)) = emeasure M (\<Inter>i. A i)"
```
```   515 proof -
```
```   516   have le_MI: "emeasure M (\<Inter>i. A i) \<le> emeasure M (A 0)"
```
```   517     using A by (auto intro!: emeasure_mono)
```
```   518   hence *: "emeasure M (\<Inter>i. A i) \<noteq> \<infinity>" using finite[of 0] by auto
```
```   519
```
```   520   have A0: "0 \<le> emeasure M (A 0)" using A by auto
```
```   521
```
```   522   have "emeasure M (A 0) - (INF n. emeasure M (A n)) = emeasure M (A 0) + (SUP n. - emeasure M (A n))"
```
```   523     by (simp add: ereal_SUP_uminus minus_ereal_def)
```
```   524   also have "\<dots> = (SUP n. emeasure M (A 0) - emeasure M (A n))"
```
```   525     unfolding minus_ereal_def using A0 assms
```
```   526     by (subst SUP_ereal_add) (auto simp add: decseq_emeasure)
```
```   527   also have "\<dots> = (SUP n. emeasure M (A 0 - A n))"
```
```   528     using A finite `decseq A`[unfolded decseq_def] by (subst emeasure_Diff) auto
```
```   529   also have "\<dots> = emeasure M (\<Union>i. A 0 - A i)"
```
```   530   proof (rule SUP_emeasure_incseq)
```
```   531     show "range (\<lambda>n. A 0 - A n) \<subseteq> sets M"
```
```   532       using A by auto
```
```   533     show "incseq (\<lambda>n. A 0 - A n)"
```
```   534       using `decseq A` by (auto simp add: incseq_def decseq_def)
```
```   535   qed
```
```   536   also have "\<dots> = emeasure M (A 0) - emeasure M (\<Inter>i. A i)"
```
```   537     using A finite * by (simp, subst emeasure_Diff) auto
```
```   538   finally show ?thesis
```
```   539     unfolding ereal_minus_eq_minus_iff using finite A0 by auto
```
```   540 qed
```
```   541
```
```   542 lemma Lim_emeasure_decseq:
```
```   543   assumes A: "range A \<subseteq> sets M" "decseq A" and fin: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
```
```   544   shows "(\<lambda>i. emeasure M (A i)) ----> emeasure M (\<Inter>i. A i)"
```
```   545   using LIMSEQ_INF[OF decseq_emeasure, OF A]
```
```   546   using INF_emeasure_decseq[OF A fin] by simp
```
```   547
```
```   548 lemma emeasure_subadditive:
```
```   549   assumes [measurable]: "A \<in> sets M" "B \<in> sets M"
```
```   550   shows "emeasure M (A \<union> B) \<le> emeasure M A + emeasure M B"
```
```   551 proof -
```
```   552   from plus_emeasure[of A M "B - A"]
```
```   553   have "emeasure M (A \<union> B) = emeasure M A + emeasure M (B - A)" by simp
```
```   554   also have "\<dots> \<le> emeasure M A + emeasure M B"
```
```   555     using assms by (auto intro!: add_left_mono emeasure_mono)
```
```   556   finally show ?thesis .
```
```   557 qed
```
```   558
```
```   559 lemma emeasure_subadditive_finite:
```
```   560   assumes "finite I" "A ` I \<subseteq> sets M"
```
```   561   shows "emeasure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. emeasure M (A i))"
```
```   562 using assms proof induct
```
```   563   case (insert i I)
```
```   564   then have "emeasure M (\<Union>i\<in>insert i I. A i) = emeasure M (A i \<union> (\<Union>i\<in>I. A i))"
```
```   565     by simp
```
```   566   also have "\<dots> \<le> emeasure M (A i) + emeasure M (\<Union>i\<in>I. A i)"
```
```   567     using insert by (intro emeasure_subadditive) auto
```
```   568   also have "\<dots> \<le> emeasure M (A i) + (\<Sum>i\<in>I. emeasure M (A i))"
```
```   569     using insert by (intro add_mono) auto
```
```   570   also have "\<dots> = (\<Sum>i\<in>insert i I. emeasure M (A i))"
```
```   571     using insert by auto
```
```   572   finally show ?case .
```
```   573 qed simp
```
```   574
```
```   575 lemma emeasure_subadditive_countably:
```
```   576   assumes "range f \<subseteq> sets M"
```
```   577   shows "emeasure M (\<Union>i. f i) \<le> (\<Sum>i. emeasure M (f i))"
```
```   578 proof -
```
```   579   have "emeasure M (\<Union>i. f i) = emeasure M (\<Union>i. disjointed f i)"
```
```   580     unfolding UN_disjointed_eq ..
```
```   581   also have "\<dots> = (\<Sum>i. emeasure M (disjointed f i))"
```
```   582     using sets.range_disjointed_sets[OF assms] suminf_emeasure[of "disjointed f"]
```
```   583     by (simp add:  disjoint_family_disjointed comp_def)
```
```   584   also have "\<dots> \<le> (\<Sum>i. emeasure M (f i))"
```
```   585     using sets.range_disjointed_sets[OF assms] assms
```
```   586     by (auto intro!: suminf_le_pos emeasure_mono disjointed_subset)
```
```   587   finally show ?thesis .
```
```   588 qed
```
```   589
```
```   590 lemma emeasure_insert:
```
```   591   assumes sets: "{x} \<in> sets M" "A \<in> sets M" and "x \<notin> A"
```
```   592   shows "emeasure M (insert x A) = emeasure M {x} + emeasure M A"
```
```   593 proof -
```
```   594   have "{x} \<inter> A = {}" using `x \<notin> A` by auto
```
```   595   from plus_emeasure[OF sets this] show ?thesis by simp
```
```   596 qed
```
```   597
```
```   598 lemma emeasure_insert_ne:
```
```   599   "A \<noteq> {} \<Longrightarrow> {x} \<in> sets M \<Longrightarrow> A \<in> sets M \<Longrightarrow> x \<notin> A \<Longrightarrow> emeasure M (insert x A) = emeasure M {x} + emeasure M A"
```
```   600   by (rule emeasure_insert)
```
```   601
```
```   602 lemma emeasure_eq_setsum_singleton:
```
```   603   assumes "finite S" "\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M"
```
```   604   shows "emeasure M S = (\<Sum>x\<in>S. emeasure M {x})"
```
```   605   using setsum_emeasure[of "\<lambda>x. {x}" S M] assms
```
```   606   by (auto simp: disjoint_family_on_def subset_eq)
```
```   607
```
```   608 lemma setsum_emeasure_cover:
```
```   609   assumes "finite S" and "A \<in> sets M" and br_in_M: "B ` S \<subseteq> sets M"
```
```   610   assumes A: "A \<subseteq> (\<Union>i\<in>S. B i)"
```
```   611   assumes disj: "disjoint_family_on B S"
```
```   612   shows "emeasure M A = (\<Sum>i\<in>S. emeasure M (A \<inter> (B i)))"
```
```   613 proof -
```
```   614   have "(\<Sum>i\<in>S. emeasure M (A \<inter> (B i))) = emeasure M (\<Union>i\<in>S. A \<inter> (B i))"
```
```   615   proof (rule setsum_emeasure)
```
```   616     show "disjoint_family_on (\<lambda>i. A \<inter> B i) S"
```
```   617       using `disjoint_family_on B S`
```
```   618       unfolding disjoint_family_on_def by auto
```
```   619   qed (insert assms, auto)
```
```   620   also have "(\<Union>i\<in>S. A \<inter> (B i)) = A"
```
```   621     using A by auto
```
```   622   finally show ?thesis by simp
```
```   623 qed
```
```   624
```
```   625 lemma emeasure_eq_0:
```
```   626   "N \<in> sets M \<Longrightarrow> emeasure M N = 0 \<Longrightarrow> K \<subseteq> N \<Longrightarrow> emeasure M K = 0"
```
```   627   by (metis emeasure_mono emeasure_nonneg order_eq_iff)
```
```   628
```
```   629 lemma emeasure_UN_eq_0:
```
```   630   assumes "\<And>i::nat. emeasure M (N i) = 0" and "range N \<subseteq> sets M"
```
```   631   shows "emeasure M (\<Union> i. N i) = 0"
```
```   632 proof -
```
```   633   have "0 \<le> emeasure M (\<Union> i. N i)" using assms by auto
```
```   634   moreover have "emeasure M (\<Union> i. N i) \<le> 0"
```
```   635     using emeasure_subadditive_countably[OF assms(2)] assms(1) by simp
```
```   636   ultimately show ?thesis by simp
```
```   637 qed
```
```   638
```
```   639 lemma measure_eqI_finite:
```
```   640   assumes [simp]: "sets M = Pow A" "sets N = Pow A" and "finite A"
```
```   641   assumes eq: "\<And>a. a \<in> A \<Longrightarrow> emeasure M {a} = emeasure N {a}"
```
```   642   shows "M = N"
```
```   643 proof (rule measure_eqI)
```
```   644   fix X assume "X \<in> sets M"
```
```   645   then have X: "X \<subseteq> A" by auto
```
```   646   then have "emeasure M X = (\<Sum>a\<in>X. emeasure M {a})"
```
```   647     using `finite A` by (subst emeasure_eq_setsum_singleton) (auto dest: finite_subset)
```
```   648   also have "\<dots> = (\<Sum>a\<in>X. emeasure N {a})"
```
```   649     using X eq by (auto intro!: setsum.cong)
```
```   650   also have "\<dots> = emeasure N X"
```
```   651     using X `finite A` by (subst emeasure_eq_setsum_singleton) (auto dest: finite_subset)
```
```   652   finally show "emeasure M X = emeasure N X" .
```
```   653 qed simp
```
```   654
```
```   655 lemma measure_eqI_generator_eq:
```
```   656   fixes M N :: "'a measure" and E :: "'a set set" and A :: "nat \<Rightarrow> 'a set"
```
```   657   assumes "Int_stable E" "E \<subseteq> Pow \<Omega>"
```
```   658   and eq: "\<And>X. X \<in> E \<Longrightarrow> emeasure M X = emeasure N X"
```
```   659   and M: "sets M = sigma_sets \<Omega> E"
```
```   660   and N: "sets N = sigma_sets \<Omega> E"
```
```   661   and A: "range A \<subseteq> E" "(\<Union>i. A i) = \<Omega>" "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
```
```   662   shows "M = N"
```
```   663 proof -
```
```   664   let ?\<mu>  = "emeasure M" and ?\<nu> = "emeasure N"
```
```   665   interpret S: sigma_algebra \<Omega> "sigma_sets \<Omega> E" by (rule sigma_algebra_sigma_sets) fact
```
```   666   have "space M = \<Omega>"
```
```   667     using sets.top[of M] sets.space_closed[of M] S.top S.space_closed `sets M = sigma_sets \<Omega> E`
```
```   668     by blast
```
```   669
```
```   670   { fix F D assume "F \<in> E" and "?\<mu> F \<noteq> \<infinity>"
```
```   671     then have [intro]: "F \<in> sigma_sets \<Omega> E" by auto
```
```   672     have "?\<nu> F \<noteq> \<infinity>" using `?\<mu> F \<noteq> \<infinity>` `F \<in> E` eq by simp
```
```   673     assume "D \<in> sets M"
```
```   674     with `Int_stable E` `E \<subseteq> Pow \<Omega>` have "emeasure M (F \<inter> D) = emeasure N (F \<inter> D)"
```
```   675       unfolding M
```
```   676     proof (induct rule: sigma_sets_induct_disjoint)
```
```   677       case (basic A)
```
```   678       then have "F \<inter> A \<in> E" using `Int_stable E` `F \<in> E` by (auto simp: Int_stable_def)
```
```   679       then show ?case using eq by auto
```
```   680     next
```
```   681       case empty then show ?case by simp
```
```   682     next
```
```   683       case (compl A)
```
```   684       then have **: "F \<inter> (\<Omega> - A) = F - (F \<inter> A)"
```
```   685         and [intro]: "F \<inter> A \<in> sigma_sets \<Omega> E"
```
```   686         using `F \<in> E` S.sets_into_space by (auto simp: M)
```
```   687       have "?\<nu> (F \<inter> A) \<le> ?\<nu> F" by (auto intro!: emeasure_mono simp: M N)
```
```   688       then have "?\<nu> (F \<inter> A) \<noteq> \<infinity>" using `?\<nu> F \<noteq> \<infinity>` by auto
```
```   689       have "?\<mu> (F \<inter> A) \<le> ?\<mu> F" by (auto intro!: emeasure_mono simp: M N)
```
```   690       then have "?\<mu> (F \<inter> A) \<noteq> \<infinity>" using `?\<mu> F \<noteq> \<infinity>` by auto
```
```   691       then have "?\<mu> (F \<inter> (\<Omega> - A)) = ?\<mu> F - ?\<mu> (F \<inter> A)" unfolding **
```
```   692         using `F \<inter> A \<in> sigma_sets \<Omega> E` by (auto intro!: emeasure_Diff simp: M N)
```
```   693       also have "\<dots> = ?\<nu> F - ?\<nu> (F \<inter> A)" using eq `F \<in> E` compl by simp
```
```   694       also have "\<dots> = ?\<nu> (F \<inter> (\<Omega> - A))" unfolding **
```
```   695         using `F \<inter> A \<in> sigma_sets \<Omega> E` `?\<nu> (F \<inter> A) \<noteq> \<infinity>`
```
```   696         by (auto intro!: emeasure_Diff[symmetric] simp: M N)
```
```   697       finally show ?case
```
```   698         using `space M = \<Omega>` by auto
```
```   699     next
```
```   700       case (union A)
```
```   701       then have "?\<mu> (\<Union>x. F \<inter> A x) = ?\<nu> (\<Union>x. F \<inter> A x)"
```
```   702         by (subst (1 2) suminf_emeasure[symmetric]) (auto simp: disjoint_family_on_def subset_eq M N)
```
```   703       with A show ?case
```
```   704         by auto
```
```   705     qed }
```
```   706   note * = this
```
```   707   show "M = N"
```
```   708   proof (rule measure_eqI)
```
```   709     show "sets M = sets N"
```
```   710       using M N by simp
```
```   711     have [simp, intro]: "\<And>i. A i \<in> sets M"
```
```   712       using A(1) by (auto simp: subset_eq M)
```
```   713     fix F assume "F \<in> sets M"
```
```   714     let ?D = "disjointed (\<lambda>i. F \<inter> A i)"
```
```   715     from `space M = \<Omega>` have F_eq: "F = (\<Union>i. ?D i)"
```
```   716       using `F \<in> sets M`[THEN sets.sets_into_space] A(2)[symmetric] by (auto simp: UN_disjointed_eq)
```
```   717     have [simp, intro]: "\<And>i. ?D i \<in> sets M"
```
```   718       using sets.range_disjointed_sets[of "\<lambda>i. F \<inter> A i" M] `F \<in> sets M`
```
```   719       by (auto simp: subset_eq)
```
```   720     have "disjoint_family ?D"
```
```   721       by (auto simp: disjoint_family_disjointed)
```
```   722     moreover
```
```   723     have "(\<Sum>i. emeasure M (?D i)) = (\<Sum>i. emeasure N (?D i))"
```
```   724     proof (intro arg_cong[where f=suminf] ext)
```
```   725       fix i
```
```   726       have "A i \<inter> ?D i = ?D i"
```
```   727         by (auto simp: disjointed_def)
```
```   728       then show "emeasure M (?D i) = emeasure N (?D i)"
```
```   729         using *[of "A i" "?D i", OF _ A(3)] A(1) by auto
```
```   730     qed
```
```   731     ultimately show "emeasure M F = emeasure N F"
```
```   732       by (simp add: image_subset_iff `sets M = sets N`[symmetric] F_eq[symmetric] suminf_emeasure)
```
```   733   qed
```
```   734 qed
```
```   735
```
```   736 lemma measure_of_of_measure: "measure_of (space M) (sets M) (emeasure M) = M"
```
```   737 proof (intro measure_eqI emeasure_measure_of_sigma)
```
```   738   show "sigma_algebra (space M) (sets M)" ..
```
```   739   show "positive (sets M) (emeasure M)"
```
```   740     by (simp add: positive_def emeasure_nonneg)
```
```   741   show "countably_additive (sets M) (emeasure M)"
```
```   742     by (simp add: emeasure_countably_additive)
```
```   743 qed simp_all
```
```   744
```
```   745 subsection {* @{text \<mu>}-null sets *}
```
```   746
```
```   747 definition null_sets :: "'a measure \<Rightarrow> 'a set set" where
```
```   748   "null_sets M = {N\<in>sets M. emeasure M N = 0}"
```
```   749
```
```   750 lemma null_setsD1[dest]: "A \<in> null_sets M \<Longrightarrow> emeasure M A = 0"
```
```   751   by (simp add: null_sets_def)
```
```   752
```
```   753 lemma null_setsD2[dest]: "A \<in> null_sets M \<Longrightarrow> A \<in> sets M"
```
```   754   unfolding null_sets_def by simp
```
```   755
```
```   756 lemma null_setsI[intro]: "emeasure M A = 0 \<Longrightarrow> A \<in> sets M \<Longrightarrow> A \<in> null_sets M"
```
```   757   unfolding null_sets_def by simp
```
```   758
```
```   759 interpretation null_sets: ring_of_sets "space M" "null_sets M" for M
```
```   760 proof (rule ring_of_setsI)
```
```   761   show "null_sets M \<subseteq> Pow (space M)"
```
```   762     using sets.sets_into_space by auto
```
```   763   show "{} \<in> null_sets M"
```
```   764     by auto
```
```   765   fix A B assume null_sets: "A \<in> null_sets M" "B \<in> null_sets M"
```
```   766   then have sets: "A \<in> sets M" "B \<in> sets M"
```
```   767     by auto
```
```   768   then have *: "emeasure M (A \<union> B) \<le> emeasure M A + emeasure M B"
```
```   769     "emeasure M (A - B) \<le> emeasure M A"
```
```   770     by (auto intro!: emeasure_subadditive emeasure_mono)
```
```   771   then have "emeasure M B = 0" "emeasure M A = 0"
```
```   772     using null_sets by auto
```
```   773   with sets * show "A - B \<in> null_sets M" "A \<union> B \<in> null_sets M"
```
```   774     by (auto intro!: antisym)
```
```   775 qed
```
```   776
```
```   777 lemma UN_from_nat_into:
```
```   778   assumes I: "countable I" "I \<noteq> {}"
```
```   779   shows "(\<Union>i\<in>I. N i) = (\<Union>i. N (from_nat_into I i))"
```
```   780 proof -
```
```   781   have "(\<Union>i\<in>I. N i) = \<Union>(N ` range (from_nat_into I))"
```
```   782     using I by simp
```
```   783   also have "\<dots> = (\<Union>i. (N \<circ> from_nat_into I) i)"
```
```   784     by (simp only: SUP_def image_comp)
```
```   785   finally show ?thesis by simp
```
```   786 qed
```
```   787
```
```   788 lemma null_sets_UN':
```
```   789   assumes "countable I"
```
```   790   assumes "\<And>i. i \<in> I \<Longrightarrow> N i \<in> null_sets M"
```
```   791   shows "(\<Union>i\<in>I. N i) \<in> null_sets M"
```
```   792 proof cases
```
```   793   assume "I = {}" then show ?thesis by simp
```
```   794 next
```
```   795   assume "I \<noteq> {}"
```
```   796   show ?thesis
```
```   797   proof (intro conjI CollectI null_setsI)
```
```   798     show "(\<Union>i\<in>I. N i) \<in> sets M"
```
```   799       using assms by (intro sets.countable_UN') auto
```
```   800     have "emeasure M (\<Union>i\<in>I. N i) \<le> (\<Sum>n. emeasure M (N (from_nat_into I n)))"
```
```   801       unfolding UN_from_nat_into[OF `countable I` `I \<noteq> {}`]
```
```   802       using assms `I \<noteq> {}` by (intro emeasure_subadditive_countably) (auto intro: from_nat_into)
```
```   803     also have "(\<lambda>n. emeasure M (N (from_nat_into I n))) = (\<lambda>_. 0)"
```
```   804       using assms `I \<noteq> {}` by (auto intro: from_nat_into)
```
```   805     finally show "emeasure M (\<Union>i\<in>I. N i) = 0"
```
```   806       by (intro antisym emeasure_nonneg) simp
```
```   807   qed
```
```   808 qed
```
```   809
```
```   810 lemma null_sets_UN[intro]:
```
```   811   "(\<And>i::'i::countable. N i \<in> null_sets M) \<Longrightarrow> (\<Union>i. N i) \<in> null_sets M"
```
```   812   by (rule null_sets_UN') auto
```
```   813
```
```   814 lemma null_set_Int1:
```
```   815   assumes "B \<in> null_sets M" "A \<in> sets M" shows "A \<inter> B \<in> null_sets M"
```
```   816 proof (intro CollectI conjI null_setsI)
```
```   817   show "emeasure M (A \<inter> B) = 0" using assms
```
```   818     by (intro emeasure_eq_0[of B _ "A \<inter> B"]) auto
```
```   819 qed (insert assms, auto)
```
```   820
```
```   821 lemma null_set_Int2:
```
```   822   assumes "B \<in> null_sets M" "A \<in> sets M" shows "B \<inter> A \<in> null_sets M"
```
```   823   using assms by (subst Int_commute) (rule null_set_Int1)
```
```   824
```
```   825 lemma emeasure_Diff_null_set:
```
```   826   assumes "B \<in> null_sets M" "A \<in> sets M"
```
```   827   shows "emeasure M (A - B) = emeasure M A"
```
```   828 proof -
```
```   829   have *: "A - B = (A - (A \<inter> B))" by auto
```
```   830   have "A \<inter> B \<in> null_sets M" using assms by (rule null_set_Int1)
```
```   831   then show ?thesis
```
```   832     unfolding * using assms
```
```   833     by (subst emeasure_Diff) auto
```
```   834 qed
```
```   835
```
```   836 lemma null_set_Diff:
```
```   837   assumes "B \<in> null_sets M" "A \<in> sets M" shows "B - A \<in> null_sets M"
```
```   838 proof (intro CollectI conjI null_setsI)
```
```   839   show "emeasure M (B - A) = 0" using assms by (intro emeasure_eq_0[of B _ "B - A"]) auto
```
```   840 qed (insert assms, auto)
```
```   841
```
```   842 lemma emeasure_Un_null_set:
```
```   843   assumes "A \<in> sets M" "B \<in> null_sets M"
```
```   844   shows "emeasure M (A \<union> B) = emeasure M A"
```
```   845 proof -
```
```   846   have *: "A \<union> B = A \<union> (B - A)" by auto
```
```   847   have "B - A \<in> null_sets M" using assms(2,1) by (rule null_set_Diff)
```
```   848   then show ?thesis
```
```   849     unfolding * using assms
```
```   850     by (subst plus_emeasure[symmetric]) auto
```
```   851 qed
```
```   852
```
```   853 subsection {* The almost everywhere filter (i.e.\ quantifier) *}
```
```   854
```
```   855 definition ae_filter :: "'a measure \<Rightarrow> 'a filter" where
```
```   856   "ae_filter M = (INF N:null_sets M. principal (space M - N))"
```
```   857
```
```   858 abbreviation almost_everywhere :: "'a measure \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
```
```   859   "almost_everywhere M P \<equiv> eventually P (ae_filter M)"
```
```   860
```
```   861 syntax
```
```   862   "_almost_everywhere" :: "pttrn \<Rightarrow> 'a \<Rightarrow> bool \<Rightarrow> bool" ("AE _ in _. _" [0,0,10] 10)
```
```   863
```
```   864 translations
```
```   865   "AE x in M. P" == "CONST almost_everywhere M (\<lambda>x. P)"
```
```   866
```
```   867 lemma eventually_ae_filter: "eventually P (ae_filter M) \<longleftrightarrow> (\<exists>N\<in>null_sets M. {x \<in> space M. \<not> P x} \<subseteq> N)"
```
```   868   unfolding ae_filter_def by (subst eventually_INF_base) (auto simp: eventually_principal subset_eq)
```
```   869
```
```   870 lemma AE_I':
```
```   871   "N \<in> null_sets M \<Longrightarrow> {x\<in>space M. \<not> P x} \<subseteq> N \<Longrightarrow> (AE x in M. P x)"
```
```   872   unfolding eventually_ae_filter by auto
```
```   873
```
```   874 lemma AE_iff_null:
```
```   875   assumes "{x\<in>space M. \<not> P x} \<in> sets M" (is "?P \<in> sets M")
```
```   876   shows "(AE x in M. P x) \<longleftrightarrow> {x\<in>space M. \<not> P x} \<in> null_sets M"
```
```   877 proof
```
```   878   assume "AE x in M. P x" then obtain N where N: "N \<in> sets M" "?P \<subseteq> N" "emeasure M N = 0"
```
```   879     unfolding eventually_ae_filter by auto
```
```   880   have "0 \<le> emeasure M ?P" by auto
```
```   881   moreover have "emeasure M ?P \<le> emeasure M N"
```
```   882     using assms N(1,2) by (auto intro: emeasure_mono)
```
```   883   ultimately have "emeasure M ?P = 0" unfolding `emeasure M N = 0` by auto
```
```   884   then show "?P \<in> null_sets M" using assms by auto
```
```   885 next
```
```   886   assume "?P \<in> null_sets M" with assms show "AE x in M. P x" by (auto intro: AE_I')
```
```   887 qed
```
```   888
```
```   889 lemma AE_iff_null_sets:
```
```   890   "N \<in> sets M \<Longrightarrow> N \<in> null_sets M \<longleftrightarrow> (AE x in M. x \<notin> N)"
```
```   891   using Int_absorb1[OF sets.sets_into_space, of N M]
```
```   892   by (subst AE_iff_null) (auto simp: Int_def[symmetric])
```
```   893
```
```   894 lemma AE_not_in:
```
```   895   "N \<in> null_sets M \<Longrightarrow> AE x in M. x \<notin> N"
```
```   896   by (metis AE_iff_null_sets null_setsD2)
```
```   897
```
```   898 lemma AE_iff_measurable:
```
```   899   "N \<in> sets M \<Longrightarrow> {x\<in>space M. \<not> P x} = N \<Longrightarrow> (AE x in M. P x) \<longleftrightarrow> emeasure M N = 0"
```
```   900   using AE_iff_null[of _ P] by auto
```
```   901
```
```   902 lemma AE_E[consumes 1]:
```
```   903   assumes "AE x in M. P x"
```
```   904   obtains N where "{x \<in> space M. \<not> P x} \<subseteq> N" "emeasure M N = 0" "N \<in> sets M"
```
```   905   using assms unfolding eventually_ae_filter by auto
```
```   906
```
```   907 lemma AE_E2:
```
```   908   assumes "AE x in M. P x" "{x\<in>space M. P x} \<in> sets M"
```
```   909   shows "emeasure M {x\<in>space M. \<not> P x} = 0" (is "emeasure M ?P = 0")
```
```   910 proof -
```
```   911   have "{x\<in>space M. \<not> P x} = space M - {x\<in>space M. P x}" by auto
```
```   912   with AE_iff_null[of M P] assms show ?thesis by auto
```
```   913 qed
```
```   914
```
```   915 lemma AE_I:
```
```   916   assumes "{x \<in> space M. \<not> P x} \<subseteq> N" "emeasure M N = 0" "N \<in> sets M"
```
```   917   shows "AE x in M. P x"
```
```   918   using assms unfolding eventually_ae_filter by auto
```
```   919
```
```   920 lemma AE_mp[elim!]:
```
```   921   assumes AE_P: "AE x in M. P x" and AE_imp: "AE x in M. P x \<longrightarrow> Q x"
```
```   922   shows "AE x in M. Q x"
```
```   923 proof -
```
```   924   from AE_P obtain A where P: "{x\<in>space M. \<not> P x} \<subseteq> A"
```
```   925     and A: "A \<in> sets M" "emeasure M A = 0"
```
```   926     by (auto elim!: AE_E)
```
```   927
```
```   928   from AE_imp obtain B where imp: "{x\<in>space M. P x \<and> \<not> Q x} \<subseteq> B"
```
```   929     and B: "B \<in> sets M" "emeasure M B = 0"
```
```   930     by (auto elim!: AE_E)
```
```   931
```
```   932   show ?thesis
```
```   933   proof (intro AE_I)
```
```   934     have "0 \<le> emeasure M (A \<union> B)" using A B by auto
```
```   935     moreover have "emeasure M (A \<union> B) \<le> 0"
```
```   936       using emeasure_subadditive[of A M B] A B by auto
```
```   937     ultimately show "A \<union> B \<in> sets M" "emeasure M (A \<union> B) = 0" using A B by auto
```
```   938     show "{x\<in>space M. \<not> Q x} \<subseteq> A \<union> B"
```
```   939       using P imp by auto
```
```   940   qed
```
```   941 qed
```
```   942
```
```   943 (* depricated replace by laws about eventually *)
```
```   944 lemma
```
```   945   shows AE_iffI: "AE x in M. P x \<Longrightarrow> AE x in M. P x \<longleftrightarrow> Q x \<Longrightarrow> AE x in M. Q x"
```
```   946     and AE_disjI1: "AE x in M. P x \<Longrightarrow> AE x in M. P x \<or> Q x"
```
```   947     and AE_disjI2: "AE x in M. Q x \<Longrightarrow> AE x in M. P x \<or> Q x"
```
```   948     and AE_conjI: "AE x in M. P x \<Longrightarrow> AE x in M. Q x \<Longrightarrow> AE x in M. P x \<and> Q x"
```
```   949     and AE_conj_iff[simp]: "(AE x in M. P x \<and> Q x) \<longleftrightarrow> (AE x in M. P x) \<and> (AE x in M. Q x)"
```
```   950   by auto
```
```   951
```
```   952 lemma AE_impI:
```
```   953   "(P \<Longrightarrow> AE x in M. Q x) \<Longrightarrow> AE x in M. P \<longrightarrow> Q x"
```
```   954   by (cases P) auto
```
```   955
```
```   956 lemma AE_measure:
```
```   957   assumes AE: "AE x in M. P x" and sets: "{x\<in>space M. P x} \<in> sets M" (is "?P \<in> sets M")
```
```   958   shows "emeasure M {x\<in>space M. P x} = emeasure M (space M)"
```
```   959 proof -
```
```   960   from AE_E[OF AE] guess N . note N = this
```
```   961   with sets have "emeasure M (space M) \<le> emeasure M (?P \<union> N)"
```
```   962     by (intro emeasure_mono) auto
```
```   963   also have "\<dots> \<le> emeasure M ?P + emeasure M N"
```
```   964     using sets N by (intro emeasure_subadditive) auto
```
```   965   also have "\<dots> = emeasure M ?P" using N by simp
```
```   966   finally show "emeasure M ?P = emeasure M (space M)"
```
```   967     using emeasure_space[of M "?P"] by auto
```
```   968 qed
```
```   969
```
```   970 lemma AE_space: "AE x in M. x \<in> space M"
```
```   971   by (rule AE_I[where N="{}"]) auto
```
```   972
```
```   973 lemma AE_I2[simp, intro]:
```
```   974   "(\<And>x. x \<in> space M \<Longrightarrow> P x) \<Longrightarrow> AE x in M. P x"
```
```   975   using AE_space by force
```
```   976
```
```   977 lemma AE_Ball_mp:
```
```   978   "\<forall>x\<in>space M. P x \<Longrightarrow> AE x in M. P x \<longrightarrow> Q x \<Longrightarrow> AE x in M. Q x"
```
```   979   by auto
```
```   980
```
```   981 lemma AE_cong[cong]:
```
```   982   "(\<And>x. x \<in> space M \<Longrightarrow> P x \<longleftrightarrow> Q x) \<Longrightarrow> (AE x in M. P x) \<longleftrightarrow> (AE x in M. Q x)"
```
```   983   by auto
```
```   984
```
```   985 lemma AE_all_countable:
```
```   986   "(AE x in M. \<forall>i. P i x) \<longleftrightarrow> (\<forall>i::'i::countable. AE x in M. P i x)"
```
```   987 proof
```
```   988   assume "\<forall>i. AE x in M. P i x"
```
```   989   from this[unfolded eventually_ae_filter Bex_def, THEN choice]
```
```   990   obtain N where N: "\<And>i. N i \<in> null_sets M" "\<And>i. {x\<in>space M. \<not> P i x} \<subseteq> N i" by auto
```
```   991   have "{x\<in>space M. \<not> (\<forall>i. P i x)} \<subseteq> (\<Union>i. {x\<in>space M. \<not> P i x})" by auto
```
```   992   also have "\<dots> \<subseteq> (\<Union>i. N i)" using N by auto
```
```   993   finally have "{x\<in>space M. \<not> (\<forall>i. P i x)} \<subseteq> (\<Union>i. N i)" .
```
```   994   moreover from N have "(\<Union>i. N i) \<in> null_sets M"
```
```   995     by (intro null_sets_UN) auto
```
```   996   ultimately show "AE x in M. \<forall>i. P i x"
```
```   997     unfolding eventually_ae_filter by auto
```
```   998 qed auto
```
```   999
```
```  1000 lemma AE_discrete_difference:
```
```  1001   assumes X: "countable X"
```
```  1002   assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
```
```  1003   assumes sets: "\<And>x. x \<in> X \<Longrightarrow> {x} \<in> sets M"
```
```  1004   shows "AE x in M. x \<notin> X"
```
```  1005 proof -
```
```  1006   have "(\<Union>x\<in>X. {x}) \<in> null_sets M"
```
```  1007     using assms by (intro null_sets_UN') auto
```
```  1008   from AE_not_in[OF this] show "AE x in M. x \<notin> X"
```
```  1009     by auto
```
```  1010 qed
```
```  1011
```
```  1012 lemma AE_finite_all:
```
```  1013   assumes f: "finite S" shows "(AE x in M. \<forall>i\<in>S. P i x) \<longleftrightarrow> (\<forall>i\<in>S. AE x in M. P i x)"
```
```  1014   using f by induct auto
```
```  1015
```
```  1016 lemma AE_finite_allI:
```
```  1017   assumes "finite S"
```
```  1018   shows "(\<And>s. s \<in> S \<Longrightarrow> AE x in M. Q s x) \<Longrightarrow> AE x in M. \<forall>s\<in>S. Q s x"
```
```  1019   using AE_finite_all[OF `finite S`] by auto
```
```  1020
```
```  1021 lemma emeasure_mono_AE:
```
```  1022   assumes imp: "AE x in M. x \<in> A \<longrightarrow> x \<in> B"
```
```  1023     and B: "B \<in> sets M"
```
```  1024   shows "emeasure M A \<le> emeasure M B"
```
```  1025 proof cases
```
```  1026   assume A: "A \<in> sets M"
```
```  1027   from imp obtain N where N: "{x\<in>space M. \<not> (x \<in> A \<longrightarrow> x \<in> B)} \<subseteq> N" "N \<in> null_sets M"
```
```  1028     by (auto simp: eventually_ae_filter)
```
```  1029   have "emeasure M A = emeasure M (A - N)"
```
```  1030     using N A by (subst emeasure_Diff_null_set) auto
```
```  1031   also have "emeasure M (A - N) \<le> emeasure M (B - N)"
```
```  1032     using N A B sets.sets_into_space by (auto intro!: emeasure_mono)
```
```  1033   also have "emeasure M (B - N) = emeasure M B"
```
```  1034     using N B by (subst emeasure_Diff_null_set) auto
```
```  1035   finally show ?thesis .
```
```  1036 qed (simp add: emeasure_nonneg emeasure_notin_sets)
```
```  1037
```
```  1038 lemma emeasure_eq_AE:
```
```  1039   assumes iff: "AE x in M. x \<in> A \<longleftrightarrow> x \<in> B"
```
```  1040   assumes A: "A \<in> sets M" and B: "B \<in> sets M"
```
```  1041   shows "emeasure M A = emeasure M B"
```
```  1042   using assms by (safe intro!: antisym emeasure_mono_AE) auto
```
```  1043
```
```  1044 subsection {* @{text \<sigma>}-finite Measures *}
```
```  1045
```
```  1046 locale sigma_finite_measure =
```
```  1047   fixes M :: "'a measure"
```
```  1048   assumes sigma_finite_countable:
```
```  1049     "\<exists>A::'a set set. countable A \<and> A \<subseteq> sets M \<and> (\<Union>A) = space M \<and> (\<forall>a\<in>A. emeasure M a \<noteq> \<infinity>)"
```
```  1050
```
```  1051 lemma (in sigma_finite_measure) sigma_finite:
```
```  1052   obtains A :: "nat \<Rightarrow> 'a set"
```
```  1053   where "range A \<subseteq> sets M" "(\<Union>i. A i) = space M" "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
```
```  1054 proof -
```
```  1055   obtain A :: "'a set set" where
```
```  1056     [simp]: "countable A" and
```
```  1057     A: "A \<subseteq> sets M" "(\<Union>A) = space M" "\<And>a. a \<in> A \<Longrightarrow> emeasure M a \<noteq> \<infinity>"
```
```  1058     using sigma_finite_countable by metis
```
```  1059   show thesis
```
```  1060   proof cases
```
```  1061     assume "A = {}" with `(\<Union>A) = space M` show thesis
```
```  1062       by (intro that[of "\<lambda>_. {}"]) auto
```
```  1063   next
```
```  1064     assume "A \<noteq> {}"
```
```  1065     show thesis
```
```  1066     proof
```
```  1067       show "range (from_nat_into A) \<subseteq> sets M"
```
```  1068         using `A \<noteq> {}` A by auto
```
```  1069       have "(\<Union>i. from_nat_into A i) = \<Union>A"
```
```  1070         using range_from_nat_into[OF `A \<noteq> {}` `countable A`] by auto
```
```  1071       with A show "(\<Union>i. from_nat_into A i) = space M"
```
```  1072         by auto
```
```  1073     qed (intro A from_nat_into `A \<noteq> {}`)
```
```  1074   qed
```
```  1075 qed
```
```  1076
```
```  1077 lemma (in sigma_finite_measure) sigma_finite_disjoint:
```
```  1078   obtains A :: "nat \<Rightarrow> 'a set"
```
```  1079   where "range A \<subseteq> sets M" "(\<Union>i. A i) = space M" "\<And>i. emeasure M (A i) \<noteq> \<infinity>" "disjoint_family A"
```
```  1080 proof atomize_elim
```
```  1081   case goal1
```
```  1082   obtain A :: "nat \<Rightarrow> 'a set" where
```
```  1083     range: "range A \<subseteq> sets M" and
```
```  1084     space: "(\<Union>i. A i) = space M" and
```
```  1085     measure: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
```
```  1086     using sigma_finite by auto
```
```  1087   note range' = sets.range_disjointed_sets[OF range] range
```
```  1088   { fix i
```
```  1089     have "emeasure M (disjointed A i) \<le> emeasure M (A i)"
```
```  1090       using range' disjointed_subset[of A i] by (auto intro!: emeasure_mono)
```
```  1091     then have "emeasure M (disjointed A i) \<noteq> \<infinity>"
```
```  1092       using measure[of i] by auto }
```
```  1093   with disjoint_family_disjointed UN_disjointed_eq[of A] space range'
```
```  1094   show ?case by (auto intro!: exI[of _ "disjointed A"])
```
```  1095 qed
```
```  1096
```
```  1097 lemma (in sigma_finite_measure) sigma_finite_incseq:
```
```  1098   obtains A :: "nat \<Rightarrow> 'a set"
```
```  1099   where "range A \<subseteq> sets M" "(\<Union>i. A i) = space M" "\<And>i. emeasure M (A i) \<noteq> \<infinity>" "incseq A"
```
```  1100 proof atomize_elim
```
```  1101   case goal1
```
```  1102   obtain F :: "nat \<Rightarrow> 'a set" where
```
```  1103     F: "range F \<subseteq> sets M" "(\<Union>i. F i) = space M" "\<And>i. emeasure M (F i) \<noteq> \<infinity>"
```
```  1104     using sigma_finite by auto
```
```  1105   then show ?case
```
```  1106   proof (intro exI[of _ "\<lambda>n. \<Union>i\<le>n. F i"] conjI allI)
```
```  1107     from F have "\<And>x. x \<in> space M \<Longrightarrow> \<exists>i. x \<in> F i" by auto
```
```  1108     then show "(\<Union>n. \<Union> i\<le>n. F i) = space M"
```
```  1109       using F by fastforce
```
```  1110   next
```
```  1111     fix n
```
```  1112     have "emeasure M (\<Union> i\<le>n. F i) \<le> (\<Sum>i\<le>n. emeasure M (F i))" using F
```
```  1113       by (auto intro!: emeasure_subadditive_finite)
```
```  1114     also have "\<dots> < \<infinity>"
```
```  1115       using F by (auto simp: setsum_Pinfty)
```
```  1116     finally show "emeasure M (\<Union> i\<le>n. F i) \<noteq> \<infinity>" by simp
```
```  1117   qed (force simp: incseq_def)+
```
```  1118 qed
```
```  1119
```
```  1120 subsection {* Measure space induced by distribution of @{const measurable}-functions *}
```
```  1121
```
```  1122 definition distr :: "'a measure \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b measure" where
```
```  1123   "distr M N f = measure_of (space N) (sets N) (\<lambda>A. emeasure M (f -` A \<inter> space M))"
```
```  1124
```
```  1125 lemma
```
```  1126   shows sets_distr[simp]: "sets (distr M N f) = sets N"
```
```  1127     and space_distr[simp]: "space (distr M N f) = space N"
```
```  1128   by (auto simp: distr_def)
```
```  1129
```
```  1130 lemma
```
```  1131   shows measurable_distr_eq1[simp]: "measurable (distr Mf Nf f) Mf' = measurable Nf Mf'"
```
```  1132     and measurable_distr_eq2[simp]: "measurable Mg' (distr Mg Ng g) = measurable Mg' Ng"
```
```  1133   by (auto simp: measurable_def)
```
```  1134
```
```  1135 lemma distr_cong:
```
```  1136   "M = K \<Longrightarrow> sets N = sets L \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> distr M N f = distr K L g"
```
```  1137   using sets_eq_imp_space_eq[of N L] by (simp add: distr_def Int_def cong: rev_conj_cong)
```
```  1138
```
```  1139 lemma emeasure_distr:
```
```  1140   fixes f :: "'a \<Rightarrow> 'b"
```
```  1141   assumes f: "f \<in> measurable M N" and A: "A \<in> sets N"
```
```  1142   shows "emeasure (distr M N f) A = emeasure M (f -` A \<inter> space M)" (is "_ = ?\<mu> A")
```
```  1143   unfolding distr_def
```
```  1144 proof (rule emeasure_measure_of_sigma)
```
```  1145   show "positive (sets N) ?\<mu>"
```
```  1146     by (auto simp: positive_def)
```
```  1147
```
```  1148   show "countably_additive (sets N) ?\<mu>"
```
```  1149   proof (intro countably_additiveI)
```
```  1150     fix A :: "nat \<Rightarrow> 'b set" assume "range A \<subseteq> sets N" "disjoint_family A"
```
```  1151     then have A: "\<And>i. A i \<in> sets N" "(\<Union>i. A i) \<in> sets N" by auto
```
```  1152     then have *: "range (\<lambda>i. f -` (A i) \<inter> space M) \<subseteq> sets M"
```
```  1153       using f by (auto simp: measurable_def)
```
```  1154     moreover have "(\<Union>i. f -`  A i \<inter> space M) \<in> sets M"
```
```  1155       using * by blast
```
```  1156     moreover have **: "disjoint_family (\<lambda>i. f -` A i \<inter> space M)"
```
```  1157       using `disjoint_family A` by (auto simp: disjoint_family_on_def)
```
```  1158     ultimately show "(\<Sum>i. ?\<mu> (A i)) = ?\<mu> (\<Union>i. A i)"
```
```  1159       using suminf_emeasure[OF _ **] A f
```
```  1160       by (auto simp: comp_def vimage_UN)
```
```  1161   qed
```
```  1162   show "sigma_algebra (space N) (sets N)" ..
```
```  1163 qed fact
```
```  1164
```
```  1165 lemma distr_id[simp]: "distr N N (\<lambda>x. x) = N"
```
```  1166   by (rule measure_eqI) (auto simp: emeasure_distr)
```
```  1167
```
```  1168 lemma measure_distr:
```
```  1169   "f \<in> measurable M N \<Longrightarrow> S \<in> sets N \<Longrightarrow> measure (distr M N f) S = measure M (f -` S \<inter> space M)"
```
```  1170   by (simp add: emeasure_distr measure_def)
```
```  1171
```
```  1172 lemma distr_cong_AE:
```
```  1173   assumes 1: "M = K" "sets N = sets L" and
```
```  1174     2: "(AE x in M. f x = g x)" and "f \<in> measurable M N" and "g \<in> measurable K L"
```
```  1175   shows "distr M N f = distr K L g"
```
```  1176 proof (rule measure_eqI)
```
```  1177   fix A assume "A \<in> sets (distr M N f)"
```
```  1178   with assms show "emeasure (distr M N f) A = emeasure (distr K L g) A"
```
```  1179     by (auto simp add: emeasure_distr intro!: emeasure_eq_AE measurable_sets)
```
```  1180 qed (insert 1, simp)
```
```  1181
```
```  1182 lemma AE_distrD:
```
```  1183   assumes f: "f \<in> measurable M M'"
```
```  1184     and AE: "AE x in distr M M' f. P x"
```
```  1185   shows "AE x in M. P (f x)"
```
```  1186 proof -
```
```  1187   from AE[THEN AE_E] guess N .
```
```  1188   with f show ?thesis
```
```  1189     unfolding eventually_ae_filter
```
```  1190     by (intro bexI[of _ "f -` N \<inter> space M"])
```
```  1191        (auto simp: emeasure_distr measurable_def)
```
```  1192 qed
```
```  1193
```
```  1194 lemma AE_distr_iff:
```
```  1195   assumes f[measurable]: "f \<in> measurable M N" and P[measurable]: "{x \<in> space N. P x} \<in> sets N"
```
```  1196   shows "(AE x in distr M N f. P x) \<longleftrightarrow> (AE x in M. P (f x))"
```
```  1197 proof (subst (1 2) AE_iff_measurable[OF _ refl])
```
```  1198   have "f -` {x\<in>space N. \<not> P x} \<inter> space M = {x \<in> space M. \<not> P (f x)}"
```
```  1199     using f[THEN measurable_space] by auto
```
```  1200   then show "(emeasure (distr M N f) {x \<in> space (distr M N f). \<not> P x} = 0) =
```
```  1201     (emeasure M {x \<in> space M. \<not> P (f x)} = 0)"
```
```  1202     by (simp add: emeasure_distr)
```
```  1203 qed auto
```
```  1204
```
```  1205 lemma null_sets_distr_iff:
```
```  1206   "f \<in> measurable M N \<Longrightarrow> A \<in> null_sets (distr M N f) \<longleftrightarrow> f -` A \<inter> space M \<in> null_sets M \<and> A \<in> sets N"
```
```  1207   by (auto simp add: null_sets_def emeasure_distr)
```
```  1208
```
```  1209 lemma distr_distr:
```
```  1210   "g \<in> measurable N L \<Longrightarrow> f \<in> measurable M N \<Longrightarrow> distr (distr M N f) L g = distr M L (g \<circ> f)"
```
```  1211   by (auto simp add: emeasure_distr measurable_space
```
```  1212            intro!: arg_cong[where f="emeasure M"] measure_eqI)
```
```  1213
```
```  1214
```
```  1215 subsection {* Real measure values *}
```
```  1216
```
```  1217 lemma measure_nonneg: "0 \<le> measure M A"
```
```  1218   using emeasure_nonneg[of M A] unfolding measure_def by (auto intro: real_of_ereal_pos)
```
```  1219
```
```  1220 lemma measure_empty[simp]: "measure M {} = 0"
```
```  1221   unfolding measure_def by simp
```
```  1222
```
```  1223 lemma emeasure_eq_ereal_measure:
```
```  1224   "emeasure M A \<noteq> \<infinity> \<Longrightarrow> emeasure M A = ereal (measure M A)"
```
```  1225   using emeasure_nonneg[of M A]
```
```  1226   by (cases "emeasure M A") (auto simp: measure_def)
```
```  1227
```
```  1228 lemma measure_Union:
```
```  1229   assumes finite: "emeasure M A \<noteq> \<infinity>" "emeasure M B \<noteq> \<infinity>"
```
```  1230   and measurable: "A \<in> sets M" "B \<in> sets M" "A \<inter> B = {}"
```
```  1231   shows "measure M (A \<union> B) = measure M A + measure M B"
```
```  1232   unfolding measure_def
```
```  1233   using plus_emeasure[OF measurable, symmetric] finite
```
```  1234   by (simp add: emeasure_eq_ereal_measure)
```
```  1235
```
```  1236 lemma measure_finite_Union:
```
```  1237   assumes measurable: "A`S \<subseteq> sets M" "disjoint_family_on A S" "finite S"
```
```  1238   assumes finite: "\<And>i. i \<in> S \<Longrightarrow> emeasure M (A i) \<noteq> \<infinity>"
```
```  1239   shows "measure M (\<Union>i\<in>S. A i) = (\<Sum>i\<in>S. measure M (A i))"
```
```  1240   unfolding measure_def
```
```  1241   using setsum_emeasure[OF measurable, symmetric] finite
```
```  1242   by (simp add: emeasure_eq_ereal_measure)
```
```  1243
```
```  1244 lemma measure_Diff:
```
```  1245   assumes finite: "emeasure M A \<noteq> \<infinity>"
```
```  1246   and measurable: "A \<in> sets M" "B \<in> sets M" "B \<subseteq> A"
```
```  1247   shows "measure M (A - B) = measure M A - measure M B"
```
```  1248 proof -
```
```  1249   have "emeasure M (A - B) \<le> emeasure M A" "emeasure M B \<le> emeasure M A"
```
```  1250     using measurable by (auto intro!: emeasure_mono)
```
```  1251   hence "measure M ((A - B) \<union> B) = measure M (A - B) + measure M B"
```
```  1252     using measurable finite by (rule_tac measure_Union) auto
```
```  1253   thus ?thesis using `B \<subseteq> A` by (auto simp: Un_absorb2)
```
```  1254 qed
```
```  1255
```
```  1256 lemma measure_UNION:
```
```  1257   assumes measurable: "range A \<subseteq> sets M" "disjoint_family A"
```
```  1258   assumes finite: "emeasure M (\<Union>i. A i) \<noteq> \<infinity>"
```
```  1259   shows "(\<lambda>i. measure M (A i)) sums (measure M (\<Union>i. A i))"
```
```  1260 proof -
```
```  1261   from summable_sums[OF summable_ereal_pos, of "\<lambda>i. emeasure M (A i)"]
```
```  1262        suminf_emeasure[OF measurable] emeasure_nonneg[of M]
```
```  1263   have "(\<lambda>i. emeasure M (A i)) sums (emeasure M (\<Union>i. A i))" by simp
```
```  1264   moreover
```
```  1265   { fix i
```
```  1266     have "emeasure M (A i) \<le> emeasure M (\<Union>i. A i)"
```
```  1267       using measurable by (auto intro!: emeasure_mono)
```
```  1268     then have "emeasure M (A i) = ereal ((measure M (A i)))"
```
```  1269       using finite by (intro emeasure_eq_ereal_measure) auto }
```
```  1270   ultimately show ?thesis using finite
```
```  1271     unfolding sums_ereal[symmetric] by (simp add: emeasure_eq_ereal_measure)
```
```  1272 qed
```
```  1273
```
```  1274 lemma measure_subadditive:
```
```  1275   assumes measurable: "A \<in> sets M" "B \<in> sets M"
```
```  1276   and fin: "emeasure M A \<noteq> \<infinity>" "emeasure M B \<noteq> \<infinity>"
```
```  1277   shows "(measure M (A \<union> B)) \<le> (measure M A) + (measure M B)"
```
```  1278 proof -
```
```  1279   have "emeasure M (A \<union> B) \<noteq> \<infinity>"
```
```  1280     using emeasure_subadditive[OF measurable] fin by auto
```
```  1281   then show "(measure M (A \<union> B)) \<le> (measure M A) + (measure M B)"
```
```  1282     using emeasure_subadditive[OF measurable] fin
```
```  1283     by (auto simp: emeasure_eq_ereal_measure)
```
```  1284 qed
```
```  1285
```
```  1286 lemma measure_subadditive_finite:
```
```  1287   assumes A: "finite I" "A`I \<subseteq> sets M" and fin: "\<And>i. i \<in> I \<Longrightarrow> emeasure M (A i) \<noteq> \<infinity>"
```
```  1288   shows "measure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. measure M (A i))"
```
```  1289 proof -
```
```  1290   { have "emeasure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. emeasure M (A i))"
```
```  1291       using emeasure_subadditive_finite[OF A] .
```
```  1292     also have "\<dots> < \<infinity>"
```
```  1293       using fin by (simp add: setsum_Pinfty)
```
```  1294     finally have "emeasure M (\<Union>i\<in>I. A i) \<noteq> \<infinity>" by simp }
```
```  1295   then show ?thesis
```
```  1296     using emeasure_subadditive_finite[OF A] fin
```
```  1297     unfolding measure_def by (simp add: emeasure_eq_ereal_measure suminf_ereal measure_nonneg)
```
```  1298 qed
```
```  1299
```
```  1300 lemma measure_subadditive_countably:
```
```  1301   assumes A: "range A \<subseteq> sets M" and fin: "(\<Sum>i. emeasure M (A i)) \<noteq> \<infinity>"
```
```  1302   shows "measure M (\<Union>i. A i) \<le> (\<Sum>i. measure M (A i))"
```
```  1303 proof -
```
```  1304   from emeasure_nonneg fin have "\<And>i. emeasure M (A i) \<noteq> \<infinity>" by (rule suminf_PInfty)
```
```  1305   moreover
```
```  1306   { have "emeasure M (\<Union>i. A i) \<le> (\<Sum>i. emeasure M (A i))"
```
```  1307       using emeasure_subadditive_countably[OF A] .
```
```  1308     also have "\<dots> < \<infinity>"
```
```  1309       using fin by simp
```
```  1310     finally have "emeasure M (\<Union>i. A i) \<noteq> \<infinity>" by simp }
```
```  1311   ultimately  show ?thesis
```
```  1312     using emeasure_subadditive_countably[OF A] fin
```
```  1313     unfolding measure_def by (simp add: emeasure_eq_ereal_measure suminf_ereal measure_nonneg)
```
```  1314 qed
```
```  1315
```
```  1316 lemma measure_eq_setsum_singleton:
```
```  1317   assumes S: "finite S" "\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M"
```
```  1318   and fin: "\<And>x. x \<in> S \<Longrightarrow> emeasure M {x} \<noteq> \<infinity>"
```
```  1319   shows "(measure M S) = (\<Sum>x\<in>S. (measure M {x}))"
```
```  1320   unfolding measure_def
```
```  1321   using emeasure_eq_setsum_singleton[OF S] fin
```
```  1322   by simp (simp add: emeasure_eq_ereal_measure)
```
```  1323
```
```  1324 lemma Lim_measure_incseq:
```
```  1325   assumes A: "range A \<subseteq> sets M" "incseq A" and fin: "emeasure M (\<Union>i. A i) \<noteq> \<infinity>"
```
```  1326   shows "(\<lambda>i. (measure M (A i))) ----> (measure M (\<Union>i. A i))"
```
```  1327 proof -
```
```  1328   have "ereal ((measure M (\<Union>i. A i))) = emeasure M (\<Union>i. A i)"
```
```  1329     using fin by (auto simp: emeasure_eq_ereal_measure)
```
```  1330   then show ?thesis
```
```  1331     using Lim_emeasure_incseq[OF A]
```
```  1332     unfolding measure_def
```
```  1333     by (intro lim_real_of_ereal) simp
```
```  1334 qed
```
```  1335
```
```  1336 lemma Lim_measure_decseq:
```
```  1337   assumes A: "range A \<subseteq> sets M" "decseq A" and fin: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
```
```  1338   shows "(\<lambda>n. measure M (A n)) ----> measure M (\<Inter>i. A i)"
```
```  1339 proof -
```
```  1340   have "emeasure M (\<Inter>i. A i) \<le> emeasure M (A 0)"
```
```  1341     using A by (auto intro!: emeasure_mono)
```
```  1342   also have "\<dots> < \<infinity>"
```
```  1343     using fin[of 0] by auto
```
```  1344   finally have "ereal ((measure M (\<Inter>i. A i))) = emeasure M (\<Inter>i. A i)"
```
```  1345     by (auto simp: emeasure_eq_ereal_measure)
```
```  1346   then show ?thesis
```
```  1347     unfolding measure_def
```
```  1348     using Lim_emeasure_decseq[OF A fin]
```
```  1349     by (intro lim_real_of_ereal) simp
```
```  1350 qed
```
```  1351
```
```  1352 subsection {* Measure spaces with @{term "emeasure M (space M) < \<infinity>"} *}
```
```  1353
```
```  1354 locale finite_measure = sigma_finite_measure M for M +
```
```  1355   assumes finite_emeasure_space: "emeasure M (space M) \<noteq> \<infinity>"
```
```  1356
```
```  1357 lemma finite_measureI[Pure.intro!]:
```
```  1358   "emeasure M (space M) \<noteq> \<infinity> \<Longrightarrow> finite_measure M"
```
```  1359   proof qed (auto intro!: exI[of _ "{space M}"])
```
```  1360
```
```  1361 lemma (in finite_measure) emeasure_finite[simp, intro]: "emeasure M A \<noteq> \<infinity>"
```
```  1362   using finite_emeasure_space emeasure_space[of M A] by auto
```
```  1363
```
```  1364 lemma (in finite_measure) emeasure_eq_measure: "emeasure M A = ereal (measure M A)"
```
```  1365   unfolding measure_def by (simp add: emeasure_eq_ereal_measure)
```
```  1366
```
```  1367 lemma (in finite_measure) emeasure_real: "\<exists>r. 0 \<le> r \<and> emeasure M A = ereal r"
```
```  1368   using emeasure_finite[of A] emeasure_nonneg[of M A] by (cases "emeasure M A") auto
```
```  1369
```
```  1370 lemma (in finite_measure) bounded_measure: "measure M A \<le> measure M (space M)"
```
```  1371   using emeasure_space[of M A] emeasure_real[of A] emeasure_real[of "space M"] by (auto simp: measure_def)
```
```  1372
```
```  1373 lemma (in finite_measure) finite_measure_Diff:
```
```  1374   assumes sets: "A \<in> sets M" "B \<in> sets M" and "B \<subseteq> A"
```
```  1375   shows "measure M (A - B) = measure M A - measure M B"
```
```  1376   using measure_Diff[OF _ assms] by simp
```
```  1377
```
```  1378 lemma (in finite_measure) finite_measure_Union:
```
```  1379   assumes sets: "A \<in> sets M" "B \<in> sets M" and "A \<inter> B = {}"
```
```  1380   shows "measure M (A \<union> B) = measure M A + measure M B"
```
```  1381   using measure_Union[OF _ _ assms] by simp
```
```  1382
```
```  1383 lemma (in finite_measure) finite_measure_finite_Union:
```
```  1384   assumes measurable: "A`S \<subseteq> sets M" "disjoint_family_on A S" "finite S"
```
```  1385   shows "measure M (\<Union>i\<in>S. A i) = (\<Sum>i\<in>S. measure M (A i))"
```
```  1386   using measure_finite_Union[OF assms] by simp
```
```  1387
```
```  1388 lemma (in finite_measure) finite_measure_UNION:
```
```  1389   assumes A: "range A \<subseteq> sets M" "disjoint_family A"
```
```  1390   shows "(\<lambda>i. measure M (A i)) sums (measure M (\<Union>i. A i))"
```
```  1391   using measure_UNION[OF A] by simp
```
```  1392
```
```  1393 lemma (in finite_measure) finite_measure_mono:
```
```  1394   assumes "A \<subseteq> B" "B \<in> sets M" shows "measure M A \<le> measure M B"
```
```  1395   using emeasure_mono[OF assms] emeasure_real[of A] emeasure_real[of B] by (auto simp: measure_def)
```
```  1396
```
```  1397 lemma (in finite_measure) finite_measure_subadditive:
```
```  1398   assumes m: "A \<in> sets M" "B \<in> sets M"
```
```  1399   shows "measure M (A \<union> B) \<le> measure M A + measure M B"
```
```  1400   using measure_subadditive[OF m] by simp
```
```  1401
```
```  1402 lemma (in finite_measure) finite_measure_subadditive_finite:
```
```  1403   assumes "finite I" "A`I \<subseteq> sets M" shows "measure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. measure M (A i))"
```
```  1404   using measure_subadditive_finite[OF assms] by simp
```
```  1405
```
```  1406 lemma (in finite_measure) finite_measure_subadditive_countably:
```
```  1407   assumes A: "range A \<subseteq> sets M" and sum: "summable (\<lambda>i. measure M (A i))"
```
```  1408   shows "measure M (\<Union>i. A i) \<le> (\<Sum>i. measure M (A i))"
```
```  1409 proof -
```
```  1410   from `summable (\<lambda>i. measure M (A i))`
```
```  1411   have "(\<lambda>i. ereal (measure M (A i))) sums ereal (\<Sum>i. measure M (A i))"
```
```  1412     by (simp add: sums_ereal) (rule summable_sums)
```
```  1413   from sums_unique[OF this, symmetric]
```
```  1414        measure_subadditive_countably[OF A]
```
```  1415   show ?thesis by (simp add: emeasure_eq_measure)
```
```  1416 qed
```
```  1417
```
```  1418 lemma (in finite_measure) finite_measure_eq_setsum_singleton:
```
```  1419   assumes "finite S" and *: "\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M"
```
```  1420   shows "measure M S = (\<Sum>x\<in>S. measure M {x})"
```
```  1421   using measure_eq_setsum_singleton[OF assms] by simp
```
```  1422
```
```  1423 lemma (in finite_measure) finite_Lim_measure_incseq:
```
```  1424   assumes A: "range A \<subseteq> sets M" "incseq A"
```
```  1425   shows "(\<lambda>i. measure M (A i)) ----> measure M (\<Union>i. A i)"
```
```  1426   using Lim_measure_incseq[OF A] by simp
```
```  1427
```
```  1428 lemma (in finite_measure) finite_Lim_measure_decseq:
```
```  1429   assumes A: "range A \<subseteq> sets M" "decseq A"
```
```  1430   shows "(\<lambda>n. measure M (A n)) ----> measure M (\<Inter>i. A i)"
```
```  1431   using Lim_measure_decseq[OF A] by simp
```
```  1432
```
```  1433 lemma (in finite_measure) finite_measure_compl:
```
```  1434   assumes S: "S \<in> sets M"
```
```  1435   shows "measure M (space M - S) = measure M (space M) - measure M S"
```
```  1436   using measure_Diff[OF _ sets.top S sets.sets_into_space] S by simp
```
```  1437
```
```  1438 lemma (in finite_measure) finite_measure_mono_AE:
```
```  1439   assumes imp: "AE x in M. x \<in> A \<longrightarrow> x \<in> B" and B: "B \<in> sets M"
```
```  1440   shows "measure M A \<le> measure M B"
```
```  1441   using assms emeasure_mono_AE[OF imp B]
```
```  1442   by (simp add: emeasure_eq_measure)
```
```  1443
```
```  1444 lemma (in finite_measure) finite_measure_eq_AE:
```
```  1445   assumes iff: "AE x in M. x \<in> A \<longleftrightarrow> x \<in> B"
```
```  1446   assumes A: "A \<in> sets M" and B: "B \<in> sets M"
```
```  1447   shows "measure M A = measure M B"
```
```  1448   using assms emeasure_eq_AE[OF assms] by (simp add: emeasure_eq_measure)
```
```  1449
```
```  1450 lemma (in finite_measure) measure_increasing: "increasing M (measure M)"
```
```  1451   by (auto intro!: finite_measure_mono simp: increasing_def)
```
```  1452
```
```  1453 lemma (in finite_measure) measure_zero_union:
```
```  1454   assumes "s \<in> sets M" "t \<in> sets M" "measure M t = 0"
```
```  1455   shows "measure M (s \<union> t) = measure M s"
```
```  1456 using assms
```
```  1457 proof -
```
```  1458   have "measure M (s \<union> t) \<le> measure M s"
```
```  1459     using finite_measure_subadditive[of s t] assms by auto
```
```  1460   moreover have "measure M (s \<union> t) \<ge> measure M s"
```
```  1461     using assms by (blast intro: finite_measure_mono)
```
```  1462   ultimately show ?thesis by simp
```
```  1463 qed
```
```  1464
```
```  1465 lemma (in finite_measure) measure_eq_compl:
```
```  1466   assumes "s \<in> sets M" "t \<in> sets M"
```
```  1467   assumes "measure M (space M - s) = measure M (space M - t)"
```
```  1468   shows "measure M s = measure M t"
```
```  1469   using assms finite_measure_compl by auto
```
```  1470
```
```  1471 lemma (in finite_measure) measure_eq_bigunion_image:
```
```  1472   assumes "range f \<subseteq> sets M" "range g \<subseteq> sets M"
```
```  1473   assumes "disjoint_family f" "disjoint_family g"
```
```  1474   assumes "\<And> n :: nat. measure M (f n) = measure M (g n)"
```
```  1475   shows "measure M (\<Union> i. f i) = measure M (\<Union> i. g i)"
```
```  1476 using assms
```
```  1477 proof -
```
```  1478   have a: "(\<lambda> i. measure M (f i)) sums (measure M (\<Union> i. f i))"
```
```  1479     by (rule finite_measure_UNION[OF assms(1,3)])
```
```  1480   have b: "(\<lambda> i. measure M (g i)) sums (measure M (\<Union> i. g i))"
```
```  1481     by (rule finite_measure_UNION[OF assms(2,4)])
```
```  1482   show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
```
```  1483 qed
```
```  1484
```
```  1485 lemma (in finite_measure) measure_countably_zero:
```
```  1486   assumes "range c \<subseteq> sets M"
```
```  1487   assumes "\<And> i. measure M (c i) = 0"
```
```  1488   shows "measure M (\<Union> i :: nat. c i) = 0"
```
```  1489 proof (rule antisym)
```
```  1490   show "measure M (\<Union> i :: nat. c i) \<le> 0"
```
```  1491     using finite_measure_subadditive_countably[OF assms(1)] by (simp add: assms(2))
```
```  1492 qed (simp add: measure_nonneg)
```
```  1493
```
```  1494 lemma (in finite_measure) measure_space_inter:
```
```  1495   assumes events:"s \<in> sets M" "t \<in> sets M"
```
```  1496   assumes "measure M t = measure M (space M)"
```
```  1497   shows "measure M (s \<inter> t) = measure M s"
```
```  1498 proof -
```
```  1499   have "measure M ((space M - s) \<union> (space M - t)) = measure M (space M - s)"
```
```  1500     using events assms finite_measure_compl[of "t"] by (auto intro!: measure_zero_union)
```
```  1501   also have "(space M - s) \<union> (space M - t) = space M - (s \<inter> t)"
```
```  1502     by blast
```
```  1503   finally show "measure M (s \<inter> t) = measure M s"
```
```  1504     using events by (auto intro!: measure_eq_compl[of "s \<inter> t" s])
```
```  1505 qed
```
```  1506
```
```  1507 lemma (in finite_measure) measure_equiprobable_finite_unions:
```
```  1508   assumes s: "finite s" "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> sets M"
```
```  1509   assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> measure M {x} = measure M {y}"
```
```  1510   shows "measure M s = real (card s) * measure M {SOME x. x \<in> s}"
```
```  1511 proof cases
```
```  1512   assume "s \<noteq> {}"
```
```  1513   then have "\<exists> x. x \<in> s" by blast
```
```  1514   from someI_ex[OF this] assms
```
```  1515   have prob_some: "\<And> x. x \<in> s \<Longrightarrow> measure M {x} = measure M {SOME y. y \<in> s}" by blast
```
```  1516   have "measure M s = (\<Sum> x \<in> s. measure M {x})"
```
```  1517     using finite_measure_eq_setsum_singleton[OF s] by simp
```
```  1518   also have "\<dots> = (\<Sum> x \<in> s. measure M {SOME y. y \<in> s})" using prob_some by auto
```
```  1519   also have "\<dots> = real (card s) * measure M {(SOME x. x \<in> s)}"
```
```  1520     using setsum_constant assms by (simp add: real_eq_of_nat)
```
```  1521   finally show ?thesis by simp
```
```  1522 qed simp
```
```  1523
```
```  1524 lemma (in finite_measure) measure_real_sum_image_fn:
```
```  1525   assumes "e \<in> sets M"
```
```  1526   assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> sets M"
```
```  1527   assumes "finite s"
```
```  1528   assumes disjoint: "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
```
```  1529   assumes upper: "space M \<subseteq> (\<Union> i \<in> s. f i)"
```
```  1530   shows "measure M e = (\<Sum> x \<in> s. measure M (e \<inter> f x))"
```
```  1531 proof -
```
```  1532   have e: "e = (\<Union> i \<in> s. e \<inter> f i)"
```
```  1533     using `e \<in> sets M` sets.sets_into_space upper by blast
```
```  1534   hence "measure M e = measure M (\<Union> i \<in> s. e \<inter> f i)" by simp
```
```  1535   also have "\<dots> = (\<Sum> x \<in> s. measure M (e \<inter> f x))"
```
```  1536   proof (rule finite_measure_finite_Union)
```
```  1537     show "finite s" by fact
```
```  1538     show "(\<lambda>i. e \<inter> f i)`s \<subseteq> sets M" using assms(2) by auto
```
```  1539     show "disjoint_family_on (\<lambda>i. e \<inter> f i) s"
```
```  1540       using disjoint by (auto simp: disjoint_family_on_def)
```
```  1541   qed
```
```  1542   finally show ?thesis .
```
```  1543 qed
```
```  1544
```
```  1545 lemma (in finite_measure) measure_exclude:
```
```  1546   assumes "A \<in> sets M" "B \<in> sets M"
```
```  1547   assumes "measure M A = measure M (space M)" "A \<inter> B = {}"
```
```  1548   shows "measure M B = 0"
```
```  1549   using measure_space_inter[of B A] assms by (auto simp: ac_simps)
```
```  1550 lemma (in finite_measure) finite_measure_distr:
```
```  1551   assumes f: "f \<in> measurable M M'"
```
```  1552   shows "finite_measure (distr M M' f)"
```
```  1553 proof (rule finite_measureI)
```
```  1554   have "f -` space M' \<inter> space M = space M" using f by (auto dest: measurable_space)
```
```  1555   with f show "emeasure (distr M M' f) (space (distr M M' f)) \<noteq> \<infinity>" by (auto simp: emeasure_distr)
```
```  1556 qed
```
```  1557
```
```  1558
```
```  1559 subsection {* Counting space *}
```
```  1560
```
```  1561 lemma strict_monoI_Suc:
```
```  1562   assumes ord [simp]: "(\<And>n. f n < f (Suc n))" shows "strict_mono f"
```
```  1563   unfolding strict_mono_def
```
```  1564 proof safe
```
```  1565   fix n m :: nat assume "n < m" then show "f n < f m"
```
```  1566     by (induct m) (auto simp: less_Suc_eq intro: less_trans ord)
```
```  1567 qed
```
```  1568
```
```  1569 lemma emeasure_count_space:
```
```  1570   assumes "X \<subseteq> A" shows "emeasure (count_space A) X = (if finite X then ereal (card X) else \<infinity>)"
```
```  1571     (is "_ = ?M X")
```
```  1572   unfolding count_space_def
```
```  1573 proof (rule emeasure_measure_of_sigma)
```
```  1574   show "X \<in> Pow A" using `X \<subseteq> A` by auto
```
```  1575   show "sigma_algebra A (Pow A)" by (rule sigma_algebra_Pow)
```
```  1576   show positive: "positive (Pow A) ?M"
```
```  1577     by (auto simp: positive_def)
```
```  1578   have additive: "additive (Pow A) ?M"
```
```  1579     by (auto simp: card_Un_disjoint additive_def)
```
```  1580
```
```  1581   interpret ring_of_sets A "Pow A"
```
```  1582     by (rule ring_of_setsI) auto
```
```  1583   show "countably_additive (Pow A) ?M"
```
```  1584     unfolding countably_additive_iff_continuous_from_below[OF positive additive]
```
```  1585   proof safe
```
```  1586     fix F :: "nat \<Rightarrow> 'a set" assume "incseq F"
```
```  1587     show "(\<lambda>i. ?M (F i)) ----> ?M (\<Union>i. F i)"
```
```  1588     proof cases
```
```  1589       assume "\<exists>i. \<forall>j\<ge>i. F i = F j"
```
```  1590       then guess i .. note i = this
```
```  1591       { fix j from i `incseq F` have "F j \<subseteq> F i"
```
```  1592           by (cases "i \<le> j") (auto simp: incseq_def) }
```
```  1593       then have eq: "(\<Union>i. F i) = F i"
```
```  1594         by auto
```
```  1595       with i show ?thesis
```
```  1596         by (auto intro!: Lim_eventually eventually_sequentiallyI[where c=i])
```
```  1597     next
```
```  1598       assume "\<not> (\<exists>i. \<forall>j\<ge>i. F i = F j)"
```
```  1599       then obtain f where f: "\<And>i. i \<le> f i" "\<And>i. F i \<noteq> F (f i)" by metis
```
```  1600       then have "\<And>i. F i \<subseteq> F (f i)" using `incseq F` by (auto simp: incseq_def)
```
```  1601       with f have *: "\<And>i. F i \<subset> F (f i)" by auto
```
```  1602
```
```  1603       have "incseq (\<lambda>i. ?M (F i))"
```
```  1604         using `incseq F` unfolding incseq_def by (auto simp: card_mono dest: finite_subset)
```
```  1605       then have "(\<lambda>i. ?M (F i)) ----> (SUP n. ?M (F n))"
```
```  1606         by (rule LIMSEQ_SUP)
```
```  1607
```
```  1608       moreover have "(SUP n. ?M (F n)) = \<infinity>"
```
```  1609       proof (rule SUP_PInfty)
```
```  1610         fix n :: nat show "\<exists>k::nat\<in>UNIV. ereal n \<le> ?M (F k)"
```
```  1611         proof (induct n)
```
```  1612           case (Suc n)
```
```  1613           then guess k .. note k = this
```
```  1614           moreover have "finite (F k) \<Longrightarrow> finite (F (f k)) \<Longrightarrow> card (F k) < card (F (f k))"
```
```  1615             using `F k \<subset> F (f k)` by (simp add: psubset_card_mono)
```
```  1616           moreover have "finite (F (f k)) \<Longrightarrow> finite (F k)"
```
```  1617             using `k \<le> f k` `incseq F` by (auto simp: incseq_def dest: finite_subset)
```
```  1618           ultimately show ?case
```
```  1619             by (auto intro!: exI[of _ "f k"])
```
```  1620         qed auto
```
```  1621       qed
```
```  1622
```
```  1623       moreover
```
```  1624       have "inj (\<lambda>n. F ((f ^^ n) 0))"
```
```  1625         by (intro strict_mono_imp_inj_on strict_monoI_Suc) (simp add: *)
```
```  1626       then have 1: "infinite (range (\<lambda>i. F ((f ^^ i) 0)))"
```
```  1627         by (rule range_inj_infinite)
```
```  1628       have "infinite (Pow (\<Union>i. F i))"
```
```  1629         by (rule infinite_super[OF _ 1]) auto
```
```  1630       then have "infinite (\<Union>i. F i)"
```
```  1631         by auto
```
```  1632
```
```  1633       ultimately show ?thesis by auto
```
```  1634     qed
```
```  1635   qed
```
```  1636 qed
```
```  1637
```
```  1638 lemma emeasure_count_space_finite[simp]:
```
```  1639   "X \<subseteq> A \<Longrightarrow> finite X \<Longrightarrow> emeasure (count_space A) X = ereal (card X)"
```
```  1640   using emeasure_count_space[of X A] by simp
```
```  1641
```
```  1642 lemma emeasure_count_space_infinite[simp]:
```
```  1643   "X \<subseteq> A \<Longrightarrow> infinite X \<Longrightarrow> emeasure (count_space A) X = \<infinity>"
```
```  1644   using emeasure_count_space[of X A] by simp
```
```  1645
```
```  1646 lemma emeasure_count_space_eq_0:
```
```  1647   "emeasure (count_space A) X = 0 \<longleftrightarrow> (X \<subseteq> A \<longrightarrow> X = {})"
```
```  1648 proof cases
```
```  1649   assume X: "X \<subseteq> A"
```
```  1650   then show ?thesis
```
```  1651   proof (intro iffI impI)
```
```  1652     assume "emeasure (count_space A) X = 0"
```
```  1653     with X show "X = {}"
```
```  1654       by (subst (asm) emeasure_count_space) (auto split: split_if_asm)
```
```  1655   qed simp
```
```  1656 qed (simp add: emeasure_notin_sets)
```
```  1657
```
```  1658 lemma null_sets_count_space: "null_sets (count_space A) = { {} }"
```
```  1659   unfolding null_sets_def by (auto simp add: emeasure_count_space_eq_0)
```
```  1660
```
```  1661 lemma AE_count_space: "(AE x in count_space A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P x)"
```
```  1662   unfolding eventually_ae_filter by (auto simp add: null_sets_count_space)
```
```  1663
```
```  1664 lemma sigma_finite_measure_count_space_countable:
```
```  1665   assumes A: "countable A"
```
```  1666   shows "sigma_finite_measure (count_space A)"
```
```  1667   proof qed (auto intro!: exI[of _ "(\<lambda>a. {a}) ` A"] simp: A)
```
```  1668
```
```  1669 lemma sigma_finite_measure_count_space:
```
```  1670   fixes A :: "'a::countable set" shows "sigma_finite_measure (count_space A)"
```
```  1671   by (rule sigma_finite_measure_count_space_countable) auto
```
```  1672
```
```  1673 lemma finite_measure_count_space:
```
```  1674   assumes [simp]: "finite A"
```
```  1675   shows "finite_measure (count_space A)"
```
```  1676   by rule simp
```
```  1677
```
```  1678 lemma sigma_finite_measure_count_space_finite:
```
```  1679   assumes A: "finite A" shows "sigma_finite_measure (count_space A)"
```
```  1680 proof -
```
```  1681   interpret finite_measure "count_space A" using A by (rule finite_measure_count_space)
```
```  1682   show "sigma_finite_measure (count_space A)" ..
```
```  1683 qed
```
```  1684
```
```  1685 subsection {* Measure restricted to space *}
```
```  1686
```
```  1687 lemma emeasure_restrict_space:
```
```  1688   assumes "\<Omega> \<inter> space M \<in> sets M" "A \<subseteq> \<Omega>"
```
```  1689   shows "emeasure (restrict_space M \<Omega>) A = emeasure M A"
```
```  1690 proof cases
```
```  1691   assume "A \<in> sets M"
```
```  1692   show ?thesis
```
```  1693   proof (rule emeasure_measure_of[OF restrict_space_def])
```
```  1694     show "op \<inter> \<Omega> ` sets M \<subseteq> Pow (\<Omega> \<inter> space M)" "A \<in> sets (restrict_space M \<Omega>)"
```
```  1695       using `A \<subseteq> \<Omega>` `A \<in> sets M` sets.space_closed by (auto simp: sets_restrict_space)
```
```  1696     show "positive (sets (restrict_space M \<Omega>)) (emeasure M)"
```
```  1697       by (auto simp: positive_def emeasure_nonneg)
```
```  1698     show "countably_additive (sets (restrict_space M \<Omega>)) (emeasure M)"
```
```  1699     proof (rule countably_additiveI)
```
```  1700       fix A :: "nat \<Rightarrow> _" assume "range A \<subseteq> sets (restrict_space M \<Omega>)" "disjoint_family A"
```
```  1701       with assms have "\<And>i. A i \<in> sets M" "\<And>i. A i \<subseteq> space M" "disjoint_family A"
```
```  1702         by (fastforce simp: sets_restrict_space_iff[OF assms(1)] image_subset_iff
```
```  1703                       dest: sets.sets_into_space)+
```
```  1704       then show "(\<Sum>i. emeasure M (A i)) = emeasure M (\<Union>i. A i)"
```
```  1705         by (subst suminf_emeasure) (auto simp: disjoint_family_subset)
```
```  1706     qed
```
```  1707   qed
```
```  1708 next
```
```  1709   assume "A \<notin> sets M"
```
```  1710   moreover with assms have "A \<notin> sets (restrict_space M \<Omega>)"
```
```  1711     by (simp add: sets_restrict_space_iff)
```
```  1712   ultimately show ?thesis
```
```  1713     by (simp add: emeasure_notin_sets)
```
```  1714 qed
```
```  1715
```
```  1716 lemma measure_restrict_space:
```
```  1717   assumes "\<Omega> \<inter> space M \<in> sets M" "A \<subseteq> \<Omega>"
```
```  1718   shows "measure (restrict_space M \<Omega>) A = measure M A"
```
```  1719   using emeasure_restrict_space[OF assms] by (simp add: measure_def)
```
```  1720
```
```  1721 lemma AE_restrict_space_iff:
```
```  1722   assumes "\<Omega> \<inter> space M \<in> sets M"
```
```  1723   shows "(AE x in restrict_space M \<Omega>. P x) \<longleftrightarrow> (AE x in M. x \<in> \<Omega> \<longrightarrow> P x)"
```
```  1724 proof -
```
```  1725   have ex_cong: "\<And>P Q f. (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> P (f x)) \<Longrightarrow> (\<exists>x. P x) \<longleftrightarrow> (\<exists>x. Q x)"
```
```  1726     by auto
```
```  1727   { fix X assume X: "X \<in> sets M" "emeasure M X = 0"
```
```  1728     then have "emeasure M (\<Omega> \<inter> space M \<inter> X) \<le> emeasure M X"
```
```  1729       by (intro emeasure_mono) auto
```
```  1730     then have "emeasure M (\<Omega> \<inter> space M \<inter> X) = 0"
```
```  1731       using X by (auto intro!: antisym) }
```
```  1732   with assms show ?thesis
```
```  1733     unfolding eventually_ae_filter
```
```  1734     by (auto simp add: space_restrict_space null_sets_def sets_restrict_space_iff
```
```  1735                        emeasure_restrict_space cong: conj_cong
```
```  1736              intro!: ex_cong[where f="\<lambda>X. (\<Omega> \<inter> space M) \<inter> X"])
```
```  1737 qed
```
```  1738
```
```  1739 lemma restrict_restrict_space:
```
```  1740   assumes "A \<inter> space M \<in> sets M" "B \<inter> space M \<in> sets M"
```
```  1741   shows "restrict_space (restrict_space M A) B = restrict_space M (A \<inter> B)" (is "?l = ?r")
```
```  1742 proof (rule measure_eqI[symmetric])
```
```  1743   show "sets ?r = sets ?l"
```
```  1744     unfolding sets_restrict_space image_comp by (intro image_cong) auto
```
```  1745 next
```
```  1746   fix X assume "X \<in> sets (restrict_space M (A \<inter> B))"
```
```  1747   then obtain Y where "Y \<in> sets M" "X = Y \<inter> A \<inter> B"
```
```  1748     by (auto simp: sets_restrict_space)
```
```  1749   with assms sets.Int[OF assms] show "emeasure ?r X = emeasure ?l X"
```
```  1750     by (subst (1 2) emeasure_restrict_space)
```
```  1751        (auto simp: space_restrict_space sets_restrict_space_iff emeasure_restrict_space ac_simps)
```
```  1752 qed
```
```  1753
```
```  1754 lemma restrict_count_space: "restrict_space (count_space B) A = count_space (A \<inter> B)"
```
```  1755 proof (rule measure_eqI)
```
```  1756   show "sets (restrict_space (count_space B) A) = sets (count_space (A \<inter> B))"
```
```  1757     by (subst sets_restrict_space) auto
```
```  1758   moreover fix X assume "X \<in> sets (restrict_space (count_space B) A)"
```
```  1759   ultimately have "X \<subseteq> A \<inter> B" by auto
```
```  1760   then show "emeasure (restrict_space (count_space B) A) X = emeasure (count_space (A \<inter> B)) X"
```
```  1761     by (cases "finite X") (auto simp add: emeasure_restrict_space)
```
```  1762 qed
```
```  1763
```
```  1764 lemma restrict_distr:
```
```  1765   assumes [measurable]: "f \<in> measurable M N"
```
```  1766   assumes [simp]: "\<Omega> \<inter> space N \<in> sets N" and restrict: "f \<in> space M \<rightarrow> \<Omega>"
```
```  1767   shows "restrict_space (distr M N f) \<Omega> = distr M (restrict_space N \<Omega>) f"
```
```  1768   (is "?l = ?r")
```
```  1769 proof (rule measure_eqI)
```
```  1770   fix A assume "A \<in> sets (restrict_space (distr M N f) \<Omega>)"
```
```  1771   with restrict show "emeasure ?l A = emeasure ?r A"
```
```  1772     by (subst emeasure_distr)
```
```  1773        (auto simp: sets_restrict_space_iff emeasure_restrict_space emeasure_distr
```
```  1774              intro!: measurable_restrict_space2)
```
```  1775 qed (simp add: sets_restrict_space)
```
```  1776
```
```  1777 end
```
```  1778
```