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) On Wednesday, 9 March 2016 21:24:38 UTC+1, [email protected] wrote: > > 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 > 4∗metric(i4,i5)∗p(L0)∗q(−L0) > > Now how can i replace p*q with another expression? > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/64f2d1f7-fa48-4f2c-91b6-6519f4ca0348%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
