Non-uniform sampling #
SPComp.sample samples uniformly from a finite nonempty type, which is the only
sampling combinator in Core.Code. This tree adds sampleFrom d for an arbitrary
SDistr d, together with the pRHL and pHL rules for reasoning about it.
Layout #
Sample— the combinator, its monadic laws, its mass/losslessness characterisation, andofPMFfor total distributionsConditional— restriction, rescaling, conditioning andexcepted, with the weight, support and point-mass results for eachProduct— the independent product of two sub-distributions and of aFin n-indexed family, withmass_bind_of_mass_oneand the marginalsCouplingRules— pushforward couplings and the general pRHL sampling rule, with the uniform rules re-derived as instancesUnaryRules— event and success probability of a program that starts with a general sampleBernoulli— biased coins, the negation coupling, and its pRHL stepCenteredBinomial— the ML-KEM noise distribution overℤ, its symmetry under negation, and the resulting sign-independence of a noise termLimit— the limit of a sequence of sub-distributions that is non-decreasing on values, and the two laws commuting that limit withbindon either sideWhileApprox—whileApprox guard body n, which runsbodyat mostntimes whileguardholds and fails when the budget runs outWhileApproxMono— the approximants are non-decreasing on values and non-increasing on failure as the budget grows, and their value mass stays summable to at most oneWhileUnary— the pHL invariant rule at each budget, and the probability-one form under a losslessness hypothesisWhileRelational— the pRHL synchronous invariant rule at each budget, over two loops whose guards the invariant keeps equalWhile—whileLoop guard bodyas the limit of the approximants, and the pHL rule for itWhileRelationalLimit— the pRHL rule at the loop, over a non-decreasing family of couplings built by recursion on the budget
The pHL rule transports from the approximants to the limit because pHoare
constrains the support, and an outcome of the limit is an outcome of some
approximant. rHoare asserts that a coupling exists, so it does not transport
that way: couplings obtained for each budget separately need not be comparable,
and only a non-decreasing family has a limit that couples the two loops. The
family is therefore constructed rather than obtained, by recursion on the budget
from one chosen coupling of the two bodies.
sampleFrom (SDistr.uniform α) = SPComp.sample α holds by rfl, and the
derived-instance examples in CouplingRules and UnaryRules state the uniform
rules verbatim, so the uniform API is untouched.
The one-sided rules rHoare_sampleFrom_l/r carry a SDistr.mass d = 1 hypothesis
that the uniform versions rHoare_sample_l/r do not need, because
SDistr.mass (SDistr.uniform α) = 1 is automatic. The uniform rules are therefore
corollaries, not instances of a strictly weaker statement.