# Summation simplification

I have a list of terms of the form

f[1]g[[a,b]]g[[c,d]]g[[e,f]] + f[2]g[[a,f]]g[[e,d]]g[[c,b]] +...

some terms have the same $ggg$ form but have different $f$.. for instance

f[146]g[[a,f]]g[[e,d]]g[[c,b]] + f[21]g[[a,f]]g[[e,d]]g[[c,b]] +...+ f[7]g[[a,f]]g[[e,d]]g[[c,b]]

I'd like to take all the terms in this list that differ only by the front $f$ and leave just one of them, ie: f[146]g[[a,f]]g[[e,d]]g[[c,b]] + f[21]g[[a,f]]g[[e,d]]g[[c,b]] +...+ f[7]g[[a,f]]g[[e,d]]g[[c,b]] should become: f[146]g[[a,f]]g[[e,d]]g[[c,b]]

and it doesn't matter which one is saved!.

Any help will be greatly appreciated! Thank you!!

• g[[a,b]] should never remain unevaluated -- it will either generate an error or evaluate to something else. Do you mean g[a,b] (and so on) instead? – jjc385 May 11 '17 at 21:33

If I understand correctly this is it. You have the sum (I will use functions for g instead of parts):

tst = f[1] g[1, 2] g[4, 5] g[6, 7] + f[2] g[1, 2] g[4, 5] g[6, 7] +
f[3] g[1, 2] g[1, 3] g[3, 3] + f[4] g[1, 2] g[4, 5] g[6, 7]


And Then

Plus @@ Times @@@
DeleteDuplicatesBy[List @@ tst /. f[x_]*g_ -> {f[x], g}, Last]

• I recommend using :> here rather than ->, as the latter does nothing but encourage bad habits (and possible mistakes down the road) for new users. For an explanation why, see the "Why use RuleDelayed rather than Rule" section of [this answer]((mathematica.stackexchange.com/a/144904/11035). +1 – jjc385 May 12 '17 at 2:35
• Yeap, of course , thanx – David Baghdasaryan May 12 '17 at 6:05