# [Numpy-discussion] polynomial ring dtype

Sebastian Walter sebastian.walter@gmail....
Tue Sep 22 02:42:56 CDT 2009

```This is somewhat similar to the question about fixed-point arithmetic
earlier on this mailing list.

I need to do computations on arrays whose elements are truncated polynomials.
At the momement, I have implemented the univariate truncated
polynomials as objects of a class UTPS.

The class basically looks like this:

class UTPS:
def __init__(self, taylor_coeffs):
"""  polynomial x(t) =  tc[0] + tc[1] t + tc[2] t^2 + tc[3]
t^3 + ... """
self.tc = numpy.asarray(taylor_coeffs)

return UTPS(self.tc + rhs.tc)

def sin(self):
# numpy.sin(self) apparently automatically calls self.sin()
which is very cool

etc....

One can create arrays of UTPS instances  like this:
x = numpy.array( [[UTPS([1,2]), UTPS([3,4])], [UTPS([0,1]), UTPS([4,3])]])

and perform funcs and ufuncs on it

y = numpy.sum(x)
y = numy.sin(x)
y = numpy.dot(numpy.eye(2), x)

This works out of the box, which is very nice.

my question:
Is it possible to speed up the computation by defining a special dtype
for truncated polynomials? Especially when the arrays get large,
computing on arrays of objects is quite slow. I had a look at the
numpy svn trunk but couldn't find any clues.

If you are interested, you can have a look at the full pre alpha
version code (BSD licence) at http://github.com/b45ch1/algopy .

regards,
Sebastian
```