PortPattern

Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.

PortPattern

class PortPattern

A Symbolica pattern for a tensor index or its representation.

Use an exact representation or a wildcard constrained by representation tags. Omitting the index produces representation-only syntax for compact vectors and traces. These are Expression objects for matching, not actual tensor axes with an inferred dimension.

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_")
port = PortPattern.self_dual("SelfDual_", D_, i_)

Methods

Name Description
any Match any registered representation head.
chain_in Refer to a factor’s input endpoint inside a chain or trace pattern.
chain_out Refer to a factor’s output endpoint inside a chain or trace pattern.
dualizable Match a dualizable representation head.
exact Match one specific representation and optionally an index.
self_dual Match a self-dual representation head.

any

PortPattern.any(
    name: builtins.str,
    dimension: _ScalarInput,
    index: typing.Optional[_ScalarInput] = None,
) -> PortPattern

Match any registered representation head.

Parameters

  • name (str) Wildcard name ending in exactly one underscore. Reuse this name to constrain multiple occurrences to the same representation.
  • dimension (scalar expression) Dimension value or wildcard.
  • index (scalar expression, optional) Index value or wildcard. Omit for representation-only syntax.

Returns

  • PortPattern Tagged Symbolica pattern, without constructing a concrete index space.

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_")
port = PortPattern.any("R_", D_, i_)

chain_in

PortPattern.chain_in() -> PortPattern

Refer to a factor’s input endpoint inside a chain or trace pattern.

Returns

  • PortPattern Contextual endpoint marker, interpreted relative to the surrounding factor sequence rather than as an explicit index label.

Notes

Exchange chain_in() and chain_out() in a factor pattern to match its transposed orientation.

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_")
gamma = TensorPattern.dirac_gamma(D_, PortPattern.chain_in(), PortPattern.chain_out(), mu_)

chain_out

PortPattern.chain_out() -> PortPattern

Refer to a factor’s output endpoint inside a chain or trace pattern.

Returns

  • PortPattern Contextual endpoint marker, interpreted relative to the surrounding factor sequence rather than as an explicit index label.

Notes

Exchange chain_in() and chain_out() in a factor pattern to match its transposed orientation.

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_")
gamma = TensorPattern.dirac_gamma(D_, PortPattern.chain_in(), PortPattern.chain_out(), mu_)

dualizable

PortPattern.dualizable(
    name: builtins.str,
    dimension: _ScalarInput,
    index: typing.Optional[_ScalarInput] = None,
    *,
    dual: builtins.bool = False,
) -> PortPattern

Match a dualizable representation head.

Parameters

  • name (str) Wildcard name ending in exactly one underscore. Reuse this name to constrain multiple occurrences to the same representation.
  • dimension (scalar expression) Dimension value or wildcard.
  • index (scalar expression, optional) Index value or wildcard. Omit for representation-only syntax.
  • dual (bool, default False) Match the dual partner rather than the base orientation.

Returns

  • PortPattern Tagged Symbolica pattern, without constructing a concrete index space.

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_")
port = PortPattern.dualizable("Dual_", D_, i_)

exact

PortPattern.exact(rep: Representation, index: typing.Optional[_ScalarInput] = None) -> PortPattern

Match one specific representation and optionally an index.

Parameters

  • rep (Representation) Representation, including its dimension and duality. Its dimension may be a wildcard symbol.
  • index (scalar expression, optional) Exact index or wildcard. Omit it to match representation-only syntax.

Returns

  • PortPattern Symbolica expression for a typed port or a stripped representation.

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_")
port = PortPattern.exact(Representation.euc(3), i_)

self_dual

PortPattern.self_dual(
    name: builtins.str,
    dimension: _ScalarInput,
    index: typing.Optional[_ScalarInput] = None,
) -> PortPattern

Match a self-dual representation head.

Parameters

  • name (str) Wildcard name ending in exactly one underscore. Reuse this name to constrain multiple occurrences to the same representation.
  • dimension (scalar expression) Dimension value or wildcard.
  • index (scalar expression, optional) Index value or wildcard. Omit for representation-only syntax.

Returns

  • PortPattern Tagged Symbolica pattern, without constructing a concrete index space.

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_")
port = PortPattern.self_dual("SelfDual_", D_, i_)