(edits are also saved when you close the window). Finally you can
Recap of lesson 1
Proof language
- move=> name /view // /= [..|..] to name/change the goal
- : name, : (lem arg)
- rewrite lem -lem
- apply: lem
- apply/view
Library
- naming convention: addnC, eqP, orbN, orNb, ...
- notations: .+1, if-is-then-else
- Search (_ + _) inside ssrnat
- Search addn "C" inside ssrnat
- Use the HTML doc!
Approach
- boolean predicates
- reflect P b to link bool with Prop
Today
- the SSReflect proof language (part 2)
- stack model and views
- rewrite idioms and patterns
- forward reasoning with have
- spec lemmas
Bookkeeping 101
- the goal is a stack
- defective case/elim (the top implicit tactic argument)
- tactical => for post processing
- tactical : for pre processing
-
rename
, reorder
(notes)
We say that the goal (under the horizontal bar) is a stack, since
items can only be accessed accorrding to a stack discipline.
If the goal is forall x y, x = 1 + 2 * y -> odd x one has to
deal with x and y before accessing x = 1 + 2 * y.
Induction
- elim with generalization
- in x * alternative
- rewrite (lem args) to specialize a lemma
(notes)
Recall that elim (or case) actually operate on
the top of the stack, which is the last item generalized
by :.
Views are just lemmas (plus some automatic adaptors)
- lemmas like A -> B can be used as views too
- boolean connectives have associated views (
P
suffix)
(notes)
There is nothin special with the /andP[H1 H2] we did
in lesson 1, it is just the composition of /view
followed by a case split [] (in this case only one branch)
rewrite, one command to rule them all
- 1/3 of the lines of Math Comp proofs are rewrite
- side conditions handling via // and ?
- rewrite a boolean predicate (is_true hides an eqaution)
rewrite and subterm selection
- keyed matching drives the search
- specialization via argument passing
- specialization via pattern
- localization via contextual pattern (approximate or precise)
- LHS and RHS notations
(notes)
The details can be found in the reference
manual
or in the
paper
The reflect predicate
- reflect P b is the preferred way to state that
the predicate P (in Prop) is logically equivalent
to b = true
Proving the reflection lemma for eqn
- the convenience lemma iffP
- the congr tactic
- trivial branches => //
- rewrite on the fly ->
- first by
- congr
Spec lemmas
- Inductive predicates to drive the proof:
- you chose how many branches
- you chose which equations are automatically applied
- you chose which extra assumption a branch has
- of syntax for inductives
Let's try out leqP on an ugly goal
- matching of indexes uses the same discipline of rewrite
Bonus (time permitting):
- generalization of unresolved implicits after /leq_trans
- specialization of the top stack item via /(_ arg)
(notes)
While I presonally find /leq_trans too clever and
likely unnecessary, it is used in the library, hence this slide
Another commodity: ifP
- a spec lemma for if-then-else
- handy with case, since matching spares you to write
the expressions involved
- remark how the goal is used as a work space
Forward reasoning
- have : statement.
- have := proof
- have /view ... : .. := .. and variations
Definition of all
Fixpoint all a s := if s is x :: s' then a x && all a s' else true.
Definition of count
Fixpoint count a s := if s is x :: s' then a x + count s' else 0.
A lemma linking the two concepts
References for this lesson:
Demo (time permitting, or as an exercise)
- you should be now able to read this proof