Real analysis question the continuity of infimum Let $E\subseteq \Bbb R$. Define $$g(x) = \inf_{y\in E}|x-y|.$$How should I prove that $g(x)$ is continuous and if $g^{-1}(0)=E$ then $E$ is closed set? 
 A: For the continuity part, we can use the following:

LEMMA Let $(X,d)$ be a metric space, $A\subset X$. For $x,y\in X$, we have that
$$d(x,A)\leq d(x,y)+d(y,A)$$

PROOF The triangle inequality means $$d(x,w)\leq d(x,y)+d(y,w)$$ for each $x,y\in X$, $w\in A$. Thus, for every $w\in A$, the above follows, which means $$d(x,A)\leq d(x,w)\leq d(x,y)+d(y,w)$$
Now we have
$$d(x,A)- d(x,y)\leq d(y,w)$$
means the left hand side is a lower bound for the elements of $\{d(y,w):w\in A\}$, so
$$d(x,A)\leq d(x,y)+d(y,A)$$
Can you now prove your function is continuous?
SPOILER
The above gives, by symmetry $d(x,y)=d(y,x)$ that  $$d(y,A)\leq d(x,y)+d(x,A)$$ $$d(x,A)\leq d(x,y)+d(y,A)$$
Which all in all mean $$|d(y,A)-d(x,A)|\leq d(x,y)$$
for any $x,y\in X$. This is precisely what Dominic states: it is $1$-Lipschitz.


PROPOSITION Let $A\in \Bbb R$. Define $$d(y,A)=\inf_{x\in A}|x-y|$$ for $y\in\Bbb R$
Then $A$ is closed if and only if  $d(x,A)=0\implies x\in A$

PROOF Since we have defined $$d(y,A)=\inf_{x\in A}|x-y|$$
there exists a sequence of points $\langle a_n\rangle$ in $A$ such that $\lim |y-a_n|=d(y,A)$.
Suppose $A$ is closed, and $d(x,A)=0$. Then there exists a sequence of points in $A$ such that $\lim |x-a_n|=d(x,A)=0$. If some $a_n=x$, $x\in A$. Otherwise (that is, if $a_n\neq x$ for each $n$) $x$ is a limit point of $A$, and since $A$ is closed, $x\in A$. Suppose now that for each $x\in X$, $d(x,A)=0\implies x\in A$. Let $x$ be a limit point of $A$. It follows there exists a sequence of points $\langle a_n\rangle$ in $A$ that converge to $x$. But then $\lim |a_n-x|=0$. It follows that $d(x,A)=0$; so $x\in A$. Thus $A$ contains all its limits points, whence it is closed. $\blacktriangle$

NOTE In the above we used that, given a set $A\in \Bbb R$, the following are equivalent:
$(1)$ $\alpha=\inf A$.
$(2)$ For each $\epsilon >0$ there exists $a\in A$ such that $a-\alpha<\epsilon$.

A: Hint: Prove it is Lipschitz continuous with Lipschitz constant $1$.
For your new question use that the preimages of closed sets under continuous functions are closed, and $\{0\}$ is closed.
