Square of the distance function on a Riemannian manifold Let $(M^n,g)$ be a smooth Riemannian manifold. Consider the square of the distance function
$$dist^2\colon M\times M\to \mathbb{R}$$
given by $(x,y)\mapsto dist^2(x,y)$. It is easy to see that this function is infinitely smooth near the diagonal.
Now fix a point $a\in M$. Consider the Taylor series of $dist^2$ at $(a,a)$ in some coordinate system (say normal). Can one compute explicitly its coefficients up to the third order?
 A: Fix a point $x_0 \in M$. Then let $x = \exp_{x_0}(t v)$ and $y=\exp_{x_0}(t w)$, with $v,w \in T_{x_0}M$.
Then we have the following formula for the distance squared between two geodesic emanating from $x_0$
$$ d^2(\exp_{x_0}(t v),\exp_{x_0}(t w)) = |v-w|^2t^2-\frac{1}{3}R(v,w,w,v) t^4 + O(t^5)$$
whre $R$ is the Riemann curvature tensor. From here you can derive an expression where you follow the two geodesics for different times (just rescale $w \to s/t w$), that is
$$ d^2(\exp_{x_0}(t v),\exp_{x_0}(s w)) = |v|^2t^2 +|w|s^2 -2 g(v,w) ts -\frac{1}{3}R(v,w,w,v) s^2 t^2 + O(|t^2+s^2|^{5/2})$$
Take now $|v| = |w|=1$, then $(t,v)$ and $(s,w)$ (both $\in [0,\epsilon) \times \mathbb{S}_{x_0}^{n-1}$) are polar coordinates of $x,y$. More explicitly, setting $t = d(x_0,x)$ and $s = d(x_0,y)$, you have
$$ d^2(x,y) = t^2 + s^2 - 2\cos\theta t s - \tfrac{1}{3} K_\sigma (1-\cos\theta^2)t^2 s^2 +  O(|t^2+s^2|^{5/2})$$
where $\cos\theta = g(v,w)$ is the angle between the two vectors and $K_\sigma$ is the sectional curvature of the plane $\sigma = \mathrm{span}(v,w)$.
As you can see, this can be used effectively as a purely metric definition of sectional curvature, with no connection or covariant derivative whatsoever.
A: The function $dist^2$ satisfies   a Hamilton-Jacobi equation. Using this  you can  find its Taylor expansion  at $(a,a)$ up to any order. In Appendix A of this paper I  use this approach  to find  the degree 4 Taylor expansion  of this function; see Eq. (A.17) in the paper. The procedure  used in this appendix can be used to find the degree $6$ expansion as well, though the formulas become increasingly more complicated.  I should mention that this approach is also used in
B. DeWitt: The Global Approach to Quantum Field Theory, Oxford University Press, 2003,
pages 281-282, though the physicists' notation may be a bit hard to follow.
