On this page

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

NameTypeDefaultDescription
slotsTensorIndices | list[Slot]
nameTensorName | str | Expression | NoneNone

Optional tensor name to assign to the structure

Member details

set_name

Method
#
set_name(name: TensorName | str | Expression) -> None

Set 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

NameTypeDefaultDescription
nameTensorName | str | Expression

The tensor name to assign

get_name

Method
#
get_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
#
__repr__() -> str

No description is available for this member.

__str__

Method
#
__str__() -> str

No description is available for this member.

to_expression

Method
#
to_expression() -> Expression

Convert 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

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()

__len__

Method
#
__len__() -> int

No description is available for this member.

__add__

Method
#
__add__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> Expression

Add this expression to other, returning the result.

Parameters

NameTypeDefaultDescription
rhsExpression | int | str | float | complex | TensorIndices | Expression

__radd__

Method
#
__radd__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> Expression

Add this expression to other, returning the result.

Parameters

NameTypeDefaultDescription
rhsExpression | int | str | float | complex | TensorIndices | Expression

__sub__

Method
#
__sub__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> Expression

Subtract other from this expression, returning the result.

Parameters

NameTypeDefaultDescription
rhsExpression | int | str | float | complex | TensorIndices | Expression

__rsub__

Method
#
__rsub__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> Expression

Subtract this expression from other, returning the result.

Parameters

NameTypeDefaultDescription
rhsExpression | int | str | float | complex | TensorIndices | Expression

__mul__

Method
#
__mul__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> Expression

Add this expression to other, returning the result.

Parameters

NameTypeDefaultDescription
rhsExpression | int | str | float | complex | TensorIndices | Expression

__rmul__

Method
#
__rmul__(rhs: Expression | int | str | float | complex | TensorIndices | Expression) -> Expression

Add this expression to other, returning the result.

Parameters

NameTypeDefaultDescription
rhsExpression | int | str | float | complex | TensorIndices | Expression

__getitem__

Method
#

Overloads

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
NameTypeDefaultDescription
itemslice

Slice object defining the range of indices

Overload 2 #
__getitem__(item: Sequence[int]) -> Expression | complex | float

Get flattened index associated to this expanded index.

Returns

int

The flat index

Parameters
NameTypeDefaultDescription
itemSequence[int]

Multi-dimensional index coordinates

Overload 3 #
__getitem__(item: int) -> Expression | complex | float

Get expanded index associated to this flat index.

Returns

list of int

Multi-dimensional index coordinates

Parameters
NameTypeDefaultDescription
itemint

Flat index into the tensor