2
$\begingroup$

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.

$\endgroup$
3
  • 3
    $\begingroup$ 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. $\endgroup$ – gwr Dec 17 '14 at 21:30
  • 3
    $\begingroup$ 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]] $\endgroup$ – Basheer Algohi Dec 17 '14 at 21:37
  • $\begingroup$ 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 $\endgroup$ – Srivatsan Balakrishnan Dec 21 '14 at 14:52