Composition of functions injective implies one of them is injective?

Suppose we have $f: X \to Y $ and $g:Y \to Z $ maps. Prove that:

  1. $g \circ f $ injective $\implies$ $f$ injective
  2. $g \circ f $ surjective $\implies $ $g$ is surjective

Attempt:

  1. Pick any $x,x' \in X $ with $x \neq x'$. We ought to show that $f(x) \neq f(x')$. Since the composition is injective, we have that $g ( f(x) ) \neq g ( f (x')) $. It is evident from here that we cannot have $f(x) = f(x')$ since otherwise it would contradict the injectivity of $g \circ f $. It follows that $f(x) \neq f(x') $. Hence, $f$ is injective.

  2. Pick arbitrary $z \in Z $. Can find some $x \in X $ such that $g ( f(x) ) = z $. Choose $y = f(x) $. Then we have that for every $z \in Z $ we can find some $f(x) = y \in Y $ such that $g(y) = z $. It follows that $g$ is surjective.

Is this a correct approach to this problem? I know this is elementary, but I'd like to know if I'm writing math correctly.


The first one can also be demonstrated this way

  1. Suppose $f(x)=f(y)$. We have to prove $x=y$. For our hypothesis $g(f(x))=g(f(y))$; since $g\circ f$ is injective, this imply $x=y$.