Documentation

Std.WP.Monad.Basic

The Weakest Precondition Interpretation of a Monad #

WPMonad m Pred EPosts carries a WP (m α) α Pred EPosts 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)) (EPosts : outParam (Type w')) [Monad m] [Assertion Pred] [Assertion EPosts] 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} {EPosts : Type w'} {α : Type u} [Monad m] [Assertion Pred] [Assertion EPosts] [inst : WPMonad m Pred EPosts] :
    WP (m α) α Pred EPosts

    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} {EPosts : Type u_2} {m : Type u → Type z} [Monad m] [Assertion Pred] [Assertion EPosts] [WPMonad m Pred EPosts] {α β : Type u} (f : α → β) (x : m α) (post : β → Pred) (eposts : EPosts) :
    Lean.Order.PartialOrder.rel (wp x (fun (a : α) => post (f a)) eposts) (wp (f <$> x) post eposts)

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

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

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