src/HOL/Probability/Caratheodory.thy
changeset 62975 1d066f6ab25d
parent 62390 842917225d56
child 63040 eb4ddd18d635
equal deleted inserted replaced
62974:f17602cbf76a 62975:1d066f6ab25d
    11 
    11 
    12 text \<open>
    12 text \<open>
    13   Originally from the Hurd/Coble measure theory development, translated by Lawrence Paulson.
    13   Originally from the Hurd/Coble measure theory development, translated by Lawrence Paulson.
    14 \<close>
    14 \<close>
    15 
    15 
    16 lemma suminf_ereal_2dimen:
    16 lemma suminf_ennreal_2dimen:
    17   fixes f:: "nat \<times> nat \<Rightarrow> ereal"
    17   fixes f:: "nat \<times> nat \<Rightarrow> ennreal"
    18   assumes pos: "\<And>p. 0 \<le> f p"
       
    19   assumes "\<And>m. g m = (\<Sum>n. f (m,n))"
    18   assumes "\<And>m. g m = (\<Sum>n. f (m,n))"
    20   shows "(\<Sum>i. f (prod_decode i)) = suminf g"
    19   shows "(\<Sum>i. f (prod_decode i)) = suminf g"
    21 proof -
    20 proof -
    22   have g_def: "g = (\<lambda>m. (\<Sum>n. f (m,n)))"
    21   have g_def: "g = (\<lambda>m. (\<Sum>n. f (m,n)))"
    23     using assms by (simp add: fun_eq_iff)
    22     using assms by (simp add: fun_eq_iff)
    24   have reindex: "\<And>B. (\<Sum>x\<in>B. f (prod_decode x)) = setsum f (prod_decode ` B)"
    23   have reindex: "\<And>B. (\<Sum>x\<in>B. f (prod_decode x)) = setsum f (prod_decode ` B)"
    25     by (simp add: setsum.reindex[OF inj_prod_decode] comp_def)
    24     by (simp add: setsum.reindex[OF inj_prod_decode] comp_def)
    26   { fix n
    25   have "(SUP n. \<Sum>i<n. f (prod_decode i)) = (SUP p : UNIV \<times> UNIV. \<Sum>i<fst p. \<Sum>n<snd p. f (i, n))"
       
    26   proof (intro SUP_eq; clarsimp simp: setsum.cartesian_product reindex)
       
    27     fix n
    27     let ?M = "\<lambda>f. Suc (Max (f ` prod_decode ` {..<n}))"
    28     let ?M = "\<lambda>f. Suc (Max (f ` prod_decode ` {..<n}))"
    28     { fix a b x assume "x < n" and [symmetric]: "(a, b) = prod_decode x"
    29     { fix a b x assume "x < n" and [symmetric]: "(a, b) = prod_decode x"
    29       then have "a < ?M fst" "b < ?M snd"
    30       then have "a < ?M fst" "b < ?M snd"
    30         by (auto intro!: Max_ge le_imp_less_Suc image_eqI) }
    31         by (auto intro!: Max_ge le_imp_less_Suc image_eqI) }
    31     then have "setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<?M fst} \<times> {..<?M snd})"
    32     then have "setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<?M fst} \<times> {..<?M snd})"
    32       by (auto intro!: setsum_mono3 simp: pos)
    33       by (auto intro!: setsum_mono3)
    33     then have "\<exists>a b. setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<a} \<times> {..<b})" by auto }
    34     then show "\<exists>a b. setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<a} \<times> {..<b})" by auto
    34   moreover
    35   next
    35   { fix a b
    36     fix a b
    36     let ?M = "prod_decode ` {..<Suc (Max (prod_encode ` ({..<a} \<times> {..<b})))}"
    37     let ?M = "prod_decode ` {..<Suc (Max (prod_encode ` ({..<a} \<times> {..<b})))}"
    37     { fix a' b' assume "a' < a" "b' < b" then have "(a', b') \<in> ?M"
    38     { fix a' b' assume "a' < a" "b' < b" then have "(a', b') \<in> ?M"
    38         by (auto intro!: Max_ge le_imp_less_Suc image_eqI[where x="prod_encode (a', b')"]) }
    39         by (auto intro!: Max_ge le_imp_less_Suc image_eqI[where x="prod_encode (a', b')"]) }
    39     then have "setsum f ({..<a} \<times> {..<b}) \<le> setsum f ?M"
    40     then have "setsum f ({..<a} \<times> {..<b}) \<le> setsum f ?M"
    40       by (auto intro!: setsum_mono3 simp: pos) }
    41       by (auto intro!: setsum_mono3)
    41   ultimately
    42     then show "\<exists>n. setsum f ({..<a} \<times> {..<b}) \<le> setsum f (prod_decode ` {..<n})"
    42   show ?thesis unfolding g_def using pos
    43       by auto
    43     by (auto intro!: SUP_eq  simp: setsum.cartesian_product reindex SUP_upper2
    44   qed
    44                      suminf_ereal_eq_SUP SUP_pair
    45   also have "\<dots> = (SUP p. \<Sum>i<p. \<Sum>n. f (i, n))"
    45                      SUP_ereal_setsum[symmetric] incseq_setsumI setsum_nonneg)
    46     unfolding suminf_setsum[OF summableI, symmetric]
       
    47     by (simp add: suminf_eq_SUP SUP_pair setsum.commute[of _ "{..< fst _}"])
       
    48   finally show ?thesis unfolding g_def
       
    49     by (simp add: suminf_eq_SUP)
    46 qed
    50 qed
    47 
    51 
    48 subsection \<open>Characterizations of Measures\<close>
    52 subsection \<open>Characterizations of Measures\<close>
    49 
       
    50 definition subadditive where
       
    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)"
       
    52 
       
    53 definition countably_subadditive where
       
    54   "countably_subadditive M f \<longleftrightarrow>
       
    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))))"
       
    56 
    53 
    57 definition outer_measure_space where
    54 definition outer_measure_space where
    58   "outer_measure_space M f \<longleftrightarrow> positive M f \<and> increasing M f \<and> countably_subadditive M f"
    55   "outer_measure_space M f \<longleftrightarrow> positive M f \<and> increasing M f \<and> countably_subadditive M f"
    59 
    56 
    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"
       
    61   by (auto simp add: subadditive_def)
       
    62 
       
    63 subsubsection \<open>Lambda Systems\<close>
    57 subsubsection \<open>Lambda Systems\<close>
    64 
    58 
    65 definition lambda_system where
    59 definition lambda_system :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> 'a set set"
       
    60 where
    66   "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (l \<inter> x) + f ((\<Omega> - l) \<inter> x) = f x}"
    61   "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (l \<inter> x) + f ((\<Omega> - l) \<inter> x) = f x}"
    67 
    62 
    68 lemma (in algebra) lambda_system_eq:
    63 lemma (in algebra) lambda_system_eq:
    69   "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (x \<inter> l) + f (x - l) = f x}"
    64   "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (x \<inter> l) + f (x - l) = f x}"
    70 proof -
    65 proof -
    79 
    74 
    80 lemma lambda_system_sets: "x \<in> lambda_system \<Omega> M f \<Longrightarrow> x \<in> M"
    75 lemma lambda_system_sets: "x \<in> lambda_system \<Omega> M f \<Longrightarrow> x \<in> M"
    81   by (simp add: lambda_system_def)
    76   by (simp add: lambda_system_def)
    82 
    77 
    83 lemma (in algebra) lambda_system_Compl:
    78 lemma (in algebra) lambda_system_Compl:
    84   fixes f:: "'a set \<Rightarrow> ereal"
    79   fixes f:: "'a set \<Rightarrow> ennreal"
    85   assumes x: "x \<in> lambda_system \<Omega> M f"
    80   assumes x: "x \<in> lambda_system \<Omega> M f"
    86   shows "\<Omega> - x \<in> lambda_system \<Omega> M f"
    81   shows "\<Omega> - x \<in> lambda_system \<Omega> M f"
    87 proof -
    82 proof -
    88   have "x \<subseteq> \<Omega>"
    83   have "x \<subseteq> \<Omega>"
    89     by (metis sets_into_space lambda_system_sets x)
    84     by (metis sets_into_space lambda_system_sets x)
    92   with x show ?thesis
    87   with x show ?thesis
    93     by (force simp add: lambda_system_def ac_simps)
    88     by (force simp add: lambda_system_def ac_simps)
    94 qed
    89 qed
    95 
    90 
    96 lemma (in algebra) lambda_system_Int:
    91 lemma (in algebra) lambda_system_Int:
    97   fixes f:: "'a set \<Rightarrow> ereal"
    92   fixes f:: "'a set \<Rightarrow> ennreal"
    98   assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
    93   assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
    99   shows "x \<inter> y \<in> lambda_system \<Omega> M f"
    94   shows "x \<inter> y \<in> lambda_system \<Omega> M f"
   100 proof -
    95 proof -
   101   from xl yl show ?thesis
    96   from xl yl show ?thesis
   102   proof (auto simp add: positive_def lambda_system_eq Int)
    97   proof (auto simp add: positive_def lambda_system_eq Int)
   126     finally show "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y) = f u" .
   121     finally show "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y) = f u" .
   127   qed
   122   qed
   128 qed
   123 qed
   129 
   124 
   130 lemma (in algebra) lambda_system_Un:
   125 lemma (in algebra) lambda_system_Un:
   131   fixes f:: "'a set \<Rightarrow> ereal"
   126   fixes f:: "'a set \<Rightarrow> ennreal"
   132   assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
   127   assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
   133   shows "x \<union> y \<in> lambda_system \<Omega> M f"
   128   shows "x \<union> y \<in> lambda_system \<Omega> M f"
   134 proof -
   129 proof -
   135   have "(\<Omega> - x) \<inter> (\<Omega> - y) \<in> M"
   130   have "(\<Omega> - x) \<inter> (\<Omega> - y) \<in> M"
   136     by (metis Diff_Un Un compl_sets lambda_system_sets xl yl)
   131     by (metis Diff_Un Un compl_sets lambda_system_sets xl yl)
   174   thus "f (x \<union> y) = f x + f y"
   169   thus "f (x \<union> y) = f x + f y"
   175     using lambda_system_strong_additive [OF top disj xl yl]
   170     using lambda_system_strong_additive [OF top disj xl yl]
   176     by (simp add: Un)
   171     by (simp add: Un)
   177 qed
   172 qed
   178 
   173 
   179 lemma (in ring_of_sets) countably_subadditive_subadditive:
       
   180   assumes f: "positive M f" and cs: "countably_subadditive M f"
       
   181   shows  "subadditive M f"
       
   182 proof (auto simp add: subadditive_def)
       
   183   fix x y
       
   184   assume x: "x \<in> M" and y: "y \<in> M" and "x \<inter> y = {}"
       
   185   hence "disjoint_family (binaryset x y)"
       
   186     by (auto simp add: disjoint_family_on_def binaryset_def)
       
   187   hence "range (binaryset x y) \<subseteq> M \<longrightarrow>
       
   188          (\<Union>i. binaryset x y i) \<in> M \<longrightarrow>
       
   189          f (\<Union>i. binaryset x y i) \<le> (\<Sum> n. f (binaryset x y n))"
       
   190     using cs by (auto simp add: countably_subadditive_def)
       
   191   hence "{x,y,{}} \<subseteq> M \<longrightarrow> x \<union> y \<in> M \<longrightarrow>
       
   192          f (x \<union> y) \<le> (\<Sum> n. f (binaryset x y n))"
       
   193     by (simp add: range_binaryset_eq UN_binaryset_eq)
       
   194   thus "f (x \<union> y) \<le>  f x + f y" using f x y
       
   195     by (auto simp add: Un o_def suminf_binaryset_eq positive_def)
       
   196 qed
       
   197 
       
   198 lemma lambda_system_increasing: "increasing M f \<Longrightarrow> increasing (lambda_system \<Omega> M f) f"
   174 lemma lambda_system_increasing: "increasing M f \<Longrightarrow> increasing (lambda_system \<Omega> M f) f"
   199   by (simp add: increasing_def lambda_system_def)
   175   by (simp add: increasing_def lambda_system_def)
   200 
   176 
   201 lemma lambda_system_positive: "positive M f \<Longrightarrow> positive (lambda_system \<Omega> M f) f"
   177 lemma lambda_system_positive: "positive M f \<Longrightarrow> positive (lambda_system \<Omega> M f) f"
   202   by (simp add: positive_def lambda_system_def)
   178   by (simp add: positive_def lambda_system_def)
   203 
   179 
   204 lemma (in algebra) lambda_system_strong_sum:
   180 lemma (in algebra) lambda_system_strong_sum:
   205   fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> ereal"
   181   fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> ennreal"
   206   assumes f: "positive M f" and a: "a \<in> M"
   182   assumes f: "positive M f" and a: "a \<in> M"
   207       and A: "range A \<subseteq> lambda_system \<Omega> M f"
   183       and A: "range A \<subseteq> lambda_system \<Omega> M f"
   208       and disj: "disjoint_family A"
   184       and disj: "disjoint_family A"
   209   shows  "(\<Sum>i = 0..<n. f (a \<inter>A i)) = f (a \<inter> (\<Union>i\<in>{0..<n}. A i))"
   185   shows  "(\<Sum>i = 0..<n. f (a \<inter>A i)) = f (a \<inter> (\<Union>i\<in>{0..<n}. A i))"
   210 proof (induct n)
   186 proof (induct n)
   245     by (metis A'' countable_UN)
   221     by (metis A'' countable_UN)
   246   have U_eq: "f (\<Union>i. A i) = (\<Sum>i. f (A i))"
   222   have U_eq: "f (\<Union>i. A i) = (\<Sum>i. f (A i))"
   247   proof (rule antisym)
   223   proof (rule antisym)
   248     show "f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))"
   224     show "f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))"
   249       using csa[unfolded countably_subadditive_def] A'' disj U_in by auto
   225       using csa[unfolded countably_subadditive_def] A'' disj U_in by auto
   250     have *: "\<And>i. 0 \<le> f (A i)" using pos A'' unfolding positive_def by auto
       
   251     have dis: "\<And>N. disjoint_family_on A {..<N}" by (intro disjoint_family_on_mono[OF _ disj]) auto
   226     have dis: "\<And>N. disjoint_family_on A {..<N}" by (intro disjoint_family_on_mono[OF _ disj]) auto
   252     show "(\<Sum>i. f (A i)) \<le> f (\<Union>i. A i)"
   227     show "(\<Sum>i. f (A i)) \<le> f (\<Union>i. A i)"
   253       using ls.additive_sum [OF lambda_system_positive[OF pos] lambda_system_additive _ A' dis] A''
   228       using ls.additive_sum [OF lambda_system_positive[OF pos] lambda_system_additive _ A' dis] A''
   254       by (intro suminf_bound[OF _ *]) (auto intro!: increasingD[OF inc] countable_UN)
   229       by (intro suminf_le_const[OF summableI]) (auto intro!: increasingD[OF inc] countable_UN)
   255   qed
   230   qed
   256   have "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) = f a"
   231   have "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) = f a"
   257     if a [iff]: "a \<in> M" for a
   232     if a [iff]: "a \<in> M" for a
   258   proof (rule antisym)
   233   proof (rule antisym)
   259     have "range (\<lambda>i. a \<inter> A i) \<subseteq> M" using A''
   234     have "range (\<lambda>i. a \<inter> A i) \<subseteq> M" using A''
   269       using csa[unfolded countably_subadditive_def, rule_format, of "(\<lambda>i. a \<inter> A i)"]
   244       using csa[unfolded countably_subadditive_def, rule_format, of "(\<lambda>i. a \<inter> A i)"]
   270       by (simp add: o_def)
   245       by (simp add: o_def)
   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))"
   246     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))"
   272       by (rule add_right_mono)
   247       by (rule add_right_mono)
   273     also have "\<dots> \<le> f a"
   248     also have "\<dots> \<le> f a"
   274     proof (intro suminf_bound_add allI)
   249     proof (intro ennreal_suminf_bound_add)
   275       fix n
   250       fix n
   276       have UNION_in: "(\<Union>i\<in>{0..<n}. A i) \<in> M"
   251       have UNION_in: "(\<Union>i\<in>{0..<n}. A i) \<in> M"
   277         by (metis A'' UNION_in_sets)
   252         by (metis A'' UNION_in_sets)
   278       have le_fa: "f (UNION {0..<n} A \<inter> a) \<le> f a" using A''
   253       have le_fa: "f (UNION {0..<n} A \<inter> a) \<le> f a" using A''
   279         by (blast intro: increasingD [OF inc] A'' UNION_in_sets)
   254         by (blast intro: increasingD [OF inc] A'' UNION_in_sets)
   283         by (simp add: lambda_system_eq UNION_in)
   258         by (simp add: lambda_system_eq UNION_in)
   284       have "f (a - (\<Union>i. A i)) \<le> f (a - (\<Union>i\<in>{0..<n}. A i))"
   259       have "f (a - (\<Union>i. A i)) \<le> f (a - (\<Union>i\<in>{0..<n}. A i))"
   285         by (blast intro: increasingD [OF inc] UNION_in U_in)
   260         by (blast intro: increasingD [OF inc] UNION_in U_in)
   286       thus "(\<Sum>i<n. f (a \<inter> A i)) + f (a - (\<Union>i. A i)) \<le> f a"
   261       thus "(\<Sum>i<n. f (a \<inter> A i)) + f (a - (\<Union>i. A i)) \<le> f a"
   287         by (simp add: lambda_system_strong_sum pos A disj eq_fa add_left_mono atLeast0LessThan[symmetric])
   262         by (simp add: lambda_system_strong_sum pos A disj eq_fa add_left_mono atLeast0LessThan[symmetric])
   288     next
       
   289       have "\<And>i. a \<inter> A i \<in> M" using A'' by auto
       
   290       then show "\<And>i. 0 \<le> f (a \<inter> A i)" using pos[unfolded positive_def] by auto
       
   291       have "\<And>i. a - (\<Union>i. A i) \<in> M" using A'' by auto
       
   292       then have "\<And>i. 0 \<le> f (a - (\<Union>i. A i))" using pos[unfolded positive_def] by auto
       
   293       then show "f (a - (\<Union>i. A i)) \<noteq> -\<infinity>" by auto
       
   294     qed
   263     qed
   295     finally show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a" .
   264     finally show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a"
       
   265       by simp
   296   next
   266   next
   297     have "f a \<le> f (a \<inter> (\<Union>i. A i) \<union> (a - (\<Union>i. A i)))"
   267     have "f a \<le> f (a \<inter> (\<Union>i. A i) \<union> (a - (\<Union>i. A i)))"
   298       by (blast intro:  increasingD [OF inc] U_in)
   268       by (blast intro:  increasingD [OF inc] U_in)
   299     also have "... \<le>  f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))"
   269     also have "... \<le>  f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))"
   300       by (blast intro: subadditiveD [OF sa] U_in)
   270       by (blast intro: subadditiveD [OF sa] U_in)
   325   ultimately
   295   ultimately
   326   show ?thesis
   296   show ?thesis
   327     using pos by (simp add: measure_space_def)
   297     using pos by (simp add: measure_space_def)
   328 qed
   298 qed
   329 
   299 
   330 definition outer_measure :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> 'a set \<Rightarrow> ereal" where
   300 definition outer_measure :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> 'a set \<Rightarrow> ennreal" where
   331    "outer_measure M f X =
   301    "outer_measure M f X =
   332      (INF A:{A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i)}. \<Sum>i. f (A i))"
   302      (INF A:{A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i)}. \<Sum>i. f (A i))"
   333 
   303 
   334 lemma (in ring_of_sets) outer_measure_agrees:
   304 lemma (in ring_of_sets) outer_measure_agrees:
   335   assumes posf: "positive M f" and ca: "countably_additive M f" and s: "s \<in> M"
   305   assumes posf: "positive M f" and ca: "countably_additive M f" and s: "s \<in> M"
   344   also have "\<dots> = (\<Sum>i. f (A i \<inter> s))"
   314   also have "\<dots> = (\<Sum>i. f (A i \<inter> s))"
   345     using sA dA A s
   315     using sA dA A s
   346     by (intro ca[unfolded countably_additive_def, rule_format, symmetric])
   316     by (intro ca[unfolded countably_additive_def, rule_format, symmetric])
   347        (auto simp: Int_absorb1 disjoint_family_on_def)
   317        (auto simp: Int_absorb1 disjoint_family_on_def)
   348   also have "... \<le> (\<Sum>i. f (A i))"
   318   also have "... \<le> (\<Sum>i. f (A i))"
   349     using A s by (intro suminf_le_pos increasingD[OF inc] positiveD2[OF posf]) auto
   319     using A s by (auto intro!: suminf_le increasingD[OF inc])
   350   finally show "f s \<le> (\<Sum>i. f (A i))" .
   320   finally show "f s \<le> (\<Sum>i. f (A i))" .
   351 next
   321 next
   352   have "(\<Sum>i. f (if i = 0 then s else {})) \<le> f s"
   322   have "(\<Sum>i. f (if i = 0 then s else {})) \<le> f s"
   353     using positiveD1[OF posf] by (subst suminf_finite[of "{0}"]) auto
   323     using positiveD1[OF posf] by (subst suminf_finite[of "{0}"]) auto
   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"
   324   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"
   355     by (intro INF_lower2[of "\<lambda>i. if i = 0 then s else {}"])
   325     by (intro INF_lower2[of "\<lambda>i. if i = 0 then s else {}"])
   356        (auto simp: disjoint_family_on_def)
   326        (auto simp: disjoint_family_on_def)
   357 qed
   327 qed
   358 
   328 
   359 lemma outer_measure_nonneg: "positive M f \<Longrightarrow> 0 \<le> outer_measure M f X"
       
   360   by (auto intro!: INF_greatest suminf_0_le intro: positiveD2 simp: outer_measure_def)
       
   361 
       
   362 lemma outer_measure_empty:
   329 lemma outer_measure_empty:
   363   assumes posf: "positive M f" and "{} \<in> M"
   330   "positive M f \<Longrightarrow> {} \<in> M \<Longrightarrow> outer_measure M f {} = 0"
   364   shows "outer_measure M f {} = 0"
   331   unfolding outer_measure_def
   365 proof (rule antisym)
   332   by (intro antisym INF_lower2[of  "\<lambda>_. {}"]) (auto simp: disjoint_family_on_def positive_def)
   366   show "outer_measure M f {} \<le> 0"
       
   367     using assms by (auto intro!: INF_lower2[of "\<lambda>_. {}"] simp: outer_measure_def disjoint_family_on_def positive_def)
       
   368 qed (intro outer_measure_nonneg posf)
       
   369 
   333 
   370 lemma (in ring_of_sets) positive_outer_measure:
   334 lemma (in ring_of_sets) positive_outer_measure:
   371   assumes "positive M f" shows "positive (Pow \<Omega>) (outer_measure M f)"
   335   assumes "positive M f" shows "positive (Pow \<Omega>) (outer_measure M f)"
   372   unfolding positive_def by (auto simp: assms outer_measure_empty outer_measure_nonneg)
   336   unfolding positive_def by (auto simp: assms outer_measure_empty)
   373 
   337 
   374 lemma (in ring_of_sets) increasing_outer_measure: "increasing (Pow \<Omega>) (outer_measure M f)"
   338 lemma (in ring_of_sets) increasing_outer_measure: "increasing (Pow \<Omega>) (outer_measure M f)"
   375   by (force simp: increasing_def outer_measure_def intro!: INF_greatest intro: INF_lower)
   339   by (force simp: increasing_def outer_measure_def intro!: INF_greatest intro: INF_lower)
   376 
   340 
   377 lemma (in ring_of_sets) outer_measure_le:
   341 lemma (in ring_of_sets) outer_measure_le:
   381 proof (safe intro!: INF_lower2[of "disjointed A"] del: subsetI)
   345 proof (safe intro!: INF_lower2[of "disjointed A"] del: subsetI)
   382   show dA: "range (disjointed A) \<subseteq> M"
   346   show dA: "range (disjointed A) \<subseteq> M"
   383     by (auto intro!: A range_disjointed_sets)
   347     by (auto intro!: A range_disjointed_sets)
   384   have "\<forall>n. f (disjointed A n) \<le> f (A n)"
   348   have "\<forall>n. f (disjointed A n) \<le> f (A n)"
   385     by (metis increasingD [OF inc] UNIV_I dA image_subset_iff disjointed_subset A)
   349     by (metis increasingD [OF inc] UNIV_I dA image_subset_iff disjointed_subset A)
   386   moreover have "\<forall>i. 0 \<le> f (disjointed A i)"
   350   then show "(\<Sum>i. f (disjointed A i)) \<le> (\<Sum>i. f (A i))"
   387     using pos dA unfolding positive_def by auto
   351     by (blast intro!: suminf_le)
   388   ultimately show "(\<Sum>i. f (disjointed A i)) \<le> (\<Sum>i. f (A i))"
       
   389     by (blast intro!: suminf_le_pos)
       
   390 qed (auto simp: X UN_disjointed_eq disjoint_family_disjointed)
   352 qed (auto simp: X UN_disjointed_eq disjoint_family_disjointed)
   391 
   353 
   392 lemma (in ring_of_sets) outer_measure_close:
   354 lemma (in ring_of_sets) outer_measure_close:
   393   assumes posf: "positive M f" and "0 < e" and "outer_measure M f X \<noteq> \<infinity>"
   355   "outer_measure M f X < e \<Longrightarrow> \<exists>A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i) \<and> (\<Sum>i. f (A i)) < e"
   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"
   356   unfolding outer_measure_def INF_less_iff by auto
   395 proof -
       
   396   from \<open>outer_measure M f X \<noteq> \<infinity>\<close> have fin: "\<bar>outer_measure M f X\<bar> \<noteq> \<infinity>"
       
   397     using outer_measure_nonneg[OF posf, of X] by auto
       
   398   show ?thesis
       
   399     using Inf_ereal_close [OF fin [unfolded outer_measure_def], OF \<open>0 < e\<close>]
       
   400     by (auto intro: less_imp_le simp add: outer_measure_def)
       
   401 qed
       
   402 
   357 
   403 lemma (in ring_of_sets) countably_subadditive_outer_measure:
   358 lemma (in ring_of_sets) countably_subadditive_outer_measure:
   404   assumes posf: "positive M f" and inc: "increasing M f"
   359   assumes posf: "positive M f" and inc: "increasing M f"
   405   shows "countably_subadditive (Pow \<Omega>) (outer_measure M f)"
   360   shows "countably_subadditive (Pow \<Omega>) (outer_measure M f)"
   406 proof (simp add: countably_subadditive_def, safe)
   361 proof (simp add: countably_subadditive_def, safe)
   407   fix A :: "nat \<Rightarrow> _" assume A: "range A \<subseteq> Pow (\<Omega>)" and sb: "(\<Union>i. A i) \<subseteq> \<Omega>"
   362   fix A :: "nat \<Rightarrow> _" assume A: "range A \<subseteq> Pow (\<Omega>)" and sb: "(\<Union>i. A i) \<subseteq> \<Omega>"
   408   let ?O = "outer_measure M f"
   363   let ?O = "outer_measure M f"
   409 
   364   show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n))"
   410   { fix e :: ereal assume e: "0 < e" and "\<forall>i. ?O (A i) \<noteq> \<infinity>"
   365   proof (rule ennreal_le_epsilon)
   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>
   366     fix b and e :: real assume "0 < e" "(\<Sum>n. outer_measure M f (A n)) < top"
   412         (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
   367     then have *: "\<And>n. outer_measure M f (A n) < outer_measure M f (A n) + e * (1/2)^Suc n"
   413       using e sb by (auto intro!: choice outer_measure_close [of f, OF posf] simp: ereal_zero_less_0_iff one_ereal_def)
   368       by (auto simp add: less_top dest!: ennreal_suminf_lessD)
   414     then obtain B
   369     obtain B
   415       where B: "\<And>n. range (B n) \<subseteq> M"
   370       where B: "\<And>n. range (B n) \<subseteq> M"
   416       and sbB: "\<And>n. A n \<subseteq> (\<Union>i. B n i)"
   371       and sbB: "\<And>n. A n \<subseteq> (\<Union>i. B n i)"
   417       and Ble: "\<And>n. (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
   372       and Ble: "\<And>n. (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
   418       by auto blast
   373       by (metis less_imp_le outer_measure_close[OF *])
   419 
   374 
   420     def C \<equiv> "case_prod B o prod_decode"
   375     def C \<equiv> "case_prod B o prod_decode"
   421     from B have B_in_M: "\<And>i j. B i j \<in> M"
   376     from B have B_in_M: "\<And>i j. B i j \<in> M"
   422       by (rule range_subsetD)
   377       by (rule range_subsetD)
   423     then have C: "range C \<subseteq> M"
   378     then have C: "range C \<subseteq> M"
   424       by (auto simp add: C_def split_def)
   379       by (auto simp add: C_def split_def)
   425     have A_C: "(\<Union>i. A i) \<subseteq> (\<Union>i. C i)"
   380     have A_C: "(\<Union>i. A i) \<subseteq> (\<Union>i. C i)"
   426       using sbB by (auto simp add: C_def subset_eq) (metis prod.case prod_encode_inverse)
   381       using sbB by (auto simp add: C_def subset_eq) (metis prod.case prod_encode_inverse)
   427 
   382 
   428     have "?O (\<Union>i. A i) \<le> ?O (\<Union>i. C i)"  
   383     have "?O (\<Union>i. A i) \<le> ?O (\<Union>i. C i)"
   429       using A_C A C by (intro increasing_outer_measure[THEN increasingD]) (auto dest!: sets_into_space)
   384       using A_C A C by (intro increasing_outer_measure[THEN increasingD]) (auto dest!: sets_into_space)
   430     also have "\<dots> \<le> (\<Sum>i. f (C i))"
   385     also have "\<dots> \<le> (\<Sum>i. f (C i))"
   431       using C by (intro outer_measure_le[OF posf inc]) auto
   386       using C by (intro outer_measure_le[OF posf inc]) auto
   432     also have "\<dots> = (\<Sum>n. \<Sum>i. f (B n i))"
   387     also have "\<dots> = (\<Sum>n. \<Sum>i. f (B n i))"
   433       using B_in_M unfolding C_def comp_def by (intro suminf_ereal_2dimen positiveD2[OF posf]) auto
   388       using B_in_M unfolding C_def comp_def by (intro suminf_ennreal_2dimen) auto
   434     also have "\<dots> \<le> (\<Sum>n. ?O (A n) + e*(1/2) ^ Suc n)"
   389     also have "\<dots> \<le> (\<Sum>n. ?O (A n) + e * (1/2) ^ Suc n)"
   435       using B_in_M by (intro suminf_le_pos[OF Ble] suminf_0_le posf[THEN positiveD2]) auto
   390       using B_in_M by (intro suminf_le suminf_nonneg allI Ble) auto
   436     also have "... = (\<Sum>n. ?O (A n)) + (\<Sum>n. e*(1/2) ^ Suc n)"
   391     also have "... = (\<Sum>n. ?O (A n)) + (\<Sum>n. ennreal e * ennreal ((1/2) ^ Suc n))"
   437       using e by (subst suminf_add_ereal) (auto simp add: ereal_zero_le_0_iff outer_measure_nonneg posf)
   392       using \<open>0 < e\<close> by (subst suminf_add[symmetric])
   438     also have "(\<Sum>n. e*(1/2) ^ Suc n) = e"
   393                        (auto simp del: ennreal_suminf_cmult simp add: ennreal_mult[symmetric])
   439       using suminf_half_series_ereal e by (simp add: ereal_zero_le_0_iff suminf_cmult_ereal)
   394     also have "\<dots> = (\<Sum>n. ?O (A n)) + e"
   440     finally have "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n)) + e" . }
   395       unfolding ennreal_suminf_cmult
   441   note * = this
   396       by (subst suminf_ennreal_eq[OF zero_le_power power_half_series]) auto
   442 
   397     finally show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n)) + e" .
   443   show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n))"
   398   qed
   444   proof cases
       
   445     assume "\<forall>i. ?O (A i) \<noteq> \<infinity>" with * show ?thesis
       
   446       by (intro ereal_le_epsilon) auto
       
   447   qed (metis suminf_PInfty[OF outer_measure_nonneg, OF posf] ereal_less_eq(1))
       
   448 qed
   399 qed
   449 
   400 
   450 lemma (in ring_of_sets) outer_measure_space_outer_measure:
   401 lemma (in ring_of_sets) outer_measure_space_outer_measure:
   451   "positive M f \<Longrightarrow> increasing M f \<Longrightarrow> outer_measure_space (Pow \<Omega>) (outer_measure M f)"
   402   "positive M f \<Longrightarrow> increasing M f \<Longrightarrow> outer_measure_space (Pow \<Omega>) (outer_measure M f)"
   452   by (simp add: outer_measure_space_def
   403   by (simp add: outer_measure_space_def
   479         by (rule disjoint_family_on_bisimulation) auto
   430         by (rule disjoint_family_on_bisimulation) auto
   480     qed (insert x A, auto)
   431     qed (insert x A, auto)
   481     ultimately have "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le>
   432     ultimately have "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le>
   482         (\<Sum>i. f (A i \<inter> x)) + (\<Sum>i. f (A i - x))" by (rule add_mono)
   433         (\<Sum>i. f (A i \<inter> x)) + (\<Sum>i. f (A i - x))" by (rule add_mono)
   483     also have "\<dots> = (\<Sum>i. f (A i \<inter> x) + f (A i - x))"
   434     also have "\<dots> = (\<Sum>i. f (A i \<inter> x) + f (A i - x))"
   484       using A(2) x posf by (subst suminf_add_ereal) (auto simp: positive_def)
   435       using A(2) x posf by (subst suminf_add) (auto simp: positive_def)
   485     also have "\<dots> = (\<Sum>i. f (A i))"
   436     also have "\<dots> = (\<Sum>i. f (A i))"
   486       using A x
   437       using A x
   487       by (subst add[THEN additiveD, symmetric])
   438       by (subst add[THEN additiveD, symmetric])
   488          (auto intro!: arg_cong[where f=suminf] arg_cong[where f=f])
   439          (auto intro!: arg_cong[where f=suminf] arg_cong[where f=f])
   489     finally show "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le> (\<Sum>i. f (A i))" .
   440     finally show "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le> (\<Sum>i. f (A i))" .
   494     have "outer_measure M f s = outer_measure M f ((s \<inter> x) \<union> (s - x))"
   445     have "outer_measure M f s = outer_measure M f ((s \<inter> x) \<union> (s - x))"
   495       by (metis Un_Diff_Int Un_commute)
   446       by (metis Un_Diff_Int Un_commute)
   496     also have "... \<le> outer_measure M f (s \<inter> x) + outer_measure M f (s - x)"
   447     also have "... \<le> outer_measure M f (s \<inter> x) + outer_measure M f (s - x)"
   497       apply (rule subadditiveD)
   448       apply (rule subadditiveD)
   498       apply (rule ring_of_sets.countably_subadditive_subadditive [OF ring_of_sets_Pow])
   449       apply (rule ring_of_sets.countably_subadditive_subadditive [OF ring_of_sets_Pow])
   499       apply (simp add: positive_def outer_measure_empty[OF posf] outer_measure_nonneg[OF posf])
   450       apply (simp add: positive_def outer_measure_empty[OF posf])
   500       apply (rule countably_subadditive_outer_measure)
   451       apply (rule countably_subadditive_outer_measure)
   501       using s by (auto intro!: posf inc)
   452       using s by (auto intro!: posf inc)
   502     finally show ?thesis .
   453     finally show ?thesis .
   503   qed
   454   qed
   504   ultimately
   455   ultimately
   511 
   462 
   512 subsection \<open>Caratheodory's theorem\<close>
   463 subsection \<open>Caratheodory's theorem\<close>
   513 
   464 
   514 theorem (in ring_of_sets) caratheodory':
   465 theorem (in ring_of_sets) caratheodory':
   515   assumes posf: "positive M f" and ca: "countably_additive M f"
   466   assumes posf: "positive M f" and ca: "countably_additive M f"
   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>"
   467   shows "\<exists>\<mu> :: 'a set \<Rightarrow> ennreal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
   517 proof -
   468 proof -
   518   have inc: "increasing M f"
   469   have inc: "increasing M f"
   519     by (metis additive_increasing ca countably_additive_additive posf)
   470     by (metis additive_increasing ca countably_additive_additive posf)
   520   let ?O = "outer_measure M f"
   471   let ?O = "outer_measure M f"
   521   def ls \<equiv> "lambda_system \<Omega> (Pow \<Omega>) ?O"
   472   def ls \<equiv> "lambda_system \<Omega> (Pow \<Omega>) ?O"
   539 qed
   490 qed
   540 
   491 
   541 lemma (in ring_of_sets) caratheodory_empty_continuous:
   492 lemma (in ring_of_sets) caratheodory_empty_continuous:
   542   assumes f: "positive M f" "additive M f" and fin: "\<And>A. A \<in> M \<Longrightarrow> f A \<noteq> \<infinity>"
   493   assumes f: "positive M f" "additive M f" and fin: "\<And>A. A \<in> M \<Longrightarrow> f A \<noteq> \<infinity>"
   543   assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> 0"
   494   assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> 0"
   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>"
   495   shows "\<exists>\<mu> :: 'a set \<Rightarrow> ennreal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
   545 proof (intro caratheodory' empty_continuous_imp_countably_additive f)
   496 proof (intro caratheodory' empty_continuous_imp_countably_additive f)
   546   show "\<forall>A\<in>M. f A \<noteq> \<infinity>" using fin by auto
   497   show "\<forall>A\<in>M. f A \<noteq> \<infinity>" using fin by auto
   547 qed (rule cont)
   498 qed (rule cont)
   548 
   499 
   549 subsection \<open>Volumes\<close>
   500 subsection \<open>Volumes\<close>
   550 
   501 
   551 definition volume :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
   502 definition volume :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
   552   "volume M f \<longleftrightarrow>
   503   "volume M f \<longleftrightarrow>
   553   (f {} = 0) \<and> (\<forall>a\<in>M. 0 \<le> f a) \<and>
   504   (f {} = 0) \<and> (\<forall>a\<in>M. 0 \<le> f a) \<and>
   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))"
   505   (\<forall>C\<subseteq>M. disjoint C \<longrightarrow> finite C \<longrightarrow> \<Union>C \<in> M \<longrightarrow> f (\<Union>C) = (\<Sum>c\<in>C. f c))"
   555 
   506 
   556 lemma volumeI:
   507 lemma volumeI:
   567 lemma volume_empty:
   518 lemma volume_empty:
   568   "volume M f \<Longrightarrow> f {} = 0"
   519   "volume M f \<Longrightarrow> f {} = 0"
   569   by (auto simp: volume_def)
   520   by (auto simp: volume_def)
   570 
   521 
   571 lemma volume_finite_additive:
   522 lemma volume_finite_additive:
   572   assumes "volume M f" 
   523   assumes "volume M f"
   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"
   524   assumes A: "\<And>i. i \<in> I \<Longrightarrow> A i \<in> M" "disjoint_family_on A I" "finite I" "UNION I A \<in> M"
   574   shows "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
   525   shows "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
   575 proof -
   526 proof -
   576   have "A`I \<subseteq> M" "disjoint (A`I)" "finite (A`I)" "\<Union>(A`I) \<in> M"
   527   have "A`I \<subseteq> M" "disjoint (A`I)" "finite (A`I)" "\<Union>(A`I) \<in> M"
   577     using A by (auto simp: disjoint_family_on_disjoint_image)
   528     using A by (auto simp: disjoint_family_on_disjoint_image)
   588   finally show "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
   539   finally show "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
   589     by simp
   540     by simp
   590 qed
   541 qed
   591 
   542 
   592 lemma (in ring_of_sets) volume_additiveI:
   543 lemma (in ring_of_sets) volume_additiveI:
   593   assumes pos: "\<And>a. a \<in> M \<Longrightarrow> 0 \<le> \<mu> a" 
   544   assumes pos: "\<And>a. a \<in> M \<Longrightarrow> 0 \<le> \<mu> a"
   594   assumes [simp]: "\<mu> {} = 0"
   545   assumes [simp]: "\<mu> {} = 0"
   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"
   546   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"
   596   shows "volume M \<mu>"
   547   shows "volume M \<mu>"
   597 proof (unfold volume_def, safe)
   548 proof (unfold volume_def, safe)
   598   fix C assume "finite C" "C \<subseteq> M" "disjoint C"
   549   fix C assume "finite C" "C \<subseteq> M" "disjoint C"
   612 proof -
   563 proof -
   613   let ?R = generated_ring
   564   let ?R = generated_ring
   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)"
   565   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)"
   615     by (auto simp: generated_ring_def)
   566     by (auto simp: generated_ring_def)
   616   from bchoice[OF this] guess \<mu>' .. note \<mu>'_spec = this
   567   from bchoice[OF this] guess \<mu>' .. note \<mu>'_spec = this
   617   
   568 
   618   { fix C assume C: "C \<subseteq> M" "finite C" "disjoint C"
   569   { fix C assume C: "C \<subseteq> M" "finite C" "disjoint C"
   619     fix D assume D: "D \<subseteq> M" "finite D" "disjoint D"
   570     fix D assume D: "D \<subseteq> M" "finite D" "disjoint D"
   620     assume "\<Union>C = \<Union>D"
   571     assume "\<Union>C = \<Union>D"
   621     have "(\<Sum>d\<in>D. \<mu> d) = (\<Sum>d\<in>D. \<Sum>c\<in>C. \<mu> (c \<inter> d))"
   572     have "(\<Sum>d\<in>D. \<mu> d) = (\<Sum>d\<in>D. \<Sum>c\<in>C. \<mu> (c \<inter> d))"
   622     proof (intro setsum.cong refl)
   573     proof (intro setsum.cong refl)
   686 
   637 
   687 subsubsection \<open>Caratheodory on semirings\<close>
   638 subsubsection \<open>Caratheodory on semirings\<close>
   688 
   639 
   689 theorem (in semiring_of_sets) caratheodory:
   640 theorem (in semiring_of_sets) caratheodory:
   690   assumes pos: "positive M \<mu>" and ca: "countably_additive M \<mu>"
   641   assumes pos: "positive M \<mu>" and ca: "countably_additive M \<mu>"
   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>'"
   642   shows "\<exists>\<mu>' :: 'a set \<Rightarrow> ennreal. (\<forall>s \<in> M. \<mu>' s = \<mu> s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>'"
   692 proof -
   643 proof -
   693   have "volume M \<mu>"
   644   have "volume M \<mu>"
   694   proof (rule volumeI)
   645   proof (rule volumeI)
   695     { fix a assume "a \<in> M" then show "0 \<le> \<mu> a"
   646     { fix a assume "a \<in> M" then show "0 \<le> \<mu> a"
   696         using pos unfolding positive_def by auto }
   647         using pos unfolding positive_def by auto }
   785         have Ai_eq: "A i = (\<Union>x<card C. f x)"
   736         have Ai_eq: "A i = (\<Union>x<card C. f x)"
   786           using f C Ai unfolding bij_betw_def by auto
   737           using f C Ai unfolding bij_betw_def by auto
   787         then have "\<Union>range f = A i"
   738         then have "\<Union>range f = A i"
   788           using f C Ai unfolding bij_betw_def
   739           using f C Ai unfolding bij_betw_def
   789             by (auto simp add: f_def cong del: strong_SUP_cong)
   740             by (auto simp add: f_def cong del: strong_SUP_cong)
   790         moreover 
   741         moreover
   791         { have "(\<Sum>j. \<mu>_r (f j)) = (\<Sum>j. if j \<in> {..< card C} then \<mu>_r (f j) else 0)"
   742         { have "(\<Sum>j. \<mu>_r (f j)) = (\<Sum>j. if j \<in> {..< card C} then \<mu>_r (f j) else 0)"
   792             using volume_empty[OF V(1)] by (auto intro!: arg_cong[where f=suminf] simp: f_def)
   743             using volume_empty[OF V(1)] by (auto intro!: arg_cong[where f=suminf] simp: f_def)
   793           also have "\<dots> = (\<Sum>j<card C. \<mu>_r (f j))"
   744           also have "\<dots> = (\<Sum>j<card C. \<mu>_r (f j))"
   794             by (rule sums_If_finite_set[THEN sums_unique, symmetric]) simp
   745             by (rule sums_If_finite_set[THEN sums_unique, symmetric]) simp
   795           also have "\<dots> = \<mu>_r (A i)"
   746           also have "\<dots> = \<mu>_r (A i)"
   825           with f A neq show ?thesis
   776           with f A neq show ?thesis
   826             by (fastforce simp: disjoint_family_on_def subset_eq set_eq_iff)
   777             by (fastforce simp: disjoint_family_on_def subset_eq set_eq_iff)
   827         qed
   778         qed
   828       qed
   779       qed
   829       from f have "(\<Sum>n. \<mu>_r (A n)) = (\<Sum>n. \<mu>_r (case_prod f (prod_decode n)))"
   780       from f have "(\<Sum>n. \<mu>_r (A n)) = (\<Sum>n. \<mu>_r (case_prod f (prod_decode n)))"
   830         by (intro suminf_ereal_2dimen[symmetric] positiveD2[OF pos] generated_ringI_Basic)
   781         by (intro suminf_ennreal_2dimen[symmetric] generated_ringI_Basic)
   831          (auto split: prod.split)
   782          (auto split: prod.split)
   832       also have "\<dots> = (\<Sum>n. \<mu> (case_prod f (prod_decode n)))"
   783       also have "\<dots> = (\<Sum>n. \<mu> (case_prod f (prod_decode n)))"
   833         using f V(2) by (auto intro!: arg_cong[where f=suminf] split: prod.split)
   784         using f V(2) by (auto intro!: arg_cong[where f=suminf] split: prod.split)
   834       also have "\<dots> = \<mu> (\<Union>i. case_prod f (prod_decode i))"
   785       also have "\<dots> = \<mu> (\<Union>i. case_prod f (prod_decode i))"
   835         using f \<open>c \<in> C'\<close> C'
   786         using f \<open>c \<in> C'\<close> C'
   845          (auto simp: disjoint_def disjoint_family_on_def
   796          (auto simp: disjoint_def disjoint_family_on_def
   846                intro!: G.Int G.finite_Union arg_cong[where f="\<lambda>X. suminf (\<lambda>i. \<mu>_r (X i))"] ext
   797                intro!: G.Int G.finite_Union arg_cong[where f="\<lambda>X. suminf (\<lambda>i. \<mu>_r (X i))"] ext
   847                intro: generated_ringI_Basic)
   798                intro: generated_ringI_Basic)
   848     also have "\<dots> = (\<Sum>c\<in>C'. \<Sum>n. \<mu>_r (A' n \<inter> c))"
   799     also have "\<dots> = (\<Sum>c\<in>C'. \<Sum>n. \<mu>_r (A' n \<inter> c))"
   849       using C' A'
   800       using C' A'
   850       by (intro suminf_setsum_ereal positiveD2[OF pos] G.Int G.finite_Union)
   801       by (intro suminf_setsum G.Int G.finite_Union) (auto intro: generated_ringI_Basic)
   851          (auto intro: generated_ringI_Basic)
       
   852     also have "\<dots> = (\<Sum>c\<in>C'. \<mu>_r c)"
   802     also have "\<dots> = (\<Sum>c\<in>C'. \<mu>_r c)"
   853       using eq V C' by (auto intro!: setsum.cong)
   803       using eq V C' by (auto intro!: setsum.cong)
   854     also have "\<dots> = \<mu>_r (\<Union>C')"
   804     also have "\<dots> = \<mu>_r (\<Union>C')"
   855       using C' Un_A
   805       using C' Un_A
   856       by (subst volume_finite_additive[symmetric, OF V(1)])
   806       by (subst volume_finite_additive[symmetric, OF V(1)])
   907       by fact
   857       by fact
   908     then show "positive (sets M) \<mu>'" "countably_additive (sets M) \<mu>'"
   858     then show "positive (sets M) \<mu>'" "countably_additive (sets M) \<mu>'"
   909       using \<mu>' by (simp_all add: M sets_extend_measure measure_space_def)
   859       using \<mu>' by (simp_all add: M sets_extend_measure measure_space_def)
   910   qed fact
   860   qed fact
   911 qed
   861 qed
   912   
   862 
   913 lemma extend_measure_caratheodory_pair:
   863 lemma extend_measure_caratheodory_pair:
   914   fixes G :: "'i \<Rightarrow> 'j \<Rightarrow> 'a set"
   864   fixes G :: "'i \<Rightarrow> 'j \<Rightarrow> 'a set"
   915   assumes M: "M = extend_measure \<Omega> {(a, b). P a b} (\<lambda>(a, b). G a b) (\<lambda>(a, b). \<mu> a b)"
   865   assumes M: "M = extend_measure \<Omega> {(a, b). P a b} (\<lambda>(a, b). G a b) (\<lambda>(a, b). \<mu> a b)"
   916   assumes "P i j"
   866   assumes "P i j"
   917   assumes semiring: "semiring_of_sets \<Omega> {G a b | a b. P a b}"
   867   assumes semiring: "semiring_of_sets \<Omega> {G a b | a b. P a b}"