src/HOL/Probability/Caratheodory.thy
author wenzelm
Mon Nov 09 19:42:33 2009 +0100 (2009-11-09)
changeset 33536 fd28b7399f2b
parent 33271 7be66dee1a5a
child 35582 b16d99a72dc9
permissions -rw-r--r--
eliminated hard tabulators;
     1 header {*Caratheodory Extension Theorem*}
     2 
     3 theory Caratheodory
     4   imports Sigma_Algebra SupInf SeriesPlus
     5 begin
     6 
     7 text{*From the Hurd/Coble measure theory development, translated by Lawrence Paulson.*}
     8 
     9 subsection {* Measure Spaces *}
    10 
    11 text {*A measure assigns a nonnegative real to every measurable set. 
    12        It is countably additive for disjoint sets.*}
    13 
    14 record 'a measure_space = "'a algebra" +
    15   measure:: "'a set \<Rightarrow> real"
    16 
    17 definition
    18   disjoint_family  where
    19   "disjoint_family A \<longleftrightarrow> (\<forall>m n. m \<noteq> n \<longrightarrow> A m \<inter> A n = {})"
    20 
    21 definition
    22   positive  where
    23   "positive M f \<longleftrightarrow> f {} = (0::real) & (\<forall>x \<in> sets M. 0 \<le> f x)"
    24 
    25 definition
    26   additive  where
    27   "additive M f \<longleftrightarrow> 
    28     (\<forall>x \<in> sets M. \<forall>y \<in> sets M. x \<inter> y = {} 
    29     \<longrightarrow> f (x \<union> y) = f x + f y)"
    30 
    31 definition
    32   countably_additive  where
    33   "countably_additive M f \<longleftrightarrow> 
    34     (\<forall>A. range A \<subseteq> sets M \<longrightarrow> 
    35          disjoint_family A \<longrightarrow>
    36          (\<Union>i. A i) \<in> sets M \<longrightarrow> 
    37          (\<lambda>n. f (A n))  sums  f (\<Union>i. A i))"
    38 
    39 definition
    40   increasing  where
    41   "increasing M f \<longleftrightarrow> (\<forall>x \<in> sets M. \<forall>y \<in> sets M. x \<subseteq> y \<longrightarrow> f x \<le> f y)"
    42 
    43 definition
    44   subadditive  where
    45   "subadditive M f \<longleftrightarrow> 
    46     (\<forall>x \<in> sets M. \<forall>y \<in> sets M. x \<inter> y = {} 
    47     \<longrightarrow> f (x \<union> y) \<le> f x + f y)"
    48 
    49 definition
    50   countably_subadditive  where
    51   "countably_subadditive M f \<longleftrightarrow> 
    52     (\<forall>A. range A \<subseteq> sets M \<longrightarrow> 
    53          disjoint_family A \<longrightarrow>
    54          (\<Union>i. A i) \<in> sets M \<longrightarrow> 
    55          summable (f o A) \<longrightarrow>
    56          f (\<Union>i. A i) \<le> suminf (\<lambda>n. f (A n)))"
    57 
    58 definition
    59   lambda_system where
    60   "lambda_system M f = 
    61     {l. l \<in> sets M & (\<forall>x \<in> sets M. f (l \<inter> x) + f ((space M - l) \<inter> x) = f x)}"
    62 
    63 definition
    64   outer_measure_space where
    65   "outer_measure_space M f  \<longleftrightarrow> 
    66      positive M f & increasing M f & countably_subadditive M f"
    67 
    68 definition
    69   measure_set where
    70   "measure_set M f X =
    71      {r . \<exists>A. range A \<subseteq> sets M & disjoint_family A & X \<subseteq> (\<Union>i. A i) & (f \<circ> A) sums r}"
    72 
    73 
    74 locale measure_space = sigma_algebra +
    75   assumes positive: "!!a. a \<in> sets M \<Longrightarrow> 0 \<le> measure M a"
    76       and empty_measure [simp]: "measure M {} = (0::real)"
    77       and ca: "countably_additive M (measure M)"
    78 
    79 subsection {* Basic Lemmas *}
    80 
    81 lemma positive_imp_0: "positive M f \<Longrightarrow> f {} = 0"
    82   by (simp add: positive_def) 
    83 
    84 lemma positive_imp_pos: "positive M f \<Longrightarrow> x \<in> sets M \<Longrightarrow> 0 \<le> f x"
    85   by (simp add: positive_def) 
    86 
    87 lemma increasingD:
    88      "increasing M f \<Longrightarrow> x \<subseteq> y \<Longrightarrow> x\<in>sets M \<Longrightarrow> y\<in>sets M \<Longrightarrow> f x \<le> f y"
    89   by (auto simp add: increasing_def)
    90 
    91 lemma subadditiveD:
    92      "subadditive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x\<in>sets M \<Longrightarrow> y\<in>sets M 
    93       \<Longrightarrow> f (x \<union> y) \<le> f x + f y"
    94   by (auto simp add: subadditive_def)
    95 
    96 lemma additiveD:
    97      "additive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x\<in>sets M \<Longrightarrow> y\<in>sets M 
    98       \<Longrightarrow> f (x \<union> y) = f x + f y"
    99   by (auto simp add: additive_def)
   100 
   101 lemma countably_additiveD:
   102   "countably_additive M f \<Longrightarrow> range A \<subseteq> sets M \<Longrightarrow> disjoint_family A 
   103    \<Longrightarrow> (\<Union>i. A i) \<in> sets M \<Longrightarrow> (\<lambda>n. f (A n))  sums  f (\<Union>i. A i)"
   104   by (simp add: countably_additive_def) 
   105 
   106 lemma Int_Diff_disjoint: "A \<inter> B \<inter> (A - B) = {}"
   107   by blast
   108 
   109 lemma Int_Diff_Un: "A \<inter> B \<union> (A - B) = A"
   110   by blast
   111 
   112 lemma disjoint_family_subset:
   113      "disjoint_family A \<Longrightarrow> (!!x. B x \<subseteq> A x) \<Longrightarrow> disjoint_family B"
   114   by (force simp add: disjoint_family_def) 
   115 
   116 subsection {* A Two-Element Series *}
   117 
   118 definition binaryset :: "'a set \<Rightarrow> 'a set \<Rightarrow> nat \<Rightarrow> 'a set "
   119   where "binaryset A B = (\<lambda>\<^isup>x. {})(0 := A, Suc 0 := B)"
   120 
   121 lemma range_binaryset_eq: "range(binaryset A B) = {A,B,{}}"
   122   apply (simp add: binaryset_def) 
   123   apply (rule set_ext) 
   124   apply (auto simp add: image_iff) 
   125   done
   126 
   127 lemma UN_binaryset_eq: "(\<Union>i. binaryset A B i) = A \<union> B"
   128   by (simp add: UNION_eq_Union_image range_binaryset_eq) 
   129 
   130 lemma LIMSEQ_binaryset: 
   131   assumes f: "f {} = 0"
   132   shows  "(\<lambda>n. \<Sum>i = 0..<n. f (binaryset A B i)) ----> f A + f B"
   133 proof -
   134   have "(\<lambda>n. \<Sum>i = 0..< Suc (Suc n). f (binaryset A B i)) = (\<lambda>n. f A + f B)"
   135     proof 
   136       fix n
   137       show "(\<Sum>i\<Colon>nat = 0\<Colon>nat..<Suc (Suc n). f (binaryset A B i)) = f A + f B"
   138         by (induct n)  (auto simp add: binaryset_def f) 
   139     qed
   140   moreover
   141   have "... ----> f A + f B" by (rule LIMSEQ_const) 
   142   ultimately
   143   have "(\<lambda>n. \<Sum>i = 0..< Suc (Suc n). f (binaryset A B i)) ----> f A + f B" 
   144     by metis
   145   hence "(\<lambda>n. \<Sum>i = 0..< n+2. f (binaryset A B i)) ----> f A + f B"
   146     by simp
   147   thus ?thesis by (rule LIMSEQ_offset [where k=2])
   148 qed
   149 
   150 lemma binaryset_sums:
   151   assumes f: "f {} = 0"
   152   shows  "(\<lambda>n. f (binaryset A B n)) sums (f A + f B)"
   153     by (simp add: sums_def LIMSEQ_binaryset [where f=f, OF f]) 
   154 
   155 lemma suminf_binaryset_eq:
   156      "f {} = 0 \<Longrightarrow> suminf (\<lambda>n. f (binaryset A B n)) = f A + f B"
   157   by (metis binaryset_sums sums_unique)
   158 
   159 
   160 subsection {* Lambda Systems *}
   161 
   162 lemma (in algebra) lambda_system_eq:
   163     "lambda_system M f = 
   164         {l. l \<in> sets M & (\<forall>x \<in> sets M. f (x \<inter> l) + f (x - l) = f x)}"
   165 proof -
   166   have [simp]: "!!l x. l \<in> sets M \<Longrightarrow> x \<in> sets M \<Longrightarrow> (space M - l) \<inter> x = x - l"
   167     by (metis Diff_eq Int_Diff Int_absorb1 Int_commute sets_into_space)
   168   show ?thesis
   169     by (auto simp add: lambda_system_def) (metis Diff_Compl Int_commute)+
   170 qed
   171 
   172 lemma (in algebra) lambda_system_empty:
   173     "positive M f \<Longrightarrow> {} \<in> lambda_system M f"
   174   by (auto simp add: positive_def lambda_system_eq) 
   175 
   176 lemma lambda_system_sets:
   177     "x \<in> lambda_system M f \<Longrightarrow> x \<in> sets M"
   178   by (simp add:  lambda_system_def)
   179 
   180 lemma (in algebra) lambda_system_Compl:
   181   fixes f:: "'a set \<Rightarrow> real"
   182   assumes x: "x \<in> lambda_system M f"
   183   shows "space M - x \<in> lambda_system M f"
   184   proof -
   185     have "x \<subseteq> space M"
   186       by (metis sets_into_space lambda_system_sets x)
   187     hence "space M - (space M - x) = x"
   188       by (metis double_diff equalityE) 
   189     with x show ?thesis
   190       by (force simp add: lambda_system_def)
   191   qed
   192 
   193 lemma (in algebra) lambda_system_Int:
   194   fixes f:: "'a set \<Rightarrow> real"
   195   assumes xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   196   shows "x \<inter> y \<in> lambda_system M f"
   197   proof -
   198     from xl yl show ?thesis
   199       proof (auto simp add: positive_def lambda_system_eq Int)
   200         fix u
   201         assume x: "x \<in> sets M" and y: "y \<in> sets M" and u: "u \<in> sets M"
   202            and fx: "\<forall>z\<in>sets M. f (z \<inter> x) + f (z - x) = f z"
   203            and fy: "\<forall>z\<in>sets M. f (z \<inter> y) + f (z - y) = f z"
   204         have "u - x \<inter> y \<in> sets M"
   205           by (metis Diff Diff_Int Un u x y)
   206         moreover
   207         have "(u - (x \<inter> y)) \<inter> y = u \<inter> y - x" by blast
   208         moreover
   209         have "u - x \<inter> y - y = u - y" by blast
   210         ultimately
   211         have ey: "f (u - x \<inter> y) = f (u \<inter> y - x) + f (u - y)" using fy
   212           by force
   213         have "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y) 
   214               = (f (u \<inter> (x \<inter> y)) + f (u \<inter> y - x)) + f (u - y)"
   215           by (simp add: ey) 
   216         also have "... =  (f ((u \<inter> y) \<inter> x) + f (u \<inter> y - x)) + f (u - y)"
   217           by (simp add: Int_ac) 
   218         also have "... = f (u \<inter> y) + f (u - y)"
   219           using fx [THEN bspec, of "u \<inter> y"] Int y u
   220           by force
   221         also have "... = f u"
   222           by (metis fy u) 
   223         finally show "f (u \<inter> (x \<inter> y)) + f (u - x \<inter> y) = f u" .
   224       qed
   225   qed
   226 
   227 
   228 lemma (in algebra) lambda_system_Un:
   229   fixes f:: "'a set \<Rightarrow> real"
   230   assumes xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   231   shows "x \<union> y \<in> lambda_system M f"
   232 proof -
   233   have "(space M - x) \<inter> (space M - y) \<in> sets M"
   234     by (metis Diff_Un Un compl_sets lambda_system_sets xl yl) 
   235   moreover
   236   have "x \<union> y = space M - ((space M - x) \<inter> (space M - y))"
   237     by auto  (metis subsetD lambda_system_sets sets_into_space xl yl)+
   238   ultimately show ?thesis
   239     by (metis lambda_system_Compl lambda_system_Int xl yl) 
   240 qed
   241 
   242 lemma (in algebra) lambda_system_algebra:
   243     "positive M f \<Longrightarrow> algebra (M (|sets := lambda_system M f|))"
   244   apply (auto simp add: algebra_def) 
   245   apply (metis lambda_system_sets set_mp sets_into_space)
   246   apply (metis lambda_system_empty)
   247   apply (metis lambda_system_Compl)
   248   apply (metis lambda_system_Un) 
   249   done
   250 
   251 lemma (in algebra) lambda_system_strong_additive:
   252   assumes z: "z \<in> sets M" and disj: "x \<inter> y = {}"
   253       and xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   254   shows "f (z \<inter> (x \<union> y)) = f (z \<inter> x) + f (z \<inter> y)"
   255   proof -
   256     have "z \<inter> x = (z \<inter> (x \<union> y)) \<inter> x" using disj by blast
   257     moreover
   258     have "z \<inter> y = (z \<inter> (x \<union> y)) - x" using disj by blast
   259     moreover 
   260     have "(z \<inter> (x \<union> y)) \<in> sets M"
   261       by (metis Int Un lambda_system_sets xl yl z) 
   262     ultimately show ?thesis using xl yl
   263       by (simp add: lambda_system_eq)
   264   qed
   265 
   266 lemma (in algebra) Int_space_eq1 [simp]: "x \<in> sets M \<Longrightarrow> space M \<inter> x = x"
   267   by (metis Int_absorb1 sets_into_space)
   268 
   269 lemma (in algebra) Int_space_eq2 [simp]: "x \<in> sets M \<Longrightarrow> x \<inter> space M = x"
   270   by (metis Int_absorb2 sets_into_space)
   271 
   272 lemma (in algebra) lambda_system_additive:
   273      "additive (M (|sets := lambda_system M f|)) f"
   274   proof (auto simp add: additive_def)
   275     fix x and y
   276     assume disj: "x \<inter> y = {}"
   277        and xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
   278     hence  "x \<in> sets M" "y \<in> sets M" by (blast intro: lambda_system_sets)+
   279     thus "f (x \<union> y) = f x + f y" 
   280       using lambda_system_strong_additive [OF top disj xl yl]
   281       by (simp add: Un)
   282   qed
   283 
   284 
   285 lemma (in algebra) countably_subadditive_subadditive:
   286   assumes f: "positive M f" and cs: "countably_subadditive M f"
   287   shows  "subadditive M f"
   288 proof (auto simp add: subadditive_def) 
   289   fix x y
   290   assume x: "x \<in> sets M" and y: "y \<in> sets M" and "x \<inter> y = {}"
   291   hence "disjoint_family (binaryset x y)"
   292     by (auto simp add: disjoint_family_def binaryset_def) 
   293   hence "range (binaryset x y) \<subseteq> sets M \<longrightarrow> 
   294          (\<Union>i. binaryset x y i) \<in> sets M \<longrightarrow> 
   295          summable (f o (binaryset x y)) \<longrightarrow>
   296          f (\<Union>i. binaryset x y i) \<le> suminf (\<lambda>n. f (binaryset x y n))"
   297     using cs by (simp add: countably_subadditive_def) 
   298   hence "{x,y,{}} \<subseteq> sets M \<longrightarrow> x \<union> y \<in> sets M \<longrightarrow> 
   299          summable (f o (binaryset x y)) \<longrightarrow>
   300          f (x \<union> y) \<le> suminf (\<lambda>n. f (binaryset x y n))"
   301     by (simp add: range_binaryset_eq UN_binaryset_eq)
   302   thus "f (x \<union> y) \<le>  f x + f y" using f x y binaryset_sums
   303     by (auto simp add: Un sums_iff positive_def o_def) 
   304 qed 
   305 
   306 
   307 definition disjointed :: "(nat \<Rightarrow> 'a set) \<Rightarrow> nat \<Rightarrow> 'a set "
   308   where "disjointed A n = A n - (\<Union>i\<in>{0..<n}. A i)"
   309 
   310 lemma finite_UN_disjointed_eq: "(\<Union>i\<in>{0..<n}. disjointed A i) = (\<Union>i\<in>{0..<n}. A i)"
   311 proof (induct n)
   312   case 0 show ?case by simp
   313 next
   314   case (Suc n)
   315   thus ?case by (simp add: atLeastLessThanSuc disjointed_def) 
   316 qed
   317 
   318 lemma UN_disjointed_eq: "(\<Union>i. disjointed A i) = (\<Union>i. A i)"
   319   apply (rule UN_finite2_eq [where k=0]) 
   320   apply (simp add: finite_UN_disjointed_eq) 
   321   done
   322 
   323 lemma less_disjoint_disjointed: "m<n \<Longrightarrow> disjointed A m \<inter> disjointed A n = {}"
   324   by (auto simp add: disjointed_def)
   325 
   326 lemma disjoint_family_disjointed: "disjoint_family (disjointed A)"
   327   by (simp add: disjoint_family_def) 
   328      (metis neq_iff Int_commute less_disjoint_disjointed)
   329 
   330 lemma disjointed_subset: "disjointed A n \<subseteq> A n"
   331   by (auto simp add: disjointed_def)
   332 
   333 
   334 lemma (in algebra) UNION_in_sets:
   335   fixes A:: "nat \<Rightarrow> 'a set"
   336   assumes A: "range A \<subseteq> sets M "
   337   shows  "(\<Union>i\<in>{0..<n}. A i) \<in> sets M"
   338 proof (induct n)
   339   case 0 show ?case by simp
   340 next
   341   case (Suc n) 
   342   thus ?case
   343     by (simp add: atLeastLessThanSuc) (metis A Un UNIV_I image_subset_iff)
   344 qed
   345 
   346 lemma (in algebra) range_disjointed_sets:
   347   assumes A: "range A \<subseteq> sets M "
   348   shows  "range (disjointed A) \<subseteq> sets M"
   349 proof (auto simp add: disjointed_def) 
   350   fix n
   351   show "A n - (\<Union>i\<in>{0..<n}. A i) \<in> sets M" using UNION_in_sets
   352     by (metis A Diff UNIV_I disjointed_def image_subset_iff)
   353 qed
   354 
   355 lemma sigma_algebra_disjoint_iff: 
   356      "sigma_algebra M \<longleftrightarrow> 
   357       algebra M &
   358       (\<forall>A. range A \<subseteq> sets M \<longrightarrow> disjoint_family A \<longrightarrow> 
   359            (\<Union>i::nat. A i) \<in> sets M)"
   360 proof (auto simp add: sigma_algebra_iff)
   361   fix A :: "nat \<Rightarrow> 'a set"
   362   assume M: "algebra M"
   363      and A: "range A \<subseteq> sets M"
   364      and UnA: "\<forall>A. range A \<subseteq> sets M \<longrightarrow>
   365                disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> sets M"
   366   hence "range (disjointed A) \<subseteq> sets M \<longrightarrow>
   367          disjoint_family (disjointed A) \<longrightarrow>
   368          (\<Union>i. disjointed A i) \<in> sets M" by blast
   369   hence "(\<Union>i. disjointed A i) \<in> sets M"
   370     by (simp add: algebra.range_disjointed_sets M A disjoint_family_disjointed) 
   371   thus "(\<Union>i::nat. A i) \<in> sets M" by (simp add: UN_disjointed_eq)
   372 qed
   373 
   374 
   375 lemma (in algebra) additive_sum:
   376   fixes A:: "nat \<Rightarrow> 'a set"
   377   assumes f: "positive M f" and ad: "additive M f"
   378       and A: "range A \<subseteq> sets M"
   379       and disj: "disjoint_family A"
   380   shows  "setsum (f o A) {0..<n} = f (\<Union>i\<in>{0..<n}. A i)"
   381 proof (induct n)
   382   case 0 show ?case using f by (simp add: positive_def) 
   383 next
   384   case (Suc n) 
   385   have "A n \<inter> (\<Union>i\<in>{0..<n}. A i) = {}" using disj 
   386     by (auto simp add: disjoint_family_def neq_iff) blast
   387   moreover 
   388   have "A n \<in> sets M" using A by blast 
   389   moreover have "(\<Union>i\<in>{0..<n}. A i) \<in> sets M"
   390     by (metis A UNION_in_sets atLeast0LessThan)
   391   moreover 
   392   ultimately have "f (A n \<union> (\<Union>i\<in>{0..<n}. A i)) = f (A n) + f(\<Union>i\<in>{0..<n}. A i)"
   393     using ad UNION_in_sets A by (auto simp add: additive_def) 
   394   with Suc.hyps show ?case using ad
   395     by (auto simp add: atLeastLessThanSuc additive_def) 
   396 qed
   397 
   398 
   399 lemma countably_subadditiveD:
   400   "countably_subadditive M f \<Longrightarrow> range A \<subseteq> sets M \<Longrightarrow> disjoint_family A \<Longrightarrow>
   401    (\<Union>i. A i) \<in> sets M \<Longrightarrow> summable (f o A) \<Longrightarrow> f (\<Union>i. A i) \<le> suminf (f o A)" 
   402   by (auto simp add: countably_subadditive_def o_def)
   403 
   404 lemma (in algebra) increasing_additive_summable:
   405   fixes A:: "nat \<Rightarrow> 'a set"
   406   assumes f: "positive M f" and ad: "additive M f"
   407       and inc: "increasing M f"
   408       and A: "range A \<subseteq> sets M"
   409       and disj: "disjoint_family A"
   410   shows  "summable (f o A)"
   411 proof (rule pos_summable) 
   412   fix n
   413   show "0 \<le> (f \<circ> A) n" using f A
   414     by (force simp add: positive_def)
   415   next
   416   fix n
   417   have "setsum (f \<circ> A) {0..<n} = f (\<Union>i\<in>{0..<n}. A i)"
   418     by (rule additive_sum [OF f ad A disj]) 
   419   also have "... \<le> f (space M)" using space_closed A
   420     by (blast intro: increasingD [OF inc] UNION_in_sets top) 
   421   finally show "setsum (f \<circ> A) {0..<n} \<le> f (space M)" .
   422 qed
   423 
   424 lemma lambda_system_positive:
   425      "positive M f \<Longrightarrow> positive (M (|sets := lambda_system M f|)) f"
   426   by (simp add: positive_def lambda_system_def) 
   427 
   428 lemma lambda_system_increasing:
   429    "increasing M f \<Longrightarrow> increasing (M (|sets := lambda_system M f|)) f"
   430   by (simp add: increasing_def lambda_system_def) 
   431 
   432 lemma (in algebra) lambda_system_strong_sum:
   433   fixes A:: "nat \<Rightarrow> 'a set"
   434   assumes f: "positive M f" and a: "a \<in> sets M"
   435       and A: "range A \<subseteq> lambda_system M f"
   436       and disj: "disjoint_family A"
   437   shows  "(\<Sum>i = 0..<n. f (a \<inter>A i)) = f (a \<inter> (\<Union>i\<in>{0..<n}. A i))"
   438 proof (induct n)
   439   case 0 show ?case using f by (simp add: positive_def) 
   440 next
   441   case (Suc n) 
   442   have 2: "A n \<inter> UNION {0..<n} A = {}" using disj
   443     by (force simp add: disjoint_family_def neq_iff) 
   444   have 3: "A n \<in> lambda_system M f" using A
   445     by blast
   446   have 4: "UNION {0..<n} A \<in> lambda_system M f"
   447     using A algebra.UNION_in_sets [OF local.lambda_system_algebra [OF f]] 
   448     by simp
   449   from Suc.hyps show ?case
   450     by (simp add: atLeastLessThanSuc lambda_system_strong_additive [OF a 2 3 4])
   451 qed
   452 
   453 
   454 lemma (in sigma_algebra) lambda_system_caratheodory:
   455   assumes oms: "outer_measure_space M f"
   456       and A: "range A \<subseteq> lambda_system M f"
   457       and disj: "disjoint_family A"
   458   shows  "(\<Union>i. A i) \<in> lambda_system M f & (f \<circ> A)  sums  f (\<Union>i. A i)"
   459 proof -
   460   have pos: "positive M f" and inc: "increasing M f" 
   461    and csa: "countably_subadditive M f" 
   462     by (metis oms outer_measure_space_def)+
   463   have sa: "subadditive M f"
   464     by (metis countably_subadditive_subadditive csa pos) 
   465   have A': "range A \<subseteq> sets (M(|sets := lambda_system M f|))" using A 
   466     by simp
   467   have alg_ls: "algebra (M(|sets := lambda_system M f|))"
   468     by (rule lambda_system_algebra [OF pos]) 
   469   have A'': "range A \<subseteq> sets M"
   470      by (metis A image_subset_iff lambda_system_sets)
   471   have sumfA: "summable (f \<circ> A)" 
   472     by (metis algebra.increasing_additive_summable [OF alg_ls]
   473           lambda_system_positive lambda_system_additive lambda_system_increasing
   474           A' oms outer_measure_space_def disj)
   475   have U_in: "(\<Union>i. A i) \<in> sets M"
   476     by (metis A countable_UN image_subset_iff lambda_system_sets)
   477   have U_eq: "f (\<Union>i. A i) = suminf (f o A)" 
   478     proof (rule antisym)
   479       show "f (\<Union>i. A i) \<le> suminf (f \<circ> A)"
   480         by (rule countably_subadditiveD [OF csa A'' disj U_in sumfA]) 
   481       show "suminf (f \<circ> A) \<le> f (\<Union>i. A i)"
   482         by (rule suminf_le [OF sumfA]) 
   483            (metis algebra.additive_sum [OF alg_ls] pos disj UN_Un Un_UNIV_right
   484                   lambda_system_positive lambda_system_additive 
   485                   subset_Un_eq increasingD [OF inc] A' A'' UNION_in_sets U_in) 
   486     qed
   487   {
   488     fix a 
   489     assume a [iff]: "a \<in> sets M" 
   490     have "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) = f a"
   491     proof -
   492       have summ: "summable (f \<circ> (\<lambda>i. a \<inter> i) \<circ> A)" using pos A'' 
   493         apply -
   494         apply (rule summable_comparison_test [OF _ sumfA]) 
   495         apply (rule_tac x="0" in exI) 
   496         apply (simp add: positive_def) 
   497         apply (auto simp add: )
   498         apply (subst abs_of_nonneg)
   499         apply (metis A'' Int UNIV_I a image_subset_iff)
   500         apply (blast intro:  increasingD [OF inc] a)   
   501         done
   502       show ?thesis
   503       proof (rule antisym)
   504         have "range (\<lambda>i. a \<inter> A i) \<subseteq> sets M" using A''
   505           by blast
   506         moreover 
   507         have "disjoint_family (\<lambda>i. a \<inter> A i)" using disj
   508           by (auto simp add: disjoint_family_def) 
   509         moreover 
   510         have "a \<inter> (\<Union>i. A i) \<in> sets M"
   511           by (metis Int U_in a)
   512         ultimately 
   513         have "f (a \<inter> (\<Union>i. A i)) \<le> suminf (f \<circ> (\<lambda>i. a \<inter> i) \<circ> A)"
   514           using countably_subadditiveD [OF csa, of "(\<lambda>i. a \<inter> A i)"] summ
   515           by (simp add: o_def) 
   516         moreover 
   517         have "suminf (f \<circ> (\<lambda>i. a \<inter> i) \<circ> A)  \<le> f a - f (a - (\<Union>i. A i))"
   518           proof (rule suminf_le [OF summ])
   519             fix n
   520             have UNION_in: "(\<Union>i\<in>{0..<n}. A i) \<in> sets M"
   521               by (metis A'' UNION_in_sets) 
   522             have le_fa: "f (UNION {0..<n} A \<inter> a) \<le> f a" using A''
   523               by (blast intro: increasingD [OF inc] A'' Int UNION_in_sets a) 
   524             have ls: "(\<Union>i\<in>{0..<n}. A i) \<in> lambda_system M f"
   525               using algebra.UNION_in_sets [OF lambda_system_algebra [OF pos]]
   526               by (simp add: A) 
   527             hence eq_fa: "f (a \<inter> (\<Union>i\<in>{0..<n}. A i)) + f (a - (\<Union>i\<in>{0..<n}. A i)) = f a"
   528               by (simp add: lambda_system_eq UNION_in Diff_Compl a)
   529             have "f (a - (\<Union>i. A i)) \<le> f (a - (\<Union>i\<in>{0..<n}. A i))"
   530               by (blast intro: increasingD [OF inc] Diff UNION_eq_Union_image 
   531                                UNION_in U_in a) 
   532             thus "setsum (f \<circ> (\<lambda>i. a \<inter> i) \<circ> A) {0..<n} \<le> f a - f (a - (\<Union>i. A i))"
   533               using eq_fa
   534               by (simp add: suminf_le [OF summ] lambda_system_strong_sum pos 
   535                             a A disj)
   536           qed
   537         ultimately show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a" 
   538           by arith
   539       next
   540         have "f a \<le> f (a \<inter> (\<Union>i. A i) \<union> (a - (\<Union>i. A i)))" 
   541           by (blast intro:  increasingD [OF inc] a U_in)
   542         also have "... \<le>  f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))"
   543           by (blast intro: subadditiveD [OF sa] Int Diff U_in) 
   544         finally show "f a \<le> f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i))" .
   545         qed
   546      qed
   547   }
   548   thus  ?thesis
   549     by (simp add: lambda_system_eq sums_iff U_eq U_in sumfA)
   550 qed
   551 
   552 lemma (in sigma_algebra) caratheodory_lemma:
   553   assumes oms: "outer_measure_space M f"
   554   shows "measure_space (|space = space M, sets = lambda_system M f, measure = f|)"
   555 proof -
   556   have pos: "positive M f" 
   557     by (metis oms outer_measure_space_def)
   558   have alg: "algebra (|space = space M, sets = lambda_system M f, measure = f|)"
   559     using lambda_system_algebra [OF pos]
   560     by (simp add: algebra_def) 
   561   then moreover 
   562   have "sigma_algebra (|space = space M, sets = lambda_system M f, measure = f|)"
   563     using lambda_system_caratheodory [OF oms]
   564     by (simp add: sigma_algebra_disjoint_iff) 
   565   moreover 
   566   have "measure_space_axioms (|space = space M, sets = lambda_system M f, measure = f|)" 
   567     using pos lambda_system_caratheodory [OF oms]
   568     by (simp add: measure_space_axioms_def positive_def lambda_system_sets 
   569                   countably_additive_def o_def) 
   570   ultimately 
   571   show ?thesis
   572     by intro_locales (auto simp add: sigma_algebra_def) 
   573 qed
   574 
   575 
   576 lemma (in algebra) inf_measure_nonempty:
   577   assumes f: "positive M f" and b: "b \<in> sets M" and a: "a \<subseteq> b"
   578   shows "f b \<in> measure_set M f a"
   579 proof -
   580   have "(f \<circ> (\<lambda>i. {})(0 := b)) sums setsum (f \<circ> (\<lambda>i. {})(0 := b)) {0..<1::nat}"
   581     by (rule series_zero)  (simp add: positive_imp_0 [OF f]) 
   582   also have "... = f b" 
   583     by simp
   584   finally have "(f \<circ> (\<lambda>i. {})(0 := b)) sums f b" .
   585   thus ?thesis using a
   586     by (auto intro!: exI [of _ "(\<lambda>i. {})(0 := b)"] 
   587              simp add: measure_set_def disjoint_family_def b split_if_mem2) 
   588 qed  
   589 
   590 lemma (in algebra) inf_measure_pos0:
   591      "positive M f \<Longrightarrow> x \<in> measure_set M f a \<Longrightarrow> 0 \<le> x"
   592 apply (auto simp add: positive_def measure_set_def sums_iff intro!: suminf_ge_zero)
   593 apply blast
   594 done
   595 
   596 lemma (in algebra) inf_measure_pos:
   597   shows "positive M f \<Longrightarrow> x \<subseteq> space M \<Longrightarrow> 0 \<le> Inf (measure_set M f x)"
   598 apply (rule Inf_greatest)
   599 apply (metis emptyE inf_measure_nonempty top)
   600 apply (metis inf_measure_pos0) 
   601 done
   602 
   603 lemma (in algebra) additive_increasing:
   604   assumes posf: "positive M f" and addf: "additive M f" 
   605   shows "increasing M f"
   606 proof (auto simp add: increasing_def) 
   607   fix x y
   608   assume xy: "x \<in> sets M" "y \<in> sets M" "x \<subseteq> y"
   609   have "f x \<le> f x + f (y-x)" using posf
   610     by (simp add: positive_def) (metis Diff xy)
   611   also have "... = f (x \<union> (y-x))" using addf
   612     by (auto simp add: additive_def) (metis Diff_disjoint Un_Diff_cancel Diff xy) 
   613   also have "... = f y"
   614     by (metis Un_Diff_cancel Un_absorb1 xy)
   615   finally show "f x \<le> f y" .
   616 qed
   617 
   618 lemma (in algebra) countably_additive_additive:
   619   assumes posf: "positive M f" and ca: "countably_additive M f" 
   620   shows "additive M f"
   621 proof (auto simp add: additive_def) 
   622   fix x y
   623   assume x: "x \<in> sets M" and y: "y \<in> sets M" and "x \<inter> y = {}"
   624   hence "disjoint_family (binaryset x y)"
   625     by (auto simp add: disjoint_family_def binaryset_def) 
   626   hence "range (binaryset x y) \<subseteq> sets M \<longrightarrow> 
   627          (\<Union>i. binaryset x y i) \<in> sets M \<longrightarrow> 
   628          f (\<Union>i. binaryset x y i) = suminf (\<lambda>n. f (binaryset x y n))"
   629     using ca
   630     by (simp add: countably_additive_def) (metis UN_binaryset_eq sums_unique) 
   631   hence "{x,y,{}} \<subseteq> sets M \<longrightarrow> x \<union> y \<in> sets M \<longrightarrow> 
   632          f (x \<union> y) = suminf (\<lambda>n. f (binaryset x y n))"
   633     by (simp add: range_binaryset_eq UN_binaryset_eq)
   634   thus "f (x \<union> y) = f x + f y" using posf x y
   635     by (simp add: Un suminf_binaryset_eq positive_def)
   636 qed 
   637  
   638 lemma (in algebra) inf_measure_agrees:
   639   assumes posf: "positive M f" and ca: "countably_additive M f" 
   640       and s: "s \<in> sets M"  
   641   shows "Inf (measure_set M f s) = f s"
   642 proof (rule Inf_eq) 
   643   fix z
   644   assume z: "z \<in> measure_set M f s"
   645   from this obtain A where 
   646     A: "range A \<subseteq> sets M" and disj: "disjoint_family A"
   647     and "s \<subseteq> (\<Union>x. A x)" and sm: "summable (f \<circ> A)"
   648     and si: "suminf (f \<circ> A) = z"
   649     by (auto simp add: measure_set_def sums_iff) 
   650   hence seq: "s = (\<Union>i. A i \<inter> s)" by blast
   651   have inc: "increasing M f"
   652     by (metis additive_increasing ca countably_additive_additive posf)
   653   have sums: "(\<lambda>i. f (A i \<inter> s)) sums f (\<Union>i. A i \<inter> s)"
   654     proof (rule countably_additiveD [OF ca]) 
   655       show "range (\<lambda>n. A n \<inter> s) \<subseteq> sets M" using A s
   656         by blast
   657       show "disjoint_family (\<lambda>n. A n \<inter> s)" using disj
   658         by (auto simp add: disjoint_family_def)
   659       show "(\<Union>i. A i \<inter> s) \<in> sets M" using A s
   660         by (metis UN_extend_simps(4) s seq)
   661     qed
   662   hence "f s = suminf (\<lambda>i. f (A i \<inter> s))"
   663     by (metis Int_commute UN_simps(4) seq sums_iff) 
   664   also have "... \<le> suminf (f \<circ> A)" 
   665     proof (rule summable_le [OF _ _ sm]) 
   666       show "\<forall>n. f (A n \<inter> s) \<le> (f \<circ> A) n" using A s
   667         by (force intro: increasingD [OF inc]) 
   668       show "summable (\<lambda>i. f (A i \<inter> s))" using sums
   669         by (simp add: sums_iff) 
   670     qed
   671   also have "... = z" by (rule si) 
   672   finally show "f s \<le> z" .
   673 next
   674   fix y
   675   assume y: "!!u. u \<in> measure_set M f s \<Longrightarrow> y \<le> u"
   676   thus "y \<le> f s"
   677     by (blast intro: inf_measure_nonempty [OF posf s subset_refl])
   678 qed
   679 
   680 lemma (in algebra) inf_measure_empty:
   681   assumes posf: "positive M f"
   682   shows "Inf (measure_set M f {}) = 0"
   683 proof (rule antisym)
   684   show "0 \<le> Inf (measure_set M f {})"
   685     by (metis empty_subsetI inf_measure_pos posf) 
   686   show "Inf (measure_set M f {}) \<le> 0"
   687     by (metis Inf_lower empty_sets inf_measure_pos0 inf_measure_nonempty posf
   688               positive_imp_0 subset_refl) 
   689 qed
   690 
   691 lemma (in algebra) inf_measure_positive:
   692   "positive M f \<Longrightarrow> 
   693    positive (| space = space M, sets = Pow (space M) |)
   694                   (\<lambda>x. Inf (measure_set M f x))"
   695   by (simp add: positive_def inf_measure_empty inf_measure_pos) 
   696 
   697 lemma (in algebra) inf_measure_increasing:
   698   assumes posf: "positive M f"
   699   shows "increasing (| space = space M, sets = Pow (space M) |)
   700                     (\<lambda>x. Inf (measure_set M f x))"
   701 apply (auto simp add: increasing_def) 
   702 apply (rule Inf_greatest, metis emptyE inf_measure_nonempty top posf)
   703 apply (rule Inf_lower) 
   704 apply (clarsimp simp add: measure_set_def, blast) 
   705 apply (blast intro: inf_measure_pos0 posf)
   706 done
   707 
   708 
   709 lemma (in algebra) inf_measure_le:
   710   assumes posf: "positive M f" and inc: "increasing M f" 
   711       and x: "x \<in> {r . \<exists>A. range A \<subseteq> sets M & s \<subseteq> (\<Union>i. A i) & (f \<circ> A) sums r}"
   712   shows "Inf (measure_set M f s) \<le> x"
   713 proof -
   714   from x
   715   obtain A where A: "range A \<subseteq> sets M" and ss: "s \<subseteq> (\<Union>i. A i)" 
   716              and sm: "summable (f \<circ> A)" and xeq: "suminf (f \<circ> A) = x"
   717     by (auto simp add: sums_iff)
   718   have dA: "range (disjointed A) \<subseteq> sets M"
   719     by (metis A range_disjointed_sets)
   720   have "\<forall>n. \<bar>(f o disjointed A) n\<bar> \<le> (f \<circ> A) n"
   721     proof (auto)
   722       fix n
   723       have "\<bar>f (disjointed A n)\<bar> = f (disjointed A n)" using posf dA
   724         by (auto simp add: positive_def image_subset_iff)
   725       also have "... \<le> f (A n)" 
   726         by (metis increasingD [OF inc] UNIV_I dA image_subset_iff disjointed_subset A)
   727       finally show "\<bar>f (disjointed A n)\<bar> \<le> f (A n)" .
   728     qed
   729   from Series.summable_le2 [OF this sm]
   730   have sda:  "summable (f o disjointed A)"  
   731              "suminf (f o disjointed A) \<le> suminf (f \<circ> A)"
   732     by blast+
   733   hence ley: "suminf (f o disjointed A) \<le> x"
   734     by (metis xeq) 
   735   from sda have "(f \<circ> disjointed A) sums suminf (f \<circ> disjointed A)"
   736     by (simp add: sums_iff) 
   737   hence y: "suminf (f o disjointed A) \<in> measure_set M f s"
   738     apply (auto simp add: measure_set_def)
   739     apply (rule_tac x="disjointed A" in exI) 
   740     apply (simp add: disjoint_family_disjointed UN_disjointed_eq ss dA)
   741     done
   742   show ?thesis
   743     by (blast intro: Inf_lower y order_trans [OF _ ley] inf_measure_pos0 posf)
   744 qed
   745 
   746 lemma (in algebra) inf_measure_close:
   747   assumes posf: "positive M f" and e: "0 < e" and ss: "s \<subseteq> (space M)"
   748   shows "\<exists>A l. range A \<subseteq> sets M & disjoint_family A & s \<subseteq> (\<Union>i. A i) & 
   749                (f \<circ> A) sums l & l \<le> Inf (measure_set M f s) + e"
   750 proof -
   751   have " measure_set M f s \<noteq> {}" 
   752     by (metis emptyE ss inf_measure_nonempty [OF posf top])
   753   hence "\<exists>l \<in> measure_set M f s. l < Inf (measure_set M f s) + e" 
   754     by (rule Inf_close [OF _ e])
   755   thus ?thesis 
   756     by (auto simp add: measure_set_def, rule_tac x=" A" in exI, auto)
   757 qed
   758 
   759 lemma (in algebra) inf_measure_countably_subadditive:
   760   assumes posf: "positive M f" and inc: "increasing M f" 
   761   shows "countably_subadditive (| space = space M, sets = Pow (space M) |)
   762                   (\<lambda>x. Inf (measure_set M f x))"
   763 proof (auto simp add: countably_subadditive_def o_def, rule field_le_epsilon)
   764   fix A :: "nat \<Rightarrow> 'a set" and e :: real
   765     assume A: "range A \<subseteq> Pow (space M)"
   766        and disj: "disjoint_family A"
   767        and sb: "(\<Union>i. A i) \<subseteq> space M"
   768        and sum1: "summable (\<lambda>n. Inf (measure_set M f (A n)))"
   769        and e: "0 < e"
   770     have "!!n. \<exists>B l. range B \<subseteq> sets M \<and> disjoint_family B \<and> A n \<subseteq> (\<Union>i. B i) \<and>
   771                     (f o B) sums l \<and>
   772                     l \<le> Inf (measure_set M f (A n)) + e * (1/2)^(Suc n)"
   773       apply (rule inf_measure_close [OF posf])
   774       apply (metis e half mult_pos_pos zero_less_power) 
   775       apply (metis UNIV_I UN_subset_iff sb)
   776       done
   777     hence "\<exists>BB ll. \<forall>n. range (BB n) \<subseteq> sets M \<and> disjoint_family (BB n) \<and>
   778                        A n \<subseteq> (\<Union>i. BB n i) \<and> (f o BB n) sums ll n \<and>
   779                        ll n \<le> Inf (measure_set M f (A n)) + e * (1/2)^(Suc n)"
   780       by (rule choice2)
   781     then obtain BB ll
   782       where BB: "!!n. (range (BB n) \<subseteq> sets M)"
   783         and disjBB: "!!n. disjoint_family (BB n)" 
   784         and sbBB: "!!n. A n \<subseteq> (\<Union>i. BB n i)"
   785         and BBsums: "!!n. (f o BB n) sums ll n"
   786         and ll: "!!n. ll n \<le> Inf (measure_set M f (A n)) + e * (1/2)^(Suc n)"
   787       by auto blast
   788     have llpos: "!!n. 0 \<le> ll n"
   789         by (metis BBsums sums_iff o_apply posf positive_imp_pos suminf_ge_zero 
   790               range_subsetD BB) 
   791     have sll: "summable ll &
   792                suminf ll \<le> suminf (\<lambda>n. Inf (measure_set M f (A n))) + e"
   793       proof -
   794         have "(\<lambda>n. e * (1/2)^(Suc n)) sums (e*1)"
   795           by (rule sums_mult [OF power_half_series]) 
   796         hence sum0: "summable (\<lambda>n. e * (1 / 2) ^ Suc n)"
   797           and eqe:  "(\<Sum>n. e * (1 / 2) ^ n / 2) = e"
   798           by (auto simp add: sums_iff) 
   799         have 0: "suminf (\<lambda>n. Inf (measure_set M f (A n))) +
   800                  suminf (\<lambda>n. e * (1/2)^(Suc n)) =
   801                  suminf (\<lambda>n. Inf (measure_set M f (A n)) + e * (1/2)^(Suc n))"
   802           by (rule suminf_add [OF sum1 sum0]) 
   803         have 1: "\<forall>n. \<bar>ll n\<bar> \<le> Inf (measure_set M f (A n)) + e * (1/2) ^ Suc n"
   804           by (metis ll llpos abs_of_nonneg)
   805         have 2: "summable (\<lambda>n. Inf (measure_set M f (A n)) + e*(1/2)^(Suc n))"
   806           by (rule summable_add [OF sum1 sum0]) 
   807         have "suminf ll \<le> (\<Sum>n. Inf (measure_set M f (A n)) + e*(1/2) ^ Suc n)"
   808           using Series.summable_le2 [OF 1 2] by auto
   809         also have "... = (\<Sum>n. Inf (measure_set M f (A n))) + 
   810                          (\<Sum>n. e * (1 / 2) ^ Suc n)"
   811           by (metis 0) 
   812         also have "... = (\<Sum>n. Inf (measure_set M f (A n))) + e"
   813           by (simp add: eqe) 
   814         finally show ?thesis using  Series.summable_le2 [OF 1 2] by auto
   815       qed
   816     def C \<equiv> "(split BB) o nat_to_nat2"
   817     have C: "!!n. C n \<in> sets M"
   818       apply (rule_tac p="nat_to_nat2 n" in PairE)
   819       apply (simp add: C_def)
   820       apply (metis BB subsetD rangeI)  
   821       done
   822     have sbC: "(\<Union>i. A i) \<subseteq> (\<Union>i. C i)"
   823       proof (auto simp add: C_def)
   824         fix x i
   825         assume x: "x \<in> A i"
   826         with sbBB [of i] obtain j where "x \<in> BB i j"
   827           by blast        
   828         thus "\<exists>i. x \<in> split BB (nat_to_nat2 i)"
   829           by (metis nat_to_nat2_surj internal_split_def prod.cases 
   830                 prod_case_split surj_f_inv_f)
   831       qed 
   832     have "(f \<circ> C) = (f \<circ> (\<lambda>(x, y). BB x y)) \<circ> nat_to_nat2"
   833       by (rule ext)  (auto simp add: C_def) 
   834     also have "... sums suminf ll" 
   835       proof (rule suminf_2dimen)
   836         show "\<And>m n. 0 \<le> (f \<circ> (\<lambda>(x, y). BB x y)) (m, n)" using posf BB 
   837           by (force simp add: positive_def)
   838         show "\<And>m. (\<lambda>n. (f \<circ> (\<lambda>(x, y). BB x y)) (m, n)) sums ll m"using BBsums BB
   839           by (force simp add: o_def)
   840         show "summable ll" using sll
   841           by auto
   842       qed
   843     finally have Csums: "(f \<circ> C) sums suminf ll" .
   844     have "Inf (measure_set M f (\<Union>i. A i)) \<le> suminf ll"
   845       apply (rule inf_measure_le [OF posf inc], auto)
   846       apply (rule_tac x="C" in exI)
   847       apply (auto simp add: C sbC Csums) 
   848       done
   849     also have "... \<le> (\<Sum>n. Inf (measure_set M f (A n))) + e" using sll
   850       by blast
   851     finally show "Inf (measure_set M f (\<Union>i. A i)) \<le> 
   852           (\<Sum>n. Inf (measure_set M f (A n))) + e" .
   853 qed
   854 
   855 lemma (in algebra) inf_measure_outer:
   856   "positive M f \<Longrightarrow> increasing M f 
   857    \<Longrightarrow> outer_measure_space (| space = space M, sets = Pow (space M) |)
   858                           (\<lambda>x. Inf (measure_set M f x))"
   859   by (simp add: outer_measure_space_def inf_measure_positive
   860                 inf_measure_increasing inf_measure_countably_subadditive) 
   861 
   862 (*MOVE UP*)
   863 
   864 lemma (in algebra) algebra_subset_lambda_system:
   865   assumes posf: "positive M f" and inc: "increasing M f" 
   866       and add: "additive M f"
   867   shows "sets M \<subseteq> lambda_system (| space = space M, sets = Pow (space M) |)
   868                                 (\<lambda>x. Inf (measure_set M f x))"
   869 proof (auto dest: sets_into_space 
   870             simp add: algebra.lambda_system_eq [OF algebra_Pow]) 
   871   fix x s
   872   assume x: "x \<in> sets M"
   873      and s: "s \<subseteq> space M"
   874   have [simp]: "!!x. x \<in> sets M \<Longrightarrow> s \<inter> (space M - x) = s-x" using s 
   875     by blast
   876   have "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
   877         \<le> Inf (measure_set M f s)"
   878     proof (rule field_le_epsilon) 
   879       fix e :: real
   880       assume e: "0 < e"
   881       from inf_measure_close [OF posf e s]
   882       obtain A l where A: "range A \<subseteq> sets M" and disj: "disjoint_family A"
   883                    and sUN: "s \<subseteq> (\<Union>i. A i)" and fsums: "(f \<circ> A) sums l"
   884                    and l: "l \<le> Inf (measure_set M f s) + e"
   885         by auto
   886       have [simp]: "!!x. x \<in> sets M \<Longrightarrow>
   887                       (f o (\<lambda>z. z \<inter> (space M - x)) o A) = (f o (\<lambda>z. z - x) o A)"
   888         by (rule ext, simp, metis A Int_Diff Int_space_eq2 range_subsetD)
   889       have  [simp]: "!!n. f (A n \<inter> x) + f (A n - x) = f (A n)"
   890         by (subst additiveD [OF add, symmetric])
   891            (auto simp add: x range_subsetD [OF A] Int_Diff_Un Int_Diff_disjoint)
   892       have fsumb: "summable (f \<circ> A)"
   893         by (metis fsums sums_iff) 
   894       { fix u
   895         assume u: "u \<in> sets M"
   896         have [simp]: "\<And>n. \<bar>f (A n \<inter> u)\<bar> \<le> f (A n)"
   897           by (simp add: positive_imp_pos [OF posf]  increasingD [OF inc] 
   898                         u Int  range_subsetD [OF A]) 
   899         have 1: "summable (f o (\<lambda>z. z\<inter>u) o A)" 
   900           by (rule summable_comparison_test [OF _ fsumb]) simp
   901         have 2: "Inf (measure_set M f (s\<inter>u)) \<le> suminf (f o (\<lambda>z. z\<inter>u) o A)"
   902           proof (rule Inf_lower) 
   903             show "suminf (f \<circ> (\<lambda>z. z \<inter> u) \<circ> A) \<in> measure_set M f (s \<inter> u)"
   904               apply (simp add: measure_set_def) 
   905               apply (rule_tac x="(\<lambda>z. z \<inter> u) o A" in exI) 
   906               apply (auto simp add: disjoint_family_subset [OF disj])
   907               apply (blast intro: u range_subsetD [OF A]) 
   908               apply (blast dest: subsetD [OF sUN])
   909               apply (metis 1 o_assoc sums_iff) 
   910               done
   911           next
   912             show "\<And>x. x \<in> measure_set M f (s \<inter> u) \<Longrightarrow> 0 \<le> x"
   913               by (blast intro: inf_measure_pos0 [OF posf]) 
   914             qed
   915           note 1 2
   916       } note lesum = this
   917       have sum1: "summable (f o (\<lambda>z. z\<inter>x) o A)"
   918         and inf1: "Inf (measure_set M f (s\<inter>x)) \<le> suminf (f o (\<lambda>z. z\<inter>x) o A)"
   919         and sum2: "summable (f o (\<lambda>z. z \<inter> (space M - x)) o A)"
   920         and inf2: "Inf (measure_set M f (s \<inter> (space M - x))) 
   921                    \<le> suminf (f o (\<lambda>z. z \<inter> (space M - x)) o A)"
   922         by (metis Diff lesum top x)+
   923       hence "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
   924            \<le> suminf (f o (\<lambda>s. s\<inter>x) o A) + suminf (f o (\<lambda>s. s-x) o A)"
   925         by (simp add: x)
   926       also have "... \<le> suminf (f o A)" using suminf_add [OF sum1 sum2] 
   927         by (simp add: x) (simp add: o_def) 
   928       also have "... \<le> Inf (measure_set M f s) + e"
   929         by (metis fsums l sums_unique) 
   930       finally show "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
   931         \<le> Inf (measure_set M f s) + e" .
   932     qed
   933   moreover 
   934   have "Inf (measure_set M f s)
   935        \<le> Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))"
   936     proof -
   937     have "Inf (measure_set M f s) = Inf (measure_set M f ((s\<inter>x) \<union> (s-x)))"
   938       by (metis Un_Diff_Int Un_commute)
   939     also have "... \<le> Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))" 
   940       apply (rule subadditiveD) 
   941       apply (iprover intro: algebra.countably_subadditive_subadditive algebra_Pow 
   942                inf_measure_positive inf_measure_countably_subadditive posf inc)
   943       apply (auto simp add: subsetD [OF s])  
   944       done
   945     finally show ?thesis .
   946     qed
   947   ultimately 
   948   show "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
   949         = Inf (measure_set M f s)"
   950     by (rule order_antisym)
   951 qed
   952 
   953 lemma measure_down:
   954      "measure_space N \<Longrightarrow> sigma_algebra M \<Longrightarrow> sets M \<subseteq> sets N \<Longrightarrow>
   955       (measure M = measure N) \<Longrightarrow> measure_space M"
   956   by (simp add: measure_space_def measure_space_axioms_def positive_def 
   957                 countably_additive_def) 
   958      blast
   959 
   960 theorem (in algebra) caratheodory:
   961   assumes posf: "positive M f" and ca: "countably_additive M f" 
   962   shows "\<exists>MS :: 'a measure_space. 
   963              (\<forall>s \<in> sets M. measure MS s = f s) \<and>
   964              ((|space = space MS, sets = sets MS|) = sigma (space M) (sets M)) \<and>
   965              measure_space MS" 
   966   proof -
   967     have inc: "increasing M f"
   968       by (metis additive_increasing ca countably_additive_additive posf) 
   969     let ?infm = "(\<lambda>x. Inf (measure_set M f x))"
   970     def ls \<equiv> "lambda_system (|space = space M, sets = Pow (space M)|) ?infm"
   971     have mls: "measure_space (|space = space M, sets = ls, measure = ?infm|)"
   972       using sigma_algebra.caratheodory_lemma
   973               [OF sigma_algebra_Pow  inf_measure_outer [OF posf inc]]
   974       by (simp add: ls_def)
   975     hence sls: "sigma_algebra (|space = space M, sets = ls, measure = ?infm|)"
   976       by (simp add: measure_space_def) 
   977     have "sets M \<subseteq> ls" 
   978       by (simp add: ls_def)
   979          (metis ca posf inc countably_additive_additive algebra_subset_lambda_system)
   980     hence sgs_sb: "sigma_sets (space M) (sets M) \<subseteq> ls" 
   981       using sigma_algebra.sigma_sets_subset [OF sls, of "sets M"]
   982       by simp
   983     have "measure_space (|space = space M, 
   984                           sets = sigma_sets (space M) (sets M),
   985                           measure = ?infm|)"
   986       by (rule measure_down [OF mls], rule sigma_algebra_sigma_sets) 
   987          (simp_all add: sgs_sb space_closed)
   988     thus ?thesis
   989       by (force simp add: sigma_def inf_measure_agrees [OF posf ca]) 
   990 qed
   991 
   992 end