Error In Least Squares Proof? TLDR: I think Miller's proof of the Least Squares formula has an error in it, but can't prove my suspicion  
I recently realized that I had yet to see a proof of the Least Squares Regression formula while showing the formula to a statistics class; I quickly turned to Google, and this was the first paper to pop up. However, there seems to be a flaw in the last step that makes me hesitant to accept this "proof". Here is a brief summary of the link that concludes with the step in question highlighted in red.

We first define an error function for a linear regression with Least Squares. We define this error function as
  $$E(a,b) = \sum_{n=1}^N (y_n-(ax_n+b))^2$$
  We desire to find $a,b$ that minimizes this function. Taking partial derivatives and equating to zero, we find that
  $$\begin{cases}
\sum_{n=1}^N (y_n-(ax_n+b))^2x_n &= 0   \\
\sum_{n=1}^N (y_n-(ax_n+b))^2 &= 0
\end{cases}$$
  Separating, we convert to matrix notation and invert
  $$\begin{pmatrix}
        \sum_{n=1}^N x_n^2 & \sum_{n=1}^N x_n \\
        \sum_{n=1}^N x_n & \sum_{n=1}^N 1 \\
        \end{pmatrix}
\begin{pmatrix}
        a \\
        b \\
        \end{pmatrix}
 = 
\begin{pmatrix}
        \sum_{n=1}^N y_nx_n \\
        \sum_{n=1}^N y_n \\
        \end{pmatrix}$$
  $$\implies
\begin{pmatrix}
        a \\
        b \\
        \end{pmatrix}
 = 
 \begin{pmatrix}
        \sum_{n=1}^N x_n^2 & \sum_{n=1}^N x_n \\
        \sum_{n=1}^N x_n & \sum_{n=1}^N 1 \\
        \end{pmatrix}^{-1}
\begin{pmatrix}
        \sum_{n=1}^N y_nx_n \\
        \sum_{n=1}^N y_n \\
        \end{pmatrix}$$
  Denote the inverted matrix with $M$; we can invert $M$ iff $\det(M) \neq 0$. We prove this as such:
  $$\begin{align}
\det(M) &= 0\\
\implies
\left(\sum_{n=1}^N x_n^2\right)\left(\sum_{n=1}^N 1\right) - \left(\sum_{n=1}^N x_n\right)\left(\sum_{n=1}^N x_n\right) &= 0\\
\implies
N\sum_{n=1}^N \left(x_n^2\right) - N^2\bar{x}^2 &= 0\\
\implies
N\sum_{n=1}^N x_n^2 - N\sum_{n=1}^N\bar{x}^2 &= 0\\
\implies
N\sum_{n=1}^N \left(x_n^2 - \bar{x}^2\right) &= 0\\
\color{red}{\implies
N\sum_{n=1}^N \left(x_n - \bar{x}\right)^2} &\color{red}{ \;= 0}
\end{align} 
$$  $$\color{red}{\text{where the last equality follows from simple algebra}}\\
\color{red}{\text{Thus, as long as all the } x_n \text{ are not equal,}}\\
\color{red}{\det(M)\text{ will be non-zero and } M \text{ will be invertible}}$$  

It seems to me that the last equality is false, since $a^2 - b^2 = (a-b)(a+b) \neq (a-b)^2$. I presume this is simply an error on Miller (the author) and the rest of the proof is correct, but I don't see how else to show that the determinant is always non-zero!
Could anyone confirm my suspicion the step is invalid? If so, how can the argument be repaired?
 A: You read the demonstration in a wrong way.
What is said is that 
$$\det(M)=N^2(\frac{1}{N}\sum_i x_i^2-{\overline x}^2)=N^2(\frac{1}{N}\sum_i (x_i-\overline x)^2)$$
This follows from the fact that
\begin{align}
\frac{1}{N}\sum_i (x_i-\overline x)^2 &= \frac{1}{N}\sum_i x_i^2-2\overline x\frac{1}{N}\sum_i x_i+\frac{1}{N}\sum_i{\overline x}^2 \\ 
&= \frac{1}{N}\sum_i x_i^2 - 2{\overline x}^2 + {\overline x}^2 \\ &= \frac{1}{N}\sum_i x_i^2-{\overline x}^2\end{align}
It's a classic formula called the Koenig-Huygens formula, to show that $\rm{Var}X=\overline{X^2}-{\overline X}^2$ is a positive number.
So $\det(M)=0$ is equivalent to $X$ being constant !!!
A: The step is valid. Consider
\begin{align}
\sum_{n=1}^{N} (x_n - \bar x)^2 &=  \sum_{n=1}^{N} (x_n^² - 2x_n \bar x + \bar x^2) =  \sum_{n=1}^Nx_n^2 - 2\bar x\sum_{n=1}^{N}x_n + \sum_{n=1}^{N}\bar x^2  \\ &=(\sum_{n=1}^{N} x_n^2) -2\cdot N \bar x^2 + N\bar x^2 = \sum_{n=1}^{N}(x_n^² - \bar x ^2)
\end{align}
Note that, much more generally, you can show that $\mathbb{E}(X-\mathbb{E}X)^2 = \mathbb{E}(X^2) - \mathbb{E}(X)^2$ 
A: There is no problem with that derivation. First expand
$$
N\sum_{n=1}^N \left(x_n - \bar{x}\right)^2=N\sum_{n=1}^N \left(x^2_n - 2 x_n\bar{x} +\bar{x}^2\right),
$$
then using 
$$
\sum_{n=1}^N x_n \bar{x}=N \bar{x}^2= \sum_{n=1}^N \bar{x}^2
$$
we get that 
$$
N\sum_{n=1}^N \left(x^2_n - 2 x_n\bar{x} +\bar{x}^2\right)=N\sum_{n=1}^N \left(x^2_n - 2\bar{x}^2 +\bar{x}^2\right),
$$
thus
$$
\begin{align}
N\sum_{n=1}^N \left(x_n^2 - \bar{x}^2\right) = 0
\implies
N\sum_{n=1}^N \left(x_n - \bar{x}\right)^2 & \;= 0.
\end{align}
$$
