Interface

These functions (mostly) form the internal interface of the package, and should not be relevant to most users.

QuantumAlgebra.BaseOperatorType
BaseOperator

Represents a single quantum operator in an expression.

A BaseOperator is one of:

  • Bosonic operators: BosonCreate, BosonDestroy
  • Fermionic operators: FermionCreate, FermionDestroy
  • Two-level system (TLS) operators: TLSCreate, TLSDestroy, TLSx, TLSy, TLSz

Each operator is associated with a name and indices.

Examples

a = BosonCreate(:a)        # Bosonic creation operator a†
f = FermionDestroy(:f, 1)  # Fermionic annihilation operator f₁
σx = TLSx(:σ, :i)          # TLS x operator σ_i
source
QuantumAlgebra.CorrType
Corr(ops::BaseOpProduct)

Represents a correlator ⟨ops⟩c in a quantum expression.

Correlators (or cumulants) represent connected correlations in the expectation value.

Examples

corr = Corr(BaseOpProduct([a, a_dag]))  # ⟨a† a⟩c

See also

ExpVal, corr

source
QuantumAlgebra.ExpValType
ExpVal(ops::BaseOpProduct)

Represents an expectation value ⟨ops⟩ in a quantum expression.

Expectation values contain products of quantum operators that should be evaluated as a single unit.

Examples

ev = ExpVal(BaseOpProduct([a, a_dag]))  # ⟨a† a⟩

See also

Corr, expval

source
QuantumAlgebra.ParamType
Param(name, state, inds)

Represents a parameter in a quantum expression.

Parameters are scalar values that can appear in quantum expressions, with optional indices and conjugation state.

Arguments

  • name: Symbol identifying the parameter
  • state: 'r' for real, 'n' for normal, 'c' for conjugate
  • inds: Quantum indices (optional)

Examples

p = Param(:λ, 'r')        # Real parameter λ
p = Param(:ω, 'r', 1)     # Real parameter ω₁
source
QuantumAlgebra.QuExprType
QuExpr

A quantum algebra expression represented as a sum of terms.

A QuExpr is a dictionary mapping QuTerms to numeric coefficients stored as Number. Using Number allows heterogeneous numeric types (e.g., Int, Float64, Rational, Complex) to coexist without forced type conversions.

Constructors

  • The quantum operator constructors generated with @boson_ops, @fermion_ops, etc., return QuExpr objects.
  • QuExpr(): Create an empty expression (zero) - zero(QuExpr) works as well.
  • QuExpr(x): Create a constant expression from a number x. QuExpr(1) is equivalent to one(QuExpr).

See also

QuTerm, normal_form

source
QuantumAlgebra.QuExprConstructorType
QuExprConstructor

Helper struct for creating operator expressions with automatic conjugate support.

Used internally by macros like @boson_ops and @fermion_ops to provide both normal and daggered operator constructors.

source
QuantumAlgebra.QuIndexType
QuIndex

Represents an index in a quantum operator expression.

A QuIndex can be:

  • An integer index (created with QuIndex(i) for integer i)
  • A symbolic index like QuIndex(:i) or QuIndex("i_2")
  • A sum index created with sumindex(n)

Examples

i = QuIndex(1)              # Integer index 1
i = QuIndex(:i)             # Symbolic index 'i'
i = QuIndex("i_2")          # Symbolic index 'i' with subscript 2
si = sumindex(1)            # Sum index #₁

See also

sumindex, issumindex, isintindex

source
QuantumAlgebra.QuTermType
QuTerm

Represents a single term in a quantum algebra expression.

A term consists of:

  • Sum indices (summed-over indices)
  • Delta functions
  • Parameters
  • Expectation values
  • Correlators/cumulants
  • Bare operators

See also

QuExpr, BaseOperator

source
QuantumAlgebra.δType
δ(iA, iB)

Represents a Kronecker delta function δ_{iA,iB} in a quantum expression.

The delta function is zero if indices are different, and one if they are the same.

Examples

δ(QuIndex(1), QuIndex(2))    # δ₁₂
δ(QuIndex(:i), QuIndex(:j))  # δᵢⱼ
source
QuantumAlgebra.AvacMethod
Avac(A; modes_in_vacuum=nothing)
vacA(A; modes_in_vacuum=nothing)

Simplify an operator expression by acting on the vacuum from the right (Avac) or from the left (vacA). Returns a new QuExpr with terms that annihilate the vacuum removed and with any TLS σz eigenvalue simplifications applied. Set modes_in_vacuum to a set or iterable of modes to restrict the vacuum assumption; defaults to all modes.

source
QuantumAlgebra.CorrPerm_islessMethod
CorrPerm_isless(a,b)

isless for Tuples of Tuples representing products of Corr (see above) of a permutation of operators. E.g., ((1,3),(2,)) represents <A1 A3>C <A2>C. It is assumed that the total number of operators in a and b is equal, i.e., that sum(length.(a)) == sum(length.(b)).

source
QuantumAlgebra.CorrTup_islessMethod
CorrTup_isless(a,b)

isless for Tuples of integers that represent Corr of sorted operators (with n representing An such that n<m == An<Am). (n,m,...) ≡ Corr(AnAm...). Defined in such a way that the same order is obtained as with BaseOperator objects

source
QuantumAlgebra.auto_normal_formFunction
auto_normal_form(t::Bool=true; set_preference=false)

Enable or disable automatic normal-ordering of expressions on construction. When set_preference is true, the setting is stored with Preferences.jl.

source
QuantumAlgebra.boson_opsMethod
boson_ops(name::Symbol)

Create constructors for bosonic operators with the given name.

Returns a tuple of (annihilation, creation) operators that can be called to create quantum expressions containing these operators.

Arguments

  • name: Symbol for the operator name (e.g., :a, :b)

Returns

  • Tuple (a, a†) of QuExprConstructor objects

Examples

a, a_dag = boson_ops(:a)
expr = a(1) + a_dag(2)  # a₁ + a₂†

See also

fermion_ops, @boson_ops

source
QuantumAlgebra.corrMethod
corr(A)

Wrap bare operators inside A into a formal connected correlator ⟨A⟩₍c₎. Accepts QuTerm or QuExpr; numeric inputs are returned as constant expressions.

source
QuantumAlgebra.dropcorrMethod
dropcorr(n::Int)

Returns a filter function that rewrites terms with correlations corrs or expectation values expvals of length greater than n in terms of lower-order expressions (up to order n) and higher-order correlators, and then drops those higher-order correlations.

For example, dropcorr(1) will replace $⟨a^† a⟩ = ⟨a^† a⟩_c + ⟨a^†⟩ ⟨a⟩ ≈ ⟨a^†⟩ ⟨a⟩$.

source
QuantumAlgebra.droplenMethod
droplen(n)

Create a filter that drops correlators/expectation values with length greater than n. Useful for truncating hierarchies of equations.

source
QuantumAlgebra.expvalMethod
expval(A)

Wrap bare operators inside A into a formal expectation value ⟨A⟩. Accepts QuTerm or QuExpr; numeric inputs are returned as constant expressions.

source
QuantumAlgebra.expval2corrs_indsMethod
expval2corrs_inds(N::Int)

for N operators, create an array of tuples of tuples that represents the terms in a sum of products of correlators. Each tuple corresponds to a sum term, see CorrTup_isless and CorrPerm_isless for details of the format. The returned array and terms are sorted such that if the N operators are sorted, the represented expression is also sorted with the conventions of the QuantumAlgebra package. This allows to directly return a normal-ordered form.

source
QuantumAlgebra.expval_as_corrsMethod
expval_as_corrs(expr::QuExpr)

Take an expression expr=A B C + D E... and write its expectation value in terms of correlations $⟨A⟩_c, ⟨B⟩_c, ⟨AB⟩_c, ⟨ABC⟩_c, \ldots$. Note that $⟨A⟩_c = ⟨A⟩$.

E.g., expval_as_corrs(a'(:n)*a(:n)) returns $⟨a^\dagger_n a_n⟩_c + ⟨a^\dagger_n⟩_c ⟨a_n⟩_c$ (which is equal to $⟨a^\dagger_n a_n⟩$), while expval_as_corrs(a'(:n)*a(:m)*a(:n)) returns $\langle a_{n}^\dagger a_{m} a_{n} \rangle_{c} + \langle a_{n}^\dagger \rangle_{c} \langle a_{m} \rangle_{c} \langle a_{n} \rangle_{c} + \langle a_{n}^\dagger \rangle_{c} \langle a_{m} a_{n} \rangle_{c} + \langle a_{m} \rangle_{c} \langle a_{n}^\dagger a_{n} \rangle_{c} + \langle a_{n} \rangle_{c} \langle a_{n}^\dagger a_{m} \rangle_{c}$.

See also: expval, corr

source
QuantumAlgebra.fermion_opsMethod
fermion_ops(name::Symbol)

Create constructors for fermionic operators with the given name.

Returns a tuple of (annihilation, creation) operators that can be called to create quantum expressions containing these operators.

Arguments

  • name: Symbol for the operator name (e.g., :f, :c)

Returns

  • Tuple (f, f†) of QuExprConstructor objects

Examples

f, f_dag = fermion_ops(:f)
expr = f(1) + f_dag(2)  # f₁ + f₂†

See also

boson_ops, @fermion_ops

source
QuantumAlgebra.heisenberg_eomFunction
heisenberg_eom(A, H; Ls=())

Compute the Heisenberg equation of motion for an observable A with Hamiltonian H and optional Lindblad operators Ls.

Returns $\dot{A} = i [H,A] + \sum_i (L_i^† A L_i - \tfrac{1}{2} \{L_i^† L_i, A\})$.

source
QuantumAlgebra.heisenberg_eom_systemFunction
heisenberg_eom_system(H, rhsfilt, Ls=(), ops=nothing)

Calculates the system of Heisenberg equations of motion for either the expectation values or the cumulants / correlators of operator products, starting from a Hamiltonian H and a list of Lindblad terms Ls describing decoherence.

rhsfilt is a filter function that is applied to the right-hand side of the equations. Typically, these equation systems are not closed without approximations as equations for products of n operators involve products of m>n operators, so the system has to be truncated. This is achieved with the filter function that removes higher-order terms or rewrites them (approximately) in terms of lower-order expressions.

ops is an optional list of operators for which the equations should be generated. If ops is nothing (default), the function will try to determine the relevant operators automatically from the Hamiltonian and Lindblad terms.

The function returns a QuEqSys object containing the system of equations.

Examples

julia> using QuantumAlgebra
julia> @boson_ops a;
julia> H = Pr"ω"*a'()*a() + Pr"χ"*a'()*(a'()+a())*a();
julia> Ls = ((Pr"γ",a()),);
julia> EQ = heisenberg_eom_system(H,2,Ls,a())
dₜ⟨a()⟩ = -1//2 γ ⟨a()⟩  - 1i ω ⟨a()⟩  - 2i χ ⟨a†() a()⟩  - 1i χ ⟨a()²⟩ 
dₜ⟨a†() a()⟩ = -γ ⟨a†() a()⟩ 
dₜ⟨a()²⟩ = -2i χ ⟨a()⟩  - γ ⟨a()²⟩  - 2i ω ⟨a()²⟩ 
source
QuantumAlgebra.julia_expressionFunction
julia_expression(A; varnames=nothing)

Convert a QuExpr (or related quantum objects) into a plain Julia expression constructed from numbers and symbolic variables. Optional varnames argument restricts allowed expectation value or correlator symbols; when provided, conjugates may be rewritten to match available names.

source
QuantumAlgebra.latexMethod
latex(A)

Render any QuantumObject to a raw LaTeX string using Latexify.jl recipes. Useful for pretty-printing expressions or embedding results in documents.

source
QuantumAlgebra.map_scalar_functionMethod
map_scalar_function(f, A::QuExpr)

Apply a function to all scalar coefficients in a quantum expression.

Arguments

  • f: Function to apply to each coefficient
  • A: Quantum expression

Returns

A new QuExpr with function applied to all coefficients

Examples

A = QuExpr(a) + 2 * QuExpr(a_dag)
B = map_scalar_function(x -> 2x, A)  # Double all coefficients
source
QuantumAlgebra.normal_formFunction
normal_form(A::QuExpr; shortcut_vacA_zero=false)

Return an equivalent expression in normal-ordered form (all commutations performed).

shortcut_vacA_zero can be set to true when the expression will be multiplied by a vacuum state from the right, allowing early elimination of annihilation terms.

source
QuantumAlgebra.paramMethod
param(name, [state], inds...)

Construct a parameter as a QuExpr. state is one of n (normal/complex), r (real), or c (conjugate). Indices are optional.

source
QuantumAlgebra.set_define_default_opsMethod
set_define_default_ops(t::Bool)

Set the preference for whether to define default operators (a, adag, f, fdag, σx, σy, σz, σp, σm) upon import. Default is true.

Note that changing this preference requires restarting the Julia session to take effect.

source
QuantumAlgebra.set_quindices_typeMethod
set_quindices_type(t::String)

Set the preference for the underlying type used to store indices. t must be either "Vector" (default) or "NTuple{N}" (where N is an integer).

  • "Vector": Uses Vector{QuIndex}. Allows arbitrary number of indices but is slower due to heap allocation.
  • "NTuple{N}": Uses NTuple{N,QuIndex}. Faster (stack allocation) but limits the number of indices per operator to a maximum of N.

Note that changing this preference requires restarting the Julia session to take effect.

source
QuantumAlgebra.sumindexMethod
sumindex(i)

Create a summation index with index i. These indices are used internally for implicit summation (Einstein summation convention).

source
QuantumAlgebra.tlspm_opsMethod
tlspm_ops(name::Symbol)

Return constructors for TLS ladder operators (σ₋, σ₊) for the given name.

The concrete output depends on use_σpm: when true, returns annihilation/creation expressions; when false, returns linear combinations of σx and σy.

source
QuantumAlgebra.tlsxyz_opsMethod
tlsxyz_ops(name::Symbol)

Return constructors for Pauli operators (σₓ, σ_y, σ_z) for the given name.

The concrete output depends on use_σpm: when true, returns combinations of ladder operators; when false, returns the direct σx/σy/σz operators.

source
QuantumAlgebra.use_σpmFunction
use_σpm(t::Bool=true; set_preference=false)

Select whether TLS operators are expressed in the (σ₊, σ₋) basis (true) or in the (σx, σy, σz) basis (false). If set_preference is true, the choice is persisted via Preferences.jl for future sessions.

source
QuantumAlgebra.use_σxyzMethod
use_σxyz(; set_preference=false)

Convenience helper to switch to the (σx, σy, σz) basis. Equivalent to use_σpm(false; set_preference).

source
QuantumAlgebra.vacExpValFunction
vacExpVal(A::QuExpr, S::QuExpr=1; modes_in_vacuum=nothing)

Calculate the vacuum expectation value $⟨0|S^\\dagger A S|0⟩$, i.e. the expectation value $⟨ψ|A|ψ⟩$ for the state $|ψ⟩ = S|0⟩$. Optionally restrict the vacuum assumption to specific modes via modes_in_vacuum.

source
QuantumAlgebra.@boson_opsMacro

@boson_ops name: define function $name for creating bosonic annihilation operators with name name (also defines deprecated $(name)dag, use $(name)' instead)

source
QuantumAlgebra.@fermion_opsMacro

@fermion_ops name: define function $name for creating fermionic annihilation operators with name name (also defines deprecated $(name)dag, use $(name)' instead)

source
QuantumAlgebra.@tlspm_opsMacro

@tlspm_ops name: define functions $(name)m and $(name)p creating jump operators for a two-level system with name name.

source
QuantumAlgebra.@tlsxyz_opsMacro

@tlsxyz_ops name: define functions $(name)x, $(name)y, and $(name)z creating Pauli operators for a two-level system with name name.

source