使用SymPy对复合物的多项式进行完全因式分解 [英] Full factorization of polynomials over complexes with SymPy
问题描述
我想完全分解一个多项式,因此可以将其分解为复数.>
SymPy 提供 factor
来执行此操作,但是令我惊讶的是,分解仅在整数根 eg 上完成:>
>>>从sympy导入*>>>z =符号('z')>>>因子(z ** 2-1-z)(z-1)*(z +1)>>>因子(z ** 2 + 1,z)z ** 2 + 1
或
>>>因子(2 * z-1,z)2 * z-1>>>因子(2 * z-1,z,扩展名= [整数(1)/2])2 *(z-1/2)
已经存在一个已回答的问题:使用sympy的复杂根因子,以及 asmeurer 作品:
>>>因子(z ** 2 + 1,z,扩展= [I])(z-I)*(z + I)
,但是您需要指定非整数根的每个除数,例如 :
>>>因子(z ** 2 + 2,z,扩展= [I])z ** 2 + 2>>>因子(z ** 2 + 2,z,扩展= [I,sqrt(2)])(z-sqrt(2)* I)*(z + sqrt(2)* I)
我的问题是:如何完全分解一个多项式(从而超过复数),而无需给每个除数赋予扩展
?
asmeurer 提供了解决方案:
>>>多边形= z ** 2 + 2>>>r =根(poly,z)>>>LC(poly,z)* Mul(* [(z-a)** r [a] for a in r])/___ \/___ \\ z-\/2 * I/* \ z + \/2 * I/
但是它应该存在一种本地方法,不是吗?
像 factor(poly,z,complex = True)
之类的东西.
我在 domain参数应该起作用,在高斯有理情况下,您也可以使用 这在您的情况下不起作用,因为分解需要超过 以上方法可以结合使用 I want to fully factorize a polynom, thus factorize it over complexes. SymPy provide or An answered question already exists : Factor to complex roots using sympy, and the solution given by asmeurer works : but you need to specify every divisor of non-integer roots, e.g. : My question is : how to fully factorize a polynom (thus over complexes), without needing to give every divisor to asmeurer gives a solution to do this : But it should exists a native way to do it, no ? I looked for in the documentation of
The domain argument should work and in the case of Gaussian rationals you can also use That doesn't work in your case though because the factorisation needs to be over The approaches above can be combined though with
这篇关于使用SymPy对复合物的多项式进行完全因式分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!>>>因子(z ** 2 + 2,z,domain ='Z')2个z + 2>>>因子(z ** 2 + 2,z,domain ='R')/2 \2.0 * \ 0.5 * z + 1.0/>>>因子(z ** 2 + 2,z,domain ='C')2个1.0 * z + 2.0
gaussian = True
等效于extension = I
:
在[24]中:factor(z ** 2 + 1,gaussian = True)输出[24] :( z-ⅈ)⋅(z +ⅈ)
QQ(I,sqrt(2))
,而不是 QQ(I)
.域'R'
和'C'
无法按预期工作的原因是,它们是不精确的浮点域,而不是表示形式中实数或复数的域纯粹的数学意义和因式分解是
在[28]中:e = z ** 2 + 2在[29]中:factor(e,extension = roots(e))Out [29] :( z-√2⋅ⅈ)⋅(z +√2⋅ⅈ)
factor
to do it, but I’m very surprised that factorization is done only over integer roots, e.g. :>>> from sympy import *
>>> z = symbols('z')
>>> factor(z**2 - 1, z)
(z - 1)*(z + 1)
>>> factor(z**2 + 1, z)
z**2 + 1
>>> factor(2*z - 1, z)
2*z - 1
>>> factor(2*z - 1, z, extension=[Integer(1)/2])
2*(z - 1/2)
>>> factor(z**2 + 1, z, extension=[I])
(z - I)*(z + I)
>>> factor(z**2 + 2, z, extension=[I])
z**2 + 2
>>> factor(z**2 + 2, z, extension=[I, sqrt(2)])
(z - sqrt(2)*I)*(z + sqrt(2)*I)
extension
?>>> poly = z**2 + 2
>>> r = roots(poly, z)
>>> LC(poly, z)*Mul(*[(z - a)**r[a] for a in r])
/ ___ \ / ___ \
\z - \/ 2 *I/*\z + \/ 2 *I/
Someting like factor(poly, z, complex=True)
.factor
, but I did not find anything.
Futhermore, factor
can take domain
as optional argument that I believed allows to specified the set on which the factorization is made, but not >>> factor(z**2 + 2, z, domain='Z')
2
z + 2
>>> factor(z**2 + 2, z, domain='R')
/ 2 \
2.0*\0.5*z + 1.0/
>>> factor(z**2 + 2, z, domain='C')
2
1.0*z + 2.0
gaussian=True
which is equivalent to extension=I
:In [24]: factor(z**2 + 1, gaussian=True)
Out[24]: (z - ⅈ)⋅(z + ⅈ)
QQ(I, sqrt(2))
rather than QQ(I)
. The reason that domains 'R'
and 'C'
don't work as expected is because they are inexact floating point domains rather than domains representing the real or complex numbers in the pure mathematical sense and factorisation is In [28]: e = z**2 + 2
In [29]: factor(e, extension=roots(e))
Out[29]: (z - √2⋅ⅈ)⋅(z + √2⋅ⅈ)