Predicate transformers for arbitrary postcondition shapes #
This module defines the type PredTrans ps of predicate transformers for a given ps : PostShape.
PredTrans forms the semantic domain of the weakest precondition interpretation
WP in which we interpret monadic programs.
A predicate transformer x : PredTrans ps α is a function that takes a postcondition
Q : PostCond α ps and returns a precondition x.apply Q : Assertion ps, with the additional
monotonicity property that the precondition is stronger the stronger the postcondition is:
Q₁ ⊢ₚ Q₂ → x.apply Q₁ ⊢ₛ x.apply Q₂.
Since PredTrans itself forms a monad, we can interpret monadic programs by writing
a monad morphism into PredTrans; this is exactly what WP encodes.
This module defines interpretations of common monadic operations, such as get, throw,
liftM, etc.
The stronger the postcondition, the stronger the transformed precondition.
Equations
- Std.Do.PredTrans.Monotonic t = ∀ (Q₁ Q₂ : Std.Do.PostCond α ps), Q₁.entails Q₂ → t Q₁ ⊢ₛ t Q₂
Instances For
Transforming a conjunction of postconditions is the same as the conjunction of transformed postconditions.
Equations
- Std.Do.PredTrans.Conjunctive t = ∀ (Q₁ Q₂ : Std.Do.PostCond α ps), t (Q₁.and Q₂) ⊣⊢ₛ t Q₁ ∧ t Q₂
Instances For
Any predicate transformer that is conjunctive is also monotonic.
Equations
- ⋯ = ⋯
Instances For
The type of predicate transformers for a given ps : PostShape and return type α : Type. A
predicate transformer x : PredTrans ps α is a function that takes a postcondition Q : PostCond α ps and returns a precondition x.apply Q : Assertion ps.
Apply the predicate transformer to a postcondition.
- conjunctive : Conjunctive self.apply
The predicate transformer is conjunctive:
t (Q₁ ∧ₚ Q₂) ⊣⊢ₛ t Q₁ ∧ t Q₂. So the stronger the postcondition, the stronger the resulting precondition.
Instances For
Equations
The identity predicate transformer that transforms the postcondition's assertion about the return
value into an assertion about a.
Equations
- Std.Do.PredTrans.pure a = { apply := fun (Q : Std.Do.PostCond α ps) => Q.fst a, conjunctive := ⋯ }
Instances For
The predicate transformer that always returns the same precondition P; (const P).apply Q = P.
Equations
- Std.Do.PredTrans.const P = { apply := fun (Q : Std.Do.PostCond α ps) => P, conjunctive := ⋯ }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Adds the ability to make assertions about a state of type σ to a predicate transformer with
postcondition shape ps, resulting in postcondition shape .arg σ ps. This is done by
interpreting StateT σ (PredTrans ps) α into PredTrans (.arg σ ps) α.
This can be used to for all kinds of state-like effects, including reader effects or append-only states, by interpreting them as states.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Adds the ability to make assertions about exceptions of type ε to a predicate transformer with
postcondition shape ps, resulting in postcondition shape .except ε ps. This is done by
interpreting ExceptT ε (PredTrans ps) α into PredTrans (.except ε ps) α.
This can be used for all kinds of exception-like effects, such as early termination, by interpreting them as exceptions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Adds the ability to make assertions about early termination to a predicate transformer with
postcondition shape ps, resulting in postcondition shape .except PUnit ps. This is done by
interpreting OptionT (PredTrans ps) α into PredTrans (.except PUnit ps) α, which models the type
Option as being equivalent to Except PUnit.
Equations
- One or more equations did not get rendered due to their size.