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 -> Qbeing a function from "things of typeP" to "things of typeQ".2The usual way to prove a goal of type
P -> Qis to useintroorintrosto 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 takesPandQand producesR, then we can define a function that takesQandPand 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, sofis our function that takesPs andQs and producesRs. After theintros(which introduces multiple terms), we see thatq: Qandp: P. The last line (before theQed.) simply applies the functionftopandqto get something inR.For your problem, the
introsintroduces the propositionsP,QandR, as well asH1: P -> QandH2: Q -> R. We can still introduce one more term of typePthough, since the goal isP -> R. Can you see how to useH1andH2and an element ofPto produce an element ofR? Hint: you'll go throughQ. Also, remember thatH1andH2are 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
Propare still types and have very similar behavior to elements ofSetorType. The only difference is thatPropis "impredicative", which allows propositions to quantify over all propositions. For exampleforall P: Prop, P -> Pis an element ofProp, butforall A: Type, A -> Ais an element of the next level up ofType(Typeis actually an infinite hierarchy).