Let $(X,d)$ be a metric space, $M\subseteq X$ and $f: M \to \mathbb{R}$ continuous. Show that:
If $M$ is compact, then follows from $\forall x \in M | f(x) < a$ that $\sup_{x\in M} f(x)<a$.
My try:
By $B_u(v)$ I refer to an open ball of radius $u$ and center point $v$.
As $f(x)<a$ there exists a $B_a(f(x))$.
As $f$ is continuous, there exists a $\delta >0$ so that $$f(B_\delta (x))\subseteq B_a(f(x)))$$ with $B_\delta (x) \subseteq M$
As $M$ is compact, it is also bounded and closed, what means, that its supremum exists and is also cointained in $M$.
We choose $\delta'=\sup (x\in M)$ and $\delta'<\delta$. Because $f$ continuous is, then for an $a' \in \mathbb{R}$ $$f(B_{\delta'} (x))\subseteq B_{a'}(f(x)))$$.
If we chose $a' = \sup_{x\in M} f(x)$, how can I proove that $a'<a$?
Is my approach in general right (I would appreciate any other suggestions)?
If $M$ was not compact, how could I proove that indeed $\sup_{x\in M} f(x)\leq a$?
We assume the well-known fact that for a metric space $(X,d)$ and $M\subseteq X$, $M$ is compact iff $M$ is sequentially compact.
We go back to your question. Consider the case that $M\neq\emptyset$. Let $A=\{f(x)\mid x\in M\},$ which is non-empty and bounded above by $a$, so $\sup A$ exists. Denote $l=\sup A$. For each $n\in\mathbb{N}$, $l-\frac{1}{n}$ is not an upper bound of the set $A$, so there exists $x_{n}\in M$ such that $f(x_{n})>l-\frac{1}{n}$. In this way, we obtain a sequence $(x_{n})$ in $M$. (Formally, we need to argue in this way: For each $n\in\mathbb{N}$, let $B_{n}=\{x\in M\mid f(x)>l-\frac{1}{n}\}$. Note that $B_{n}$ is non-empty because $l-\frac{1}{n}$ is not an upper bound of the set $A$. Now, $\{B_{n}\mid n\in\mathbb{N}\}$ is a family of non-empty sets, indexed by $\mathbb{N}$. By the Axiom of Choice (or, we can invoke a less powerful axiom: The Axiom of Countable Choice), there exists a map $\theta:\mathbb{N}\rightarrow\cup_{n}B_{n}$ such that $\theta(n)\in B_{n}$. Denote $x_{n}=\theta(n)$, then $\theta=(x_{n})$ is a sequence in $M$.)
Since $M$ is compact, $(x_{n})$ has a convergent subsequence $(x_{n_{k}})$ that converges to some point in $M$. Suppose that $x_{n_{k}}\rightarrow x_{0}\in M$. For each $k$, we have that $l-\frac{1}{n_{k}}<f(x_{n_{k}})\leq l$. Letting $k\rightarrow\infty$, by continuity of $f$, we obtain $l\leq f(x_{0})\leq l$. That is, $\sup A=l=f(x_{0})<a$.