pRHL core: a relational wp calculus for ProgramDenotation #
ProgramDenotation.rel p q Pre Post is the asymmetric relational lifting: for every
pair of postconditions compatible with Post, the wp of p from a
Pre-related pair of states is below the wp of q. ProgramDenotation.relE is the
symmetric (equality) variant, used for bridging game hops; rel itself is
the primitive, used for reductions and up-to-bad inequalities.
Design notes:
- The judgment is defined by its elimination form, so the probability
bridges (
rel.wp_le,relE.wp_eq) are definitional and every proof rule is a small consequence of the existing unarywplemma base — no witness couplings, hence no measurability, countability, or a.e.-support side conditions. For discrete subprobabilities this lifting is coextensive with the coupling-based one (Strassen) in the direction proofs consume. - Heterogeneous state and result types are supported (
ProgramDenotation s₁ αvsProgramDenotation s₂ β): the calculus can relate a concrete game to an abstract schema, or a program to its lens-factored inner core. - Unsound-rule warning: conjunction of postconditions is NOT admissible.
From
rel p q Pre Post₁andrel p q Pre Post₂one may NOT concluderel p q Pre (fun x y => Post₁ x y ∧ Post₂ x y). (Standard counterexample: forp = q =a uniform coin, both postx₁ = x₂and postx₁ ≠ x₂hold relationally — with different implicit couplings — but their conjunction is empty.) Do not add such a rule.
Relational wp judgment (asymmetric form). p.rel q Pre Post holds iff
for all post-pairs F ≤ G along Post and all Pre-related starting
states, p.wp F ≤ q.wp G.
Equations
Instances For
Relational wp equivalence: rel in both directions (with flipped
relations). The two-sided judgment used for bridging game hops.
Equations
Instances For
Elimination (Pr-bridges) #
Elimination form (definitional): a rel judgment yields a wp inequality
at any compatible post-pair.
Structural rules #
Consequence: weaken the precondition, strengthen the postcondition.
Reflexivity at the diagonal.
Transitivity through a middle program, with composed pre/post relations.
No PER or losslessness side conditions: the middle postcondition is
interpolated by fun y => ⨆ x, ⨆ (_ : Post₁ x y), F x (possible because
posts are ENNReal-valued and need no measurability).
Eliminate an existential in the precondition.
Case split on the precondition.
Sequence rule (the workhorse): relate the prefixes at a middle
relation Mid, then the continuations from every Mid-related pair.
Prepend a left-only prefix (e.g. a ghost write): if p₀ ~ skip carries
Pre to Mid, and k ~ q from Mid, then (p₀; k) ~ q from Pre.
Avoids inserting pure () >>= on the right by hand.
Prepend a right-only prefix: mirror image of prefix_left.
Synchronized conditional with statically equivalent guards. (For
state-dependent guards, the guards become values bound by bind, so they
are static by the time this rule applies; for genuinely one-sided
conditionals use by_cases at the meta level.)
Assignment rules (ProgramDenotation.set / ProgramDenotation.get) #
Sampling rules #
Coupled sampling along a bijection (the rnd rule): two uniform
samples are related by pairing v with e v.
Left-only sampling: an average is below any uniform upper bound. No mass side condition.
Right-only sampling (sample introduction): a uniform average of lower
bounds is a lower bound. Mass-1 of uniform is what makes this sound.
relE: elimination and mechanical two-sided variants #
Elimination form: a relE judgment yields wp equality at any post-pair
that agrees along Post.
Reflexivity.
ProgramDenotation equality gives the diagonal relE.
Symmetry (with flipped relations).
Transitivity for relE (composed pre/post relations).
Eliminate an existential in the precondition.
Case split on the precondition, for relE.
Consequence for relE.
Sequence rule for relE.
Coupled sampling along a bijection, for relE.
Synchronized conditional for relE.