# Continuity of the metric function

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.

-
I just proved this in this answer a few hours ago, see point 1. in my answer there. –  t.b. Jul 1 '11 at 7:31
thanks, voted there also ) –  Ilya Jul 1 '11 at 7:36

If $A = X$ (or if $\overline{A} = X$) then $d(\cdot,A) = 0$ and there's nothing to prove. If $A$ is empty, the usual conventions in the infimum yield $d(\cdot,\emptyset) = \infty$ and Lipschitz continuity doesn't really make sense. However a constant function is certainly continuous.

So, assume that $\emptyset \neq A$ and let $\varepsilon \gt 0$. Choose $a\in A$ such that $d(x,a) \leq d(x,A) + \varepsilon$. Then the triangle inequality yields $d(y,A) - d(x,A) \leq d(y,a) - d(x,a) + \varepsilon \leq d(y,x) + \varepsilon$. By symmetry we get $|d(x,A) - d(y,A)| \leq d(x,y) + \varepsilon$ and the desired result follows because $\varepsilon$ was arbitrary. Note that I didn't use that $A$ is closed. Update: Alternatively, you can choose Zarrax's way and permute two steps in this paragraph and make the argument nicer by getting rid of the explicit mentioning of $\varepsilon$ or appeal to the valuable general result mentioned by Didier.

If $A$ is non-empty and not dense, i.e., $\overline{A} \neq X$ then $1$ is in fact the best Lipschitz constant. Indeed, there are $x$ and $r\gt0$ such that $B_r(x) \cap \overline{A} = \emptyset$, so $d(x,A) \geq r \gt 0$. For every $\varepsilon \gt 0$ we can find $a \in A$ such that $d(x,a) \leq (1+\varepsilon)d(x,A)$. But then $|d(a,A) - d(x,A)| = d(x,A)\geq \frac{1}{1+\varepsilon} d(x,a)$ and the claim follows.

For a closely related thread, see here.

-

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.

-

This is a special case of the following general situation.

For any nonempty set $T$, consider a collection $(u_t)$ of real valued functions defined on $X$ and indexed by $t$ in $T$. Assume that each $u_t$ is $1$-Lipschitz, that is $|u_t(x)-u_t(y)|\le d(x,y)$ for every $x$ and $y$ in $X$ and every $t$ in $T$. Let $v=\inf_{t\in T}u_t$ the function 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 $1$-Lipschitz.

To prove this, start from the inequalities $v(x)\le u_t(x)\le 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 $u_a$ is nonnegative and $1$-Lipschitz, hence the function $v=\inf_{a\in A}u_a=d(A,\ )$ is finite everywhere and $1$-Lipschitz.

Note that $A$ can be any nonempty subset of $X$.

-