简体   繁体   English

使用 SymPy 对复数上的多项式进行全因式分解

[英]Full factorization of polynomials over complexes with SymPy

I want to fully factorize a polynom, thus factorize it over complexes .我想完全分解一个多项式,从而将它分解为 complexes

SymPy provide factor to do it, but I'm very surprised that factorization is done only over integer roots, eg : SymPy提供了这样做的factor ,但我很惊讶分解仅在 integer 根上完成,例如

>>> from sympy import *
>>> z = symbols('z')
>>> factor(z**2 - 1, z)
(z - 1)*(z + 1)
>>> factor(z**2 + 1, z)
z**2 + 1

or或者

>>> factor(2*z - 1, z)
2*z - 1
>>> factor(2*z - 1, z, extension=[Integer(1)/2])
2*(z - 1/2)

An answered question already exists: Factor to complex roots using sympy , and the solution given by asmeurer works:一个已回答的问题已经存在:使用 sympy 分解复杂根,asmeurer给出的解决方案有效:

>>> factor(z**2 + 1, z, extension=[I])
(z - I)*(z + I)

but you need to specify every divisor of non-integer roots, eg :但是您需要指定非整数根的每个除数,例如

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

My question is: how to fully factorize a polynom (thus over complexes), without needing to give every divisor to extension ?我的问题是:如何完全分解一个多项式(因此超过复数),而不需要给每个除数进行extension

asmeurer gives a solution to do this: asmeurer提供了一个解决方案来做到这一点:

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

But it should exists a native way to do it, no?但它应该存在一种本地方式来做到这一点,不是吗?
Someting like factor(poly, z, complex=True) .有点像factor(poly, z, complex=True)

I looked for in the documentation of factor , but I did not find anything.我在factor的文档中查找,但没有找到任何东西。 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可以将domain作为可选参数,我认为它允许指定进行分解的集合,但不能

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

The domain argument should work and in the case of Gaussian rationals you can also use gaussian=True which is equivalent to extension=I :域参数应该有效,在高斯有理数的情况下,您还可以使用gaussian=True相当于extension=I

In [24]: factor(z**2 + 1, gaussian=True)
Out[24]: (z - ⅈ)⋅(z + ⅈ)

That doesn't work in your case though because the factorisation needs to be over QQ(I, sqrt(2)) rather than QQ(I) .不过,这在您的情况下不起作用,因为分解需要超过QQ(I, sqrt(2))而不是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'R''C'不能按预期工作的原因是因为它们是不精确的浮点域,而不是代表纯数学意义上的实数或复数的域,因式分解是

The approaches above can be combined though with上述方法可以与

In [28]: e = z**2 + 2

In [29]: factor(e, extension=roots(e))
Out[29]: (z - √2⋅ⅈ)⋅(z + √2⋅ⅈ)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM