TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Member-only story

Why You (Almost) Can’t Calculate Pi to a Billion Digits in Python at Home

Bex T.
9 min readOct 9, 2023

--

bexgboost_The_number_Pi_in_all_its_majesty_and_glory_mathematic_a06a71bf-6cb1-4585-86cf-315265ccf38e.png
Image by me with Midjourney.

Introduction

In June 9, 2022 Google set a new world record for calculating the most number 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 7.651 seconds.

If one billion is 100 thousand times smaller than 100 trillion, would the runtime decrease accordingly? In other words, would it take only 136 seconds?

But 136 seconds is too ambitious. Home PCs are much less powerful than Google Cloud’s most formidable environments. So, how about a more reasonable runtime like 24 hours?

Turns out, calculating even a billion digits of Pi within 24 hours is a giant pipe dream. This article explains why with evidence in Python.

First of all, what is wrong with math.pi?

import math

print(math.pi)
3.141592653589793

math.pi has a precision of 15 digits. While it is not much, it is enough for the highest accuracy calculations in science.

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Bex T.
Bex T.

Written by Bex T.

BEXGBoost | DataCamp Instructor |🥇Top 10 AI/ML Writer on Medium | Kaggle Master | https://www.linkedin.com/in/bextuychiev/

Responses (5)