Hacker News new | ask | show | jobs
by kortex 1363 days ago
> When have you ever used the Taylor series of sine and cosine for anything (outside school) ?

I've used them a few times, mostly in the embedded space, and mostly in conjunction with lookup tables and/or Newton's method, but yes I've absolutely used them outside school (years ago, I forget the exact details).

- implementing my own trig functions for embedded applications where I wanted fine control over the computation-vs-precision tradeoff

- implementing my own functions for hypercomplex numbers (quaternions, duals, dual quaternions, and friends).

- automatic differentiation

Does the Taylor series form survive to the final application? Usually not, usually it gets optimized to something else, but "start with Taylor series and get back to basics to get a slow but accurate function" has gotten me out of several pickles. And the final form usually has some chunks of the Taylor series.

1 comments

I agree that using the Taylor series can be easier, especially during development, mainly because convenient tools for generating approximation polynomials or other kinds of approximating functions are not widespread.

However, the performance when using Taylor series is guaranteed to be worse than when using optimal approximation polynomials, according to appropriate criteria.

Still I cannot see when you would want to use the Taylor series of the trigonometric functions, even if for less usual functions it could be handy.

There are plenty of open-source libraries with good approximations of the trigonometric functions, so there is no need to develop one's own.

In the case of a very weak embedded CPU there is the alternative to use CORDIC for the trigonometric functions, instead of polynomial approximations. CORDIC can be very accurate, even if on CPUs with fast multipliers it is slower than polynomial approximation.