# pattern matching and applying a function, not working as expected [duplicate]

Consider the following code

G[x, y] /. a_[b__] -> Total[a @@@ Permutations[List[b]]]


I expect it to give

G[x, y]+G[y,x]


But it gives,

G[x, y]


Can anyone explain why this happens? Thank you.

• If you use RuleDelayed, e.g. G[x, y] /. a_[b__] :> Total[a @@@ Permutations[List[b]]] it will work. Use yourcode//Trace to see what is happening. – gwr Dec 17 '14 at 21:30
• Permutation is evaluated first. check G[x, y] /. a_[b__] -> Total[a @@@ Permutations[List[b]]]//Trace. Other that that, why not simply:Total@Permutations[G[x, y]] – Basheer Algohi Dec 17 '14 at 21:37
• your comments were very helpful. Thanks for your time. I knew about the easier way of doing it, but I wanted to understand the way this code works, and Trace is indeed very helpful to diagnose that – Srivatsan Balakrishnan Dec 21 '14 at 14:52