# Calculating trig functions faster than with standard power series

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.

• But this is the standard power series for Sine (i.e., the value computed with so-and-so-many terms is the same as the Taylor polynomial of corresponding degree), just in a Horner-like evaluation scheme Feb 28, 2019 at 22:12
• The trick is to find the ratios of coefficients in the original series. Among the functions you listed it's feasible for cosine, and I think also arcsine and arccosine, but not for secant or cosecant unless you can easily get (IIRC) Bell numbers.
– J.G.
Feb 28, 2019 at 22:25
• See this question for an arctan algorithm. Feb 28, 2019 at 22:30
• @Hagen von Eitzen has given you an important keyword "Horner" (algorithm). Here is another one : CORDIC algorithm for "$\arctan$-like" functions Feb 28, 2019 at 23:23
• For cosine you get $\;\cos x =1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}\cdots =1-\frac{x^2}{2\cdot 1}\left(1-\frac{x^2}{4 \cdot 3}\left(1-\frac{x^2}{6 \cdot 5}\left(1-\frac{x^2}{8 \cdot 7}\left(\phantom{\frac{}{}}\cdots\right.\right.\right.\right.$ Mar 1, 2019 at 13:15

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}$$.

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))$$.