Quantitative Relational Program Logic (eRHL) #
This file develops the main theorem layer for the eRHL-style quantitative relational
logic for OracleComp, building on the core interfaces in
VCVio.ProgramLogic.Relational.QuantitativeDefs.
The core idea (from Avanzini-Barthe-Gregoire-Davoli, POPL 2025) is to make pre/postconditions
ℝ≥0∞-valued instead of Prop-valued. This subsumes both pRHL (exact coupling, via indicator
postconditions) and apRHL (ε-approximate coupling, via threshold preconditions).
Main results in this file #
- coupling-mass lemmas and support facts
- introduction, consequence, and bind rules for eRHL
- bridges to exact and approximate couplings
- total-variation characterizations via
EqRel
Design #
eRHL (ℝ≥0∞-valued pre/post)
/ | \
/ | \
pRHL (exact) apRHL (ε-approx) stat-distance
indicator R 1-ε, indicator R 1, indicator(=)
Helpers for coupling mass #
Conditional distribution of a PMF along a deterministic observation map.
For an observation value outside the support of f <$> p, the choice of
distribution is irrelevant; we use an arbitrary support point of p.
Instances For
Conditional output kernel induced by a deterministic observation map.
When the observation value is not in the support of f <$> p, the fallback
is used. Since the observation has zero mass there, this does not affect the
rebuilt distribution, but it makes pointwise continuation equalities easier
to state.
Instances For
Lift a coupling of a deterministic observation of the left computation into a coupling of the full left computation with the right one.
Instances For
Bridge: the eRHL-based definition agrees with the existing coupling-based one.
Forward direction blocker: RelTriple' → CouplingPost requires extracting a coupling c
with f(c) = 1 from 1 ≤ ⨆ c, f(c). Although the coupling polytope is compact and f is
linear (so the max IS attained in standard math), formalizing this in Lean requires proving
compactness of the coupling space, which needs topology infrastructure not yet available here.
Bridge: RelTriple' agrees with the existing RelTriple.
If a RelTriple' holds for fun a b => f a = g b, then mapping by f and g
produces equal distributions. This is the eRHL-level version of
evalDist_map_eq_of_relTriple.
Quantitative relational WP rules #
Pure rule for quantitative relational WP.
Monotonicity/consequence rule for quantitative relational WP.
Bind/sequential composition rule for quantitative relational WP.
Indicator-postcondition rules (RelTriple') #
These are direct quantitative analogues of the pRHL effect-rule block in
VCVio.ProgramLogic.Relational.Basic, expressed as quantitative eRelWP lower bounds
via the relTriple'_iff_relTriple bridge. They give the eRHL-flavoured statement of
every coupling primitive OracleComp already exposes, so downstream proofs can mix exact
indicator rules with the genuinely quantitative bounds below without having to re-derive the
bridge each time.
Each rule is a one-line wrapper of its RelTriple cousin. The proofs that the underlying
couplings exist live in Basic.lean; this section only repackages them at the RelTriple'
level.
RelTriple' introduction from a pure-pure pair satisfying the post.
Reflexivity rule for RelTriple' on the diagonal equality relation.
Postcondition monotonicity for RelTriple'.
Sequential composition rule for RelTriple'.
Equality of programs lifts to a RelTriple' on EqRel.
Equality of evaluation distributions lifts to a RelTriple' on EqRel.
Pointwise output-probability equality lifts to a RelTriple' on EqRel.
Oracle-query coupling rules (eRHL level) #
Same-type identity coupling for queries: RelTriple' analogue of relTriple_query.
Bijection coupling for queries (the eRHL "rnd" rule).
Functorial / structural rules #
Functor.map rule for RelTriple'.
Synchronized conditional rule for RelTriple'.
Pure-left rule: lift the strengthened post (· = a) ∧ R back to R.
Pure-right rule: lift the strengthened post (· = b) ∧ R back to R.
Iteration / list-traversal rules #
RelTriple' for OracleComp.replicate.
Equality-relation specialization of relTriple'_replicate.
RelTriple' for List.mapM.
Same-input specialization of relTriple'_list_mapM.
RelTriple' for List.foldlM.
Same-input specialization of relTriple'_list_foldlM.
Bijection coupling for uniform sampling at the RelTriple' level.
Identity coupling for uniform sampling at the RelTriple' level.
Helpers for statistical distance / coupling characterization #
Statistical distance via eRHL #
Statistical distance as a complement of eRHL value with equality indicator.
Uses SPMF.tvDist directly to handle cross-spec comparison.
A TV-distance bound induces an approximate equality coupling.
Game equivalence from pRHL equality coupling.
Relational algebra instance #
Pure values characterize the quantitative relational weakest precondition.
Quantitative relational weakest precondition is monotone in the postcondition.
Quantitative relational weakest preconditions compose through bind.
Quantitative relational algebra instance for OracleComp, based on eRelWP.
Anchoring instance for the quantitative ℝ≥0∞-valued relational logic on OracleComp.
When one of the two computations is pure, the supremum over couplings collapses to the
single Dirac coupling (existence: IsCoupling.dirac_left; uniqueness on the supports follows
from IsCoupling.apply_pure_left_eq), and the relational expectation reduces to the unary
expectation wp y (post a) (resp. wp x (fun a => post a b)). This is the genuinely
quantitative analogue of the qualitative Anchored Prop instance in
VCVio/ProgramLogic/Relational/Basic.lean.
Specialisations of the generic asynchronous and structural rules #
The following examples confirm that the new generic rules in
ToMathlib/Control/Monad/RelationalAlgebra.lean (asynchronous one-sided
binds and structural pure rules) automatically apply to eRelWP. They are
the quantitative counterparts of SSProve's apply_left / apply_right /
if_rule style rules.
Quantitative effect-specific rules (eRHL primitives) #
These are the genuinely quantitative companions of the indicator wrappers above: they
expose witness-based lower bounds for eRelWP on the basic OracleComp effect operations
(uniform sampling and oracle queries under a bijection). Together with the existing closed
form eRelWP_pure and the core eRelWP_pure_le / _conseq / _bind_rule, they are sufficient to
discharge most apRHL-style goals without descending to the underlying coupling supremum.
A witness coupling provides a lower bound on the eRHL weakest precondition.
This is the basic primitive used by every closed-form / lower-bound rule below, and is the right tool whenever a proof can exhibit a specific coupling.
A witness coupling whose score dominates the precondition discharges a quantitative relational WP lower-bound obligation.
Uniform sampling under a bijection #
Quantitative lower bound for two uniform samples coupled by a bijection.
The bijection coupling (fun x => (x, f x)) <$> $ᵗ α realises the sum on the left as a
score, providing the sharpest "syntactic" lower bound on the coupling supremum.
Any precondition below the bijection average discharges the quantitative relational WP lower-bound for two uniform samples.
Oracle queries under a bijection #
Quantitative lower bound for two oracle queries coupled by a bijection on the range.
This is the eRHL counterpart of relTriple_query_bij.
Triple form of eRelWP_query_bij_ge.
Demonstration examples for the indicator wrappers and quantitative primitives #
Small examples illustrating how the RelTriple' wrappers and the closed-form / lower-bound
eRelWP rules combine in practice.