TITLE: Distance to a closed set is continuous.
QUESTION [16 upvotes]: I want to prove that given a metric space $(M,d)$ and $F \subset M$, then the function $f_F: M \to \Bbb R$ given by $f_F(x) = d(x,F) = \inf\{d(x,y) \ : \ y \in M\}$ is continuous.
Take $x \in M$. If $x \in F$ it is obvious. I am convinced that it is continuous, since if you take a sequence $(x_n)_{n \in \Bbb N}$ which converges to $x \in M$, then the distances from the $x_n$ to $F$ go close to the distance from $x$ to $F$, since the $x_n$ go close to $x$.
But I'm having much trouble writing it. My teacher said to "just forget about the $\inf$ and work with sequences", but that doesn't help me at all.
Given $\epsilon > 0$ and a sequence $(x_n)_{x \in \Bbb N}$ such that $x_n \to x$, I must prove that $f_F(x_n) \to f_F(x)$, that is, find $n_\epsilon \in \Bbb N$ such that: $$n > n_\epsilon \implies |d(x_n,F) - d(x,F)| < \epsilon $$
Surely if $y \in F$, we have $d(x,y) \geq d(x,F)$. Other than this, I don't know how to deal with these infs, and this absolute value. I suppose I'll have to use the triangle inequality. Can someone help me do it?

REPLY [4 votes]: Here is a more worked example without "taking infimum" using the inverse triangle inequality: 
We wish to show for all $x, y \in M$, $\lvert f_F(x) - f_X(y)\rvert \le d(x, y)$.
Case: $d(x, z) \ge d(y, z)$. 
Fix the $z$ such that both bounds are true. By the definitions of infimum, we have two bounds (let $\epsilon > 0$): 
\begin{align}
\forall z \in F \quad &f_F(x) \le d(x, z) \\
\exists z \in F \quad &f_F(x) + \epsilon > d(x, z)
\end{align}
By the inverse triangle inequality, 
\begin{align}
& d(x, z) - d(y,z) \le  d(x,y) \\
\implies & f_F(x) - d(y, z) \le  d(x,y) \\
\implies & f_F(x) - f_F(y) - \epsilon \le  d(x,y)  \\
\implies & f_F(x) - f_F(y) \le  d(x,y) + \epsilon 
\end{align}
Since this holds for all $\epsilon > 0$, $f_F(x) - f_F(y) \le d(x,y)$. The case of $d(x,z) < d(y,z)$ is similar, so we have proved $\lvert f_F(x) - f_F(y)\rvert \le d(x, y)$. Now simply apply our definition of continuity using $\delta = \epsilon$ (actually $f_F$ is Lipschitz continuous with constant $1$).