
The May 6, 1993 episode of The Simpsons has the character Apu boast "I can recite pi to 40,000 places. The last digit is one." See the 40000 digits above, where the 40000th one is red. (A colleague of Borwein actually supplied this information to the Simpson's program: see "Life of Pi on slides" above.)
The most interesting decimal run in pi starts in position 762 (row 7, column 7), where 9999998 occurs. Expressions giving an approximation of pi: pi from an expression.
| C program to calculate 15000 digits of pi | The Formula used |
|---|---|
a[52514],b,c=52514,d,e,f=1e4,g,h;
main(){for(;b=c-=14;h=printf("%04d", e+d/f))
for(e=d%=f;g=--b*2;d/=g)d=d*b+f*(h?a[b]:f/5),a[b]=d%--g;}
|
|
| Output of a run | |
| here (with newlines inserted by hand), or here |
This is called a spigot algorithm because it spits out digits as if from a spigot. Other versions of this program can be found on the Internet. Still, with this method one has to commit ahead of time to a specific number of digits to calculate. The next method doesn't have this weakness.
| Ruby program to calculate pi | The Formula used |
|---|---|
#!/usr/local/bin/ruby
k, a, b, a1, b1 = 2, 4, 1, 12, 4
loop do
p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
d, d1 = a/b, a1/b1
while d == d1
print d
$stdout.flush
a, a1 = 10*(a%b), 10*(a1%b1)
d, d1 = a/b, a1/b1
end
end |
|
| Output of a run | |
% pi.rb 3141592653589793238462643383279502884 ... |
|
pi has commonly been calculated using arc tan formulas, as shown in:
|
Everything done for Gregory's series can be done for this one: see reciprocals of squares. In particular, I discovered the following formula (without proof) that I haven't seen elsewhere:
|
Here the coefficients in the numerators above (leaving off the first 1): 1, 1, 3, 17, 155, 2073, 38227, 929569, ... are called Genocchi numbers (after an Italian mathematician).