Lagrange's identity in the complex form
Solution 1:
When you sum the terms in the diagonal you don't get $$\sum_{i=1}^n |a_i|^2\sum_{j=1}^n |b_j|^2.$$
Instead, what you get is $$\sum_{i=1}^n |a_ib_i|^2.$$
Let's write $[n] = \{1,\ldots,n\}$. Here it helps to separate the sum in two sums, one where the indexes agree and one where the indexes are different. Notice that
$$ \sum_{i=1}^n |a_i|^2\sum_{j=1}^n |b_j|^2 = \sum_{i,j\in[n]} |a_ib_j|^2 = \sum_{i=j} |a_ib_j|^2 + \sum_{i\neq j} |a_ib_j|^2 = \sum_{i=1}^n |a_ib_i|^2 + \sum_{i\neq j} |a_ib_j|^2. $$
But if $i\neq j$, of course $j\neq i$, so $$\sum_{i\neq j} |a_ib_j|^2 = \sum_{1\leq i\lt j\leq n} |a_ib_j|^2 + |a_jb_i|^2.$$
Following your line of thought \begin{align} \left|\sum_{i = 1}^na_ib_i\right|^2 &=\left(\sum_{i = 1}^na_ib_i\right)\left(\sum_{j = 1}^n\bar{a}_j\bar{b}_j\right)\\ &= \sum_{i,j\in[n]}a_i\bar{a}_jb_i\bar{b}_j\\ &= \sum_{i=1}^n |a_ib_i|^2 + \sum_{1\leq i\lt j\leq n}a_i\bar{a}_jb_i\bar{b}_j+a_j\bar{a}_ib_j\bar{b}_i \\ &= \sum_{i=1}^n |a_ib_i|^2 + \sum_{i\neq j} |a_ib_j|^2 - \sum_{i\neq j} |a_ib_j|^2 + \sum_{1\leq i\lt j\leq n}a_i\bar{a}_jb_i\bar{b}_j+a_j\bar{a}_ib_j\bar{b}_i \\ &= \sum_{i=1}^n |a_i|^2\sum_{j=1}^n |b_j|^2 - \left( \sum_{i\neq j} |a_ib_j|^2 - \sum_{1\leq i\lt j\leq n}a_i\bar{a}_jb_i\bar{b}_j+a_j\bar{a}_ib_j\bar{b}_i \right) \\ &= \sum_{i=1}^n |a_i|^2\sum_{j=1}^n |b_j|^2 - \sum_{1\leq i\lt j\leq n} |a_ib_j|^2 + |a_jb_i|^2 - a_i\bar{a}_jb_i\bar{b}_j-a_j\bar{a}_ib_j\bar{b}_i \\ &= \sum_{i=1}^n |a_i|^2\sum_{j=1}^n |b_j|^2-\sum_{1\leq i\lt j\leq n}\lvert a_i\bar{b}_j - a_j\bar{b}_i\rvert^2 \end{align}
Solution 2:
I think you are some wrong,in fact, we have $$\left|\sum_{i=1}^{n}a_{i}b_{i}\right|^2=\Re{\left(\sum_{j=1}^{n}\sum_{k=1}^{n}a_{j}b_{j}\overline{a_{k}b_{k}}\right)}=\dfrac{1}{2}\sum_{j=1}^{n}\sum_{k=1}^{n}2\Re{(a_{j}b_{j}\overline{a_{k}b_{k}})}$$ and Note well known indentity: $$2\Re{(a_{j}b_{j}\overline{a_{k}b_{k}})}=|a_{j}|^2|b_{k}|^2+|a_{k}|^2|b_{j}|^2-|a_{j}\overline{b_{k}}-a_{k}\overline{b_{j}}|^2$$ so \begin{align*}\left|\sum_{i=1}^{n}a_{i}b_{i}\right|^2&=\dfrac{1}{2}\sum_{j=1}^{n}\sum_{k=1}^{n}\left(|a_{j}|^2|b_{k}|^2+|a_{k}|^2|b_{j}|^2-|a_{j}\overline{b_{k}}-a_{k}\overline{b_{j}}|^2\right)\\ &=\sum_{j=1}^{n}\sum_{k=1}^{n}|a_{j}|^2|b_{k}|^2-\sum_{1\le i<j\le n}\left(|a_{j}\overline{b_{k}}-a_{k}\overline{b_{j}}|^2\right)\\ &=\left(\sum_{i=1}^{n}|a_{i}|^2\right)\left(\sum_{i=1}^{n}|b_{i}|^2\right)-\sum_{1\le i<j\le n}\left(|a_{j}\overline{b_{k}}-a_{k}\overline{b_{j}}|^2\right) \end{align*}