# How to check two summands give same summation value without evaluating the sum?

It is easier for me to explain the question with the following toy example.

Suppose I have two summands,

Summand1 = n1 + 2 n2;
Summand2 = 2 n1 + n2;


Now, it is easy to see that the summands are equal with respect to the following summation.

Sum[Summand, {n1, 0, lim}, {n2, 0, lim}]


But I can't think of an excellent way to show on Mathematica that the summands are equal. Of course, one trivial way is to do this,

SameQ[Summand1, Summand2] || SameQ[Summand1, Summand2 /. {n1 -> n2, n2 -> n1}]


Although this won't look good when we check summands having three or more summation variables, maybe, I need a way to tell Mathematica that n1 and n2 are dummy variables.

Any suggestions will be very useful.

• Would something like Equal @@ (Sum[#, {n1, 0, lim}, {n2, 0, lim}] & /@ {Summand1, Summand2}) work for you? Sep 24 at 15:19
• Yes, thank you! Sep 24 at 15:29

You can try permuting the variables and then sorting and taking the first element of the result. For instance:

canon[expr_, vars_List] := First @ Sort @ ReplaceAll[
expr,
]


Then:

c1 = canon[n1 + 2 n2, {n1, n2}]
c2 = canon[2 n1 + n2, {n1, n2}]

c1 === c2


2 n1 + n2

2 n1 + n2

True