Calculating trig functions faster than with standard power series

536 Views Asked by At

I found the question "Is there a way to get trig functions without a calculator?" when searching for a faster way to calculate Sine.

@AlexPeter's answer included a "Tailored Taylor" representation: $$\sin(x)=x\left(1-\frac{x^2}{3 \cdot 2}\left(1-\frac{x^2}{5 \cdot 4}\left(1-\frac{x^2}{7 \cdot 6}\left(\phantom{\frac{}{}}\cdots\right.\right.\right.\right.$$

The above works very well and is extremely fast when compared to the standard Power-Series usually given for Sine.

Is there a series for Cosine as well? And Secant, CoSecant, Arcsine, Arc-cosine, etc. I want to use it within my calculator program.

Thank you very much.

2

There are 2 best solutions below

0
On

Too long for a comment.

As you know, infinite series are available for all trigonometric functions but, as they are infinite, for a given accuracy, many terms could be required.

What can also be done is to transform them as Padé approximants which write $$f(x) \sim \frac{\sum_{m=0}^n a_m x^m } {1+\sum_{p=1}^q a_p x^p }$$ which are equivalent to $O(x^{n+q+1})$ or even better.

For example $$\sin(x) \sim x \,\frac{1-\frac{29593 }{207636}x^2+\frac{34911 }{7613320}x^4-\frac{479249 }{11511339840}x^6 } {1+\frac{1671 }{69212}x^2+\frac{97 }{351384}x^4+\frac{2623 }{1644477120}x^6}\tag 1$$

Using long division and comparing to the Taylor series, the absolute difference is $$\frac{1768969 }{2986723025814528000}x^{15}$$ which, for $x=\frac \pi 2$ is $\approx 5.18 \times 10^{-10}$.

1
On

Note that you can use any algorithm to compute the complex exponential function $\exp$. See this post that details elementary techniques to do so quite efficiently, as well as links to a paper on an advanced technique called AGM iteration.

Then you can easily compute the trigonometric functions, since $\cos(z) = \frac12(\exp(iz)+\exp(-iz))$ and $\sin(z) = \frac1{2i}(\exp(iz)-\exp(-iz))$.