For nonempty sets A and B and functions f : A → B and g : B → A, suppose that $g \circ f =$ the identity function on A. $(♦)$
(d) $(=>)$ Assume that $f$ is onto. This means there exist $a_1, a_2\in A$ such that $f(a_1)=b_1$ and $f(a_2)=b_2$, , where $b_i\in B$
Suppose that $g(b_1)=g(b_2)$. Substitute $b_i$ with the above equations for $f(a_i)$: $ g(f(a_1))=g(f(a_2))$. By virtue of (♦), we have $a_1=a_2$.
What's the proof strategy? I'm not asking about the proofs, but they both look guileful and wily. For example, how would one determine when to apply $f$ or $g$? I realise that the proof leverages $(♦)$.
This is one of those cases where the proof strategy is just to write down your conclusion and your premise, and at every step just write down the first thing you can do with the tools you are given.
Always start by writing down the premise:
We would like to show that $g$ is one-to-one, which means $g(a) = g(b) \implies a = b$. To show this, start with the premise:
Now what? Well, there aren't very many possible options at this point as we only have a few symbols. We have some $b_1,b_2$ - what can we do with them? We have to use the premise somewhere, which is that $f$ is onto. Even if we don't see immediately how it's useful, there's only one thing we can say:
What now? There's only one thing we know about $b_1,b_2$, and one thing we know about $a_1,a_2$, so put them together and rewrite what we have.
But then we're already finished.
Tim Gowers has written some nice blog posts about this kind of proof. You don't have to be clever - just write down the premise and then keep writing down something you can do with the symbols you currently have according to what you know at that point. In my experience students mainly have trouble getting the logical form of the argument right rather than coming up with the individual steps.