[Math] Why does a left inverse not have to be surjective

functions

My book says:

Assume $A\neq 0$ and let $f:A\to B$ be a function. Then $f$ has a left inverse if and only if it is injective.

Let the left inverse of $f$ be $g$. Then we have $g\circ f=id_A$. Obviously $g:B\to A$. I wonder why $f$ does not have to be surjective. If $f$ is not surjective, then clearly some points of $B$ are not mapped by $g$, which disqualifies $g$ from being called a function!

Can someone please shed some light on this?

Best Answer

$f$ need not to be surjective because $g\circ f$ is defined even if the image of $f$ is not the whole domain of $g$.

Example. Let $A\subset B$ non empty, and $f:A\to B$ the inclusion, that is to say $f(x)=x$. Define the map $g:B\to A$ as follows. Let $a_0\in A$ any point (which exists because $A\neq\emptyset$) then set:

$$g(x)=x\qquad\text{ for } x\in A$$ $$g(x)=a_0\qquad \text{ for } x\notin A$$

$g$ is a left inverse of $f$.

Related Question