Analysis

The digits a slow series gets wrong

Leibniz's series 4(1 − 1/3 + 1/5 − …) is notoriously slow: after 500,000 terms it is off by two millionths, so its sixth decimal is wrong. But the seventh to sixteenth decimals are right, and so are most of the next forty; of the first sixty only ten are wrong, at isolated places. The error is 2/10⁶ − 2/10¹⁸ + 10/10³⁰ − 122/10⁴² + 2770/10⁵⁴ − …, and the numbers 1, 1, 5, 61, 1385 are the Euler numbers, the coefficients of the secant. The series has not become fast. Its error has a structure, a half-million is a round number, and an integral with a hyperbolic cosine in it explains both.

Worth reading first: Turning a slow series geometric · The tangent counts zigzags.

The series 1−13+15−17+⋯=π41 - \tfrac13 + \tfrac15 - \tfrac17 + \cdots = \tfrac{\pi}{4}, found by Madhava in India and rediscovered by Gregory and Leibniz, and summed at its endpoint only with the care that Abel’s theorem supplies, is the textbook example of a series that converges too slowly to use, and the series everything else is measured against — the geometric one — is the opposite case, gaining a fixed number of digits with every term. Its terms shrink like 1/(2k)1/(2k), and an alternating series with terms that size is in error, after NN terms, by about half the next term: to get π\pi to six decimals by summing it takes about a million terms. Turning a slow series geometric measured what acceleration methods do to it, and the answer was a great deal; left alone, it gains one digit for every tenfold increase in work, and so does its neighbour the sum after Leibniz’s, Catalan’s constant 1−19+125−⋯1 - \tfrac19 + \tfrac1{25} - \cdots.

So it is a surprise to sum exactly 500,000 terms, multiply by four, and look at the result to sixty decimal places. The sixth decimal is wrong, as the size of the error predicts: the partial sum is 3.141590…, and π\pi is 3.141592…. But the next ten decimals are right. So are most of the forty after those. Of the first sixty decimals, only ten differ from π\pi, and they come in small clusters separated by long correct stretches.

The phenomenon was noticed by Joseph North in 1988 and explained the next year by Jonathan Borwein, Peter Borwein and Karl Dilcher. The explanation is short and exact, and it says the clusters of wrong digits are the Euler numbers — the same numbers that count alternating permutations — written out in decimal. This essay computes the partial sums exactly, in integer arithmetic to ninety decimals, and draws the structure the explanation predicts.

Sixty decimals, ten of them wrong

Five hundred thousand terms of Leibniz's series. S = 3.141590653589793240462643383269502884197291399375103050974944; wrong at 6,17,18,29,40,41,42,51,52,53
Fig. 1 π and the first 500,000 terms of Leibniz’s series, to sixty decimals. Only ten digits differ (shaded), and six terms built from the Euler numbers account for the whole difference to seventy decimals.

The figure writes the two numbers one above the other in groups of five. The partial sum SS is 3.14159 06535 89793 24046 26433 83269 50288 41972 91399 37510 30509 74944, and π\pi is 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944. The disagreements are at decimals 6, 17 and 18, 29, 40 to 42 and 51 to 53. Everything else agrees.

Subtracting the two numbers explains the pattern. The difference π−S\pi - S is

π−S=2106−21018+101030−1221042+27701054−⋯ ,\pi - S = \frac{2}{10^{6}} - \frac{2}{10^{18}} + \frac{10}{10^{30}} - \frac{122}{10^{42}} + \frac{2770}{10^{54}} - \cdots,

a sum of whole numbers times powers of ten, each power twelve places beyond the last. Each term disturbs only the few digits where it lands: a 2 at the sixth place, a 2 at the eighteenth, which with a borrow touches the seventeenth too, a 10 at the twenty-ninth and thirtieth, 122 at the fortieth to forty-second, 2,770 at the fifty-first to fifty-fourth. In between, the partial sum is exactly π\pi. The figure’s check is that six terms of this form, with the numerators below, reproduce the difference to seventy decimals.

The numerators are 2, −2, 10, −122, 2,770 and −101,042: twice 1, −1, 5, −61, 1,385, −50,521. These are the Euler numbers, the coefficients in the series for the secant, sec⁡x=1+x22!+5x44!+61x66!+⋯\sec x = 1 + \tfrac{x^2}{2!} + \tfrac{5x^4}{4!} + \tfrac{61x^6}{6!} + \cdots, with alternating signs. The secant has turned up in the error of a series for π\pi, and the number 500,000 was chosen so that twice it is a million, which makes every term of the error a whole number over a power of ten.

An integral with a hyperbolic cosine

The appearance of the secant is not a coincidence, and the derivation fits in a few lines. Each term of the series is an integral: 12k+1=∫0∞e−(2k+1)t dt\tfrac{1}{2k + 1} = \int_0^\infty e^{-(2k+1)t}\,dt. The tail of the series after NN terms is therefore a geometric series under an integral sign,

∑k≥N(−1)k2k+1=(−1)N∫0∞e−(2N+1)t1+e−2t dt=(−1)N∫0∞e−2Nt2cosh⁡t dt,\sum_{k \ge N} \frac{(-1)^k}{2k+1} = (-1)^N \int_0^\infty \frac{e^{-(2N+1)t}}{1 + e^{-2t}}\,dt = (-1)^N \int_0^\infty \frac{e^{-2Nt}}{2\cosh t}\,dt,

the oldest trick for alternating sums, a geometric series summed inside an integral, used here for the tail rather than the whole.

The factor e−2Nte^{-2Nt} is negligible except for tt near 0, so the integral is governed by the behaviour of 1/cosh⁡t1/\cosh t there. That function is the hyperbolic secant, and its Taylor series is the secant’s with the signs alternating: sech⁡t=∑mE2m t2m/(2m)!\operatorname{sech} t = \sum_m E_{2m}\, t^{2m}/(2m)!, with E0=1E_0 = 1, E2=−1E_2 = -1, E4=5E_4 = 5, E6=−61E_6 = -61. Integrating term by term against e−Mte^{-Mt}, with M=2NM = 2N, each power t2m/(2m)!t^{2m}/(2m)! contributes exactly 1/M2m+11/M^{2m+1}. So for even NN

π−4SN  ∼  2∑m≥0E2m(2N)2m+1=22N−2(2N)3+10(2N)5−122(2N)7+⋯ ,\pi - 4S_N \;\sim\; 2\sum_{m \ge 0} \frac{E_{2m}}{(2N)^{2m+1}} = \frac{2}{2N} - \frac{2}{(2N)^3} + \frac{10}{(2N)^5} - \frac{122}{(2N)^7} + \cdots,

and for odd NN the same with the sign reversed. With 2N=1062N = 10^6 this is the expansion in the first figure. The structure was always there; choosing NN so that 2N2N is a power of ten makes it legible in decimal.

Each correction, in turn

The error of Leibniz's series rescaled. m0: 1.000,1.000,1.000,1.000; m1: -1.000,-1.000,-1.000,-1.000; m2: 4.998,5.000,5.000,5.000; m3: -60.965,-60.991,-60.996,-60.998
Fig. 2 The error after N terms, for even N to 400, multiplied by 2N/2 — and then, with each known term of the expansion removed, the remainder multiplied by the next odd power of 2N. The four curves settle on 1, −1, 5 and −61.

The expansion can be checked one term at a time, without relying on a single fortunate NN. Take the error π−4SN\pi - 4S_N for every even NN from 10 to 400 and multiply it by 2N/2=N2N/2 = N: the result tends to 1, the first Euler number, as the top-left panel shows. Subtract the first term, 2/(2N)2/(2N), and multiply what is left by (2N)3/2(2N)^3/2: the result tends to −1-1. Subtract the second term and multiply by (2N)5/2(2N)^5/2: the result tends to 5. One more: −61-61.

Each panel is a sharper test than the last, because each residual is smaller and each scaling factor larger, so a wrong coefficient at any stage would send the curve away from its line. All four curves converge, and they converge from the side and at the rate the next term predicts: at N=100N = 100 the fourth panel reads −60.965-60.965, short of −61-61 by 1385/(2N)2=0.0351385/(2N)^2 = 0.035, the next Euler number making itself felt. The error of Leibniz’s series is, to every order that can be checked, the Euler numbers divided by powers of 2N2N.

This is a characteristic way for a slow series to behave. Its error is not random-looking or erratic; it is a smooth function of NN with an expansion in inverse powers, and the expansion’s coefficients carry information about the function the series came from. The same is true of the sum that never stops growing, the harmonic series, whose partial sums differ from ln⁡N+γ\ln N + \gamma by 12N−112N2+⋯\tfrac{1}{2N} - \tfrac{1}{12N^2} + \cdots with Bernoulli numbers in the coefficients, and for exactly the same reason: an integral representation and a Taylor series near zero.

A correction from Kerala

The expansion was not a modern discovery in every sense. The astronomers of the Kerala school, following Madhava in the fourteenth century, knew that the series for π/4\pi/4 converges slowly and added an end correction to its partial sums: stop after nn terms and add, with the sign of the next term, a fraction F(n)F(n). Three corrections appear in their texts, F1(n)=14nF_1(n) = \tfrac{1}{4n}, F2(n)=n4n2+1F_2(n) = \tfrac{n}{4n^2 + 1} and F3(n)=n2+14n3+5nF_3(n) = \tfrac{n^2 + 1}{4n^3 + 5n}, each more accurate than the last.

Read against the Euler-number expansion, the three corrections are its first terms in disguise. With M=2nM = 2n, four times F1F_1 is 2/M2/M, the leading term. Four times F2F_2 is 2M⋅11+1/M2=2M−2M3+⋯\tfrac{2}{M} \cdot \tfrac{1}{1 + 1/M^2} = \tfrac{2}{M} - \tfrac{2}{M^3} + \cdots, which matches the first two terms. Four times F3F_3 is 2M⋅1+4/M21+5/M2=2M−2M3+10M5−⋯\tfrac{2}{M} \cdot \tfrac{1 + 4/M^2}{1 + 5/M^2} = \tfrac{2}{M} - \tfrac{2}{M^3} + \tfrac{10}{M^5} - \cdots, which matches three: the Euler numbers 1, −1 and 5. The corrections are rational functions whose expansions agree with the true error as far as they go, which is to say they are the early convergents of a continued fraction for it — rational approximations of the kind that reach past a Taylor series’ radius because a denominator can carry what a polynomial cannot.

The effect is dramatic at small nn. Ten terms of the series give π\pi with an error of about 0.0998. With F1F_1 added the error is 0.00025; with F2F_2, 0.0000024; with F3F_3, 0.00000005 — seven correct decimals from ten terms, where the bare series would need tens of millions. The Kerala astronomers did not have the Euler numbers or the hyperbolic secant. They had the right corrections, and the corrections encode the same structure that makes the wrong digits at half a million terms fall where they do.

An expansion that does not converge

The Euler-number expansion diverges. N=2: best m=3 at log10 -2.4; N=4: best m=7 at log10 -5.3; N=6: best m=10 at log10 -8.1; N=10: best m=16 at log10 -13.7
Fig. 3 How close the expansion comes to the true error after N = 2, 4, 6 and 10 terms, as more of its terms are used. The remaining error falls to a best point and then grows without limit.

The expansion has one property that the first figure hides. It does not converge. The hyperbolic secant has poles at t=±iπ/2t = \pm i\pi/2, so its Taylor series has radius of convergence π/2\pi/2, and its coefficients grow at the rate that forces, since a Taylor series can reach no further than the nearest singularity: ∣E2m∣|E_{2m}| is about 2(2m)!(2/π)2m+12 (2m)! (2/\pi)^{2m+1}, faster than any power. For fixed NN, the terms E2m/(2N)2m+1E_{2m}/(2N)^{2m+1} shrink at first, while (2N)2m(2N)^{2m} outruns the Euler numbers, and then grow, once the factorial takes over.

The figure shows what that means in practice for small NN. After two terms of Leibniz’s series, using the expansion improves the estimate of the error for three terms and then makes it worse; after ten terms, the best is reached after sixteen terms of the expansion, at an error of about 10−13.710^{-13.7}, and beyond that the corrections grow. The best point moves out roughly as 1.6N1.6N, and the smallest error it reaches is about e−πNe^{-\pi N} — the factor that comes from the poles of sech⁡\operatorname{sech} at distance π/2\pi/2, felt through e−2Nte^{-2Nt}.

So the expansion is asymptotic: for each fixed number of its terms, the error of using them falls faster than the next power of 1/N1/N as NN grows, but for each fixed NN there is a limit to how well it can do. With N=500,000N = 500{,}000 the limit is around e−1,570,000e^{-1{,}570{,}000}, so far away that the divergence is invisible in any number of decimals anyone will print. That is why the first figure looks as if it converges: its NN is large enough that the turning point is a million terms out.

The same accident for ln 2

Five hundred thousand terms of the series for ln 2. A = 0.693146180560945309417230121458176584075500134088255254128616; wrong at 6,11,12,24,35,36,46,47,48,57,59,60
Fig. 4 ln 2 and the first 500,000 terms of 1 − 1/2 + 1/3 − …, to sixty decimals. Only twelve digits differ; the error is 1/(2N) followed by the tangent numbers 1, 2, 16, 272 over powers of N.

The argument used nothing particular to π\pi except the integral representation, and the same calculation works for the series 1−12+13−⋯=ln⁡21 - \tfrac12 + \tfrac13 - \cdots = \ln 2. After NN terms, with NN even, its tail is ∫0∞e−Nt/(1+e−t) dt\int_0^\infty e^{-Nt}/(1 + e^{-t})\,dt, and 1/(1+e−t)1/(1 + e^{-t}) is 12+12tanh⁡(t/2)\tfrac12 + \tfrac12\tanh(t/2). The hyperbolic tangent’s Taylor coefficients are, up to powers of 2 and factorials, the tangent numbers 1, 2, 16, 272, 7,936, which count the alternating permutations of odd length as the Euler numbers count those of even length. So the error is 12N−14N2+18N4−14N6+1716N8−⋯\tfrac{1}{2N} - \tfrac{1}{4N^2} + \tfrac{1}{8N^4} - \tfrac{1}{4N^6} + \tfrac{17}{16N^8} - \cdots, with only even powers after the first.

The figure sums the first 500,000 terms exactly and compares the result with ln⁡2\ln 2. With N=5×105N = 5 \times 10^5 the terms of the error are 10−610^{-6}, 10−1210^{-12}, 2×10−242 \times 10^{-24}, 16×10−3616 \times 10^{-36} and 272×10−48272 \times 10^{-48}, and the wrong digits fall at decimals 6, 11 and 12, 24, 35 and 36, 46 to 48, and near the sixtieth. Twelve of sixty are wrong, and the tangent numbers are visible in the shaded clusters exactly as the Euler numbers were in Leibniz’s series. The check in the figure is that five terms of the expansion account for the difference to forty-five decimals.

The two series sit together in the theory of alternating permutations. André’s theorem says that the up-down arrangements of nn objects are counted by the coefficients of sec⁡x+tan⁡x\sec x + \tan x: the secant for even nn, the tangent for odd. Here the secant governs the error of the series for π\pi, and the tangent the error of the series for ln⁡2\ln 2. The genuinely surprising connection is that an estimate of how wrong two slow series are, read off in decimal, is a table of how many ways there are to arrange numbers in a zigzag.

Why the number of terms has to be round

Why the number of terms has to be round. 5000000: 44/50 right, first wrong 7; 500000: 43/50 right, first wrong 6; 50000: 40/50 right, first wrong 5; 400000: 20/50 right, first wrong 6; 625000: 31/50 right, first wrong 6; 314159: 9/50 right, first wrong 6; 271828: 7/50 right, first wrong 5
Fig. 5 The first fifty decimals of Leibniz’s series after seven numbers of terms, every digit that disagrees with π shaded. When 2N is a power of ten most digits are right; at 314,159 and 271,828 terms almost none are.

Nothing in the expansion depends on 2N2N being a power of ten. What depends on it is whether the error is easy to see in decimal. The figure computes the partial sum for seven values of NN and shades every one of the first fifty decimals that disagrees with π\pi. With 5,000,000, 500,000 and 50,000 terms, so that 2N2N is 10710^7, 10610^6 or 10510^5, the error’s terms are whole numbers times powers of ten and 44, 43 and 40 of the fifty digits are right.

With 400,000 and 625,000 terms, 2N2N is 8×1058 \times 10^5 or 1.25×1061.25 \times 10^6. The terms 2E2m/(2N)2m+12E_{2m}/(2N)^{2m+1} are still finite decimals, because 2N2N has no prime factors but 2 and 5, but they are long ones — 1/(8×105)31/(8 \times 10^5)^3 runs to many digits — and the clusters of wrong digits spread and overlap. Twenty and thirty-one of fifty are right. With 314,159 and 271,828 terms, 2N2N has other prime factors, every term of the error is an infinite decimal, and the same tiny error smears across every place: after the first five or six decimals, the partial sum agrees with π\pi only where a digit matches by chance, about one place in ten.

So the partial sum after 314,159 terms is not a worse approximation to π\pi than the one after 500,000 in any meaningful sense; it is a little worse, as the extra terms predict, and its error has exactly the same structure. It is only harder to read. A half-million is a lens: it lines up the error’s expansion with the decimal system, so that each term occupies its own block of digits.

What sixty digits cannot establish

The figures are exact computations, and they show the expansion holding to every order checked and for every NN tried. The proof that it holds for every NN and every order is the integral argument, which the figures illustrate but do not carry out. In particular, the first figure’s seventy-decimal agreement is a check on six terms at one value of NN; the asymptotic statement — that the error after MM terms of the expansion is of the order of the next term, for every MM — is Watson’s lemma applied to sech⁡\operatorname{sech}, not something sixty digits can establish.

The figures also cannot make the series useful. Seeing the error’s structure suggests subtracting the first few terms of the expansion from the partial sum, and that does give a vastly better estimate of π\pi from 500,000 terms — but it is a form of acceleration, and the methods measured in turning a slow series geometric do the same job far more cheaply, from forty terms rather than half a million. The digit pattern is a curiosity about how a slow series is wrong, not a way to make it fast.

And the choice of base matters to the picture and to nothing else. In base 2, the clusters would appear for NN a power of 2; in base 12 for NN with 2N2N a power of 12. A reader who works in decimal sees the Euler numbers at N=500,000N = 500{,}000 because of the base, and the Euler numbers are there at every NN whatever the base.

Still open: what kind of number the corrected sum is

The expansion raises a natural question about the numbers it produces. The partial sums SNS_N are rational, and the corrections 2E2m/(2N)2m+12E_{2m}/(2N)^{2m+1} are rational, so subtracting any finite number of them from 4SN4S_N gives a rational approximation to π\pi of a very particular shape. How good can such approximations be, as a function of their denominators? For fixed NN the best is limited by the divergence, near e−πNe^{-\pi N}, while the denominators grow like the least common multiple of the odd numbers up to 2N2N, about e2Ne^{2N}; whether combinations of partial sums and corrections can be found that approximate π\pi unusually well relative to their size — the kind of question behind proofs of irrationality — is not settled by anything here.

A second question concerns which other series show the same effect so cleanly. Any alternating series ∑(−1)kf(k)\sum (-1)^k f(k) whose ff is a Laplace transform has an error expansion governed by the Taylor coefficients of a hyperbolic function, and the Borweins and Dilcher worked out several examples. For series that are not alternating, such as ∑1/k2\sum 1/k^2, the expansion involves Bernoulli numbers, whose fractions 16\tfrac16, 130\tfrac1{30}, 142\tfrac1{42} are not finite decimals, so no round NN lines them up into blocks; for series whose terms are not smooth in kk — sums over primes, say — no such expansion exists, and the digits of a partial sum are as ragged as they look. Exactly which series have a “digit lens” at round NN, and how many decimals it can align, is a question that has been explored case by case rather than answered.

Ten wrong digits in sixty

After 500,000 terms Leibniz’s series gives 3.14159065358979324046…, wrong at decimals 6, 17, 18, 29, 40–42 and 51–53 of the first sixty and right everywhere else. The tail of the series is ∫0∞e−2Nt/(2cosh⁡t) dt\int_0^\infty e^{-2Nt}/(2\cosh t)\,dt, so its error is 2∑E2m/(2N)2m+12\sum E_{2m}/(2N)^{2m+1} with the Euler numbers 1, −1, 5, −61, 1,385 from the secant — confirmed term by term for NN to 400, and to seventy decimals at N=500,000N = 500{,}000, where 2N=1062N = 10^6 puts each term in its own block of digits. The expansion diverges, with a best error near e−πNe^{-\pi N}; the series for ln⁡2\ln 2 does the same with the tangent numbers; and at a ragged NN like 314,159 the identical structure smears across every decimal. The series is as slow as ever. Its error is a table of zigzags.

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.

Alternating seriesAsymptotic expansionConvergence rateEuler numberLaplace transformPartial sumPi