Tensor calculus API
Metric → Christoffel → Riemann / Ricci / Einstein / Weyl on a coordinate chart,
and an abstract-index layer with Einstein summation (tensor).
Every component is computed in an exact field: integer polynomials over the
coordinates, the parameters and one generator per transcendental atom
(sin/cos, sinh/cosh, exp, log, radicals, undefined
functions such as a(t) and their Derivative nodes), with
sin² = 1 − cos², cosh² − sinh² = 1, i² = −1 and (√b)² = b
applied and every denominator made free of sin, radicals and i. That
normal form is canonical, so a component that vanishes identically is the
literal 0 and a non-zero one is never reported as zero — no sampling, no
floats. Only independent components are computed; the rest follow by symmetry.
Conventions (MTW / Carroll / Wald):
Γ^a_{bc} = ½ g^{ad}(∂_b g_{dc} + ∂_c g_{db} − ∂_d g_{bc}),
R^a_{bcd} = ∂_c Γ^a_{db} − ∂_d Γ^a_{cb} + Γ^a_{ce}Γ^e_{db} − Γ^a_{de}Γ^e_{cb},
R_{bd} = R^a_{bad}, G_{ab} = R_{ab} − ½ R g_{ab},
K = R_{abcd}R^{abcd}; the 2-sphere of radius ρ has R = 2/ρ².
Metric
A (pseudo-)Riemannian metric g_{ab} on the chart coords.
glist of lists or MatrixThe symmetric components
g[a][b](Expr,intorFraction).coordssequence of ExprDistinct coordinate symbols, one per row.
- TensorError
E-TENSOR-001(shape / coordinates),E-TENSOR-002(not symmetric),E-TENSOR-003(determinant identically zero),E-TENSOR-004(a float entry),E-TENSOR-005(Piecewiseor another node the exact field cannot hold).
Every curvature method is computed once and cached; timings() reports
the wall time of each stage.
Christoffel symbols of the first kind: out[a][b][c] = Γ_{abc} = g_{ad}Γ^d_{bc}.
Coordinate accelerations d²x^a/dτ² = −Γ^a_{bc} ẋ^b ẋ^c.
velocities defaults to fresh symbols <coord>_dot; any expressions
may be passed (e.g. ak.diff(x(τ), τ)). Returns one Expr per
coordinate.
A Tensor bound to this metric (for raising/lowering).
∂expr/∂coord in canonical form (coord an index or a coordinate).
Abstract indices
Make indices from "a b c" (spaces or commas) or a list of names.
Returns a tuple of contravariant TensorIndex; negate one for the
covariant position.
class Tensor(
components: Any,
variance: str | Sequence[Any],
metric: Metric | None=None
)
Components of a tensor with a fixed variance per slot.
componentsnested listscomponents[i][j]...(rank-many levels; a bareExprfor rank 0).variancestrOne character per slot:
"u"(contravariant) or"d"(covariant), e.g."uddd"forR^a_{bcd}.metricMetric, optionalUsed to raise/lower slots when indexed in the other variance, and to simplify components.
T[0, 1] (integers) is a component; T[-a, -b] (indices) is an
IndexedTensor.
class IndexedTensor(
data: dict[tuple[int, ...], Any],
free: Sequence[TensorIndex],
dim: int,
metric: Metric | None
)
A tensor with named free indices, the result of indexing a Tensor.
Supports +, -, * (outer product with Einstein summation over a
repeated index, once up once down), scalar *//,
symmetrize(), antisymmetrize(), and tensor() /
components to read the result. Components are kept in the
metric's canonical form, so a combination that vanishes is 0.
T_{(ab)} = ½(T_{ab} + T_{ba}) over the named free indices.
T_{[ab]} = ½(T_{ab} − T_{ba}) over the named free indices.
Refusals are TensorError (E-TENSOR-001 … E-TENSOR-010); see
errors.
Indices
An abstract index. +a (or a) is contravariant, -a covariant.