In order to simplify my expression, I face a list manipulation problem.
For example, given the input list
list = {a[1] cof[1], a[2] cof[2], a[3] cof[3], a[4] cof[4], a[5] cof[5], a[6] cof[6]};
I can calculate the values of f[a[i]] and then combine the idential elements (f[] is just a function of the a[]). The condition of this transformation is
f[a[1]] == f[a[3]] == f[a[6]]; f[a[2]] == f[a[4]];
so that the output list becomes
newlist = {(cof[1] + cof[3] + cof[6]) a[1], (cof[2] + cof[4]) a[2], cof[5] a[5]};
How can I get this kind transformation to newlist for the general case?
GatherBy[#, Head@# === a &]work for you? Also, be aware thatGatherBylists element groups by the order in which they first appear so ifa[*]is not always first the third step will break; you may need to add a sort. If you include a more complex example in your question I'll try to address it. – Mr.Wizard Feb 24 '13 at 07:44