Suppose I have expressions that involve terms like:
p1.p1+p2.p2+p3.p3+p4.p4
p1, p2, p3, and p4 are all elements of an array:
p={p1, p2, p3, p4}
I would like Mathematica to replace this term with simply "p^2" anytime it sees it. How do I tell it to do this?
{p1, p2, p3, p4}.{p1, p2, p3, p4}
instead? That is equivalent top.p
with your definition ofp
, and it returnsp1^2 + p2^2 + p3^2 + p4^2
, which seems to be what you want. $\endgroup$ – MarcoB Mar 8 '16 at 22:48