Dense univariate polynomials over \(\RR\), implemented using MPFR

Dense univariate polynomials over \(\RR\), implemented using MPFR

class sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense

Bases: sage.rings.polynomial.polynomial_element.Polynomial

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: PolynomialRealDense(RR['x'], [1, int(2), RR(3), 4/1, pi])
3.14159265358979*x^4 + 4.00000000000000*x^3 + 3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000
sage: PolynomialRealDense(RR['x'], None)
0

TESTS:

Check that errors and interrupts are handled properly (see #10100):

sage: a = var('a')
sage: PolynomialRealDense(RR['x'], [1,a])
Traceback (most recent call last):
...
TypeError: Cannot evaluate symbolic expression to a numeric value.
sage: R.<x> = SR[]
sage: (x-a).change_ring(RR)
Traceback (most recent call last):
...
TypeError: Cannot evaluate symbolic expression to a numeric value.
sage: sig_on_count()
0
sage: alarm(0.5); PolynomialRealDense(RR['x'], ZZ)  # Will loop forever
Traceback (most recent call last):
...
AlarmInterrupt

Test that we don’t clean up uninitialized coefficients (#9826):

sage: k.<a> = GF(7^3)
sage: P.<x> = PolynomialRing(k)
sage: (a*x).complex_roots()
Traceback (most recent call last):
...
TypeError: Unable to convert x (='a') to real number.
change_ring(R)

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [-2, 0, 1.5])
sage: f.change_ring(QQ)
3/2*x^2 - 2
sage: f.change_ring(RealField(10))
1.5*x^2 - 2.0
sage: f.change_ring(RealField(100))
1.5000000000000000000000000000*x^2 - 2.0000000000000000000000000000
degree()

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [1, 2, 3]); f
3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000
sage: f.degree()
2
gcd(other)

Returns the gcd of self and other as a monic polynomial. Due to the inherit instability of division in this inexact ring, the results may not be entirely stable.

EXAMPLES:

sage: R.<x> = RR[]
sage: (x^3).gcd(x^5+1)
1.00000000000000
sage: (x^3).gcd(x^5+x^2)
x^2
sage: f = (x+3)^2 * (x-1)
sage: g = (x+3)^5
sage: f.gcd(g)
x^2 + 6.00000000000000*x + 9.00000000000000

Unless the division is exact (i.e. no rounding occurs) the returned gcd is almost certain to be 1.

sage: f = (x+RR.pi())^2 * (x-1)
sage: g = (x+RR.pi())^5
sage: f.gcd(g)
1.00000000000000
integral()

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [3, pi, 1])
sage: f.integral()
0.333333333333333*x^3 + 1.57079632679490*x^2 + 3.00000000000000*x
list()

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [1, 0, -2]); f
-2.00000000000000*x^2 + 1.00000000000000
sage: f.list()
[1.00000000000000, 0.000000000000000, -2.00000000000000]
quo_rem(other)

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [-2, 0, 1])
sage: g = PolynomialRealDense(RR['x'], [5, 1])
sage: q, r = f.quo_rem(g)
sage: q
x - 5.00000000000000
sage: r
23.0000000000000
sage: q*g + r == f
True
sage: fg = f*g
sage: fg.quo_rem(f)
(x + 5.00000000000000, 0)
sage: fg.quo_rem(g)
(x^2 - 2.00000000000000, 0)

sage: f = PolynomialRealDense(RR['x'], range(5))
sage: g = PolynomialRealDense(RR['x'], [pi,3000,4])
sage: q, r = f.quo_rem(g)
sage: g*q + r == f
True
reverse()

Returns \(x^d f(1/x)\) where \(d\) is the degree of \(f\).

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [-3, pi, 0, 1])
sage: f.reverse()
-3.00000000000000*x^3 + 3.14159265358979*x^2 + 1.00000000000000
shift(n)

Returns this polynomial multiplied by the power \(x^n\). If \(n\) is negative, terms below \(x^n\) will be discarded. Does not change this polynomial.

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RR['x'], [1, 2, 3]); f
3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000
sage: f.shift(10)
3.00000000000000*x^12 + 2.00000000000000*x^11 + x^10
sage: f.shift(-1)
3.00000000000000*x + 2.00000000000000
sage: f.shift(-10)
0

TESTS:

sage: f = RR['x'](0)
sage: f.shift(3).is_zero()
True
sage: f.shift(-3).is_zero()
True
truncate(n)

Returns the polynomial of degree \(< n\) which is equivalent to self modulo \(x^n\).

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RealField(10)['x'], [1, 2, 4, 8])
sage: f.truncate(3)
4.0*x^2 + 2.0*x + 1.0
sage: f.truncate(100)
8.0*x^3 + 4.0*x^2 + 2.0*x + 1.0
sage: f.truncate(1)
1.0
sage: f.truncate(0)
0
truncate_abs(bound)

Truncate all high order coefficients below bound.

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense
sage: f = PolynomialRealDense(RealField(10)['x'], [10^-k for k in range(10)])
sage: f
1.0e-9*x^9 + 1.0e-8*x^8 + 1.0e-7*x^7 + 1.0e-6*x^6 + 0.000010*x^5 + 0.00010*x^4 + 0.0010*x^3 + 0.010*x^2 + 0.10*x + 1.0
sage: f.truncate_abs(0.5e-6)
1.0e-6*x^6 + 0.000010*x^5 + 0.00010*x^4 + 0.0010*x^3 + 0.010*x^2 + 0.10*x + 1.0
sage: f.truncate_abs(10.0)
0
sage: f.truncate_abs(1e-100) == f
True
sage.rings.polynomial.polynomial_real_mpfr_dense.make_PolynomialRealDense(parent, data)

EXAMPLES:

sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import make_PolynomialRealDense
sage: make_PolynomialRealDense(RR['x'], [1,2,3])
3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000

Previous topic

Dense univariate polynomials over \(\ZZ/n\ZZ\), implemented using NTL.

Next topic

Polynomial Interfaces to Singular

This Page