Interface

The exported functions, macros and types of QuantumAlgebra. The functions and types that are not exported are described in Internals.

QuantumAlgebra.QuantumAlgebra — Module
QuantumAlgebra

Quantum operator algebra: define operators (bosons, fermions, two-level systems, qudits, spins and generators of so(n) and u(n), see @boson etc.) and parameters (@qparam), compute normal forms (normal_form), commutators (comm), vacuum expectation values (vacExpVal), Heisenberg equations of motion (heisenberg_eom, heisenberg_eom_system) and cumulant expansions (expval_as_corrs), and convert the results to LaTeX (latex) or Julia code (julia_expression).

source
QuantumAlgebra.a — Constant
a(inds...)
a'(inds...)

The default bosonic operator of the legacy interface: a(inds...) is the annihilation operator with the given indices (e.g., a(:i) for $a_i$ and a() without indices), and a'(inds...) the creation operator. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @boson a[:] (see @boson).

source
QuantumAlgebra.f — Constant
f(inds...)
f'(inds...)

The default fermionic operator of the legacy interface: f(inds...) is the annihilation operator with the given indices, and f'(inds...) the creation operator. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @fermion f[:] (see @fermion).

source
QuantumAlgebra.σm — Constant
σp(inds...)
σm(inds...)

The raising and lowering operators $σ^+$ and $σ^-$ of the default two-level system σ of the legacy interface, with the given indices. Depending on use_σpm (when they are created), they are represented as jump operators or through Pauli matrices. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @tls σ[:], with σ'[i] for $σ^+_i$ and σ[i] for $σ^-_i$ (see @tls).

source
QuantumAlgebra.σp — Constant
σp(inds...)
σm(inds...)

The raising and lowering operators $σ^+$ and $σ^-$ of the default two-level system σ of the legacy interface, with the given indices. Depending on use_σpm (when they are created), they are represented as jump operators or through Pauli matrices. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @tls σ[:], with σ'[i] for $σ^+_i$ and σ[i] for $σ^-_i$ (see @tls).

source
QuantumAlgebra.σx — Constant
σx(inds...)
σy(inds...)
σz(inds...)

The Pauli matrices of the default two-level system σ of the legacy interface, with the given indices. Depending on use_σpm (when they are created), they are represented as Pauli matrices or through $σ^±$. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @tlsxyz σ[:] (see @tlsxyz).

source
QuantumAlgebra.σy — Constant
σx(inds...)
σy(inds...)
σz(inds...)

The Pauli matrices of the default two-level system σ of the legacy interface, with the given indices. Depending on use_σpm (when they are created), they are represented as Pauli matrices or through $σ^±$. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @tlsxyz σ[:] (see @tlsxyz).

source
QuantumAlgebra.σz — Constant
σx(inds...)
σy(inds...)
σz(inds...)

The Pauli matrices of the default two-level system σ of the legacy interface, with the given indices. Depending on use_σpm (when they are created), they are represented as Pauli matrices or through $σ^±$. The default operators are deprecated and will be removed in version 2.0; define operators with the macros instead, e.g., @tlsxyz σ[:] (see @tlsxyz).

source
QuantumAlgebra.Corr — Type
Corr(ops::BaseOpProduct)

The correlator (or cumulant) $⟨ops⟩_c$ of a product of operators in a term, i.e., the connected part of the expectation value $⟨ops⟩$ (see expval_as_corrs). Correlators are created with corr, e.g., corr(a'*a) gives ⟨a†() a()⟩c. As the first argument of heisenberg_eom_system, Corr selects equations for correlators.

See also ExpVal.

source
QuantumAlgebra.ExpVal — Type
ExpVal(ops::BaseOpProduct)

The expectation value $⟨ops⟩$ of a product of operators in a term. Expectation values are created with expval, e.g., expval(a'*a) gives ⟨a†() a()⟩. As the first argument of heisenberg_eom_system, ExpVal selects equations for expectation values.

See also Corr.

source
QuantumAlgebra.QuExpr — Type
QuExpr

A quantum expression: a sum of terms (QuTerm) with numerical coefficients, which are stored in the dictionary A.terms (from terms to coefficients). The coefficients can be numbers of any type, including symbolic numbers (e.g., from Symbolics.jl or SymPy.jl), and numbers of different types can appear in the same expression.

Expressions are built from operators and parameters (see @boson and @qparam), which are QuExprs themselves, with +, -, *, ^, the adjoint ', sums (∑), and functions such as normal_form, comm or expval. QuExpr() (or zero(QuExpr)) is the empty expression, i.e., zero, and QuExpr(x) is the constant x (e.g., QuExpr(1) == one(QuExpr)).

source
QuantumAlgebra.Avac — Method
Avac(A, modes_in_vacuum=nothing)
vacA(A, modes_in_vacuum=nothing)

Simplify the expression A acting on the vacuum from the right (Avac, for $A|0⟩$) or from the left (vacA, for $⟨0|A$): Avac(A) returns an expression $A'$ with $A'|0⟩ = A|0⟩$ (and similarly for vacA), where the terms that annihilate the vacuum are removed and operators for which the vacuum is an eigenstate (e.g., $σ^z$) are replaced by their eigenvalues. E.g., Avac(a*a') gives 1, and Avac(a*a'*b[1]) gives 0.

modes_in_vacuum restricts the vacuum to the given modes (the others are left as they are): an operator or a collection of operators, given as the variables defined by the macros (e.g., a after @boson a, or b after @boson b[:], which stands for all modes of b).

source
QuantumAlgebra.boson — Method
boson(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,…]).

source
QuantumAlgebra.boson_ops — Method
boson_ops(name::Symbol)

Return the constructors (a, adag) for the bosonic operators with the given name in the legacy interface: a(inds...) is the annihilation operator with these indices, and a'(inds...) the creation operator (adag is deprecated, use a' instead). See also @boson_ops.

Legacy interface

This function is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use boson or @boson instead.

source
QuantumAlgebra.comm — Method
comm(A, B)

Return the commutator $[A,B] = AB - BA$ in normal form. It is computed directly from the commutators of pairs of single operators (with the Leibniz rule), so that the terms of $AB$ and $BA$ that cancel are never generated. E.g., comm(b[:i], b'[:j]*b[:j]) gives δ(ij) b(i) (after @boson b[:]).

source
QuantumAlgebra.corr — Method
corr(A)

Return the correlator (cumulant) of A, i.e., the operators in each term are wrapped in a correlator $⟨…⟩_c$ (the coefficients and parameters stay outside), e.g., corr(a'*a) gives ⟨a†() a()⟩c. A can be a QuExpr, a QuTerm or a number (which is returned as a constant expression).

See also expval, corr_as_expvals.

source
QuantumAlgebra.corr_as_expvals — Method
corr_as_expvals(A::QuExpr)

Return the correlator (cumulant) of A expressed through expectation values, the inverse of expval_as_corrs: the operators of each term of A are taken as a correlator, which is written as a sum of products of expectation values. E.g., corr_as_expvals(b'[:n]*b[:m]) gives -⟨b†(n)⟩ ⟨b(m)⟩ + ⟨b†(n) b(m)⟩ (after @boson b[:]). Expectation values and correlators that are already in A are not changed.

source
QuantumAlgebra.dropcorr — Method
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.droplen — Method
droplen(n)

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

source
QuantumAlgebra.expval — Method
expval(A)

Return the expectation value of A, i.e., the operators in each term are wrapped in an expectation value (the coefficients and parameters stay outside), e.g., expval(2g[:i]*a) gives 2 g(i) ⟨a()⟩. A can be a QuExpr, a QuTerm or a number (which is returned as a constant expression).

See also corr, expval_as_corrs.

source
QuantumAlgebra.expval_as_corrs — Method
expval_as_corrs(A::QuExpr)

Return the expectation value of A expressed through correlators (cumulants): the operators $B C D…$ of each term of A are taken as an expectation value $⟨B C D…⟩$, which is written as the sum over all partitions of the operators into products of correlators, $⟨B⟩_c ⟨C⟩_c ⟨D⟩_c… + ⟨B C⟩_c ⟨D⟩_c… + … + ⟨B C D…⟩_c$ (note that $⟨B⟩_c = ⟨B⟩$). Expectation values and correlators that are already in A are not changed.

Examples

julia> @boson b[:];

julia> expval_as_corrs(b'[:n]*b[:n])
⟨b†(n)⟩c ⟨b(n)⟩c + ⟨b†(n) b(n)⟩c

julia> expval_as_corrs(b'[:n]*b[:m]*b[:n])
⟨b†(n)⟩c ⟨b(m)⟩c ⟨b(n)⟩c + ⟨b†(n)⟩c ⟨b(m) b(n)⟩c + ⟨b(m)⟩c ⟨b†(n) b(n)⟩c + ⟨b(n)⟩c ⟨b†(n) b(m)⟩c + ⟨b†(n) b(m) b(n)⟩c

See also corr_as_expvals.

source
QuantumAlgebra.fermion_ops — Method
fermion_ops(name::Symbol)

Return the constructors (f, fdag) for the fermionic operators with the given name in the legacy interface: f(inds...) is the annihilation operator with these indices, and f'(inds...) the creation operator (fdag is deprecated, use f' instead). See also @fermion_ops.

Legacy interface

This function is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use fermion or @fermion instead.

source
QuantumAlgebra.gellmann — Method
gellmann(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³³()
source
QuantumAlgebra.heisenberg_eom — Function
heisenberg_eom(A, H, Ls=())

Return the right-hand side of the Heisenberg equation of motion of the operator A for the Hamiltonian H and the Lindblad terms Ls (with $\hbar = 1$),

\[\frac{dA}{dt} = i [H,A] + \sum_k γ_k \left(L_k^† A L_k - \frac{1}{2} \{L_k^† L_k, A\}\right).\]

The result is not normal ordered (use normal_form). Each element of the tuple Ls describes a Lindblad term (see lindbladterm): (L,) or (γ, L) for the jump operator L with rate γ (1 if it is not given), ((L1, L2),) or (γ, (L1, L2)) for a "mixed" term with two operators (see MixedLindbladTerm), and (:i, γ, L) (or with a tuple of indices) for the sum of the term over the index i.

Examples

julia> @boson a; @qparam ω γ;

julia> normal_form(heisenberg_eom(a, ω*a'*a, ((γ, a),)))
-1//2 γ a() - 1i ω a()
source
QuantumAlgebra.heisenberg_eom_system — Function
heisenberg_eom_system(H, rhsfilt, Ls=(), ops=nothing)
heisenberg_eom_system(T, H, rhsfilt, Ls=(), ops=nothing)

Return the system of Heisenberg equations of motion for the expectation values (for T = ExpVal, the default) or the correlators (cumulants, for T = Corr) of operator products, for the Hamiltonian H and the Lindblad terms Ls (see heisenberg_eom), as a QuEqSys.

Starting from the operators ops (an operator, or a tuple of operators or products of operators), the equations of all expectation values (or correlators) that appear on the right-hand sides are added until the system is closed. If ops is nothing (the default), the system starts from the annihilation operators that appear in H. Since the equations of products of $n$ operators usually contain products of more operators, the system is truncated by the filter function rhsfilt, which is applied to the right-hand side of each equation and removes higher-order terms or approximates them by lower-order ones (see droplen and dropcorr). An integer n stands for droplen(n).

Examples

julia> @boson a; @qparam ω χ γ;

julia> H = ω*a'*a + χ*a'*(a'+a)*a;

julia> heisenberg_eom_system(H, 2, ((γ, a),), 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_expression — Function
julia_expression(A, varnames=nothing)

Return a Julia expression (an Expr) that computes the value of A, a QuExpr without bare operators (e.g., with expectation values or correlators). Expectation values and correlators become arrays with a name made from their operators, e.g., $⟨b^†_i b_j⟩$ becomes bᴴb[i,j], parameters become arrays with their names (or, for names like f(t), function calls), Kronecker deltas become I[i,j] (from LinearAlgebra), and summation indices are named s̄₁, s̄₂, … (but the sums are not written explicitly). If the collection of symbols varnames is given, expectation values (or correlators) whose name is not in it are written as the complex conjugate of their adjoint (using $⟨A⟩ = ⟨A^†⟩^*$), e.g., julia_expression(expval(b[:i]), [:bᴴ]) gives conj(bᴴ[i]).

Examples

julia> @boson b[:]; @qparam g[:];

julia> julia_expression(expval_as_corrs(g[:i]*b'[:i]*b[:j]))
:(g[i] * bᴴ[i] * b[j] + g[i] * bᴴb[i, j])
source
QuantumAlgebra.latex — Method
latex(A)

Return the LaTeX code for A (an expression, a term, an operator, or a system of equations, see QuEqSys), without surrounding $ signs. E.g., latex(g[:i]*b'[:i]) gives g_{i} {b}_{i}^{\dagger} (after @boson b[:] and @qparam g[:]). Unicode characters in names are converted to LaTeX, e.g., ω to \omega and b̄ to \bar{b}.

source
QuantumAlgebra.map_scalar_function — Method
map_scalar_function(f, A::QuExpr)

Return the expression A with the function f applied to the coefficient of each term, e.g., to round numerical coefficients or to simplify symbolic ones.

Examples

julia> @boson a;

julia> map_scalar_function(x -> round(x, digits=3), a/3 + a'/7)
0.143 a†() + 0.333 a()
source
QuantumAlgebra.normal_form — Function
normal_form(A::QuExpr, shortcut_vacA_zero=false)

Return the normal form of A, an equal expression in which the operators of each term are normal ordered (creation operators to the left of annihilation operators, using the algebra of the operators, e.g., $a a^† = 1 + a^† a$), products of operators that simplify are simplified, and the terms are in a canonical form (e.g., summation indices are numbered canonically), so that equal expressions have the same normal form. E.g., normal_form(a*a') gives 1 + a†() a().

If the vacuum $⟨0|$ will be applied from the left (see vacA), shortcut_vacA_zero=true drops the terms that it annihilates during normal ordering already.

See also auto_normal_form, is_normal_form.

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

Return the parameter name with the given indices as a QuExpr, where state is 'r' for a real parameter, 'n' (the default) for a complex parameter, and 'c' for its complex conjugate. E.g., param(:g,'r',:i) is the real parameter $g_i$.

Legacy interface

This function is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use @qparam or qparam instead, e.g., qparam(:g; ndims=1)[:i] for param(:g,'r',:i), or qparam(:α, Complex)' for param(:α,'c').

source
QuantumAlgebra.qindex — Method
qindex(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ₙ).

source
QuantumAlgebra.qparam — Function
qparam(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.

source
QuantumAlgebra.qudit — Method
qudit(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ⁱʲ).

With a d×d matrix M, q(M) (or q(M)[k,…]) is the operator $\sum_{ij} M_{ij} |i⟩⟨j|$ with this matrix. The entries of M can be numbers or expressions, e.g., parameters. This gives, e.g., the Hamiltonian of a d-level system, or the generators of a Lie algebra in a d-dimensional representation (which then satisfy all the relations of this representation).

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 i
# so(3) in the vector representation, (L_k)_ab = -i ϵ_kab, with L² = l(l+1) = 2
Lx, Ly, Lz = q([0 0 0; 0 0 -im; 0 im 0]), q([0 0 im; 0 0 0; -im 0 0]), q([0 -im 0; im 0 0; 0 0 0])
normal_form(Lx^2 + Ly^2 + Lz^2)  # 2
source
QuantumAlgebra.so — Method
so(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¹³()
source
QuantumAlgebra.spin — Function
spin(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⟩$. If j is a number (and not symbolic), all relations of the $(2j+1)$-dimensional representation are used, i.e., also $J_+^a ∏_{m=-j}^{j-a} (J_z - m) = 0$ and $J_-^b ∏_{m=b-j}^{j} (J_z - m) = 0$ (e.g., $J_+^2 = 0$ and $J_z^2 = 1/4$ for j = 1//2), so that the products on one site are $J_+^a J_z^n$ with $n ≤ 2j-a$ and $J_-^b J_z^n$ with $n ≤ 2j-b$.

source
QuantumAlgebra.tls — Method
tls(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).

source
QuantumAlgebra.tlspm_ops — Method
tlspm_ops(name::Symbol)

Return the constructors (σm, σp) for the lowering and raising operators $σ^-$ and $σ^+$ of the two-level system name in the legacy interface. Depending on use_σpm (when the operators are created), they are represented as jump operators or through the Pauli matrices.

Legacy interface

This function is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use tls or @tls instead.

source
QuantumAlgebra.tlsxyz — Method
tlsxyz(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. With an empty name, the Pauli matrices are printed as X, Y and Z, as in quantum computing (e.g., X, Y, Z = tlsxyz(""; ndims=1)).

source
QuantumAlgebra.tlsxyz_ops — Method
tlsxyz_ops(name::Symbol)

Return the constructors (σx, σy, σz) for the Pauli matrices of the two-level system name in the legacy interface. Depending on use_σpm (when the operators are created), they are represented as Pauli matrices or through the jump operators $σ^±$.

Legacy interface

This function is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use tlsxyz or @tlsxyz instead.

source
QuantumAlgebra.un — Method
un(name, n::Integer; ndims=0)

Return the generators S of the Lie algebra u(n) (the function version of @un), such that S(a,b) is the generator $S_{ab}$ ($a,b = 1,…,n$), with $S_{ab}^† = S_{ba}$. With ndims > 0, the generators have ndims indices, given as S(a,b)[k,…]. The commutation relations are

\[[S_{ab}, S_{cd}] = δ_{bc} S_{ad} - δ_{ad} S_{cb},\]

as, e.g., for the collective operators $S_{ab} = \sum_k |a⟩_k⟨b|_k$ of an ensemble of n-level systems (or $S_{ab} = b_a^† b_b$ for bosons $b_a$). Only these commutation relations are used, so that results hold in any representation (e.g., for any number of n-level systems), in the same way as for spins without fixed j (see spin), which are the case n = 2 (with $J_+ = S_{21}$, $J_- = S_{12}$ and $J_z = (S_{22} - S_{11})/2$). For a single n-level system, use a qudit instead (see qudit), whose transition operators satisfy the same commutation relations, but also all relations of the n-dimensional representation. The sum $\sum_a S_{aa}$ commutes with all generators (e.g., it is the number of n-level systems), and the traceless combinations of the generators span su(n).

Products of generators are ordered as the "raising" generators $S_{ab}$ with $a > b$, then the "lowering" generators with $a < b$, and then the diagonal generators $S_{aa}$ (each sorted by $(a,b)$). Vacuum expectation values are not defined.

Examples

S = un(:S, 3)
normal_form(comm(S(1,2), S(2,3)))  # S¹³()
normal_form(S(1,2)*S(2,1))          # S²¹() S¹²() + S¹¹() - S²²()
source
QuantumAlgebra.vacA — Function
Avac(A, modes_in_vacuum=nothing)
vacA(A, modes_in_vacuum=nothing)

Simplify the expression A acting on the vacuum from the right (Avac, for $A|0⟩$) or from the left (vacA, for $⟨0|A$): Avac(A) returns an expression $A'$ with $A'|0⟩ = A|0⟩$ (and similarly for vacA), where the terms that annihilate the vacuum are removed and operators for which the vacuum is an eigenstate (e.g., $σ^z$) are replaced by their eigenvalues. E.g., Avac(a*a') gives 1, and Avac(a*a'*b[1]) gives 0.

modes_in_vacuum restricts the vacuum to the given modes (the others are left as they are): an operator or a collection of operators, given as the variables defined by the macros (e.g., a after @boson a, or b after @boson b[:], which stands for all modes of b).

source
QuantumAlgebra.vacExpVal — Function
vacExpVal(A, S=1, modes_in_vacuum=nothing)

Return the vacuum expectation value $⟨0|S^\dagger A S|0⟩$, i.e., the expectation value $⟨ψ|A|ψ⟩$ in the state $|ψ⟩ = S|0⟩$ (which is not normalized automatically). E.g., vacExpVal(a'*a, 1 + a') gives 1. With modes_in_vacuum, only the given modes are assumed to be in the vacuum, and the result can contain operators of the other modes (see Avac).

source
QuantumAlgebra.∑ — Method
∑(ind, A)
∑((ind1, ind2, …), A)

Return the sum of the expression A over the index ind (a symbol such as :i, or an index variable, see @qindex), or over several indices. (∑ is entered as \sum<tab>.) The sum is formal, i.e., the range of the index is not specified. The summed index is replaced by a summation index (see sumindex), so that ∑(:i, g[:i]*b[:i]) is shown as ∑₁ g(#₁) b(#₁). When normal ordering, terms with a Kronecker delta of a summation index are summed, e.g., normal_form(∑(:i, b[:i])*b'[:j]) gives 1 + ∑₁ b†(j) b(#₁).

source
QuantumAlgebra.@Pc_str — Macro
Pc"name_inds"

Return the complex parameter name with the indices inds (separated by commas, optionally in braces), e.g., Pc"α" or Pc"g_i,j_2" (for $g_{i j_2}$). See also @Pr_str.

Legacy interface

This string macro is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use parameters defined with @qparam instead, e.g., g[:i,:j_2] after @qparam g[:,:]::Complex.

source
QuantumAlgebra.@Pr_str — Macro
Pr"name_inds"

Return the real parameter name with the indices inds (separated by commas, optionally in braces), e.g., Pr"ω" or Pr"g_i,j_2" (for $g_{i j_2}$). See also @Pc_str.

Legacy interface

This string macro is part of the legacy interface, which is deprecated and will be removed in version 2.0. Use parameters defined with @qparam instead, e.g., g[:i,:j_2] after @qparam g[:,:].

source
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.

source
QuantumAlgebra.@boson_ops — Macro

@boson_ops name: define the function $name that creates bosonic annihilation operators with name name, e.g., $name(:i) (and the deprecated $(name)dag, use $(name)' instead). Legacy interface (deprecated, will be removed in version 2.0), use @boson instead.

source
QuantumAlgebra.@fermion_ops — Macro

@fermion_ops name: define the function $name that creates fermionic annihilation operators with name name, e.g., $name(:i) (and the deprecated $(name)dag, use $(name)' instead). Legacy interface (deprecated, will be removed in version 2.0), use @fermion instead.

source
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]).

source
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).

source
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])
source
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.

source
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.)

source
QuantumAlgebra.@tls — Macro
@tls σ
@tls σ[:] τ ...

Define the variable σ for the lowering operator $σ^-$ of a two-level system, with $σ^+$ = σ' (see tls and @boson).

source
QuantumAlgebra.@tlspm_ops — Macro

@tlspm_ops name: define the functions $(name)m and $(name)p that create the lowering and raising operators $σ^-$ and $σ^+$ of the two-level system name (see tlspm_ops). Legacy interface (deprecated, will be removed in version 2.0), use @tls instead.

source
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. With @tlsxyz σ = "", the Pauli matrices are printed as X, Y and Z.

source
QuantumAlgebra.@tlsxyz_ops — Macro

@tlsxyz_ops name: define the functions $(name)x, $(name)y, and $(name)z that create the Pauli matrices of the two-level system name (see tlsxyz_ops). Legacy interface (deprecated, will be removed in version 2.0), use @tlsxyz instead.

source
QuantumAlgebra.@un — Macro
@un n S
@un n S[:,:]
@un n S T[:] ...

Define the variable S for the generators of u(n) (see un), such that S(a,b) is the generator $S_{ab}$. With S[:,:] (with any number of :), the generators have indices, which are given as S(a,b)[k,l]. With several names, all of them are generators of u(n) for the same n.

Examples

@un 3 S
normal_form(comm(S(1,2), S(2,3)))  # S¹³()
@un 3 T[:]
∑(:k, T(2,1)[:k] * T(1,2)[:k])
source