I'm trying to prove the transitivity of ->
in Coq's propositions:
Theorem implies_trans : forall P Q R : Prop,
(P -> Q) -> (Q -> R) -> (P -> R).
Proof.
I wanted to destruct all propositions and simply handle all 8 possibilities with reflexivity. Apparently it's not that simple. Here's what I tried:
Theorem implies_trans : forall P Q R : Prop,
(P -> Q) -> (Q -> R) -> (P -> R).
Proof.
intros P Q R H1 H2.
destruct P. (** Hmmm ... this doesn't work *)
Admitted.
And this is what I get:
1 subgoal
P, Q, R : Prop
H1 : P -> Q
H2 : Q -> R
______________________________________(1/1)
P -> R
followed by this error:
Error: Not an inductive product.
Any help is very much appreciated, thanks!
Coq's logic is not classical logic where propositions are true or false. Instead, it's based in type theory and has an intuitionistic flavor by default.1 In type theory, you should think of
P -> Q
being a function from "things of typeP
" to "things of typeQ
".2The usual way to prove a goal of type
P -> Q
is to useintro
orintros
to introduce a hypothesis of typeP
, then use that hypothesis to somehow produce an element of typeQ
.For example, we can prove that
(P -> Q -> R) -> (Q -> P -> R)
. In the "implication is a function" interpretation, this could be read as saying that if we have a function that takesP
andQ
and producesR
, then we can define a function that takesQ
andP
and producesR
. This is the same function, but with the arguments swapped.Using tactics, we can see the types of the individual elements.
After the
intro
, we see thatf: P -> Q -> R
, sof
is our function that takesP
s andQ
s and producesR
s. After theintros
(which introduces multiple terms), we see thatq: Q
andp: P
. The last line (before theQed.
) simply applies the functionf
top
andq
to get something inR
.For your problem, the
intros
introduces the propositionsP
,Q
andR
, as well asH1: P -> Q
andH2: Q -> R
. We can still introduce one more term of typeP
though, since the goal isP -> R
. Can you see how to useH1
andH2
and an element ofP
to produce an element ofR
? Hint: you'll go throughQ
. Also, remember thatH1
andH2
are functions.1 You could add the law of excluded middle as an axiom, which would allow the kind of case analysis you want, but I think it misses the point of Coq.
2 If you're wondering, the elements of
Prop
are still types and have very similar behavior to elements ofSet
orType
. The only difference is thatProp
is "impredicative", which allows propositions to quantify over all propositions. For exampleforall P: Prop, P -> P
is an element ofProp
, butforall A: Type, A -> A
is an element of the next level up ofType
(Type
is actually an infinite hierarchy).