equal
deleted
inserted
replaced
229 using assms by transfer (auto split: option.splits) |
229 using assms by transfer (auto split: option.splits) |
230 |
230 |
231 qualified lemma mapping_of_bind_pmf: |
231 qualified lemma mapping_of_bind_pmf: |
232 assumes "finite (set_pmf p)" |
232 assumes "finite (set_pmf p)" |
233 shows "mapping_of_pmf (bind_pmf p f) = |
233 shows "mapping_of_pmf (bind_pmf p f) = |
234 fold_combine_plus (\<lambda>x. Mapping.map_values (\<lambda>_. ( * ) (pmf p x)) |
234 fold_combine_plus (\<lambda>x. Mapping.map_values (\<lambda>_. (*) (pmf p x)) |
235 (mapping_of_pmf (f x))) (set_pmf p)" |
235 (mapping_of_pmf (f x))) (set_pmf p)" |
236 using assms |
236 using assms |
237 by (intro mapping_of_pmfI') |
237 by (intro mapping_of_pmfI') |
238 (auto simp: keys_fold_combine_plus lookup_default_fold_combine_plus |
238 (auto simp: keys_fold_combine_plus lookup_default_fold_combine_plus |
239 pmf_bind integral_measure_pmf lookup_default_0_map_values |
239 pmf_bind integral_measure_pmf lookup_default_0_map_values |
266 by (intro mapping_of_pmfI') simp_all |
266 by (intro mapping_of_pmfI') simp_all |
267 |
267 |
268 lemma bind_pmf_aux_code_aux: |
268 lemma bind_pmf_aux_code_aux: |
269 assumes "finite A" |
269 assumes "finite A" |
270 shows "bind_pmf_aux p f A = |
270 shows "bind_pmf_aux p f A = |
271 fold_combine_plus (\<lambda>x. Mapping.map_values (\<lambda>_. ( * ) (pmf p x)) |
271 fold_combine_plus (\<lambda>x. Mapping.map_values (\<lambda>_. (*) (pmf p x)) |
272 (mapping_of_pmf (f x))) A" (is "?lhs = ?rhs") |
272 (mapping_of_pmf (f x))) A" (is "?lhs = ?rhs") |
273 proof (intro mapping_eqI'[where d = 0]) |
273 proof (intro mapping_eqI'[where d = 0]) |
274 fix x assume "x \<in> Mapping.keys ?lhs" |
274 fix x assume "x \<in> Mapping.keys ?lhs" |
275 then obtain y where y: "y \<in> A" "x \<in> set_pmf (f y)" by auto |
275 then obtain y where y: "y \<in> A" "x \<in> set_pmf (f y)" by auto |
276 hence "Mapping.lookup_default 0 ?lhs x = |
276 hence "Mapping.lookup_default 0 ?lhs x = |
285 finally show "Mapping.lookup_default 0 ?lhs x = Mapping.lookup_default 0 ?rhs x" . |
285 finally show "Mapping.lookup_default 0 ?lhs x = Mapping.lookup_default 0 ?rhs x" . |
286 qed (insert assms, simp_all add: keys_fold_combine_plus) |
286 qed (insert assms, simp_all add: keys_fold_combine_plus) |
287 |
287 |
288 lemma bind_pmf_aux_code [code]: |
288 lemma bind_pmf_aux_code [code]: |
289 "bind_pmf_aux p f (set xs) = |
289 "bind_pmf_aux p f (set xs) = |
290 fold_combine_plus (\<lambda>x. Mapping.map_values (\<lambda>_. ( * ) (pmf p x)) |
290 fold_combine_plus (\<lambda>x. Mapping.map_values (\<lambda>_. (*) (pmf p x)) |
291 (mapping_of_pmf (f x))) (set xs)" |
291 (mapping_of_pmf (f x))) (set xs)" |
292 by (rule bind_pmf_aux_code_aux) simp_all |
292 by (rule bind_pmf_aux_code_aux) simp_all |
293 |
293 |
294 lemmas bind_pmf_code [code abstract] = bind_pmf_aux_correct |
294 lemmas bind_pmf_code [code abstract] = bind_pmf_aux_correct |
295 |
295 |