Hoare triple specifications for select functions #
This module contains Hoare triple specifications for some functions in Core.
Lifting MonadStateOf
#
Lifting MonadReaderOf
#
Lifting MonadExceptOf
#
The type of loop invariants used by the specifications of for ... in ...
loops.
A loop invariant is a PostCond
that takes as parameters
- A
List.Cursor xs
representing the iteration state of the loop. It is parameterized by the list of elementsxs
that thefor
loop iterates over. - A state tuple of type
β
, which will be a nesting ofMProd
s representing the elaboration oflet mut
variables and early return.
The loop specification lemmas will use this in the following way:
Before entering the loop, the zipper's prefix is empty and the suffix is xs
.
After leaving the loop, the zipper's suffix is empty and the prefix is xs
.
During the induction step, the invariant holds for a suffix with head element x
.
After running the loop body, the invariant then holds after shifting x
to the prefix.
Equations
- Std.Do.Invariant xs β ps = Std.Do.PostCond (xs.Cursor × β) ps
Instances For
Helper definition for specifying loop invariants for loops with early return.
for ... in ...
loops with early return of type γ
elaborate to a call like this:
forIn (β := MProd (Option γ) ...) (b := ⟨none, ...⟩) collection loopBody
Note that the first component of the MProd
state tuple is the optional early return value.
It is none
as long as there was no early return and some r
if the loop returned early with r
.
This function allows to specify different invariants for the loop body depending on whether the loop
terminated early or not. When there was an early return, the loop has effectively finished, which is
encoded by the additional ⌜xs.suffix = []⌝
assertion in the invariant. This assertion is vital for
successfully proving the induction step, as it contradicts with the assumption that
xs.suffix = x::rest
of the inductive hypothesis at the start of the loop body, meaning that users
won't need to prove anything about the bogus case where the loop has returned early yet takes
another iteration of the loop body.
Equations
- One or more equations did not get rendered due to their size.