# Using recursion to find the trace of gamma matrices

All you need to know about the gamma matrices for this problem is that there are four of them, $\gamma_{\mu}$ with $\mu = 0, 1, 2, 3$, and that the trace of the product of n gamma matrices (n even) obeys the following recursive relation:

$Tr(\gamma_{\nu_1}\gamma_{\nu_2}...\gamma_{\nu_n}&space;)&space;=&space;\begin{cases}&space;4g_{\nu_1,\nu_2}&space;&&space;\text{if}\&space;n&space;=2&space;\\&space;\sum_{k=2}^{n}&space;(-1)^{k}g_{\nu_1,\nu_k}&space;Tr(\gamma_{\nu_2}...\widehat{\gamma}_{\nu_k}...\gamma_{\nu_n})&space;&&space;\text{if}\&space;n&space;>&space;2&space;\end{cases}$

Here, $\widehat{\gamma}_{\nu_k}$ signifies absence of $\gamma_{\nu_k}$ and $g_{\nu_1,\nu_k}$ is a tensor with two indices.(BTW, when n is odd the result is zero). Here's my attempt at the code:

TrGamma[z__] :=
If[Length[z] == 2,
4*Subscript[g, z[[1]], z[[2]]] ,

(*Else*)
Module[ {x = 0, n = Length[z]},
For[i = 2, i <= n, i++,
Module[{y = Delete[z, {{1}, {i}}]},
x = x + (-1)^i*Subscript[g, z[[1]], z[[i]]]*TrGamma[y]]
];
x
]
]


This gives the correct answer for n=2 and n=4:

In[4]:= TrGamma[{Subscript[\[Nu], 1],Subscript[\[Nu], 2]}]
TrGamma[{Subscript[\[Nu], 1],Subscript[\[Nu], 2],Subscript[\[Nu],3],Subscript[\[Nu], 4]}]


Output:

$4&space;g_{\nu&space;_1,\nu&space;_2}$

$4&space;g_{\nu&space;_1,\nu&space;_4}&space;g_{\nu&space;_2,\nu&space;_3}-4&space;g_{\nu&space;_1,\nu&space;_3}&space;g_{\nu&space;_2,\nu&space;_4}+4&space;g_{\nu&space;_1,\nu&space;_2}&space;g_{\nu&space;_3,\nu&space;_4}$

However, when I try n = 6 or higher it just keeps running. I'm guess there's something about Module that I'm missing or have misunderstood. I've tried replacing Module with Block and the problem still persists.

• You might be interested in InternalDiracGammaMatrix[]: Table[InternalDiracGammaMatrix[k], {k, 5}]. – J. M.'s torpor Jan 15 '17 at 12:32
• Or you could study the source code of DiracTrace – Rolf Mertig Jan 15 '17 at 18:58

Since the formula has a sum ($\sum$), it's best to use Sum:

TrGamma[nu1_, nu2_] := 4 Subscript[g, nu1, nu2]

TrGamma[indices___] :=
Sum[
(-1)^k Subscript[g, {indices}[[1]], {indices}[[k]]] *
TrGamma @@ Delete[{indices}, {{1}, {k}}],
{k, 2, Length[{indices}]}]

• Tried it and it works! – Feynmaniac Jan 15 '17 at 19:37
• @Feynmaniac Ok, don't forget to upvote this and other answers if you found them helpful. Mark it as accepted if it answers your question. – QuantumDot Jan 15 '17 at 21:32
• Right. Sorry, I'm new here. – Feynmaniac Jan 15 '17 at 21:46

Are you just trying to understand how to get recursion working in Mathematica, or are you mainly interested in having some useful functions for dealing with gamma matrices? If the latter, there is a package GAMMA by Ulf Gran which will handle all your gamma matrix needs, in any dimension and in any signature:

https://arxiv.org/abs/hep-th/0105086

• I'm interested in both, actually. I'll check out the package. – Feynmaniac Jan 15 '17 at 19:37
• @Feynmaniac Depending on what you want to do, you may find FeynCalc quite useful. – QuantumDot Jan 15 '17 at 21:34