Hoare triple specifications for select functions #
This module contains Hoare triple specifications for some functions in Core.
The specifications follow the Triple x pre post epost argument order, program first.
Lifting MonadStateOf #
Lifting MonadReaderOf #
Lifting MonadExceptOf #
The type of loop invariants used by the specifications of for ... in ... loops.
A loop invariant maps the elements consumed so far, the elements remaining, and the accumulator
state to an assertion.
Equations
- Std.Internal.Do.Invariant α β Pred = (List α → List α → β → Pred)
Instances For
An invariant combinator for loops with early return, for the new do elaborator which
uses Prod for the state tuple: onContinue is the invariant while iterating, onReturn
holds once the loop returned early with a value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Every container with a PureForIn' instance iterates over ForIn.toList, so one specification
covers them all.
Every container with a PureForIn instance iterates over ForIn.toList, so one specification
covers them all.
The type of loop invariants used by the specifications of for ... in ... loops over strings.
A loop invariant is a function mapping the current position and state to a lattice element.
Equations
- Std.Internal.Do.StringInvariant s β Pred = (s.Pos → β → Pred)
Instances For
An invariant combinator for String loops with early return, for the new do elaborator
which uses Prod for the state tuple: onContinue is the invariant while iterating, onReturn
holds once the loop returned early with a value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The type of loop invariants used by the specifications of for ... in ... loops over string slices.
A loop invariant is a function mapping the current position and state to a lattice element.
Equations
- Std.Internal.Do.StringSliceInvariant s β Pred = (s.Pos → β → Pred)
Instances For
An invariant combinator for String.Slice loops with early return, for the new do
elaborator which uses Prod for the state tuple: onContinue is the invariant while iterating,
onReturn holds once the loop returned early with a value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
An invariant for a repeatM loop, given as a predicate over the α ⊕ β cursor:
.inl a is the continue case at a; .inr b is the break case with result b.
Equations
- Std.Internal.Do.RepeatInvariant α β Pred = (α ⊕ β → Pred)
Instances For
A termination measure for a repeatM loop: a type γ of measure values equipped with a
well-founded relation, and a lattice-embedded evaluation of the measure at each cursor.
Build one from a measure function with RepeatVariant.ofMeasure.
- γ : Type uγ
The type of measure values.
- wfRel : WellFoundedRelation self.γ
The well-founded relation that measure values decrease along.
- EvalsTo : α → self.γ → Pred
Relates the measure at cursor
ato a valueninside the assertion lattice. The measure evaluates to some value.
Instances For
The relation that measure values decrease along.
Equations
Instances For
Eliminate the covering join of EvalsTo from the left of an entailment.
Build a RepeatVariant from a measure function f. The measure's value type γ (its codomain
through any NondetFun state layers) provides the well-founded relation, e.g. < for Nat and
the lexicographic order for products.
Equations
- Std.Internal.Do.RepeatVariant.ofMeasure f = { γ := γ, wfRel := inst✝, EvalsTo := fun (a : α) (n : γ) => Std.Internal.Do.Assertion.NondetFun.EvalsTo (f a) n, total := ⋯ }
Instances For
Decrease along ofMeasure is decrease of measure values along the well-founded relation of
γ. Rewriting with this lemma brings a decrease proof obligation into the shape produced by
termination_by, so that decreasing_tactic applies.
The measure at cursor a' evaluates to a value strictly below ma.
Equations
- v.EvalsBelow a' ma = Lean.Order.iSup fun (ma' : v.γ) => Lean.Order.meet (v.EvalsTo a' ma') (Lean.Order.CompleteLattice.ofProp (v.rel ma' ma))
Instances For
For a state-independent measure the pinned value is the measure itself, so the join
collapses to a decrease along the well-founded relation of γ. The proof obligation has the
shape produced by termination_by, so that decreasing_tactic applies.
Pointwise characterization of EvalsBelow on a function lattice, for ofMeasure
measures.
Fixed-arity specializations of evalsBelow_ofMeasure_apply for Nat-valued measures at a
lattice tower ending in Prop, in the manner of CompleteLattice.ofProp_apply_1 and its
siblings: the ground instances leave every parameter recoverable from the trigger, so these are
usable @[grind =] lemmas where the general evalsBelow_ofMeasure_apply is not.
Specification for repeatM. The user supplies a termination measure, an invariant, and a step
Triple whose pre asserts the measure evaluates to ma and the in-progress invariant holds, and
whose post either continues with a measure value below ma (the invariant still holding) or
finishes with the .inr invariant.
Construct an invariant from a loop invariant inv and a break condition onBreak.
inv holds at the end of every loop iteration (including the breaking one), and onBreak holds in
addition to inv once the loop is done. For a normal while loop onBreak can be taken as the
negation of the loop condition.
Equations
- Std.Internal.Do.RepeatInvariant.ofInvariantAndBreak inv onBreak (Sum.inl a) = inv a
- Std.Internal.Do.RepeatInvariant.ofInvariantAndBreak inv onBreak (Sum.inr a) = Lean.Order.meet (inv a) (onBreak a)
Instances For
Specification for forIn over a Lean.Loop. The cursor is β ⊕ β: .inl b means
"still iterating with b", .inr b means "finished with result b".