5 ms·
Unfortunately, Taylor series are just about the worst choice possible for implementing transcendental math functions, due to the highly non-uniform error distri
by stephencanon 15y ago
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.
- jvranish 15y agoIf 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.
- stephencanon 15y agoIt'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.
- jvranish 15y agoDo you know of good resource for how to compute minimax polynomials that approximate transcendental functions? My Google foo appears to be failing me.
- jeremysalwen 15y agoLook up the remez algorithm
- stephencanon 15y agoThe 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.
- balsam 15y agoMathematica, if you have access to it, can give you the minimax polynomial in one line.
- deleted 15y ago[deleted]
- ArbitraryLimits 15y agoHow do you define "minimax" such that it's not a Chebyshev series?
- stephencanon 15y agoThe 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).
- ArbitraryLimits 15y agoI 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?
- stephencanon 15y agoThe 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.
- ArbitraryLimits 15y agoThank you, that was enlightening.
- sanxiyn 15y agoTaylor 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/libmp/libelefun.py?r=1240 http://code.google.com/p/mpmath/source/browse/trunk/mpmath/l...
- stephencanon 15y agoYes, arbitrary-precision approximations are one area in which they are appropriate.