The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V20. Probability

Mathlib.Probability.ProbabilityMassFunction.Constructions

52 declarations and 4 deprecated aliases. Mathlib docs · Source

Specific Constructions of Probability Mass Functions

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 β.

ofFinset and ofFintype 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.

bernoulliMeasure represents the Bernoulli distribution on Bool.

theorem PMF.bernoulli.congr_simp E1 #

∀ (p p_1 : NNReal) (e_p : p = p_1) (h : p ≤ 1), PMF.bernoulli p h = PMF.bernoulli p_1 ⋯

theorem PMF.normalize.congr_simp E1 #

∀ {α : Type u_1} (f f_1 : α → ENNReal) (e_f : f = f_1) (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ⊤),
  PMF.normalize f hf0 hf = PMF.normalize f_1 ⋯ ⋯

theorem PMF.ofFinset.congr_simp E1 #

∀ {α : Type u_1} (f f_1 : α → ENNReal) (e_f : f = f_1) (s s_1 : Finset α) (e_s : s = s_1) (h : ∑ a ∈ s, f a = 1)
  (h' : ∀ a ∉ s, f a = 0), PMF.ofFinset f s h h' = PMF.ofFinset f_1 s_1 ⋯ ⋯

theorem PMF.ofFintype.congr_simp E1 #

∀ {α : Type u_1} [inst : Fintype α] (f f_1 : α → ENNReal) (e_f : f = f_1) (h : ∑ a, f a = 1),
  PMF.ofFintype f h = PMF.ofFintype f_1 ⋯

def PMF.map E1 #

{α : Type u_1} → {β : Type u_2} → (α → β) → PMF α → PMF β

The functorial action of a function on a PMF.

theorem PMF.monad_map_eq_map E1 #

∀ {α β : Type u} (f : α → β) (p : PMF α), f <$> p = PMF.map f p

theorem PMF.map_apply E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (p : PMF α) (b : β),
  (PMF.map f p) b = ∑' (a : α), if b = f a then p a else 0

theorem PMF.support_map E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (p : PMF α), (PMF.map f p).support = f '' p.support

theorem PMF.mem_support_map_iff E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (p : PMF α) (b : β), b ∈ (PMF.map f p).support ↔ ∃ a ∈ p.support, f a = b

theorem PMF.bind_pure_comp E1 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (p : PMF α), p.bind (PMF.pure ∘ f) = PMF.map f p

theorem PMF.map_id E0 #

∀ {α : Type u_1} (p : PMF α), PMF.map id p = p

theorem PMF.map_comp E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : α → β) (p : PMF α) (g : β → γ),
  PMF.map g (PMF.map f p) = PMF.map (g ∘ f) p

theorem PMF.pure_map E1 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (a : α), PMF.map f (PMF.pure a) = PMF.pure (f a)

theorem PMF.map_bind E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (p : PMF α) (q : α → PMF β) (f : β → γ),
  PMF.map f (p.bind q) = p.bind fun a ↦ PMF.map f (q a)

theorem PMF.bind_map E0 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} (p : PMF α) (f : α → β) (q : β → PMF γ),
  (PMF.map f p).bind q = p.bind (q ∘ f)

theorem PMF.map_const E0 #

∀ {α : Type u_1} {β : Type u_2} (p : PMF α) (b : β), PMF.map (Function.const α b) p = PMF.pure b

theorem PMF.toOuterMeasure_map_apply E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (p : PMF α) (s : Set β),
  (PMF.map f p).toOuterMeasure s = p.toOuterMeasure (f ⁻¹' s)

theorem PMF.toMeasure_map_apply E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) (p : PMF α) (s : Set β) {mα : MeasurableSpace α} {mβ : MeasurableSpace β},
  Measurable f → MeasurableSet s → (PMF.map f p).toMeasure s = p.toMeasure (f ⁻¹' s)

theorem PMF.toMeasure_map E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α → β) {mα : MeasurableSpace α} {mβ : MeasurableSpace β} (p : PMF α),
  Measurable f → MeasureTheory.Measure.map f p.toMeasure = (PMF.map f p).toMeasure

def PMF.seq E1 #

{α : Type u_1} → {β : Type u_2} → PMF (α → β) → PMF α → PMF β

The monadic sequencing operation for PMF.

theorem PMF.monad_seq_eq_seq E1 #

∀ {α β : Type u} (q : PMF (α → β)) (p : PMF α), q <*> p = q.seq p

theorem PMF.seq_apply E0 #

∀ {α : Type u_1} {β : Type u_2} (q : PMF (α → β)) (p : PMF α) (b : β),
  (q.seq p) b = ∑' (f : α → β) (a : α), if b = f a then q f * p a else 0

theorem PMF.support_seq E0 #

∀ {α : Type u_1} {β : Type u_2} (q : PMF (α → β)) (p : PMF α), (q.seq p).support = ⋃ f ∈ q.support, f '' p.support

theorem PMF.mem_support_seq_iff E0 #

∀ {α : Type u_1} {β : Type u_2} (q : PMF (α → β)) (p : PMF α) (b : β),
  b ∈ (q.seq p).support ↔ ∃ f ∈ q.support, b ∈ f '' p.support

instance PMF.instLawfulFunctor E0 #

LawfulFunctor PMF

instance PMF.instLawfulMonad E0 #

LawfulMonad PMF

instance PMF.instULiftable E0 #

ULiftable PMF PMF

This instance allows do notation for PMF to be used across universes, for instance as

example {R : Type u} [Ring R] (x : PMF ℕ) : PMF R := do
  let ⟨n⟩ ← ULiftable.up x
  pure n

where x is in universe 0, but the return value is in universe u.

def PMF.ofFinset E1 #

{α : Type u_1} → (f : α → ENNReal) → (s : Finset α) → ∑ a ∈ s, f a = 1 → (∀ 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.

theorem PMF.ofFinset_apply E0 #

∀ {α : Type u_1} {f : α → ENNReal} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ a ∉ s, f a = 0) (a : α),
  (PMF.ofFinset f s h h') a = f a

theorem PMF.support_ofFinset E0 #

∀ {α : Type u_1} {f : α → ENNReal} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ a ∉ s, f a = 0),
  (PMF.ofFinset f s h h').support = ↑s ∩ Function.support f

theorem PMF.mem_support_ofFinset_iff E0 #

∀ {α : Type u_1} {f : α → ENNReal} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ a ∉ s, f a = 0) (a : α),
  a ∈ (PMF.ofFinset f s h h').support ↔ a ∈ s ∧ f a ≠ 0

theorem PMF.ofFinset_apply_of_notMem E1 #

∀ {α : Type u_1} {f : α → ENNReal} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ a ∉ s, f a = 0) {a : α},
  a ∉ s → (PMF.ofFinset f s h h') a = 0

theorem PMF.toOuterMeasure_ofFinset_apply E0 #

∀ {α : Type u_1} {f : α → ENNReal} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ a ∉ s, f a = 0) (t : Set α),
  (PMF.ofFinset f s h h').toOuterMeasure t = ∑' (x : α), t.indicator f x

theorem PMF.toMeasure_ofFinset_apply E0 #

∀ {α : Type u_1} {f : α → ENNReal} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ a ∉ s, f a = 0) (t : Set α)
  [inst : MeasurableSpace α], MeasurableSet t → (PMF.ofFinset f s h h').toMeasure t = ∑' (x : α), t.indicator f x

def PMF.ofFintype E1 #

{α : Type u_1} → [inst : Fintype α] → (f : α → ENNReal) → ∑ a, f a = 1 → PMF α

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

theorem PMF.ofFintype_apply E0 #

∀ {α : Type u_1} [inst : Fintype α] {f : α → ENNReal} (h : ∑ a, f a = 1) (a : α), (PMF.ofFintype f h) a = f a

theorem PMF.support_ofFintype E0 #

∀ {α : Type u_1} [inst : Fintype α] {f : α → ENNReal} (h : ∑ a, f a = 1),
  (PMF.ofFintype f h).support = Function.support f

theorem PMF.mem_support_ofFintype_iff E0 #

∀ {α : Type u_1} [inst : Fintype α] {f : α → ENNReal} (h : ∑ a, f a = 1) (a : α),
  a ∈ (PMF.ofFintype f h).support ↔ f a ≠ 0

theorem PMF.map_ofFintype E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (f : α → ENNReal) (h : ∑ a, f a = 1)
  (g : α → β), PMF.map g (PMF.ofFintype f h) = PMF.ofFintype (fun b ↦ ∑ a with g a = b, f a) ⋯

theorem PMF.toOuterMeasure_ofFintype_apply E0 #

∀ {α : Type u_1} [inst : Fintype α] {f : α → ENNReal} (h : ∑ a, f a = 1) (s : Set α),
  (PMF.ofFintype f h).toOuterMeasure s = ∑' (x : α), s.indicator f x

theorem PMF.toMeasure_ofFintype_apply E0 #

∀ {α : Type u_1} [inst : Fintype α] {f : α → ENNReal} (h : ∑ a, f a = 1) (s : Set α) [inst_1 : MeasurableSpace α],
  MeasurableSet s → (PMF.ofFintype f h).toMeasure s = ∑' (x : α), s.indicator f x

def PMF.normalize E1 #

{α : Type u_1} → (f : α → ENNReal) → tsum f ≠ 0 → tsum f ≠ ⊤ → PMF α

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

theorem PMF.normalize_apply E0 #

∀ {α : Type u_1} {f : α → ENNReal} (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ⊤) (a : α),
  (PMF.normalize f hf0 hf) a = f a * (∑' (x : α), f x)⁻¹

theorem PMF.support_normalize E0 #

∀ {α : Type u_1} {f : α → ENNReal} (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ⊤),
  (PMF.normalize f hf0 hf).support = Function.support f

theorem PMF.mem_support_normalize_iff E0 #

∀ {α : Type u_1} {f : α → ENNReal} (hf0 : tsum f ≠ 0) (hf : tsum f ≠ ⊤) (a : α),
  a ∈ (PMF.normalize f hf0 hf).support ↔ f a ≠ 0

def PMF.filter E1 #

{α : Type u_1} → (p : PMF α) → (s : Set α) → (∃ a ∈ s, a ∈ p.support) → PMF α

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

theorem PMF.filter_apply E0 #

∀ {α : Type u_1} {p : PMF α} {s : Set α} (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_notMem E1 #

∀ {α : Type u_1} {p : PMF α} {s : Set α} (h : ∃ a ∈ s, a ∈ p.support) {a : α}, a ∉ s → (p.filter s h) a = 0

theorem PMF.mem_support_filter_iff E0 #

∀ {α : Type u_1} {p : PMF α} {s : Set α} (h : ∃ a ∈ s, a ∈ p.support) {a : α},
  a ∈ (p.filter s h).support ↔ a ∈ s ∧ a ∈ p.support

theorem PMF.support_filter E0 #

∀ {α : Type u_1} {p : PMF α} {s : Set α} (h : ∃ a ∈ s, a ∈ p.support), (p.filter s h).support = s ∩ p.support

theorem PMF.filter_apply_eq_zero_iff E0 #

∀ {α : Type u_1} {p : PMF α} {s : Set α} (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 E0 #

∀ {α : Type u_1} {p : PMF α} {s : Set α} (h : ∃ a ∈ s, a ∈ p.support) (a : α),
  (p.filter s h) a ≠ 0 ↔ a ∈ s ∧ a ∈ p.support

Deprecated aliases

NameNew nameSince
PMF.bernoulliProbabilityTheory.bernoulliMeasure2026-05-31
PMF.bernoulli_applyProbabilityTheory.bernoulliMeasure_apply2026-05-31
PMF.mem_support_bernoulli_iffProbabilityTheory.bernoulliMeasure_apply_of_notMem_of_notMem2026-05-31
PMF.support_bernoulliProbabilityTheory.bernoulliMeasure_apply_of_notMem_of_notMem2026-05-31