1319 context |
1319 context |
1320 fixes rate :: real assumes rate_pos: "0 < rate" |
1320 fixes rate :: real assumes rate_pos: "0 < rate" |
1321 begin |
1321 begin |
1322 |
1322 |
1323 lift_definition poisson_pmf :: "nat pmf" is "\<lambda>k. rate ^ k / fact k * exp (-rate)" |
1323 lift_definition poisson_pmf :: "nat pmf" is "\<lambda>k. rate ^ k / fact k * exp (-rate)" |
1324 proof |
1324 proof (* by Manuel Eberl *) |
1325 (* Proof by Manuel Eberl *) |
|
1326 |
|
1327 have summable: "summable (\<lambda>x::nat. rate ^ x / fact x)" using summable_exp |
1325 have summable: "summable (\<lambda>x::nat. rate ^ x / fact x)" using summable_exp |
1328 by (simp add: field_simps divide_inverse [symmetric]) |
1326 by (simp add: field_simps divide_inverse [symmetric]) |
1329 have "(\<integral>\<^sup>+(x::nat). rate ^ x / fact x * exp (-rate) \<partial>count_space UNIV) = |
1327 have "(\<integral>\<^sup>+(x::nat). rate ^ x / fact x * exp (-rate) \<partial>count_space UNIV) = |
1330 exp (-rate) * (\<integral>\<^sup>+(x::nat). rate ^ x / fact x \<partial>count_space UNIV)" |
1328 exp (-rate) * (\<integral>\<^sup>+(x::nat). rate ^ x / fact x \<partial>count_space UNIV)" |
1331 by (simp add: field_simps nn_integral_cmult[symmetric]) |
1329 by (simp add: field_simps nn_integral_cmult[symmetric]) |
1332 also from rate_pos have "(\<integral>\<^sup>+(x::nat). rate ^ x / fact x \<partial>count_space UNIV) = (\<Sum>x. rate ^ x / fact x)" |
1330 also from rate_pos have "(\<integral>\<^sup>+(x::nat). rate ^ x / fact x \<partial>count_space UNIV) = (\<Sum>x. rate ^ x / fact x)" |
1333 by (simp_all add: nn_integral_count_space_nat suminf_ereal summable suminf_ereal_finite) |
1331 by (simp_all add: nn_integral_count_space_nat suminf_ereal summable suminf_ereal_finite) |
1334 also have "... = exp rate" unfolding exp_def |
1332 also have "... = exp rate" unfolding exp_def |
1335 by (simp add: field_simps divide_inverse [symmetric] transfer_int_nat_factorial) |
1333 by (simp add: field_simps divide_inverse [symmetric]) |
1336 also have "ereal (exp (-rate)) * ereal (exp rate) = 1" |
1334 also have "ereal (exp (-rate)) * ereal (exp rate) = 1" |
1337 by (simp add: mult_exp_exp) |
1335 by (simp add: mult_exp_exp) |
1338 finally show "(\<integral>\<^sup>+ x. ereal (rate ^ x / real (fact x) * exp (- rate)) \<partial>count_space UNIV) = 1" . |
1336 finally show "(\<integral>\<^sup>+ x. ereal (rate ^ x / (fact x) * exp (- rate)) \<partial>count_space UNIV) = 1" . |
1339 qed (simp add: rate_pos[THEN less_imp_le]) |
1337 qed (simp add: rate_pos[THEN less_imp_le]) |
1340 |
1338 |
1341 lemma pmf_poisson[simp]: "pmf poisson_pmf k = rate ^ k / fact k * exp (-rate)" |
1339 lemma pmf_poisson[simp]: "pmf poisson_pmf k = rate ^ k / fact k * exp (-rate)" |
1342 by transfer rule |
1340 by transfer rule |
1343 |
1341 |