Lesson goal: Add numbers to get $\pi$

Previous: A clever for-loop for Pi | Home | Next: What kinds of numbers?

D. Bailey, P. Borwein, and S. Plouffe (called "BBP") came up with this formula for $\pi$:

$\pi=\sum\limits_{n=0}^\infty \frac{1}{16^n}\left(\frac{4}{8n+1}-\frac{2}{8n+4}-\frac{1}{8n+5}-\frac{1}{8n+6}\right)$ (from "Pi Unleashed," by J. Arndt and C. Haenel, p. 117).

Use a for loop of about 10 terms, and see how close this sum comes to $\pi$.

Now you try. Use this BBP sum to compute $\pi$! Try 100 terms! 1000!

Type your code here:

See your results here:

This code will not run! Fix the for-loop to run over your desired number of terms, and fix the term= line to be the formula for each "term" in the sum (the $\frac{1}{16^n}\left(...\right)$ in the formula above).
Here's another formula to try:


This one was found by Adamchik and Wagon in 1997 (see p. 227 of "Pi Unleashed).


Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.