test_gamma_matrices.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. from sympy.matrices.dense import eye, Matrix
  2. from sympy.tensor.tensor import tensor_indices, TensorHead, tensor_heads, \
  3. TensExpr, canon_bp
  4. from sympy.physics.hep.gamma_matrices import GammaMatrix as G, LorentzIndex, \
  5. kahane_simplify, gamma_trace, _simplify_single_line, simplify_gamma_expression
  6. from sympy import Symbol
  7. def _is_tensor_eq(arg1, arg2):
  8. arg1 = canon_bp(arg1)
  9. arg2 = canon_bp(arg2)
  10. if isinstance(arg1, TensExpr):
  11. return arg1.equals(arg2)
  12. elif isinstance(arg2, TensExpr):
  13. return arg2.equals(arg1)
  14. return arg1 == arg2
  15. def execute_gamma_simplify_tests_for_function(tfunc, D):
  16. """
  17. Perform tests to check if sfunc is able to simplify gamma matrix expressions.
  18. Parameters
  19. ==========
  20. `sfunc` a function to simplify a `TIDS`, shall return the simplified `TIDS`.
  21. `D` the number of dimension (in most cases `D=4`).
  22. """
  23. mu, nu, rho, sigma = tensor_indices("mu, nu, rho, sigma", LorentzIndex)
  24. a1, a2, a3, a4, a5, a6 = tensor_indices("a1:7", LorentzIndex)
  25. mu11, mu12, mu21, mu31, mu32, mu41, mu51, mu52 = tensor_indices("mu11, mu12, mu21, mu31, mu32, mu41, mu51, mu52", LorentzIndex)
  26. mu61, mu71, mu72 = tensor_indices("mu61, mu71, mu72", LorentzIndex)
  27. m0, m1, m2, m3, m4, m5, m6 = tensor_indices("m0:7", LorentzIndex)
  28. def g(xx, yy):
  29. return (G(xx)*G(yy) + G(yy)*G(xx))/2
  30. # Some examples taken from Kahane's paper, 4 dim only:
  31. if D == 4:
  32. t = (G(a1)*G(mu11)*G(a2)*G(mu21)*G(-a1)*G(mu31)*G(-a2))
  33. assert _is_tensor_eq(tfunc(t), -4*G(mu11)*G(mu31)*G(mu21) - 4*G(mu31)*G(mu11)*G(mu21))
  34. t = (G(a1)*G(mu11)*G(mu12)*\
  35. G(a2)*G(mu21)*\
  36. G(a3)*G(mu31)*G(mu32)*\
  37. G(a4)*G(mu41)*\
  38. G(-a2)*G(mu51)*G(mu52)*\
  39. G(-a1)*G(mu61)*\
  40. G(-a3)*G(mu71)*G(mu72)*\
  41. G(-a4))
  42. assert _is_tensor_eq(tfunc(t), \
  43. 16*G(mu31)*G(mu32)*G(mu72)*G(mu71)*G(mu11)*G(mu52)*G(mu51)*G(mu12)*G(mu61)*G(mu21)*G(mu41) + 16*G(mu31)*G(mu32)*G(mu72)*G(mu71)*G(mu12)*G(mu51)*G(mu52)*G(mu11)*G(mu61)*G(mu21)*G(mu41) + 16*G(mu71)*G(mu72)*G(mu32)*G(mu31)*G(mu11)*G(mu52)*G(mu51)*G(mu12)*G(mu61)*G(mu21)*G(mu41) + 16*G(mu71)*G(mu72)*G(mu32)*G(mu31)*G(mu12)*G(mu51)*G(mu52)*G(mu11)*G(mu61)*G(mu21)*G(mu41))
  44. # Fully Lorentz-contracted expressions, these return scalars:
  45. def add_delta(ne):
  46. return ne * eye(4) # DiracSpinorIndex.delta(DiracSpinorIndex.auto_left, -DiracSpinorIndex.auto_right)
  47. t = (G(mu)*G(-mu))
  48. ts = add_delta(D)
  49. assert _is_tensor_eq(tfunc(t), ts)
  50. t = (G(mu)*G(nu)*G(-mu)*G(-nu))
  51. ts = add_delta(2*D - D**2) # -8
  52. assert _is_tensor_eq(tfunc(t), ts)
  53. t = (G(mu)*G(nu)*G(-nu)*G(-mu))
  54. ts = add_delta(D**2) # 16
  55. assert _is_tensor_eq(tfunc(t), ts)
  56. t = (G(mu)*G(nu)*G(-rho)*G(-nu)*G(-mu)*G(rho))
  57. ts = add_delta(4*D - 4*D**2 + D**3) # 16
  58. assert _is_tensor_eq(tfunc(t), ts)
  59. t = (G(mu)*G(nu)*G(rho)*G(-rho)*G(-nu)*G(-mu))
  60. ts = add_delta(D**3) # 64
  61. assert _is_tensor_eq(tfunc(t), ts)
  62. t = (G(a1)*G(a2)*G(a3)*G(a4)*G(-a3)*G(-a1)*G(-a2)*G(-a4))
  63. ts = add_delta(-8*D + 16*D**2 - 8*D**3 + D**4) # -32
  64. assert _is_tensor_eq(tfunc(t), ts)
  65. t = (G(-mu)*G(-nu)*G(-rho)*G(-sigma)*G(nu)*G(mu)*G(sigma)*G(rho))
  66. ts = add_delta(-16*D + 24*D**2 - 8*D**3 + D**4) # 64
  67. assert _is_tensor_eq(tfunc(t), ts)
  68. t = (G(-mu)*G(nu)*G(-rho)*G(sigma)*G(rho)*G(-nu)*G(mu)*G(-sigma))
  69. ts = add_delta(8*D - 12*D**2 + 6*D**3 - D**4) # -32
  70. assert _is_tensor_eq(tfunc(t), ts)
  71. t = (G(a1)*G(a2)*G(a3)*G(a4)*G(a5)*G(-a3)*G(-a2)*G(-a1)*G(-a5)*G(-a4))
  72. ts = add_delta(64*D - 112*D**2 + 60*D**3 - 12*D**4 + D**5) # 256
  73. assert _is_tensor_eq(tfunc(t), ts)
  74. t = (G(a1)*G(a2)*G(a3)*G(a4)*G(a5)*G(-a3)*G(-a1)*G(-a2)*G(-a4)*G(-a5))
  75. ts = add_delta(64*D - 120*D**2 + 72*D**3 - 16*D**4 + D**5) # -128
  76. assert _is_tensor_eq(tfunc(t), ts)
  77. t = (G(a1)*G(a2)*G(a3)*G(a4)*G(a5)*G(a6)*G(-a3)*G(-a2)*G(-a1)*G(-a6)*G(-a5)*G(-a4))
  78. ts = add_delta(416*D - 816*D**2 + 528*D**3 - 144*D**4 + 18*D**5 - D**6) # -128
  79. assert _is_tensor_eq(tfunc(t), ts)
  80. t = (G(a1)*G(a2)*G(a3)*G(a4)*G(a5)*G(a6)*G(-a2)*G(-a3)*G(-a1)*G(-a6)*G(-a4)*G(-a5))
  81. ts = add_delta(416*D - 848*D**2 + 584*D**3 - 172*D**4 + 22*D**5 - D**6) # -128
  82. assert _is_tensor_eq(tfunc(t), ts)
  83. # Expressions with free indices:
  84. t = (G(mu)*G(nu)*G(rho)*G(sigma)*G(-mu))
  85. assert _is_tensor_eq(tfunc(t), (-2*G(sigma)*G(rho)*G(nu) + (4-D)*G(nu)*G(rho)*G(sigma)))
  86. t = (G(mu)*G(nu)*G(-mu))
  87. assert _is_tensor_eq(tfunc(t), (2-D)*G(nu))
  88. t = (G(mu)*G(nu)*G(rho)*G(-mu))
  89. assert _is_tensor_eq(tfunc(t), 2*G(nu)*G(rho) + 2*G(rho)*G(nu) - (4-D)*G(nu)*G(rho))
  90. t = 2*G(m2)*G(m0)*G(m1)*G(-m0)*G(-m1)
  91. st = tfunc(t)
  92. assert _is_tensor_eq(st, (D*(-2*D + 4))*G(m2))
  93. t = G(m2)*G(m0)*G(m1)*G(-m0)*G(-m2)
  94. st = tfunc(t)
  95. assert _is_tensor_eq(st, ((-D + 2)**2)*G(m1))
  96. t = G(m0)*G(m1)*G(m2)*G(m3)*G(-m1)
  97. st = tfunc(t)
  98. assert _is_tensor_eq(st, (D - 4)*G(m0)*G(m2)*G(m3) + 4*G(m0)*g(m2, m3))
  99. t = G(m0)*G(m1)*G(m2)*G(m3)*G(-m1)*G(-m0)
  100. st = tfunc(t)
  101. assert _is_tensor_eq(st, ((D - 4)**2)*G(m2)*G(m3) + (8*D - 16)*g(m2, m3))
  102. t = G(m2)*G(m0)*G(m1)*G(-m2)*G(-m0)
  103. st = tfunc(t)
  104. assert _is_tensor_eq(st, ((-D + 2)*(D - 4) + 4)*G(m1))
  105. t = G(m3)*G(m1)*G(m0)*G(m2)*G(-m3)*G(-m0)*G(-m2)
  106. st = tfunc(t)
  107. assert _is_tensor_eq(st, (-4*D + (-D + 2)**2*(D - 4) + 8)*G(m1))
  108. t = 2*G(m0)*G(m1)*G(m2)*G(m3)*G(-m0)
  109. st = tfunc(t)
  110. assert _is_tensor_eq(st, ((-2*D + 8)*G(m1)*G(m2)*G(m3) - 4*G(m3)*G(m2)*G(m1)))
  111. t = G(m5)*G(m0)*G(m1)*G(m4)*G(m2)*G(-m4)*G(m3)*G(-m0)
  112. st = tfunc(t)
  113. assert _is_tensor_eq(st, (((-D + 2)*(-D + 4))*G(m5)*G(m1)*G(m2)*G(m3) + (2*D - 4)*G(m5)*G(m3)*G(m2)*G(m1)))
  114. t = -G(m0)*G(m1)*G(m2)*G(m3)*G(-m0)*G(m4)
  115. st = tfunc(t)
  116. assert _is_tensor_eq(st, ((D - 4)*G(m1)*G(m2)*G(m3)*G(m4) + 2*G(m3)*G(m2)*G(m1)*G(m4)))
  117. t = G(-m5)*G(m0)*G(m1)*G(m2)*G(m3)*G(m4)*G(-m0)*G(m5)
  118. st = tfunc(t)
  119. result1 = ((-D + 4)**2 + 4)*G(m1)*G(m2)*G(m3)*G(m4) +\
  120. (4*D - 16)*G(m3)*G(m2)*G(m1)*G(m4) + (4*D - 16)*G(m4)*G(m1)*G(m2)*G(m3)\
  121. + 4*G(m2)*G(m1)*G(m4)*G(m3) + 4*G(m3)*G(m4)*G(m1)*G(m2) +\
  122. 4*G(m4)*G(m3)*G(m2)*G(m1)
  123. # Kahane's algorithm yields this result, which is equivalent to `result1`
  124. # in four dimensions, but is not automatically recognized as equal:
  125. result2 = 8*G(m1)*G(m2)*G(m3)*G(m4) + 8*G(m4)*G(m3)*G(m2)*G(m1)
  126. if D == 4:
  127. assert _is_tensor_eq(st, (result1)) or _is_tensor_eq(st, (result2))
  128. else:
  129. assert _is_tensor_eq(st, (result1))
  130. # and a few very simple cases, with no contracted indices:
  131. t = G(m0)
  132. st = tfunc(t)
  133. assert _is_tensor_eq(st, t)
  134. t = -7*G(m0)
  135. st = tfunc(t)
  136. assert _is_tensor_eq(st, t)
  137. t = 224*G(m0)*G(m1)*G(-m2)*G(m3)
  138. st = tfunc(t)
  139. assert _is_tensor_eq(st, t)
  140. def test_kahane_algorithm():
  141. # Wrap this function to convert to and from TIDS:
  142. def tfunc(e):
  143. return _simplify_single_line(e)
  144. execute_gamma_simplify_tests_for_function(tfunc, D=4)
  145. def test_kahane_simplify1():
  146. i0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15 = tensor_indices('i0:16', LorentzIndex)
  147. mu, nu, rho, sigma = tensor_indices("mu, nu, rho, sigma", LorentzIndex)
  148. D = 4
  149. t = G(i0)*G(i1)
  150. r = kahane_simplify(t)
  151. assert r.equals(t)
  152. t = G(i0)*G(i1)*G(-i0)
  153. r = kahane_simplify(t)
  154. assert r.equals(-2*G(i1))
  155. t = G(i0)*G(i1)*G(-i0)
  156. r = kahane_simplify(t)
  157. assert r.equals(-2*G(i1))
  158. t = G(i0)*G(i1)
  159. r = kahane_simplify(t)
  160. assert r.equals(t)
  161. t = G(i0)*G(i1)
  162. r = kahane_simplify(t)
  163. assert r.equals(t)
  164. t = G(i0)*G(-i0)
  165. r = kahane_simplify(t)
  166. assert r.equals(4*eye(4))
  167. t = G(i0)*G(-i0)
  168. r = kahane_simplify(t)
  169. assert r.equals(4*eye(4))
  170. t = G(i0)*G(-i0)
  171. r = kahane_simplify(t)
  172. assert r.equals(4*eye(4))
  173. t = G(i0)*G(i1)*G(-i0)
  174. r = kahane_simplify(t)
  175. assert r.equals(-2*G(i1))
  176. t = G(i0)*G(i1)*G(-i0)*G(-i1)
  177. r = kahane_simplify(t)
  178. assert r.equals((2*D - D**2)*eye(4))
  179. t = G(i0)*G(i1)*G(-i0)*G(-i1)
  180. r = kahane_simplify(t)
  181. assert r.equals((2*D - D**2)*eye(4))
  182. t = G(i0)*G(-i0)*G(i1)*G(-i1)
  183. r = kahane_simplify(t)
  184. assert r.equals(16*eye(4))
  185. t = (G(mu)*G(nu)*G(-nu)*G(-mu))
  186. r = kahane_simplify(t)
  187. assert r.equals(D**2*eye(4))
  188. t = (G(mu)*G(nu)*G(-nu)*G(-mu))
  189. r = kahane_simplify(t)
  190. assert r.equals(D**2*eye(4))
  191. t = (G(mu)*G(nu)*G(-nu)*G(-mu))
  192. r = kahane_simplify(t)
  193. assert r.equals(D**2*eye(4))
  194. t = (G(mu)*G(nu)*G(-rho)*G(-nu)*G(-mu)*G(rho))
  195. r = kahane_simplify(t)
  196. assert r.equals((4*D - 4*D**2 + D**3)*eye(4))
  197. t = (G(-mu)*G(-nu)*G(-rho)*G(-sigma)*G(nu)*G(mu)*G(sigma)*G(rho))
  198. r = kahane_simplify(t)
  199. assert r.equals((-16*D + 24*D**2 - 8*D**3 + D**4)*eye(4))
  200. t = (G(-mu)*G(nu)*G(-rho)*G(sigma)*G(rho)*G(-nu)*G(mu)*G(-sigma))
  201. r = kahane_simplify(t)
  202. assert r.equals((8*D - 12*D**2 + 6*D**3 - D**4)*eye(4))
  203. # Expressions with free indices:
  204. t = (G(mu)*G(nu)*G(rho)*G(sigma)*G(-mu))
  205. r = kahane_simplify(t)
  206. assert r.equals(-2*G(sigma)*G(rho)*G(nu))
  207. t = (G(mu)*G(-mu)*G(rho)*G(sigma))
  208. r = kahane_simplify(t)
  209. assert r.equals(4*G(rho)*G(sigma))
  210. t = (G(rho)*G(sigma)*G(mu)*G(-mu))
  211. r = kahane_simplify(t)
  212. assert r.equals(4*G(rho)*G(sigma))
  213. def test_gamma_matrix_class():
  214. i, j, k = tensor_indices('i,j,k', LorentzIndex)
  215. # define another type of TensorHead to see if exprs are correctly handled:
  216. A = TensorHead('A', [LorentzIndex])
  217. t = A(k)*G(i)*G(-i)
  218. ts = simplify_gamma_expression(t)
  219. assert _is_tensor_eq(ts, Matrix([
  220. [4, 0, 0, 0],
  221. [0, 4, 0, 0],
  222. [0, 0, 4, 0],
  223. [0, 0, 0, 4]])*A(k))
  224. t = G(i)*A(k)*G(j)
  225. ts = simplify_gamma_expression(t)
  226. assert _is_tensor_eq(ts, A(k)*G(i)*G(j))
  227. execute_gamma_simplify_tests_for_function(simplify_gamma_expression, D=4)
  228. def test_gamma_matrix_trace():
  229. g = LorentzIndex.metric
  230. m0, m1, m2, m3, m4, m5, m6 = tensor_indices('m0:7', LorentzIndex)
  231. n0, n1, n2, n3, n4, n5 = tensor_indices('n0:6', LorentzIndex)
  232. # working in D=4 dimensions
  233. D = 4
  234. # traces of odd number of gamma matrices are zero:
  235. t = G(m0)
  236. t1 = gamma_trace(t)
  237. assert t1.equals(0)
  238. t = G(m0)*G(m1)*G(m2)
  239. t1 = gamma_trace(t)
  240. assert t1.equals(0)
  241. t = G(m0)*G(m1)*G(-m0)
  242. t1 = gamma_trace(t)
  243. assert t1.equals(0)
  244. t = G(m0)*G(m1)*G(m2)*G(m3)*G(m4)
  245. t1 = gamma_trace(t)
  246. assert t1.equals(0)
  247. # traces without internal contractions:
  248. t = G(m0)*G(m1)
  249. t1 = gamma_trace(t)
  250. assert _is_tensor_eq(t1, 4*g(m0, m1))
  251. t = G(m0)*G(m1)*G(m2)*G(m3)
  252. t1 = gamma_trace(t)
  253. t2 = -4*g(m0, m2)*g(m1, m3) + 4*g(m0, m1)*g(m2, m3) + 4*g(m0, m3)*g(m1, m2)
  254. assert _is_tensor_eq(t1, t2)
  255. t = G(m0)*G(m1)*G(m2)*G(m3)*G(m4)*G(m5)
  256. t1 = gamma_trace(t)
  257. t2 = t1*g(-m0, -m5)
  258. t2 = t2.contract_metric(g)
  259. assert _is_tensor_eq(t2, D*gamma_trace(G(m1)*G(m2)*G(m3)*G(m4)))
  260. # traces of expressions with internal contractions:
  261. t = G(m0)*G(-m0)
  262. t1 = gamma_trace(t)
  263. assert t1.equals(4*D)
  264. t = G(m0)*G(m1)*G(-m0)*G(-m1)
  265. t1 = gamma_trace(t)
  266. assert t1.equals(8*D - 4*D**2)
  267. t = G(m0)*G(m1)*G(m2)*G(m3)*G(m4)*G(-m0)
  268. t1 = gamma_trace(t)
  269. t2 = (-4*D)*g(m1, m3)*g(m2, m4) + (4*D)*g(m1, m2)*g(m3, m4) + \
  270. (4*D)*g(m1, m4)*g(m2, m3)
  271. assert _is_tensor_eq(t1, t2)
  272. t = G(-m5)*G(m0)*G(m1)*G(m2)*G(m3)*G(m4)*G(-m0)*G(m5)
  273. t1 = gamma_trace(t)
  274. t2 = (32*D + 4*(-D + 4)**2 - 64)*(g(m1, m2)*g(m3, m4) - \
  275. g(m1, m3)*g(m2, m4) + g(m1, m4)*g(m2, m3))
  276. assert _is_tensor_eq(t1, t2)
  277. t = G(m0)*G(m1)*G(-m0)*G(m3)
  278. t1 = gamma_trace(t)
  279. assert t1.equals((-4*D + 8)*g(m1, m3))
  280. # p, q = S1('p,q')
  281. # ps = p(m0)*G(-m0)
  282. # qs = q(m0)*G(-m0)
  283. # t = ps*qs*ps*qs
  284. # t1 = gamma_trace(t)
  285. # assert t1 == 8*p(m0)*q(-m0)*p(m1)*q(-m1) - 4*p(m0)*p(-m0)*q(m1)*q(-m1)
  286. t = G(m0)*G(m1)*G(m2)*G(m3)*G(m4)*G(m5)*G(-m0)*G(-m1)*G(-m2)*G(-m3)*G(-m4)*G(-m5)
  287. t1 = gamma_trace(t)
  288. assert t1.equals(-4*D**6 + 120*D**5 - 1040*D**4 + 3360*D**3 - 4480*D**2 + 2048*D)
  289. t = G(m0)*G(m1)*G(n1)*G(m2)*G(n2)*G(m3)*G(m4)*G(-n2)*G(-n1)*G(-m0)*G(-m1)*G(-m2)*G(-m3)*G(-m4)
  290. t1 = gamma_trace(t)
  291. tresu = -7168*D + 16768*D**2 - 14400*D**3 + 5920*D**4 - 1232*D**5 + 120*D**6 - 4*D**7
  292. assert t1.equals(tresu)
  293. # checked with Mathematica
  294. # In[1]:= <<Tracer.m
  295. # In[2]:= Spur[l];
  296. # In[3]:= GammaTrace[l, {m0},{m1},{n1},{m2},{n2},{m3},{m4},{n3},{n4},{m0},{m1},{m2},{m3},{m4}]
  297. t = G(m0)*G(m1)*G(n1)*G(m2)*G(n2)*G(m3)*G(m4)*G(n3)*G(n4)*G(-m0)*G(-m1)*G(-m2)*G(-m3)*G(-m4)
  298. t1 = gamma_trace(t)
  299. # t1 = t1.expand_coeff()
  300. c1 = -4*D**5 + 120*D**4 - 1200*D**3 + 5280*D**2 - 10560*D + 7808
  301. c2 = -4*D**5 + 88*D**4 - 560*D**3 + 1440*D**2 - 1600*D + 640
  302. assert _is_tensor_eq(t1, c1*g(n1, n4)*g(n2, n3) + c2*g(n1, n2)*g(n3, n4) + \
  303. (-c1)*g(n1, n3)*g(n2, n4))
  304. p, q = tensor_heads('p,q', [LorentzIndex])
  305. ps = p(m0)*G(-m0)
  306. qs = q(m0)*G(-m0)
  307. p2 = p(m0)*p(-m0)
  308. q2 = q(m0)*q(-m0)
  309. pq = p(m0)*q(-m0)
  310. t = ps*qs*ps*qs
  311. r = gamma_trace(t)
  312. assert _is_tensor_eq(r, 8*pq*pq - 4*p2*q2)
  313. t = ps*qs*ps*qs*ps*qs
  314. r = gamma_trace(t)
  315. assert _is_tensor_eq(r, -12*p2*pq*q2 + 16*pq*pq*pq)
  316. t = ps*qs*ps*qs*ps*qs*ps*qs
  317. r = gamma_trace(t)
  318. assert _is_tensor_eq(r, -32*pq*pq*p2*q2 + 32*pq*pq*pq*pq + 4*p2*p2*q2*q2)
  319. t = 4*p(m1)*p(m0)*p(-m0)*q(-m1)*q(m2)*q(-m2)
  320. assert _is_tensor_eq(gamma_trace(t), t)
  321. t = ps*ps*ps*ps*ps*ps*ps*ps
  322. r = gamma_trace(t)
  323. assert r.equals(4*p2*p2*p2*p2)
  324. def test_bug_13636():
  325. """Test issue 13636 regarding handling traces of sums of products
  326. of GammaMatrix mixed with other factors."""
  327. pi, ki, pf = tensor_heads("pi, ki, pf", [LorentzIndex])
  328. i0, i1, i2, i3, i4 = tensor_indices("i0:5", LorentzIndex)
  329. x = Symbol("x")
  330. pis = pi(i2) * G(-i2)
  331. kis = ki(i3) * G(-i3)
  332. pfs = pf(i4) * G(-i4)
  333. a = pfs * G(i0) * kis * G(i1) * pis * G(-i1) * kis * G(-i0)
  334. b = pfs * G(i0) * kis * G(i1) * pis * x * G(-i0) * pi(-i1)
  335. ta = gamma_trace(a)
  336. tb = gamma_trace(b)
  337. t_a_plus_b = gamma_trace(a + b)
  338. assert ta == 4 * (
  339. -4 * ki(i0) * ki(-i0) * pf(i1) * pi(-i1)
  340. + 8 * ki(i0) * ki(i1) * pf(-i0) * pi(-i1)
  341. )
  342. assert tb == -8 * x * ki(i0) * pf(-i0) * pi(i1) * pi(-i1)
  343. assert t_a_plus_b == ta + tb