Number

Almost no number is one

Sums of two squares look common — a sixth of all numbers up to a million are one. The fraction is falling to nothing, at a rate so slow that no computation will ever make it obvious, and the constant in front of it has been computed to fifty places and identified with nothing.
18 min read 5 figures Pi turns up uninvitedSmall cases lie

Worth reading first: Two squares, and a lattice · The two squares actually produced.

The first few sums of two squares are 1,2,4,5,8,9,10,13,16,17,18,201, 2, 4, 5, 8, 9, 10, 13, 16, 17, 18, 20. That is twelve of the first twenty, which suggests a property most numbers have.

Count further and the impression survives for a long time. Below a hundred there are forty-three; below a thousand, three hundred and thirty; below a million, a hundred and fifty-five thousand or so — still more than one in seven. The fraction is going to nought, and the going is slow enough that no range anyone can count over shows it convincingly.

How rare a sum of two squares is. Two curves against the logarithm of the bound: the fraction of numbers below it that are sums of two squares, falling; and that count times the square root of the logarithm, divided by the bound, which is nearly constant.
Fig. 1 Two curves against the bound. The lower one is the fraction of numbers below the bound that are sums of two squares, falling steadily and headed nowhere but zero. The upper one is that count multiplied by the square root of the logarithm and divided by the bound, and it is nearly flat — near 0.76420.7642, which is the whole content of the theorem.

Landau proved in 1908 that the count below xx behaves like

B(x)    Kxlogx,B(x) \;\sim\; K\,\frac{x}{\sqrt{\log x}},

with K0.76422365K \approx 0.76422365, and Ramanujan had the same statement, unproved, in his first letter to Hardy. Dividing by xx gives a density of K/logxK/\sqrt{\log x}, which goes to nought — and at x=106x = 10^6 is still 0.2060.206, and at x=10100x = 10^{100} is still 0.050.05.

What the condition is

The count is of numbers, not of primes, so the first thing needed is which numbers qualify. The condition is a statement about factorisation: a number is a sum of two squares exactly when every prime congruent to 33 modulo 44 in its factorisation appears to an even power.

The reason is that the quantity a2+b2a^2 + b^2 is a norm in the Gaussian integers and norms multiply. A prime 1\equiv 1 splits into two conjugate Gaussian primes and contributes freely; 22 ramifies and contributes freely; a prime 3\equiv 3 stays prime in Z[i]\mathbb{Z}[i] and can only appear as the norm of a power of itself, which costs two of it at a time. So the condition is a parity constraint, one prime at a time, and it is a condition on the factorisation rather than on the number — which is why no congruence on nn decides it, unlike the three-square case.

That is what makes the counting hard. Asking how many numbers below xx have a property of their factorisation is asking a question that the sieve was built for, and the answer is never a clean fraction.

Where the square root of the logarithm comes from

The exponent is a half, and it is a half for a reason that is worth following, because the same shape of argument fixes the exponent in a whole family of counting problems.

Think of building a qualifying number by choosing its primes. The primes 1(mod4)\equiv 1 \pmod 4 may be used freely; the primes 3\equiv 3 must be used in pairs, which is a severe restriction; and the two classes each contain half the primes, a fact of Dirichlet’s, which is the theorem that the primes do not favour a residue class in its smallest interesting case.

Being forbidden from using half the primes at all costs a factor of logx\sqrt{\log x}, and here is the shape of why. The count of numbers below xx built only from an allowed set of primes is governed by a product px,allowed(11/p)1\prod_{p \le x, \text{allowed}} (1 - 1/p)^{-1}; over all primes that product behaves like logx\log x, by Mertens; and over a set of density one half in the primes it behaves like logx\sqrt{\log x}, because the density appears in the exponent. A number formed with a free choice over half the primes therefore has logx\sqrt{\log x} rather than logx\log x worth of freedom, and the count comes out smaller by the missing factor.

So the exponent 12\tfrac12 in logx\sqrt{\log x} is the density of the allowed primes, and nothing else. Change the condition so that a third of the primes are free and the exponent becomes a third; that is the general theorem, due to Landau in the same paper and sharpened by Selberg and Delange, and it says the count of numbers whose prime factors are restricted to a set of density δ\delta behaves like x(logx)δ1x(\log x)^{\delta - 1} up to a constant.

The pairing of the forbidden primes contributes only to the constant. That is worth separating, because it is the counterintuitive half: the requirement that primes 3\equiv 3 appear to even powers is what makes the arithmetic of the constant complicated, and the shape x/logxx/\sqrt{\log x} would be the same if they were forbidden outright.

The constant, computed and unidentified

KK has an exact expression, and looking at it explains why nobody has a closed form.

K  =  12p3 (4)(11p2)1/2K \;=\; \frac{1}{\sqrt 2}\prod_{p \equiv 3 \ (4)} \left(1 - \frac{1}{p^2}\right)^{-1/2}

The product runs over the primes 3(mod4)\equiv 3 \pmod 43,7,11,19,23,3, 7, 11, 19, 23, \ldots — and it converges, because 1/p2\sum 1/p^2 does. But it converges slowly, and worse, it converges over a set defined by a congruence, which is exactly the kind of set whose products do not simplify.

The computation is nonetheless routine, and it is worth knowing how. Taking logarithms turns the product into 12log(1p2)-\tfrac12\sum \log(1 - p^{-2}), and expanding the logarithm turns that into a sum of p3p2k\sum_{p \equiv 3} p^{-2k} over kk. Each of those prime sums over a congruence class is expressible in terms of the Riemann zeta function and the Dirichlet LL-function for the character mod 44 — and that LL-function at even arguments is a rational multiple of a power of π\pi, while at odd arguments it is Catalan’s constant and its relatives. So KK is built from ζ\zeta and LL at integer points, and the series converges fast enough that Flajolet and Vardi computed thirty digits in 1996 with a few lines.

K=0.764223653589220662990698731250K = 0.764223653589220662990698731250\ldots, and it is not known to be irrational.

That is the state of affairs worth dwelling on. A constant can be computed to any accuracy wanted and still be unidentified, and the two are genuinely separate achievements — the second requires knowing that it equals something, and no candidate has been found. It sits with Catalan’s constant, the Euler–Mascheroni constant of the collector’s wait, and the Brun constant in a class of numbers that arithmetic produces routinely and about which almost nothing is known.

How rare is rare

Lattice points on the circles of squared radius 1 to 48. One bar per squared radius, its height the number of whole-numbered points on that circle; the bars of height zero are the numbers that are not a sum of two squares.
Fig. 2 The count of lattice points on each circle of squared radius up to forty-eight, which is the circle count read for a different purpose. The empty columns are the numbers ruled out, and there are a great many of them even at this size — twenty-seven of the forty-eight. The density of the non-empty columns is what this essay is about, read at the smallest possible scale.

At x=106x = 10^6 the density is about 0.2060.206; it takes x=1028x = 10^{28} to halve that, and x=10112x = 10^{112} to halve it again. The function 1/logx1/\sqrt{\log x} is one of the slowest decays a natural counting problem produces, and there are two consequences.

It is worth putting one comparison beside that. The primes themselves have density 1/logx1/\log x, which at a million is about 0.0720.072 — so a random number below a million is about three times more likely to be a sum of two squares than to be prime, and both densities are heading to nought. The one that gets there faster is the primes’, by a factor of logx\sqrt{\log x}, which at any size a person deals with is a single-digit multiplier.

Nobody would guess the answer from data. A table of counts to a billion is compatible with a density tending to a positive limit, with a density tending to zero like 1/logx1/\log x, and with a density tending to zero like 1/logx1/\sqrt{\log x}. The three differ by factors nobody could distinguish over any computable range, and the theorem is the only way to know.

And the qualitative statement is the surprising one. Almost no number is a sum of two squares is true and is not what any amount of counting suggests. The reason to trust it is the structure of the last section rather than the arithmetic: half the primes are forbidden, and forbidding half the primes has a cost that accumulates without bound, however slowly.

That contrast — a theorem whose content is invisible at every scale that can be examined — is the same shape as the harmonic series passing every bound, which was doubted for centuries for exactly the reason. Slow is not small, and the two are confused whenever the evidence is a table.

How rare a sum of two squares is. Two curves against the logarithm of the bound: the fraction of numbers below it that are sums of two squares, falling; and that count times the square root of the logarithm, divided by the bound, which is nearly constant.
Fig. 3 The same two curves run seven and a half times further. The fraction has fallen from about a fifth to about a sixth — one step of a decline that needs another twenty-two orders of magnitude to halve again — and the scaled curve has not moved. That is what an asymptotic result looks like from inside a range: the thing it predicts is invisible and the thing it is scaled by is exact.

Multiplicity, and the difference between a number and a circle

There is a distinction the counting quietly makes and it is worth pulling out, because the two questions are often run together and have completely different answers.

How many nn below xx are sums of two squares at all is B(x)Kx/logxB(x) \sim Kx/\sqrt{\log x} — this essay’s subject, a count of numbers.

How many lattice points lie inside a circle of radius RR is πR2\pi R^2 plus an error — a count of points, which is the route to the Leibniz series and a problem open since 1837.

The two are the same sum organised differently: adding r2(n)r_2(n) over nR2n \le R^2 gives the point count, and counting the nn with r2(n)>0r_2(n) > 0 gives BB. So the point count is a total over a rapidly-varying function and the number count is a count of its support, and the first has a smooth answer while the second has a logarithm in it.

What separates them is that r2r_2 is very unevenly spread. The numbers that qualify are rarer and rarer, and the ones that qualify carry more and more representations to compensate — a number with kk distinct prime factors 1(mod4)\equiv 1 \pmod 4 has at least 2k2^k points on its circle. So the average of r2r_2 is π\pi, exactly, for ever; the median is nought and stays nought; and the whole difference between the two counting problems is the gap between those two statements.

Lattice points on the circles of squared radius 1 to 64. One bar per squared radius, its height the number of whole-numbered points on that circle; the bars of height zero are the numbers that are not a sum of two squares.
Fig. 4 The same counts to sixty-four, where the unevenness is already visible. The average column height is heading for π\pi and more than half the columns are empty, so the non-empty ones are tall — 5050 carries twelve points, 6565 carries sixteen, and thirty-seven of the sixty-four carry none at all.

Where the same question has a different answer

Putting three neighbours beside it is the fastest way to see what is special.

Sums of four squares: every number. Density one, no condition at all, Lagrange 1770. Four squares is enough room that no obstruction survives.

Sums of three squares: all but 4a(8b+7)4^a(8b+7). Density 5/65/6, and the excluded set is defined by a congruence — so this is a positive density and the count is a fraction of xx rather than xx over anything.

Sums of two squares: density nought. The condition is on the factorisation, and no congruence describes it.

Numbers that are themselves squares: density nought too, and for a reason nothing like this one — there are x\sqrt x of them below xx, which is a power smaller rather than a logarithm smaller. Being a square is rare in a way that is easy to see; being a sum of two squares is rare in a way that no amount of looking reveals.

Sums of two cubes, or of two fourth powers: a count of order x2/3x^{2/3} and x1/2x^{1/2} respectively, which is a power of xx smaller rather than a logarithm smaller — a completely different regime, because there are only about x1/2x^{1/2} squares below xx but their sums fill a positive-density-looking set, while there are x1/3x^{1/3} cubes and their sums cannot.

So two squares sits at the boundary of two regimes, and it is the only one of the five whose answer is neither a constant fraction nor a power of xx. The logarithm in it is the signature of a condition that is about factorisation rather than about size, and it is what makes this the interesting case.

Primes below 60 as sums of two squares. Each prime with its remainder on division by four, and the two squares that add to it where they exist.
Fig. 5 The underlying dichotomy at the level of primes: every prime one more than a multiple of four splits, and no other odd prime does. The two classes are equally numerous in the long run, and the essay’s whole answer comes from what happens when only one of them may be used freely.

Four decades of data, and a claim about the limit

The falling curve is drawn over four orders of magnitude and the claim is about the limit. Over the range drawn the density moves from about a third to about a fifth, which is a fall and is equally compatible with a limit of a sixth. The figure establishes only that the density is falling, which is true and is not the theorem; the theorem is about behaviour no plot reaches.

The flat curve is flat because the theorem is true, and its flatness is not evidence of the constant. What is drawn is B(x)logx/xB(x)\sqrt{\log x}/x against xx, and it sits near 0.7640.764 over the range. A wrong constant would show as a curve near a different value, but a wrong exponentlogx\log x in place of logx\sqrt{\log x} — would show as a slowly drifting curve that over four decades is hard to distinguish from a flat one. The figure cannot separate the theorem from its near neighbours.

The sieve is exact and the range is small. Every count here is made by testing every number’s factorisation up to twenty thousand, checked against the circle count for the first two hundred. That is a measurement and it is not an approximation; what it is not is large, and the asymptotic statement is about a region no exact sieve reaches.

And the constant is quoted, not computed. 0.764223650.76422365 appears in the figure as a horizontal line taken from the literature, since evaluating the product over primes 3(mod4)\equiv 3 \pmod 4 to that accuracy needs the LL-function machinery of the section above and is not a page-build’s business. Everything else on the page is computed from the numbers; that line is not, and it is the one number a reader should check elsewhere.

The theorem’s other half, which is about the primes

Landau’s argument has an ingredient this essay has used without naming, and naming it says where the difficulty actually is.

The count is over numbers built from a set of primes, and what makes the sum computable is knowing how many primes there are in each residue class below xx. Dirichlet’s theorem says the two classes mod 44 are equally populated; the quantitative version, which is what the counting needs, says each has about 12x/logx\tfrac12 \cdot x/\log x members below xx, with an error term.

That error term is where the subject’s hard questions live. How evenly the primes distribute between 11 and 33 modulo 44 is a question about the zeros of an LL-function, exactly as the overall prime count is a question about the zeros of ζ\zeta; and the small persistent excess of primes 3\equiv 3 over primes 1\equiv 1 — Chebyshev’s bias, which holds for most xx and not all — is a phenomenon nobody had a clean account of until the 1990s.

None of that disturbs the leading term here. Landau’s result needs the classes to have density a half and nothing finer, and the density is a nineteenth-century theorem. What it means is that sharpening this essay’s answer past its leading term runs into the same wall every counting problem about primes runs into, one layer down and from an unexpected direction: a question about which numbers are sums of two squares turns out to be a question about where a certain function’s zeros are.

Still open here: what the constant is, and how well it approximates

KK is computed to thirty digits, has an exact product formula, and is not known to be irrational — nor is Catalan’s constant, which appears in its evaluation. There is no reason to expect any of them to be anything nameable, and no method that would settle it.

The other open direction is sharper and more interesting: how good is the approximation? Landau’s theorem gives the leading term, and there is a full asymptotic expansion in descending powers of logx\log x — the error after the leading term is of order x/(logx)3/2x/(\log x)^{3/2}, with a computable constant, and so on down. What that expansion does not have is an error term of the kind the prime number theorem has, tied to the zeros of the zeta function, and obtaining one is the analogue here of the questions the prime count leaves open.

Density nought, at a human scale

The habit is about what almost none means and how badly it can be misread.

A property held by a fifth of the numbers below a million, and by a twentieth of those below 1010010^{100}, is a property that a person examining numbers will meet constantly and that almost no number has. Both halves are true and they describe the same fact. A density tending to zero says nothing about any particular range, and a density in a particular range says nothing about the limit.

The arithmetic that produces this is the same arithmetic in every case where a logarithm appears in a density: the restriction accumulates across scales, each scale contributes a little, and the total passes any bound while never being visible at any one scale. When a count is off by a logarithm, the honest statement is about a limit and the honest picture is of a range — and the two will not agree, which is not a defect of either.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

ApproximationAsymptoticConvergence ratePrimesSums of two squaresUnique factorisation