info prev up next book cdrom email home


The number of representations of $n$ by $k$ squares is denoted $r_k(n)$. The Mathematica ${}^{\scriptstyle\circledRsymbol}$ (Wolfram Research, Champaign, IL) function NumberTheory`NumberTheoryFunctions`SumOfSquaresR[k,n] gives $r_k(n)$.

$r_2(n)$ is often simply written $r(n)$. Jacobi solved the problem for $k=2$, 4, 6, and 8. The first cases $k=2$, 4, and 6 were found by equating Coefficients of the Theta Function $\vartheta_3(x)$, ${\vartheta_3}^2(x)$, and ${\vartheta_3}^4(x)$. The solutions for $k=10$ and 12 were found by Liouville and Eisenstein, and Glaisher (1907) gives a table of $r_k(n)$ for $k=2s=18$. $r_3(n)$ was found as a finite sum involving quadratic reciprocity symbols by Dirichlet. $r_5(n)$ and $r_7(n)$ were found by Eisenstein, Smith, and Minkowski.

$r(n)=r_2(n)$ is 0 whenever $n$ has a Prime divisor of the form $4k+3$ to an Odd Power; it doubles upon reaching a new Prime of the form $4k+1$. It is given explicitly by

r(n) = 4\sum_{d=1, 3, \dots \vert n} (-1)^{(d-1)/2} = 4[d_1(n)-d_3(n)],
\end{displaymath} (1)

where $d_k(n)$ is the number of Divisors of $n$ of the form $4m+k$. The first few values are 4, 4, 0, 4, 8, 0, 0, 4, 4, 8, 0, 0, 8, 0, 0, 4, 8, 4, 0, 8, 0, 0, 0, 0, 12, 8, 0, 0, ... (Sloane's A004018). The first few values of the summatory function
R(n)\equiv \sum_{k=1}^n r(n)
\end{displaymath} (2)

are 0, 4, 8, 8, 12, 20, 20, 20, 24, 28, 36, ... (Sloane's A014198). Shanks (1993) defines instead $R'(n)=1+R(n)$, with $R'(0)=1$. A Lambert Series for $r(n)$ is
\sum_{n=1}^\infty {4(-1)^{n+1}x^n\over 1-x^n}=\sum_{n=1}^\infty r(n)x^n
\end{displaymath} (3)

(Hardy and Wright 1979).

\begin{figure}\begin{center}\BoxedEPSF{r2.epsf scaled 600}\end{center}\end{figure}

Asymptotic results include

$\displaystyle \sum_{k=1}^n r_2(k)$ $\textstyle =$ $\displaystyle \pi n+{\mathcal O}(\sqrt{n}\,)$ (4)
$\displaystyle \sum_{k=1}^n {r_2(k)\over k}$ $\textstyle =$ $\displaystyle K+\pi\ln n+{\mathcal O}(n^{-1/2}),$ (5)

where $K$ is a constant known as the Sierpinski Constant. The left plot above shows
\left[{\sum_{k=1}^n r_2(k)}\right]-\pi n,
\end{displaymath} (6)

with $\pm\sqrt{n}$ illustrated by the dashed curve, and the right plot shows
\left[{\sum_{k=1}^n {r_2(k)\over k}}\right]-\pi\ln n,
\end{displaymath} (7)

with the value of $K$ indicated as the solid horizontal line.

The number of solutions of

\end{displaymath} (8)

for a given $n$ without restriction on the signs or relative sizes of $x$, $y$, and $z$ is given by $r_3(n)$. If $n>4$ is Squarefree, then Gauß proved that
24h(-n) & for $n\equiv 3\ \left({{\rm mod\ }...
0 & for $n\equiv 7\ \left({{\rm mod\ } {8}}\right)$\cr}
\end{displaymath} (9)

(Arno 1992), where $h(x)$ is the Class Number of $x$.

Additional higher-order identities are given by

$\displaystyle r_4(n)$ $\textstyle =$ $\displaystyle 8\sum_{d\vert n} d = 8\sigma(n)$ (10)
  $\textstyle =$ $\displaystyle 24 \sum_{d=1, 3, \dots \vert n} d = 24\sigma_0(n)$ (11)
$\displaystyle r_{10}(n)$ $\textstyle =$ $\displaystyle {\textstyle{4\over 5}} [E_4(n)+16 E'_4(n)+8\chi_4(n)]$ (12)
$\displaystyle r_{24}(n)$ $\textstyle =$ $\displaystyle \rho_{24}(n)+ {\textstyle{128\over 691}} [(-1)^{n-1}259\tau(n)-512\tau({\textstyle{1\over 2}}n)],$ (13)

$\displaystyle E_4(n)$ $\textstyle =$ $\displaystyle \sum_{d=1, 3, \dots \vert n} (-1)^{(d-1)/2} d^4$ (14)
$\displaystyle E'_4(n)$ $\textstyle =$ $\displaystyle \sum_{d'=1, 3, \dots \vert n} (-1)^{(d'-1)/2} d^4$ (15)
$\displaystyle \chi_4(n)$ $\textstyle =$ $\displaystyle {\textstyle{1\over 4}}\sum_{a^2+b^2=n} (a+bi)^4,$ (16)

$d'\equiv {n/d}$, $d_k(n)$ is the number of divisors of $n$ of the form $4m+k$, $\rho_{24}(n)$ is a Singular Series, $\sigma(n)$ is the Divisor Function, $\sigma_0(n)$ is the Divisor Function of order 0 (i.e., the number of Divisors), and $\tau$ is the Tau Function.

Similar expressions exist for larger Even $k$, but they quickly become extremely complicated and can be written simply only in terms of expansions of modular functions.

See also Class Number, Landau-Ramanujan Constant, Prime Factors, Sierpinski Constant, Tau Function


Arno, S. ``The Imaginary Quadratic Fields of Class Number 4.'' Acta Arith. 60, 321-334, 1992.

Boulyguine. Comptes Rendus Paris 161, 28-30, 1915.

New York: Chelsea, p. 317, 1952.

Glaisher, J. W. L. ``On the Numbers of a Representation of a Number as a Sum of $2r$ Squares, where $2r$ Does Not Exceed 18.'' Proc. London Math. Soc. 5, 479-490, 1907.

Grosswald, E. Representations of Integers as Sums of Squares. New York: Springer-Verlag, 1985.

Hardy, G. H. ``The Representation of Numbers as Sums of Squares.'' Ch. 9 in Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work, 3rd ed. New York: Chelsea, 1959.

Hardy, G. H. and Wright, E. M. ``The Function $r(n)$,'' ``Proof of the Formula for $r(n)$,'' ``The Generating Function of $r(n)$,'' and ``The Order of $r(n)$.'' §16.9, 16.10, 17.9, and 18.7 in An Introduction to the Theory of Numbers, 5th ed. Oxford, England: Clarendon Press, pp. 241-243, 256-258, and 270-271, 1979.

Shanks, D. Solved and Unsolved Problems in Number Theory, 4th ed. New York: Chelsea, pp. 162-153, 1993.

Sloane, N. J. A. Sequences A014198 and A004018/M3218 in ``An On-Line Version of the Encyclopedia of Integer Sequences.'' and Sloane, N. J. A. and Plouffe, S. The Encyclopedia of Integer Sequences. San Diego: Academic Press, 1995.

info prev up next book cdrom email home

© 1996-9 Eric W. Weisstein