# Proof of a Surjective Function

I've run into a question in my textbook and I'm not sure if I understand fully the answer from the solution manual. Here is the question:

Problem: Suppose that $f: A \rightarrow B$ is any function. Then a function $g: B \rightarrow A$ is called a right inverse for $f$ if $f(g(y)) = y$ for all $y \in B$. Prove that if $f$ has a right inverse, $f$ is surjective.

Proof: Suppose $f$ has a right inverse. If $y \in B, f(g(y)) = y$, so $y \in$ ran $f$. Thus $f$ is surjective.

I get that in order for $f$ to be considered a surjective function, every point in its codomain $B$ must be defined by a point in its domain $A$. However, I don't understand how this is stated in the proof. Can someone please explain the logic of this proof?

• Given any $y \in B,\,$ let $x = g(y) \in A$. Then $f(x) = y$. Hence f is surjective. – steven gregory Jun 13 '16 at 3:31

Let $y$ be any point of $B$. We’re given that $g$ is a right inverse of $f$, so we know that $f\big(g(y)\big)=y$. Let $x=g(y)$; then $x\in A$, since $g:B\to A$, and $f(x)=y$. We’ve just shown that $y\in\operatorname{ran}f$: we’ve shown that $y$ is $f(x)$ for some $x\in A$. We even know one such $x$, namely, $g(y)$. Since we can do this for each $y\in B$, we’ve shown that $B\subseteq\operatorname{ran}f$. On the other hand, $f:A\to B$, so obviously $\operatorname{ran}f\subseteq B$. Combining results, we see that $\operatorname{ran}f=B$ and hence that $f$ maps $A$ onto $B$.