The Weakest Precondition Interpretation of a Monad #
WPMonad m Pred EPred carries a WP (m α) α Pred EPred interpretation for every result type α,
together with soundness of that interpretation for pure and bind. An instance supplies the
WP interpretation of m α at low priority, so a program type with a bespoke interpretation keeps
its own.
Weakest precondition monad: a monad m whose weakest precondition interpretation is sound for
pure and bind. The interpretation for every result type is carried as the toWP field; an
instance exposes it as a WP (m α) … interpretation.
- seq_assoc {α β γ : Type u} (x : m α) (g : m (α → β)) (h : m (β → γ)) : h <*> (g <*> x) = Function.comp <$> h <*> g <*> x
The weakest precondition interpretation of
mat every result type.- pure_le_wp_pure {α : Type u} (x : α) (post : α → Pred) (epost : EPred) : Lean.Order.PartialOrder.rel (post x) (wp (pure x) post epost)
Soundness of
pure: the postcondition applied toximplies the weakest precondition ofpure x. - bind_le_wp_bind {α β : Type u} (x : m α) (f : α → m β) (post : β → Pred) (epost : EPred) : Lean.Order.PartialOrder.rel (wp x (fun (a : α) => wp (f a) post epost) epost) (wp (x >>= f) post epost)
Soundness of
bind: composing weakest preconditions is at least as strong as the weakest precondition of>>=.
Instances
A monadic WP interpretation is sourced from the monad's WPMonad instance. Low priority so a
program type with a bespoke WP instance (e.g. a non-monadic one) is preferred.
Equations
Derived WPMonad Lemmas #
One-directional consequences of the WPMonad axioms for pure, bind, map, and seq.
Soundness of Functor.map: mapping f over x preserves the WP.
Soundness of Seq.seq: sequencing f <*> x preserves the WP.