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 <-> ~ X

False

Now we have X <-> ~ X which is a conjunction, so we match on it.

  
X: Prop
h: X <-> ~ X
f: X -> ~ X
g: ~ X -> X

False

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 -> X

X

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: X

False

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

Russel is defined

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.

lt is defined
lt_ind is defined
lt_sind is defined
lt_plus_4 is defined

Now we make lt_S easier to use by making n, m implicit

Arguments lt_S {n m}.

lt_plus_4' is defined

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:

iFalse is defined

Notice the similarity with False_ind.

False_ind : forall P : Prop, False -> P

For conjunction, it's the same idea.

and_ind : forall A B P : Prop, (A -> B -> P) -> A /\ B -> P
iAnd is defined

Now apply plays the role of destruct for such a proof.


forall A B : Prop, iAnd A B -> A /\ B

forall A B : Prop, iAnd A B -> A /\ B
A, B: Prop
h: iAnd A B

A /\ B

With A /\ B the following would be destruct h as [hA hB].

  
A, B: Prop
h: iAnd A B

A -> B -> A /\ B
A, B: Prop
h: iAnd A B
hA: A
hB: B

A /\ B
A, B: Prop
h: iAnd A B
hA: A
hB: B

A
A, B: Prop
h: iAnd A B
hA: A
hB: B
B
all: assumption.
iAnd_and is defined

Now for exists x, P x.

ex_ind : forall (A : Type) (P : A -> Prop) (P0 : Prop), (forall x : A, P x -> P0) -> (exists y, P y) -> P0
iEx is defined

forall (A : Type) (P : A -> Prop), iEx A P -> exists x : A, P x

forall (A : Type) (P : A -> Prop), iEx A P -> exists x : A, P x
A: Type
P: A -> Prop
h: iEx A P

exists x : A, P x
A: Type
P: A -> Prop
h: iEx A P

forall x : A, P x -> exists x0 : A, P x0
A: Type
P: A -> Prop
h: iEx A P
x: A
hx: P x

exists x0 : A, P x0
A: Type
P: A -> Prop
h: iEx A P
x: A
hx: P x

P x
assumption.
iEx_ex is defined

SELF-EVALUATION TIME

We'll do again some paper proving.

even is defined
even_ind is defined
even_sind is defined

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?


forall P Q R : Prop, (P -> R) -> (Q -> R) -> P \/ Q -> R
Abort.

EXERCISE

What is the goal after the following script?


true <> false

true <> false
e: true = false

False
e: true = false

if true then False else True
e: true = false

True

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 m

forall n m : nat, n <= m -> S n <= S m
n, m: nat
h: n <= m

S n <= S m
n: nat

S n <= S n
n, m: nat
h: n <= m
IHh: S n <= S m
S n <= S (S m)
n: nat

S n <= S n
constructor.
n, m: nat
h: n <= m
IHh: S n <= S m

S n <= S (S m)

Here.

Abort.