/
euler_bbp.tex
599 lines (511 loc) · 23.3 KB
/
euler_bbp.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
\documentclass[11pt]{article}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{latexsym,amsfonts,amsthm,amsmath,amssymb}
\usepackage{hyperref}
\hypersetup{hidelinks}
\usepackage{xcolor}
\usepackage{verbatim}
\usepackage{enumerate}
\usepackage{tabularx,graphicx}
% Theorem environments:
\newtheorem{Thm}{Theorem}
\newtheorem{Cor}{Corollary}
\newtheorem{Def}{Definition}
\newtheorem{Prop}{Proposition}
\newtheorem{Claim}{Claim}
\newtheorem{Lemma}{Lemma}
% Formatting:
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\thefootnote}{\alph{footnote}}
\parindent=0.25in
\setlength{\parsep}{30pt}
\pagestyle{empty}
%% \documentclass{article}
%% \usepackage{amsmath}
%% \title{Euler found the first BBP formula in 1779}
%% \author{Nick Craig-Wood}
%% \date{\today}
%% \begin{document}
%% \maketitle
\begin{document}
%\iffalse %comment out for review
\begin{center}
{\LARGE Euler found the first binary digit extraction formula for $\pi$ in 1779} \\
\bigskip\bigskip
{Nick Craig-Wood \\ {\tt nick@craig-wood.com}}
\end{center}
\medskip
\begin{abstract}\noindent
In 1779 Euler discovered two formulas for $\pi$ which can be used to calculate any binary digit of $\pi$ without calculating the previous digits. Up until now it was believed that the first formula with the correct properties (known as a BBP-type formula) for this calculation was published by Bailey, Borwein and Plouffe in 1997.
\end{abstract}
\medskip
%\fi %comment out for review
\section{Introduction}
In 1997 Bailey, Borwein and Plouffe published their paper \cite{BBP} demonstrating how to calculate any binary or hexadecimal digit of $\pi$ without calculating the previous digits. Remarkably this algorithm needs constant space and runs in $O(n \log{n})$ time making it extremely practical.
The calculation revolves about this equation which was discovered using a computer-aided search using the integer relation algorithm PSLQ \cite{PSLQ}.
\begin{equation} \label{eq:originalbbp}
\pi = \sum_{n = 0}^\infty \left[ \frac{1}{16^n} \left( \frac{4}{8n + 1} - \frac{2}{8n + 4} - \frac{1}{8n + 5} - \frac{1}{8n + 6} \right) \right]
\end{equation}
This style of equation is now known as a BBP-type formula after its inventors Bailey, Borwein and Plouffe.
What the authors didn't know is that Leonhard Euler (1707-1783) discovered two BBP-type formulas which would have worked just as well as the formula for which they spent a lot of computer time searching.
Euler's 1779 paper ``De novo genere serierum rationalium et valde convergentium quibus ratio peripheriae ad diametrum exprimi potest'' \cite{E706latin} (E706)
(as translated by Jordan Bell with the English title ``On a new type of rational and highly convergent series, by which the ratio of the circumference to the diameter is able to be expressed'') contains the formulas. Those who wish to read more about the history of this paper should consult Ed Sandifer's article \cite{Sandifer} from his ``How Euler Did It'' series.
It isn't immediately obvious what the BBP-type formula is as Euler left it in expanded form:
\begin{equation*}
\pi = \left \{
\begin{aligned}
2 &( 1 &- \tfrac{1}{5}\cdot\tfrac{1}{4} &&+ \tfrac{1}{9}\cdot\tfrac{1}{4^2} &&- \tfrac{1}{13}\cdot\tfrac{1}{4^3} &&+ \tfrac{1}{17}\cdot\tfrac{1}{4^4} &&- etc. ) \\
+ 1 &( 1 &- \tfrac{1}{3}\cdot\tfrac{1}{4} &&+ \tfrac{1}{5}\cdot\tfrac{1}{4^2} &&- \tfrac{1}{7}\cdot\tfrac{1}{4^3} &&+ \tfrac{1}{9}\cdot\tfrac{1}{4^4} &&- etc. ) \\
+ 1 &( \tfrac{1}{3} &- \tfrac{1}{7}\cdot\tfrac{1}{4} &&+ \tfrac{1}{11}\cdot\tfrac{1}{4^2} &&- \tfrac{1}{15}\cdot\tfrac{1}{4^3} &&+ \tfrac{1}{19}\cdot\tfrac{1}{4^4} &&- etc. )
\end{aligned}
\right.
\end{equation*}
But in more compact notation it is this, where the similarities to equation~\eqref{eq:originalbbp} are immediately apparent:
\begin{equation} \label{eq:eulerbbp}
\pi = \sum_{n = 0}^\infty \left[ \frac{(-1)^n}{4^n} \left( \frac{2}{4n + 1} + \frac{2}{4n + 2} + \frac{1}{4n + 3} \right) \right].
\end{equation}
This was discovered independently by Adamchik and Wagon \cite{Adamchik_Wagon_1997} in 1997.
Euler also produced this formula \footnote{Note that this equation is incorrect in the original paper and the translation - the bottom left term is printed as $1$ whereas it should be $\frac{1}{3}$ as shown here.}:
\nopagebreak
\begin{equation*}
\pi = \left \{
% \begin{array}{@{}r@{}r@{}r@{}r@{}r@{}r}
\begin{aligned}
% \begin{alignedat}{8}
%% &+ & 2 &( 1 &-& \tfrac{1}{5}&\cdot&\tfrac{1}{64} &+&& \tfrac{1}{9} &\cdot&&\tfrac{1}{64^2} &-&& \tfrac{1}{13}&\cdot&&\tfrac{1}{64^3} &- etc. ) \\
%% &+& \tfrac{1}{2} &( 1 &-& \tfrac{1}{3}&\cdot&\tfrac{1}{64} &+&& \tfrac{1}{5} &\cdot&&\tfrac{1}{64^2} &-&& \tfrac{1}{7} &\cdot&&\tfrac{1}{64^3} &- etc. ) \\
%% &+& \tfrac{1}{4} &( \tfrac{1}{3} &-& \tfrac{1}{7}&\cdot&\tfrac{1}{64} &+&& \tfrac{1}{11}&\cdot&&\tfrac{1}{64^2} &-&& \tfrac{1}{15}&\cdot&&\tfrac{1}{64^3} &- etc. ) \\
%% &+& \tfrac{1}{2} &( 1 &-& \tfrac{1}{5}&\cdot&\tfrac{1}{1024} &+&& \tfrac{1}{9} &\cdot&&\tfrac{1}{1024^2} &-&& \tfrac{1}{13}&\cdot&&\tfrac{1}{1024^3} &- etc. ) \\
%% &+& \tfrac{1}{16} &( 1 &-& \tfrac{1}{3}&\cdot&\tfrac{1}{1024} &+&& \tfrac{1}{5} &\cdot&&\tfrac{1}{1024^2} &-&& \tfrac{1}{7} &\cdot&&\tfrac{1}{1024^3} &- etc. ) \\
%% &+& \tfrac{1}{64} &( \tfrac{1}{3} &-& \tfrac{1}{7}&\cdot&\tfrac{1}{1024} &+&& \tfrac{1}{11}&\cdot&&\tfrac{1}{1024^2} &-&& \tfrac{1}{15}&\cdot&&\tfrac{1}{1024^3} &- etc. )
2 &( 1 &- \tfrac{1}{5}\cdot\tfrac{1}{64} &&+ \tfrac{1}{9}\cdot\tfrac{1}{64^2} &&- \tfrac{1}{13}\cdot\tfrac{1}{64^3} &&- etc. ) \\
+ \tfrac{1}{2} &( 1 &- \tfrac{1}{3}\cdot\tfrac{1}{64} &&+ \tfrac{1}{5}\cdot\tfrac{1}{64^2} &&- \tfrac{1}{7}\cdot\tfrac{1}{64^3} &&- etc. ) \\
+ \tfrac{1}{4} &( \tfrac{1}{3} &- \tfrac{1}{7}\cdot\tfrac{1}{64} &&+ \tfrac{1}{11}\cdot\tfrac{1}{64^2} &&- \tfrac{1}{15}\cdot\tfrac{1}{64^3} &&- etc. ) \\
+ \tfrac{1}{2} &( 1 &- \tfrac{1}{5}\cdot\tfrac{1}{1024} &&+ \tfrac{1}{9}\cdot\tfrac{1}{1024^2} &&- \tfrac{1}{13}\cdot\tfrac{1}{1024^3} &&- etc. ) \\
+ \tfrac{1}{16} &( 1 &- \tfrac{1}{3}\cdot\tfrac{1}{1024} &&+ \tfrac{1}{5}\cdot\tfrac{1}{1024^2} &&- \tfrac{1}{7}\cdot\tfrac{1}{1024^3} &&- etc. ) \\
+ \tfrac{1}{64} &( \tfrac{1}{3} &- \tfrac{1}{7}\cdot\tfrac{1}{1024} &&+ \tfrac{1}{11}\cdot\tfrac{1}{1024^2} &&- \tfrac{1}{15}\cdot\tfrac{1}{1024^3} &&- etc. )
% \end{alignedat}
\end{aligned}
% \end{array}
\right.
\end{equation*}
With a bit of effort (as will be described below) this can be rewritten as:
\begin{equation} \label{eq:eulerbbp2}
\begin{split}
\pi
= \frac{1}{2^{26}} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{27}}{20n+1}
+ \frac{2^{25}}{12n+1}
+ \frac{2^{25}}{10n+1}
+ \frac{2^{24}}{20n+3}
+ \frac{2^{22}}{6n+1} \\
&- \frac{2^{20}}{60n+15}
- \frac{2^{19}}{10n+3}
- \frac{2^{18}}{20n+7}
- \frac{2^{15}}{12n+5} \\
&+ \frac{2^{15}}{20n+9}
+ \frac{2^{12}}{30n+15}
+ \frac{2^{12}}{20n+11}
- \frac{2^{10}}{12n+7} \\
&- \frac{2^{9}}{20n+13}
- \frac{2^{7}}{10n+7}
- \frac{2^{5}}{60n+45}
+ \frac{2^{3}}{20n+17} \\
&+ \frac{2^{2}}{6n+5}
+ \frac{2}{10n+9}
+ \frac{1}{12n+11}
+ \frac{1}{20n+19}
\end{aligned}
\right].
\end{split}
\end{equation}
This is clearly a BBP-type formula and it was discovered independently by Pschill \cite{Arndt2001} in 1999.
\section{Euler's Derivation of Equation (\ref{eq:eulerbbp})}
Starting from the observation $v^4 + 4 = (v^2 + 2v + 2)(v^2 - 2v + 2)$, Euler observed:
\begin{align}
\int_0^x \frac{v^2 + 2v + 2}{v^4 + 4} \,dv \label{eq:integral}
&= \int_0^x \frac{dv}{v^2 - 2v + 2} \\
%&= \left[ -\arctan{(1-v)} \right]_0^x \\
&= -\arctan{(1-x)} + \arctan{1} \\
&= \arctan{\frac{x}{2-x}} \label{eq:rhs}
\end{align}
%% Using the trig identity
%% \begin{equation} \label{eq:arctan}
%% \arctan{x} + \arctan{y} = \arctan{\frac{x + y}{1 - xy}}
%% \end{equation}
%% Euler then produced
%% \begin{align} \label{eq:rhs}
%% \int_0^x \frac{x^2 + 2x + 2}{x^4 + 4} \,dx
%% &= \arctan{\frac{x}{2-x}}
%% \end{align}
%% (Euler actually went straight from equation \eqref{eq:integral} to this result presumably using some previous knowledge.)
Euler then went to work on the left hand side of this equation by expanding $\frac{v^k}{v^4 + 4}$, where $k$ is an integer, as an infinite series by polynomial division.
\begin{align}
\frac{v^k}{v^4 + 4}
&= \sum_{n = 0}^\infty (-1)^n \frac{v^{4n+k}}{4^{n+1}}
\end{align}
Integrating this we get
\begin{align}
\int_0^x \frac{v^k}{v^4 + 4} \, dv
&= \int_0^x \sum_{n = 0}^\infty (-1)^n \frac{v^{4n+k}}{4^{n+1}} \, dv \\
&= \sum_{n = 0}^\infty (-1)^n \frac{x^{4n+k+1}}{(4n+k+1)4^{n+1}}
\end{align}
We can now rewrite the LHS of equation~\eqref{eq:rhs} as
\begin{align}
\int_0^x \frac{v^2 + 2v + 2}{v^4 + 4} \,dv
&= \int_0^x \frac{v^2}{v^4 + 4} \,dv
+ \int_0^x \frac{2v}{v^4 + 4} \,dv
+ \int_0^x \frac{2}{v^4 + 4} \,dv \\
&= \sum_{n = 0}^\infty \frac{(-1)^n}{4^{n+1}} \left[ \label{eq:lhs}
\frac{x^{4n+3}}{4n+3}
+ \frac{2x^{4n+2}}{4n+2}
+ \frac{2x^{4n+1}}{4n+1}
\right]
\end{align}
Equating equation~\eqref{eq:lhs} and equation~\eqref{eq:rhs} Euler produced this infinite series for $\arctan{\frac{x}{2-x}}$:
\begin{align} \label{eq:arctanseries}
\arctan{\frac{x}{2-x}}
&= \sum_{n = 0}^\infty \frac{(-1)^n}{4^{n+1}} \left[
\frac{2x^{4n+1}}{4n+1}
+ \frac{2x^{4n+2}}{4n+2}
+ \frac{x^{4n+3}}{4n+3}
\right]
\end{align}
Euler then substituted $x = 1$ to produce $\arctan{1} = \frac{\pi}{4}$ to create the BBP-type equation \eqref{eq:eulerbbp} directly.
\section{Euler's Derivation of Equation (\ref{eq:eulerbbp2})}
Euler obviously realised that equation~\eqref{eq:arctanseries} had more to give in terms of $\pi$ generating sequences. Equation~\eqref{eq:eulerbbp} generates roughly 4 bits of $\pi$ or $1.2$ decimal digits per iteration. To do better he took this identity that was first discovered by Hutton \cite{Arndt2001} in 1776:
\begin{equation}
\pi = 8 \arctan{\tfrac{1}{3}} + 4 \arctan{\tfrac{1}{7}}.
\end{equation}
He then used equation \eqref{eq:arctanseries} with $x=\frac{1}{2}$ and $x=\frac{1}{4}$ to give series for $\arctan{\frac{1}{3}}$ and $\arctan{\frac{1}{7}}$, respectively. Combining them Euler got:
\iffalse %commented working
\begin{equation}
\begin{split}
\pi
&= 8 \sum_{n = 0}^\infty \frac{(-1)^n}{4^{n+1}} \left[
\frac{2(\frac{1}{2})^{4n+1}}{4n+1}
+ \frac{2(\frac{1}{2})^{4n+2}}{4n+2}
+ \frac{(\frac{1}{2})^{4n+3}}{4n+3}
\right] \\
&+ 4 \sum_{n = 0}^\infty \frac{(-1)^n}{4^{n+1}} \left[
\frac{2(\frac{1}{4})^{4n+1}}{4n+1}
+ \frac{2(\frac{1}{4})^{4n+2}}{4n+2}
+ \frac{(\frac{1}{4})^{4n+3}}{4n+3}
\right]
\end{split}
\end{equation}
Which with a bit of simplification becomes
\fi %commented working
\begin{equation}
\begin{aligned}
\pi
&&=&& \frac{1}{4} &\sum_{n = 0}^\infty \frac{(-1)^n}{64^n} \left[
\frac{8}{4n+1}
+ \frac{4}{4n+2}
+ \frac{1}{4n+3}
\right] \\
&&+&& \frac{1}{64} &\sum_{n = 0}^\infty \frac{(-1)^n}{1024^n} \left[
\frac{32}{4n+1}
+ \frac{8}{4n+2}
+ \frac{1}{4n+3}
\right].
\end{aligned}
\end{equation}
This was as far as Euler went. While we can clearly see it is a BBP-type formula, it isn't yet in the form we expect to see.
To write this as a single BBP-type formula, we can collect groups of terms (five for the first sum, three for the second) to get a common multiplier of $\frac{(-1)^n}{2^{30n}}$.
\begin{equation}
\begin{split}
\pi
&= \frac{1}{4} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{8}{20n+1}
+ \frac{4}{20n+2}
+ \frac{1}{20n+3} \\
-& \frac{8.2^{-6}}{20n+5}
- \frac{4.2^{-6}}{20n+6}
- \frac{1.2^{-6}}{20n+7} \\
+& \frac{8.2^{-12}}{20n+9}
+ \frac{4.2^{-12}}{20n+10}
+ \frac{1.2^{-12}}{20n+11} \\
-& \frac{8.2^{-18}}{20n+13}
- \frac{4.2^{-18}}{20n+14}
- \frac{1.2^{-18}}{20n+15} \\
+& \frac{8.2^{-24}}{20n+17}
+ \frac{4.2^{-24}}{20n+18}
+ \frac{1.2^{-24}}{20n+19} \\
\end{aligned}
\right] \\
&+ \frac{1}{64} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{32}{12n+1}
+ \frac{8}{12n+2}
+ \frac{1}{12n+3} \\
-& \frac{32.2^{-10}}{12n+5}
- \frac{8.2^{-10}}{12n+6}
- \frac{1.2^{-10}}{12n+7} \\
+& \frac{32.2^{-20}}{12n+9}
+ \frac{8.2^{-20}}{12n+10}
+ \frac{1.2^{-20}}{12n+11} \\
\end{aligned}
\right]
\end{split}
\end{equation}
After much simplification, this becomes equation \eqref{eq:eulerbbp2}.
\iffalse % working commented out
\begin{equation}
\begin{split}
\pi
&= \frac{1}{4} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{-2}.8}{20n+1}
+ \frac{2^{-2}.4}{20n+2}
+ \frac{2^{-2}.1}{20n+3} \\
-& \frac{2^{-2}.8.2^{-6}}{20n+5}
- \frac{2^{-2}.4.2^{-6}}{20n+6}
- \frac{2^{-2}.1.2^{-6}}{20n+7} \\
+& \frac{2^{-2}.8.2^{-12}}{20n+9}
+ \frac{2^{-2}.4.2^{-12}}{20n+10}
+ \frac{2^{-2}.1.2^{-12}}{20n+11} \\
-& \frac{2^{-2}.8.2^{-18}}{20n+13}
- \frac{2^{-2}.4.2^{-18}}{20n+14}
- \frac{2^{-2}.1.2^{-18}}{20n+15} \\
+& \frac{2^{-2}.8.2^{-24}}{20n+17}
+ \frac{2^{-2}.4.2^{-24}}{20n+18}
+ \frac{2^{-2}.1.2^{-24}}{20n+19} \\
\end{aligned}
\right] \\
&+ \frac{1}{64} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{-6}.32}{12n+1}
+ \frac{2^{-6}.8}{12n+2}
+ \frac{2^{-6}.1}{12n+3} \\
-& \frac{2^{-6}.32.2^{-10}}{12n+5}
- \frac{2^{-6}.8.2^{-10}}{12n+6}
- \frac{2^{-6}.1.2^{-10}}{12n+7} \\
+& \frac{2^{-6}.32.2^{-20}}{12n+9}
+ \frac{2^{-6}.8.2^{-20}}{12n+10}
+ \frac{2^{-6}.1.2^{-20}}{12n+11} \\
\end{aligned}
\right]
\end{split}
\end{equation}
\begin{equation}
\begin{split}
\pi
&= \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{1}}{20n+1}
+ \frac{2^{0}}{20n+2}
+ \frac{2^{-2}}{20n+3} \\
-& \frac{2^{1}.2^{-6}}{20n+5}
- \frac{2^{0}.2^{-6}}{20n+6}
- \frac{2^{-2}.2^{-6}}{20n+7} \\
+& \frac{2^{1}.2^{-12}}{20n+9}
+ \frac{2^{0}.2^{-12}}{20n+10}
+ \frac{2^{-2}.2^{-12}}{20n+11} \\
-& \frac{2^{1}.2^{-18}}{20n+13}
- \frac{2^{0}.2^{-18}}{20n+14}
- \frac{2^{-2}.2^{-18}}{20n+15} \\
+& \frac{2^{1}.2^{-24}}{20n+17}
+ \frac{2^{0}.2^{-24}}{20n+18}
+ \frac{2^{-2}.2^{-24}}{20n+19} \\
+& \frac{2^{yes-1}}{12n+1}
+ \frac{2^{-3}}{12n+2}
+ \frac{2^{-6}}{12n+3} \\
-& \frac{2^{-1}.2^{-10}}{12n+5}
- \frac{2^{-3}.2^{-10}}{12n+6}
- \frac{2^{-6}.2^{-10}}{12n+7} \\
+& \frac{2^{-1}.2^{-20}}{12n+9}
+ \frac{2^{-3}.2^{-20}}{12n+10}
+ \frac{2^{-6}.2^{-20}}{12n+11} \\
\end{aligned}
\right]
\end{split}
\end{equation}
\begin{equation}
\begin{split}
\pi
&= \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{1}}{20n+1}
+ \frac{2^{-1}}{10n+1}
+ \frac{2^{-2}}{20n+3} \\
-& \frac{2^{-5}}{20n+5}
- \frac{2^{-7}}{10n+3}
- \frac{2^{-8}}{20n+7} \\
+& \frac{2^{-11}}{20n+9}
+ \frac{2^{-13}}{10n+5}
+ \frac{2^{-14}}{20n+11} \\
-& \frac{2^{-17}}{20n+13}
- \frac{2^{-19}}{10n+7}
- \frac{2^{-20}}{20n+15} \\
+& \frac{2^{-23}}{20n+17}
+ \frac{2^{-25}}{10n+9}
+ \frac{2^{-26}}{20n+19} \\
+& \frac{2^{-1}}{12n+1}
+ \frac{2^{-4}}{6n+1}
+ \frac{2^{-6}}{12n+3} \\
-& \frac{2^{-11}}{12n+5}
- \frac{2^{-14}}{6n+3}
- \frac{2^{-16}}{12n+7} \\
+& \frac{2^{-21}}{12n+9}
+ \frac{2^{-24}}{6n+5}
+ \frac{2^{-26}}{12n+11} \\
\end{aligned}
\right]
\end{split}
\end{equation}
\begin{equation}
\begin{split}
\pi
&= \frac{1}{2^{26}} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{27}}{20n+1}
+ \frac{2^{25}}{10n+1}
+ \frac{2^{24}}{20n+3} \\
-& \frac{2^{21}}{20n+5}
- \frac{2^{19}}{10n+3}
- \frac{2^{18}}{20n+7} \\
+& \frac{2^{15}}{20n+9}
+ \frac{2^{13}}{10n+5}
+ \frac{2^{12}}{20n+11} \\
-& \frac{2^{9}}{20n+13}
- \frac{2^{7}}{10n+7}
- \frac{2^{6}}{20n+15} \\
+& \frac{2^{3}}{20n+17}
+ \frac{2^{1}}{10n+9}
+ \frac{2^{0}}{20n+19} \\
+& \frac{2^{25}}{12n+1}
+ \frac{2^{22}}{6n+1}
+ \frac{2^{20}}{12n+3} \\
-& \frac{2^{15}}{12n+5}
- \frac{2^{12}}{6n+3}
- \frac{2^{10}}{12n+7} \\
+& \frac{2^{5}}{12n+9}
+ \frac{2^{2}}{6n+5}
+ \frac{2^{0}}{12n+11} \\
\end{aligned}
\right]
\end{split}
\end{equation}
\begin{equation}
\begin{split}
\pi
&= \frac{1}{2^{26}} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{27}}{20n+1}
+ \frac{2^{25}}{10n+1}
+ \frac{2^{24}}{20n+3} \\
-& \frac{2^{20}}{60n+15}
- \frac{2^{19}}{10n+3}
- \frac{2^{18}}{20n+7} \\
+& \frac{2^{15}}{20n+9}
+ \frac{2^{12}}{30n+15}
+ \frac{2^{12}}{20n+11} \\
-& \frac{2^{9}}{20n+13}
- \frac{2^{7}}{10n+7}
- \frac{2^{5}}{60n+45} \\
+& \frac{2^{3}}{20n+17}
+ \frac{2^{1}}{10n+9}
+ \frac{2^{0}}{20n+19} \\
+& \frac{2^{25}}{12n+1}
+ \frac{2^{22}}{6n+1}
-& \frac{2^{15}}{12n+5}
- \frac{2^{10}}{12n+7} \\
+& \frac{2^{2}}{6n+5}
+ \frac{2^{0}}{12n+11} \\
\end{aligned}
\right]
\end{split}
\end{equation}
\begin{equation}
\begin{split}
\pi
= \frac{1}{2^{26}} \sum_{n = 0}^\infty \frac{(-1)^n}{2^{30n}} \left[
\begin{aligned}
& \frac{2^{27}}{20n+1}
+ \frac{2^{25}}{12n+1}
+ \frac{2^{25}}{10n+1}
+ \frac{2^{24}}{20n+3}
+ \frac{2^{22}}{6n+1} \\
&- \frac{2^{20}}{60n+15}
- \frac{2^{19}}{10n+3}
- \frac{2^{18}}{20n+7}
- \frac{2^{15}}{12n+5} \\
&+ \frac{2^{15}}{20n+9}
+ \frac{2^{12}}{30n+15}
+ \frac{2^{12}}{20n+11}
- \frac{2^{10}}{12n+7} \\
&- \frac{2^{9}}{20n+13}
- \frac{2^{7}}{10n+7}
- \frac{2^{5}}{60n+45}
+ \frac{2^{3}}{20n+17} \\
&+ \frac{2^{2}}{6n+5}
+ \frac{2}{10n+9}
+ \frac{1}{12n+11}
+ \frac{1}{20n+19}
\end{aligned}
\right]
\end{split}
\end{equation}
\fi % working commented out
This formula calculates 30 bits of $\pi$ per iteration or about 9 decimal places. For binary digit extraction purposes it is about $1.42$ times faster than equation~\eqref{eq:originalbbp} as it calculates $30/21 = 1.42$ bits of $\pi$ per division as compared to $4/4 = 1$ bit of $\pi$ per division for the original equation.
\section{Calculating binary digits of $\pi$}
The secret to calculating the $m$-th binary digit of $\pi$ without calculating the previous digits is to multiply equation~\eqref{eq:eulerbbp} by $2^m$ and to calculate the fractional parts only which we will denote as $\pmod 1$ arithmetic. Printing this fractional result as a binary or hexadecimal floating point number will reveal the $m$-th binary digit of $\pi$ and some following digits.
\begin{equation}
2^m \pi = \left[
\begin{aligned}
\sum_{n = 0}^{\lfloor m/2 \rfloor} \left[ (-1)^n 2^{m-2n} \left( \frac{2}{4n + 1} + \frac{2}{4n + 2} + \frac{1}{4n + 3} \right) \right] \\
+ \sum_{n = \lfloor m/2 \rfloor+1}^\infty \left[ \frac{(-1)^n}{2^{2n-m}} \left( \frac{2}{4n + 1} + \frac{2}{4n + 2} + \frac{1}{4n + 3} \right) \right]
\end{aligned}
\right] \pmod 1
\end{equation}
The second half of this equation is easy to calculate as the absolute value of all terms is less than 1 and very quickly these will become so small that we don't need to worry about them. In general, $\lfloor p_f/2 \rfloor$ terms will be sufficient for a floating point number with precision $p_f$.
The first half looks looks more difficult to calculate at first glance due to the large powers involved; however we can use modular arithmetic to calculate this as:
\begin{equation}
2^m \pi \approx \left[
\begin{aligned}
&\sum_{n = 0}^{\lfloor m/2 \rfloor} \left[ (-1)^n \left(
\begin{aligned}
&& \frac{2^{m-2n+1} \pmod{4n + 1}}{4n + 1} \\
&&+ \frac{2^{m-2n+1} \pmod{4n + 2}}{4n + 2} \\
&&+ \frac{2^{m-2n} \pmod{4n + 3}}{4n + 3}
\end{aligned}
\right) \right] \\
&+ \sum_{n = \lfloor m/2 \rfloor+1}^{\lfloor m/2 \rfloor+\lfloor p_f/2 \rfloor} \left[ \frac{(-1)^n}{2^{2n-m}} \left( \frac{2}{4n + 1} + \frac{2}{4n + 2} + \frac{1}{4n + 3} \right) \right]
\end{aligned}
\right] \pmod 1.
\end{equation}
All parts of this equation are now computable using fixed precision floating point numbers of precision $p_f$ bits and integers of precision $p_i$ bits; $2^x \pmod k$ can easily be computed using only $O(\log{n})$ operations \cite{Knuth_1995} using an integer of sufficient size to hold $k$.
There are two limits to the accuracy of this equation. Firstly we need the maximum denominator to fit into $p_i$ bits this means that $4(m/2)+3 < 2^{p_i}$ so $m < 2^{p_i-1}-1.5$. Secondly each time we add a floating point number we will, on average, add half a bit of inaccuracy to the result. This equation needs 3 additions per iteration so our final computed result will only have accuracy approximately $p_f - \log_2{(3(m/2)/2)} = p_f - \log_2(3m/4)$ bits.
\section{Computation}
A program to calculate hex digits of $\pi$ was written based on equation~\eqref{eq:originalbbp}, \eqref{eq:eulerbbp} and \eqref{eq:eulerbbp2} using 64 bit integers ($p_i = 64$) and double precision floating point ($p_f = 53$). Table~\ref{table:results} shows the result of the computation on the author's laptop.
It can be seen in the table that Equation~\eqref{eq:eulerbbp2} is $1.42$ times faster than Equation~\eqref{eq:originalbbp} as expected, but Equation~\eqref{eq:eulerbbp} is $1.5$ times slower.
The program which generated this table can be downloaded from the website for this article \cite{Github}.
\begin{center}
\begin{table}[htb]
\begin{tabular}{|l|l|r|r|r|}
\hline
Digit & Hex Result & Equation~\eqref{eq:originalbbp} & Equation~\eqref{eq:eulerbbp} & Equation~\eqref{eq:eulerbbp2} \\ \hline
$10^{1}$ & \texttt{5A308D31319} & 31.1{\textmu}s & 33.0{\textmu}s & 33.0{\textmu}s \\
$10^{2}$ & \texttt{C29B7C97C50} & 37.6{\textmu}s & 61.3{\textmu}s & 33.9{\textmu}s \\
$10^{3}$ & \texttt{349F1C09B0} & 231{\textmu}s & 342{\textmu}s & 127{\textmu}s \\
$10^{4}$ & \texttt{68AC8FCFB} & 2.23ms & 3.36ms & 1.45ms \\
$10^{5}$ & \texttt{535EA16C} & 27.0ms & 21.5ms & 17.0ms \\
$10^{6}$ & \texttt{26C65E52} & 57.8ms & 83.0ms & 162.5ms \\
$10^{7}$ & \texttt{17AF586} & 476ms & 707ms & 392ms \\
$10^{8}$ & \texttt{ECB840} & 5.95s & 8.93s & 4.07s \\
$10^{9}$ & \texttt{85895} & 66.7s & 100.5s & 44.6s \\
$10^{10}$ & \texttt{921C} & 12m56s & 19m38s & 8m53s \\
$10^{11}$ & \texttt{C9C} & 2h28m &3h43m & 1h37m \\
\hline
\end{tabular}
\caption{\label{table:results}The $10^{m}$-th hex digits of $\pi$ and the calculation time for each equation.}
\end{table}
\end{center}
\section{Conclusion}
Euler noted about equation~\eqref{eq:eulerbbp2}, ``This occurs as most noteworthy, because all these series proceed only by powers of two'' and it is indeed this property which enables its use as a binary digit extraction formula for $\pi$. Euler did not make the leap to note that this formula could be used for binary digit extraction --- that was Bailey, Borwein and Plouffe's stroke of genius --- but amazingly he did find two formulas of the right form 200 years earlier.
\bibliographystyle{plain}
\bibliography{refs} % References are in the refs.bib file
\end{document}