Univariate polynomials and solvers

Mmx] 

use "realroot"; type_mode?:= true

:

The default representation for polynomials is the sparse representation corresponding to the following ring construction:

Mmx] 

R := ZZ['x]

:

Here we define a polynomial from a string in the ring R:

Mmx] 

s:=R<<"x^17-1454*x^5+2*x^2-7"

:

In this representation only the non-zero coefficients are stored:

Mmx] 

coefficients s

:

To manipulate dense (multivariate) polynomials, one can use the following ring construction:

Mmx] 

R := tensor ZZ['x]

:

The same polynomial is constructed in this ring as:

Mmx] 

p:=R<<"x^17-1454*x^5+2*x^2-7"

:

or from s as:

Mmx] 

tensor s

:

Now we list, the coefficients of all its monomials up to its degree, even those which are zero:

Mmx] 

coefficients p

:

The Bernstein basis over the interval can also be used:

Mmx] 

b := bernstein QQ['x] <<"x^17-1454*x^5+2*x^2-7"

:

Notice that even if the polynomial has integer coefficients in the monomial basis, its representation in the Bernstein basis may have rational coefficients. That is why we change the coefficient field, using the ring of rational numbers.

We list the coefficients of the polynomial in the Bernstein basis:

Mmx] 

coefficients b

:

Here are the coefficient of the square of this polynomial:

Mmx] 

coefficients (b*b)

:

Univariate solvers are using the dense monomial representation. Here we output intervals with rational bounds, which contain exactly one real root of the polynomial. The precision we require on this approximation is :

Mmx] 

solve (p,500)

:

We can also approximate the roots. The default bit precision which is used by the function solve_approx is the precision given by:

Mmx] 

bit_precision

:

Mmx] 

solve_approx p

:

Here we increase the precision to get 1OOO exact bits on the numerical approximation of the roots:

Mmx] 

solve_approx(p,1000)

:

Mmx]