It’s harder than you’re thinking that
Introduction
In June 9, 2022 Google set a brand new world record for calculating probably the most variety of digits of Pi — 100 TRILLION! This monumental achievement was possible using the y-cruncher program running 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 times smaller than 100 trillion, would the runtime decrease accordingly? In other words, would it not take only 136 seconds?
But 136 seconds is simply too ambitious. Home PCs are much less powerful than Google Cloud’s most formidable environments. So, how a few more reasonable 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 evidence in Python.
Initially, what’s mistaken with math.pi?
import mathprint(math.pi)
3.141592653589793
math.pi has a precision of 15 digits. While it isn’t much, it’s enough for the best accuracy calculations in science.
For instance, NASA’s Jet Propulsion Lab (JPL) uses 15 digits of Pi to navigate between planets. To provide you an idea, this level of precision is sufficient to calculate the circumference of a circle with a radius of 15 billion miles. The resulting 94 billion miles circumference can be off by not more than the width of your little finger. Take into consideration that!
So, why even trouble with a billion digits, let alone a 100 trillion?
Well, to provide you the geek’s answer: “Because it could be so freaking cool!”.
What if we increase the decimal precision?
Before we take out the massive guns (the algorithms!), what if we increase decimal precision in Python when approximating π? That might be much simpler.
For the approximation, we are going to use Ramanujan’s formula for π. Mathematicians everywhere in the world use it to approximate π to an insurmountable extent.
from decimal import Decimal…