Substitution of tensor expressions

50 views
Skip to first unread message

sxw...@gmail.com

unread,
Mar 9, 2016, 3:24:38 PM3/9/16
to sympy
Is there currently any possibility to replace subexpressions in tensor expressions? I am trying to evaluate Feynman diagrams; computing the gamma_trace is easy, but how do i substitute the fourvector products (tensor multiplications) that occur in the end?

Here is an example
from sympy import *
from sympy.physics.hep.gamma_matrices import GammaMatrix as G
from sympy.tensor.tensor import tensor_indices, tensorhead, TensMul
init_printing
()

p
, q = tensorhead('p, q', [G.LorentzIndex], [[1]])
i0
,i1,i2,i3,i4,i5 = tensor_indices('i0:6', G.LorentzIndex)

ps
= p(i0)*G(-i0)*q(i0)*G(-i0)*G.LorentzIndex.metric(i4, i5)
t
= G.gamma_trace(ps)
t

which yields
4metric(i4,i5)p(L0)q(L0)

Now how can i replace p*q with another expression?

Francesco Bonazzi

unread,
Mar 10, 2016, 2:33:16 AM3/10/16
to sympy
You can get the tuple of factors of your expression:

In [9]: t.args
Out[9]: (4, metric(i4, i5), p(L_0), q(-L_0))



Slice away the terms you don't want, and multiply by something else:

In [20]: prod(t.args[:2]) * other
Out[20]: (4*other)*metric(i4, i5)

Reply all
Reply to author
Forward
0 new messages