PMF constructors and ℝ-coercion utilities beyond mathlib's basic surface #
Two layers:
ℝ-coercion utilities — toRealFn, sum_toRealFn_eq_one, and
nonneg/≤1 lemmas. The standard way to access a PMF α's masses as
ℝ-valued (via ENNReal.toReal) without losing the 0 ≤ · ≤ 1 /
sum-to-1 invariants.
ℝ-valued constructor — PMF.ofRealWeightFn, the canonical entry
point for "I have non-negative ℝ weights and want a PMF":
| Constructor | Input | Specialises |
|---|---|---|
PMF.ofRealWeightFn | (α → ℝ) non-negative + element-witness positivity (Fintype) | lifts via ENNReal.ofReal and routes through mathlib's PMF.normalize |
The constructor takes a specific positive witness (a : α) (h : 0 < f a)
rather than the existential form (∃ a, 0 < f a). This avoids
Classical.choose in the body and matches the shape of mathlib's own
PMF.normalize hypotheses (tsum f ≠ 0, which is tsum_ne_zero_iff-
equivalent to a single witness via ENNReal.summable.tsum_ne_zero_iff).
For consumers holding 0 < ∑ a, f a instead, derive a witness via
Finset.sum_pos.
[UPSTREAM] candidate: ofRealWeightFn fits cleanly into
Mathlib/Probability/ProbabilityMassFunction/Constructions.lean as the
standard "non-negative real weights" entry point, paralleling ofFintype
(already-normalised ℝ≥0∞) and normalize (general ℝ≥0∞).
Note on PMF.normalize for Fintype ℝ≥0∞-valued weights: there is
no wrapper — call PMF.normalize f hf0 hf directly. The hypothesis
boilerplate at Fintype call sites is:
PMF.normalize f
(ENNReal.summable.tsum_ne_zero_iff.mpr ⟨a, h_pos⟩)
(ENNReal.tsum_ne_top_of_fintype h_finite)
A normalizeOfFintype wrapper around this pattern was tried and removed
(0.231.X) — it bundled marginal value at the cost of an extra layer.
On a finite type, an ENNReal tsum is finite iff every term is.
Convenience composition of tsum_fintype + ENNReal.sum_ne_top — the
combined form is the natural hypothesis shape for PMF.normalize /
PMF.posterior consumers.
Mass of the uniform distribution, in ℝ.
For a [Fintype α] PMF, the toReal-coerced masses sum to 1.
Convex mixture #
Convex combination of two PMFs at rate r: draw a Bernoulli-r coin,
then sample q on heads and p on tails. Normalization is free from
bind — no Fintype, no sum proof.
Equations
- PMF.mix r hr p q = (PMF.bernoulli r hr).bind fun (b : Bool) => bif b then q else p
Instances For
Normalize non-negative ℝ weights with positive total into a PMF.
The _h_nonneg hypothesis is unused in the body (ENNReal.ofReal clamps
negatives silently) but is kept so the spec lemmas characterise the
result faithfully.
Equations
- PMF.ofRealWeightFn f _h_nonneg h_pos = PMF.normalize (fun (x : α) => ENNReal.ofReal (f x)) ⋯ ⋯
Instances For
Closed-form value of ofRealWeightFn in ℝ≥0∞.
Closed form in ℝ: each mass is its weight divided by the total.
Support of ofRealWeightFn: the strictly-positive weights.
Already-normalised weights are recovered exactly.
Iterated conditioning #
Iterated conditioning collapses: filtering on s, then on a subevent
s' ⊆ s, is filtering on s' directly. Incremental Bayesian update by
restriction agrees with direct conditioning ([Lev08]'s eqs. (5)–(8)).
[UPSTREAM] candidate for Mathlib/Probability/ProbabilityMassFunction.
Conditional mass of a subevent under filtering: for s' ⊆ s, the filtered
distribution gives s' the mass p(s') / p(s).
A set meeting the support has nonzero measure.
PMF.filter is Measure.cond: conditioning a PMF on an event agrees with
the measure-theoretic conditional measure. [UPSTREAM] candidate — it
connects mathlib's two conditioning notions.