# Euler's four-square identity

In mathematics, Euler's four-square identity says that the product of two numbers, each of which is a sum of four squares, is itself a sum of four squares. Specifically:

$(a_1^2+a_2^2+a_3^2+a_4^2)(b_1^2+b_2^2+b_3^2+b_4^2)=\,$
$(a_1 b_1 + a_2 b_2 + a_3 b_3 + a_4 b_4)^2 +\,$
$(a_1 b_2 - a_2 b_1 + a_3 b_4 - a_4 b_3)^2 +\,$
$(a_1 b_3 - a_2 b_4 - a_3 b_1 + a_4 b_2)^2 +\,$
$(a_1 b_4 + a_2 b_3 - a_3 b_2 - a_4 b_1)^2.\,$

Euler wrote about this identity in a letter dated May 4, 1748 to Goldbach[1][2] (but he used a different sign convention from the above). It can be proven with elementary algebra and holds in every commutative ring. If the $a_k$ and $b_k$ are real numbers, a more elegant proof is available: the identity expresses the fact that the absolute value of the product of two quaternions is equal to the product of their absolute values, in the same way that the Brahmagupta–Fibonacci two-square identity does for complex numbers.

The identity was used by Lagrange to prove his four square theorem. More specifically, it implies that it is sufficient to prove the theorem for prime numbers, after which the more general theorem follows. The sign convention used above corresponds to the signs obtained by multiplying two quaternions. Other sign conventions can be obtained by changing any $a_k$ to $-a_k$, $b_k$ to $-b_k$, or by changing the signs inside any of the squared terms on the right hand side.

Hurwitz's theorem states that an identity of form,

$(a_1^2+a_2^2+a_3^2+...+a_n^2)(b_1^2+b_2^2+b_3^2+...+b_n^2) = c_1^2+c_2^2+c_3^2+...+c_n^2\,$

where the $c_i$ are bilinear functions of the $a_i$ and $b_i$ is possible only for n = {1, 2, 4, 8}. However, the more general Pfister's theorem allows that if the $c_i$ are just rational functions of one set of variables, hence has a denominator, then it is possible for all $n = 2^m$.[3] Thus, a different kind of four-square identity can be given as,

$(a_1^2+a_2^2+a_3^2+a_4^2)(b_1^2+b_2^2+b_3^2+b_4^2)=\,$
$(a_1 b_4 + a_2 b_3 + a_3 b_2 + a_4 b_1)^2 +\,$
$(a_1 b_3 - a_2 b_4 + a_3 b_1 - a_4 b_2)^2 +\,$
$\left(a_1 b_2 + a_2 b_1 + \frac{a_3 u_1}{b_1^2+b_2^2} - \frac{a_4 u_2}{b_1^2+b_2^2}\right)^2+\,$
$\left(a_1 b_1 - a_2 b_2 - \frac{a_4 u_1}{b_1^2+b_2^2} - \frac{a_3 u_2}{b_1^2+b_2^2}\right)^2\,$

where,

$u_1 = b_1^2b_4-2b_1b_2b_3-b_2^2b_4$
$u_2 = b_1^2b_3+2b_1b_2b_4-b_2^2b_3$

Note also the incidental fact that,

$u_1^2+u_2^2 = (b_1^2+b_2^2)^2(b_3^2+b_4^2)$