Operator functions
Some Hamiltonians are not polynomials in the ladder operators. A trapped ion driven by a laser picks up the phase of the light at its position, and its motion enters through the displacement $e^{i\eta(a + a^\dagger)}$ with the Lamb–Dicke parameter $\eta$,
\[H = \nu a^\dagger a + \frac{\Omega}{2} \left( \sigma^{21} e^{i\eta(a + a^\dagger)} + \sigma^{12} e^{-i\eta(a + a^\dagger)} \right).\]
Functions of operators such as this exponential, or the cosine potential of a Josephson junction, are kept as formal functions. They take part in the algebra without being expanded, and a Taylor expansion to a chosen order turns them into polynomials when needed.
Formal functions
The exponential $e^{iA}$ of a Hermitian operator is written expim, which also writes unit phases of numbers. With it the trapped-ion Hamiltonian reads as on paper.
using SecondQuantizedAlgebrah = FockSpace(:motion) ⊗ NLevelSpace(:ion, 2)@qnumbers a::Destroy(h, 1)σ(k, l) = Transition(h, :σ, k, l)@variables η Ω νH = ν * a' * a + Ω / 2 * (σ(2, 1) * expim(η * (a + a')) + σ(1, 2) * expim(-η * (a + a')))\[\nu a^{\dagger}a + \frac{1}{2} ~ \Omega {\sigma}^{{12}} e^{i\left( - \eta a - \eta a^{\dagger} \right)} + \frac{1}{2} ~ \Omega {\sigma}^{{21}} e^{i\left( \eta a + \eta a^{\dagger} \right)}\]
Sine and cosine of operators are formal in the same way. There is no exp of an operator; $e^{iA}$ is written expim(A).
SecondQuantizedAlgebra.expim — Method
expim(A)Exponential of im times a Hermitian operator expression, kept as a formal function.
The result is the unitary $e^{iA}$. A must be Hermitian as written, meaning that A - A' simplifies to zero; parameters in it must therefore be real. Otherwise an ArgumentError is thrown. No series is expanded until taylor is called, and products such as $e^{iA} e^{-iA}$ are not combined. General operator exp(A) is unsupported; use expim(A) for this unitary exponential. To change the frame of an expression by such a unitary, use a UnitaryTransform, which applies $e^{iA} X e^{-iA}$ exactly.
Examples
julia> a = Destroy(FockSpace(:cavity), :a);julia> @variables θ;julia> U = expim(θ * a' * a)exp(im*(θ * a' * a))julia> taylor(U, 0:1)1 + θim * a' * ajulia> expim(a)ERROR: ArgumentError: `expim(::QField)` requires a provably Hermitian argument[...]See also taylor, UnitaryTransform, expim(::Real).
Base.sin — Method
sin(A)Sine of an operator expression, kept as a formal function.
No series is expanded. The function enters sums and products like any other operator, and keeps its position relative to operators on the same subsystem. A may be any operator expression. Use taylor to turn the function into a polynomial.
Examples
julia> a = Destroy(FockSpace(:cavity), :a);julia> sin(a + a') * asin(a + a') * ajulia> taylor(sin(a + a'), 0:3)1//2 * a + 1//2 * a' - 1//6 * a * a * a - 1//2 * a' * a * a - 1//2 * a' * a' * a - 1//6 * a' * a' * a'Base.cos — Method
cos(A)Cosine of an operator expression, kept as a formal function.
No series is expanded. The function enters sums and products like any other operator, and keeps its position relative to operators on the same subsystem; a commutator with it stays formal. A may be any operator expression. Use taylor to turn the function into a polynomial.
Examples
julia> a = Destroy(FockSpace(:cavity), :a);julia> commutator(cos(a + a'), a)-a * cos(a + a') + cos(a + a') * ajulia> taylor(cos(a + a'), 0:2)1//2 - 1//2 * a * a - a' * a - 1//2 * a' * a'A formal function keeps its place in a product. It commutes with operators on other subsystems but not with operators it shares a subsystem with.
a * cos(a + a') == cos(a + a') * a, σ(2, 1) * cos(a + a') == cos(a + a') * σ(2, 1)(false, true)No identities between functions are applied, not even $\sin^2 + \cos^2 = 1$ or $e^{iA} e^{-iA} = 1$. Where such an identity is needed, it is applied by hand.
expim(η * (a + a')) * expim(η * (a + a'))'\[e^{i\left( \eta a + \eta a^{\dagger} \right)} e^{i\left( - \eta a - \eta a^{\dagger} \right)}\]
An expression that contains a formal function has its own type, which holds it as written rather than in canonical form.
SecondQuantizedAlgebra.QExpr — Type
QExpr <: QFieldType of operator expressions that contain formal functions such as sin, cos or expim.
Polynomials in the operators are kept in canonical form, with products reordered and like terms collected. An expression containing a formal function cannot be brought into that form, so it is held as written: products keep the order of factors on a shared subsystem, factors on different subsystems are sorted, and products are not multiplied out over sums. Exact operations act on the arguments: adjoint, substitute, change_index, normal_order, simplify, expand, expand_completeness, assume_distinct_index, and frame changes with conjugate. A commutator with a formal function stays formal. Identities between functions, including sine/cosine completeness and inverse exponential products, are not applied automatically.
taylor turns a QExpr back into an ordinary polynomial. A symbolic Σ over a formal function, normal_to_symmetric, and symmetric_to_normal require polynomial lowering. Static to_numeric instead evaluates the complete arguments as finite matrices. average, numeric_average, expect, and formal superoperator conversion require polynomial lowering. The type is public but not exported.
Examples
julia> using SecondQuantizedAlgebra: QExprjulia> a = Destroy(FockSpace(:cavity), :a);julia> x = (a + a') * cos(a' * a);julia> x isa QExpr, taylor(x, 0:0) isa QExpr(true, false)julia> x'cos(a' * a) * (a + a')Exact operations
Operations that are exact without an expansion pass through the functions to their arguments. These are the adjoint, substitute, change_index, normal_order, simplify, expand, expand_completeness, assume_distinct_index and the conjugate of a unitary transformation. The Hamiltonian above is Hermitian as a whole.
H' == HtrueSubstitution reaches inside the functions, so the Lamb–Dicke parameter can be set to zero to recover the bare two-level drive.
substitute(H, Dict(η => 0))\[\left( \frac{1}{2} ~ \Omega {\sigma}^{{12}} + \frac{1}{2} ~ \Omega {\sigma}^{{21}} + \nu a^{\dagger}a \right)\]
A unitary transformation acts on the argument of the function, so the result is exact and needs no Baker–Campbell–Hausdorff series.
@variables θR = Rotation(a, θ)conjugate(cos(a + a'), R) == cos(conjugate(a + a', R))trueA commutator with a formal function stays formal, since evaluating it would need the series.
Taylor expansion
For small $\eta$ the exponentials are expanded. To first order the drive acquires the sidebands $a \sigma^{21}$ and $a^\dagger \sigma^{21}$, which couple the internal state to the motion.
taylor(H, 0:1)\[\frac{1}{2} ~ \Omega {\sigma}^{{12}} + \frac{1}{2} ~ \Omega {\sigma}^{{21}} - \frac{1}{2} ~ \Omega ~ \eta ~ \mathit{i} a{\sigma}^{{12}} + \frac{1}{2} ~ \Omega ~ \eta ~ \mathit{i} a{\sigma}^{{21}} + \nu a^{\dagger}a - \frac{1}{2} ~ \Omega ~ \eta ~ \mathit{i} a^{\dagger}{\sigma}^{{12}} + \frac{1}{2} ~ \Omega ~ \eta ~ \mathit{i} a^{\dagger}{\sigma}^{{21}}\]
Symbolics.taylor — Function
taylor(expr, 0:n)Replace every formal operator function in expr by its Taylor polynomial up to order n.
The coefficients are exact and the result is a polynomial in canonical form; an expression without formal functions is returned unchanged. Each function is truncated on its own, so the order is not a total degree of the result: sin(A)^2 truncated at order 1 is A^2, and sin(A)^2 + cos(A)^2 truncated at any order is not 1. A function inside another function throws an ArgumentError; lower the inner part first. So does a function of an argument containing a Σ, since a power such as $(\sum_i A_i)^2$ would need fresh summation indices. The range must start at 0. This operator overload is distinct from the scalar taylor(f, x, 0:n) method, which expands a scalar function in the variable x.
Examples
julia> a = Destroy(FockSpace(:cavity), :a);julia> A = a + a';julia> taylor(sin(A)^2, 0:1)1 + a * a + 2 * a' * a + a' * a'julia> taylor(sin(A)^2, 0:1) == A^2truetaylor(X::SuperExpr, ns)
taylor(L::Lindbladian{QExpr}, ns)Lower every formal side of a map to its Maclaurin polynomial through order n, for ns = 0:n.
A SuperExpr becomes a SuperOperator and a Lindbladian{QExpr} a polynomial Lindbladian. Each formal function is expanded as for an operator.
The operator method of taylor takes an operator expression and an order range. It is distinct from the scalar method taylor(f, x, 0:n) of Symbolics, which expands in a variable x.
Numerical conversion
to_numeric converts a formal function without an expansion. It applies the matrix function to the complete numerical argument on the chosen basis, so the trapped-ion Hamiltonian converts as written once its parameters have values.
using QuantumOpticsBasebackend = QuantumOpticsBackend()parameter = Dict(η => 0.1, Ω => 1.0, ν => 1.0)Hn = to_numeric(H, h, (10, 2); backend, parameter)size(Hn)(22, 22)The result is exact at the given cutoff, but the cutoff is still a truncation. The vacuum matrix element of a motional cosine changes as the cutoff grows, although the vacuum state is part of every basis.
V = cos(η * (a + a'))ηvalue = Dict(η => 0.7)[ (cutoff = n, vacuum = real(dense(to_numeric( V, h, (n, 2); backend, parameter = ηvalue, )).data[1, 1])) for n in (2, 4, 10)]3-element Vector{@NamedTuple{cutoff::Int64, vacuum::Float64}}:
(cutoff = 2, vacuum = 0.7835798675184037)
(cutoff = 4, vacuum = 0.7827053708986271)
(cutoff = 10, vacuum = 0.7827045382418691)The order of a Taylor polynomial is a separate approximation. At a fixed cutoff, the second- and fourth-order polynomials approach the matrix cosine.
V2 = taylor(V, 0:2)V4 = taylor(V, 0:4)[ (method = label, vacuum = real(dense(to_numeric( expr, h, (10, 2); backend, parameter = ηvalue, )).data[1, 1])) for (label, expr) in (("matrix cosine", V), ("Taylor order 2", V2), ("Taylor order 4", V4))]3-element Vector{@NamedTuple{method::String, vacuum::Float64}}:
(method = "matrix cosine", vacuum = 0.7827045382418691)
(method = "Taylor order 2", vacuum = 0.755)
(method = "Taylor order 4", vacuum = 0.7850125)numeric_average, expect and average still need the polynomial from taylor. So do a symbolic Σ over a formal function and conversion between normal and symmetric order with normal_to_symmetric and symmetric_to_normal. Perturbative frame changes such as Schrieffer–Wolff or van Vleck transformations are a separate problem of effective Hamiltonians and are not part of the formal functions.