4

I would like to know why the closed form expression of

$$\sum_{i=1}^{n}\sum_{j=i+1}^{n} (a_i + a_j)^2 + (b_i + b_j)^2$$

evalutes to

$$ (n-2) \cdot \sum_{i=1}^{n} (a_i^2 + b_i^2) + (\sum_{i=1}^{n} a_i)^2 + (\sum_{i=1}^{n} b_i)^2$$.

The problem poster offered us to use the substitution $s = \sum_{i=1}^{n} a_i$.

I am assuming that when $i=n$, the lower bound is larger than the higher bound, and the sum has a value $0$ so can be neglected (thus upper bound of the outer sum is actually up to $i = n-1$, but I left it in original form in case I am wrong).

I tried to expand the inner sum over $j$ into $\sum_{j=1}^{n}(\cdot) - \sum_{j=1}^{i}(\cdot)$ but it did not seem to help simplify terms.

Source: Codeforces global round 19 problem D. You can see his explanation under question 1637D https://codeforces.com/blog/entry/99883

  • Yes, the upper bound of the outer sum should be $n-1$, but it is common practice to ignore the terms which arise when the index exceeds the upper bound - so there isn't really a problem. By the way, I have added a detailed answer. – stoic-santiago Feb 13 '22 at 11:20

2 Answers2

2

It suffices to show that $$\sum_{i=1}^n \sum_{j=i+1}^n (a_i + a_j)^2 = (n-2)\sum_{i=1}^n a_i^2 + \left(\sum_{i=1}^n a_i \right)^2$$ Observe that \begin{align} \sum_{i=1}^n \sum_{j=i+1}^n (a_i + a_j)^2 &= \sum_{i=1}^n a_i^2(n-i) + \sum_{i=1}^n\sum_{j=i+1}^n a_j^2 + \sum_{i=1}^n 2a_i \sum_{j=i+1}^n a_j\\ &= \sum_{i=1}^n a_i^2(n-i) + \sum_{i=2}^n (i-1)a_i^2 + \sum_{i=1}^n 2a_i \sum_{j=i+1}^n a_j\\ &= (n-2)\sum_{i=1}^n a_i^2 + \sum_{i=1}^n a_i^2 + \sum_{i=1}^n 2a_i \sum_{j=i+1}^n a_j\\ &= (n-2)\sum_{i=1}^n a_i^2 + \sum_{i=1}^n a_i^2 + 2 \sum_{i=1}^n \sum_{j=i+1}^n a_ia_j\\&= (n-2)\sum_{i=1}^n a_i^2 + \left(\sum_{i=1}^n a_i \right)^2 \end{align} as $$ \sum_{i=1}^n \sum_{j=i+1}^n a_j^2 = \sum_{i=2}^n (i-1)a_i^2 $$ and $$\left(\sum_{i=1}^n a_i \right)^2 = \sum_{i=1}^n a_i^2 + 2 \sum_{i=1}^n \sum_{j=i+1}^n a_ia_j$$ where the latter equality follows from the multinomial theorem. Similarly, you can show that $$\sum_{i=1}^n \sum_{j=i+1}^n (b_i + b_j)^2 = (n-2)\sum_{i=1}^n b_i^2 + \left(\sum_{i=1}^n b_i \right)^2$$ which implies the desired result.


Remark. To better understand $$ S: =\sum_{i=1}^n \sum_{j=i+1}^n a_j^2 = \sum_{i=2}^n (i-1)a_i^2 $$ observe that $S$ is just the sum of all entries of the following matrix: $$A = \left[\begin{matrix}0 & a_2^2 & a_3^2 & a_4^2 & \ldots & a_n^2\\ 0 & 0 & a_3^2 & a_4^2 &\ldots & a_n^2\\ 0 & 0 & 0 & a_4^2 &\ldots & a_n^2 \\ \vdots & \vdots & \vdots & \ddots & a_{n-1}^2 & a_n^2\\ 0 & 0 & 0 & 0 & 0 & a_n^2\end{matrix}\right]_{n-1\times n}$$

  • 1
    Thanks for the clear explanation! The visual representation of the sum S was exactly what I needed, as though you knew what I was going to ask about. I don't think I would have worked out the factorization tricks on my own, it was very good to know. – Jia Geng Feb 13 '22 at 13:51
  • No problem! The matrix representation is pretty good for double sums, especially if you want to change the order of the sums over $i,j$. By the way, feel free to upvote if you found the answer helpful :) – stoic-santiago Feb 13 '22 at 13:53
1

First, notice that : $$\begin{array}{lcl} \displaystyle \left(\sum_{i = 1}^n a_i\right)^2 & = & \displaystyle \sum_{i = 1}^n a_i \sum_{i = 1}^n a_i \\[3mm] & = & \displaystyle \sum_{i = 1}^n \sum_{j = 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n a_i^2 + \sum_{i = 1}^n \sum_{j = 1}^{i - 1} a_i a_j + \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n a_i^2 + \sum_{j = 1}^n \sum_{i = 1}^{j + 1} a_i a_j + \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n a_i^2 + \sum_{i = 1}^n \sum_{j = 1}^{i + 1} a_i a_j + \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n a_i^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] \end{array}$$ We deduce that : $$\begin{array}{lcl} \displaystyle \sum_{i = 1}^n \sum_{j = i + 1}^n (a_i + a_j)^2 & = & \displaystyle \sum_{i = 1}^n \sum_{j = i + 1}^n (a_i^2 + a_j^2 + 2 a_i a_j) \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - i) a_i^2 + \sum_{i = 1}^n \sum_{j = i + 1}^n a_j^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - i) a_i^2 + \sum_{j = 1}^n \sum_{i = 1}^{j - 1} a_j^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - i) a_i^2 + \sum_{j = 1}^n (j - 1) a_j^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - i) a_i^2 + \sum_{i = 1}^n (i - 1) a_i^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - 1) a_i^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - 2) a_i^2 + \sum_{i = 1}^n a_i^2 + 2 \sum_{i = 1}^n \sum_{j = i + 1}^n a_i a_j \\[3mm] & = & \displaystyle \sum_{i = 1}^n (n - 2) a_i^2 + \left(\sum_{i = 1}^n a_i^2\right)^2 \\[3mm] \end{array}$$

Essaidi
  • 1,733
  • I see, I like your idea of substituting both i and j at the third equality step. Thank you very much for the working! – Jia Geng Feb 13 '22 at 13:53