# Every Continuous Function Attains Maximum Implies Compact

Let $K$ be a compact metric space, and let $A \subset K$. Prove that $A$ is compact if and only if, for every continuous function $f:K \to \mathbb{R}$, there exists a $q \in A$ so that $$f(q) = \max_{a \in A} \{f(a)\}.$$ i.e. $f$ attains its maximum on the restriction to $A$.

Here's an attempt:

The forward direction is a standard theorem.

Suppose conversely every restriction attains its maximum on $A$. Let $\rho \in \overline{A}$. We shall show $\rho \in A$ and therefore $A$ is closed, and being a subset of a compact space, compact.

Suppose $\rho \notin A$.

Let $\{a_n\}_{n \in \mathbb{N}} \to \rho$. There exists a continuous function $f: K \to \mathbb{R}$ which attains its maximum at $\rho$
(for example, $d:A \to \mathbb{R}$ with $d: x \mapsto -d(x,\rho)$).
In particular, $f: \overline{A} \to \mathbb{R}$ is continuous and has a maximum at $\rho$. Therefore, given $\epsilon >0$, there exists $\delta >0$ so that $f(B_\delta(\rho)) \subset B_\epsilon (f(\rho)).$ Choose any $a_{n_1} \in B_\delta(\rho)$. Then, we may take $0 < \tilde{\epsilon} < \epsilon$ and $0< \tilde{\delta}< d(a_{n_1},\rho)$ so that, given $a_{n_2} \in B_{\tilde{\delta}}$, $f(a_{n_2}) > f(a_{n_1})$. Repeating this process indefinitely, we see that $f$ cannot attain a maximum on $a$, a contradiction. We conclude $\rho \in A$, so that $A$ is compact.

Any issues? Other methods of proof are welcome. In fact, it'd be great to see alternatives.

I've never seen this result anywhere, so I thought it interesting.

• 'There exists a continuous function f:K→ℝ which attains its maximum at ρ.', how do you know that? – azureai Sep 14 '15 at 8:42
• @see Is there a good way to formally show this? – Anthony Peter Sep 14 '15 at 8:48
• @see : $f(x) = -d(x, p)$ is one such function. – user99914 Sep 14 '15 at 8:49
• @JohnMa Ah yes, that would work fine. If you have other examples, I'm open to see them. – Anthony Peter Sep 14 '15 at 8:51