Weakest Precondition Interpretation #
WP Prog Value Pred EPosts interprets a program type Prog whose results have type Value as a
monotone predicate transformer PredTrans Pred EPosts Value. For a program x : Prog, a normal
postcondition post : Value → Pred and an exception postcondition eposts : EPosts, the assertion
wp x post eposts is the weakest precondition under which x establishes post and eposts.
The program type Prog determines the other three types, which are outParams of the class.
Instance search runs on Prog alone. A term wp x post eposts therefore fixes the result type, the
assertion lattice and the exception postcondition type from the type of x, and each program type
carries one interpretation.
Two examples show the range of Prog. The error-state monad EStateM ε σ has the instance
WP (EStateM ε σ α) α (σ → Prop) (ε → σ → Prop). Here a state predicate is the assertion, and an
error paired with a state is the exception postcondition.
A deep embedding is the second example. A command language Cmd with assertions Env → State → Prop
has the instance WP Cmd Unit (Env → State → Prop) EStack⟨⟩. Its wp is defined in terms of an
operational semantics such as an omnisemantics. The file tests/elab/vcgenImp.lean carries this
example in full.
Everything here is generic over the program type. The interpretation of a monad and of the monad
transformers is in Std.WP.Monad.
Assertion Language Classes #
Assertion is an alias type class for CompleteLattice.
We use Assertion Pred for the assertion language of normal postconditions
and Assertion EPosts for exception postconditions.
The WP Typeclass #
The WP typeclass interprets a program type Prog whose results have type Value as a monotone
predicate transformer trans : Prog → PredTrans Pred EPosts Value.
Weakest precondition interpretation of a program type Prog whose results have type Value,
as a monotone predicate transformer over assertion language Pred with exception postconditions
EPosts.
- trans : Prog → Lean.Order.PredTrans Pred EPosts Value
The weakest precondition transformer for a program.
- wpTrans : Prog → Lean.Order.PredTrans Pred EPosts Value
Deprecated alias for
trans; provide either field when defining an instance. Monotonicity: weaker postconditions yield weaker preconditions.
Deprecated alias for
trans_monotone; provide either field when defining an instance.
Instances
Weakest precondition of x for normal postcondition post and exception postcondition eposts.
The WP interpretation can be supplied explicitly via dot notation (inst.wp x post eposts).
Equations
- Std.WP.wp x post eposts = (Std.WP.WP.trans x).apply post eposts
Instances For
Rewriting the program of a weakest precondition along an equation x = y weakens it:
the precondition of y entails the precondition of x.