DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Algorithm of the Week: Algorithm Used for World Record Pi Calculations

Algorithm of the Week: Algorithm Used for World Record Pi Calculations

John Cook user avatar by
John Cook
·
Aug. 21, 12 · Interview
Like (0)
Save
Tweet
Share
8.55K Views

Join the DZone community and get the full member experience.

Join For Free

the following algorithm is based on work of ramanujan and has been used in several world-record calculations of pi.

initialize a 0 = 6 – 4 √2 and y 0 = √2 – 1. then compute

y_{n+1} = \frac{1 - (1-y_n^4)^{1/4}}{1 + (1-y_n^4)^{1/4}}


and

a_{n+1} = (1 + y_{n+1})^4 a_n - 2^{2n+3} y_{n+1}(1 + y_{n+1} + y_{n+1}^2)


the terms a n form a sequence of approximations to 1/π. the error in each approximation is given by

0 < a_n - \frac{1}{\pi} < 16\cdot 4^n \exp(-2\cdot 4^n \pi)


this says that the number of correct digits roughly quadruples after each step. to see this, note that the number of correct decimal places after the n th step is the negative of the logarithm base 10 of the error:

\frac{2\cdot 4^n \pi - n \ln 4 - \ln 16}{\ln 10}


[the error term goes to zero so quickly that you cannot (in ordinary precision) compute the error bound and then take logarithms; the exp(-2 π 4 n ) term will underflow to zero for n larger than 3. (see why here .) you have to take the log of the error term directly before evaluating numerically.]

the number of correct digits quadruples at each step because the leading term in the numerator above is 4 n .

to give a few specifics, a 1 is accurate to 9 digits, a 2 is accurate to 41 digits, and a 3 is accurate to 171 digits. after 10 steps, a 10 is accurate to over 2.8 million digits.

the algorithm given here was state of the art as of 1989. it was used to set world records in 1986. i don’t know whether it has been used more recently. see more here .

according to this page , π has been calculated to 6.4 billion digits. you can beat this record if you can carry out 16 steps of the method described here. a 16 would be accurate to over 11 billion digits.

update : the algorithm used most recently for world record calculations for pi has been the chudnovsky algorithm . as of october 2011, the record was over 10 trillion digits.

Algorithm Record (computer science)

Published at DZone with permission of John Cook, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Using JSON Web Encryption (JWE)
  • The Data Leakage Nightmare in AI
  • Too Many Tools? Streamline Your Stack With AIOps
  • Connecting Your Devs' Work to the Business

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: