Differentiability of the distance function Suppose that $d:X \times X \to \mathbb{R}$ is a geodesic distance function on a smooth Riemannian manifold $X$ ($d$ is determined by metric tensor) and $x \in X$ is fixed. What can be said about the points in which $f:=d(x,\cdot)$ is differentiable? In particular:
-is it possible that $f$ is everywhere differentiable?
-how big the set of points in which $f$ isn't differentiable can be?
-what can be said about the structure of the set of point in which $f$ isn't differentiable (can it be a submanifold?)
I would be grateful if anybody could shed some light on these issues.
 A: Except on $0$-manifolds, $f$ will never be smooth, or even $C^1$: In normal coordinates $(u^i)$ centered at $x$, $f(u) = \sqrt{u_1^2 + \cdots + u_n^2}$ for sufficiently small $u$, and so in particular $f := d(x, \, \cdot \,)$ always has an isolated singularity at $x$.
For $X = \mathbb{R}$, $$f(t) := d(0, t) = |t|,$$ which is nondifferentiable only at $0$, and $\{0\}$ is of course a submanifold. For $X = \mathbb{S}^n$, $f$ has discontinuities at $x$ and its antipodes. The only connected Riemannian $1$-manifolds up to isometry are $\mathbb{R}$ and $\mathbb{S}^1$, and so for such manifolds, the singularity set is always a submanifold, with one or two points. The second example shows that the singularity set can be a ($0$-)submanifold no matter $n$.
On the real projective space $\mathbb{RP}^n$, endowed with the metric induced by the round metric via the covering $\pi: \mathbb{S}^n \to \mathbb{RP}^n$, at a point $[x] = \pi(x)$, the set of discontinuity is $\{ [x] \} \cup \mathbb{RP}^{n - 1}$, where $\mathbb{RP}^{n - 1}$ is the image of $(n - 1)$-sphere orthogonal to $x$ in $\mathbb{S}^n$, which shows that for $n > 1$ the singularity set is not in general a submanifold, and that it can have components which are hypersurfaces.
A: Travis's examples have a general explanation - on any complete, connected $n$-manifold, the distance function $d(p,\cdot)$ is smooth everywhere except at $p$ and on the cut locus of $p$. (You can make this conclusion by studying the exponential map - see e.g. Chapter 5.9 of Petersen's Riemannian Geometry.)
Thus your question amounts to studying the structure of the cut locus, which has been the subject of a lot of research over the last few decades; so while I'm not too familiar with it myself, you should be able to find many relevant papers online. While the picture I have in my head of the cut locus is a submanifold, I'm pretty sure there are degenerate cases where you at least lose differentiability.
If I'm interpreting the main theorem of this article correctly, you can conclude that the cut locus has Hausdorff dimension at most $n-1$, and thus that the distance function is almost everywhere differentiable, which answers the "how big" question.
A: For example, we can take a point $(x_0,\frac{1}{2})$ on $\mathbb{R}^2/\mathbb{Z}^2$  and geodesics $y=\pm\frac{x_0}{2}x$. Obviously, for $x_0\leqslant \frac{1}{2}$ these two lines are shortest geodesics. And if we move the point upper or lower, then the distance has a positive one-sided derivative and therefore is not differentiable at any point of $\{y=\frac{1}{2}\}$. The same for $\{x=\frac{1}{2}\}$.
Subset of singular points is not a subvariety.
