How to prove function $d_S(x)$ is uniformly continuous 
Suppose $S\subset \mathbb R$ is a arbitrary subset and function $d_S(x):\mathbb R\to \mathbb R$ $$d_S(x)=\inf\{|x-a|:a\in S\}
$$ prove this function is uniformly continuous

Since I know the definition of uniformly continuous $$ \forall \epsilon >0 ,\exists \delta>0, \forall x,y\in \text{dom}f: |x-y|<\delta \implies |f(x)-f(y)|<\epsilon$$
I want to prove this function from the definition. My attempt was to write down $$|d_S(x)-d_S(y)|<\epsilon$$Then find the suitable $\delta$ to make this be true
However
$$|d_S(x)-d_S(y)|=|\inf\{|x-a|:a\in S\}-\inf\{|y-a|:a\in S\}|$$
I don't know how to deal with this. Then I try to let $a(x),a(y)\in S$ such that $$d_S(x)=|x-a(x)| \\ d_S(y)=|y-a(y)|$$
Then $|d_S(x)-d_S(y)|$ can be rewritten as $$ |\ |x-a(x)| -|y-a(y)| \ |\leq |x-a(x)-y+a(y)|\leq |x-y|+|a(x)-a(y)|$$.
Then I still don't have too much idea about dealing with this. If I just let $|x-y|<\delta=\epsilon$, the first term will be less than $\epsilon$ but the second term remains tricky for me.
Any help on this? Or maybe my method is the wrong idea for solving this problem? Thank!
 A: The function you deal with is $d(\cdot,S)$, so I'll note it like this (in fact, this result is valid for metric space $(X,d)$).
Let $\varepsilon>0$ and $x,y\in \mathbb{R}$. By characterization of the infimum, there exists $a\in S$ such that
$$d(x,a)\leq d(x,S)+\varepsilon.$$
Therefore,
$$d(y,S)\leq d(y,a)\leq d(y,x)+d(x,a)\leq d(x,y) + d(x,S)+\varepsilon.$$
Since $\varepsilon$ is arbitrary, we get
$$d(y,S)-d(x,S)\leq d(x,y).$$
In the same way, you show that
$$d(x,S)-d(y,S)\leq d(x,y).$$
Thus,
$$|d(x,S)-d(y,S)|\leq d(x,y).$$
You can easily conclude by taking $\delta=\varepsilon$ in the definition of uniform continuity.
A: $(X, d) $ be a metric space and $S\subset X$ .
$d_S : X\to \Bbb{R} $ defined by  $d_S (x) =d (x, S) =\inf \{d(x, s) : s\in S \}$ is uniformly continuous  (Infact we can say more strong kind of continuity, Lipchitz continuous)
For any $x, y\in X $ we have
$|d_S(x) -d_S(y)|\le d(x, y) $
Proof : For $x, y\in X $ and $s\in S$ ,
$d(x, s) \le d(x, y) +d(y, s) $
Then, $\inf \{ d(x, s) : s\in S \} \le d(x, s) \le d(x, y) +d(y, s) $
Implies, $d_S(x) \le d(x, y) +d(y, s) $
Hence, $d_S(x) $ is lower bound of the set $\{d(x, y) +d(y, s) : s\in S \}$
Hence, $d_S(x) \le \inf \{ d(x, y) +d(y, s) :s\in S  \}= d(x, y) +d_S(y) $
So, $d_S(x) -d_S(y) \le d(x, y) $
And similarly, we can show using the triangle inequality $d(y, s) \le  d(x, y) +d(x, s) $ that $d_S(y) -d_S(x) \le d(x, y) $
Hence , $|d_S(x) -d_S(y) |\le d(x, y) $.
If you don't know metric space , set $X=\Bbb{R} $ and $d(x, y) =|x-y|$
A: You can prove something stronger: that is $d_{S}$ is Lipshitz.
Consider $x,y\in{\mathbb{R}}$.  For all $z\in{S}$ we have that $d_{S}(x)\leq |x-z|$ from the definition of $d_{S}$. Now, using the triangular inequality we conclude that: $$d_{S}(x)\leq |x-z|\leq |x-y|+|y-z|$$ and taking infimum with respect to $z$, we conclude that: $$d_{S}(x)\leq |x-y| + \inf\limits_{z\in{S}} |y-z|= |x-y|+d_{s}(y).$$ Thus, $d_{S}(x)-d_{S}(y)\leq |x-y|$. Respectively, using the same arguments we show that $d_{S}(y)-d_{S}(x)\leq |x-y|$ and we finally conclude that $|d_{S}(x)-d_{S}(y)|\leq |x-y|,$ which indicates that $d_{S}$ is $1$-Lipschitz and thus uniformly continuous.
