About This Site
Pi is a famously irrational number: it can't be expressed as a ratio of finite-length numbers. Its digits go on without end, never repeating, so you can't store the whole thing in a computer.
But the Wolfram Language can calculate millions of digits of pi in fractions of a second.
Implementing the My Pi Day site began with this simple Wolfram Language expression to collect the first 10,000,000 digits of pi into one long character string:
How did we know that 10,000,000 digits were enough to contain every possible date? We didn't. It was an intuitive, order-of-magnitude guess that turned out to be right on the money.
Dates are written in My Pi Day graphics as 4- to 6-digit strings, like 5•16•95 for May 16, 1995. Since we don't include the century in the year, there are a finite number of possible dates: 36,525 to be precise. The first occurrence of each date in the digits of pi ranges from digit 1 (3•14•15, or Pi Day) to November 23, 1960 (11•23•60) at digit 9,982,546, just short of 10,000,000.
Equipped with the pi string, finding where in the digits a particular date occurs is a simple string search:
For the website, it was important that visitors be able to enter dates in any reasonable format. That flexibility is built into the Wolfram Language's Interpreter function. A date interpreter will translate any common date format to an exact, computable DateObject:
DateString translates a DateObject into the format we need to search the pi digit string:
Those steps are packaged in the function pidayindex, which returns the character positions of the start and end of a given date in the digits of pi:
Finding the pi position of a date was relatively straightforward. Getting nearly 10 million digits onto a T-shirt or poster was a bigger challenge.
Our design group solved that problem elegantly with nested spirals that start with 3.14159..., spiral off to vanishingly small digits in the middle, and then back out to your date. This is the function that formats a list of digits as one spiral arm:
This is what you get for a particular setting of the spiral parameters:
The spiral is drawn by making a Table of digits, each one positioned at its location in the spiral. Drawing starts at the center with the last digit, thus Reverse[digits] is used to begin at the tail of the list. This is the basic structure of the singlespiral function, illustrated with an example lists of digits:
The code sizes digits with Style and positions them with Text and Rotate. As successive elements of the spiral are calculated in Table, the radius r, font size fs, and angle a used to position the digits are updated incrementally. Here's an example with r = 1, fs = 42, and a = 34.
Text positions the center of the digit at r units along the y axis:
Style sets the font size of the digit:
And finally, Rotate rotates the text into its position in the spiral:
Dates close to the beginning of pi don't have enough digits to make a spiral. In those cases, the digits are laid out linearly (try, for example, Sep 26, 1953). In fact, there are actually fifteen different designs; which one is chosen depends on how deep in pi your date occurs (try Jul 16, 1993 or Aug 23, 2006 to see some other layouts). To complete the design, the layout of the digits is given a black background and programmatically overlaid with a beautiful red π. Those steps are encapsulated in a function called mypiday.
To create the website, we put mypiday into the cloud using CloudDeploy, something like this:
And now it's there, online, for everyone to use.
Though this site came together rather quickly as a lark to celebrate the occasion, this is actually the first of many similar sites to come that will show how easy it is to produce interesting services and dynamic applications with the Wolfram Language.
Happy Pi Day!