Show the limit exists almost every where Let $E\subseteq \mathbb{R}$ be a Lebesgue measurable set. Define
$$f(x)=\operatorname{dist}(x,E)=\inf\{|x-e| \ : \ e\in E\}. $$
I want to prove that for almost every $x\in E$ that 
$$\lim_{r\rightarrow 0^+}\frac{f(x+r)}{r}=0. $$
What I've Tried: This looks very much like the right derivative at $x$. Noting that if $x\in E$ then $f(x)=0$ and thus 
$$\lim_{r\rightarrow 0^+} \frac{f(x+r)-f(x)}{r}= \lim_{r\rightarrow 0^+}\frac{f(x+r)}{r}. $$
But I really don't know how to proceed from here... If $x\in \operatorname{Int}(E)$ then the limit should exist, so it seems we only need to worry about points in $E-\operatorname{Int}(E)$. 
 A: Try applying the Lebesgue density theorem . It states that for a Lebesgue measurable set $E\subset\mathbb{R}^n$, $\lim_{r\rightarrow0}\frac{\mu(E\cap B_{r}(x))}{\mu(B_r(x))}=1$ for almost every point of $E$. The idea is that for small enough $r$ the point $x+r\in B_r(x)$ must get arbitrarily close to some point of $E$ inside $B_r(x)$ for the maximum "gap" between $x+r$ and the other points of $E$ in $B_r(x)$ can only be so large as the the ratio in question gets small. More explicitly:
For small enough $r$, we have that $\frac{\mu(E\cap B_{r}(x))}{\mu(B_r(x))}>1-\epsilon$. It must be the case that $f(x+r)<\mu(B_r(x))-\mu(E\cap B_r(x))$ (if you're having trouble seeing this draw a picture). Manipulating the first inequality, we see that $\mu(B_r(x))-\mu(E\cap B_r(x))<\epsilon\mu(B_r(x))=2r\epsilon$ so it follows that $f(x+r)<2r\epsilon$ for all $r$ sufficiently small.
A: Since $|f(x)-f(y)|\leq |x-y|$, $f$ is of bounded variation. Hence, $f$ is differentiable almost everywhere. Now, since $f$ is nonnegative and $f=0$ on $E$, for each point $x\in E$, $f$ has a local minimum at $x$. Thus, at every point $x\in E$ at which $f$ is diffetentiable, $f'(x)=0$.
