Interface
These functions (mostly) form the internal interface of the package, and should not be relevant to most users.
QuantumAlgebra.BaseOperatorQuantumAlgebra.CorrQuantumAlgebra.ExpValQuantumAlgebra.ParamQuantumAlgebra.QuExprQuantumAlgebra.QuExprConstructorQuantumAlgebra.QuIndexQuantumAlgebra.QuTermQuantumAlgebra.δQuantumAlgebra.AvacQuantumAlgebra.BosonCreateQuantumAlgebra.BosonDestroyQuantumAlgebra.CorrPerm_islessQuantumAlgebra.CorrTup_islessQuantumAlgebra.FermionCreateQuantumAlgebra.FermionDestroyQuantumAlgebra.TLSCreateQuantumAlgebra.TLSDestroyQuantumAlgebra.TLSxQuantumAlgebra.TLSyQuantumAlgebra.TLSzQuantumAlgebra.auto_normal_formQuantumAlgebra.boson_opsQuantumAlgebra.commQuantumAlgebra.corrQuantumAlgebra.corr_as_expvalsQuantumAlgebra.dropcorrQuantumAlgebra.droplenQuantumAlgebra.expvalQuantumAlgebra.expval2corrs_indsQuantumAlgebra.expval_as_corrsQuantumAlgebra.extindicesQuantumAlgebra.fermion_opsQuantumAlgebra.heisenberg_eomQuantumAlgebra.heisenberg_eom_systemQuantumAlgebra.isintindexQuantumAlgebra.issumindexQuantumAlgebra.julia_expressionQuantumAlgebra.latexQuantumAlgebra.map_scalar_functionQuantumAlgebra.normal_formQuantumAlgebra.paramQuantumAlgebra.set_define_default_opsQuantumAlgebra.set_quindices_typeQuantumAlgebra.sumindexQuantumAlgebra.symmetric_index_numsQuantumAlgebra.tlspm_opsQuantumAlgebra.tlsxyz_opsQuantumAlgebra.use_σpmQuantumAlgebra.use_σxyzQuantumAlgebra.using_auto_normal_formQuantumAlgebra.using_σpmQuantumAlgebra.vacExpValQuantumAlgebra.∑QuantumAlgebra.@anticommuting_fermion_groupQuantumAlgebra.@boson_opsQuantumAlgebra.@fermion_opsQuantumAlgebra.@tlspm_opsQuantumAlgebra.@tlsxyz_ops
QuantumAlgebra.BaseOperator — TypeBaseOperatorRepresents 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 σ_iQuantumAlgebra.Corr — TypeCorr(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⟩cSee also
QuantumAlgebra.ExpVal — TypeExpVal(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
QuantumAlgebra.Param — TypeParam(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 parameterstate: 'r' for real, 'n' for normal, 'c' for conjugateinds: Quantum indices (optional)
Examples
p = Param(:λ, 'r') # Real parameter λ
p = Param(:ω, 'r', 1) # Real parameter ω₁QuantumAlgebra.QuExpr — TypeQuExprA 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., returnQuExprobjects. QuExpr(): Create an empty expression (zero) -zero(QuExpr)works as well.QuExpr(x): Create a constant expression from a numberx.QuExpr(1)is equivalent toone(QuExpr).
See also
QuantumAlgebra.QuExprConstructor — TypeQuExprConstructorHelper 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.
QuantumAlgebra.QuIndex — TypeQuIndexRepresents an index in a quantum operator expression.
A QuIndex can be:
- An integer index (created with
QuIndex(i)for integeri) - A symbolic index like
QuIndex(:i)orQuIndex("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
QuantumAlgebra.QuTerm — TypeQuTermRepresents 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
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)) # δᵢⱼQuantumAlgebra.Avac — MethodAvac(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.
QuantumAlgebra.BosonCreate — MethodBosonCreate(name,inds): represent bosonic creation operator $name_{inds}$
QuantumAlgebra.BosonDestroy — MethodBosonDestroy(name,inds): represent bosonic annihilation operator $name_{inds}$
QuantumAlgebra.CorrPerm_isless — MethodCorrPerm_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)).
QuantumAlgebra.CorrTup_isless — MethodCorrTup_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
QuantumAlgebra.FermionCreate — MethodFermionCreate(name,inds): represent fermionic creation operator $name_{inds}$
QuantumAlgebra.FermionDestroy — MethodFermionDestroy(name,inds): represent fermionic annihilation operator $name_{inds}$
QuantumAlgebra.TLSCreate — MethodTLSCreate(name,inds): represent TLS creation operator $name_{inds}$
QuantumAlgebra.TLSDestroy — MethodTLSDestroy(name,inds): represent TLS annihilation operator $name_{inds}$
QuantumAlgebra.TLSx — MethodTLSx(name,inds): represent TLS x operator $name_{inds}$
QuantumAlgebra.TLSy — MethodTLSy(name,inds): represent TLS y operator $name_{inds}$
QuantumAlgebra.TLSz — MethodTLSz(name,inds): represent TLS z operator $name_{inds}$
QuantumAlgebra.auto_normal_form — Functionauto_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.
QuantumAlgebra.boson_ops — Methodboson_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†)ofQuExprConstructorobjects
Examples
a, a_dag = boson_ops(:a)
expr = a(1) + a_dag(2) # a₁ + a₂†See also
QuantumAlgebra.comm — Methodcomm(A, B)Compute the commutator $[A,B] = A*B - B*A$.
QuantumAlgebra.corr — Methodcorr(A)Wrap bare operators inside A into a formal connected correlator ⟨A⟩₍c₎. Accepts QuTerm or QuExpr; numeric inputs are returned as constant expressions.
QuantumAlgebra.corr_as_expvals — Methodcorr_as_expvals(A::QuExpr)Rewrite connected correlators in A into ordinary expectation values.
QuantumAlgebra.dropcorr — Methoddropcorr(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⟩$.
QuantumAlgebra.droplen — Methoddroplen(n)Create a filter that drops correlators/expectation values with length greater than n. Useful for truncating hierarchies of equations.
QuantumAlgebra.expval — Methodexpval(A)Wrap bare operators inside A into a formal expectation value ⟨A⟩. Accepts QuTerm or QuExpr; numeric inputs are returned as constant expressions.
QuantumAlgebra.expval2corrs_inds — Methodexpval2corrs_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.
QuantumAlgebra.expval_as_corrs — Methodexpval_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}$.
QuantumAlgebra.extindices — Methodextindices(A) return externally visible indices of an expression
QuantumAlgebra.fermion_ops — Methodfermion_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†)ofQuExprConstructorobjects
Examples
f, f_dag = fermion_ops(:f)
expr = f(1) + f_dag(2) # f₁ + f₂†See also
QuantumAlgebra.heisenberg_eom — Functionheisenberg_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\})$.
QuantumAlgebra.heisenberg_eom_system — Functionheisenberg_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()²⟩ QuantumAlgebra.isintindex — Methodisintindex(i::QuIndex)Check if the index i is an integer index (created with QuIndex(i::Integer)).
QuantumAlgebra.issumindex — Methodissumindex(i::QuIndex)Check if the index i is a summation index (created with sumindex(i)).
QuantumAlgebra.julia_expression — Functionjulia_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.
QuantumAlgebra.latex — Methodlatex(A)Render any QuantumObject to a raw LaTeX string using Latexify.jl recipes. Useful for pretty-printing expressions or embedding results in documents.
QuantumAlgebra.map_scalar_function — Methodmap_scalar_function(f, A::QuExpr)Apply a function to all scalar coefficients in a quantum expression.
Arguments
f: Function to apply to each coefficientA: 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 coefficientsQuantumAlgebra.normal_form — Functionnormal_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.
QuantumAlgebra.param — Methodparam(name, [state], inds...)Construct a parameter as a QuExpr. state is one of n (normal/complex), r (real), or c (conjugate). Indices are optional.
QuantumAlgebra.set_define_default_ops — Methodset_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.
QuantumAlgebra.set_quindices_type — Methodset_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": UsesVector{QuIndex}. Allows arbitrary number of indices but is slower due to heap allocation."NTuple{N}": UsesNTuple{N,QuIndex}. Faster (stack allocation) but limits the number of indices per operator to a maximum ofN.
Note that changing this preference requires restarting the Julia session to take effect.
QuantumAlgebra.sumindex — Methodsumindex(i)Create a summation index with index i. These indices are used internally for implicit summation (Einstein summation convention).
QuantumAlgebra.symmetric_index_nums — Methodsymmetric_index_nums(A) return sequence of numbers of exchange-symmetric indices
QuantumAlgebra.tlspm_ops — Methodtlspm_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.
QuantumAlgebra.tlsxyz_ops — Methodtlsxyz_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.
QuantumAlgebra.use_σpm — Functionuse_σ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.
QuantumAlgebra.use_σxyz — Methoduse_σxyz(; set_preference=false)Convenience helper to switch to the (σx, σy, σz) basis. Equivalent to use_σpm(false; set_preference).
QuantumAlgebra.using_auto_normal_form — Methodusing_auto_normal_form()Return whether automatic normal-ordering is currently enabled.
QuantumAlgebra.using_σpm — Methodusing_σpm()Return whether TLS operators are currently configured to use the (σ₊, σ₋) basis.
QuantumAlgebra.vacExpVal — FunctionvacExpVal(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.
QuantumAlgebra.∑ — Method∑(ind,A::QuExpr): return (formal) sum of expression A over index ind.
QuantumAlgebra.@anticommuting_fermion_group — Macro@anticommuting_fermion_group name1 name2 ...: define a group of mutually anticommuting fermionic operators
QuantumAlgebra.@boson_ops — Macro@boson_ops name: define function $name for creating bosonic annihilation operators with name name (also defines deprecated $(name)dag, use $(name)' instead)
QuantumAlgebra.@fermion_ops — Macro@fermion_ops name: define function $name for creating fermionic annihilation operators with name name (also defines deprecated $(name)dag, use $(name)' instead)
QuantumAlgebra.@tlspm_ops — Macro@tlspm_ops name: define functions $(name)m and $(name)p creating jump operators for a two-level system with name name.
QuantumAlgebra.@tlsxyz_ops — Macro@tlsxyz_ops name: define functions $(name)x, $(name)y, and $(name)z creating Pauli operators for a two-level system with name name.