Lagrange's four-square theorem
Lagrange's four-square theorem, also known as Bachet's conjecture, states that any natural number can be represented as the sum of four integer squares
where the four numbers are integers. For illustration, 3, 31 and 310 can be represented as the sum of four squares as follows:
Adrien-Marie Legendre improved on the theorem in 1798 with his three-square theorem, by stating that a positive integer can be expressed as the sum of three squares if and only if it is not of the form for integers and . His proof was incomplete, leaving a gap which was later filled by Carl Friedrich Gauss. Later, in 1834, Carl Gustav Jakob Jacobi discovered a simple formula for the number of representations of an integer as the sum of four squares with his own four-square theorem.
The formula is also linked to Descartes' theorem of four "kissing circles", which involves the sum of the squares of the curvatures of four circles. This is also linked to Apollonian gaskets, which were more recently related to the Ramanujan–Petersson conjecture.
Proof using the Hurwitz integers
One of the ways to prove the theorem relies on Hurwitz quaternions, which are the analog of integers for quaternions. 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
where are integers. Thus, the quaternion components are either all integers or all half-integers, depending on whether 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.
where is the conjugate of . Note that the norm of a Hurwitz quaternion is always an integer. (If the coefficients are half-integers, then using modular arithmetic their squares are numbers equivalent to , 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:
For any , . It follows easily that is a unit in the ring of Hurwitz quaternions if and only if .
The proof of the main theorem begins by reduction to the case of prime numbers. Euler's four-square identity implies that if Langrange'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 . To show this for an odd prime integer , represent it as a quaternion 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
The norms of are integers such that
and . This shows that both and are equal to (since they are integers), and is the sum of four squares
If it happens that the chosen has half-integer coefficients, it can be replaced by another Hurwitz quaternion. Choose in such a way that has even integer coefficients. Then
Since has even integer coefficients, will have integer coefficients and can be used instead of the original 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 , where and are integers. This can be seen as follows: since is prime, can hold for integers , only when . Thus, the set of squares contains distinct residues modulo . Likewise, contains residues. Since there are only residues in total, and , the sets and must intersect.
The number can be factored in Hurwitz quaternions:
The norm on Hurwitz quaternions satisfies a form of the Euclidean property: for any quaternion with rational coefficients we can choose a Hurwitz quaternion so that by first choosing so that and then so that for . Then we obtain
It follows that for any Hurwitz quaternions with , there exists a Hurwitz quaternion such that
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 such that
In particular, for some Hurwitz quaternion . If were a unit, would be a multiple of , however this is impossible as is not a Hurwitz quaternion for . Similarly, if were a unit, we would have
as divides , which again contradicts the fact that is not a Hurwitz quaternion. Thus, is not Hurwitz irreducible, as claimed.
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 , can we solve
for all positive integers in integers ? The case 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 then there are exactly 54 possible choices for such that the problem is solvable in integers for all . (Ramanujan listed a 55th possibility , but in this case the problem is not solvable if .)
def Four_Squares(N): M = [ for T in range(N+1)] ## Element T of M will be populated with all pairs [a,b] such that a, b < sqrt(N) and a*a + b*b = T for a in range(0,int(sqrt(N)) + 1): for b in range(a,int(sqrt(N)) + 1): T = a*a + b*b if T <= N: M[T].append([a,b]) P =  ## P will be populated with all lists [a,b,c,d] such that 0 <= a <= b <= c <= d whose squares sum to N for i in range(0,N//2+1): for j in range(0,len(M[i])): for k in range(0,len(M[N-i])): X = [M[i][j], M[i][j], M[N-i][k], M[N-i][k]] X.sort() if X not in P: P.append(X) return P
The sequence of positive integers whose representation as a sum of four squares is unique (up to order) is:
- 1, 2, 3, 5, 6, 7, 8, 11, 14, 15, 23, 24, 32, 56, 96, 128, 224, 384, 512, 896 ... (sequence A006431 in OEIS).
These integers consist of the seven odd numbers 1, 3, 5, 7, 11, 15, 23 and all numbers of the form or .
The sequence of positive integers which cannot be represented as a sum of four non-zero squares is:
- 1, 2, 3, 5, 6, 8, 9, 11, 14, 17, 24, 29, 32, 41, 56, 96, 128, 224, 384, 512, 896 ... (sequence A000534 in OEIS).
These integers consist of the eight odd numbers 1, 3, 5, 9, 11, 17, 29, 41 and all numbers of the form or .
- Fermat's theorem on sums of two squares
- Lagrange's three-square theorem
- Euler's four-square identity
- Jacobi's four-square theorem
- 15 and 290 theorems
- Ireland and Rosen (1990). A Classical Introduction to Modern Number Theory. Springer-Verlag. ISBN 0-387-97329-X.
- The Ramanujan Conhecture and some Diophantine Equations, Peter Sarnak, lecture at Tata Institute of Fundamental Research, of the ICTS lecture series. Bangalore, 2013 via youtube.
- Stillwell J (2003). Elements of Number Theory. New York: Springer-Verlag. pp. 138–157. ISBN 0-387-95587-9.
- Myung-Hwan Kim REPRESENTATIONS OF BINARY FORMS BY QUINARY QUADRATIC FORMS
- M. O. Rabin, J. O. Shallit, Randomized Algorithms in Number Theory, Communications on Pure and Applied Mathematics 39 (1986), no. S1, pp. S239–S256. doi:10.1002/cpa.3160390713