Hi all-
I'm trying to understand why factor() and Poly.all_roots() behave differently when trying to find simple complex roots. I suspect there is something to do with exact values vs. numerical approximations, but I want something that "just works". I'm doing work with transfer functions, and I'd really like to be able to manipulate the numerator and denominator forms and get back an expression of the form (x + a)*(x + b) rather than a list of the roots [-a, -b].
Here's an example:
from sympy import *
x = Symbol('x')
factor(x**2 + 4, x, extension=[I])
Poly(x**2 + 4).all_roots()
factor(x**2 + 3, x, extension=[I])
Poly(x**2 + 3).all_roots()
With sympy 0.7.4.1 the output is:
In [3]: factor(x**2 + 4, x, extension=[I])
Out[3]: (x - 2*I)*(x + 2*I)
In [4]: Poly(x**2 + 4).all_roots()
Out[4]: [-2*I, 2*I]
In [5]: factor(x**2 + 3, x, extension=[I])
Out[5]: x**2 + 3
In [6]: Poly(x**2 + 3).all_roots()
Out[6]: [-sqrt(3)*I, sqrt(3)*I]
As you can see, Out[3] and Out[4] both "work".
But, Out[5] doesn't work (it's just the same as the input), while Out[6] is correct (but not in the form I want it).
Any help is much appreciated :)