def from_polynomial(cls, pol): pol = PolynomialRing(QQ, 'x')(str(pol)) pol *= pol.denominator() R = pol.parent() pol = R(pari(pol).polredbest().polredabs()) return cls.from_coeffs( [int(c) for c in pol.coefficients(sparse=False)])
def polredabs(self): if "polredabs" in self._data.keys(): return self._data["polredabs"] else: pol = PolynomialRing(QQ, 'x')(self.polynomial()) pol *= pol.denominator() R = pol.parent() from sage.all import pari pol = R(pari(pol).polredabs()) self._data["polredabs"] = pol return pol
def polredabs(self): if "polredabs" in self._data.keys(): return self._data["polredabs"] else: pol = PolynomialRing(QQ, 'x')(map(str, self.polynomial())) # Need to map because the coefficients are given as unicode, which does not convert to QQ pol *= pol.denominator() R = pol.parent() from sage.all import pari pol = R(pari(pol).polredabs()) self._data["polredabs"] = pol return pol
def polredabs(self): if "polredabs" in self._data.keys(): return self._data["polredabs"] else: pol = PolynomialRing(QQ, 'x')(map(str,self.polynomial())) # Need to map because the coefficients are given as unicode, which does not convert to QQ pol *= pol.denominator() R = pol.parent() from sage.all import pari pol = R(pari(pol).polredabs()) self._data["polredabs"] = pol return pol
def from_polynomial(cls, pol): try: # try to cast to ring pol = PolynomialRing(QQ, 'x')(pol) except Exception: # try again as a string pol = PolynomialRing(QQ, 'x')(str(pol)) pol *= pol.denominator() R = pol.parent() pol = R(pari(pol).polredbest().polredabs()) return cls.from_coeffs( [int(c) for c in pol.coefficients(sparse=False)])
def from_polynomial(cls, pol): try: # try to cast to ring pol = PolynomialRing(QQ, 'x')(pol) except Exception: # try again as a string pol = PolynomialRing(QQ, 'x')(str(pol)) pol *= pol.denominator() # For some reason the error raised by Pari on a constant polynomial is not being caught if pol.degree() < 1: raise ValueError("Polynomial cannot be constant") R = pol.parent() pol = R(pari(pol).polredbest().polredabs()) return cls.from_coeffs([int(c) for c in pol.coefficients(sparse=False)])
def poly_to_field_label(pol): try: pol = PolynomialRing(QQ, 'x')(str(pol)) pol *= pol.denominator() R = pol.parent() pol = R(pari(pol).polredabs()) except: return None coeffs = list2string([int(c) for c in pol.coeffs()]) d = int(pol.degree()) query = {'coeffs': coeffs} C = base.getDBConnection() one = C.numberfields.fields.find_one(query) if one: return one['label'] return None
def from_polynomial(cls, pol): pol = PolynomialRing(QQ, 'x')(str(pol)) pol *= pol.denominator() R = pol.parent() pol = R(pari(pol).polredbest().polredabs()) return cls.from_coeffs([int(c) for c in pol.coefficients(sparse=False)])