The classical proof Several very similar modern versions of Lagrange's proof exist. The proof below is a slightly simplified version, in which the cases for which
m is even or odd do not require separate arguments. {{math proof|title=The classical proof|proof= It is sufficient to prove the theorem for every odd prime number
p. This immediately follows from
Euler's four-square identity (and from the fact that the theorem is true for the numbers 1 and 2). The residues of
a2 modulo
p are distinct for every
a between 0 and (inclusive). To see this, take some
a and define
c as
a2 mod
p.
a is a root of the polynomial over the field . So is (which is different from
a). In a field
K, any polynomial of degree
n has at most
n distinct roots (
Lagrange's theorem (number theory)), so there are no other
a with this property, in particular not among 0 to . Similarly, for
b taking integral values between 0 and (inclusive), the are distinct. By the
pigeonhole principle, there are
a and
b in this range, for which
a2 and are congruent modulo
p, that is for which a^2 + b^2 + 1^2 + 0^2 = np. Now let
m be the smallest positive integer such that
mp is the sum of four squares, (we have just shown that there is some
m (namely
n) with this property, so there is a least one
m, and it is smaller than
p). We show by contradiction that
m equals 1: supposing it is not the case, we prove the existence of a positive integer
r less than
m, for which
rp is also the sum of four squares (this is in the spirit of the
infinite descent method of Fermat). For this purpose, we consider for each
xi the
yi which is in the same residue class modulo
m and between and
m/2 (possibly included). It follows that , for some strictly positive integer
r less than
m. Finally, another appeal to Euler's four-square identity shows that . But the fact that each
xi is congruent to its corresponding
yi implies that all of the
zi are divisible by
m. Indeed, \begin{cases} z_1 &= x_1 y_1 + x_2 y_2 + x_3 y_3 + x_4 y_4 &\equiv x_1^2 + x_2^2 + x_3^2 + x_4^2 &= mp \equiv 0 &\pmod{m}, \\ z_2 &= x_1 y_2 - x_2 y_1 + x_3 y_4 - x_4 y_3 &\equiv x_1 x_2 - x_2 x_1 + x_3 x_4 - x_4 x_3 &= 0 &\pmod{m}, \\ z_3 &= x_1 y_3 - x_2 y_4 - x_3 y_1 + x_4 y_2 &\equiv x_1 x_3 - x_2 x_4 - x_3 x_1 + x_4 x_2 &= 0 &\pmod{m}, \\ z_4 &= x_1 y_4 + x_2 y_3 - x_3 y_2 - x_4 y_1 &\equiv x_1 x_4 + x_2 x_3 - x_3 x_2 - x_4 x_1 &= 0 &\pmod{m}. \end{cases} It follows that, for , , and this is in contradiction with the minimality of
m. In the descent above, we must rule out both the case (which would give and no descent), and also the case (which would give rather than strictly positive). For both of those cases, one can check that would be a multiple of
m2, contradicting the fact that
p is a prime greater than
m. }}
Proof using the Hurwitz integers Another way to prove the theorem relies on
Hurwitz quaternions, which are the analog of
integers for
quaternions. {{math proof|title=Proof using the Hurwitz integers|proof= The Hurwitz quaternions consist of all quaternions with integer components and all quaternions with
half-integer components. These two sets can be combined into a single formula \alpha = \frac{1}{2} E_0 (1 + \mathbf{i} + \mathbf{j} + \mathbf{k}) +E_1\mathbf{i} +E_2\mathbf{j} + E_3\mathbf{k} = a_0 +a_1\mathbf{i} +a_2\mathbf{j} +a_3\mathbf{k} where E_0, E_1, E_2, E_3 are integers. Thus, the quaternion components a_0, a_1, a_2, a_3 are either all integers or all half-integers, depending on whether E_0 is even or odd, respectively. The set of Hurwitz quaternions forms a
ring; that is to say, the sum or product of any two Hurwitz quaternions is likewise a Hurwitz quaternion. The
(arithmetic, or field) norm \mathrm N(\alpha) of a rational quaternion \alpha is the nonnegative
rational number \mathrm{N}(\alpha) = \alpha\bar\alpha = a_0^2 + a_1^2 + a_2^2 + a_3^2 where \bar\alpha=a_0 -a_1\mathbf{i} -a_2\mathbf{j} -a_3\mathbf{k} is the
conjugate of \alpha. Note that the norm of a Hurwitz quaternion is always an integer. (If the coefficients are half-integers, then their squares are of the form \tfrac{1}{4} + n : n \in \mathbb{Z}, and the sum of four such numbers is an integer.) Since quaternion multiplication is associative, and real numbers commute with other quaternions, the norm of a product of quaternions equals the product of the norms: \mathrm{N}(\alpha\beta)=\alpha\beta(\overline{\alpha\beta})=\alpha\beta\bar{\beta}\bar{\alpha}=\alpha \mathrm{N}(\beta)\bar\alpha=\alpha\bar\alpha \mathrm{N}(\beta)= \mathrm{N}(\alpha) \mathrm{N}(\beta). For any \alpha\ne0, \alpha^{-1}=\bar\alpha\mathrm N(\alpha)^{-1}. It follows easily that \alpha is a unit in the ring of Hurwitz quaternions if and only if \mathrm N(\alpha)=1. The proof of the main theorem begins by reduction to the case of prime numbers.
Euler's four-square identity implies that if Lagrange's four-square theorem holds for two numbers, it holds for the product of the two numbers. Since any natural number can be factored into powers of primes, it suffices to prove the theorem for prime numbers. It is true for 2 = 1^2 + 1^2 + 0^2 + 0^2. To show this for an odd prime integer , represent it as a quaternion (p,0,0,0) and assume for now (as we shall show later) that it is not a Hurwitz
irreducible; that is, it can be factored into two non-unit Hurwitz quaternions p = \alpha\beta. The norms of p,\alpha,\beta are integers such that \mathrm N(p)=p^2=\mathrm N(\alpha\beta)=\mathrm N(\alpha)\mathrm N(\beta) and \mathrm N(\alpha),\mathrm N(\beta) > 1. This shows that both \mathrm N(\alpha) and \mathrm N(\beta) are equal to (since they are integers), and is the sum of four squares p=\mathrm N(\alpha)=a_0^2+a_1^2+a_2^2+a_3^2. If it happens that the \alpha chosen has half-integer coefficients, it can be replaced by another Hurwitz quaternion. Choose \omega = (\pm 1\pm\mathbf{i}\pm\mathbf{j} \pm\mathbf{k})/2 in such a way that \gamma \equiv \omega + \alpha has even integer coefficients. Then p=(\bar\gamma-\bar\omega)\omega\bar\omega(\gamma-\omega)=(\bar\gamma\omega-1)(\bar\omega\gamma-1). Since \gamma has even integer coefficients, (\bar\omega\gamma-1) will have integer coefficients and can be used instead of the original \alpha to give a representation of as the sum of four squares. As for showing that is not a Hurwitz irreducible,
Lagrange proved that any odd prime divides at least one number of the form u=1+l^2+m^2, where and are integers. This can be seen as follows: since is prime, a^2\equiv b^2\pmod p can hold for integers a,b, only when a\equiv\pm b\pmod p. Thus, the set X=\{0^2,1^2,\dots,((p-1)/2)^2\} of squares contains (p+1)/2 distinct
residues modulo . Likewise, Y=\{-(1+x):x\in X\} contains (p+1)/2 residues. Since there are only residues in total, and |X|+|Y| = p+1>p, the sets and must intersect. The number can be factored in Hurwitz quaternions: 1+l^2+m^2=(1+l\;\mathbf{i}+m\;\mathbf{j})(1-l\;\mathbf{i}-m\;\mathbf{j}). The norm on Hurwitz quaternions satisfies a form of the
Euclidean property: for any quaternion \alpha=a_0+a_1\mathbf{i}+a_2\mathbf{j}+a_3\mathbf{k} with rational coefficients we can choose a Hurwitz quaternion \beta=b_0+b_1\mathbf{i}+b_2\mathbf{j}+b_3\mathbf{k} so that \mathrm{N}(\alpha-\beta) by first choosing b_0 so that |a_0-b_0| \leq 1/4 and then b_1, b_2, b_3 so that |a_i-b_i| \leq 1/2 for i = 1,2,3. Then we obtain \begin{align} \mathrm{N}(\alpha-\beta) & =(a_0-b_0)^2+(a_1-b_1)^2+(a_2-b_2)^2+(a_3-b_3)^2 \\ & \leq \left(\frac{1}{4} \right)^2+\left(\frac{1}{2}\right)^2+\left(\frac{1}{2}\right)^2+\left(\frac{1}{2}\right)^2=\frac{13}{16} It follows that for any Hurwitz quaternions \alpha,\beta with \alpha \neq 0, there exists a Hurwitz quaternion \gamma such that \mathrm N(\beta-\alpha\gamma) The ring of Hurwitz quaternions is not commutative, hence it is not an actual Euclidean domain, and it does not have
unique factorization in the usual sense. Nevertheless, the property above implies that every right
ideal is
principal. Thus, there is a Hurwitz quaternion \alpha such that \alpha H = p H + (1-l\;\mathbf{i}-m\;\mathbf{j}) H. In particular, p=\alpha\beta for some Hurwitz quaternion \beta. If \beta were a unit, 1-l\;\mathbf{i}-m\;\mathbf{j} would be a multiple of , however this is impossible as 1/p-l/p\;\mathbf{i}-m/p\;\mathbf{j} is not a Hurwitz quaternion for p>2. Similarly, if \alpha were a unit, we would have (1+l\;\mathbf{i}+m\;\mathbf{j})H = (1+l\;\mathbf{i}+m\;\mathbf{j})p H+(1+l\;\mathbf{i}+m\;\mathbf{j})(1-l\;\mathbf{i}-m\;\mathbf{j})H \subseteq p H so divides 1+l\;\mathbf{i}+m\;\mathbf{j}, which again contradicts the fact that 1/p-l/p\;\mathbf{i}-m/p\;\mathbf{j} is not a Hurwitz quaternion. Thus, is not Hurwitz irreducible, as claimed. }} ==Generalizations==