We love the number $\pi=3.1415..$. Why? Well, even outside of math circles, everyone knows what it is, and it is a wonderfully quirky number,
that offers a lot to think about and have fun with.

We are constantly intrigued by various ways of computing $\pi$. In a past lesson we showed you how to compute $\pi$ by adding a particular sequence of numbers together. Here's another example of that, which uses the factorial numbers. Believe it or not, the value of $1/\pi$ can be found from $$\frac{1}{\pi}=\frac{2\sqrt{2}}{9801}\sum_{n=0}^\infty \frac{(4n)!}{(n!)^4}\times \frac{1103+26390n}{(4\times 99)^{4n}}$$ What a wonderfully juicy expression indeed! We also like it because it is a use of the factorial function, which you learned about in a past lesson This formula was discovered by the Borwein brothers in 1985 (see p. 210 of Stewart).

In formulas like this, the $\Sigma$ means to let $n$ run from $0$ to $\infty$ and do this: one by one, plug the value of $n$ into the formula to the right of the $\Sigma$ sign. You add each result for each $n$ together in a big sum. Indeed $\Sigma$ sums are very similar to for-loops. In this case, the first two terms ($n=0$ and $n=1$) of the sum will be: $$ \frac{0!}{(0!)^4}\times \frac{1103+26390\cdot 0}{(4\times 99)^{4\cdot 0}} +\frac{(4\cdot 1)!}{(1!)^4}\times \frac{1103+26390\cdot 1}{(4\times 99)^{4\cdot 1}}.$$

Of course you can't run $n$ up to infinity. How large should $n$ be? Well try going up to $10$, because the factorial function gets pretty large pretty fast, and the $(4n)!$ will get too large for the computer to handle. We found that no more than about $20$ terms will do just fine to discover $\pi$ with this wonderful formula.

`sum=sum+`

line, translate the expression to the right of the $\Sigma$ sign into code. Remember
to use your factorial function, as in $n!=$fact(n).
Type your code here:

See your results here:

This code will not run! See if you can program in the form of the expression to the right of the $\Sigma$ sign in the
$1/\pi$ definition.
Dismiss.

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

Here's your code:

- Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.
- Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into
this page
- Then click the "Use on iPhone" button that you'll see.