Given $g : N \to \mathbb{R}$ is continuous $\iff$ $g \circ f: M \to \mathbb{R}$ is continuous, Show $f : (M,d) \to (N, \rho)$ is a homeomorphism. I am currently finishing up a the chapter on homeomorphisms in my textbook for a class on metric spaces and before I start the next section, I wanted to have my work checked on the following problem. Note that $(M, d)$ and $(N, \rho)$ are metric spaces and $f:(M, d) \to (N, \rho)$ is bijective:

Given $g : N \to \mathbb{R}$ is continuous $\iff$ $g \circ f: M \to \mathbb{R}$ is continuous, Show $f : (M,d) \to (N, \rho)$ is a homeomorphism.

My work:

Given that $g \circ f$ is continuous, we know that this implies $g$ is continuous. Also, we know that that $f$ is continuous just by the definition of what it means for $g \circ f$ to be continuous in the first place. By the continuity of $f$, given $(x_n)$ in $M$ and a point $x \in M$: $x_n \to x$ in $M \implies$ $f(x_n) \to f(x)$ in $N$. Therefore, by continuity of $g \circ f$, $g(f(x_n)) \to g(f(x))$ in $\mathbb{R}$. However, by knowing that for every real valued continuous function on a metric space $(M,d)$, if $g(f(x_n)) \to g(f(x))$ in $\mathbb{R}$ $\implies$ $x_n \to x$ in $M$. So we get that $g(f(x_n)) \to g(f(x)) \iff x_n \to x$. So putting $f(x_n) \to f(x) \implies$ $x_n \to x$ together with $x_n \to x  \implies f(x_n) \to f(x)$ (what we started with) we get $x_n \to x  \iff f(x_n) \to f(x)$. So $f$ is a homeomorphism.
Is this conclusion correct? I feel as if I may have used a little too much "hand waiving", but I wanted to make sure.
 A: Let $C$ be closed in $N$. Then let $g: N \to \Bbb R$ be the continuous function $g(x)=d(x,C)$. We know that $g \circ f$ is continuous and $f^{-1}[C] = (g \circ f)^{-1}[\{0\}]$ because $C = g^{-1}[\{0\}]$ and so $f^{-1}[C]$ is closed in $M$. This shows continuity of $f$. To see closedness of $f$ (which finishes the proof as $f$ is a bijection by assumption), try to apply the same idea to the inverse function of $f$.
A: There are a few problems with your proofs. For example,

we know that that $f$ is continuous just by the definition of what it means for $g\circ f$ to be continuous in the first place.

Except if I am missing something, this is not the definition of continuity of $f$. If it is a consequence, it should be proved. But it seems that your are claiming that the continuity of $g\circ f$ implies the continuity of $f$... which is exactly what the problem ask you to prove.

given $(x_n)$ in $M$ and a point $x \in M$: $x_n \to x$ in $M$ $\implies$ (...) $\implies$ $x_n \to x$ in $M$.

I am not sure what you are trying to do here. Maybe you intended to prove an equivalence, that is a double implication but it looks like a circular reasoning.

$x_n \to x$ in $M \implies$ $f(x_n) \to f(x)$ in $N$.

This is a consequence of the continuity of $f$. Since your goal is to prove that $f$ is continuous, you cannot use that fact.

we get that $g(f(x_n)) \to g(f(x)) \iff x_n \to x$

That's clearly false. If $h$ is a continuous function, $x_n\to x$ implies that $h(x_n)\to h(x)$. But the converse is false. Consider a constant function $h$ for example.

I think the main problem is how the theorem you are trying to prove is stated. As written,

Given $g : N \to \mathbb{R}$ is continuous $\iff$ $g \circ f: M \to \mathbb{R}$ is continuous, Show $f : (M,d) \to (N, \rho)$ is a homeomorphism.

makes little sense to me. It seems that, in addition of $f$ being bijective, $g\circ f$ has to be continuous for one continuous function $g$ ("Given $g$...") for $f$ to be a homeomorphism.
Let's rewrite the theorem:

Let $(M,d)$ and $(N,\rho)$ be two metric spaces and $f:(M,d)\to(N,\rho)$ a bijective function. Assume that, for every function $g:(N,\rho)\to \mathbb R$, $g$ is continuous if and only if $g\circ f$ is continuous. Then $f$ is a homeomorphism.


Idea for the proof: there is certainly other ways to prove the theorem but most proofs of a function being a homeomorphism will check three boxes:

*

*Show that $f$ is bijective;

*Show that $f$ is continuous;

*Show that $f^{-1}$ is continuous.

Alternatively, you can prove that $f$ and $f^{-1}$ are open as an alternative to points $2$ and $3$ (using that a bijective application is continuous if and only if its reciprocal is open).
Now, the point $1$ is a hypothesis, so nothing to prove here. Note that if $f$ satisfies the property

for every function $g:(N,\rho)\to \mathbb R$, $g$ is continuous if and only if $g\circ f$ is continuous.

then $f^{-1}$ also satisfies it (for functions $g:(M,d)\to \mathbb R$). So only the point 2 should be proved.
Finally, to prove that $f$ is continous in this setting, you can use the various definitions/characterisations of continuity you know. Since you started with sequences, let's use sequences. Precisely,

$f$ is continuous if and only if for every sequence $\{ x_n \}$ that converges to $x$ in $M$, the sequence $\{f(x_n)\}$ converges to $f(x)$ in $\mathbb R$.

Let's consider a sequence $\{x_n\}$ of elements of $M$ that converges to $x$ in $M$. We put $y_n=f(x_n)$ and $y=f(x)$. From what precedes, we want to show that $y_n \to y$. For, consider the function $g$ defined on $M$ by $g(x)=d(x,y)$. The function $g$ is continuous, so $g\circ f$ is continuous. Therefore, $g\circ f(x_n) \to g\circ f(x)=d(f(x),y)=d(y,y)=0$. But $g\circ f(x_n)=g(y_n)=d(y_n,y)$, so by definition, $y_n\to y$.

The proof (nicely wrapped up):

The function $f$ is bijective. Let's prove it is continuous. For, we consider a sequence $\{x_n\}$ of elements of $M$ that converges to $x$ in $M$. We put $y_n=f(x_n)$ and $y=f(x)$. We claim that $y_n$ converges $y$. Indeed, consider the function $g$ defined on $M$ by $g(x)=d(x,y)$. The function $g$ is continuous, so $g\circ f$ is continuous by assumption. Therefore, $g\circ f(x_n)$ converges to $g\circ f(x)=d(f(x),y)=d(y,y)=0$. But $g\circ f(x_n)=g(y_n)=d(y_n,y)$, so by definition, $y_n$ converges to $y$.
Similarly, $f^{-1}$ is continuous (since it satisfies the same property as $f$). As a conclusion, $f$ is bijective, continuous and with a continuous inverse function, so $f$ is a homeomorphism. $\square$

To be complete, let's show that, under the conditions of the problem, $f^{-1}$ satisfies

if $h$ is a function from $M$ into $\mathbb R$, then $h$ is continuous if and only if $h\circ f^{-1}$ is continuous.

Let $h$ be a function from $M$ into $\mathbb R$. We put $g=h\circ f^{-1}$. Remark that $g$ is a function from $N$ into $\mathbb R$.
If $h$ is continuous, then $h=g\circ f$ is continuous. By assumption on $f$, this means that $g=h\circ f^{-1}$ is continuous.
Conversely, if $g=h\circ f^{-1}$ is continuous, we know that $g\circ f$ is also continuous. But $g\circ f=h$, so $h$ is continuous.
