# Relabeling of dummy variables

I have the following expression

F[p1, p2] a[p1] ** b[p2] - F[p1, p2] a[p2] ** b[p1]


where ** is the non-commutative multiplication operation in Mathematica.

p1, p2 are dummy variables that are integrated or summed over in my example. Ideally, I'd like Mathematica to simplify that expression to

(F[p1, p2] - F[p1, p2]) a[p1] ** b[p2]


So that the variables in the string a[pi] ** b[pj] are sorted according to some rule. In principle I would like to generalize that to monomials of a and b of arbitrary order.

What I tried to do was a symbolic sum:

sum[F[p1, p2] a[p1] ** b[p2] - F[p1, p2] a[p2] ** b[p1], p1, p2]


but it doesn't simplify the result. Is there a way to do pattern matching so that the dummy variables in my expression are relabeled according to my rule?

• Did you mean to rewrite as F[p1, p2] (a[p1] ** b[p2] - a[p2] ** b[p1])? If so, Factor will do that. – Daniel Lichtblau May 20 '18 at 13:18

Check out NCAlgebra. NCCollect will do what you want.

Try this:

F[p1, p2] a[p1] **
b[p2] - ((F[p1, p2] a[p2] ** b[p1] /. {p1 -> q1,
p2 -> q2}) /. {q1 -> p2, q2 -> p1}) // Simplify


Have fun!

• My problem is that I want to convert an arbitrary sum of monomials of a's and b's of arbitrary order. Your solution only applies to the particular simplified example I posted (sum of two terms of order two) – chubecca Oct 11 '17 at 14:50
• @chubecca One cannot guess of what you have in mind. Post a complete problem with a sum you need. – Alexei Boulbitch Oct 12 '17 at 7:36