# Derivative of distance function to a closed, rectifiable set

Let $$\Gamma \subset \mathbf{R}^d$$ be a closed, countably $$n$$-rectifiable set. Is there any reasonable way to write the derivatives $$\frac{\partial}{\partial x_i} \mathrm{dist}\, (x,\Gamma)$$ for $$x \notin \Gamma$$?

It is Lipschitz and therefore differentiable almost everywhere. And since $$\Gamma$$ has tangent planes almost everywhere, it of course has a normal space at almost every point too, so you might hope/guess that for almost every point in some neighbourhood of $$\Gamma$$, there is a reasonable expression for these derivatives. Is anything like that true?

• Is $\Gamma$ convex? Otherwise the nearest point need not be unique and there may be no continuous choice of $\Pi_\Gamma(x)$. – Nik Weaver Aug 14 '19 at 14:15
• That's true. Edited to ask just about distance function. Of course $|x - \Pi_{\Gamma}(x)|$ is well-defined so it still might be useful to think about, I don't know. – T_M Aug 14 '19 at 14:40

The distance $$f: x \mapsto \mathsf{dist}(x,\Gamma)$$ to a closed set $$\Gamma$$ in $$\mathbb{R}^n$$ is differentiable in $$x \notin \Gamma$$ iff the nearest point projection is unique; denote this by $$x_\Gamma$$. In $$\mathbb{R}^n$$ the derivative at those points is given by $$(x-x_\Gamma)/\| x-x_\Gamma\|$$. Note that points in $$\Gamma$$ are in general not points of differentiability (points in the interior of $$\Gamma$$ would be, but the derivative is obviously zero).

Note that we don't assume anything on $$\Gamma$$ except closedness which is needed to show that the set of nearest points to $$x$$ is compact.

The statement also holds for smooth Riemannian/Finsler manifolds if one replaces nearest point projection with "unique geodesic of length $$d(x,\Gamma)$$ connecting $$x$$ and $$\Gamma$$.

As I couldn't find a quick reference to this fact here a small proof:

If $$f$$ is differentiable at $$x$$ then $$f(y)=f(x)+v\cdot(y-x)+o(\|x-y\|)$$ for some $$v$$. Picking $$y=(1-\epsilon)x+\epsilon z$$ for a point $$z\in\Gamma$$ with $$d(x,z)=f(x)$$ it holds $$f(y)=(1-\epsilon)f(x)$$. But then $$v=(x-z)/\|x-z\|$$. In particular, the nearest point projection must be unique.

Let $$(x_{n},y_{n})$$ be two sequences with $$x_{n}\to x$$ and $$y_{n}\in\Gamma$$ such that $$d(x_{n},y_{n})=f(x_{n})$$. W.l.o.g. also assume $$\frac{x_{n}-x}{\|x_{n}-x\|}\to v\in\partial B_{1}(0)$$. If the nearest point projection at $$x$$ is unique then $$y_{n}\to x_{\Gamma}$$.

Now observe by convexity of $$d_{z}:x\mapsto\|x-z\|$$ one has \begin{align*} \|y-z\|-\|x-z\| & \ge\nabla d_{z}(x)\cdot(y-x)\\ & =\frac{(x-z)\cdot(y-x)}{\|x-z\|}. \end{align*} Thus \begin{align*} \frac{(x-y_{n})\cdot(x_{n}-x)}{\|x-y_{n}\|\|x_{n}-x\|} & \le\frac{\|x_{n}-y_{n}\|-\|x-y_{n}\|}{\|x_{n}-x\|}\\ & \le\frac{f(x_{n})-f(x)}{\|x_{n}-x\|}\\ & \le\frac{\|x_{n}-x_{\Gamma}\|-\|x-x_{\Gamma}\|}{\|x_{n}-x\|}.\\ \end{align*} Taking the limit we see that the left hand side converges to $$\frac{(x-x_{\Gamma})}{\|x-x_{\Gamma}\|}\cdot v$$ which is nothing but the derivative of $$d_{x_\Gamma}$$ at $$x$$ in direction $$v$$, i.e. the limit of the right hand side. Hence $$f$$ is differentiable in $$x$$.

• I am confused by your second sentence: a point $\gamma \in \Gamma$ has a unique nearest point in $\Gamma$, that is itself. So $\text{dist}(., \Gamma)$ should be differentiable at $\gamma$ by the first sentence. – Luc Guyot Aug 18 '19 at 16:10
• I would appreciate some hints regarding "But then $v=(x-z)/\|x-z\|$." I understand only that $f(y)$ and $\| y - z \|$ coincide for $y = (1 - \epsilon)x + \epsilon z, 0 \le \epsilon \le 1$ so that $\frac{\partial f}{\partial e}(x) = \frac{\partial \| . - z \|}{\partial e}(x)$ for $e = (x-z)/\|x-z\|$. – Luc Guyot Aug 18 '19 at 16:25
• (1) I adjusted the claim to "..$x \notin \Gamma$ ...". The whole argument assumes $x \ne x_\Gamma$. (2) Note $f$ is $1$-Lipschitz and for general $1$-Lipschitz functions it holds that the gradient is equal to $e$ whenever a partial in direction $e$ is equal to $1$. Alternatively, observe that on the one hand $f(y)- f(x)$= -\|y-x\|$by choice of$y$. On the other hand$f(y) = f(x) + v\cdot (x-y) + o(\|x-y\|) by differentiability in $x$. So if $y$ is close to $x$ then necessarily $v = e$ by the "equality case" of Cauchy-Schwarz. – Martin Kell Aug 18 '19 at 19:37