The pRHL rule for the unbounded loop #
rHoare_whileLoop relates whileLoop guard₁ body₁ to whileLoop guard₂ body₂
under the hypotheses of the fixed-budget rule rHoare_whileApprox: a relational
invariant I that makes the two guards agree, and two bodies that preserve I
from any I-related pair of heaps at which the guards hold.
The judgment at a fixed budget only produces a coupling of the two approximants
at that budget, and couplings at different budgets need not be comparable. The
rule at the loop is proved by building one non-decreasing family of couplings
loopJoint and taking its limit: a chosen coupling bodyJoint of the two bodies
is threaded through the recursion on the budget, so the coupling at budget n is
a restriction of the coupling at budget n + 1.
Main definitions #
loopJoint guard₁ bj n h₁ h₂— the joint distribution of the lockstep run of the two loops for at mostniterations, withbjcoupling one execution of the two bodiesbodyJoint hbody h₁ h₂— a coupling of the two bodies chosen from the body judgmentloopJointLim hbody h₁ h₂— the limit ofloopJoint guard₁ (bodyJoint hbody)over the budget
Main results #
loopJoint_mono— the family is non-decreasing in the budgetloopJoint_bind_fst,loopJoint_bind_snd— the two marginals of the family at budgetnare the two approximants at budgetnloopJoint_support— every coupled pair at any budget satisfiesIwith both guards falserHoare_whileLoop— the synchronous invariant rule at the unbounded loop
Support of a bind #
A value of nonzero weight under a bind comes from a value of nonzero weight under the bound distribution.
The joint distribution of a budgeted lockstep run #
The joint distribution of the lockstep run of two loops at budget n: while
the left guard holds, bj couples one execution of the two bodies and the
remaining budget is spent from the two resulting heaps.
Equations
- One or more equations did not get rendered due to their size.
- CatCrypt.NonUniform.loopJoint guard₁ bj 0 x✝¹ x✝ = CatCrypt.Prob.SDistr.fail
Instances For
The family is non-decreasing in the budget #
Raising the budget by one does not decrease the weight of a coupled pair.
A chosen coupling of the two bodies #
The body judgment supplies, at every pair of heaps, a distribution that is a coupling of the two bodies supported in the invariant whenever the invariant holds and both guards are true.
A coupling of the two bodies chosen from the body judgment.
Equations
- CatCrypt.NonUniform.bodyJoint hbody h₁ h₂ = ⋯.choose
Instances For
At a pair of heaps satisfying the invariant with both guards true, the chosen distribution has the two bodies as marginals and is supported in the invariant.
The marginals of the family #
The left marginal of the coupling at budget n is the left approximant at
budget n.
The right marginal of the coupling at budget n is the right approximant at
budget n.
The support of the family #
Every pair coupled at any budget satisfies the invariant with both guards false.
The limit of the family #
The limit over the budget of the couplings of the two loops.
Equations
- CatCrypt.NonUniform.loopJointLim hbody h₁ h₂ = CatCrypt.NonUniform.mlim (fun (n : ℕ) => CatCrypt.NonUniform.loopJoint guard₁ (CatCrypt.NonUniform.bodyJoint hbody) n h₁ h₂) ⋯
Instances For
A pair coupled in the limit is coupled at some budget.
The left marginal of the limit is the left loop.
The right marginal of the limit is the right loop.
The rule #
The synchronous invariant rule for the unbounded loop.
If the relational invariant I forces the two guards to agree, and the two
bodies preserve I from any I-related pair of heaps at which the guards hold,
then the two loops are related by I together with both guards being false.
The rule with one guard and one body on both sides.