Predicate transformers #
PredTrans Pred EPred α wraps a map from a normal postcondition α → Pred and an exception
postcondition EPred to a precondition Pred. The order and the chain-complete suprema are the
pointwise ones of the function space.
PredTrans Pred EPred is a monad, so monadic programs can be interpreted by a monad morphism into
it. This module provides that monad structure, the apply simp framework of the monadic
combinators, the push family that moves a result type into a postcondition, and the standard
monad class instances.
A 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
- Lean.Order.PredTrans.instPartialOrder = { rel := fun (x y : Lean.Order.PredTrans Pred EPred α) => Lean.Order.PartialOrder.rel x.apply y.apply, rel_refl := ⋯, rel_trans := ⋯, rel_antisymm := ⋯ }
Chain-complete partial order on predicate transformers, for fixed-point reasoning.
Equations
- Lean.Order.PredTrans.instCCPO = { toPartialOrder := Lean.Order.PredTrans.instPartialOrder, has_csup := ⋯ }
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
Monad Structure #
apply_* simp framework #
Simp lemmas for reducing (expr).apply post epost for each monadic combinator.
Unfolding PredTrans.pure through apply.
Unfolding PredTrans.bind through apply.
Arguments #
Combinators that add or remove a state argument.
Adds a state argument to a predicate transformer.
Given a state-dependent transformer σ → PredTrans Pred EPred (α × σ), produces a transformer
over σ → Pred that threads the state through postconditions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Order.PredTrans.instMonadLiftForall = { monadLift := fun {α : Type ?u.1} => Lean.Order.PredTrans.liftArg }
Results #
Postconditions for Except and Option results, and the transformer combinators built on them.
The postcondition for an Except ε α result: ok a uses post a, and error e uses
epost e.
Equations
- Lean.Order.pushExcept post epost (Except.ok a) = post a
- Lean.Order.pushExcept post epost (Except.error e) = epost e
Instances For
A normal result uses the normal postcondition.
An exceptional result uses the exception postcondition.
The postcondition for an Option α result: some a uses post a, and none uses
epost ().
Equations
- Lean.Order.pushOption post epost (some a) = post a
- Lean.Order.pushOption post epost none = epost ()
Instances For
A present result uses the normal postcondition.
An absent result uses the absent postcondition.
Adds an exception postcondition layer to a predicate transformer, mirroring ExceptT.
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.pushExceptT = { apply := fun (post : α → Pred) (epost : (ε → Pred) × EPred) => x.apply (Lean.Order.pushExcept post epost.fst) epost.snd }
Instances For
Unfolding lemma for pushExceptT.
Adds an early-termination layer to a predicate transformer, mirroring OptionT.
Given a transformer over Option α, produces one over α with an additional exception
postcondition for the none case.
Equations
- x.pushOptionT = { apply := fun (post : α → Pred) (epost : (Unit → Pred) × EPred) => x.apply (Lean.Order.pushOption post epost.fst) epost.snd }
Instances For
Unfolding lemma for pushOptionT.
Exception Instances #
throw and tryCatch on the first exception postcondition, and the combinators that lift the
MonadExceptOf instance through further layers.
tryCatch x handle replaces the first exception postcondition of x with the precondition
of the handler.
Equations
Instances For
Equations
- Lean.Order.PredTrans.instMonadExceptOfProdForall = { throw := fun {α : Type ?u.1} => Lean.Order.PredTrans.throw, tryCatch := fun {α : Type ?u.1} => Lean.Order.PredTrans.tryCatch }
Unfolding tryCatch through apply: the handler replaces the first exception
postcondition.
Unfolding liftExcept through apply.
Equations
- One or more equations did not get rendered due to their size.
get transforms the postcondition into its assertion at the current state.
Equations
- Lean.Order.PredTrans.get = { apply := fun (post : σ → σ → Pred) (_epost : EPred) (s : σ) => post s s }
Instances For
set s' transforms the postcondition into its assertion at the state s'.
Equations
- Lean.Order.PredTrans.set s' = { apply := fun (post : PUnit → σ → Pred) (_epost : EPred) (_s : σ) => post PUnit.unit s' }
Instances For
Equations
- Lean.Order.PredTrans.instMonadStateOfForall = { get := Lean.Order.PredTrans.get, set := Lean.Order.PredTrans.set, modifyGet := fun {α : Type ?u.1} => Lean.Order.PredTrans.modifyGet }
Equations
Unfolding read through apply.
Equations
- One or more equations did not get rendered due to their size.