Can a non-surjective function have an inverse? I am confused by the many conflicting answers/opinions at e.g. 1, 2. Many claim that only bijective functions have inverses (while a few disagree).

So, for example, does $f:\{0\}\rightarrow \{1,2\}$ defined by $f(0)=1$ have an inverse?
According to the view that only bijective functions have inverses, the answer is no.
But it seems to me that $f$ does (or "should") have an inverse, namely the function $f^{-1}:\{1\} \rightarrow \{0\}$ defined by $f^{-1}(1)=0$.
 A: It depends on how you define inverse. There are three kinds of inverses in this context: left-sided, right-sided, and two-sided.


*

*$f^{-1}$ is a left inverse for $f$ if $(f^{-1} \circ f)(x) = x$

*$f^{-1}$ is a right inverse for $f$ if $(f \circ f^{-1})(x) = x$

*$f^{-1}$ is a two-sided inverse for $f$ if it is both a left- and right-sided one, i.e. $(f^{-1} \circ f)(x) = (f \circ f^{-1})(x) = x$
As it happens:


*

*If $f$ has a left inverse, $f$ is injective

*If $f$ has a right inverse, $f$ is surjective

*If $f$ has a two-sided inverse, $f$ is bijective


Throughout this discussion, I've called the third case a two-sided inverse, but oftentimes these are just referred to as "inverses." This convention somewhat makes sense. Let $f : S \to T$, and let $T = \text{range}(f)$, i.e. the codomain of $f$ is precisely the set of outputs for the function. Then, obviously, $f$ is surjective outright. Then in some sense it might be meaningless to talk about right- or left-sided inverses, since once you have a left-sided inverse and thus injectivity, you have bijectivity outright. And really, between the two when it comes to invertibility, injectivity is more useful or noteworthy since it means each input uniquely maps to an output.
Personally I'm not a huge fan of this convention since it muddies the waters somewhat, especially to students just starting out, but it is what it is.
Anyhow, let's address your example:

So, for example, does $f:\{0\}\rightarrow \{1,2\}$ defined by $f(0)=1$ have an inverse?

It has a left inverse, but not a right inverse. This means you can find a $f^{-1}$ such that $(f^{-1} \circ f)(x) = x$. More intuitively, you can always find, for any element $b$ which is mapped to, a unique element $a$ such that $f(a) = b$. (This as opposed to the case of non-injectivity, in which case you only have a set of elements that map to that chosen element of the codomain.)
So in this sense, if you view an inverse as being "I can find the unique input that produces this output," what term you really want is "left inverse." But if you mean an inverse as "I can compose it on either side of the original function to get the identity function," then there is no inverse to any function between $\{0\}$ and $\{1,2\}$.
