Predicate Transformers #
This module defines the type PredTrans Pred EPred α of predicate transformers for weakest
precondition reasoning over monadic programs with exception postconditions.
A predicate transformer x : PredTrans Pred EPred α takes a normal postcondition post : α → Pred,
an exception postcondition epost : EPred, and returns a precondition of type Pred.
PredTrans forms a monad, so monadic programs can be interpreted by a monad morphism into
PredTrans; this is exactly what WPMonad encodes.
Main definitions #
PredTrans Pred EPred α— the type of monotone predicate transformersPredTrans.pushExcept— adds an exception layer to a predicate transformerpushArg— adds a state argument to a predicate transformer- Instances for
Monad,LawfulMonad,MonadStateOf,MonadExceptOf, etc.
A monotone predicate transformer from postconditions to preconditions.
Given a return type α, a lattice Pred for assertions, and an exception assertion type EPred,
PredTrans Pred EPred α wraps a function (α → Pred) → EPred → Pred.
- apply : (α → Pred) → EPred → Pred
Apply the predicate transformer to a postcondition and exception postcondition.
Instances For
Partial order on predicate transformers, inherited from the function space.
Equations
- One or more equations did not get rendered due to their size.
Chain-complete partial order on predicate transformers, for fixed-point reasoning.
Equations
- Std.Internal.Do.instCCPOPredTrans = { toPartialOrder := Std.Internal.Do.instPartialOrderPredTrans, has_csup := ⋯ }
Monad instance for PredTrans: pure returns the postcondition applied to the value,
and bind threads the postcondition through the continuation.
Equations
- One or more equations did not get rendered due to their size.
PredTrans is a lawful monad: all monad laws hold definitionally.
Monotonicity property for a predicate transformer: if both post and epost grow,
then the resulting precondition grows.
Equations
- One or more equations did not get rendered due to their size.
Instances For
apply_* simp framework #
Simp lemmas for reducing (expr).apply post epost for each monadic combinator.
Exception Handling #
Definitions for pushing and lifting exception layers through predicate transformers.
Push an Except ε α result into separate normal and exception postconditions:
ok a uses post a, and error e uses epost.head e.
Equations
- Std.Internal.Do.EPost.cons.pushExcept post epost (Except.ok a) = post a
- Std.Internal.Do.EPost.cons.pushExcept post epost (Except.error e) = epost.head e
Instances For
Adds an exception layer to a predicate transformer.
Given a transformer over Except ε α, produces one over α with an additional
exception postcondition for ε. The normal and error postconditions are combined
via pushExcept.
Equations
- x.pushExcept = { apply := fun (post : α → Pred) (epost : EPost.cons✝ (ε → Pred) EPred) => x.apply (Std.Internal.Do.EPost.cons.pushExcept post epost) epost.tail }
Instances For
Push an Option α result into separate normal and none postconditions:
some a uses post a, and none uses epost.head.
Equations
- Std.Internal.Do.EPost.cons.pushOption post epost (some a) = post a
- Std.Internal.Do.EPost.cons.pushOption post epost none = epost.head
Instances For
Adds an early-termination layer to a predicate transformer, modelling Option as
early termination. Given a transformer over Option α, produces one over α with an
additional exception postcondition for the none case.
Equations
- x.pushOption = { apply := fun (post : α → Pred) (epost : EPost.cons✝ Pred EPred) => x.apply (Std.Internal.Do.EPost.cons.pushOption post epost) epost.tail }
Instances For
Unfolding pushOption through apply.
State Handling #
Definitions for adding state arguments to predicate transformers.
Adds a state argument to a predicate transformer.
Given a state-dependent transformer σ → PredTrans l e (α × σ), produces a transformer
over σ → l that threads the state through postconditions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Lift a predicate transformer to one with a state argument (pointwise).
Equations
- One or more equations did not get rendered due to their size.
Lift a predicate transformer to one with an additional exception layer (high priority).
Equations
- One or more equations did not get rendered due to their size.
MonadStateOf instance: get returns the state, set replaces it,
modifyGet applies a function to the state.
Equations
- One or more equations did not get rendered due to their size.
MonadReaderOf instance: read provides the state without consuming it.
MonadExceptOf instance for the outermost exception layer:
throw invokes the head exception postcondition, tryCatch intercepts it.
Equations
- One or more equations did not get rendered due to their size.
MonadExceptOf instance lifted through a state layer:
delegates throw and tryCatch to the inner PredTrans l e instance.
Equations
- One or more equations did not get rendered due to their size.
MonadExceptOf instance lifted through an unrelated exception layer:
delegates to the inner instance, threading the extra exception postcondition.
Equations
- One or more equations did not get rendered due to their size.