Summation of a Summation of two variables I am taking a physical chemistry course and some of our practice problems include summations of summations, which I've never dealt with before. I have the answer, but I don't understand where it came from - why aren't there any terms with $ i $ or $ j $ left? I thought you took the inner summation and then did the outer summation, but I can't seem to get the correct answer since it's all in terms of the two variables.

The problem: How many terms are there in the following summation? Write out the terms.
$$ S = \sum _ { i = 1 } ^ 3 \sum _ { j = 1 } ^ 2 x _ i y _ j $$


The solution: Six terms:
$$ x _ 1 y _ 1 + x _ 1 y _ 2 + x _ 2 y _ 1 + x _ 2 y _ 2 + x _ 3 y _ 1 + x _ 3 y _ 2 $$

 A: 
We obtain
\begin{align*}
\color{blue}{S}&\color{blue}{=\sum_{i=1}^3\sum_{j=1}^2x_iy_j}\\
&=\sum_{i=1}^3x_i\sum_{j=1}^2y_j\tag{1}\\
&=\sum_{i=1}^3x_i\left(y_1+y_2\right)\tag{2}\\
&=x_1\left(y_1+y_2\right)+x_2\left(y_1+y_2\right)+x_3\left(y_1+y_2\right)\tag{3}\\
&\,\,\color{blue}{=x_1y_1+x_1y_2+x_2y_1+x_2y_2+x_3y_1+x_3y_2}
\end{align*}
and the claim follows.

Comment:

*

*In (1) we factor out $x_i$ from the inner sum, since they do not depend on the index $j$.


*In (2) we expand the inner sum.


*In (3) we expand the outer sum.


*In (4) we multiply out.
A: You compute the inner sum for each value of the index $i$ of the outer sum. Thus, you set $i=1$ and compute $\sum_{j=1}^2x_1y_j$, which is $x_1y_1+x_1y_2$. Then you increment $i$ to $2$ and compute the inner sum again; now it’s $\sum_{j=1}^2x_2y_j=x_2y_1+x_2y_2$. Finally, you increment $i$ to $3$ and do it one more time: $\sum_{j=1}^2x_3y_j=x_3y_1+x_3y_2$. The value of the expression is the sum of these three sums, or
$$x_1y_1+x_1y_2+x_2y_1+x_2y_2+x_3y_1+x_3y_2\,.$$
You can think of it as a computer program, if you’re comfortable with such things. Each summation is in effect a for-next loop:
S=0;
for i=1 to 3 do;
   for j=1 to 2 do;
      S=S+x(i)y(j);
   next j;
next i;

