TensorIndices
symbolica.community.spenso Class
TensorIndices(*slots: TensorIndices | list[Slot], name: TensorName | str | Expression | None = None)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()Constructor
#Create tensor structure from slots and optional arguments.
Returns
TensorIndices
A 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)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
slots | TensorIndices | list[Slot] | — | — |
name | TensorName | str | Expression | None | None | Optional tensor name to assign to the structure |
Member details
set_name
Methodset_name(name: TensorName | str | Expression) -> NoneSet the tensor name for this structure.
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)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | TensorName | str | Expression | — | The tensor name to assign |
get_name
Methodget_name() -> Optional[TensorName]Get the tensor name of this structure.
Returns
TensorName or None
The tensor name if set, None otherwise
Examples
name = structure.get_name()__repr__
Method__str__
Methodto_expression
Methodto_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
Expression
A symbolic Expression representing this indexed tensor
Raises
RuntimeErrorIf 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()__len__
Method__add__
Method__add__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Expression | int | str | float | complex | TensorIndices | Expression | — | — |
__radd__
Method__radd__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Expression | int | str | float | complex | TensorIndices | Expression | — | — |
__sub__
Method__sub__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> ExpressionSubtract other from this expression, returning the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Expression | int | str | float | complex | TensorIndices | Expression | — | — |
__rsub__
Method__rsub__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> ExpressionSubtract this expression from other, returning the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Expression | int | str | float | complex | TensorIndices | Expression | — | — |
__mul__
Method__mul__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Expression | int | str | float | complex | TensorIndices | Expression | — | — |
__rmul__
Method__rmul__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> ExpressionAdd this expression to other, returning the result.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Expression | int | str | float | complex | TensorIndices | Expression | — | — |
__getitem__
MethodOverloads
Overload 1 #
__getitem__(item: slice) -> list[Expression | complex | float]Get expanded indices at the specified range of flattened indices.
Returns
list of list of int
List of expanded indices
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | slice | — | Slice object defining the range of indices |
Overload 2 #
__getitem__(item: Sequence[int]) -> Expression | complex | floatGet flattened index associated to this expanded index.
Returns
int
The flat index
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | Sequence[int] | — | Multi-dimensional index coordinates |
Overload 3 #
__getitem__(item: int) -> Expression | complex | floatGet expanded index associated to this flat index.
Returns
list of int
Multi-dimensional index coordinates
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | int | — | Flat index into the tensor |
View generated signature source: docs/api/python/spynso3.pyi:955