# HG changeset patch # User paulson # Date 1257781815 0 # Node ID 40b44cb20c8c1c38b8515f7d704fb47d85a880c7 # Parent 535789c26230f227233352df4abd4de57000e598 New theory Probability/Borel.thy, and some associated lemmas diff -r 535789c26230 -r 40b44cb20c8c src/HOL/IsaMakefile --- a/src/HOL/IsaMakefile Mon Nov 09 11:34:22 2009 +0100 +++ b/src/HOL/IsaMakefile Mon Nov 09 15:50:15 2009 +0000 @@ -1069,7 +1069,8 @@ Probability/Sigma_Algebra.thy \ Probability/SeriesPlus.thy \ Probability/Caratheodory.thy \ - Probability/Measure.thy + Probability/Measure.thy \ + Probability/Borel.thy @$(ISABELLE_TOOL) usedir -g true $(OUT)/HOL Probability diff -r 535789c26230 -r 40b44cb20c8c src/HOL/Probability/Borel.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Borel.thy Mon Nov 09 15:50:15 2009 +0000 @@ -0,0 +1,425 @@ +header {*Borel Sets*} + +theory Borel + imports Measure +begin + +text{*From the Hurd/Coble measure theory development, translated by Lawrence Paulson.*} + +definition borel_space where + "borel_space = sigma (UNIV::real set) (range (\a::real. {x. x \ a}))" + +definition borel_measurable where + "borel_measurable a = measurable a borel_space" + +definition indicator_fn where + "indicator_fn s = (\x. if x \ s then 1 else (0::real))" + +definition mono_convergent where + "mono_convergent u f s \ + (\x m n. m \ n \ x \ s \ u m x \ u n x) \ + (\x \ s. (\i. u i x) ----> f x)" + +lemma in_borel_measurable: + "f \ borel_measurable M \ + sigma_algebra M \ + (\s \ sets (sigma UNIV (range (\a::real. {x. x \ a}))). + f -` s \ space M \ sets M)" +apply (auto simp add: borel_measurable_def measurable_def borel_space_def) +apply (metis PowD UNIV_I Un_commute sigma_algebra_sigma subset_Pow_Union subset_UNIV subset_Un_eq) +done + +lemma (in sigma_algebra) borel_measurable_const: + "(\x. c) \ borel_measurable M" + by (auto simp add: in_borel_measurable prems) + +lemma (in sigma_algebra) borel_measurable_indicator: + assumes a: "a \ sets M" + shows "indicator_fn a \ borel_measurable M" +apply (auto simp add: in_borel_measurable indicator_fn_def prems) +apply (metis Diff_eq Int_commute a compl_sets) +done + +lemma Collect_eq: "{w \ X. f w \ a} = {w. f w \ a} \ X" + by (metis Collect_conj_eq Collect_mem_eq Int_commute) + +lemma (in measure_space) borel_measurable_le_iff: + "f \ borel_measurable M = (\a. {w \ space M. f w \ a} \ sets M)" +proof + assume f: "f \ borel_measurable M" + { fix a + have "{w \ space M. f w \ a} \ sets M" using f + apply (auto simp add: in_borel_measurable sigma_def Collect_eq) + apply (drule_tac x="{x. x \ a}" in bspec, auto) + apply (metis equalityE rangeI subsetD sigma_sets.Basic) + done + } + thus "\a. {w \ space M. f w \ a} \ sets M" by blast +next + assume "\a. {w \ space M. f w \ a} \ sets M" + thus "f \ borel_measurable M" + apply (simp add: borel_measurable_def borel_space_def Collect_eq) + apply (rule measurable_sigma, auto) + done +qed + +lemma Collect_less_le: + "{w \ X. f w < g w} = (\n. {w \ X. f w \ g w - inverse(real(Suc n))})" + proof auto + fix w + assume w: "f w < g w" + hence nz: "g w - f w \ 0" + by arith + with w have "real(Suc(natceiling(inverse(g w - f w)))) > inverse(g w - f w)" + by (metis lessI order_le_less_trans real_natceiling_ge real_of_nat_less_iff) hence "inverse(real(Suc(natceiling(inverse(g w - f w))))) + < inverse(inverse(g w - f w))" + by (metis less_iff_diff_less_0 less_imp_inverse_less linorder_neqE_ordered_idom nz positive_imp_inverse_positive real_le_anti_sym real_less_def w) + hence "inverse(real(Suc(natceiling(inverse(g w - f w))))) < g w - f w" + by (metis inverse_inverse_eq order_less_le_trans real_le_refl) + thus "\n. f w \ g w - inverse(real(Suc n))" using w + by (rule_tac x="natceiling(inverse(g w - f w))" in exI, auto) + next + fix w n + assume le: "f w \ g w - inverse(real(Suc n))" + hence "0 < inverse(real(Suc n))" + by (metis inverse_real_of_nat_gt_zero) + thus "f w < g w" using le + by arith + qed + + +lemma (in sigma_algebra) sigma_le_less: + assumes M: "!!a::real. {w \ space M. f w \ a} \ sets M" + shows "{w \ space M. f w < a} \ sets M" +proof - + show ?thesis using Collect_less_le [of "space M" f "\x. a"] + by (auto simp add: countable_UN M) +qed + +lemma (in sigma_algebra) sigma_less_ge: + assumes M: "!!a::real. {w \ space M. f w < a} \ sets M" + shows "{w \ space M. a \ f w} \ sets M" +proof - + have "{w \ space M. a \ f w} = space M - {w \ space M. f w < a}" + by auto + thus ?thesis using M + by auto +qed + +lemma (in sigma_algebra) sigma_ge_gr: + assumes M: "!!a::real. {w \ space M. a \ f w} \ sets M" + shows "{w \ space M. a < f w} \ sets M" +proof - + show ?thesis using Collect_less_le [of "space M" "\x. a" f] + by (auto simp add: countable_UN le_diff_eq M) +qed + +lemma (in sigma_algebra) sigma_gr_le: + assumes M: "!!a::real. {w \ space M. a < f w} \ sets M" + shows "{w \ space M. f w \ a} \ sets M" +proof - + have "{w \ space M. f w \ a} = space M - {w \ space M. a < f w}" + by auto + thus ?thesis + by (simp add: M compl_sets) +qed + +lemma (in measure_space) borel_measurable_gr_iff: + "f \ borel_measurable M = (\a. {w \ space M. a < f w} \ sets M)" +proof (auto simp add: borel_measurable_le_iff sigma_gr_le) + fix u + assume M: "\a. {w \ space M. f w \ a} \ sets M" + have "{w \ space M. u < f w} = space M - {w \ space M. f w \ u}" + by auto + thus "{w \ space M. u < f w} \ sets M" + by (force simp add: compl_sets countable_UN M) +qed + +lemma (in measure_space) borel_measurable_less_iff: + "f \ borel_measurable M = (\a. {w \ space M. f w < a} \ sets M)" +proof (auto simp add: borel_measurable_le_iff sigma_le_less) + fix u + assume M: "\a. {w \ space M. f w < a} \ sets M" + have "{w \ space M. f w \ u} = space M - {w \ space M. u < f w}" + by auto + thus "{w \ space M. f w \ u} \ sets M" + using Collect_less_le [of "space M" "\x. u" f] + by (force simp add: compl_sets countable_UN le_diff_eq sigma_less_ge M) +qed + +lemma (in measure_space) borel_measurable_ge_iff: + "f \ borel_measurable M = (\a. {w \ space M. a \ f w} \ sets M)" +proof (auto simp add: borel_measurable_less_iff sigma_le_less sigma_ge_gr sigma_gr_le) + fix u + assume M: "\a. {w \ space M. f w < a} \ sets M" + have "{w \ space M. u \ f w} = space M - {w \ space M. f w < u}" + by auto + thus "{w \ space M. u \ f w} \ sets M" + by (force simp add: compl_sets countable_UN M) +qed + +lemma (in measure_space) affine_borel_measurable: + assumes g: "g \ borel_measurable M" + shows "(\x. a + (g x) * b) \ borel_measurable M" +proof (cases rule: linorder_cases [of b 0]) + case equal thus ?thesis + by (simp add: borel_measurable_const) +next + case less + { + fix w c + have "a + g w * b \ c \ g w * b \ c - a" + by auto + also have "... \ (c-a)/b \ g w" using less + by (metis divide_le_eq less less_asym) + finally have "a + g w * b \ c \ (c-a)/b \ g w" . + } + hence "\w c. a + g w * b \ c \ (c-a)/b \ g w" . + thus ?thesis using less g + by (simp add: borel_measurable_ge_iff [of g]) + (simp add: borel_measurable_le_iff) +next + case greater + hence 0: "\x c. (g x * b \ c - a) \ (g x \ (c - a) / b)" + by (metis mult_imp_le_div_pos le_divide_eq) + have 1: "\x c. (a + g x * b \ c) \ (g x * b \ c - a)" + by auto + from greater g + show ?thesis + by (simp add: borel_measurable_le_iff 0 1) +qed + +definition + nat_to_rat_surj :: "nat \ rat" where + "nat_to_rat_surj n = (let (i,j) = nat_to_nat2 n + in Fract (nat_to_int_bij i) (nat_to_int_bij j))" + +lemma nat_to_rat_surj: "surj nat_to_rat_surj" +proof (auto simp add: surj_def nat_to_rat_surj_def) + fix y + show "\x. y = (\(i, j). Fract (nat_to_int_bij i) (nat_to_int_bij j)) (nat_to_nat2 x)" + proof (cases y) + case (Fract a b) + obtain i where i: "nat_to_int_bij i = a" using surj_nat_to_int_bij + by (metis surj_def) + obtain j where j: "nat_to_int_bij j = b" using surj_nat_to_int_bij + by (metis surj_def) + obtain n where n: "nat_to_nat2 n = (i,j)" using nat_to_nat2_surj + by (metis surj_def) + + from Fract i j n show ?thesis + by (metis prod.cases prod_case_split) + qed +qed + +lemma rats_enumeration: "\ = range (of_rat o nat_to_rat_surj)" + using nat_to_rat_surj + by (auto simp add: image_def surj_def) (metis Rats_cases) + +lemma (in measure_space) borel_measurable_less_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "{w \ space M. f w < g w} \ sets M" +proof - + have "{w \ space M. f w < g w} = + (\r\\. {w \ space M. f w < r} \ {w \ space M. r < g w })" + by (auto simp add: Rats_dense_in_real) + thus ?thesis using f g + by (simp add: borel_measurable_less_iff [of f] + borel_measurable_gr_iff [of g]) + (blast intro: gen_countable_UN [OF rats_enumeration]) +qed + +lemma (in measure_space) borel_measurable_leq_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "{w \ space M. f w \ g w} \ sets M" +proof - + have "{w \ space M. f w \ g w} = space M - {w \ space M. g w < f w}" + by auto + thus ?thesis using f g + by (simp add: borel_measurable_less_borel_measurable compl_sets) +qed + +lemma (in measure_space) borel_measurable_eq_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "{w \ space M. f w = g w} \ sets M" +proof - + have "{w \ space M. f w = g w} = + {w \ space M. f w \ g w} \ {w \ space M. g w \ f w}" + by auto + thus ?thesis using f g + by (simp add: borel_measurable_leq_borel_measurable Int) +qed + +lemma (in measure_space) borel_measurable_neq_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "{w \ space M. f w \ g w} \ sets M" +proof - + have "{w \ space M. f w \ g w} = space M - {w \ space M. f w = g w}" + by auto + thus ?thesis using f g + by (simp add: borel_measurable_eq_borel_measurable compl_sets) +qed + +lemma (in measure_space) borel_measurable_plus_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "(\x. f x + g x) \ borel_measurable M" +proof - + have 1:"!!a. {w \ space M. a \ f w + g w} = {w \ space M. a + (g w) * -1 \ f w}" + by auto + have "!!a. (\w. a + (g w) * -1) \ borel_measurable M" + by (rule affine_borel_measurable [OF g]) + hence "!!a. {w \ space M. (\w. a + (g w) * -1)(w) \ f w} \ sets M" using f + by (rule borel_measurable_leq_borel_measurable) + hence "!!a. {w \ space M. a \ f w + g w} \ sets M" + by (simp add: 1) + thus ?thesis + by (simp add: borel_measurable_ge_iff) +qed + + +lemma (in measure_space) borel_measurable_square: + assumes f: "f \ borel_measurable M" + shows "(\x. (f x)^2) \ borel_measurable M" +proof - + { + fix a + have "{w \ space M. (f w)\ \ a} \ sets M" + proof (cases rule: linorder_cases [of a 0]) + case less + hence "{w \ space M. (f w)\ \ a} = {}" + by auto (metis less order_le_less_trans power2_less_0) + also have "... \ sets M" + by (rule empty_sets) + finally show ?thesis . + next + case equal + hence "{w \ space M. (f w)\ \ a} = + {w \ space M. f w \ 0} \ {w \ space M. 0 \ f w}" + by auto + also have "... \ sets M" + apply (insert f) + apply (rule Int) + apply (simp add: borel_measurable_le_iff) + apply (simp add: borel_measurable_ge_iff) + done + finally show ?thesis . + next + case greater + have "\x. (f x ^ 2 \ sqrt a ^ 2) = (- sqrt a \ f x & f x \ sqrt a)" + by (metis abs_le_interval_iff abs_of_pos greater real_sqrt_abs + real_sqrt_le_iff real_sqrt_power) + hence "{w \ space M. (f w)\ \ a} = + {w \ space M. -(sqrt a) \ f w} \ {w \ space M. f w \ sqrt a}" + using greater by auto + also have "... \ sets M" + apply (insert f) + apply (rule Int) + apply (simp add: borel_measurable_ge_iff) + apply (simp add: borel_measurable_le_iff) + done + finally show ?thesis . + qed + } + thus ?thesis by (auto simp add: borel_measurable_le_iff) +qed + +lemma times_eq_sum_squares: + fixes x::real + shows"x*y = ((x+y)^2)/4 - ((x-y)^ 2)/4" +by (simp add: power2_eq_square ring_distribs diff_divide_distrib [symmetric]) + + +lemma (in measure_space) borel_measurable_uminus_borel_measurable: + assumes g: "g \ borel_measurable M" + shows "(\x. - g x) \ borel_measurable M" +proof - + have "(\x. - g x) = (\x. 0 + (g x) * -1)" + by simp + also have "... \ borel_measurable M" + by (fast intro: affine_borel_measurable g) + finally show ?thesis . +qed + +lemma (in measure_space) borel_measurable_times_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "(\x. f x * g x) \ borel_measurable M" +proof - + have 1: "(\x. 0 + (f x + g x)\ * inverse 4) \ borel_measurable M" + by (fast intro: affine_borel_measurable borel_measurable_square + borel_measurable_plus_borel_measurable f g) + have "(\x. -((f x + -g x) ^ 2 * inverse 4)) = + (\x. 0 + ((f x + -g x) ^ 2 * inverse -4))" + by (simp add: Ring_and_Field.minus_divide_right) + also have "... \ borel_measurable M" + by (fast intro: affine_borel_measurable borel_measurable_square + borel_measurable_plus_borel_measurable + borel_measurable_uminus_borel_measurable f g) + finally have 2: "(\x. -((f x + -g x) ^ 2 * inverse 4)) \ borel_measurable M" . + show ?thesis + apply (simp add: times_eq_sum_squares real_diff_def) + using 1 2 apply (simp add: borel_measurable_plus_borel_measurable) + done +qed + +lemma (in measure_space) borel_measurable_diff_borel_measurable: + assumes f: "f \ borel_measurable M" + assumes g: "g \ borel_measurable M" + shows "(\x. f x - g x) \ borel_measurable M" +unfolding real_diff_def + by (fast intro: borel_measurable_plus_borel_measurable + borel_measurable_uminus_borel_measurable f g) + +lemma (in measure_space) mono_convergent_borel_measurable: + assumes u: "!!n. u n \ borel_measurable M" + assumes mc: "mono_convergent u f (space M)" + shows "f \ borel_measurable M" +proof - + { + fix a + have 1: "!!w. w \ space M & f w <= a \ w \ space M & (\i. u i w <= a)" + proof safe + fix w i + assume w: "w \ space M" and f: "f w \ a" + hence "u i w \ f w" + by (auto intro: SEQ.incseq_le + simp add: incseq_def mc [unfolded mono_convergent_def]) + thus "u i w \ a" using f + by auto + next + fix w + assume w: "w \ space M" and u: "\i. u i w \ a" + thus "f w \ a" + by (metis LIMSEQ_le_const2 mc [unfolded mono_convergent_def]) + qed + have "{w \ space M. f w \ a} = {w \ space M. (\i. u i w <= a)}" + by (simp add: 1) + also have "... = (\i. {w \ space M. u i w \ a})" + by auto + also have "... \ sets M" using u + by (auto simp add: borel_measurable_le_iff intro: countable_INT) + finally have "{w \ space M. f w \ a} \ sets M" . + } + thus ?thesis + by (auto simp add: borel_measurable_le_iff) +qed + +lemma (in measure_space) borel_measurable_SIGMA_borel_measurable: + assumes s: "finite s" + shows "(!!i. i \ s ==> f i \ borel_measurable M) \ (\x. setsum (\i. f i x) s) \ borel_measurable M" using s +proof (induct s) + case empty + thus ?case + by (simp add: borel_measurable_const) +next + case (insert x s) + thus ?case + by (auto simp add: borel_measurable_plus_borel_measurable) +qed + +end diff -r 535789c26230 -r 40b44cb20c8c src/HOL/Probability/Sigma_Algebra.thy --- a/src/HOL/Probability/Sigma_Algebra.thy Mon Nov 09 11:34:22 2009 +0100 +++ b/src/HOL/Probability/Sigma_Algebra.thy Mon Nov 09 15:50:15 2009 +0000 @@ -71,7 +71,7 @@ assumes countable_UN [intro]: "!!A. range A \ sets M \ (\i::nat. A i) \ sets M" -lemma (in sigma_algebra) countable_INT: +lemma (in sigma_algebra) countable_INT [intro]: assumes a: "range a \ sets M" shows "(\i::nat. a i) \ sets M" proof - @@ -83,6 +83,15 @@ ultimately show ?thesis by metis qed +lemma (in sigma_algebra) gen_countable_UN: + fixes f :: "nat \ 'c" + shows "I = range f \ range A \ sets M \ (\x\I. A x) \ sets M" +by auto + +lemma (in sigma_algebra) gen_countable_INT: + fixes f :: "nat \ 'c" + shows "I = range f \ range A \ sets M \ (\x\I. A x) \ sets M" +by auto lemma algebra_Pow: "algebra (| space = sp, sets = Pow sp |)" diff -r 535789c26230 -r 40b44cb20c8c src/HOL/Set.thy --- a/src/HOL/Set.thy Mon Nov 09 11:34:22 2009 +0100 +++ b/src/HOL/Set.thy Mon Nov 09 15:50:15 2009 +0000 @@ -1645,6 +1645,14 @@ lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f" by blast +lemma vimage_const [simp]: "((\x. c) -` A) = (if c \ A then UNIV else {})" + by auto + +lemma vimage_if [simp]: "((\x. if x \ B then c else d) -` A) = + (if c \ A then (if d \ A then UNIV else B) + else if d \ A then -B else {})" + by (auto simp add: vimage_def) + lemma image_Int_subset: "f`(A Int B) <= f`A Int f`B" by blast