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