If every continuous function $f: A \rightarrow \mathbb{R}$ is bounded, then A is compact. I'm doing a metric spaces course and got stuck on the proposition:
If $A\subset\mathbb R^n,$ such that every continuous $f:A\to\mathbb R$ is bounded, then $A$ is compact.
I have a feeling that I want to show that if $A\subset\mathbb R^n$ is bounded and closed, then use Heine-Borel Theorem provides compactness. It just seems obvious and I seem to be going around in a circular argument.
 A: Since $A\subset \mathbb R^n$, then in order to show that $A$ is compact, it suffices to show that $A$ is bounded and closed.
$A$ is bounded. Clearly the function $f:A\to\mathbb R$, with $f(x)=\|x\|$ is continuous, and as it has to be bounded, then there exists an $M>0$, such that $f(x)=\|x\|\le M$, for all $x\in A$. But this means that $A$ is bounded.
$A$ is closed. If not, then there exists a sequence $\{x_n\}_{n\in\mathbb N}\subset A$, with $x_n\to x_0\not\in A$. Then the function $\,f:A\to\mathbb R$, with
$$
f(x)=\frac{1}{\|x-x_0\|},
$$
in continuous and unbounded. A contradiction, and hence $A$ is closed.
Altogether, indeed $A$ is compact.
Note. Another way to obtain contradiction, is by observing that the function $g(x)=\|x-x_0\|$ is also continuous, but it does not attain a minimum. The infimum of $f$ is equal to zero, while $f$ takes only positive values.
A: Let $B \subseteq \mathbb{R}$ be any bounded subset. Then "$B$ attains its bounds" means that $B$ is closed.
Call $C(A)= \{ f: \mathbb{R}^n \longrightarrow \mathbb{R} \mbox{ continuous functions} \} $. Then
$$A = \bigcap_{f \in C(A)} f^{-1}(f(A))$$
Since for all $f \in C(A)$ $f(A)$ is closed, $f^{-1}(f(A))$ is closed as well (because $f$ is continuous). So, $A$ is an intersection of closed sets, hence it is closed.
Finally, consider for all $i=1, \dots, n$ the continuous functions
$$\pi_i :A \longrightarrow \mathbb{R} \ \ \ \ \ (x_1, \dots, x_n) \mapsto x_i$$
Since all the sets $\{\pi_i(A) \}_{i=1}^n$ are bounded, then so is their product $\prod_{i=1}^n \pi_i(A) \subseteq \mathbb{R}^n$. But $A \subseteq \prod_{i=1}^n \pi_i(A)$, so it is bounded.
Being closed and bounded, $A$ is compact.
