TITLE: Riemannian surfaces with an explicit distance function?
QUESTION [72 upvotes]: I'm looking for explicit examples of Riemannian surfaces (two-dimensional Riemannian manifolds $(M,g)$) for which the distance function d(x,y) can be given explicitly in terms of local coordinates of x,y, assuming that x and y are sufficiently close.  By "explicit", I mean things like a closed form description in terms of special functions, by implicitly solving a transcendental equation or (at worst) by solving an ODE, as opposed to having to solve a variational problem or a PDE such as the eikonal equation, or an inverse problem for an ODE, or to sum an asymptotic series.
The only examples of this that I know of are the constant curvature surfaces, which can be locally modeled either by the Euclidean plane ${\bf R}^2$, the sphere ${\bf S}^2$, or the hyperbolic plane ${\bf H}^2$, for which we have classical formulae for the distance function.
But I don't know of any other examples.  For instance, the distance functions on the surface of the solid ellipsoid or solid torus in ${\bf R}^3$ look quite unpleasant already to write down explicitly.  Presumably Zoll surfaces would be the next thing to try, but I don't know of any tractable explicit examples of Zoll surfaces that are not already constant curvature.

REPLY [11 votes]: In the course of writing an answer to a related MO question, I realized that there is a surface with a complete Riemannian metric of non-constant negative curvature for which one can write down the distance function explicitly, so I thought I would record it here for those who might be interested.
Such metrics are quite rare; even when the geodesic flow is integrable (or even rotationally symmetric), one cannot generally compute the arc length along geodesics in a sufficiently explicit form that one can actually compute the geodesic distance between two given points in any explicit way.  This is the first complete example with nonconstant curvature that I have seen.  (There are many explicit but non-complete examples with non-constant curvature in the classical literature, c.f. Tome III of Darboux' monumental Leçons sur la théorie générale des surfaces et les applications géométriques du calcul infinitésimal.)
The surface is $\mathbb{R}^2$ and the metric in standard coordinates is
the rotationally symmetric metric
$$
g = (x^2+y^2+2)\,(\mathrm{d}x^2 + \mathrm{d}y^2).
$$
The Gauss curvature of $g$ is $K = -4/(x^2+y^2+2)^3<0$. It is  complete, since it dominates the standard flat metric.  It follows from general theory that any two points lie on a unique geodesic and each geodesic segment minimizes $g$-distance between its endpoints.
The geodesics of $g$ are easy to describe as curves: For every pair of numbers $(a,b)$ with $a^2+b^2\ge 1$, consider the equation
$$
(1+a)\,x^2 + 2b\,xy + (1-a)\,y^2 = a^2+b^2-1.
$$
When $a^2+b^2>1$, this is a hyperbola, and each of the branches is a geodesic.
When $a^2+b^2=1$, this is the equation of a line through the origin, which is also a geodesic.  Conversely, every geodesic of $g$ is either a line through the origin or a branch of one of the hyperbolae listed above.
The geodesic distance along a line through the origin is not hard to write down:
On the line $y=0$, the element of arc length is
$$
\mathrm{d}s = \sqrt{x^2+2}\,\mathrm{d}x = \mathrm{d}\left(\sinh^{-1}\left(\frac{x}{\sqrt{2}}\right)+\frac{x\sqrt{x^2+2}}{2}\right).
$$
Set
$$
f(x) = \sinh^{-1}\left(\frac{x}{\sqrt{2}}\right)+\frac{x\sqrt{x^2+2}}{2}
\approx \sqrt2\left(x + \frac{x^3}{12}-\frac{x^5}{160}+\cdots\right).
$$
I will now show that the $g$-distance between any two points $p,q\in\mathbb{R}^2$
is given by the formula
$$
\delta(p,q) = f\left(\frac{|p+q|+|p-q|}{2}\right)-f\left(\frac{|p+q|-|p-q|}{2}\right),
$$
where the norms are the Euclidean norms, i.e., taken with respect to the standard Euclidean inner product on $\mathbb{R}^2$.
Remark: In fact, the above formula also holds for the rotationally invariant metric $g = (2+x{\cdot}x)(\mathrm{d}x{\cdot}\mathrm{d}x)$ on $\mathbb{R}^n$ for $n\ge2$, since each geodesic for this metric lies in a (totally geodesic) $2$-plane through the origin $x=0$.
To prove the claim, first, note that, while the distance function $\delta:\mathbb{R}^2\times\mathbb{R}^2\to\mathbb{R}$ is not smooth along the diagonal, its square $\sigma = \delta^2$
is a smooth function on $\mathbb{R}^2\times\mathbb{R}^2$ that vanishes along the diagonal.  In fact, because $g$ is real-analytic, it follows that $\sigma$ is real-analytic.  Because $g$ is invariant under (Euclidean) rotation about the origin and reflection across lines through the origin, it follows that $\delta$ and $\sigma$ are also invariant under these rotations and reflections, now acting diagonally on $\mathbb{R}^2\times\mathbb{R}^2$.  Using this, one can show that $\sigma$ must be representable as
$$
\sigma(p,q) = C\bigl(|p|^2,\,p{\cdot}q,\,|q|^2\bigr)
\quad\text{for all}\ p,q\in\mathbb{R}^2,
$$
where $C(a,b,c)$ is a smooth function on the cone $\mathcal{C}_+$
defined by $a,c\ge 0$ and $ac-b^2\ge0$.
Now, for fixed $q\in\mathbb{R}^2$ the function $\delta_q:\mathbb{R}^2\to\mathbb{R}$, defined by $\delta_q(p) = \delta(p,q)$, vanishes at $q$ and satisfies $|\mathrm{d}(\delta_q)|^2_g = 1$ except at $q$ (where it is not differentiable).
This implies that the corresponding $\sigma_q = {\delta_q}^2$ attains its minimum value of $0$ at $q$ and satisfies the first-order PDE $|\mathrm{d}(\sigma_q)|^2_g = 4\sigma_q$.  Interpreting this in terms of the above representation of $\sigma$,
we find that $C$ must satisfy the first order PDE
$$
4aC_a^2 + 4bC_aC_b+cC_b^2 - 4(a+2)C^2 = 0.
$$
Similarly, using the fact that $C(a,b,c) = C(c,b,a)$ (since $\sigma(p,q) = \sigma(q,p)$), we find that
$$
4cC_c^2 + 4bC_cC_b+aC_b^2 - 4(c+2)C^2 = 0.
$$
This pair of first-order PDE for $C$ is singular at $(a,b,c) = (0,0,0)$, but, since $C$ must vanish when $a+c-2b = |p-q|^2 = 0$ but otherwise be positive in the cone $\mathcal{C}_+$, it is easy to show that $C$ has a Taylor expansion
$$
C\simeq (a{-}2b{+}c)\left(2 + \frac{(a{+}b{+}c)}{3}-\frac{(4a{+}7b{+}4c)(a{-}2b{+}c)}{360} + \cdots\right).
$$
In fact, examining the higher terms, it becomes apparent that $C$
should be a function of $u = a{+}c$ and $v = a{-}2b{+}c$.  Indeed, if
$$
C(a,b,c) = H(a{+}c,\,a{-}2b{+}c) = H(u,v)
$$
were to hold for some smooth function $H$ on the $uv$-domain defined by $0\le v\le 2u$, then one finds that $H$ would have to satisfy
$$
u\,{H_u}^2 + 2v\,(H_uH_v+{H_v}^2) - (u+4)\,H = 0.
$$
with $H \simeq v\,\bigr(2-\tfrac1{6}(v-3u)-\tfrac1{720}(15u-7v)v+\cdots\bigr)$.
Using the theory of singular analytic first-order PDE, it is not difficult to show that such an analytic solution $H(u,v)$ exists, is unique, and is a multiple of $v$.  (It's easy to show that there is a unique power series solution whose lowest term is $2v$, but one needs to show that this series converges.)
As a consequence, $C(a,b,c) = H(a{+}c,\,a{-}2b{+}c)$ satisfies the pair of first-order singular analytic PDE listed above.  Consequently,
$$
\sigma(p,q) = C\bigl(|p|^2,\,p{\cdot}q,\,|q|^2\bigr) 
= H\bigl(|p|^2{+}|q|^2,\,|p{-}q|^2\bigr),
$$
Since $H$ is a multiple of $v = |p{-}q|^2$, it follows that
$$
\delta(p,q) = |p{-}q|\,G\bigl(|p|^2{+}|q|^2,\,|p{-}q|^2\bigr)
$$
for some smooth positive function $G(u,v)$.  Meanwhile, for $b<a\in\mathbb{R}$,
taking $p = (a,0)$ and $q=(b,0)$, we have
$$
(a{-}b)\,G\bigl(a^2{+}b^2,\,(a{-}b)^2\bigr) = \delta(p,q) = f(a)-f(b).
$$
The function $G(u,v)$ is determined in the wedge $0\le v\le 2u$ by this equation
as $(a,b)$ vary over the half-plane $b<a$.  It follows from this that
$$
|p{-}q|\,G\bigl(|p|^2{+}|q|^2,\,|p{-}q|^2\bigr)
= f\left(\frac{|p+q|+|p-q|}{2}\right)-f\left(\frac{|p+q|-|p-q|}{2}\right),
$$
as desired.
Remark:  The reader might be startled (as I was initially) upon realizing that the above formula implies a seemingly strange identity
$$
f\left(\frac{|a+b|+|a-b|}{2}\right)-f\left(\frac{|a+b|-|a-b|}{2}\right)
= |f(a)-f(b)|
$$
for all real numbers $a$ and $b$, but, in fact, this identity holds for any increasing odd function $f$.
Added Remark (16 May 2020):  A similar analysis, yielding an explicit distance function, can be done for the incomplete metric
$$
g = (1-x^2-y^2)\bigl(\mathrm{d}x^2+\mathrm{d}y^2\bigr)
$$
on the interior of the unit disk $D$ defined by $x^2+y^2<1$.  This is a metric of positive curvature $K = 4/(1-x^2-y^2)^3$.  What one finds is that, setting
$$
s(x) = \tfrac12\arcsin(x) + \tfrac12x\sqrt{1-x^2}
\quad\text{for}\ |x|\le 1,
$$
the function
$$
\delta(p,q) = s\left(\frac{|p+q|+|p-q|}{2}\right)-s\left(\frac{|p+q|-|p-q|}{2}\right)
$$
gives the length of the shortest geodesic joining $p$ and $q$ when $|p+q|+|p-q|\le 2$.  (This inequality is also the condition for the existence of a geodesic joining $p$ and $q$ within the interior of $D$.)
Meanwhile, regarding the boundary circle $x^2+y^2=1$ as a single point $z$ whose distance from $p\in D$ is $s(1) - s(|p|) = \tfrac14\pi - s(|p|)$, we see that there is always a path from $p$ to $q$ (through z) of length $L(p,q) = \tfrac12\pi - s(|p|)-s(|q|)$.
It is now not difficult to show that the actual distance from $p$ to $q$ is $L(p,q)$ when $|p+q|+|p-q|\ge 2$ and is the minimum of $\delta(p,q)$ and $L(p,q)$ when $|p+q|+|p-q|\le 2$.