arb_poly – polynomials over real numbers¶
- class flint.arb_poly(val=None)¶
- coeffs(self)¶
Returns the coefficients of
selfas a list>>> from flint import fmpz_poly >>> f = fmpz_poly([1,2,3,4,5]) >>> f.coeffs() [1, 2, 3, 4, 5]
- complex_roots(self, **kwargs)¶
Compute the complex roots of the polynomial by converting from arb_poly to acb_poly
- degree(self) long¶
- derivative(self)¶
- evaluate(self, xs, algorithm='fast')¶
Multipoint evaluation: evaluates self at the list of points xs. The algorithm can be ‘iter’ or ‘fast’. The ‘fast’ algorithm is asymptotically fast, but has worse numerical stability.
Note: for ordinary single-point evaluation, just call the polynomial with the point as the argument.
- classmethod from_roots(cls, roots)¶
Constructs the monic polynomial whose roots are the given real numbers.
>>> from flint import arb_poly, ctx >>> ctx.prec = 53 >>> arb_poly.from_roots(range(4)) 1.00000000000000*x^4 + (-6.00000000000000)*x^3 + 11.0000000000000*x^2 + (-6.00000000000000)*x
There is currently no dedicated method to construct a real polynomial from complex conjugate roots (use
acb_poly.from_roots()).
- integral(self)¶
- classmethod interpolate(cls, xs, ys, algorithm='fast')¶
Constructs the unique interpolating polynomial of length at most n taking the values ys when evaluated at the n distinct points xs. Algorithm can be ‘newton’, ‘barycentric’ or ‘fast’. The ‘fast’ algorithm is asymptotically fast, but has worse numerical stability.
- left_shift(self, slong n)¶
Returns
selfshifted left byncoefficients by inserting zero coefficients. This is equivalent to multiplying the polynomial by x^n>>> f = arb_poly([1,2,3]) >>> f.left_shift(0) 3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000 >>> f.left_shift(1) 3.00000000000000*x^3 + 2.00000000000000*x^2 + 1.00000000000000*x >>> f.left_shift(4) 3.00000000000000*x^6 + 2.00000000000000*x^5 + 1.00000000000000*x^4
- length(self) long¶
- real_roots(self)¶
- repr(self)¶
- right_shift(self, slong n)¶
Returns
selfshifted right byncoefficients. This is equivalent to the floor division of the polynomial by x^n>>> f = arb_poly([1,2,3]) >>> f.right_shift(0) 3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000 >>> f.right_shift(1) 3.00000000000000*x + 2.00000000000000 >>> f.right_shift(4) 0
- roots(self)¶
Computes all the roots in the base ring of the polynomial. Returns a list of all pairs (v, m) where v is the integer root and m is the multiplicity of the root.
To compute complex roots of a polynomial, instead use the
.complex_roots()method, which is available on certain polynomial rings.>>> from flint import fmpz_poly >>> fmpz_poly([1, 2]).roots() [] >>> fmpz_poly([2, 1]).roots() [(-2, 1)] >>> fmpz_poly([12, 7, 1]).roots() [(-3, 1), (-4, 1)] >>> (fmpz_poly([-5,1]) * fmpz_poly([-5,1]) * fmpz_poly([-3,1])).roots() [(3, 1), (5, 2)]
- str(self, bool ascending=False, var='x', *args, **kwargs)¶
Convert to a human-readable string (generic implementation for all polynomial types).
If ascending is True, the monomials are output from low degree to high, otherwise from high to low.
- truncate(self, slong n)¶
Notionally truncate the polynomial to have length
n. Ifnis larger than the length of the input, then a copy ofselfis returned. Ifnis not positive, then the zero polynomial is returned.Effectively returns this polynomial \(\mod x^n\).
>>> f = arb_poly([1,2,3]) >>> f.truncate(3) 3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000 >>> f.truncate(2) 2.00000000000000*x + 1.00000000000000 >>> f.truncate(1) 1.00000000000000 >>> f.truncate(0) 0 >>> f.truncate(-1) 0
- unique_fmpz_poly(self)¶