Analysis

A rule that counts lets the sum escape

Strike out every number containing a 9 and the harmonic series converges, to 22.92. Keep only the numbers with as many 7s as 3s and it diverges — slowly, like the square root of the number of digits. Ask for two such balances and it still diverges; ask for three and it converges. The dividing line is Pólya's theorem that a random walk comes home in one and two dimensions and not in three.
19 min read 6 figures The same thing twiceSmall cases lie

Worth reading first: What a missing string of digits leaves behind · A walk that always comes home, until it does not.

What a missing string of digits leaves behind summed the harmonic series with every term struck out whose denominator contains a given string of digits — 9, or 42, or 314 — and found that it always converges, to a total close to ln⁡10\ln 10 times the average time a random stream of digits takes to produce the string. The method was exact and fast, and it depended on one thing: the rule “contains 42” can be checked by a machine with a fixed, finite number of states, reading the digits one at a time and remembering only how much of 42 the number currently ends with. That essay closed by naming the rules it could not handle — the numbers with as many 7s as 3s, the numbers whose digits add up to a prime — rules that no finite machine can follow, because they have to count.

This essay handles them, and the answer is that counting is exactly what lets the series escape. Both of those thinned series diverge. And a whole family of rules sits between them and Kempner’s, in which the series diverges or converges according to a single number: how many independent counts the rule keeps.

Two thinned harmonic series that never stop growing. every n: 10d 23.603067, 40d 92.680619, 120d 276.887427; no digit 9: 10d 15.109789, 40d 22.589564, 120d 22.920604; as many 7s as 3s: 10d 11.327995, 40d 24.391523, 120d 43.428896; digit sum a prime: 10d 7.156214, 40d 21.096266, 120d 51.331792
Fig. 1 Partial sums of 1/n1/n over the survivors of four rules, for nn up to 1010 to the number of digits on the horizontal scale, every block computed exactly. The full series runs off the top; Kempner’s no-9 series settles; the two counting rules never do.

The same method, with a counter for a memory

The block method carries over almost unchanged. All the surviving numbers with jj digits form one block, and the block of j+1j + 1 digits is built by appending a digit dd to each jj-digit number nn, giving 10n+d10n + d. Robert Baillie’s trick is to carry, for each block, not only ∑1/n\sum 1/n but ∑1/n2\sum 1/n^2, ∑1/n3\sum 1/n^3 and higher powers, and to expand

1(10n+d)k=∑w≥0(k+w−1w)(−d)w10k+w 1nk+w,\frac{1}{(10n + d)^k} = \sum_{w \ge 0} \binom{k + w - 1}{w}\frac{(-d)^w}{10^{k + w}}\,\frac{1}{n^{k + w}},

so that each power sum of the new block is a fixed combination of the power sums of the old one and no term is ever written down.

For a forbidden string the power sums are carried separately for each state of the matching automaton, and the states are few. For “as many 7s as 3s” the state is the balance — the number of 7s minus the number of 3s so far — and it can be any whole number. A 7 raises it by one, a 3 lowers it by one, and any other digit leaves it where it is. A jj-digit number has a balance between −j-j and jj, so the jj-th block needs 2j+12j + 1 sets of power sums rather than one or two; and at the end of each block only the numbers whose balance is exactly nought are added to the thinned series. The rule is an automaton with infinitely many states, of which any one block uses only finitely many, and that is all the method needs.

The computation scales the power sums by a power of ten matched to the block, so that nothing underflows over hundreds of blocks, and it sums the first four blocks term by term to start the recursion. The hero shows the result to 120 digits. The full harmonic series gains ln⁡10≈2.3026\ln 10 \approx 2.3026 a digit, as a sum that never stops growing explained by grouping. The no-9 series settles at 22.920722.9207, Kempner’s sum, within about forty digits. The series of numbers with as many 7s as 3s has reached 43.4343.43 at 120 digits and is still rising; the series of numbers whose digit sum is prime has reached 51.3351.33, having overtaken it near 65 digits, and is rising faster.

The recursion against ten million terms

The block recursion against ten million terms. 1d: direct 2.35277777777778 recursion 2.35277777777778; 2d: direct 1.59020854460131 recursion 1.59020854460131; 3d: direct 1.31865374433706 recursion 1.31865374433706; 4d: direct 1.14074906137503 recursion 1.14074906137503; 5d: direct 1.01001813078457 recursion 1.01001813078456; 6d: direct 0.91059771596687 recursion 0.91059771596686; 7d: direct 0.83311999501042 recursion 0.83311999501039
Fig. 2 The sum of 1/n1/n over the numbers with as many 7s as 3s, length by length up to seven digits, added one term at a time over every number below ten million and computed by the block recursion. They agree to the rounding of the arithmetic.

A method that never writes a term down needs checking against one that writes all of them down. Below ten million the check is cheap: run through every number, compute its balance digit by digit, and add 1/n1/n to the total for its length when the balance is nought. The figure sets the two side by side. The one-digit block holds 1,2,4,5,6,8,91, 2, 4, 5, 6, 8, 9, whose reciprocals add to 2.352782.35278; the two-digit block, with numbers like 10, 11, 37 and 73, adds to 1.590211.59021; the seven-digit block to 0.833120.83312. The first four lengths are where the recursion starts, so they agree by construction. From five digits on the recursion computes each block from the one before and nothing else, and the largest disagreement with the direct sums is 3×10−143 \times 10^{-14}, which is rounding in the last places of double precision.

The table also shows the first sign of the divergence. A block of the full series is worth about ln⁡10\ln 10, and the survivors’ share of it falls from 2.352.35 to 0.830.83 over seven digits — slowly, and more slowly as it goes: from the fifth block to the sixth it loses ten per cent, from the sixth to the seventh eight and a half. A Kempner block, by contrast, loses a fixed percentage every time. Forbidding 9 keeps nine tenths of each block, and nine tenths of nine tenths, and the blocks form a geometric series whose sum is finite. Here the ratio of successive blocks creeps towards one, and a series whose ratio tends to one can do either thing. Which it does is decided by how fast.

A block spread over a walk

One block of the harmonic series, sorted by its balance. j=30: total 2.30258509; balance sums -6:0.02029, -5:0.04911, -4:0.10227, -3:0.18214, -2:0.27564, -1:0.35244, 0:0.37921, 1:0.34283, 2:0.26080, 3:0.16763, 4:0.09155, 5:0.04276, 6:0.01719.
Fig. 3 The sum of 1/n1/n over all 30-digit numbers, split by the balance of 7s against 3s each number carries. Only the bar at balance 0 belongs to the thinned series. The bars follow the bell of a lazy random walk.

The recursion carries every balance, not only the one that is kept, and looking at all of them shows what governs the rate. The figure takes the block of 30-digit numbers, whose reciprocals add to 2.302592.30259 — ln⁡10\ln 10 to four places — and divides that total among the balances. The balance-nought bar, the part the thinned series keeps, is 0.37920.3792; the bars at ±1\pm 1 are a little smaller, and the rest fall away symmetrically.

The shape is a bell, and the reason is that the balance is a random walk. Read the digits of a typical 30-digit number from left to right and the balance takes a step up with chance one in ten, a step down with chance one in ten, and stays put otherwise: a lazy walk, with variance 0.20.2 a step. After jj steps it is spread like a bell of variance 0.2j0.2j — the Galton board of the bell curve from coin flips, with most of its pegs missing — and the chance of being back at nought is about 1/2π⋅0.2j=1/0.4πj1/\sqrt{2\pi \cdot 0.2j} = 1/\sqrt{0.4\pi j}. The dashed curve is ln⁡10\ln 10 times that bell, with no adjustment, and the bars sit on it. The thinned block is the full block times the chance that a walk of jj steps has come home.

That is the difference from Kempner’s series in one sentence. A forbidden string is a finite automaton, and the chance of never having been absorbed by its deadly state decays geometrically, which is the waiting-time argument of two patterns with one chance and different waits in another form — at rate 0.90.9 a digit for a single forbidden digit, 0.98990.9899 for 42. A balance is a walk on an infinite line, and the chance of being at its start decays only like a power of the length, j−1/2j^{-1/2}. Geometric decay makes any series converge. Decay like j−1/2j^{-1/2} does not.

How fast the blocks shrink

Block sums falling like a walk's return chance. one balance √j·Sⱼ: 10:2.14844, 20:2.09093, 40:2.07076, 80:2.06207 → 2.05405; two balances j·Sⱼ: 10:1.76058, 20:1.79195, 40:1.81142, 80:1.82175 → 1.83234.
Fig. 4 The balanced block sums times j\sqrt j (red), and the block sums of the series kept to as many 7s as 3s and as many 1s as 2s, times jj (blue), computed exactly to 80 digits. They level off at ln⁡10/0.4π\ln 10/\sqrt{0.4\pi} and ln⁡10/(0.4π)\ln 10/(0.4\pi).

If the block sums are ln⁡10/0.4πj\ln 10/\sqrt{0.4\pi j}, then j\sqrt j times the block sum should settle at ln⁡10/0.4π=2.0541\ln 10/\sqrt{0.4\pi} = 2.0541. The red curve is that product, computed exactly, and it comes down from 2.352.35 at one digit to 2.06212.0621 at 80 digits, approaching the predicted level from above. The approach is slow because the leading digit is not quite like the others — it is never 0, and the reciprocal weights favour small leading digits, which are neither 3 nor 7 — and the effect of one unusual step on a walk of jj steps dies away like 1/j1/j.

So the partial sums of the thinned series, up to numbers of JJ digits, grow like

∑j≤J2.0541j≈4.11J,\sum_{j \le J} \frac{2.0541}{\sqrt j} \approx 4.11\sqrt J,

and since a number NN has about log⁡10N\log_{10} N digits, the sum over the survivors below NN grows like 4.11log⁡10N4.11\sqrt{\log_{10} N}. It diverges, but at a pace that makes the harmonic series look hasty: to add another ten to the 43.43 of the hero takes the numbers up to about 180 digits, and to reach a hundred takes numbers of about six hundred.

Add a second balance. Keep only the numbers with as many 7s as 3s and as many 1s as 2s, and the state of the counter becomes a point of the square lattice — a walk in two dimensions, stepping in one of four directions with chance one in ten each and resting otherwise. The chance of being home after jj steps is now about 1/(0.4πj)1/(0.4\pi j), a whole power of jj, and the blue curve, jj times the exactly computed block sum, levels off at ln⁡10/(0.4π)=1.8323\ln 10/(0.4\pi) = 1.8323. The partial sums grow like 1.83ln⁡J1.83 \ln J, the logarithm of the number of digits, which is the logarithm of the logarithm of NN. That series diverges too, at a rate nobody could observe by adding terms.

Pólya’s theorem in a harmonic series

One or two balances diverge, three converge. d=1: 10:10.6486, 100:38.7775, 1000:127.6068, 10000:408.5012, 100000:1296.7789; d=2: 10:5.1376, 100:9.3291, 1000:13.5442, 10000:17.7628, 100000:21.9818; d=3: 10:2.5047, 100:3.1907, 1000:3.4134, 10000:3.4841, 100000:3.5064; d=4: 10:1.1286, 100:1.2504, 1000:1.2634, 10000:1.2647, 100000:1.2649
Fig. 5 ln⁡10\ln 10 times the share of jj-digit numbers with one, two, three and four pairs of digits balanced, summed over every length up to 100,000 digits. One and two balances diverge; three and four converge.

The pattern now asks to be pushed. With dd independent balances — 7s against 3s, 1s against 2s, 5s against 6s, 4s against 8s — the counter is a lazy walk in dd dimensions, and the chance of being home after jj steps is about (0.4πj)−d/2(0.4\pi j)^{-d/2}. The series of block sums then behaves like ∑jj−d/2\sum_j j^{-d/2}, which diverges when d/2≤1d/2 \le 1 and converges when d/2>1d/2 > 1. The figure computes the shares exactly to 4,000 digits, by counting the arrangements in which every pair balances, continues them with the walk’s return chance beyond, and sums ln⁡10\ln 10 times the shares to 100,000 digits. One balance has passed 1,296 by then and is climbing like a square root; two have reached 21.98 and are climbing like a logarithm; three have settled at about 3.51 and four at about 1.26, and over the last factor of ten in length the three-balance sum moves by less than a twentieth.

This is Pólya’s recurrence theorem, met in an unexpected place. George Pólya proved in 1921 that a random walk on the integer lattice returns to its starting point with certainty in one and two dimensions and with probability less than one in three or more, and a walk that comes home drew the reason: the expected number of returns is the sum of the return chances, ∑jj−d/2\sum_j j^{-d/2}, which is infinite exactly when d≤2d \le 2. The harmonic series thinned by dd balances is that same sum with every term multiplied by ln⁡10\ln 10. Whether the series converges is whether the walk is recurrent, and the numbers with as many 7s as 3s, as many 1s as 2s and as many 5s as 6s form a convergent series for the same reason that a drunkard in space may never find the way home.

The figure’s sums are not quite the thinned series. They take each block to be ln⁡10\ln 10 times the share of survivors, which ignores the leading-digit effect the exact computation sees; that changes each term by a factor tending to one, and so it can change the totals but not the question of convergence. The exact block sums for one and two balances, in the previous figure, confirm that the factor does tend to one.

Digits that add up to a prime

Digit sums that are prime thin the series by a logarithm. Sⱼ·ln(4.5j)/ln10 at j=5:0.8631, 10:0.9137, 25:0.9345, 50:0.9501, 100:1.0558, 150:0.9890; partial sum 62.4017.
Fig. 6 The sum of 1/n1/n over the jj-digit numbers whose digits add up to a prime, computed exactly for every length to 150 digits, divided by ln⁡10/ln⁡(4.5j)\ln 10/\ln(4.5j). The ratio stays near 1, so the blocks shrink only like one over a logarithm.

The second rule the earlier essay named counts too, with a different counter. The state is the digit sum so far, and a jj-digit number has a digit sum between 1 and 9j9j; the recursion carries a set of power sums for each, about 1,350 of them at 150 digits, and keeps the numbers whose final digit sum is a prime.

The digit sum of a typical jj-digit number is about 4.5j4.5j, spread over a window a few times 8.25j\sqrt{8.25j} wide, and near 4.5j4.5j the primes have density about 1/ln⁡(4.5j)1/\ln(4.5j), as counting what has no formula found for the primes everywhere. So the block sums should be about ln⁡10/ln⁡(4.5j)\ln 10/\ln(4.5j), and the figure divides the exact block sums by that prediction. The ratio stays close to one, averaging 1.0671.067 over the last twenty blocks, and it wobbles: the window of likely digit sums is only a few dozen wide, and over a window that narrow the primes are visibly uneven — between 600 and 660, for instance, there are eleven primes where the density predicts nine. The wobble is the primes’ own irregularity, seen through a harmonic series.

So these blocks shrink like one over the logarithm of the length, far more slowly than any power, and the partial sums grow like the number of digits divided by its logarithm. This series diverges almost as fast as the harmonic series itself — about a sixth of the full series’ gain per digit at 120 digits, a share falling only logarithmically — which is why it overtakes the balanced series in the hero and leaves it behind. The two rules sit at different places on one scale. A finite automaton makes the share decay geometrically; a walk in dd dimensions makes it decay like j−d/2j^{-d/2}; a test of primality on a sum makes it decay like 1/ln⁡j1/\ln j; and the series converges only for the first and for d≥3d \ge 3.

What the computation settles and what it leaves

The block sums are exact up to rounding, by a recursion checked against ten million directly added terms, and they extend to 120 digits for the hero, 80 for the rates and 150 for the digit sums; nothing beyond those lengths is computed term by term or by recursion. The divergence of the balanced series is not read off the curves, which no finite computation could show; it follows from the local limit theorem, which says the walk’s return chance is 1/0.4πj1/\sqrt{0.4\pi j} to within a factor tending to one, together with the comparison ∑j−1/2=∞\sum j^{-1/2} = \infty. The convergence for three balances follows the same way from ∑j−3/2<∞\sum j^{-3/2} < \infty. The figures show the constants arriving where the theorem puts them, which is evidence the computation is right, not proof that the series behaves.

The values of the convergent series are not computed exactly. The three-balance and four-balance totals in the figure are ln⁡10\ln 10 times shares, so they estimate the true sums without leading-digit corrections, and no figure here gives the sum of 1/n1/n over the numbers with three balanced pairs to more than about one significant figure. Doing so needs the recursion carried over a three-dimensional array of balances, which grows like the cube of the length and becomes expensive within a few dozen digits.

And the digit-sum series’ divergence rests on the prime number theorem applied to numbers near 4.5j4.5j, with the window of digit sums growing like j\sqrt j. That the ratio in the last figure tends to one, rather than merely staying near it, needs the primes to be evenly spread over windows of width j\sqrt j around 4.5j4.5j — which is true, but is a theorem about primes in short intervals, of the kind the longest wait for a prime showed can be delicate.

Still open: rules with no counter at all

Every rule here is decided by a counter, finite or infinite, read along the digits from left to right, and for every such rule the series’ fate is decided by how fast the counter’s chance of ending in an accepted state decays. That covers a great deal, but not everything. Keep only the numbers whose digits, read as a number in base three, are prime; or the numbers nn for which the nn-th digit of π\pi is a 7; or the numbers that are not the sum of two squares. The first two have no counter of this kind at all, and the third has one only after factoring. For rules like these the share of survivors among jj-digit numbers need not decay in any regular way, and whether the thinned harmonic series converges has to be settled by whatever is known about the rule, one case at a time.

There is also a finer question about the rules that do have counters. A coin in front of every term found a harmonic series whose fate was decided by the squares of its terms; here the fate is decided by a walk, and both say that thinning or signing the terms changes the answer only through how fast a probability decays. Kempner’s series converge to totals that the earlier essay matched to the waiting time for a string, ln⁡10\ln 10 times the wait plus a leading-digit correction. The three-balance series converges too, and its total is presumably ln⁡10\ln 10 times something like the expected number of returns of a lazy walk in three dimensions, plus a correction — Watson’s integrals give that expected number exactly for the simple walk — but the correction depends on the leading digit in a way no formula here captures. A closed expression for the sum of 1/n1/n over the numbers with three balanced pairs is not known, and it is not obvious that one exists.

Counting is what lets the sum run

Thin the harmonic series by a rule that a finite automaton can check and the blocks shrink geometrically, so the series converges; thin it by a rule that has to count, and the blocks shrink only as fast as the counter’s chance of ending in the right place. For as many 7s as 3s that chance is a lazy walk’s return probability, 1/0.4πj1/\sqrt{0.4\pi j}, the blocks times j\sqrt j settle at 2.05412.0541, and the series diverges like log⁡N\sqrt{\log N}. With dd balances the walk is dd-dimensional and the series diverges for dd of one or two and converges for three — Pólya’s recurrence theorem, line for line. And when the digits must add up to a prime the blocks shrink like one over a logarithm, and the series runs on nearly as fast as the one it was cut from.

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.

Convergence rateExact arithmeticFinite automatonHarmonic seriesLogarithmPrimesRandom walk