Recent from talks
Nothing was collected or created yet.
Lagrange's four-square theorem
View on Wikipedia
Lagrange's four-square theorem, also known as Bachet's conjecture, states that every nonnegative integer can be represented as a sum of four non-negative integer squares.[1] That is, the squares form an additive basis of order four: where the four numbers are integers. For illustration, 3, 31, and 310 can be represented as the sum of four squares as follows:
This theorem was proven by Joseph-Louis Lagrange in 1770. It is a special case of the Fermat polygonal number theorem.
Historical development
[edit]From examples given in the Arithmetica, it is clear that Diophantus was aware of the theorem. This book was translated in 1621 into Latin by Bachet (Claude Gaspard Bachet de Méziriac), who stated the theorem in the notes of his translation. But the theorem was not proved until 1770 by Lagrange.[2]
Adrien-Marie Legendre extended the theorem in 1797–8 with his three-square theorem, by proving 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 k and m. 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.[3]
Proofs
[edit]The classical proof
[edit]Several very similar modern versions[4][5][6] 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.
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 (p − 1)/2 (inclusive). To see this, take some a and define c as a2 mod p. a is a root of the polynomial x2 − c over the field Z/pZ. So is p − a (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 (p − 1)/2.
Similarly, for b taking integral values between 0 and (p − 1)/2 (inclusive), the −b2 − 1 are distinct. By the pigeonhole principle, there are a and b in this range, for which a2 and −b2 − 1 are congruent modulo p, that is for which
Now let m be the smallest positive integer such that mp is the sum of four squares, x12 + x22 + x32 + x42 (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[7] method of Fermat).
For this purpose, we consider for each xi the yi which is in the same residue class modulo m and between (–m + 1)/2 and m/2 (possibly included). It follows that y12 + y22 + y32 + y42 = mr, for some strictly positive integer r less than m.
Finally, another appeal to Euler's four-square identity shows that mpmr = z12 + z22 + z32 + z42. But the fact that each xi is congruent to its corresponding yi implies that all of the zi are divisible by m. Indeed,
It follows that, for wi = zi/m, w12 + w22 + w32 + w42 = rp, and this is in contradiction with the minimality of m.
In the descent above, we must rule out both the case y1 = y2 = y3 = y4 = m/2 (which would give r = m and no descent), and also the case y1 = y2 = y3 = y4 = 0 (which would give r = 0 rather than strictly positive). For both of those cases, one can check that mp = x12 + x22 + x32 + x42 would be a multiple of m2, contradicting the fact that p is a prime greater than m.
Proof using the Hurwitz integers
[edit]Another way to prove the theorem relies on Hurwitz quaternions, which are the analog of integers for quaternions.[8]
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.
The (arithmetic, or field) norm of a rational quaternion is the nonnegative rational number where is the conjugate of . 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 , 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 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 . To show this for an odd prime integer p, 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 p (since they are integers), and p 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 p as the sum of four squares.
As for showing that p is not a Hurwitz irreducible, Lagrange proved that any odd prime p divides at least one number of the form , where l and m are integers.[8] This can be seen as follows: since p is prime, can hold for integers , only when . Thus, the set of squares contains distinct residues modulo p. Likewise, contains residues. Since there are only p residues in total, and , the sets X and Y must intersect.
The number u 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 H 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 p, however this is impossible as is not a Hurwitz quaternion for . Similarly, if were a unit, we would have so p divides , which again contradicts the fact that is not a Hurwitz quaternion. Thus, p is not Hurwitz irreducible, as claimed.
Generalizations
[edit]Lagrange's four-square theorem is a special case of the Fermat polygonal number theorem and Waring's problem. Another possible generalization is the following problem: Given natural numbers , can we solve
for all positive integers n in integers ? The case is answered in the positive by Lagrange's four-square theorem. The general solution was given by Ramanujan.[9] 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 n. (Ramanujan listed a 55th possibility , but in this case the problem is not solvable if .[10])
Algorithms
[edit]In 1986, Michael O. Rabin and Jeffrey Shallit[11] proposed randomized polynomial-time algorithms for computing a single representation for a given integer n, in expected running time . It was further improved to by Paul Pollack and Enrique Treviño in 2018.[12]
Number of representations
[edit]The number of representations of a natural number n as the sum of four squares of integers is denoted by r4(n). Jacobi's four-square theorem states that this 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), i.e.
Equivalently, it is eight times the sum of all its divisors which are not divisible by 4, i.e.
We may also write this as where the second term is to be taken as zero if n is not divisible by 4. In particular, for a prime number p we have the explicit formula r4(p) = 8(p + 1).[13]
Some values of r4(n) occur infinitely often as r4(n) = r4(2mn) whenever n is even. The values of r4(n)/n can be arbitrarily large: indeed, r4(n)/n is infinitely often larger than 8√log n.[13]
Uniqueness
[edit]The sequence of positive integers which have only one representation as a sum of four squares of non-negative integers (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 the 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 the OEIS).
These integers consist of the eight odd numbers 1, 3, 5, 9, 11, 17, 29, 41 and all numbers of the form or .
Further refinements
[edit]Lagrange's four-square theorem can be refined in various ways. For example, Zhi-Wei Sun[14] proved that each natural number can be written as a sum of four squares with some requirements on the choice of these four numbers.
One may also wonder whether it is necessary to use the entire set of square integers to write each natural as the sum of four squares. Eduard Wirsing proved that there exists a set of squares S with such that every positive integer smaller than or equal to n can be written as a sum of at most 4 elements of S.[15]
See also
[edit]Notes
[edit]- ^ Andrews, George E. (1994), Number Theory, Dover Publications, p. 144, ISBN 0-486-68252-8
- ^ Ireland & Rosen 1990.
- ^ Sarnak 2013.
- ^ Landau 1958, Theorems 166 to 169.
- ^ Hardy & Wright 2008, Theorem 369.
- ^ Niven & Zuckerman 1960, paragraph 5.7.
- ^ Here the argument is a direct proof by contradiction. With the initial assumption that m > 2, m < p, is some integer such that mp is the sum of four squares (not necessarily the smallest), the argument could be modified to become an infinite descent argument in the spirit of Fermat.
- ^ a b Stillwell 2003, pp. 138–157.
- ^ Ramanujan 1916.
- ^ Oh 2000.
- ^ Rabin & Shallit 1986.
- ^ Pollack & Treviño 2018.
- ^ a b Williams 2011, p. 119.
- ^ Sun 2017.
- ^ Spencer 1996
References
[edit]- Hardy, G. H.; Wright, E. M. (2008) [1938]. Heath-Brown, D. R.; Silverman, J. H.; Wiles, Andrew (eds.). An Introduction to the Theory of Numbers (6th ed.). Oxford University Press. ISBN 978-0-19-921985-8.
- Ireland, Kenneth; Rosen, Michael (1990). A Classical Introduction to Modern Number Theory (2nd ed.). Springer. doi:10.1007/978-1-4757-2103-4. ISBN 978-1-4419-3094-1.
- Landau, Edmund (1958) [1927]. Elementary Number Theory. Vol. 125. Translated by Goodman, Jacob E. (2nd ed.). AMS Chelsea Publishing.
- Niven, Ivan; Zuckerman, Herbert S. (1960). An introduction to the theory of numbers. Wiley.
- Oh, Byeong-Kweon (2000). "Representations of Binary Forms by Quinary Quadratic Forms" (PDF). Trends in Mathematics. 3 (1): 102–107. Archived from the original (PDF) on 2017-02-02. Retrieved 2017-01-21.
- Rabin, M. O.; Shallit, J. O. (1986). "Randomized Algorithms in Number Theory". Communications on Pure and Applied Mathematics. 39 (S1): S239 – S256. doi:10.1002/cpa.3160390713.
- Ramanujan, S. (1916). "On the expression of a number in the form ax2 + by2 + cz2 + du2". Mathematical Proceedings of the Cambridge Philosophical Society. 19: 11–21.
- Sarnak, Peter (2013). "The Ramanujan Conjecture and some Diophantine Equations". YouTube (Lecture at Tata Institute of Fundamental Research). ICTS Lecture Series. Bangalore, India.
- Stillwell, John (2003). Elements of Number Theory. Undergraduate Texts in Mathematics. Springer. doi:10.1007/978-0-387-21735-2. ISBN 978-0-387-95587-2. Zbl 1112.11002.
- Sun, Z.-W. (2017). "Refining Lagrange's four-square theorem". J. Number Theory. 175: 167–190. arXiv:1604.06723. doi:10.1016/j.jnt.2016.11.008. S2CID 119597024.
- Williams, Kenneth S. (2011). Number theory in the spirit of Liouville. London Mathematical Society Student Texts. Vol. 76. Cambridge University Press. ISBN 978-0-521-17562-3. Zbl 1227.11002.
- Spencer, Joel (1996). "Four Squares with Few Squares". Number Theory: New York Seminar 1991–1995. Springer US. pp. 295–297. doi:10.1007/978-1-4612-2418-1_22. ISBN 9780387948263.
- Pollack, P.; Treviño, E. (2018). "Finding the four squares in Lagrange's theorem" (PDF). Integers. 18A: A15.
External links
[edit]Lagrange's four-square theorem
View on GrokipediaStatement and background
The theorem
Lagrange's four-square theorem states that every non-negative integer can be expressed as the sum of four squares of integers, that is, there exist integers such that This representation holds for as well, with , and the integers may be positive, negative, or zero; however, since squaring eliminates the sign, it is equivalent to using non-negative integers.[4] The theorem provides a complete solution to the Diophantine equation in integers for any non-negative integer , affirming that such equations always possess integer solutions.[5] A direct corollary is that every prime number can be written as the sum of four integer squares, as primes are a subset of the non-negative integers.[4]Historical context
The concept of representing numbers as sums of squares has roots in ancient mathematics. The Pythagoreans, in the 6th century BCE, explored right-angled triangles through the Pythagorean theorem, which equates the square of the hypotenuse to the sum of the squares of the other two sides, laying early groundwork for integer solutions involving two squares. In the 3rd century CE, Diophantus of Alexandria, in his Arithmetica, investigated Diophantine equations and sums of squares, solving problems such as expressing specific numbers as sums of two or three squares using rational numbers; he also appears to have been aware that every natural number can be expressed as a sum of four squares, though without a formal proof.[6] The problem gained prominence in the early modern period through Claude-Gaspar de Bachet de Méziriac. In his 1621 French translation and commentary on Diophantus's Arithmetica, Bachet posed the four-square representation as a conjecture—now known as Bachet's conjecture—verifying it empirically for all integers from 1 to 325 but leaving a general proof unresolved.[7] Around 1640, Pierre de Fermat encountered Bachet's conjecture and claimed in private correspondence—such as letters to Bernard Frénicle de Bessy in 1658 and Pierre de Carcavi in 1659—that every natural number is the sum of at most four squares, asserting a proof via his method of infinite descent, though he provided no details and only applied descent to special cases like certain primes.[7] Leonhard Euler took up the challenge in the mid-18th century, motivated by exchanges with Christian Goldbach dating back to 1729–1730. In memoirs published between 1749 and 1751 in the Commentarii Academiae Scientiarum Imperialis Petropolitanae, Euler established partial results, proving the theorem for numbers of specific forms (such as those not divisible by primes congruent to 3 modulo 4) and employing continued fractions alongside descent methods, but he could not complete the general case despite further efforts in the 1750s, including work related to primes of the form 4k+1.[7] Joseph-Louis Lagrange resolved the conjecture in 1770 by submitting a complete proof to the Berlin Academy, which was published two years later in the academy's Nouveaux mémoires. Titled "Démonstration d'un théorème d'arithmétique," Lagrange's work built on Euler's partial advances and Fermat's descent techniques, providing the first rigorous general proof after over a century of intermittent progress since Bachet.[7][8]Proofs
Classical proof by Lagrange
Lagrange's proof reduces the problem to showing that every prime number is a sum of four integer squares, leveraging the multiplicativity of the set of sums of four squares. This multiplicativity follows from Euler's four-square identity, which states that the product of two sums of four squares is itself a sum of four squares: The identity can be verified by direct expansion and was established by Euler in 1748. Since every natural number factors uniquely into primes (up to units), and 1 = 1^2 + 0^2 + 0^2 + 0^2 is trivially a sum of four squares, it suffices to verify the theorem for the prime 2 and all odd primes p.[5][](Lagrange, J.-L. (1772). Démonstration d'un théorème d'arithmétique. Nouveaux mémoires de l'Académie royale des sciences et belles lettres de Berlin, 123–133.) For the prime 2, observe that . Higher powers of 2 follow immediately from the identity: for example, yields a representation by substituting the values for 2 into the identity, and induction extends this to for any . A lemma handles even cases more generally: if n is even and a sum of four squares, then is also a sum of four squares by pairing terms according to parity and applying algebraic identities for halves.[5][](Lagrange, 1772) For an odd prime p, the argument proceeds by infinite descent. First, establish that there exists a positive integer m with such that mp is a sum of four squares. This relies on a key lemma: there exist integers u and v, not both zero modulo p, such that . Setting a = u, b = v, c = 1, d = 0 then gives , with the representation nontrivial modulo p. The existence of such u and v follows from a pigeonhole principle argument establishing solutions to . Choosing representatives u, v between 0 and p-1 ensures the sum satisfies , so s = mp with , and m not divisible by p since the representation is nontrivial modulo p. Refinements using smaller representatives or additional pigeonhole applications can bound , but the descent handles larger initial m.[5][](Lagrange, 1772) Now suppose m is the smallest positive integer such that mp = for some integers x_i. The goal is to derive a contradiction if m > 1. Consider the residues of the x_i modulo m and select integers b_i with such that for each i (choosing the signed representative closest to zero). Then , so for some integer r with . If r = 0, then all b_i = 0, so all , implying m^2 divides mp and thus m divides p; since p is prime and 1 < m < 2p, this is impossible. Hence r > 0 and r < m (strict inequality holds unless all |b_i| = m/2, which leads to a similar divisibility contradiction for odd m \geq 3 or even cases via the even lemma).[5][](Lagrange, 1772) To obtain a representation for rp, apply Euler's identity to the pairs (x_1, x_2, x_3, x_4) and (b_1, b_2, b_3, b_4), but with signs chosen on the b_i to ensure each bilinear term in the expansion is divisible by m (possible because the x_i generate the residues and m is minimal). The resulting four terms, say z_1, z_2, z_3, z_4, satisfy for each k, so is divisible by m^2, yielding integers y_k = z_k / m such that . This expresses rp as a sum of four squares with r < m, contradicting the minimality of m. Therefore, m = 1, and p itself is a sum of four squares. The process extends multiplicatively to all natural numbers.[5][](Lagrange, 1772)Algebraic proof using Hurwitz integers
The Hurwitz integers form a subring of the Lipschitz quaternions, consisting of all quaternions of the form , where are either all integers or all half-integers (i.e., integers plus ).[9] This ring, denoted , embeds naturally into the Hamilton quaternions over the rationals, providing an algebraic structure for extending integer arithmetic to four dimensions. The norm of an element is defined as , which is a non-negative integer and multiplicative: .[2] A fundamental property of is that it is a Euclidean domain with respect to the norm, meaning for any nonzero , there exist such that with .[9] Consequently, is a principal ideal domain (PID) and a unique factorization domain (UFD), allowing every nonzero element to factor uniquely into primes up to units. The units of are the 24 elements with norm 1: the 8 integer units , and the 16 half-integer units of the form (all sign combinations).[2] The proof that every natural number is a sum of four squares proceeds by showing that for some , leveraging the multiplicative norm and unique factorization. Since is a PID, the principal ideal generated by a rational prime factors as for prime elements , and taking norms yields . Thus, each (up to units of norm 1), so for some . For composite , factor in and use multiplicativity: if , then where is a product of elements with norms . Base cases confirm this for 1 () and primes.[9] To establish that every rational prime has norm in , classify the primes as follows: the prime 2 is ramified, since (up to units), and . For odd primes, all split: no odd prime remains inert (i.e., prime) in . Primes congruent to 1 modulo 4 factor as for some Gaussian integer extended by units to a Hurwitz integer, yielding . For primes congruent to 3 modulo 4, there exist integers and such that (provable using the pigeonhole principle on the quadratic residues to show is a sum of two squares modulo ). Thus, divides . However, does not divide (as its norm is ), so is not prime in and factors into elements of norm .[2][10] This approach connects directly to Hamilton quaternions, where the norm preservation under multiplication reflects Euler's four-square identity: the product of two sums of four squares is again a sum of four squares, arising from . Unlike Lagrange's classical descent proof, which relies on elementary identities and infinite descent, the Hurwitz integer method offers algebraic elegance through ring-theoretic factorization, providing deeper insight into quadratic forms and composition algebras while avoiding tedious case analysis.[9]Representations
Number of representations
The number of integer solutions to the equation , counting all orders and signs (including zeros), is denoted by . This counts all possible ways to express as a sum of four squares of integers. In the 1830s, Carl Gustav Jacob Jacobi proved an exact formula for in terms of the divisors of . Specifically, if is odd, then ; if is even, then . Equivalently, for all positive integers .[11] This formula arises from the generating function , where is the Jacobi theta function of order 3. As a modular form of weight 2 for the congruence subgroup , expands via the Eisenstein series of that group, yielding the divisor sum after equating coefficients.[11] The function is multiplicative: if , then . Its average order is asymptotic to , reflecting the geometric interpretation as the number of -lattice points inside a 4-dimensional ball of radius . For certain , relates to representations by positive definite quadratic forms, whose counts involve class numbers of quadratic fields in more general settings.[12] Examples include , from the 8 choices of and permutations thereof, and , from the 24 choices of and permutations.Uniqueness
In number theory, the uniqueness of a representation of a natural number as a sum of four squares refers to there being only one way to express where are non-negative integers, considered up to permutation of the summands (i.e., unordered squares, with zeros permitted). Signs are irrelevant since squaring eliminates them, and different orders of the same squares are regarded as identical. This contrasts with the total number of representations , which counts all ordered tuples with signed integers; uniqueness occurs when equals the size of the symmetry group (permutations and signs) for exactly one such non-negative tuple.[13] The positive integers admitting a unique representation in this sense are precisely 1, 3, 5, 7, 11, 15, 23, and all numbers of the form where is an integer and .[13] This classification follows from analyzing the possible forms compatible with the formula for , where smaller values of (such as 8, 24, or 32) correspond to a single symmetry class, while larger values indicate multiple distinct representations.[13] For instance, arises solely from permutations and signs of , with no alternatives. Representative examples include:- , where .
- , where .
- , where .
- , where .
- .
- .
- , where .
- .
- .
Extensions and generalizations
Higher numbers of squares
Lagrange's four-square theorem asserts that every natural number can be expressed as the sum of at most four squares of integers.[14] This result marks the minimal number such that every natural number is a sum of squares, a fact central to Waring's problem for second powers. In this context, the function denotes the smallest number guaranteeing representation for all natural numbers as sums of squares, while indicates that four squares are necessary for infinitely many numbers, despite the set of such exceptions having asymptotic density zero.[15] For fewer than four squares, explicit characterizations exist. A natural number is a sum of one square if and only if it is itself a perfect square.[16] It is a sum of two squares if and only if, in its prime factorization, every prime congruent to 3 modulo 4 appears with even exponent; this is Fermat's theorem on sums of two squares, stated by Pierre de Fermat in 1640 and proved by Leonhard Euler in 1749.[11] For three squares, Legendre's three-square theorem, proved by Adrien-Marie Legendre in 1798, states that a natural number can be written as the sum of three integer squares if and only if it is not of the form for nonnegative integers and .[17] An independent proof was given by Carl Friedrich Gauss in 1801.[15] When considering more than four squares, the representation becomes trivial: any natural number that is a sum of four squares can be padded with zeros to form a sum of squares for any . Thus, remains the tight bound, and no smaller fixed number suffices universally. The broader Hilbert–Waring theorem, proved by David Hilbert in 1909, generalizes this to higher powers by establishing that for every positive integer , there exists a finite such that every natural number is a sum of at most -th powers of nonnegative integers.[15] This existence result, while not constructive, underscores the foundational role of Lagrange's theorem as the case .Representations in other structures
Lagrange's four-square theorem admits natural analogs in other algebraic structures, particularly rings and fields where quadratic forms or norms play a similar role in representations. In the ring of Gaussian integers , the analog is Fermat's theorem on sums of two squares, which characterizes positive integers representable as with precisely when primes congruent to 3 modulo 4 appear to even powers in the prime factorization of . This result arises from the norm for , leveraging the unique factorization domain property of to determine which integers are norms.[18] A quaternionic analog appears in the ring of Hurwitz integers, an order in the quaternion algebra over consisting of elements with or half-integers under certain conditions. The norm of a Hurwitz integer is always a sum of four integer squares, and the surjectivity of the norm map onto the positive integers underpins Lagrange's theorem, showing every positive integer arises as such a norm. In this structure, every element with positive norm corresponds to a representation as a sum of four squares via the norm form.[19] Over the p-adic integers , the local analog holds: every element is a sum of four squares in . This follows from properties of quadratic forms in local fields, where the form represents all elements. The Hasse-Minkowski theorem, a local-global principle for quadratic forms over number fields, then implies that if the form represents an element locally everywhere (including at the real place), it does so globally over ; since it does locally for all positive rationals, every positive rational is a sum of four rational squares. This positive definite case contrasts with indefinite forms, where Hasse-Minkowski applies more broadly but requires fewer variables for universality in some settings.[20] In finite fields with odd, every element is a sum of two squares, hence trivially of four squares, as the map covers half the nonzero elements and pairing allows full coverage via a counting argument on solutions to . In characteristic 2, every element is a square, hence a sum of one (and thus four) square. A broader generalization, known as Siegel's theorem, extends the result to arbitrary number fields: every totally positive element of a number field (positive under all real embeddings) is a sum of four squares in . This Mordell-Lagrange analog highlights the universality of four squares for positive definite quadratic forms in global fields, with proofs relying on class number bounds and Hasse principles. Recent variants, such as extensions allowing squares of negative integers explicitly (equivalent to the original since ), appear in constructive contexts but do not alter the core theorem.[21]Computational methods
Algorithms for decomposition
A straightforward but inefficient approach to finding a four-square decomposition of a positive integer is the naive trial-and-error method. This involves nested loops over integers from 0 to , computing the remainder , and checking if is a perfect square (i.e., if is an integer ). The time complexity is , rendering it suitable only for small .[22] Lagrange's original proof of the theorem admits a constructive interpretation that can be implemented as an algorithm via infinite descent: start with an initial representation modulo some factor of (often using properties of primes congruent to 3 modulo 4), then iteratively reduce the problem size using the Euler four-square identity to combine representations until reaching 1, and back-substitute to obtain the full decomposition. However, this method is highly inefficient in practice, with exponential time in the worst case due to the descent depth and modular searches.[23] More effective strategies leverage partial decompositions, such as first attempting to express (or a multiple thereof) as a sum of two squares using Fermat's theorem on sums of two squares—applicable when all primes congruent to 3 modulo 4 in 's factorization have even exponent—and padding with zeros if successful, or otherwise adjusting via quaternion identities or randomization to handle the remaining terms.[3] The landmark efficient algorithm, developed by Michael O. Rabin and Jeffrey O. Shallit in 1986, is a randomized procedure that computes a four-square representation in expected polynomial time , assuming the Extended Riemann Hypothesis for the optimal variant, or unconditionally in . The method reduces the problem recursively while using probabilistic techniques to find suitable partial sums. The high-level steps are as follows: First, check modulo 4. If , divide by 4 (repeating as needed to reach an odd core ), compute the representation for , and scale the squares by 2 (since ). For odd , determine if it is a sum of two squares by factoring and verifying the prime conditions (using trial division or more advanced factorization); if yes, pad with two zeros. Otherwise, to handle cases like , randomly select integers with such that and even, odd if (or adjust parity accordingly). Set ; with good probability (), will be prime and . Decompose into two squares using a deterministic algorithm based on continued fractions and quadratic residues (solvable in time via Tonelli-Shanks for finding square roots modulo ). The quadruple then satisfies the equation; repeat the randomization (expected trials) if unsuccessful. For composite remainders, apply the Chinese Remainder Theorem after decomposing prime powers. Quadratic non-residues modulo primes in the factorization aid in constructing the two-square decompositions via Legendre symbol checks and probabilistic selection.[24][3] As an illustrative example, consider (odd, , not a sum of two squares). Randomly try (odd), (odd): , so (, prime). Decompose 5 as . Thus, . Alternative trials may yield the equivalent .[24][23] Implementations of these decomposition algorithms, including optimized versions of the Rabin-Shallit method, are available in mathematical software libraries. For instance, SageMath provides the functionfour_squares(n), which returns a tuple of four non-negative integers summing to in squares, using an efficient variant for large inputs.[25] Custom Python implementations can also be developed using libraries like SymPy for factorization and modular arithmetic support.[26]
Efficiency and applications
The computation of a representation of a positive integer as a sum of four squares is efficient, with both randomized and deterministic algorithms achieving polynomial time in . In 1986, Rabin and Shallit developed three randomized algorithms for this task, with expected running times of under the Extended Riemann Hypothesis (ERH), , and unconditionally. These methods rely on probabilistic techniques to find suitable modular representations and combine them using Euler's four-square identity. An improvement came in 2018 from Pollack and Treviño, who presented two randomized algorithms running in expected time, again with one conditional on ERH and the other unconditional; these avoid some of the arithmetic complexity of quaternion-based approaches by leveraging alternative decompositions. Schoof's 1985 algorithm enables deterministic polynomial-time computation of sums of two squares for primes congruent to 1 mod 4, a key subroutine for more advanced methods. However, a full unconditional deterministic polynomial-time algorithm for representing general as a sum of four squares remains an open problem as of 2025, though randomized methods are efficient in practice.[3][27][28] While every natural number can be expressed as a sum of at most four squares by Lagrange's theorem, certain numbers—specifically those of the form for nonnegative integers —require exactly four nonzero squares, as established by the contrapositive of Legendre's three-square theorem. Determining the minimal number of squares needed for a general is feasible in polynomial time, since the maximum is four and checks for one or two squares are straightforward via trial or factorization, while three squares can be verified using quadratic form theory or efficient modular searches. However, for the fixed case of four squares, the above algorithms ensure practical efficiency regardless of whether fewer suffice. Recent advancements, such as the 2022 method by Nakajima using complex continued fractions in the Gaussian integers, maintain arithmetic operations while simplifying computations by avoiding noncommutative structures like quaternions, offering comparable performance to earlier techniques without probabilistic elements.[29][30] Applications of representations as sums of four squares extend beyond pure number theory into computational and applied domains. In number theory software, such as SageMath and Magma, built-in functions likefour_squares compute explicit decompositions efficiently, aiding tasks like verifying quadratic form representations or generating examples for educational purposes; these tools indirectly support factoring algorithms by enabling norm computations in Hurwitz quaternion rings, where a four-square representation of can reveal nontrivial factors via the Brahmagupta–Fibonacci identity generalized to four terms. In coding theory, the theorem underpins constructions of 4-dimensional lattices, such as the lattice, where the Euclidean norm (a sum of four squares) facilitates dense sphere packings for error-correcting codes, improving signal detection in communications by bounding decoding complexity. For computer graphics, the associated Euler's four-square identity—provable using the theorem—enables efficient quaternion multiplications for 3D rotations, preserving vector norms during interpolations and reducing gimbal lock issues in animations, as implemented in rendering engines. In optimization, sums of four squares appear in semidefinite programming relaxations of quadratic forms, where the theorem guarantees integer feasibility for certain Diophantine constraints, aiding resource allocation problems modeled as bounded norm minimizations.[31][32]
Despite these efficiencies, limitations arise for extremely large , where the polylogarithmic time remains practical but requires high-precision arithmetic libraries to handle intermediate values up to ; no widespread GPU accelerations have been reported, as the algorithms' sequential nature and low constant factors suffice for up to cryptographic scales (e.g., 2048 bits). Post-2020 implementations in data structures and algorithms (DSA) contexts, such as dynamic programming variants for counting representations, further integrate the theorem into software engineering curricula for integer partitioning problems.[33]