The first problem of a training exercise is:
Show that if $g \circ f$ injective and $f$ surjective, then $g$ injective.
I solved this problem similar to this solution https://math.stackexchange.com/q/845295. However, the second problem is:
Show with an counterexample that the condition "$f$ surjective" is necessary.
I was not able to find an counterexample. This might be on account to the fact that I do not quite understand why it is necessary. I would be thankful if
- someone can give me such an counterexample.
- explain why it is necessary. (maybe it becomes clear to me when I see the counterexample.
The key here is that the composition $g\circ f$ does not always give you full information about $g$, but you can reconstruct the whole $g$ if $f$ is surjective.
To explain that, I put some terminology. Let $X,Y,Z$ be arbitrary sets, $f:X\to Y$ and $g:Y\to Z$. The image of $X$ through $f$, $f(X)$, is a subset in $Y$, and it coincides with the whole space $Y$ if $f$ is surjective (by definition). Suppose that $f$ is not surjective, then we have $f(X)\subset Y$ properly.
When you define $g$, you must give a value of $g$ to every point of $Y$. But, when you apply $g$ to $f(X)$, you are restricting your function to that set, so you are not studying the whole function.
A counterexample? Suppose $X=\{x_1,x_2\},Y=\{y_1,y_2,y_3\},Z=\{z_1,z_2\}$. We define $f(x_1)=y_1,f(x_2)=y_2$ and $g(y_1)=g(y_3)=z_1$, $g(y_2)=z_2$. You see that $f$ is not surjective, and $g$ is not injective. What about $g\circ f$? We answer applying it to every point of $X$: $$ g(f(x_1))=g(y_1)=z_1,\quad g(f(x_2))=g(y_2)=z_2. $$ You see that $g\circ f$ is surjective and injective, even if $g$ is not injective.