I have just proved the following:
$f: X \to Y$ and $g: Y \to X$, also $g \circ f = f \circ g$ is the identity function, then $g$ is the inverse function for $f$.
I am trying to see that in the theorem above just "$g \circ f $ is the identity function" or "$f \circ g$ is the identity function" is not enough.
So am looking for examples of $X,Y,g,f$ such that only one equality is true, and $g$ is not the inverse function for $f$.
What I found so far is: $X = \{x^*\}$, $Y$ is a set such that $|Y| >1$, $f(x^*)=y^*$ and $g(y)=x^*, \forall y \in Y$, then $g \circ f$ is the identity function, $f \circ g$ is not the identity function and $f$ does not have an inverse function.
I am looking for an example (if any exists) such that $X =Y$.
Edit
In my example $f$ does not have the inverse function at all, so also would be good to find an example (where possibly $X \ne Y$) $f$ has an inverse but it is not $g$.
For an example in which $X=Y$, we can take $X=Y=\mathbb{N}$, $f:\mathbb{N}\to\mathbb{N}$ defined by $f(n)=n+1$ and $g:\mathbb{N}\to\mathbb{N}$ defined by $$g(n)=\begin{cases}n-1 &\text{if $n\neq 0$}\\ 0 & \text{if $n=0$}\end{cases}$$
This function satisfies that $g\circ f=id_{\mathbb{N}}$, but $f$ neither $f$ nor $g$ are invertible since $f$ is not surjective and $g$ is not injective.
Now, if $X=Y$, $g\circ f=id$ and $f$ is surjective, then $f$ is bijective and you will necessarily have that $g=f^{-1}$.