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.
Equations
- Std.Do.PostShape.pure.args = []
- (Std.Do.PostShape.arg σ s).args = σ :: s.args
- (Std.Do.PostShape.except ε s).args = s.args
Instances For
An assertion on the .args in the given predicate shape.
example : Assertion (.arg ρ .pure) = (ρ → ULift Prop) := rfl
example : Assertion (.except ε .pure) = ULift Prop := rfl
example : Assertion (.arg σ (.except ε .pure)) = (σ → ULift Prop) := rfl
example : Assertion (.except ε (.arg σ .pure)) = (σ → ULift Prop) := rfl
This is an abbreviation for SPred under the hood, so all theorems about SPred apply.
Equations
- Std.Do.Assertion ps = Std.Do.SPred ps.args
Instances For
Encodes one continuation barrel for each PostShape.except in the given predicate shape.
example : ExceptConds (.pure) = Unit := rfl
example : ExceptConds (.except ε .pure) = ((ε → ULift Prop) × Unit) := rfl
example : ExceptConds (.arg σ (.except ε .pure)) = ((ε → ULift Prop) × Unit) := rfl
example : ExceptConds (.except ε (.arg σ .pure)) = ((ε → σ → ULift Prop) × Unit) := rfl
Equations
Instances For
Equations
Instances For
Instances For
Instances For
Equations
- Std.Do.instInhabitedExceptConds = { default := Std.Do.ExceptConds.true }
Equations
- Std.Do.«term_⊢ₑ_» = Lean.ParserDescr.trailingNode `Std.Do.«term_⊢ₑ_» 25 26 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⊢ₑ ") (Lean.ParserDescr.cat `term 25))
Instances For
Equations
- Std.Do.«term_∧ₑ_» = Lean.ParserDescr.trailingNode `Std.Do.«term_∧ₑ_» 35 36 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ∧ₑ ") (Lean.ParserDescr.cat `term 35))
Instances For
Equations
- Std.Do.«term_→ₑ_» = Lean.ParserDescr.trailingNode `Std.Do.«term_→ₑ_» 25 26 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " →ₑ ") (Lean.ParserDescr.cat `term 25))
Instances For
A postcondition for the given predicate shape, with one Assertion for the terminating case and
one Assertion for each .except layer in the predicate shape.
variable (α σ ε : Type)
example : PostCond α (.arg σ .pure) = ((α → σ → ULift Prop) × PUnit) := rfl
example : PostCond α (.except ε .pure) = ((α → ULift Prop) × (ε → ULift Prop) × PUnit) := rfl
example : PostCond α (.arg σ (.except ε .pure)) = ((α → σ → ULift Prop) × (ε → ULift Prop) × PUnit) := rfl
example : PostCond α (.except ε (.arg σ .pure)) = ((α → σ → ULift Prop) × (ε → σ → ULift Prop) × PUnit) := rfl
Equations
- Std.Do.PostCond α ps = ((α → Std.Do.Assertion ps) × Std.Do.ExceptConds ps)
Instances For
A postcondition for the given predicate shape, with one Assertion for the terminating case and
one Assertion for each .except layer in the predicate shape.
variable (α σ ε : Type)
example : PostCond α (.arg σ .pure) = ((α → σ → ULift Prop) × PUnit) := rfl
example : PostCond α (.except ε .pure) = ((α → ULift Prop) × (ε → ULift Prop) × PUnit) := rfl
example : PostCond α (.arg σ (.except ε .pure)) = ((α → σ → ULift Prop) × (ε → ULift Prop) × PUnit) := rfl
example : PostCond α (.except ε (.arg σ .pure)) = ((α → σ → ULift Prop) × (ε → σ → ULift Prop) × PUnit) := rfl
Equations
- One or more equations did not get rendered due to their size.
Instances For
A postcondition expressing total correctness.
That is, it expresses that the asserted computation finishes without throwing an exception
and the result satisfies the given predicate p.
Equations
Instances For
A postcondition expressing total correctness.
That is, it expresses that the asserted computation finishes without throwing an exception
and the result satisfies the given predicate p.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A postcondition expressing partial correctness.
That is, it expresses that if the asserted computation finishes without throwing an exception
then the result satisfies the given predicate p.
Nothing is asserted when the computation throws an exception.
Equations
Instances For
A postcondition expressing partial correctness.
That is, it expresses that if the asserted computation finishes without throwing an exception
then the result satisfies the given predicate p.
Nothing is asserted when the computation throws an exception.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Std.Do.instInhabitedPostCond = { default := Std.Do.PostCond.noThrow fun (x : α) => default }
Equations
- Std.Do.«term_⊢ₚ_» = Lean.ParserDescr.trailingNode `Std.Do.«term_⊢ₚ_» 25 26 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⊢ₚ ") (Lean.ParserDescr.cat `term 25))
Instances For
Equations
- Std.Do.«term_∧ₚ_» = Lean.ParserDescr.trailingNode `Std.Do.«term_∧ₚ_» 35 36 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ∧ₚ ") (Lean.ParserDescr.cat `term 35))
Instances For
Equations
- Std.Do.«term_→ₚ_» = Lean.ParserDescr.trailingNode `Std.Do.«term_→ₚ_» 25 26 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " →ₚ ") (Lean.ParserDescr.cat `term 25))