SatisfiesM #
The SatisfiesM
predicate works over an arbitrary (lawful) monad / applicative / functor,
and enables Hoare-like reasoning over monadic expressions. For example, given a monadic
function f : α → m β
, to say that the return value of f
satisfies Q
whenever
the input satisfies P
, we write ∀ a, P a → SatisfiesM Q (f a)
.
Notes #
SatisfiesM
is not yet a satisfactory solution for verifying the behaviour of large scale monadic
programs. Such a solution would allow ergonomic reasoning about large do
blocks,
with convenient mechanisms for introducing invariants and loop conditions as needed.
It is possible that in the future SatiesfiesM
will become part of such a solution,
presumably requiring more syntactic support (and smarter do
blocks) from Lean.
Or it may be that such a solution will look different!
This is an open research program, and for now one should not be overly ambitious using SatisfiesM
.
In particular lemmas about pure operations on data structures in batteries
except for HashMap
should avoid SatisfiesM
for now, so that it is easy to migrate to other approaches in future.
SatisfiesM p (x : m α)
lifts propositions over a monad. It asserts that x
may as well
have the type x : m {a // p a}
, because there exists some m {a // p a}
whose image is x
.
So p
is the postcondition of the monadic value.
Equations
- SatisfiesM p x = ∃ (x' : m { a : α // p a }), Subtype.val <$> x' = x
Instances For
If p
is always true, then every x
satisfies it.
If p
is always true, then every x
satisfies it.
(This is the strongest postcondition version of of_true
.)
The SatisfiesM p x
predicate is monotonic in p
.
SatisfiesM
distributes over <$>
, general version.
SatisfiesM
distributes over <$>
, strongest postcondition version.
(Use this for reasoning forward from assumptions.)
SatisfiesM
distributes over <$>
, weakest precondition version.
(Use this for reasoning backward from the goal.)
SatisfiesM
distributes over mapConst
, general version.
SatisfiesM
distributes over pure
, general version / weakest precondition version.
SatisfiesM
distributes over <*>
, general version.
SatisfiesM
distributes over <*>
, strongest postcondition version.
SatisfiesM
distributes over <*>
, weakest precondition version 1.
(Use this when x
and the goal are known and f
is a subgoal.)
SatisfiesM
distributes over <*>
, weakest precondition version 2.
(Use this when f
and the goal are known and x
is a subgoal.)
SatisfiesM
distributes over <*
, general version.
SatisfiesM
distributes over *>
, general version.
SatisfiesM
distributes over >>=
, general version.
SatisfiesM
distributes over >>=
, weakest precondition version.