Continuity of function defined with infimum I am trying to prove the following.
Let $F \subseteq \mathbb{R}$ be nonempty and closed. Show that $$f(x) = \text{inf} \{ \left|x-a\right| : a \in F \}$$ is continuous and that $f(x) \neq 0$ if $x \notin F$.
So far, I have tried fixing a point $c \in \mathbb{R}$ and proposing an arbitrary $\epsilon > 0$, and tried to determine a $\delta > 0$ for which $$ \left| x-c \right| < \delta \Longrightarrow \left| f(x) - f(c) \right| < \epsilon. $$ Unfortunately, I have not had much success. Could you guys give me any suggestions of how to start?
 A: We can in fact show that $f$ is uniformly continuous (even better, Lipschitz continuous) as follows. Let $a \in F$. Then by the triangle inequality, we have
$$|x-a| \leq |x-y| + |y-a|$$
Taking the infimum over $a \in F$ gives us
$$f(x) \leq |x-y| + f(y)$$
Similarly,
$$f(y) \leq |x-y| + f(x)$$
and so
$$|f(x) - f(y)| \leq |x-y|$$
which gives the desired result.
Now if $x \not\in F$, then $x$ is contained in the open set $F^c$, so there is some neighborhood $(x-\delta, x+\delta)$ contained in $F^c$, where $\delta > 0$. Therefore, every point $y$ satisfying $|x-y| < \delta$ is contained in $F^c$, which means that $f(x) \geq \delta > 0$.

Edit to respond to the question raised in the comment.
Here is more detail on how we obtain $f(x) \leq |x-y| + f(y)$.
For any $a\in F$ we have $f(x) \leq |x-a|$, since $f(x)$ is the infimum of all such $|x-a|$. By the triangle inequality, we have $|x-a| \leq |x-y| + |y-a|$. Combining these inequalities gives us
$$f(x) \leq |x-y| + |y-a|$$
Therefore the left hand side is a lower bound for the set $\{|x-y| + |y-a| : a \in F\}$, so it cannot be larger than the greatest lower bound (infimum) of that set:
$$\begin{aligned}
f(x) & \leq \inf\{|x-y| + |y-a| : a \in F\} \\
&= |x-y| + \inf\{|y-a| : a \in F\} \\
& = |x-y| + f(y)\\
\end{aligned}$$
Note that the term $|x-y|$ does not depend on $a$, so we can treat it as a constant when we take the infimum over $a \in F$.
