# Lagrange's Four Square Theorem

## Contents

## Theorem

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

## Proof 1

$1$ can trivially be expressed as a sum of four squares:

- $1 = 1^2 + 0^2 + 0^2 + 0^2$

From Product of Sums of Four Squares it is sufficient to show that each prime can be expressed as a sum of four squares.

The prime number $2$ certainly can: $2 = 1^2 + 1^2 + 0^2 + 0^2$.

It remains to consider the odd primes.

### Existence of $m: 1 \le m < p$ such that $m p$ is the sum of $4$ squares

Suppose that some multiple $m p$ of the odd prime $p$ can be expressed as:

- $m p = a^2 + b^2 + c^2 + d^2, 1 \le m < p$

If $m = 1$, we have the required expression.

If not, then after some algebra we can descend to a smaller multiple of $p$ which is also the sum of four squares:

- $m_1 p = a_1^2 + b_1^2 + c_1^2 + d_1^2, 1 \le m_1 < m$

Next we need to show that there really is a multiple of $p$ which is a sum of four squares.

From this multiple we can descend in a finite number of steps to $p$ being a sum of four squares.

Since $p$ is odd and greater than $2$, $\dfrac {p - 1} 2$ is an integer.

There are $\dfrac {p + 1} 2$ integers $a_1, a_2, \ldots$ such that $0 \le a_i \le \dfrac {p - 1} 2$.

For each $a_i$, let $r_i$ be the remainder when ${a_i}^2$ is divided by $p$.

We have:

- $\forall r_i: 0 \le r_i \le p - 1$

Aiming for a contradiction, suppose:

- $\exists a_1, a_2: 0 \le a_2 < a_1 \le \dfrac {p - 1} 2: {a_1}^2 = q_1 p + r, {a_2}^2 = q_2 p + r$

That is, two different integers in that range which have the same remainder.

Then:

\(\displaystyle {a_1}^2 - {a_2}^2\) | \(=\) | \(\displaystyle \paren {q_1 - q_2} p\) | |||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle p\) | \(\divides\) | \(\displaystyle \paren { {a_1}^2 - {a_2}^2}\) | ||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle \paren {a_1 - a_2} \paren {a_1 + a_2}\) |

By Euclid's Lemma for Prime Divisors, either:

- $p \divides a_1 - a_2$

or:

- $p \divides a_1 + a_2$

But both $a_1 - a_2$ and $a_1 + a_2$ are positive integers less than $p$.

From Absolute Value of Integer is not less than Divisors, this is impossible.

Hence by Proof by Contradiction, it is not the case that:

- $\exists a_1, a_2: 0 \le a_2 < a_1 \le \dfrac {p - 1} 2: {a_1}^2 = q_1 p + r, {a_2}^2 = q_2 p + r$

To each $r_i$, add $1$ and subtract the result from $p$:

- $\forall r_i: s_i = p - \paren {r_i + 1}$

Thus we have $\dfrac {p + 1} 2$ distinct positive integers $s_i$ such that:

- $0 \le s_i \le p - 1$

Out of these $r_i$ and $s_i$, there must exist some $r$ and $s$ such that $r = s$, otherwise there would be:

- $\dfrac {p + 1} 2 + \dfrac {p + 1} 2 = p + 1$

distinct positive integers less than $p$.

So take such an $r$ and $s$ such that $r = s$.

By construction:

- $\exists a, b \in \Z: 0 \le a, b \le \dfrac {p - 1} 2$

such that:

- $a^2 = q_1 p + r$
- $b^2 = q_2 p + r'$
- $s = p - \paren {r' + 1}$

Adding these up:

- $a^2 + b^2 + s = \paren {q_1 + q_2 + 1} p + r - 1$

As $r = s$, we can write this as:

- $a^2 + b^2 + 1 = m p$

where $m = q_1 + q_2 + 1$.

Thus we have that:

- $m p = a^2 + b^2 + 1^2 + 0^2$

and so is a sum of four squares such that:

- $m = \dfrac {a^2 + b^2 + 1} p < \dfrac 1 p \paren {\dfrac {p^2} 4 + \dfrac {p^2} 4 + 1} < p$

By hypothesis, $1 \le m < p$.

To recapitulate: what has been proved is that there exists an integer $m$ such that $1 \le m < p$ such that $m p$ is the sum of four squares.

Note the restriction on $m$: of $m = 0$ or $m = p$, then $m p = 0 = 0^2$ or $m p = p^2$, both of which are trivially the sum of four squares.

### Every prime $p > 2$ written as sum of $4$ squares

Let $m$ be the smallest positive integer such that:

- $(1): \quad m p = {x_1}^2 + {x_2}^2 + {x_3}^2 + {x_4}^2$

for integers $x_1, x_2, x_3, x_4$.

It has already been demonstrated that $m < p$.

It remains to be shown that $m = 1$.

Aiming for a contradiction, suppose $m$ is even.

Let $(1)$ be written as:

- $(2): \quad \dfrac m 2 p = \paren {\dfrac {x_1 + x_2} 2}^2 + \paren {\dfrac {x_1 - x_2} 2}^2 + \paren {\dfrac {x_3 + x_4} 2}^2 + \paren {\dfrac {x_3 - x_4} 2}^2$

Then $m p$ is also even.

We have that Parity of Integer equals Parity of its Square.

Thus there are three possibilities:

- $\text{(i)}: \quad$ All the $x_i$'s are even.
- $\text{(ii)}: \quad$ All the $x_i$'s are odd.
- $\text{(iii)}: \quad$ Two of the $x_i$'s are odd, and two of the $x_i$'s are even.

In case $\text{(i)}$ and $\text{(ii)}$ the numbers in parentheses in $(2)$ are integers.

In case $\text{(iii)}$, either $x_1$ and $x_2$ have the same parity or they do not.

If they do, then the numbers in parentheses in $(2)$ are integers.

If they do not, then each of the numbers in parentheses in $(2)$ are odd integers divided by $4$.

Thus $\dfrac m 2 p$ would not be even.

So, given that $\dfrac m 2 p$ is even, it follows that the numbers in parentheses in $(2)$ are integers.

But $\dfrac m 2$ is an integer and $\dfrac m 2 < m$.

This contradicts the statement that $m$ is the smallest positive integer such that $m p$ is the sum of $4$ squares.

By Proof by Contradiction it follows that $m$ is odd.

Aiming for a contradiction, suppose $m \ge 3$.

Again, let $(1)$ be written as:

- $(2): \quad \dfrac m 2 p = \paren {\dfrac {x_1 + x_2} 2}^2 + \paren {\dfrac {x_1 - x_2} 2}^2 + \paren {\dfrac {x_3 + x_4} 2}^2 + \paren {\dfrac {x_3 - x_4} 2}^2$

Divide each $x_i$ by $m$ to obtain a remainder $r_i$ such that $0 \le r_i \le m - 1$.

Define $y_i$ as:

- $y_i := \begin{cases} r_i & : 0 \le r_i \le \dfrac {m - 1} 2 \\ r_i - m & : \dfrac {m + 1} 2 \le r_i \le m - 1 \end{cases}$

Then:

- $x_i = q_i m + y_i$

where:

- $-\dfrac {m - 1} 2 \le y_i \le \dfrac {m - 1} 2$

We have that $y_i = x_i - q_i m$.

Hence $(1)$ gives:

\(\displaystyle \) | \(\) | \(\displaystyle {y_1}^2 + {y_2}^2 + {y_3}^2 + {y_4}^2\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle {x_1}^2 + {x_2}^2 + {x_3}^2 + {x_4}^2\) | |||||||||||

\(\displaystyle \) | \(\) | \(\, \displaystyle - \, \) | \(\displaystyle 2 m \paren {x_1 q_1 + x_2 q_2 + x_3 q_3 + x_4 q_4}\) | ||||||||||

\(\displaystyle \) | \(\) | \(\, \displaystyle + \, \) | \(\displaystyle m^2 \paren { {q_1}^2 + {q_2}^2 + {q_3}^2 + {q_4}^2}\) | ||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m p - 2 m \paren {x_1 q_1 + x_2 q_2 + x_3 q_3 + x_4 q_4}\) | |||||||||||

\(\displaystyle \) | \(\) | \(\, \displaystyle + \, \) | \(\displaystyle m^2 \paren { {q_1}^2 + {q_2}^2 + {q_3}^2 + {q_4}^2}\) | ||||||||||

\((3):\quad\) | \(\displaystyle \) | \(=\) | \(\displaystyle m n\) |

where $n \in \Z_{\ge 0}$.

Aiming for a contradiction, suppose $n = 0$.

Then all the $y$'s would be zero.

Then all the $x$'s would be divisible by $m$ and so:

- $m \paren {\paren {\dfrac {x_1} m}^2 + \paren {\dfrac {x_2} m}^2 + \paren {\dfrac {x_3} m}^2 + \paren {\dfrac {x_4} m}^2} = p$

which means $m \divides p$.

But this is impossible, as $1 < m < p$ and $p$ is prime.

Thus by Proof by Contradiction, $n \ne 0$.

We also have:

\(\displaystyle m n\) | \(=\) | \(\displaystyle {y_1}^2 + {y_2}^2 + {y_3}^2 + {y_4}^2\) | |||||||||||

\(\displaystyle \) | \(<\) | \(\displaystyle 4 \paren {\dfrac m 2}^2\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m^2\) |

and so $n < m$.

Multiplying $(1)$ by $(3)$:

\((4):\quad\) | \(\displaystyle m^2 n p\) | \(=\) | \(\displaystyle \paren { {x_1}^2 + {x_2}^2 + {x_3}^2 + {x_4}^2} \paren { {y_1}^2 + {y_2}^2 + {y_3}^2 + {y_4}^2}\) | ||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle \paren {x_1 y_1 + x_2 y_2 + x_3 y_3 + x_4 y_4}^2\) | Product of Sums of Four Squares | ||||||||||

\(\displaystyle \) | \(\) | \(\, \displaystyle + \, \) | \(\displaystyle \paren {x_1 y_2 - x_2 y_1 - x_3 y_4 + x_4 y_3}^2\) | ||||||||||

\(\displaystyle \) | \(\) | \(\, \displaystyle + \, \) | \(\displaystyle \paren {x_1 y_3 + x_2 y_4 - x_3 y_1 - x_4 y_2}^2\) | ||||||||||

\(\displaystyle \) | \(\) | \(\, \displaystyle + \, \) | \(\displaystyle \paren {x_1 y_4 - x_2 y_3 + x_3 y_2 - x_4 y_1}^2\) |

Each of the squared numbers on the right hand side is a multiple of $m$, as can be shown for example:

\(\displaystyle \) | \(\) | \(\displaystyle x_1 y_1 + x_2 y_2 + x_3 y_3 + x_4 y_4\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle x_1 \paren {x_1 - q_1 m} + x_2 \paren {x_2 - q_2 m} + x_3 \paren {x_3 - q_3 m} + x_4 \paren {x_4 - q_4 m}\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle \paren { {x_1}^2 + {x_2}^2 + {x_3}^2 + {x_4}^2} - m \paren {x_1 q_1 + x_2 q_2 + x_3 q_3 + x_4 q_4}\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m p - m \paren {x_1 q_1 + x_2 q_2 + x_3 q_3 + x_4 q_4}\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m z_1\) |

and:

\(\displaystyle \) | \(\) | \(\displaystyle x_1 y_2 - x_2 y_1 - x_3 y_4 + x_4 y_3\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle x_1 \paren {x_2 - q_2 m} - x_2 \paren {x_1 - q_1 m} - x_3 \paren {x_4 - q_4 m} + x_4 \paren {x_3 - q_3 m}\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m \paren {-x_1 q_1 + x_2 q_1 + x_3 q_4 + x_4 q_3}\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m p - m \paren {x_1 q_1 + x_2 q_2 + x_3 q_3 + x_4 q_4}\) | |||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle m z_2\) |

where $z_1$ and $z_2$ are integers

Similarly:

\(\displaystyle x_1 y_3 + x_2 y_4 - x_3 y_1 - x_4 y_2\) | \(=\) | \(\displaystyle m z_3\) | |||||||||||

\(\displaystyle x_1 y_4 - x_2 y_3 + x_3 y_2 - x_4 y_1\) | \(=\) | \(\displaystyle m z_4\) |

for some integers $z_3$ and $z_4$.

Substituting these $m z_1$, $m z_2$, $m z_3$, $m z_4$ back into $(4)$ and dividing by $m^2$ gives:

- $n p = \dfrac {\paren {m z_1}^2} {m^2} + \dfrac {\paren {m z_2}^2} {m^2} + \dfrac {\paren {m z_3}^2} {m^2} + \dfrac {\paren {m z_4}^2} {m^2} = {z_1}^2 + {z_2}^2 + {z_3}^2 + {z_4}^2$

where $1 \le n < m$.

But this contradicts the minimality of $m$.

Thus by Proof by Contradiction, $m < 3$.

It remains that $m = 1$ and so $p$ can be expressed as the sum of $4$ squares.

$\blacksquare$

## Proof 2

### 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\) | |||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \alpha x_3 + \beta x_4 + \alpha y_3 + \beta y_4\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \alpha \left({x_3 + y_3}\right) + \beta \left({x_4 + y_4}\right)\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \alpha z_3 + \beta z_4\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle z_2\) | \(=\) | \(\displaystyle x_2 + y_2\) | |||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \beta x_3 - \alpha x_4 + \beta y_3 - \alpha y_4\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \beta \left({x_3 + y_3}\right) - \alpha \left({x_4 + y_4}\right)\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \beta z_3 - \alpha z_4\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle \vec x + \vec y\) | \(=\) | \(\displaystyle \vec z\) | ||||||||||

\(\displaystyle \) | \(\in\) | \(\displaystyle L\) |

So $L$ is closed under vector addition.

\(\displaystyle -x_1\) | \(\equiv\) | \(\displaystyle -\left({\alpha x_3 + \beta x_4}\right)\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \alpha \left({-x_3}\right) + \beta \left({-x_4}\right)\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle -x_2\) | \(\equiv\) | \(\displaystyle -\left({\beta x_3 - \alpha x_4}\right)\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \beta \left({-x_3}\right) - \alpha \left({-x_4}\right)\) | \(\displaystyle \pmod p\) | ||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle -\vec x\) | \(\in\) | \(\displaystyle L\) | ||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle L\) | \(\le\) | \(\displaystyle \R^4\) |

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\) | |||||||||||

\(\displaystyle \beta c_1 - \alpha c_2 + p c_4\) | \(=\) | \(\displaystyle 0\) | |||||||||||

\(\displaystyle c_3\) | \(=\) | \(\displaystyle 0\) | |||||||||||

\(\displaystyle c_4\) | \(=\) | \(\displaystyle 0\) |

and so:

\(\displaystyle \alpha c_1 + \beta c_2\) | \(=\) | \(\displaystyle 0\) | |||||||||||

\(\displaystyle \alpha c_1 - \beta c_2\) | \(=\) | \(\displaystyle 0\) | |||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle 2 \beta c_1\) | \(=\) | \(\displaystyle 0\) | ||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle c_1\) | \(=\) | \(\displaystyle 0\) | ||||||||||

\(\displaystyle \leadsto \ \ \) | \(\displaystyle c_2\) | \(=\) | \(\displaystyle 0\) |

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\) | Definition of Metric | ||||||||||

\(\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\) | Definition of Metric | ||||||||||

\(\displaystyle \) | \(<\) | \(\displaystyle \left\vert{t}\right\vert \sqrt {2 p} + \left\vert{1 - t}\right\vert \sqrt{2 p}\) | Definition of Open Ball $B_{\sqrt{2 p} } \left({\vec 0}\right)$ | ||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle \left({\left\vert{t}\right\vert + \left\vert{1 - t}\right\vert}\right) \sqrt{2 p}\) | Distributive Property | ||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle \left({t + 1 - t}\right) \sqrt{2 p}\) | since $t \in \left[{0 \,.\,.\, 1}\right] \implies t \ge 0$ | ||||||||||

\(\displaystyle \) | \(=\) | \(\displaystyle \sqrt {2 p}\) | since $t + 1 - t = 1$ is the multiplicative identity of $\R$ |

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\) | Definition of $L$ | |||||||||

\(\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\) | Binomial Theorem | |||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle \left({\alpha^2 + \beta^2 + 1}\right) \left({a_3 + a_4}\right)\) | \(\displaystyle \pmod p\) | Distributive property | |||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle 0 \left({a_3 + a_4}\right)\) | \(\displaystyle \pmod p\) | by $(1)$ from above | |||||||||

\(\displaystyle \) | \(\equiv\) | \(\displaystyle 0\) | \(\displaystyle \pmod p\) |

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$

From Norm is a Homomorphism:

- $ 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

## Also known as

Some sources use the plural form, as **Lagrange's four squares theorem**.

Some omit Lagrange's name, and refer to this as just the **four squares theorem**.

## Also see

## Source of Name

This entry was named for Joseph Louis Lagrange.

## Historical Note

It is suggested by some sources that the result of Lagrange's Four Square Theorem was known, at least empirically, by Diophantus of Alexandria.

Some sources suggest that the theorem was originally stated formally by Pierre de Fermat.

However, it appears that Claude Gaspard Bachet de Méziriac published the results of his having tested it thoroughly up to $120$, and stated the theorem in his $1621$ translation of the *Arithmetica* of Diophantus.

Fermat read about it in his copy of that work, and studied it, but appears to have failed to find a proof, as no proof of his can be found.

Some sources claim that its first proof was by Leonhard Paul Euler, but this is questionable.

It was finally proved by Joseph Louis Lagrange in $1770$.

## Sources

- 1971: George E. Andrews:
*Number Theory*... (previous) ... (next): $\text {3-5}$ The Use of Computers in Number Theory: Exercise $5$ - 1986: David Wells:
*Curious and Interesting Numbers*... (previous) ... (next): $4$ - 1992: George F. Simmons:
*Calculus Gems*... (previous) ... (next): Chapter $\text {B}.2$: More about Numbers: Irrationals, Perfect Numbers and Mersenne Primes - 1997: David Wells:
*Curious and Interesting Numbers*(2nd ed.) ... (previous) ... (next): $4$ - 2008: Ian Stewart:
*Taming the Infinite*... (previous) ... (next): Chapter $7$: Patterns in Numbers