Probability mass functions with finite support and non-negative rational weights #
This is a special case of PMF that suffices for denotational semantics of OracleComp with finite
oracle specifications.
Design #
We use a two-layer approach:
FinRatPMF.Raw αis an array-based representation storing pairs(a, p)of outcomes and probabilities. It has a computableMonadandLawfulMonadinstance but non-canonical equality: two values representing the same distribution may differ in array order or duplicate entries.FinRatPMF αis the quotient ofFinRatPMF.Raw αby distributional equality (SameDist). It has canonical equality (two values are equal iff they define the same distribution) and aLawfulMonadinstance (necessarilynoncomputablesincebindmust extract from the quotient).
For computation, use FinRatPMF.Raw. For reasoning about distributional equality, use FinRatPMF.
Both connect to Mathlib's PMF via toPMF.
Raw representation #
Raw probability mass function with finite support and non-negative rational weights.
Stores an array of (outcome, weight) pairs whose weights sum to 1. This representation is
computable but not canonical: many different FinRatPMF.Raw values can represent the same
probability distribution.
Instances For
Instances For
Instances For
Bind sum auxiliary lemma #
Monad operations #
Probability and support #
The probability assigned to x by the raw PMF: sum of weights for all entries with key x.
Instances For
prob is independent of the DecidableEq instance, since decide (a = b) gives the same
Bool for any Decidable instance on the same Prop.
The finite support: the set of outcomes appearing in the array.
Instances For
Point probabilities for uniformList on a duplicate-free list.
Uniform distributions over duplicate-free lists have support exactly the listed elements.
Point probabilities of Raw.uniform.
Raw.uniform has full finite support.
Instances For
Instances For
Merge duplicate outcomes and discard zero-weight entries. This implementation is linear in the
number of raw entries up to hash-map operations, so it avoids the repeated support/prob rescans
that would make normalization quadratic.
Instances For
Convert to a PMF by mapping weights through ℚ≥0 → ℝ≥0 → ℝ≥0∞.
Instances For
Distributional equality and quotient #
Two raw PMFs represent the same distribution if they assign the same probability to every
outcome. Uses classical decidable equality since this is a Prop.
Instances For
Probability mass function with finite support and rational weights, with canonical equality.
Defined as the quotient of FinRatPMF.Raw by distributional equality. Two values are equal iff
they assign the same probability to every outcome.