src/HOL/Probability/Caratheodory.thy
author hoelzl
Mon Sep 28 17:29:01 2015 +0200 (2015-09-28)
changeset 61273 542a4d9bac96
parent 61032 b57df8eecad6
child 61424 c3658c18b7bc
permissions -rw-r--r--
Caratheodory: cleanup and modernisation
hoelzl@42067
     1
(*  Title:      HOL/Probability/Caratheodory.thy
hoelzl@42067
     2
    Author:     Lawrence C Paulson
hoelzl@42067
     3
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     4
*)
hoelzl@42067
     5
wenzelm@58876
     6
section {*Caratheodory Extension Theorem*}
paulson@33271
     7
paulson@33271
     8
theory Caratheodory
hoelzl@47694
     9
  imports Measure_Space
paulson@33271
    10
begin
paulson@33271
    11
hoelzl@42067
    12
text {*
hoelzl@42067
    13
  Originally from the Hurd/Coble measure theory development, translated by Lawrence Paulson.
hoelzl@42067
    14
*}
hoelzl@42067
    15
hoelzl@43920
    16
lemma suminf_ereal_2dimen:
hoelzl@43920
    17
  fixes f:: "nat \<times> nat \<Rightarrow> ereal"
hoelzl@41981
    18
  assumes pos: "\<And>p. 0 \<le> f p"
hoelzl@41981
    19
  assumes "\<And>m. g m = (\<Sum>n. f (m,n))"
hoelzl@41981
    20
  shows "(\<Sum>i. f (prod_decode i)) = suminf g"
hoelzl@41981
    21
proof -
hoelzl@41981
    22
  have g_def: "g = (\<lambda>m. (\<Sum>n. f (m,n)))"
hoelzl@41981
    23
    using assms by (simp add: fun_eq_iff)
hoelzl@41981
    24
  have reindex: "\<And>B. (\<Sum>x\<in>B. f (prod_decode x)) = setsum f (prod_decode ` B)"
haftmann@57418
    25
    by (simp add: setsum.reindex[OF inj_prod_decode] comp_def)
hoelzl@41981
    26
  { fix n
hoelzl@41981
    27
    let ?M = "\<lambda>f. Suc (Max (f ` prod_decode ` {..<n}))"
hoelzl@41981
    28
    { fix a b x assume "x < n" and [symmetric]: "(a, b) = prod_decode x"
hoelzl@41981
    29
      then have "a < ?M fst" "b < ?M snd"
hoelzl@41981
    30
        by (auto intro!: Max_ge le_imp_less_Suc image_eqI) }
hoelzl@41981
    31
    then have "setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<?M fst} \<times> {..<?M snd})"
hoelzl@41981
    32
      by (auto intro!: setsum_mono3 simp: pos)
hoelzl@41981
    33
    then have "\<exists>a b. setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<a} \<times> {..<b})" by auto }
hoelzl@41981
    34
  moreover
hoelzl@41981
    35
  { fix a b
hoelzl@41981
    36
    let ?M = "prod_decode ` {..<Suc (Max (prod_encode ` ({..<a} \<times> {..<b})))}"
hoelzl@41981
    37
    { fix a' b' assume "a' < a" "b' < b" then have "(a', b') \<in> ?M"
hoelzl@41981
    38
        by (auto intro!: Max_ge le_imp_less_Suc image_eqI[where x="prod_encode (a', b')"]) }
hoelzl@41981
    39
    then have "setsum f ({..<a} \<times> {..<b}) \<le> setsum f ?M"
hoelzl@41981
    40
      by (auto intro!: setsum_mono3 simp: pos) }
hoelzl@41981
    41
  ultimately
hoelzl@41981
    42
  show ?thesis unfolding g_def using pos
haftmann@57418
    43
    by (auto intro!: SUP_eq  simp: setsum.cartesian_product reindex SUP_upper2
hoelzl@61273
    44
                     suminf_ereal_eq_SUP SUP_pair
haftmann@56212
    45
                     SUP_ereal_setsum[symmetric] incseq_setsumI setsum_nonneg)
hoelzl@41981
    46
qed
hoelzl@41981
    47
hoelzl@56994
    48
subsection {* Characterizations of Measures *}
paulson@33271
    49
hoelzl@61273
    50
definition subadditive where
hoelzl@61273
    51
  "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@41689
    52
hoelzl@61273
    53
definition countably_subadditive where
hoelzl@61273
    54
  "countably_subadditive M f \<longleftrightarrow>
hoelzl@61273
    55
    (\<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@41689
    56
hoelzl@61273
    57
definition outer_measure_space where
hoelzl@61273
    58
  "outer_measure_space M f \<longleftrightarrow> positive M f \<and> increasing M f \<and> countably_subadditive M f"
paulson@33271
    59
hoelzl@61273
    60
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"
paulson@33271
    61
  by (auto simp add: subadditive_def)
paulson@33271
    62
hoelzl@56994
    63
subsubsection {* Lambda Systems *}
hoelzl@56994
    64
hoelzl@61273
    65
definition lambda_system where
hoelzl@61273
    66
  "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (l \<inter> x) + f ((\<Omega> - l) \<inter> x) = f x}"
paulson@33271
    67
paulson@33271
    68
lemma (in algebra) lambda_system_eq:
hoelzl@61273
    69
  "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (x \<inter> l) + f (x - l) = f x}"
paulson@33271
    70
proof -
hoelzl@61273
    71
  have [simp]: "\<And>l x. l \<in> M \<Longrightarrow> x \<in> M \<Longrightarrow> (\<Omega> - l) \<inter> x = x - l"
huffman@37032
    72
    by (metis Int_Diff Int_absorb1 Int_commute sets_into_space)
paulson@33271
    73
  show ?thesis
huffman@37032
    74
    by (auto simp add: lambda_system_def) (metis Int_commute)+
paulson@33271
    75
qed
paulson@33271
    76
hoelzl@61273
    77
lemma (in algebra) lambda_system_empty: "positive M f \<Longrightarrow> {} \<in> lambda_system \<Omega> M f"
hoelzl@42066
    78
  by (auto simp add: positive_def lambda_system_eq)
paulson@33271
    79
hoelzl@61273
    80
lemma lambda_system_sets: "x \<in> lambda_system \<Omega> M f \<Longrightarrow> x \<in> M"
hoelzl@41689
    81
  by (simp add: lambda_system_def)
paulson@33271
    82
paulson@33271
    83
lemma (in algebra) lambda_system_Compl:
hoelzl@43920
    84
  fixes f:: "'a set \<Rightarrow> ereal"
hoelzl@47694
    85
  assumes x: "x \<in> lambda_system \<Omega> M f"
hoelzl@47694
    86
  shows "\<Omega> - x \<in> lambda_system \<Omega> M f"
hoelzl@41689
    87
proof -
hoelzl@47694
    88
  have "x \<subseteq> \<Omega>"
hoelzl@41689
    89
    by (metis sets_into_space lambda_system_sets x)
hoelzl@47694
    90
  hence "\<Omega> - (\<Omega> - x) = x"
hoelzl@41689
    91
    by (metis double_diff equalityE)
hoelzl@41689
    92
  with x show ?thesis
hoelzl@41689
    93
    by (force simp add: lambda_system_def ac_simps)
hoelzl@41689
    94
qed
paulson@33271
    95
paulson@33271
    96
lemma (in algebra) lambda_system_Int:
hoelzl@43920
    97
  fixes f:: "'a set \<Rightarrow> ereal"
hoelzl@47694
    98
  assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
hoelzl@47694
    99
  shows "x \<inter> y \<in> lambda_system \<Omega> M f"
hoelzl@41689
   100
proof -
hoelzl@41689
   101
  from xl yl show ?thesis
hoelzl@41689
   102
  proof (auto simp add: positive_def lambda_system_eq Int)
hoelzl@41689
   103
    fix u
hoelzl@47694
   104
    assume x: "x \<in> M" and y: "y \<in> M" and u: "u \<in> M"
hoelzl@47694
   105
       and fx: "\<forall>z\<in>M. f (z \<inter> x) + f (z - x) = f z"
hoelzl@47694
   106
       and fy: "\<forall>z\<in>M. f (z \<inter> y) + f (z - y) = f z"
hoelzl@47694
   107
    have "u - x \<inter> y \<in> M"
hoelzl@41689
   108
      by (metis Diff Diff_Int Un u x y)
hoelzl@41689
   109
    moreover
hoelzl@41689
   110
    have "(u - (x \<inter> y)) \<inter> y = u \<inter> y - x" by blast
hoelzl@41689
   111
    moreover
hoelzl@41689
   112
    have "u - x \<inter> y - y = u - y" by blast
hoelzl@41689
   113
    ultimately
hoelzl@41689
   114
    have ey: "f (u - x \<inter> y) = f (u \<inter> y - x) + f (u - y)" using fy
hoelzl@41689
   115
      by force
hoelzl@41689
   116
    have "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y)
hoelzl@41689
   117
          = (f (u \<inter> (x \<inter> y)) + f (u \<inter> y - x)) + f (u - y)"
hoelzl@41689
   118
      by (simp add: ey ac_simps)
hoelzl@41689
   119
    also have "... =  (f ((u \<inter> y) \<inter> x) + f (u \<inter> y - x)) + f (u - y)"
hoelzl@41689
   120
      by (simp add: Int_ac)
hoelzl@41689
   121
    also have "... = f (u \<inter> y) + f (u - y)"
hoelzl@41689
   122
      using fx [THEN bspec, of "u \<inter> y"] Int y u
hoelzl@41689
   123
      by force
hoelzl@41689
   124
    also have "... = f u"
hoelzl@41689
   125
      by (metis fy u)
hoelzl@41689
   126
    finally show "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y) = f u" .
paulson@33271
   127
  qed
hoelzl@41689
   128
qed
paulson@33271
   129
paulson@33271
   130
lemma (in algebra) lambda_system_Un:
hoelzl@43920
   131
  fixes f:: "'a set \<Rightarrow> ereal"
hoelzl@47694
   132
  assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
hoelzl@47694
   133
  shows "x \<union> y \<in> lambda_system \<Omega> M f"
paulson@33271
   134
proof -
hoelzl@47694
   135
  have "(\<Omega> - x) \<inter> (\<Omega> - y) \<in> M"
hoelzl@38656
   136
    by (metis Diff_Un Un compl_sets lambda_system_sets xl yl)
paulson@33271
   137
  moreover
hoelzl@47694
   138
  have "x \<union> y = \<Omega> - ((\<Omega> - x) \<inter> (\<Omega> - y))"
wenzelm@46731
   139
    by auto (metis subsetD lambda_system_sets sets_into_space xl yl)+
paulson@33271
   140
  ultimately show ?thesis
hoelzl@38656
   141
    by (metis lambda_system_Compl lambda_system_Int xl yl)
paulson@33271
   142
qed
paulson@33271
   143
paulson@33271
   144
lemma (in algebra) lambda_system_algebra:
hoelzl@47694
   145
  "positive M f \<Longrightarrow> algebra \<Omega> (lambda_system \<Omega> M f)"
hoelzl@42065
   146
  apply (auto simp add: algebra_iff_Un)
paulson@33271
   147
  apply (metis lambda_system_sets set_mp sets_into_space)
paulson@33271
   148
  apply (metis lambda_system_empty)
paulson@33271
   149
  apply (metis lambda_system_Compl)
hoelzl@38656
   150
  apply (metis lambda_system_Un)
paulson@33271
   151
  done
paulson@33271
   152
paulson@33271
   153
lemma (in algebra) lambda_system_strong_additive:
hoelzl@47694
   154
  assumes z: "z \<in> M" and disj: "x \<inter> y = {}"
hoelzl@47694
   155
      and xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
paulson@33271
   156
  shows "f (z \<inter> (x \<union> y)) = f (z \<inter> x) + f (z \<inter> y)"
hoelzl@41689
   157
proof -
hoelzl@41689
   158
  have "z \<inter> x = (z \<inter> (x \<union> y)) \<inter> x" using disj by blast
hoelzl@41689
   159
  moreover
hoelzl@41689
   160
  have "z \<inter> y = (z \<inter> (x \<union> y)) - x" using disj by blast
hoelzl@41689
   161
  moreover
hoelzl@47694
   162
  have "(z \<inter> (x \<union> y)) \<in> M"
hoelzl@41689
   163
    by (metis Int Un lambda_system_sets xl yl z)
hoelzl@41689
   164
  ultimately show ?thesis using xl yl
hoelzl@41689
   165
    by (simp add: lambda_system_eq)
hoelzl@41689
   166
qed
paulson@33271
   167
hoelzl@47694
   168
lemma (in algebra) lambda_system_additive: "additive (lambda_system \<Omega> M f) f"
hoelzl@41689
   169
proof (auto simp add: additive_def)
hoelzl@41689
   170
  fix x and y
hoelzl@41689
   171
  assume disj: "x \<inter> y = {}"
hoelzl@47694
   172
     and xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
hoelzl@47694
   173
  hence  "x \<in> M" "y \<in> M" by (blast intro: lambda_system_sets)+
hoelzl@41689
   174
  thus "f (x \<union> y) = f x + f y"
hoelzl@41689
   175
    using lambda_system_strong_additive [OF top disj xl yl]
hoelzl@41689
   176
    by (simp add: Un)
hoelzl@41689
   177
qed
paulson@33271
   178
hoelzl@42145
   179
lemma (in ring_of_sets) countably_subadditive_subadditive:
hoelzl@41689
   180
  assumes f: "positive M f" and cs: "countably_subadditive M f"
paulson@33271
   181
  shows  "subadditive M f"
hoelzl@35582
   182
proof (auto simp add: subadditive_def)
paulson@33271
   183
  fix x y
hoelzl@47694
   184
  assume x: "x \<in> M" and y: "y \<in> M" and "x \<inter> y = {}"
paulson@33271
   185
  hence "disjoint_family (binaryset x y)"
hoelzl@35582
   186
    by (auto simp add: disjoint_family_on_def binaryset_def)
hoelzl@47694
   187
  hence "range (binaryset x y) \<subseteq> M \<longrightarrow>
hoelzl@47694
   188
         (\<Union>i. binaryset x y i) \<in> M \<longrightarrow>
hoelzl@41981
   189
         f (\<Union>i. binaryset x y i) \<le> (\<Sum> n. f (binaryset x y n))"
hoelzl@41981
   190
    using cs by (auto simp add: countably_subadditive_def)
hoelzl@47694
   191
  hence "{x,y,{}} \<subseteq> M \<longrightarrow> x \<union> y \<in> M \<longrightarrow>
hoelzl@41981
   192
         f (x \<union> y) \<le> (\<Sum> n. f (binaryset x y n))"
paulson@33271
   193
    by (simp add: range_binaryset_eq UN_binaryset_eq)
hoelzl@38656
   194
  thus "f (x \<union> y) \<le>  f x + f y" using f x y
hoelzl@41981
   195
    by (auto simp add: Un o_def suminf_binaryset_eq positive_def)
paulson@33271
   196
qed
paulson@33271
   197
hoelzl@61273
   198
lemma lambda_system_increasing: "increasing M f \<Longrightarrow> increasing (lambda_system \<Omega> M f) f"
hoelzl@38656
   199
  by (simp add: increasing_def lambda_system_def)
paulson@33271
   200
hoelzl@61273
   201
lemma lambda_system_positive: "positive M f \<Longrightarrow> positive (lambda_system \<Omega> M f) f"
hoelzl@41689
   202
  by (simp add: positive_def lambda_system_def)
hoelzl@41689
   203
paulson@33271
   204
lemma (in algebra) lambda_system_strong_sum:
hoelzl@43920
   205
  fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> ereal"
hoelzl@47694
   206
  assumes f: "positive M f" and a: "a \<in> M"
hoelzl@47694
   207
      and A: "range A \<subseteq> lambda_system \<Omega> M f"
paulson@33271
   208
      and disj: "disjoint_family A"
paulson@33271
   209
  shows  "(\<Sum>i = 0..<n. f (a \<inter>A i)) = f (a \<inter> (\<Union>i\<in>{0..<n}. A i))"
paulson@33271
   210
proof (induct n)
hoelzl@38656
   211
  case 0 show ?case using f by (simp add: positive_def)
paulson@33271
   212
next
hoelzl@38656
   213
  case (Suc n)
paulson@33271
   214
  have 2: "A n \<inter> UNION {0..<n} A = {}" using disj
hoelzl@38656
   215
    by (force simp add: disjoint_family_on_def neq_iff)
hoelzl@47694
   216
  have 3: "A n \<in> lambda_system \<Omega> M f" using A
paulson@33271
   217
    by blast
hoelzl@47694
   218
  interpret l: algebra \<Omega> "lambda_system \<Omega> M f"
hoelzl@42065
   219
    using f by (rule lambda_system_algebra)
hoelzl@47694
   220
  have 4: "UNION {0..<n} A \<in> lambda_system \<Omega> M f"
hoelzl@42065
   221
    using A l.UNION_in_sets by simp
paulson@33271
   222
  from Suc.hyps show ?case
paulson@33271
   223
    by (simp add: atLeastLessThanSuc lambda_system_strong_additive [OF a 2 3 4])
paulson@33271
   224
qed
paulson@33271
   225
paulson@33271
   226
lemma (in sigma_algebra) lambda_system_caratheodory:
paulson@33271
   227
  assumes oms: "outer_measure_space M f"
hoelzl@47694
   228
      and A: "range A \<subseteq> lambda_system \<Omega> M f"
paulson@33271
   229
      and disj: "disjoint_family A"
hoelzl@47694
   230
  shows  "(\<Union>i. A i) \<in> lambda_system \<Omega> M f \<and> (\<Sum>i. f (A i)) = f (\<Union>i. A i)"
paulson@33271
   231
proof -
hoelzl@41689
   232
  have pos: "positive M f" and inc: "increasing M f"
hoelzl@38656
   233
   and csa: "countably_subadditive M f"
paulson@33271
   234
    by (metis oms outer_measure_space_def)+
paulson@33271
   235
  have sa: "subadditive M f"
hoelzl@38656
   236
    by (metis countably_subadditive_subadditive csa pos)
hoelzl@47694
   237
  have A': "\<And>S. A`S \<subseteq> (lambda_system \<Omega> M f)" using A
hoelzl@47694
   238
    by auto
hoelzl@47694
   239
  interpret ls: algebra \<Omega> "lambda_system \<Omega> M f"
hoelzl@42065
   240
    using pos by (rule lambda_system_algebra)
hoelzl@47694
   241
  have A'': "range A \<subseteq> M"
paulson@33271
   242
     by (metis A image_subset_iff lambda_system_sets)
hoelzl@38656
   243
hoelzl@47694
   244
  have U_in: "(\<Union>i. A i) \<in> M"
huffman@37032
   245
    by (metis A'' countable_UN)
hoelzl@41981
   246
  have U_eq: "f (\<Union>i. A i) = (\<Sum>i. f (A i))"
hoelzl@41689
   247
  proof (rule antisym)
hoelzl@41981
   248
    show "f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))"
hoelzl@41981
   249
      using csa[unfolded countably_subadditive_def] A'' disj U_in by auto
hoelzl@41981
   250
    have *: "\<And>i. 0 \<le> f (A i)" using pos A'' unfolding positive_def by auto
hoelzl@41981
   251
    have dis: "\<And>N. disjoint_family_on A {..<N}" by (intro disjoint_family_on_mono[OF _ disj]) auto
hoelzl@41981
   252
    show "(\<Sum>i. f (A i)) \<le> f (\<Union>i. A i)"
hoelzl@61273
   253
      using ls.additive_sum [OF lambda_system_positive[OF pos] lambda_system_additive _ A' dis] A''
hoelzl@47694
   254
      by (intro suminf_bound[OF _ *]) (auto intro!: increasingD[OF inc] countable_UN)
hoelzl@41689
   255
  qed
hoelzl@61273
   256
  have "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) = f a"
hoelzl@61273
   257
    if a [iff]: "a \<in> M" for a
hoelzl@61273
   258
  proof (rule antisym)
hoelzl@61273
   259
    have "range (\<lambda>i. a \<inter> A i) \<subseteq> M" using A''
hoelzl@61273
   260
      by blast
hoelzl@61273
   261
    moreover
hoelzl@61273
   262
    have "disjoint_family (\<lambda>i. a \<inter> A i)" using disj
hoelzl@61273
   263
      by (auto simp add: disjoint_family_on_def)
hoelzl@61273
   264
    moreover
hoelzl@61273
   265
    have "a \<inter> (\<Union>i. A i) \<in> M"
hoelzl@61273
   266
      by (metis Int U_in a)
hoelzl@61273
   267
    ultimately
hoelzl@61273
   268
    have "f (a \<inter> (\<Union>i. A i)) \<le> (\<Sum>i. f (a \<inter> A i))"
hoelzl@61273
   269
      using csa[unfolded countably_subadditive_def, rule_format, of "(\<lambda>i. a \<inter> A i)"]
hoelzl@61273
   270
      by (simp add: o_def)
hoelzl@61273
   271
    hence "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> (\<Sum>i. f (a \<inter> A i)) + f (a - (\<Union>i. A i))"
hoelzl@61273
   272
      by (rule add_right_mono)
hoelzl@61273
   273
    also have "\<dots> \<le> f a"
hoelzl@61273
   274
    proof (intro suminf_bound_add allI)
hoelzl@61273
   275
      fix n
hoelzl@61273
   276
      have UNION_in: "(\<Union>i\<in>{0..<n}. A i) \<in> M"
hoelzl@61273
   277
        by (metis A'' UNION_in_sets)
hoelzl@61273
   278
      have le_fa: "f (UNION {0..<n} A \<inter> a) \<le> f a" using A''
hoelzl@61273
   279
        by (blast intro: increasingD [OF inc] A'' UNION_in_sets)
hoelzl@61273
   280
      have ls: "(\<Union>i\<in>{0..<n}. A i) \<in> lambda_system \<Omega> M f"
hoelzl@61273
   281
        using ls.UNION_in_sets by (simp add: A)
hoelzl@61273
   282
      hence eq_fa: "f a = f (a \<inter> (\<Union>i\<in>{0..<n}. A i)) + f (a - (\<Union>i\<in>{0..<n}. A i))"
hoelzl@61273
   283
        by (simp add: lambda_system_eq UNION_in)
hoelzl@61273
   284
      have "f (a - (\<Union>i. A i)) \<le> f (a - (\<Union>i\<in>{0..<n}. A i))"
hoelzl@61273
   285
        by (blast intro: increasingD [OF inc] UNION_in U_in)
hoelzl@61273
   286
      thus "(\<Sum>i<n. f (a \<inter> A i)) + f (a - (\<Union>i. A i)) \<le> f a"
hoelzl@61273
   287
        by (simp add: lambda_system_strong_sum pos A disj eq_fa add_left_mono atLeast0LessThan[symmetric])
hoelzl@61273
   288
    next
hoelzl@61273
   289
      have "\<And>i. a \<inter> A i \<in> M" using A'' by auto
hoelzl@61273
   290
      then show "\<And>i. 0 \<le> f (a \<inter> A i)" using pos[unfolded positive_def] by auto
hoelzl@61273
   291
      have "\<And>i. a - (\<Union>i. A i) \<in> M" using A'' by auto
hoelzl@61273
   292
      then have "\<And>i. 0 \<le> f (a - (\<Union>i. A i))" using pos[unfolded positive_def] by auto
hoelzl@61273
   293
      then show "f (a - (\<Union>i. A i)) \<noteq> -\<infinity>" by auto
hoelzl@61273
   294
    qed
hoelzl@61273
   295
    finally show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a" .
hoelzl@61273
   296
  next
hoelzl@61273
   297
    have "f a \<le> f (a \<inter> (\<Union>i. A i) \<union> (a - (\<Union>i. A i)))"
hoelzl@61273
   298
      by (blast intro:  increasingD [OF inc] U_in)
hoelzl@61273
   299
    also have "... \<le>  f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))"
hoelzl@61273
   300
      by (blast intro: subadditiveD [OF sa] U_in)
hoelzl@61273
   301
    finally show "f a \<le> f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))" .
hoelzl@61273
   302
  qed
paulson@33271
   303
  thus  ?thesis
hoelzl@38656
   304
    by (simp add: lambda_system_eq sums_iff U_eq U_in)
paulson@33271
   305
qed
paulson@33271
   306
paulson@33271
   307
lemma (in sigma_algebra) caratheodory_lemma:
paulson@33271
   308
  assumes oms: "outer_measure_space M f"
hoelzl@47694
   309
  defines "L \<equiv> lambda_system \<Omega> M f"
hoelzl@47694
   310
  shows "measure_space \<Omega> L f"
paulson@33271
   311
proof -
hoelzl@41689
   312
  have pos: "positive M f"
paulson@33271
   313
    by (metis oms outer_measure_space_def)
hoelzl@47694
   314
  have alg: "algebra \<Omega> L"
hoelzl@38656
   315
    using lambda_system_algebra [of f, OF pos]
hoelzl@47694
   316
    by (simp add: algebra_iff_Un L_def)
hoelzl@42065
   317
  then
hoelzl@47694
   318
  have "sigma_algebra \<Omega> L"
paulson@33271
   319
    using lambda_system_caratheodory [OF oms]
hoelzl@47694
   320
    by (simp add: sigma_algebra_disjoint_iff L_def)
hoelzl@38656
   321
  moreover
hoelzl@47694
   322
  have "countably_additive L f" "positive L f"
paulson@33271
   323
    using pos lambda_system_caratheodory [OF oms]
hoelzl@47694
   324
    by (auto simp add: lambda_system_sets L_def countably_additive_def positive_def)
hoelzl@38656
   325
  ultimately
paulson@33271
   326
  show ?thesis
hoelzl@47694
   327
    using pos by (simp add: measure_space_def)
hoelzl@38656
   328
qed
hoelzl@38656
   329
hoelzl@61273
   330
definition outer_measure :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> 'a set \<Rightarrow> ereal" where
hoelzl@61273
   331
   "outer_measure M f X =
hoelzl@61273
   332
     (INF A:{A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i)}. \<Sum>i. f (A i))"
hoelzl@39096
   333
hoelzl@61273
   334
lemma (in ring_of_sets) outer_measure_agrees:
hoelzl@61273
   335
  assumes posf: "positive M f" and ca: "countably_additive M f" and s: "s \<in> M"
hoelzl@61273
   336
  shows "outer_measure M f s = f s"
hoelzl@61273
   337
  unfolding outer_measure_def
hoelzl@61273
   338
proof (safe intro!: antisym INF_greatest)
hoelzl@61273
   339
  fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> M" and dA: "disjoint_family A" and sA: "s \<subseteq> (\<Union>x. A x)"
paulson@33271
   340
  have inc: "increasing M f"
paulson@33271
   341
    by (metis additive_increasing ca countably_additive_additive posf)
hoelzl@61273
   342
  have "f s = f (\<Union>i. A i \<inter> s)"
hoelzl@61273
   343
    using sA by (auto simp: Int_absorb1)
hoelzl@61273
   344
  also have "\<dots> = (\<Sum>i. f (A i \<inter> s))"
hoelzl@61273
   345
    using sA dA A s
hoelzl@61273
   346
    by (intro ca[unfolded countably_additive_def, rule_format, symmetric])
hoelzl@61273
   347
       (auto simp: Int_absorb1 disjoint_family_on_def)
hoelzl@41981
   348
  also have "... \<le> (\<Sum>i. f (A i))"
hoelzl@61273
   349
    using A s by (intro suminf_le_pos increasingD[OF inc] positiveD2[OF posf]) auto
hoelzl@61273
   350
  finally show "f s \<le> (\<Sum>i. f (A i))" .
hoelzl@61273
   351
next
hoelzl@61273
   352
  have "(\<Sum>i. f (if i = 0 then s else {})) \<le> f s"
hoelzl@61273
   353
    using positiveD1[OF posf] by (subst suminf_finite[of "{0}"]) auto
hoelzl@61273
   354
  with s show "(INF A:{A. range A \<subseteq> M \<and> disjoint_family A \<and> s \<subseteq> UNION UNIV A}. \<Sum>i. f (A i)) \<le> f s"
hoelzl@61273
   355
    by (intro INF_lower2[of "\<lambda>i. if i = 0 then s else {}"])
hoelzl@61273
   356
       (auto simp: disjoint_family_on_def)
hoelzl@41981
   357
qed
hoelzl@41981
   358
hoelzl@61273
   359
lemma outer_measure_nonneg: "positive M f \<Longrightarrow> 0 \<le> outer_measure M f X"
hoelzl@61273
   360
  by (auto intro!: INF_greatest suminf_0_le intro: positiveD2 simp: outer_measure_def)
hoelzl@61273
   361
hoelzl@61273
   362
lemma outer_measure_empty:
hoelzl@47694
   363
  assumes posf: "positive M f" and "{} \<in> M"
hoelzl@61273
   364
  shows "outer_measure M f {} = 0"
paulson@33271
   365
proof (rule antisym)
hoelzl@61273
   366
  show "outer_measure M f {} \<le> 0"
hoelzl@61273
   367
    using assms by (auto intro!: INF_lower2[of "\<lambda>_. {}"] simp: outer_measure_def disjoint_family_on_def positive_def)
hoelzl@61273
   368
qed (intro outer_measure_nonneg posf)
hoelzl@61273
   369
hoelzl@61273
   370
lemma (in ring_of_sets) positive_outer_measure:
hoelzl@61273
   371
  assumes "positive M f" shows "positive (Pow \<Omega>) (outer_measure M f)"
hoelzl@61273
   372
  unfolding positive_def by (auto simp: assms outer_measure_empty outer_measure_nonneg)
hoelzl@61273
   373
hoelzl@61273
   374
lemma (in ring_of_sets) increasing_outer_measure: "increasing (Pow \<Omega>) (outer_measure M f)"
hoelzl@61273
   375
  by (force simp: increasing_def outer_measure_def intro!: INF_greatest intro: INF_lower)
paulson@33271
   376
hoelzl@61273
   377
lemma (in ring_of_sets) outer_measure_le:
hoelzl@61273
   378
  assumes pos: "positive M f" and inc: "increasing M f" and A: "range A \<subseteq> M" and X: "X \<subseteq> (\<Union>i. A i)"
hoelzl@61273
   379
  shows "outer_measure M f X \<le> (\<Sum>i. f (A i))"
hoelzl@61273
   380
  unfolding outer_measure_def
hoelzl@61273
   381
proof (safe intro!: INF_lower2[of "disjointed A"] del: subsetI)
hoelzl@61273
   382
  show dA: "range (disjointed A) \<subseteq> M"
hoelzl@61273
   383
    by (auto intro!: A range_disjointed_sets)
hoelzl@61273
   384
  have "\<forall>n. f (disjointed A n) \<le> f (A n)"
hoelzl@61273
   385
    by (metis increasingD [OF inc] UNIV_I dA image_subset_iff disjointed_subset A)
hoelzl@61273
   386
  moreover have "\<forall>i. 0 \<le> f (disjointed A i)"
hoelzl@61273
   387
    using pos dA unfolding positive_def by auto
hoelzl@61273
   388
  ultimately show "(\<Sum>i. f (disjointed A i)) \<le> (\<Sum>i. f (A i))"
hoelzl@61273
   389
    by (blast intro!: suminf_le_pos)
hoelzl@61273
   390
qed (auto simp: X UN_disjointed_eq disjoint_family_disjointed)
paulson@33271
   391
hoelzl@61273
   392
lemma (in ring_of_sets) outer_measure_close:
hoelzl@61273
   393
  assumes posf: "positive M f" and "0 < e" and "outer_measure M f X \<noteq> \<infinity>"
hoelzl@61273
   394
  shows "\<exists>A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i) \<and> (\<Sum>i. f (A i)) \<le> outer_measure M f X + e"
paulson@33271
   395
proof -
hoelzl@61273
   396
  from `outer_measure M f X \<noteq> \<infinity>` have fin: "\<bar>outer_measure M f X\<bar> \<noteq> \<infinity>"
hoelzl@61273
   397
    using outer_measure_nonneg[OF posf, of X] by auto
paulson@33271
   398
  show ?thesis
hoelzl@61273
   399
    using Inf_ereal_close[OF fin[unfolded outer_measure_def INF_def], OF \<open>0 < e\<close>]
hoelzl@61273
   400
    unfolding INF_def[symmetric] outer_measure_def[symmetric] by (auto intro: less_imp_le)
paulson@33271
   401
qed
paulson@33271
   402
hoelzl@61273
   403
lemma (in ring_of_sets) countably_subadditive_outer_measure:
hoelzl@41689
   404
  assumes posf: "positive M f" and inc: "increasing M f"
hoelzl@61273
   405
  shows "countably_subadditive (Pow \<Omega>) (outer_measure M f)"
hoelzl@42066
   406
proof (simp add: countably_subadditive_def, safe)
hoelzl@61273
   407
  fix A :: "nat \<Rightarrow> _" assume A: "range A \<subseteq> Pow (\<Omega>)" and sb: "(\<Union>i. A i) \<subseteq> \<Omega>"
hoelzl@61273
   408
  let ?O = "outer_measure M f"
hoelzl@42066
   409
hoelzl@61273
   410
  { fix e :: ereal assume e: "0 < e" and "\<forall>i. ?O (A i) \<noteq> \<infinity>"
hoelzl@61273
   411
    hence "\<exists>B. \<forall>n. range (B n) \<subseteq> M \<and> disjoint_family (B n) \<and> A n \<subseteq> (\<Union>i. B n i) \<and>
hoelzl@61273
   412
        (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
hoelzl@61273
   413
      using e sb by (auto intro!: choice outer_measure_close [of f, OF posf] simp: ereal_zero_less_0_iff one_ereal_def)
hoelzl@61273
   414
    then obtain B
hoelzl@61273
   415
      where B: "\<And>n. range (B n) \<subseteq> M"
hoelzl@61273
   416
      and sbB: "\<And>n. A n \<subseteq> (\<Union>i. B n i)"
hoelzl@61273
   417
      and Ble: "\<And>n. (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
hoelzl@42066
   418
      by auto blast
hoelzl@61273
   419
hoelzl@61273
   420
    def C \<equiv> "split B o prod_decode"
hoelzl@61273
   421
    from B have B_in_M: "\<And>i j. B i j \<in> M"
haftmann@61032
   422
      by (rule range_subsetD)
hoelzl@61273
   423
    then have C: "range C \<subseteq> M"
hoelzl@61273
   424
      by (auto simp add: C_def split_def)
hoelzl@61273
   425
    have A_C: "(\<Union>i. A i) \<subseteq> (\<Union>i. C i)"
hoelzl@61273
   426
      using sbB by (auto simp add: C_def subset_eq) (metis prod.case prod_encode_inverse)
hoelzl@42066
   427
hoelzl@61273
   428
    have "?O (\<Union>i. A i) \<le> ?O (\<Union>i. C i)"  
hoelzl@61273
   429
      using A_C A C by (intro increasing_outer_measure[THEN increasingD]) (auto dest!: sets_into_space)
hoelzl@61273
   430
    also have "\<dots> \<le> (\<Sum>i. f (C i))"
hoelzl@61273
   431
      using C by (intro outer_measure_le[OF posf inc]) auto
hoelzl@61273
   432
    also have "\<dots> = (\<Sum>n. \<Sum>i. f (B n i))"
hoelzl@61273
   433
      using B_in_M unfolding C_def comp_def by (intro suminf_ereal_2dimen positiveD2[OF posf]) auto
hoelzl@61273
   434
    also have "\<dots> \<le> (\<Sum>n. ?O (A n) + e*(1/2) ^ Suc n)"
hoelzl@61273
   435
      using B_in_M by (intro suminf_le_pos[OF Ble] suminf_0_le posf[THEN positiveD2]) auto
hoelzl@61273
   436
    also have "... = (\<Sum>n. ?O (A n)) + (\<Sum>n. e*(1/2) ^ Suc n)"
hoelzl@61273
   437
      using e by (subst suminf_add_ereal) (auto simp add: ereal_zero_le_0_iff outer_measure_nonneg posf)
hoelzl@61273
   438
    also have "(\<Sum>n. e*(1/2) ^ Suc n) = e"
hoelzl@61273
   439
      using suminf_half_series_ereal e by (simp add: ereal_zero_le_0_iff suminf_cmult_ereal)
hoelzl@61273
   440
    finally have "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n)) + e" . }
hoelzl@61273
   441
  note * = this
hoelzl@61273
   442
hoelzl@61273
   443
  show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n))"
hoelzl@42066
   444
  proof cases
hoelzl@61273
   445
    assume "\<forall>i. ?O (A i) \<noteq> \<infinity>" with * show ?thesis
hoelzl@43920
   446
      by (intro ereal_le_epsilon) auto
hoelzl@61273
   447
  qed (metis suminf_PInfty[OF outer_measure_nonneg, OF posf] ereal_less_eq(1))
paulson@33271
   448
qed
paulson@33271
   449
hoelzl@61273
   450
lemma (in ring_of_sets) outer_measure_space_outer_measure:
hoelzl@61273
   451
  "positive M f \<Longrightarrow> increasing M f \<Longrightarrow> outer_measure_space (Pow \<Omega>) (outer_measure M f)"
hoelzl@61273
   452
  by (simp add: outer_measure_space_def
hoelzl@61273
   453
    positive_outer_measure increasing_outer_measure countably_subadditive_outer_measure)
paulson@33271
   454
hoelzl@42066
   455
lemma (in ring_of_sets) algebra_subset_lambda_system:
hoelzl@41689
   456
  assumes posf: "positive M f" and inc: "increasing M f"
paulson@33271
   457
      and add: "additive M f"
hoelzl@61273
   458
  shows "M \<subseteq> lambda_system \<Omega> (Pow \<Omega>) (outer_measure M f)"
hoelzl@38656
   459
proof (auto dest: sets_into_space
hoelzl@38656
   460
            simp add: algebra.lambda_system_eq [OF algebra_Pow])
hoelzl@61273
   461
  fix x s assume x: "x \<in> M" and s: "s \<subseteq> \<Omega>"
hoelzl@61273
   462
  have [simp]: "\<And>x. x \<in> M \<Longrightarrow> s \<inter> (\<Omega> - x) = s - x" using s
paulson@33271
   463
    by blast
hoelzl@61273
   464
  have "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le> outer_measure M f s"
hoelzl@61273
   465
    unfolding outer_measure_def[of M f s]
hoelzl@61273
   466
  proof (safe intro!: INF_greatest)
hoelzl@61273
   467
    fix A :: "nat \<Rightarrow> 'a set" assume A: "disjoint_family A" "range A \<subseteq> M" "s \<subseteq> (\<Union>i. A i)"
hoelzl@61273
   468
    have "outer_measure M f (s \<inter> x) \<le> (\<Sum>i. f (A i \<inter> x))"
hoelzl@61273
   469
      unfolding outer_measure_def
hoelzl@61273
   470
    proof (safe intro!: INF_lower2[of "\<lambda>i. A i \<inter> x"])
hoelzl@61273
   471
      from A(1) show "disjoint_family (\<lambda>i. A i \<inter> x)"
hoelzl@61273
   472
        by (rule disjoint_family_on_bisimulation) auto
hoelzl@61273
   473
    qed (insert x A, auto)
hoelzl@61273
   474
    moreover
hoelzl@61273
   475
    have "outer_measure M f (s - x) \<le> (\<Sum>i. f (A i - x))"
hoelzl@61273
   476
      unfolding outer_measure_def
hoelzl@61273
   477
    proof (safe intro!: INF_lower2[of "\<lambda>i. A i - x"])
hoelzl@61273
   478
      from A(1) show "disjoint_family (\<lambda>i. A i - x)"
hoelzl@61273
   479
        by (rule disjoint_family_on_bisimulation) auto
hoelzl@61273
   480
    qed (insert x A, auto)
hoelzl@61273
   481
    ultimately have "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le>
hoelzl@61273
   482
        (\<Sum>i. f (A i \<inter> x)) + (\<Sum>i. f (A i - x))" by (rule add_mono)
hoelzl@61273
   483
    also have "\<dots> = (\<Sum>i. f (A i \<inter> x) + f (A i - x))"
hoelzl@61273
   484
      using A(2) x posf by (subst suminf_add_ereal) (auto simp: positive_def)
hoelzl@61273
   485
    also have "\<dots> = (\<Sum>i. f (A i))"
hoelzl@61273
   486
      using A x
hoelzl@61273
   487
      by (subst add[THEN additiveD, symmetric])
hoelzl@61273
   488
         (auto intro!: arg_cong[where f=suminf] arg_cong[where f=f])
hoelzl@61273
   489
    finally show "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le> (\<Sum>i. f (A i))" .
hoelzl@42066
   490
  qed
hoelzl@38656
   491
  moreover
hoelzl@61273
   492
  have "outer_measure M f s \<le> outer_measure M f (s \<inter> x) + outer_measure M f (s - x)"
hoelzl@42145
   493
  proof -
hoelzl@61273
   494
    have "outer_measure M f s = outer_measure M f ((s \<inter> x) \<union> (s - x))"
paulson@33271
   495
      by (metis Un_Diff_Int Un_commute)
hoelzl@61273
   496
    also have "... \<le> outer_measure M f (s \<inter> x) + outer_measure M f (s - x)"
hoelzl@38656
   497
      apply (rule subadditiveD)
hoelzl@42145
   498
      apply (rule ring_of_sets.countably_subadditive_subadditive [OF ring_of_sets_Pow])
hoelzl@61273
   499
      apply (simp add: positive_def outer_measure_empty[OF posf] outer_measure_nonneg[OF posf])
hoelzl@61273
   500
      apply (rule countably_subadditive_outer_measure)
hoelzl@41689
   501
      using s by (auto intro!: posf inc)
paulson@33271
   502
    finally show ?thesis .
hoelzl@42145
   503
  qed
hoelzl@38656
   504
  ultimately
hoelzl@61273
   505
  show "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) = outer_measure M f s"
paulson@33271
   506
    by (rule order_antisym)
paulson@33271
   507
qed
paulson@33271
   508
hoelzl@61273
   509
lemma measure_down: "measure_space \<Omega> N \<mu> \<Longrightarrow> sigma_algebra \<Omega> M \<Longrightarrow> M \<subseteq> N \<Longrightarrow> measure_space \<Omega> M \<mu>"
hoelzl@57446
   510
  by (auto simp add: measure_space_def positive_def countably_additive_def subset_eq)
paulson@33271
   511
hoelzl@56994
   512
subsection {* Caratheodory's theorem *}
hoelzl@56994
   513
hoelzl@47762
   514
theorem (in ring_of_sets) caratheodory':
hoelzl@41689
   515
  assumes posf: "positive M f" and ca: "countably_additive M f"
hoelzl@47694
   516
  shows "\<exists>\<mu> :: 'a set \<Rightarrow> ereal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
hoelzl@41689
   517
proof -
hoelzl@41689
   518
  have inc: "increasing M f"
hoelzl@41689
   519
    by (metis additive_increasing ca countably_additive_additive posf)
hoelzl@61273
   520
  let ?O = "outer_measure M f"
hoelzl@61273
   521
  def ls \<equiv> "lambda_system \<Omega> (Pow \<Omega>) ?O"
hoelzl@61273
   522
  have mls: "measure_space \<Omega> ls ?O"
hoelzl@41689
   523
    using sigma_algebra.caratheodory_lemma
hoelzl@61273
   524
            [OF sigma_algebra_Pow outer_measure_space_outer_measure [OF posf inc]]
hoelzl@41689
   525
    by (simp add: ls_def)
hoelzl@47694
   526
  hence sls: "sigma_algebra \<Omega> ls"
hoelzl@41689
   527
    by (simp add: measure_space_def)
hoelzl@47694
   528
  have "M \<subseteq> ls"
hoelzl@41689
   529
    by (simp add: ls_def)
hoelzl@41689
   530
       (metis ca posf inc countably_additive_additive algebra_subset_lambda_system)
hoelzl@47694
   531
  hence sgs_sb: "sigma_sets (\<Omega>) (M) \<subseteq> ls"
hoelzl@47694
   532
    using sigma_algebra.sigma_sets_subset [OF sls, of "M"]
hoelzl@41689
   533
    by simp
hoelzl@61273
   534
  have "measure_space \<Omega> (sigma_sets \<Omega> M) ?O"
hoelzl@41689
   535
    by (rule measure_down [OF mls], rule sigma_algebra_sigma_sets)
hoelzl@41689
   536
       (simp_all add: sgs_sb space_closed)
hoelzl@61273
   537
  thus ?thesis using outer_measure_agrees [OF posf ca]
hoelzl@61273
   538
    by (intro exI[of _ ?O]) auto
hoelzl@41689
   539
qed
paulson@33271
   540
hoelzl@42145
   541
lemma (in ring_of_sets) caratheodory_empty_continuous:
hoelzl@47694
   542
  assumes f: "positive M f" "additive M f" and fin: "\<And>A. A \<in> M \<Longrightarrow> f A \<noteq> \<infinity>"
hoelzl@47694
   543
  assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) ----> 0"
hoelzl@47694
   544
  shows "\<exists>\<mu> :: 'a set \<Rightarrow> ereal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
hoelzl@47762
   545
proof (intro caratheodory' empty_continuous_imp_countably_additive f)
hoelzl@47694
   546
  show "\<forall>A\<in>M. f A \<noteq> \<infinity>" using fin by auto
hoelzl@42145
   547
qed (rule cont)
hoelzl@42145
   548
hoelzl@56994
   549
subsection {* Volumes *}
hoelzl@47762
   550
hoelzl@47762
   551
definition volume :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47762
   552
  "volume M f \<longleftrightarrow>
hoelzl@47762
   553
  (f {} = 0) \<and> (\<forall>a\<in>M. 0 \<le> f a) \<and>
hoelzl@47762
   554
  (\<forall>C\<subseteq>M. disjoint C \<longrightarrow> finite C \<longrightarrow> \<Union>C \<in> M \<longrightarrow> f (\<Union>C) = (\<Sum>c\<in>C. f c))"
hoelzl@47762
   555
hoelzl@47762
   556
lemma volumeI:
hoelzl@47762
   557
  assumes "f {} = 0"
hoelzl@47762
   558
  assumes "\<And>a. a \<in> M \<Longrightarrow> 0 \<le> f a"
hoelzl@47762
   559
  assumes "\<And>C. C \<subseteq> M \<Longrightarrow> disjoint C \<Longrightarrow> finite C \<Longrightarrow> \<Union>C \<in> M \<Longrightarrow> f (\<Union>C) = (\<Sum>c\<in>C. f c)"
hoelzl@47762
   560
  shows "volume M f"
hoelzl@47762
   561
  using assms by (auto simp: volume_def)
hoelzl@47762
   562
hoelzl@47762
   563
lemma volume_positive:
hoelzl@47762
   564
  "volume M f \<Longrightarrow> a \<in> M \<Longrightarrow> 0 \<le> f a"
hoelzl@47762
   565
  by (auto simp: volume_def)
hoelzl@47762
   566
hoelzl@47762
   567
lemma volume_empty:
hoelzl@47762
   568
  "volume M f \<Longrightarrow> f {} = 0"
hoelzl@47762
   569
  by (auto simp: volume_def)
hoelzl@47762
   570
hoelzl@47762
   571
lemma volume_finite_additive:
hoelzl@47762
   572
  assumes "volume M f" 
hoelzl@47762
   573
  assumes A: "\<And>i. i \<in> I \<Longrightarrow> A i \<in> M" "disjoint_family_on A I" "finite I" "UNION I A \<in> M"
hoelzl@47762
   574
  shows "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
hoelzl@47762
   575
proof -
haftmann@52141
   576
  have "A`I \<subseteq> M" "disjoint (A`I)" "finite (A`I)" "\<Union>(A`I) \<in> M"
hoelzl@47762
   577
    using A unfolding SUP_def by (auto simp: disjoint_family_on_disjoint_image)
haftmann@52141
   578
  with `volume M f` have "f (\<Union>(A`I)) = (\<Sum>a\<in>A`I. f a)"
hoelzl@47762
   579
    unfolding volume_def by blast
hoelzl@47762
   580
  also have "\<dots> = (\<Sum>i\<in>I. f (A i))"
haftmann@57418
   581
  proof (subst setsum.reindex_nontrivial)
hoelzl@47762
   582
    fix i j assume "i \<in> I" "j \<in> I" "i \<noteq> j" "A i = A j"
hoelzl@47762
   583
    with `disjoint_family_on A I` have "A i = {}"
hoelzl@47762
   584
      by (auto simp: disjoint_family_on_def)
hoelzl@47762
   585
    then show "f (A i) = 0"
hoelzl@47762
   586
      using volume_empty[OF `volume M f`] by simp
hoelzl@47762
   587
  qed (auto intro: `finite I`)
hoelzl@47762
   588
  finally show "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
hoelzl@47762
   589
    by simp
hoelzl@47762
   590
qed
hoelzl@47762
   591
hoelzl@47762
   592
lemma (in ring_of_sets) volume_additiveI:
hoelzl@47762
   593
  assumes pos: "\<And>a. a \<in> M \<Longrightarrow> 0 \<le> \<mu> a" 
hoelzl@47762
   594
  assumes [simp]: "\<mu> {} = 0"
hoelzl@47762
   595
  assumes add: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<inter> b = {} \<Longrightarrow> \<mu> (a \<union> b) = \<mu> a + \<mu> b"
hoelzl@47762
   596
  shows "volume M \<mu>"
hoelzl@47762
   597
proof (unfold volume_def, safe)
hoelzl@47762
   598
  fix C assume "finite C" "C \<subseteq> M" "disjoint C"
hoelzl@47762
   599
  then show "\<mu> (\<Union>C) = setsum \<mu> C"
hoelzl@47762
   600
  proof (induct C)
hoelzl@47762
   601
    case (insert c C)
hoelzl@47762
   602
    from insert(1,2,4,5) have "\<mu> (\<Union>insert c C) = \<mu> c + \<mu> (\<Union>C)"
hoelzl@47762
   603
      by (auto intro!: add simp: disjoint_def)
hoelzl@47762
   604
    with insert show ?case
hoelzl@47762
   605
      by (simp add: disjoint_def)
hoelzl@47762
   606
  qed simp
hoelzl@47762
   607
qed fact+
hoelzl@47762
   608
hoelzl@47762
   609
lemma (in semiring_of_sets) extend_volume:
hoelzl@47762
   610
  assumes "volume M \<mu>"
hoelzl@47762
   611
  shows "\<exists>\<mu>'. volume generated_ring \<mu>' \<and> (\<forall>a\<in>M. \<mu>' a = \<mu> a)"
hoelzl@47762
   612
proof -
hoelzl@47762
   613
  let ?R = generated_ring
hoelzl@47762
   614
  have "\<forall>a\<in>?R. \<exists>m. \<exists>C\<subseteq>M. a = \<Union>C \<and> finite C \<and> disjoint C \<and> m = (\<Sum>c\<in>C. \<mu> c)"
hoelzl@47762
   615
    by (auto simp: generated_ring_def)
hoelzl@47762
   616
  from bchoice[OF this] guess \<mu>' .. note \<mu>'_spec = this
hoelzl@47762
   617
  
hoelzl@47762
   618
  { fix C assume C: "C \<subseteq> M" "finite C" "disjoint C"
hoelzl@47762
   619
    fix D assume D: "D \<subseteq> M" "finite D" "disjoint D"
hoelzl@47762
   620
    assume "\<Union>C = \<Union>D"
hoelzl@47762
   621
    have "(\<Sum>d\<in>D. \<mu> d) = (\<Sum>d\<in>D. \<Sum>c\<in>C. \<mu> (c \<inter> d))"
haftmann@57418
   622
    proof (intro setsum.cong refl)
hoelzl@47762
   623
      fix d assume "d \<in> D"
hoelzl@47762
   624
      have Un_eq_d: "(\<Union>c\<in>C. c \<inter> d) = d"
hoelzl@47762
   625
        using `d \<in> D` `\<Union>C = \<Union>D` by auto
hoelzl@47762
   626
      moreover have "\<mu> (\<Union>c\<in>C. c \<inter> d) = (\<Sum>c\<in>C. \<mu> (c \<inter> d))"
hoelzl@47762
   627
      proof (rule volume_finite_additive)
hoelzl@47762
   628
        { fix c assume "c \<in> C" then show "c \<inter> d \<in> M"
hoelzl@47762
   629
            using C D `d \<in> D` by auto }
hoelzl@47762
   630
        show "(\<Union>a\<in>C. a \<inter> d) \<in> M"
hoelzl@47762
   631
          unfolding Un_eq_d using `d \<in> D` D by auto
hoelzl@47762
   632
        show "disjoint_family_on (\<lambda>a. a \<inter> d) C"
hoelzl@47762
   633
          using `disjoint C` by (auto simp: disjoint_family_on_def disjoint_def)
hoelzl@47762
   634
      qed fact+
hoelzl@47762
   635
      ultimately show "\<mu> d = (\<Sum>c\<in>C. \<mu> (c \<inter> d))" by simp
hoelzl@47762
   636
    qed }
hoelzl@47762
   637
  note split_sum = this
hoelzl@47762
   638
hoelzl@47762
   639
  { fix C assume C: "C \<subseteq> M" "finite C" "disjoint C"
hoelzl@47762
   640
    fix D assume D: "D \<subseteq> M" "finite D" "disjoint D"
hoelzl@47762
   641
    assume "\<Union>C = \<Union>D"
hoelzl@47762
   642
    with split_sum[OF C D] split_sum[OF D C]
hoelzl@47762
   643
    have "(\<Sum>d\<in>D. \<mu> d) = (\<Sum>c\<in>C. \<mu> c)"
haftmann@57418
   644
      by (simp, subst setsum.commute, simp add: ac_simps) }
hoelzl@47762
   645
  note sum_eq = this
hoelzl@47762
   646
hoelzl@47762
   647
  { fix C assume C: "C \<subseteq> M" "finite C" "disjoint C"
hoelzl@47762
   648
    then have "\<Union>C \<in> ?R" by (auto simp: generated_ring_def)
hoelzl@47762
   649
    with \<mu>'_spec[THEN bspec, of "\<Union>C"]
hoelzl@47762
   650
    obtain D where
hoelzl@47762
   651
      D: "D \<subseteq> M" "finite D" "disjoint D" "\<Union>C = \<Union>D" and "\<mu>' (\<Union>C) = (\<Sum>d\<in>D. \<mu> d)"
hoelzl@47762
   652
      by blast
hoelzl@47762
   653
    with sum_eq[OF C D] have "\<mu>' (\<Union>C) = (\<Sum>c\<in>C. \<mu> c)" by simp }
hoelzl@47762
   654
  note \<mu>' = this
hoelzl@47762
   655
hoelzl@47762
   656
  show ?thesis
hoelzl@47762
   657
  proof (intro exI conjI ring_of_sets.volume_additiveI[OF generating_ring] ballI)
hoelzl@47762
   658
    fix a assume "a \<in> M" with \<mu>'[of "{a}"] show "\<mu>' a = \<mu> a"
hoelzl@47762
   659
      by (simp add: disjoint_def)
hoelzl@47762
   660
  next
hoelzl@47762
   661
    fix a assume "a \<in> ?R" then guess Ca .. note Ca = this
hoelzl@47762
   662
    with \<mu>'[of Ca] `volume M \<mu>`[THEN volume_positive]
hoelzl@47762
   663
    show "0 \<le> \<mu>' a"
hoelzl@47762
   664
      by (auto intro!: setsum_nonneg)
hoelzl@47762
   665
  next
hoelzl@47762
   666
    show "\<mu>' {} = 0" using \<mu>'[of "{}"] by auto
hoelzl@47762
   667
  next
hoelzl@47762
   668
    fix a assume "a \<in> ?R" then guess Ca .. note Ca = this
hoelzl@47762
   669
    fix b assume "b \<in> ?R" then guess Cb .. note Cb = this
hoelzl@47762
   670
    assume "a \<inter> b = {}"
hoelzl@47762
   671
    with Ca Cb have "Ca \<inter> Cb \<subseteq> {{}}" by auto
hoelzl@47762
   672
    then have C_Int_cases: "Ca \<inter> Cb = {{}} \<or> Ca \<inter> Cb = {}" by auto
hoelzl@47762
   673
wenzelm@60585
   674
    from `a \<inter> b = {}` have "\<mu>' (\<Union>(Ca \<union> Cb)) = (\<Sum>c\<in>Ca \<union> Cb. \<mu> c)"
hoelzl@47762
   675
      using Ca Cb by (intro \<mu>') (auto intro!: disjoint_union)
hoelzl@47762
   676
    also have "\<dots> = (\<Sum>c\<in>Ca \<union> Cb. \<mu> c) + (\<Sum>c\<in>Ca \<inter> Cb. \<mu> c)"
hoelzl@47762
   677
      using C_Int_cases volume_empty[OF `volume M \<mu>`] by (elim disjE) simp_all
hoelzl@47762
   678
    also have "\<dots> = (\<Sum>c\<in>Ca. \<mu> c) + (\<Sum>c\<in>Cb. \<mu> c)"
haftmann@57418
   679
      using Ca Cb by (simp add: setsum.union_inter)
hoelzl@47762
   680
    also have "\<dots> = \<mu>' a + \<mu>' b"
hoelzl@47762
   681
      using Ca Cb by (simp add: \<mu>')
hoelzl@47762
   682
    finally show "\<mu>' (a \<union> b) = \<mu>' a + \<mu>' b"
hoelzl@47762
   683
      using Ca Cb by simp
hoelzl@47762
   684
  qed
hoelzl@47762
   685
qed
hoelzl@47762
   686
hoelzl@56994
   687
subsubsection {* Caratheodory on semirings *}
hoelzl@47762
   688
hoelzl@47762
   689
theorem (in semiring_of_sets) caratheodory:
hoelzl@47762
   690
  assumes pos: "positive M \<mu>" and ca: "countably_additive M \<mu>"
hoelzl@47762
   691
  shows "\<exists>\<mu>' :: 'a set \<Rightarrow> ereal. (\<forall>s \<in> M. \<mu>' s = \<mu> s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>'"
hoelzl@47762
   692
proof -
hoelzl@47762
   693
  have "volume M \<mu>"
hoelzl@47762
   694
  proof (rule volumeI)
hoelzl@47762
   695
    { fix a assume "a \<in> M" then show "0 \<le> \<mu> a"
hoelzl@47762
   696
        using pos unfolding positive_def by auto }
hoelzl@47762
   697
    note p = this
hoelzl@47762
   698
hoelzl@47762
   699
    fix C assume sets_C: "C \<subseteq> M" "\<Union>C \<in> M" and "disjoint C" "finite C"
hoelzl@47762
   700
    have "\<exists>F'. bij_betw F' {..<card C} C"
hoelzl@47762
   701
      by (rule finite_same_card_bij[OF _ `finite C`]) auto
hoelzl@47762
   702
    then guess F' .. note F' = this
hoelzl@47762
   703
    then have F': "C = F' ` {..< card C}" "inj_on F' {..< card C}"
hoelzl@47762
   704
      by (auto simp: bij_betw_def)
hoelzl@47762
   705
    { fix i j assume *: "i < card C" "j < card C" "i \<noteq> j"
hoelzl@47762
   706
      with F' have "F' i \<in> C" "F' j \<in> C" "F' i \<noteq> F' j"
hoelzl@47762
   707
        unfolding inj_on_def by auto
hoelzl@47762
   708
      with `disjoint C`[THEN disjointD]
hoelzl@47762
   709
      have "F' i \<inter> F' j = {}"
hoelzl@47762
   710
        by auto }
hoelzl@47762
   711
    note F'_disj = this
hoelzl@47762
   712
    def F \<equiv> "\<lambda>i. if i < card C then F' i else {}"
hoelzl@47762
   713
    then have "disjoint_family F"
hoelzl@47762
   714
      using F'_disj by (auto simp: disjoint_family_on_def)
hoelzl@47762
   715
    moreover from F' have "(\<Union>i. F i) = \<Union>C"
hoelzl@47762
   716
      by (auto simp: F_def set_eq_iff split: split_if_asm)
hoelzl@47762
   717
    moreover have sets_F: "\<And>i. F i \<in> M"
hoelzl@47762
   718
      using F' sets_C by (auto simp: F_def)
hoelzl@47762
   719
    moreover note sets_C
hoelzl@47762
   720
    ultimately have "\<mu> (\<Union>C) = (\<Sum>i. \<mu> (F i))"
hoelzl@47762
   721
      using ca[unfolded countably_additive_def, THEN spec, of F] by auto
hoelzl@47762
   722
    also have "\<dots> = (\<Sum>i<card C. \<mu> (F' i))"
hoelzl@47762
   723
    proof -
hoelzl@47762
   724
      have "(\<lambda>i. if i \<in> {..< card C} then \<mu> (F' i) else 0) sums (\<Sum>i<card C. \<mu> (F' i))"
hoelzl@47762
   725
        by (rule sums_If_finite_set) auto
hoelzl@47762
   726
      also have "(\<lambda>i. if i \<in> {..< card C} then \<mu> (F' i) else 0) = (\<lambda>i. \<mu> (F i))"
hoelzl@47762
   727
        using pos by (auto simp: positive_def F_def)
hoelzl@47762
   728
      finally show "(\<Sum>i. \<mu> (F i)) = (\<Sum>i<card C. \<mu> (F' i))"
hoelzl@47762
   729
        by (simp add: sums_iff)
hoelzl@47762
   730
    qed
hoelzl@47762
   731
    also have "\<dots> = (\<Sum>c\<in>C. \<mu> c)"
haftmann@57418
   732
      using F'(2) by (subst (2) F') (simp add: setsum.reindex)
hoelzl@47762
   733
    finally show "\<mu> (\<Union>C) = (\<Sum>c\<in>C. \<mu> c)" .
hoelzl@47762
   734
  next
hoelzl@47762
   735
    show "\<mu> {} = 0"
hoelzl@47762
   736
      using `positive M \<mu>` by (rule positiveD1)
hoelzl@47762
   737
  qed
hoelzl@47762
   738
  from extend_volume[OF this] obtain \<mu>_r where
hoelzl@47762
   739
    V: "volume generated_ring \<mu>_r" "\<And>a. a \<in> M \<Longrightarrow> \<mu> a = \<mu>_r a"
hoelzl@47762
   740
    by auto
hoelzl@47762
   741
hoelzl@47762
   742
  interpret G: ring_of_sets \<Omega> generated_ring
hoelzl@47762
   743
    by (rule generating_ring)
hoelzl@47762
   744
hoelzl@47762
   745
  have pos: "positive generated_ring \<mu>_r"
hoelzl@47762
   746
    using V unfolding positive_def by (auto simp: positive_def intro!: volume_positive volume_empty)
hoelzl@47762
   747
hoelzl@47762
   748
  have "countably_additive generated_ring \<mu>_r"
hoelzl@47762
   749
  proof (rule countably_additiveI)
hoelzl@47762
   750
    fix A' :: "nat \<Rightarrow> 'a set" assume A': "range A' \<subseteq> generated_ring" "disjoint_family A'"
hoelzl@47762
   751
      and Un_A: "(\<Union>i. A' i) \<in> generated_ring"
hoelzl@47762
   752
hoelzl@47762
   753
    from generated_ringE[OF Un_A] guess C' . note C' = this
hoelzl@47762
   754
hoelzl@47762
   755
    { fix c assume "c \<in> C'"
hoelzl@47762
   756
      moreover def A \<equiv> "\<lambda>i. A' i \<inter> c"
hoelzl@47762
   757
      ultimately have A: "range A \<subseteq> generated_ring" "disjoint_family A"
hoelzl@47762
   758
        and Un_A: "(\<Union>i. A i) \<in> generated_ring"
hoelzl@47762
   759
        using A' C'
hoelzl@47762
   760
        by (auto intro!: G.Int G.finite_Union intro: generated_ringI_Basic simp: disjoint_family_on_def)
hoelzl@47762
   761
      from A C' `c \<in> C'` have UN_eq: "(\<Union>i. A i) = c"
hoelzl@47762
   762
        by (auto simp: A_def)
hoelzl@47762
   763
hoelzl@47762
   764
      have "\<forall>i::nat. \<exists>f::nat \<Rightarrow> 'a set. \<mu>_r (A i) = (\<Sum>j. \<mu>_r (f j)) \<and> disjoint_family f \<and> \<Union>range f = A i \<and> (\<forall>j. f j \<in> M)"
hoelzl@47762
   765
        (is "\<forall>i. ?P i")
hoelzl@47762
   766
      proof
hoelzl@47762
   767
        fix i
hoelzl@47762
   768
        from A have Ai: "A i \<in> generated_ring" by auto
hoelzl@47762
   769
        from generated_ringE[OF this] guess C . note C = this
hoelzl@47762
   770
hoelzl@47762
   771
        have "\<exists>F'. bij_betw F' {..<card C} C"
hoelzl@47762
   772
          by (rule finite_same_card_bij[OF _ `finite C`]) auto
hoelzl@47762
   773
        then guess F .. note F = this
hoelzl@47762
   774
        def f \<equiv> "\<lambda>i. if i < card C then F i else {}"
hoelzl@47762
   775
        then have f: "bij_betw f {..< card C} C"
hoelzl@47762
   776
          by (intro bij_betw_cong[THEN iffD1, OF _ F]) auto
hoelzl@47762
   777
        with C have "\<forall>j. f j \<in> M"
hoelzl@47762
   778
          by (auto simp: Pi_iff f_def dest!: bij_betw_imp_funcset)
hoelzl@47762
   779
        moreover
hoelzl@47762
   780
        from f C have d_f: "disjoint_family_on f {..<card C}"
hoelzl@47762
   781
          by (intro disjoint_image_disjoint_family_on) (auto simp: bij_betw_def)
hoelzl@47762
   782
        then have "disjoint_family f"
hoelzl@47762
   783
          by (auto simp: disjoint_family_on_def f_def)
hoelzl@47762
   784
        moreover
wenzelm@60585
   785
        have Ai_eq: "A i = (\<Union>x<card C. f x)"
hoelzl@47762
   786
          using f C Ai unfolding bij_betw_def by (simp add: Union_image_eq[symmetric])
hoelzl@47762
   787
        then have "\<Union>range f = A i"
hoelzl@47762
   788
          using f C Ai unfolding bij_betw_def by (auto simp: f_def)
hoelzl@47762
   789
        moreover 
hoelzl@47762
   790
        { have "(\<Sum>j. \<mu>_r (f j)) = (\<Sum>j. if j \<in> {..< card C} then \<mu>_r (f j) else 0)"
hoelzl@47762
   791
            using volume_empty[OF V(1)] by (auto intro!: arg_cong[where f=suminf] simp: f_def)
hoelzl@47762
   792
          also have "\<dots> = (\<Sum>j<card C. \<mu>_r (f j))"
hoelzl@47762
   793
            by (rule sums_If_finite_set[THEN sums_unique, symmetric]) simp
hoelzl@47762
   794
          also have "\<dots> = \<mu>_r (A i)"
hoelzl@47762
   795
            using C f[THEN bij_betw_imp_funcset] unfolding Ai_eq
hoelzl@47762
   796
            by (intro volume_finite_additive[OF V(1) _ d_f, symmetric])
hoelzl@47762
   797
               (auto simp: Pi_iff Ai_eq intro: generated_ringI_Basic)
hoelzl@47762
   798
          finally have "\<mu>_r (A i) = (\<Sum>j. \<mu>_r (f j))" .. }
hoelzl@47762
   799
        ultimately show "?P i"
hoelzl@47762
   800
          by blast
hoelzl@47762
   801
      qed
hoelzl@47762
   802
      from choice[OF this] guess f .. note f = this
hoelzl@47762
   803
      then have UN_f_eq: "(\<Union>i. split f (prod_decode i)) = (\<Union>i. A i)"
hoelzl@47762
   804
        unfolding UN_extend_simps surj_prod_decode by (auto simp: set_eq_iff)
hoelzl@47762
   805
hoelzl@47762
   806
      have d: "disjoint_family (\<lambda>i. split f (prod_decode i))"
hoelzl@47762
   807
        unfolding disjoint_family_on_def
hoelzl@47762
   808
      proof (intro ballI impI)
hoelzl@47762
   809
        fix m n :: nat assume "m \<noteq> n"
hoelzl@47762
   810
        then have neq: "prod_decode m \<noteq> prod_decode n"
hoelzl@47762
   811
          using inj_prod_decode[of UNIV] by (auto simp: inj_on_def)
hoelzl@47762
   812
        show "split f (prod_decode m) \<inter> split f (prod_decode n) = {}"
hoelzl@47762
   813
        proof cases
hoelzl@47762
   814
          assume "fst (prod_decode m) = fst (prod_decode n)"
hoelzl@47762
   815
          then show ?thesis
hoelzl@47762
   816
            using neq f by (fastforce simp: disjoint_family_on_def)
hoelzl@47762
   817
        next
hoelzl@47762
   818
          assume neq: "fst (prod_decode m) \<noteq> fst (prod_decode n)"
hoelzl@47762
   819
          have "split f (prod_decode m) \<subseteq> A (fst (prod_decode m))"
hoelzl@47762
   820
            "split f (prod_decode n) \<subseteq> A (fst (prod_decode n))"
hoelzl@47762
   821
            using f[THEN spec, of "fst (prod_decode m)"]
hoelzl@47762
   822
            using f[THEN spec, of "fst (prod_decode n)"]
hoelzl@47762
   823
            by (auto simp: set_eq_iff)
hoelzl@47762
   824
          with f A neq show ?thesis
hoelzl@47762
   825
            by (fastforce simp: disjoint_family_on_def subset_eq set_eq_iff)
hoelzl@47762
   826
        qed
hoelzl@47762
   827
      qed
hoelzl@47762
   828
      from f have "(\<Sum>n. \<mu>_r (A n)) = (\<Sum>n. \<mu>_r (split f (prod_decode n)))"
hoelzl@47762
   829
        by (intro suminf_ereal_2dimen[symmetric] positiveD2[OF pos] generated_ringI_Basic)
hoelzl@47762
   830
         (auto split: prod.split)
hoelzl@47762
   831
      also have "\<dots> = (\<Sum>n. \<mu> (split f (prod_decode n)))"
hoelzl@47762
   832
        using f V(2) by (auto intro!: arg_cong[where f=suminf] split: prod.split)
hoelzl@47762
   833
      also have "\<dots> = \<mu> (\<Union>i. split f (prod_decode i))"
hoelzl@47762
   834
        using f `c \<in> C'` C'
hoelzl@47762
   835
        by (intro ca[unfolded countably_additive_def, rule_format])
hoelzl@47762
   836
           (auto split: prod.split simp: UN_f_eq d UN_eq)
hoelzl@47762
   837
      finally have "(\<Sum>n. \<mu>_r (A' n \<inter> c)) = \<mu> c"
hoelzl@47762
   838
        using UN_f_eq UN_eq by (simp add: A_def) }
hoelzl@47762
   839
    note eq = this
hoelzl@47762
   840
hoelzl@47762
   841
    have "(\<Sum>n. \<mu>_r (A' n)) = (\<Sum>n. \<Sum>c\<in>C'. \<mu>_r (A' n \<inter> c))"
bulwahn@49394
   842
      using C' A'
hoelzl@47762
   843
      by (subst volume_finite_additive[symmetric, OF V(1)])
haftmann@56166
   844
         (auto simp: disjoint_def disjoint_family_on_def Union_image_eq[symmetric] simp del: Sup_image_eq Union_image_eq
hoelzl@47762
   845
               intro!: G.Int G.finite_Union arg_cong[where f="\<lambda>X. suminf (\<lambda>i. \<mu>_r (X i))"] ext
hoelzl@47762
   846
               intro: generated_ringI_Basic)
hoelzl@47762
   847
    also have "\<dots> = (\<Sum>c\<in>C'. \<Sum>n. \<mu>_r (A' n \<inter> c))"
hoelzl@47762
   848
      using C' A'
hoelzl@47762
   849
      by (intro suminf_setsum_ereal positiveD2[OF pos] G.Int G.finite_Union)
hoelzl@47762
   850
         (auto intro: generated_ringI_Basic)
hoelzl@47762
   851
    also have "\<dots> = (\<Sum>c\<in>C'. \<mu>_r c)"
haftmann@57418
   852
      using eq V C' by (auto intro!: setsum.cong)
hoelzl@47762
   853
    also have "\<dots> = \<mu>_r (\<Union>C')"
hoelzl@47762
   854
      using C' Un_A
hoelzl@47762
   855
      by (subst volume_finite_additive[symmetric, OF V(1)])
haftmann@56166
   856
         (auto simp: disjoint_family_on_def disjoint_def Union_image_eq[symmetric] simp del: Sup_image_eq Union_image_eq 
hoelzl@47762
   857
               intro: generated_ringI_Basic)
hoelzl@47762
   858
    finally show "(\<Sum>n. \<mu>_r (A' n)) = \<mu>_r (\<Union>i. A' i)"
hoelzl@47762
   859
      using C' by simp
hoelzl@47762
   860
  qed
hoelzl@47762
   861
  from G.caratheodory'[OF `positive generated_ring \<mu>_r` `countably_additive generated_ring \<mu>_r`]
hoelzl@47762
   862
  guess \<mu>' ..
hoelzl@47762
   863
  with V show ?thesis
hoelzl@47762
   864
    unfolding sigma_sets_generated_ring_eq
hoelzl@47762
   865
    by (intro exI[of _ \<mu>']) (auto intro: generated_ringI_Basic)
hoelzl@47762
   866
qed
hoelzl@47762
   867
hoelzl@57447
   868
lemma extend_measure_caratheodory:
hoelzl@57447
   869
  fixes G :: "'i \<Rightarrow> 'a set"
hoelzl@57447
   870
  assumes M: "M = extend_measure \<Omega> I G \<mu>"
hoelzl@57447
   871
  assumes "i \<in> I"
hoelzl@57447
   872
  assumes "semiring_of_sets \<Omega> (G ` I)"
hoelzl@57447
   873
  assumes empty: "\<And>i. i \<in> I \<Longrightarrow> G i = {} \<Longrightarrow> \<mu> i = 0"
hoelzl@57447
   874
  assumes inj: "\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> G i = G j \<Longrightarrow> \<mu> i = \<mu> j"
hoelzl@57447
   875
  assumes nonneg: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> \<mu> i"
hoelzl@57447
   876
  assumes add: "\<And>A::nat \<Rightarrow> 'i. \<And>j. A \<in> UNIV \<rightarrow> I \<Longrightarrow> j \<in> I \<Longrightarrow> disjoint_family (G \<circ> A) \<Longrightarrow>
hoelzl@57447
   877
    (\<Union>i. G (A i)) = G j \<Longrightarrow> (\<Sum>n. \<mu> (A n)) = \<mu> j"
hoelzl@57447
   878
  shows "emeasure M (G i) = \<mu> i"
hoelzl@57447
   879
proof -
hoelzl@57447
   880
  interpret semiring_of_sets \<Omega> "G ` I"
hoelzl@57447
   881
    by fact
hoelzl@57447
   882
  have "\<forall>g\<in>G`I. \<exists>i\<in>I. g = G i"
hoelzl@57447
   883
    by auto
hoelzl@57447
   884
  then obtain sel where sel: "\<And>g. g \<in> G ` I \<Longrightarrow> sel g \<in> I" "\<And>g. g \<in> G ` I \<Longrightarrow> G (sel g) = g"
hoelzl@57447
   885
    by metis
hoelzl@57447
   886
hoelzl@57447
   887
  have "\<exists>\<mu>'. (\<forall>s\<in>G ` I. \<mu>' s = \<mu> (sel s)) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G ` I)) \<mu>'"
hoelzl@57447
   888
  proof (rule caratheodory)
hoelzl@57447
   889
    show "positive (G ` I) (\<lambda>s. \<mu> (sel s))"
hoelzl@57447
   890
      by (auto simp: positive_def intro!: empty sel nonneg)
hoelzl@57447
   891
    show "countably_additive (G ` I) (\<lambda>s. \<mu> (sel s))"
hoelzl@57447
   892
    proof (rule countably_additiveI)
hoelzl@57447
   893
      fix A :: "nat \<Rightarrow> 'a set" assume "range A \<subseteq> G ` I" "disjoint_family A" "(\<Union>i. A i) \<in> G ` I"
hoelzl@57447
   894
      then show "(\<Sum>i. \<mu> (sel (A i))) = \<mu> (sel (\<Union>i. A i))"
hoelzl@57447
   895
        by (intro add) (auto simp: sel image_subset_iff_funcset comp_def Pi_iff intro!: sel)
hoelzl@57447
   896
    qed
hoelzl@57447
   897
  qed
hoelzl@57447
   898
  then obtain \<mu>' where \<mu>': "\<forall>s\<in>G ` I. \<mu>' s = \<mu> (sel s)" "measure_space \<Omega> (sigma_sets \<Omega> (G ` I)) \<mu>'"
hoelzl@57447
   899
    by metis
hoelzl@57447
   900
hoelzl@57447
   901
  show ?thesis
hoelzl@57447
   902
  proof (rule emeasure_extend_measure[OF M])
hoelzl@57447
   903
    { fix i assume "i \<in> I" then show "\<mu>' (G i) = \<mu> i"
hoelzl@57447
   904
      using \<mu>' by (auto intro!: inj sel) }
hoelzl@57447
   905
    show "G ` I \<subseteq> Pow \<Omega>"
hoelzl@57447
   906
      by fact
hoelzl@57447
   907
    then show "positive (sets M) \<mu>'" "countably_additive (sets M) \<mu>'"
hoelzl@57447
   908
      using \<mu>' by (simp_all add: M sets_extend_measure measure_space_def)
hoelzl@57447
   909
  qed fact
hoelzl@57447
   910
qed
hoelzl@57447
   911
  
hoelzl@57447
   912
lemma extend_measure_caratheodory_pair:
hoelzl@57447
   913
  fixes G :: "'i \<Rightarrow> 'j \<Rightarrow> 'a set"
hoelzl@57447
   914
  assumes M: "M = extend_measure \<Omega> {(a, b). P a b} (\<lambda>(a, b). G a b) (\<lambda>(a, b). \<mu> a b)"
hoelzl@57447
   915
  assumes "P i j"
hoelzl@57447
   916
  assumes semiring: "semiring_of_sets \<Omega> {G a b | a b. P a b}"
hoelzl@57447
   917
  assumes empty: "\<And>i j. P i j \<Longrightarrow> G i j = {} \<Longrightarrow> \<mu> i j = 0"
hoelzl@57447
   918
  assumes inj: "\<And>i j k l. P i j \<Longrightarrow> P k l \<Longrightarrow> G i j = G k l \<Longrightarrow> \<mu> i j = \<mu> k l"
hoelzl@57447
   919
  assumes nonneg: "\<And>i j. P i j \<Longrightarrow> 0 \<le> \<mu> i j"
hoelzl@57447
   920
  assumes add: "\<And>A::nat \<Rightarrow> 'i. \<And>B::nat \<Rightarrow> 'j. \<And>j k.
hoelzl@57447
   921
    (\<And>n. P (A n) (B n)) \<Longrightarrow> P j k \<Longrightarrow> disjoint_family (\<lambda>n. G (A n) (B n)) \<Longrightarrow>
hoelzl@57447
   922
    (\<Union>i. G (A i) (B i)) = G j k \<Longrightarrow> (\<Sum>n. \<mu> (A n) (B n)) = \<mu> j k"
hoelzl@57447
   923
  shows "emeasure M (G i j) = \<mu> i j"
hoelzl@57447
   924
proof -
hoelzl@57447
   925
  have "emeasure M ((\<lambda>(a, b). G a b) (i, j)) = (\<lambda>(a, b). \<mu> a b) (i, j)"
hoelzl@57447
   926
  proof (rule extend_measure_caratheodory[OF M])
hoelzl@57447
   927
    show "semiring_of_sets \<Omega> ((\<lambda>(a, b). G a b) ` {(a, b). P a b})"
hoelzl@57447
   928
      using semiring by (simp add: image_def conj_commute)
hoelzl@57447
   929
  next
hoelzl@57447
   930
    fix A :: "nat \<Rightarrow> ('i \<times> 'j)" and j assume "A \<in> UNIV \<rightarrow> {(a, b). P a b}" "j \<in> {(a, b). P a b}"
hoelzl@57447
   931
      "disjoint_family ((\<lambda>(a, b). G a b) \<circ> A)"
hoelzl@57447
   932
      "(\<Union>i. case A i of (a, b) \<Rightarrow> G a b) = (case j of (a, b) \<Rightarrow> G a b)"
hoelzl@57447
   933
    then show "(\<Sum>n. case A n of (a, b) \<Rightarrow> \<mu> a b) = (case j of (a, b) \<Rightarrow> \<mu> a b)"
hoelzl@57447
   934
      using add[of "\<lambda>i. fst (A i)" "\<lambda>i. snd (A i)" "fst j" "snd j"]
hoelzl@57447
   935
      by (simp add: split_beta' comp_def Pi_iff)
hoelzl@57447
   936
  qed (auto split: prod.splits intro: assms)
hoelzl@57447
   937
  then show ?thesis by simp
hoelzl@57447
   938
qed
hoelzl@57447
   939
paulson@33271
   940
end