What's the trick behind the reformulation of the following line? Is this a special case of the multinomial theorem and if so can somebody provide any details?
\begin{equation} \int (\sum_{j=1}^{N}v_j\phi_j(x) - \sum_{j=1}^{N}w_j\phi_j(x))^2 dx \\ = \sum_{i=1}^{N}\sum_{j=1}^{N} (v_i-w_i)(v_j-w_j) \int \phi_i(x)\phi_j(x)dx \end{equation}
There's really no trick to this. It is $$\left(\sum_j(v_j-w_j)\phi_j\right)^2 =\left(\sum_j(v_j-w_j)\phi_j\right)\left(\sum_k(v_k-w_k)\phi_k\right) =\sum_{j,k}(v_j-w_j)(v_k-w_k)\phi_j\phi_k$$ plus a few integral signs.