Documentation

Std.WP.Monad.Basic

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.

class Std.WP.WPMonad (m : Type u → Type v) (Pred : outParam (Type w)) (EPred : outParam (Type w')) [Monad m] [Assertion Pred] [Assertion EPred] extends LawfulMonad m :
Type (max (max (max (u + 1) v) w) w')

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.

Instances
    @[instance_reducible, instance 100]
    instance Std.WP.instWPOfWPMonad {m : Type u → Type v} {Pred : Type w} {EPred : Type w'} {α : Type u} [Monad m] [Assertion Pred] [Assertion EPred] [inst : WPMonad m Pred EPred] :
    WP (m α) α Pred EPred

    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.

    theorem Std.WP.WPMonad.map_le_wp_map {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type z} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α β : Type u} (f : αβ) (x : m α) (post : βPred) (epost : EPred) :
    Lean.Order.PartialOrder.rel (wp x (fun (a : α) => post (f a)) epost) (wp (f <$> x) post epost)

    Soundness of Functor.map: mapping f over x preserves the WP.

    theorem Std.WP.WPMonad.seq_le_wp_seq {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type z} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α β : Type u} (f : m (αβ)) (x : m α) (post : βPred) (epost : EPred) :
    Lean.Order.PartialOrder.rel (wp f (fun (g : αβ) => wp x (fun (a : α) => post (g a)) epost) epost) (wp (f <*> x) post epost)

    Soundness of Seq.seq: sequencing f <*> x preserves the WP.