0

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.

user376343
  • 8,311
  • 3
    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 – Hagen von Eitzen Feb 28 '19 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 '19 at 22:25
  • See this question for an arctan algorithm. – Fabio Lucchini Feb 28 '19 at 22:30
  • @Hagen von Eitzen has given you an important keyword "Horner" (algorithm). Here is another one : CORDIC algorithm for "$\arctan$-like" functions – Jean Marie Feb 28 '19 at 23:23
  • As @Hagen von Eitzen as said, have a look at Horner algorithm. See as well CORDIC algorithme for $\arctan$-like functions. But be conscious that in many cases, functions are computed plainly by interpolating tabulated values + some tricks. – Jean Marie Feb 28 '19 at 23:29
  • To Hagen von Eitzen, The series shown is not formatted as the standard power series for Sine. This is closer to a continued fraction. I can not re-design a power-series. I will never be at that level. I did Calculus I, II, III and a few other heavy Math courses and the creativity never hit me. I can do Assembly Language, C, Basic, DCL, Unix, C#, Awk. You now know where my bread and butter, my kids college degrees came from. If possible can anybody show me, tell me, the Series for Cosine be like the series for Sine as shown on this page? Thank You very much. – Bill Bollinger Mar 01 '19 at 00:08
  • The reason the standard power series for is very slow, while processing an iteration of the Sine series, one must divide a Factorial (example 11! ) into x11. This takes a long time. And I can iterate way pass "x11/11!". The re-formated series does not use "x**11/11!". It is much simpler, thus much much faster. Thank you for time. – Bill Bollinger Mar 01 '19 at 00:25
  • 1
    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.$ – user376343 Mar 01 '19 at 13:15
  • Thank you extremely much. – Bill Bollinger Mar 01 '19 at 15:47

2 Answers2

2

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

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

user21820
  • 57,693
  • 9
  • 98
  • 256
  • And in case it's not obvious, exp(−i·z) is the complex conjugate of exp(i·z), so cos(z) is just the real part of exp(i·z), and sin(z) is the imaginary part. – user21820 Jun 21 '23 at 09:06