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.

  • 2
    $\begingroup$ Would something like Equal @@ (Sum[#, {n1, 0, lim}, {n2, 0, lim}] & /@ {Summand1, Summand2}) work for you? $\endgroup$
    – MarcoB
    Sep 24 at 15:19
  • $\begingroup$ Yes, thank you! $\endgroup$
    – Epsilon
    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[
    Thread[vars -> Permutations @ vars]


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

c1 === c2

2 n1 + n2

2 n1 + n2



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.