# mathlib3documentation

probability.probability_mass_function.constructions

# Specific Constructions of Probability Mass Functions #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

This file gives a number of different pmf constructions for common probability distributions.

map and seq allow pushing a pmf α along a function f : α → β (or distribution of functions f : pmf (α → β)) to get a pmf β

of_finset and of_fintype simplify the construction of a pmf α from a function f : α → ℝ≥0∞, by allowing the "sum equals 1" constraint to be in terms of finset.sum instead of tsum.

normalize constructs a pmf α by normalizing a function f : α → ℝ≥0∞ by its sum, and filter uses this to filter the support of a pmf and re-normalize the new distribution.

bernoulli represents the bernoulli distribution on bool

noncomputable def pmf.map {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) :
pmf β

The functorial action of a function on a pmf.

Equations
theorem pmf.monad_map_eq_map {α β : Type u_1} (f : α β) (p : pmf α) :
f <\$> p = p
@[simp]
theorem pmf.map_apply {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) (b : β) :
(pmf.map f p) b = ∑' (a : α), ite (b = f a) (p a) 0
@[simp]
theorem pmf.support_map {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) :
theorem pmf.mem_support_map_iff {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) (b : β) :
b (pmf.map f p).support (a : α) (H : a p.support), f a = b
theorem pmf.bind_pure_comp {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) :
p.bind (pmf.pure f) = p
theorem pmf.map_id {α : Type u_1} (p : pmf α) :
= p
theorem pmf.map_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α β) (p : pmf α) (g : β γ) :
(pmf.map f p) = pmf.map (g f) p
theorem pmf.pure_map {α : Type u_1} {β : Type u_2} (f : α β) (a : α) :
(pmf.pure a) = pmf.pure (f a)
theorem pmf.map_bind {α : Type u_1} {β : Type u_2} {γ : Type u_3} (p : pmf α) (q : α pmf β) (f : β γ) :
(p.bind q) = p.bind (λ (a : α), (q a))
@[simp]
theorem pmf.bind_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} (p : pmf α) (f : α β) (q : β pmf γ) :
(pmf.map f p).bind q = p.bind (q f)
@[simp]
theorem pmf.map_const {α : Type u_1} {β : Type u_2} (p : pmf α) (b : β) :
pmf.map b) p =
@[simp]
theorem pmf.to_outer_measure_map_apply {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) (s : set β) :
@[simp]
theorem pmf.to_measure_map_apply {α : Type u_1} {β : Type u_2} (f : α β) (p : pmf α) (s : set β) (hf : measurable f) (hs : measurable_set s) :
noncomputable def pmf.seq {α : Type u_1} {β : Type u_2} (q : pmf β)) (p : pmf α) :
pmf β

The monadic sequencing operation for pmf.

Equations
theorem pmf.monad_seq_eq_seq {α β : Type u_1} (q : pmf β)) (p : pmf α) :
q <*> p = q.seq p
@[simp]
theorem pmf.seq_apply {α : Type u_1} {β : Type u_2} (q : pmf β)) (p : pmf α) (b : β) :
(q.seq p) b = ∑' (f : α β) (a : α), ite (b = f a) (q f * p a) 0
@[simp]
theorem pmf.support_seq {α : Type u_1} {β : Type u_2} (q : pmf β)) (p : pmf α) :
(q.seq p).support = (f : α β) (H : f q.support), f '' p.support
theorem pmf.mem_support_seq_iff {α : Type u_1} {β : Type u_2} (q : pmf β)) (p : pmf α) (b : β) :
b (q.seq p).support (f : α β) (H : f q.support), b f '' p.support
@[protected, instance]
@[protected, instance]
def pmf.of_finset {α : Type u_1} (f : α ennreal) (s : finset α) (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) :
pmf α

Given a finset s and a function f : α → ℝ≥0∞ with sum 1 on s, such that f a = 0 for a ∉ s, we get a pmf

Equations
@[simp]
theorem pmf.of_finset_apply {α : Type u_1} {f : α ennreal} {s : finset α} (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) (a : α) :
s h h') a = f a
@[simp]
theorem pmf.support_of_finset {α : Type u_1} {f : α ennreal} {s : finset α} (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) :
s h h').support =
theorem pmf.mem_support_of_finset_iff {α : Type u_1} {f : α ennreal} {s : finset α} (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) (a : α) :
a s h h').support a s f a 0
theorem pmf.of_finset_apply_of_not_mem {α : Type u_1} {f : α ennreal} {s : finset α} (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) {a : α} (ha : a s) :
s h h') a = 0
@[simp]
theorem pmf.to_outer_measure_of_finset_apply {α : Type u_1} {f : α ennreal} {s : finset α} (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) (t : set α) :
s h h').to_outer_measure) t = ∑' (x : α), t.indicator f x
@[simp]
theorem pmf.to_measure_of_finset_apply {α : Type u_1} {f : α ennreal} {s : finset α} (h : s.sum (λ (a : α), f a) = 1) (h' : (a : α), a s f a = 0) (t : set α) (ht : measurable_set t) :
s h h').to_measure) t = ∑' (x : α), t.indicator f x
def pmf.of_fintype {α : Type u_1} [fintype α] (f : α ennreal) (h : finset.univ.sum (λ (a : α), f a) = 1) :
pmf α

Given a finite type α and a function f : α → ℝ≥0∞ with sum 1, we get a pmf.

Equations
• = _
@[simp]
theorem pmf.of_fintype_apply {α : Type u_1} [fintype α] {f : α ennreal} (h : finset.univ.sum (λ (a : α), f a) = 1) (a : α) :
h) a = f a
@[simp]
theorem pmf.support_of_fintype {α : Type u_1} [fintype α] {f : α ennreal} (h : finset.univ.sum (λ (a : α), f a) = 1) :
theorem pmf.mem_support_of_fintype_iff {α : Type u_1} [fintype α] {f : α ennreal} (h : finset.univ.sum (λ (a : α), f a) = 1) (a : α) :
a h).support f a 0
@[simp]
theorem pmf.to_outer_measure_of_fintype_apply {α : Type u_1} [fintype α] {f : α ennreal} (h : finset.univ.sum (λ (a : α), f a) = 1) (s : set α) :
h).to_outer_measure) s = ∑' (x : α), s.indicator f x
@[simp]
theorem pmf.to_measure_of_fintype_apply {α : Type u_1} [fintype α] {f : α ennreal} (h : finset.univ.sum (λ (a : α), f a) = 1) (s : set α) (hs : measurable_set s) :
h).to_measure) s = ∑' (x : α), s.indicator f x
noncomputable def pmf.normalize {α : Type u_1} (f : α ennreal) (hf0 : tsum f 0) (hf : tsum f ) :
pmf α

Given a f with non-zero and non-infinite sum, get a pmf by normalizing f by its tsum

Equations
@[simp]
theorem pmf.normalize_apply {α : Type u_1} {f : α ennreal} (hf0 : tsum f 0) (hf : tsum f ) (a : α) :
hf0 hf) a = f a * (∑' (x : α), f x)⁻¹
@[simp]
theorem pmf.support_normalize {α : Type u_1} {f : α ennreal} (hf0 : tsum f 0) (hf : tsum f ) :
hf0 hf).support =
theorem pmf.mem_support_normalize_iff {α : Type u_1} {f : α ennreal} (hf0 : tsum f 0) (hf : tsum f ) (a : α) :
a hf0 hf).support f a 0
noncomputable def pmf.filter {α : Type u_1} (p : pmf α) (s : set α) (h : (a : α) (H : a s), a p.support) :
pmf α

Create new pmf by filtering on a set with non-zero measure and normalizing

Equations
@[simp]
theorem pmf.filter_apply {α : Type u_1} {p : pmf α} {s : set α} (h : (a : α) (H : a s), a p.support) (a : α) :
(p.filter s h) a = s.indicator p a * (∑' (a' : α), s.indicator p a')⁻¹
theorem pmf.filter_apply_eq_zero_of_not_mem {α : Type u_1} {p : pmf α} {s : set α} (h : (a : α) (H : a s), a p.support) {a : α} (ha : a s) :
(p.filter s h) a = 0
theorem pmf.mem_support_filter_iff {α : Type u_1} {p : pmf α} {s : set α} (h : (a : α) (H : a s), a p.support) {a : α} :
a (p.filter s h).support a s a p.support
@[simp]
theorem pmf.support_filter {α : Type u_1} {p : pmf α} {s : set α} (h : (a : α) (H : a s), a p.support) :
(p.filter s h).support = s p.support
theorem pmf.filter_apply_eq_zero_iff {α : Type u_1} {p : pmf α} {s : set α} (h : (a : α) (H : a s), a p.support) (a : α) :
(p.filter s h) a = 0 a s a p.support
theorem pmf.filter_apply_ne_zero_iff {α : Type u_1} {p : pmf α} {s : set α} (h : (a : α) (H : a s), a p.support) (a : α) :
(p.filter s h) a 0 a s a p.support
noncomputable def pmf.bernoulli (p : ennreal) (h : p 1) :

A pmf which assigns probability p to tt and 1 - p to ff.

Equations
@[simp]
theorem pmf.bernoulli_apply {p : ennreal} (h : p 1) (b : bool) :
h) b = cond b p (1 - p)
@[simp]
theorem pmf.support_bernoulli {p : ennreal} (h : p 1) :
h).support = {b : bool | cond b (p 0) (p 1)}
theorem pmf.mem_support_bernoulli_iff {p : ennreal} (h : p 1) (b : bool) :
b h).support cond b (p 0) (p 1)