Soundness of the Weakest Precondition Interpretation #
LawfulWPMonadAttach m Pred EPred relates the wp interpretation of m to the values that a
program x : m α returns. Its single field of_canReturn_wp says: if the postcondition
fun a => ⌜P a⌝ follows from ⊤ under wp x, then P a holds for every a with
MonadAttach.CanReturn x a.
For a transformer, MonadAttach.CanReturn speaks about the computation that remains once the
reader or state argument is supplied and the Except or Option result is exposed. The
of_canReturn_run_wp lemmas take the witness in that form, pairing it with wp prog at the
supplied argument.
The of_run_eq_wp family at the end of the file specializes soundness to the concrete monads
Id, Option, StateM, ReaderM, Except and EStateM, where the witness is an equation
prog.run s = x.
Soundness of the weakest precondition interpretation of m: a postcondition that wp proves
holds of every value the program returns.
- of_canReturn_wp {α : Type u} {x : m α} {P : α → Prop} {a : α} : MonadAttach.CanReturn x a → Lean.Order.PartialOrder.rel Lean.Order.top (wp x (fun (a : α) => Lean.Order.CompleteLattice.ofProp (P a)) Lean.Order.top) → P a
From a
wp-provable postcondition and aMonadAttach.CanReturnwitness, concludePat that value.
Instances
Soundness at the Post-Run Computation #
For a transformer T, T.of_canReturn_run_wp takes the MonadAttach.CanReturn witness for the
base-monad computation that prog becomes once its arguments are supplied.
A wp-provable postcondition holds at every value that the post-run computation
prog.run r : m α returns.
A wp-provable postcondition holds at every value-state pair that the post-run computation
prog.run s : m (α × σ) returns.
A wp-provable postcondition with split .ok/.error cases holds at every result that the
post-run computation prog.run : m (Except ε α) returns.
A wp-provable postcondition with split some/none cases holds at every result that the
post-run computation prog.run : m (Option α) returns.
Soundness at a Concrete Result #
Each lemma below takes the program's result as an equation and concludes a property of it.
Soundness for StateM: if wp prog P s holds, then P holds of the value and final state of
StateT.run prog s.
Soundness for StateM, at the value alone: if wp prog P s holds, then P holds of
StateT.run' prog s.
Soundness for ReaderM: if wp prog P r holds, then P holds of ReaderT.run prog r.
Soundness for Except: the postcondition takes an ok case and an error case, and
wp prog holds of prog itself.
Soundness for EStateM: if wp prog P s holds, then P holds of (prog.run s).