Ask Your Question

Revision history [back]

Laurent Expansion at Infinity / Root finding

I'm new to sage, and I was trying to implement the following, to partial success:

I want to take the $p^{th}$ root of a polynomial (for a specified $p$), expand it as a Laurent series at infinity, and take the polynomial part of the expansion. I've written some code which seems to work with partial success, but it also fails in some very straightforward cases.

def poly_truncate(f):
     g=f(1/x)
     h = g.series(x==0,1).truncate()
     return h(1/x)

It works, for instance, with $(x^2-3x+5)^{1/2}$ and $(x^3-5x^2+45x-713)^{1/3}$, but not (for example) with $(x^8-x^7+9x^6-7x^5+4x^4-x^3)^{1/2}$. I feel as though my method is kind of ad-hoc, and was hoping somebody could point me to a better way to do this. This is the error message it throws, for what it's worth:

       poly_truncate((x^8-x^7+9*x^6-7*x^5+4*x^4-x^3)^(1/2))
       ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-d95c1391d7b5> in <module>()
----> 1 poly_truncate((x**Integer(8)-x**Integer(7)+Integer(9)*x**Integer(6)-Integer(7)*x**Integer(5)+Integer(4)*x**Integer(4)-x**Integer(3))**(Integer(1)/Integer(2)))

<string> in poly_truncate(f)

/Applications/SageMath-8.1.app/Contents/Resources/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__call__ (build/cythonized/sage/symbolic/expression.cpp:32775)()
   5273             z^2 + x^y
   5274         """
-> 5275         return self._parent._call_element_(self, *args, **kwds)
   5276 
   5277     def variables(self):

/Applications/SageMath-8.1.app/Contents/Resources/sage/src/sage/symbolic/ring.pyx in sage.symbolic.ring.SymbolicRing._call_element_ (build/cythonized/sage/symbolic/ring.cpp:11496)()
    973                     d[ vars[i] ] = arg
    974                 except IndexError:
--> 975                     raise ValueError("the number of arguments must be less than or equal to %s"%len(vars))
    976 
    977         return _the_element.subs(d, **kwds)

ValueError: the number of arguments must be less than or equal to 0

Additionally, is there a faster/more trustworthy built-in function or package which computes the rational/integer roots of polynomials in $\mathbb{Q}[x]$ (i.e. better than just f.roots())?