Hi, On 30 November 2015 at 07:01, Adam Leeper <[email protected]> wrote: > 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 :)
output _5 is correct, x**2 + 3 doesn't have linear factors over Q(I). However, it has over Q(I, sqrt(3)): In [1]: factor(x**2 + 3, x, extension=[I, sqrt(3)]) Out[1]: (x - sqrt(3)*I)*(x + sqrt(3)*I) With all_roots() method (or roots() function), you can get the expected form like this: In [2]: Mul(*[ (x - r)**k for r, k in roots(x**2 + 3).items() ]) Out[2]: (x - sqrt(3)*I)*(x + sqrt(3)*I) Mateusz > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/2ef035c5-e6cf-4573-99ee-c30d72f86e1a%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAGBZUCbA4P9x6fga4wMRRYfbhRGjF%3DudS8EKL%2Bb6jvJ%3Djy_9%3Dg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
