符号根上多项式与组合平方根的因式分解

2024-10-02 00:27:18 发布

您现在位置:Python中文网/ 问答频道 /正文

SymPyfactor函数可以在符号根上分解,例如

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)

但如果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 

因此,如果应用了标识sqrt(a) * sqrt(a) = a,则分解失败,并且始终应用该标识,因为它是标识a**x + a**y = a**(x + y)的特定实例,该实例始终为真(cfdocumentation

我尝试使用extension,因为它适用于非整数根(参见我的其他question),但不起作用:

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)>

当应用这样的恒等式时,有没有办法在符号根上分解多项式


Tags: 实例infromextension符号sqrtout标识

热门问题