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