# roots doesn't find all roots of a polynomial

Let's consider the following example:

w = x^4 - (1+3*i)*x^3 - (2-4*i)*x^2 + (6-2*i)*x - 4 - 4*i
p = x^4 + (1-3*i)*x^3 - (4-3*i)*x^2 - (4-2*i)*x + 2*i
solve(w, x)
w.roots()


When using solve, all complex roots are found. When using roots, only two of them. Why?

edit retag close merge delete

Sort by » oldest newest most voted

As you can see with the documentation of the roots() method, (which you can get by typing w.roots?), " Not all roots are guaranteed to be found.". But you can also set a ring option to tell that the symbolic expression should be considered as a polynomial over the given ring, and find roots which belong to that ring. You can get all root by chosing the albebraic numbers for the ring:

sage: w.roots(ring=QQbar)
[(-1 + 1*I, 1), (2*I, 1), (1 - 1*I, 1), (1 + 1*I, 1)]


Or numerically, with the complex double field:

sage: w.roots(ring=CDF)
[(-1.0000000000000002 + 1.0000000000000004*I, 1),
(-1.473610092985238e-15 + 2.000000000000001*I, 1),
(1.0000000000000004 - 0.9999999999999997*I, 1),
(1.0000000000000018 + 1.0000000000000038*I, 1)]

more