Ask Your Question

Complex roots of non-squarefree real polynomial

asked 2020-07-31 09:34:25 +0200

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)
--> ok, good result
P0 = 1-2*x-7*x^2-4*x^3 # -4 * (x-1/4) * (x + 1)^2
P  = R0X( P0)
--> waiting, waiting ....

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

 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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-07-31 11:59:01 +0200

Sébastien gravatar image

updated 2020-07-31 18:08:39 +0200

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
edit flag offensive delete link more


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

Olivier R. gravatar imageOlivier R. ( 2020-07-31 12:47:54 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-07-31 09:34:25 +0200

Seen: 199 times

Last updated: Jul 31 '20