# About roots of a certain polynomial equation

Why is Sage hanging up trying to find roots of this equation?

0 = (x^2 - 6.00000000000000)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1

edit retag close merge delete

Sort by » oldest newest most voted

The answer is somehow similar to that one. It is important to know where your objects are living and define them into the right place. As for mathematics, Sage will not be able to handle ill-defined expressions consistently.

First, when you write 6.00000000000000 you define a numerical (floating-point, i.e. approximated) number:

sage: 6.00000000000000.parent()
Real Field with 53 bits of precision


While, when you write e^(-2/5*I*pi), you define a symbolic expression:

sage: (e^(-2/5*I*pi)).parent()
Symbolic Ring


So, if you want something exact, you have to replace 6.00000000000000 by 6, which is an exact integer:

sage: 6.parent()
Integer Ring


Also, e^(-2/5*I*pi) is not any complex number, but an algebraic one, so you should take the benefit of this.

Then, your function is not a genuine polynomial but a symbolic expression (you could also have cos(log(x)) in such expression for example):

sage: p = (x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
sage: p.parent()
Symbolic Ring


So, let us transform it into a genuine polynomial defined on the field of (complex) algebraic numbers:

sage: P = p.polynomial(QQbar)
sage: P.parent()
Univariate Polynomial Ring in x over Algebraic Field


The Univariate Polynomial Ring in x over Algebraic Field makes more sense than a mysterious Symbolic Ring, isn't it ?

In this safer place, you can have a look at its roots:

sage: P.roots()
[(-2.175570504584946? + 0.?e-17*I, 1),
(-0.618033988749895? + 0.?e-17*I, 1),
(0.1755705045849463? + 0.?e-18*I, 1),
(2.618033988749895? + 0.?e-17*I, 1)]

more

Actually, Sage can solve your form symbolically as soon as you replace 6.0 with 6 and apply simplify_rectform:

sage: ((x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1).simplify_rectform()
(x^2 - 6)*x^2 - 2*x*(sqrt(5) - 1) + 1/2*sqrt(5) - 1/2
sage: solve(_,x)
[x == -1/2*sqrt(-2*sqrt(5) + 10) - 1, x == 1/2*sqrt(-2*sqrt(5) + 10) - 1, x == -1/2*sqrt(2*sqrt(5) + 6) + 1, x == 1/2*sqrt(2*sqrt(5) + 6) + 1]

more

I assume you are wondering why Sage is not recognizing that $(x^2 - 6)x^2 - 4x(e^{\frac{2}{5}i\pi} + e^{\frac{-2}{5}i\pi}) - e^{\frac{4}{5}i\pi} - e^{\frac{-4}{5}i\pi} - 1=(x^2 - 6)x^2 - 8xcos(\frac{2}{5}\pi) - 2*cos(\frac{4}{5}\pi) - 1$, and thereafter doesn't find the four real roots: $x=-2.1755705045849463, -0.618033988749891, 0.17557050458494627, 2.618033988749895$.

Mixing the world of solving algebraic equations - which are exact - with the world of finding roots - which are approximations - is seldom a good idea. If you would split both worlds, it goes fluently.

var('x')
f(x)=(x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
g(x)=real_part(f(x)).simplify()
print g
x |--> x^4 - 6*x^2 - 2*sqrt(5)*x + 2*x + 1/2*sqrt(5) - 1/2

print [find_root(g,-3,-2), find_root(g,-1,0), find_root(g,0,1), find_root(g,2,3)]
[-2.1755705045849463, -0.6180339887498911, 0.17557050458494627, 2.618033988749895]


Stated differently, always simplify your function (= exact) before going into a numerical process such as root finding. Any system - thus also Sage - hangs up because it is impossible to determine the simplification numerically.

more

@Rolandb Why did you remove the imaginary part of the function? And since this is a quartic equation, shouldn't it be able to tell me the exact roots in terms of square-roots?

( 2015-01-20 18:02:54 -0500 )edit