# Derivative of $d(x,A)$

For $A \subseteq \mathbb{R}$, define $$d(x, A) = \inf_{y \in A}|x-y|.$$ Let $A \subseteq \mathbb{R},$ define $f : \mathbb{R} \rightarrow [0,\infty)$ by $$f(x) = d(x, A).$$ Then I can show that, for any $x, y$, $$|f(x) - f(y)| < |x - y|.$$ So $f$ is Lipschitz which yields that $f$ is of bounded varition. So $f'$ exists almost everywhere.

I need to show that for $x$ such that $f'(x)$ exists, then $f'(x) \in \{-1, 0, 1\}.$

$\textbf{Attemp}$ I know that $f(x) = 0 \leftrightarrow d(x, A) = 0 \leftrightarrow x \in \ \mbox{cl} \ A$ where $\mbox{cl} \ A$ is the closure of the set $A$. Since $$\frac{|f(x) - f(y)|}{|x - y|} \leq 1$$ for any $x,y \in \mathbb{R} ,$ then $|f'(x)| \leq 1.$

Specifically, $$f'(x) = \lim_{y \rightarrow x} \frac{f(x) - f(y)}{x-y} .$$

If $x \in \ \mbox{cl} \ A,$ then $f(x) = 0.$ Then there exists a sequence $\{x_n\}$ such that $x_n \in A$ and $x_n \rightarrow x.$ So $f(x_n) = 0$ for all $n$. This yields that $f(x) - f(x_n) = 0$ for all $n$. Since $f'(x)$ exists, then $$\lim_{y \rightarrow x} \frac{f(x) - f(y)}{x-y} = \lim_{n \rightarrow \infty} \frac{f(x) - f(x_n)}{x - x_n} = 0.$$

Now $x \not\in \ \mbox{cl} \ A.$ I am not sure how to proceed in this case.

Any help or suggestion ?

if $x\notin A$

$\exists a\in \bar A: d(x,a) = d(x, A) = f(x) = |x-a|$

i.e. $a$ is the element in the closure of $A$ that is closest to $x.$

If there is an open ball around $x$ such that all $y\in B_\delta(x)$

$d(y,a) = d(y,A)$

Then $\frac {|f(x) - f(y)|}{|x-y|} = \frac {x-y}{|x-y|} = \pm 1$

and if not $f'(x)$ does not exist.

• What's $a$ if $A=(0,1)$ and $x=2$? – egreg Mar 6 '18 at 23:22
• @egreg Thanks... I knew there was a reason this felt a little soft... does it firm it up if we say $\exists a \in \bar A$ – Doug M Mar 7 '18 at 0:05
• Yes, you can assume $A$ closed, because $d(x,A)=d(x,\bar{A})$. – egreg Mar 7 '18 at 0:18