Calculating the value of pi, formulaically

author: Gene Biondo

written in about 2012. Updated 2/2014.

Note:

I recall encountering and trying out a particularly cool little BASIC program and formula, using a VIC20 and Commodore 64 as a teenager in the 1980s. It was interesting in that it used a very simple formula to calculate gradually less imprecise values of pi while looping forever. I wish I could remember just how long it took to lock a few decimal places back then - it seems like it would have taken days with that interpreted BASIC and slow MHz.

I poked around several times over the years to find a copy of that old program so that I could modernize it. I eventually found a TI BASIC program that worked in exactly the same way. Seeing the formula at work hurts my brain, but nonetheless I've rewritten it all in JavaScript/JQuery here, and enhanced it. It's especially nice having the values periodically saved in cookies so you can resume where you left off when rebooting, etc. (note - not sure at this point of the accuracy when resuming - need to follow up)

current approximation of pi:

?

total iterations:
?
points found inside circle:
?
Π

Converted to JavaScript from the following TI Basic:

:0 --> N0 --> D
:While 1
:rand*2-1 --> X
:rand*2-1 --> Y
:If sqrt(x^2+y^2)=< 1
:N+1 --> N
:End
:D+1 --> D
:Disp (N/D*4)
:End

Next things to do:

  • Do a variation using pi/4 = 1 -1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - 1/15.... It should be quicker and far more precise. I've seen it takes 10 million iterations to lock 6 decimal points, but much more quickly than the random test I use on this page.
  • ensure accuracy of resume feature
  • list some formulas. Examples
  • find references/links to original programs
  • optimize speed of calculatePi(). Yes, as of 2014 this still runs far faster using the Chrome browser's JS engine, though I'm beginning to question the randomness/precision of its random-number generator.

Here is the actual value of pi to the first 1000 decimal points:

Pi = 3.
1415926535 8979323846 2643383279 5028841971 6939937510  : 50
5820974944 5923078164 0628620899 8628034825 3421170679  : 100
8214808651 3282306647 0938446095 5058223172 5359408128  : 150
4811174502 8410270193 8521105559 6446229489 5493038196  : 200
4428810975 6659334461 2847564823 3786783165 2712019091  : 250
4564856692 3460348610 4543266482 1339360726 0249141273  : 300
7245870066 0631558817 4881520920 9628292540 9171536436  : 350
7892590360 0113305305 4882046652 1384146951 9415116094  : 400
3305727036 5759591953 0921861173 8193261179 3105118548  : 450
0744623799 6274956735 1885752724 8912279381 8301194912  : 500

9833673362 4406566430 8602139494 6394819912 8378179183  : 550
3418247744 4853615337 3608835056 5132349664 8227184400  : 600
6947763137 5263307273 3185606008 7806765476 3491032337  : 650
4818639519 9947798976 5496143576 0713078663 7658227890  : 700
5182753138 1518899515 6063792499 5583597838 9682252140  : 750
5876176842 2661335613 7253712755 8442444995 1099021885  : 800
7134767647 7107069051 0992854782 0084796524 1346530135  : 850
5358194569 9854672410 0288340228 5318125444 8475683595  : 900
0543750053 5668828211 7470492377 8411625840 3680909735  : 950
6478019548 0795466544 0260245141 9277318661 7863637397  : 1000
idx

 Pages in this section: (sorry, still building this)

  1. Temp link

    [This is where child links will go once the content management system is in place]

  2. Temp link

    At least, the ones that will get pages in the CMS.


Related info:

This box may one day hold a related link, so you could then follow it.

Still not blah?

Blah a [blah] at Blah.

Shinies:

I Got Mine @ GeneBiondo .com!
Push2Check Download: Fast, Fun, Awesome

Why should I even bother to put a footer here?  Blah blah blah, legal mumbo jumbo and so forth. You actually read this thing?  If you’re so smart, what should I put here?