# Expand a complicated polynomial

I am entirely new to Mathematica.

I am wondering whether Mathematica can help me to expand expression like the following

$$f(x_1,\dots, x_n) = \left(\sum_i x_i\sum_j x_ix_j^2\right)^3\left(\sum_{i,j} x_i^3x_j^2\sum_k (x_j-x_k)^2\right)$$

The real thing that I care is more complicated. The point here is that $f$ is invariant with respect to permutation of indices and therefore admits a succinct representation.

It would be great if somebody can give some pointer on how to write this in mathematica or tell me that it can't be done by mathematic easily. (My alternative is to write my own code to do it)

Best, Tengyu

• You might be interested in SymmetricPolynomial[]. Jul 22, 2016 at 15:55
• Closely related question Finding the coefficient of a certain power in a generating function Jul 22, 2016 at 17:04
• I'm not clear on what the expansion you want would look like. Could you give a simple expression and corresponding expansion? Jul 22, 2016 at 21:30
• @mikado, for example, if the input is $(\sum x_i^2)(\sum x_j^3)$ I would like to get in return $\sum_{ij} x_i^2x_j^3$. Jul 23, 2016 at 19:25

Let us start with simpler example and expand $g=\left(\sum _i x(i)^2\right){}^2$ in terms of symmetric polynomials. Notice, I make no assumptions on the limits of summations. Therefore we need to try progressively several limits denoted here by n:

nmx = 3;
TableForm[Table[
g = (Sum[x[i]^2, {i, n}])^2;
SymmetricReduction[g, Table[x[i], {i, n}], Table[s[i], {i, n}]],
{n,nmx}],

$\begin{array}{l|ll} n&\text{representation}&\text{reminder}\\\hline 1&s(1)^4 & 0 \\ 2&s(1)^4-4 s(2) s(1)^2+4 s(2)^2 & 0 \\ 3&s(1)^4-4 s(2) s(1)^2+4 s(2)^2 & 0 \\ \end{array}$
where $s[i]$ are corresponding symmetric polynomials. We see that in this case it is sufficient to restrict to $n=2$ to get an answer. Your example is much more complex because you need to be able to generate from your formula (which involves infinite sums and is probably symmetric under permutations) a finite formula (that is still symmetric and that MA can handle). By the way, it is not obvious for me that your expression is symmetric. Can you demonstrate it?
• Thanks! I couldn't immediately fully understand your answer because the lack of background knowledge in this, but it seems to be very useful! To see why it's symmetric -- I think if I am not wrong, for every f, $\sum_{ij} f(x_i,x_j)$ is symmetric, and this shows that second big multiplier is symmetric. The first one is simpler since it's just $\sum_i g(x_i)$. Jul 23, 2016 at 19:21