Get a list of factors in sympy.factor

I am implementing an algorithm, and in it I need to get a factor polynomial f (x) = p (x) q (x) with p and q relatively simple. I can use, of course, sympy.factor, but I would like to build a function that returns, possibly, a list of factors as a result of sympy.factor.

For instance,

x = sympy.Symbol('x')
y = sympy.Symbol('y')
g = sympy.Poly(y**4 + x*y**3 + y**2 + x*y, y)
sympy.factor(g)

throws out

y*(x + y)*(y**2 + 1)

so maybe I could build a parser that interprets the string and divides it between the brackets, displaying a list of [y, x + y, y * * 2 + 1], but I would like to know: is it easier?

+2
source share
1 answer

factor_list, . , Python 3. Python 2

In [1]: factor_list(y**4 + x*y**3 + y**2 + x*y, y)
Out[1]:
⎛   ⎡                    ⎛ 2       ⎞⎤⎞
⎝1, ⎣(y, 1), (x + y, 1), ⎝y  + 1, 1⎠⎦⎠

- . - (factor, power) ( constant * factor**power * ... * factor**power).

+3

Source: https://habr.com/ru/post/1690646/


All Articles