Number

The wait for the next sum of two squares

Sums of two squares thin out to a share of nought, and yet the gaps between them stay short. Take the largest square below any number; what is left over is small, and a small number is always close to a square. Two squarings in a row say the next sum of two squares is never more than about 2√2 times the fourth root of n away — a bound proved in 1947 that nobody has improved, sitting far above every gap anyone has found.

Worth reading first: Almost no number is one · Two squares, and a lattice.

Almost no number is a sum of two squares. Among the numbers up to xx the share that are falls off like 1/log⁡x1/\sqrt{\log x}, so it tends to nothing — slowly, but to nothing. A share tending to nothing usually means the members spread further and further apart. The primes behave that way: they thin out like 1/log⁡x1/\log x, and the gaps between consecutive primes grow without bound, with a run of a million composite numbers in a row starting at (106+1)!+2(10^6 + 1)! + 2.

Sums of two squares thin out more slowly than primes do, and their gaps are also forced to stay much shorter than anything the density alone would allow. The next sum of two squares after nn is never more than about 22 n1/42\sqrt 2\, n^{1/4} away. The proof is two lines of arithmetic, and it has not been improved in eighty years.

Where they sit on the number line

It helps to look before arguing.

Sums of two squares from 0 to 199. A grid of the numbers 0 to 199 with the 79 sums of two squares filled in. The longest gap, 7 numbers from 186, is marked.
Fig. 1 The numbers 0 to 199, twenty to a row, with the 79 that are sums of two squares filled. The longest stretch containing none is seven numbers long, from 186 to 192, ringed. The filled cells thin out down the rows — 12 in the first row, 7 in the last — but no gap opens wide.

Two things are visible at once. The sums of two squares get rarer — twelve in the first row of twenty, seven in the last. And they never leave a long hole. The widest stretch without one below two hundred is 186 to 192, seven numbers, after which 193 = 144 + 49 arrives.

Some of the structure in the picture is the rule about primes: a number is a sum of two squares exactly when every prime that is 3 more than a multiple of 4 divides it to an even power. That rule makes every number of the form 4k+34k + 3 unfilled — a whole column-pattern of holes — and makes 21, 22, 24, 27, 28, 30, 31 all fail for their own reasons. It does not by itself say anything about how long a run of failures can last. For that the argument has to find a sum of two squares near any given number, and the rule about primes is no help in finding one: it decides a number presented to it, but it cannot say where the next success lies without factoring every candidate in turn. What is needed is a construction — a way of writing down, from nn alone, a nearby number that is visibly a sum of two squares because it has been built as one.

The largest square, and then the smallest

Take any nn. Let a2a^2 be the largest square not exceeding it, so a=⌊n⌋a = \lfloor \sqrt n \rfloor, and write the remainder as r=n−a2r = n - a^2. Because (a+1)2=a2+2a+1(a+1)^2 = a^2 + 2a + 1 is already bigger than nn, the remainder is at most 2a2a. That is the first squaring: the distance from nn down to a square is at most about 2n2\sqrt n.

Now do the same thing to rr, upward. Let b2b^2 be the smallest square at least rr. The distance from rr up to b2b^2 is less than 2b2b, and bb is about r≤2n\sqrt r \le \sqrt{2\sqrt n}. That is the second squaring.

Put them together: a2+b2a^2 + b^2 is a sum of two squares, it is at least a2+r=na^2 + r = n, and it exceeds nn by b2−r<2bb^2 - r < 2b. So

the next sum of two squares after n ≤ n+22 n1/4+1.\text{the next sum of two squares after } n \ \le\ n + 2\sqrt{2}\, n^{1/4} + 1.

The next sum of two squares after 150. A quarter of the circle of radius √150 on the integer lattice, with the column x = 12 and the first lattice point above the circle in it, (12, 3), on the circle of radius √153.
Fig. 2 The argument on n = 150. The largest square below it is 122=14412^2 = 144, leaving r = 6 — at most 2·12, as it must be. The smallest square at least 6 is 32=93^2 = 9. So the lattice point (12, 3) sits just outside the circle of radius 150\sqrt{150}, and 122+32=15312^2 + 3^2 = 153 is a sum of two squares only 3 past n.

The picture says the same thing geometrically. A sum of two squares is a lattice point, and x2+y2=nx^2 + y^2 = n is a circle of radius n\sqrt n. The argument walks out along the xx-axis to the last lattice column inside the circle, x=ax = a, and climbs that column until it leaves the circle. The circle crosses the column at height r\sqrt r, and the first lattice point above is less than one unit further on. How far outside the circle can that lattice point be? Its squared distance from the origin exceeds nn by less than 2r+12\sqrt r + 1, and since rr is small compared with nn — the column is near the edge — the excess is small too.

The argument is due to R. P. Bambah and S. Chowla, in 1947, and it is the kind of proof that looks as though a little more care would sharpen it. The next section shows that it has room to spare. Nobody has found the care.

Record gaps against the bound

The bound is easy to test, since sums of two squares are easy to sieve for.

Record gaps between sums of two squares, up to 1,000,000. Dots for each new longest gap between consecutive sums of two squares below 1,000,000, the largest 35, under the curve 2√2 n^(1/4) + 1 on logarithmic axes.
Fig. 3 Every record gap between consecutive sums of two squares up to a million — each dot is a new longest gap, plotted where it starts — against the curve 22 n1/4+12\sqrt 2\, n^{1/4} + 1, on logarithmic axes. The largest gap below a million is 35. The bound is never approached, and the records rise far more slowly than any power of n appears to.

Below a million the longest wait is 35 numbers, where the bound allows about 90. More telling than any single gap is the shape of the records: on logarithmic axes a power law would be a straight line, and the dots bend away beneath the bound’s straight line as nn grows. What they look like is a quantity growing like a power of log⁡n\log n rather than a power of nn.

That is also what heuristics predict. If sums of two squares behaved like random numbers of density c/log⁡nc/\sqrt{\log n}, gaps would be typically about log⁡n\sqrt{\log n} long and the longest in a range would be of order log⁡n⋅log⁡n\log n \cdot \sqrt{\log n} — a slowly growing function nowhere near n1/4n^{1/4}. And the true numbers are not random: the rule about primes makes them avoid residue classes, which lengthens some gaps and shortens others in ways the heuristic ignores.

The gap between the proved bound and the observed behaviour is enormous, and it is open. No argument is known that gives a gap of n1/4−εn^{1/4 - \varepsilon} for any ε>0\varepsilon > 0. In the other direction, Ian Richards proved in 1982 that gaps as long as about 14log⁡n\tfrac14 \log n occur infinitely often, so the gaps are genuinely unbounded; between log⁡n\log n and n1/4n^{1/4} is a range nobody has been able to narrow.

Why the easy argument is stuck

The two-squarings argument uses only the fact that squares are dense near the scale r\sqrt r: the gap between consecutive squares near rr is about 2r2\sqrt r. To do better one would want to choose the first square more cleverly — not the largest square below nn, but some square a2a^2 for which the remainder n−a2n - a^2 happens to be a square itself, or close to one.

There are about n\sqrt n choices of aa, and each remainder n−a2n - a^2 is a number of size up to nn; the chance that a random such number is within kk of a square is about k/nk/\sqrt n. So with n\sqrt n tries and a success probability of k/nk/\sqrt n each, one expects to succeed with kk of order 1 — a bounded gap, if the remainders behaved like random numbers. They do not behave like random numbers, and proving that enough of them come close to squares is exactly the kind of statement about the distribution of n−a2n - a^2 modulo squares that current methods cannot reach. The easy argument takes one try and accepts whatever remainder it gets; every improvement would need to control many tries at once.

A second route would be to use the rule about primes directly — to show that among the numbers just after nn one of them has all its 4k+34k + 3 primes to even powers. That is a sieve problem, and sieves are good at counting how many numbers in a long interval survive and bad at guaranteeing that a short interval contains one. The interval here has length n1/4n^{1/4}, which is short by the standards of sieve theory. Sieve methods do show that almost every interval of length a power of log⁡n\log n contains a sum of two squares — the exceptions are rare — but a statement about every interval, with no exceptions allowed, is out of their reach at any length below the fourth root.

The same obstruction, in a different costume, is what separates the count of lattice points in a disc from its expected value. There the question is how far the number of lattice points in a circle of radius n\sqrt n can stray from πn\pi n; the easy bound is of order n\sqrt n, the truth is conjectured to be about n1/4n^{1/4}, and eighty years of work have moved the proved exponent only a little. Lattice points near a circle are hard to control, and a gap between sums of two squares is precisely a thin ring round a circle containing no lattice point at all.

Three in a row, and never four

The strip showed 8, 9, 10 filled side by side, and 16, 17, 18, and 72, 73, 74. Runs of consecutive sums of two squares are worth counting, because one length never occurs.

Runs of consecutive sums of two squares, up to 100,000. A bar chart: 14293 sums of two squares with neither neighbour one, 4199 runs of two, 445 runs of three, and none of four.
Fig. 4 The sums of two squares up to 100,000 split into maximal runs of consecutive numbers: 14,293 standing alone, 4,199 runs of two, 445 runs of three — the first, after 0, 1, 2, being 8, 9, 10 — and no run of four at all.

A run of four consecutive numbers always contains one that is 3 more than a multiple of 4. A square leaves remainder 0 or 1 when divided by 4 — an even number squared is a multiple of 4, an odd one is one more than a multiple of 8 — so a sum of two squares leaves 0, 1 or 2, and never 3. So four in a row is impossible, and the reason is arithmetic on a clock with four hours.

Three in a row is not forbidden by any remainder, and it happens, hundreds of times below a hundred thousand. That runs of three recur without end is a theorem, and it can be seen from a family: n2−1n^2 - 1, n2n^2, n2+1n^2 + 1 are three consecutive numbers of which the last two are sums of two squares trivially, and for infinitely many nn the first is too. Take n=2k2+1n = 2k^2 + 1: then n−1=k2+k2n - 1 = k^2 + k^2 and n+1=(k+1)2+(k−1)2n + 1 = (k+1)^2 + (k-1)^2, and a product of two sums of two squares is again one, so n2−1=(n−1)(n+1)n^2 - 1 = (n-1)(n+1) is a sum of two squares. With k=2k = 2 that gives 80, 81, 82. How often runs of three occur in general — how their count up to xx compares with what an independence model of the three conditions would predict — has conjectural answers and only partial theorems.

Further out, the same shape

A strip at the start of the number line can mislead, because small numbers are special. So look again ten thousand numbers on.

Sums of two squares from 10000 to 10199. A grid of the numbers 10000 to 10199 with the 50 sums of two squares filled in. The longest gap, 13 numbers from 10101, is marked.
Fig. 5 The numbers 10,000 to 10,199 with the 50 sums of two squares among them filled — a quarter of the cells, against two-fifths at the start of the line. The longest stretch with none is thirteen numbers, 10,101 to 10,113, ringed — well inside what the two squarings allow.

Two hundred numbers past ten thousand contain fifty sums of two squares, where the first two hundred contained seventy-nine; the thinning is visible, and it is the slow 1/log⁡x1/\sqrt{\log x} thinning of the density rather than anything faster. The longest hole has grown from seven to thirteen. And the holes are still scattered rather than clustered: most rows have three or four filled cells, and none is empty. That is the qualitative content of the bound — the density falls but the spacing stays even — seen at a scale where the fourth root of nn is ten rather than four.

The hole from 10,101 to 10,113 is also worth reading closely, because it shows what a gap is made of. Among its thirteen numbers, three are 4k+34k + 3 and fail automatically; the rest fail because each has some prime 4k+34k + 3 to an odd power — 10,101 is 3×7×13×373 \times 7 \times 13 \times 37, 10,102 is 2×50512 \times 5051 with 5051≡3(mod4)5051 \equiv 3 \pmod 4 — each for its own reason. A long gap is a coincidence of many independent failures, which is why long gaps are rare and why their length grows so slowly.

The same bound for other shapes

The argument used nothing specific to squares beyond the gaps between them. Replace x2+y2x^2 + y^2 by x2+y3x^2 + y^3, or by any sum of two powers, and the same two-step argument gives a gap bound — the largest $k$th power below nn, then the nearest power above the remainder — with an exponent that depends on the powers. For sums of three squares the question disappears: every number not of the form 4a(8b+7)4^a(8b + 7) is one, so the gaps are bounded outright — never more than two numbers in a row are missed, and 111 and 112 are the first such pair. For four squares there are no gaps at all, since every number is a sum of four.

So two squares is the interesting case for a structural reason. With three or more squares the representable numbers have positive density and the gaps are bounded; with two they have density zero, and the question becomes how that zero density is distributed. It is thin but evenly spread, and the easy argument sees only a crude version of the evenness.

There is a version of the question for primes that shows how much the answer depends on the set. The primes are also of density zero, thinning like 1/log⁡x1/\log x, and the best proved bound for the gap after nn is about n0.525n^{0.525} — a much weaker statement than n1/4n^{1/4}, for a set that is only a little thinner. The difference is that sums of two squares can be constructed near any number, by the two squarings, while nobody knows how to construct a prime near a given number at all.

What the pictures cannot establish

A million is not large. The record gaps are plotted up to 10610^6, where log⁡n\log n is about 14 and n1/4n^{1/4} is about 32. The two scales are not yet far apart, and the eye can be misled about which curve the dots follow. The claim that the records grow like a power of log⁡n\log n is a heuristic and an extrapolation, not something the figure proves; the only proved statements are the bound above them and Richards’s bound below.

The first figure’s gap of seven is special. Short ranges have their own record gaps, and a strip of two hundred numbers shows a structure — rows thinning, holes at every 4k+34k + 3 — that is qualitatively right and quantitatively nothing like the asymptotic regime.

The run counts are a census, not a density. The bar chart counts runs below a hundred thousand; it establishes that four in a row never occurs there, which the remainder argument proves everywhere, and it shows three in a row occurring often, which the infinite family above guarantees. It does not say how the proportions change as the range grows.

Still open: the true size of the gaps

Two questions are open, and they are the natural next steps.

What is the right exponent? It is conjectured that for every ε>0\varepsilon > 0 the gap after nn is eventually less than nεn^{\varepsilon} — that is, smaller than any power — and most likely of order log⁡n\log n at most. The proved exponent is 1/41/4, from the argument drawn above. Any improvement, to 1/4−0.0011/4 - 0.001, would be a new result.

How long are the longest gaps, really? Richards’s lower bound of about 14log⁡n\tfrac14\log n shows the gaps are unbounded; the heuristics suggest the longest gap up to xx is of order log⁡x\log x times a small power of log⁡log⁡x\log\log x at most. Closing the distance between 14log⁡n\tfrac14 \log n from below and n1/4n^{1/4} from above is a problem about the fine distribution of lattice points near circles, and it is not expected to be easy.

Both questions would follow from strong enough information about lattice points in thin annuli — rings between radius n\sqrt n and n+h\sqrt{n + h} — and that information is exactly what the circle problem lacks. So the two open problems, the gaps and the circle, are one problem seen at two scales: the number of lattice points in a whole disc, and whether a thin ring of it contains any at all.

A thin set that is evenly spread

Sums of two squares are rare in the long run and never far apart. Both statements are true at once because the rarity is so slow — a factor of log⁡x\sqrt{\log x} — and because squares are so dense near any small number that a remainder can always be topped up to one. The argument that shows it takes two squarings and fits on a line, and the fact that nobody has improved it is a measure of how little is known about where lattice points lie near a circle.

It is also a small lesson about the difference between counting and constructing. Landau’s count says how many sums of two squares there are, to a precision the gap bound cannot approach; the gap bound says where one of them is, near any number, which the count cannot say. Each kind of statement is blind to what the other sees, and the best results in this subject are the ones that manage both. Here the count is sharp and the placement is crude, and the eighty-year-old crude one is still the best there is.

Reads more easily once this is understood

Essays that name this one as worth reading first.

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.

AsymptoticDensityExhaustive searchLatticeModular arithmeticPrimesSums of two squares