src/HOL/Probability/Probability_Mass_Function.thy
changeset 59525 dfe6449aecd8
parent 59496 6faf024a1893
child 59526 af02440afb4a
     1.1 --- a/src/HOL/Probability/Probability_Mass_Function.thy	Wed Feb 11 15:04:23 2015 +0100
     1.2 +++ b/src/HOL/Probability/Probability_Mass_Function.thy	Wed Feb 11 15:22:37 2015 +0100
     1.3 @@ -502,6 +502,12 @@
     1.4    shows "(\<integral>x. f x \<partial>bernoulli_pmf p) = f True * p + f False * (1 - p)"
     1.5    by (subst integral_measure_pmf[of UNIV]) (auto simp: UNIV_bool)
     1.6  
     1.7 +lemma pmf_bernoulli_half [simp]: "pmf (bernoulli_pmf (1 / 2)) x = 1 / 2"
     1.8 +by(cases x) simp_all
     1.9 +
    1.10 +lemma measure_pmf_bernoulli_half: "measure_pmf (bernoulli_pmf (1 / 2)) = uniform_count_measure UNIV"
    1.11 +by(rule measure_eqI)(simp_all add: nn_integral_pmf[symmetric] emeasure_uniform_count_measure nn_integral_count_space_finite sets_uniform_count_measure)
    1.12 +
    1.13  subsubsection \<open> Geometric Distribution \<close>
    1.14  
    1.15  lift_definition geometric_pmf :: "nat pmf" is "\<lambda>n. 1 / 2^Suc n"
    1.16 @@ -639,7 +645,7 @@
    1.17    "(\<lambda>x. measure_pmf (M x)) \<in> measurable (count_space UNIV) (subprob_algebra (count_space UNIV))"
    1.18    by (auto simp: space_subprob_algebra intro!: prob_space_imp_subprob_space) unfold_locales
    1.19  
    1.20 -lemma bind_pmf_cong:
    1.21 +lemma bind_measure_pmf_cong:
    1.22    assumes "\<And>x. A x \<in> space (subprob_algebra N)" "\<And>x. B x \<in> space (subprob_algebra N)"
    1.23    assumes "\<And>i. i \<in> set_pmf x \<Longrightarrow> A i = B i"
    1.24    shows "bind (measure_pmf x) A = bind (measure_pmf x) B"
    1.25 @@ -879,6 +885,16 @@
    1.26    unfolding bind_return_pmf''[symmetric] join_eq_bind_pmf bind_assoc_pmf
    1.27    by (simp add: bind_return_pmf'')
    1.28  
    1.29 +lemma bind_pmf_cong:
    1.30 +  "\<lbrakk> p = q; \<And>x. x \<in> set_pmf q \<Longrightarrow> f x = g x \<rbrakk>
    1.31 +  \<Longrightarrow> bind_pmf p f = bind_pmf q g"
    1.32 +by(simp add: bind_pmf_def cong: map_pmf_cong)
    1.33 +
    1.34 +lemma bind_pmf_cong_simp:
    1.35 +  "\<lbrakk> p = q; \<And>x. x \<in> set_pmf q =simp=> f x = g x \<rbrakk>
    1.36 +  \<Longrightarrow> bind_pmf p f = bind_pmf q g"
    1.37 +by(simp add: simp_implies_def cong: bind_pmf_cong)
    1.38 +
    1.39  definition "pair_pmf A B = bind_pmf A (\<lambda>x. bind_pmf B (\<lambda>y. return_pmf (x, y)))"
    1.40  
    1.41  lemma pmf_pair: "pmf (pair_pmf M N) (a, b) = pmf M a * pmf N b"
    1.42 @@ -1235,5 +1251,38 @@
    1.43                     map_pair)
    1.44  qed
    1.45  
    1.46 +lemma rel_pmf_reflI: 
    1.47 +  assumes "\<And>x. x \<in> set_pmf p \<Longrightarrow> P x x"
    1.48 +  shows "rel_pmf P p p"
    1.49 +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)
    1.50 +
    1.51 +lemma rel_pmf_joinI:
    1.52 +  assumes "rel_pmf (rel_pmf P) p q"
    1.53 +  shows "rel_pmf P (join_pmf p) (join_pmf q)"
    1.54 +proof -
    1.55 +  from assms obtain pq where p: "p = map_pmf fst pq"
    1.56 +    and q: "q = map_pmf snd pq"
    1.57 +    and P: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> rel_pmf P x y"
    1.58 +    by cases auto
    1.59 +  from P obtain PQ 
    1.60 +    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"
    1.61 +    and x: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> map_pmf fst (PQ x y) = x"
    1.62 +    and y: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> map_pmf snd (PQ x y) = y"
    1.63 +    by(metis rel_pmf.simps)
    1.64 +
    1.65 +  let ?r = "bind_pmf pq (\<lambda>(x, y). PQ x y)"
    1.66 +  have "\<And>a b. (a, b) \<in> set_pmf ?r \<Longrightarrow> P a b" by(auto simp add: set_bind_pmf intro: PQ)
    1.67 +  moreover have "map_pmf fst ?r = join_pmf p" "map_pmf snd ?r = join_pmf q"
    1.68 +    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)
    1.69 +  ultimately show ?thesis ..
    1.70 +qed
    1.71 +
    1.72 +lemma rel_pmf_bindI:
    1.73 +  assumes pq: "rel_pmf R p q"
    1.74 +  and fg: "\<And>x y. R x y \<Longrightarrow> rel_pmf P (f x) (g y)"
    1.75 +  shows "rel_pmf P (bind_pmf p f) (bind_pmf q g)"
    1.76 +unfolding bind_pmf_def
    1.77 +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)
    1.78 +
    1.79  end
    1.80