## Writing an Integer as a Sum of Four Squares

\[\begin{equation} \begin{aligned} &(a^2+b^2+c^2+d^2) (w^2+x^2+y^2+z^2) \\ &= (aw+bx+cy+dz)^2+(ax-bw+cz-dy)^2 \\ &+ (ay-bz-cw+dx)^2+(az+by-cx-dw)^2 \end{aligned} \end{equation}\]

to write a number as a sum of four squares.

Example

\[\begin{equation} \begin{aligned} 4731 &= 83 \times 57 \\ &= (0^2+5^2+7^2+3^2) (1^2+2^2+4^2+6^2) \\ &=(0 \times 1 + 5 \times 2 + 7 \times 4 +3 \times 6)^2 \\ &+ (0 \times 2 - 5 \times 1 + 7 \times 6 -3 \times 4)^2 \\ &+ (0 \times 4 - 5 \times 6 - 7 \times 1 +3 \times 2)^2 \\ &+ (0 \times 6 + 5 \times 4 - 7 \times 2 -3 \times 1)^2 \\ &=56^2+25^2+31^2+3^2 \end{aligned} \end{equation}\]

This expression is not unique. By reordering the squares being dded we obtain a different sum of squares. Every positive integer can be written as the sum of four squares, some of which are zero and some of which are repeated. This is known as Lagrange's Theorem.