0

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 :

enter image description here

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.
Romain C
  • 11
  • 1
  • 3

2 Answers2

0

Instead of cut, use unfold injective. to reveal the hypothesis compose g f x = compose g f x'.

Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56
0

apply H2 in H says you're missing an x1 and x2. First get yourself an x1 and x2 by unfolding injective in your goal and using intros. Then you can apply H2 (with appropriate parameters) in H1.

jbapple
  • 3,297
  • 1
  • 24
  • 38