fmpq_poly – polynomials over rational numbers

class flint.fmpq_poly(p=None, q=None)

The fmpq_poly type represents dense univariate polynomials over the rational numbers. For efficiency reasons, an fmpq_poly is structurally an integer polynomial with a single common denominator.

>>> fmpq_poly([1,2,3],5) ** 3
27/125*x^6 + 54/125*x^5 + 63/125*x^4 + 44/125*x^3 + 21/125*x^2 + 6/125*x + 1/125
>>> ctx.pretty = False
>>> fmpq_poly([1,2,3],5) ** 3
fmpq_poly([1, 6, 21, 44, 63, 54, 27], 125)
>>> divmod(fmpq_poly([2,0,1,1,6]), fmpq_poly([3,5,7]))
(fmpq_poly([38, -161, 294], 343), fmpq_poly([572, 293], 343))
>>> ctx.pretty = True
static bernoulli_poly(n)

Returns the Bernoulli polynomial \(B_n(x)\) as an fmpq_poly.

>>> fmpq_poly.bernoulli_poly(2)
x^2 + (-1)*x + 1/6
coeffs(self)
degree(self) → long
denom(self)
static euler_poly(n)

Returns the Euler polynomial \(E_n(x)\) as an fmpq_poly.

>>> fmpq_poly.euler_poly(3)
x^3 + (-3/2)*x^2 + 1/4
factor(self)

Factors self into irreducible polynomials. Returns (c, factors) where c is the leading coefficient and factors is a list of (poly, exp) pairs with all poly monic.

>>> fmpq_poly.legendre_p(5).factor()
(63/8, [(x, 1), (x^4 + (-10/9)*x^2 + 5/21, 1)])
>>> (fmpq_poly([1,-1],10) ** 5 * fmpq_poly([1,2,3],7)).factor()
(-3/700000, [(x^2 + 2/3*x + 1/3, 1), (x + (-1), 5)])
gcd(self, other)

Returns the greatest common divisor of self and other.

>>> A = fmpq_poly([1,2,6],6); B = fmpq_poly([4,2,1],12)
>>> (A * B).gcd(B)
x^2 + 2*x + 4
static legendre_p(n)

Returns the Legendre polynomial \(P_n(x)\) as an fmpq_poly.

>>> fmpq_poly.legendre_p(3)
5/2*x^3 + (-3/2)*x
length(self) → long
numer(self)
p

fmpq_poly.numer(self)

q

fmpq_poly.denom(self)

repr(self)
roots(self, **kwargs)

Computes the complex roots of this polynomial. See fmpz_poly.roots().

>>> fmpq_poly([fmpq(2,3),1]).roots()
[([-0.666666666666667 +/- 3.34e-16], 1)]
str(self, bool ascending=False)

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.