# [Numpy-tickets] [NumPy] #664: more accurate representation of polynomials

NumPy numpy-tickets@scipy....
Fri Feb 22 14:25:38 CST 2008

```#664: more accurate representation of polynomials
-------------------------+--------------------------------------------------
Reporter:  pv           |       Owner:  somebody
Type:  enhancement  |      Status:  new
Priority:  normal       |   Milestone:  1.1
Component:  numpy.lib    |     Version:  none
Severity:  normal       |    Keywords:
-------------------------+--------------------------------------------------
numpy.poly1d represents polynomials by storing the polynomial
coefficients. I believe that for high-order polynomials, this is not
always the optimal way to represent them.

Consider one of the orthogonal polynomial functions in scipy.special:
{{{
>>> import scipy, scipy.special
>>> for n in xrange(0,70,10): print n,
scipy.special.chebyt(n)(scipy.cos(z)) - scipy.cos(n*z)
0 0.0
10 3.80806497446e-14
20 1.94978477808e-10
30 2.65364360286e-06
40 -0.0237953834481
50 -114.714051465
60 272370.465462
}}}
It can be seen that as the order of the polynomial increases, the accuracy
of evaluation decreases very rapidly, and for n > 40 the result is
basically numerical noise.

The scipy.special.chebyt function generates a poly1d object by passing the
roots of the polynomial to poly1d. In poly1d.__init__, polynomial
coefficients are calculated from the roots. For high-order Chebyshev
polynomials, the coefficients are large and of varying sign which leads to
loss of precision when evaluating the polynomial.

It might be useful if there was a poly1d-compatible object that would
retain a more accurate representation of the polynomial. (Using the roots,
or a Horner scheme?) This would come useful when more information than the
coefficients is initially available.