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