Documentation

Std.Do.PostCond

Pre and postconditions #

This module defines Assertion and PostCond, the types which constitute the pre and postconditions of a Hoare triple in the program logic.

Predicate shapes #

Since WP supports arbitrary monads, PostCond must be general enough to cope with state and exceptions. For this reason, PostCond is indexed by a PostShape which is an abstraction of the stack of effects supported by the monad, corresponding directly to StateT and ExceptT layers in a transformer stack. For every StateT σ effect, we get one PostShape.arg σ layer, whereas for every ExceptT ε effect, we get one PostShape.except ε layer. Currently, the only supported base layer is PostShape.pure.

Pre and postconditions #

The type of preconditions Assertion ps is distinct from the type of postconditions PostCond α ps.

This is because postconditions not only specify what happens upon successful termination of the program, but also need to specify a property that holds upon failure. We get one "barrel" for the success case, plus one barrel per PostShape.except layer.

It does not make much sense to talk about failure barrels in the context of preconditions. Hence, Assertion ps is defined such that all PostShape.except layers are discarded from ps, via PostShape.args.

inductive Std.Do.PostShape :
Instances For
    @[reducible, inline]

    An assertion on the .args in the given predicate shape.

    example : Assertion (.arg ρ .pure) = (ρ → Prop) := rfl
    example : Assertion (.except ε .pure) = Prop := rfl
    example : Assertion (.arg σ (.except ε .pure)) = (σ → Prop) := rfl
    example : Assertion (.except ε (.arg σ .pure)) = (σ → Prop) := rfl
    

    This is an abbreviation for SPred under the hood, so all theorems about SPred apply.

    Equations
    Instances For

      Encodes one continuation barrel for each PostShape.except in the given predicate shape.

      example : FailConds (.pure) = Unit := rfl
      example : FailConds (.except ε .pure) = ((ε → Prop) × Unit) := rfl
      example : FailConds (.arg σ (.except ε .pure)) = ((ε → Prop) × Unit) := rfl
      example : FailConds (.except ε (.arg σ .pure)) = ((ε → σ → Prop) × Unit) := rfl
      
      Equations
      Instances For
        Equations
        Instances For
          @[simp]
          theorem Std.Do.FailConds.entails.trans {ps : PostShape} {x y z : FailConds ps} :
          (x ⊢ₑ y) → (y ⊢ₑ z) → x ⊢ₑ z
          Equations
          Instances For
            theorem Std.Do.FailConds.and_eq_left {ps : PostShape} {p q : FailConds ps} (h : p ⊢ₑ q) :
            p = (p ∧ₑ q)
            @[reducible, inline]
            abbrev Std.Do.PostCond (α : Type) (s : PostShape) :

            A multi-barreled postcondition for the given predicate shape.

            example : PostCond α (.arg ρ .pure) = ((α → ρ → Prop) × Unit) := rfl
            example : PostCond α (.except ε .pure) = ((α → Prop) × (ε → Prop) × Unit) := rfl
            example : PostCond α (.arg σ (.except ε .pure)) = ((α → σ → Prop) × (ε → Prop) × Unit) := rfl
            example : PostCond α (.except ε (.arg σ .pure)) = ((α → σ → Prop) × (ε → σ → Prop) × Unit) := rfl
            
            Equations
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[reducible, inline]
                abbrev Std.Do.PostCond.total {α : Type} {ps : PostShape} (p : αAssertion ps) :
                PostCond α ps

                A postcondition expressing total correctness.

                Equations
                Instances For
                  @[reducible, inline]
                  abbrev Std.Do.PostCond.partial {α : Type} {ps : PostShape} (p : αAssertion ps) :
                  PostCond α ps

                  A postcondition expressing partial correctness.

                  Equations
                  Instances For
                    Equations
                    def Std.Do.PostCond.entails {α : Type} {ps : PostShape} (p q : PostCond α ps) :
                    Equations
                    Instances For
                      @[simp]
                      theorem Std.Do.PostCond.entails.refl {α : Type} {ps : PostShape} (Q : PostCond α ps) :
                      Q ⊢ₚ Q
                      theorem Std.Do.PostCond.entails.rfl {α : Type} {ps : PostShape} {Q : PostCond α ps} :
                      Q ⊢ₚ Q
                      theorem Std.Do.PostCond.entails.trans {α : Type} {ps : PostShape} {P Q R : PostCond α ps} (h₁ : P ⊢ₚ Q) (h₂ : Q ⊢ₚ R) :
                      P ⊢ₚ R
                      @[simp]
                      theorem Std.Do.PostCond.entails_total {α : Type} {ps : PostShape} (p : αAssertion ps) (q : PostCond α ps) :
                      Std.Do.PostCond.total p ⊢ₚ q ∀ (a : α), p a ⊢ₛ q.fst a
                      @[simp]
                      theorem Std.Do.PostCond.entails_partial {α : Type} {ps : PostShape} (p : PostCond α ps) (q : αAssertion ps) :
                      p ⊢ₚ «partial» q ∀ (a : α), p.fst a ⊢ₛ q a
                      @[reducible, inline]
                      abbrev Std.Do.PostCond.and {α : Type} {ps : PostShape} (p q : PostCond α ps) :
                      PostCond α ps
                      Equations
                      Instances For
                        theorem Std.Do.PostCond.and_eq_left {α : Type} {ps : PostShape} {p q : PostCond α ps} (h : p ⊢ₚ q) :
                        p = (p ∧ₚ q)