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 length n) 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:
Returns:

A new tensor with the specified index raised.

Return type:

MutableDenseNDimArray

See also

lower_index

Examples

  1. 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]]
  1. 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]]