# Derive a spigot formula for pi using Julia

The BBP formula for \pi is

\pi= \sum_{k=0}^\infty \frac{1}{16^k} \left(\frac{4}{8k+1}-\frac{2}{8k+4}-\frac{1}{8k+5}-\frac{1}{8k+6}\right).

It was the first technique that could produce a digit (hexadecimal in this case) for \pi without calculating the prior digits. The package PiBBP.jl from Tomáš Kalvoda can be used to calculate the millionth digit of \pi. Mosè Giordano has also used Julia to evaluate the formula.

Can we use Julia to derive this formula? Or better yet, similar formulas for our favorite irrationals? Yes; the spigotBBP function in the LLLplus.jl package can be used to look for a formula for an irrational \alpha of the form

\alpha = \sum_{k=0}^\infty \frac{1}{b^k} \left( \frac{a_1}{(nk+1)^s} + \ldots + \frac{a_n}{(nk+n)^s} \right),

where s, b, and n are parameters. In particular, fixing s=1, b=16, n=8, and looking for an approximation to the first K=45 terms we can use the following command to find a_1,...a_n:

julia> Pkg.add("LLLplus");  using LLLplus
julia> spigotBBP(BigFloat(pi),1,16,8,45,true)'
A solution was found w error -4.728672e-60. In LaTeX form it is
\alpha= \sum_{k=0}^\infty \frac{1}{16^k} \left(\frac{4}{8k+1}-\frac{2}{8k+4}-\frac{1}{8k+5}-\frac{1}{8k+6}\right)

I.e. the BBP formula for \pi at the top of the post was found. If you want other irrational fun, it’s fairly straightforward to find other formulas with s=1; see the help text for spigotBBP. Unfortunately the function does not seem to work for s>1; it’s not obvious if this is somehow fundamental to the LLL-based scheme I used, or there is a bug. This does help show that spigotBBP is not a robust tool, yet hopefully good enough for March 14.
flatten the curve! 