# Why does a left inverse not have to be surjective?

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?

• The book says the same. I quote: "If $f:A\to B$ has a left inverse, then there exists a $g:B\to A$ such that $g\circ f=id_A$. Commented Mar 10, 2014 at 15:40
• Yes, that's correct.It boils down to the definition of $\circ$. Commented Mar 10, 2014 at 15:43
• @GitGud- On a related note, why does the right inverse $g$ of $f$ not have to be injective? Say $f(a)=f(b)$ for $a\neq b$. Then $g(f(a))=g(f(b))$ will have two images. This is a contradiction. Commented Mar 10, 2014 at 16:00
• "clearly some points of $B$ are not mapped by $g$" Hmm, what makes you say that? Commented Mar 10, 2014 at 16:14
• Let's start from somewhere concrete. If $g\circ f = I_A$, then we are guaranteed $f$ is 1-1 and $g$ is onto, and we can conclude nothing else about $f$ and $g$. Now if $g$ also has a left inverse $h$, so that $h\circ g=I_B$ then we could (by the same token) conclude $g$ is 1-1 and $h$ is onto, and moreover that $f=h$. Commented Mar 10, 2014 at 16:17

$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$.

• @user126154- On a related note, why does the right inverse $g$ of $f$ not have to be injective? Say $f(a)=f(b)$ for $a\neq b$. Then $g(f(a))=g(f(b))$ will have two images. This is a contradiction. Commented Mar 10, 2014 at 15:58
• I don't understand your comment, could you explain better? (and also, are we talking of right or left inverses?) Commented Mar 10, 2014 at 16:01
• @user126154- In the question, we're talking about left inverses. Now, we're talking about right inverses. A right inverse has to be surjective. I'm asking why it does not have to be injective too. Let $g$ be the right inverse of $f$. Then $f:A\to B$ and $g: B\to A$. Commented Mar 10, 2014 at 16:04
• OK. In the case of right inverse, then yes, the right inverse need to be injective. As you proved. Commented Mar 10, 2014 at 16:09
• @algebraically_speaking A right-inverse clearly must be injective. Apart from being trivially shown, as user126154 did, it also follows from your question. After all, if $f$ has a right-inverse $g$, then $f$ is $g$'s left-inverse! Which, as your question states, must be injective!
– fgp
Commented Mar 10, 2014 at 16:46

Let $A = B = \mathbb{N}$ and let $$f(n) = n+1 \text{.}$$ Then $g(n) = n-1$ is obviously a left inverse since $(n + 1) - 1 = n$. Yet $f$ is not surjective - $f(\mathbb{N}) = \mathbb{N}\setminus\{0\}$.

You might object that, the way I defined it, $g$ isn't a function from $\mathbb{N} \to \mathbb{N}$, since $g(0)$ isn't defined. You're right of course, but that doesn't really matter, because $f(n) \neq 0$ for all $n \in \mathbb{N}$, so the value of $g(0)$ doesn't affect whether $g(f(n)) = n$ for all $n \in \mathbb{N}$. So you can just set $g(0) = 0$, and $g$ is still a left-inverse of $f$, and $f$ is still not surjective.

Also note that the corrected definition of $g$, i.e. $$g(n) = \begin{cases} n-1 &\text{if n \neq 0} \\ 0 &\text{otherwise} \end{cases}$$ is not injective - you have $g(1) = g(0) = 0$. And since $f$ is $g$'s right-inverse, it follows that while a function must be injective (but not necessarily surjective) to have a left-inverse, it doesn't need to be injective (but does needs to be surective) to have a right-inverse.

• 1. $0\notin\Bbb{N}$. 2. $g(n)$ is not a left inverse, as it does not act from $B$ to $A$. It acts from $B\setminus\{1\}\to A$ Commented Mar 10, 2014 at 15:41
• @algebraically_speaking For the purpose of this answer, $0 \in \mathbb{N}$. For 2. - yeah, I was a bit sloppy there, fixed it now.
– fgp
Commented Mar 10, 2014 at 15:43
• @algebraically_speaking Plus, the whole point is that the value of $g(0)$ is utterly irrelevant, since $0 \not\in f(\mathbb{N})$
– fgp
Commented Mar 10, 2014 at 15:44
• In spite of the fact that I agree with the idea, saying $0\in \mathbb N$ doesn't solve the problem. Now the OP can just ask about $g(-1)$. Of course the answer is the same. Commented Mar 10, 2014 at 15:46
• @GitGud True, but the updated answer now says "Just set $g(0)=0$". My point remains that obessing with $g(0)$ is a bit of a smoke-screen, because the value $0$ is never taken by $f$. Which is exactly the point here - if the codomain of $f$ is larger than the image of the domain, $f$ isn't surjective, yet might very well have a left-inverse.
– fgp
Commented Mar 10, 2014 at 15:54