This page uses Gosper's series identity for π to calculate an unbounded stream of digits.

I haven't really looked into the derivation of the algorithm; I just translated the code in Jeremy Gibbons' paper Unbounded Spigot Algorithms for the Digits of Pi. (That paper has a typo in what I call \(y\), by the way - it has \(27i+15\) instead of \(27i-12\))

The state consists of two pieces of information, whose initial values are as follows:

\begin{align*} \mathrm{M} &= \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \\ i &= 1 \end{align*}

At each iteration of the algorithm, the following values are computed:

\begin{align*} \begin{pmatrix}y_1 \\ y_2\end{pmatrix} &= \mathrm{M} \times \begin{pmatrix}27i-12 \\ 5\end{pmatrix} \\ y &= \left\lfloor y_1/y_2 \right\rfloor \\ \\ \begin{pmatrix} z_1 \\ z_2\end{pmatrix} &= \mathrm{M} \times \begin{pmatrix}675i-216 \\ 125\end{pmatrix} \\ z &= \left\lfloor z_1/z_2 \right\rfloor \end{align*}

If \(y=z\), then \(y\) is output as the next digit of \(\pi\), and the matrix \(\mathrm{M}\) becomes

\[ \mathrm{M'} = \begin{pmatrix} 10 & -10y \\ 0 & 1\end{pmatrix} \times \mathrm{M}\]

If \(y \neq z\), then nothing is output and the state instead becomes

\[ \mathrm{M'} = \mathrm{M} \times \begin{pmatrix} i(2i-1) & j(5i-2) \\ 0 & j\end{pmatrix} \]

where \(j = 3(3i+1)(3i+2)\), and \(i\) is increased by one.

The process is then repeated, with the new values of \(\mathrm{M'}\) and \(i\).

The numbers in the matrix \(\mathrm{M}\) get very big very quickly, so I had to use Matthew Crumley's BigInteger library for this javascript implementation.


tl;dr I'm a massive nerd.


My name is Christian Lawson-Perfect. Yes it is.

Bonus technical things