Show that $\sup_{x\in D}|f(x)| =\sup_{x \in X}|f(x)|$. Let $(X,d)$ metric space and $D\subseteq X$ dense subset of $X$. If $f:(X,d)\to \mathbb{R}$ continuous and bounced, show that $$\sup_{x\in D}|f(x)|=\sup_{x \in X}|f(x)|.$$
I tried the following thought :
We khow that exists $(x_{n})\subseteq X$ with $|f(x_{n})|\to \sup_{x\in X}|f(x)|$ and $(d_{n})\subseteq D$ with $d(x_{n},d_{n})\to 0$.If we show that $|f(x_{n})|-|f(d_{n})|\to 0$ or one subsequense of $(x_{n}),(d_{n})$ satisfies the previous relation then we have that $\sup_{x\in X}|f(x)\leq \sup_{x \in D}|f(x)|$ and will have proof the claim. My thought could be right and if not how can we proof this claim ?
 A: Obviously $\sup_{x\in D}|f(x)|\leq\sup_{x\in X}|f(x)|$. We go to
prove the reverse inequality. Let $\varepsilon>0$ be arbitrary. Choose
$x_{0}\in X$ such that $|f(x_{0})|>\sup_{x\in X}|f(x)|-\varepsilon$.
(This is possible because $\sup_{x\in X}|f(x)|<\infty$). Choose a
sequence $(y_{n})$ in $D$ such that $d(y_{n},x_{0})\rightarrow0$.
By continuity of $f$ at $x_{0}$, we have $|f(y_{n})|\rightarrow|f(x_{0})|$.
Therefore, there exists $n$ such that $|f(y_{n})|>\sup_{x\in X}|f(x)|-\varepsilon$.
Hence, $\sup_{y\in D}|f(y)|\geq|f(y_{n})|>\sup_{x\in X}|f(x)|-\varepsilon$.
Finally, since $\varepsilon$ is arbitrary, we have $\sup_{y\in D}|f(y)|\geq\sup_{x\in X}|f(x)|$.
Remark: The argument $d(x_{n},y_{n})\rightarrow0\Rightarrow f(x_{n})-f(y_{n})\rightarrow0$
actually does not work. For example, let $X=(0,\infty)$, equipped
with the usual metric. Let $f:X\rightarrow\mathbb{R}$ be defined
by $f(x)=\sin(1/x)$, which is bounded and continuous. It is easy
to construct two sequences $(x_{n})$ and $(y_{n})$ such that $|x_{n}-y_{n}|\rightarrow0$
but $f(x_{n})-f(y_{n})\not\rightarrow0$. For example, $x_{n}=(2n\pi+\frac{\pi}{2})^{-1}$
and $y_{n}=(2n\pi)^{-1}$.
A: It works out. Here’s another way: The map $\lvert f \rvert \colon X → [0..∞)$ is continuous, and so $\lvert f \rvert (\overline D) ⊆ \overline {\lvert f \rvert (D)}$ (by some characterization of continuity). As $\overline D = X$, we have
$$\sup \lvert f \rvert (X) = \sup \lvert f \rvert (\overline D) ≤ \sup \overline {\lvert f \rvert (D)} = \sup \lvert f \rvert (D) ≤ \sup \lvert f \rvert (X).$$
