Example #1
0
 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)])
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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
Example #5
0
 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)])
Example #6
0
 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)])
Example #7
0
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
Example #8
0
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
Example #9
0
 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)])