more lemmas
authorAndreas Lochbihler
Wed, 11 Feb 2015 15:22:37 +0100
changeset 59525 dfe6449aecd8
parent 59524 67deb7bed6d3
child 59526 af02440afb4a
more lemmas
--- a/src/HOL/Probability/Giry_Monad.thy	Wed Feb 11 15:04:23 2015 +0100
+++ b/src/HOL/Probability/Giry_Monad.thy	Wed Feb 11 15:22:37 2015 +0100
@@ -142,6 +142,20 @@
     "subprob_space (null_measure M) \<longleftrightarrow> space M \<noteq> {}"
   by (auto intro!: subprob_spaceI dest: subprob_space.subprob_not_empty)
+lemma subprob_space_restrict_space:
+  assumes M: "subprob_space M"
+  and A: "A \<inter> space M \<in> sets M" "A \<inter> space M \<noteq> {}"
+  shows "subprob_space (restrict_space M A)"
+proof(rule subprob_spaceI)
+  have "emeasure (restrict_space M A) (space (restrict_space M A)) = emeasure M (A \<inter> space M)"
+    using A by(simp add: emeasure_restrict_space space_restrict_space)
+  also have "\<dots> \<le> 1" by(rule subprob_space.subprob_emeasure_le_1)(rule M)
+  finally show "emeasure (restrict_space M A) (space (restrict_space M A)) \<le> 1" .
+  show "space (restrict_space M A) \<noteq> {}"
+    using A by(simp add: space_restrict_space)
 definition subprob_algebra :: "'a measure \<Rightarrow> 'a measure measure" where
   "subprob_algebra K =
     (\<Squnion>\<^sub>\<sigma> A\<in>sets K. vimage_algebra {M. subprob_space M \<and> sets M = sets K} (\<lambda>M. emeasure M A) borel)"
--- a/src/HOL/Probability/Probability_Mass_Function.thy	Wed Feb 11 15:04:23 2015 +0100
+++ b/src/HOL/Probability/Probability_Mass_Function.thy	Wed Feb 11 15:22:37 2015 +0100
@@ -502,6 +502,12 @@
   shows "(\<integral>x. f x \<partial>bernoulli_pmf p) = f True * p + f False * (1 - p)"
   by (subst integral_measure_pmf[of UNIV]) (auto simp: UNIV_bool)
+lemma pmf_bernoulli_half [simp]: "pmf (bernoulli_pmf (1 / 2)) x = 1 / 2"
+by(cases x) simp_all
+lemma measure_pmf_bernoulli_half: "measure_pmf (bernoulli_pmf (1 / 2)) = uniform_count_measure UNIV"
+by(rule measure_eqI)(simp_all add: nn_integral_pmf[symmetric] emeasure_uniform_count_measure nn_integral_count_space_finite sets_uniform_count_measure)
 subsubsection \<open> Geometric Distribution \<close>
 lift_definition geometric_pmf :: "nat pmf" is "\<lambda>n. 1 / 2^Suc n"
@@ -639,7 +645,7 @@
   "(\<lambda>x. measure_pmf (M x)) \<in> measurable (count_space UNIV) (subprob_algebra (count_space UNIV))"
   by (auto simp: space_subprob_algebra intro!: prob_space_imp_subprob_space) unfold_locales
-lemma bind_pmf_cong:
+lemma bind_measure_pmf_cong:
   assumes "\<And>x. A x \<in> space (subprob_algebra N)" "\<And>x. B x \<in> space (subprob_algebra N)"
   assumes "\<And>i. i \<in> set_pmf x \<Longrightarrow> A i = B i"
   shows "bind (measure_pmf x) A = bind (measure_pmf x) B"
@@ -879,6 +885,16 @@
   unfolding bind_return_pmf''[symmetric] join_eq_bind_pmf bind_assoc_pmf
   by (simp add: bind_return_pmf'')
+lemma bind_pmf_cong:
+  "\<lbrakk> p = q; \<And>x. x \<in> set_pmf q \<Longrightarrow> f x = g x \<rbrakk>
+  \<Longrightarrow> bind_pmf p f = bind_pmf q g"
+by(simp add: bind_pmf_def cong: map_pmf_cong)
+lemma bind_pmf_cong_simp:
+  "\<lbrakk> p = q; \<And>x. x \<in> set_pmf q =simp=> f x = g x \<rbrakk>
+  \<Longrightarrow> bind_pmf p f = bind_pmf q g"
+by(simp add: simp_implies_def cong: bind_pmf_cong)
 definition "pair_pmf A B = bind_pmf A (\<lambda>x. bind_pmf B (\<lambda>y. return_pmf (x, y)))"
 lemma pmf_pair: "pmf (pair_pmf M N) (a, b) = pmf M a * pmf N b"
@@ -1235,5 +1251,38 @@
+lemma rel_pmf_reflI: 
+  assumes "\<And>x. x \<in> set_pmf p \<Longrightarrow> P x x"
+  shows "rel_pmf P p p"
+by(rule rel_pmf.intros[where pq="map_pmf (\<lambda>x. (x, x)) p"])(auto simp add: pmf.map_comp o_def set_map_pmf assms)
+lemma rel_pmf_joinI:
+  assumes "rel_pmf (rel_pmf P) p q"
+  shows "rel_pmf P (join_pmf p) (join_pmf q)"
+proof -
+  from assms obtain pq where p: "p = map_pmf fst pq"
+    and q: "q = map_pmf snd pq"
+    and P: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> rel_pmf P x y"
+    by cases auto
+  from P obtain PQ 
+    where PQ: "\<And>x y a b. \<lbrakk> (x, y) \<in> set_pmf pq; (a, b) \<in> set_pmf (PQ x y) \<rbrakk> \<Longrightarrow> P a b"
+    and x: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> map_pmf fst (PQ x y) = x"
+    and y: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> map_pmf snd (PQ x y) = y"
+    by(metis rel_pmf.simps)
+  let ?r = "bind_pmf pq (\<lambda>(x, y). PQ x y)"
+  have "\<And>a b. (a, b) \<in> set_pmf ?r \<Longrightarrow> P a b" by(auto simp add: set_bind_pmf intro: PQ)
+  moreover have "map_pmf fst ?r = join_pmf p" "map_pmf snd ?r = join_pmf q"
+    by(simp_all add: bind_pmf_def map_join_pmf pmf.map_comp o_def split_def p q x y cong: pmf.map_cong)
+  ultimately show ?thesis ..
+lemma rel_pmf_bindI:
+  assumes pq: "rel_pmf R p q"
+  and fg: "\<And>x y. R x y \<Longrightarrow> rel_pmf P (f x) (g y)"
+  shows "rel_pmf P (bind_pmf p f) (bind_pmf q g)"
+unfolding bind_pmf_def
+by(rule rel_pmf_joinI)(auto simp add: pmf.rel_map intro: pmf.rel_mono[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp, OF _ pq] fg)