Spenso · latest
On this page

TensorPattern

symbolica.community.tensor Class

TensorPattern(head: TensorName, *, args: Sequence[_ScalarInput] = [], ports: Sequence[Slot | Representation | _ScalarInput] = [])

Representation-aware Symbolica patterns for matching tensor expressions.

Scalar arguments and structural ports are specified separately. Either section can contain Symbolica wildcards, including sequence wildcards. Unlike TensorExpression, a pattern does not require a concrete rank or compatible external tensor axes. Use patterns with TensorRule for checked whole-tensor replacements, or with ordinary Expression matching.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.dirac_gamma(D_, i_, j_, mu_)

Constructor

#

Match a fixed tensor function with separately specified arguments and ports.

Returns

TensorPattern

Pattern expression with args before ports.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern(TensorName("B"), ports=[PortPattern.exact(Representation.euc(3), i_)])

Parameters

NameTypeDefaultDescription
headTensorName—

Exact tensor function head to match.

argsSequence[_ScalarInput][]

Non-index tensor arguments, including ordinary or sequence wildcards.

portsSequence[Slot | Representation | _ScalarInput][]

Structural port patterns, placed after args. PortPattern and sequence wildcards can describe representations, indices, or variable arity.

Member details

any

Static method#
any(name: str, *, args: Sequence[_ScalarInput] = [], ports: Sequence[Slot | Representation | _ScalarInput] = []) -> TensorPattern

Match any tensor-tagged function.

Returns

TensorPattern

Tagged pattern. Concrete arity is not imposed, so sequence wildcards can match the argument and port lists.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
rest = S("ports___")
pattern = TensorPattern.any("T_", ports=[rest])

Parameters

NameTypeDefaultDescription
namestr—

Wildcard function name ending in exactly one underscore.

argsSequence[_ScalarInput][]

Non-index tensor arguments, including ordinary or sequence wildcards.

portsSequence[Slot | Representation | _ScalarInput][]

Structural port patterns, placed after args. PortPattern and sequence wildcards can describe representations, indices, or variable arity.

vector

Static method#
vector(name: str, *, args: Sequence[_ScalarInput] = [], ports: Sequence[Slot | Representation | _ScalarInput] = []) -> TensorPattern

Match a function tagged as a rank-one tensor.

Returns

TensorPattern

Tagged pattern. Concrete arity is not imposed, so sequence wildcards can match the argument and port lists.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
rest = S("ports___")
pattern = TensorPattern.vector("V_", ports=[rest])

Parameters

NameTypeDefaultDescription
namestr—

Wildcard function name ending in exactly one underscore.

argsSequence[_ScalarInput][]

Non-index tensor arguments, including ordinary or sequence wildcards.

portsSequence[Slot | Representation | _ScalarInput][]

Structural port patterns, placed after args. PortPattern and sequence wildcards can describe representations, indices, or variable arity.

dot

Static method#
dot(left: _ScalarInput, right: _ScalarInput) -> TensorPattern

Match a compact tensor dot product.

Returns

TensorPattern

Pattern for the compact dot notation, not explicit indexed products.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.dot(S("left_"), S("right_"))

Parameters

NameTypeDefaultDescription
left_ScalarInput—

Operand patterns, including unrestricted wildcards.

right_ScalarInput—

Operand patterns, including unrestricted wildcards.

chain

Static method#
chain(start: Slot | Representation | _ScalarInput, end: Slot | Representation | _ScalarInput, *factors: _ScalarInput) -> TensorPattern

Match an ordered tensor chain with endpoints and factor patterns.

Returns

TensorPattern

A chain pattern that does not infer a concrete matrix interface.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.chain(i_, j_, S("factors___"))

Parameters

NameTypeDefaultDescription
startSlot | Representation | _ScalarInput—

Endpoint patterns.

endSlot | Representation | _ScalarInput—

Endpoint patterns.

factors_ScalarInput——

trace

Static method#
trace(representation: Representation | Expression, *factors: _ScalarInput) -> TensorPattern

Match a compact cyclic trace.

Returns

TensorPattern

Trace pattern with the cyclic factor wrapper used by tensor notation.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.trace(Representation.euc(3), S("factors___"))

Parameters

NameTypeDefaultDescription
representationRepresentation | Expression—

Exact traced space, representation pattern, or wildcard.

factors_ScalarInput——

casimir

Static method#
casimir(degree: _ScalarInput, representation: Representation | Expression) -> TensorPattern

Match a symbolic Casimir invariant.

Returns

TensorPattern

Pattern for a scalar representation invariant.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.casimir(S("degree_"), S("rep_"))

Parameters

NameTypeDefaultDescription
degree_ScalarInput—

Invariant degree or wildcard.

representationRepresentation | Expression—

Exact representation, representation pattern, or wildcard.

dynkin_index

Static method#
dynkin_index(degree: _ScalarInput, representation: Representation | Expression) -> TensorPattern

Match a symbolic Dynkin index.

Returns

TensorPattern

Pattern for a scalar representation invariant.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.dynkin_index(S("degree_"), S("rep_"))

Parameters

NameTypeDefaultDescription
degree_ScalarInput—

Invariant degree or wildcard.

representationRepresentation | Expression—

Exact representation, representation pattern, or wildcard.

symmetric

Static method#
symmetric(*factors: _ScalarInput) -> TensorPattern

Match a normalized symmetric group of matrix factors.

Returns

TensorPattern

Pattern for the compact FactorProjector syntax inside a chain or trace.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.symmetric(S("factors___"))

Parameters

NameTypeDefaultDescription
factors_ScalarInput——

antisymmetric

Static method#
antisymmetric(*factors: _ScalarInput) -> TensorPattern

Match a normalized antisymmetric group of matrix factors.

Returns

TensorPattern

Pattern for the compact FactorProjector syntax inside a chain or trace.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.antisymmetric(S("factors___"))

Parameters

NameTypeDefaultDescription
factors_ScalarInput——

cyclic

Static method#
cyclic(*factors: _ScalarInput) -> TensorPattern

Match a normalized cyclic group of matrix factors.

Returns

TensorPattern

Pattern for the compact FactorProjector syntax inside a chain or trace.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.cyclic(S("factors___"))

Parameters

NameTypeDefaultDescription
factors_ScalarInput——

gamma0

Static method#
gamma0(spinor_dimension: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the time-component Dirac matrix gamma^0.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.gamma0(D_, i_, j_)

Parameters

NameTypeDefaultDescription
spinor_dimension_ScalarInput—

Spinor dimension or wildcard.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

charge_conjugation

Static method#
charge_conjugation(spinor_dimension: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the Dirac charge-conjugation matrix.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.charge_conjugation(D_, i_, j_)

Parameters

NameTypeDefaultDescription
spinor_dimension_ScalarInput—

Spinor dimension or wildcard.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

levi_civita

Static method#
levi_civita(rep_pattern: Representation | Expression, *indices: _ScalarInput) -> TensorPattern

Match the totally antisymmetric Levi-Civita tensor.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Notes

For an unrestricted number of epsilon axes, use TensorPattern(TensorName.levi_civita(), ports=[ports___]).

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.levi_civita(Representation.euc(D_), i_, j_, a_)

Parameters

NameTypeDefaultDescription
rep_patternRepresentation | Expression—

Exact space or a representation-only PortPattern.

indices_ScalarInput——

g

Static method#
g(rep_pattern: Representation | Expression, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the metric pairing.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.g(Representation.euc(D_), i_, j_)

Parameters

NameTypeDefaultDescription
rep_patternRepresentation | Expression—

Exact space or a representation-only PortPattern.

i_ScalarInput—

Index values, wildcards, or contextual chain endpoints.

j_ScalarInput—

Index values, wildcards, or contextual chain endpoints.

flat

Static method#
flat(rep_pattern: Representation | Expression, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the metric map for raising or lowering an index.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.flat(Representation.euc(D_), i_, j_)

Parameters

NameTypeDefaultDescription
rep_patternRepresentation | Expression—

Exact space or a representation-only PortPattern.

i_ScalarInput—

Index values, wildcards, or contextual chain endpoints.

j_ScalarInput—

Index values, wildcards, or contextual chain endpoints.

dirac_gamma

Static method#
dirac_gamma(minkowski_dimension: _ScalarInput, i: _ScalarInput, j: _ScalarInput, mu: _ScalarInput) -> TensorPattern

Match the Dirac gamma matrices for Clifford algebra.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.dirac_gamma(D_, i_, j_, mu_)

Parameters

NameTypeDefaultDescription
minkowski_dimension_ScalarInput—

Minkowski dimension or wildcard. Spinor dimensions are fixed at four.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

mu_ScalarInput—

Lorentz-index pattern.

gamma5

Static method#
gamma5(spinor_dimension: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the Dirac chirality matrix gamma^5.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.gamma5(D_, i_, j_)

Parameters

NameTypeDefaultDescription
spinor_dimension_ScalarInput—

Spinor dimension or wildcard.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

projm

Static method#
projm(spinor_dimension: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the left-chiral Dirac projector (I - gamma^5)/2.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.projm(D_, i_, j_)

Parameters

NameTypeDefaultDescription
spinor_dimension_ScalarInput—

Spinor dimension or wildcard.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

projp

Static method#
projp(spinor_dimension: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the right-chiral Dirac projector (I + gamma^5)/2.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.projp(D_, i_, j_)

Parameters

NameTypeDefaultDescription
spinor_dimension_ScalarInput—

Spinor dimension or wildcard.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

sigma

Static method#
sigma(minkowski_dimension: _ScalarInput, mu: _ScalarInput, nu: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the antisymmetric Dirac sigma tensor.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.sigma(D_, mu_, nu_, i_, j_)

Parameters

NameTypeDefaultDescription
minkowski_dimension_ScalarInput—

Minkowski dimension or wildcard. Spinor dimensions are fixed at four.

mu_ScalarInput—

Lorentz-index patterns.

nu_ScalarInput—

Lorentz-index patterns.

i_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

j_ScalarInput—

Spinor-index patterns or contextual chain endpoints.

color_f

Static method#
color_f(adjoint_dimension: _ScalarInput, a: _ScalarInput, b: _ScalarInput, c: _ScalarInput) -> TensorPattern

Match the antisymmetric color structure constants f^{abc}.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.color_f(D_, a_, b_, c_)

Parameters

NameTypeDefaultDescription
adjoint_dimension_ScalarInput—

Adjoint dimension or wildcard, e.g. 8 for SU(3).

a_ScalarInput—

Patterns for the three adjoint indices.

b_ScalarInput—

Patterns for the three adjoint indices.

c_ScalarInput—

Patterns for the three adjoint indices.

color_t

Static method#
color_t(adjoint_dimension: _ScalarInput, fundamental_dimension: _ScalarInput, a: _ScalarInput, i: _ScalarInput, j: _ScalarInput) -> TensorPattern

Match the fundamental color generators T^a.

Returns

TensorPattern

Registered tensor syntax with representation-aware port patterns. Wildcards are retained rather than checked as a concrete tensor.

Examples

from symbolica import S
from symbolica.community.tensor import TensorPattern, PortPattern, Representation, TensorName
D_, i_, j_, mu_, nu_, a_, b_, c_ = S("D_", "i_", "j_", "mu_", "nu_", "a_", "b_", "c_")
pattern = TensorPattern.color_t(D_, S("N_"), a_, i_, j_)

Parameters

NameTypeDefaultDescription
adjoint_dimension_ScalarInput—

Adjoint dimension or wildcard, e.g. 8 for SU(3).

fundamental_dimension_ScalarInput—

Fundamental dimension or wildcard, e.g. 3 for SU(3).

a_ScalarInput—

Adjoint-index pattern.

i_ScalarInput—

Fundamental and antifundamental index patterns, or contextual endpoints.

j_ScalarInput—

Fundamental and antifundamental index patterns, or contextual endpoints.