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