pRHL sampling rules for arbitrary distributions #
The Prob/Coupling.lean notion liftR R d₁ d₂ — a joint sub-distribution with
marginals d₁, d₂ whose support lies in R — is already stated for arbitrary
SDistr. The rules here consume such a coupling directly, so a pRHL sampling
step is available for any pair of distributions, not just uniform ones.
Main results #
rHoare_coupling_step— the general two-sided sampling rule: a coupling ofd₁andd₂plus the pointwise premise on the continuations givesrHoare Φ (sampleFrom d₁ >>= k₁) (sampleFrom d₂ >>= k₂) ΨrHoare_coupling— bare form, no continuationsrHoare_bij_step_of_coupling,rHoare_same_step_of_coupling,rHoare_sample_vs_sample_coupling_of_coupling— the uniform rules ofRelational/Rules.leanandRelational/Sync.leanre-derived as instances, each with the statement of the existing rule verbatimrHoare_sampleFrom_l,rHoare_sampleFrom_r— one-sided rules, requiring the discarded distribution to be totaleq_of_rHoare_eqPost— a full-equality judgment identifies the output sub-distributions
Pushforward couplings #
Prob/Coupling.lean provides liftR_uniform_bij, which couples two uniform
distributions along a bijection. Bijectivity is used there only to identify the
pushforward of SDistr.uniform α with SDistr.uniform β; the coupling itself
exists for an arbitrary function and an arbitrary distribution.
Graph coupling: an arbitrary function f couples d with its pushforward
along f, the joint distribution being supported on the graph of f.
Equations
- CatCrypt.NonUniform.Coupling.graph d f = { joint := d.bind fun (a : α) => CatCrypt.Prob.SDistr.pure (a, f a), left_marginal := ⋯, right_marginal := ⋯ }
Instances For
The graph coupling lifts the graph relation of f.
If the pushforward of d along f is e, then f's graph relation lifts
to d and e.
Prob.liftR_uniform_bij derived from liftR_pushforward: a bijection's only
role is to make the pushforward of uniform uniform again.
The general two-sided rule #
Sampling rule for two arbitrary distributions related by a coupling.
Given a coupling of d₁ and d₂ supported in R, and continuations that are
related whenever their arguments are R-related, the two sampling programs are
related. Specialising d₁ = d₂ = SDistr.uniform and R to the graph of a
bijection recovers rHoare_bij_step; see rHoare_bij_step_of_coupling.
Bare form of rHoare_coupling_step: the coupling relation appears in the
postcondition alongside the preserved precondition.
Same distribution on both sides, diagonal coupling.
The uniform rules as instances #
Each rule below restates a uniform rule already in the library and proves it from
rHoare_coupling_step. The example after each one equates the two constants,
so the kernel checks that the restatement is the same proposition.
Relational.rHoare_bij_step derived from rHoare_coupling_step.
SPComp.sample α is sampleFrom (SDistr.uniform α) by definition, and
liftR_uniform_bij supplies the coupling.
Relational.rHoare_same_step derived from rHoare_coupling_step.
Relational.r_sample_vs_sample_coupling derived from rHoare_coupling.
That rule takes a coupling of two uniform distributions; here the
uniformity is only used to name the programs.
One-sided rules #
A one-sided rule averages the other side over the sampled distribution, so the
sampled distribution must be total: if SDistr.mass d < 1 the left program has
strictly smaller mass than the right and no coupling exists.
One-sided sample on the left, for a total distribution.
One-sided sample on the right, for a total distribution.
From a full-equality judgment to distribution equality #
A judgment with eqPre/eqPost says the two programs have the same output
sub-distribution from every heap: an equality coupling forces all mass onto
the diagonal, and the two marginals then agree.