% Cadabra notebook version 1.0
\documentclass[11pt]{article}
\usepackage[textwidth=460pt, textheight=660pt]{geometry}
\usepackage[usenames]{color}
\usepackage[parfill]{parskip}
\usepackage{breqn}
\def\specialcolon{\mathrel{\mathop{:}}\hspace{-.5em}}
\renewcommand{\bar}[1]{\overline{#1}}
\begin{document}
% Begin TeX cell closed
{\large\bfseries Some simple gamma matrix algebra.}
% End TeX cell
{\color[named]{Blue}\begin{verbatim}
::PostDefaultRules( @@prodsort!(%), @@eliminate_kr!(%),  
                                    @@canonicalise!(%), @@collect_terms!(%) ).
\end{verbatim}}
\begin{verbatim}
Assigning property PostDefaultRules to .
\end{verbatim}
{\color[named]{Blue}\begin{verbatim}
{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.
\end{verbatim}}
\begin{verbatim}
Assigning property Indices to s, r, l, k, m, n.
Assigning property Integer to s, r, l, k, m, n.
Assigning property GammaMatrix to \Gamma.
Assigning property KroneckerDelta to \delta.
\end{verbatim}
% Begin TeX cell closed
The expression which we want to simplify:
% End TeX cell
{\color[named]{Blue}\begin{verbatim}
\Gamma_{s r} \Gamma_{r l} \Gamma_{k m} \Gamma_{m s};
\end{verbatim}}
\begin{dmath*}[compact, spread=2pt]
1\specialcolon{}= (-1)\, \Gamma_{m r} \Gamma_{l m} \Gamma_{k s} \Gamma_{r s};
\end{dmath*}
% Begin TeX cell closed
By twice joining adjacent gamma matrices, we join the first and second and third and fourth factor:
% End TeX cell
{\color[named]{Blue}\begin{verbatim}
@join!(%){expand}:
@join!(%){expand};
\end{verbatim}}
\begin{dmath*}[compact, spread=2pt]
1\specialcolon{}= (-1)\, (2\, \Gamma_{l r} - \Gamma_{l r} d + \delta_{l r} d - \delta_{l r}) (2\, \Gamma_{k r} - \Gamma_{k r} d + \delta_{k r} - \delta_{k r} d);
\end{dmath*}
% Begin TeX cell closed
After distributing the result and joining once more, we collect factors and get the desired result:
% End TeX cell
{\color[named]{Blue}\begin{verbatim}
@distribute!(%):
@canonicalise!(%):
@join!(%){expand}:
@distribute!(%):
@factorise!(%){d}:
@collect_factors!(%);
\end{verbatim}}
\begin{dmath*}[compact, spread=2pt]
1\specialcolon{}= \Gamma_{k l} (12 - 18\, d + 8\, d**2 - d**3) + \delta_{k l} ( - 3 + 6\, d - 4\, d**2 + d**3);
\end{dmath*}
\end{document}
