Optional Stopping Theorem
For the analysis of loops, the induction proof rule allows obtaining upper bounds on the wp
-semantics through superinvariants.
Under certain additional conditions, subinvariants I
can also provide valid lower bounds on the wp
-semantics (I <= wp[C](f)
).
The Optional Stopping Theorem identifies conditions ensuring uniform integrability of the subinvariant as one such constraint.
Intuitively, the proof rule requires that the loop executes finitely many iterations in expectation (e.g. that the loop is PAST) and that one can find a constant that bounds the expected change of the subinvariant by one loop iteration.
Caesar supports the "Optional Stopping Theorem for Weakest Preexpectation Reasoning" by Hark et al. as a built-in encoding.1 You can find the extended version of the paper on arxiv. The paper was published at POPL 2020.
Formal Theorem
Consider a loop while G { Body }
whose Body
is AST.
The loop's used and modified variables, except the ones declared within the loop, are referred to as vars
.
Give
I
, a function assigning a value to every state,PAST_I
, a function assigning a value to every state,c
,f
, a function assigning a value to every state,
such that all the following conditions are fulfilled:
-
I
is awp
-subinvariant ofwhile G { Body }
with respect tof
,HeyVL Encoding
@wp
proc I_wp_subinvariant(init_vars: ...) -> (vars: ...)
pre I(init_vars)
post f(vars)
{
vars = init_vars // set current state to input values
@unroll(1, I(vars))
while G {
Body
}
} -
while G { Body }
performs finitely many loop iterations in expectation:PAST_I
is awp
-superinvariant2 ofwhile G { Body; tick 1 }
with respect toPAST_I
,HeyVL Encoding
@wp
coproc PAST_I_ert_superinvariant(init_vars: ...) -> (vars: ...)
pre PAST_I(init_vars)
post PAST_I(vars)
{
vars = init_vars // set current state to input values
if G {
Body
tick 1
} else {}
} -
I
harmonizes withf
: