Condition for inverse function. I found this line about the condition of inverse function at Inverse function.Here is the line.

In the verification step we technically really do need to check that both $\left( {{f} \circ f^{-1}} \right)\left( x \right) = x$ and $\left( {{f^{ - 1}} \circ f} \right)\left( x \right) = x$
are true. For all the functions that we are going to be looking at in this course if one is true then the other will also be true. However, there are functions (they are beyond the scope of this course however) for which it is possible for only one of these to be true. This is brought up because in all the problems here we will be just checking one of them. We just need to always remember that technically we should check both.

Can someone give me an example of such a function?
 A: Consider $f:\mathbb{R}\to\mathbb{R}$ given by $f(x) = x+1$ for $x\geq 0$ and $f(x)=x-1$ for $x<0$
Now consider  $g:\mathbb{R}\to\mathbb{R}$ given by $g(x)=x-1$ for $x\in[1,\infty)$, $g(x)=x+1$ for $x\in (-\infty,-1)$ and $g(x)=1$ otherwise.
I suggest you graph these functions.
Then $(g\circ f)(x)=x$ for all $x\in\mathbb{R}$ but $(f\circ g)(0)=f(1)=2$.
A: Indeed, $\tan(\tan^{-1} x)=x$ is true for all real $x$, but $\tan^{-1}(\tan x)=x$ is only true for $x\in(-\frac {\pi}{2}, \frac {\pi}{2})$. In general, both the conditions will simultaneously hold only in the intersection of the principal domain of $f(x)$ where it is bijective, with the domain of $f^{-1}(x)$.
One might say a similar thing for $f(x)=e^x$ and $g(x)=f^{-1}(x)=\ln x$.
$g(f(x))=x$ is true for all real $x$, but $f(g(x))=x$ holds only for $x\in (0,\infty)$.
A: One cool example could be taken from functions that takes other functions as an argument. This is not an example from functions of a real value, so it might not be really what you’re expecting - but I do think it’s interesting!
Let $D: C_{\infty}(\mathbb{R}, \mathbb{R}) \rightarrow C_{\infty}(\mathbb{R}, \mathbb{R}) $ and $I: C_{\infty}(\mathbb{R}, \mathbb{R}) \rightarrow C_{\infty}(\mathbb{R}, \mathbb{R}) $ such that:
$$\forall f \in C_{\infty}(\mathbb{R}, \mathbb{R}), D(f)=f’$$
$$\forall f \in C_{\infty}(\mathbb{R}, \mathbb{R}), I(f)=\int_0^x f(t)dt$$
Note here that D and I are respectively the derivative and the antiderivative operators. Now, we could expect that one is the other’s reciprocical. But... let’s take any $f \in C_{\infty}(\mathbb{R}, \mathbb{R})$, and $F$ a primitive of $f$. We have:
$$D \circ I (f)=D(\int_0^x f(t)dt)=D(F(x)-F(0))=f$$
We see here that $D \circ I = Id$. However:
$$I \circ D (f)=I(f’)=\int_0^x f’(t)dt=f(x)-f(0)$$
So, if $f(0) \neq 0$, we don’t have $I \circ D (f)=f$ - which explains why antiderivatives are only defined within a constant!
A: In general, we have:
$f:X \to Y$ is injective if and only if exists $g:Y \to X$ such that $g(f(x))=x$. That is $f$ has a left inverse .
$f:X \to Y$ is surjective if and only if exists $g:Y \to X$ such that $f(g(x))=x$. That is $g$ has a right inverse.
For a function to have an inverse you need it to be bijective, that is, injective and surjective. So in order to find the examples you are looking for you need to find functions that are injective but not surjective  or surjective but not injective.
Take for example,  $f:\Bbb R\to\Bbb R^{\ge0}, f(x)=x^2$. It is surjective but not injective. The function $g:\Bbb R^{\ge 0}\to \Bbb R, g(x)=\sqrt{x}$ satisfies $f(g(x))=x$ for all $x$ in the domain of $g$, but $g(f(x))=\sqrt{x^2}=|x|\ne x$ for $x<0$. So $f$ has a right inverse, but not a left one.
Notice that this is also gives and example in the other direction: $g$ is injective but not surjective. So $g$ has a left inverse but not a right one.
Notice that the domain and codomain of the functions are very important. If we change the domain of $f$ and codomain of $g$ to be $\Bbb R^{\ge0}$, then $f$ and $g$ becomes bijective and are inverses of each other.
A: $f,f'$ can be swapped.
A reflection about $x=y$ when reflected for second time about $=y$ gets back $x$.
