Hypothetically you are put in math jail and the jailer says he will let you out only if you can give him 707 digits of pi. You can have a ream of paper and a couple pens, no computer, books, previous pi memorization or outside help.

What is the best formula to use? Where best will result in the least margin of error (most important) and is decently quick (second importance).

707 probably seems arbitrary, but I got it from here: http://en.wikipedia.org/wiki/William_Shanks

Also I don't really understand how he could use that formula because I thought you need a table to get arctan values or it would probably take a long time to make values of arctan to use in the formula, but that isn't too important.

I asked this question today because it celebrates the most accurate pi day for the next 100 years :)

  • 1
    That formula gives you 527 correct decimals, not 707 – Carlos Laguillo Mar 14 '15 at 18:42
  • 10
    @CarlosLaguillo: The formula gives you arbitrary many correct digits, but Shanks made an arithmetic error at the 527th position. – Henning Makholm Mar 14 '15 at 18:46
  • 6
    The last sentence is false. $3.1416$ is closer to $\pi$ than $3.1415$. – Spenser Mar 14 '15 at 19:18
  • 11
    In Europe, of course, $\pi$ day is 31st April. Oh wait... – TonyK Mar 15 '15 at 10:24
  • 2
    You could also do it in base pi and give the digits 1.00000... – glaba Mar 18 '15 at 2:44

12 Answers 12

As metioned in Wikipedia's biography, Shanks used Machin's formula $$ \pi = 16\arctan(\frac15) - 4\arctan(\frac1{239}) $$

The standard way to use that (and the various Machin-like formulas found later) is to compute the arctangents using the power series

$$ \arctan x = x - \frac{x^3}3 + \frac{x^5}5 - \frac{x^7}7 + \frac{x^9}9 - \cdots $$

Getting $\arctan(\frac15)$ to 707 digits requires about 500 terms calculated to that precision. Each requires two long divisions -- one to divide the previous numerator by 25, another to divide it by the denominator.

The series for $\arctan(\frac1{239})$ converges faster and only needs some 150 terms.

(You can know how many terms you need because the series is alternating (and absolutely decreasing) -- so once you reach a term that is smaller than your desired precision, you can stop).

The point of Machin-like formulas is that the series for $\arctan x$ converges faster the smaller $x$ is. We could just compute $\pi$ as $4\arctan(1)$, but the series converges hysterically slowly when $x$ is as large as $1$ (and not at all if it is even larger). The trick embodied by Machin's formula is to express a straight angle as a sum/difference of the corner angles of (a small number of different sizes of) long and thin right triangles with simple integer ratios between the cathetes.

The arctangent gets easier to compute the longer and thinner each triangle is, and especially if the neighboring side is an integer multiple of the opposite one, which corresponds to angles of the form $\arctan\frac{1}{\text{something}}$. Then going from one numerator in the series to the next costs only a division, rather than a division and a multiplication.

Machin observed that four copies of the $5$-$1$-$\sqrt{26}$ triangle makes the same angle as an $1$-$1$-$\sqrt2$ triangle (whose angle is $\pi/4$) plus one $239$-$1$-$\sqrt{239^2+1}$ triangle. These facts can be computed exactly using the techniques displayed here.

Later workers have found better variants of Machin's idea, nut if you're in prison without reference works, it's probably easiest to rediscover Machin's formula by remembering that some number of copies of $\arctan\frac1k$ for some fairly small $k$ adds up to something very close to 45°.

  • how did you come up with the numbers 1/5 and 1/239. Is it just that the closer the fraction is to zero the closer it is to pi? If that's the case then why pick those specific numbers. – Neil Mar 14 '15 at 19:03
  • @Neil: No, but the series for $\arctan x$ converges faster the smaller $x$ is. We have $\pi = 4\arctan 1$, but the series converges hysterically slowly when $x$ is as large as $1$ (and not at all if it is even larger). The trick embodied by Machin's formula is to express a straight angle as a sum/difference of the corner angles of long and thin right triangles with simple integer ratios between the cathetes. – Henning Makholm Mar 14 '15 at 19:12
  • 1
    What is a cathete? also why not pick a bigger number than 239 to make it faster or is 239 the best number for some reason? – Neil Mar 14 '15 at 19:22
  • @Neil: A cathete is one of the two sides in a right triangle that make up the right angle. I've extended the answer a bit. The combination of $\frac15$ and $\frac1{239}$ was the best known in Shank's time (where "best" means roughly that it was the one where the larger of the angles, namely $\arctan\frac15$ was smallest), but there are others, some of which are shown in the Wikipedia article. – Henning Makholm Mar 14 '15 at 19:28
  • 4
    @HenningMakholm: "because the series is alternating" is not enough; you need the sequence of the absolute values to decrease monotonically to zero. – Martin Argerami Mar 15 '15 at 5:30

If pi is a normal number, you can give him any sequence of 707 numbers and they are guaranteed to be digits of pi...

  • 24
    And what do you think the math police will do to you if you assume that pi is normal without proof? – Winston Ewert Mar 15 '15 at 2:26
  • 2
    I guess they want the 707 first digits, not any 707 digits. (Or at least a sequence of digits together with the location they appear in the decimal expansion of $\pi$.) – Paŭlo Ebermann Mar 15 '15 at 10:22
  • @WinstonEwert They will give you a non-computable number and tell you to find the first trillion digits. – k_g Mar 15 '15 at 18:52

Gauss–Legendre algorithm is really good, it only uses four elementary operation and square root; it also converges very fast.

  • This would literally take decades to do by hand, and aslo I am going to have to give it to machin's formula because it states in your link, "However, the drawback is that it(The Gauss-Legendre Algorithm) is memory intensive and it is therefore sometimes not used over Machin-like formulas." – Irrational Person Mar 14 '15 at 18:56
  • 2
    Life Sentence in math jail, oh no :) – Neil Mar 14 '15 at 19:45

The following formula by Ramanujan gives 8 correct decimal digits for each $k$.

$$ \pi = \left( \frac{2\sqrt{2}}{9801} \sum^\infty_{k=0} \frac{(4k)!(1103+26390k)}{(k!)^4 396^{4k}} \right)^{-1}.$$

If you calculate the partial sum from $k=0$ to $88$, then you will get $712$ correct digits of $\pi$.

  • How long would you estimate this would take? – Neil Mar 14 '15 at 19:46
  • But the terms look complicated enough to compute that it's not clear that it's less work than Machin's formula. – Henning Makholm Mar 14 '15 at 19:48
  • 1
    @Neil I don't know. It depends on how good you are at calculating factorials and powers. $(88!)^4$ is $538$ digits long, $396^{88\,\cdot\,4}$ has $915$ digits, and you have to calculate them correctly. But you don't have to calculate tenthousands of operations. – user153012 Mar 14 '15 at 19:55
  • Is this Ramanujan formula better to get to 707 manually or is the Chudnovsky algorithm based on the Ramanujan formula better? – Neil Mar 14 '15 at 20:07
  • @Neil The Chudnovsky algorithm is faster. – user153012 Mar 14 '15 at 20:10

Hand him 707 digits, starting with 111111 then moving on to 222222 and 3333 and so forth. Call your jailor over and tell him you have 707 digits of pi. Out of the kindness of your heart, offer to help him put them in the right order after he lets you out.

  • 1
    Cort Ammon, I like that :) – Neil Mar 15 '15 at 1:04

Using Bellard's formula, you can find $707$ digits of $\pi$ with relatively simple operations taking $233$ terms of the series (i.e. $n_{\mathrm{max}}=233$):

$$\pi = \frac1{2^6} \sum_{n=0}^\infty \frac{(-1)^n}{2^{10n}} \, \left(-\frac{2^5}{4n+1} \right. {} - \frac1{4n+3} + \frac{2^8}{10n+1} - \frac{2^6}{10n+3} \left. {} - \frac{2^2}{10n+5} - \frac{2^2}{10n+7} + \frac1{10n+9} \right).$$

Another option is to use Bailey–Borwein–Plouffe digit extraction algorithm for base-$16$ representation of $\pi$, since no one said the digits must be decimal.

  • How long do you think it would take to do that calculation? Also doing that whole sum only gives 1 number right? Or does it give you more? – Neil Mar 15 '15 at 10:27
  • Dunno, depends on how fast you are at calculation. What do you mean by the whole sum? If you sum this up to $n=233$, you get $\pi$ with an error of $\approx2.7\cdot10^{-708}$. – Ruslan Oct 27 '15 at 5:30

We may use Leibniz series combined with the Euler-Maclaurin formula.

$$\frac\pi4=\sum_{k=0}^\infty\frac{(-1)^k}{2k+1}\\\small=1-\sum_{k=1}^{n-1}\left(\frac1{4k-1}-\frac1{4k+1}\right)-\int_n^\infty\left(\frac1{4x-1}-\frac1{4x+1}\right)~\mathrm dx-\frac12\left(\frac1{4x-1}-\frac1{4x+1}\right)-\sum_{k=1}^p\frac{B_{2k}}{2k}\left(\frac1{(n-1/4)^{2k}}-\frac1{(n+1/4)^{2k}}\right)+R_{n,p}\\|R_{n,p}|<\frac{3\cdot(2p)!}{(6n^2)^{2p}}$$To get 707 digits of $\pi$, you'll need $|R_{n,p}|<10^{-708}$. For example, taking $p=833,n=20$ gives the desired error.


Where $B_k$ are the Bernoulli numbers and you can evaluate


and $\pm$ denotes maximum possible error.

Nilakantha's Series haven't been mentioned yet.

$$ \pi = 3 + \frac4{2\times3\times4} - \frac4{4\times5\times6} + \frac4{6\times7\times8} - \frac4{8\times9\times10} + \dots $$

Without dots: $$ \pi = 3 + \sum_{k=1}^\infty (-1)^{k+1}\frac1{k \times (2k+1) \times (k+1)} $$

This formula is better than Leibniz's formula, but inefficient compared to Machin's formula.

It gives the first five digits of pi in (only) 14 terms of the series. Yet with it, computing each next digit of pi requires to compute twice as many terms as for the previous digit. So it can't be used to compute the 707 firsts digits of pi.

You can use this method that counts digit for digit in any base:


And if you can smuggle in a computer there are programs using this method:


There are a few super-convergent series and sequences that may be used to approximate $\pi$. I add this as a CW since I already have my own answer, and I merely stumbled upon this one, though I have absolutely zero clue how they work.

The mentioned series and sequences are known as Borwein's algorithm.

The first such example:

\begin{aligned}A&=212175710912{\sqrt {61}}+1657145277365\\B&=13773980892672{\sqrt {61}}+107578229802750\\C&={\big (}5280(236674+30303{\sqrt {61}}){\big )}^{3}\end{aligned}

$$\frac1\pi =12\sum_{n=0}^{\infty }\frac{(-1)^{n}(6n)!\,(A+nB)}{(n!)^{3}(3n)!\,C^{n+1/2}}$$

This series only requires about 30 terms to get 707 digits of $\pi$.

The second such example:

\begin{aligned}A={}&63365028312971999585426220\\&{}+28337702140800842046825600{\sqrt {5}}\\&{}+384{\sqrt {5}}(10891728551171178200467436212395209160385656017\\&{}+4870929086578810225077338534541688721351255040{\sqrt {5}})^{1/2}\\B={}&7849910453496627210289749000\\&{}+3510586678260932028965606400{\sqrt {5}}\\&{}+2515968{\sqrt {3110}}(6260208323789001636993322654444020882161\\&{}+2799650273060444296577206890718825190235{\sqrt {5}})^{1/2}\\C={}&-214772995063512240\\&{}-96049403338648032{\sqrt {5}}\\&{}-1296{\sqrt {5}}(10985234579463550323713318473\\&{}+4912746253692362754607395912{\sqrt {5}})^{1/2}\end{aligned}

$$\frac{\sqrt{-C^3}}\pi=\sum _{n=0}^\infty\frac{(6n)!}{(3n)!(n!)^3}\frac{A+nB}{C^{3n}}$$

This series only requires about 15 terms to get 707 digits of $\pi$.

The last example I will show:

\begin{aligned}a_{0}&={\frac {1}{3}}\\r_{0}&={\frac {{\sqrt {3}}-1}{2}}\\s_{0}&=(1-r_{0}^{3})^{1/3}\end{aligned}

\begin{aligned}t_{n+1}&=1+2r_{n}\\u_{n+1}&=(9r_{n}(1+r_{n}+r_{n}^{2}))^{1/3}\\v_{n+1}&=t_{n+1}^{2}+t_{n+1}u_{n+1}+u_{n+1}^{2}\\w_{n+1}&={\frac {27(1+s_{n}+s_{n}^{2})}{v_{n+1}}}\\a_{n+1}&=w_{n+1}a_{n}+3^{2n-1}(1-w_{n+1})\\s_{n+1}&={\frac {(1-r_{n})^{3}}{(t_{n+1}+2u_{n+1})v_{n+1}}}\\r_{n+1}&=(1-s_{n+1}^{3})^{1/3}\end{aligned}


To get 707 digits of $\pi$, you only need to evaluate out to $a_5$ or $a_6$. (I have no idea, but apparently if $a_n$ approximates $\pi$ out $k$ digits, then $a_{n+1}$ approximates $\pi$ out approximately $9k$ digits. Insane!)

  • Simply: Thank you!${}{}$ – amWhy Sep 21 '17 at 15:45

Most websites state that William Shanks “calculated” 707 digits this is not correct as when he “published” his 707 of Pi he also published the two ark tangents to 709 digits which was the correct value of the digits he calculated. If you are interested the last two digits they are 92 and no he did not round up the 707th digit he just dropped the last two digits. The correct values were published in 1873can be found in the Proceedings of the Royal Society of London, Volume 21 page 319 which was known to have typo errors, it also had the two sub terms William Shanks used to arrive at PI. Look at “On the extension of the numerical value of π” found in the “Proceedings of the Royal Society of London 21:318–319”. The page required can be found at “archive.org/stream/philtrans00902295/00902295#page/n1/mode/2up”. As a side note there is a two digits error in the last 180 error digits, “51100” should be “51111”..

So as you can see he did calculate 709 digits and in some cases the “3” is also counted which would have made a nice round number like 710, there is no proof this was done in this case. In his 1853 book he printed the term values for his first 530 calculation with his 609 values for the ark tangents and the value of PI to 607 digits. There was a 20 year before he published the 707 digit of PI during this time he worked on may other types of numbers. I have calculated PI by hand to 100 digits which took 108 pages, increasing this value to 709 digits it would take 5429 pages, the cost of this much paper at that time must have been a great cost. If William shanks had done a perfect job the last 5 digits correct digits are 99561 his ,calculated value would have been 99456 with an error of 105 units in the last digit which would have made the last 3 digits in error the 707th through 709th digits.


A pretty simple method i would use if i had no access to books would be to just calculate the alternating sum of reciprocals of consecutive odd numbers and multiply by four, since $$\sum_{k=0}^\infty\frac{(-1)^k}{2k+1}=\frac \pi 4$$ It would take a very very very long time though, but it is a fairly simple method.

Another method would be to make some kind of small, circular pool, measure the diameter, then pour water from a measure cup into the pool, keeping in mind the amount of water you have pured. Once the pool is filled to a certain height, measure the height and, since the volume of water is given by $h*d*\pi$, then with a big (diameter-wise) enough pool we could be able to work out the digits accurately enough. This approach is less time consuming but needs a lot more resources.

  • 7
    On the other hand, it takes $10^8$ terms to get 7 decimal terms correctly, so this might not be a good approach. – cirpis Mar 14 '15 at 19:18
  • 1
    Life sentence in math jail without parole, jk :) – Neil Mar 14 '15 at 19:24
  • 7
    The universe is not (by FAR) large enough to contain a pool with enough water in it that the relative error implicit in rounding off to an integer number of molecules of water is less than $10^{-707}$. – Henning Makholm Mar 14 '15 at 19:43
  • 1
    Sorry cripis bro, that wouldn't work either. The visible universe isn't big enough to give you a measurement to get past 63 digits of pi. Ignoring the effects of physics and stuff. – Neil Mar 14 '15 at 19:44
  • 5
    But the universe is expanding! So someday it will be lange enough :D – cirpis Mar 14 '15 at 19:44

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.