API

KeldyshContractionModule

KeldyshContraction.jl

docs codecov Benchmarks

Code Style: Blue Aqua QA jet

KeldyshContraction.jl is a package for the symbolic derivation of the two-point correlator diagrams in Keldysh-Schwinger field theory. The symbolic quantum field theory algebra is implemented using SymbolicUtils.jl and TermInterface.jl of the JuliaSymbolic ecosystem. The typesystem has been heavily inspired by the second quantization algebra defined in QuantumCumulants.jl. For more details on the implementation see the "symbolic quantum field algebra" documentation page.

In developing this package, the work SciPost Phys. Core 8, 014 (2025) symbolic quantum field algebra was used extensively. Hence, the corresponding conventions and notation are used in this package.

source

Field Types

Individual Fields

╭───────────────────────── Types hierarchy ───╮
                                             
  KeldyshContraction.QField                  
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━                 
                                         
             ├── KeldyshContraction.QTerm    
             └── KeldyshContraction.QSym     
                 ├── Create                  
                 └── Destroy                 
                                             
╰─────────────────────────────────────────────╯

Field Properties

The field properties are determined by the Enum objects:

KeldyshContraction.KeldyshContourModule
KeldyshContour `Quantum` `Classical`

Keldysh contour enum for the Keldysh quantum field. The Keldysh contour is used to distinguish the field on quantum and classical contour.

source
KeldyshContraction.RegularisationModule
Regularisation `Plus` `Zero` `Minus`

Regularisation enum for the Keldysh quantum field. The regularisation is used to perform tadpole regularisation during the Wick contraction.

source

And the position of the field is determined by the AbstractPosition object:

KeldyshContraction.PositionType
struct Position

Position type for the Keldysh quantum field. The position is used to determine the coordinate of the field during the wick contraction.

Position has thee cases:

  • In: Position.index will be typemax(Int8), which is used to represent the input field.Position
  • Out: Position.index will be typemin(Int8), which is used to represent the output field.Position
  • Bulk: Position.index will be a positive integer
source

Field Constructors

It is expected to create the fields using the Create and Destroy constructors, together with the @qfields macro.

KeldyshContraction.@qfieldsMacro
@qfields

Convenience macro for the construction of fields.

Examples

julia> using KeldyshContraction: Classical, Quantum

julia> @qnumbers ψ::Destroy(Classical)
(ψ,)
source

The created fields are callable to change a property of the individual fields:

using KeldyshContraction
using KeldyshContraction: position

@qfields ϕ::Destroy(Classical)

position(ϕ)
KeldyshContraction.Position(1)

Field Algebra

╭──────────────────────────── Types hierarchy ───╮
                                                
  KeldyshContraction.QField                     
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━                    
                                            
             ├── KeldyshContraction.QSym        
             └── KeldyshContraction.QTerm       
                 ├── KeldyshContraction.QAdd    
                 └── KeldyshContraction.QMul    
                                                
╰────────────────────────────────────────────────╯
KeldyshContraction.QMulType
struct QMul{T<:Number} <: KeldyshContraction.QTerm

Represent a multiplication involving quantum fields of QSym types.

  • arg_c: The commutative prefactor.

  • args_nc: A vector containing all QSym types.

source

The properties of the expression can be checked using:

KeldyshContraction.is_physicalFunction
is_physical(a::QTerm)

Checks if an expression [QTerm])(@ref) is physical. A physical expression is one that if it has an In position field it also has an Out position field and vice versa ([Position])(@ref). Furthermore, In position field can only creation fields (Create) and Out position field can only have annihilation fields (Destroy).

See also: is_conserved

source

Systems

KeldyshContraction.InteractionLagrangianType
struct InteractionLagrangian{T}

Represents an interaction Lagrangian

Fields

  • lagrangian: The Lagrangian expression as a QTerm

  • qfield: The quantum field destruction operator

  • cfield: The classical field destruction operator

  • position: The position of the interaction Lagrangian

  • parameter: Parameters of the perturbation series

Constructor

Constructs an InteractionLagrangian from a given QTerm expression.

Requirements

The constructor enforces several constraints on the input expression and throws AssertionError if any of them are not met:

  • Must be a bulk term (is_bulk)
  • Must be conserved (is_conserved)
  • Must be physical (is_physical)
  • Can only contain up to two different fields
  • Fields must have opposite contours
source

Wick Contraction

KeldyshContraction.wick_contractionFunction
wick_contraction(expr::QTerm)

Compute all possible Wick contractions of quantum fields in the expression expr.

Wick contractions decompose products of quantum field operators into sums of products of propagators (two-point correlation functions). The rules of the contraction are:

  • Conservation (equal numbers of creation/annihilation operators)
  • Physicality (proper time ordering)
  • No quantum-quantum contractions
  • If the fields have a Regularisation applied, the contractions are regularised. The Regularisation property is set to zero after the reguralisation.

The function handles two types of inputs:

  • QAdd: Distributes the contraction over sums
  • QMul: Contracts products of fields into propagators

The function returns a new expression of propagators of type SymbolicUtils.Symbol.

source

Propagator

KeldyshContraction.PropagatorTypeModule
PropagatorType `Keldysh`, `Advanced`, `Retarded`

The type of propagator taken of two fields with the x-y Contour where x is the Contour of the Destroy field and y the contour of the Create field.

  • Keldysh propagator of a Classical-Classical contour
  • Advanced propagator of a Quantum-Classical contour
  • Retarded propagator of a Classical-Quantum contour

The Quantum-Quantum propagator should always be zero.

source
KeldyshContraction.DressedPropagatorType
struct DressedPropagator{E1, E2}

A structure representing dressed propagator in the Retarded-Advanced-Keldysh basis (PropagatorType).

Fields

  • keldysh: The Keldysh component of the propagator

  • retarded: The retarded component of the propagator

  • advanced: The advanced component of the propagator

  • order: The order of the dressed propagator in the perturbation series

  • parameter: Parameters of the perturbation series

where it assumed that the fields are of type Union{SymbolicUtils.Symbolic{<:Number}, Number}.

Constructor

Constructs a DressedPropagator with the given Keldysh, retarded, and advanced components.

source
KeldyshContraction.matrixMethod
matrix(G::DressedPropagator)

Returns the matrix representation of the dressed propagator G in the Retarded-Advanced-Keldysh basis.

\[\hat{G}\left(x_1, x_2\right) =\left( \begin{array}{cc} G^K\left(x_1, x_2\right) & G^R\left(x_1, x_2\right) \\ G^A\left(x_1, x_2\right) & 0 \end{array} \right)\]

source
matrix(Σ::SelfEnergy)

Returns the matrix representation of the self energy Σ in the Retarded-Advanced-Keldysh basis.

\[\hat{\Sigma}\left(y_1, y_2\right)= \left(\begin{array}{cc}0 & \Sigma^A\left(y_1, y_2\right) \\ \Sigma^R\left(y_1, y_2\right) & \Sigma^K\left(y_1, y_2\right) \end{array} \right)\]

source

Self-Energy

KeldyshContraction.SelfEnergyType
struct SelfEnergy{E1, E2}

A struct representing the self-energy components in the Retarded-Advance-Keldysh basis (PropagatorType). The self-energy is divided into three components: Keldysh, retarded, and advanced.

Fields

  • keldysh: The Keldysh component of the self-energy.

  • retarded: The retarded component of the self-energy.

  • advanced: The advanced component of the self-energy.

  • order: The order of the self-energy in the perturbation series

  • parameter: Parameters of the perturbation series

where it assumed that the fields are of type Union{SymbolicUtils.Symbolic{<:Number}, Number}.

Constructor

Constructs a SelfEnergy object from a DressedPropagator. The self-energy is computed based on the Keldysh Green's function (G.keldysh) and expanded into its quantum-quantum (qq), classical-quantum (cq), and quantum-classical (qc) components.

source
KeldyshContraction.matrixMethod
matrix(G::DressedPropagator)

Returns the matrix representation of the dressed propagator G in the Retarded-Advanced-Keldysh basis.

\[\hat{G}\left(x_1, x_2\right) =\left( \begin{array}{cc} G^K\left(x_1, x_2\right) & G^R\left(x_1, x_2\right) \\ G^A\left(x_1, x_2\right) & 0 \end{array} \right)\]

source
matrix(Σ::SelfEnergy)

Returns the matrix representation of the self energy Σ in the Retarded-Advanced-Keldysh basis.

\[\hat{\Sigma}\left(y_1, y_2\right)= \left(\begin{array}{cc}0 & \Sigma^A\left(y_1, y_2\right) \\ \Sigma^R\left(y_1, y_2\right) & \Sigma^K\left(y_1, y_2\right) \end{array} \right)\]

source