src/HOL/Analysis/Measure_Space.thy
author haftmann
Wed Aug 10 18:57:20 2016 +0200 (2016-08-10)
changeset 63657 3663157ee197
parent 63627 6ddb43c6b711
child 63658 7faa9bf9860b
permissions -rw-r--r--
tuned order of declarations and proofs
hoelzl@63627
     1
(*  Title:      HOL/Analysis/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
wenzelm@61808
     7
section \<open>Measure spaces and their properties\<close>
hoelzl@47694
     8
hoelzl@47694
     9
theory Measure_Space
hoelzl@47694
    10
imports
hoelzl@63626
    11
  Measurable "~~/src/HOL/Library/Extended_Nonnegative_Real"
hoelzl@47694
    12
begin
hoelzl@47694
    13
hoelzl@50104
    14
subsection "Relate extended reals and the indicator function"
hoelzl@50104
    15
hoelzl@47694
    16
lemma suminf_cmult_indicator:
hoelzl@62975
    17
  fixes f :: "nat \<Rightarrow> ennreal"
hoelzl@62975
    18
  assumes "disjoint_family A" "x \<in> A i"
hoelzl@47694
    19
  shows "(\<Sum>n. f n * indicator (A n) x) = f i"
hoelzl@47694
    20
proof -
hoelzl@62975
    21
  have **: "\<And>n. f n * indicator (A n) x = (if n = i then f n else 0 :: ennreal)"
wenzelm@61808
    22
    using \<open>x \<in> A i\<close> assms unfolding disjoint_family_on_def indicator_def by auto
hoelzl@62975
    23
  then have "\<And>n. (\<Sum>j<n. f j * indicator (A j) x) = (if i < n then f i else 0 :: ennreal)"
haftmann@57418
    24
    by (auto simp: setsum.If_cases)
hoelzl@62975
    25
  moreover have "(SUP n. if i < n then f i else 0) = (f i :: ennreal)"
hoelzl@51000
    26
  proof (rule SUP_eqI)
hoelzl@62975
    27
    fix y :: ennreal assume "\<And>n. n \<in> UNIV \<Longrightarrow> (if i < n then f i else 0) \<le> y"
hoelzl@47694
    28
    from this[of "Suc i"] show "f i \<le> y" by auto
hoelzl@63333
    29
  qed (insert assms, simp)
hoelzl@47694
    30
  ultimately show ?thesis using assms
hoelzl@62975
    31
    by (subst suminf_eq_SUP) (auto simp: indicator_def)
hoelzl@47694
    32
qed
hoelzl@47694
    33
hoelzl@47694
    34
lemma suminf_indicator:
hoelzl@47694
    35
  assumes "disjoint_family A"
hoelzl@62975
    36
  shows "(\<Sum>n. indicator (A n) x :: ennreal) = indicator (\<Union>i. A i) x"
hoelzl@47694
    37
proof cases
hoelzl@47694
    38
  assume *: "x \<in> (\<Union>i. A i)"
hoelzl@47694
    39
  then obtain i where "x \<in> A i" by auto
wenzelm@61808
    40
  from suminf_cmult_indicator[OF assms(1), OF \<open>x \<in> A i\<close>, of "\<lambda>k. 1"]
hoelzl@47694
    41
  show ?thesis using * by simp
hoelzl@47694
    42
qed simp
hoelzl@47694
    43
hoelzl@60727
    44
lemma setsum_indicator_disjoint_family:
hoelzl@60727
    45
  fixes f :: "'d \<Rightarrow> 'e::semiring_1"
hoelzl@60727
    46
  assumes d: "disjoint_family_on A P" and "x \<in> A j" and "finite P" and "j \<in> P"
hoelzl@60727
    47
  shows "(\<Sum>i\<in>P. f i * indicator (A i) x) = f j"
hoelzl@60727
    48
proof -
hoelzl@60727
    49
  have "P \<inter> {i. x \<in> A i} = {j}"
wenzelm@61808
    50
    using d \<open>x \<in> A j\<close> \<open>j \<in> P\<close> unfolding disjoint_family_on_def
hoelzl@60727
    51
    by auto
hoelzl@60727
    52
  thus ?thesis
hoelzl@60727
    53
    unfolding indicator_def
wenzelm@61808
    54
    by (simp add: if_distrib setsum.If_cases[OF \<open>finite P\<close>])
hoelzl@60727
    55
qed
hoelzl@60727
    56
wenzelm@61808
    57
text \<open>
hoelzl@47694
    58
  The type for emeasure spaces is already defined in @{theory Sigma_Algebra}, as it is also used to
hoelzl@47694
    59
  represent sigma algebras (with an arbitrary emeasure).
wenzelm@61808
    60
\<close>
hoelzl@47694
    61
hoelzl@56994
    62
subsection "Extend binary sets"
hoelzl@47694
    63
hoelzl@47694
    64
lemma LIMSEQ_binaryset:
hoelzl@47694
    65
  assumes f: "f {} = 0"
wenzelm@61969
    66
  shows  "(\<lambda>n. \<Sum>i<n. f (binaryset A B i)) \<longlonglongrightarrow> f A + f B"
hoelzl@47694
    67
proof -
hoelzl@47694
    68
  have "(\<lambda>n. \<Sum>i < Suc (Suc n). f (binaryset A B i)) = (\<lambda>n. f A + f B)"
hoelzl@47694
    69
    proof
hoelzl@47694
    70
      fix n
hoelzl@47694
    71
      show "(\<Sum>i < Suc (Suc n). f (binaryset A B i)) = f A + f B"
hoelzl@47694
    72
        by (induct n)  (auto simp add: binaryset_def f)
hoelzl@47694
    73
    qed
hoelzl@47694
    74
  moreover
wenzelm@61969
    75
  have "... \<longlonglongrightarrow> f A + f B" by (rule tendsto_const)
hoelzl@47694
    76
  ultimately
wenzelm@61969
    77
  have "(\<lambda>n. \<Sum>i< Suc (Suc n). f (binaryset A B i)) \<longlonglongrightarrow> f A + f B"
hoelzl@47694
    78
    by metis
wenzelm@61969
    79
  hence "(\<lambda>n. \<Sum>i< n+2. f (binaryset A B i)) \<longlonglongrightarrow> f A + f B"
hoelzl@47694
    80
    by simp
hoelzl@47694
    81
  thus ?thesis by (rule LIMSEQ_offset [where k=2])
hoelzl@47694
    82
qed
hoelzl@47694
    83
hoelzl@47694
    84
lemma binaryset_sums:
hoelzl@47694
    85
  assumes f: "f {} = 0"
hoelzl@47694
    86
  shows  "(\<lambda>n. f (binaryset A B n)) sums (f A + f B)"
hoelzl@47694
    87
    by (simp add: sums_def LIMSEQ_binaryset [where f=f, OF f] atLeast0LessThan)
hoelzl@47694
    88
hoelzl@47694
    89
lemma suminf_binaryset_eq:
hoelzl@47694
    90
  fixes f :: "'a set \<Rightarrow> 'b::{comm_monoid_add, t2_space}"
hoelzl@47694
    91
  shows "f {} = 0 \<Longrightarrow> (\<Sum>n. f (binaryset A B n)) = f A + f B"
hoelzl@47694
    92
  by (metis binaryset_sums sums_unique)
hoelzl@47694
    93
wenzelm@61808
    94
subsection \<open>Properties of a premeasure @{term \<mu>}\<close>
hoelzl@47694
    95
wenzelm@61808
    96
text \<open>
hoelzl@47694
    97
  The definitions for @{const positive} and @{const countably_additive} should be here, by they are
hoelzl@47694
    98
  necessary to define @{typ "'a measure"} in @{theory Sigma_Algebra}.
wenzelm@61808
    99
\<close>
hoelzl@47694
   100
hoelzl@62975
   101
definition subadditive where
hoelzl@62975
   102
  "subadditive M f \<longleftrightarrow> (\<forall>x\<in>M. \<forall>y\<in>M. x \<inter> y = {} \<longrightarrow> f (x \<union> y) \<le> f x + f y)"
hoelzl@62975
   103
hoelzl@62975
   104
lemma subadditiveD: "subadditive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x \<in> M \<Longrightarrow> y \<in> M \<Longrightarrow> f (x \<union> y) \<le> f x + f y"
hoelzl@62975
   105
  by (auto simp add: subadditive_def)
hoelzl@62975
   106
hoelzl@62975
   107
definition countably_subadditive where
hoelzl@62975
   108
  "countably_subadditive M f \<longleftrightarrow>
hoelzl@62975
   109
    (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow> (f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))))"
hoelzl@62975
   110
hoelzl@62975
   111
lemma (in ring_of_sets) countably_subadditive_subadditive:
hoelzl@62975
   112
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@62975
   113
  assumes f: "positive M f" and cs: "countably_subadditive M f"
hoelzl@62975
   114
  shows  "subadditive M f"
hoelzl@62975
   115
proof (auto simp add: subadditive_def)
hoelzl@62975
   116
  fix x y
hoelzl@62975
   117
  assume x: "x \<in> M" and y: "y \<in> M" and "x \<inter> y = {}"
hoelzl@62975
   118
  hence "disjoint_family (binaryset x y)"
hoelzl@62975
   119
    by (auto simp add: disjoint_family_on_def binaryset_def)
hoelzl@62975
   120
  hence "range (binaryset x y) \<subseteq> M \<longrightarrow>
hoelzl@62975
   121
         (\<Union>i. binaryset x y i) \<in> M \<longrightarrow>
hoelzl@62975
   122
         f (\<Union>i. binaryset x y i) \<le> (\<Sum> n. f (binaryset x y n))"
hoelzl@62975
   123
    using cs by (auto simp add: countably_subadditive_def)
hoelzl@62975
   124
  hence "{x,y,{}} \<subseteq> M \<longrightarrow> x \<union> y \<in> M \<longrightarrow>
hoelzl@62975
   125
         f (x \<union> y) \<le> (\<Sum> n. f (binaryset x y n))"
hoelzl@62975
   126
    by (simp add: range_binaryset_eq UN_binaryset_eq)
hoelzl@62975
   127
  thus "f (x \<union> y) \<le>  f x + f y" using f x y
hoelzl@62975
   128
    by (auto simp add: Un o_def suminf_binaryset_eq positive_def)
hoelzl@62975
   129
qed
hoelzl@62975
   130
hoelzl@47694
   131
definition additive where
hoelzl@47694
   132
  "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
   133
hoelzl@47694
   134
definition increasing where
hoelzl@47694
   135
  "increasing M \<mu> \<longleftrightarrow> (\<forall>x\<in>M. \<forall>y\<in>M. x \<subseteq> y \<longrightarrow> \<mu> x \<le> \<mu> y)"
hoelzl@47694
   136
hoelzl@49773
   137
lemma positiveD1: "positive M f \<Longrightarrow> f {} = 0" by (auto simp: positive_def)
hoelzl@49773
   138
hoelzl@47694
   139
lemma positiveD_empty:
hoelzl@47694
   140
  "positive M f \<Longrightarrow> f {} = 0"
hoelzl@47694
   141
  by (auto simp add: positive_def)
hoelzl@47694
   142
hoelzl@47694
   143
lemma additiveD:
hoelzl@47694
   144
  "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
   145
  by (auto simp add: additive_def)
hoelzl@47694
   146
hoelzl@47694
   147
lemma increasingD:
hoelzl@47694
   148
  "increasing M f \<Longrightarrow> x \<subseteq> y \<Longrightarrow> x\<in>M \<Longrightarrow> y\<in>M \<Longrightarrow> f x \<le> f y"
hoelzl@47694
   149
  by (auto simp add: increasing_def)
hoelzl@47694
   150
hoelzl@50104
   151
lemma countably_additiveI[case_names countably]:
hoelzl@47694
   152
  "(\<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
   153
  \<Longrightarrow> countably_additive M f"
hoelzl@47694
   154
  by (simp add: countably_additive_def)
hoelzl@47694
   155
hoelzl@47694
   156
lemma (in ring_of_sets) disjointed_additive:
hoelzl@47694
   157
  assumes f: "positive M f" "additive M f" and A: "range A \<subseteq> M" "incseq A"
hoelzl@47694
   158
  shows "(\<Sum>i\<le>n. f (disjointed A i)) = f (A n)"
hoelzl@47694
   159
proof (induct n)
hoelzl@47694
   160
  case (Suc n)
hoelzl@47694
   161
  then have "(\<Sum>i\<le>Suc n. f (disjointed A i)) = f (A n) + f (disjointed A (Suc n))"
hoelzl@47694
   162
    by simp
hoelzl@47694
   163
  also have "\<dots> = f (A n \<union> disjointed A (Suc n))"
hoelzl@60727
   164
    using A by (subst f(2)[THEN additiveD]) (auto simp: disjointed_mono)
hoelzl@47694
   165
  also have "A n \<union> disjointed A (Suc n) = A (Suc n)"
wenzelm@61808
   166
    using \<open>incseq A\<close> by (auto dest: incseq_SucD simp: disjointed_mono)
hoelzl@47694
   167
  finally show ?case .
hoelzl@47694
   168
qed simp
hoelzl@47694
   169
hoelzl@47694
   170
lemma (in ring_of_sets) additive_sum:
hoelzl@47694
   171
  fixes A:: "'i \<Rightarrow> 'a set"
hoelzl@47694
   172
  assumes f: "positive M f" and ad: "additive M f" and "finite S"
hoelzl@47694
   173
      and A: "A`S \<subseteq> M"
hoelzl@47694
   174
      and disj: "disjoint_family_on A S"
hoelzl@47694
   175
  shows  "(\<Sum>i\<in>S. f (A i)) = f (\<Union>i\<in>S. A i)"
wenzelm@61808
   176
  using \<open>finite S\<close> disj A
wenzelm@53374
   177
proof induct
hoelzl@47694
   178
  case empty show ?case using f by (simp add: positive_def)
hoelzl@47694
   179
next
hoelzl@47694
   180
  case (insert s S)
hoelzl@47694
   181
  then have "A s \<inter> (\<Union>i\<in>S. A i) = {}"
hoelzl@47694
   182
    by (auto simp add: disjoint_family_on_def neq_iff)
hoelzl@47694
   183
  moreover
hoelzl@47694
   184
  have "A s \<in> M" using insert by blast
hoelzl@47694
   185
  moreover have "(\<Union>i\<in>S. A i) \<in> M"
wenzelm@61808
   186
    using insert \<open>finite S\<close> by auto
hoelzl@47694
   187
  ultimately have "f (A s \<union> (\<Union>i\<in>S. A i)) = f (A s) + f(\<Union>i\<in>S. A i)"
hoelzl@47694
   188
    using ad UNION_in_sets A by (auto simp add: additive_def)
hoelzl@47694
   189
  with insert show ?case using ad disjoint_family_on_mono[of S "insert s S" A]
hoelzl@47694
   190
    by (auto simp add: additive_def subset_insertI)
hoelzl@47694
   191
qed
hoelzl@47694
   192
hoelzl@47694
   193
lemma (in ring_of_sets) additive_increasing:
hoelzl@62975
   194
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@47694
   195
  assumes posf: "positive M f" and addf: "additive M f"
hoelzl@47694
   196
  shows "increasing M f"
hoelzl@47694
   197
proof (auto simp add: increasing_def)
hoelzl@47694
   198
  fix x y
hoelzl@47694
   199
  assume xy: "x \<in> M" "y \<in> M" "x \<subseteq> y"
hoelzl@47694
   200
  then have "y - x \<in> M" by auto
hoelzl@62975
   201
  then have "f x + 0 \<le> f x + f (y-x)" by (intro add_left_mono zero_le)
hoelzl@47694
   202
  also have "... = f (x \<union> (y-x))" using addf
hoelzl@47694
   203
    by (auto simp add: additive_def) (metis Diff_disjoint Un_Diff_cancel Diff xy(1,2))
hoelzl@47694
   204
  also have "... = f y"
hoelzl@47694
   205
    by (metis Un_Diff_cancel Un_absorb1 xy(3))
hoelzl@47694
   206
  finally show "f x \<le> f y" by simp
hoelzl@47694
   207
qed
hoelzl@47694
   208
immler@50087
   209
lemma (in ring_of_sets) subadditive:
hoelzl@62975
   210
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@62975
   211
  assumes f: "positive M f" "additive M f" and A: "A`S \<subseteq> M" and S: "finite S"
immler@50087
   212
  shows "f (\<Union>i\<in>S. A i) \<le> (\<Sum>i\<in>S. f (A i))"
hoelzl@62975
   213
using S A
immler@50087
   214
proof (induct S)
immler@50087
   215
  case empty thus ?case using f by (auto simp: positive_def)
immler@50087
   216
next
immler@50087
   217
  case (insert x F)
wenzelm@60585
   218
  hence in_M: "A x \<in> M" "(\<Union>i\<in>F. A i) \<in> M" "(\<Union>i\<in>F. A i) - A x \<in> M" using A by force+
wenzelm@60585
   219
  have subs: "(\<Union>i\<in>F. A i) - A x \<subseteq> (\<Union>i\<in>F. A i)" by auto
wenzelm@60585
   220
  have "(\<Union>i\<in>(insert x F). A i) = A x \<union> ((\<Union>i\<in>F. A i) - A x)" by auto
wenzelm@60585
   221
  hence "f (\<Union>i\<in>(insert x F). A i) = f (A x \<union> ((\<Union>i\<in>F. A i) - A x))"
immler@50087
   222
    by simp
wenzelm@60585
   223
  also have "\<dots> = f (A x) + f ((\<Union>i\<in>F. A i) - A x)"
immler@50087
   224
    using f(2) by (rule additiveD) (insert in_M, auto)
wenzelm@60585
   225
  also have "\<dots> \<le> f (A x) + f (\<Union>i\<in>F. A i)"
immler@50087
   226
    using additive_increasing[OF f] in_M subs by (auto simp: increasing_def intro: add_left_mono)
immler@50087
   227
  also have "\<dots> \<le> f (A x) + (\<Sum>i\<in>F. f (A i))" using insert by (auto intro: add_left_mono)
wenzelm@60585
   228
  finally show "f (\<Union>i\<in>(insert x F). A i) \<le> (\<Sum>i\<in>(insert x F). f (A i))" using insert by simp
immler@50087
   229
qed
immler@50087
   230
hoelzl@47694
   231
lemma (in ring_of_sets) countably_additive_additive:
hoelzl@62975
   232
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@47694
   233
  assumes posf: "positive M f" and ca: "countably_additive M f"
hoelzl@47694
   234
  shows "additive M f"
hoelzl@47694
   235
proof (auto simp add: additive_def)
hoelzl@47694
   236
  fix x y
hoelzl@47694
   237
  assume x: "x \<in> M" and y: "y \<in> M" and "x \<inter> y = {}"
hoelzl@47694
   238
  hence "disjoint_family (binaryset x y)"
hoelzl@47694
   239
    by (auto simp add: disjoint_family_on_def binaryset_def)
hoelzl@47694
   240
  hence "range (binaryset x y) \<subseteq> M \<longrightarrow>
hoelzl@47694
   241
         (\<Union>i. binaryset x y i) \<in> M \<longrightarrow>
hoelzl@47694
   242
         f (\<Union>i. binaryset x y i) = (\<Sum> n. f (binaryset x y n))"
hoelzl@47694
   243
    using ca
hoelzl@47694
   244
    by (simp add: countably_additive_def)
hoelzl@47694
   245
  hence "{x,y,{}} \<subseteq> M \<longrightarrow> x \<union> y \<in> M \<longrightarrow>
hoelzl@47694
   246
         f (x \<union> y) = (\<Sum>n. f (binaryset x y n))"
hoelzl@47694
   247
    by (simp add: range_binaryset_eq UN_binaryset_eq)
hoelzl@47694
   248
  thus "f (x \<union> y) = f x + f y" using posf x y
hoelzl@47694
   249
    by (auto simp add: Un suminf_binaryset_eq positive_def)
hoelzl@47694
   250
qed
hoelzl@47694
   251
hoelzl@47694
   252
lemma (in algebra) increasing_additive_bound:
hoelzl@62975
   253
  fixes A:: "nat \<Rightarrow> 'a set" and  f :: "'a set \<Rightarrow> ennreal"
hoelzl@47694
   254
  assumes f: "positive M f" and ad: "additive M f"
hoelzl@47694
   255
      and inc: "increasing M f"
hoelzl@47694
   256
      and A: "range A \<subseteq> M"
hoelzl@47694
   257
      and disj: "disjoint_family A"
hoelzl@47694
   258
  shows  "(\<Sum>i. f (A i)) \<le> f \<Omega>"
hoelzl@62975
   259
proof (safe intro!: suminf_le_const)
hoelzl@47694
   260
  fix N
hoelzl@47694
   261
  note disj_N = disjoint_family_on_mono[OF _ disj, of "{..<N}"]
hoelzl@47694
   262
  have "(\<Sum>i<N. f (A i)) = f (\<Union>i\<in>{..<N}. A i)"
hoelzl@47694
   263
    using A by (intro additive_sum [OF f ad _ _]) (auto simp: disj_N)
hoelzl@47694
   264
  also have "... \<le> f \<Omega>" using space_closed A
hoelzl@47694
   265
    by (intro increasingD[OF inc] finite_UN) auto
hoelzl@47694
   266
  finally show "(\<Sum>i<N. f (A i)) \<le> f \<Omega>" by simp
hoelzl@47694
   267
qed (insert f A, auto simp: positive_def)
hoelzl@47694
   268
hoelzl@47694
   269
lemma (in ring_of_sets) countably_additiveI_finite:
hoelzl@62975
   270
  fixes \<mu> :: "'a set \<Rightarrow> ennreal"
hoelzl@47694
   271
  assumes "finite \<Omega>" "positive M \<mu>" "additive M \<mu>"
hoelzl@47694
   272
  shows "countably_additive M \<mu>"
hoelzl@47694
   273
proof (rule countably_additiveI)
hoelzl@47694
   274
  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
   275
hoelzl@47694
   276
  have "\<forall>i\<in>{i. F i \<noteq> {}}. \<exists>x. x \<in> F i" by auto
hoelzl@47694
   277
  from bchoice[OF this] obtain f where f: "\<And>i. F i \<noteq> {} \<Longrightarrow> f i \<in> F i" by auto
hoelzl@47694
   278
hoelzl@47694
   279
  have inj_f: "inj_on f {i. F i \<noteq> {}}"
hoelzl@47694
   280
  proof (rule inj_onI, simp)
hoelzl@47694
   281
    fix i j a b assume *: "f i = f j" "F i \<noteq> {}" "F j \<noteq> {}"
hoelzl@47694
   282
    then have "f i \<in> F i" "f j \<in> F j" using f by force+
hoelzl@47694
   283
    with disj * show "i = j" by (auto simp: disjoint_family_on_def)
hoelzl@47694
   284
  qed
hoelzl@47694
   285
  have "finite (\<Union>i. F i)"
hoelzl@47694
   286
    by (metis F(2) assms(1) infinite_super sets_into_space)
hoelzl@47694
   287
hoelzl@47694
   288
  have F_subset: "{i. \<mu> (F i) \<noteq> 0} \<subseteq> {i. F i \<noteq> {}}"
wenzelm@61808
   289
    by (auto simp: positiveD_empty[OF \<open>positive M \<mu>\<close>])
hoelzl@47694
   290
  moreover have fin_not_empty: "finite {i. F i \<noteq> {}}"
hoelzl@47694
   291
  proof (rule finite_imageD)
hoelzl@47694
   292
    from f have "f`{i. F i \<noteq> {}} \<subseteq> (\<Union>i. F i)" by auto
hoelzl@47694
   293
    then show "finite (f`{i. F i \<noteq> {}})"
hoelzl@47694
   294
      by (rule finite_subset) fact
hoelzl@47694
   295
  qed fact
hoelzl@47694
   296
  ultimately have fin_not_0: "finite {i. \<mu> (F i) \<noteq> 0}"
hoelzl@47694
   297
    by (rule finite_subset)
hoelzl@47694
   298
hoelzl@47694
   299
  have disj_not_empty: "disjoint_family_on F {i. F i \<noteq> {}}"
hoelzl@47694
   300
    using disj by (auto simp: disjoint_family_on_def)
hoelzl@47694
   301
hoelzl@47694
   302
  from fin_not_0 have "(\<Sum>i. \<mu> (F i)) = (\<Sum>i | \<mu> (F i) \<noteq> 0. \<mu> (F i))"
hoelzl@47761
   303
    by (rule suminf_finite) auto
hoelzl@47694
   304
  also have "\<dots> = (\<Sum>i | F i \<noteq> {}. \<mu> (F i))"
haftmann@57418
   305
    using fin_not_empty F_subset by (rule setsum.mono_neutral_left) auto
hoelzl@47694
   306
  also have "\<dots> = \<mu> (\<Union>i\<in>{i. F i \<noteq> {}}. F i)"
wenzelm@61808
   307
    using \<open>positive M \<mu>\<close> \<open>additive M \<mu>\<close> fin_not_empty disj_not_empty F by (intro additive_sum) auto
hoelzl@47694
   308
  also have "\<dots> = \<mu> (\<Union>i. F i)"
hoelzl@47694
   309
    by (rule arg_cong[where f=\<mu>]) auto
hoelzl@47694
   310
  finally show "(\<Sum>i. \<mu> (F i)) = \<mu> (\<Union>i. F i)" .
hoelzl@47694
   311
qed
hoelzl@47694
   312
hoelzl@49773
   313
lemma (in ring_of_sets) countably_additive_iff_continuous_from_below:
hoelzl@62975
   314
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@49773
   315
  assumes f: "positive M f" "additive M f"
hoelzl@49773
   316
  shows "countably_additive M f \<longleftrightarrow>
wenzelm@61969
   317
    (\<forall>A. range A \<subseteq> M \<longrightarrow> incseq A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> f (\<Union>i. A i))"
hoelzl@49773
   318
  unfolding countably_additive_def
hoelzl@49773
   319
proof safe
hoelzl@49773
   320
  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
   321
  fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" "incseq A" "(\<Union>i. A i) \<in> M"
hoelzl@49773
   322
  then have dA: "range (disjointed A) \<subseteq> M" by (auto simp: range_disjointed_sets)
hoelzl@49773
   323
  with count_sum[THEN spec, of "disjointed A"] A(3)
hoelzl@49773
   324
  have f_UN: "(\<Sum>i. f (disjointed A i)) = f (\<Union>i. A i)"
hoelzl@49773
   325
    by (auto simp: UN_disjointed_eq disjoint_family_disjointed)
wenzelm@61969
   326
  moreover have "(\<lambda>n. (\<Sum>i<n. f (disjointed A i))) \<longlonglongrightarrow> (\<Sum>i. f (disjointed A i))"
hoelzl@49773
   327
    using f(1)[unfolded positive_def] dA
hoelzl@63333
   328
    by (auto intro!: summable_LIMSEQ)
hoelzl@49773
   329
  from LIMSEQ_Suc[OF this]
wenzelm@61969
   330
  have "(\<lambda>n. (\<Sum>i\<le>n. f (disjointed A i))) \<longlonglongrightarrow> (\<Sum>i. f (disjointed A i))"
hoelzl@56193
   331
    unfolding lessThan_Suc_atMost .
hoelzl@49773
   332
  moreover have "\<And>n. (\<Sum>i\<le>n. f (disjointed A i)) = f (A n)"
hoelzl@49773
   333
    using disjointed_additive[OF f A(1,2)] .
wenzelm@61969
   334
  ultimately show "(\<lambda>i. f (A i)) \<longlonglongrightarrow> f (\<Union>i. A i)" by simp
hoelzl@49773
   335
next
wenzelm@61969
   336
  assume cont: "\<forall>A. range A \<subseteq> M \<longrightarrow> incseq A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> f (\<Union>i. A i)"
hoelzl@49773
   337
  fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" "disjoint_family A" "(\<Union>i. A i) \<in> M"
hoelzl@57446
   338
  have *: "(\<Union>n. (\<Union>i<n. A i)) = (\<Union>i. A i)" by auto
wenzelm@61969
   339
  have "(\<lambda>n. f (\<Union>i<n. A i)) \<longlonglongrightarrow> f (\<Union>i. A i)"
hoelzl@49773
   340
  proof (unfold *[symmetric], intro cont[rule_format])
wenzelm@60585
   341
    show "range (\<lambda>i. \<Union>i<i. A i) \<subseteq> M" "(\<Union>i. \<Union>i<i. A i) \<in> M"
hoelzl@49773
   342
      using A * by auto
hoelzl@49773
   343
  qed (force intro!: incseq_SucI)
hoelzl@57446
   344
  moreover have "\<And>n. f (\<Union>i<n. A i) = (\<Sum>i<n. f (A i))"
hoelzl@49773
   345
    using A
hoelzl@49773
   346
    by (intro additive_sum[OF f, of _ A, symmetric])
hoelzl@49773
   347
       (auto intro: disjoint_family_on_mono[where B=UNIV])
hoelzl@49773
   348
  ultimately
hoelzl@49773
   349
  have "(\<lambda>i. f (A i)) sums f (\<Union>i. A i)"
hoelzl@57446
   350
    unfolding sums_def by simp
hoelzl@49773
   351
  from sums_unique[OF this]
hoelzl@49773
   352
  show "(\<Sum>i. f (A i)) = f (\<Union>i. A i)" by simp
hoelzl@49773
   353
qed
hoelzl@49773
   354
hoelzl@49773
   355
lemma (in ring_of_sets) continuous_from_above_iff_empty_continuous:
hoelzl@62975
   356
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@49773
   357
  assumes f: "positive M f" "additive M f"
wenzelm@61969
   358
  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)) \<longlonglongrightarrow> f (\<Inter>i. A i))
wenzelm@61969
   359
     \<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)) \<longlonglongrightarrow> 0)"
hoelzl@49773
   360
proof safe
wenzelm@61969
   361
  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)) \<longlonglongrightarrow> f (\<Inter>i. A i))"
hoelzl@49773
   362
  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>"
wenzelm@61969
   363
  with cont[THEN spec, of A] show "(\<lambda>i. f (A i)) \<longlonglongrightarrow> 0"
wenzelm@61808
   364
    using \<open>positive M f\<close>[unfolded positive_def] by auto
hoelzl@49773
   365
next
wenzelm@61969
   366
  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)) \<longlonglongrightarrow> 0"
hoelzl@49773
   367
  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
   368
hoelzl@49773
   369
  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
   370
    using additive_increasing[OF f] unfolding increasing_def by simp
hoelzl@49773
   371
hoelzl@49773
   372
  have decseq_fA: "decseq (\<lambda>i. f (A i))"
hoelzl@49773
   373
    using A by (auto simp: decseq_def intro!: f_mono)
hoelzl@49773
   374
  have decseq: "decseq (\<lambda>i. A i - (\<Inter>i. A i))"
hoelzl@49773
   375
    using A by (auto simp: decseq_def)
hoelzl@49773
   376
  then have decseq_f: "decseq (\<lambda>i. f (A i - (\<Inter>i. A i)))"
hoelzl@49773
   377
    using A unfolding decseq_def by (auto intro!: f_mono Diff)
hoelzl@49773
   378
  have "f (\<Inter>x. A x) \<le> f (A 0)"
hoelzl@49773
   379
    using A by (auto intro!: f_mono)
hoelzl@49773
   380
  then have f_Int_fin: "f (\<Inter>x. A x) \<noteq> \<infinity>"
hoelzl@62975
   381
    using A by (auto simp: top_unique)
hoelzl@49773
   382
  { fix i
hoelzl@49773
   383
    have "f (A i - (\<Inter>i. A i)) \<le> f (A i)" using A by (auto intro!: f_mono)
hoelzl@49773
   384
    then have "f (A i - (\<Inter>i. A i)) \<noteq> \<infinity>"
hoelzl@62975
   385
      using A by (auto simp: top_unique) }
hoelzl@49773
   386
  note f_fin = this
wenzelm@61969
   387
  have "(\<lambda>i. f (A i - (\<Inter>i. A i))) \<longlonglongrightarrow> 0"
hoelzl@49773
   388
  proof (intro cont[rule_format, OF _ decseq _ f_fin])
hoelzl@49773
   389
    show "range (\<lambda>i. A i - (\<Inter>i. A i)) \<subseteq> M" "(\<Inter>i. A i - (\<Inter>i. A i)) = {}"
hoelzl@49773
   390
      using A by auto
hoelzl@49773
   391
  qed
hoelzl@49773
   392
  from INF_Lim_ereal[OF decseq_f this]
hoelzl@49773
   393
  have "(INF n. f (A n - (\<Inter>i. A i))) = 0" .
hoelzl@49773
   394
  moreover have "(INF n. f (\<Inter>i. A i)) = f (\<Inter>i. A i)"
hoelzl@49773
   395
    by auto
hoelzl@49773
   396
  ultimately have "(INF n. f (A n - (\<Inter>i. A i)) + f (\<Inter>i. A i)) = 0 + f (\<Inter>i. A i)"
hoelzl@49773
   397
    using A(4) f_fin f_Int_fin
hoelzl@62975
   398
    by (subst INF_ennreal_add_const) (auto simp: decseq_f)
hoelzl@49773
   399
  moreover {
hoelzl@49773
   400
    fix n
hoelzl@49773
   401
    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
   402
      using A by (subst f(2)[THEN additiveD]) auto
hoelzl@49773
   403
    also have "(A n - (\<Inter>i. A i)) \<union> (\<Inter>i. A i) = A n"
hoelzl@49773
   404
      by auto
hoelzl@49773
   405
    finally have "f (A n - (\<Inter>i. A i)) + f (\<Inter>i. A i) = f (A n)" . }
hoelzl@49773
   406
  ultimately have "(INF n. f (A n)) = f (\<Inter>i. A i)"
hoelzl@49773
   407
    by simp
hoelzl@51351
   408
  with LIMSEQ_INF[OF decseq_fA]
wenzelm@61969
   409
  show "(\<lambda>i. f (A i)) \<longlonglongrightarrow> f (\<Inter>i. A i)" by simp
hoelzl@49773
   410
qed
hoelzl@49773
   411
hoelzl@49773
   412
lemma (in ring_of_sets) empty_continuous_imp_continuous_from_below:
hoelzl@62975
   413
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@49773
   414
  assumes f: "positive M f" "additive M f" "\<forall>A\<in>M. f A \<noteq> \<infinity>"
wenzelm@61969
   415
  assumes cont: "\<forall>A. range A \<subseteq> M \<longrightarrow> decseq A \<longrightarrow> (\<Inter>i. A i) = {} \<longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> 0"
hoelzl@49773
   416
  assumes A: "range A \<subseteq> M" "incseq A" "(\<Union>i. A i) \<in> M"
wenzelm@61969
   417
  shows "(\<lambda>i. f (A i)) \<longlonglongrightarrow> f (\<Union>i. A i)"
hoelzl@49773
   418
proof -
wenzelm@61969
   419
  from A have "(\<lambda>i. f ((\<Union>i. A i) - A i)) \<longlonglongrightarrow> 0"
hoelzl@49773
   420
    by (intro cont[rule_format]) (auto simp: decseq_def incseq_def)
hoelzl@49773
   421
  moreover
hoelzl@49773
   422
  { fix i
hoelzl@62975
   423
    have "f ((\<Union>i. A i) - A i \<union> A i) = f ((\<Union>i. A i) - A i) + f (A i)"
hoelzl@62975
   424
      using A by (intro f(2)[THEN additiveD]) auto
hoelzl@62975
   425
    also have "((\<Union>i. A i) - A i) \<union> A i = (\<Union>i. A i)"
hoelzl@49773
   426
      by auto
hoelzl@62975
   427
    finally have "f ((\<Union>i. A i) - A i) = f (\<Union>i. A i) - f (A i)"
hoelzl@62975
   428
      using f(3)[rule_format, of "A i"] A by (auto simp: ennreal_add_diff_cancel subset_eq) }
hoelzl@62975
   429
  moreover have "\<forall>\<^sub>F i in sequentially. f (A i) \<le> f (\<Union>i. A i)"
hoelzl@62975
   430
    using increasingD[OF additive_increasing[OF f(1, 2)], of "A _" "\<Union>i. A i"] A
hoelzl@62975
   431
    by (auto intro!: always_eventually simp: subset_eq)
hoelzl@62975
   432
  ultimately show "(\<lambda>i. f (A i)) \<longlonglongrightarrow> f (\<Union>i. A i)"
hoelzl@62975
   433
    by (auto intro: ennreal_tendsto_const_minus)
hoelzl@49773
   434
qed
hoelzl@49773
   435
hoelzl@49773
   436
lemma (in ring_of_sets) empty_continuous_imp_countably_additive:
hoelzl@62975
   437
  fixes f :: "'a set \<Rightarrow> ennreal"
hoelzl@49773
   438
  assumes f: "positive M f" "additive M f" and fin: "\<forall>A\<in>M. f A \<noteq> \<infinity>"
wenzelm@61969
   439
  assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> 0"
hoelzl@49773
   440
  shows "countably_additive M f"
hoelzl@49773
   441
  using countably_additive_iff_continuous_from_below[OF f]
hoelzl@49773
   442
  using empty_continuous_imp_continuous_from_below[OF f fin] cont
hoelzl@49773
   443
  by blast
hoelzl@49773
   444
wenzelm@61808
   445
subsection \<open>Properties of @{const emeasure}\<close>
hoelzl@47694
   446
hoelzl@47694
   447
lemma emeasure_positive: "positive (sets M) (emeasure M)"
hoelzl@47694
   448
  by (cases M) (auto simp: sets_def emeasure_def Abs_measure_inverse measure_space_def)
hoelzl@47694
   449
hoelzl@47694
   450
lemma emeasure_empty[simp, intro]: "emeasure M {} = 0"
hoelzl@47694
   451
  using emeasure_positive[of M] by (simp add: positive_def)
hoelzl@47694
   452
hoelzl@59000
   453
lemma emeasure_single_in_space: "emeasure M {x} \<noteq> 0 \<Longrightarrow> x \<in> space M"
hoelzl@62975
   454
  using emeasure_notin_sets[of "{x}" M] by (auto dest: sets.sets_into_space zero_less_iff_neq_zero[THEN iffD2])
hoelzl@59000
   455
hoelzl@47694
   456
lemma emeasure_countably_additive: "countably_additive (sets M) (emeasure M)"
hoelzl@47694
   457
  by (cases M) (auto simp: sets_def emeasure_def Abs_measure_inverse measure_space_def)
hoelzl@47694
   458
hoelzl@47694
   459
lemma suminf_emeasure:
hoelzl@47694
   460
  "range A \<subseteq> sets M \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Sum>i. emeasure M (A i)) = emeasure M (\<Union>i. A i)"
immler@50244
   461
  using sets.countable_UN[of A UNIV M] emeasure_countably_additive[of M]
hoelzl@47694
   462
  by (simp add: countably_additive_def)
hoelzl@47694
   463
hoelzl@57447
   464
lemma sums_emeasure:
hoelzl@57447
   465
  "disjoint_family F \<Longrightarrow> (\<And>i. F i \<in> sets M) \<Longrightarrow> (\<lambda>i. emeasure M (F i)) sums emeasure M (\<Union>i. F i)"
hoelzl@62975
   466
  unfolding sums_iff by (intro conjI suminf_emeasure) auto
hoelzl@57447
   467
hoelzl@47694
   468
lemma emeasure_additive: "additive (sets M) (emeasure M)"
immler@50244
   469
  by (metis sets.countably_additive_additive emeasure_positive emeasure_countably_additive)
hoelzl@47694
   470
hoelzl@47694
   471
lemma plus_emeasure:
hoelzl@47694
   472
  "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
   473
  using additiveD[OF emeasure_additive] ..
hoelzl@47694
   474
hoelzl@47694
   475
lemma setsum_emeasure:
hoelzl@47694
   476
  "F`I \<subseteq> sets M \<Longrightarrow> disjoint_family_on F I \<Longrightarrow> finite I \<Longrightarrow>
hoelzl@47694
   477
    (\<Sum>i\<in>I. emeasure M (F i)) = emeasure M (\<Union>i\<in>I. F i)"
immler@50244
   478
  by (metis sets.additive_sum emeasure_positive emeasure_additive)
hoelzl@47694
   479
hoelzl@47694
   480
lemma emeasure_mono:
hoelzl@47694
   481
  "a \<subseteq> b \<Longrightarrow> b \<in> sets M \<Longrightarrow> emeasure M a \<le> emeasure M b"
hoelzl@62975
   482
  by (metis zero_le sets.additive_increasing emeasure_additive emeasure_notin_sets emeasure_positive increasingD)
hoelzl@47694
   483
hoelzl@47694
   484
lemma emeasure_space:
hoelzl@47694
   485
  "emeasure M A \<le> emeasure M (space M)"
hoelzl@62975
   486
  by (metis emeasure_mono emeasure_notin_sets sets.sets_into_space sets.top zero_le)
hoelzl@47694
   487
hoelzl@47694
   488
lemma emeasure_Diff:
hoelzl@47694
   489
  assumes finite: "emeasure M B \<noteq> \<infinity>"
hoelzl@50002
   490
  and [measurable]: "A \<in> sets M" "B \<in> sets M" and "B \<subseteq> A"
hoelzl@47694
   491
  shows "emeasure M (A - B) = emeasure M A - emeasure M B"
hoelzl@47694
   492
proof -
wenzelm@61808
   493
  have "(A - B) \<union> B = A" using \<open>B \<subseteq> A\<close> by auto
hoelzl@47694
   494
  then have "emeasure M A = emeasure M ((A - B) \<union> B)" by simp
hoelzl@47694
   495
  also have "\<dots> = emeasure M (A - B) + emeasure M B"
hoelzl@50002
   496
    by (subst plus_emeasure[symmetric]) auto
hoelzl@47694
   497
  finally show "emeasure M (A - B) = emeasure M A - emeasure M B"
hoelzl@62975
   498
    using finite by simp
hoelzl@47694
   499
qed
hoelzl@47694
   500
hoelzl@62975
   501
lemma emeasure_compl:
hoelzl@62975
   502
  "s \<in> sets M \<Longrightarrow> emeasure M s \<noteq> \<infinity> \<Longrightarrow> emeasure M (space M - s) = emeasure M (space M) - emeasure M s"
hoelzl@62975
   503
  by (rule emeasure_Diff) (auto dest: sets.sets_into_space)
hoelzl@62975
   504
hoelzl@49773
   505
lemma Lim_emeasure_incseq:
wenzelm@61969
   506
  "range A \<subseteq> sets M \<Longrightarrow> incseq A \<Longrightarrow> (\<lambda>i. (emeasure M (A i))) \<longlonglongrightarrow> emeasure M (\<Union>i. A i)"
hoelzl@49773
   507
  using emeasure_countably_additive
immler@50244
   508
  by (auto simp add: sets.countably_additive_iff_continuous_from_below emeasure_positive
immler@50244
   509
    emeasure_additive)
hoelzl@47694
   510
hoelzl@47694
   511
lemma incseq_emeasure:
hoelzl@47694
   512
  assumes "range B \<subseteq> sets M" "incseq B"
hoelzl@47694
   513
  shows "incseq (\<lambda>i. emeasure M (B i))"
hoelzl@47694
   514
  using assms by (auto simp: incseq_def intro!: emeasure_mono)
hoelzl@47694
   515
hoelzl@49773
   516
lemma SUP_emeasure_incseq:
hoelzl@47694
   517
  assumes A: "range A \<subseteq> sets M" "incseq A"
hoelzl@49773
   518
  shows "(SUP n. emeasure M (A n)) = emeasure M (\<Union>i. A i)"
hoelzl@51000
   519
  using LIMSEQ_SUP[OF incseq_emeasure, OF A] Lim_emeasure_incseq[OF A]
hoelzl@49773
   520
  by (simp add: LIMSEQ_unique)
hoelzl@47694
   521
hoelzl@47694
   522
lemma decseq_emeasure:
hoelzl@47694
   523
  assumes "range B \<subseteq> sets M" "decseq B"
hoelzl@47694
   524
  shows "decseq (\<lambda>i. emeasure M (B i))"
hoelzl@47694
   525
  using assms by (auto simp: decseq_def intro!: emeasure_mono)
hoelzl@47694
   526
hoelzl@47694
   527
lemma INF_emeasure_decseq:
hoelzl@47694
   528
  assumes A: "range A \<subseteq> sets M" and "decseq A"
hoelzl@47694
   529
  and finite: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
hoelzl@47694
   530
  shows "(INF n. emeasure M (A n)) = emeasure M (\<Inter>i. A i)"
hoelzl@47694
   531
proof -
hoelzl@47694
   532
  have le_MI: "emeasure M (\<Inter>i. A i) \<le> emeasure M (A 0)"
hoelzl@47694
   533
    using A by (auto intro!: emeasure_mono)
hoelzl@62975
   534
  hence *: "emeasure M (\<Inter>i. A i) \<noteq> \<infinity>" using finite[of 0] by (auto simp: top_unique)
hoelzl@47694
   535
hoelzl@62975
   536
  have "emeasure M (A 0) - (INF n. emeasure M (A n)) = (SUP n. emeasure M (A 0) - emeasure M (A n))"
hoelzl@62975
   537
    by (simp add: ennreal_INF_const_minus)
hoelzl@47694
   538
  also have "\<dots> = (SUP n. emeasure M (A 0 - A n))"
wenzelm@61808
   539
    using A finite \<open>decseq A\<close>[unfolded decseq_def] by (subst emeasure_Diff) auto
hoelzl@47694
   540
  also have "\<dots> = emeasure M (\<Union>i. A 0 - A i)"
hoelzl@47694
   541
  proof (rule SUP_emeasure_incseq)
hoelzl@47694
   542
    show "range (\<lambda>n. A 0 - A n) \<subseteq> sets M"
hoelzl@47694
   543
      using A by auto
hoelzl@47694
   544
    show "incseq (\<lambda>n. A 0 - A n)"
wenzelm@61808
   545
      using \<open>decseq A\<close> by (auto simp add: incseq_def decseq_def)
hoelzl@47694
   546
  qed
hoelzl@47694
   547
  also have "\<dots> = emeasure M (A 0) - emeasure M (\<Inter>i. A i)"
hoelzl@47694
   548
    using A finite * by (simp, subst emeasure_Diff) auto
hoelzl@47694
   549
  finally show ?thesis
hoelzl@62975
   550
    by (rule ennreal_minus_cancel[rotated 3])
hoelzl@62975
   551
       (insert finite A, auto intro: INF_lower emeasure_mono)
hoelzl@47694
   552
qed
hoelzl@47694
   553
hoelzl@61359
   554
lemma emeasure_INT_decseq_subset:
hoelzl@61359
   555
  fixes F :: "nat \<Rightarrow> 'a set"
hoelzl@61359
   556
  assumes I: "I \<noteq> {}" and F: "\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> i \<le> j \<Longrightarrow> F j \<subseteq> F i"
hoelzl@61359
   557
  assumes F_sets[measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> sets M"
hoelzl@61359
   558
    and fin: "\<And>i. i \<in> I \<Longrightarrow> emeasure M (F i) \<noteq> \<infinity>"
hoelzl@61359
   559
  shows "emeasure M (\<Inter>i\<in>I. F i) = (INF i:I. emeasure M (F i))"
hoelzl@61359
   560
proof cases
hoelzl@61359
   561
  assume "finite I"
hoelzl@61359
   562
  have "(\<Inter>i\<in>I. F i) = F (Max I)"
hoelzl@61359
   563
    using I \<open>finite I\<close> by (intro antisym INF_lower INF_greatest F) auto
hoelzl@61359
   564
  moreover have "(INF i:I. emeasure M (F i)) = emeasure M (F (Max I))"
hoelzl@61359
   565
    using I \<open>finite I\<close> by (intro antisym INF_lower INF_greatest F emeasure_mono) auto
hoelzl@61359
   566
  ultimately show ?thesis
hoelzl@61359
   567
    by simp
hoelzl@61359
   568
next
hoelzl@61359
   569
  assume "infinite I"
wenzelm@63040
   570
  define L where "L n = (LEAST i. i \<in> I \<and> i \<ge> n)" for n
hoelzl@61359
   571
  have L: "L n \<in> I \<and> n \<le> L n" for n
hoelzl@61359
   572
    unfolding L_def
hoelzl@61359
   573
  proof (rule LeastI_ex)
hoelzl@61359
   574
    show "\<exists>x. x \<in> I \<and> n \<le> x"
hoelzl@61359
   575
      using \<open>infinite I\<close> finite_subset[of I "{..< n}"]
hoelzl@61359
   576
      by (rule_tac ccontr) (auto simp: not_le)
hoelzl@61359
   577
  qed
hoelzl@61359
   578
  have L_eq[simp]: "i \<in> I \<Longrightarrow> L i = i" for i
hoelzl@61359
   579
    unfolding L_def by (intro Least_equality) auto
hoelzl@61359
   580
  have L_mono: "i \<le> j \<Longrightarrow> L i \<le> L j" for i j
hoelzl@61359
   581
    using L[of j] unfolding L_def by (intro Least_le) (auto simp: L_def)
hoelzl@61359
   582
hoelzl@61359
   583
  have "emeasure M (\<Inter>i. F (L i)) = (INF i. emeasure M (F (L i)))"
hoelzl@61359
   584
  proof (intro INF_emeasure_decseq[symmetric])
hoelzl@61359
   585
    show "decseq (\<lambda>i. F (L i))"
hoelzl@61359
   586
      using L by (intro antimonoI F L_mono) auto
hoelzl@61359
   587
  qed (insert L fin, auto)
hoelzl@61359
   588
  also have "\<dots> = (INF i:I. emeasure M (F i))"
hoelzl@61359
   589
  proof (intro antisym INF_greatest)
hoelzl@61359
   590
    show "i \<in> I \<Longrightarrow> (INF i. emeasure M (F (L i))) \<le> emeasure M (F i)" for i
hoelzl@61359
   591
      by (intro INF_lower2[of i]) auto
hoelzl@61359
   592
  qed (insert L, auto intro: INF_lower)
hoelzl@61359
   593
  also have "(\<Inter>i. F (L i)) = (\<Inter>i\<in>I. F i)"
hoelzl@61359
   594
  proof (intro antisym INF_greatest)
hoelzl@61359
   595
    show "i \<in> I \<Longrightarrow> (\<Inter>i. F (L i)) \<subseteq> F i" for i
hoelzl@61359
   596
      by (intro INF_lower2[of i]) auto
hoelzl@61359
   597
  qed (insert L, auto)
hoelzl@61359
   598
  finally show ?thesis .
hoelzl@61359
   599
qed
hoelzl@61359
   600
hoelzl@47694
   601
lemma Lim_emeasure_decseq:
hoelzl@47694
   602
  assumes A: "range A \<subseteq> sets M" "decseq A" and fin: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
wenzelm@61969
   603
  shows "(\<lambda>i. emeasure M (A i)) \<longlonglongrightarrow> emeasure M (\<Inter>i. A i)"
hoelzl@51351
   604
  using LIMSEQ_INF[OF decseq_emeasure, OF A]
hoelzl@47694
   605
  using INF_emeasure_decseq[OF A fin] by simp
hoelzl@47694
   606
hoelzl@60636
   607
lemma emeasure_lfp'[consumes 1, case_names cont measurable]:
hoelzl@59000
   608
  assumes "P M"
hoelzl@60172
   609
  assumes cont: "sup_continuous F"
hoelzl@59000
   610
  assumes *: "\<And>M A. P M \<Longrightarrow> (\<And>N. P N \<Longrightarrow> Measurable.pred N A) \<Longrightarrow> Measurable.pred M (F A)"
hoelzl@59000
   611
  shows "emeasure M {x\<in>space M. lfp F x} = (SUP i. emeasure M {x\<in>space M. (F ^^ i) (\<lambda>x. False) x})"
hoelzl@59000
   612
proof -
hoelzl@59000
   613
  have "emeasure M {x\<in>space M. lfp F x} = emeasure M (\<Union>i. {x\<in>space M. (F ^^ i) (\<lambda>x. False) x})"
hoelzl@60172
   614
    using sup_continuous_lfp[OF cont] by (auto simp add: bot_fun_def intro!: arg_cong2[where f=emeasure])
wenzelm@61808
   615
  moreover { fix i from \<open>P M\<close> have "{x\<in>space M. (F ^^ i) (\<lambda>x. False) x} \<in> sets M"
hoelzl@59000
   616
    by (induct i arbitrary: M) (auto simp add: pred_def[symmetric] intro: *) }
hoelzl@59000
   617
  moreover have "incseq (\<lambda>i. {x\<in>space M. (F ^^ i) (\<lambda>x. False) x})"
hoelzl@59000
   618
  proof (rule incseq_SucI)
hoelzl@59000
   619
    fix i
hoelzl@59000
   620
    have "(F ^^ i) (\<lambda>x. False) \<le> (F ^^ (Suc i)) (\<lambda>x. False)"
hoelzl@59000
   621
    proof (induct i)
hoelzl@59000
   622
      case 0 show ?case by (simp add: le_fun_def)
hoelzl@59000
   623
    next
hoelzl@60172
   624
      case Suc thus ?case using monoD[OF sup_continuous_mono[OF cont] Suc] by auto
hoelzl@59000
   625
    qed
hoelzl@59000
   626
    then show "{x \<in> space M. (F ^^ i) (\<lambda>x. False) x} \<subseteq> {x \<in> space M. (F ^^ Suc i) (\<lambda>x. False) x}"
hoelzl@59000
   627
      by auto
hoelzl@59000
   628
  qed
hoelzl@59000
   629
  ultimately show ?thesis
hoelzl@59000
   630
    by (subst SUP_emeasure_incseq) auto
hoelzl@59000
   631
qed
hoelzl@59000
   632
hoelzl@60636
   633
lemma emeasure_lfp:
hoelzl@60636
   634
  assumes [simp]: "\<And>s. sets (M s) = sets N"
hoelzl@60636
   635
  assumes cont: "sup_continuous F" "sup_continuous f"
hoelzl@60636
   636
  assumes meas: "\<And>P. Measurable.pred N P \<Longrightarrow> Measurable.pred N (F P)"
hoelzl@60714
   637
  assumes iter: "\<And>P s. Measurable.pred N P \<Longrightarrow> P \<le> lfp F \<Longrightarrow> emeasure (M s) {x\<in>space N. F P x} = f (\<lambda>s. emeasure (M s) {x\<in>space N. P x}) s"
hoelzl@60636
   638
  shows "emeasure (M s) {x\<in>space N. lfp F x} = lfp f s"
hoelzl@60636
   639
proof (subst lfp_transfer_bounded[where \<alpha>="\<lambda>F s. emeasure (M s) {x\<in>space N. F x}" and g=f and f=F and P="Measurable.pred N", symmetric])
hoelzl@60636
   640
  fix C assume "incseq C" "\<And>i. Measurable.pred N (C i)"
hoelzl@60636
   641
  then show "(\<lambda>s. emeasure (M s) {x \<in> space N. (SUP i. C i) x}) = (SUP i. (\<lambda>s. emeasure (M s) {x \<in> space N. C i x}))"
hoelzl@60636
   642
    unfolding SUP_apply[abs_def]
hoelzl@60636
   643
    by (subst SUP_emeasure_incseq) (auto simp: mono_def fun_eq_iff intro!: arg_cong2[where f=emeasure])
hoelzl@62975
   644
qed (auto simp add: iter le_fun_def SUP_apply[abs_def] intro!: meas cont)
hoelzl@47694
   645
hoelzl@47694
   646
lemma emeasure_subadditive_finite:
hoelzl@62975
   647
  "finite I \<Longrightarrow> A ` I \<subseteq> sets M \<Longrightarrow> emeasure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. emeasure M (A i))"
hoelzl@62975
   648
  by (rule sets.subadditive[OF emeasure_positive emeasure_additive]) auto
hoelzl@62975
   649
hoelzl@62975
   650
lemma emeasure_subadditive:
hoelzl@62975
   651
  "A \<in> sets M \<Longrightarrow> B \<in> sets M \<Longrightarrow> emeasure M (A \<union> B) \<le> emeasure M A + emeasure M B"
hoelzl@62975
   652
  using emeasure_subadditive_finite[of "{True, False}" "\<lambda>True \<Rightarrow> A | False \<Rightarrow> B" M] by simp
hoelzl@47694
   653
hoelzl@47694
   654
lemma emeasure_subadditive_countably:
hoelzl@47694
   655
  assumes "range f \<subseteq> sets M"
hoelzl@47694
   656
  shows "emeasure M (\<Union>i. f i) \<le> (\<Sum>i. emeasure M (f i))"
hoelzl@47694
   657
proof -
hoelzl@47694
   658
  have "emeasure M (\<Union>i. f i) = emeasure M (\<Union>i. disjointed f i)"
hoelzl@47694
   659
    unfolding UN_disjointed_eq ..
hoelzl@47694
   660
  also have "\<dots> = (\<Sum>i. emeasure M (disjointed f i))"
immler@50244
   661
    using sets.range_disjointed_sets[OF assms] suminf_emeasure[of "disjointed f"]
hoelzl@47694
   662
    by (simp add:  disjoint_family_disjointed comp_def)
hoelzl@47694
   663
  also have "\<dots> \<le> (\<Sum>i. emeasure M (f i))"
immler@50244
   664
    using sets.range_disjointed_sets[OF assms] assms
hoelzl@62975
   665
    by (auto intro!: suminf_le emeasure_mono disjointed_subset)
hoelzl@47694
   666
  finally show ?thesis .
hoelzl@47694
   667
qed
hoelzl@47694
   668
hoelzl@47694
   669
lemma emeasure_insert:
hoelzl@47694
   670
  assumes sets: "{x} \<in> sets M" "A \<in> sets M" and "x \<notin> A"
hoelzl@47694
   671
  shows "emeasure M (insert x A) = emeasure M {x} + emeasure M A"
hoelzl@47694
   672
proof -
wenzelm@61808
   673
  have "{x} \<inter> A = {}" using \<open>x \<notin> A\<close> by auto
hoelzl@47694
   674
  from plus_emeasure[OF sets this] show ?thesis by simp
hoelzl@47694
   675
qed
hoelzl@47694
   676
hoelzl@57447
   677
lemma emeasure_insert_ne:
hoelzl@57447
   678
  "A \<noteq> {} \<Longrightarrow> {x} \<in> sets M \<Longrightarrow> A \<in> sets M \<Longrightarrow> x \<notin> A \<Longrightarrow> emeasure M (insert x A) = emeasure M {x} + emeasure M A"
lp15@61609
   679
  by (rule emeasure_insert)
hoelzl@57447
   680
hoelzl@47694
   681
lemma emeasure_eq_setsum_singleton:
hoelzl@47694
   682
  assumes "finite S" "\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M"
hoelzl@47694
   683
  shows "emeasure M S = (\<Sum>x\<in>S. emeasure M {x})"
hoelzl@47694
   684
  using setsum_emeasure[of "\<lambda>x. {x}" S M] assms
hoelzl@47694
   685
  by (auto simp: disjoint_family_on_def subset_eq)
hoelzl@47694
   686
hoelzl@47694
   687
lemma setsum_emeasure_cover:
hoelzl@47694
   688
  assumes "finite S" and "A \<in> sets M" and br_in_M: "B ` S \<subseteq> sets M"
hoelzl@47694
   689
  assumes A: "A \<subseteq> (\<Union>i\<in>S. B i)"
hoelzl@47694
   690
  assumes disj: "disjoint_family_on B S"
hoelzl@47694
   691
  shows "emeasure M A = (\<Sum>i\<in>S. emeasure M (A \<inter> (B i)))"
hoelzl@47694
   692
proof -
hoelzl@47694
   693
  have "(\<Sum>i\<in>S. emeasure M (A \<inter> (B i))) = emeasure M (\<Union>i\<in>S. A \<inter> (B i))"
hoelzl@47694
   694
  proof (rule setsum_emeasure)
hoelzl@47694
   695
    show "disjoint_family_on (\<lambda>i. A \<inter> B i) S"
wenzelm@61808
   696
      using \<open>disjoint_family_on B S\<close>
hoelzl@47694
   697
      unfolding disjoint_family_on_def by auto
hoelzl@47694
   698
  qed (insert assms, auto)
hoelzl@47694
   699
  also have "(\<Union>i\<in>S. A \<inter> (B i)) = A"
hoelzl@47694
   700
    using A by auto
hoelzl@47694
   701
  finally show ?thesis by simp
hoelzl@47694
   702
qed
hoelzl@47694
   703
hoelzl@47694
   704
lemma emeasure_eq_0:
hoelzl@47694
   705
  "N \<in> sets M \<Longrightarrow> emeasure M N = 0 \<Longrightarrow> K \<subseteq> N \<Longrightarrow> emeasure M K = 0"
hoelzl@62975
   706
  by (metis emeasure_mono order_eq_iff zero_le)
hoelzl@47694
   707
hoelzl@47694
   708
lemma emeasure_UN_eq_0:
hoelzl@47694
   709
  assumes "\<And>i::nat. emeasure M (N i) = 0" and "range N \<subseteq> sets M"
wenzelm@60585
   710
  shows "emeasure M (\<Union>i. N i) = 0"
hoelzl@47694
   711
proof -
hoelzl@62975
   712
  have "emeasure M (\<Union>i. N i) \<le> 0"
hoelzl@47694
   713
    using emeasure_subadditive_countably[OF assms(2)] assms(1) by simp
hoelzl@62975
   714
  then show ?thesis
hoelzl@62975
   715
    by (auto intro: antisym zero_le)
hoelzl@47694
   716
qed
hoelzl@47694
   717
hoelzl@47694
   718
lemma measure_eqI_finite:
hoelzl@47694
   719
  assumes [simp]: "sets M = Pow A" "sets N = Pow A" and "finite A"
hoelzl@47694
   720
  assumes eq: "\<And>a. a \<in> A \<Longrightarrow> emeasure M {a} = emeasure N {a}"
hoelzl@47694
   721
  shows "M = N"
hoelzl@47694
   722
proof (rule measure_eqI)
hoelzl@47694
   723
  fix X assume "X \<in> sets M"
hoelzl@47694
   724
  then have X: "X \<subseteq> A" by auto
hoelzl@47694
   725
  then have "emeasure M X = (\<Sum>a\<in>X. emeasure M {a})"
wenzelm@61808
   726
    using \<open>finite A\<close> by (subst emeasure_eq_setsum_singleton) (auto dest: finite_subset)
hoelzl@47694
   727
  also have "\<dots> = (\<Sum>a\<in>X. emeasure N {a})"
haftmann@57418
   728
    using X eq by (auto intro!: setsum.cong)
hoelzl@47694
   729
  also have "\<dots> = emeasure N X"
wenzelm@61808
   730
    using X \<open>finite A\<close> by (subst emeasure_eq_setsum_singleton) (auto dest: finite_subset)
hoelzl@47694
   731
  finally show "emeasure M X = emeasure N X" .
hoelzl@47694
   732
qed simp
hoelzl@47694
   733
hoelzl@47694
   734
lemma measure_eqI_generator_eq:
hoelzl@47694
   735
  fixes M N :: "'a measure" and E :: "'a set set" and A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
   736
  assumes "Int_stable E" "E \<subseteq> Pow \<Omega>"
hoelzl@47694
   737
  and eq: "\<And>X. X \<in> E \<Longrightarrow> emeasure M X = emeasure N X"
hoelzl@47694
   738
  and M: "sets M = sigma_sets \<Omega> E"
hoelzl@47694
   739
  and N: "sets N = sigma_sets \<Omega> E"
hoelzl@49784
   740
  and A: "range A \<subseteq> E" "(\<Union>i. A i) = \<Omega>" "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
hoelzl@47694
   741
  shows "M = N"
hoelzl@47694
   742
proof -
hoelzl@49773
   743
  let ?\<mu>  = "emeasure M" and ?\<nu> = "emeasure N"
hoelzl@47694
   744
  interpret S: sigma_algebra \<Omega> "sigma_sets \<Omega> E" by (rule sigma_algebra_sigma_sets) fact
hoelzl@49789
   745
  have "space M = \<Omega>"
wenzelm@61808
   746
    using sets.top[of M] sets.space_closed[of M] S.top S.space_closed \<open>sets M = sigma_sets \<Omega> E\<close>
immler@50244
   747
    by blast
hoelzl@49789
   748
hoelzl@49789
   749
  { fix F D assume "F \<in> E" and "?\<mu> F \<noteq> \<infinity>"
hoelzl@47694
   750
    then have [intro]: "F \<in> sigma_sets \<Omega> E" by auto
wenzelm@61808
   751
    have "?\<nu> F \<noteq> \<infinity>" using \<open>?\<mu> F \<noteq> \<infinity>\<close> \<open>F \<in> E\<close> eq by simp
hoelzl@49789
   752
    assume "D \<in> sets M"
wenzelm@61808
   753
    with \<open>Int_stable E\<close> \<open>E \<subseteq> Pow \<Omega>\<close> have "emeasure M (F \<inter> D) = emeasure N (F \<inter> D)"
hoelzl@49789
   754
      unfolding M
hoelzl@49789
   755
    proof (induct rule: sigma_sets_induct_disjoint)
hoelzl@49789
   756
      case (basic A)
wenzelm@61808
   757
      then have "F \<inter> A \<in> E" using \<open>Int_stable E\<close> \<open>F \<in> E\<close> by (auto simp: Int_stable_def)
hoelzl@49789
   758
      then show ?case using eq by auto
hoelzl@47694
   759
    next
hoelzl@49789
   760
      case empty then show ?case by simp
hoelzl@47694
   761
    next
hoelzl@49789
   762
      case (compl A)
hoelzl@47694
   763
      then have **: "F \<inter> (\<Omega> - A) = F - (F \<inter> A)"
hoelzl@47694
   764
        and [intro]: "F \<inter> A \<in> sigma_sets \<Omega> E"
wenzelm@61808
   765
        using \<open>F \<in> E\<close> S.sets_into_space by (auto simp: M)
hoelzl@49773
   766
      have "?\<nu> (F \<inter> A) \<le> ?\<nu> F" by (auto intro!: emeasure_mono simp: M N)
hoelzl@62975
   767
      then have "?\<nu> (F \<inter> A) \<noteq> \<infinity>" using \<open>?\<nu> F \<noteq> \<infinity>\<close> by (auto simp: top_unique)
hoelzl@49773
   768
      have "?\<mu> (F \<inter> A) \<le> ?\<mu> F" by (auto intro!: emeasure_mono simp: M N)
hoelzl@62975
   769
      then have "?\<mu> (F \<inter> A) \<noteq> \<infinity>" using \<open>?\<mu> F \<noteq> \<infinity>\<close> by (auto simp: top_unique)
hoelzl@49773
   770
      then have "?\<mu> (F \<inter> (\<Omega> - A)) = ?\<mu> F - ?\<mu> (F \<inter> A)" unfolding **
wenzelm@61808
   771
        using \<open>F \<inter> A \<in> sigma_sets \<Omega> E\<close> by (auto intro!: emeasure_Diff simp: M N)
wenzelm@61808
   772
      also have "\<dots> = ?\<nu> F - ?\<nu> (F \<inter> A)" using eq \<open>F \<in> E\<close> compl by simp
hoelzl@49773
   773
      also have "\<dots> = ?\<nu> (F \<inter> (\<Omega> - A))" unfolding **
wenzelm@61808
   774
        using \<open>F \<inter> A \<in> sigma_sets \<Omega> E\<close> \<open>?\<nu> (F \<inter> A) \<noteq> \<infinity>\<close>
hoelzl@47694
   775
        by (auto intro!: emeasure_Diff[symmetric] simp: M N)
hoelzl@49789
   776
      finally show ?case
wenzelm@61808
   777
        using \<open>space M = \<Omega>\<close> by auto
hoelzl@47694
   778
    next
hoelzl@49789
   779
      case (union A)
hoelzl@49773
   780
      then have "?\<mu> (\<Union>x. F \<inter> A x) = ?\<nu> (\<Union>x. F \<inter> A x)"
hoelzl@49773
   781
        by (subst (1 2) suminf_emeasure[symmetric]) (auto simp: disjoint_family_on_def subset_eq M N)
hoelzl@49789
   782
      with A show ?case
hoelzl@49773
   783
        by auto
hoelzl@49789
   784
    qed }
hoelzl@47694
   785
  note * = this
hoelzl@47694
   786
  show "M = N"
hoelzl@47694
   787
  proof (rule measure_eqI)
hoelzl@47694
   788
    show "sets M = sets N"
hoelzl@47694
   789
      using M N by simp
hoelzl@49784
   790
    have [simp, intro]: "\<And>i. A i \<in> sets M"
hoelzl@49784
   791
      using A(1) by (auto simp: subset_eq M)
hoelzl@49773
   792
    fix F assume "F \<in> sets M"
hoelzl@49784
   793
    let ?D = "disjointed (\<lambda>i. F \<inter> A i)"
wenzelm@61808
   794
    from \<open>space M = \<Omega>\<close> have F_eq: "F = (\<Union>i. ?D i)"
wenzelm@61808
   795
      using \<open>F \<in> sets M\<close>[THEN sets.sets_into_space] A(2)[symmetric] by (auto simp: UN_disjointed_eq)
hoelzl@49784
   796
    have [simp, intro]: "\<And>i. ?D i \<in> sets M"
wenzelm@61808
   797
      using sets.range_disjointed_sets[of "\<lambda>i. F \<inter> A i" M] \<open>F \<in> sets M\<close>
hoelzl@49784
   798
      by (auto simp: subset_eq)
hoelzl@49784
   799
    have "disjoint_family ?D"
hoelzl@49784
   800
      by (auto simp: disjoint_family_disjointed)
hoelzl@50002
   801
    moreover
hoelzl@50002
   802
    have "(\<Sum>i. emeasure M (?D i)) = (\<Sum>i. emeasure N (?D i))"
hoelzl@50002
   803
    proof (intro arg_cong[where f=suminf] ext)
hoelzl@50002
   804
      fix i
hoelzl@49784
   805
      have "A i \<inter> ?D i = ?D i"
hoelzl@49784
   806
        by (auto simp: disjointed_def)
hoelzl@50002
   807
      then show "emeasure M (?D i) = emeasure N (?D i)"
hoelzl@50002
   808
        using *[of "A i" "?D i", OF _ A(3)] A(1) by auto
hoelzl@50002
   809
    qed
hoelzl@50002
   810
    ultimately show "emeasure M F = emeasure N F"
wenzelm@61808
   811
      by (simp add: image_subset_iff \<open>sets M = sets N\<close>[symmetric] F_eq[symmetric] suminf_emeasure)
hoelzl@47694
   812
  qed
hoelzl@47694
   813
qed
hoelzl@47694
   814
hoelzl@47694
   815
lemma measure_of_of_measure: "measure_of (space M) (sets M) (emeasure M) = M"
hoelzl@47694
   816
proof (intro measure_eqI emeasure_measure_of_sigma)
hoelzl@47694
   817
  show "sigma_algebra (space M) (sets M)" ..
hoelzl@47694
   818
  show "positive (sets M) (emeasure M)"
hoelzl@62975
   819
    by (simp add: positive_def)
hoelzl@47694
   820
  show "countably_additive (sets M) (emeasure M)"
hoelzl@47694
   821
    by (simp add: emeasure_countably_additive)
hoelzl@47694
   822
qed simp_all
hoelzl@47694
   823
wenzelm@61808
   824
subsection \<open>\<open>\<mu>\<close>-null sets\<close>
hoelzl@47694
   825
hoelzl@47694
   826
definition null_sets :: "'a measure \<Rightarrow> 'a set set" where
hoelzl@47694
   827
  "null_sets M = {N\<in>sets M. emeasure M N = 0}"
hoelzl@47694
   828
hoelzl@47694
   829
lemma null_setsD1[dest]: "A \<in> null_sets M \<Longrightarrow> emeasure M A = 0"
hoelzl@47694
   830
  by (simp add: null_sets_def)
hoelzl@47694
   831
hoelzl@47694
   832
lemma null_setsD2[dest]: "A \<in> null_sets M \<Longrightarrow> A \<in> sets M"
hoelzl@47694
   833
  unfolding null_sets_def by simp
hoelzl@47694
   834
hoelzl@47694
   835
lemma null_setsI[intro]: "emeasure M A = 0 \<Longrightarrow> A \<in> sets M \<Longrightarrow> A \<in> null_sets M"
hoelzl@47694
   836
  unfolding null_sets_def by simp
hoelzl@47694
   837
hoelzl@47694
   838
interpretation null_sets: ring_of_sets "space M" "null_sets M" for M
hoelzl@47762
   839
proof (rule ring_of_setsI)
hoelzl@47694
   840
  show "null_sets M \<subseteq> Pow (space M)"
immler@50244
   841
    using sets.sets_into_space by auto
hoelzl@47694
   842
  show "{} \<in> null_sets M"
hoelzl@47694
   843
    by auto
wenzelm@53374
   844
  fix A B assume null_sets: "A \<in> null_sets M" "B \<in> null_sets M"
wenzelm@53374
   845
  then have sets: "A \<in> sets M" "B \<in> sets M"
hoelzl@47694
   846
    by auto
wenzelm@53374
   847
  then have *: "emeasure M (A \<union> B) \<le> emeasure M A + emeasure M B"
hoelzl@47694
   848
    "emeasure M (A - B) \<le> emeasure M A"
hoelzl@47694
   849
    by (auto intro!: emeasure_subadditive emeasure_mono)
wenzelm@53374
   850
  then have "emeasure M B = 0" "emeasure M A = 0"
wenzelm@53374
   851
    using null_sets by auto
wenzelm@53374
   852
  with sets * show "A - B \<in> null_sets M" "A \<union> B \<in> null_sets M"
hoelzl@62975
   853
    by (auto intro!: antisym zero_le)
hoelzl@47694
   854
qed
hoelzl@47694
   855
lp15@61609
   856
lemma UN_from_nat_into:
hoelzl@57275
   857
  assumes I: "countable I" "I \<noteq> {}"
hoelzl@57275
   858
  shows "(\<Union>i\<in>I. N i) = (\<Union>i. N (from_nat_into I i))"
hoelzl@47694
   859
proof -
hoelzl@57275
   860
  have "(\<Union>i\<in>I. N i) = \<Union>(N ` range (from_nat_into I))"
hoelzl@57275
   861
    using I by simp
hoelzl@57275
   862
  also have "\<dots> = (\<Union>i. (N \<circ> from_nat_into I) i)"
haftmann@62343
   863
    by simp
hoelzl@57275
   864
  finally show ?thesis by simp
hoelzl@57275
   865
qed
hoelzl@57275
   866
hoelzl@57275
   867
lemma null_sets_UN':
hoelzl@57275
   868
  assumes "countable I"
hoelzl@57275
   869
  assumes "\<And>i. i \<in> I \<Longrightarrow> N i \<in> null_sets M"
hoelzl@57275
   870
  shows "(\<Union>i\<in>I. N i) \<in> null_sets M"
hoelzl@57275
   871
proof cases
hoelzl@57275
   872
  assume "I = {}" then show ?thesis by simp
hoelzl@57275
   873
next
hoelzl@57275
   874
  assume "I \<noteq> {}"
hoelzl@57275
   875
  show ?thesis
hoelzl@57275
   876
  proof (intro conjI CollectI null_setsI)
hoelzl@57275
   877
    show "(\<Union>i\<in>I. N i) \<in> sets M"
hoelzl@57275
   878
      using assms by (intro sets.countable_UN') auto
hoelzl@57275
   879
    have "emeasure M (\<Union>i\<in>I. N i) \<le> (\<Sum>n. emeasure M (N (from_nat_into I n)))"
wenzelm@61808
   880
      unfolding UN_from_nat_into[OF \<open>countable I\<close> \<open>I \<noteq> {}\<close>]
wenzelm@61808
   881
      using assms \<open>I \<noteq> {}\<close> by (intro emeasure_subadditive_countably) (auto intro: from_nat_into)
hoelzl@57275
   882
    also have "(\<lambda>n. emeasure M (N (from_nat_into I n))) = (\<lambda>_. 0)"
wenzelm@61808
   883
      using assms \<open>I \<noteq> {}\<close> by (auto intro: from_nat_into)
hoelzl@57275
   884
    finally show "emeasure M (\<Union>i\<in>I. N i) = 0"
hoelzl@62975
   885
      by (intro antisym zero_le) simp
hoelzl@57275
   886
  qed
hoelzl@47694
   887
qed
hoelzl@47694
   888
hoelzl@47694
   889
lemma null_sets_UN[intro]:
hoelzl@57275
   890
  "(\<And>i::'i::countable. N i \<in> null_sets M) \<Longrightarrow> (\<Union>i. N i) \<in> null_sets M"
hoelzl@57275
   891
  by (rule null_sets_UN') auto
hoelzl@47694
   892
hoelzl@47694
   893
lemma null_set_Int1:
hoelzl@47694
   894
  assumes "B \<in> null_sets M" "A \<in> sets M" shows "A \<inter> B \<in> null_sets M"
hoelzl@47694
   895
proof (intro CollectI conjI null_setsI)
hoelzl@47694
   896
  show "emeasure M (A \<inter> B) = 0" using assms
hoelzl@47694
   897
    by (intro emeasure_eq_0[of B _ "A \<inter> B"]) auto
hoelzl@47694
   898
qed (insert assms, auto)
hoelzl@47694
   899
hoelzl@47694
   900
lemma null_set_Int2:
hoelzl@47694
   901
  assumes "B \<in> null_sets M" "A \<in> sets M" shows "B \<inter> A \<in> null_sets M"
hoelzl@47694
   902
  using assms by (subst Int_commute) (rule null_set_Int1)
hoelzl@47694
   903
hoelzl@47694
   904
lemma emeasure_Diff_null_set:
hoelzl@47694
   905
  assumes "B \<in> null_sets M" "A \<in> sets M"
hoelzl@47694
   906
  shows "emeasure M (A - B) = emeasure M A"
hoelzl@47694
   907
proof -
hoelzl@47694
   908
  have *: "A - B = (A - (A \<inter> B))" by auto
hoelzl@47694
   909
  have "A \<inter> B \<in> null_sets M" using assms by (rule null_set_Int1)
hoelzl@47694
   910
  then show ?thesis
hoelzl@47694
   911
    unfolding * using assms
hoelzl@47694
   912
    by (subst emeasure_Diff) auto
hoelzl@47694
   913
qed
hoelzl@47694
   914
hoelzl@47694
   915
lemma null_set_Diff:
hoelzl@47694
   916
  assumes "B \<in> null_sets M" "A \<in> sets M" shows "B - A \<in> null_sets M"
hoelzl@47694
   917
proof (intro CollectI conjI null_setsI)
hoelzl@47694
   918
  show "emeasure M (B - A) = 0" using assms by (intro emeasure_eq_0[of B _ "B - A"]) auto
hoelzl@47694
   919
qed (insert assms, auto)
hoelzl@47694
   920
hoelzl@47694
   921
lemma emeasure_Un_null_set:
hoelzl@47694
   922
  assumes "A \<in> sets M" "B \<in> null_sets M"
hoelzl@47694
   923
  shows "emeasure M (A \<union> B) = emeasure M A"
hoelzl@47694
   924
proof -
hoelzl@47694
   925
  have *: "A \<union> B = A \<union> (B - A)" by auto
hoelzl@47694
   926
  have "B - A \<in> null_sets M" using assms(2,1) by (rule null_set_Diff)
hoelzl@47694
   927
  then show ?thesis
hoelzl@47694
   928
    unfolding * using assms
hoelzl@47694
   929
    by (subst plus_emeasure[symmetric]) auto
hoelzl@47694
   930
qed
hoelzl@47694
   931
wenzelm@61808
   932
subsection \<open>The almost everywhere filter (i.e.\ quantifier)\<close>
hoelzl@47694
   933
hoelzl@47694
   934
definition ae_filter :: "'a measure \<Rightarrow> 'a filter" where
hoelzl@57276
   935
  "ae_filter M = (INF N:null_sets M. principal (space M - N))"
hoelzl@47694
   936
hoelzl@57276
   937
abbreviation almost_everywhere :: "'a measure \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
hoelzl@47694
   938
  "almost_everywhere M P \<equiv> eventually P (ae_filter M)"
hoelzl@47694
   939
hoelzl@47694
   940
syntax
hoelzl@47694
   941
  "_almost_everywhere" :: "pttrn \<Rightarrow> 'a \<Rightarrow> bool \<Rightarrow> bool" ("AE _ in _. _" [0,0,10] 10)
hoelzl@47694
   942
hoelzl@47694
   943
translations
hoelzl@62975
   944
  "AE x in M. P" \<rightleftharpoons> "CONST almost_everywhere M (\<lambda>x. P)"
hoelzl@47694
   945
hoelzl@57276
   946
lemma eventually_ae_filter: "eventually P (ae_filter M) \<longleftrightarrow> (\<exists>N\<in>null_sets M. {x \<in> space M. \<not> P x} \<subseteq> N)"
hoelzl@57276
   947
  unfolding ae_filter_def by (subst eventually_INF_base) (auto simp: eventually_principal subset_eq)
hoelzl@47694
   948
hoelzl@47694
   949
lemma AE_I':
hoelzl@47694
   950
  "N \<in> null_sets M \<Longrightarrow> {x\<in>space M. \<not> P x} \<subseteq> N \<Longrightarrow> (AE x in M. P x)"
hoelzl@47694
   951
  unfolding eventually_ae_filter by auto
hoelzl@47694
   952
hoelzl@47694
   953
lemma AE_iff_null:
hoelzl@47694
   954
  assumes "{x\<in>space M. \<not> P x} \<in> sets M" (is "?P \<in> sets M")
hoelzl@47694
   955
  shows "(AE x in M. P x) \<longleftrightarrow> {x\<in>space M. \<not> P x} \<in> null_sets M"
hoelzl@47694
   956
proof
hoelzl@47694
   957
  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
   958
    unfolding eventually_ae_filter by auto
hoelzl@62975
   959
  have "emeasure M ?P \<le> emeasure M N"
hoelzl@47694
   960
    using assms N(1,2) by (auto intro: emeasure_mono)
hoelzl@62975
   961
  then have "emeasure M ?P = 0"
hoelzl@62975
   962
    unfolding \<open>emeasure M N = 0\<close> by auto
hoelzl@47694
   963
  then show "?P \<in> null_sets M" using assms by auto
hoelzl@47694
   964
next
hoelzl@47694
   965
  assume "?P \<in> null_sets M" with assms show "AE x in M. P x" by (auto intro: AE_I')
hoelzl@47694
   966
qed
hoelzl@47694
   967
hoelzl@47694
   968
lemma AE_iff_null_sets:
hoelzl@47694
   969
  "N \<in> sets M \<Longrightarrow> N \<in> null_sets M \<longleftrightarrow> (AE x in M. x \<notin> N)"
immler@50244
   970
  using Int_absorb1[OF sets.sets_into_space, of N M]
hoelzl@47694
   971
  by (subst AE_iff_null) (auto simp: Int_def[symmetric])
hoelzl@47694
   972
hoelzl@47761
   973
lemma AE_not_in:
hoelzl@47761
   974
  "N \<in> null_sets M \<Longrightarrow> AE x in M. x \<notin> N"
hoelzl@47761
   975
  by (metis AE_iff_null_sets null_setsD2)
hoelzl@47761
   976
hoelzl@47694
   977
lemma AE_iff_measurable:
hoelzl@47694
   978
  "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
   979
  using AE_iff_null[of _ P] by auto
hoelzl@47694
   980
hoelzl@47694
   981
lemma AE_E[consumes 1]:
hoelzl@47694
   982
  assumes "AE x in M. P x"
hoelzl@47694
   983
  obtains N where "{x \<in> space M. \<not> P x} \<subseteq> N" "emeasure M N = 0" "N \<in> sets M"
hoelzl@47694
   984
  using assms unfolding eventually_ae_filter by auto
hoelzl@47694
   985
hoelzl@47694
   986
lemma AE_E2:
hoelzl@47694
   987
  assumes "AE x in M. P x" "{x\<in>space M. P x} \<in> sets M"
hoelzl@47694
   988
  shows "emeasure M {x\<in>space M. \<not> P x} = 0" (is "emeasure M ?P = 0")
hoelzl@47694
   989
proof -
hoelzl@47694
   990
  have "{x\<in>space M. \<not> P x} = space M - {x\<in>space M. P x}" by auto
hoelzl@47694
   991
  with AE_iff_null[of M P] assms show ?thesis by auto
hoelzl@47694
   992
qed
hoelzl@47694
   993
hoelzl@47694
   994
lemma AE_I:
hoelzl@47694
   995
  assumes "{x \<in> space M. \<not> P x} \<subseteq> N" "emeasure M N = 0" "N \<in> sets M"
hoelzl@47694
   996
  shows "AE x in M. P x"
hoelzl@47694
   997
  using assms unfolding eventually_ae_filter by auto
hoelzl@47694
   998
hoelzl@47694
   999
lemma AE_mp[elim!]:
hoelzl@47694
  1000
  assumes AE_P: "AE x in M. P x" and AE_imp: "AE x in M. P x \<longrightarrow> Q x"
hoelzl@47694
  1001
  shows "AE x in M. Q x"
hoelzl@47694
  1002
proof -
hoelzl@47694
  1003
  from AE_P obtain A where P: "{x\<in>space M. \<not> P x} \<subseteq> A"
hoelzl@47694
  1004
    and A: "A \<in> sets M" "emeasure M A = 0"
hoelzl@47694
  1005
    by (auto elim!: AE_E)
hoelzl@47694
  1006
hoelzl@47694
  1007
  from AE_imp obtain B where imp: "{x\<in>space M. P x \<and> \<not> Q x} \<subseteq> B"
hoelzl@47694
  1008
    and B: "B \<in> sets M" "emeasure M B = 0"
hoelzl@47694
  1009
    by (auto elim!: AE_E)
hoelzl@47694
  1010
hoelzl@47694
  1011
  show ?thesis
hoelzl@47694
  1012
  proof (intro AE_I)
hoelzl@62975
  1013
    have "emeasure M (A \<union> B) \<le> 0"
hoelzl@47694
  1014
      using emeasure_subadditive[of A M B] A B by auto
hoelzl@62975
  1015
    then show "A \<union> B \<in> sets M" "emeasure M (A \<union> B) = 0"
hoelzl@62975
  1016
      using A B by auto
hoelzl@47694
  1017
    show "{x\<in>space M. \<not> Q x} \<subseteq> A \<union> B"
hoelzl@47694
  1018
      using P imp by auto
hoelzl@47694
  1019
  qed
hoelzl@47694
  1020
qed
hoelzl@47694
  1021
hoelzl@47694
  1022
(* depricated replace by laws about eventually *)
hoelzl@47694
  1023
lemma
hoelzl@47694
  1024
  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
  1025
    and AE_disjI1: "AE x in M. P x \<Longrightarrow> AE x in M. P x \<or> Q x"
hoelzl@47694
  1026
    and AE_disjI2: "AE x in M. Q x \<Longrightarrow> AE x in M. P x \<or> Q x"
hoelzl@47694
  1027
    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
  1028
    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
  1029
  by auto
hoelzl@47694
  1030
hoelzl@47694
  1031
lemma AE_impI:
hoelzl@47694
  1032
  "(P \<Longrightarrow> AE x in M. Q x) \<Longrightarrow> AE x in M. P \<longrightarrow> Q x"
hoelzl@47694
  1033
  by (cases P) auto
hoelzl@47694
  1034
hoelzl@47694
  1035
lemma AE_measure:
hoelzl@47694
  1036
  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
  1037
  shows "emeasure M {x\<in>space M. P x} = emeasure M (space M)"
hoelzl@47694
  1038
proof -
hoelzl@47694
  1039
  from AE_E[OF AE] guess N . note N = this
hoelzl@47694
  1040
  with sets have "emeasure M (space M) \<le> emeasure M (?P \<union> N)"
hoelzl@47694
  1041
    by (intro emeasure_mono) auto
hoelzl@47694
  1042
  also have "\<dots> \<le> emeasure M ?P + emeasure M N"
hoelzl@47694
  1043
    using sets N by (intro emeasure_subadditive) auto
hoelzl@47694
  1044
  also have "\<dots> = emeasure M ?P" using N by simp
hoelzl@47694
  1045
  finally show "emeasure M ?P = emeasure M (space M)"
hoelzl@47694
  1046
    using emeasure_space[of M "?P"] by auto
hoelzl@47694
  1047
qed
hoelzl@47694
  1048
hoelzl@47694
  1049
lemma AE_space: "AE x in M. x \<in> space M"
hoelzl@47694
  1050
  by (rule AE_I[where N="{}"]) auto
hoelzl@47694
  1051
hoelzl@47694
  1052
lemma AE_I2[simp, intro]:
hoelzl@47694
  1053
  "(\<And>x. x \<in> space M \<Longrightarrow> P x) \<Longrightarrow> AE x in M. P x"
hoelzl@47694
  1054
  using AE_space by force
hoelzl@47694
  1055
hoelzl@47694
  1056
lemma AE_Ball_mp:
hoelzl@47694
  1057
  "\<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
  1058
  by auto
hoelzl@47694
  1059
hoelzl@47694
  1060
lemma AE_cong[cong]:
hoelzl@47694
  1061
  "(\<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
  1062
  by auto
hoelzl@47694
  1063
hoelzl@47694
  1064
lemma AE_all_countable:
hoelzl@47694
  1065
  "(AE x in M. \<forall>i. P i x) \<longleftrightarrow> (\<forall>i::'i::countable. AE x in M. P i x)"
hoelzl@47694
  1066
proof
hoelzl@47694
  1067
  assume "\<forall>i. AE x in M. P i x"
hoelzl@47694
  1068
  from this[unfolded eventually_ae_filter Bex_def, THEN choice]
hoelzl@47694
  1069
  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
  1070
  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
  1071
  also have "\<dots> \<subseteq> (\<Union>i. N i)" using N by auto
hoelzl@47694
  1072
  finally have "{x\<in>space M. \<not> (\<forall>i. P i x)} \<subseteq> (\<Union>i. N i)" .
hoelzl@47694
  1073
  moreover from N have "(\<Union>i. N i) \<in> null_sets M"
hoelzl@47694
  1074
    by (intro null_sets_UN) auto
hoelzl@47694
  1075
  ultimately show "AE x in M. \<forall>i. P i x"
hoelzl@47694
  1076
    unfolding eventually_ae_filter by auto
hoelzl@47694
  1077
qed auto
hoelzl@47694
  1078
lp15@61609
  1079
lemma AE_ball_countable:
hoelzl@59000
  1080
  assumes [intro]: "countable X"
hoelzl@59000
  1081
  shows "(AE x in M. \<forall>y\<in>X. P x y) \<longleftrightarrow> (\<forall>y\<in>X. AE x in M. P x y)"
hoelzl@59000
  1082
proof
hoelzl@59000
  1083
  assume "\<forall>y\<in>X. AE x in M. P x y"
hoelzl@59000
  1084
  from this[unfolded eventually_ae_filter Bex_def, THEN bchoice]
hoelzl@59000
  1085
  obtain N where N: "\<And>y. y \<in> X \<Longrightarrow> N y \<in> null_sets M" "\<And>y. y \<in> X \<Longrightarrow> {x\<in>space M. \<not> P x y} \<subseteq> N y"
hoelzl@59000
  1086
    by auto
hoelzl@59000
  1087
  have "{x\<in>space M. \<not> (\<forall>y\<in>X. P x y)} \<subseteq> (\<Union>y\<in>X. {x\<in>space M. \<not> P x y})"
hoelzl@59000
  1088
    by auto
hoelzl@59000
  1089
  also have "\<dots> \<subseteq> (\<Union>y\<in>X. N y)"
hoelzl@59000
  1090
    using N by auto
hoelzl@59000
  1091
  finally have "{x\<in>space M. \<not> (\<forall>y\<in>X. P x y)} \<subseteq> (\<Union>y\<in>X. N y)" .
hoelzl@59000
  1092
  moreover from N have "(\<Union>y\<in>X. N y) \<in> null_sets M"
hoelzl@59000
  1093
    by (intro null_sets_UN') auto
hoelzl@59000
  1094
  ultimately show "AE x in M. \<forall>y\<in>X. P x y"
hoelzl@59000
  1095
    unfolding eventually_ae_filter by auto
hoelzl@59000
  1096
qed auto
hoelzl@59000
  1097
hoelzl@57275
  1098
lemma AE_discrete_difference:
hoelzl@57275
  1099
  assumes X: "countable X"
lp15@61609
  1100
  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
hoelzl@57275
  1101
  assumes sets: "\<And>x. x \<in> X \<Longrightarrow> {x} \<in> sets M"
hoelzl@57275
  1102
  shows "AE x in M. x \<notin> X"
hoelzl@57275
  1103
proof -
hoelzl@57275
  1104
  have "(\<Union>x\<in>X. {x}) \<in> null_sets M"
hoelzl@57275
  1105
    using assms by (intro null_sets_UN') auto
hoelzl@57275
  1106
  from AE_not_in[OF this] show "AE x in M. x \<notin> X"
hoelzl@57275
  1107
    by auto
hoelzl@57275
  1108
qed
hoelzl@57275
  1109
hoelzl@47694
  1110
lemma AE_finite_all:
hoelzl@47694
  1111
  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
  1112
  using f by induct auto
hoelzl@47694
  1113
hoelzl@47694
  1114
lemma AE_finite_allI:
hoelzl@47694
  1115
  assumes "finite S"
hoelzl@47694
  1116
  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"
wenzelm@61808
  1117
  using AE_finite_all[OF \<open>finite S\<close>] by auto
hoelzl@47694
  1118
hoelzl@47694
  1119
lemma emeasure_mono_AE:
hoelzl@47694
  1120
  assumes imp: "AE x in M. x \<in> A \<longrightarrow> x \<in> B"
hoelzl@47694
  1121
    and B: "B \<in> sets M"
hoelzl@47694
  1122
  shows "emeasure M A \<le> emeasure M B"
hoelzl@47694
  1123
proof cases
hoelzl@47694
  1124
  assume A: "A \<in> sets M"
hoelzl@47694
  1125
  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
  1126
    by (auto simp: eventually_ae_filter)
hoelzl@47694
  1127
  have "emeasure M A = emeasure M (A - N)"
hoelzl@47694
  1128
    using N A by (subst emeasure_Diff_null_set) auto
hoelzl@47694
  1129
  also have "emeasure M (A - N) \<le> emeasure M (B - N)"
immler@50244
  1130
    using N A B sets.sets_into_space by (auto intro!: emeasure_mono)
hoelzl@47694
  1131
  also have "emeasure M (B - N) = emeasure M B"
hoelzl@47694
  1132
    using N B by (subst emeasure_Diff_null_set) auto
hoelzl@47694
  1133
  finally show ?thesis .
hoelzl@62975
  1134
qed (simp add: emeasure_notin_sets)
hoelzl@47694
  1135
hoelzl@47694
  1136
lemma emeasure_eq_AE:
hoelzl@47694
  1137
  assumes iff: "AE x in M. x \<in> A \<longleftrightarrow> x \<in> B"
hoelzl@47694
  1138
  assumes A: "A \<in> sets M" and B: "B \<in> sets M"
hoelzl@47694
  1139
  shows "emeasure M A = emeasure M B"
hoelzl@47694
  1140
  using assms by (safe intro!: antisym emeasure_mono_AE) auto
hoelzl@47694
  1141
hoelzl@59000
  1142
lemma emeasure_Collect_eq_AE:
hoelzl@59000
  1143
  "AE x in M. P x \<longleftrightarrow> Q x \<Longrightarrow> Measurable.pred M Q \<Longrightarrow> Measurable.pred M P \<Longrightarrow>
hoelzl@59000
  1144
   emeasure M {x\<in>space M. P x} = emeasure M {x\<in>space M. Q x}"
hoelzl@59000
  1145
   by (intro emeasure_eq_AE) auto
hoelzl@59000
  1146
hoelzl@59000
  1147
lemma emeasure_eq_0_AE: "AE x in M. \<not> P x \<Longrightarrow> emeasure M {x\<in>space M. P x} = 0"
hoelzl@59000
  1148
  using AE_iff_measurable[OF _ refl, of M "\<lambda>x. \<not> P x"]
hoelzl@59000
  1149
  by (cases "{x\<in>space M. P x} \<in> sets M") (simp_all add: emeasure_notin_sets)
hoelzl@59000
  1150
hoelzl@60715
  1151
lemma emeasure_add_AE:
hoelzl@60715
  1152
  assumes [measurable]: "A \<in> sets M" "B \<in> sets M" "C \<in> sets M"
hoelzl@60715
  1153
  assumes 1: "AE x in M. x \<in> C \<longleftrightarrow> x \<in> A \<or> x \<in> B"
hoelzl@60715
  1154
  assumes 2: "AE x in M. \<not> (x \<in> A \<and> x \<in> B)"
hoelzl@60715
  1155
  shows "emeasure M C = emeasure M A + emeasure M B"
hoelzl@60715
  1156
proof -
hoelzl@60715
  1157
  have "emeasure M C = emeasure M (A \<union> B)"
hoelzl@60715
  1158
    by (rule emeasure_eq_AE) (insert 1, auto)
hoelzl@60715
  1159
  also have "\<dots> = emeasure M A + emeasure M (B - A)"
hoelzl@60715
  1160
    by (subst plus_emeasure) auto
hoelzl@60715
  1161
  also have "emeasure M (B - A) = emeasure M B"
hoelzl@60715
  1162
    by (rule emeasure_eq_AE) (insert 2, auto)
hoelzl@60715
  1163
  finally show ?thesis .
hoelzl@60715
  1164
qed
hoelzl@60715
  1165
wenzelm@61808
  1166
subsection \<open>\<open>\<sigma>\<close>-finite Measures\<close>
hoelzl@47694
  1167
hoelzl@47694
  1168
locale sigma_finite_measure =
hoelzl@47694
  1169
  fixes M :: "'a measure"
hoelzl@57447
  1170
  assumes sigma_finite_countable:
hoelzl@57447
  1171
    "\<exists>A::'a set set. countable A \<and> A \<subseteq> sets M \<and> (\<Union>A) = space M \<and> (\<forall>a\<in>A. emeasure M a \<noteq> \<infinity>)"
hoelzl@57447
  1172
hoelzl@57447
  1173
lemma (in sigma_finite_measure) sigma_finite:
hoelzl@57447
  1174
  obtains A :: "nat \<Rightarrow> 'a set"
hoelzl@57447
  1175
  where "range A \<subseteq> sets M" "(\<Union>i. A i) = space M" "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
hoelzl@57447
  1176
proof -
hoelzl@57447
  1177
  obtain A :: "'a set set" where
hoelzl@57447
  1178
    [simp]: "countable A" and
hoelzl@57447
  1179
    A: "A \<subseteq> sets M" "(\<Union>A) = space M" "\<And>a. a \<in> A \<Longrightarrow> emeasure M a \<noteq> \<infinity>"
hoelzl@57447
  1180
    using sigma_finite_countable by metis
hoelzl@57447
  1181
  show thesis
hoelzl@57447
  1182
  proof cases
wenzelm@61808
  1183
    assume "A = {}" with \<open>(\<Union>A) = space M\<close> show thesis
hoelzl@57447
  1184
      by (intro that[of "\<lambda>_. {}"]) auto
hoelzl@57447
  1185
  next
lp15@61609
  1186
    assume "A \<noteq> {}"
hoelzl@57447
  1187
    show thesis
hoelzl@57447
  1188
    proof
hoelzl@57447
  1189
      show "range (from_nat_into A) \<subseteq> sets M"
wenzelm@61808
  1190
        using \<open>A \<noteq> {}\<close> A by auto
hoelzl@57447
  1191
      have "(\<Union>i. from_nat_into A i) = \<Union>A"
wenzelm@61808
  1192
        using range_from_nat_into[OF \<open>A \<noteq> {}\<close> \<open>countable A\<close>] by auto
hoelzl@57447
  1193
      with A show "(\<Union>i. from_nat_into A i) = space M"
hoelzl@57447
  1194
        by auto
wenzelm@61808
  1195
    qed (intro A from_nat_into \<open>A \<noteq> {}\<close>)
hoelzl@57447
  1196
  qed
hoelzl@57447
  1197
qed
hoelzl@47694
  1198
hoelzl@47694
  1199
lemma (in sigma_finite_measure) sigma_finite_disjoint:
hoelzl@47694
  1200
  obtains A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
  1201
  where "range A \<subseteq> sets M" "(\<Union>i. A i) = space M" "\<And>i. emeasure M (A i) \<noteq> \<infinity>" "disjoint_family A"
wenzelm@60580
  1202
proof -
hoelzl@47694
  1203
  obtain A :: "nat \<Rightarrow> 'a set" where
hoelzl@47694
  1204
    range: "range A \<subseteq> sets M" and
hoelzl@47694
  1205
    space: "(\<Union>i. A i) = space M" and
hoelzl@47694
  1206
    measure: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
haftmann@62343
  1207
    using sigma_finite by blast
wenzelm@60580
  1208
  show thesis
wenzelm@60580
  1209
  proof (rule that[of "disjointed A"])
wenzelm@60580
  1210
    show "range (disjointed A) \<subseteq> sets M"
wenzelm@60580
  1211
      by (rule sets.range_disjointed_sets[OF range])
wenzelm@60580
  1212
    show "(\<Union>i. disjointed A i) = space M"
wenzelm@60580
  1213
      and "disjoint_family (disjointed A)"
wenzelm@60580
  1214
      using disjoint_family_disjointed UN_disjointed_eq[of A] space range
wenzelm@60580
  1215
      by auto
wenzelm@60580
  1216
    show "emeasure M (disjointed A i) \<noteq> \<infinity>" for i
wenzelm@60580
  1217
    proof -
wenzelm@60580
  1218
      have "emeasure M (disjointed A i) \<le> emeasure M (A i)"
wenzelm@60580
  1219
        using range disjointed_subset[of A i] by (auto intro!: emeasure_mono)
hoelzl@62975
  1220
      then show ?thesis using measure[of i] by (auto simp: top_unique)
wenzelm@60580
  1221
    qed
wenzelm@60580
  1222
  qed
hoelzl@47694
  1223
qed
hoelzl@47694
  1224
hoelzl@47694
  1225
lemma (in sigma_finite_measure) sigma_finite_incseq:
hoelzl@47694
  1226
  obtains A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
  1227
  where "range A \<subseteq> sets M" "(\<Union>i. A i) = space M" "\<And>i. emeasure M (A i) \<noteq> \<infinity>" "incseq A"
wenzelm@60580
  1228
proof -
hoelzl@47694
  1229
  obtain F :: "nat \<Rightarrow> 'a set" where
hoelzl@47694
  1230
    F: "range F \<subseteq> sets M" "(\<Union>i. F i) = space M" "\<And>i. emeasure M (F i) \<noteq> \<infinity>"
haftmann@62343
  1231
    using sigma_finite by blast
wenzelm@60580
  1232
  show thesis
wenzelm@60580
  1233
  proof (rule that[of "\<lambda>n. \<Union>i\<le>n. F i"])
wenzelm@60580
  1234
    show "range (\<lambda>n. \<Union>i\<le>n. F i) \<subseteq> sets M"
wenzelm@60580
  1235
      using F by (force simp: incseq_def)
wenzelm@60580
  1236
    show "(\<Union>n. \<Union>i\<le>n. F i) = space M"
wenzelm@60580
  1237
    proof -
wenzelm@60580
  1238
      from F have "\<And>x. x \<in> space M \<Longrightarrow> \<exists>i. x \<in> F i" by auto
wenzelm@60580
  1239
      with F show ?thesis by fastforce
wenzelm@60580
  1240
    qed
wenzelm@60585
  1241
    show "emeasure M (\<Union>i\<le>n. F i) \<noteq> \<infinity>" for n
wenzelm@60580
  1242
    proof -
wenzelm@60585
  1243
      have "emeasure M (\<Union>i\<le>n. F i) \<le> (\<Sum>i\<le>n. emeasure M (F i))"
wenzelm@60580
  1244
        using F by (auto intro!: emeasure_subadditive_finite)
wenzelm@60580
  1245
      also have "\<dots> < \<infinity>"
hoelzl@62975
  1246
        using F by (auto simp: setsum_Pinfty less_top)
wenzelm@60580
  1247
      finally show ?thesis by simp
wenzelm@60580
  1248
    qed
wenzelm@60580
  1249
    show "incseq (\<lambda>n. \<Union>i\<le>n. F i)"
wenzelm@60580
  1250
      by (force simp: incseq_def)
wenzelm@60580
  1251
  qed
hoelzl@47694
  1252
qed
hoelzl@47694
  1253
wenzelm@61808
  1254
subsection \<open>Measure space induced by distribution of @{const measurable}-functions\<close>
hoelzl@47694
  1255
hoelzl@47694
  1256
definition distr :: "'a measure \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b measure" where
hoelzl@47694
  1257
  "distr M N f = measure_of (space N) (sets N) (\<lambda>A. emeasure M (f -` A \<inter> space M))"
hoelzl@47694
  1258
hoelzl@47694
  1259
lemma
hoelzl@59048
  1260
  shows sets_distr[simp, measurable_cong]: "sets (distr M N f) = sets N"
hoelzl@47694
  1261
    and space_distr[simp]: "space (distr M N f) = space N"
hoelzl@47694
  1262
  by (auto simp: distr_def)
hoelzl@47694
  1263
hoelzl@47694
  1264
lemma
hoelzl@47694
  1265
  shows measurable_distr_eq1[simp]: "measurable (distr Mf Nf f) Mf' = measurable Nf Mf'"
hoelzl@47694
  1266
    and measurable_distr_eq2[simp]: "measurable Mg' (distr Mg Ng g) = measurable Mg' Ng"
hoelzl@47694
  1267
  by (auto simp: measurable_def)
hoelzl@47694
  1268
hoelzl@54417
  1269
lemma distr_cong:
hoelzl@54417
  1270
  "M = K \<Longrightarrow> sets N = sets L \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> distr M N f = distr K L g"
hoelzl@54417
  1271
  using sets_eq_imp_space_eq[of N L] by (simp add: distr_def Int_def cong: rev_conj_cong)
hoelzl@54417
  1272
hoelzl@47694
  1273
lemma emeasure_distr:
hoelzl@47694
  1274
  fixes f :: "'a \<Rightarrow> 'b"
hoelzl@47694
  1275
  assumes f: "f \<in> measurable M N" and A: "A \<in> sets N"
hoelzl@47694
  1276
  shows "emeasure (distr M N f) A = emeasure M (f -` A \<inter> space M)" (is "_ = ?\<mu> A")
hoelzl@47694
  1277
  unfolding distr_def
hoelzl@47694
  1278
proof (rule emeasure_measure_of_sigma)
hoelzl@47694
  1279
  show "positive (sets N) ?\<mu>"
hoelzl@47694
  1280
    by (auto simp: positive_def)
hoelzl@47694
  1281
hoelzl@47694
  1282
  show "countably_additive (sets N) ?\<mu>"
hoelzl@47694
  1283
  proof (intro countably_additiveI)
hoelzl@47694
  1284
    fix A :: "nat \<Rightarrow> 'b set" assume "range A \<subseteq> sets N" "disjoint_family A"
hoelzl@47694
  1285
    then have A: "\<And>i. A i \<in> sets N" "(\<Union>i. A i) \<in> sets N" by auto
hoelzl@47694
  1286
    then have *: "range (\<lambda>i. f -` (A i) \<inter> space M) \<subseteq> sets M"
hoelzl@47694
  1287
      using f by (auto simp: measurable_def)
hoelzl@47694
  1288
    moreover have "(\<Union>i. f -`  A i \<inter> space M) \<in> sets M"
hoelzl@47694
  1289
      using * by blast
hoelzl@47694
  1290
    moreover have **: "disjoint_family (\<lambda>i. f -` A i \<inter> space M)"
wenzelm@61808
  1291
      using \<open>disjoint_family A\<close> by (auto simp: disjoint_family_on_def)
hoelzl@47694
  1292
    ultimately show "(\<Sum>i. ?\<mu> (A i)) = ?\<mu> (\<Union>i. A i)"
hoelzl@47694
  1293
      using suminf_emeasure[OF _ **] A f
hoelzl@47694
  1294
      by (auto simp: comp_def vimage_UN)
hoelzl@47694
  1295
  qed
hoelzl@47694
  1296
  show "sigma_algebra (space N) (sets N)" ..
hoelzl@47694
  1297
qed fact
hoelzl@47694
  1298
hoelzl@59000
  1299
lemma emeasure_Collect_distr:
hoelzl@59000
  1300
  assumes X[measurable]: "X \<in> measurable M N" "Measurable.pred N P"
hoelzl@59000
  1301
  shows "emeasure (distr M N X) {x\<in>space N. P x} = emeasure M {x\<in>space M. P (X x)}"
hoelzl@59000
  1302
  by (subst emeasure_distr)
hoelzl@59000
  1303
     (auto intro!: arg_cong2[where f=emeasure] X(1)[THEN measurable_space])
hoelzl@59000
  1304
hoelzl@59000
  1305
lemma emeasure_lfp2[consumes 1, case_names cont f measurable]:
hoelzl@59000
  1306
  assumes "P M"
hoelzl@60172
  1307
  assumes cont: "sup_continuous F"
hoelzl@59000
  1308
  assumes f: "\<And>M. P M \<Longrightarrow> f \<in> measurable M' M"
hoelzl@59000
  1309
  assumes *: "\<And>M A. P M \<Longrightarrow> (\<And>N. P N \<Longrightarrow> Measurable.pred N A) \<Longrightarrow> Measurable.pred M (F A)"
hoelzl@59000
  1310
  shows "emeasure M' {x\<in>space M'. lfp F (f x)} = (SUP i. emeasure M' {x\<in>space M'. (F ^^ i) (\<lambda>x. False) (f x)})"
hoelzl@59000
  1311
proof (subst (1 2) emeasure_Collect_distr[symmetric, where X=f])
hoelzl@59000
  1312
  show "f \<in> measurable M' M"  "f \<in> measurable M' M"
wenzelm@61808
  1313
    using f[OF \<open>P M\<close>] by auto
hoelzl@59000
  1314
  { fix i show "Measurable.pred M ((F ^^ i) (\<lambda>x. False))"
wenzelm@61808
  1315
    using \<open>P M\<close> by (induction i arbitrary: M) (auto intro!: *) }
hoelzl@59000
  1316
  show "Measurable.pred M (lfp F)"
wenzelm@61808
  1317
    using \<open>P M\<close> cont * by (rule measurable_lfp_coinduct[of P])
hoelzl@59000
  1318
hoelzl@59000
  1319
  have "emeasure (distr M' M f) {x \<in> space (distr M' M f). lfp F x} =
hoelzl@59000
  1320
    (SUP i. emeasure (distr M' M f) {x \<in> space (distr M' M f). (F ^^ i) (\<lambda>x. False) x})"
wenzelm@61808
  1321
    using \<open>P M\<close>
hoelzl@60636
  1322
  proof (coinduction arbitrary: M rule: emeasure_lfp')
hoelzl@59000
  1323
    case (measurable A N) then have "\<And>N. P N \<Longrightarrow> Measurable.pred (distr M' N f) A"
hoelzl@59000
  1324
      by metis
hoelzl@59000
  1325
    then have "\<And>N. P N \<Longrightarrow> Measurable.pred N A"
hoelzl@59000
  1326
      by simp
wenzelm@61808
  1327
    with \<open>P N\<close>[THEN *] show ?case
hoelzl@59000
  1328
      by auto
hoelzl@59000
  1329
  qed fact
hoelzl@59000
  1330
  then show "emeasure (distr M' M f) {x \<in> space M. lfp F x} =
hoelzl@59000
  1331
    (SUP i. emeasure (distr M' M f) {x \<in> space M. (F ^^ i) (\<lambda>x. False) x})"
hoelzl@59000
  1332
   by simp
hoelzl@59000
  1333
qed
hoelzl@59000
  1334
hoelzl@50104
  1335
lemma distr_id[simp]: "distr N N (\<lambda>x. x) = N"
hoelzl@50104
  1336
  by (rule measure_eqI) (auto simp: emeasure_distr)
hoelzl@50104
  1337
hoelzl@50001
  1338
lemma measure_distr:
hoelzl@50001
  1339
  "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
  1340
  by (simp add: emeasure_distr measure_def)
hoelzl@50001
  1341
hoelzl@57447
  1342
lemma distr_cong_AE:
lp15@61609
  1343
  assumes 1: "M = K" "sets N = sets L" and
hoelzl@57447
  1344
    2: "(AE x in M. f x = g x)" and "f \<in> measurable M N" and "g \<in> measurable K L"
hoelzl@57447
  1345
  shows "distr M N f = distr K L g"
hoelzl@57447
  1346
proof (rule measure_eqI)
hoelzl@57447
  1347
  fix A assume "A \<in> sets (distr M N f)"
hoelzl@57447
  1348
  with assms show "emeasure (distr M N f) A = emeasure (distr K L g) A"
hoelzl@57447
  1349
    by (auto simp add: emeasure_distr intro!: emeasure_eq_AE measurable_sets)
hoelzl@57447
  1350
qed (insert 1, simp)
hoelzl@57447
  1351
hoelzl@47694
  1352
lemma AE_distrD:
hoelzl@47694
  1353
  assumes f: "f \<in> measurable M M'"
hoelzl@47694
  1354
    and AE: "AE x in distr M M' f. P x"
hoelzl@47694
  1355
  shows "AE x in M. P (f x)"
hoelzl@47694
  1356
proof -
hoelzl@47694
  1357
  from AE[THEN AE_E] guess N .
hoelzl@47694
  1358
  with f show ?thesis
hoelzl@47694
  1359
    unfolding eventually_ae_filter
hoelzl@47694
  1360
    by (intro bexI[of _ "f -` N \<inter> space M"])
hoelzl@47694
  1361
       (auto simp: emeasure_distr measurable_def)
hoelzl@47694
  1362
qed
hoelzl@47694
  1363
hoelzl@49773
  1364
lemma AE_distr_iff:
hoelzl@50002
  1365
  assumes f[measurable]: "f \<in> measurable M N" and P[measurable]: "{x \<in> space N. P x} \<in> sets N"
hoelzl@49773
  1366
  shows "(AE x in distr M N f. P x) \<longleftrightarrow> (AE x in M. P (f x))"
hoelzl@49773
  1367
proof (subst (1 2) AE_iff_measurable[OF _ refl])
hoelzl@50002
  1368
  have "f -` {x\<in>space N. \<not> P x} \<inter> space M = {x \<in> space M. \<not> P (f x)}"
hoelzl@50002
  1369
    using f[THEN measurable_space] by auto
hoelzl@50002
  1370
  then show "(emeasure (distr M N f) {x \<in> space (distr M N f). \<not> P x} = 0) =
hoelzl@49773
  1371
    (emeasure M {x \<in> space M. \<not> P (f x)} = 0)"
hoelzl@50002
  1372
    by (simp add: emeasure_distr)
hoelzl@50002
  1373
qed auto
hoelzl@49773
  1374
hoelzl@47694
  1375
lemma null_sets_distr_iff:
hoelzl@47694
  1376
  "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
  1377
  by (auto simp add: null_sets_def emeasure_distr)
hoelzl@47694
  1378
hoelzl@47694
  1379
lemma distr_distr:
hoelzl@50002
  1380
  "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
  1381
  by (auto simp add: emeasure_distr measurable_space
hoelzl@47694
  1382
           intro!: arg_cong[where f="emeasure M"] measure_eqI)
hoelzl@47694
  1383
wenzelm@61808
  1384
subsection \<open>Real measure values\<close>
hoelzl@47694
  1385
hoelzl@62975
  1386
lemma ring_of_finite_sets: "ring_of_sets (space M) {A\<in>sets M. emeasure M A \<noteq> top}"
hoelzl@62975
  1387
proof (rule ring_of_setsI)
hoelzl@62975
  1388
  show "a \<in> {A \<in> sets M. emeasure M A \<noteq> top} \<Longrightarrow> b \<in> {A \<in> sets M. emeasure M A \<noteq> top} \<Longrightarrow>
hoelzl@62975
  1389
    a \<union> b \<in> {A \<in> sets M. emeasure M A \<noteq> top}" for a b
hoelzl@62975
  1390
    using emeasure_subadditive[of a M b] by (auto simp: top_unique)
hoelzl@62975
  1391
hoelzl@62975
  1392
  show "a \<in> {A \<in> sets M. emeasure M A \<noteq> top} \<Longrightarrow> b \<in> {A \<in> sets M. emeasure M A \<noteq> top} \<Longrightarrow>
hoelzl@62975
  1393
    a - b \<in> {A \<in> sets M. emeasure M A \<noteq> top}" for a b
hoelzl@62975
  1394
    using emeasure_mono[of "a - b" a M] by (auto simp: Diff_subset top_unique)
hoelzl@62975
  1395
qed (auto dest: sets.sets_into_space)
hoelzl@62975
  1396
hoelzl@62975
  1397
lemma measure_nonneg[simp]: "0 \<le> measure M A"
hoelzl@63333
  1398
  unfolding measure_def by auto
hoelzl@47694
  1399
hoelzl@61880
  1400
lemma zero_less_measure_iff: "0 < measure M A \<longleftrightarrow> measure M A \<noteq> 0"
hoelzl@61880
  1401
  using measure_nonneg[of M A] by (auto simp add: le_less)
hoelzl@61880
  1402
hoelzl@59000
  1403
lemma measure_le_0_iff: "measure M X \<le> 0 \<longleftrightarrow> measure M X = 0"
hoelzl@62975
  1404
  using measure_nonneg[of M X] by linarith
hoelzl@59000
  1405
hoelzl@47694
  1406
lemma measure_empty[simp]: "measure M {} = 0"
hoelzl@62975
  1407
  unfolding measure_def by (simp add: zero_ennreal.rep_eq)
hoelzl@62975
  1408
hoelzl@62975
  1409
lemma emeasure_eq_ennreal_measure:
hoelzl@62975
  1410
  "emeasure M A \<noteq> top \<Longrightarrow> emeasure M A = ennreal (measure M A)"
hoelzl@62975
  1411
  by (cases "emeasure M A" rule: ennreal_cases) (auto simp: measure_def)
hoelzl@47694
  1412
hoelzl@62975
  1413
lemma measure_zero_top: "emeasure M A = top \<Longrightarrow> measure M A = 0"
hoelzl@62975
  1414
  by (simp add: measure_def enn2ereal_top)
hoelzl@47694
  1415
hoelzl@62975
  1416
lemma measure_eq_emeasure_eq_ennreal: "0 \<le> x \<Longrightarrow> emeasure M A = ennreal x \<Longrightarrow> measure M A = x"
hoelzl@62975
  1417
  using emeasure_eq_ennreal_measure[of M A]
hoelzl@62975
  1418
  by (cases "A \<in> M") (auto simp: measure_notin_sets emeasure_notin_sets)
hoelzl@62975
  1419
hoelzl@62975
  1420
lemma enn2real_plus:"a < top \<Longrightarrow> b < top \<Longrightarrow> enn2real (a + b) = enn2real a + enn2real b"
hoelzl@63333
  1421
  by (simp add: enn2real_def plus_ennreal.rep_eq real_of_ereal_add less_top
hoelzl@62975
  1422
           del: real_of_ereal_enn2ereal)
Andreas@61633
  1423
hoelzl@47694
  1424
lemma measure_Union:
hoelzl@62975
  1425
  "emeasure M A \<noteq> \<infinity> \<Longrightarrow> emeasure M B \<noteq> \<infinity> \<Longrightarrow> A \<in> sets M \<Longrightarrow> B \<in> sets M \<Longrightarrow> A \<inter> B = {} \<Longrightarrow>
hoelzl@62975
  1426
    measure M (A \<union> B) = measure M A + measure M B"
hoelzl@63333
  1427
  by (simp add: measure_def plus_emeasure[symmetric] enn2real_plus less_top)
hoelzl@62975
  1428
hoelzl@62975
  1429
lemma disjoint_family_on_insert:
hoelzl@62975
  1430
  "i \<notin> I \<Longrightarrow> disjoint_family_on A (insert i I) \<longleftrightarrow> A i \<inter> (\<Union>i\<in>I. A i) = {} \<and> disjoint_family_on A I"
hoelzl@62975
  1431
  by (fastforce simp: disjoint_family_on_def)
hoelzl@47694
  1432
hoelzl@47694
  1433
lemma measure_finite_Union:
hoelzl@62975
  1434
  "finite S \<Longrightarrow> A`S \<subseteq> sets M \<Longrightarrow> disjoint_family_on A S \<Longrightarrow> (\<And>i. i \<in> S \<Longrightarrow> emeasure M (A i) \<noteq> \<infinity>) \<Longrightarrow>
hoelzl@62975
  1435
    measure M (\<Union>i\<in>S. A i) = (\<Sum>i\<in>S. measure M (A i))"
hoelzl@62975
  1436
  by (induction S rule: finite_induct)
hoelzl@62975
  1437
     (auto simp: disjoint_family_on_insert measure_Union setsum_emeasure[symmetric] sets.countable_UN'[OF countable_finite])
hoelzl@47694
  1438
hoelzl@47694
  1439
lemma measure_Diff:
hoelzl@47694
  1440
  assumes finite: "emeasure M A \<noteq> \<infinity>"
hoelzl@47694
  1441
  and measurable: "A \<in> sets M" "B \<in> sets M" "B \<subseteq> A"
hoelzl@47694
  1442
  shows "measure M (A - B) = measure M A - measure M B"
hoelzl@47694
  1443
proof -
hoelzl@47694
  1444
  have "emeasure M (A - B) \<le> emeasure M A" "emeasure M B \<le> emeasure M A"
hoelzl@47694
  1445
    using measurable by (auto intro!: emeasure_mono)
hoelzl@47694
  1446
  hence "measure M ((A - B) \<union> B) = measure M (A - B) + measure M B"
hoelzl@62975
  1447
    using measurable finite by (rule_tac measure_Union) (auto simp: top_unique)
wenzelm@61808
  1448
  thus ?thesis using \<open>B \<subseteq> A\<close> by (auto simp: Un_absorb2)
hoelzl@47694
  1449
qed
hoelzl@47694
  1450
hoelzl@47694
  1451
lemma measure_UNION:
hoelzl@47694
  1452
  assumes measurable: "range A \<subseteq> sets M" "disjoint_family A"
hoelzl@47694
  1453
  assumes finite: "emeasure M (\<Union>i. A i) \<noteq> \<infinity>"
hoelzl@47694
  1454
  shows "(\<lambda>i. measure M (A i)) sums (measure M (\<Union>i. A i))"
hoelzl@47694
  1455
proof -
hoelzl@62975
  1456
  have "(\<lambda>i. emeasure M (A i)) sums (emeasure M (\<Union>i. A i))"
hoelzl@62975
  1457
    unfolding suminf_emeasure[OF measurable, symmetric] by (simp add: summable_sums)
hoelzl@47694
  1458
  moreover
hoelzl@47694
  1459
  { fix i
hoelzl@47694
  1460
    have "emeasure M (A i) \<le> emeasure M (\<Union>i. A i)"
hoelzl@47694
  1461
      using measurable by (auto intro!: emeasure_mono)
hoelzl@62975
  1462
    then have "emeasure M (A i) = ennreal ((measure M (A i)))"
hoelzl@62975
  1463
      using finite by (intro emeasure_eq_ennreal_measure) (auto simp: top_unique) }
hoelzl@47694
  1464
  ultimately show ?thesis using finite
hoelzl@63333
  1465
    by (subst (asm) (2) emeasure_eq_ennreal_measure) simp_all
hoelzl@47694
  1466
qed
hoelzl@47694
  1467
hoelzl@47694
  1468
lemma measure_subadditive:
hoelzl@47694
  1469
  assumes measurable: "A \<in> sets M" "B \<in> sets M"
hoelzl@47694
  1470
  and fin: "emeasure M A \<noteq> \<infinity>" "emeasure M B \<noteq> \<infinity>"
hoelzl@62975
  1471
  shows "measure M (A \<union> B) \<le> measure M A + measure M B"
hoelzl@47694
  1472
proof -
hoelzl@47694
  1473
  have "emeasure M (A \<union> B) \<noteq> \<infinity>"
hoelzl@62975
  1474
    using emeasure_subadditive[OF measurable] fin by (auto simp: top_unique)
hoelzl@47694
  1475
  then show "(measure M (A \<union> B)) \<le> (measure M A) + (measure M B)"
hoelzl@47694
  1476
    using emeasure_subadditive[OF measurable] fin
hoelzl@62975
  1477
    apply simp
hoelzl@62975
  1478
    apply (subst (asm) (2 3 4) emeasure_eq_ennreal_measure)
hoelzl@62975
  1479
    apply (auto simp add: ennreal_plus[symmetric] simp del: ennreal_plus)
hoelzl@62975
  1480
    done
hoelzl@47694
  1481
qed
hoelzl@47694
  1482
hoelzl@47694
  1483
lemma measure_subadditive_finite:
hoelzl@47694
  1484
  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
  1485
  shows "measure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. measure M (A i))"
hoelzl@47694
  1486
proof -
hoelzl@47694
  1487
  { have "emeasure M (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. emeasure M (A i))"
hoelzl@47694
  1488
      using emeasure_subadditive_finite[OF A] .
hoelzl@47694
  1489
    also have "\<dots> < \<infinity>"
hoelzl@62975
  1490
      using fin by (simp add: less_top A)
hoelzl@62975
  1491
    finally have "emeasure M (\<Union>i\<in>I. A i) \<noteq> top" by simp }
hoelzl@62975
  1492
  note * = this
hoelzl@62975
  1493
  show ?thesis
hoelzl@47694
  1494
    using emeasure_subadditive_finite[OF A] fin
hoelzl@62975
  1495
    unfolding emeasure_eq_ennreal_measure[OF *]
hoelzl@63333
  1496
    by (simp_all add: setsum_nonneg emeasure_eq_ennreal_measure)
hoelzl@47694
  1497
qed
hoelzl@47694
  1498
hoelzl@47694
  1499
lemma measure_subadditive_countably:
hoelzl@47694
  1500
  assumes A: "range A \<subseteq> sets M" and fin: "(\<Sum>i. emeasure M (A i)) \<noteq> \<infinity>"
hoelzl@47694
  1501
  shows "measure M (\<Union>i. A i) \<le> (\<Sum>i. measure M (A i))"
hoelzl@47694
  1502
proof -
hoelzl@62975
  1503
  from fin have **: "\<And>i. emeasure M (A i) \<noteq> top"
hoelzl@62975
  1504
    using ennreal_suminf_lessD[of "\<lambda>i. emeasure M (A i)"] by (simp add: less_top)
hoelzl@47694
  1505
  { have "emeasure M (\<Union>i. A i) \<le> (\<Sum>i. emeasure M (A i))"
hoelzl@47694
  1506
      using emeasure_subadditive_countably[OF A] .
hoelzl@47694
  1507
    also have "\<dots> < \<infinity>"
hoelzl@62975
  1508
      using fin by (simp add: less_top)
hoelzl@62975
  1509
    finally have "emeasure M (\<Union>i. A i) \<noteq> top" by simp }
hoelzl@62975
  1510
  then have "ennreal (measure M (\<Union>i. A i)) = emeasure M (\<Union>i. A i)"
hoelzl@62975
  1511
    by (rule emeasure_eq_ennreal_measure[symmetric])
hoelzl@62975
  1512
  also have "\<dots> \<le> (\<Sum>i. emeasure M (A i))"
hoelzl@62975
  1513
    using emeasure_subadditive_countably[OF A] .
hoelzl@62975
  1514
  also have "\<dots> = ennreal (\<Sum>i. measure M (A i))"
hoelzl@62975
  1515
    using fin unfolding emeasure_eq_ennreal_measure[OF **]
hoelzl@62975
  1516
    by (subst suminf_ennreal) (auto simp: **)
hoelzl@62975
  1517
  finally show ?thesis
hoelzl@62975
  1518
    apply (rule ennreal_le_iff[THEN iffD1, rotated])
hoelzl@62975
  1519
    apply (intro suminf_nonneg allI measure_nonneg summable_suminf_not_top)
hoelzl@62975
  1520
    using fin
hoelzl@62975
  1521
    apply (simp add: emeasure_eq_ennreal_measure[OF **])
hoelzl@62975
  1522
    done
hoelzl@47694
  1523
qed
hoelzl@47694
  1524
hoelzl@47694
  1525
lemma measure_eq_setsum_singleton:
hoelzl@62975
  1526
  "finite S \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M) \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> emeasure M {x} \<noteq> \<infinity>) \<Longrightarrow>
hoelzl@62975
  1527
    measure M S = (\<Sum>x\<in>S. measure M {x})"
hoelzl@62975
  1528
  using emeasure_eq_setsum_singleton[of S M]
hoelzl@62975
  1529
  by (intro measure_eq_emeasure_eq_ennreal) (auto simp: setsum_nonneg emeasure_eq_ennreal_measure)
hoelzl@47694
  1530
hoelzl@47694
  1531
lemma Lim_measure_incseq:
hoelzl@47694
  1532
  assumes A: "range A \<subseteq> sets M" "incseq A" and fin: "emeasure M (\<Union>i. A i) \<noteq> \<infinity>"
hoelzl@62975
  1533
  shows "(\<lambda>i. measure M (A i)) \<longlonglongrightarrow> measure M (\<Union>i. A i)"
hoelzl@62975
  1534
proof (rule tendsto_ennrealD)
hoelzl@62975
  1535
  have "ennreal (measure M (\<Union>i. A i)) = emeasure M (\<Union>i. A i)"
hoelzl@62975
  1536
    using fin by (auto simp: emeasure_eq_ennreal_measure)
hoelzl@62975
  1537
  moreover have "ennreal (measure M (A i)) = emeasure M (A i)" for i
hoelzl@62975
  1538
    using assms emeasure_mono[of "A _" "\<Union>i. A i" M]
hoelzl@62975
  1539
    by (intro emeasure_eq_ennreal_measure[symmetric]) (auto simp: less_top UN_upper intro: le_less_trans)
hoelzl@62975
  1540
  ultimately show "(\<lambda>x. ennreal (Sigma_Algebra.measure M (A x))) \<longlonglongrightarrow> ennreal (Sigma_Algebra.measure M (\<Union>i. A i))"
hoelzl@62975
  1541
    using A by (auto intro!: Lim_emeasure_incseq)
hoelzl@62975
  1542
qed auto
hoelzl@47694
  1543
hoelzl@47694
  1544
lemma Lim_measure_decseq:
hoelzl@47694
  1545
  assumes A: "range A \<subseteq> sets M" "decseq A" and fin: "\<And>i. emeasure M (A i) \<noteq> \<infinity>"
wenzelm@61969
  1546
  shows "(\<lambda>n. measure M (A n)) \<longlonglongrightarrow> measure M (\<Inter>i. A i)"
hoelzl@62975
  1547
proof (rule tendsto_ennrealD)
hoelzl@62975
  1548
  have "ennreal (measure M (\<Inter>i. A i)) = emeasure M (\<Inter>i. A i)"
hoelzl@62975
  1549
    using fin[of 0] A emeasure_mono[of "\<Inter>i. A i" "A 0" M]
hoelzl@62975
  1550
    by (auto intro!: emeasure_eq_ennreal_measure[symmetric] simp: INT_lower less_top intro: le_less_trans)
hoelzl@62975
  1551
  moreover have "ennreal (measure M (A i)) = emeasure M (A i)" for i
hoelzl@62975
  1552
    using A fin[of i] by (intro emeasure_eq_ennreal_measure[symmetric]) auto
hoelzl@62975
  1553
  ultimately show "(\<lambda>x. ennreal (Sigma_Algebra.measure M (A x))) \<longlonglongrightarrow> ennreal (Sigma_Algebra.measure M (\<Inter>i. A i))"
hoelzl@62975
  1554
    using fin A by (auto intro!: Lim_emeasure_decseq)
hoelzl@62975
  1555
qed auto
hoelzl@47694
  1556
wenzelm@61808
  1557
subsection \<open>Measure spaces with @{term "emeasure M (space M) < \<infinity>"}\<close>
hoelzl@47694
  1558
hoelzl@47694
  1559
locale finite_measure = sigma_finite_measure M for M +
hoelzl@62975
  1560
  assumes finite_emeasure_space: "emeasure M (space M) \<noteq> top"
hoelzl@47694
  1561
hoelzl@47694
  1562
lemma finite_measureI[Pure.intro!]:
hoelzl@57447
  1563
  "emeasure M (space M) \<noteq> \<infinity> \<Longrightarrow> finite_measure M"
hoelzl@57447
  1564
  proof qed (auto intro!: exI[of _ "{space M}"])
hoelzl@47694
  1565
hoelzl@62975
  1566
lemma (in finite_measure) emeasure_finite[simp, intro]: "emeasure M A \<noteq> top"
hoelzl@62975
  1567
  using finite_emeasure_space emeasure_space[of M A] by (auto simp: top_unique)
hoelzl@47694
  1568
hoelzl@62975
  1569
lemma (in finite_measure) emeasure_eq_measure: "emeasure M A = ennreal (measure M A)"
hoelzl@62975
  1570
  by (intro emeasure_eq_ennreal_measure) simp
hoelzl@47694
  1571
hoelzl@62975
  1572
lemma (in finite_measure) emeasure_real: "\<exists>r. 0 \<le> r \<and> emeasure M A = ennreal r"
hoelzl@62975
  1573
  using emeasure_finite[of A] by (cases "emeasure M A" rule: ennreal_cases) auto
hoelzl@47694
  1574
hoelzl@47694
  1575
lemma (in finite_measure) bounded_measure: "measure M A \<le> measure M (space M)"
hoelzl@47694
  1576
  using emeasure_space[of M A] emeasure_real[of A] emeasure_real[of "space M"] by (auto simp: measure_def)
hoelzl@47694
  1577
hoelzl@47694
  1578
lemma (in finite_measure) finite_measure_Diff:
hoelzl@47694
  1579
  assumes sets: "A \<in> sets M" "B \<in> sets M" and "B \<subseteq> A"
hoelzl@47694
  1580
  shows "measure M (A - B) = measure M A - measure M B"
hoelzl@47694
  1581
  using measure_Diff[OF _ assms] by simp
hoelzl@47694
  1582
hoelzl@47694
  1583
lemma (in finite_measure) finite_measure_Union:
hoelzl@47694
  1584
  assumes sets: "A \<in> sets M" "B \<in> sets M" and "A \<inter> B = {}"
hoelzl@47694
  1585
  shows "measure M (A \<union> B) = measure M A + measure M B"
hoelzl@47694
  1586
  using measure_Union[OF _ _ assms] by simp
hoelzl@47694
  1587
hoelzl@47694
  1588
lemma (in finite_measure) finite_measure_finite_Union:
hoelzl@62975
  1589
  assumes measurable: "finite S" "A`S \<subseteq> sets M" "disjoint_family_on A S"
hoelzl@47694
  1590
  shows "measure M (\<Union>i\<in>S. A i) = (\<Sum>i\<in>S. measure M (A i))"
hoelzl@47694
  1591
  using measure_finite_Union[OF assms] by simp
hoelzl@47694
  1592
hoelzl@47694
  1593
lemma (in finite_measure) finite_measure_UNION:
hoelzl@47694
  1594
  assumes A: "range A \<subseteq> sets M" "disjoint_family A"
hoelzl@47694
  1595
  shows "(\<lambda>i. measure M (A i)) sums (measure M (\<Union>i. A i))"
hoelzl@47694
  1596
  using measure_UNION[OF A] by simp
hoelzl@47694
  1597
hoelzl@47694
  1598
lemma (in finite_measure) finite_measure_mono:
hoelzl@47694
  1599
  assumes "A \<subseteq> B" "B \<in> sets M" shows "measure M A \<le> measure M B"
hoelzl@47694
  1600
  using emeasure_mono[OF assms] emeasure_real[of A] emeasure_real[of B] by (auto simp: measure_def)
hoelzl@47694
  1601
hoelzl@47694
  1602
lemma (in finite_measure) finite_measure_subadditive:
hoelzl@47694
  1603
  assumes m: "A \<in> sets M" "B \<in> sets M"
hoelzl@47694
  1604
  shows "measure M (A \<union> B) \<le> measure M A + measure M B"
hoelzl@47694
  1605
  using measure_subadditive[OF m] by simp
hoelzl@47694
  1606
hoelzl@47694
  1607
lemma (in finite_measure) finite_measure_subadditive_finite:
hoelzl@47694
  1608
  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
  1609
  using measure_subadditive_finite[OF assms] by simp
hoelzl@47694
  1610
hoelzl@47694
  1611
lemma (in finite_measure) finite_measure_subadditive_countably:
hoelzl@62975
  1612
  "range A \<subseteq> sets M \<Longrightarrow> summable (\<lambda>i. measure M (A i)) \<Longrightarrow> measure M (\<Union>i. A i) \<le> (\<Sum>i. measure M (A i))"
hoelzl@62975
  1613
  by (rule measure_subadditive_countably)
hoelzl@62975
  1614
     (simp_all add: ennreal_suminf_neq_top emeasure_eq_measure)
hoelzl@47694
  1615
hoelzl@47694
  1616
lemma (in finite_measure) finite_measure_eq_setsum_singleton:
hoelzl@47694
  1617
  assumes "finite S" and *: "\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M"
hoelzl@47694
  1618
  shows "measure M S = (\<Sum>x\<in>S. measure M {x})"
hoelzl@47694
  1619
  using measure_eq_setsum_singleton[OF assms] by simp
hoelzl@47694
  1620
hoelzl@47694
  1621
lemma (in finite_measure) finite_Lim_measure_incseq:
hoelzl@47694
  1622
  assumes A: "range A \<subseteq> sets M" "incseq A"
wenzelm@61969
  1623
  shows "(\<lambda>i. measure M (A i)) \<longlonglongrightarrow> measure M (\<Union>i. A i)"
hoelzl@47694
  1624
  using Lim_measure_incseq[OF A] by simp
hoelzl@47694
  1625
hoelzl@47694
  1626
lemma (in finite_measure) finite_Lim_measure_decseq:
hoelzl@47694
  1627
  assumes A: "range A \<subseteq> sets M" "decseq A"
wenzelm@61969
  1628
  shows "(\<lambda>n. measure M (A n)) \<longlonglongrightarrow> measure M (\<Inter>i. A i)"
hoelzl@47694
  1629
  using Lim_measure_decseq[OF A] by simp
hoelzl@47694
  1630
hoelzl@47694
  1631
lemma (in finite_measure) finite_measure_compl:
hoelzl@47694
  1632
  assumes S: "S \<in> sets M"
hoelzl@47694
  1633
  shows "measure M (space M - S) = measure M (space M) - measure M S"
immler@50244
  1634
  using measure_Diff[OF _ sets.top S sets.sets_into_space] S by simp
hoelzl@47694
  1635
hoelzl@47694
  1636
lemma (in finite_measure) finite_measure_mono_AE:
hoelzl@47694
  1637
  assumes imp: "AE x in M. x \<in> A \<longrightarrow> x \<in> B" and B: "B \<in> sets M"
hoelzl@47694
  1638
  shows "measure M A \<le> measure M B"
hoelzl@47694
  1639
  using assms emeasure_mono_AE[OF imp B]
hoelzl@47694
  1640
  by (simp add: emeasure_eq_measure)
hoelzl@47694
  1641
hoelzl@47694
  1642
lemma (in finite_measure) finite_measure_eq_AE:
hoelzl@47694
  1643
  assumes iff: "AE x in M. x \<in> A \<longleftrightarrow> x \<in> B"
hoelzl@47694
  1644
  assumes A: "A \<in> sets M" and B: "B \<in> sets M"
hoelzl@47694
  1645
  shows "measure M A = measure M B"
hoelzl@47694
  1646
  using assms emeasure_eq_AE[OF assms] by (simp add: emeasure_eq_measure)
hoelzl@47694
  1647
hoelzl@50104
  1648
lemma (in finite_measure) measure_increasing: "increasing M (measure M)"
hoelzl@50104
  1649
  by (auto intro!: finite_measure_mono simp: increasing_def)
hoelzl@50104
  1650
hoelzl@50104
  1651
lemma (in finite_measure) measure_zero_union:
hoelzl@50104
  1652
  assumes "s \<in> sets M" "t \<in> sets M" "measure M t = 0"
hoelzl@50104
  1653
  shows "measure M (s \<union> t) = measure M s"
hoelzl@50104
  1654
using assms
hoelzl@50104
  1655
proof -
hoelzl@50104
  1656
  have "measure M (s \<union> t) \<le> measure M s"
hoelzl@50104
  1657
    using finite_measure_subadditive[of s t] assms by auto
hoelzl@50104
  1658
  moreover have "measure M (s \<union> t) \<ge> measure M s"
hoelzl@50104
  1659
    using assms by (blast intro: finite_measure_mono)
hoelzl@50104
  1660
  ultimately show ?thesis by simp
hoelzl@50104
  1661
qed
hoelzl@50104
  1662
hoelzl@50104
  1663
lemma (in finite_measure) measure_eq_compl:
hoelzl@50104
  1664
  assumes "s \<in> sets M" "t \<in> sets M"
hoelzl@50104
  1665
  assumes "measure M (space M - s) = measure M (space M - t)"
hoelzl@50104
  1666
  shows "measure M s = measure M t"
hoelzl@50104
  1667
  using assms finite_measure_compl by auto
hoelzl@50104
  1668
hoelzl@50104
  1669
lemma (in finite_measure) measure_eq_bigunion_image:
hoelzl@50104
  1670
  assumes "range f \<subseteq> sets M" "range g \<subseteq> sets M"
hoelzl@50104
  1671
  assumes "disjoint_family f" "disjoint_family g"
hoelzl@50104
  1672
  assumes "\<And> n :: nat. measure M (f n) = measure M (g n)"
wenzelm@60585
  1673
  shows "measure M (\<Union>i. f i) = measure M (\<Union>i. g i)"
hoelzl@50104
  1674
using assms
hoelzl@50104
  1675
proof -
wenzelm@60585
  1676
  have a: "(\<lambda> i. measure M (f i)) sums (measure M (\<Union>i. f i))"
hoelzl@50104
  1677
    by (rule finite_measure_UNION[OF assms(1,3)])
wenzelm@60585
  1678
  have b: "(\<lambda> i. measure M (g i)) sums (measure M (\<Union>i. g i))"
hoelzl@50104
  1679
    by (rule finite_measure_UNION[OF assms(2,4)])
hoelzl@50104
  1680
  show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
hoelzl@50104
  1681
qed
hoelzl@50104
  1682
hoelzl@50104
  1683
lemma (in finite_measure) measure_countably_zero:
hoelzl@50104
  1684
  assumes "range c \<subseteq> sets M"
hoelzl@50104
  1685
  assumes "\<And> i. measure M (c i) = 0"
wenzelm@60585
  1686
  shows "measure M (\<Union>i :: nat. c i) = 0"
hoelzl@50104
  1687
proof (rule antisym)
wenzelm@60585
  1688
  show "measure M (\<Union>i :: nat. c i) \<le> 0"
hoelzl@50104
  1689
    using finite_measure_subadditive_countably[OF assms(1)] by (simp add: assms(2))
hoelzl@62975
  1690
qed simp
hoelzl@50104
  1691
hoelzl@50104
  1692
lemma (in finite_measure) measure_space_inter:
hoelzl@50104
  1693
  assumes events:"s \<in> sets M" "t \<in> sets M"
hoelzl@50104
  1694
  assumes "measure M t = measure M (space M)"
hoelzl@50104
  1695
  shows "measure M (s \<inter> t) = measure M s"
hoelzl@50104
  1696
proof -
hoelzl@50104
  1697
  have "measure M ((space M - s) \<union> (space M - t)) = measure M (space M - s)"
hoelzl@50104
  1698
    using events assms finite_measure_compl[of "t"] by (auto intro!: measure_zero_union)
hoelzl@50104
  1699
  also have "(space M - s) \<union> (space M - t) = space M - (s \<inter> t)"
hoelzl@50104
  1700
    by blast
hoelzl@50104
  1701
  finally show "measure M (s \<inter> t) = measure M s"
hoelzl@50104
  1702
    using events by (auto intro!: measure_eq_compl[of "s \<inter> t" s])
hoelzl@50104
  1703
qed
hoelzl@50104
  1704
hoelzl@50104
  1705
lemma (in finite_measure) measure_equiprobable_finite_unions:
hoelzl@50104
  1706
  assumes s: "finite s" "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> sets M"
hoelzl@50104
  1707
  assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> measure M {x} = measure M {y}"
hoelzl@50104
  1708
  shows "measure M s = real (card s) * measure M {SOME x. x \<in> s}"
hoelzl@50104
  1709
proof cases
hoelzl@50104
  1710
  assume "s \<noteq> {}"
hoelzl@50104
  1711
  then have "\<exists> x. x \<in> s" by blast
hoelzl@50104
  1712
  from someI_ex[OF this] assms
hoelzl@50104
  1713
  have prob_some: "\<And> x. x \<in> s \<Longrightarrow> measure M {x} = measure M {SOME y. y \<in> s}" by blast
hoelzl@50104
  1714
  have "measure M s = (\<Sum> x \<in> s. measure M {x})"
hoelzl@50104
  1715
    using finite_measure_eq_setsum_singleton[OF s] by simp
hoelzl@50104
  1716
  also have "\<dots> = (\<Sum> x \<in> s. measure M {SOME y. y \<in> s})" using prob_some by auto
hoelzl@50104
  1717
  also have "\<dots> = real (card s) * measure M {(SOME x. x \<in> s)}"
lp15@61609
  1718
    using setsum_constant assms by simp
hoelzl@50104
  1719
  finally show ?thesis by simp
hoelzl@50104
  1720
qed simp
hoelzl@50104
  1721
hoelzl@50104
  1722
lemma (in finite_measure) measure_real_sum_image_fn:
hoelzl@50104
  1723
  assumes "e \<in> sets M"
hoelzl@50104
  1724
  assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> sets M"
hoelzl@50104
  1725
  assumes "finite s"
hoelzl@50104
  1726
  assumes disjoint: "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
wenzelm@60585
  1727
  assumes upper: "space M \<subseteq> (\<Union>i \<in> s. f i)"
hoelzl@50104
  1728
  shows "measure M e = (\<Sum> x \<in> s. measure M (e \<inter> f x))"
hoelzl@50104
  1729
proof -
haftmann@62343
  1730
  have "e \<subseteq> (\<Union>i\<in>s. f i)"
wenzelm@61808
  1731
    using \<open>e \<in> sets M\<close> sets.sets_into_space upper by blast
haftmann@62343
  1732
  then have e: "e = (\<Union>i \<in> s. e \<inter> f i)"
haftmann@62343
  1733
    by auto
wenzelm@60585
  1734
  hence "measure M e = measure M (\<Union>i \<in> s. e \<inter> f i)" by simp
hoelzl@50104
  1735
  also have "\<dots> = (\<Sum> x \<in> s. measure M (e \<inter> f x))"
hoelzl@50104
  1736
  proof (rule finite_measure_finite_Union)
hoelzl@50104
  1737
    show "finite s" by fact
hoelzl@50104
  1738
    show "(\<lambda>i. e \<inter> f i)`s \<subseteq> sets M" using assms(2) by auto
hoelzl@50104
  1739
    show "disjoint_family_on (\<lambda>i. e \<inter> f i) s"
hoelzl@50104
  1740
      using disjoint by (auto simp: disjoint_family_on_def)
hoelzl@50104
  1741
  qed
hoelzl@50104
  1742
  finally show ?thesis .
hoelzl@50104
  1743
qed
hoelzl@50104
  1744
hoelzl@50104
  1745
lemma (in finite_measure) measure_exclude:
hoelzl@50104
  1746
  assumes "A \<in> sets M" "B \<in> sets M"
hoelzl@50104
  1747
  assumes "measure M A = measure M (space M)" "A \<inter> B = {}"
hoelzl@50104
  1748
  shows "measure M B = 0"
hoelzl@50104
  1749
  using measure_space_inter[of B A] assms by (auto simp: ac_simps)
hoelzl@57235
  1750
lemma (in finite_measure) finite_measure_distr:
lp15@61609
  1751
  assumes f: "f \<in> measurable M M'"
hoelzl@57235
  1752
  shows "finite_measure (distr M M' f)"
hoelzl@57235
  1753
proof (rule finite_measureI)
hoelzl@57235
  1754
  have "f -` space M' \<inter> space M = space M" using f by (auto dest: measurable_space)
hoelzl@57235
  1755
  with f show "emeasure (distr M M' f) (space (distr M M' f)) \<noteq> \<infinity>" by (auto simp: emeasure_distr)
hoelzl@57235
  1756
qed
hoelzl@57235
  1757
hoelzl@60636
  1758
lemma emeasure_gfp[consumes 1, case_names cont measurable]:
hoelzl@60636
  1759
  assumes sets[simp]: "\<And>s. sets (M s) = sets N"
hoelzl@60636
  1760
  assumes "\<And>s. finite_measure (M s)"
hoelzl@60636
  1761
  assumes cont: "inf_continuous F" "inf_continuous f"
hoelzl@60636
  1762
  assumes meas: "\<And>P. Measurable.pred N P \<Longrightarrow> Measurable.pred N (F P)"
hoelzl@60636
  1763
  assumes iter: "\<And>P s. Measurable.pred N P \<Longrightarrow> emeasure (M s) {x\<in>space N. F P x} = f (\<lambda>s. emeasure (M s) {x\<in>space N. P x}) s"
hoelzl@60636
  1764
  assumes bound: "\<And>P. f P \<le> f (\<lambda>s. emeasure (M s) (space (M s)))"
hoelzl@60636
  1765
  shows "emeasure (M s) {x\<in>space N. gfp F x} = gfp f s"
hoelzl@60636
  1766
proof (subst gfp_transfer_bounded[where \<alpha>="\<lambda>F s. emeasure (M s) {x\<in>space N. F x}" and g=f and f=F and
hoelzl@60636
  1767
    P="Measurable.pred N", symmetric])
hoelzl@60636
  1768
  interpret finite_measure "M s" for s by fact
hoelzl@60636
  1769
  fix C assume "decseq C" "\<And>i. Measurable.pred N (C i)"
hoelzl@60636
  1770
  then show "(\<lambda>s. emeasure (M s) {x \<in> space N. (INF i. C i) x}) = (INF i. (\<lambda>s. emeasure (M s) {x \<in> space N. C i x}))"
hoelzl@60636
  1771
    unfolding INF_apply[abs_def]
hoelzl@60636
  1772
    by (subst INF_emeasure_decseq) (auto simp: antimono_def fun_eq_iff intro!: arg_cong2[where f=emeasure])
hoelzl@60636
  1773
next
hoelzl@60636
  1774
  show "f x \<le> (\<lambda>s. emeasure (M s) {x \<in> space N. F top x})" for x
hoelzl@60636
  1775
    using bound[of x] sets_eq_imp_space_eq[OF sets] by (simp add: iter)
hoelzl@60636
  1776
qed (auto simp add: iter le_fun_def INF_apply[abs_def] intro!: meas cont)
hoelzl@60636
  1777
wenzelm@61808
  1778
subsection \<open>Counting space\<close>
hoelzl@47694
  1779
hoelzl@49773
  1780
lemma strict_monoI_Suc:
hoelzl@49773
  1781
  assumes ord [simp]: "(\<And>n. f n < f (Suc n))" shows "strict_mono f"
hoelzl@49773
  1782
  unfolding strict_mono_def
hoelzl@49773
  1783
proof safe
hoelzl@49773
  1784
  fix n m :: nat assume "n < m" then show "f n < f m"
hoelzl@49773
  1785
    by (induct m) (auto simp: less_Suc_eq intro: less_trans ord)
hoelzl@49773
  1786
qed
hoelzl@49773
  1787
hoelzl@47694
  1788
lemma emeasure_count_space:
hoelzl@62975
  1789
  assumes "X \<subseteq> A" shows "emeasure (count_space A) X = (if finite X then of_nat (card X) else \<infinity>)"
hoelzl@47694
  1790
    (is "_ = ?M X")
hoelzl@47694
  1791
  unfolding count_space_def
hoelzl@47694
  1792
proof (rule emeasure_measure_of_sigma)
wenzelm@61808
  1793
  show "X \<in> Pow A" using \<open>X \<subseteq> A\<close> by auto
hoelzl@47694
  1794
  show "sigma_algebra A (Pow A)" by (rule sigma_algebra_Pow)
hoelzl@49773
  1795
  show positive: "positive (Pow A) ?M"
hoelzl@47694
  1796
    by (auto simp: positive_def)
hoelzl@49773
  1797
  have additive: "additive (Pow A) ?M"
hoelzl@49773
  1798
    by (auto simp: card_Un_disjoint additive_def)
hoelzl@47694
  1799
hoelzl@49773
  1800
  interpret ring_of_sets A "Pow A"
hoelzl@49773
  1801
    by (rule ring_of_setsI) auto
lp15@61609
  1802
  show "countably_additive (Pow A) ?M"
hoelzl@49773
  1803
    unfolding countably_additive_iff_continuous_from_below[OF positive additive]
hoelzl@49773
  1804
  proof safe
hoelzl@49773
  1805
    fix F :: "nat \<Rightarrow> 'a set" assume "incseq F"
wenzelm@61969
  1806
    show "(\<lambda>i. ?M (F i)) \<longlonglongrightarrow> ?M (\<Union>i. F i)"
hoelzl@49773
  1807
    proof cases
hoelzl@49773
  1808
      assume "\<exists>i. \<forall>j\<ge>i. F i = F j"
hoelzl@49773
  1809
      then guess i .. note i = this
wenzelm@61808
  1810
      { fix j from i \<open>incseq F\<close> have "F j \<subseteq> F i"
hoelzl@49773
  1811
          by (cases "i \<le> j") (auto simp: incseq_def) }
hoelzl@49773
  1812
      then have eq: "(\<Union>i. F i) = F i"
hoelzl@49773
  1813
        by auto
hoelzl@49773
  1814
      with i show ?thesis
hoelzl@63626
  1815
        by (auto intro!: Lim_transform_eventually[OF _ tendsto_const] eventually_sequentiallyI[where c=i])
hoelzl@49773
  1816
    next
hoelzl@49773
  1817
      assume "\<not> (\<exists>i. \<forall>j\<ge>i. F i = F j)"
wenzelm@53374
  1818
      then obtain f where f: "\<And>i. i \<le> f i" "\<And>i. F i \<noteq> F (f i)" by metis
wenzelm@61808
  1819
      then have "\<And>i. F i \<subseteq> F (f i)" using \<open>incseq F\<close> by (auto simp: incseq_def)
wenzelm@53374
  1820
      with f have *: "\<And>i. F i \<subset> F (f i)" by auto
hoelzl@47694
  1821
hoelzl@49773
  1822
      have "incseq (\<lambda>i. ?M (F i))"
wenzelm@61808
  1823
        using \<open>incseq F\<close> unfolding incseq_def by (auto simp: card_mono dest: finite_subset)
wenzelm@61969
  1824
      then have "(\<lambda>i. ?M (F i)) \<longlonglongrightarrow> (SUP n. ?M (F n))"
hoelzl@51000
  1825
        by (rule LIMSEQ_SUP)
hoelzl@47694
  1826
hoelzl@62975
  1827
      moreover have "(SUP n. ?M (F n)) = top"
hoelzl@62975
  1828
      proof (rule ennreal_SUP_eq_top)
hoelzl@62975
  1829
        fix n :: nat show "\<exists>k::nat\<in>UNIV. of_nat n \<le> ?M (F k)"
hoelzl@49773
  1830
        proof (induct n)
hoelzl@49773
  1831
          case (Suc n)
hoelzl@49773
  1832
          then guess k .. note k = this
hoelzl@49773
  1833
          moreover have "finite (F k) \<Longrightarrow> finite (F (f k)) \<Longrightarrow> card (F k) < card (F (f k))"
wenzelm@61808
  1834
            using \<open>F k \<subset> F (f k)\<close> by (simp add: psubset_card_mono)
hoelzl@49773
  1835
          moreover have "finite (F (f k)) \<Longrightarrow> finite (F k)"
wenzelm@61808
  1836
            using \<open>k \<le> f k\<close> \<open>incseq F\<close> by (auto simp: incseq_def dest: finite_subset)
hoelzl@49773
  1837
          ultimately show ?case
hoelzl@62975
  1838
            by (auto intro!: exI[of _ "f k"] simp del: of_nat_Suc)
hoelzl@49773
  1839
        qed auto
hoelzl@47694
  1840
      qed
hoelzl@49773
  1841
hoelzl@49773
  1842
      moreover
hoelzl@49773
  1843
      have "inj (\<lambda>n. F ((f ^^ n) 0))"
hoelzl@49773
  1844
        by (intro strict_mono_imp_inj_on strict_monoI_Suc) (simp add: *)
hoelzl@49773
  1845
      then have 1: "infinite (range (\<lambda>i. F ((f ^^ i) 0)))"
hoelzl@49773
  1846
        by (rule range_inj_infinite)
hoelzl@49773
  1847
      have "infinite (Pow (\<Union>i. F i))"
hoelzl@49773
  1848
        by (rule infinite_super[OF _ 1]) auto
hoelzl@49773
  1849
      then have "infinite (\<Union>i. F i)"
hoelzl@49773
  1850
        by auto
lp15@61609
  1851
hoelzl@49773
  1852
      ultimately show ?thesis by auto
hoelzl@49773
  1853
    qed
hoelzl@47694
  1854
  qed
hoelzl@47694
  1855
qed
hoelzl@47694
  1856
hoelzl@59011
  1857
lemma distr_bij_count_space:
hoelzl@59011
  1858
  assumes f: "bij_betw f A B"
hoelzl@59011
  1859
  shows "distr (count_space A) (count_space B) f = count_space B"
hoelzl@59011
  1860
proof (rule measure_eqI)
hoelzl@59011
  1861
  have f': "f \<in> measurable (count_space A) (count_space B)"
hoelzl@59011
  1862
    using f unfolding Pi_def bij_betw_def by auto
hoelzl@59011
  1863
  fix X assume "X \<in> sets (distr (count_space A) (count_space B) f)"
hoelzl@59011
  1864
  then have X: "X \<in> sets (count_space B)" by auto
wenzelm@63540
  1865
  moreover from X have "f -` X \<inter> A = the_inv_into A f ` X"
hoelzl@59011
  1866
    using f by (auto simp: bij_betw_def subset_image_iff image_iff the_inv_into_f_f intro: the_inv_into_f_f[symmetric])
hoelzl@59011
  1867
  moreover have "inj_on (the_inv_into A f) B"
hoelzl@59011
  1868
    using X f by (auto simp: bij_betw_def inj_on_the_inv_into)
hoelzl@59011
  1869
  with X have "inj_on (the_inv_into A f) X"
hoelzl@59011
  1870
    by (auto intro: subset_inj_on)
hoelzl@59011
  1871
  ultimately show "emeasure (distr (count_space A) (count_space B) f) X = emeasure (count_space B) X"
hoelzl@59011
  1872
    using f unfolding emeasure_distr[OF f' X]
hoelzl@59011
  1873
    by (subst (1 2) emeasure_count_space) (auto simp: card_image dest: finite_imageD)
hoelzl@59011
  1874
qed simp
hoelzl@59011
  1875
hoelzl@47694
  1876
lemma emeasure_count_space_finite[simp]:
hoelzl@62975
  1877
  "X \<subseteq> A \<Longrightarrow> finite X \<Longrightarrow> emeasure (count_space A) X = of_nat (card X)"
hoelzl@47694
  1878
  using emeasure_count_space[of X A] by simp
hoelzl@47694
  1879
hoelzl@47694
  1880
lemma emeasure_count_space_infinite[simp]:
hoelzl@47694
  1881
  "X \<subseteq> A \<Longrightarrow> infinite X \<Longrightarrow> emeasure (count_space A) X = \<infinity>"
hoelzl@47694
  1882
  using emeasure_count_space[of X A] by simp
hoelzl@47694
  1883
hoelzl@62975
  1884
lemma measure_count_space: "measure (count_space A) X = (if X \<subseteq> A then of_nat (card X) else 0)"
hoelzl@62975
  1885
  by (cases "finite X") (auto simp: measure_notin_sets ennreal_of_nat_eq_real_of_nat
hoelzl@62975
  1886
                                    measure_zero_top measure_eq_emeasure_eq_ennreal)
hoelzl@58606
  1887
hoelzl@47694
  1888
lemma emeasure_count_space_eq_0:
hoelzl@47694
  1889
  "emeasure (count_space A) X = 0 \<longleftrightarrow> (X \<subseteq> A \<longrightarrow> X = {})"
hoelzl@47694
  1890
proof cases
hoelzl@47694
  1891
  assume X: "X \<subseteq> A"
hoelzl@47694
  1892
  then show ?thesis
hoelzl@47694
  1893
  proof (intro iffI impI)
hoelzl@47694
  1894
    assume "emeasure (count_space A) X = 0"
hoelzl@47694
  1895
    with X show "X = {}"
nipkow@62390
  1896
      by (subst (asm) emeasure_count_space) (auto split: if_split_asm)
hoelzl@47694
  1897
  qed simp
hoelzl@47694
  1898
qed (simp add: emeasure_notin_sets)
hoelzl@47694
  1899
hoelzl@58606
  1900
lemma space_empty: "space M = {} \<Longrightarrow> M = count_space {}"
hoelzl@58606
  1901
  by (rule measure_eqI) (simp_all add: space_empty_iff)
hoelzl@58606
  1902
hoelzl@47694
  1903
lemma null_sets_count_space: "null_sets (count_space A) = { {} }"
hoelzl@47694
  1904
  unfolding null_sets_def by (auto simp add: emeasure_count_space_eq_0)
hoelzl@47694
  1905
hoelzl@47694
  1906
lemma AE_count_space: "(AE x in count_space A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P x)"
hoelzl@47694
  1907
  unfolding eventually_ae_filter by (auto simp add: null_sets_count_space)
hoelzl@47694
  1908
hoelzl@57025
  1909
lemma sigma_finite_measure_count_space_countable:
hoelzl@57025
  1910
  assumes A: "countable A"
hoelzl@47694
  1911
  shows "sigma_finite_measure (count_space A)"
hoelzl@62975
  1912
  proof qed (insert A, auto intro!: exI[of _ "(\<lambda>a. {a}) ` A"])
hoelzl@47694
  1913
hoelzl@57025
  1914
lemma sigma_finite_measure_count_space:
hoelzl@57025
  1915
  fixes A :: "'a::countable set" shows "sigma_finite_measure (count_space A)"
hoelzl@57025
  1916
  by (rule sigma_finite_measure_count_space_countable) auto
hoelzl@57025
  1917
hoelzl@47694
  1918
lemma finite_measure_count_space:
hoelzl@47694
  1919
  assumes [simp]: "finite A"
hoelzl@47694
  1920
  shows "finite_measure (count_space A)"
hoelzl@47694
  1921
  by rule simp
hoelzl@47694
  1922
hoelzl@47694
  1923
lemma sigma_finite_measure_count_space_finite:
hoelzl@47694
  1924
  assumes A: "finite A" shows "sigma_finite_measure (count_space A)"
hoelzl@47694
  1925
proof -
hoelzl@47694
  1926
  interpret finite_measure "count_space A" using A by (rule finite_measure_count_space)
hoelzl@47694
  1927
  show "sigma_finite_measure (count_space A)" ..
hoelzl@47694
  1928
qed
hoelzl@47694
  1929
wenzelm@61808
  1930
subsection \<open>Measure restricted to space\<close>
hoelzl@54417
  1931
hoelzl@54417
  1932
lemma emeasure_restrict_space:
hoelzl@57025
  1933
  assumes "\<Omega> \<inter> space M \<in> sets M" "A \<subseteq> \<Omega>"
hoelzl@54417
  1934
  shows "emeasure (restrict_space M \<Omega>) A = emeasure M A"
wenzelm@63540
  1935
proof (cases "A \<in> sets M")
wenzelm@63540
  1936
  case True
hoelzl@57025
  1937
  show ?thesis
hoelzl@54417
  1938
  proof (rule emeasure_measure_of[OF restrict_space_def])
hoelzl@57025
  1939
    show "op \<inter> \<Omega> ` sets M \<subseteq> Pow (\<Omega> \<inter> space M)" "A \<in> sets (restrict_space M \<Omega>)"
wenzelm@61808
  1940
      using \<open>A \<subseteq> \<Omega>\<close> \<open>A \<in> sets M\<close> sets.space_closed by (auto simp: sets_restrict_space)
hoelzl@57025
  1941
    show "positive (sets (restrict_space M \<Omega>)) (emeasure M)"
hoelzl@62975
  1942
      by (auto simp: positive_def)
hoelzl@57025
  1943
    show "countably_additive (sets (restrict_space M \<Omega>)) (emeasure M)"
hoelzl@54417
  1944
    proof (rule countably_additiveI)
hoelzl@54417
  1945
      fix A :: "nat \<Rightarrow> _" assume "range A \<subseteq> sets (restrict_space M \<Omega>)" "disjoint_family A"
hoelzl@54417
  1946
      with assms have "\<And>i. A i \<in> sets M" "\<And>i. A i \<subseteq> space M" "disjoint_family A"
hoelzl@57025
  1947
        by (fastforce simp: sets_restrict_space_iff[OF assms(1)] image_subset_iff
hoelzl@57025
  1948
                      dest: sets.sets_into_space)+
hoelzl@57025
  1949
      then show "(\<Sum>i. emeasure M (A i)) = emeasure M (\<Union>i. A i)"
hoelzl@54417
  1950
        by (subst suminf_emeasure) (auto simp: disjoint_family_subset)
hoelzl@54417
  1951
    qed
hoelzl@54417
  1952
  qed
hoelzl@54417
  1953
next
wenzelm@63540
  1954
  case False
wenzelm@63540
  1955
  with assms have "A \<notin> sets (restrict_space M \<Omega>)"
hoelzl@54417
  1956
    by (simp add: sets_restrict_space_iff)
wenzelm@63540
  1957
  with False show ?thesis
hoelzl@54417
  1958
    by (simp add: emeasure_notin_sets)
hoelzl@54417
  1959
qed
hoelzl@54417
  1960
hoelzl@57137
  1961
lemma measure_restrict_space:
hoelzl@57137
  1962
  assumes "\<Omega> \<inter> space M \<in> sets M" "A \<subseteq> \<Omega>"
hoelzl@57137
  1963
  shows "measure (restrict_space M \<Omega>) A = measure M A"
hoelzl@57137
  1964
  using emeasure_restrict_space[OF assms] by (simp add: measure_def)
hoelzl@57137
  1965
hoelzl@57137
  1966
lemma AE_restrict_space_iff:
hoelzl@57137
  1967
  assumes "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
  1968
  shows "(AE x in restrict_space M \<Omega>. P x) \<longleftrightarrow> (AE x in M. x \<in> \<Omega> \<longrightarrow> P x)"
hoelzl@57137
  1969
proof -
hoelzl@57137
  1970
  have ex_cong: "\<And>P Q f. (\<And>x. P x \<Longrightarrow> Q x) \<Longrightarrow> (\<And>x. Q x \<Longrightarrow> P (f x)) \<Longrightarrow> (\<exists>x. P x) \<longleftrightarrow> (\<exists>x. Q x)"
hoelzl@57137
  1971
    by auto
hoelzl@57137
  1972
  { fix X assume X: "X \<in> sets M" "emeasure M X = 0"
hoelzl@57137
  1973
    then have "emeasure M (\<Omega> \<inter> space M \<inter> X) \<le> emeasure M X"
hoelzl@57137
  1974
      by (intro emeasure_mono) auto
hoelzl@57137
  1975
    then have "emeasure M (\<Omega> \<inter> space M \<inter> X) = 0"
hoelzl@57137
  1976
      using X by (auto intro!: antisym) }
hoelzl@57137
  1977
  with assms show ?thesis
hoelzl@57137
  1978
    unfolding eventually_ae_filter
hoelzl@57137
  1979
    by (auto simp add: space_restrict_space null_sets_def sets_restrict_space_iff
hoelzl@57137
  1980
                       emeasure_restrict_space cong: conj_cong
hoelzl@57137
  1981
             intro!: ex_cong[where f="\<lambda>X. (\<Omega> \<inter> space M) \<inter> X"])
lp15@61609
  1982
qed
hoelzl@57137
  1983
hoelzl@57025
  1984
lemma restrict_restrict_space:
hoelzl@57025
  1985
  assumes "A \<inter> space M \<in> sets M" "B \<inter> space M \<in> sets M"
hoelzl@57025
  1986
  shows "restrict_space (restrict_space M A) B = restrict_space M (A \<inter> B)" (is "?l = ?r")
hoelzl@57025
  1987
proof (rule measure_eqI[symmetric])
hoelzl@57025
  1988
  show "sets ?r = sets ?l"
hoelzl@57025
  1989
    unfolding sets_restrict_space image_comp by (intro image_cong) auto
hoelzl@57025
  1990
next
hoelzl@57025
  1991
  fix X assume "X \<in> sets (restrict_space M (A \<inter> B))"
hoelzl@57025
  1992
  then obtain Y where "Y \<in> sets M" "X = Y \<inter> A \<inter> B"
hoelzl@57025
  1993
    by (auto simp: sets_restrict_space)
hoelzl@57025
  1994
  with assms sets.Int[OF assms] show "emeasure ?r X = emeasure ?l X"
hoelzl@57025
  1995
    by (subst (1 2) emeasure_restrict_space)
hoelzl@57025
  1996
       (auto simp: space_restrict_space sets_restrict_space_iff emeasure_restrict_space ac_simps)
hoelzl@57025
  1997
qed
hoelzl@57025
  1998
hoelzl@57025
  1999
lemma restrict_count_space: "restrict_space (count_space B) A = count_space (A \<inter> B)"
hoelzl@54417
  2000
proof (rule measure_eqI)
hoelzl@57025
  2001
  show "sets (restrict_space (count_space B) A) = sets (count_space (A \<inter> B))"
hoelzl@57025
  2002
    by (subst sets_restrict_space) auto
hoelzl@54417
  2003
  moreover fix X assume "X \<in> sets (restrict_space (count_space B) A)"
hoelzl@57025
  2004
  ultimately have "X \<subseteq> A \<inter> B" by auto
hoelzl@57025
  2005
  then show "emeasure (restrict_space (count_space B) A) X = emeasure (count_space (A \<inter> B)) X"
hoelzl@54417
  2006
    by (cases "finite X") (auto simp add: emeasure_restrict_space)
hoelzl@54417
  2007
qed
hoelzl@54417
  2008
Andreas@60063
  2009
lemma sigma_finite_measure_restrict_space:
Andreas@60063
  2010
  assumes "sigma_finite_measure M"
Andreas@60063
  2011
  and A: "A \<in> sets M"
Andreas@60063
  2012
  shows "sigma_finite_measure (restrict_space M A)"
Andreas@60063
  2013
proof -
Andreas@60063
  2014
  interpret sigma_finite_measure M by fact
Andreas@60063
  2015
  from sigma_finite_countable obtain C
Andreas@60063
  2016
    where C: "countable C" "C \<subseteq> sets M" "(\<Union>C) = space M" "\<forall>a\<in>C. emeasure M a \<noteq> \<infinity>"
Andreas@60063
  2017
    by blast
Andreas@60063
  2018
  let ?C = "op \<inter> A ` C"
Andreas@60063
  2019
  from C have "countable ?C" "?C \<subseteq> sets (restrict_space M A)" "(\<Union>?C) = space (restrict_space M A)"
Andreas@60063
  2020
    by(auto simp add: sets_restrict_space space_restrict_space)
Andreas@60063
  2021
  moreover {
Andreas@60063
  2022
    fix a
Andreas@60063
  2023
    assume "a \<in> ?C"
Andreas@60063
  2024
    then obtain a' where "a = A \<inter> a'" "a' \<in> C" ..
Andreas@60063
  2025
    then have "emeasure (restrict_space M A) a \<le> emeasure M a'"
Andreas@60063
  2026
      using A C by(auto simp add: emeasure_restrict_space intro: emeasure_mono)
hoelzl@62975
  2027
    also have "\<dots> < \<infinity>" using C(4)[rule_format, of a'] \<open>a' \<in> C\<close> by (simp add: less_top)
Andreas@60063
  2028
    finally have "emeasure (restrict_space M A) a \<noteq> \<infinity>" by simp }
Andreas@60063
  2029
  ultimately show ?thesis
Andreas@60063
  2030
    by unfold_locales (rule exI conjI|assumption|blast)+
Andreas@60063
  2031
qed
Andreas@60063
  2032
Andreas@60063
  2033
lemma finite_measure_restrict_space:
Andreas@60063
  2034
  assumes "finite_measure M"
Andreas@60063
  2035
  and A: "A \<in> sets M"
Andreas@60063
  2036
  shows "finite_measure (restrict_space M A)"
Andreas@60063
  2037
proof -
Andreas@60063
  2038
  interpret finite_measure M by fact
Andreas@60063
  2039
  show ?thesis
Andreas@60063
  2040
    by(rule finite_measureI)(simp add: emeasure_restrict_space A space_restrict_space)
Andreas@60063
  2041
qed
Andreas@60063
  2042
lp15@61609
  2043
lemma restrict_distr:
hoelzl@57137
  2044
  assumes [measurable]: "f \<in> measurable M N"
hoelzl@57137
  2045
  assumes [simp]: "\<Omega> \<inter> space N \<in> sets N" and restrict: "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@57137
  2046
  shows "restrict_space (distr M N f) \<Omega> = distr M (restrict_space N \<Omega>) f"
hoelzl@57137
  2047
  (is "?l = ?r")
hoelzl@57137
  2048
proof (rule measure_eqI)
hoelzl@57137
  2049
  fix A assume "A \<in> sets (restrict_space (distr M N f) \<Omega>)"
hoelzl@57137
  2050
  with restrict show "emeasure ?l A = emeasure ?r A"
hoelzl@57137
  2051
    by (subst emeasure_distr)
hoelzl@57137
  2052
       (auto simp: sets_restrict_space_iff emeasure_restrict_space emeasure_distr
hoelzl@57137
  2053
             intro!: measurable_restrict_space2)
hoelzl@57137
  2054
qed (simp add: sets_restrict_space)
hoelzl@57137
  2055
hoelzl@59000
  2056
lemma measure_eqI_restrict_generator:
hoelzl@59000
  2057
  assumes E: "Int_stable E" "E \<subseteq> Pow \<Omega>" "\<And>X. X \<in> E \<Longrightarrow> emeasure M X = emeasure N X"
hoelzl@59000
  2058
  assumes sets_eq: "sets M = sets N" and \<Omega>: "\<Omega> \<in> sets M"
hoelzl@59000
  2059
  assumes "sets (restrict_space M \<Omega>) = sigma_sets \<Omega> E"
lp15@61609
  2060
  assumes "sets (restrict_space N \<Omega>) = sigma_sets \<Omega> E"
hoelzl@59000
  2061
  assumes ae: "AE x in M. x \<in> \<Omega>" "AE x in N. x \<in> \<Omega>"
hoelzl@59000
  2062
  assumes A: "countable A" "A \<noteq> {}" "A \<subseteq> E" "\<Union>A = \<Omega>" "\<And>a. a \<in> A \<Longrightarrow> emeasure M a \<noteq> \<infinity>"
hoelzl@59000
  2063
  shows "M = N"
hoelzl@59000
  2064
proof (rule measure_eqI)
hoelzl@59000
  2065
  fix X assume X: "X \<in> sets M"
hoelzl@59000
  2066
  then have "emeasure M X = emeasure (restrict_space M \<Omega>) (X \<inter> \<Omega>)"
hoelzl@59000
  2067
    using ae \<Omega> by (auto simp add: emeasure_restrict_space intro!: emeasure_eq_AE)
hoelzl@59000
  2068
  also have "restrict_space M \<Omega> = restrict_space N \<Omega>"
hoelzl@59000
  2069
  proof (rule measure_eqI_generator_eq)
hoelzl@59000
  2070
    fix X assume "X \<in> E"
hoelzl@59000
  2071
    then show "emeasure (restrict_space M \<Omega>) X = emeasure (restrict_space N \<Omega>) X"
hoelzl@59000
  2072
      using E \<Omega> by (subst (1 2) emeasure_restrict_space) (auto simp: sets_eq sets_eq[THEN sets_eq_imp_space_eq])
hoelzl@59000
  2073
  next
hoelzl@59000
  2074
    show "range (from_nat_into A) \<subseteq> E" "(\<Union>i. from_nat_into A i) = \<Omega>"
haftmann@62343
  2075
      using A by (auto cong del: strong_SUP_cong)
hoelzl@59000
  2076
  next
hoelzl@59000
  2077
    fix i
hoelzl@59000
  2078
    have "emeasure (restrict_space M \<Omega>) (from_nat_into A i) = emeasure M (from_nat_into A i)"
hoelzl@59000
  2079
      using A \<Omega> by (subst emeasure_restrict_space)
hoelzl@59000
  2080
                   (auto simp: sets_eq sets_eq[THEN sets_eq_imp_space_eq] intro: from_nat_into)
hoelzl@59000
  2081
    with A show "emeasure (restrict_space M \<Omega>) (from_nat_into A i) \<noteq> \<infinity>"
hoelzl@59000
  2082
      by (auto intro: from_nat_into)
hoelzl@59000
  2083
  qed fact+
hoelzl@59000
  2084
  also have "emeasure (restrict_space N \<Omega>) (X \<inter> \<Omega>) = emeasure N X"
hoelzl@59000
  2085
    using X ae \<Omega> by (auto simp add: emeasure_restrict_space sets_eq intro!: emeasure_eq_AE)
hoelzl@59000
  2086
  finally show "emeasure M X = emeasure N X" .
hoelzl@59000
  2087
qed fact
hoelzl@59000
  2088
wenzelm@61808
  2089
subsection \<open>Null measure\<close>
hoelzl@59425
  2090
hoelzl@59425
  2091
definition "null_measure M = sigma (space M) (sets M)"
hoelzl@59425
  2092
hoelzl@59425
  2093
lemma space_null_measure[simp]: "space (null_measure M) = space M"
hoelzl@59425
  2094
  by (simp add: null_measure_def)
hoelzl@59425
  2095
lp15@61609
  2096
lemma sets_null_measure[simp, measurable_cong]: "sets (null_measure M) = sets M"
hoelzl@59425
  2097
  by (simp add: null_measure_def)
hoelzl@59425
  2098
hoelzl@59425
  2099
lemma emeasure_null_measure[simp]: "emeasure (null_measure M) X = 0"
hoelzl@59425
  2100
  by (cases "X \<in> sets M", rule emeasure_measure_of)
hoelzl@59425
  2101
     (auto simp: positive_def countably_additive_def emeasure_notin_sets null_measure_def
hoelzl@59425
  2102
           dest: sets.sets_into_space)
hoelzl@59425
  2103
hoelzl@59425
  2104
lemma measure_null_measure[simp]: "measure (null_measure M) X = 0"
hoelzl@62975
  2105
  by (intro measure_eq_emeasure_eq_ennreal) auto
hoelzl@59425
  2106
Andreas@61633
  2107
lemma null_measure_idem [simp]: "null_measure (null_measure M) = null_measure M"
hoelzl@62975
  2108
  by(rule measure_eqI) simp_all
Andreas@61633
  2109
Andreas@61634
  2110
subsection \<open>Scaling a measure\<close>
Andreas@61634
  2111
hoelzl@62975
  2112
definition scale_measure :: "ennreal \<Rightarrow> 'a measure \<Rightarrow> 'a measure"
hoelzl@62975
  2113
where
hoelzl@62975
  2114
  "scale_measure r M = measure_of (space M) (sets M) (\<lambda>A. r * emeasure M A)"
Andreas@61634
  2115
Andreas@61634
  2116
lemma space_scale_measure: "space (scale_measure r M) = space M"
hoelzl@62975
  2117
  by (simp add: scale_measure_def)
Andreas@61634
  2118
Andreas@61634
  2119
lemma sets_scale_measure [simp, measurable_cong]: "sets (scale_measure r M) = sets M"
hoelzl@62975
  2120
  by (simp add: scale_measure_def)
Andreas@61634
  2121
Andreas@61634
  2122
lemma emeasure_scale_measure [simp]:
hoelzl@62975
  2123
  "emeasure (scale_measure r M) A = r * emeasure M A"
Andreas@61634
  2124
  (is "_ = ?\<mu> A")
Andreas@61634
  2125
proof(cases "A \<in> sets M")
Andreas@61634
  2126
  case True
Andreas@61634
  2127
  show ?thesis unfolding scale_measure_def
Andreas@61634
  2128
  proof(rule emeasure_measure_of_sigma)
Andreas@61634
  2129
    show "sigma_algebra (space M) (sets M)" ..
hoelzl@62975
  2130
    show "positive (sets M) ?\<mu>" by (simp add: positive_def)
Andreas@61634
  2131
    show "countably_additive (sets M) ?\<mu>"
Andreas@61634
  2132
    proof (rule countably_additiveI)
Andreas@61634
  2133
      fix A :: "nat \<Rightarrow> _"  assume *: "range A \<subseteq> sets M" "disjoint_family A"
hoelzl@62975
  2134
      have "(\<Sum>i. ?\<mu> (A i)) = r * (\<Sum>i. emeasure M (A i))"
hoelzl@62975
  2135
        by simp
Andreas@61634
  2136
      also have "\<dots> = ?\<mu> (\<Union>i. A i)" using * by(simp add: suminf_emeasure)
Andreas@61634
  2137
      finally show "(\<Sum>i. ?\<mu> (A i)) = ?\<mu> (\<Union>i. A i)" .
Andreas@61634
  2138
    qed
Andreas@61634
  2139
  qed(fact True)
Andreas@61634
  2140
qed(simp add: emeasure_notin_sets)
Andreas@61634
  2141
hoelzl@62975
  2142
lemma scale_measure_1 [simp]: "scale_measure 1 M = M"
hoelzl@62975
  2143
  by(rule measure_eqI) simp_all
Andreas@61634
  2144
hoelzl@62975
  2145
lemma scale_measure_0[simp]: "scale_measure 0 M = null_measure M"
hoelzl@62975
  2146
  by(rule measure_eqI) simp_all
Andreas@61634
  2147
hoelzl@62975
  2148
lemma measure_scale_measure [simp]: "0 \<le> r \<Longrightarrow> measure (scale_measure r M) A = r * measure M A"
hoelzl@62975
  2149
  using emeasure_scale_measure[of r M A]
hoelzl@62975
  2150
    emeasure_eq_ennreal_measure[of M A]
hoelzl@62975
  2151
    measure_eq_emeasure_eq_ennreal[of _ "scale_measure r M" A]
hoelzl@62975
  2152
  by (cases "emeasure (scale_measure r M) A = top")
hoelzl@62975
  2153
     (auto simp del: emeasure_scale_measure
hoelzl@62975
  2154
           simp: ennreal_top_eq_mult_iff ennreal_mult_eq_top_iff measure_zero_top ennreal_mult[symmetric])
Andreas@61634
  2155
Andreas@61634
  2156
lemma scale_scale_measure [simp]:
hoelzl@62975
  2157
  "scale_measure r (scale_measure r' M) = scale_measure (r * r') M"
hoelzl@62975
  2158
  by (rule measure_eqI) (simp_all add: max_def mult.assoc)
Andreas@61634
  2159
Andreas@61634
  2160
lemma scale_null_measure [simp]: "scale_measure r (null_measure M) = null_measure M"
hoelzl@62975
  2161
  by (rule measure_eqI) simp_all
Andreas@61634
  2162
hoelzl@63333
  2163
hoelzl@63333
  2164
subsection \<open>Complete lattice structure on measures\<close>
hoelzl@63333
  2165
hoelzl@63333
  2166
lemma (in finite_measure) finite_measure_Diff':
hoelzl@63333
  2167
  "A \<in> sets M \<Longrightarrow> B \<in> sets M \<Longrightarrow> measure M (A - B) = measure M A - measure M (A \<inter> B)"
hoelzl@63333
  2168
  using finite_measure_Diff[of A "A \<inter> B"] by (auto simp: Diff_Int)
hoelzl@63333
  2169
hoelzl@63333
  2170
lemma (in finite_measure) finite_measure_Union':
hoelzl@63333
  2171
  "A \<in> sets M \<Longrightarrow> B \<in> sets M \<Longrightarrow> measure M (A \<union> B) = measure M A + measure M (B - A)"
hoelzl@63333
  2172
  using finite_measure_Union[of A "B - A"] by auto
hoelzl@63333
  2173
hoelzl@63333
  2174
lemma finite_unsigned_Hahn_decomposition:
hoelzl@63333
  2175
  assumes "finite_measure M" "finite_measure N" and [simp]: "sets N = sets M"
hoelzl@63333
  2176
  shows "\<exists>Y\<in>sets M. (\<forall>X\<in>sets M. X \<subseteq> Y \<longrightarrow> N X \<le> M X) \<and> (\<forall>X\<in>sets M. X \<inter> Y = {} \<longrightarrow> M X \<le> N X)"
hoelzl@63333
  2177
proof -
hoelzl@63333
  2178
  interpret M: finite_measure M by fact
hoelzl@63333
  2179
  interpret N: finite_measure N by fact
hoelzl@63333
  2180
hoelzl@63333
  2181
  define d where "d X = measure M X - measure N X" for X
hoelzl@63333
  2182
hoelzl@63333
  2183
  have [intro]: "bdd_above (d`sets M)"
hoelzl@63333
  2184
    using sets.sets_into_space[of _ M]
hoelzl@63333
  2185
    by (intro bdd_aboveI[where M="measure M (space M)"])
hoelzl@63333
  2186
       (auto simp: d_def field_simps subset_eq intro!: add_increasing M.finite_measure_mono)
hoelzl@63333
  2187
hoelzl@63333
  2188
  define \<gamma> where "\<gamma> = (SUP X:sets M. d X)"
hoelzl@63333
  2189
  have le_\<gamma>[intro]: "X \<in> sets M \<Longrightarrow> d X \<le> \<gamma>" for X
hoelzl@63333
  2190
    by (auto simp: \<gamma>_def intro!: cSUP_upper)
hoelzl@63333
  2191
hoelzl@63333
  2192
  have "\<exists>f. \<forall>n. f n \<in> sets M \<and> d (f n) > \<gamma> - 1 / 2^n"
hoelzl@63333
  2193
  proof (intro choice_iff[THEN iffD1] allI)
hoelzl@63333
  2194
    fix n
hoelzl@63333
  2195
    have "\<exists>X\<in>sets M. \<gamma> - 1 / 2^n < d X"
hoelzl@63333
  2196
      unfolding \<gamma>_def by (intro less_cSUP_iff[THEN iffD1]) auto
hoelzl@63333
  2197
    then show "\<exists>y. y \<in> sets M \<and> \<gamma> - 1 / 2 ^ n < d y"
hoelzl@63333
  2198
      by auto
hoelzl@63333
  2199
  qed
hoelzl@63333
  2200
  then obtain E where [measurable]: "E n \<in> sets M" and E: "d (E n) > \<gamma> - 1 / 2^n" for n
hoelzl@63333
  2201
    by auto
hoelzl@63333
  2202
hoelzl@63333
  2203
  define F where "F m n = (if m \<le> n then \<Inter>i\<in>{m..n}. E i else space M)" for m n
hoelzl@63333
  2204
hoelzl@63333
  2205
  have [measurable]: "m \<le> n \<Longrightarrow> F m n \<in> sets M" for m n
hoelzl@63333
  2206
    by (auto simp: F_def)
hoelzl@63333
  2207
hoelzl@63333
  2208
  have 1: "\<gamma> - 2 / 2 ^ m + 1 / 2 ^ n \<le> d (F m n)" if "m \<le> n" for m n
hoelzl@63333
  2209
    using that
hoelzl@63333
  2210
  proof (induct rule: dec_induct)
hoelzl@63333
  2211
    case base with E[of m] show ?case
hoelzl@63333
  2212
      by (simp add: F_def field_simps)
hoelzl@63333
  2213
  next
hoelzl@63333
  2214
    case (step i)
hoelzl@63333
  2215
    have F_Suc: "F m (Suc i) = F m i \<inter> E (Suc i)"
hoelzl@63333
  2216
      using \<open>m \<le> i\<close> by (auto simp: F_def le_Suc_eq)
hoelzl@63333
  2217
hoelzl@63333
  2218
    have "\<gamma> + (\<gamma> - 2 / 2^m + 1 / 2 ^ Suc i) \<le> (\<gamma> - 1 / 2^Suc i) + (\<gamma> - 2 / 2^m + 1 / 2^i)"
hoelzl@63333
  2219
      by (simp add: field_simps)
hoelzl@63333
  2220
    also have "\<dots> \<le> d (E (Suc i)) + d (F m i)"
hoelzl@63333
  2221
      using E[of "Suc i"] by (intro add_mono step) auto
hoelzl@63333
  2222
    also have "\<dots> = d (E (Suc i)) + d (F m i - E (Suc i)) + d (F m (Suc i))"
hoelzl@63333
  2223
      using \<open>m \<le> i\<close> by (simp add: d_def field_simps F_Suc M.finite_measure_Diff' N.finite_measure_Diff')
hoelzl@63333
  2224
    also have "\<dots> = d (E (Suc i) \<union> F m i) + d (F m (Suc i))"
hoelzl@63333
  2225
      using \<open>m \<le> i\<close> by (simp add: d_def field_simps M.finite_measure_Union' N.finite_measure_Union')
hoelzl@63333
  2226
    also have "\<dots> \<le> \<gamma> + d (F m (Suc i))"
hoelzl@63333
  2227
      using \<open>m \<le> i\<close> by auto
hoelzl@63333
  2228
    finally show ?case
hoelzl@63333
  2229
      by auto
hoelzl@63333
  2230
  qed
hoelzl@63333
  2231
hoelzl@63333
  2232
  define F' where "F' m = (\<Inter>i\<in>{m..}. E i)" for m
hoelzl@63333
  2233
  have F'_eq: "F' m = (\<Inter>i. F m (i + m))" for m
hoelzl@63333
  2234
    by (fastforce simp: le_iff_add[of m] F'_def F_def)
hoelzl@63333
  2235
hoelzl@63333
  2236
  have [measurable]: "F' m \<in> sets M" for m
hoelzl@63333
  2237
    by (auto simp: F'_def)
hoelzl@63333
  2238
hoelzl@63333
  2239
  have \<gamma>_le: "\<gamma> - 0 \<le> d (\<Union>m. F' m)"
hoelzl@63333
  2240
  proof (rule LIMSEQ_le)
hoelzl@63333
  2241
    show "(\<lambda>n. \<gamma> - 2 / 2 ^ n) \<longlonglongrightarrow> \<gamma> - 0"
hoelzl@63333
  2242
      by (intro tendsto_intros LIMSEQ_divide_realpow_zero) auto
hoelzl@63333
  2243
    have "incseq F'"
hoelzl@63333
  2244
      by (auto simp: incseq_def F'_def)
hoelzl@63333
  2245
    then show "(\<lambda>m. d (F' m)) \<longlonglongrightarrow> d (\<Union>m. F' m)"
hoelzl@63333
  2246
      unfolding d_def
hoelzl@63333
  2247
      by (intro tendsto_diff M.finite_Lim_measure_incseq N.finite_Lim_measure_incseq) auto
hoelzl@63333
  2248
hoelzl@63333
  2249
    have "\<gamma> - 2 / 2 ^ m + 0 \<le> d (F' m)" for m
hoelzl@63333
  2250
    proof (rule LIMSEQ_le)
hoelzl@63333
  2251
      have *: "decseq (\<lambda>n. F m (n + m))"
hoelzl@63333
  2252
        by (auto simp: decseq_def F_def)
hoelzl@63333
  2253
      show "(\<lambda>n. d (F m n)) \<longlonglongrightarrow> d (F' m)"
hoelzl@63333
  2254
        unfolding d_def F'_eq
hoelzl@63333
  2255
        by (rule LIMSEQ_offset[where k=m])
hoelzl@63333
  2256
           (auto intro!: tendsto_diff M.finite_Lim_measure_decseq N.finite_Lim_measure_decseq *)
hoelzl@63333
  2257
      show "(\<lambda>n. \<gamma> - 2 / 2 ^ m + 1 / 2 ^ n) \<longlonglongrightarrow> \<gamma> - 2 / 2 ^ m + 0"
hoelzl@63333
  2258
        by (intro tendsto_add LIMSEQ_divide_realpow_zero tendsto_const) auto
hoelzl@63333
  2259
      show "\<exists>N. \<forall>n\<ge>N. \<gamma> - 2 / 2 ^ m + 1 / 2 ^ n \<le> d (F m n)"
hoelzl@63333
  2260
        using 1[of m] by (intro exI[of _ m]) auto
hoelzl@63333
  2261
    qed
hoelzl@63333
  2262
    then show "\<exists>N. \<forall>n\<ge>N. \<gamma> - 2 / 2 ^ n \<le> d (F' n)"
hoelzl@63333
  2263
      by auto
hoelzl@63333
  2264
  qed
hoelzl@63333
  2265
hoelzl@63333
  2266
  show ?thesis
hoelzl@63333
  2267
  proof (safe intro!: bexI[of _ "\<Union>m. F' m"])
hoelzl@63333
  2268
    fix X assume [measurable]: "X \<in> sets M" and X: "X \<subseteq> (\<Union>m. F' m)"
hoelzl@63333
  2269
    have "d (\<Union>m. F' m) - d X = d ((\<Union>m. F' m) - X)"
hoelzl@63333
  2270
      using X by (auto simp: d_def M.finite_measure_Diff N.finite_measure_Diff)
hoelzl@63333
  2271
    also have "\<dots> \<le> \<gamma>"
hoelzl@63333
  2272
      by auto
hoelzl@63333
  2273
    finally have "0 \<le> d X"
hoelzl@63333
  2274
      using \<gamma>_le by auto
hoelzl@63333
  2275
    then show "emeasure N X \<le> emeasure M X"
hoelzl@63333
  2276
      by (auto simp: d_def M.emeasure_eq_measure N.emeasure_eq_measure)
hoelzl@63333
  2277
  next
hoelzl@63333
  2278
    fix X assume [measurable]: "X \<in> sets M" and X: "X \<inter> (\<Union>m. F' m) = {}"
hoelzl@63333
  2279
    then have "d (\<Union>m. F' m) + d X = d (X \<union> (\<Union>m. F' m))"
hoelzl@63333
  2280
      by (auto simp: d_def M.finite_measure_Union N.finite_measure_Union)
hoelzl@63333
  2281
    also have "\<dots> \<le> \<gamma>"
hoelzl@63333
  2282
      by auto
hoelzl@63333
  2283
    finally have "d X \<le> 0"
hoelzl@63333
  2284
      using \<gamma>_le by auto
hoelzl@63333
  2285
    then show "emeasure M X \<le> emeasure N X"
hoelzl@63333
  2286
      by (auto simp: d_def M.emeasure_eq_measure N.emeasure_eq_measure)
hoelzl@63333
  2287
  qed auto
hoelzl@63333
  2288
qed
hoelzl@63333
  2289
hoelzl@63333
  2290
lemma unsigned_Hahn_decomposition:
hoelzl@63333
  2291
  assumes [simp]: "sets N = sets M" and [measurable]: "A \<in> sets M"
hoelzl@63333
  2292
    and [simp]: "emeasure M A \<noteq> top" "emeasure N A \<noteq> top"
hoelzl@63333
  2293
  shows "\<exists>Y\<in>sets M. Y \<subseteq> A \<and> (\<forall>X\<in>sets M. X \<subseteq> Y \<longrightarrow> N X \<le> M X) \<and> (\<forall>X\<in>sets M. X \<subseteq> A \<longrightarrow> X \<inter> Y = {} \<longrightarrow> M X \<le> N X)"
hoelzl@63333
  2294
proof -
hoelzl@63333
  2295
  have "\<exists>Y\<in>sets (restrict_space M A).
hoelzl@63333
  2296
    (\<forall>X\<in>sets (restrict_space M A). X \<subseteq> Y \<longrightarrow> (restrict_space N A) X \<le> (restrict_space M A) X) \<and>
hoelzl@63333
  2297
    (\<forall>X\<in>sets (restrict_space M A). X \<inter> Y = {} \<longrightarrow> (restrict_space M A) X \<le> (restrict_space N A) X)"
hoelzl@63333
  2298
  proof (rule finite_unsigned_Hahn_decomposition)
hoelzl@63333
  2299
    show "finite_measure (restrict_space M A)" "finite_measure (restrict_space N A)"
hoelzl@63333
  2300
      by (auto simp: space_restrict_space emeasure_restrict_space less_top intro!: finite_measureI)
hoelzl@63333
  2301
  qed (simp add: sets_restrict_space)
hoelzl@63333
  2302
  then guess Y ..
hoelzl@63333
  2303
  then show ?thesis
hoelzl@63333
  2304
    apply (intro bexI[of _ Y] conjI ballI conjI)
hoelzl@63333
  2305
    apply (simp_all add: sets_restrict_space emeasure_restrict_space)
hoelzl@63333
  2306
    apply safe
hoelzl@63333
  2307
    subgoal for X Z
hoelzl@63333
  2308
      by (erule ballE[of _ _ X]) (auto simp add: Int_absorb1)
hoelzl@63333
  2309
    subgoal for X Z
hoelzl@63333
  2310
      by (erule ballE[of _ _ X])  (auto simp add: Int_absorb1 ac_simps)
hoelzl@63333
  2311
    apply auto
hoelzl@63333
  2312
    done
hoelzl@63333
  2313
qed
hoelzl@63333
  2314
hoelzl@63333
  2315
text \<open>
hoelzl@63333
  2316
  Define a lexicographical order on @{type measure}, in the order space, sets and measure. The parts
hoelzl@63333
  2317
  of the lexicographical order are point-wise ordered.
hoelzl@63333
  2318
\<close>
hoelzl@60772
  2319
hoelzl@60772
  2320
instantiation measure :: (type) order_bot
hoelzl@60772
  2321
begin
hoelzl@60772
  2322
hoelzl@60772
  2323
inductive less_eq_measure :: "'a measure \<Rightarrow> 'a measure \<Rightarrow> bool" where
hoelzl@63333
  2324
  "space M \<subset> space N \<Longrightarrow> less_eq_measure M N"
hoelzl@63333
  2325
| "space M = space N \<Longrightarrow> sets M \<subset> sets N \<Longrightarrow> less_eq_measure M N"
hoelzl@63333
  2326
| "space M = space N \<Longrightarrow> sets M = sets N \<Longrightarrow> emeasure M \<le> emeasure N \<Longrightarrow> less_eq_measure M N"
hoelzl@63333
  2327
hoelzl@63333
  2328
lemma le_measure_iff:
hoelzl@63333
  2329
  "M \<le> N \<longleftrightarrow> (if space M = space N then
hoelzl@63333
  2330
    if sets M = sets N then emeasure M \<le> emeasure N else sets M \<subseteq> sets N else space M \<subseteq> space N)"
hoelzl@63333
  2331
  by (auto elim: less_eq_measure.cases intro: less_eq_measure.intros)
hoelzl@60772
  2332
hoelzl@60772
  2333
definition less_measure :: "'a measure \<Rightarrow> 'a measure \<Rightarrow> bool" where
hoelzl@60772
  2334
  "less_measure M N \<longleftrightarrow> (M \<le> N \<and> \<not> N \<le> M)"
hoelzl@60772
  2335
hoelzl@63333
  2336
definition bot_measure :: "'a measure" where
hoelzl@63333
  2337
  "bot_measure = sigma {} {}"
hoelzl@60772
  2338
hoelzl@60772
  2339
lemma
hoelzl@63333
  2340
  shows space_bot[simp]: "space bot = {}"
hoelzl@63333
  2341
    and sets_bot[simp]: "sets bot = {{}}"
hoelzl@63333
  2342
    and emeasure_bot[simp]: "emeasure bot X = 0"
hoelzl@63333
  2343
  by (auto simp: bot_measure_def sigma_sets_empty_eq emeasure_sigma)
hoelzl@63333
  2344
hoelzl@63333
  2345
instance
hoelzl@63333
  2346
proof standard
hoelzl@63333
  2347
  show "bot \<le> a" for a :: "'a measure"
hoelzl@63333
  2348
    by (simp add: le_measure_iff bot_measure_def sigma_sets_empty_eq emeasure_sigma le_fun_def)
hoelzl@63333
  2349
qed (auto simp: le_measure_iff less_measure_def split: if_split_asm intro: measure_eqI)
hoelzl@63333
  2350
hoelzl@63333
  2351
end
hoelzl@63333
  2352
hoelzl@63333
  2353
lemma le_measure: "sets M = sets N \<Longrightarrow> M \<le> N \<longleftrightarrow> (\<forall>A\<in>sets M. emeasure M A \<le> emeasure N A)"
hoelzl@63333
  2354
  apply (auto simp: le_measure_iff le_fun_def dest: sets_eq_imp_space_eq)
hoelzl@63333
  2355
  subgoal for X
hoelzl@63333
  2356
    by (cases "X \<in> sets M") (auto simp: emeasure_notin_sets)
hoelzl@63333
  2357
  done
hoelzl@63333
  2358
hoelzl@63333
  2359
definition sup_measure' :: "'a measure \<Rightarrow> 'a measure \<Rightarrow> 'a measure"
hoelzl@63333
  2360
where
hoelzl@63333
  2361
  "sup_measure' A B = measure_of (space A) (sets A) (\<lambda>X. SUP Y:sets A. emeasure A (X \<inter> Y) + emeasure B (X \<inter> -