Top Qs
Timeline
Chat
Perspective

Chudnovsky algorithm

Fast method for calculating the digits of π From Wikipedia, the free encyclopedia

Remove ads
Remove ads

The Chudnovsky algorithm is a fast method for calculating the digits of π, based on Ramanujan's π formulae. Published by the Chudnovsky brothers in 1988,[1] it was used to calculate π to a billion decimal places.[2]

It was used in the world record calculations of 2.7 trillion digits of π in December 2009,[3] 10 trillion digits in October 2011,[4][5] 22.4 trillion digits in November 2016,[6] 31.4 trillion digits in September 2018–January 2019,[7] 50 trillion digits on January 29, 2020,[8] 62.8 trillion digits on August 14, 2021,[9] 100 trillion digits on March 21, 2022,[10] 105 trillion digits on March 14, 2024,[11] and 202 trillion digits on June 28, 2024.[12] Recently, the record was broken yet again on April 2nd 2025 with 300 trillion digits of pi.[13][14] This was done through the usage of the algorithm on y-cruncher.

Remove ads

Algorithm

The algorithm is based on the negated Heegner number , the j-function , and on the following rapidly convergent generalized hypergeometric series:[15]A detailed proof of this formula can be found here: [16]


This identity is similar to some of Ramanujan's formulas involving π,[15] and is an example of a Ramanujan–Sato series.

The time complexity of the algorithm is .[17]

Remove ads

Optimizations

Summarize
Perspective

The optimization technique used for the world record computations is called binary splitting.[18]

Binary splitting

A factor of can be taken out of the sum and simplified to


Let , and substitute that into the sum.


can be simplified to , so

from the original definition of , so

This definition of is not defined for , so compute the first term of the sum and use the new definition of

Let and , so

Let and

can never be computed, so instead compute and as approaches , the approximation will get better.

From the original definition of ,

Recursively computing the functions

Consider a value such that

Base case for recursion

Consider

Python code

# This code is a basic implementation of the Chudnovsky algorithm with binary
# splitting optimizations. It is not meant to be maximally efficient.

from decimal import Decimal, Context, setcontext

setcontext(Context(prec=28))  # increase `prec` for higher precision


def binary_split(a, b):
    if b == a + 1:
        Pab = -(6*a - 1)*(2*a - 1)*(6*a - 5)
        Qab = 10939058860032000 * a**3
        Rab = Pab * (545140134*a + 13591409)

        return Pab, Qab, Rab

    m = (a + b) // 2
    Pam, Qam, Ram = binary_split(a, m)
    Pmb, Qmb, Rmb = binary_split(m, b)

    Pab = Pam * Pmb
    Qab = Qam * Qmb
    Rab = Qmb * Ram + Pam * Rmb

    return Pab, Qab, Rab


def chudnovsky(n):
    _, Q1n, R1n = binary_split(1, n)
    return (426880 * Decimal(10005).sqrt() * Q1n) / (13591409*Q1n + R1n)


# increase argument of `chudnovsky` for higher accuracy
print(chudnovsky(2))  # 3.141592653589793238462643384
Remove ads

Notes

See also

  • How is π calculated to trillions of digits?

References

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads