Interface
These functions (mostly) form the internal interface of the package, and should not be relevant to most users.
QuantumAlgebra.BaseOperatorQuantumAlgebra.CorrQuantumAlgebra.DeltaViewQuantumAlgebra.ExpValQuantumAlgebra.IndexViewQuantumAlgebra.ItemSeqQuantumAlgebra.OpPartitionQuantumAlgebra.OpProductQuantumAlgebra.ParamQuantumAlgebra.QuExprQuantumAlgebra.QuExprConstructorQuantumAlgebra.QuIndexQuantumAlgebra.QuTermQuantumAlgebra.QuditVariableQuantumAlgebra.SOVariableQuantumAlgebra.WorkTermQuantumAlgebra._COWDictQuantumAlgebra.δQuantumAlgebra.AvacQuantumAlgebra.BosonCreateQuantumAlgebra.BosonDestroyQuantumAlgebra.CorrPerm_islessQuantumAlgebra.CorrTup_islessQuantumAlgebra.FermionCreateQuantumAlgebra.FermionDestroyQuantumAlgebra.TLSCreateQuantumAlgebra.TLSDestroyQuantumAlgebra.TLSxQuantumAlgebra.TLSyQuantumAlgebra.TLSzQuantumAlgebra._canonicalize_sumindsQuantumAlgebra._encode_termQuantumAlgebra._reorder_sumindsQuantumAlgebra._suminds_canonicalQuantumAlgebra._suminds_signaturesQuantumAlgebra.anticommuting_fermionsQuantumAlgebra.auto_normal_formQuantumAlgebra.baresQuantumAlgebra.bosonQuantumAlgebra.boson_opsQuantumAlgebra.commQuantumAlgebra.commutesQuantumAlgebra.contract!QuantumAlgebra.corrQuantumAlgebra.corr_as_expvalsQuantumAlgebra.corrsQuantumAlgebra.deltasQuantumAlgebra.dropcorrQuantumAlgebra.droplenQuantumAlgebra.exchange!QuantumAlgebra.expvalQuantumAlgebra.expval2corrs_indsQuantumAlgebra.expval_as_corrsQuantumAlgebra.expvalsQuantumAlgebra.extindicesQuantumAlgebra.fermionQuantumAlgebra.fermion_opsQuantumAlgebra.gellmannQuantumAlgebra.heisenberg_eomQuantumAlgebra.heisenberg_eom_systemQuantumAlgebra.indsQuantumAlgebra.isintindexQuantumAlgebra.issumindexQuantumAlgebra.julia_expressionQuantumAlgebra.latexQuantumAlgebra.make_indicesQuantumAlgebra.map_scalar_functionQuantumAlgebra.normal_formQuantumAlgebra.normal_order!QuantumAlgebra.nsumindsQuantumAlgebra.opextraQuantumAlgebra.opnameQuantumAlgebra.opsQuantumAlgebra.optypeQuantumAlgebra.paramQuantumAlgebra.paramsQuantumAlgebra.parstateQuantumAlgebra.qindexQuantumAlgebra.qparamQuantumAlgebra.quditQuantumAlgebra.qudit_levelsQuantumAlgebra.qudit_opQuantumAlgebra.set_define_default_opsQuantumAlgebra.set_quindices_typeQuantumAlgebra.soQuantumAlgebra.so_generatorQuantumAlgebra.so_opQuantumAlgebra.spinQuantumAlgebra.spin_jQuantumAlgebra.sumindexQuantumAlgebra.symmetric_index_numsQuantumAlgebra.tlsQuantumAlgebra.tlspm_opsQuantumAlgebra.tlsxyzQuantumAlgebra.tlsxyz_opsQuantumAlgebra.use_bracket_displayQuantumAlgebra.use_σpmQuantumAlgebra.use_σxyzQuantumAlgebra.using_auto_normal_formQuantumAlgebra.using_bracket_displayQuantumAlgebra.using_σpmQuantumAlgebra.vacExpValQuantumAlgebra.ϵ_abQuantumAlgebra.∑QuantumAlgebra.@anticommuting_fermion_groupQuantumAlgebra.@anticommuting_fermionsQuantumAlgebra.@bosonQuantumAlgebra.@boson_opsQuantumAlgebra.@fermionQuantumAlgebra.@fermion_opsQuantumAlgebra.@qindexQuantumAlgebra.@qparamQuantumAlgebra.@quditQuantumAlgebra.@soQuantumAlgebra.@spinQuantumAlgebra.@tlsQuantumAlgebra.@tlspm_opsQuantumAlgebra.@tlsxyzQuantumAlgebra.@tlsxyz_ops
QuantumAlgebra.OpProduct — Typeany (stored or mutable) product of operators
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.DeltaView — TypeDeltaView: the Kronecker deltas of a term (a read-only view into its storage)
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.IndexView — TypeIndexView: the indices of an operator or parameter (a read-only view into its storage)
QuantumAlgebra.ItemSeq — TypeItemSeq{T}: n consecutive items of type T (stored in nw words starting at w[off])
QuantumAlgebra.OpPartition — TypeOpPartition: a partition of operators 1:N into groups, each given by the (sorted) indices of the operators in it
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.QuditVariable — TypeQuditVariableA qudit created by qudit or @qudit: q(i,j) is the transition operator $|i⟩⟨j|$ (for a qudit with indices, an object that is indexed with the indices, q(i,j)[k]).
QuantumAlgebra.SOVariable — TypeSOVariableThe generators of so(n) created by so or @so: L(a,b) is the generator $L_{ab}$ (for generators with indices, an object that is indexed with the indices, L(a,b)[k]).
QuantumAlgebra.WorkTerm — TypeWorkTermMutable working form of a QuTerm used while normal ordering. All vectors are owned by the WorkTerm and can be modified freely. Convert back with QuTerm(w::WorkTerm).
QuantumAlgebra._COWDict — Type_COWDict{K,V}()A dictionary that can be read from several threads without locking. It is never modified in place, but replaced as a whole (under a lock) when entries are added, so it is only meant for small tables (such as caches with few entries).
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 an operator or an iterable of operators to restrict the vacuum assumption to these modes; defaults to all modes. The operators are given without indices, i.e., as the variables defined by the macros (e.g., a after @boson a or @boson a[:]), and stand for all modes of an operator with indices.
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._canonicalize_suminds — Method_canonicalize_suminds(t::QuTerm)Renumber the sum indices of the normal-ordered term t canonically. Returns (tc, sign, isnormal) such that t = sign*tc, where isnormal is true if tc is in normal form, or nothing if the term vanishes (because renumbering gives the same term with opposite sign).
QuantumAlgebra._encode_term — Method_encode_term(nsuminds, δs, params, expvals, corrs, bares, fδ, f)Create a QuTerm from its parts. Each part is a tuple of collections whose concatenation gives the respective part of the term. The index function fδ is applied to the indices of the δs and f to all other indices (nothing stands for no change). Index functions are applied in the order in which the indices are stored, i.e., δs, params, expvals, corrs, bares.
QuantumAlgebra._reorder_suminds — Method_reorder_suminds(t::QuTerm): renumber the sum indices of t in the order in which they appear (returns t if that is already the case)
QuantumAlgebra._suminds_canonical — Method_suminds_canonical(t::QuTerm): whether the sum indices of the normal-ordered term t are numbered canonically
QuantumAlgebra._suminds_signatures — Method_suminds_signatures(t::QuTerm): signatures of the sum indices of t that do not depend on their numbering
QuantumAlgebra.anticommuting_fermions — Methodanticommuting_fermions(names...; ndims=0)Return fermionic annihilation operators with the given names that mutually anticommute (the function version of @anticommuting_fermions), see fermion.
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.bares — Methodbares(t::QuTerm): the product of "bare" operators (outside expectation values) in the term
QuantumAlgebra.boson — Methodboson(name; ndims=0)Return the bosonic annihilation operator name (the function version of @boson), where name is a Symbol or a string (which can be any name, e.g., "c↑"). With ndims=0, this is the operator itself, and otherwise an object a such that a[i,j,…] (with ndims indices) is the operator with these indices. The creation operator is obtained as a' (or a'[i,j,…]).
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$, in normal form.
The commutator is computed directly from the commutators of pairs of single operators (with the Leibniz rule), so that only the terms that do not cancel are generated.
QuantumAlgebra.commutes — Methodcommutes(A, B): whether operators A and B commute.
QuantumAlgebra.contract! — Methodcontract!(emit, A, B): simplify the product A B. Returns nothing if it does not simplify, or (fac, op) with A B = fac op + R (see exchange! for R).
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.corrs — Methodcorrs(t::QuTerm): the correlators Corr in the term
QuantumAlgebra.deltas — Methoddeltas(t::QuTerm): the Kronecker deltas δ in the term
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.exchange! — Methodexchange!(emit, B, A): rewrite B A = x A B + R, with A < B. Passes the terms of R to emit(c, δs, ops...) and returns x.
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 partitions (see OpPartition) that represents the terms in a sum of products of correlators. Each partition corresponds to a sum term. Internally, they are computed as tuples of tuples, see CorrTup_isless and CorrPerm_isless for details. 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.expvals — Methodexpvals(t::QuTerm): the expectation values ExpVal in the term
QuantumAlgebra.extindices — Methodextindices(A) return externally visible indices of an expression
QuantumAlgebra.fermion — Methodfermion(name; ndims=0)Return the fermionic annihilation operator name (the function version of @fermion), see boson. Fermions with different names commute, see anticommuting_fermions for fermions that anticommute.
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.gellmann — Methodgellmann(q::QuditVariable; sqrt=Base.sqrt)Return the d²-1 generalized Gell-Mann matrices $λ_1, …, λ_{d²-1}$ of the d-level qudit q (see qudit), with the standard normalization $\mathrm{Tr}(λ_a λ_b) = 2δ_{ab}$ (for a qudit with indices, as objects that are indexed with the indices, λ[1][k]). For k = 2, …, d, these are (in this order) the pairs $|j⟩⟨k| + |k⟩⟨j|$ and $-i|j⟩⟨k| + i|k⟩⟨j|$ for $j = 1, …, k-1$, followed by the diagonal matrix $\sqrt{2/(l(l+1))} (\sum_{m≤l} |m⟩⟨m| - l |l+1⟩⟨l+1|)$ with $l = k-1$. For d = 3, these are the Gell-Mann matrices $λ_1, …, λ_8$ in their usual order. Note that since level 1 is the ground state, for d = 2 they correspond to $(σ^x, -σ^y, -σ^z)$.
The normalization factors $\sqrt{2/(l(l+1))}$ of the diagonal matrices are computed by calling sqrt with the rational number 2//(l*(l+1)) (unless the result is rational, e.g., for l = 1). By default, this gives Float64 numbers. To keep them exact, pass a function that computes the square root symbolically, e.g., sqrt = x -> sqrt(SymPyPythonCall.Sym(x)).
Examples
q = qudit(:q, 3)
λ = gellmann(q)
normal_form(comm(λ[1], λ[2])) # 2i λ₃
λ[8] # 0.57735 - 1.73205 q³³()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.inds — Methodinds(A): the indices of an operator or parameter
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.make_indices — Methodmake_indices(inds...): convert the arguments (or a single tuple or vector of them) to a vector of QuIndex
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.normal_order! — Functionnormal_order!(ops::BaseOpProduct, term_collector, shortcut_vacA_zero=false, prefactor=1)Bring the operator product ops into normal order in place. Returns the prefactor p of the reordered product, such that the original prefactor*ops is equal to p*ops (after reordering) plus the terms that are added to term_collector (which still have to be normal ordered).
QuantumAlgebra.nsuminds — Methodnsuminds(t::QuTerm): number of summation indices in the term
QuantumAlgebra.opextra — Methodopextra(A::BaseOperator): additional (family-specific) information stored with an operator
QuantumAlgebra.opname — Methodopname(A): the name (as a QuOpName) of an operator or parameter
QuantumAlgebra.ops — Methodops(A::Union{ExpVal,Corr}): the product of operators inside the expectation value or correlator
QuantumAlgebra.optype — Methodoptype(A::BaseOperator): the BaseOpType of an operator
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.params — Methodparams(t::QuTerm): the parameters Param in the term
QuantumAlgebra.parstate — Methodparstate(A::Param): one of 'r' (real), 'n' (normal/complex) or 'c' (complex conjugate)
QuantumAlgebra.qindex — Methodqindex(name::Symbol; ndims=0)Return the index name (the function version of @qindex): with ndims=0, the index itself, and with ndims=1, an object j such that j[n] is the index with name j and numeric subindex n (printed as jₙ).
QuantumAlgebra.qparam — Functionqparam(name, T=Real; ndims=0)Return the parameter name (the function version of @qparam), which is real for T = Real and complex for T = Complex. The name is a Symbol or a string, which can be any name, e.g., "f(t)" (which is also how the parameter appears in julia_expression). With ndims=0, this is the parameter itself, and otherwise an object g such that g[i,j,…] (with ndims indices) is the parameter with these indices. For a complex parameter α, α' (or α'[i]) is its complex conjugate.
QuantumAlgebra.qudit — Methodqudit(name, d::Integer; ndims=0)Return the qudit (d-level system) name (the function version of @qudit), such that q(i,j) is the transition operator $|i⟩⟨j|$ (with levels 1 ≤ i,j ≤ d). With ndims > 0, the qudit has ndims indices, given as q(i,j)[k,…]. Level 1 is the ground state, i.e., the vacuum.
Internally, all operators are expressed through the "creation" operators $|i⟩⟨1|$ and "annihilation" operators $|1⟩⟨i|$ (with $i ≥ 2$), using $|i⟩⟨j| = |i⟩⟨1|1⟩⟨j|$ and $|1⟩⟨1| = 1 - \sum_{k≥2} |k⟩⟨1|1⟩⟨k|$, which gives a unique normal form. For d=2, q(2,1) and q(1,2) are equivalent to $σ^{+}$ and $σ^{-}$. When printing, products $|i⟩⟨1|1⟩⟨j|$ acting on the same qudit are shown as $|i⟩⟨j|$ (written qⁱʲ).
Examples
q = qudit(:q, 3)
normal_form(q(1,2)*q(2,3)) # |1⟩⟨3|
q(1,1) # 1 - |2⟩⟨2| - |3⟩⟨3|
r = qudit(:r, 3; ndims=1)
r(2,3)[:i] # |2⟩⟨3| = |2⟩⟨1|1⟩⟨3| acting on qudit iQuantumAlgebra.qudit_levels — Methodqudit_levels(A): (d,i,j) for a qudit operator A = |i⟩⟨j| (with i == 1 or j == 1) of a d-level system
QuantumAlgebra.qudit_op — Methodqudit_op(name, d, i, j, inds): the operator |i⟩⟨j| of a d-level system, with either i == 1 or j == 1 (but not both)
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)Deprecated: indices are now always stored in a compact form that supports an arbitrary number of indices, so the "quindices_type" preference no longer has any effect.
QuantumAlgebra.so — Methodso(name, n::Integer; ndims=0)Return the generators L of the Lie algebra so(n) of rotations in n dimensions (the function version of @so), such that L(a,b) is the generator $L_{ab} = -L_{ba}$ ($a,b = 1,…,n$). With ndims > 0, the generators have ndims indices, given as L(a,b)[k,…]. The generators are Hermitian, with
\[[L_{ab}, L_{cd}] = i (δ_{ac} L_{bd} - δ_{ad} L_{bc} - δ_{bc} L_{ad} + δ_{bd} L_{ac}),\]
as, e.g., for the angular momenta $L_{ab} = x_a p_b - x_b p_a$ of a particle in n dimensions (for n = 3, $(L_x, L_y, L_z) = (L_{23}, L_{31}, L_{12})$). Only these commutation relations are used, so that results hold in any representation. Operators are stored and printed as $L_{ab}$ with $a < b$.
Examples
L = so(:L, 4)
L(2,1) # -L¹²()
normal_form(comm(L(1,2), L(2,3))) # -i L¹³()QuantumAlgebra.so_generator — Methodso_generator(A): (n,a,b) for the generator A = L_ab (with a < b) of so(n)
QuantumAlgebra.so_op — Methodso_op(name, n, a, b, inds): the generator L_ab of so(n), with a < b
QuantumAlgebra.spin — Functionspin(name, j=nothing; ndims=0)Return the operators (Jp, Jm, Jz), i.e., $J_+$, $J_-$ and $J_z$, of the spin name (the function version of @spin), see boson for ndims. They generate the Lie algebra su(2) ≅ so(3), with $[J_z,J_±] = ±J_±$ and $[J_+,J_-] = 2J_z$. If j is not given, only these commutation relations are used, which hold in any representation (e.g., for collective spins). If the spin j is given (any number, e.g., 1//2, 3, or a symbolic variable), products $J_+ J_-$ acting on the same spin are replaced by $j(j+1) - J_z^2 + J_z$, and the vacuum is the lowest-weight state with $J_-|0⟩ = 0$ and $J_z|0⟩ = -j|0⟩$. Note that other relations that hold for a specific j (e.g., $J_+^2 = 0$ for j = 1//2) are not used.
QuantumAlgebra.spin_j — Methodspin_j(A): the spin j of the spin operator A, or nothing if it is not fixed
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.tls — Methodtls(name; ndims=0)Return the lowering operator $σ^-$ of the two-level system name (the function version of @tls), see boson. The raising operator $σ^+$ is obtained as σ'. The operators are represented as jump operators or through Pauli matrices depending on use_σpm (at the time the operator is created).
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 — Methodtlsxyz(name; ndims=0)Return the Pauli matrices $(σ^x, σ^y, σ^z)$ of the two-level system name (the function version of @tlsxyz), see boson and tls.
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_bracket_display — Functionuse_bracket_display(t::Bool=true; set_preference=false)Select whether operators and parameters are printed in the syntax of the interface with operator variables (see @boson), e.g., a†[i,j], g[i] and a (for true), or with parentheses, e.g., a†(ij), g(i) and a() (for false, the default in v1.x). If set_preference is true, the choice is stored with Preferences.jl for future sessions.
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_bracket_display — Methodusing_bracket_display()Return whether operators are printed in the syntax with brackets (see use_bracket_display).
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 (see Avac).
QuantumAlgebra.ϵ_ab — Methodϵ_ab(A,B): for Pauli matrices σᵃ, σᵇ (with a≠b), return the third one, σᶜ, and the Levi-Civita symbol ϵ_abc
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.@anticommuting_fermions — Macro@anticommuting_fermions c d[:] ...
@anticommuting_fermions cu="c↑" cd="c↓" ...Define fermionic annihilation operators that mutually anticommute (see anticommuting_fermions and @boson). All of them must have the same number of indices.
QuantumAlgebra.@boson — Macro@boson a
@boson a[:,:]
@boson a b[:] ...
@boson au="a↑" ad[:]="a↓" ...Define the variable a for a bosonic annihilation operator (see boson). With a[:,:] (with any number of :), the operator has as many indices, given as a[i,j] (with indices declared by @qindex, or with symbols and integers, e.g., a[:i,2]). The creation operator is a' (or a'[i,j]). Several operators can be defined at once, and with au = "a↑", the variable au is an operator with the name a↑ (also for the other macros that define operators or parameters). This can be any name, e.g., one that is not a valid variable name. Note that unicode characters in names are converted to LaTeX for LaTeX output (e.g., @boson b̄ gives $\bar{b}$), so a LaTeX name (which is also used for text output) is usually not needed.
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 — Macro@fermion f
@fermion f[:,:] g cu="c↑" ...Define the variable f for a fermionic annihilation operator (see fermion and @boson).
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.@qindex — Macro@qindex i j[:] ...Define the indices i, j, … (see qindex), where an index declared as j[:] has a numeric subindex, j[2] (printed as j₂). Indices can then be used directly, e.g., a[i,j[2]] (instead of a[:i,:j_2]).
QuantumAlgebra.@qparam — Macro@qparam g
@qparam g[:,:] α::Complex ft="f(t)" ...Define the variable g for a real parameter, or several parameters at once (see qparam). With g[:,:] (with any number of :), the parameter has indices, given as g[i,j]. Parameters declared as α::Complex (or α[:]::Complex) are complex, and α' (or α'[i]) is their complex conjugate. With ft = "f(t)", the variable ft is the parameter with the name f(t) (see @boson).
QuantumAlgebra.@qudit — Macro@qudit d q
@qudit d q[:,:]
@qudit d q r[:] ...Define the variable q for a qudit with d levels (see qudit), such that q(i,j) is the transition operator $|i⟩⟨j|$. With q[:,:] (with any number of :), the qudit has indices, which are given as q(i,j)[k,l]. With several names, all qudits have d levels.
Examples
@qudit 3 q
q(2,1) * q(1,3) # |2⟩⟨3|
@qudit 3 m[:]
∑(:k, m(2,1)[:k] * m(1,2)[:k])QuantumAlgebra.@so — Macro@so n L
@so n L[:,:]
@so n L M[:] ...Define the variable L for the generators of so(n) (see so), such that L(a,b) is the generator $L_{ab}$. With L[:,:] (with any number of :), the generators have indices, which are given as L(a,b)[k,l]. With several names, all of them are generators of so(n) for the same n.
QuantumAlgebra.@spin — Macro@spin J
@spin J K[:] ...
@spin 1//2 J K[:] ...
@spin j=jval J K[:] ...Define the variables Jp, Jm and Jz for the operators $J_+$, $J_-$ and $J_z$ of a spin J (see spin), and similarly for each further name. With J[:,:] (with any number of :), the spin has indices, given as, e.g., Jp[i,j]. A fixed spin j (the same for all names) is given as the first argument if it is a number (e.g., 1//2 or 3), and as j=jval otherwise (e.g., for a variable jval or a symbolic value), since a name as the first argument is interpreted as the name of a spin. (j = "name", with a string, is the spin j with that name.)
QuantumAlgebra.@tls — Macro@tls σ
@tls σ[:] τ ...Define the variable σ for the lowering operator $σ^-$ of a two-level system, with $σ^+$ = σ' (see tls and @boson).
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 — Macro@tlsxyz σ
@tlsxyz σ[:] τ ...Define the variables σx, σy and σz for the Pauli matrices of a two-level system (see tlsxyz and @boson), and similarly for each further 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.