Isolate all real roots of a real univariate polynomial
This functionality does not run in MATLAB.
polylib::realroots(p
) polylib::realroots(p
,eps
)
polylib::realroots(p)
returns intervals isolating
the real roots of the real univariate polynomial p
.
polylib::realroots(p, eps)
returns refined
intervals approximating the real roots of p
to
the relative precision given by eps
.
All coefficients of p
must be real and numerical,
i.e., either integers, rationals or floatingpoint numbers. Numerical
symbolic objects such as sqrt(2)
, exp(10*PI)
etc.
are accepted, if they can be converted to real floatingpoint numbers
via float
. The
same holds for the precision goal eps
.
The isolating intervals are ordered such that their centers are increasing, i.e., a_{i} + b_{i} < a_{i + 1} + b_{i + 1}.
The number nops(realroots(p))
of intervals
is the number of real roots of p
. Multiple roots
are counted only once. Cf. Example 3.
Isolating intervals may be quite large. The optional argument eps
may
be used to refine the intervals such that they approximate the real
roots to a relative precision eps
. With this argument
the returned intervals satisfy
,
i.e., each center
approximates
a root with a relative precision eps/2
.
Note:
Some care should be taken when trying to obtain highly accurate
approximations of the roots via small values of 
Note:
Unexpected results may be obtained when the polynomial contains
irrational coefficients. Internally, any such coefficient c is
converted to a floatingpoint number. This float is then replaced
by an approximating rational number r satisfying
.
Finally, 
The function is sensitive to the environment variable DIGITS
,
if there are noninteger or nonrational coefficients in the polynomial.
Any such coefficient is replaced by a rational number approximating
the coefficient to DIGITS
significant decimal places.
We use a polynomial expression as input to polylib::realroots
:
p := (x  1/3)*(x  1)*(x  4/3)*(x  2)*(x  17):
polylib::realroots(p)
The roots 1 and 2 are found exactly: the corresponding intervals
have length 0. The other isolating intervals are quite large. We refine
the intervals such that they approximate the roots to 12 decimal places.
Note that this is independent of the current value of DIGITS
,
because no floatingpoint arithmetic is used:
polylib::realroots(p, 10^(12))
We convert these exact bounds for the real roots to floating
point approximations. Note that with the default value of DIGITS=10
we
ignore 2 of the 12 correct digits the rational bounds could potentially
give:
map(%, map, float)
delete p:
Orthogonal polynomials of degree n have n simple
real roots. We consider the Legendre polynomial of degree 5,
available in the library orthpoly
for orthogonal
polynomials:
polylib::realroots(orthpoly::legendre(5, x), 10^(DIGITS)):
map(%, float@op, 1)
We consider a polynomial with a multiple root:
p := poly((x  1/3)^3*(x  1), [x])
Note that only one isolating interval [
0,
1] is returned for the triple root
:
polylib::realroots(p)
delete p:
We consider a polynomial with nonrational roots:
p := (x  3)^2*(x  PI)^2:
Converting the result of polylib::realroots
to
floatingpoint numbers one sees that the exact roots 3, 3,
PI, PI
are approximated only to 3 decimal places:
map(polylib::realroots(p, 10^(10)), map, float)
This is caused by the internal rationalization of the coefficients
of p
.
The intervals returned by polylib::realroots(p, 10^(10))
correctly
locate the 4 exact roots of this rationalized polynomial to a precision
of 10 digits. However, because all 4 roots are close, the small perturbations
of the coefficients introduced by rationalization have a drastic effect
on the location of the roots. In particular, rationalization splits
the two original double roots into 4 simple roots.
delete p:
We consider a further example involving nonexact coefficients. First we approximate the roots of a polynomial with exact coefficients:
p1 := (x  1/3)^3*(x  4/3):
map(polylib::realroots(p1, 10^(10)), map, float)
Now we introduce roundoff errors by replacing one entry by a floatingpoint approximation:
p2 := (x  1.0/3)^3*(x  4/3):
map(polylib::realroots(p2, 10^(10)),map,float)
In this example rationalization caused the triple root 1/3
to
split into one real root and two complex conjugate roots.
delete p1, p2:
We want to approximate roots to a precision of 1000 digits:
p := x^5  129/20*x^4 + 69/5*x^3  14*x^2 + 12*x  8:
We recommend not to obtain the result directly by polylib::realroots(p,10^(1000))
,
because the internal bisectioning process for refining crude isolating
intervals converges only linearly. Instead, we compute first approximations
of the roots to a precision of 10 digits:
approx := map(polylib::realroots(p, 10^(10)), float@op, 1)
These values are used as starting points for a numerical root
finder. The internal Newton search in numeric::fsolve
converges quadratically
and yields the high precision results much faster than polylib::realroots
:
DIGITS := 1000:
roots := map(approx, x0 > numeric::fsolve([p = 0], [x = x0]))
[[x = 1.489177598846870281338916114673844643894...], [x = 1.752191733304413195335101727880090131407...], [x = 3.255184555797733438479691333705558491124...]]
delete approx, DIGITS, roots, x0:

A univariate polynomial: either an expression or a polyomial
of domain type 

A (small) positive real number determining the size of the returned intervals. 
List of lists [[a_{1}, b_{1}],
[a_{2}, b_{2}],
…] with rational numbers a_{i} ≤ b_{i} is
returned. Lists with a_{i} = b_{i} represent
exact rational roots. Lists with a_{i} < b_{i} represent
open intervals containing exactly one real root. If the polynomial
has no real roots, then the empty list [ ]
is returned.