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