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