Documentation

Std.Do.WP.Basic

Weakest precondition interpretation #

This module defines the weakest precondition interpretation WP of monadic programs in terms of predicate transformers PredTrans.

This interpretation forms the basis of our notion of Hoare triples. It is the main mechanism of this library for reasoning about monadic programs.

An instance WP m ps determines an interpretation wp⟦x⟧ of a program x : m α in terms of a predicate transformer PredTrans ps α; The monad m determines ps : PostShape and hence the particular shape of the predicate transformer.

This library comes with pre-defined instances for common monads and transformers such as

These instances are all monad morphisms, a fact which is properly encoded and exploited by the subclass WPMonad.

class Std.Do.WP (m : Type u → Type v) (ps : outParam PostShape) :
Type (max (u + 1) v)

A weakest precondition interpretation of a monadic program x : m α in terms of a predicate transformer PredTrans ps α. The monad m determines ps : PostShape. See the module comment for more details.

  • wp {α : Type u} (x : m α) : PredTrans ps α

    Interpret a monadic program x : m α in terms of a predicate transformer PredTrans ps α.

Instances

    wp⟦x⟧ Q is defined as (WP.wp x).apply Q.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        Equations
        instance Std.Do.StateT.instWP {m : Type u → Type v} {ps : PostShape} {σ : Type u} [WP m ps] :
        WP (StateT σ m) (PostShape.arg σ ps)
        Equations
        instance Std.Do.ReaderT.instWP {m : Type u → Type v} {ps : PostShape} {ρ : Type u} [WP m ps] :
        WP (ReaderT ρ m) (PostShape.arg ρ ps)
        Equations
        instance Std.Do.ExceptT.instWP {m : Type u → Type v} {ps : PostShape} {ε : Type u} [WP m ps] :
        WP (ExceptT ε m) (PostShape.except ε ps)
        Equations
        instance Std.Do.OptionT.instWP {m : Type u → Type v} {ps : PostShape} [WP m ps] :
        Equations
        Equations
        • One or more equations did not get rendered due to their size.
        theorem Std.Do.Id.of_wp_run_eq {α : Type u} {x : α} {prog : Id α} (h : prog.run = x) (P : αProp) :
        (⊢ₛ wp⟦prog (PostCond.noThrow fun (a : α) => { down := P a })) → P x

        Adequacy lemma for Id.run. Useful if you want to prove a property about an expression x defined as Id.run prog and you want to use mvcgen to reason about prog.

        theorem Std.Do.StateM.of_wp_run_eq {σ : Type u_1} {s : σ} {α : Type u_1} {x : α × σ} {prog : StateM σ α} (h : StateT.run prog s = x) (P : α × σProp) :
        (⊢ₛ wp⟦prog (PostCond.noThrow fun (a : α) (s' : σ) => P (a, s')) s) → P x

        Adequacy lemma for StateM.run. Useful if you want to prove a property about an expression x defined as StateM.run prog s and you want to use mvcgen to reason about prog.

        theorem Std.Do.StateM.of_wp_run'_eq {σ : Type u_1} {s : σ} {α : Type u_1} {x : α} {prog : StateM σ α} (h : StateT.run' prog s = x) (P : αProp) :
        (⊢ₛ wp⟦prog (PostCond.noThrow fun (a : α) => P a) s) → P x

        Adequacy lemma for StateM.run'. Useful if you want to prove a property about an expression x defined as StateM.run' prog s and you want to use mvcgen to reason about prog.

        theorem Std.Do.ReaderM.of_wp_run_eq {ρ : Type u_1} {r : ρ} {α : Type u_1} {x : α} {prog : ReaderM ρ α} (h : ReaderT.run prog r = x) (P : αProp) :
        (⊢ₛ wp⟦prog (PostCond.noThrow fun (a : α) (x : ρ) => P a) r) → P x

        Adequacy lemma for ReaderM.run. Useful if you want to prove a property about an expression x defined as ReaderM.run prog r and you want to use mvcgen to reason about prog.

        theorem Std.Do.Except.of_wp {ε α : Type} {prog : Except ε α} (P : Except ε αProp) :
        (⊢ₛ wp⟦prog (fun (a : α) => P (Except.ok a), fun (e : ε) => P (Except.error e), ())) → P prog

        Adequacy lemma for Except. Useful if you want to prove a property about an expression prog : Except ε α and you want to use mvcgen to reason about prog.

        theorem Std.Do.EStateM.of_wp_run_eq {ε σ : Type} {s : σ} {α : Type} {x : EStateM.Result ε σ α} {prog : EStateM ε σ α} (h : prog.run s = x) (P : EStateM.Result ε σ αProp) :
        (⊢ₛ wp⟦prog (fun (a : α) (s' : σ) => P (EStateM.Result.ok a s'), fun (e : ε) (s' : σ) => P (EStateM.Result.error e s'), ()) s) → P x

        Adequacy lemma for EStateM.run. Useful if you want to prove a property about an expression x defined as EStateM.run prog s and you want to use mvcgen to reason about prog.