TITLE: An example of a complete metric space $X$ and a function $f: X \to X$ which is a continuous bijection such that $f^{-1}$ is not continuous.
QUESTION [5 upvotes]: Give an example of a complete metric space $X$ and a function $f: X \to X$ which is a continuous bijection such that $f^{-1}$ is not continuous. This is an offshoot of the following: Finding an (easy) example of a bijective continuous self mapping whose inverse is not continuous
There are examples where the domain and range are not the same and examples where completeness is not a requirement. Of course, OMT shows that we cannot take  a linear map between Banach spaces.  I tried some non-linear maps on Banach spaces but I didn't succeed in finding an example. Thank you for your time.

REPLY [3 votes]: One can construct also examples using nonlinear maps between Banach spaces. In fact any infinite-dimensional space will do. I copied this from my (edited) answer in Easy example of a bijective continuous self mapping whose inverse is discontinuous.
First we note that we cannot have any such counterexample in any finite-dimensional normed space. Indeed, they are all homeomorphic to some $\mathbb{R}^n$ and the invariance of the domain theorem (https://en.wikipedia.org/wiki/Invariance_of_domain) tells us that any continuous, injective map $f: \mathbb{R}^n \rightarrow \mathbb{R}^n$ is a homeomorphism on its image.
In
Van Mill, J. (1987). Domain Invariance in Infinite-Dimensional Linear Spaces. Proceedings of the American Mathematical Society, 101(1), 173-180. doi:10.2307/2046571
it is claimed that we can construct such an example in any infinite-dimensional normed space $X$. The only thing one needs to construct is a continuous map $\lambda : S \rightarrow (0,1]$ with $\inf_{x\in S} \lambda(x) =0$, where $S$ is the unit sphere in $X$. Then one considers the map
$$f: X \rightarrow X, \ f(x) = \begin{cases} \lambda\left( \frac{x}{\Vert x \Vert} \right) x,& x\neq 0, \\
0,& x=0.
\end{cases}$$
The function $f$ is clearly bijective and continuous (as $\lambda$ is continuous and does not vanish). To see that it is not a homeomorphism we show that it is not an open map. This follows from the fact that $f$ preserves all halfrays starting in zero and that by construction that we find halfrays that shrink as much as we like (as $\inf_{x\in S} \lambda(x) =0$). So for any bounded set $A\subseteq X$ we have $0\notin \operatorname{int}(f(A))$ and thus $f$ is not an open map and hence not a homeomorphism.
We are left to show that such a $\lambda$ really exists. As we are in infinite-dimensions, by the Riesz lemma (https://en.wikipedia.org/wiki/Riesz%27s_lemma) there exists a sequence $(x_n)_{n\in \mathbb{N}} \subseteq S$ such that $\Vert x_n - x_m \Vert \geq \frac{1}{2}$ for all $n\neq m$. Now we make them slightly bigger, i.e. we define $y_n:= \left( 1+ \frac{1}{n+4} \right) x_n$. Then we have that $dist(S, y_n)=1/(n+1)$ and for $n\neq m$
$$\Vert y_n - y_m \Vert \geq \Vert x_n - x_m \Vert - \frac{1}{n+4} - \frac{1}{m+1} \geq \frac{1}{2} - \frac{1}{4} - \frac{1}{5} = \frac{1}{20}. $$
Hence, $Y:=\{ y_n \ : n\in \mathbb{N} \}$ is discrete and hence closed. Now we define (inspired by the proof of the Urysohn lemma)
$$ g: S \rightarrow [0,\infty), \ g(x) := dist(x,Y). $$
Hence, $g$ is continuous and $g(x) = 0$ iff $x\in \overline{Y}=Y$. This shows that $g$ is continuous and never vanishes. Furthermore, we have
$$g(x) = dist(x,Y) \leq \Vert x - y_0 \Vert \leq \Vert x \Vert + \Vert y_0 \Vert  
\leq 1 + \left( 1 + \frac{1}{4}\right) = \frac{9}{4}.  $$
Thus, we may pick $\lambda = \frac{4}{9} g$.