15

Let $X$ be a compact metric space, show that a continuous function $f:X\rightarrow\mathbb{R}$ attains a maximum and a minimum value on $X$.

Attempt: So the important thing is that I have previously shown that such a function is bounded and that for compact $X$, $f(X)$ is compact given $f$ continuous. In $\mathbb{R}$, compact $\implies$ closed and bounded. So $f(X)$ is closed and contains its accumulation points, and it is bounded so $\exists \sup(A),\inf(A)$ and since closed $\implies \sup(A)\in A, \inf(A)\in A$.

Did I miss anything/make an unwarranted leap of logic?

Emir
  • 2,303

2 Answers2

55

Here’s an example of how the same argument could be written up nicely.

Since $X$ is compact and $f$ is continuous, $f[X]$ is a compact subset of $\mathbb{R}$ and therefore closed and bounded. Since $f[X]$ is bounded, it has both a supremum and an infimum, and since it is closed, $\sup f[X]\in f[X]$ and $\inf f[X]\in f[X]$. Thus, there are $x_0,x_1\in X$ such that $f(x_0)=\inf f[X]$ and $f(x_1)=\sup f[X]$; that is, $f$ attains its minimum and maximum values at $x_0$ and $x_1$, respectively.

Brian M. Scott
  • 631,399
  • Nice proof, how does this generalize to X is an arbitrary topological space? will the same proof hold? – grayQuant Oct 19 '15 at 03:35
  • 7
    @grayQuant: The proof actually used only the compactness of $X$; the hypothesis that $X$ is metric isn’t needed. If $X$ is not compact, however, there may be continuous real-valued functions on $X$ that do not attain at least one extremum. – Brian M. Scott Oct 19 '15 at 03:39
  • This has been bothering me for a while, to see that $f[X]$ is bounded implies $f[X]$ has both a supremum and infimum, we need the fact that $f[X]$ is nonempty, right? but if we take $X$ to be the empty set, then it is compact and $f$ is then the empty set, so it is continuous, so that $f[X]$ is also an empty set. Thanks. – hteica Jul 20 '20 at 13:06
  • 1
    @hteica: The default assumption is that spaces are not empty. – Brian M. Scott Jul 20 '20 at 17:13
  • @BrianM.Scott I see, I forgot this crucial fact. – hteica Jul 21 '20 at 18:42
  • @BrianM.Scott do you have an example of a function from a non-compact topological space to the real line that does not attain its max/min? – Crash Bandicoot Apr 08 '21 at 15:45
  • 1
    @LorenzoLotto: The identity function from $(0,1)$ to $\Bbb R$ is an example. For that matter, so is the identity function from $\Bbb R$ to $\Bbb R$. Any injection from $\Bbb N$ to $\Bbb R$ whose range does not have a smallest or largest element is another example. – Brian M. Scott Apr 08 '21 at 18:09
  • @BrianMScott sorry I did not specify the question I was looking for. I was looking for an example where $X$ is a generic non-compact topological space. We know that if $X$ is a noncompact metric space then there exists a function whose image is not closed. I was wondering if we can always construct such a function also in the case $X$ is a generic topological space. But I think this deserves a different question. Thanks anyways! – Crash Bandicoot Apr 08 '21 at 21:10
  • 1
    @CrashBandicoot: This is a very belated answer, since I only just realized that you never did ask the question separately. The question was in fact asked and answered somewhat earlier: we cannot always construct such a function. Indeed, there are even non-compact spaces on which every continuous real-valued function is constant. – Brian M. Scott Jan 15 '23 at 03:50
  • Even if belated, I appreciated a lot your answer! Thank you very much! – Crash Bandicoot Jan 16 '23 at 07:43
  • @CrashBandicoot: You’re very welcome! – Brian M. Scott Jan 16 '23 at 19:31
5

Your argument is fundamentally sound, but you have to assume that your metric space is nonempty. Here is a direct proof that requires no other results (the proof generalizes, like yours, to arbitrary topological spaces):

Let $X$ be a nonempty metric space and $f:X\to\mathbb{R}$ a continuous function without a maximum. Then $X$ has an open cover without a finite subcover.

Proof:

  1. Suppose $f(X)$ is unbounded. Then $\big\{f^{-1}\big((-\infty, n)\big):n\in\mathbb{N}\big\}$ is an open cover without finite subcover.

  2. Suppose $f(X)$ is bounded, with supremum $s$. Since $f$ has no maximum, $s\notin f(X)$ and $\big\{f^{-1}\big((-\infty, s-1/n)\big):n\in\mathbb{N}\big\}$ is an open cover without finite subcover.