# Lagrange's Four Square Theorem/Proof 2

## Theorem

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

## Proof

### Proof for Primes

Suppose $p$ is a prime.

Define:

$S := \set {\alpha^2 \pmod p: \alpha \in \hointr 0 {\dfrac p 2} \cap \Z}$

Define:

$S' := \set {-1 - \beta^2 \pmod p: \beta \in \hointr 0 {\dfrac p 2} \cap \Z}$

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' < \dfrac p 2$:

$\alpha + \alpha' \not \equiv 0 \pmod p \implies \alpha - \alpha' \equiv 0 \pmod p$ we have $\left\vert{S}\right\vert = \left\vert{\hointr 0 {\dfrac p 2} \cap \Z}\right\vert = 1 + \dfrac {p - 1} 2 = \dfrac {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:

$\card {S'} = \card S = \dfrac {p + 1} 2$

By the Pigeonhole Principle:

$S \cap S' \ne \O$

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

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

Define:

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

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

 $\displaystyle z_1$ $=$ $\displaystyle x_1 + y_1$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \alpha x_3 + \beta x_4 + \alpha y_3 + \beta y_4$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \alpha \left({x_3 + y_3}\right) + \beta \left({x_4 + y_4}\right)$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \alpha z_3 + \beta z_4$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle z_2$ $=$ $\displaystyle x_2 + y_2$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \beta x_3 - \alpha x_4 + \beta y_3 - \alpha y_4$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \beta \left({x_3 + y_3}\right) - \alpha \left({x_4 + y_4}\right)$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \beta z_3 - \alpha z_4$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle \leadsto \ \$ $\displaystyle \vec x + \vec y$ $=$ $\displaystyle \vec z$ $\quad$ $\quad$ $\displaystyle$ $\in$ $\displaystyle L$ $\quad$ $\quad$

So $L$ is closed under vector addition.

 $\displaystyle -x_1$ $\equiv$ $\displaystyle -\left({\alpha x_3 + \beta x_4}\right)$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \alpha \left({-x_3}\right) + \beta \left({-x_4}\right)$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle -x_2$ $\equiv$ $\displaystyle -\left({\beta x_3 - \alpha x_4}\right)$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \beta \left({-x_3}\right) - \alpha \left({-x_4}\right)$ $\displaystyle \pmod p$ $\quad$ $\quad$ $\displaystyle \leadsto \ \$ $\displaystyle -\vec x$ $\in$ $\displaystyle L$ $\quad$ $\quad$ $\displaystyle \leadsto \ \$ $\displaystyle L$ $\le$ $\displaystyle \R^4$ $\quad$ $\quad$

So $L$ has additive inverses.

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

Since:

$\vec x = x_3 \left({\alpha, \beta, 1, 0}\right) + x_4 \left({\beta, -\alpha, 0, 1}\right) + \left\lfloor{\dfrac {x_1} p }\right\rfloor \left({p, 0, 0, 0}\right) + \left\lfloor{\dfrac{x_2} p}\right\rfloor \left({0, p, 0, 0}\right)$

Thus:

$\set {\left({\alpha, \beta, 1, 0}\right), \left({\beta, -\alpha, 0, 1}\right), \left({p, 0, 0, 0}\right), \left({0, p, 0, 0}\right)}$

spans $L$.

We have:

$c_1 \left({\alpha, \beta, 1, 0}\right) + c_2 \left({\beta, -\alpha , 0, 1}\right) + c_3 \left({p, 0, 0, 0}\right) + c_4 \left({0, p, 0, 0}\right)$

Extracting the various coordinates:

 $\displaystyle \alpha c_1 + \beta c_2 + p c_3$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle \beta c_1 - \alpha c_2 + p c_4$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle c_3$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle c_4$ $=$ $\displaystyle 0$ $\quad$ $\quad$

and so:

 $\displaystyle \alpha c_1 + \beta c_2$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle \alpha c_1 - \beta c_2$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle \leadsto \ \$ $\displaystyle 2 \beta c_1$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle \leadsto \ \$ $\displaystyle c_1$ $=$ $\displaystyle 0$ $\quad$ $\quad$ $\displaystyle \leadsto \ \$ $\displaystyle c_2$ $=$ $\displaystyle 0$ $\quad$ $\quad$

So:

$\set {\left({\alpha, \beta, 1, 0}\right), \left({\beta, -\alpha, 0, 1}\right), \left({p, 0, 0, 0}\right), \left({0, p, 0, 0}\right)}$

is linearly independent and thus a basis for $L$.

Thus:

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

Thus:

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

So $L$ is a lattice.

Notice:

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

Then:

$\left({\Z^4 / L}\right) \le \left\vert{\N_p^2 \times \left\{ {\left({0, 0}\right)}\right\} }\right\vert = 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 {2 p} } \left({\vec 0}\right)$, the open ball of radius $\sqrt {2 p}$.

Then:

$\forall \vec x, \vec y \in B_{\sqrt{2p}} \left({\vec 0}\right), \forall t \in \left[{0 \,.\,.\, 1}\right]$:
 $\displaystyle \left\Vert{t \vec x + \left({1 - t}\right) \vec y }\right\Vert$ $\le$ $\displaystyle \left\Vert{t \vec x}\right\Vert + \left\Vert{\left({1 - t}\right) \vec y}\right\Vert$ $\quad$ Definition of Metric $\quad$ $\displaystyle$ $=$ $\displaystyle \left\vert{t}\right\vert \left\Vert{\vec x}\right\Vert + \left\vert{1 - t}\right\vert \left\Vert{\vec y}\right\Vert$ $\quad$ Definition of Metric $\quad$ $\displaystyle$ $<$ $\displaystyle \left\vert{t}\right\vert \sqrt {2 p} + \left\vert{1 - t}\right\vert \sqrt{2 p}$ $\quad$ Definition of Open Ball $B_{\sqrt{2 p} } \left({\vec 0}\right)$ $\quad$ $\displaystyle$ $=$ $\displaystyle \left({\left\vert{t}\right\vert + \left\vert{1 - t}\right\vert}\right) \sqrt{2 p}$ $\quad$ Distributive Property $\quad$ $\displaystyle$ $=$ $\displaystyle \left({t + 1 - t}\right) \sqrt{2 p}$ $\quad$ since $t \in \left[{0 \,.\,.\, 1}\right] \implies t \ge 0$ $\quad$ $\displaystyle$ $=$ $\displaystyle \sqrt {2 p}$ $\quad$ since $t + 1 - t = 1$ is the multiplicative identity of $\R$ $\quad$

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

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

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

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

That means:

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

So:

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

Then $B_{\sqrt{2 p} } \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$):

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

Since $2\pi^2 > 1$:

$\operatorname{Vol} \left({B_{\sqrt{2 p} } \left({\vec 0}\right) }\right) > \det \left({L}\right)$
$L \cap B_{\sqrt{2 p} } \left({\vec 0}\right) \ne \varnothing$

Thus, if:

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

then:

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

However:

 $\displaystyle a_1^2 + a_2^2 + a_3^2 + a_4^2$ $\equiv$ $\displaystyle \left({\alpha a_3 + \beta a_4}\right)^2 + \left({\beta a_3 - \alpha a_4}\right)^2 + a_3^2 + a_4^2$ $\displaystyle \pmod p$ $\quad$ Definition of $L$ $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \alpha^2 a_3^2 + 2 \alpha \beta a_3 a_4 + \beta^2 a_4^2 + \beta^2 a_3^2 - 2 \alpha \beta a_3 a_4 + \alpha^2 a_4^2 + a_3^2 + a_4^2$ $\displaystyle \pmod p$ $\quad$ Binomial Theorem $\quad$ $\displaystyle$ $\equiv$ $\displaystyle \left({\alpha^2 + \beta^2 + 1}\right) \left({a_3 + a_4}\right)$ $\displaystyle \pmod p$ $\quad$ Distributive property $\quad$ $\displaystyle$ $\equiv$ $\displaystyle 0 \left({a_3 + a_4}\right)$ $\displaystyle \pmod p$ $\quad$ by $(1)$ from above $\quad$ $\displaystyle$ $\equiv$ $\displaystyle 0$ $\displaystyle \pmod p$ $\quad$ $\quad$

So $\exists k \in \Z$:

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

Dividing $(2)$ by $p$:

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

Thus:

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

$\Box$

### 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 $\mathbb H$ denote the set of Hurwitz quaternions.

Let $N: \mathbb H \to \R, a + b i + c j + d k \mapsto a^2 + b^2 + c^2 + d^2$ be the standard norm on $\mathbb H$.

Notice:

$x$ is a sum of four squares if and only if $x$ is a norm of a Hurwitz quaternion

Then:

$\exists \mu, \lambda \in \mathbb H: x = \map N \mu, y = \map N \lambda$
$x y = \map N \mu \, \map N \lambda = N \left({\mu \lambda}\right)$

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