Lagrange's Four Square Theorem/Proof 1

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


 * $\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$
 * $\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:

By Euclid's Lemma for Prime Divisors, either:
 * $p \mathrel \backslash a_1 - a_2$

or:
 * $p \mathrel \backslash a_1 + a_2$

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

From Integer Absolute Value 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 - \left({r_i + 1}\right)$

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 - \left({r' + 1}\right)$

Adding these up:
 * $a^2 + b^2 + s = \left({q_1 + q_2 + 1}\right) 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 \left({\dfrac {p^2} 4 + \dfrac {p^2} 4 + 1}\right) < 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$.

$m$ is even.

Let $(1)$ be written as:
 * $(2): \quad \dfrac m 2 p = \left({\dfrac {x_1 + x_2} 2}\right)^2 + \left({\dfrac {x_1 - x_2} 2}\right)^2 + \left({\dfrac {x_3 + x_4} 2}\right)^2 + \left({\dfrac {x_3 - x_4} 2}\right)^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.

$m \ge 3$.

Again, let $(1)$ be written as:
 * $(2): \quad \dfrac m 2 p = \left({\dfrac {x_1 + x_2} 2}\right)^2 + \left({\dfrac {x_1 - x_2} 2}\right)^2 + \left({\dfrac {x_3 + x_4} 2}\right)^2 + \left({\dfrac {x_3 - x_4} 2}\right)^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:

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

$n = 0$.

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

Then all the $x$'s would be divisible by $m$ and so:
 * $m \left({\left({\dfrac {x_1} m}\right)^2 + \left({\dfrac {x_2} m}\right)^2 + \left({\dfrac {x_3} m}\right)^2 + \left({\dfrac {x_4} m}\right)^2}\right) = p$

which means $m \mathrel \backslash p$.

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

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

We also have:

and so $n < m$.

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

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

and:

where $z_1$ and $z_2$ are integers

Similarly:

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{\left({m z_1}\right)^2} {m^2} + \dfrac{\left({m z_2}\right)^2} {m^2} + \dfrac{\left({m z_3}\right)^2} {m^2} + \dfrac{\left({m z_4}\right)^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.