News for hackers. Stuff that matters.
Re:Implementing Advanced Math Functions by stephencanon on Wednesday April 25, 2012 @10:09AM (#3889160)
Unfortunately, Taylor series are just about the worst choice possible for implementing transcendental math functions, due to the highly non-uniform error distribution. You end up doing far to much work to get good accuracy near the edges of the domain of interest. Much better choices of polynomial approximations for almost any such situation are (in increasing order of goodness and difficulty to work with): Chebyshev series, Cathedory-Fejer, and Minimax.
Re:Implementing Advanced Math Functions by jvranish on Wednesday April 25, 2012 @10:29AM (#3889237)
If your goal is accuracy, you are absolutely correct. But in the instances where I've wanted to implement my own versions of transcendental math functions, accuracy was actually pretty low on my list of priorities. Often just a couple terms of a taylor series was accurate enough, fast, and easy to implement.
Re:Implementing Advanced Math Functions by stephencanon on Wednesday April 25, 2012 @10:33AM (#3889260)
It's true regardless of what your goal is (unless your goal is to play with Taylor series approximations). Even if you're going purely for speed, you can often replace a third-order Taylor series with a second-order minimax polynomial, and deliver the same or better accuracy with significantly fewer operations.
Re:Implementing Advanced Math Functions by jvranish on Wednesday April 25, 2012 @01:03PM (#3889941)
Do you know of good resource for how to compute minimax polynomials that approximate transcendental functions? My Google foo appears to be failing me.
Re:Implementing Advanced Math Functions by stephencanon on Wednesday April 25, 2012 @01:31PM (#3890083)
The standard approach to minimax approximations is called the "Remez Exchange Algorithm" (or Remez algorithm, or Remes algorithm). It can be fussy, however, and often requires a knowledgeable user to product good results, which is why Chebyshev and Cathedory-Fejer approximants are often used instead -- they are very nearly as good, and much easier to compute.
Re:Implementing Advanced Math Functions by balsam on Wednesday April 25, 2012 @05:10PM (#3891106)
Mathematica, if you have access to it, can give you the minimax polynomial in one line.
Re:Implementing Advanced Math Functions by sanxiyn on Wednesday April 25, 2012 @11:36AM (#3889527)
Taylor series is fine for implementing arbitrary precision transcendental functions though. I found this Python implementation enlightening.

http://code.google.com/p/mpmath/source/browse/trunk/mpmath/l...

Re:Implementing Advanced Math Functions by stephencanon on Wednesday April 25, 2012 @11:36AM (#3889532)
Yes, arbitrary-precision approximations are one area in which they are appropriate.
Re:Implementing Advanced Math Functions by ArbitraryLimits on Wednesday April 25, 2012 @11:30AM (#3889505)
How do you define "minimax" such that it's not a Chebyshev series?
Re:Implementing Advanced Math Functions by stephencanon on Wednesday April 25, 2012 @11:36AM (#3889529)
The minimax polynomial minimizes the maximum error (the L-inf norm). The truncated Chebyshev series of an arbitrary function does not have that property (though it often comes close).
Re:Implementing Advanced Math Functions by ArbitraryLimits on Wednesday April 25, 2012 @12:19PM (#3889706)
I thought the truncated Chebyshev series of an arbitrary function minimizes the L-inf error among all polynomials of the same degree, because Chebyshev polynomials have minimum L-inf norm among all monic polynomials of the same degree.

Let's try this: Tell me how you would construct a minimax approximation according to your definition?

Re:Implementing Advanced Math Functions by stephencanon on Wednesday April 25, 2012 @12:41PM (#3889833)
The truncated Chebyshev series does not generally minimize the L-inf error among all polynomials of the same degree (unless the function being approximated is a polynomial of degree n+1). Constructing a minimax approximation is typically done via the Remez exchange algorithm, which is iterative, fussy, and prone to convergence failures. However, none of those matter when designing an offline approximation as is the case when you're writing math library functions.
Re:Implementing Advanced Math Functions by ArbitraryLimits on Wednesday April 25, 2012 @02:38PM (#3890403)
Thank you, that was enlightening.