src/HOL/Probability/Caratheodory.thy
author hoelzl
Tue Mar 22 20:06:10 2011 +0100 (2011-03-22)
changeset 42067 66c8281349ec
parent 42066 6db76c88907a
child 42145 8448713d48b7
permissions -rw-r--r--
standardized headers
     1 (*  Title:      HOL/Probability/Caratheodory.thy
     2     Author:     Lawrence C Paulson
     3     Author:     Johannes Hölzl, TU München
     4 *)
     5 
     6 header {*Caratheodory Extension Theorem*}
     7 
     8 theory Caratheodory
     9   imports Sigma_Algebra Extended_Real_Limits
    10 begin
    11 
    12 text {*
    13   Originally from the Hurd/Coble measure theory development, translated by Lawrence Paulson.
    14 *}
    15 
    16 lemma suminf_extreal_2dimen:
    17   fixes f:: "nat \<times> nat \<Rightarrow> extreal"
    18   assumes pos: "\<And>p. 0 \<le> f p"
    19   assumes "\<And>m. g m = (\<Sum>n. f (m,n))"
    20   shows "(\<Sum>i. f (prod_decode i)) = suminf g"
    21 proof -
    22   have g_def: "g = (\<lambda>m. (\<Sum>n. f (m,n)))"
    23     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)"
    25     by (simp add: setsum_reindex[OF inj_prod_decode] comp_def)
    26   { fix n
    27     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       then have "a < ?M fst" "b < ?M snd"
    30         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       by (auto intro!: setsum_mono3 simp: pos)
    33     then have "\<exists>a b. setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<a} \<times> {..<b})" by auto }
    34   moreover
    35   { fix a b
    36     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         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       by (auto intro!: setsum_mono3 simp: pos) }
    41   ultimately
    42   show ?thesis unfolding g_def using pos
    43     by (auto intro!: SUPR_eq  simp: setsum_cartesian_product reindex le_SUPI2
    44                      setsum_nonneg suminf_extreal_eq_SUPR SUPR_pair
    45                      SUPR_extreal_setsum[symmetric] incseq_setsumI setsum_nonneg)
    46 qed
    47 
    48 subsection {* Measure Spaces *}
    49 
    50 record 'a measure_space = "'a algebra" +
    51   measure :: "'a set \<Rightarrow> extreal"
    52 
    53 definition positive where "positive M f \<longleftrightarrow> f {} = (0::extreal) \<and> (\<forall>A\<in>sets M. 0 \<le> f A)"
    54 
    55 definition additive where "additive M f \<longleftrightarrow>
    56   (\<forall>x \<in> sets M. \<forall>y \<in> sets M. x \<inter> y = {} \<longrightarrow> f (x \<union> y) = f x + f y)"
    57 
    58 definition countably_additive :: "('a, 'b) algebra_scheme \<Rightarrow> ('a set \<Rightarrow> extreal) \<Rightarrow> bool" where
    59   "countably_additive M f \<longleftrightarrow> (\<forall>A. range A \<subseteq> sets M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> sets M \<longrightarrow>
    60     (\<Sum>i. f (A i)) = f (\<Union>i. A i))"
    61 
    62 definition increasing where "increasing M f \<longleftrightarrow>
    63   (\<forall>x \<in> sets M. \<forall>y \<in> sets M. x \<subseteq> y \<longrightarrow> f x \<le> f y)"
    64 
    65 definition subadditive where "subadditive M f \<longleftrightarrow>
    66   (\<forall>x \<in> sets M. \<forall>y \<in> sets M. x \<inter> y = {} \<longrightarrow> f (x \<union> y) \<le> f x + f y)"
    67 
    68 definition countably_subadditive where "countably_subadditive M f \<longleftrightarrow>
    69   (\<forall>A. range A \<subseteq> sets M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> sets M \<longrightarrow>
    70     (f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))))"
    71 
    72 definition lambda_system where "lambda_system M f = {l \<in> sets M.
    73   \<forall>x \<in> sets M. f (l \<inter> x) + f ((space M - l) \<inter> x) = f x}"
    74 
    75 definition outer_measure_space where "outer_measure_space M f \<longleftrightarrow>
    76   positive M f \<and> increasing M f \<and> countably_subadditive M f"
    77 
    78 definition measure_set where "measure_set M f X = {r.
    79   \<exists>A. range A \<subseteq> sets M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i) \<and> (\<Sum>i. f (A i)) = r}"
    80 
    81 locale measure_space = sigma_algebra M for M :: "('a, 'b) measure_space_scheme" +
    82   assumes measure_positive: "positive M (measure M)"
    83       and ca: "countably_additive M (measure M)"
    84 
    85 abbreviation (in measure_space) "\<mu> \<equiv> measure M"
    86 
    87 lemma (in measure_space)
    88   shows empty_measure[simp, intro]: "\<mu> {} = 0"
    89   and positive_measure[simp, intro!]: "\<And>A. A \<in> sets M \<Longrightarrow> 0 \<le> \<mu> A"
    90   using measure_positive unfolding positive_def by auto
    91 
    92 lemma increasingD:
    93   "increasing M f \<Longrightarrow> x \<subseteq> y \<Longrightarrow> x\<in>sets M \<Longrightarrow> y\<in>sets M \<Longrightarrow> f x \<le> f y"
    94   by (auto simp add: increasing_def)
    95 
    96 lemma subadditiveD:
    97   "subadditive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x \<in> sets M \<Longrightarrow> y \<in> sets M
    98     \<Longrightarrow> f (x \<union> y) \<le> f x + f y"
    99   by (auto simp add: subadditive_def)
   100 
   101 lemma additiveD:
   102   "additive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x \<in> sets M \<Longrightarrow> y \<in> sets M
   103     \<Longrightarrow> f (x \<union> y) = f x + f y"
   104   by (auto simp add: additive_def)
   105 
   106 lemma countably_additiveI:
   107   assumes "\<And>A x. range A \<subseteq> sets M \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Union>i. A i) \<in> sets M
   108     \<Longrightarrow> (\<Sum>i. f (A i)) = f (\<Union>i. A i)"
   109   shows "countably_additive M f"
   110   using assms by (simp add: countably_additive_def)
   111 
   112 section "Extend binary sets"
   113 
   114 lemma LIMSEQ_binaryset:
   115   assumes f: "f {} = 0"
   116   shows  "(\<lambda>n. \<Sum>i<n. f (binaryset A B i)) ----> f A + f B"
   117 proof -
   118   have "(\<lambda>n. \<Sum>i < Suc (Suc n). f (binaryset A B i)) = (\<lambda>n. f A + f B)"
   119     proof
   120       fix n
   121       show "(\<Sum>i < Suc (Suc n). f (binaryset A B i)) = f A + f B"
   122         by (induct n)  (auto simp add: binaryset_def f)
   123     qed
   124   moreover
   125   have "... ----> f A + f B" by (rule LIMSEQ_const)
   126   ultimately
   127   have "(\<lambda>n. \<Sum>i< Suc (Suc n). f (binaryset A B i)) ----> f A + f B"
   128     by metis
   129   hence "(\<lambda>n. \<Sum>i< n+2. f (binaryset A B i)) ----> f A + f B"
   130     by simp
   131   thus ?thesis by (rule LIMSEQ_offset [where k=2])
   132 qed
   133 
   134 lemma binaryset_sums:
   135   assumes f: "f {} = 0"
   136   shows  "(\<lambda>n. f (binaryset A B n)) sums (f A + f B)"
   137     by (simp add: sums_def LIMSEQ_binaryset [where f=f, OF f] atLeast0LessThan)
   138 
   139 lemma suminf_binaryset_eq:
   140   fixes f :: "'a set \<Rightarrow> 'b::{comm_monoid_add, t2_space}"
   141   shows "f {} = 0 \<Longrightarrow> (\<Sum>n. f (binaryset A B n)) = f A + f B"
   142   by (metis binaryset_sums sums_unique)
   143 
   144 subsection {* Lambda Systems *}
   145 
   146 lemma (in algebra) lambda_system_eq:
   147   shows "lambda_system M f = {l \<in> sets M.
   148     \<forall>x \<in> sets M. f (x \<inter> l) + f (x - l) = f x}"
   149 proof -
   150   have [simp]: "!!l x. l \<in> sets M \<Longrightarrow> x \<in> sets M \<Longrightarrow> (space M - l) \<inter> x = x - l"
   151     by (metis Int_Diff Int_absorb1 Int_commute sets_into_space)
   152   show ?thesis
   153     by (auto simp add: lambda_system_def) (metis Int_commute)+
   154 qed
   155 
   156 lemma (in algebra) lambda_system_empty:
   157   "positive M f \<Longrightarrow> {} \<in> lambda_system M f"
   158   by (auto simp add: positive_def lambda_system_eq)
   159 
   160 lemma lambda_system_sets:
   161   "x \<in> lambda_system M f \<Longrightarrow> x \<in> sets M"
   162   by (simp add: lambda_system_def)
   163 
   164 lemma (in algebra) lambda_system_Compl:
   165   fixes f:: "'a set \<Rightarrow> extreal"
   166   assumes x: "x \<in> lambda_system M f"
   167   shows "space M - x \<in> lambda_system M f"
   168 proof -
   169   have "x \<subseteq> space M"
   170     by (metis sets_into_space lambda_system_sets x)
   171   hence "space M - (space M - x) = x"
   172     by (metis double_diff equalityE)
   173   with x show ?thesis
   174     by (force simp add: lambda_system_def ac_simps)
   175 qed
   176 
   177 lemma (in algebra) lambda_system_Int:
   178   fixes f:: "'a set \<Rightarrow> extreal"
   179   assumes xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   180   shows "x \<inter> y \<in> lambda_system M f"
   181 proof -
   182   from xl yl show ?thesis
   183   proof (auto simp add: positive_def lambda_system_eq Int)
   184     fix u
   185     assume x: "x \<in> sets M" and y: "y \<in> sets M" and u: "u \<in> sets M"
   186        and fx: "\<forall>z\<in>sets M. f (z \<inter> x) + f (z - x) = f z"
   187        and fy: "\<forall>z\<in>sets M. f (z \<inter> y) + f (z - y) = f z"
   188     have "u - x \<inter> y \<in> sets M"
   189       by (metis Diff Diff_Int Un u x y)
   190     moreover
   191     have "(u - (x \<inter> y)) \<inter> y = u \<inter> y - x" by blast
   192     moreover
   193     have "u - x \<inter> y - y = u - y" by blast
   194     ultimately
   195     have ey: "f (u - x \<inter> y) = f (u \<inter> y - x) + f (u - y)" using fy
   196       by force
   197     have "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y)
   198           = (f (u \<inter> (x \<inter> y)) + f (u \<inter> y - x)) + f (u - y)"
   199       by (simp add: ey ac_simps)
   200     also have "... =  (f ((u \<inter> y) \<inter> x) + f (u \<inter> y - x)) + f (u - y)"
   201       by (simp add: Int_ac)
   202     also have "... = f (u \<inter> y) + f (u - y)"
   203       using fx [THEN bspec, of "u \<inter> y"] Int y u
   204       by force
   205     also have "... = f u"
   206       by (metis fy u)
   207     finally show "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y) = f u" .
   208   qed
   209 qed
   210 
   211 lemma (in algebra) lambda_system_Un:
   212   fixes f:: "'a set \<Rightarrow> extreal"
   213   assumes xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   214   shows "x \<union> y \<in> lambda_system M f"
   215 proof -
   216   have "(space M - x) \<inter> (space M - y) \<in> sets M"
   217     by (metis Diff_Un Un compl_sets lambda_system_sets xl yl)
   218   moreover
   219   have "x \<union> y = space M - ((space M - x) \<inter> (space M - y))"
   220     by auto  (metis subsetD lambda_system_sets sets_into_space xl yl)+
   221   ultimately show ?thesis
   222     by (metis lambda_system_Compl lambda_system_Int xl yl)
   223 qed
   224 
   225 lemma (in algebra) lambda_system_algebra:
   226   "positive M f \<Longrightarrow> algebra (M\<lparr>sets := lambda_system M f\<rparr>)"
   227   apply (auto simp add: algebra_iff_Un)
   228   apply (metis lambda_system_sets set_mp sets_into_space)
   229   apply (metis lambda_system_empty)
   230   apply (metis lambda_system_Compl)
   231   apply (metis lambda_system_Un)
   232   done
   233 
   234 lemma (in algebra) lambda_system_strong_additive:
   235   assumes z: "z \<in> sets M" and disj: "x \<inter> y = {}"
   236       and xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   237   shows "f (z \<inter> (x \<union> y)) = f (z \<inter> x) + f (z \<inter> y)"
   238 proof -
   239   have "z \<inter> x = (z \<inter> (x \<union> y)) \<inter> x" using disj by blast
   240   moreover
   241   have "z \<inter> y = (z \<inter> (x \<union> y)) - x" using disj by blast
   242   moreover
   243   have "(z \<inter> (x \<union> y)) \<in> sets M"
   244     by (metis Int Un lambda_system_sets xl yl z)
   245   ultimately show ?thesis using xl yl
   246     by (simp add: lambda_system_eq)
   247 qed
   248 
   249 lemma (in algebra) lambda_system_additive:
   250      "additive (M (|sets := lambda_system M f|)) f"
   251 proof (auto simp add: additive_def)
   252   fix x and y
   253   assume disj: "x \<inter> y = {}"
   254      and xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   255   hence  "x \<in> sets M" "y \<in> sets M" by (blast intro: lambda_system_sets)+
   256   thus "f (x \<union> y) = f x + f y"
   257     using lambda_system_strong_additive [OF top disj xl yl]
   258     by (simp add: Un)
   259 qed
   260 
   261 lemma (in algebra) countably_subadditive_subadditive:
   262   assumes f: "positive M f" and cs: "countably_subadditive M f"
   263   shows  "subadditive M f"
   264 proof (auto simp add: subadditive_def)
   265   fix x y
   266   assume x: "x \<in> sets M" and y: "y \<in> sets M" and "x \<inter> y = {}"
   267   hence "disjoint_family (binaryset x y)"
   268     by (auto simp add: disjoint_family_on_def binaryset_def)
   269   hence "range (binaryset x y) \<subseteq> sets M \<longrightarrow>
   270          (\<Union>i. binaryset x y i) \<in> sets M \<longrightarrow>
   271          f (\<Union>i. binaryset x y i) \<le> (\<Sum> n. f (binaryset x y n))"
   272     using cs by (auto simp add: countably_subadditive_def)
   273   hence "{x,y,{}} \<subseteq> sets M \<longrightarrow> x \<union> y \<in> sets M \<longrightarrow>
   274          f (x \<union> y) \<le> (\<Sum> n. f (binaryset x y n))"
   275     by (simp add: range_binaryset_eq UN_binaryset_eq)
   276   thus "f (x \<union> y) \<le>  f x + f y" using f x y
   277     by (auto simp add: Un o_def suminf_binaryset_eq positive_def)
   278 qed
   279 
   280 lemma (in algebra) additive_sum:
   281   fixes A:: "nat \<Rightarrow> 'a set"
   282   assumes f: "positive M f" and ad: "additive M f" and "finite S"
   283       and A: "range A \<subseteq> sets M"
   284       and disj: "disjoint_family_on A S"
   285   shows  "(\<Sum>i\<in>S. f (A i)) = f (\<Union>i\<in>S. A i)"
   286 using `finite S` disj proof induct
   287   case empty show ?case using f by (simp add: positive_def)
   288 next
   289   case (insert s S)
   290   then have "A s \<inter> (\<Union>i\<in>S. A i) = {}"
   291     by (auto simp add: disjoint_family_on_def neq_iff)
   292   moreover
   293   have "A s \<in> sets M" using A by blast
   294   moreover have "(\<Union>i\<in>S. A i) \<in> sets M"
   295     using A `finite S` by auto
   296   moreover
   297   ultimately have "f (A s \<union> (\<Union>i\<in>S. A i)) = f (A s) + f(\<Union>i\<in>S. A i)"
   298     using ad UNION_in_sets A by (auto simp add: additive_def)
   299   with insert show ?case using ad disjoint_family_on_mono[of S "insert s S" A]
   300     by (auto simp add: additive_def subset_insertI)
   301 qed
   302 
   303 lemma (in algebra) increasing_additive_bound:
   304   fixes A:: "nat \<Rightarrow> 'a set" and  f :: "'a set \<Rightarrow> extreal"
   305   assumes f: "positive M f" and ad: "additive M f"
   306       and inc: "increasing M f"
   307       and A: "range A \<subseteq> sets M"
   308       and disj: "disjoint_family A"
   309   shows  "(\<Sum>i. f (A i)) \<le> f (space M)"
   310 proof (safe intro!: suminf_bound)
   311   fix N
   312   note disj_N = disjoint_family_on_mono[OF _ disj, of "{..<N}"]
   313   have "(\<Sum>i<N. f (A i)) = f (\<Union>i\<in>{..<N}. A i)"
   314     by (rule additive_sum [OF f ad _ A]) (auto simp: disj_N)
   315   also have "... \<le> f (space M)" using space_closed A
   316     by (intro increasingD[OF inc] finite_UN) auto
   317   finally show "(\<Sum>i<N. f (A i)) \<le> f (space M)" by simp
   318 qed (insert f A, auto simp: positive_def)
   319 
   320 lemma lambda_system_increasing:
   321  "increasing M f \<Longrightarrow> increasing (M (|sets := lambda_system M f|)) f"
   322   by (simp add: increasing_def lambda_system_def)
   323 
   324 lemma lambda_system_positive:
   325   "positive M f \<Longrightarrow> positive (M (|sets := lambda_system M f|)) f"
   326   by (simp add: positive_def lambda_system_def)
   327 
   328 lemma (in algebra) lambda_system_strong_sum:
   329   fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> extreal"
   330   assumes f: "positive M f" and a: "a \<in> sets M"
   331       and A: "range A \<subseteq> lambda_system M f"
   332       and disj: "disjoint_family A"
   333   shows  "(\<Sum>i = 0..<n. f (a \<inter>A i)) = f (a \<inter> (\<Union>i\<in>{0..<n}. A i))"
   334 proof (induct n)
   335   case 0 show ?case using f by (simp add: positive_def)
   336 next
   337   case (Suc n)
   338   have 2: "A n \<inter> UNION {0..<n} A = {}" using disj
   339     by (force simp add: disjoint_family_on_def neq_iff)
   340   have 3: "A n \<in> lambda_system M f" using A
   341     by blast
   342   interpret l: algebra "M\<lparr>sets := lambda_system M f\<rparr>"
   343     using f by (rule lambda_system_algebra)
   344   have 4: "UNION {0..<n} A \<in> lambda_system M f"
   345     using A l.UNION_in_sets by simp
   346   from Suc.hyps show ?case
   347     by (simp add: atLeastLessThanSuc lambda_system_strong_additive [OF a 2 3 4])
   348 qed
   349 
   350 lemma (in sigma_algebra) lambda_system_caratheodory:
   351   assumes oms: "outer_measure_space M f"
   352       and A: "range A \<subseteq> lambda_system M f"
   353       and disj: "disjoint_family A"
   354   shows  "(\<Union>i. A i) \<in> lambda_system M f \<and> (\<Sum>i. f (A i)) = f (\<Union>i. A i)"
   355 proof -
   356   have pos: "positive M f" and inc: "increasing M f"
   357    and csa: "countably_subadditive M f"
   358     by (metis oms outer_measure_space_def)+
   359   have sa: "subadditive M f"
   360     by (metis countably_subadditive_subadditive csa pos)
   361   have A': "range A \<subseteq> sets (M(|sets := lambda_system M f|))" using A
   362     by simp
   363   interpret ls: algebra "M\<lparr>sets := lambda_system M f\<rparr>"
   364     using pos by (rule lambda_system_algebra)
   365   have A'': "range A \<subseteq> sets M"
   366      by (metis A image_subset_iff lambda_system_sets)
   367 
   368   have U_in: "(\<Union>i. A i) \<in> sets M"
   369     by (metis A'' countable_UN)
   370   have U_eq: "f (\<Union>i. A i) = (\<Sum>i. f (A i))"
   371   proof (rule antisym)
   372     show "f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))"
   373       using csa[unfolded countably_subadditive_def] A'' disj U_in by auto
   374     have *: "\<And>i. 0 \<le> f (A i)" using pos A'' unfolding positive_def by auto
   375     have dis: "\<And>N. disjoint_family_on A {..<N}" by (intro disjoint_family_on_mono[OF _ disj]) auto
   376     show "(\<Sum>i. f (A i)) \<le> f (\<Union>i. A i)"
   377       using ls.additive_sum [OF lambda_system_positive[OF pos] lambda_system_additive _ A' dis]
   378       using A''
   379       by (intro suminf_bound[OF _ *]) (auto intro!: increasingD[OF inc] allI countable_UN)
   380   qed
   381   {
   382     fix a
   383     assume a [iff]: "a \<in> sets M"
   384     have "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) = f a"
   385     proof -
   386       show ?thesis
   387       proof (rule antisym)
   388         have "range (\<lambda>i. a \<inter> A i) \<subseteq> sets M" using A''
   389           by blast
   390         moreover
   391         have "disjoint_family (\<lambda>i. a \<inter> A i)" using disj
   392           by (auto simp add: disjoint_family_on_def)
   393         moreover
   394         have "a \<inter> (\<Union>i. A i) \<in> sets M"
   395           by (metis Int U_in a)
   396         ultimately
   397         have "f (a \<inter> (\<Union>i. A i)) \<le> (\<Sum>i. f (a \<inter> A i))"
   398           using csa[unfolded countably_subadditive_def, rule_format, of "(\<lambda>i. a \<inter> A i)"]
   399           by (simp add: o_def)
   400         hence "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le>
   401             (\<Sum>i. f (a \<inter> A i)) + f (a - (\<Union>i. A i))"
   402           by (rule add_right_mono)
   403         moreover
   404         have "(\<Sum>i. f (a \<inter> A i)) + f (a - (\<Union>i. A i)) \<le> f a"
   405           proof (intro suminf_bound_add allI)
   406             fix n
   407             have UNION_in: "(\<Union>i\<in>{0..<n}. A i) \<in> sets M"
   408               by (metis A'' UNION_in_sets)
   409             have le_fa: "f (UNION {0..<n} A \<inter> a) \<le> f a" using A''
   410               by (blast intro: increasingD [OF inc] A'' UNION_in_sets)
   411             have ls: "(\<Union>i\<in>{0..<n}. A i) \<in> lambda_system M f"
   412               using ls.UNION_in_sets by (simp add: A)
   413             hence eq_fa: "f a = f (a \<inter> (\<Union>i\<in>{0..<n}. A i)) + f (a - (\<Union>i\<in>{0..<n}. A i))"
   414               by (simp add: lambda_system_eq UNION_in)
   415             have "f (a - (\<Union>i. A i)) \<le> f (a - (\<Union>i\<in>{0..<n}. A i))"
   416               by (blast intro: increasingD [OF inc] UNION_eq_Union_image
   417                                UNION_in U_in)
   418             thus "(\<Sum>i<n. f (a \<inter> A i)) + f (a - (\<Union>i. A i)) \<le> f a"
   419               by (simp add: lambda_system_strong_sum pos A disj eq_fa add_left_mono atLeast0LessThan[symmetric])
   420           next
   421             have "\<And>i. a \<inter> A i \<in> sets M" using A'' by auto
   422             then show "\<And>i. 0 \<le> f (a \<inter> A i)" using pos[unfolded positive_def] by auto
   423             have "\<And>i. a - (\<Union>i. A i) \<in> sets M" using A'' by auto
   424             then have "\<And>i. 0 \<le> f (a - (\<Union>i. A i))" using pos[unfolded positive_def] by auto
   425             then show "f (a - (\<Union>i. A i)) \<noteq> -\<infinity>" by auto
   426           qed
   427         ultimately show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a"
   428           by (rule order_trans)
   429       next
   430         have "f a \<le> f (a \<inter> (\<Union>i. A i) \<union> (a - (\<Union>i. A i)))"
   431           by (blast intro:  increasingD [OF inc] U_in)
   432         also have "... \<le>  f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))"
   433           by (blast intro: subadditiveD [OF sa] U_in)
   434         finally show "f a \<le> f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))" .
   435         qed
   436      qed
   437   }
   438   thus  ?thesis
   439     by (simp add: lambda_system_eq sums_iff U_eq U_in)
   440 qed
   441 
   442 lemma (in sigma_algebra) caratheodory_lemma:
   443   assumes oms: "outer_measure_space M f"
   444   shows "measure_space \<lparr> space = space M, sets = lambda_system M f, measure = f \<rparr>"
   445     (is "measure_space ?M")
   446 proof -
   447   have pos: "positive M f"
   448     by (metis oms outer_measure_space_def)
   449   have alg: "algebra ?M"
   450     using lambda_system_algebra [of f, OF pos]
   451     by (simp add: algebra_iff_Un)
   452   then
   453   have "sigma_algebra ?M"
   454     using lambda_system_caratheodory [OF oms]
   455     by (simp add: sigma_algebra_disjoint_iff)
   456   moreover
   457   have "measure_space_axioms ?M"
   458     using pos lambda_system_caratheodory [OF oms]
   459     by (simp add: measure_space_axioms_def positive_def lambda_system_sets
   460                   countably_additive_def o_def)
   461   ultimately
   462   show ?thesis
   463     by (simp add: measure_space_def)
   464 qed
   465 
   466 lemma (in ring_of_sets) additive_increasing:
   467   assumes posf: "positive M f" and addf: "additive M f"
   468   shows "increasing M f"
   469 proof (auto simp add: increasing_def)
   470   fix x y
   471   assume xy: "x \<in> sets M" "y \<in> sets M" "x \<subseteq> y"
   472   then have "y - x \<in> sets M" by auto
   473   then have "0 \<le> f (y-x)" using posf[unfolded positive_def] by auto
   474   then have "f x + 0 \<le> f x + f (y-x)" by (intro add_left_mono) auto
   475   also have "... = f (x \<union> (y-x))" using addf
   476     by (auto simp add: additive_def) (metis Diff_disjoint Un_Diff_cancel Diff xy(1,2))
   477   also have "... = f y"
   478     by (metis Un_Diff_cancel Un_absorb1 xy(3))
   479   finally show "f x \<le> f y" by simp
   480 qed
   481 
   482 lemma (in ring_of_sets) countably_additive_additive:
   483   assumes posf: "positive M f" and ca: "countably_additive M f"
   484   shows "additive M f"
   485 proof (auto simp add: additive_def)
   486   fix x y
   487   assume x: "x \<in> sets M" and y: "y \<in> sets M" and "x \<inter> y = {}"
   488   hence "disjoint_family (binaryset x y)"
   489     by (auto simp add: disjoint_family_on_def binaryset_def)
   490   hence "range (binaryset x y) \<subseteq> sets M \<longrightarrow>
   491          (\<Union>i. binaryset x y i) \<in> sets M \<longrightarrow>
   492          f (\<Union>i. binaryset x y i) = (\<Sum> n. f (binaryset x y n))"
   493     using ca
   494     by (simp add: countably_additive_def)
   495   hence "{x,y,{}} \<subseteq> sets M \<longrightarrow> x \<union> y \<in> sets M \<longrightarrow>
   496          f (x \<union> y) = (\<Sum>n. f (binaryset x y n))"
   497     by (simp add: range_binaryset_eq UN_binaryset_eq)
   498   thus "f (x \<union> y) = f x + f y" using posf x y
   499     by (auto simp add: Un suminf_binaryset_eq positive_def)
   500 qed
   501 
   502 lemma inf_measure_nonempty:
   503   assumes f: "positive M f" and b: "b \<in> sets M" and a: "a \<subseteq> b" "{} \<in> sets M"
   504   shows "f b \<in> measure_set M f a"
   505 proof -
   506   let ?A = "\<lambda>i::nat. (if i = 0 then b else {})"
   507   have "(\<Sum>i. f (?A i)) = (\<Sum>i<1::nat. f (?A i))"
   508     by (rule suminf_finite) (simp add: f[unfolded positive_def])
   509   also have "... = f b"
   510     by simp
   511   finally show ?thesis using assms
   512     by (auto intro!: exI [of _ ?A]
   513              simp: measure_set_def disjoint_family_on_def split_if_mem2 comp_def)
   514 qed
   515 
   516 lemma (in ring_of_sets) inf_measure_agrees:
   517   assumes posf: "positive M f" and ca: "countably_additive M f"
   518       and s: "s \<in> sets M"
   519   shows "Inf (measure_set M f s) = f s"
   520   unfolding Inf_extreal_def
   521 proof (safe intro!: Greatest_equality)
   522   fix z
   523   assume z: "z \<in> measure_set M f s"
   524   from this obtain A where
   525     A: "range A \<subseteq> sets M" and disj: "disjoint_family A"
   526     and "s \<subseteq> (\<Union>x. A x)" and si: "(\<Sum>i. f (A i)) = z"
   527     by (auto simp add: measure_set_def comp_def)
   528   hence seq: "s = (\<Union>i. A i \<inter> s)" by blast
   529   have inc: "increasing M f"
   530     by (metis additive_increasing ca countably_additive_additive posf)
   531   have sums: "(\<Sum>i. f (A i \<inter> s)) = f (\<Union>i. A i \<inter> s)"
   532     proof (rule ca[unfolded countably_additive_def, rule_format])
   533       show "range (\<lambda>n. A n \<inter> s) \<subseteq> sets M" using A s
   534         by blast
   535       show "disjoint_family (\<lambda>n. A n \<inter> s)" using disj
   536         by (auto simp add: disjoint_family_on_def)
   537       show "(\<Union>i. A i \<inter> s) \<in> sets M" using A s
   538         by (metis UN_extend_simps(4) s seq)
   539     qed
   540   hence "f s = (\<Sum>i. f (A i \<inter> s))"
   541     using seq [symmetric] by (simp add: sums_iff)
   542   also have "... \<le> (\<Sum>i. f (A i))"
   543     proof (rule suminf_le_pos)
   544       fix n show "f (A n \<inter> s) \<le> f (A n)" using A s
   545         by (force intro: increasingD [OF inc])
   546       fix N have "A N \<inter> s \<in> sets M"  using A s by auto
   547       then show "0 \<le> f (A N \<inter> s)" using posf unfolding positive_def by auto
   548     qed
   549   also have "... = z" by (rule si)
   550   finally show "f s \<le> z" .
   551 next
   552   fix y
   553   assume y: "\<forall>u \<in> measure_set M f s. y \<le> u"
   554   thus "y \<le> f s"
   555     by (blast intro: inf_measure_nonempty [of _ f, OF posf s subset_refl])
   556 qed
   557 
   558 lemma measure_set_pos:
   559   assumes posf: "positive M f" "r \<in> measure_set M f X"
   560   shows "0 \<le> r"
   561 proof -
   562   obtain A where "range A \<subseteq> sets M" and r: "r = (\<Sum>i. f (A i))"
   563     using `r \<in> measure_set M f X` unfolding measure_set_def by auto
   564   then show "0 \<le> r" using posf unfolding r positive_def
   565     by (intro suminf_0_le) auto
   566 qed
   567 
   568 lemma inf_measure_pos:
   569   assumes posf: "positive M f"
   570   shows "0 \<le> Inf (measure_set M f X)"
   571 proof (rule complete_lattice_class.Inf_greatest)
   572   fix r assume "r \<in> measure_set M f X" with posf show "0 \<le> r"
   573     by (rule measure_set_pos)
   574 qed
   575 
   576 lemma inf_measure_empty:
   577   assumes posf: "positive M f" and "{} \<in> sets M"
   578   shows "Inf (measure_set M f {}) = 0"
   579 proof (rule antisym)
   580   show "Inf (measure_set M f {}) \<le> 0"
   581     by (metis complete_lattice_class.Inf_lower `{} \<in> sets M`
   582               inf_measure_nonempty[OF posf] subset_refl posf[unfolded positive_def])
   583 qed (rule inf_measure_pos[OF posf])
   584 
   585 lemma (in ring_of_sets) inf_measure_positive:
   586   assumes p: "positive M f" and "{} \<in> sets M"
   587   shows "positive M (\<lambda>x. Inf (measure_set M f x))"
   588 proof (unfold positive_def, intro conjI ballI)
   589   show "Inf (measure_set M f {}) = 0" using inf_measure_empty[OF assms] by auto
   590   fix A assume "A \<in> sets M"
   591 qed (rule inf_measure_pos[OF p])
   592 
   593 lemma (in ring_of_sets) inf_measure_increasing:
   594   assumes posf: "positive M f"
   595   shows "increasing \<lparr> space = space M, sets = Pow (space M) \<rparr>
   596                     (\<lambda>x. Inf (measure_set M f x))"
   597 apply (auto simp add: increasing_def)
   598 apply (rule complete_lattice_class.Inf_greatest)
   599 apply (rule complete_lattice_class.Inf_lower)
   600 apply (clarsimp simp add: measure_set_def, rule_tac x=A in exI, blast)
   601 done
   602 
   603 lemma (in ring_of_sets) inf_measure_le:
   604   assumes posf: "positive M f" and inc: "increasing M f"
   605       and x: "x \<in> {r . \<exists>A. range A \<subseteq> sets M \<and> s \<subseteq> (\<Union>i. A i) \<and> (\<Sum>i. f (A i)) = r}"
   606   shows "Inf (measure_set M f s) \<le> x"
   607 proof -
   608   obtain A where A: "range A \<subseteq> sets M" and ss: "s \<subseteq> (\<Union>i. A i)"
   609              and xeq: "(\<Sum>i. f (A i)) = x"
   610     using x by auto
   611   have dA: "range (disjointed A) \<subseteq> sets M"
   612     by (metis A range_disjointed_sets)
   613   have "\<forall>n. f (disjointed A n) \<le> f (A n)"
   614     by (metis increasingD [OF inc] UNIV_I dA image_subset_iff disjointed_subset A comp_def)
   615   moreover have "\<forall>i. 0 \<le> f (disjointed A i)"
   616     using posf dA unfolding positive_def by auto
   617   ultimately have sda: "(\<Sum>i. f (disjointed A i)) \<le> (\<Sum>i. f (A i))"
   618     by (blast intro!: suminf_le_pos)
   619   hence ley: "(\<Sum>i. f (disjointed A i)) \<le> x"
   620     by (metis xeq)
   621   hence y: "(\<Sum>i. f (disjointed A i)) \<in> measure_set M f s"
   622     apply (auto simp add: measure_set_def)
   623     apply (rule_tac x="disjointed A" in exI)
   624     apply (simp add: disjoint_family_disjointed UN_disjointed_eq ss dA comp_def)
   625     done
   626   show ?thesis
   627     by (blast intro: y order_trans [OF _ ley] posf complete_lattice_class.Inf_lower)
   628 qed
   629 
   630 lemma (in ring_of_sets) inf_measure_close:
   631   fixes e :: extreal
   632   assumes posf: "positive M f" and e: "0 < e" and ss: "s \<subseteq> (space M)" and "Inf (measure_set M f s) \<noteq> \<infinity>"
   633   shows "\<exists>A. range A \<subseteq> sets M \<and> disjoint_family A \<and> s \<subseteq> (\<Union>i. A i) \<and>
   634                (\<Sum>i. f (A i)) \<le> Inf (measure_set M f s) + e"
   635 proof -
   636   from `Inf (measure_set M f s) \<noteq> \<infinity>` have fin: "\<bar>Inf (measure_set M f s)\<bar> \<noteq> \<infinity>"
   637     using inf_measure_pos[OF posf, of s] by auto
   638   obtain l where "l \<in> measure_set M f s" "l \<le> Inf (measure_set M f s) + e"
   639     using Inf_extreal_close[OF fin e] by auto
   640   thus ?thesis
   641     by (auto intro!: exI[of _ l] simp: measure_set_def comp_def)
   642 qed
   643 
   644 lemma (in ring_of_sets) inf_measure_countably_subadditive:
   645   assumes posf: "positive M f" and inc: "increasing M f"
   646   shows "countably_subadditive (| space = space M, sets = Pow (space M) |)
   647                   (\<lambda>x. Inf (measure_set M f x))"
   648 proof (simp add: countably_subadditive_def, safe)
   649   fix A :: "nat \<Rightarrow> 'a set"
   650   let "?outer B" = "Inf (measure_set M f B)"
   651   assume A: "range A \<subseteq> Pow (space M)"
   652      and disj: "disjoint_family A"
   653      and sb: "(\<Union>i. A i) \<subseteq> space M"
   654 
   655   { fix e :: extreal assume e: "0 < e" and "\<forall>i. ?outer (A i) \<noteq> \<infinity>"
   656     hence "\<exists>BB. \<forall>n. range (BB n) \<subseteq> sets M \<and> disjoint_family (BB n) \<and>
   657         A n \<subseteq> (\<Union>i. BB n i) \<and> (\<Sum>i. f (BB n i)) \<le> ?outer (A n) + e * (1/2)^(Suc n)"
   658       apply (safe intro!: choice inf_measure_close [of f, OF posf])
   659       using e sb by (auto simp: extreal_zero_less_0_iff one_extreal_def)
   660     then obtain BB
   661       where BB: "\<And>n. (range (BB n) \<subseteq> sets M)"
   662       and disjBB: "\<And>n. disjoint_family (BB n)"
   663       and sbBB: "\<And>n. A n \<subseteq> (\<Union>i. BB n i)"
   664       and BBle: "\<And>n. (\<Sum>i. f (BB n i)) \<le> ?outer (A n) + e * (1/2)^(Suc n)"
   665       by auto blast
   666     have sll: "(\<Sum>n. \<Sum>i. (f (BB n i))) \<le> (\<Sum>n. ?outer (A n)) + e"
   667     proof -
   668       have sum_eq_1: "(\<Sum>n. e*(1/2) ^ Suc n) = e"
   669         using suminf_half_series_extreal e
   670         by (simp add: extreal_zero_le_0_iff zero_le_divide_extreal suminf_cmult_extreal)
   671       have "\<And>n i. 0 \<le> f (BB n i)" using posf[unfolded positive_def] BB by auto
   672       then have "\<And>n. 0 \<le> (\<Sum>i. f (BB n i))" by (rule suminf_0_le)
   673       then have "(\<Sum>n. \<Sum>i. (f (BB n i))) \<le> (\<Sum>n. ?outer (A n) + e*(1/2) ^ Suc n)"
   674         by (rule suminf_le_pos[OF BBle])
   675       also have "... = (\<Sum>n. ?outer (A n)) + e"
   676         using sum_eq_1 inf_measure_pos[OF posf] e
   677         by (subst suminf_add_extreal) (auto simp add: extreal_zero_le_0_iff)
   678       finally show ?thesis .
   679     qed
   680     def C \<equiv> "(split BB) o prod_decode"
   681     have C: "!!n. C n \<in> sets M"
   682       apply (rule_tac p="prod_decode n" in PairE)
   683       apply (simp add: C_def)
   684       apply (metis BB subsetD rangeI)
   685       done
   686     have sbC: "(\<Union>i. A i) \<subseteq> (\<Union>i. C i)"
   687     proof (auto simp add: C_def)
   688       fix x i
   689       assume x: "x \<in> A i"
   690       with sbBB [of i] obtain j where "x \<in> BB i j"
   691         by blast
   692       thus "\<exists>i. x \<in> split BB (prod_decode i)"
   693         by (metis prod_encode_inverse prod.cases)
   694     qed
   695     have "(f \<circ> C) = (f \<circ> (\<lambda>(x, y). BB x y)) \<circ> prod_decode"
   696       by (rule ext)  (auto simp add: C_def)
   697     moreover have "suminf ... = (\<Sum>n. \<Sum>i. f (BB n i))" using BBle
   698       using BB posf[unfolded positive_def]
   699       by (force intro!: suminf_extreal_2dimen simp: o_def)
   700     ultimately have Csums: "(\<Sum>i. f (C i)) = (\<Sum>n. \<Sum>i. f (BB n i))" by (simp add: o_def)
   701     have "?outer (\<Union>i. A i) \<le> (\<Sum>n. \<Sum>i. f (BB n i))"
   702       apply (rule inf_measure_le [OF posf(1) inc], auto)
   703       apply (rule_tac x="C" in exI)
   704       apply (auto simp add: C sbC Csums)
   705       done
   706     also have "... \<le> (\<Sum>n. ?outer (A n)) + e" using sll
   707       by blast
   708     finally have "?outer (\<Union>i. A i) \<le> (\<Sum>n. ?outer (A n)) + e" . }
   709   note for_finite_Inf = this
   710 
   711   show "?outer (\<Union>i. A i) \<le> (\<Sum>n. ?outer (A n))"
   712   proof cases
   713     assume "\<forall>i. ?outer (A i) \<noteq> \<infinity>"
   714     with for_finite_Inf show ?thesis
   715       by (intro extreal_le_epsilon) auto
   716   next
   717     assume "\<not> (\<forall>i. ?outer (A i) \<noteq> \<infinity>)"
   718     then have "\<exists>i. ?outer (A i) = \<infinity>"
   719       by auto
   720     then have "(\<Sum>n. ?outer (A n)) = \<infinity>"
   721       using suminf_PInfty[OF inf_measure_pos, OF posf]
   722       by metis
   723     then show ?thesis by simp
   724   qed
   725 qed
   726 
   727 lemma (in ring_of_sets) inf_measure_outer:
   728   "\<lbrakk> positive M f ; increasing M f \<rbrakk>
   729    \<Longrightarrow> outer_measure_space \<lparr> space = space M, sets = Pow (space M) \<rparr>
   730                           (\<lambda>x. Inf (measure_set M f x))"
   731   using inf_measure_pos[of M f]
   732   by (simp add: outer_measure_space_def inf_measure_empty
   733                 inf_measure_increasing inf_measure_countably_subadditive positive_def)
   734 
   735 lemma (in ring_of_sets) algebra_subset_lambda_system:
   736   assumes posf: "positive M f" and inc: "increasing M f"
   737       and add: "additive M f"
   738   shows "sets M \<subseteq> lambda_system \<lparr> space = space M, sets = Pow (space M) \<rparr>
   739                                 (\<lambda>x. Inf (measure_set M f x))"
   740 proof (auto dest: sets_into_space
   741             simp add: algebra.lambda_system_eq [OF algebra_Pow])
   742   fix x s
   743   assume x: "x \<in> sets M"
   744      and s: "s \<subseteq> space M"
   745   have [simp]: "!!x. x \<in> sets M \<Longrightarrow> s \<inter> (space M - x) = s-x" using s
   746     by blast
   747   have "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
   748         \<le> Inf (measure_set M f s)"
   749   proof cases
   750     assume "Inf (measure_set M f s) = \<infinity>" then show ?thesis by simp
   751   next
   752     assume fin: "Inf (measure_set M f s) \<noteq> \<infinity>"
   753     then have "measure_set M f s \<noteq> {}"
   754       by (auto simp: top_extreal_def)
   755     show ?thesis
   756     proof (rule complete_lattice_class.Inf_greatest)
   757       fix r assume "r \<in> measure_set M f s"
   758       then obtain A where A: "disjoint_family A" "range A \<subseteq> sets M" "s \<subseteq> (\<Union>i. A i)"
   759         and r: "r = (\<Sum>i. f (A i))" unfolding measure_set_def by auto
   760       have "Inf (measure_set M f (s \<inter> x)) \<le> (\<Sum>i. f (A i \<inter> x))"
   761         unfolding measure_set_def
   762       proof (safe intro!: complete_lattice_class.Inf_lower exI[of _ "\<lambda>i. A i \<inter> x"])
   763         from A(1) show "disjoint_family (\<lambda>i. A i \<inter> x)"
   764           by (rule disjoint_family_on_bisimulation) auto
   765       qed (insert x A, auto)
   766       moreover
   767       have "Inf (measure_set M f (s - x)) \<le> (\<Sum>i. f (A i - x))"
   768         unfolding measure_set_def
   769       proof (safe intro!: complete_lattice_class.Inf_lower exI[of _ "\<lambda>i. A i - x"])
   770         from A(1) show "disjoint_family (\<lambda>i. A i - x)"
   771           by (rule disjoint_family_on_bisimulation) auto
   772       qed (insert x A, auto)
   773       ultimately have "Inf (measure_set M f (s \<inter> x)) + Inf (measure_set M f (s - x)) \<le>
   774           (\<Sum>i. f (A i \<inter> x)) + (\<Sum>i. f (A i - x))" by (rule add_mono)
   775       also have "\<dots> = (\<Sum>i. f (A i \<inter> x) + f (A i - x))"
   776         using A(2) x posf by (subst suminf_add_extreal) (auto simp: positive_def)
   777       also have "\<dots> = (\<Sum>i. f (A i))"
   778         using A x
   779         by (subst add[THEN additiveD, symmetric])
   780            (auto intro!: arg_cong[where f=suminf] arg_cong[where f=f])
   781       finally show "Inf (measure_set M f (s \<inter> x)) + Inf (measure_set M f (s - x)) \<le> r"
   782         using r by simp
   783     qed
   784   qed
   785   moreover
   786   have "Inf (measure_set M f s)
   787        \<le> Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))"
   788     proof -
   789     have "Inf (measure_set M f s) = Inf (measure_set M f ((s\<inter>x) \<union> (s-x)))"
   790       by (metis Un_Diff_Int Un_commute)
   791     also have "... \<le> Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))"
   792       apply (rule subadditiveD)
   793       apply (rule algebra.countably_subadditive_subadditive[OF algebra_Pow])
   794       apply (simp add: positive_def inf_measure_empty[OF posf] inf_measure_pos[OF posf])
   795       apply (rule inf_measure_countably_subadditive)
   796       using s by (auto intro!: posf inc)
   797     finally show ?thesis .
   798     qed
   799   ultimately
   800   show "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
   801         = Inf (measure_set M f s)"
   802     by (rule order_antisym)
   803 qed
   804 
   805 lemma measure_down:
   806   "measure_space N \<Longrightarrow> sigma_algebra M \<Longrightarrow> sets M \<subseteq> sets N \<Longrightarrow> measure N = measure M \<Longrightarrow> measure_space M"
   807   by (simp add: measure_space_def measure_space_axioms_def positive_def
   808                 countably_additive_def)
   809      blast
   810 
   811 theorem (in ring_of_sets) caratheodory:
   812   assumes posf: "positive M f" and ca: "countably_additive M f"
   813   shows "\<exists>\<mu> :: 'a set \<Rightarrow> extreal. (\<forall>s \<in> sets M. \<mu> s = f s) \<and>
   814             measure_space \<lparr> space = space M, sets = sets (sigma M), measure = \<mu> \<rparr>"
   815 proof -
   816   have inc: "increasing M f"
   817     by (metis additive_increasing ca countably_additive_additive posf)
   818   let ?infm = "(\<lambda>x. Inf (measure_set M f x))"
   819   def ls \<equiv> "lambda_system (|space = space M, sets = Pow (space M)|) ?infm"
   820   have mls: "measure_space \<lparr>space = space M, sets = ls, measure = ?infm\<rparr>"
   821     using sigma_algebra.caratheodory_lemma
   822             [OF sigma_algebra_Pow  inf_measure_outer [OF posf inc]]
   823     by (simp add: ls_def)
   824   hence sls: "sigma_algebra (|space = space M, sets = ls, measure = ?infm|)"
   825     by (simp add: measure_space_def)
   826   have "sets M \<subseteq> ls"
   827     by (simp add: ls_def)
   828        (metis ca posf inc countably_additive_additive algebra_subset_lambda_system)
   829   hence sgs_sb: "sigma_sets (space M) (sets M) \<subseteq> ls"
   830     using sigma_algebra.sigma_sets_subset [OF sls, of "sets M"]
   831     by simp
   832   have "measure_space \<lparr> space = space M, sets = sets (sigma M), measure = ?infm \<rparr>"
   833     unfolding sigma_def
   834     by (rule measure_down [OF mls], rule sigma_algebra_sigma_sets)
   835        (simp_all add: sgs_sb space_closed)
   836   thus ?thesis using inf_measure_agrees [OF posf ca]
   837     by (intro exI[of _ ?infm]) auto
   838 qed
   839 
   840 end