factor(x**2+x+1) is not working in sympy? Is there any solution to find factors?

Viewed 1996

I'm trying to find the factors of function x**2+x+1.

Most of the suggetions are to use factor and you get the answer. However, factor(f) doesn't work for all the equations.

I also tried factor(f,gaussian=True) but gives the same result.

import sympy as sp
x = sp.Symbol('x')
f = x**2 + x + 1
sp.factor(f)

Output of the code: x**2 + x + 1

Expected output: complex roots

-1/2 - sqrt(3)*i/2

-1/2 + sqrt(3)*i/2

1 Answers

It's easier to use solveset :

import sympy as sp
x = sp.Symbol('x')
f = x**2 + x + 1
polyRoots = sp.solveset(f, x)
print(polyRoots)

and you'll get complex factors

Related