Often in theoretical physics, one needs to calculate commutators of complicated symbolic expressions in some non-commuting algebra. It is useful to be able to check calculations done by hand, and it should be a routine task anyway. This example code shows how one can use Haskell code to define and calculate in such algebras with the normal background of a working theorist.
Note that this is a use case! I have not written the library behind all the math, I'm just connecting the dots for physicists interested in using the library for practical calculations!
First, install Haskell and its build system Cabal through the Haskell Platform.
Second, if you at any time feel the need to read up on Haskell (you may skip this step for now), I recommend this introduction and this blog. You will not be disappointed.
Third, install the excellent package HaskellForMaths:
cabal update
cabal install haskellformaths
To learn more about Haskell and mathematics, check out the accompanying blog. There are a lot of other interesting things to be learnt from Haskell for physicists and mathematicians.
To use the algebra of Pauli matrices and the identity matrix, for example to calculate the equations of motions of some Hamiltonian, is simple. From the terminal:
ghci
and then write
:load SU2.hs
let [j, h] = map var ["j", "h"]
let hamiltonian = j *> sx + h *> sz
let comm [x, y] = x * y - y * x
let eom o = i *> comm [hamiltonian, o]
eom sy
To define your own algebra, follow the pattern in these files.
I want to thank David Amos and the Haskell community for helpful discussions and help with these basic things.
BSD3 License, see the file LICENSE
Axel Gagge 2017. The library is written by David Amos and licensed under a BSD3 License.