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