\[ \newcommand{\e}{\mathrm{e}} \DeclareMathOperator{\id}{id} \]

A function \(f:X\to Y\) is injective if and only if it has a left inverse, i.e. there is a function \(g:Y\to X\) such that \(g\circ f=\id_X\).

Proof

Let \(g\) be the left inverse of \(f\). Then for \(x_1,x_2\in X\) applying \(g\) on \(f(x_1)=f(x_2)\) yields \(x_1=x_2\).

If \(f\) is injective define \(g:Y\to X\) on \(f(X)\) with \(g(y)=f^{-1}(y)\) which is unique since \(f\) is injective. For all \(y\in Y\setminus f(X)\) set \(g(y)=x_0\) for some \(x_0\in X\).