def pol_string_to_list(pol, deg=None, var=None): if var is None: from lmfdb.hilbert_modular_forms.hilbert_field import findvar var = findvar(pol) if not var: var = 'a' pol = PolynomialRing(QQ, var)(str(pol)) if deg is None: fill = 0 else: fill = deg - pol.degree() - 1 return [str(c) for c in pol.coefficients(sparse=False)] + ['0']*fill
def pol_string_to_list(pol, deg=None, var=None): if var is None: from lmfdb.hilbert_modular_forms.hilbert_field import findvar var = findvar(pol) if not var: var = 'a' pol = PolynomialRing(QQ, var)(str(pol)) if deg is None: fill = 0 else: fill = deg - pol.degree() - 1 return [str(c) for c in pol.coefficients(sparse=False)] + ['0'] * fill
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 check_roots_are_roots(self, rec, verbose=False): """ check that embedding_root_real, and embedding_root_image approximate a root of field_poly """ poly = PolynomialRing(ZZ, "x")(rec['field_poly']) dpoly = poly.derivative() dbroots = db.mf_hecke_cc.search( {'hecke_orbit_code': rec['hecke_orbit_code']}, ["embedding_root_real", "embedding_root_imag"]) dbroots = [ CCC(root["embedding_root_real"], root["embedding_root_imag"]) for root in dbroots ] if len(dbroots) != poly.degree(): if verbose: print("Wrong number of roots") return False for r in dbroots: # f is irreducible, so all roots are simple and checking relative error is the way to go if poly(r) / dpoly(r) > 1e-11: # It's still possible that the roots are correct; it could just be a problem of numerical instability print(r, poly(r) / dpoly(r)) break else: return True roots = poly.roots(CCC, multiplicities=False) # greedily match. The degrees are all at most 20, so it's okay to use a quadratic algorithm while len(roots) > 0: best_dist = infinity r = roots[0] for i, s in enumerate(dbroots): dist = abs(r - s) if dist < best_dist: best_dist, best_i = dist, i # The dim 1 case where poly=x is handled correctly in the earlier loop, so r != 0. if best_dist / abs(r) > 1e-13: if verbose: print("Roots mismatch", sorted(roots), sorted(dbroots)) return False roots.pop(0) dbroots.pop(best_i) return True
def check_roots_are_roots(self, rec, verbose=False): """ check that embedding_root_real, and embedding_root_image approximate a root of field_poly """ poly = PolynomialRing(ZZ, "x")(rec['field_poly']) dpoly = poly.derivative() dbroots = db.mf_hecke_cc.search({'hecke_orbit_code': rec['hecke_orbit_code']}, ["embedding_root_real", "embedding_root_imag"]) dbroots = [CCC(root["embedding_root_real"], root["embedding_root_imag"]) for root in dbroots] if len(dbroots) != poly.degree(): if verbose: print "Wrong number of roots" return False for r in dbroots: # f is irreducible, so all roots are simple and checking relative error is the way to go if poly(r)/dpoly(r) > 1e-11: # It's still possible that the roots are correct; it could just be a problem of numerical instability print r, poly(r)/dpoly(r) break else: return True roots = poly.roots(CCC, multiplicities=False) # greedily match. The degrees are all at most 20, so it's okay to use a quadratic algorithm while len(roots) > 0: best_dist = infinity r = roots[0] for i, s in enumerate(dbroots): dist = abs(r-s) if dist < best_dist: best_dist, best_i = dist, i # The dim 1 case where poly=x is handled correctly in the earlier loop, so r != 0. if best_dist/abs(r) > 1e-13: if verbose: print "Roots mismatch", sorted(roots), sorted(dbroots) return False roots.pop(0) dbroots.pop(best_i) return True
def field(self): if not self.__field: f = PolynomialRing(ZZ, name='x')(str(self.__field_poly)) self.__field = QQ if f.degree() == 1 else NumberField(f, 'a') return self.__field
def field(self): if not self.__field: f = PolynomialRing(ZZ,name='x')(str(self.__field_poly)) self.__field = QQ if f.degree() == 1 else NumberField(f,'a') return self.__field