f is surjective $\iff$ $g_1 \circ f = g_2 \circ f \to g_1 = g_2 $ I was given a task to prove the following

f is surjective $\iff$ $g_1 \circ f = g_2 \circ f \to g_1 = g_2 $

But I do not completely understand the task. Could you please give some clarification ?
I figured out that I do not understand how to prove statements in the form

A if and only if B implies C

Is it the correct way of proof?
Suppose A is true and from there get that B is also true.
Then suppose that B is true and from there get that A is true.
 A: Suppose $g_1\ne g_2$. Then for some $x$ we have $g_1(x)\ne g_2(x)$. So if $f$ was surjective then $x=f(y)$ for some $y$. But then $ g_1\circ f(y)\ne g_2\circ f(y)$ and $g_1\circ f \ne g_2\circ f$. Conversely if $g_1\circ f\ne g_2\circ f$ then for some $y$ we have $g_1(f(y))\ne g_2(f(y))$ so $ g_1\ne g_2$.
A: Consider a map $f \colon A \to B$. The goal is to show $f$ is surjective if and only if for any pair of maps $g, h \colon B \to M$ the relation $g \circ f=h \circ f$ entails the equality $g=h$ (in brief, a map $f$ exhibiting this property is said to be right-cancellable, as it can be cancelled whenever it occurs as the right factor of two equal compositions).

*

*The easy implication: assume that $f$ is surjective and that $g, h \colon B \to M$ are such that $g \circ f=h \circ f$. This means that $g(f(x))=h(f(x))$ is valid for any $x \in A$ and -- since by virtue of the surjectivity of $f$ any element $y \in B$ can be expressed as $y=f(x)$ for a certain $x \in A$ -- this leads to $g(y)=h(y)$ for any $y \in B$. Since the two maps $g$ and $h$ coincide in terms of domains of definition, codomain and map the same arguments into the same images, they are equal.

*The less simple implication: assume by contradiction there exists a map $f$ which is right-cancellable however not surjective. This means that $\mathrm{Im}f=f[A] \subset B$ (strict inclusion) and thus we can fix a certain $a \in B \setminus f[A]$. Consider the following maps:
$$\begin{align*}
g, h \colon B &\to \{\varnothing, \{\varnothing\}\}\\
g(y)&=\varnothing\\
h(y)&=\begin{cases}
\varnothing, &y \in f[A]\\
\{\varnothing\}, &y \in B \setminus f[A].
\end{cases}
\end{align*}$$
It is clear that $g \circ f=h \circ f$, since for any $x \in A$ we have by definition $g(f(x))=h(f(x))=\varnothing$, however $g \neq h$, since $g(a)=\varnothing \neq \{\varnothing\}=h(a)$ ($\{\varnothing\}$ is a singleton containing the only element $\varnothing$, so in any case it isn't empty). This means that the map $f$ actually fails to be right-cancellable, contradicting our hypothesis. It follows that $f$ is necessarily surjective.


As a minor remark on method, a more direct way to establish the second implication is by rendering it through contraposition into the equivalent statement: "a non-surjective map is not right-cancellable". Essentially that is what the above argument does: under the assumption that $f$ is not surjective it exhibits an explicit pair of distinct maps which nevertheless yield equal compositions when composed with $f$ on the left.
