# Multiply out product of sums

For a specific quantum mechanical problem I need to multiply out operators in order to calculate a trace by hand. For example I need a Hamiltonian squared with $H^2$. The Hamiltonian contains of a few single terms and flip-flop terms embedded in sums like $\frac{1}{2} \sum_{m=1}^N S_0^+ S_m^- + S_0^- S_m^+$.

My first idea was simply to write down the sums and ask Mathematica to multiply them out by expanding them. Unfortunately, this yields a result I could have imagined myself with $\sum_m (...) \times \sum_n (...)$. What I need is a sum of those product terms for example of the form $\sum_{m=1,n=1}^N S_0^+ S_m^-S_0^+ S_n^- + \sum_{m=1,n=1}^N (...)$ as I want to evaluate each operator separately by hand.

Changing the sum parenthesis doesn't seem to have any effect. Expand refuses to work.

Is there a possibility to let Mathematica multiply out all those terms individually?

Remark: As specific operators don't commute, e.g. $[S^+,S^-]$ for the same index I need Mathematica to give out each term. Simplifying by changing operator positions could lead to false results, so something like $(a+b)*(a+b)=a^2+ab+ba+b^2$ is needed here.

Edit: Here is a minimum example of what doesn't work as expected:

Expand[(-h Subscript[S^z, 0] -
Sum[Subscript[J,
m] (Subscript[S, 0]^z Subscript[S, m]^z +
1/2 SuperPlus[Subscript[S, 0]] SuperMinus[Subscript[S, m]] +
1/2 SuperMinus[Subscript[S, 0]] SuperPlus[Subscript[S,
m]]), {m, 1, NN}]) (-h Subscript[S^z, 0] -
Sum[Subscript[J,
n] (Subscript[S, 0]^z Subscript[S, n]^z +
1/2 SuperPlus[Subscript[S, 0]] SuperMinus[Subscript[S, n]] +
1/2 SuperMinus[Subscript[S, 0]] SuperPlus[Subscript[S,
n]]), {n, 1, NN}])]

• If you can provide a minimum (non-)working example it would be great. – Sektor Apr 22 '15 at 15:56
• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Apr 22 '15 at 16:15
• is NN known, or does it need to remain as NN? – chuy Apr 22 '15 at 16:51
• – Jens Apr 22 '15 at 19:40
• @chuy It has to remain that way. The variable is not known beforehand. – pbx Apr 23 '15 at 11:34