# If every real-valued continuous bounded function on a metric space $M$ attains its maximum (or minimum), then $M$ is compact

Suppose that $(M,d)$ is a metric space. I want to show if every continuous bounded function $f:M \rightarrow \mathbb{R}$ achieves a maximum or minimum, them $M$ is compact.

I found a similar assertion in the question If every real-valued continuous function is bounded on $X$ (metric space), then $X$ is compact. The trick of proof of that assertion is to assume that $M$ is not compact and then make an unbounded function, but here the function must be bounded. What should I do?

• $$t \mapsto \frac{t}{1+\lvert t\rvert}$$ – Daniel Fischer May 8 '15 at 15:26
• @DanielFischer so why this function doesn't get its extremum? – F.K May 8 '15 at 15:33
• That function is not defined on $M$, but on $\mathbb{R}$. But you can use it to get a bounded function that doesn't attain its maximum (or minimum) if you have an unbounded function on $M$. You can of course also directly modify the construction. – Daniel Fischer May 8 '15 at 15:36