# Modifying/optimizing a double sum with an If condition

I would like to better understand double summations where one of the sums depends on the upper limit of the previous sum. This appears frequently in representation theory (to the extent of my knowledge) and some physics systems. With representations of the form $$[a,b,c]$$ or even of a simpler form it is tricky -at least for me- as I explain below.

Ideally, I would like to understand how I can efficiently implement something like the following example of representations.

Consider the formula:

$$[0,p_1,0] \otimes [0,p_2,0] = \sum_{k_1=0}^{p_1} \sum_{k_2=0}^{p_1-k_1} [k_1,p_2-p_1+2k_2,k_1]$$ with $$p_1 \leq p_2$$.

This is essentially a decomposition of representations; each term $$[a,b,c]$$ is a representation to be more concrete.

A minimal and non-trivial example of what it should give is the following:

$$[0,2,0] \otimes [0,2,0] = [0,0,0] \oplus [0,2,0] \otimes [0,4,0] \otimes [2,0,2] \otimes [1,0,1] \otimes [1,2,1]$$

What I have implemented is the following:

decompose[p1_, p2_] :=
Module[{x1 = p1, x2 = p2},
If[x1 <= x2,
Sum[Print[k1, x2 - x1 + 2 k2, k1], {k1, 0, x1}, {k2, 0, x1 - k1}],
Print["Wrong values for the p1 and the p2"]]]


And in order to perform the aforementioned example, one has to run the simple

decompose[2, 2]


If you try to run this command -the absolute timing is $$0.000328$$- you obtain the correct decompositions and none is missing. After the representations are printed I am getting the following message:

6 Null


Six is the number of terms; which is great and very helpful as I wanted to implement a command telling me how many terms I will get after the decomposition. I understand why I am getting the Null. This is coming from the way I have written the sum. However, I have not managed to resolve the issue. Namely, if I tweak the implementation of the sum the code does not work.

Punchline: I would like to be able to run the command and obtain something like -for the example above-

There are 6 channels

000

020

040

101

121

202


P.S: A bit more generally, this is -I believe- the equivalent of asking how can I make Mma to perform a summation or a product in a symbolic form and not by actually computing the traditional algebraic problem.

• Print[] doesn't return a number...so it doesn't make sense to Sum[] over those results. Try replacing the Print[] statement with something that returns a numerical value, e.g., x2 - x1 + 2 k2 – Joshua Schrier Jun 19 '19 at 17:52
• You may replace the Print[...] also by Print[k1, x2 - x1 + 2 k2, k1]; 1. This executes the Print command but return 1 instead of Null. – Henrik Schumacher Jun 19 '19 at 18:20
• Something like this? CircleTimes[AngleBracket[0, p1_, 0], AngleBracket[0, p2_, 0]] := Sum[AngleBracket[k1, p2 - p1 + 2 k2, k1], {k1, 0, p1}, {k2, 0, p1 - k1}]/.Plus:>CirclePlus – chuy Jun 19 '19 at 19:42

I tried:

decompose[p1_, p2_] :=
Module[{x1 = p1, x2 = p2},
If[x1 <= x2, count = 0;
Do[count++;
Print[k1, x2 - x1 + 2 k2, k1], {k1, 0, x1}, {k2, 0, x1 - k1}];
Print["Total of ", count],
Print["Wrong values for the p1 and the p2"]]];
decompose[2, 2];


The output is:

000
020
040
101
121
202
Total of 6


The do loop function allows for the computation of expression and iterates through based on the conditions give see https://reference.wolfram.com/language/ref/Do.html?q=Do.