Lagrange's Four Square Theorem/Proof 2

Theorem
Every positive integer can be expressed as a sum of four squares.

Proof for Primes
Suppose $p$ is a prime.

Define:


 * $S := \left\{{\alpha^2 \pmod p: \alpha \in \left[{0 \,.\,.\, \dfrac p 2}\right) \cap \Z}\right\}$

Define:


 * $S' := \left\{{-1 - \beta^2 \pmod p: \beta \in \left[{0 \,.\,.\, \dfrac p 2}\right) \cap \Z}\right\}$

Choose $\alpha, \alpha' \in S$:


 * $\alpha^2 \equiv \alpha'^2 \pmod p$

Obviously:


 * $\left( \alpha + \alpha' \right) \left( \alpha - \alpha' \right) = \alpha^2 - \alpha'^2 \equiv 0 \pmod p$

Since $0 \le \alpha$, $\alpha' < \frac p 2$:


 * $\alpha + \alpha' \not \equiv 0 \pmod p \implies \alpha - \alpha' \equiv 0 \pmod p$ we have $\left| S \right|

= \left| \left[ 0,\frac p 2 \right) \cap \Z \right| = 1 + \frac{p-1} 2 = \frac{p+1} 2$

Choose $\beta,\beta' \in S'$:


 * $-1-\beta^2 \equiv -1-\beta'^2 \pmod p$

By simple algebraic manipulation:


 * $-1-\beta^2 \equiv -1-\beta'^2 \pmod p \iff \beta^2 \equiv \beta'^2 \pmod p$

Then:


 * $\left| S' \right| = \left| S \right| = \frac{p+1} 2$

By the Pigeonhole Principle:


 * $S \cap S' \ne \varnothing$

Thus $\exists \alpha,\beta \in \Z$:


 * $(1): \alpha^2 + \beta^2 + 1 \equiv 0 \pmod p$

Define:


 * $L=\left\{{\vec{x}=\left( x_1, x_2, x_3,x_4 \right) \in \Z^4 \left| x_1 \equiv \alpha x_3 + \beta x_4 \pmod p, \: x_2 \equiv \beta x_3 - \alpha x_4 \pmod p \right.}\right\}$

If $\vec{x}$, $\vec{y} \in L$ and $\vec{z} = (z_1, z_2, z_3, z_4)$, then:


 * $z_1 = x_1 + y_1 \equiv \alpha x_3 + \beta x_4 + \alpha y_3 + \beta y_4 \pmod p \equiv \alpha (x_3 + y_3) + \beta (x_4 + y_4) \pmod p \equiv \alpha z_3 + \beta z_4 \pmod p$


 * $z_2 = x_2 + y_2 \equiv \beta x_3 - \alpha x_4 + \beta y_3 - \alpha y_4 \pmod p \equiv \beta (x_3 + y_3) - \alpha(x_4 + y_4) \pmod p \equiv \beta z_3 - \alpha z_4 \pmod p$


 * $\implies \vec{x}+\vec{y}=\vec{z} \in L$

So $L$ is closed under vector addition.


 * $-x_1 \equiv -(\alpha x_3 + \beta x_4) \pmod p \equiv \alpha (-x_3) + \beta (-x_4) \pmod p$


 * $-x_2 \equiv -(\beta x_3 - \alpha x_4) \pmod p \equiv \beta (-x_3) - \alpha (-x_4) \pmod p$


 * $\implies -\vec{x} \in L \implies L \le \R^4$

So $L$ has additive inverses.

Thus $L$ is a subgroup of $\R^4$ (associativity is trivial).

Since:
 * $\vec{x} = x_3 (\alpha ,\beta ,1,0)+x_4 (\beta ,-\alpha ,0,1)+\lfloor \frac{x_1} p \rfloor (p,0,0,0) + \lfloor \frac{ x_2} p \rfloor (0,p,0,0)$

Thus $\left\{{(\alpha ,\beta ,1,0),(\beta ,-\alpha ,0,1),(p,0,0,0),(0,p,0,0)}\right\}$ spans $L$.


 * $c_1 (\alpha, \beta, 1, 0) + c_2 (\beta, -\alpha ,0,1) + c_3 (p,0,0,0)+c_4 (0,p,0,0)=0$


 * $\iff \alpha c_1 + \beta c_2 + p c_3 = 0, \beta c_1 - \alpha c_2 + p c_4 = 0, c_3 = 0, c_4 = 0 \implies \alpha c_1 + \beta c_2 = 0, \alpha c_1 - \beta c_2 = 0 \implies 2 \beta c_1 = 0 \implies c_1 = 0 \implies c_2 = 0$

So $\left\{{(\alpha ,\beta ,1,0),(\beta ,-\alpha ,0,1),(p,0,0,0),(0,p,0,0)}\right\}$ is a linearly independent and thus a basis for $L$.


 * $\displaystyle \dim_{_{^\R}} (\operatorname{span}_{_{^\R}} L)= \dim_{_{^{\Z}}} L = \left| \left\{{(\alpha ,\beta ,1,0),(\beta ,-\alpha ,0,1),(p,0,0,0),(0,p,0,0)}\right\} \right| = 4$

Thus:
 * $\operatorname{span}_\R L = \R^4$

So $L$ is a lattice.

Notice:


 * $\exists \varphi: \N_p^2 \times \left\{{\left({0,0}\right)}\right\} \twoheadrightarrow \Z^4 / L,(x,y,0,0)\mapsto [(x,y,0,0)]$

Then:


 * $\left({\Z^4 / L}\right) \le \left|{\N_p^2 \times \left\{{\left({0, 0}\right)}\right\}}\right| = p^2$

So:


 * $\det \left( L \right) = \# \left( \Z^4 / L \right) < p^2$

Let $\Vert \cdot \Vert$ be the Euclidean metric.

Consider $B_{\sqrt{2p}}\left(\vec{0}\right)$, the open ball of radius $\sqrt{2n}$.

Then $\forall \vec{x}$, $\vec{y} \in B_{\sqrt{2p}}\left(\vec{0}\right)$, $\forall t \in \left[ 0,1 \right]$:

}}
 * multiplicative identity]] of $\R$

Thus the line between $\vec{x}$ and $\vec{y}$ is contained in $ B_{\sqrt{2p}}\left(\vec{0}\right)$.

So $ B_{\sqrt{2p}}\left(\vec{0}\right)$ is convex.

Let $\vec{x} \in B_{\sqrt{2p}}\left(\vec{0}\right)$.

Then $\vec{x} < \sqrt{2p}$.

That means:


 * $\Vert -\vec{x} \Vert = \vert -1 \vert \Vert \vec{x} \Vert = \Vert \vec{x} \Vert < \sqrt{2p}$

So $-\vec{x} \in B_{\sqrt{2p}}\left(\vec{0}\right)$.

Then $B_{\sqrt{2p}}\left(\vec{0}\right)$ is symmetric about the origin.

By the | formula for the volume of an n-ball (with respect to the standard measure on $\R^{n}$):


 * $\displaystyle \operatorname{Vol}\left( B_{\sqrt{2p}} \left( \vec{0} \right) \right) = \frac{\pi^2 \left( \sqrt{2p} \right)^4} 2 = 2 \pi^2 p^2$

Since $2\pi^2 > 1$:


 * $\operatorname{Vol}\left( B_{\sqrt{2p}} \left( \vec{0} \right) \right) > \det \left( L \right)$.

By Minkowski's Theorem:


 * $L \cap B_{\sqrt{2p}}\left( \vec{0} \right) \ne \varnothing$.

Thus, if $\vec{a} = (a_1, a_2, a_3, a_4) \in L \cap B_{\sqrt{2p}} \left( \vec{0} \right)$ then:


 * $0<a_1^2 + a_2^2 + a_3^2 + a_4^2 = \Vert \vec{a} \Vert^2 < 2p$

However:

So $\exists k \in \Z$:


 * $(2): 0 < a_1^2 + a_2^2 + a_3^2 + a_4^2 = kp \le 2 p$

Dividing by (2) by $p$:


 * $0 < k < 2 \implies k=1 $

Thus:


 * $a_1^2 + a_2^2 + a_3^2 + a_4^2 = p$

Proof for Composites
Suppose $x$, $y\in \Z$ are a sum of four squares with neither of $x$, $y$ being primes.

Suppose one of them is equal to $1$.

Then $x*1=x$ is a sum of four squares.

Suppose neither of them is equal to $1$.

Let $N: \mathbb H \to \R, a+bi+cj+dk \mapsto a^2 + b^2 + c^2 + d^2$ be the standard norm on $\mathbb H$ (the set of Hurwitz Quaternions).

Notice:


 * $x$ is a sum of four squares $\iff x$ is a norm of a Hurwitz quaternion

Then:


 * $\exists \mu$, $\lambda \in \mathbb H : x = N(\mu)$, $y=N(\lambda)$

From Norm is a Homomorphism:


 * $xy=N(\mu)N(\lambda)=N(\mu\lambda)$

Since $\mathbb H$ is a ring, we have $\mu \lambda \in \mathbb H$ and thus $x y$ is a sum of four squares.

From the Unique Factorization Theorem, every number can be written as a unique product of primes.

Then