Differential geometry
Standard descriptions of properties like curvature—as used for example in general relativity—are normally based on differential geometry. In its usual formulation this assumes that space is continuous, and can always effectively be treated as some kind of deformed version of ordinary Euclidean space—thus forming what is known as a manifold. The result of this is that points in space can always be specified by lists of coordinates—although historically one of the objectives of differential geometry has been to find ways to define properties like curvature so that they do not depend on the choice of such coordinates. The geometrical properties of a space are in general specified by its so-called metric—and this metric allows one to compute quantities based on lengths and angles from coordinates. The metric can be written as a matrix g, defined so that the analog for infinitesimal vectors u and v of u . v in ordinary Euclidean space is u . g . v. (This is essentially equivalent to saying that infinitesimal arc length is related to infinitesimal coordinate distances by ds2 = gi, j dxi dxj.) In d dimensions the metric g for a so-called Riemannian space can in general be any d × d positive-definite symmetric matrix—and can vary with position. But for ordinary flat Euclidean space it is always just IdentityMatrix[d] (at least with Cartesian coordinates). Within say a surface whose points {x1, x2, …} are obtained by evaluating an expression e as a function of parameters p (so that for example e = {x, y, f[x, y]}, p = {x, y} for a Plot3D surface) the metric turns out to be given by
(Transpose[#] . # &) [Outer[D, e, p]]
In ordinary Euclidean space a defining feature of geometry is that the shortest path between two points is a straight line. But in an arbitrary space things can be more complicated, and in general such a path will be a geodesic (see note below) which can have a more complicated form. If the coordinates along a path are given by an expression s (such as {t, 1 + t, t2}) that depends on a parameter t, and the metric at position p is g[p], then the length of a path turns out to be
Integrate[Sqrt[∂ts . g[s] . ∂ts], {t, t1, t2}]
and geodesics then correspond to paths that extremize this quantity. In ordinary Euclidean space, such paths are straight lines, so that the length of a path between points with lists of coordinates a and b is just the ordinary Euclidean distance Sqrt[(a - b) . (a - b)]. But in general, even though geodesics are not straight lines their lengths can still be used to define a so-called geodesic distance—which turns out to have all the various properties of a distance discussed on page 1030.
If one draws a circle of radius r on a page, then the smaller r is, the more curved the circle will be—and one can define the circle to have a constant curvature equal to 1/r. If one draws a more general curve on a page, one can define its curvature at every point by seeing what size of circle fits it best at that point—or equivalently what the coefficients are in a quadratic approximation. (Compare page 418.) With a 2D surface in ordinary 3D space, one can imagine fitting quadrics (generalized ellipsoids). But these are now specified by two radii, yielding two principal curvatures. And in general these curvatures depend on the way the surface is laid out in 3D space. But a crucial point noted by Carl-Friedrich Gauss in the 1820s is that the product of such curvatures—the so-called Gaussian curvature—is always independent of how the surface is laid out, and can thus be viewed as intrinsic to the surface itself, and for example determined purely from the metric for the 2D space corresponding to the surface.
In a 2D space, intrinsic curvature is completely specified just by Gaussian curvature. In higher-dimensional spaces, there are more components, but in general they are all part of the so-called Riemann tensor—a rank-4 tensor introduced by Bernhard Riemann in 1854. (In Mathematica, the explicit form of such a tensor can be represented as a nested list for which TensorRank[list] 4.) Several descriptions of the Riemann tensor can be given. One is based on looking at infinitesimal vectors u, v and w and asking how much w differs when transported two ways around the edges of a parallelogram, from x to x + u + v via x + u and via x + v. In ordinary flat space there is no difference, but in general the difference is a vector that is defined to be Riemann . u . v. w. (The Riemann that appears here is formally Rijkl.) Another description of the Riemann tensor is based on geodesics. In flat Euclidean space any two geodesics that start parallel always remain so. But a defining feature of general non-Euclidean spaces is that this is not in general so. And it turns out that the Riemann tensor is what determines the rate at which geodesics deviate from being parallel. Still another description of the Riemann tensor is as the coefficient of the quadratic terms in an expansion of the metric about a particular point, using so-called normal coordinates set up to make linear terms vanish. In general the Riemann tensor can always be computed from the metric, though it is somewhat complicated. If p is a list of coordinate parameters that appear in a d-dimensional metric g, then
Riemann = Table[∂p〚j〛Γ〚i, k〛 - ∂p〚i〛Γ〚j, k〛 + Γ〚i, k〛 . Γ〚j〛 - Γ〚j , k〛 . Γ〚i〛, {i, d}, {j, d}, {k, d}]
where the so-called Christoffel symbol Γijk is
Γ = With[{gi = Inverse[g]}, Table[Sum[gi〚l, k〛 (∂p〚j〛g〚i, l〛 + ∂p〚i〛g〚j, l〛 - ∂p〚l〛g〚j, l〛), {l, d}], {i, d}, {j, d}, {k, d}]]/2
There are d4 elements in the nested lists for Riemann, but symmetries and the so-called Bianchi identity reduce the number of independent components to 1/12 d2 (d2 - 1)—or 20 for d = 4. One can then compute the Ricci tensor (Rik = Rijkj) using
RicciTensor = Map[Tr, Transpose[Riemann, {1, 3, 2, 4}], {2}]
and this has 1/2 d(d + 1) independent components in d > 2 dimensions. (The parts of the Riemann tensor not captured by the Ricci tensor correspond to the so-called Weyl tensor; for d = 2 the Ricci tensor has only one independent component, equal to the negative of the Gaussian curvature.) Finally, the Ricci scalar curvature is given by
RicciScalar = Tr[RicciTensor . Inverse[g]]