	(* DoTrace handles chirality and applies Furry's theorem *)

DoTrace[ChiralityProjector[pm_], g___] :=
  Distribute//@ (1/2 Trace4[g] + pm/2 Trace5[g]) /; EvenQ[Length[{g}]]

DoTrace[__] = 0


	(* Trace4 is the straightforward bit *)

Trace4[mu_, g__] :=
Block[ {Trace4, s = -1},
  Plus@@ MapIndexed[((s = -s) Pair[mu, #1] Drop[Trace4[g], #2])&, {g}]
]

Trace4[] = 4


	(* Trace5: The gamma_5 used here anticommutes in all dimensions.
	   This introduces an error of the order (D - 4).  Folklore has
	   it that at one loop the wrong terms cancel in an anomaly-free
	   theory. *)

Trace5[mu_, nu_, ro_, si_] := 4 Eps[mu, nu, ro, si]

Trace5[mu_, nu_, r_, g__] :=
  Pair[mu, nu] Trace5[ro, g] +
  Pair[nu, ro] Trace5[mu, g] -
  Pair[mu, ro] Trace5[nu, g] +
  Eps[mu, nu, ro, Index[]] Trace4[Index[], g]

Trace5[___] = 0


Attributes[Pair] = {Orderless}


(* try some examples *)

tr1 = Trace4[mu, nu, ro, si]

tr2a = DoTrace[ChiralityProjector[+1], mu, nu, ro, si]

tr2b = DoTrace[ChiralityProjector[-1], mu, nu, ro, si]

Pair[mu, mu] = 4

tr3a = Trace4[mu, nu, ro, mu]

Pair[al, al] = D

tr3b = Trace4[al, nu, ro, al]

