Lenght of the curve of function $\delta_F(x) = dist(x, F)$ for $F$ compact Let $F$ be a compact subset of a closed interval $[a, b] \subset \mathbb{R}$. Let
$Γ ⊂ \mathbb{R}^2$ be the graph of the function $\delta_F(x) = dist(x, F)$. I am trying to find a formula for the lenght of $Γ$. I think the graph is gonna take zero value on F and and it will be piecewise linear elsewhere, having local maxima halfway between the intervals of $F$. Can someone give any idea of expressing the formula in a neat way. Thanks!! 
 A: You are absolutely correct about the form of $f$. Now, if $J$ is an open interval component of $[a,b]\setminus F,$ say $J=(c,d),$ then what is the length of the graph restricted to that interval? (Draw a picture.) Since $[a,b]\setminus F$ is a disjoint union of countably-many such intervals, then what can we conclude about the length of the graph restricted to $[a,b]\setminus F$? What is the length of the graph restricted to $F$? What is the length of the graph? (You should be able to give an answer in terms of $a,b,$ and the measure of $F$.)
Let me know if you have trouble answering any of these questions, and I'll see what I can do to get you unstuck.
Added: As you have aptly pointed out, the above sketch tacitly assumes that $a,b\in F,$ and so one naturally wonders if a formula that it yields is truly applicable for all compact $F\subseteq [a,b].$ The answer (with one possible exception, which I will address later) is "yes." Let me give a more in-depth proof outline.

Suppose that $F$ is a non-empty compact subset of $[a,b],$ and let $J$ be a connected component of $[a,b]\setminus F.$ Then

*

*$J=(c,d)$ for some $c,d\in F$ with $c<d,$

*$J=[a,\min F),$ or

*$J=(\max F,b].$
Of course, there is a $J$ of the second (resp., third) form iff $a\notin F$ (resp., $b\notin F$). Regardless of form, however, we see that the arc length of $\Gamma$ restricted to $J$ is $\sqrt{2}\ell(J),$ where $\ell$ is the interval length function. Since $[a,b]\setminus F$ is comprised of a disjoint union of countably-many open intervals (and at most two half-open intervals), then the arc length of $\Gamma$ restricted to $[a,b]\setminus F$ is $$\sqrt{2}m\bigl([a,b]\setminus F\bigr)=\sqrt{2}\bigl(b-a-m(F)\bigr),$$ where $m$ is the real Lebesgue measure.
Moreover, since the portion of the graph of $f$ restricted to $F$ effectively is the set $F$ (identifying the $x$-axis with the real line), then we readily see that the arc length of $\Gamma$ restricted to $F$ is simply $m(F).$
Consequently, the arc length of $\Gamma$ is given by $$\sqrt{2}(b-a)+\left(1-\sqrt{2}\right)m(F).\tag{$\star$}$$

You surely noticed the emphasis I put on the condition that $F$ be non-empty. This is because $f$ need not be defined if $F=\emptyset,$ even though $\emptyset$ is certainly a compact subset of $[a,b].$ Even if $f$ is defined in such a case, the formula may not apply. It all depends on how $\operatorname{dist}$ is defined.
There are a few ways I can think of that it might be defined, neither of which is wholly satisfactory. Let me address each.
The most straightforward way is as follows:

Given a compact set $F\subseteq\Bbb R$ and any $x\in\Bbb R,$ let $$\operatorname{dist}(x,F):=\inf\bigl\{|x-y|:y\in F\bigr\}.$$

We can readily show that this is well-defined unless $F$ is empty, in which case, $\bigl\{|x-y|:y\in F\bigr\}=\emptyset,$ which has no infimum.
Another issue with the above definition is that it seems we should be restricting our attention only to those $x\in[a,b].$ Otherwise, our $\Gamma$ will have infinite length! Also, we're really only interested in $F\subseteq[a,b].$ This suggests that the following definition would be better:

Given $x\in[a,b]$ and $F\subseteq[a,b]$ with $F$ compact, let $$\operatorname{dist}(x,F):=\inf\bigl\{|x-y|:y\in F\bigr\}.$$

This takes care of the infinite length problem, but $\operatorname{dist}(x,F)$ is still undefined if $F=\emptyset,$ so we need a bit more.
One potential fix is to define it as follows:

Given $x\in[a,b]$ and $F\subseteq[a,b]$ with $F$ compact, let $$\operatorname{dist}(x,F):=\inf\bigl\{|x-y|:y\in F\cup(-\infty,a)\cup(b,+\infty)\bigr\}.$$

This lets us define $\operatorname{dist}$ even when $F=\emptyset.$ Here, though, we run into a problem if $a\notin F$ or if $b\notin F.$ For example, suppose that $a\notin F$. Then we can readily show that $\operatorname{dist}(a,F)=0$ by this definition, which is not at all the way an ostensible distance function should operate! It is worth noting, though, that $(\star)$ does still hold under this definition of $\operatorname{dist}.$ We will need to add the case $J=[a,b]$ to the proof, but it still carries through.
Please let me know what definition of $\operatorname{dist}$ you're using, and I will update my answer accordingly.
