When does a function have an inverse? I have been told that a function has an inverse if it is one-to-one or injective, but how can we rigorously prove this?  I have been struggling to find a proof for days.  
 A: If you have a function $f\colon X\subset\mathbb{R}\to Y\subset\mathbb{R}$, the definition of inverse function is some $g$ such if $\color{red}{f(x)=y\Rightarrow g(y)=x\mbox{ or }f\circ g= g\circ f =id}$
How to get this? suppose that there are $x_1,x_2\in X$ such $f(x_1)=f(x_2)=y_0$ then the "inverse function $g$" what would do with $g(y_0)$? this is why we need $f$ be inJective (or one-to-one)
Then if we have some $y_1\in Y$ such no exists some $x\in\ X$ with $f(x)=y_1$ what should we do with $g(y_1)$? That's why we need $f$ be surjective.
$\therefore$ We need $f$ be bijective.
A: 
A function $f:X\to Y$ is a subset of the Cartesian product $X \times Y$ subject to the following condition: every element of $X$ is the first component of one and only one ordered pair in the subset.

Now, suppose $f$ is one to one and onto.
Consider $f^{-1}:Y\to X$, defined as $f^{-1}(y)=x \iff f(x)=y$ (or in other words, $(y,x)\in f^{-1} \iff (x,y)\in f$). Now, for every $y\in Y$, there exist at least a $x\in X$ such that $f(y)=x$ since it is onto.
Uniqueness of such ordered pair $(y,x)$ is assured by the fact that $f$ is one-one.
Hence $f^{-1}$ is clearly a function by definition.
A: This is not "the proof" that you might be looking for, but just to help you think about it. A function $y = f(x)$ has an inverse if there exists another function $y = g(x)$ such that for all $x$ $f(g(x)) = x$ and $g(f(x)) = x$. (It is possible that only one of these formulas hold. In that case we would talk about right and left inverses.) 
If a function is not injective, then there are two distinct values $x_1$ and $x_2$ such that $f(x_1) = f(x_2)$. In that case there can't be an inverse because if such a function existed, then 
$$
x_1 = g(f(x_1)) = g(f(x_2)) = x_2.
$$
Likewise, if a function is injective, then it does have an inverse defined by $g(x)$ is that unique number $x'$ satisfying that $f(x') = x$. You, of course, have to be careful about domains and ranges.
