TensorIndices
TensorIndices
TensorIndices()A tensor structure with abstract indices for symbolic tensor operations.
TensorIndices represents the index structure of tensors with named abstract indices that can be contracted, manipulated symbolically, and converted to expressions. It maintains both the representation structure and index assignments.
Examples
from symbolica.community.spenso import TensorIndices, Representation, TensorName
rep = Representation.euc(3)
mu = rep('mu')
nu = rep('nu')
indices = TensorIndices(mu, nu)
T = TensorName("T")
named_indices = T(mu, nu)
expr = named_indices.to_expression()Methods
| Name | Description |
|---|---|
__add__ |
Add this expression to other, returning the result. |
__getitem__ |
Get expanded indices at the specified range of flattened indices. |
__len__ |
|
__mul__ |
Add this expression to other, returning the result. |
__new__ |
Create tensor structure from slots and optional arguments. |
__radd__ |
Add this expression to other, returning the result. |
__repr__ |
|
__rmul__ |
Add this expression to other, returning the result. |
__rsub__ |
Subtract this expression from other, returning the result. |
__str__ |
|
__sub__ |
Subtract other from this expression, returning the result. |
get_name |
Get the tensor name of this structure. |
set_name |
Set the tensor name for this structure. |
to_expression |
Convert the tensor indices to a symbolic expression |
__add__
TensorIndices.__add__(rhs: Expression | int | str | float | builtins.complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
__getitem__
__getitem__ has 3 variants:
__getitem__ with item: builtins.slice
TensorIndices.__getitem__(item: builtins.slice) -> builtins.list[Expression | builtins.complex | float]Get expanded indices at the specified range of flattened indices.
Parameters
item(slice) Slice object defining the range of indices
Returns
list of list of intList of expanded indices
__getitem__ with item: typing.Sequence[builtins.int]
TensorIndices.__getitem__(item: typing.Sequence[builtins.int]) -> Expression | builtins.complex | floatGet flattened index associated to this expanded index.
Parameters
item(list of int) Multi-dimensional index coordinates
Returns
intThe flat index
__getitem__ with item: builtins.int
TensorIndices.__getitem__(item: builtins.int) -> Expression | builtins.complex | floatGet expanded index associated to this flat index.
Parameters
item(int) Flat index into the tensor
Returns
list of intMulti-dimensional index coordinates
__len__
TensorIndices.__len__() -> builtins.int__mul__
TensorIndices.__mul__(rhs: Expression | int | str | float | builtins.complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
__new__
TensorIndices.__new__(
*slots: TensorIndices | builtins.list[Slot],
name: TensorName | builtins.str | Expression | None = None,
) -> TensorIndicesCreate tensor structure from slots and optional arguments.
Parameters
*additional_args(Slot or Expression) Mixed arguments (Slot objects and Expressions for additional arguments)name(TensorName, optional) Optional tensor name to assign to the structure
Returns
TensorIndicesA new TensorIndices object
Examples
from symbolica import S
from symbolica.community.spenso import TensorIndices, Representation, TensorName
rep = Representation.euc(3)
mu = rep('mu')
nu = rep('nu')
structure = TensorIndices(mu, nu)
x = S('x')
structure_with_args = TensorIndices(mu, nu, x)
T = TensorName("T")
named_structure = TensorIndices(mu, nu, name=T)__radd__
TensorIndices.__radd__(rhs: Expression | int | str | float | builtins.complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
__repr__
TensorIndices.__repr__() -> builtins.str__rmul__
TensorIndices.__rmul__(rhs: Expression | int | str | float | builtins.complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
__rsub__
TensorIndices.__rsub__(rhs: Expression | int | str | float | builtins.complex | TensorIndices | Expression) -> ExpressionSubtract this expression from other, returning the result.
__str__
TensorIndices.__str__() -> builtins.str__sub__
TensorIndices.__sub__(rhs: Expression | int | str | float | builtins.complex | TensorIndices | Expression) -> ExpressionSubtract other from this expression, returning the result.
get_name
TensorIndices.get_name() -> typing.Optional[TensorName]Get the tensor name of this structure.
Returns
TensorName or NoneThe tensor name if set, None otherwise
Examples
name = structure.get_name()set_name
TensorIndices.set_name(name: TensorName | builtins.str | Expression) -> NoneSet the tensor name for this structure.
Parameters
name(TensorName) The tensor name to assign
Examples
from symbolica.community.spenso import TensorIndices, TensorName, Representation
rep = Representation.euc(3)
structure = TensorIndices(rep('mu'), rep('nu'))
T = TensorName("T")
structure.set_name(T)to_expression
TensorIndices.to_expression() -> ExpressionConvert the tensor indices to a symbolic expression.
Creates a symbolic representation of the tensor with its indices that can be used in algebraic manipulations and pattern matching.
Returns
ExpressionA symbolic Expression representing this indexed tensor
Raises
RuntimeError: If the tensor structure has no name
Examples
from symbolica.community.spenso import TensorName, Representation
T = TensorName("T")
rep = Representation.euc(3)
mu = rep('mu')
nu = rep('nu')
indices = T(mu, nu)
expr = indices.to_expression()