AUTHORS:
A dense polynomial over the integers, implemented via FLINT.
EXAMPLES:
sage: R.<x> = ZZ[]
sage: (x^2+1)//x
x
sage: (5*x^2+1)//(2*x)
2*x
Divide by a scalar.
sage: (5*x^3 + 5*x + 10)//5
x^3 + x + 2
TESTS:
sage: x//0
...
ZeroDivisionError: division by zero
sage: (x^2 + 13*x + 169) // 13
x + 13
Returns coefficient of x^n, or zero if n is negative.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = 2*x^2 - 3
sage: f[0]
-3
sage: f[1]
0
sage: f[2]
2
sage: f[3]
0
sage: f[-1]
0
x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
Used for pickling.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: loads(dumps(x)) == x
True
sage: f = 2*x + 3
sage: loads(dumps(f)) == f
True
Returns self plus right.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = 2*x + 1
sage: g = -3*x^2 + 6
sage: f + g
-3*x^2 + 2*x + 7
EXAMPLES:
sage: R.<x> = ZZ[]
sage: f = (x^2-2)*(x^5-3)^2
sage: f._factor_ntl()
(x^2 - 2) * (x^5 - 3)^2
sage: (12345678987654321234567898765432123456789876*f)._factor_ntl()
12345678987654321234567898765432123456789876 * (x^2 - 2) * (x^5 - 3)^2
EXAMPLES:
sage: R.<x> = ZZ[]
sage: f = (x^2-2)*(x^5-3)^2
sage: f._factor_pari()
(x^2 - 2) * (x^5 - 3)^2
sage: (1234567898765432123456789876543212345678987*f)._factor_pari()
1234567898765432123456789876543212345678987 * (x^2 - 2) * (x^5 - 3)^2
Return the latex representation of this polynomial.
EXAMPLES:
sage: R.<t> = ZZ['t']
sage: latex(t^10-t^2-5*t+1)
t^{10} - t^{2} - 5t + 1
sage: cyclotomic_polynomial(10^5)._latex_()
'x^{40000} - x^{30000} + x^{20000} - x^{10000} + 1'
sage: cyclotomic_polynomial(10^5)._latex_(name='y')
'y^{40000} - y^{30000} + y^{20000} - y^{10000} + 1'
Returns self multiplied by right, where right is a scalar (integer).
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: x*3
3*x
sage: (2*x^2 + 4)*3
6*x^2 + 12
Returns self multiplied by right.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: (x - 2)*(x^2 - 8*x + 16)
x^3 - 10*x^2 + 32*x - 32
Returns negative of self.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = 2*x - 1
sage: -f
-2*x + 1
EXAMPLES:
sage: t = PolynomialRing(ZZ,"t").gen()
sage: f = t^3 + 3*t - 17
sage: pari(f)
t^3 + 3*t - 17
sage: f._pari_(variable='y')
y^3 + 3*y - 17
Return string representation of this polynomial.
EXAMPLES:
sage: R.<x> = ZZ['x']
sage: (-x+1)^5
-x^5 + 5*x^4 - 10*x^3 + 10*x^2 - 5*x + 1
sage: ((-x+1)^5)._repr()
'-x^5 + 5*x^4 - 10*x^3 + 10*x^2 - 5*x + 1'
sage: ((-x+1)^5)._repr(name='y')
'-y^5 + 5*y^4 - 10*y^3 + 10*y^2 - 5*y + 1'
Returns self multiplied by right, where right is a scalar (integer).
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: 3*x
3*x
sage: 3*(2*x^2 + 4)
6*x^2 + 12
Return self minus right.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = 2*x + 1
sage: g = -3*x^2 + 6
sage: f - g
3*x^2 + 2*x - 5
Sets coefficient of to value.
This is very unsafe, because Sage polynomials are supposed to be immutable. (Shhhh don’t tell anyone!)
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = 2*x^2 + 3; f
2*x^2 + 3
sage: f._unsafe_mutate(1, 42); f
2*x^2 + 42*x + 3
sage: f._unsafe_mutate(1, int(5)); f
2*x^2 + 5*x + 3
sage: f._unsafe_mutate(1, Zmod(15)(7)); f
2*x^2 + 7*x + 3
Return the greatest common divisor of the coefficients of this polynomial.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: (2*x^2 - 4*x^4 + 14*x^7).content()
2
sage: x.content()
1
sage: R(1).content()
1
sage: R(0).content()
0
TESTS:
sage: t = x^2+x+1
sage: t.content()
1
sage: (123456789123456789123456789123456789123456789*t).content()
123456789123456789123456789123456789123456789
Return the degree of this polynomial. The zero polynomial has degree -1.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: x.degree()
1
sage: (x^2).degree()
2
sage: R(1).degree()
0
sage: R(0).degree()
-1
Return the discriminant of self, which is by definition
where , and
is
the leading coefficient of a. If proof is False (the default is
True), then this function may use a randomized strategy that errors
with probability no more than
.
EXAMPLES:
sage: R.<x> = ZZ[]
sage: f = 3*x^3 + 2*x + 1
sage: f.discriminant()
-339
sage: f.discriminant(proof=False)
-339
This function overrides the generic polynomial factorization to make a somewhat intelligent decision to use Pari or NTL based on some benchmarking.
Note: This function factors the content of the polynomial, which can take very long if it’s a really big integer. If you do not need the content factored, divide it out of your polynomial before calling this function.
EXAMPLES:
sage: R.<x>=ZZ[]
sage: f=x^4-1
sage: f.factor()
(x - 1) * (x + 1) * (x^2 + 1)
sage: f=1-x
sage: f.factor()
(-1) * (x - 1)
sage: f.factor().unit()
-1
sage: f = -30*x; f.factor()
(-1) * 2 * 3 * 5 * x
Return the factorization of self modulo the prime .
INPUT:
OUTPUT:
factorization of self reduced modulo p.
EXAMPLES:
sage: R.<x> = ZZ['x']
sage: f = -3*x*(x-2)*(x-9) + x
sage: f.factor_mod(3)
x
sage: f = -3*x*(x-2)*(x-9)
sage: f.factor_mod(3)
...
ValueError: factorization of 0 not defined
sage: f = 2*x*(x-2)*(x-9)
sage: f.factor_mod(7)
(2) * x * (x + 5)^2
Return -adic factorization of self to given precision.
INPUT:
OUTPUT:
factorization of self reduced modulo p.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = x^2 + 1
sage: f.factor_padic(5, 4)
((1 + O(5^4))*x + (2 + 5 + 2*5^2 + 5^3 + O(5^4))) * ((1 + O(5^4))*x + (3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)))
Return the GCD of self and right. The leading coefficient need not be 1.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = (6*x + 47)*(7*x^2 - 2*x + 38)
sage: g = (6*x + 47)*(3*x^3 + 2*x + 1)
sage: f.gcd(g)
6*x + 47
Returns True if self is equal to zero.
EXAMPLES:
sage: R.<x> = ZZ[]
sage: R(0).is_zero()
True
sage: R(1).is_zero()
False
sage: x.is_zero()
False
Return the LCM of self and right.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = (6*x + 47)*(7*x^2 - 2*x + 38)
sage: g = (6*x + 47)*(3*x^3 + 2*x + 1)
sage: h = f.lcm(g); h
126*x^6 + 951*x^5 + 486*x^4 + 6034*x^3 + 585*x^2 + 3706*x + 1786
sage: h == (6*x + 47)*(7*x^2 - 2*x + 38)*(3*x^3 + 2*x + 1)
True
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
sage: x = PolynomialRing(ZZ,'x').0
sage: f = x^3 + 3*x - 17
sage: f.list()
[-17, 3, 0, 1]
sage: f = PolynomialRing(ZZ,'x')(0)
sage: f.list()
[]
Write A = self. This function computes polynomials and
and an integer
such that
where R has degree less than that of B.
INPUT:
OUTPUT:
EXAMPLES:
sage: R.<x> = ZZ['x']
sage: A = R(range(10)); B = 3*R([-1, 0, 1])
sage: Q, R, d = A.pseudo_divrem(B)
sage: Q, R, d
(9*x^7 + 8*x^6 + 16*x^5 + 14*x^4 + 21*x^3 + 18*x^2 + 24*x + 20, 75*x + 60, 1)
sage: B.leading_coefficient()^d * A == B*Q + R
True
Attempts to divide self by right, and return a quotient and remainder.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = R(range(10)); g = R([-1, 0, 1])
sage: q, r = f.quo_rem(g)
sage: q, r
(9*x^7 + 8*x^6 + 16*x^5 + 14*x^4 + 21*x^3 + 18*x^2 + 24*x + 20, 25*x + 20)
sage: q*g + r == f
True
sage: f = x^2
sage: f.quo_rem(0)
...
ZeroDivisionError: division by zero polynomial
sage: f = (x^2 + 3) * (2*x - 1)
sage: f.quo_rem(2*x - 1)
(x^2 + 3, 0)
sage: f = x^2
sage: f.quo_rem(2*x - 1)
(0, x^2)
TESTS:
sage: z = R(0)
sage: z.quo_rem(1)
(0, 0)
sage: z.quo_rem(x)
(0, 0)
sage: z.quo_rem(2*x)
(0, 0)
Returns isolating intervals for the real roots of this polynomial.
EXAMPLE: We compute the roots of the characteristic polynomial of some Salem numbers:
sage: R.<x> = PolynomialRing(ZZ)
sage: f = 1 - x^2 - x^3 - x^4 + x^6
sage: f.real_root_intervals()
[((1/2, 3/4), 1), ((1, 3/2), 1)]
Returns the resultant of self and other, which must lie in the same polynomial ring.
If proof = False (the default is proof=True), then this function may
use a randomized strategy that errors with probability no more than
.
INPUT:
OUTPUT:
an element of the base ring of the polynomial ring
EXAMPLES:
sage: x = PolynomialRing(ZZ,'x').0
sage: f = x^3 + x + 1; g = x^3 - x - 1
sage: r = f.resultant(g); r
-8
sage: r.parent() is ZZ
True
Return the square-free decomposition of self. This is a partial factorization of self into square-free, relatively prime polynomials.
This is a wrapper for the NTL function SquareFreeDecomp.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: p = (x-1)^2 * (x-2)^2 * (x-3)^3 * (x-4)
sage: p.squarefree_decomposition()
(x - 4) * (x^2 - 3*x + 2)^2 * (x - 3)^3
sage: p = 37 * (x-1)^2 * (x-2)^2 * (x-3)^3 * (x-4)
sage: p.squarefree_decomposition()
(37) * (x - 4) * (x^2 - 3*x + 2)^2 * (x - 3)^3
Return g, u, v such that g = u*self + v*right.
If self and right are coprime as polynomials over the rationals, then g is guaranteed to be the resultant of self and right, as a constant polynomial.
EXAMPLES:
sage: P.<x> = PolynomialRing(ZZ)
sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3)
sage: g, u, v = F.xgcd(G)
sage: g, u, v
(27*x^2 + 54, 1, -x^2 - 3*x - 9)
sage: u*F + v*G
27*x^2 + 54
sage: x.xgcd(P(0))
(x, 1, 0)
sage: f = P(0)
sage: f.xgcd(x)
(x, 0, 1)
sage: F = (x-3)^3; G = (x-15)^2
sage: g, u, v = F.xgcd(G)
sage: g, u, v
(2985984, -432*x + 8208, 432*x^2 + 864*x + 14256)
sage: u*F + v*G
2985984