sft_wick.expressions — Symbolic Expression Tree

All expression types are frozen dataclasses — immutable and hashable. Uses exact rational arithmetic via fractions.Fraction.

Expr

Base class for all symbolic expressions.

Rational

Exact rational number.

Symbol

A named symbol, possibly with indices.

Propagator

A two-point function C_{ij}(x, x') or R_{ij}(x, x').

Sum

Sum of expressions.

Product

Product of expressions.

SumOverIndex

Summation over a component index: sum_{i=1}^{N} body.

IntegralOver

Integration over a spatial variable: integral d(var) body.

KroneckerDelta

delta_{ij} for component indices.

DiracDelta

delta(x - y) for spatial arguments.

ImaginaryUnit

The imaginary unit \(\mathrm{i}\).

apply_response_phase

Multiply each term by \((-\mathrm{i})^n\) where n is the number of response propagators R in that term.

Custom symbolic expression tree for Wick contraction results.

All expression types are frozen dataclasses (immutable + hashable). Uses exact rational arithmetic via fractions.Fraction.

class sft_wick.expressions.Expr[source]

Bases: ABC

Base class for all symbolic expressions.

abstractmethod to_latex()[source]
Return type:

str

class sft_wick.expressions.Rational(numerator, denominator=1)[source]

Bases: Expr

Exact rational number.

Parameters:
  • numerator (int)

  • denominator (int)

numerator: int
denominator: int = 1
classmethod from_number(n)[source]
Parameters:

n (int | Fraction)

Return type:

Rational

property is_zero: bool
property is_one: bool
to_fraction()[source]
Return type:

Fraction

to_latex()[source]
Return type:

str

class sft_wick.expressions.Symbol(name, indices=(), spatial_args=())[source]

Bases: Expr

A named symbol, possibly with indices.

Examples

Symbol(‘F’, (‘i’, ‘j’, ‘k’)) -> F_{ijk} Symbol(‘K’, (‘i’, ‘j’), (‘y_0’, ‘y_1’)) -> K_{ij}(y_0, y_1)

Parameters:
name: str
indices: tuple[str, ...] = ()
spatial_args: tuple[str, ...] = ()
to_latex()[source]
Return type:

str

class sft_wick.expressions.Propagator(kind, index_left, index_right, spatial_left, spatial_right)[source]

Bases: Expr

A two-point function C_{ij}(x, x’) or R_{ij}(x, x’).

For scalar fields, index_left and index_right are None.

Convention for R: the physical field’s index/position is always on the left. R_{ij}(x, x’) means <phi_i(x) psi_j(x’)>_{S_0}.

Parameters:
  • kind (str)

  • index_left (str | None)

  • index_right (str | None)

  • spatial_left (str)

  • spatial_right (str)

kind: str
index_left: str | None
index_right: str | None
spatial_left: str
spatial_right: str
to_latex()[source]
Return type:

str

class sft_wick.expressions.Sum(terms)[source]

Bases: Expr

Sum of expressions.

Parameters:

terms (tuple[Expr, ...])

terms: tuple[Expr, ...]
to_latex()[source]
Return type:

str

class sft_wick.expressions.Product(factors)[source]

Bases: Expr

Product of expressions.

Parameters:

factors (tuple[Expr, ...])

factors: tuple[Expr, ...]
to_latex()[source]
Return type:

str

class sft_wick.expressions.SumOverIndex(index_name, dimension, body)[source]

Bases: Expr

Summation over a component index: sum_{i=1}^{N} body.

Parameters:
index_name: str
dimension: int
body: Expr
to_latex()[source]
Return type:

str

class sft_wick.expressions.IntegralOver(variable, body)[source]

Bases: Expr

Integration over a spatial variable: integral d(var) body.

Parameters:
variable: str
body: Expr
to_latex()[source]
Return type:

str

class sft_wick.expressions.KroneckerDelta(index1, index2)[source]

Bases: Expr

delta_{ij} for component indices.

Parameters:
index1: str
index2: str
to_latex()[source]
Return type:

str

class sft_wick.expressions.DiracDelta(arg1, arg2)[source]

Bases: Expr

delta(x - y) for spatial arguments.

Parameters:
arg1: str
arg2: str
to_latex()[source]
Return type:

str

class sft_wick.expressions.ImaginaryUnit[source]

Bases: Expr

The imaginary unit \(\mathrm{i}\).

Used to represent the phase factor \((-\mathrm{i})^n\) that arises from the MSR convention \(\langle\phi\,\psi\rangle \propto -\mathrm{i}\,R\).

to_latex()[source]
Return type:

str

sft_wick.expressions.I = ImaginaryUnit()

Module-level constant for the imaginary unit.

sft_wick.expressions.apply_response_phase(expr)[source]

Multiply each term by \((-\mathrm{i})^n\) where n is the number of response propagators R in that term.

This implements the MSR convention \(\langle\phi(a)\,\psi(b)\rangle = -\mathrm{i}\,R(a,b)\).

The phase is absorbed into the existing rational coefficient so that the factored form of the expression is preserved. For example, \((-\mathrm{i})^3 = \mathrm{i}\) applied to a term with prefactor \(-\tfrac{1}{6}\) yields \(-\tfrac{\mathrm{i}}{6}\).

Parameters:

expr (Expr)

Return type:

Expr