We are happy to announce QuantumAlgebra.jl, a package to do symbolic quantum operator algebra (i.e., algebra with non-commuting operators), written in the Julia programming language. It defines an opinionated canonical form (basically normal ordering plus some additional rules) that all expressions are automatically transformed to, which fulfills some invariants that then allows easy use and simplification of the resulting expressions. The output is formatted most nicely as LaTeX formulas in interfaces that support it (e.g., Jupyter notebooks).

For example, the input

H = 1//2*Pr"Ω"*σz() + (:i,Pr"ω_i"*adag(:i)*a(:i)) + (:i,Pr"g_i"*(adag(:i)+a(:i))*σx())

gets output as \(\frac{1}{2} \Omega \sigma_{z} + \sum_{i} \omega_{i} a_{i}^\dagger a_{i} + \sum_{i}g_{i} a_{i}^\dagger \sigma_{x} + \sum_{i}g_{i} a_{i} \sigma_{x}\). Here, the sum symbol can be entered as \sum<tab> in Julia, and Pr"ω" is a string macro to define the real parameter \(\omega\) (complex parameters would be Pc). You can then do, e.g.,

comm(H,adag(:k)*a(:l))

to obtain \(\omega_{k} a_{k}^\dagger a_{l} + -1 \omega_{l} a_{k}^\dagger a_{l} + -1 g_{l} a_{k}^\dagger \sigma_{x} + g_{k} a_{l} \sigma_{x}\).

The supported “fundamental” operators are bosonic operators a, adag (\(a\), \(a^\dagger\)), Pauli matrices σi (\(\sigma_i\), with \(i\in\{x,y,z,p=+,m=-\}\)) for two-level systems, and fermionic operators f, fdag (\(f\), \(f^\dagger\)) that anticommute:

fdag(:k)*f(:j) + f(:j)*fdag(:k)

giving \(\delta_{jk}\).

You can also use vacExpVal(A,S=1) to calculate the expectation value \(\langle 0|S^\dagger A S|0\rangle = \langle\psi|A|\psi\rangle\), where \(|\psi\rangle = S|0\rangle\) is the state obtained by the action of operator \(S\) on the vacuum:

S = Pc"α"*adag() + Pc"β"*adag()*adag()*adag()
vacExpVal(a()*a(),S)

giving \(6 \alpha^* \beta\).

Within the group, we already used it to cross-check our manual analytical calculations in the latest preprint by Mónica and Rui on the “Cumulant expansion for the treatment of light-matter interactions in arbitrary material structures”.

If you want to give it a spin, you can check out the notebooks in the examples folder in the repository linked above. They can also be viewed online on nbviewer and even tried out interactively with Binder. The code is open source, so contributions, bug reports, etc., are more than welcome on the github repository.