# If $g\circ f = h \circ f$ implies $g = h$, then prove that $f$ is onto.

Suppose $A,\ B$ and $C$ are sets and $f: A\rightarrow B$.

Suppose that $C$ has at least two elements, and for all functions $g$ and $h$ from $B$ to $C$, if $g\circ f = h \circ f$ then $g = h$. Prove that $f$ is onto.

The answer is here: http://users.metu.edu.tr/serge/courses/111-2011/textbook-math111.pdf at pg 352 and the question on pg 244. I'm a bit confused by it. Especially this part: $\forall x\in B\setminus\{b\}(h(x) = c1)$, and $h(b) = c2$. If $b$ is suppose to be arbitary how can we create this sort of piecewise function? Anyway can anyone explain away my problem? Also any alternative proof is welcome.

Proof by contradiction. Suppose $f$ satisfies the given condition but is not onto, then we can find $x \in B$ such that $f^{-1}(x) = \emptyset$. Now, $C$ has at least two elements so let $c_1,c_2 \in C$ with $c_1 \neq c_2$. Let $g:B \rightarrow C$ be a function satisfying $g(x) = c_1$. Next define $h: B \rightarrow C$ a function where $$h(b) = \left\{ \begin{matrix}c_2, & \text{if b = x} \\ g(b), & \text{if b \neq x} \end{matrix} \right.$$
Now clearly $g \neq h$ since $g(x) \neq h(x)$. So let's check to see if $gf = hf$. Since the image of $f$ does not contain $x$ and $x$ is the only element for which the functions $g,h$ differ we see that $gf = hf$. The argument in symbols: let $a \in A$ then $f(a) \neq x$ so $h(f(a)) = g(f(a))$ by definition of $h$, so $hf = gf$.