pRHL, version 2 — synchronized while with an exit #
ProgramDenotation.prhl2.while_loop (PRHL2.lean) couples two loops whose guards agree at
every iteration. This module proves ProgramDenotation.prhl2.while_upto, the variant needed
for an EasyCrypt-style up-to-bad call rule: at the start of any iteration where the Exit
predicate holds (together with the invariant), the guard/body couplings are abandoned and the
two remaining whole loops are coupled by a separately supplied coupling h_exit (after the
bad event, the runs are typically coupled as a product, and their guards need no longer agree).
Proof outline #
The witness is again the least fixed point of a coupling transformer Φ, which at a state
pair runs the exit coupling if Exit holds and otherwise the guard coupling followed (while it
fires) by the body coupling and a recursive call. The support follows by induction on the
Kleene iterates. The marginals are no longer the loop's Kleene iterates (in the exit branch the
marginal is the whole remaining loop), so instead each iterate's marginal is sandwiched, in
expectation, between the loop's n-th Kleene iterate and the loop itself
(while_iterate_le_while_loop, while_loop_eq_iteration); the suprema then agree.
Monotonicity of expected on the support: an integrand that is pointwise smaller on the
support integrates to a smaller value.
The while loop is a fixed point of its iteration functional, at every state.
One step of the while_iteration functional, in expectation.
Every Kleene iterate of the loop is below the loop, in expectation.
Synchronized while rule with an exit. As ProgramDenotation.prhl2.while_loop: under
the invariant (and while Exit fails) the guards are coupled to agree, refining the
invariant to PostC, and the bodies preserve the invariant from PostC true. In addition,
at the start of any iteration where Exit holds, the two remaining whole loops are related
by the coupling h_exit with post PostE. The loops then relate either at PostC false
(both guards failed together, before an exit) or at PostE (an exit was taken).
The witness is Φ.lfp, the least fixed point of the coupling transformer that runs the
exit coupling if Exit holds and otherwise the guard coupling and, while it fires, the body
coupling. Its marginals are sandwiched between the loop's Kleene iterates and the loop.