# One-to-one function composition?

Given

• $f:A\rightarrow B$
• $g: B \rightarrow C$
• $g \circ f$ is one-to-one

Why must $f$ be one-to-one, but not $g$? (Does $g$ have to be onto?)

-

If $f$ isn't one-to-one, $f(a) = f(b)$ with $a\ne b$, say, then $gf(a) = gf(b)$, contradicting the one-to-one-ness of $g\circ f$. To see $g$ needn't be one-to-one or onto, consider $A = \{0\}$, $B = C= \{0,1\}$. $f(0) = 0$, $g(0) = g(1) = 0$. Then $g\circ f\colon A \to C$ is the one-to-one, but $g$ isn't one-to-one or onto.
Recall that $g\circ f$ means taking $a\in A$ then passing it through $f$ into $B$ and then through $g$ into $C$.
Essentially what $g$ does to elements in $B\setminus\operatorname{Rng}(f)$ is of no interest to the composition, and it is exactly the possible case that $g$ is not being injective over those elements. It is essential that between $u,v\in\operatorname{Rng}(f)$ we have $g(u)=g(v)\iff u=v$. Namely $g$ restricted to $\operatorname{Rng}(f)$ is injective, but $g$ itself may be very different.
If $f$ is onto $B$ then indeed $g$ itself has to be injective as well, but other than that surjectivity does not play an important role in this specific problem.