Sampling from an arbitrary sub-distribution #
SPComp.sample samples uniformly from a finite nonempty type. sampleFrom d
samples from an arbitrary SDistr, leaving the heap unchanged, so that
non-uniform distributions — centered binomial, rejection-sampling output,
biased coins, discrete Gaussians — are expressible as SPComp programs.
Main definitions #
sampleFrom d— sample fromd : SDistr α, heap unchangedofPMF p— the total distributionp : PMF αviewed as anSDistr α
Main results #
sampleFrom_uniform—sampleFrom (SDistr.uniform α) = SPComp.sample α, so uniform sampling is a definitional special casesampleFrom_eq_liftSDistr—sampleFromand the existingliftSDistragreesampleFrom_bind_apply—(sampleFrom d >>= k) h = d.bind fun a => k a hmass_sampleFrom,isLossless_sampleFrom_iff— mass of the computation is the mass of the distributionbind_const_of_mass_one,dead_sampleFrom— a lossless sample whose result is discarded is a no-op
The combinator #
Sample from an arbitrary sub-distribution, leaving the heap unchanged.
The computation fails with probability d none.
Equations
- CatCrypt.NonUniform.sampleFrom d h = d.bind fun (a : α) => CatCrypt.Prob.SDistr.pure (a, h)
Instances For
Uniform sampling is the sampleFrom at the uniform distribution.
sampleFrom agrees with the SDistr → SPComp lift already in Core.Code.
Monadic laws #
Bind interaction: the sampled value is fed to the continuation at the
unchanged heap, so the whole computation is a bind at the SDistr level.
Operator form of sampleFrom_bind_apply.
Sampling from a point mass is returning.
Sampling from the everywhere-failing distribution is failure.
Two successive samples are one sample from the bound distribution.
sampleFrom d does not read or write the heap.
Mass and losslessness #
The failure probability of sampleFrom d is the failure probability of d.
The mass of sampleFrom d is the mass of d.
sampleFrom d is lossless exactly when d is a total distribution.
A total distribution gives a lossless computation.
Discarding a lossless sample #
Binding a total distribution to a constant continuation is that constant.
Generalizes SDistr.uniform_bind_const from uniform to arbitrary mass-one
distributions.
A lossless sample whose result is unused can be dropped.
Generalizes dead_sample from uniform to arbitrary mass-one distributions.
sampleFrom (ofPMF p) is lossless.