a field theory motivated approach to computer algebra

# fierz

Perform a Fierz transformation on a product of four spinors
Change the order of the spinors in a four-spinor expression using a Fierz transformation. This relies on the generic fact that Dirac gamma matrices satisfy the completeness relation \begin{equation*} \sum_{a} \left(\Gamma_{a}\right)_{ij} \left(\Gamma^{a}\right)_{kl} = \delta_{il} \delta_{jk}\,. \end{equation*} The following example explains the typical usage pattern.
{m,n,p,q,r,s}::Indices; {m,n,p,q,r,s}::Integer(0..3); \Gamma{#}::GammaMatrix; \bar{#}::DiracBar; {\theta, \lambda, \psi, \chi}::Spinor; ex:=\bar{\theta} \Gamma_{m} \chi \bar{\psi} \Gamma^{m} \lambda;
$$\displaystyle{}\text{Attached property Indices(position=free) to }\left(m, \mmlToken{mo}[linebreak="goodbreak"]{} n, \mmlToken{mo}[linebreak="goodbreak"]{} p, \mmlToken{mo}[linebreak="goodbreak"]{} q, \mmlToken{mo}[linebreak="goodbreak"]{} r, \mmlToken{mo}[linebreak="goodbreak"]{} s\right).$$
$$\displaystyle{}\text{Attached property Integer to }\left(m, \mmlToken{mo}[linebreak="goodbreak"]{} n, \mmlToken{mo}[linebreak="goodbreak"]{} p, \mmlToken{mo}[linebreak="goodbreak"]{} q, \mmlToken{mo}[linebreak="goodbreak"]{} r, \mmlToken{mo}[linebreak="goodbreak"]{} s\right).$$
$$\displaystyle{}\text{Attached property GammaMatrix to }\Gamma\left(\#\right).$$
$$\displaystyle{}\text{Attached property DiracBar to }\bar{\#}.$$
$$\displaystyle{}\text{Attached property Spinor to }\left(\theta, \mmlToken{mo}[linebreak="goodbreak"]{} \lambda, \mmlToken{mo}[linebreak="goodbreak"]{} \psi, \mmlToken{mo}[linebreak="goodbreak"]{} \chi\right).$$
$$\displaystyle{}\bar{\theta} \Gamma_{m} \chi \bar{\psi} \Gamma^{m} \lambda$$
fierz(_, $\theta, \lambda, \psi, \chi$);
$$\displaystyle{} - \frac{1}{4}\bar{\theta} \Gamma_{m} \Gamma^{m} \lambda \bar{\psi} \chi - \frac{1}{4}\bar{\theta} \Gamma_{m} \Gamma_{n} \Gamma^{m} \lambda \bar{\psi} \Gamma_{n} \chi - \frac{1}{8}\bar{\theta} \Gamma_{m} \Gamma_{n p} \Gamma^{m} \lambda \bar{\psi} \Gamma_{p n} \chi$$
The argument to fierz is the required order of the fermions; note that this algorithm does not flip around Majorana spinors and sort_spinors should be used for that. Also note that it is important to define not only the symbols representing the spinors, Dirac bar and gamma matrices, but also the range of the indices.