Lagrange's four-square theorem, also known as Bachet's conjecture, was proven in 1770 by Joseph Louis Lagrange. An earlier proof by Fermat was never published.
The theorem appears in the Arithmetica of Diophantus, translated into Latin by Bachet in 1621. It states that every positive integer can be expressed as the sum of four squares of integers. For example,
3 = 12 + 12 + 12 + 02
31 = 52 + 22 + 12 + 12
310 = 172 + 42 + 22 + 12.
More formally, for every positive integer n there exist integers x1, x2, x3, x4 such that
n = x12 + x22 + x32 + x42.
Adrien-Marie Legendre improved on the theorem in 1798 by stating that a positive integer can be expressed as the sum of three squares iff it is not of the form 4k(8m + 7). His proof was incomplete, leaving a gap which was later filled by Carl Friedrich Gauss.
In 1834, Carl Gustav Jakob Jacobi found an exact formula for the total number of ways a given positive integer n can be represented as the sum of four squares. This number is eight times the sum of the divisors of n if n is odd and 24 times the sum of the odd divisors of n if n is even (see divisor function).
Lagrange's four-square theorem is a special case of the Fermat polygonal number theorem and Waring's problem. Another possible generalisation is the following problem: Given natural numbers a, b, c and d, can we solve
(*) n = ax12 + bx22 + cx32 + dx42
for all positive integers n in integers x1, x2, x3, x4? The case a=b=c=d=1 is answered in the positive by Lagrange's four-square theorem. The general solution was given by Ramanujan. He proved that if we assume, without loss of generality, that a ≤ b ≤ c ≤ d then there are exactly 54 possible choices for a, b, c and d such that (*) is solvable in integers x1, x2, x3, x4 for all n. (Ramanujan listed a 55th possibility a=1, b=2, c=5, d=5, but in this case (*) is not solvable if n=15. )
* Ireland and Rosen (1990). A Classical Introduction to Modern Number Theory. Springer-Verlag. ISBN 0-387-97329-X.