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