Sum of squares function
In number theory, the sum of squares function, commonly denoted r_k(n), quantifies the number of ways to express a positive integer n as the sum of k squares of integers, where representations distinguish order, signs, and zeros (i.e., solutions to n = x_1^2 + x_2^2 + \dots + x_k^2 with x_i \in \mathbb{Z}).[1] This function arises in the analytic theory of quadratic forms and plays a central role in understanding Diophantine equations of the form \sum x_i^2 = n.[2] For k = 2, Fermat's theorem on sums of two squares characterizes which n admit representations: an odd prime p can be written as p = a^2 + b^2 with a, b > 0 if and only if p \equiv 1 \pmod{4}, and more generally, n is a sum of two squares precisely when every prime congruent to $3 \pmod{4} in its factorization has even exponent.[1] The value of r_2(n) is then given by the formula r_2(n) = 4(d_1(n) - d_3(n)), where d_1(n) and d_3(n) are the numbers of divisors of n congruent to $1 \pmod{4} and $3 \pmod{4}, respectively; equivalently, for n = 2^c \prod p_i^{a_i} \prod q_j^{b_j} with p_i \equiv 1 \pmod{4} and q_j \equiv 3 \pmod{4}, r_2(n) = 4 \prod (a_i + 1) if all b_j are even, and $0 otherwise.[1] Jacobi extended this to higher k, providing explicit formulas such as r_4(n) = 8 \sum_{d|n, 4 \nmid d} d for odd n, reflecting the multiplicative structure of the function.[2] Lagrange's four-square theorem establishes that every positive integer n satisfies r_4(n) > 0, meaning all naturals are sums of at most four squares, with the theorem proved in 1770.[1] For larger k, r_k(n) grows asymptotically like c_k n^{(k/2)-1}, linking to broader problems in additive number theory such as Waring's problem, where the minimal g(2) = 4 confirms four squares suffice globally.[2] These results underscore the function's connections to modular forms, theta functions, and the distribution of lattice points on spheres.[1]Definition and Basics
Definition
The sum of squares function, commonly denoted r_k(n), quantifies the number of ways a positive integer n can be expressed as the sum of k squares of integers. Specifically, it counts the integer solutions (x_1, x_2, \dots, x_k) \in \mathbb{Z}^k to the Diophantine equation x_1^2 + x_2^2 + \dots + x_k^2 = n, where zeros are permitted, negative integers are distinguished from positives (i.e., (-x_i)^2 = x_i^2 but the tuples are counted separately if signs differ), and the order of the summands matters, so permutations of the x_i yield distinct representations.[3] This convention aligns with the function's role in analytic number theory, where it facilitates the study of quadratic forms and modular functions. For instance, r_2(1) = 4 corresponds to the representations (\pm 1, 0) and (0, \pm 1).[3] The function originates from classical problems in number theory concerning the representability of integers by sums of squares, with foundational analytic expressions derived by C. G. J. Jacobi in 1829 for even values of k up to 8.[4] Jacobi's work in Fundamenta nova theoriae functionum ellipticarum linked r_k(n) to elliptic theta functions, establishing the generating function \sum_{n=0}^\infty r_k(n) q^n = \vartheta_3(q)^k, where \vartheta_3(q) = \sum_{m=-\infty}^\infty q^{m^2} is the Jacobi theta function of the third kind.[3] This theta-series representation underscores the function's deep connections to modular forms and lattice theory, though the basic definition remains independent of these advanced structures. In standard texts, such as Hardy and Wright's An Introduction to the Theory of Numbers, the function is presented with this full counting convention to capture all integral representations without restrictions on primitivity or positivity.[5]Notation and Conventions
The sum of squares function is standardly denoted by r_k(n), where k is a positive integer and n is a positive integer, representing the number of ways to express n as the sum of k squares of integers, that is, the number of solutions in integers x_1, x_2, \dots, x_k \in \mathbb{Z} to the equation x_1^2 + x_2^2 + \dots + x_k^2 = n. [6][3] This notation counts all ordered k-tuples, distinguishing different orders of the summands as distinct representations; it also allows zeros and distinguishes signs, so that, for example, (-x_i)^2 = x_i^2 but the signed tuples are treated separately in the counting.[3][7] For the specific case k=2, the function is often abbreviated as r(n) or r_2(n).[6] An illustrative example is r_2(5) = 8, arising from the ordered pairs (\pm 1, \pm 2) and (\pm 2, \pm 1) with all four sign combinations for each permutation.[3] Similarly, zeros are permitted, as in r_3(4) = 6, which includes representations like (\pm 2, 0, 0) and permutations.[3] While this ordered, signed convention with zeros is the predominant one in analytic number theory, variations appear in some contexts; for instance, the number of representations using only non-negative integers (disregarding order and signs) is sometimes denoted differently, such as \sigma_k(n) or studied via unordered partitions into squares, but these are not standard for r_k(n).[3][1] The generating function for r_k(n) is the k-th power of the Jacobi theta function \theta_3(q) = \sum_{m=-\infty}^{\infty} q^{m^2}, reflecting the inclusion of all integers.[6]Generating Functions
Jacobi Theta Function
The Jacobi theta function, one of the four classical theta functions introduced by Carl Gustav Jacob Jacobi, is defined as \vartheta_3(z \mid \tau) = \sum_{n=-\infty}^{\infty} \exp\left(2\pi i n z + \pi i n^2 \tau\right), where \tau lies in the upper half-plane \mathbb{H} and z \in \mathbb{C}. For the purposes of generating functions in number theory, the nome q = e^{\pi i \tau} is often used, simplifying the form to \vartheta_3(0 \mid \tau) = \sum_{n=-\infty}^{\infty} q^{n^2}, which converges absolutely for \operatorname{Im}(\tau) > 0.[8][9] This function plays a central role as the generating function for the sum of squares function r_k(n), which counts the number of integer solutions to n = x_1^2 + \cdots + x_k^2. Specifically, the k-th power of the theta function yields \vartheta_3(0 \mid \tau)^k = \sum_{n=0}^{\infty} r_k(n) q^n, where the constant term accounts for the representation of 0, and r_k(n) includes representations allowing zeros, signs, and order. This identity arises from the product expansion over independent sums for each square, making \vartheta_3^k the natural generating function for even k in particular, though it holds formally for any k.[3][10][9] The utility of this connection stems from the modular properties of \vartheta_3, which is a modular form of weight $1/2 for the congruence subgroup \Gamma_0(4) with a specific multiplier system. Key transformations include \vartheta_3(\tau + 1) = \vartheta_3(\tau) and \vartheta_3(-1/\tau) = \sqrt{-i\tau} \vartheta_3(\tau), derived via the Poisson summation formula. These properties enable the extraction of explicit formulas for r_k(n) by expanding \vartheta_3^k in terms of Eisenstein series or other basis elements of modular forms spaces, as Jacobi did for k=2,4,6,8 in his 1829 work on elliptic functions. For instance, for k=4, \vartheta_3^4(\tau) equals \frac{1}{\pi^2} \left( 4 G_2(4\tau) - G_2(\tau) \right), leading to Jacobi's formula r_4(n) = 8 \sum_{d \mid n, \, 4 \nmid d} d.[9][10][3] Higher powers \vartheta_3^k for even k remain modular forms of weight k/2, facilitating analytic continuations and identities that reveal arithmetic structure in r_k(n), such as divisor sums or class number relations. This framework, building on Jacobi's foundational contributions, underpins much of the analytic number theory of quadratic forms and has been detailed in standard treatments.[3][10]Properties and Expansions
The generating function for the sum-of-squares function r_k(n) is given by the k-th power of the Jacobi theta function, \theta(\tau)^k = \sum_{n=0}^\infty r_k(n) q^n, where q = e^{\pi i \tau} with \Im(\tau) > 0, and \theta(\tau) = \theta_3(0|\tau) = \sum_{m=-\infty}^\infty q^{m^2}. This function is holomorphic on the upper half-plane \mathbb{H} and serves as a theta series attached to the integer lattice \mathbb{Z}^k. For even k, \theta(\tau)^k is a modular form of weight k/2 on the congruence subgroup \Gamma_0(4) with a specific nebentypus character.[11][12] A fundamental property arises from the Jacobi triple product identity, which provides an infinite product expansion for the theta function: \theta(\tau) = \prod_{m=1}^\infty (1 - q^{2m})(1 + q^{2m-1})^2. Raising this to the k-th power yields the product form for the generating function, \theta(\tau)^k = \left[ \prod_{m=1}^\infty (1 - q^{2m})(1 + q^{2m-1})^2 \right]^k, facilitating connections to partition theory and elliptic functions. This non-vanishing product in \mathbb{H} underscores the theta function's role in analytic number theory, ensuring the generating function has no zeros in the upper half-plane.[11][13] Modular transformation properties are derived from Poisson summation and define the behavior under the action of \mathrm{SL}_2(\mathbb{Z}). Specifically, for the inversion \tau \mapsto -1/\tau, \theta(-1/\tau) = \sqrt{-i\tau} \, \theta(\tau), with \theta(\tau+1) = \theta(\tau), establishing invariance under translation by 1 up to the root of unity factor in the full Jacobi theta. These transformations extend to powers: \theta(\tau)^k transforms with the factor (-i\tau)^{k/2} under inversion, confirming its modular form status for appropriate subgroups. For k=2, this yields Jacobi's identity linking r_2(n) = 4(d_1(n) - d_3(n)), where d_i(n) counts divisors of n congruent to i \pmod{4}, via equating the q-expansion to a twisted Eisenstein series.[11][14][10] For higher even k, such as k=4, the generating function admits an expansion in terms of Eisenstein series of level 4: \theta(\tau)^4 = \frac{1}{\pi^2} \left( 4 G_2(4\tau) - G_2(\tau) \right), where G_2(\tau) is the weight-2 Eisenstein series, leading to Jacobi's four-squares theorem r_4(n) = 8 \sum_{d|n, \, 4 \nmid d} d. Similar Eisenstein expansions hold for k=6,8, expressing \theta(\tau)^k as linear combinations of basis forms in the space of modular forms of weight k/2 on \Gamma_0(4), with dimensions determined by the genus of the modular curve. These identities highlight the arithmetic significance, bounding r_k(n) via Hecke operators and spectral theory.[10][12]Explicit Formulas
For k=2
The explicit formula for the sum of squares function r_2(n), which counts the number of integer solutions to x^2 + y^2 = n (including orders, signs, and zeros), is provided by Jacobi's two-square theorem:r_2(n) = 4 \left( d_1(n) - d_3(n) \right),
where d_i(n) is the number of positive divisors of n congruent to i modulo 4.[3] This identity, originally established by Carl Gustav Jacob Jacobi, quantifies the representations precisely and extends Fermat's earlier result on which primes can be expressed as sums of two squares. The formula arises from the multiplicative structure of the divisor function and the behavior of quadratic residues modulo 4. For a prime p \equiv 3 \pmod{4} raised to an odd power in the prime factorization of n, d_1(n) = d_3(n), yielding r_2(n) = 0; conversely, if all such exponents are even, the difference d_1(n) - d_3(n) equals the product over primes p \equiv 1 \pmod{4} of (e_p + 1), where e_p is the exponent of p, multiplied by 1 for the contribution from powers of 2.[3] Thus, r_2(n) > 0 if and only if every prime congruent to 3 modulo 4 divides n to an even power, aligning with Fermat's sum-of-two-squares theorem. For example, consider n = 5 = 1^2 + 2^2. The divisors are 1 and 5, both \equiv 1 \pmod{4}, so d_1(5) = 2 and d_3(5) = 0, giving r_2(5) = 8 representations: (\pm 1, \pm 2), (\pm 2, \pm 1). For n = [3](/page/3), a prime \equiv 3 \pmod{4}, the divisors 1 and 3 yield d_1(3) = 1 and d_3(3) = 1, so r_2(3) = 0. These cases illustrate how the formula captures both the existence and multiplicity of representations. The theorem has been proved using various methods, including generating functions via the Jacobi theta function \theta_3(q) = \sum_{m=-\infty}^\infty q^{m^2}, where \theta_3(q)^2 = \sum_{n=0}^\infty r_2(n) q^n, and equating coefficients after expansion. Elementary proofs rely on counting lattice points or Gaussian integer factorizations, emphasizing its foundational role in analytic number theory.[3]
For k=3
A natural number n can be expressed as the sum of three squares of integers if and only if it is not of the form $4^a (8b + 7) for nonnegative integers a and b; this is Legendre's three-square theorem, proved using the theory of quadratic forms.90002-5) When such a representation exists, the number r_3(n) of ordered triples (x, y, z) \in \mathbb{Z}^3 satisfying x^2 + y^2 + z^2 = n (counting signs and zeros distinctly) is given by an explicit formula involving Hurwitz class numbers, which generalize ordinary class numbers to account for square factors in the discriminant. The Hurwitz class number H(d) for positive integer d is the weighted sum over equivalence classes of positive definite binary quadratic forms of discriminant -4d, where each class is weighted by the reciprocal of the order of its automorphism group. The formula for r_3(n) is determined recursively with respect to the 2-adic valuation: if $4 \mid n, then r_3(n) = r_3(n/4); otherwise, r_3(n) = 0 if n \equiv 7 \pmod{8}, r_3(n) = 24 H(n) if n \equiv 3 \pmod{8}, and r_3(n) = 12 H(4n) if n \equiv 1, 2, 5, or $6 \pmod{8}. This formula originates from Gauss's investigations into quadratic forms and was refined using the Hurwitz class number in modern treatments. For squarefree n > 4 not of the form $8b + 7, the formula simplifies using ordinary class numbers h(\cdot) of imaginary quadratic fields: r_3(n) = 24 h(-n) if n \equiv 3 \pmod{8}, and r_3(n) = 12 h(-4n) if n \equiv 1, 2, 5, or $6 \pmod{8}, with r_3(n) = 0 if n \equiv 7 \pmod{8}. These expressions connect r_3(n) directly to the arithmetic of quadratic fields, highlighting the deep interplay between sums of squares and algebraic number theory. Examples illustrate the formula's application. For n=1 \equiv 1 \pmod{8}, r_3(1) = 12 H(4) = 12 \times \frac{1}{2} = 6, corresponding to the six permutations of (\pm 1, 0, 0). For n=3 \equiv 3 \pmod{8}, r_3(3) = 24 H(3) = 24 \times \frac{1}{3} = 8, from the eight sign combinations of (1, 1, 1). For n=4 = 4 \times 1, r_3(4) = r_3(1) = 6, from permutations of (\pm 2, 0, 0). For n=7 \equiv 7 \pmod{8}, r_3(7) = 0, consistent with the theorem.For k=4
The sum of squares function for k=4, denoted r_4(n), counts the number of integer solutions (x_1, x_2, x_3, x_4) \in \mathbb{Z}^4 to the equation x_1^2 + x_2^2 + x_3^2 + x_4^2 = n.[10] Jacobi's four-square theorem gives an explicit formula for r_4(n) in terms of the divisors of n.[15] Specifically, r_4(n) = 8 \sum_{\substack{d \mid n \\ 4 \nmid d}} d, where the sum runs over all positive divisors d of n that are not divisible by 4.[15] This general formula admits equivalent expressions depending on the parity of n. When n is odd, all divisors are odd and thus not divisible by 4, so r_4(n) = 8 \sigma(n), where \sigma(n) denotes the sum of the positive divisors of n.[16] When n is even, write n = 2^r m with m odd and r \geq 1; then r_4(n) = 24 \sum_{\substack{d \mid n \\ d \ odd}} d = 24 \sigma(m), where the sum is over the odd positive divisors of n.[16] These forms are equivalent to the general expression, as the condition $4 \nmid d excludes higher powers of 2 in the even case while weighting the odd divisors appropriately.[17] The theorem refines Lagrange's four-square theorem by not only confirming that r_4(n) > 0 for all positive integers n (since \sigma(n) \geq n + 1 > 0), but also quantifying the exact multiplicity of representations.[16] For instance, r_4(1) = 8, corresponding to the eight permutations of (\pm 1, 0, 0, 0).[15] For n=2, r_4(2) = 24, arising from the 24 signed permutations of (\pm 1, \pm 1, 0, 0).[16] Proofs of the theorem typically employ the Jacobi theta function \vartheta(z) = \sum_{k=-\infty}^{\infty} e^{2\pi i k^2 z} and its fourth power, whose Fourier coefficients yield r_4(n), or alternatively use identities like the triple product.[15]For k=6
The explicit formula for r_6(n), the number of integer solutions to x_1^2 + x_2^2 + x_3^2 + x_4^2 + x_5^2 + x_6^2 = n, was established by Jacobi in 1829. It takes the form r_6(n) = 16 \sum_{d \mid n} \chi\left( \frac{n}{d} \right) d^2 - 4 \sum_{d \mid n} \chi(d) d^2, where the sums run over the positive divisors d of n, and \chi is the non-principal Dirichlet character modulo 4, given by \chi(m) = \begin{cases} 0 & \text{if } m \equiv 0 \pmod{2}, \\ 1 & \text{if } m \equiv 1 \pmod{4}, \\ -1 & \text{if } m \equiv 3 \pmod{4}. \end{cases} The formula arises from the coefficient extraction in the expansion of the sixth power of the Jacobi theta function \vartheta_3(q) = \sum_{m=-\infty}^{\infty} q^{m^2}, equated to a linear combination of weighted divisor sums via modular form identities. Analytic proofs rely on the convergence of theta series and Poisson summation, while elementary proofs use bijections between representations and divisor counts, avoiding complex analysis.[18] Since r_6(n) is a multiplicative function, its value for general n = 2^\alpha \prod p_i^{\beta_i} q_j^{\gamma_j} (with odd primes p_i \equiv 1 \pmod{4}, q_j \equiv 3 \pmod{4}) factors into local components computable from the formula applied to each prime power. For instance, r_6(1) = 12, accounting for the six choices of position for \pm 1 and zeros elsewhere; r_6(5) = 312, from the formula applied to divisors 1 and 5 (both \equiv 1 \pmod{4}), corresponding to representations such as permutations of (\pm 2, \pm 1, 0, 0, 0, 0) and (\pm 1, \pm 1, \pm 1, \pm 1, \pm 1, 0). These values illustrate how the character \chi encodes quadratic reciprocity to distinguish residue classes modulo 4. Jacobi's result extends Lagrange's four-square theorem by providing an exact count rather than mere existence, and it has influenced subsequent work on higher even k, though formulas grow more intricate beyond k=8. An accessible arithmetic proof, emphasizing divisor identities without theta functions, appears in the work of Alaca, Alaca, and Williams (2007).[18]For k=8
The explicit formula for r_8(n), the number of integer solutions to x_1^2 + x_2^2 + \dots + x_8^2 = n counting orders and signs, was discovered by Carl Gustav Jacobi in 1829 as part of his work on theta functions and elliptic integrals.[3] This formula expresses r_8(n) directly in terms of the divisors of n, highlighting the arithmetic nature of representations by eight squares. The formula is given by r_8(n) = 16 \sum_{d \mid n} (-1)^{n + d} d^3, where the sum runs over all positive divisors d of n.[19] This identity relies on the generating function \theta_3(q)^8, where \theta_3(q) = \sum_{m=-\infty}^{\infty} q^{m^2} is the Jacobi theta function, and employs modular form techniques to extract the coefficient of q^n.[20] For odd n, all divisors d are odd, making n + d even and (-1)^{n + d} = 1, so the formula simplifies to r_8(n) = 16 \sigma_3(n), with \sigma_3(n) = \sum_{d \mid n} d^3 denoting the sum of cubes of divisors.[19] For example, when n = 1, the sole divisor is 1, yielding \sigma_3(1) = 1 and r_8(1) = 16, corresponding to the 16 choices of position and sign for a single \pm 1 with seven zeros. For even n, the alternating sign introduces cancellations based on the parities of divisors, but the overall value remains positive, ensuring every positive integer can be expressed as a sum of eight squares.[20] Jacobi's derivation connects to the theory of quadratic forms and has implications for the composition of sums of squares, as facilitated by Degen's eight-square identity, which states that the product of two sums of eight squares is again a sum of eight squares. This identity underpins the multiplicative structure observed in the formula for r_8(n). The result extends Jacobi's earlier formulas for k = 2, 4, 6, completing the set of explicit arithmetic expressions for small even k.[19]Numerical Values and Computation
Tables of Small Values
The sum of squares function r_k(n) gives the number of integer solutions to x_1^2 + x_2^2 + \dots + x_k^2 = n, where order matters, signs are distinguished, and zeros are allowed. For small values of n, these can be computed using explicit formulas or theta series expansions. The following tables list r_k(n) for n = 0 to $10 and selected even k, as these admit particularly simple closed-form expressions derived from Jacobi's theorems.[3]For k = 2
The values follow Jacobi's two-square theorem: r_2(n) = 4 (d_1(n) - d_3(n)), where d_i(n) is the number of divisors of n congruent to i \pmod{4}.[3][21]| n | r_2(n) |
|---|---|
| 0 | 1 |
| 1 | 4 |
| 2 | 4 |
| 3 | 0 |
| 4 | 4 |
| 5 | 8 |
| 6 | 0 |
| 7 | 0 |
| 8 | 4 |
| 9 | 4 |
| 10 | 8 |
For k = 4
The values follow Jacobi's four-square theorem: r_4(n) = 8 \sum_{d \mid n, \, 4 \nmid d} d if n is odd, and r_4(n) = 24 \sum_{d \mid n, \, d \odd} d if n is even.[3][22]| n | r_4(n) |
|---|---|
| 0 | 1 |
| 1 | 8 |
| 2 | 24 |
| 3 | 32 |
| 4 | 24 |
| 5 | 48 |
| 6 | 96 |
| 7 | 64 |
| 8 | 24 |
| 9 | 104 |
| 10 | 144 |
For k = 6
The values follow Jacobi's six-square theorem, involving character sums: r_6(n) = 16 \sum_{d \mid n} \chi(d') d^2 - 4 \sum_{d \mid n} \chi(d) d^2, where \chi is the non-principal Dirichlet character modulo 4 and d' = d if d odd, d/4 if d \equiv 0 \pmod{4}.[3][23]| n | r_6(n) |
|---|---|
| 0 | 1 |
| 1 | 12 |
| 2 | 60 |
| 3 | 160 |
| 4 | 252 |
| 5 | 312 |
| 6 | 544 |
| 7 | 960 |
| 8 | 1020 |
| 9 | 876 |
| 10 | 1560 |
For k = 8
The values follow Jacobi's eight-square theorem: r_8(n) = 16 \sum_{d \mid n} (-1)^{n+d} d^3. This simplifies to $16 \sigma_3(n) for odd n, where \sigma_3(n) = \sum_{d \mid n} d^3, and adjusted forms for even n.[3]| n | r_8(n) |
|---|---|
| 0 | 1 |
| 1 | 16 |
| 2 | 112 |
| 3 | 448 |
| 4 | 240 |
| 5 | 960 |
| 6 | 2016 |
| 7 | 1792 |
| 8 | 672 |
| 9 | 3456 |
| 10 | 5376 |