# Does there exist a nonbijective function with both a left and right inverse?

I'm reading through Dummit and Foote, and they have the following statements about functions and inverses.

Given a map $$f: A\to B$$ :

• The map $$f$$ is injective if and only if $$f$$ has a left inverse.
• The map $$f$$ is surjective if and only if $$f$$ has a right inverse.
• The map $$f$$ is a bijection if and only if there exists $$g: B\to A$$ such that $$f\circ g$$ is the identity map on $$B$$ and $$g\circ f$$ is the identity map on $$A$$.

Where $$f$$ has a left inverse if there exists a function $$g: B\to A$$ such that $$g\circ f$$ is the identity on $$A$$ and $$f$$ has a right inverse if there exists a function $$h: B\to A$$ such that $$f\circ h$$ is the identity on $$B$$.

The relation between inverses and injectiveness/surjectiveness/bijectiveness make sense to me intuitively. But in particular, the bijection case requires that the right and left inverse be the same. Does this mean that there exists a function $$f$$ that is not a bijection which has distinct left and right inverses? Or would such a function require a quantifier of the domain of its inverses? The only thing I can tell is that where the domain of the left and right inverses overlap, they must be equal. If the overlap of the domains is $$B'$$, then $$f$$ must be injective on $$B'$$ (because it has a left inverse in that domain), and $$f$$ must also be surjective (because it has a right inverse in that domain). Therefore, $$f$$ is bijective on $$B'$$ and $$\forall a\in B', g(a)=h(a)$$. What else can be concluded?

If $$f:A\to B$$, then a left inverse $$l:B'\to A$$ for some $$B'\subseteq B$$ has to satisfy $$l\circ f=\operatorname{id}_A$$, which means it has to be defined on the image of $$f$$ (so $$B'\supseteq f(A)$$). If $$f$$ has a right inverse $$r:B\to A'$$ for some $$A'\subseteq A$$ such that $$f\circ r=\operatorname{id}_B$$, then in particular, $$f$$ is surjective on $$B$$, which forces that the domain of the left inverse has to be $$B'=B$$. Moreover, the existence of the left inverse will force $$A'=A$$: as the left inverse makes $$f$$ injective, it follows that any $$a\in A$$ is the unique element that realises $$b := f(a)\in B$$, so $$r(b)=a$$ is forced to ensure $$f(r(b))=b$$; in other words, any $$a\in A$$ lies in the image of $$r$$, forcing $$A'=A$$.

Finally, if a function $$f:A\to B$$ has a left inverse $$l:B\to A$$ and a right inverse $$r:B\to A$$, then in fact $$r=l$$ and $$f$$ is bijective. Indeed, this follows by the computation $$l = l\circ\operatorname{id}_B = l\circ(f\circ r) = (l\circ f)\circ r = \operatorname{id}_A\circ r = r$$ showing that a left inverse and right inverse must always coincide when they both exist.

Conclusion: If $$f:A\to B$$ has a left inverse $$l:B'\to A$$ for some $$B'\subseteq B$$ and a right inverse $$r:B\to A'$$ for some $$A'\subseteq A$$, then $$B'=B$$, $$A'=A$$, $$r=l$$, and $$f$$ is bijective.

Remark. The domain of a left inverse technically only has to be defined on the image of $$f$$, but we can extend it to an arbitrary superset of this, and it would be free to act however it likes on this set, and a right inverse would be unable to control this. For example, let $$f:\{1,2\}\to\{1,2\}$$ be the identity, then we can define a left inverse $$l:\{1,2,\dots,n\}\to\{1,2\}$$ that sends all $$k\geq2$$ to $$2$$. However, we can't do much in the case of a right inverse: the image of $$r$$ has to fit in the domain of $$f$$ or else the composite $$f\circ r$$ will not be well-defined. Therefore, perhaps a more correct formulation of the conclusion is:

Conclusion (revised): If $$f:A\to B$$ has a left inverse $$l:B'\to A$$ for $$B'\supset f(A)$$ and has a right inverse $$r:B\to A'$$ for $$A'\subseteq A$$, then

• $$A'=A$$
• $$f(A)=B$$
• $$f$$ is bijective with inverse $$l|_B=r:B\to A$$

Remark. I should mention that left and right inverses usually have their co/domains set by definition based on the co/domain of $$f:A\to B$$ (namely, they're defined to be maps $$B\to A$$) because being more flexible doesn't provide any additional benefit in the context of inverses of $$f:A\to B$$. The goal of a left inverse is to provide a rule for converting elements $$b\in B$$ into elements $$l(b)\in A$$ in a way that "undoes" $$f$$; that is, $$f(a)$$ gets sent back to $$a$$. If we look beyond elements of $$B$$ when defining $$l$$, this is beyond the scope of $$f$$ and what we do here is arguably irrelevant.