Submitted works

Advanced search

math.NT — Number Theory

Folding the Plouffe-Bellard Digit-Extraction Scheme for π\pi: A Legendre-Symbol Block Identity and an O(n3/2)O(n^{3/2}) Variant

Contributed by Mark Kim

The algorithm of Plouffe and Bellard computes the digits of π\pi at positions n+1,…,n+gn+1, \dots, n+g in any base from the series π=2∑k≥0k!/(2k+1)!!\pi = 2 \sum_{k \ge 0} k!/(2k+1)!! in O(n2)O(n^2) operations on machine words and O(1)O(1) words of memory: for each of the π(2N)\pi(2N) primes q<2Nq < 2N with N≈nlog⁡2(10)N \approx n \log_2(10), it runs a loop of length NN. We prove that for every prime qq with q2>2N+qq^2 > 2N + q, the sum of the contributions of all complete blocks k≡j(modq)k \equiv j \pmod{q} collapses to the Legendre symbol (−1/q)(-1/q), by the identity ∑i=0(q−1)/2(2ii)2−i≡(−1)(q−1)/2(modq)\sum_{i=0}^{(q-1)/2} \binom{2i}{i} 2^{-i} \equiv (-1)^{(q-1)/2} \pmod{q}. The loop of length NN is replaced by a partial sum of at most min⁡(L,h−L+1)\min(L, h - L + 1) terms, where h=(q−1)/2h = (q - 1)/2, and the total number of loop iterations drops from (2+o(1))N2/ln⁡N(2 + o(1)) N^2 / \ln N to at most (7/24+o(1))N2/ln⁡N(7/24 + o(1)) N^2 / \ln N, a reduction factor of at least 6.86.8. Each remaining partial sum is a prefix or suffix sum of a hypergeometric sequence modulo qq; computing it with the baby-step giant-step method of Bostan, Gaudry, and Schost takes O(Llog⁡L)O(\sqrt{L} \log L) operations and gives a total complexity of O(n3/2)O(n^{3/2}) operations. The proposed framework returns the correct digits in all verification cases; on benchmarks with n=2000,…,32000n = 2000, \dots, 32000, it is 4.24.2 to 18.718.7 times faster than the standard loop of the Plouffe--Bellard scheme on the same series, and the measured execution time of a single tail sum scales strictly like L\sqrt{L} up to L=4.1×107L = 4.1 \times 10^7. The complete source code, verification test suites, and benchmarks are made available.

A mix of human-written and AI-generated textHuman understanding: all partsBellard's formulaLegendre symbolPiPlouffe's algorithmbaby-step giant-stepcomputational number theorydigit-extractionhypergeometric series
Dec 05, 202611 pages
PDFView work