a field-theory motivated approach to computer algebra

# Gamma matrix algebra (Clifford algebras)

Cadabra can do gamma matrix algebra in an arbitrary number of dimensions. The example below shows how to work out the particular gamma matrix contraction \begin{equation*} \Gamma_{s r} \Gamma_{r l} \Gamma_{k m} \Gamma_{m s}\,, \end{equation*} which is not impossible to do by hand, but certainly much nicer with Cadabra. As always, we first need to declare the symbols we are going to use.
{s,r,l,k,m,n}::Indices(vector); {s,r,l,k,m,n}::Integer(0..d-1); \Gamma_{#}::GammaMatrix(metric=\delta); \delta_{m n}::KroneckerDelta;
$$\displaystyle{}\text{Attached property Indices(position=free) to }(s, r, l, k, m, n).$$
$$\displaystyle{}\text{Attached property Integer to }(s, r, l, k, m, n).$$
$$\displaystyle{}\text{Attached property GammaMatrix to }{\Gamma}_(\#).$$
$$\displaystyle{}\text{Attached property KroneckerDelta to }{\delta}_(mn).$$
After every step in which we work out the product of two generalised gamma matrices, we need a number of algorithms to simplify the result. We will use the mechanism of defining a post_process function, which gets called after every Cadabra function call. Note how every algorithm that is called in here acts on the same expression; you do not have to do things like ex = sort_product(ex).
def post_process(ex): sort_product(ex) eliminate_kronecker(ex) canonicalise(ex) collect_terms(ex)
The expression which we want to simplify reads
ex:=\Gamma_{s r} \Gamma_{r l} \Gamma_{k m} \Gamma_{m s};
$$\displaystyle{}-\Gamma_{m r} \Gamma_{l m} \Gamma_{k s} \Gamma_{r s}$$
We need to join and distribute three times to merge all four generalised gamma matrices, so
for i in range(3): join_gamma(_) distribute(_) factor_in(_, $d$);
$$\displaystyle{}\Gamma_{k l} \left(-18d+8(d d)+12-(d d d)\right)+\delta_{k l} \left(-3+6d-4(d d)+(d d d)\right)$$
collect_factors(ex);
$$\displaystyle{}\Gamma_{k l} \left(-18d+8d^{2}+12-d^{3}\right)+\delta_{k l} \left(-3+6d-4d^{2}+d^{3}\right)$$
That's the answer we wanted to compute, much easier than by hand.