Sunday, March 31, 2024

Why You (Virtually) Can’t Calculate Pi to a Billion Digits in Python at Dwelling | by Bex T. | Oct, 2023

Must read

It’s more durable than you assume

Towards Data Science
Picture by me with Midjourney.


In June 9, 2022 Google set a brand new world file for calculating probably the most variety of digits of Pi — 100 TRILLION! This monumental achievement was doable utilizing the y-cruncher program operating on Google Cloud. It crunched numbers for a whopping 157 days, 23 hours, 31 minutes and seven.651 seconds.

If one billion is 100 thousand occasions smaller than 100 trillion, would the runtime lower accordingly? In different phrases, would it not take solely 136 seconds?

However 136 seconds is just too bold. Dwelling PCs are a lot much less highly effective than Google Cloud’s most formidable environments. So, how a couple of extra affordable runtime like 24 hours?

Seems, calculating even a billion digits of Pi inside 24 hours is a huge pipe dream. This text explains why with proof in Python.

Initially, what’s incorrect with math.pi?

import math



math.pi has a precision of 15 digits. Whereas it isn’t a lot, it’s sufficient for the best accuracy calculations in science.

For instance, NASA’s Jet Propulsion Lab (JPL) makes use of 15 digits of Pi to navigate between planets. To provide you an thought, this degree of precision is sufficient to calculate the circumference of a circle with a radius of 15 billion miles. The ensuing 94 billion miles circumference can be off by not more than the width of your little finger. Take into consideration that!

So, why even hassle with a billion digits, not to mention a 100 trillion?

Effectively, to provide the geek’s reply: “As a result of it could be so freaking cool!”.

What if we improve the decimal precision?

Earlier than we take out the massive weapons (the algorithms!), what if we improve decimal precision in Python when approximating π? That might be a lot easier.

For the approximation, we’ll use Ramanujan’s system for π. Mathematicians everywhere in the world use it to approximate π to an insurmountable extent.

from decimal import Decimal…

Supply hyperlink

More articles


Please enter your comment!
Please enter your name here

Latest article