I am very new to Coq and I'm trying to prove that if two functions are injectives, the composition of theses two functions is also injective. Here is my code:
Definition compose {A B C} (g: B -> C) (f: A -> B) :=
fun x : A => g (f x).
Definition injective {A B} (f: A -> B) :=
forall x1 x2, f x1 = f x2 -> x1 = x2.
(*
Definition surjective {A B} (f: A -> B) :=
forall y: B, exists x: A, f x = y.
*)
Theorem example {A B C} (g: B -> C) (f: A -> B) :
injective f /\ injective g -> injective (compose g f).
Proof.
intros.
destruct H as (H1,H2).
cut (forall x1 x2: A, (compose g f) x1 = (compose g f) x2).
intros.
unfold compose in H.
unfold injective in H2.
The result is:
2 goals
A : Type
B : Type
C : Type
g : B -> C
f : A -> B
H1 : injective f
H2 : forall x1 x2 : B, g x1 = g x2 -> x1 = x2
H : forall x1 x2 : A, g (f x1) = g (f x2)
______________________________________(1/2)
injective (compose g f)
______________________________________(2/2)
forall x1 x2 : A, compose g f x1 = compose g f x2
From this state, I am trying to apply H2
in H
in order to prove that f(x1)=f(x2)
. I have tried the apply
tactic as well as the specialized
tactic but none of them worked.
Here is the actual proof I am following :
EDIT: Thank you very much for you help! This code works now :
Theorem compose_injective {A B C} (g: B -> C) (f: A -> B) :
injective f /\ injective g -> injective (compose g f).
Proof.
intros.
destruct H as (H1,H2).
unfold injective.
intros.
unfold injective in H2.
apply H2 in H.
unfold injective in H1.
apply H1 in H.
exact H.