# Complex roots of non-squarefree real polynomial

Dear all, I need in my script the maximum of the absolute value of the roots of a polynomial. I don't know the polynomial the user will introduce, so it may well be non squarefree and with non-integer coefficients. Here is something that baffled me for some time:

x = var('x')
R0X = PolynomialRing(RealField(40), x)
P0 = 1 + 2*x + x ^2
P  = R0X( P0)
complex_roots(P)
--> ok, good result
P0 = 1-2*x-7*x^2-4*x^3 # -4 * (x-1/4) * (x + 1)^2
P  = R0X( P0)
complex_roots(P)
--> waiting, waiting ....


The mystery is not so hard to pierce, I think:

 P.squarefree_decomposition()
sage: -4.0000*x^3 - 7.0000*x^2 - 2.0000*x + 1.0000


But then, I still have my initial problem! I can use some apriori bound for these roots. I'm still unhappy of not being able to get a better numerical approximation --

Many thanks for your lights! Olivier

edit retag close merge delete

Sort by » oldest newest most voted

x=var('x') is the variable x defined in the symbolic ring. You want to avoid that ring. The following creates the variable x that lives in the Univariate Polynomial Ring in x over Rational Field.

sage: QQ
Rational Field
sage: R.<x> = QQ[]
sage: R
Univariate Polynomial Ring in x over Rational Field
sage: p = 1-2*x-7*x^2-4*x^3
sage: p.roots()
[(-1, 2), (1/4, 1)]
sage: p.roots(multiplicities=False)
[-1, 1/4]


When there are complex roots, you may extend the ring where to find roots by doing:

sage: p.roots(QQbar)
[(-1, 2), (1/4, 1)]


where QQbar is the algebraic closure of the rational field QQ:

sage: QQbar
Algebraic Field

more

Oups, many thanks, 'p.roots()' works like a charm! I guess 'complex_roots(p)' must be kept for more specific usage. Best, O.

( 2020-07-31 05:47:54 -0500 )edit