当前位置: 首页>>代码示例>>Python>>正文


Python PolynomialRing.roots方法代码示例

本文整理汇总了Python中sage.all.PolynomialRing.roots方法的典型用法代码示例。如果您正苦于以下问题:Python PolynomialRing.roots方法的具体用法?Python PolynomialRing.roots怎么用?Python PolynomialRing.roots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.all.PolynomialRing的用法示例。


在下文中一共展示了PolynomialRing.roots方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_roots_are_roots

# 需要导入模块: from sage.all import PolynomialRing [as 别名]
# 或者: from sage.all.PolynomialRing import roots [as 别名]
 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
开发者ID:davidfarmer,项目名称:lmfdb,代码行数:39,代码来源:mf_newforms.py


注:本文中的sage.all.PolynomialRing.roots方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。