# Prove that $x\in$ Clos$(S)$ if and only if $f(x)=0$.

Given a nonempty subset S of a metric space $(M,d)$, define $f:M\rightarrow \mathbb{R}$ by $f(x)=\inf \{ d(x,s):s\in S\}$

(a) Show that $x\in$ Clos$(S)$ if and only if $f(x)=0$.

(b) Show that $|f(x)-f(y)|\le d(x,y)$ for all $x,y\in M$ and conclude that $f$ is continuous.

Clos$(S)$ = $\{ x\in M \mid$ Every ball $B(x,r)$ intersects $S\}$

$B(x,r) = \{ y\in M \mid d(x,y)<r\}$

Working on (a) I am first trying to show that $x\in$ Clos$(S)$ implies $f(x)=0$. So assuming $x\in$ Clos$(S)$ then ...

is it correct to say that: there exists a ball, $B(x,r)$ that intersects $S$. Then $d(x,y)<r$ for all $r$ so $f(x)=0$.

Then my attempt at the converse. Assume $f(x)=0$. Then $d(x,s)=0$ for some $s\in S$. This implies that $x=s$ so $x\in S$ since $s\in S$. So $x\in$ Clos$(s)$.

Are my statements correct?

As for part (b) I am not entirely sure where to start, but I wanted to be sure I had part (a) first in the event that I can make use of it for (b).

If $y \in M$ and if $\varepsilon > 0$, then $d(x,y) < \varepsilon$ only if $$|f(x) - f(y)| \leq d(x,y) < \varepsilon;$$ hence continuity follows. This solves the second problem.
For the first question, we prove the "only if" part first. If $x \in \overline{S}$, then for every $\varepsilon > 0$ we have $B_{M}^{x}(\varepsilon) \cap S \neq \varnothing$, where $B_{M}^{x}(\varepsilon)$ denotes the open ball over $M$ of center $x$ and radius $\varepsilon$. If $f(x) \neq 0$, then $\inf_{s \in S}d(x,s) \neq 0$; hence if $p := \inf_{s \in S}d(x,s)$, then $B_{M}^{x}(p/2) \cap S = \varnothing$, a contradiction. Conversely, suppose $x \in M$ and $f(x) = 0$. Then $p = 0$, implying that for every $\varepsilon > 0$ there is some $s \in S$ such that $p = 0 \leq d(x,s) < p + \varepsilon = \varepsilon$; hence $B^{x}_{M}(\varepsilon) \cap S \neq \varnothing$, so $x \in \overline{S}$.
Your first statement is correct: by definition, $x \in \text{Clos}(S)$ iff for any $r > 0$, $B(x,r) \cap S \neq \emptyset$, so you can take $s$ from balls with $r$ arbitrarily small. For the converse, it may be the case that no $s \in S$ satisfies $d(x,s) = 0$. Rather, you can find a sequence $\{s_n\}_n \subset S$ such that $d(x,s_n) < \frac{1}{n}$, say. Do you see how to use the definition of closure I just stated to conclude?
Also, for b), you should show that for each $s$, $d(x,s) \leq d(x,y) + d(y,s)$, so this is also true for $s$ that "minimizes" $d(y,s)$, i.e., find a sequence $\{s_n\}_n$ such that for $n$ sufficiently large, $d(y,s_n) < f(y)+\epsilon$. Thus, $d(x,s_n) < f(y) + \epsilon + d(x,y)$. You can do the same with $x$ first by symmetry. Do you see how to use the definition of $f$ to conclude in this problem?