### 100 Trillion Digits Edit

Records are made to be broken. In March 2022, we calculated 100 trillion digits of pi using Compute Engine. This is the second time we’ve used Google Cloud to calculate a record number of digits for the mathematical constant, tripling the number of digits in just three years after our world record with 31.4 trillion digits in 2019.

Check out the official blog for more details about the technical details and architecture of the calculation. And for more on the history of calculating pi, check out this post on The Keyword.

We’ve updated the API to serve all of the 100 trillion digits of pi. We’ve also published the entire results on Cloud Storage so you can download the files (caution: they are really big).

This website serves pi and interactive demos that you can listen to or see pi with. Scroll down to play with the demos!

To learn more about how this site works, check out the Serving the Pi section. We’ve also published the entire source code of the demos and infrastructure, including Terraform scripts, on GitHub.

This website is not an official Google product. It is managed by volunteers of the Google Cloud Developer Advocacy team and may become unavailable without notice.

### Listen (Piano Genie) Edit

What does Pi sound like? Each Pi digit is converted to a musical note so you can get to know Pi via music!

Piano Genie is an neural network model that allows you to play a note from 1 to 8, and intelligently map it to a great sounding piano performance. In this demo, we use each digit for [0, 7] and reuse the last digit for [8, 9], and use Piano Genie to map to the next logical note for great sounding Pi.

With 100 trillion digits and playing at 314 BPM, it'll play for 605,516 years!

### Listen (Bach Doodle) Edit

On March 21, 2019, Google presented Bach Doodle to celebrate world renowned German composer and musician Johann Sebastian Bach. You can create a melody line and use the AI to fill in the harmony. This demo uses Pi digits to create the melody, and then you can uses Google Bach Doodle ML model (Coconet) to infill the harmony. Coconet Javascript library is available as part of Magenta.JS. Learn more with Coconet demo and Coconet demo source.

This demo is turned off on mobile devices. Please use the latest desktop Chrome browser for the best experience.

### Visualize Edit

Visualize transitions from one digit to the next in Pi using D3.js. Each transition draws a line from a digit in the circle to another digit. Once you have a large amount of digits you can see which digits transition more often and which digits are more common.

### Art Edit

For Google Cloud Next 2019 in San Francisco, a team created the Pi Experiment Showcase, and uses the Pi API & generative algorithm to generate unique art pieces for each of the 31.4 trillion digits of Pi.

Here is an art piece to the first 11 digits of e (2.7182818284):

### /v1/pi Edit

Get Pi Digits

Returns digits of Pi based on the `start` digit position and `numberOfDigits`.

There is no SLA on this service. We may require an API key in the future & or turn off the service. This is not an official Google API.

We can use curl call the API from the command line.

``````curl 'https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100'
``````

Here’s an example to use the API in JavaScript.

``````fetch("https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100")
.then(response => response.json())
.then(data => console.log(data));
``````

The response looks like this.

``````{"content":"3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067"}
``````

The API also supports hexadecimal digits of pi. Use the `radix` parameter to specify the base.

``````curl 'https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100&radix=16'
``````

It will return a hexadecimal representation of pi.

``````{"content":"3243f6a8885a308d313198a2e03707344a4093822299f31d0082efa98ec4e6c89452821e638d01377be5466cf34e90c6cc0a"}
``````

### Fetching Digits Edit

This demo uses the REST API to fetch 100 digits of Pi from the specified starting point. You can also try getting the hexadecimal digits of pi.

### Serving the API Edit

We developed the REST API in Go and running the program in Cloud Functions (2nd gen).

The architecture looks like this:

We have the same function deployed in three regions (US, Belgium, Japan) that fetches digits from a Cloud Storage bucket in the US multi-region. The API endpoint, `api.pi.delivery` is exposed via a Global HTTP(s) Load Balancer. The authorative DNS servers are provided by Cloud DNS.

The frontend code is developed in TypeScript and React.

Finally, this site is hosted on Firebase Hosting, which not only automatically serves the static content via a CDN, it also automatically provisions a SSL certificate for the custom domain!

We have the entire source code published on GitHub including Terraform scripts that we use to provision the infrastructure.

### Calculating Pi Edit

In 2019, Emma Haruka Iwao broke the Pi digits world record by computing 31,415,926,535,897 digits of Pi using Google Cloud Platform! Learn more details from Emma’s Calculating a record-breaking 31.4 trillion digits blog, and Alex Yee (creator of y-cruncher)’s Google Cloud Topples the Pi record article.

Back in 2017, we used y-cruncher to calculate 750 billion digits of Pi on Google Compute Engine. We used a 64-core instance, with 416GB of RAM, and tons of Local SSD + Persistent SSD.

At its peak CPU utilization, it consumed all 64 cores, and 5+TB of SSD storage.

In 2018, we were able to recalculate 750 billion digits in just 10 hours!

We also calculated 1 trillion digits of Pi using a 96-core 14TB `n1-megamem-96` machine.

### Who are We? Edit

Since 2015, different members of the team worked on different Pi Day demos!

In 2022, Emma Haruka Iwao, Ben Bleything, Sara Ford, and Steve McGhee together calculated 100 trillion decimals of pi. Check out the official blog for more details about the technical details and architecture of the calculation. And for more on the history of calculating pi, check out this post on The Keyword.

In the same year, Sara calculated 64 million digits of π using Cloud Functions (2nd gen), and Emma rebuilt the API with Cloud Functions and the demos with React. We also made the source code available on GitHub.

In 2020, we updated the Pi API to return 50 trillion digits, and added Machine Learning models to generate even better Pi music. The numbers were kindly donated by Timothy Mullican, former world record holder. We also had an opportunity to interview Timothy for Pi Day 2020. Check out this video if you want to hear two world record breakers discuss about pi!

In 2019, the Pi digits world record was broken by Emma Haruka Iwao. Google Cloud Experiment for Pi Day was created by Mathias Paumgarten. The Pi API was updated to serve all 31.4+ trillion digits by Ray Tsang.

In 2018, the Pi API was updated to serve 1 trillion digits by Ray Tsang.

In 2017, we made this site and the Pi API, by Francesc Campoy, Guillaume Laforge, Ian Lewis, Ray Tsang, Sandeep Dinesh.

In 2016, we calculated 500 billion digits of Pi and made it searchable. The indexing peaked at 2-million writes per second. You can learn more how we did that in the blog Calculating and searching 500 billion digits of Pi, by Francesc Campoy, Jen Tong, Ray Tsang, Sara Robinson.

In 2015, we calculated 250 billion digits of Pi, by Greg Wilson, Ray Tsang.

### Source Code Edit

The source code for the REST API and demos are available on GitHub.