# Which implementation for the Maclaurin Series for the cosine function is better?

First, sorry if this post is off-topic. I consider it too analytic for stack overflow.

In Numerical Analysis subject I must explain which one is better (has less error). The recursive implementation seems to be better with the inputs I have used, but I don't know the reason.

Can someone explain to me which one is better and why? Having in mind round-off error and loss of significance using doubles.

Iterative implementation:

$$\cos{x} = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \ ... \ + (-1)^n\frac{x^{2n}}{(2n)!}$$

Recursive implementation:

$$y_{n+1} = (-1)^n$$ $$y_{k} = \frac{y_{k+1}x^2}{(2k)(2k-1)} + (-1)^{k-1}, \ \text{for} \ k=n,\ n-1,\ n-2,\ ... \ 1$$

• Do you need arbitrary precision or not? If you want a fast approximation with an ahead-of-time fixed precision polynomial approximations (sometimes augmented with little tricks) are often really fast and really precise. Usually series like these are not used for actual computation unless you need thousands of digits as they often converge quite slow and are expensive to compute. – orlp May 2 '17 at 21:14