acb_poly – polynomials over complex numbers

class flint.acb_poly(val=None)
coeffs(self)

Returns the coefficients of self as a list

>>> from flint import fmpz_poly
>>> f = fmpz_poly([1,2,3,4,5])
>>> f.coeffs()
[1, 2, 3, 4, 5]
complex_roots(tol=None, maxprec=None)

acb_poly.roots(s, tol=None, maxprec=None)

Attempts to isolate all the complex roots of s. If tol is specified, the roots are further refined to at least the requested tolerance. The input polynomial must be squarefree and sufficiently accurate. Raises an exception if unsuccessful.

>>> for c in acb_poly.from_roots([1,2,3,4,5]).roots(1e-10): print(float(c.real))
...
1.0
2.0
3.0
4.0
5.0
>>> for c in acb_poly.from_roots([1,2,2,4,5]).roots(1e-10): print(c)
...
Traceback (most recent call last):
  ...
ValueError: roots() failed to converge: insufficient precision, or squareful input
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 complex numbers.

>>> acb_poly.from_roots(range(4))
1.00000000000000*x^4 + (-6.00000000000000)*x^3 + 11.0000000000000*x^2 + (-6.00000000000000)*x
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 self shifted left by n coefficients by inserting zero coefficients. This is equivalent to multiplying the polynomial by x^n

>>> f = acb_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 self shifted right by n coefficients. This is equivalent to the floor division of the polynomial by x^n

>>> f = acb_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
root_bound(self)

Returns an upper bound for the absolute value of the roots of self.

roots(s, tol=None, maxprec=None)

Attempts to isolate all the complex roots of s. If tol is specified, the roots are further refined to at least the requested tolerance. The input polynomial must be squarefree and sufficiently accurate. Raises an exception if unsuccessful.

>>> for c in acb_poly.from_roots([1,2,3,4,5]).roots(1e-10): print(float(c.real))
...
1.0
2.0
3.0
4.0
5.0
>>> for c in acb_poly.from_roots([1,2,2,4,5]).roots(1e-10): print(c)
...
Traceback (most recent call last):
  ...
ValueError: roots() failed to converge: insufficient precision, or squareful input
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. If n is larger than the length of the input, then a copy of self is returned. If n is not positive, then the zero polynomial is returned.

Effectively returns this polynomial \(\mod x^n\).

>>> f = acb_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)