SymPy: Factorization of polynomials over symbolic roots with combined square roots

自作多情 提交于 2020-06-28 03:55:03

问题


SymPy factor function can factorize over symbolic roots, e.g. :

In [1]: from sympy import *
In [2]: init_printing(use_latex=False)
In [3]: z, a, b = symbols('z a b')
In [4]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z)
In [5]: poly
Out[5]: 
                       2
√a⋅√b - √a⋅z - √b⋅z + z 
In [6]: factor(poly, z)
Out[6]: (-√a + z)⋅(-√b + z)

but the factorization fails if b = a :

In [10]: b = a
In [11]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z)
In [12]: poly
Out[12]: 
               2
-2⋅√a⋅z + a + z 
In [13]: factor(poly, z)
Out[13]: 
               2
-2⋅√a⋅z + a + z 

Thus, the factorization fails if the identity sqrt(a) * sqrt(a) = a is applied, and this identity is always applied as it is a particular instance of the identity a**x + a**y = a**(x + y) which is always true (cf documentation).

I tried with extension as it works for non-integer roots (cf my other question), but it does not work :

In [14]: roo = roots(poly, z)
In [15]: roo
Out[15]: {√a: 2}

In [16]: factor(poly, z, extension=[sqrt(a)])
---------------------------------------------------------------------------
CoercionFailed                            Traceback (most recent call last)
...
CoercionFailed: can’t convert 1 of type <class 'sympy.polys.fields.FracElement'> from ZZ(a) to QQ<sqrt(a)>

In [17]: factor(poly, z, extension=roo)
---------------------------------------------------------------------------
CoercionFailed                            Traceback (most recent call last)
...
CoercionFailed: can’t convert 1 of type <class 'sympy.polys.fields.FracElement'> from ZZ(a) to QQ<sqrt(a)>

Is there a way to factorize a polynomial over symbolic roots when such identity is applied ?

来源:https://stackoverflow.com/questions/62371772/sympy-factorization-of-polynomials-over-symbolic-roots-with-combined-square-roo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!