【问题标题】:sympy mignotte_bound and ringsympy mignotte_bound 和 ring
【发布时间】:2020-04-29 18:03:35
【问题描述】:

我正在尝试将 dup_zz_mignotte_bound(f, K) 的结果与其他一些界限进行比较,但是当我添加 dup_zz_mignotte_bound 时,我未能在所有界限中使用变量 x。例如:

from sympy.polys import ring, ZZ
from sympy.abc import x
from sympy import factor

R, x = ring('x', ZZ)

poly =  x**8 +8*x**7 +47*x**6 +136*x**5 +285*x**4 +171*x**3 - 20*x**2 - 21*x+2

print(factor(poly, x)) # this is an example of a function which is used in other bounds

p = R.dup_zz_mignotte_bound(poly) #Sympys function

print(p)


这会在尝试调用 factor() 时返回错误。我如何使用这两个功能? 非常感谢您的宝贵时间!

【问题讨论】:

    标签: sympy ring


    【解决方案1】:

    您使用环变量创建的poly 对象作为多项式对象出现,即PolyElement,它不构成sympy 中的表达式。

    factor 然而,需要一个表达式。好消息是您可以轻松地将多项式转换为表达式(并且您不应发送 x 作为参数):

    >>> factor(poly.as_expr())
    (x**4 + 4*x**3 + 15*x**2 + 3*x - 2)*(x**4 + 4*x**3 + 16*x**2 + 9*x - 1)
    

    【讨论】:

      【解决方案2】:

      我的教授给出了以下答案,他通过首先从 sympy 导入函数 dup_zz_mignotte_bound 来相应地操作它。这是正确的解决方案,因为我们不使用 ring() 函数破坏 x。所以解决办法是:

      from sympy.polys.factortools import dup_zz_mignotte_bound
      from sympy.abc import x
      from sympy import factor, Poly, ZZ
      
      poly =  x**8 +8*x**7 +47*x**6 +136*x**5 +285*x**4 +171*x**3 - 20*x**2 - 21*x+2
      
      print(factor(poly, x), '\n') # this is an example of a function which is used in other bounds
      
      p = dup_zz_mignotte_bound(Poly(poly).all_coeffs(), ZZ) #Sympys function
      
      print(p)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-05
        • 2017-06-14
        • 2017-03-01
        • 2012-06-13
        • 2012-04-25
        • 1970-01-01
        • 1970-01-01
        • 2014-05-11
        相关资源
        最近更新 更多