MPRI PRFA — Proof Assistants
🏠 Go back to the course homepage.
Reviewing session 3
Proving with proof terms
If you find it hard, it's perfectly normal! It takes some time to get used to it, but it is worth it. Now when programming you can use proof-theoretic intuition, and when proving you can use programmer's intuition, this is a very powerful tool!
Let us look again at Russel for the exercises. We'll do it step by step.
X: Prop~ (X <-> ~ X)X: Prop~ (X <-> ~ X)
We want to prove a negation, that's just a function to False
X: Prop
h: X <-> ~ XFalse
Now we have X <-> ~ X which is a conjunction, so we match on it.
X: Prop
h: X <-> ~ X
f: X -> ~ X
g: ~ X -> XFalse
What can we do now? To prove False, there is not much else we can do besides applying f since f _ is of type ~ X which is X -> False. In other words f _ _ is of type False. What does f expect as two arguments? In both cases X, so we might as well just prove it once with a let.
X: Prop
h: X <-> ~ X
f: X -> ~ X
g: ~ X -> XX
Again, we don't really have a choice but to apply g.
X: Prop
h: X <-> ~ X
f: X -> ~ X
g: ~ X -> X~ X
We know the drill.
X: Prop
h: X <-> ~ X
f: X -> ~ X
g: ~ X -> X
x: XFalse
It might seem like we're back where we started, but not really… We have x : X now!
refine (f x x). Abort.
If we combine all of that, we get
Remark. The X in the definition above is on the left of the colon : so it needs not be introduced (with fun X => _) in the body of the definition.
Implicit arguments
When writing proof terms, implicit arguments become all the more important. Let's look at one of the very first exercises.
Now we make lt_S easier to use by making n, m implicit
Arguments lt_S {n m}.
Impredicative encodings
Before there were inductive types, logical connectives were defined using so-called impredicative encodings.
Note: Even datatypes were defined this way, in the advanced exercises, this was the case of the Church encoding of natural numbers.
Impredicative encodings essentially define a type as their eliminator. In other words, think about how you use it.
For False, elimination states that you can prove any other proposition from it, hence the following definition:
Notice the similarity with False_ind.
For conjunction, it's the same idea.
Now apply plays the role of destruct for such a proof.
forall A B : Prop, iAnd A B -> A /\ Bforall A B : Prop, iAnd A B -> A /\ BA, B: Prop
h: iAnd A BA /\ B
With A /\ B the following would be destruct h as [hA hB].
A, B: Prop
h: iAnd A BA -> B -> A /\ BA, B: Prop
h: iAnd A B
hA: A
hB: BA /\ Ball: assumption.A, B: Prop
h: iAnd A B
hA: A
hB: BAA, B: Prop
h: iAnd A B
hA: A
hB: BB
Now for exists x, P x.
forall (A : Type) (P : A -> Prop), iEx A P -> exists x : A, P xforall (A : Type) (P : A -> Prop), iEx A P -> exists x : A, P xA: Type
P: A -> Prop
h: iEx A Pexists x : A, P xA: Type
P: A -> Prop
h: iEx A Pforall x : A, P x -> exists x0 : A, P x0A: Type
P: A -> Prop
h: iEx A P
x: A
hx: P xexists x0 : A, P x0assumption.A: Type
P: A -> Prop
h: iEx A P
x: A
hx: P xP x
SELF-EVALUATION TIME
We'll do again some paper proving.
EXERCISE
Write down the induction principle for even.
REMINDER
Inductive or (A B : Prop) : Prop := | or_introl : A -> A / B | or_intror : B -> A / B.
Notation "A \/ B" := (or A B).
EXERCISE
What is a proof term of the following type?
Abort.forall P Q R : Prop, (P -> R) -> (Q -> R) -> P \/ Q -> R
EXERCISE
What is the goal after the following script?
true <> falsetrue <> falsee: true = falseFalsee: true = falseif true then False else Truee: true = falseTrue
Here.
Abort.EXERCISE
Inductive le (n : nat) : nat -> Prop := | le_n : n <= n | le_S : forall m, n <= m -> n <= S m.
EXERCISE
What is the goal after the following script?
forall n m : nat, n <= m -> S n <= S mforall n m : nat, n <= m -> S n <= S mn, m: nat
h: n <= mS n <= S mn: natS n <= S nn, m: nat
h: n <= m
IHh: S n <= S mS n <= S (S m)constructor.n: natS n <= S nn, m: nat
h: n <= m
IHh: S n <= S mS n <= S (S m)
Here.
Abort.