$(X,d)$ is a metric space such that every continuous function $f: X \rightarrow \mathbb{R}$ is bounded. Prove $X$ is complete.

I'm practicing an exam question and would appreciate having my proof verified.

Let $$(x_n)$$ be a Cauchy sequence in $$X$$. Suppose $$f: X \rightarrow \mathbb{R}$$ is a continuous (and therefore bounded) function.

Then, $$(f(x_n))$$ is a bounded sequence in $$\mathbb{R}$$. By Bolzano-Weierstrass, there exists a subsequence $$(f_{n_k})$$ that converges to some $$y \in \mathbb{R}$$. Therefore, there exists a ball $$B$$ of radius $$\epsilon$$ centered at $$f(x_{n_k})$$ that contains $$y$$ and all $$f(x_{n_j})$$ for $$j \geq k$$.

Let $$B' = f^{-1}(B)$$ denote the preimage of $$B$$ in $$X$$. By the continuity of $$f$$, $$B'$$ is an open ball of in $$X$$ which contains all $$x_{n_j}$$ for $$j \geq k$$ and $$f^{-1}(y) =: x$$. Thus, the subsequence $$x_{n_k}$$ converges to $$x \in X$$.

Lastly, this implies that $$x_n$$ converges to $$x$$ since $$d(x_n, x) \leq d(x_n, x_{n_k}) + d(x_{n_k}, x) < \epsilon$$ by the triangle inequality.

• Some comments: (1) $B’$ is an open set in $X$ but needs not to be an open ball. (2) You say that $x:=f^{-1}(y)$, but what if $f$ is not injective? (3) the hypothesis is that any continuous function from $X$ to $\Bbb{R}$ is bounded, however in your proof you only use that there is one continuous bounded function. Aug 26 '19 at 22:23
• Stronger conclusion: $X$ is compact: if $X$ is not compact the there is a sequence $\{x_n\}$ with no limit point. Define $f(x_n)=n$. Then $f$ is continuous on $\{x_n: n \geq 1\}$ and it can be extended to a continuous function on $X$ by Tietze's Theorem. Aug 26 '19 at 23:39

$$B'$$ is not an open ball. It's open, yes, but it doesn't have to be a ball. Also, $$f^{-1}(y)$$ can have several values at once, and you don't really know that any of them are the limit of the $$x_n$$.
Here is one approach, showing the contrapositive instead (I always consider the contrapositive; some times the proof for one variation comes much easier than the proof for the other). Which is to say, if $$X$$ is not complete, then there is a continuous, unbounded function $$X\to\Bbb R$$.
Assume $$X$$ is not complete. Let $$x_n$$ be a Cauchy sequence in $$X$$ which is not convergent. Then define the function $$f:X\to\Bbb R$$ as follows: $$f(x)=\frac1{\lim_{k\to\infty}d(x,x_k)}$$ It is well-defined and continuous (this must be shown), but $$f(x_n)$$ goes to $$\infty$$ as $$n$$ increases, so it isn't bounded (this must also be shown).
• Actually $X$ has to be compact and the proof is even simpler. Aug 26 '19 at 23:40