Is there a summation notation for the sum of products made two by two? I have the following expression:
$$x_1x_2+x_1x_3+\dots+x_1x_n+x_2x_3+x_2x_4+x_2x_5+\dots+x_2x_n+\dots+x_{n-1}x_n$$
On
n = 5;
Sum[x[i] x[j], {i, n}, {j, i + 1, n}]
x[1] x[2] + x[1] x[3] + x[2] x[3] + x[1] x[4] + x[2] x[4] + x[3] x[4] + x[1] x[5] + x[2] x[5] + x[3] x[5] + x[4] x[5]
On
You can also do something like
xv = Map[x, Range[1, 5]]
1/2 (Total@Flatten[Outer[Times, xv, xv]] - xv.xv) // Expand
which give
{x[1], x[2], x[3], x[4], x[5]}
x[1] x[2] + x[1] x[3] + x[2] x[3] + x[1] x[4] +
x[2] x[4] + x[3] x[4] + x[1] x[5] + x[2] x[5] + x[3] x[5] + x[4] x[5]
On
Code golf (not very short, but unintelligible enough)
Tr[x@#x@#2&@@@Range@5~Subsets~{2}]
(*
x[1] x[2] + x[1] x[3] + x[2] x[3] + x[1] x[4] + x[2] x[4] +
x[3] x[4] + x[1] x[5] + x[2] x[5] + x[3] x[5] + x[4] x[5]
*)
On
To follow up on wolfies' answer...Mathematica has the function AugmentedSymmetricPolynomial (among other similar functions). To get the same answer as above one can use the following:
Expand[FullSimplify[
AugmentedSymmetricPolynomial[{1, 1}, {x[1], x[2], x[3], x[4], x[5]}]/2]]
Using this function might be easier for more complicated summations.
These are known as the elementary symmetric polynomials.
See for instance: http://en.wikipedia.org/wiki/Elementary_symmetric_polynomial
$$e_2(X_1, X_2, \dots, X_n) \quad = \quad \sum _{1 \leq i < j \leq n} X_i X_j$$
They are also sometimes called the unitary symmetric functions.
It is also possible to express your 'conditional' sum $(1 \leq i < j \leq n)$ in terms of simple power sums $s_r = \sum_{i=1}^n X_i^r$. For your problem, the conversion is:
$$e_2(X_1, X_2, \dots, X_n) \quad = \quad \sum _{1 \leq i < j \leq n} X_i X_j \quad = \quad \frac{s_1^2 - s_2}{2} \quad = \quad \frac{ \big(\sum_{i=1}^n X_i\big)^2 - \sum_{i=1}^n X_i^2}{2} $$
The conversion to power sum notation is automated by the
MonomialToPowerSumfunction in the mathStatica package for Mathematica. For example, for the 3-product case $\sum _{1 \leq i < j < k \leq n} X_i X_j X_k$:returns:
$$\frac{s_1^3}{6} - \frac{s_1s_2}{2} + \frac{s_3}{3}$$