proof of Lagrange’s foursquare theorem
The following proof is essentially Lagrange’s original, from around 1770. First, we need three lemmas.
Lemma 1.
For any integers $a\mathrm{,}b\mathrm{,}c\mathrm{,}d\mathrm{,}w\mathrm{,}x\mathrm{,}y\mathrm{,}z$,
$({a}^{2}+{b}^{2}+{c}^{2}+{d}^{2})({w}^{2}+{x}^{2}+{y}^{2}+{z}^{2})$  $=$  ${(aw+bx+cy+dz)}^{2}$  
$+$  ${(axbwcz+dy)}^{2}$  
$+$  ${(ay+bzcwdx)}^{2}$  
$+$  ${(azby+cxdw)}^{2}.$ 
This is the Euler foursquare identity, q.v., with different notation.
Lemma 2.
If $\mathrm{2}\mathit{}m$ is a sum of two squares, then so is $m$.
Proof.
Lemma 3.
If $p$ is an odd prime, then ${a}^{\mathrm{2}}\mathrm{+}{b}^{\mathrm{2}}\mathrm{+}\mathrm{1}\mathrm{=}k\mathit{}p$ for some integers $a\mathrm{,}b\mathrm{,}k$ with $$.
Proof.
Let $p=2n+1$. Consider the sets
$$A:=\{{a}^{2}\mid a=0,1,\mathrm{\dots},n\}\mathit{\hspace{1em}}\text{and}\mathit{\hspace{1em}}B:=\{{b}^{2}1\mid b=0,1,\mathrm{\dots},n\}.$$ 
We have the following facts:
 1.

2.
Similarly, no two elements in $B$ are congruent mod $p$.

3.
Furthermore, $A\cap B=\mathrm{\varnothing}$ since elements of $A$ are all nonnegative, while elements of $B$ are all negative.

4.
Therefore, $C:=A\cup B$ has $2n+2$, or $p+1$ elements.
Therefore, by the pigeonhole principle^{}, two elements in $C$ must be congruent mod $p$. In addition^{}, by the first two facts, the two elements must come from different sets. As a result, we have the following equation:
$${a}^{2}+{b}^{2}+1=kp$$ 
for some $k$. Clearly $k$ is positive. Also, ${p}^{2}={(2n+1)}^{2}>2{n}^{2}+1\ge {a}^{2}+{b}^{2}+1=kp$, so $p>k$. ∎
Basically, Lemma 3 says that for any prime $p$, some multiple^{} $$ of $p$ is a sum of four squares, since ${a}^{2}+{b}^{2}+1={a}^{2}+{b}^{2}+{1}^{2}+{0}^{2}$.
Proof of Theorem.
By Lemma 1 we need only show that an arbitrary prime $p$ is a sum of four squares. Since that is trivial for $p=2$, suppose $p$ is odd. By Lemma 3, we know
$$mp={a}^{2}+{b}^{2}+{c}^{2}+{d}^{2}$$ 
for some $m,a,b,c,d$ with $$. If $m=1$, then we are done. To complete^{} the proof, we will show that if $m>1$ then $np$ is a sum of four squares for some $n$ with $$.
If $m$ is even, then none, two, or all four of $a,b,c,d$ are even; in any of those cases, we may break up $a,b,c,d$ into two groups, each group containing elements of the same parity. Then Lemma 2 allows us to take $n=m/2$.
Now assume $m$ is odd but $>1$. Write
$w$  $\equiv $  $a\phantom{\rule{veryverythickmathspace}{0ex}}(modm)$  
$x$  $\equiv $  $b\phantom{\rule{veryverythickmathspace}{0ex}}(modm)$  
$y$  $\equiv $  $c\phantom{\rule{veryverythickmathspace}{0ex}}(modm)$  
$z$  $\equiv $  $d\phantom{\rule{veryverythickmathspace}{0ex}}(modm)$ 
where $w,x,y,z$ are all in the interval $(m/2,m/2)$. We have
$$ 
$${w}^{2}+{x}^{2}+{y}^{2}+{z}^{2}\equiv 0\phantom{\rule{veryverythickmathspace}{0ex}}(modm).$$ 
So ${w}^{2}+{x}^{2}+{y}^{2}+{z}^{2}=nm$ for some integer nonnegative $n$. Since $$, $$. In addition, if $n=0$, then $w=x=y=z=0$, so that $a\equiv b\equiv c\equiv d\equiv 0\phantom{\rule{veryverythickmathspace}{0ex}}(modm)$, which implies $mp={a}^{2}+{b}^{2}+{c}^{2}+{d}^{2}={m}^{2}q$, or that $mp$. But $p$ is prime, forcing^{} $m=p$, and contradicting $$. So $$. Look at the product $({a}^{2}+{b}^{2}+{c}^{2}+{d}^{2})({w}^{2}+{x}^{2}+{y}^{2}+{z}^{2})$ and examine Lemma 1. On the left is $n{m}^{2}p$. One the right, we have a sum of four squares. Evidently three of them
$$axbwcz+dy=(axbw)+(dycz)$$ 
$$ay+bzcwdx=(aycw)+(bzdx)$$ 
$$azby+cxdw=(azdw)+(cxby)$$ 
are multiples of $m$. The same is true of the other sum on the right in Lemma 1:
$$aw+bx+cy+dz\equiv {w}^{2}+{x}^{2}+{y}^{2}+{z}^{2}\equiv 0\phantom{\rule{veryverythickmathspace}{0ex}}(modm).$$ 
The equation in Lemma 1 can therefore be divided through by ${m}^{2}$. The result is an expression for $np$ as a sum of four squares. Since $$, the proof is complete. ∎
Remark: Lemma 3 can be improved: it is enough for $p$ to be an odd number^{}, not necessarily prime. But that stronger statement requires a longer proof.
Title  proof of Lagrange’s foursquare theorem 

Canonical name  ProofOfLagrangesFoursquareTheorem 
Date of creation  20130322 13:21:07 
Last modified on  20130322 13:21:07 
Owner  CWoo (3771) 
Last modified by  CWoo (3771) 
Numerical id  13 
Author  CWoo (3771) 
Entry type  Proof 
Classification  msc 11P05 