Lean from zero, for reading Schedule.lean #
The book's chapter "Proofs" (Foundations) walks through this file. It uses only Lean's core
library, like Schedule.lean, and every example is a smaller version of something there.
lean verify/Tutorial.lean # prints nothing when every proof checks
1. Definitions, and proofs by computation #
$$\mathrm{double}(21) = 42$$
rfl: both sides compute to the same value.
2. Programs as lists of steps (runAll in Schedule.lean) #
Run a list of state transformers in order.
Equations
- Tutorial.applyAll [] x✝ = x✝
- Tutorial.applyAll (f :: fs) x✝ = Tutorial.applyAll fs (f x✝)
Instances For
$$\mathrm{applyAll}(xs \mathbin{+\!\!+} ys)(s) = \mathrm{applyAll}(ys)\bigl(\mathrm{applyAll}(xs)(s)\bigr)$$
Running xs ++ ys is running xs, then ys. Proof by induction on xs.
4. The rest of what Schedule.lean uses #
A set of locations as a predicate: Small l is the proposition "l is in the set".
Schedule.lean's footprints R and W are sets like this, Loc → Prop.
Equations
- Tutorial.Small n = (n < 10)
Instances For
Instances For
5. Solutions to the chapter's exercises #
$$(\forall f \in fs,\ \forall s,\ f(s) = s) \implies \mathrm{applyAll}(fs)(s) = s$$
Exercise 3: steps that change nothing can be run any number of times
(speculation_harmless in Schedule.lean).