26
$\begingroup$

It's a standard theorem that the number of ways to write a positive integer N as the sum of two squares is given by four times the difference between its number of divisors which are congruent to 1 mod 4 and its number of divisors which are congruent to 3 mod 4. Alternatively, there are no such representations if the prime factorization of N contains any prime of form 4k+3 an odd number of times. If the prime factorization of N contains all such primes an even number of times, then we have

$$r_2(N) = 4(b_1+1)(b_2+1) \cdots (b_r+1)$$

where $b_1, \ldots, b_r$ are the exponents of the primes congruent to 1 mod 4 in the factorization of $N$.

For example, $325 = 5^2 \times 13$ can be written in $4(2+1)(1+1) = 24$ ways as a sum of squares. These are $18^2 + 1^2, 17^2 + 6^2, 15^2 + 10^2$, and the representations obtained from these by changing signs and/or permuting.

Is there an analogous formula in the three-square case? I know that an integer can be written as the sum of three squares if and only if it is not of the form $4^m (8n+7)$. There is a simple argument that shows that the number of ways to write all integers up to N as a sum of three squares is asymptotically $4\pi N^{3/2}/3$ -- representations of an integer less than $N$ as a sum of three squares can be identified with points in the ball in $\mathbb{R}^3$ centered at the origin with radius $N^{1/2}$. Differentiating, a "typical" integer near N should have about $2\pi N^{1/2}$ representations as a sum of three squares. From playing around with some data it looks like

$$\lim_{n \to \infty} {|\{k \le n, r_3(k)/k^{1/2} \le x \}| \over n}$$

might be a nonzero constant. That is, for each positive real $x$, the probability that a random integer $k$ can be written in no more than $x k^{1/2}$ ways approaches some constant in the open interval $(0, 1)$ as $k \to \infty$.

One way to prove this (if it is in fact true) would be if there were some formula for $r_3(k)$, in terms of the prime factorization, which is why I'm curious.

(I apologize if this is something that is well-known to number theorists, although I'd appreciate a pointer if it is. I am not a number theorist, I just play around with this sort of thing every so often and generate amusing conjectures.)

$\endgroup$
6
  • $\begingroup$ The Mathworld article has one: mathworld.wolfram.com/SumofSquaresFunction.html $\endgroup$ Commented Oct 31, 2009 at 20:57
  • $\begingroup$ In addition to the formula (which is not very explicit) there is a reference before equation (15) to a different representation. $\endgroup$ Commented Oct 31, 2009 at 21:01
  • $\begingroup$ The mean square of r_3(k)/k^(1/2) is known, in the following sense (arXiv math/0502007v2): r_3(1)^2 + ... + r_3(n)^2 ~ 8 pi^4/(21 zeta(3)) * n^2. Differentiating, r_3(n)^2 itself is typically around (16 pi^4/(21 zeta(3))) n, or ~61.74n. But r_3(1)+...+r_3(n) ~ 4Pi/3*n^(3/2), so r_3(n) is typically near 2Pi*n^(1/2). The mean of the square is thus 4Pi^2 * n, less than the square of the mean, suggesting strongly that the distribution is nontrivial. $\endgroup$ Commented Nov 1, 2009 at 18:29
  • $\begingroup$ I believe that even the criterion for whether there's at least one way to write a number as the sum of three squares does not have an easy description, so the answer must be no. $\endgroup$ Commented Apr 27, 2010 at 9:56
  • 2
    $\begingroup$ @Zsbán Ambrus: Michael Lugo was correct in saying "an integer can be written as the sum of three squares if and only if it is not of the form $4^m(8n+7)$." See : Dickson_Diagonal_1939.pdf on my site zakuski.math.utsa.edu/~kap/forms.html $\endgroup$
    – Will Jagy
    Commented May 2, 2010 at 1:10

5 Answers 5

81
$\begingroup$

I just can't stop myself from putting up the following, from the MOTD on the Berkeley server:

Oct  2: Warning: Due to a known bug, the default Linux document viewer
        evince prints N*N copies of a PDF file when N copies requested.
        As a workaround, use Adobe Reader acroread for printing multiple
        copies of PDF documents, or use the fact that every natural number
        is a sum of at most four squares.
$\endgroup$
1
  • $\begingroup$ It's been ten years since I upvoted and forgot this; it would be nice to be able to upvote again. $\endgroup$ Commented Dec 24, 2019 at 16:31
29
$\begingroup$

I put a fair amount of effort into this, just about as the recent duplicate question was being closed. So I am moving it.

I wanted to include the viewpoint of Burton Wadsworth Jones, given in his little book "The Arithmetic Theory of Quadratic Forms." The theorem, with many cases, is that the number of "primitive" or "proper" representations $R_{0}(n)$ of a number by $x^2 + y^2 + z^2,$ (meaning $\gcd (x,y,z) = 1$) is a multiple of the class number of binary quadratic forms of discriminant $-4n,$ but the multiple changes depending on congruence properties of $n.$ Also there are "ground" cases, here $n=1,$ which are done separately anyway.To get the actual number of representations for a number that is not squarefree it is necessary to take a sum.

Let's see, if $n$ is a multiple of 4 there are no primitive representations, as $x^2 + y^2 + z^2 \equiv 0 \pmod 4$ means that $x,y,z$ are all even. But that is fine, because this also means that the number of representations of $4n$ is exactly the same as the number of representations of $n.$ Also, if $ n \equiv 7 \pmod 8$ there are no representations at all.

For $n > 1$ and $ n \equiv 1 \pmod 8,$ $\; \; R_{0}(n) = 12 h(-4n).$

For $ n \equiv 3 \pmod 8,$ $ \; \; R_{0}(n) = 8 h(-4n).$

For $ n \equiv 5 \pmod 8,$ $ \; \; R_{0}(n) = 12 h(-4n).$

For $ n \equiv 2 \pmod 8,$ $ \; \; R_{0}(n) = 12 h(-4n).$

For $ n \equiv 6 \pmod 8,$ $ \; \;R_{0}(n) = 12 h(-4n).$

Just to include something that is not entirely about proper representations, from the Hecke eigenform method one gets, with p an odd prime, $$ R(p^2 n) = (p + 1 - (-n|p) ) \; \; R(n) - \; \; p \; R( n / p^2) $$ where $R(n)$ is the number of representations including both proper and improper, the Jacobi symbol $(-n|p)$ is taken to be 0 if $p | n,$ while $R(n/p^2)$ is taken to be 0 if $p^2$ does not divide $n.$ This appears in an article by Hirschhorn and Sellers called, and I think this is clever, "On representations of a number as a sum of three squares" which appeared about 1999 in a journal with the word "Discrete" in the title. I just have a preprint here.

$\endgroup$
13
  • 1
    $\begingroup$ The paper is Michael D. Hirschhorn and James A. Sellers, On representations of a number as a sum of three squares, Discrete Math. 199 (1999), no. 1-3, 85-101, MR1675913 (2000a:11141). $\endgroup$ Commented Apr 27, 2010 at 0:00
  • 2
    $\begingroup$ This is a very nice answer! You organized the data much more clearly than any of the articles I found. $\endgroup$ Commented Apr 27, 2010 at 0:07
  • 3
    $\begingroup$ Just checking: you meant $h(d)$ to count the class number of not-necessarily-primitive binary quadratic forms of discriminant $d<0$? So $h(d)$ is not the class number of the quadratic order of discriminant $d$? Something must be up because $R_0(3) = 4\cdot 8 = 32$ by counting orbits of $(0,\pm 1, \pm 1, \pm 1)$, but the only reduced primitive quadratic form of discriminant $-12$ is $x^2+3y^2$. $\endgroup$ Commented Jan 7, 2017 at 2:02
  • 1
    $\begingroup$ Ah! OK, so did you mean primitive also in the class number of binary quadratic forms? I think now you mean "yes". $\endgroup$ Commented Jan 7, 2017 at 2:15
  • 1
    $\begingroup$ @John Yes, primitive. I believe I kept copies of the pages in Grosswald's book, if I can find them and only one or two pages are involved, I'll scan those and email. $\endgroup$
    – Will Jagy
    Commented Jan 7, 2017 at 2:18
24
$\begingroup$

Short answer: no.

Medium answer: For n square free, this is closely related to the class number of Q(sqrt{-n}); this is a result of Gauss. See Mathworld for a precise statement. This class number can then be rewritten in terms of the quadratic residue symbol. We can either use the class number formula to get an expresion as an infinite sum, or use Dirichlet's evaluation of L(1, chi) (same Wikipedia link) to give a finite expression.

When n is not square free, one can still give an answer in terms of the product of the class number and certain elementary correction factors, but the correction factors are so bad that no one wants to write them down. (By no one, I mean that the first half dozen papers I found on mathscinet wouldn't do it.)

Long answer: I did find a paper with all the details. See Theorem B of Bateman "On the representations of a number as the sum of three squares." Trans. Amer. Math. Soc. 71, (1951). 70--101. That's right, I won't write it down either :).

$\endgroup$
4
  • $\begingroup$ Thanks. It seems that the formulas for the number of ways to write n as a sum of k squares are much simpler when k is even than when k is odd. My conjecture, suitably rewritten, still seems to be true from numerical data: lim (n → ∞) #{k ≤ n and r_j(k)/k^(j/2-1) ≤ x} / n seems to be nontrivial, at least for x in a certain range. I'm now trying to familiarize myself with the literature, which is a daunting task since so many people have studied this... $\endgroup$ Commented Nov 2, 2009 at 19:48
  • $\begingroup$ Hmmm. Since a positive proportion of integers are square free, you could just concentrate on that case. Then you are asking whether the class number h(n) is less than x*sqrt{n} with positive probability. I'm pretty sure that this is either known or conjectured to be true. $\endgroup$ Commented Nov 2, 2009 at 21:33
  • $\begingroup$ Bounds for the class number of imaginary quadratic fields follow from the Brauer-Siegel formula. See e.g. Davenport's book. $\endgroup$ Commented Apr 27, 2010 at 2:27
  • 2
    $\begingroup$ Actually, the nice formula for square-free $n$ generalizes nicely to primitive representations. From this formula, it is straightforward to generate Bateman's formula for all representations. $\endgroup$
    – GH from MO
    Commented Jun 3, 2014 at 23:55
9
$\begingroup$

See Granville-Soundararajan, ``The distribution of values of L(1, \chi),'' for (whatever is known about) the distribution of r_3(n)/sqrt(n).

$\endgroup$
0
$\begingroup$

The best reference I've found is Chapter 3 and 4 of Grosswald, Emil (1985). Representations of Integers as Sums of Squares. Berlin: Springer-Verlag.

r3 formula

Simple? No. You need an efficient way to calculate Jacobi symbols, and it may be more efficient to just compute $$\sum_k r_2(N-k^2)$$

The time complexity of that is the sum of how hard it is to factor each $N - k^2$...

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .