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