TITLE: Continuity of the function $x\mapsto d(x,A)$ on a metric space
QUESTION [27 upvotes]: Let $(X,d)$ be a metric space. How to prove that for any closed $A$ a function $d(x,A)$ is continuous - I know that it is even Lipschitz continuous, but I have a problem with the proof: 
$$
|d(x,a) - d(y,a)| \leq d(x,y)
$$
for any $a\in A$ - but we cannot just replace it by $|d(x,A) - d(y,A)|\leq d(x,y)$ since the minimum (or infimum in general) can be attained in different points $a\in A$ for $x$ and $y$, so we only have that
$$
|d(x,A)-d(y,A)|\leq d(x,y)+\sup\limits_{a,b\in A}d(a,b)
$$
which does not mean continuity.

REPLY [29 votes]: If $a$ is in $A$, by the triangle inequality you have
$$d(x,a) \leq d(x,y) + d(y,a)$$
The left hand side is at least $d(x,A)$, so we get
$$d(x,A) \leq d(x,y) + d(y,a)$$
Take the infinum of this over all $a$ in $A$ and you obtain
$$d(x,A) \leq d(x,y) + d(y,A)$$
Which is the same as
$$d(x,A) - d(y,A) \leq d(x,y)$$
Reversing the roles of $x$ and $y$ you have 
$$d(y,A) - d(x,A) \leq d(x,y)$$
Combining the last two equations gives
$$|d(x,A) - d(y,A)| \leq d(x,y)$$
Notice $A$ doesn't even have to be closed for this to work.

REPLY [12 votes]: This is a special case of the following general situation.

Fix some nonempty set $T$ and a collection $(u_t)$ of real valued functions defined on $X$ and indexed by $t$ in $T$. Assume that each function $u_t$ is $1$-Lipschitz, that is, that for every $x$ and $y$ in $X$ and every $t$ in $T$, $|u_t(x)-u_t(y)|\leqslant d(x,y)$.
Consider the function 
  $v=\inf\limits_{t\in T}u_t$, defined for every $x$ in $X$ by $$v(x)=\inf\{u_t(x);t\in T\}$$ Then:

Either, $v=-\infty$ everywhere.
Or, $v$ is finite everywhere and then $v$ is $1$-Lipschitz.


To prove this, start from the inequalities $v(x)\leqslant u_t(x)\leqslant u_t(y)+d(x,y)$ for every $x$ and $y$ in $X$ and every $t$ in $T$, and follow the lights...
In your setting, one can choose $T=A$ and $u_a=d(a,\ )$ for every $a$ in $A$. Then each function $u_a$ is nonnegative and $1$-Lipschitz, hence the function $$v=\inf\limits_{a\in A}u_a=d(A,\ )$$ is finite everywhere and $1$-Lipschitz. 
Note that $A$ can be any nonempty subset of $X$.