Fact-checked by Grok 2 weeks ago

Lagrange's four-square theorem

Lagrange's four-square theorem asserts that every can be represented as the sum of four squares of integers. Formally, for any positive integer n, there exist integers a, b, c, d such that n = a^2 + b^2 + c^2 + d^2. This result, a cornerstone of , was first proved by the mathematician . The theorem originated from earlier conjectures in Diophantine problems, notably Bachet's 1621 claim that every number is a sum of at most four squares, which Fermat claimed to have proved using his method of infinite descent, though no proof was published. Euler extended this by establishing an identity showing that the product of two sums of four squares is itself a sum of four squares, facilitating multiplicative properties. Lagrange submitted his complete proof to the Berlin Academy in 1770, with publication following in 1772; his approach combined Euler's identity with a descent argument and analysis of quadratic residues modulo primes to handle prime cases before extending to all naturals. Beyond its statement, the theorem has profound implications in quadratic forms and , influencing later results like for the number of representations and connections to quaternions via Hurwitz integers. It exemplifies the power of identities in and remains a benchmark for algorithms finding such representations, with applications in .

Statement and background

The theorem

Lagrange's four-square theorem states that every non-negative n can be expressed as the of four squares of , that is, there exist a, b, c, d such that n = a^2 + b^2 + c^2 + d^2. This representation holds for n = 0 as well, with $0 = 0^2 + 0^2 + 0^2 + 0^2, and the a, b, c, d may be positive, negative, or zero; however, since squaring eliminates the sign, it is equivalent to using non-negative . The theorem provides a complete to the x_1^2 + x_2^2 + x_3^2 + x_4^2 = n in for any non-negative n, affirming that such equations always possess integer solutions. A direct is that every can be written as the sum of four squares, as primes are a subset of the non-negative integers.

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 , 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, of , in his , 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 can be expressed as a sum of four squares, though without a formal proof. 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. 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. Leonhard Euler took up the challenge in the mid-18th century, motivated by exchanges with 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 4) and employing continued fractions alongside 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. 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.

Proofs

Classical proof by Lagrange

Lagrange's proof reduces the problem to showing that every is a of four 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 of four squares: (a^2 + b^2 + c^2 + d^2)(e^2 + f^2 + g^2 + h^2) = (ae - bf - cg - dh)^2 + (af + be + ch - dg)^2 + (ag - bh + ce + df)^2 + (ah + bg - cf + de)^2. The identity can be verified by direct expansion and was established by Euler in 1748. Since every 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.[](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 2 = 1^2 + 1^2 + ^2 + ^2. Higher powers of 2 follow immediately from the : for example, 4 = 2 \cdot 2 yields a representation by substituting the values for 2 into the identity, and extends this to 2^k for any k \geq 1. A handles even cases more generally: if n is even and a sum of four squares, then n/2 is also a sum of four squares by pairing terms according to and applying algebraic identities for halves.[](Lagrange, 1772) For an odd prime p, the argument proceeds by infinite descent. First, establish that there exists a positive m with 0 < m < p 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 u^2 + v^2 \equiv -1 \pmod{p}. Setting a = u, b = v, c = 1, d = 0 then gives a^2 + b^2 + c^2 + d^2 \equiv 0 \pmod{p}, with the representation nontrivial modulo p. The existence of such u and v follows from a pigeonhole principle argument establishing solutions to u^2 + v^2 + 1 \equiv 0 \pmod{p}. Choosing representatives u, v between 0 and p-1 ensures the sum s = u^2 + v^2 + 1^2 + 0^2 satisfies 0 < s < 2p^2 + 1, so s = mp with 1 \leq m < 2p + 1/p, and m not divisible by p since the representation is nontrivial modulo p. Refinements using smaller representatives or additional pigeonhole applications can bound m < p/2, but the descent handles larger initial m.[](Lagrange, 1772) Now suppose m is the smallest positive integer such that mp = x_1^2 + x_2^2 + x_3^2 + x_4^2 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 |b_i| \leq m/2 such that x_i \equiv b_i \pmod{m} for each i (choosing the signed representative closest to zero). Then \sum b_i^2 \equiv \sum x_i^2 \equiv 0 \pmod{m}, so \sum b_i^2 = rm for some integer r with 0 \leq r \leq 4(m/2)^2 / m = m. If r = 0, then all b_i = 0, so all x_i \equiv 0 \pmod{m}, 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).[](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 z_k \equiv 0 \pmod{m} for each k, so \sum z_k^2 = (mp)(rm) = r m^2 p is divisible by m^2, yielding integers y_k = z_k / m such that \sum y_k^2 = r p. 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.[](Lagrange, 1772)

Algebraic proof using Hurwitz integers

The Hurwitz integers form a subring of the Lipschitz quaternions, consisting of all quaternions of the form q = a + bi + cj + dk, where a, b, c, d are either all integers or all half-integers (i.e., integers plus \frac{1}{2}). This ring, denoted \mathbb{H}, 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 q \in \mathbb{H} is defined as N(q) = a^2 + b^2 + c^2 + d^2, which is a non-negative integer and multiplicative: N(q_1 q_2) = N(q_1) N(q_2). A fundamental property of \mathbb{H} is that it is a Euclidean domain with respect to the norm, meaning for any nonzero \alpha, \beta \in \mathbb{H}, there exist \mu, \rho \in \mathbb{H} such that \alpha = \mu \beta + \rho with N(\rho) < N(\beta). Consequently, \mathbb{H} is a (PID) and a (UFD), allowing every nonzero element to factor uniquely into primes up to units. The units of \mathbb{H} are the 24 elements with norm 1: the 8 integer units \pm 1, \pm i, \pm j, \pm k, and the 16 half-integer units of the form \pm \frac{1}{2} \pm \frac{1}{2} i \pm \frac{1}{2} j \pm \frac{1}{2} k (all sign combinations). The proof that every natural number n is a sum of four squares proceeds by showing that n = N(q) for some q \in \mathbb{H}, leveraging the multiplicative norm and unique factorization. Since \mathbb{H} is a PID, the principal ideal generated by a rational prime p factors as (p) = (\pi_1) \cdots (\pi_r) for prime elements \pi_i, and taking norms yields p^2 = N(p) = \prod N(\pi_i). Thus, each N(\pi_i) = p (up to units of norm 1), so p = N(\pi) for some \pi \in \mathbb{H}. For composite n, factor n in \mathbb{Z} and use multiplicativity: if n = p_1^{e_1} \cdots p_k^{e_k}, then n = N(q) where q is a product of elements with norms p_i^{e_i}. Base cases confirm this for 1 (N(1) = 1) and primes. To establish that every rational prime p has norm p in \mathbb{H}, classify the primes as follows: the prime 2 is ramified, since $2 = -i (1 + i)^2 (up to units), and N(1 + i) = 2. For odd primes, all split: no odd prime remains inert (i.e., prime) in \mathbb{H}. Primes congruent to 1 modulo 4 factor as p = N(\alpha) for some Gaussian integer \alpha = a + bi extended by units to a Hurwitz integer, yielding p = a^2 + b^2 + 0^2 + 0^2. For primes congruent to 3 modulo 4, there exist integers l and m such that 1 + l^2 + m^2 \equiv 0 \pmod{p} (provable using the pigeonhole principle on the (p+1)/2 quadratic residues to show -1 is a sum of two squares modulo p). Thus, p divides N(1 + l i + m j). However, p does not divide 1 + l i + m j (as its norm is p), so p is not prime in \mathbb{H} and factors into elements of norm p. 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 N(q_1 q_2) = N(q_1) N(q_2). 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.

Representations

Number of representations

The number of integer solutions (a, b, c, d) \in \mathbb{Z}^4 to the equation a^2 + b^2 + c^2 + d^2 = n, counting all orders and signs (including zeros), is denoted by r_4(n). This counts all possible ways to express n as a sum of four squares of integers. In the 1830s, Carl Gustav Jacob Jacobi proved an exact formula for r_4(n) in terms of the divisors of n. Specifically, if n is odd, then r_4(n) = 8 \sum_{d \mid n} d; if n is even, then r_4(n) = 24 \sum_{\substack{d \mid n \\ d \ odd}} d. Equivalently, r_4(n) = 8 \sum_{\substack{d \mid n \\ 4 \nmid d}} d for all positive integers n. This formula arises from the generating function \sum_{n=0}^\infty r_4(n) q^n = \theta_3(q)^4, where \theta_3(q) = \sum_{k=-\infty}^\infty q^{k^2} is the of order 3. As a modular form of weight 2 for the congruence subgroup \Gamma_0(4), \theta_3(q)^4 expands via the of that group, yielding the divisor sum after equating coefficients. The function r_4(n) is multiplicative: if \gcd(m,n)=1, then r_4(mn) = r_4(m) r_4(n). Its average order is asymptotic to \frac{\pi^2}{2} n, reflecting the geometric interpretation as the number of \mathbb{Z}^4-lattice points inside a 4-dimensional ball of radius \sqrt{n}. For certain n, r_4(n) relates to representations by positive definite quadratic forms, whose counts involve class numbers of quadratic fields in more general settings. Examples include r_4(1) = 8, from the 8 choices of (\pm 1, 0, 0, 0) and permutations thereof, and r_4(2) = 24, from the 24 choices of (\pm 1, \pm 1, 0, 0) and permutations.

Uniqueness

In number theory, the uniqueness of a representation of a natural number n as a sum of four squares refers to there being only one way to express n = a^2 + b^2 + c^2 + d^2 where a, b, c, d 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 r_4(n), which counts all ordered tuples with signed integers; uniqueness occurs when r_4(n) equals the size of the symmetry group (permutations and signs) for exactly one such non-negative tuple. The positive integers n admitting a unique representation in this sense are precisely 1, 3, 5, 7, 11, 15, 23, and all numbers of the form $2^{2k+1} m where k \geq 0 is an integer and m \in \{1, 3, 7\}. This classification follows from analyzing the possible forms compatible with the formula for r_4(n), where smaller values of r_4(n) (such as 8, 24, or 32) correspond to a single symmetry class, while larger values indicate multiple distinct representations. For instance, r_4(1) = 8 arises solely from permutations and signs of (1, 0, 0, 0), with no alternatives. Representative examples include:
  • n = 1 = 1^2 + 0^2 + 0^2 + 0^2, where r_4(1) = 8.
  • n = 2 = 2^{1} \cdot 1 = 1^2 + 1^2 + 0^2 + 0^2, where r_4(2) = 24.
  • n = 3 = 1^2 + 1^2 + 1^2 + 0^2, where r_4(3) = 32.
  • n = 5 = 2^2 + 1^2 + 0^2 + 0^2, where r_4(5) = 48.
  • n = 6 = 2^{1} \cdot 3 = 2^2 + 1^2 + 1^2 + 0^2.
  • n = 7 = 2^2 + 1^2 + 1^2 + 1^2.
  • n = 8 = 2^{3} \cdot 1 = 2^2 + 2^2 + 0^2 + 0^2, where r_4(8) = 24.
  • n = 14 = 2^{1} \cdot 7 = 3^2 + 2^2 + 1^2 + 0^2.
  • n = 23 = 3^2 + 3^2 + 2^2 + 1^2.
For prime numbers p \equiv 3 \pmod{4}, uniqueness holds only for the specific cases 3, 7, 11, and 23, as these align with the listed forms and yield r_4(p) matching a single representation class (often involving three or four nonzero squares, per , which excludes sums of three squares for numbers of form $4^k(8m+7)). Larger such primes, like 19 or 31, admit multiple representations; for example, $19 = 4^2 + 1^2 + 1^2 + 1^2 = 3^2 + 3^2 + 1^2 + 0^2. In general, uniqueness is rare and tied to n having few divisors, ensuring no overlapping symmetry classes from distinct tuples.

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. This result marks the minimal number k=4 such that every natural number is a sum of k squares, a fact central to for second powers. In this context, the function g(2)=4 denotes the smallest number guaranteeing representation for all natural numbers as sums of g(2) squares, while G(2)=4 indicates that four squares are necessary for infinitely many numbers, despite the set of such exceptions having asymptotic density zero. 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. 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. For three squares, Legendre's three-square theorem, proved by Adrien-Marie Legendre in 1798, states that a natural number n can be written as the sum of three integer squares if and only if it is not of the form $4^a(8b + 7) for nonnegative integers a and b. An independent proof was given by Carl Friedrich Gauss in 1801. 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 k squares for any k > 4. Thus, g(2) = 4 remains the tight bound, and no smaller fixed number suffices universally. The broader , proved by in , generalizes this to higher powers by establishing that for every positive integer m \geq 2, there exists a finite g(m) such that every is a sum of at most g(m) m-th powers of nonnegative integers. This existence result, while not constructive, underscores the foundational role of as the case m=2.

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 \mathbb{Z}, the analog is on sums of two squares, which characterizes positive integers representable as n = a^2 + b^2 with a, b \in \mathbb{Z} precisely when primes congruent to 3 modulo 4 appear to even powers in the prime factorization of n. This result arises from the norm N(\alpha) = a^2 + b^2 for \alpha = a + bi \in \mathbb{Z}, leveraging the unique factorization domain property of \mathbb{Z} to determine which integers are norms. A quaternionic analog appears in the ring of Hurwitz integers, an in the algebra over \mathbb{Q} consisting of elements a + bi + cj + dk with a, b, c, d \in \mathbb{Z} or half-integers under certain conditions. The N(\gamma) = a^2 + b^2 + c^2 + d^2 of a Hurwitz integer \gamma is always a sum of four squares, and the surjectivity of the norm map onto the positive integers underpins , showing every positive arises as such a norm. In this structure, every element with positive norm corresponds to a as a sum of four squares via the norm form. Over the p-adic integers \mathbb{Z}_p, the local analog holds: every element is a sum of four squares in \mathbb{Q}_p. This follows from properties of quadratic forms in local fields, where the form x_1^2 + x_2^2 + x_3^2 + x_4^2 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 place), it does so globally over \mathbb{Q}; 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. In finite fields \mathbb{F}_q with q odd, every element is a sum of two squares, hence trivially of four squares, as the map x \mapsto x^2 covers half the nonzero elements and pairing allows full coverage via a counting argument on solutions to a^2 + b^2 = c. 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 K (positive under all real embeddings) is a sum of four squares in K. 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 (-a)^2 = a^2), appear in constructive contexts but do not alter the core theorem.

Computational methods

Algorithms for decomposition

A straightforward but inefficient approach to finding a four-square decomposition of a positive n is the naive trial-and-error method. This involves nested loops over a, b, c from 0 to \lfloor \sqrt{n} \rfloor, computing the r = n - a^2 - b^2 - c^2, and checking if r is a (i.e., if \sqrt{r} is an d \geq 0). The is O(n^{3/2}), rendering it suitable only for small n. Lagrange's original proof of the theorem admits a constructive that can be implemented as an via infinite descent: start with an initial representation some factor of n (often using properties of primes congruent to 3 4), then iteratively reduce the problem size using the Euler four-square 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. More effective strategies leverage partial decompositions, such as first attempting to express n (or a multiple thereof) as a sum of two squares using on sums of two squares—applicable when all primes congruent to 3 modulo 4 in n's have even exponent—and padding with zeros if successful, or otherwise adjusting via identities or to handle the remaining terms. The landmark efficient , developed by and Jeffrey O. Shallit in , is a randomized procedure that computes a four-square representation in expected polynomial time O((\log n)^2), assuming the Extended for the optimal variant, or unconditionally in O((\log n)^2 \log \log n). The method reduces the problem recursively while using probabilistic techniques to find suitable partial sums. The high-level steps are as follows: First, check n modulo 4. If n \equiv 0 \pmod{4}, divide by 4 (repeating as needed to reach an odd core m = n / 4^k), compute the representation for m, and scale the squares by 2 (since (2a)^2 + (2b)^2 + (2c)^2 + (2d)^2 = 4(a^2 + b^2 + c^2 + d^2)). For odd n, determine if it is a sum of two squares by factoring n and verifying the prime conditions (using trial division or more advanced factorization); if yes, pad with two zeros. Otherwise, to handle cases like n \equiv 3 \pmod{4}, randomly select integers x, y with $0 \leq x, y \leq \sqrt{n} such that x^2 + y^2 < n and x even, y odd if n \equiv 2 \pmod{4} (or adjust parity accordingly). Set p = n - x^2 - y^2; with good probability (\sim 1 / \log n), p will be prime and \equiv 1 \pmod{4}. Decompose p into two squares z^2 + w^2 using a deterministic algorithm based on continued fractions and quadratic residues (solvable in O((\log p)^2) time via Tonelli-Shanks for finding square roots modulo p). The quadruple (x, y, z, w) then satisfies the equation; repeat the randomization (expected O(\log \log n) 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. As an illustrative example, consider n = 7 (odd, \equiv 3 \pmod{4}, not a sum of two squares). Randomly try x = 1 (odd), y = 1 (odd): $1^2 + 1^2 = 2, so p = 7 - 2 = 5 (\equiv 1 \pmod{4}, prime). Decompose 5 as $1^2 + 2^2. Thus, $7 = 1^2 + 1^2 + 1^2 + 2^2. Alternative trials may yield the equivalent $2^2 + 1^2 + 1^2 + 1^2. Implementations of these decomposition algorithms, including optimized versions of the Rabin-Shallit , are available in mathematical software libraries. For instance, provides the function four_squares(n), which returns a of four non-negative integers summing to n in squares, using an efficient variant for large inputs. Custom implementations can also be developed using libraries like for and support.

Efficiency and applications

The computation of a representation of a positive integer n as a sum of four squares is efficient, with both randomized and deterministic algorithms achieving polynomial time in \log n. In 1986, Rabin and Shallit developed three randomized algorithms for this task, with expected running times of O((\log n)^2) under the Extended Riemann Hypothesis (ERH), O((\log n)^2 \log \log n), and O((\log n)^2 (\log \log n)^2) 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 O((\log n)^2 (\log \log n)^{-1}) 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 n as a sum of four squares remains an open problem as of 2025, though randomized methods are efficient in practice. While every natural number n can be expressed as a sum of at most four squares by , certain numbers—specifically those of the form $4^k(8m + 7) for nonnegative integers k, m—require exactly four nonzero squares, as established by the contrapositive of . Determining the minimal number of squares needed for a general n is feasible in polynomial time, since the maximum is four and checks for one or two squares are straightforward via trial or , while three squares can be verified using 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 O(\log n) arithmetic operations while simplifying computations by avoiding noncommutative structures like quaternions, offering comparable performance to earlier techniques without probabilistic elements. Applications of representations as sums of four squares extend beyond pure into computational and applied domains. In number theory software, such as and , built-in functions like four_squares compute explicit decompositions efficiently, aiding tasks like verifying representations or generating examples for educational purposes; these tools indirectly support factoring algorithms by enabling norm computations in rings, where a four-square representation of n can reveal nontrivial factors via the generalized to four terms. In , the theorem underpins constructions of 4-dimensional s, such as the D_4 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 , the associated Euler's four-square identity—provable using the theorem—enables efficient multiplications for rotations, preserving vector norms during interpolations and reducing issues in animations, as implemented in rendering engines. In optimization, sums of four squares appear in relaxations of s, where the theorem guarantees integer feasibility for certain Diophantine constraints, aiding problems modeled as bounded norm minimizations. Despite these efficiencies, limitations arise for extremely large n, where the polylogarithmic time remains practical but requires high-precision arithmetic libraries to handle intermediate values up to O(n); no widespread GPU accelerations have been reported, as the algorithms' sequential nature and low constant factors suffice for n 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 curricula for integer partitioning problems.

References

  1. [1]
    [PDF] Math 153: The Four Square Theorem
    Apr 12, 2014 · The purpose of these notes is to explain Lagrange's famous 4 square theorem. Every positive integer n can be written as the sum of 4 integer.
  2. [2]
    [PDF] Quarternions and the four square theorem - UChicago Math
    The Four Square Theorem was proved by Lagrange in 1770: ev- ery positive integer is the sum of at most four squares of positive integers, i.e. n = A2 + B2 + C2 ...
  3. [3]
    [PDF] Finding the four squares in Lagrange's Theorem - Lake Forest College
    So we see that these ideas lead immediately to a quick proof of Lagrange's theorem (but one that assumes the theorem of Dirichlet, proved nearly 70 years later) ...
  4. [4]
    [PDF] Lagrange's four square theorem via convex geometry - UCSD Math
    Feb 10, 2009 · If each of m and n can be written as a sum of four squares, then so can mn. Proof. The fancy way to say this is that a2. 1 + a2. 2 + a2. 3 + a2.Missing: statement primary
  5. [5]
    [PDF] Lagrange's Four Square Theorem
    LAGRANGE'S FOUR SQUARE THEOREM. Euler's four squares identity. For any numbers a, b, c, d, w, x, y, z. (a2 + b2 + c2 + d2)(w2 + x2 + y2 + z2)=(aw − bx − cy ...
  6. [6]
    Diophantus (200 - 284) - Biography - MacTutor History of Mathematics
    Diophantus also appears to know that every number can be written as the sum of four squares. If indeed he did know this result it would be truly remarkable for ...
  7. [7]
    Lagrange and the four-square theorem | Lettera Matematica
    May 22, 2014 · In this article we will first provide an overview of Lagrange's arithmetic work, written between 1768 and 1777. We then focus on the proof of the four-square ...
  8. [8]
    Pierre Fermat - Biography
    ### Summary of Fermat and Four-Square Theorem
  9. [9]
    Leonhard Euler - Biography
    ### Summary of Euler's Work on Sums of Four Squares
  10. [10]
    Joseph-Louis Lagrange (1736 - 1813) - Biography - MacTutor
    He also worked on number theory proving in 1770 that every positive integer is the sum of four squares. In 1771 he proved Wilson's theorem (first stated ...Missing: title | Show results with:title<|control11|><|separator|>
  11. [11]
    Hurwitz's Lectures on the Number Theory of Quaternions - EMS Press
    May 4, 2023 · Hurwitz's Lectures on the Number Theory of Quaternions, by Nicola Oswald, Jörn Steuding ... Buy from $68.00Download PDF. Quaternions are ...
  12. [12]
    [PDF] Lagrange's Four-Square Theorem with Quaternions
    This handout is an attempt to explain the proof of Lagrange's Four-Square Theorem using quater- nions. Theorem 1.1 (Lagrange's Four-Square Theorem). Every ...
  13. [13]
    Sum of Squares Function -- from Wolfram MathWorld
    The sum of squares function counts the number of ways to represent a number as a sum of k squares, allowing zeros and distinguishing signs and order.<|control11|><|separator|>
  14. [14]
    Asymptotic formula for sums of four squares? - MathOverflow
    Apr 12, 2017 · The function you are asking for is r4(n), the number of ways to write n as a sum of four squares. The exact formula was discovered by Jacobi ...Asymptotic analysis of a peculiar sum of squares sequenceEuler and the Four-Squares Theorem - MathOverflowMore results from mathoverflow.netMissing: average | Show results with:average
  15. [15]
    Representations of Integers as Sums of Squares - SpringerLink
    Book Title: Representations of Integers as Sums of Squares · Authors: Emil Grosswald · Publisher: Springer New York, NY · eBook Packages: Springer Book Archive.
  16. [16]
    Lagrange's Four-Square Theorem -- from Wolfram MathWorld
    The first published proof was given by Lagrange in 1770 and made use of the Euler four-square identity. Lagrange proved that g(2)=4 , where 4 may be reduced to ...Missing: original statement
  17. [17]
    Waring's Problem -- from Wolfram MathWorld
    In Lagrange's four-square theorem, Lagrange proved that g(2)=4 , where 4 may be reduced to 3 except for numbers of the form 4^n(8k+7) (as proved by Legendre ...
  18. [18]
    Square Number -- from Wolfram MathWorld
    A square number, also called a perfect square, is a figurate number of the form S_n=n^2, where n is an integer. The square numbers for n=0, 1, ... are 0, 1, ...
  19. [19]
    Fermat's Polygonal Number Theorem -- from Wolfram MathWorld
    In 1638, Fermat proposed that every positive integer is a sum of at most three triangular numbers, four square numbers, five pentagonal numbers, and n n-
  20. [20]
    [PDF] the representation of a number by two or four squares
    Theorem 3.7 (Lagrange's four square theorem). Every natural number is the sum of four squares. Proof. As demonstrated, it remains to prove the theorem for any ...
  21. [21]
    [PDF] Sum of four squares via the Hurwitz quaternions
    Sep 21, 2016 · Every positive integer is a sum of four squares. Proof. First note that 1 and 2 are both sums of four squares, so that we are left to show that.
  22. [22]
    [PDF] The Local-Global Principle in Number Theory
    We can now effortlessly derive Lagrange's result . Theorem 3.4 (Lagrange's Four Square Theorem). Any positive integer n is a sum of squares of four integers.
  23. [23]
    A p‐adic analogue of Siegel's theorem on sums of squares
    Jun 8, 2020 · Siegel proved that every totally positive element of a number field K is the sum of four squares, so in particular the Pythagoras number is ...
  24. [24]
    Efficient method to write number as a sum of four squares?
    Jan 9, 2017 · One of their methods for n=4k+2 is as follows: Randomly select an even number a and an odd number b such that a2+b2<n.<|control11|><|separator|>
  25. [25]
    Every positive integer is a sum of four integer squares - Alpertron
    Jun 9, 2024 · We give here a proof that has the added advantage not only of being constructive, but actually quite easily implemented as an algorithm. It ...
  26. [26]
    [PDF] The four squares problem and its application in operator ...
    Dec 1, 2020 · I will first walk through an algorithm of Rabin and Shallit [2, 1] that efficiently solves the four-square Diophantine equation.Missing: sum | Show results with:sum
  27. [27]
  28. [28]
    Lagrange - Peter Schorn
    In 1770 Lagrange has shown that any natural number can be written as a sum of at most four squares, a conjecture dating back to the days of Diophantus.
  29. [29]
  30. [30]
    [PDF] a25 integers 24 (2024) finding sums of four squares via complex ...
    Mar 15, 2024 · Abstract. The problem of representing a given positive integer as a sum of four squares of integers has been widely studied for a long time.
  31. [31]
    [PDF] Finding Sums of Four Squares via Complex Continued Fractions
    May 2, 2022 · The theorem holds for all odd positive integers that are not perfect squares, but we only have deterministic polynomial algorithm for finding ...
  32. [32]
    Fast decomposition of small integers into sums of squares
    Implement fast version of decomposition of (small) integers into sum of squares by direct method not relying on factorisation.
  33. [33]
    [PDF] Solving Problems with Magma
    2.3.2 Example: Sums of Squares. For each integer n in the range 1020 ≤ n ≤ 1020 + 100, we determine whether n can be written as the sum of two perfect squares.
  34. [34]
    Lagrange's four square theorem - GeeksforGeeks
    Jul 11, 2025 · Lagrange's Four Square Theorem states that every natural number can be written as sum of squares of four non negative integers.