# Infinite series for arctan of x

this is a bit of a vague question so I won't be too surprised if I get vague responses.

$$\tan^{-1}(x) = x - (x^3 / 3) + (x^5 / 5) - (x^7 / 7) + \cdots$$ ad infinitum

I'm using this, where $x = (\sqrt{2} - 1)$ to calculate $\pi$, as $\pi = 8 \tan^{-1}(x)$

I have never really learnt about infinite series before, and obviously when I translate this into a python code, I can't use a range from $(0, \infty)$.

So, my question is this; How do I/can I represent this idea in the form of a geometric series or is that the wrong way of going about it?

Thanks.

-
The problem is that it is not a geometric series, so you cannot turn it into a nice closed-form expression. You can get approximations for $\pi$ by taking the first $N$ terms for some choice of $N$. – TMM May 28 '13 at 18:06
So it's acceptable to take an infinite series and just evaluate n number of terms - as long as you keep in mind you get only an approximation with accuracy dependent on number of terms evaluated. – Jacobadtr May 28 '13 at 18:29
What $x = (\sqrt{2} - 1)$ has to do? – Mhenni Benghorbal May 28 '13 at 18:51
That comes from saying tan(pi/8) = x, then substituting back into the trig identity to get x^2 + 2x - 1. Completing the square gives you sqrt(2) - 1 – Jacobadtr May 28 '13 at 19:02
@Jacobadtr: Indeed. The accuracy depends on how many terms you use, but also on how fast the series converges to the right value. For instance, a famous fast-converging series to compute $\pi$ is $\pi = 16 \arctan(1/5) - 4 \arctan(1/239)$. – TMM May 28 '13 at 19:07

You are only going to get an approximation good to some number of decimal places. If you use $N$ terms in the series, then the error is approximately the magnitude of the $N+1$th term. The question you must ask yourself is, if I want $M$ decimal places of accuracy, then how big must $N$ be?

Example: say you want $M=6$ places of accuracy. Then

$$\frac{(\sqrt{2}-1)^{2 N+1}}{2 N+1} < 10^{-6}$$

By trial and error, I get $N=6$. That means you only need $6$ terms in the series to get that level of accuracy.

-
I concur with $\ N = 6 \$ satisfying the inequality, so the series can stop with the $\ N = 5 \$ term (giving an exponent of 11). But using this general term, the first term in the arctangent Taylor polynomial corresponds to $\ N = 0 \$ , so you would need 6 terms. – RecklessReckoner May 28 '13 at 18:20
@RecklessReckoner: you are right - thanks. – Ron Gordon May 28 '13 at 18:21
I usually find it easier just to state the value of the index at which to terminate. (The number of terms required for a series at a specified precision is the subject of numerous "nasty little" multiple-choice questions I have seen on exams.) – RecklessReckoner May 28 '13 at 18:29

You will have to truncate at some point. For this kind of alternating series (terms alternate in sign, decrease in absolute value, and have limit $0$) the truncation error is $\lt$ the first "neglected" term.

Remark: Note that $\tan^{-1}\frac{1}{2}+\tan^{-1}\frac{1}{3}=\tan^{-1}1 =\frac{\pi}{4}$. This may be a more pleasant way to approximate $\pi$ than stuff involving $\sqrt{2}$. There are many such "Machin-like" formulas.

-
I think what you're talking about there is the leibniz series? I have actually written a piece of code that evaluates that for some range of n. It converges very slowly though, for (0, 500000) I get about 5 significant figures correct. The way I am trying now is supposed to converge faster, and is really just practice in math and coding for me - it's not of practical use. – Jacobadtr May 28 '13 at 18:22
I am definitely not talking about the Leibniz series, which in unmodified form is computationally hopeless. I am taking about taking two series, one for $\tan^{-1}(1/2)$, the other for $\tan^{-1}(1/3)$, and adding suitably truncated versions. Apart from differences of detail (what was actually used was usually $4\tan^{-1}(1/5)+\tan^{-1}(1/239)$) this is how high precision computations were done from the $18$-th century to the $20$-th. Look in Wikipedia for Machin-like formulas. To be concrete, the series used would be the one you quote, except we would be adding two of them. – André Nicolas May 28 '13 at 18:28