# Methods of Estimating Pi

## Recommended Posts

$\arctan(z) = \sum_{n=0}^\infty \frac {(-1)^n z^{2n+1}} {2n+1} \; \qquad | z | \le 1 \qquad z \neq i,-i$

$4 \arctan(1) = 4 \cdot \sum_{n=0}^\infty \frac {(-1)^n 1^{2n+1}} {2n+1} = \pi$

Reference:

Inverse trigonometric functions - infinite series - Wikipedia

So it's really just a different series representation as post #71 above.....

##### Share on other sites

$4 \cdot \sum_{n=0}^\infty \frac {(-1)^n} {2n+1} = \pi$

This equation appears to be the most reduced, however the arctan identity is gone.

Edited by Orion1

##### Share on other sites

$4 \cdot \sum_{n=0}^\infty \frac {(-1)^n} {2n+1} = \pi$

This equation appears to be the most reduced, however the arctan identity is gone.

This series converges very slowly.

##### Share on other sites

This is the formula you gave us:

$\pi=4\cdot arctan(1)=4\sum_{n=0}^{\infty}\frac{(-1)^n\cdot 1^{2n+1}}{2n+1}=4\sum_{n=0}^{\infty}\frac{(-1)^n}{2n+1}$

I wrote a small computer program on my C64 computer using this formula.

It doesn't converge on pi fast enough. Even after 1000 runs through the loop, which took 57 seconds, the only correct part was 3.14

Edited by IsaacAsimov

##### Share on other sites

This is the formula you gave us:

$\pi=4\cdot arctan(1)=4\sum_{n=0}^{\infty}\frac{(-1)^n\cdot 1^{2n+1}}{2n+1}=4\sum_{n=0}^{\infty}\frac{(-1)^n}{2n+1}$

I wrote a small computer program on my C64 computer using this formula.

It doesn't converge on pi fast enough. Even after 1000 runs through the loop, which took 57 seconds, the only correct part was 3.14

Go to WolframAlpha and just click on more digits to get the precision you want.

##### Share on other sites
I wrote a small computer program on my C64 computer using this formula.

It doesn't converge on pi fast enough. Even after 1000 runs through the loop, which took 57 seconds, the only correct part was 3.14[/Quote]

Why are you programming on a Commodore 64 computer? nostalgia reasons?

Try this program, let me know how fast it converges.

10 PRINT 4*ATN(1)


##### Share on other sites

This is the formula you gave us:

$\pi=4\cdot arctan(1)=4\sum_{n=0}^{\infty}\frac{(-1)^n\cdot 1^{2n+1}}{2n+1}=4\sum_{n=0}^{\infty}\frac{(-1)^n}{2n+1}$

I wrote a small computer program on my C64 computer using this formula.

It doesn't converge on pi fast enough. Even after 1000 runs through the loop, which took 57 seconds, the only correct part was 3.14

For estimating the speed of convergence, note that the series is ~ 1/n^2, so that the remainder after n terms is ~ 1/n.

P.S. A more precise estimate of the remainder is 1/(4n+1).

Edited by mathematic

##### Share on other sites

Why are you programming on a Commodore 64 computer? nostalgia reasons?

Try this program, let me know how fast it converges.

10 PRINT 4*ATN(1)


Very good. You are also using a series. An optimized one for the language you've picked. You know how that series was found? Through a lot of ways similar to those presented in this thread. Or did you not know that behind 'ATN' is also a series calculator of some sort? The computer doesn't just know the answer. It calculates it in ways not unlike what this thread has presented.

I really think you are a missing the point -- granted, the thread hasn't been terribly focused. But, the point isn't to just use a built-in optimized series. But to explore how the various series behave.

Edited by Bignose

##### Share on other sites

$\pi = 4 \sum_{n=0}^{\infty} \frac{(-1)^n}{2n+1}$

I calculated the integer sum steps required to complete each numerical place, note that these numbers are fundamental to this equation and are independent of any computer specifications. (i.e. CPU, RAM, Memory, OS, basic language, etc.)

Integer sum:

$n \; ( \text{2}, \text{18}, \text{118}, \text{1687}, \text{10793}, \text{136120}, \text{1530011}, \text{18660287}, \text{155974698})$

Numerical place:

$n_l \; (3,1,4,1,5,9,2,6,5)$

Numerical length:

$l \; (1,2,3,4,5,6,7,8,9)$

Example:

$4 \sum_{n=0}^{1687} \frac{(-1)^n}{2n+1} = 3.141... \; \; \; l = 4$

Note that $l = 9$ required a compiler.

Edited by Orion1

##### Share on other sites
Example:

$4 \sum_{n=0}^{1687} \frac{(-1)^n}{2n+1} = 3.141... \; \; \; l = 4$

To four places, pi is 3.142, not 3.141. This is the problem in a nutshell. You have three, not four, place accuracy after your 1687 elements. This series is incredibly, incredibly slow to converge, taking on the order of 10n iterations to acheive n place accuracy. Compare that to some techniques that yield over ten decimal places per iteration.

##### Share on other sites

I haven't looked at this thread for some time, but I see you did have a go at the Wallis formula I posted.

However you did express some uncertainty in the algebra.

With a computer, the easiest way to eliminate the square root is to square the equation. It is perfectly acceptable to square the infinite products term by term and the extra multiplications are no problem to the computer. The idea of breaking the multiplications into a sequence of fractions multiplied together is also good.

On squaring the expression becomes

$\frac{\pi }{2} = \frac{{2*2*4*4*6*6*8*8...........\left( {2m - 2} \right)\left( {2m - 2} \right)2m}}{{3*3*5*5*7*7*9*9.........\left( {2m - 1} \right)\left( {2m - 1} \right)}}$

Edited by studiot

##### Share on other sites
To four places, pi is 3.142, not 3.141.

$4 \sum_{n=0}^{1687} \frac{(-1)^n}{2n+1} = 3.141... \; \; \; l = 4$

According to my computer algorithm and Mathematica and Wolframalpha, the solution is 3.141. Can anyone else verify?

Reference:

Wolframalpha - sum formula

Edited by Orion1

##### Share on other sites

$4 \sum_{n=0}^{1687} \frac{(-1)^n}{2n+1} = 3.141... \; \; \; l = 4$

According to my computer algorithm and Mathematica and Wolframalpha, the solution is 3.141. Can anyone else verify?

Reference:

Wolframalpha - sum formula

Yes, the output of your series is 3.141 but pi being 3.141592653589..... it rounds to 3.142 for 4 place accuracy so 3.141 is not accurate to 4 places, only 3. Just because you've computed it to 4 places does not mean your result is accurate to 4 places.

##### Share on other sites
According to my computer algorithm and Mathematica and Wolframalpha, the solution is 3.141. Can anyone else verify?

But according to The Man, that is the wrong answer!

That is it is not pi.

Edited by studiot

##### Share on other sites

Why are you programming on a Commodore 64 computer? nostalgia reasons?

Try this program, let me know how fast it converges.

10 PRINT 4*ATN(1)


Perfect Pi Formula:

I am still programming on a Commodore 64 computer because it still works, I am familiar with it, it has a good programming language, namely BASIC, and I can program in

Structured BASIC.

I tried your short program, and I got a value of pi =

3.14159266

On my computer keyboard, there is a special character for pi, which I can get by pressing <shift> $\pi$

Here is the program:

10 PRINT $\pi$

I get a value for pi=

3.14159265

If I press the <shift> $\pi$ button on my calculator, I get a value of pi=

3.141592654

Here is the Perfect Pi Program:

10 REM PERFECT PI PROGRAM

14 REM FROM ATN PI AND SIMPLE PI

20 PRINT "ATN PI ="

30 PRINT 4*ATN(1)

34 PRINT

40 PRINT "SIMPLE PI ="

50 PRINT $\pi$

I think the ATN formula you gave me is the perfect pi formula.

Congratulations!

##### Share on other sites
Or did you not know that behind 'ATN' is also a series calculator of some sort? The computer doesn't just know the answer. It calculates it in ways not unlike what this thread has presented.[/Quote]

Yes, the output of your series is 3.141 but pi being 3.141592653589..... it rounds to 3.142 for 4 place accuracy so 3.141 is not accurate to 4 places, only 3. Just because you've computed it to 4 places does not mean your result is accurate to 4 places.

If the computer is evaluating pi from scratch, such as the case example for the Atn(x) and partial sum functions, then the computer does not know that the answer is pi, so how can it 'know' to round up to the nearest decimal point? and in the case where the solution is only 3.141 at that point in the sum, then there are no further decimal places to round up from!.

I am still programming on a Commodore 64 computer because it still works, I am familiar with it, it has a good programming language, namely BASIC, and I can program in Structured BASIC.[/Quote]

Excellent!, I used to program on an old Apple IIe myself, the basic languages are very similar. The C64 is really easy to program.

Have you tried using a Commodore 64 emulator yet?

Check out the WinVICE-2.2-x86 link listed in reference 1, and try out the 'warp' option!.

Reference:

WinVICE-2.2-x86 - a Commodore 64 emulator for Windows

Edited by Orion1

##### Share on other sites

If the computer is evaluating pi from scratch, such as the case example for the Atn(x) and partial sum functions, then the computer does not know that the answer is pi, so how can it 'know' to round up to the nearest decimal point? and in the case where the solution is only 3.141 at that point in the sum, then there are no further decimal places to round up from!.

I never said the computer would know what to round up to but it has not calculated Pi accurately to 4 places, only 3, Pi to 4 places is 3.142, not 3.141.

##### Share on other sites

Actually, to be fair, the computer holds the value to quite a few more places than 3.

The fault is in the user programming which does not include rounding.

I can't remember if the C64 used truncation or rounding when asked to report to a specific no of figs.

##### Share on other sites
I never said the computer would know what to round up to but it has not calculated Pi accurately to 4 places, only 3, Pi to 4 places is 3.142, not 3.141.[/Quote]

Again, your assumption is that the computer 'knows' that the solution is pi, which it does not.

Actually' date=' to be fair, the computer holds the value to quite a few more places than 3.

The fault is in the user programming which does not include rounding.[/Quote']

Rounding a number during mid summation would produce an incorrect solution, not a correct solution.

Edited by Orion1

##### Share on other sites
Rounding a number during mid summation would produce an incorrect solution, not a correct solution.

What does this have to do with my comment?

##### Share on other sites
What does this have to do with my comment?[/Quote]

The point of contention was whether or not to round the solution from post#84 during mid summation at $n = 1687$ and $l = 4$.

$\pi = \sum_{n=0}^{\infty} \left(- \frac{1}{4} \right)^n \left( \frac{1}{1+2n} + \frac{2}{1+4n} + \frac{1}{3+4n} \right)$

Integer sum:

$n \; (0,1,2,4,5,7,9,10,12)$

Reference:

Wolframalpha - sum formulas

Edited by Orion1

##### Share on other sites
Again, your assumption is that the computer 'knows' that the solution is pi, which it does not.

The same goes for your silly 1687 value.

Just because the value isn't known doesn't mean the error isn't known. This is a monotonically decreasing alternating series. The first omitted term provides an upper bound on the error.

This latest set of posts represents a massive sidetrack. Orion, you appear to have missed this post:

Ok, but that Ramanujan series converges much faster than this one. That's kind of the point of this thread.

The series under discussion in the last bunch of posts is a terrible way to estimate pi. It is very, very slow to converge. The series upon which this is based, the Maclaurin series for arctan(x), is also a terrible way to estimate arctan(x). It is not how your computer computes the inverse tangent.

##### Share on other sites
The point of contention was whether or not to round the solution from post#84 during mid summation at and .

Not in the posted computer program I referred to it wasn't.

Edit

I apologise you were correct.

Looking at posts#84 and #85 I see that this was for a different solution from the one I was looking at, which was your arctan solution.

However my original point is still valid. some early computers used truncating not rounding and you always had to be aware which was which in those days. I have long since discarded all my Commodore paperwork so I can't look it up now.

Edited by studiot

##### Share on other sites
The series under discussion in the last bunch of posts is a terrible way to estimate pi. It is very, very slow to converge. The series upon which this is based, the Maclaurin series for arctan(x), is also a terrible way to estimate arctan(x). It is not how your computer computes the inverse tangent.[/Quote]

I agree, I think I managed to pick absolutely the worst series listed in that reference from Wikipedia for my initial evaluation. It seemed like such a simple harmless equation at the time!

Is it possible to determine which series was used for the Commodore 64 arctan(x) function?

I did manage to achieve $n = 12$ at $l = 9$ on post#96.

However my original point is still valid. some early computers used truncating not rounding ...[/Quote]

On the Commodore 64, $4 \arctan (1)$ at $n_9 = 6$ at $l = 9$, where $\pi$ at $n_9 = 5$, which means that the Commodore 64 rounds up only at $l = 9$.

Edited by Orion1

##### Share on other sites

Again, your assumption is that the computer 'knows' that the solution is pi, which it does not.

No, that's not my assumption. My statement is the same as DH's, that you stated that you calculated the integer sums required to complete each numerical place, i.e.

$\pi = 4 \sum_{n=0}^{\infty} \frac{(-1)^n}{2n+1}$I calculated the integer sum steps required to complete each numerical place, note that these numbers are fundamental to this equation and are independent of any computer specifications. (i.e. CPU, RAM, Memory, OS, basic language, etc.)Integer sum:$n \; ( \text{2}, \text{18}, \text{118}, \text{1687}, \text{10793}, \text{136120}, \text{1530011}, \text{18660287}, \text{155974698})$Numerical place:$n_l \; (3,1,4,1,5,9,2,6,5)$Numerical length:$l \; (1,2,3,4,5,6,7,8,9)$Example:$4 \sum_{n=0}^{1687} \frac{(-1)^n}{2n+1} = 3.141... \; \; \; l = 4$Note that $l = 9$ required a compiler.

You stated the completed value of pi to the 4th numerical place is 3.141 when it is actually 3.142. The fault in this is not the computer's, it is yours.

BTW, if you have a Windows machine you can download qbasic and run your program on there faster than your C64. The language is pretty much the same.

Edited by doG

## Create an account

Register a new account