I want to expand the least-squares formula $\sum |a-b|^2$, but I can't follow the reasoning behind what I've heard is the answer:
$|a-b|^2 = |a|^2 - 2|ab| + |b|^2$
Instructions or a link would be much appreciated. Thanks!
EDIT!: Corrected the formula >.<
If $x$ is a real number, then $|x|^2=x^2$. (If you are unsure about this, check separately the cases when $x$ is positive and negative.) Thus $$ |a-b|^2 = (a-b)^2 = a^2-2ab+b^2 = |a|^2-2ab+|b|^2. $$ The formula is wrong if you put absolute values on $ab$. In fact, $|a-b|^2=|a|^2-2|ab|+|b|^2$ if and only if $a$ and $b$ have the same sign.
The complex case: Write $a=re^{i\phi}$ and $b=se^{i\theta}$. Then $$ |a-b|^2 = (a-b)(\bar a-\bar b) = (re^{i\phi}-se^{i\theta})(re^{-i\phi}-se^{-i\theta}) = r^2+s^2-(e^{i(\phi-\theta)}+e^{-i(\phi-\theta)})sr = |a|^2+|b|^2-2\text{Re}(a\bar b). $$ This can also be written as $|a|^2+|b|^2-2\cos(\phi-\theta)|a||b|$ if you prefer such form. I omitted some details in the calculations; ask if you can't fill the gaps.
If you need further clarification, do ask.