differential_geometry.symbolic.raise_index#
- differential_geometry.symbolic.raise_index(tensor: MutableDenseNDimArray | ImmutableDenseNDimArray | ImmutableDenseMatrix | MutableDenseMatrix, inverse_metric: ImmutableDenseMatrix | MutableDenseMatrix | ImmutableDenseNDimArray | MutableDenseNDimArray, axis: int) MutableDenseNDimArray | ImmutableDenseNDimArray | ImmutableDenseMatrix | MutableDenseMatrix [source]#
Raise a single index of a tensor using the provided inverse metric.
This function supports: - A full inverse metric \(g^{\mu\nu}\) (shape
(n,n)
). - A diagonal inverse metric (1D array of lengthn
) for orthogonal coordinates.General Formula (when inverse_metric is a full matrix):
\[T^{\ldots\mu\ldots} \;=\; T_{\ldots\nu\ldots}\; g^{\mu\nu},\]Orthogonal Diagonal Case (1D array):
\[T^{\ldots\mu\ldots} \;=\; T_{\ldots\mu\ldots} \;\times\; g^{\mu\mu}.\]- Parameters:
tensor (
MutableDenseNDimArray
) – A symbolic tensor of arbitrary rank.inverse_metric (
MutableDenseMatrix
orMutableDenseNDimArray
) – Either a full inverse metric \(g^{\mu\nu}\) (shape(n, n)
) or a 1D diagonal array of shape(n,)
for orthogonal coordinates.axis (
int
) – The index position to raise.
- Returns:
A new tensor with the specified index raised.
- Return type:
See also
Examples
Full matrix usage:
>>> import sympy as sp >>> from pymetric.differential_geometry.symbolic import raise_index >>> >>> r, theta = sp.symbols('r theta', positive=True) >>> # Inverse metric for polar coords >>> ginv = sp.Matrix([[1, 0], [0, 1/r**2]]) >>> # Rank-2 tensor >>> T = sp.Array([ ... [sp.Function("T0")(r, theta), sp.Function("T1")(r, theta)], ... [sp.Function("T2")(r, theta), sp.Function("T3")(r, theta)] ... ]) >>> >>> raise_index(T, ginv, axis=1) [[T0(r, theta), T1(r, theta)/r**2], [T2(r, theta), T3(r, theta)/r**2]]
Orthogonal diagonal usage (just multiply each slice):
>>> # Suppose inverse_metric is [1, 1/r^2] >>> ginv_diag = sp.Array([1, 1/r**2]) >>> raise_index(T, ginv_diag, axis=1) [[T0(r, theta), T1(r, theta)/r**2], [T2(r, theta), T3(r, theta)/r**2]]