MPRI PRFA — Proof Assistants
🏠 Go back to the course homepage.
Reviewing session 2
Think before you prove
We all jump right in the proof and it can be quite fun, but sometimes just thinking a little will save some trouble.
Let us look at the add_sub example from the exercise session. It might be tempting to prove things by induction on n, after all it's the first variable we have in the context, but it's actually must better to perform induction on m.
forall n m : nat, n + m - m = nforall n m : nat, n + m - m = nn, m: natn + m - m = nn: natn + 0 - 0 = nn, m: nat
ih: n + m - m = nn + S m - S m = nn: natn + 0 - 0 = nn: natn - 0 = nall: reflexivity.0 - 0 = 0n: natS n - 0 = S nn, m: nat
ih: n + m - m = nn + S m - S m = nn, m: nat
ih: n + m - m = nS (n + m) - S m = nassumption.n, m: nat
ih: n + m - m = nn + m - m = n
Shadowing
We have several ways to write the definition of subtraction, depending on whether we reuse the name of the argument or not in the pattern matching. If we reuse the name, the original name is then shadowed which is fine as long as we don't want to mention it again. Sometimes, it is useful to mention it.
Discriminating by hand
We write instructions in the document in the form of comments, please follow them! This includes writing the induction principle, or not using certain tactics or libraries, so that you can learn. 🧑🎓 When we told you to prove true ≠ false, we were expecting the following.
true <> falsetrue <> falsee: true = falseFalsee: true = falseif true then False else Truesplit.e: true = falseTrue
Using custom induction principles
When you prove an induction principle, you can use it directly with the induction tactic. Much nicer than applying it by hand.
forall P : nat -> Prop, (forall n : nat, (forall m : nat, m < n -> P m) -> P n) -> forall n : nat, P nFrom Stdlib Require Import Lia.forall n : nat, even3 n -> even4 nforall n : nat, even3 n -> even4 nn: nat
h: even3 neven4 nn: nat
ih:= forall m: nat, m < n -> even3 m -> even4 m
h: even3 neven4 nih:= forall m: nat, m < 0 -> even3 m -> even4 m
h: even3 0even4 0ih:= forall m: nat, m < 1 -> even3 m -> even4 m
h: even3 1even4 1n: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))even4 (S (S n))constructor.ih:= forall m: nat, m < 0 -> even3 m -> even4 m
h: even3 0even4 0ih:= forall m: nat, m < 1 -> even3 m -> even4 m
h: even3 1even4 1contradiction.ih:= forall m: nat, m < 1 -> even3 m -> even4 m
h: Falseeven4 1n: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))even4 (S (S n))n: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))even4 nn: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))n < S (S n)n: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))even3 nlia.n: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))n < S (S n)assumption.n: nat
ih:= forall m: nat, m < S (S n) -> even3 m -> even4 m
h: even3 (S (S n))even3 n
SELF-EVALUATION TIME
Finally, we would like you to try to do the following on paper, that is without using Rocq on your computer to tell you the answer!
EXERCISE
Write down the induction principle for list.
EXERCISE
What is the goal after the following script?
forall P Q : Prop, P \/ Q -> Q \/ Pforall P Q : Prop, P \/ Q -> Q \/ PP, Q: Prop
h: P \/ QQ \/ PP, Q: Prop
h: PQ \/ PP, Q: Prop
h: QQ \/ PP, Q: Prop
h: PQ \/ PP, Q: Prop
h: PQ
Here, what is the goal?
Abort.
EXERCISE
Prove 0 ≠ 1 without automation.