TensorExpression
symbolica.community.spenso Class
TensorExpression()A Symbolica expression with an ordered external tensor interface.
Predefined tensors are constructed by typed factories and indexed afterward in logical interface order. Dimensions are representation metadata, not scalar tensor arguments.
Examples
from symbolica.community.spenso import Representation, TensorExpression
mink = Representation.mink(4)
metric = TensorExpression.g(mink)("mu", "nu")
flat = TensorExpression.flat(mink)("mu", "nu")
gamma = TensorExpression.gamma(4)("i", "j", "mu")
gamma5 = TensorExpression.gamma5(4)("i", "j")
projm = TensorExpression.projm(4)("i", "j")
projp = TensorExpression.projp(4)("i", "j")
sigma = TensorExpression.sigma(4)("mu", "nu", "i", "j")
structure_constant = TensorExpression.f(8)("a", "b", "c")
generator = TensorExpression.t(8, 3)("a", "i", "j")Member details
rank
Property · read-onlyis_scalar
Property · read-onlyinterface
Property · read-onlyname
Property · read-onlyg
Static methodg(rep: Representation) -> TensorExpressionCreate an unresolved metric tensor for rep.
Call the result with two indices to fill its ports in logical order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rep | Representation | — | — |
flat
Static methodflat(rep: Representation) -> TensorExpressionCreate an unresolved musical-isomorphism tensor for rep.
Call the result with two indices to fill its ports in logical order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rep | Representation | — | — |
gamma
Static methodgamma(minkowski_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved gamma matrix with Minkowski dimension minkowski_dimension.
Its public ports use storage order: bispinor, bispinor, then Minkowski. The bispinor dimension is four. Call the result with (i, j, mu) to index it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
minkowski_dimension | int | Expression | str | — | — |
gamma5
Static methodgamma5(spinor_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved gamma-five matrix with two bispinor ports of spinor_dimension; call the result with (i, j).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
spinor_dimension | int | Expression | str | — | — |
projm
Static methodprojm(spinor_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved left-chiral projector with two bispinor ports of spinor_dimension; call the result with (i, j).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
spinor_dimension | int | Expression | str | — | — |
projp
Static methodprojp(spinor_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved right-chiral projector with two bispinor ports of spinor_dimension; call the result with (i, j).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
spinor_dimension | int | Expression | str | — | — |
sigma
Static methodsigma(minkowski_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved sigma matrix with Minkowski dimension minkowski_dimension.
Its logical ports are two Minkowski ports followed by two four-dimensional bispinor ports. Call the result with (mu, nu, i, j) to index it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
minkowski_dimension | int | Expression | str | — | — |
f
Static methodf(adjoint_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved color structure constant.
All three logical ports are adjoint representations of adjoint_dimension; call the result with (a, b, c).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
adjoint_dimension | int | Expression | str | — | — |
t
Static methodt(adjoint_dimension: int | Expression | str, fundamental_dimension: int | Expression | str) -> TensorExpressionCreate an unresolved color generator.
The logical ports are adjoint, fundamental, and antifundamental. Dimensions belong to those representations and are not tensor key arguments.
Examples
from symbolica.community.spenso import TensorExpression
generator = TensorExpression.t(8, 3)
indexed = generator("a", "i", "j")Parameters
| Name | Type | Default | Description |
|---|---|---|---|
adjoint_dimension | int | Expression | str | — | — |
fundamental_dimension | int | Expression | str | — | — |
with_name
Methodwith_name(name: TensorName | str | Expression | TensorExpression) -> TensorExpressionReturn a named descriptor without changing the underlying expression.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | TensorName | str | Expression | TensorExpression | — | — |
__len__
Methodto_expression
Methodto_expression() -> ExpressionDrop the structured interface and return an ordinary Symbolica Expression.
reinfer
Methodreinfer() -> TensorExpressionRe-parse the underlying symbolic expression and rebuild its ordered tensor interface.
expand
Methodexpand(var: Optional[Expression | int | Float | int | float | str | decimal.Decimal | ComplexFloat | Float | int | float | str | decimal.Decimal | complex | tuple[Float | int | float | str | decimal.Decimal, Float | int | float | str | decimal.Decimal]] = None, via_poly: Optional[bool] = None) -> TensorExpressionExpand scalar algebra while preserving and validating the tensor interface.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
var | Optional[Expression | int | Float | int | float | str | decimal.Decimal | ComplexFloat | Float | int | float | str | decimal.Decimal | complex | tuple[Float | int | float | str | decimal.Decimal, Float | int | float | str | decimal.Decimal]] | None | — |
via_poly | Optional[bool] | None | — |
simplify_gamma
Methodsimplify_gamma(settings: Optional[GammaSimplifySettings] = None) -> TensorExpressionApply Idenso's gamma-algebra simplifier and re-infer the tensor interface.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[GammaSimplifySettings] | None | — |
collect_gamma_chains
Methodcollect_gamma_chains() -> TensorExpressionConvert bispinor tensors into chain/trace shorthands and join adjacent gamma chains.
simplify_gamma0
Methodsimplify_gamma0() -> TensorExpressionSimplify products and linear combinations involving the time-like gamma matrix gamma0.
simplify_gamma_conjugate
Methodsimplify_gamma_conjugate() -> TensorExpressionRewrite conjugated gamma matrices as gamma0-sandwiched matrices.
simplify_epsilon
Methodsimplify_epsilon() -> TensorExpressionSimplify Levi-Civita/metric contractions and pairs of Levi-Civita tensors.
simplify_metrics
Methodsimplify_metrics() -> TensorExpressionContract metric and identity tensors and re-infer the external interface.
simplify_color
Methodsimplify_color(settings: Optional[ColorSimplifySettings] = None) -> TensorExpressionApply Idenso's SU(N) color-algebra simplifier and re-infer the interface.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[ColorSimplifySettings] | None | — |
collect_color
Methodcollect_color() -> TensorExpressionFactor around tensors carrying fundamental, antifundamental, or adjoint color.
collect_color_constants
Methodcollect_color_constants() -> TensorExpressionFactor around recognized scalar color invariants such as Casimirs and indices.
to_color_casimir
Methodto_color_casimir(*, fundamental: Representation, adjoint: Representation, settings: Optional[ColorCasimirSettings] = None) -> TensorExpressionRewrite supplied color dimensions and invariants into a representation-aware Casimir basis.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
fundamental | Representation | — | — |
adjoint | Representation | — | — |
settings | Optional[ColorCasimirSettings] | None | — |
to_cof_dimension_invariants
Methodto_cof_dimension_invariants() -> TensorExpressionReplace supported cof(N) invariants by explicit dimension formulas.
wrap_color
Methodwrap_color(symbol: Expression) -> TensorExpressionExpand around color structures and wrap each scalar coefficient with symbol.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
symbol | Expression | — | — |
expand_mink
Methodexpand_mink() -> list[tuple[Expression, Expression]]Selectively expand around Minkowski structures into (structure, coefficient) pairs.
expand_bis
Methodexpand_bis() -> list[tuple[Expression, Expression]]Selectively expand around bispinor structures into (structure, coefficient) pairs.
expand_mink_bis
Methodexpand_mink_bis() -> list[tuple[Expression, Expression]]Selectively expand around Minkowski and bispinor structures into factorized pairs.
expand_metrics
Methodexpand_metrics() -> list[tuple[Expression, Expression]]Selectively expand around metric tensors into (structure, coefficient) pairs.
expand_color
Methodexpand_color() -> list[tuple[Expression, Expression]]Selectively expand around color structures into (structure, coefficient) pairs.
expand_in_patterns
Methodexpand_in_patterns(patterns: Sequence[Expression]) -> list[tuple[Expression, Expression]]Selectively expand around the supplied Symbolica patterns into factorized pairs.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
patterns | Sequence[Expression] | — | — |
wrap_indices
Methodwrap_indices(header: Expression) -> ExpressionWrap every abstract-index payload with header and return an ordinary expression.
Wrapped payloads are not Spenso abstract indices until they are cooked, so the result intentionally has no TensorExpression interface.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
header | Expression | — | — |
cook_indices
Methodcook_indices(settings: Optional[CookSettings] = None) -> TensorExpressionFlatten nested representation-index payloads using index cooking by default.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[CookSettings] | None | — |
cook_function
Methodcook_function(settings: Optional[CookSettings] = None) -> ExpressionEncode one function call as an ordinary Symbolica expression.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[CookSettings] | None | — |
wrap_dummies
Methodwrap_dummies(header: Expression) -> TensorExpressionWrap only contracted-index payloads with header and re-infer the interface.
Raises ValueError when the expression cannot be parsed as a tensor network.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
header | Expression | — | — |
list_dangling
Methodlist_dangling() -> list[Expression]Return the ordered external, uncontracted indices as Symbolica expressions.
Raises ValueError when the expression cannot be parsed as a tensor network.
canonize
Methodcanonize() -> TensorExpressionCanonically order tensor factors and deterministically rename contracted indices.
alias_subtensors
Methodalias_subtensors(tensor_name: str) -> tuple[Expression, list[tuple[Expression, Expression]]]Replace nested tensor subexpressions by aliases and return the root plus alias mappings.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
tensor_name | str | — | — |
spenso_conjugate
Methodspenso_conjugate() -> TensorExpressionComplex-conjugate this tensor expression and re-infer its interface.
conjugate_transpose
Methodconjugate_transpose(representation: Representation) -> TensorExpressionComplex-conjugate this expression and transpose slots in representation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
representation | Representation | — | — |
dirac_adjoint
Methoddirac_adjoint() -> TensorExpressionConstruct the physics-aware Dirac adjoint and re-infer the tensor interface.
cook
Methodcook(settings: Optional[CookSettings] = None) -> ExpressionEncode this expression using Idenso's reversible cooking format.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[CookSettings] | None | — |
uncook
Methoduncook(settings: Optional[CookSettings] = None) -> TensorExpressionRestore a reversibly cooked expression and re-infer its tensor interface.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[CookSettings] | None | — |
schoonschip
Methodschoonschip(settings: Optional[SchoonschipSettings] = None) -> TensorExpressionSimplify tensor shorthands using the configured Schoonschip traversal.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[SchoonschipSettings] | None | — |
schoonschip_net
Methodschoonschip_net(settings: Optional[SchoonschipSettings] = None, *, expand_contracted_sums: bool = False) -> TensorExpressionParse and contract this expression as a symbolic tensor network.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
settings | Optional[SchoonschipSettings] | None | — |
expand_contracted_sums | bool | False | — |
to_dots
Methodnormalize_dots
Methodexpand_dots
Methodmetric_shorthand_to_dot
Methodundo_all
Methodundo_schoonschip
Methodundo_schoonschip() -> TensorExpressionExpand Schoonschip shorthands while leaving dots, chains, and traces compact.
undo_dots
Methodundo_chain
Methodundo_trace
Methodcollect_chains
Methodcollect_chains(representation: Representation) -> TensorExpressionJoin adjacent open chains for representation and re-infer the interface.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
representation | Representation | — | — |
chainify
Methodchainify(representation: Representation) -> TensorExpressionRewrite tensors with two representation slots as open-chain factors.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
representation | Representation | — | — |
normalize_chains
Methodundo_single_length
Methodto_network
Methodto_network(library: Optional[TensorLibrary] = None) -> TensorNetworkMaterialize unresolved ports and parse this expression as a tensor network.
When library is omitted, use the built-in four-dimensional HEP and SU(3) library.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
library | Optional[TensorLibrary] | None | — |
index
Methodindex(*indices: Any, cook_indices: bool = False) -> TensorExpressionFill the unresolved external ports with indices in interface order.
Pass AUTO to leave a port unresolved. Set cook_indices=True to flatten nested symbolic index payloads before insertion. Repeated compatible indices contract their ports, in which case the result no longer carries the original stored-data identity.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
indices | Any | — | — |
cook_indices | bool | False | — |
__call__
Method__call__(*indices: Any, cook_indices: bool = False) -> TensorExpressionFill the unresolved external ports with indices in interface order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
indices | Any | — | — |
cook_indices | bool | False | — |
__neg__
Method__add__
Method__add__(rhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
__radd__
Method__radd__(lhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
lhs | Any | — | — |
__sub__
Method__sub__(rhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
__rsub__
Method__rsub__(lhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
lhs | Any | — | — |
__mul__
Method__mul__(rhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
__rmul__
Method__rmul__(lhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
lhs | Any | — | — |
__truediv__
Method__truediv__(rhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
__rtruediv__
Method__rtruediv__(lhs: Any) -> TensorExpression | TensorNetworkNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
lhs | Any | — | — |
outer
Methodouter(rhs: Any) -> TensorExpression | TensorNetworkForm an outer product without contracting compatible ports.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
contract
Methodcontract(rhs: Any, *, left: int, right: int) -> TensorExpression | TensorNetworkContract one selected pair of ordered interface positions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
left | int | — | — |
right | int | — | — |
compose
Methodcompose(rhs: Any, *, left: tuple[int, int], right: tuple[int, int]) -> TensorExpression | TensorNetworkCompose two selected (input, output) matrix channels.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
rhs | Any | — | — |
left | tuple[int, int] | — | — |
right | tuple[int, int] | — | — |
trace
Methodformat_tensor
Methodformat_tensor(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None) -> strFormat this structured expression using compact Spenso notation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
show_dimensions | Optional[bool] | None | — |
settings | Optional[DisplaySettings] | None | — |
to_typst
Methodto_typst(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None) -> strFormat this structured expression as Typst math source.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
show_dimensions | Optional[bool] | None | — |
settings | Optional[DisplaySettings] | None | — |
formatted
Methodformatted(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None, notation_source: Optional[str] = None) -> FormattedOutputBuild Symbolica's rich display value, including semantic HTML when the optional gammaloop[typst-display] renderer is installed.
notation_source is a trusted complete replacement for the bundled notation.typ module, not a style fragment. Typst executes it. When HTML cannot be rendered, the result retains its LaTeX and text forms.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
show_dimensions | Optional[bool] | None | — |
settings | Optional[DisplaySettings] | None | — |
notation_source | Optional[str] | None | — |
to_html
Methodto_html(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None, notation_source: Optional[str] = None) -> strCompile this expression to semantic HTML with the optional Typst renderer.
Install gammaloop[typst-display] to enable this method. notation_source, when supplied, is trusted Typst code replacing the complete bundled notation.typ module.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
show_dimensions | Optional[bool] | None | — |
settings | Optional[DisplaySettings] | None | — |
notation_source | Optional[str] | None | — |
to_svg
Methodto_svg(show_dimensions: Optional[bool] = None, *, settings: Optional[DisplaySettings] = None, notation_source: Optional[str] = None) -> strCompile this expression to SVG with the optional Typst renderer.
Install gammaloop[typst-display] to enable this method. notation_source, when supplied, is trusted Typst code replacing the complete bundled notation.typ module.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
show_dimensions | Optional[bool] | None | — |
settings | Optional[DisplaySettings] | None | — |
notation_source | Optional[str] | None | — |
__repr__
Method__str__
Method_repr_pretty_
Method_repr_pretty_(pretty: Any, cycle: bool) -> NoneNo description is available for this member.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pretty | Any | — | — |
cycle | bool | — | — |
_repr_html_
Method_repr_latex_
Method__getitem__
MethodOverloads
Overload 1 #
__getitem__(item: int) -> list[int]Convert a logical row-major flat index to tensor coordinates.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | int | — | — |
Overload 2 #
__getitem__(item: Sequence[int]) -> intConvert tensor coordinates to a logical row-major flat index.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | Sequence[int] | — | — |
Overload 3 #
__getitem__(item: slice) -> list[list[int]]Expand a slice of logical row-major flat indices to tensor coordinates.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
item | slice | — | — |
View generated signature source: docs/api/python/spynso3.pyi:930