Multivariate Polynomials via libSINGULAR

This module implements specialized and optimized implementations for multivariate polynomials over many coefficient rings, via a shared library interface to SINGULAR. In particular, the following coefficient rings are supported by this implementation:

  • the rational numbers \QQ,
  • the ring of integers \ZZ,
  • \ZZ/n\ZZ for any integer n,
  • finite fields \GF{p^n} for p prime and n > 0,
  • and absolute number fields \QQ(a).

AUTHORS:

The libSINGULAR interface was implemented by

  • Martin Albrecht (2007-01): initial implementation
  • Joel Mohler (2008-01): misc improvements, polishing
  • Martin Albrecht (2008-08): added \QQ(a) and \ZZ support
  • Simon King (2009-04): improved coercion
  • Martin Albrecht (2009-05): added \ZZ/n\ZZ support, refactoring

TODO:

  • implement Real, Complex coefficient rings via libSINGULAR

EXAMPLES:

We show how to construct various multivariate polynomial rings:

sage: P.<x,y,z> = QQ[]
sage: P
Multivariate Polynomial Ring in x, y, z over Rational Field

sage: f = 27/113 * x^2 + y*z + 1/2; f
27/113*x^2 + y*z + 1/2

sage: P.term_order()
Degree reverse lexicographic term order

sage: P = PolynomialRing(GF(127),3,names='abc', order='lex')
sage: P
Multivariate Polynomial Ring in a, b, c over Finite Field of size 127

sage: a,b,c = P.gens()
sage: f = 57 * a^2*b + 43 * c + 1; f
57*a^2*b + 43*c + 1

sage: P.term_order()
Lexicographic term order

sage: z = QQ['z'].0
sage: K.<s> = NumberField(z^2 - 2)
sage: P.<x,y> = PolynomialRing(K, 2)
sage: 1/2*s*x^2 + 3/4*s
(1/2*s)*x^2 + (3/4*s)

sage: P.<x,y,z> = ZZ[]; P
Multivariate Polynomial Ring in x, y, z over Integer Ring

sage: P.<x,y,z> = Zmod(2^10)[]; P
Multivariate Polynomial Ring in x, y, z over Ring of integers modulo 1024

sage: P.<x,y,z> = Zmod(3^10)[]; P
Multivariate Polynomial Ring in x, y, z over Ring of integers modulo 59049

sage: P.<x,y,z> = Zmod(2^100)[]; P
Multivariate Polynomial Ring in x, y, z over Ring of integers modulo 1267650600228229401496703205376

sage: P.<x,y,z> = Zmod(2521352)[]; P
Multivariate Polynomial Ring in x, y, z over Ring of integers modulo 2521352
sage: type(P)
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular'>

sage: P.<x,y,z> = Zmod(25213521351515232)[]; P
Multivariate Polynomial Ring in x, y, z over Ring of integers modulo 25213521351515232
sage: type(P)
<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict'>

We construct the Frobenius morphism on \GF{5}[x,y,z] over \GF{5}:

sage: R.<x,y,z> = PolynomialRing(GF(5), 3)
sage: frob = R.hom([x^5, y^5, z^5])
sage: frob(x^2 + 2*y - z^4)
-z^20 + x^10 + 2*y^5
sage: frob((x + 2*y)^3)
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15
sage: (x^5 + 2*y^5)^3
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15

We make a polynomial ring in one variable over a polynomial ring in two variables:

sage: R.<x, y> = PolynomialRing(QQ, 2)
sage: S.<t> = PowerSeriesRing(R)
sage: t*(x+y)
(x + y)*t

TESTS:

sage: P.<x,y,z> = QQ[]
sage: loads(dumps(P)) == P
True
sage: loads(dumps(x)) == x
True
sage: P.<x,y,z> = GF(2^8,'a')[]
sage: loads(dumps(P)) == P
True
sage: loads(dumps(x)) == x
True
sage: P.<x,y,z> = GF(127)[]
sage: loads(dumps(P)) == P
True
sage: loads(dumps(x)) == x
True
sage: P.<x,y,z> = GF(127)[]
sage: loads(dumps(P)) == P
True
sage: loads(dumps(x)) == x
True

sage: Rt.<t> = PolynomialRing(QQ,1)
sage: p = 1+t
sage: R.<u,v> = PolynomialRing(QQ, 2)
sage: p(u/v)
(u + v)/v
class sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular
__call__()

Construct a new element in this polynomial ring, i.e. try to coerce in element if at all possible.

INPUT:

- ``element`` - several types are supported, see below

EXAMPLES:

Call supports all conversions _coerce_ supports, plus: coercion from strings:

sage: P.<x,y,z> = QQ[]
sage: P('x+y + 1/4')
x + y + 1/4

, coercion from SINGULAR elements:

sage: P._singular_()
//   characteristic : 0
//   number of vars : 3
//        block   1 : ordering dp
//                  : names    x y z
//        block   2 : ordering C

sage: P._singular_().set_ring()
sage: P(singular('x + 3/4'))
x + 3/4

, coercion from symbolic variables:

sage: x,y,z = var('x,y,z')
sage: R = QQ[x,y,z]
sage: R(x)
x

, coercion from ‘similar’ rings:

sage: P.<x,y,z> = QQ[]
sage: R.<a,b,c> = ZZ[]
sage: P(a)
x

, coercion from PARI objects:

sage: P.<x,y,z> = QQ[]
sage: P(pari('x^2 + y'))
x^2 + y
sage: P(pari('x*y'))
x*y  

, coercion from boolean polynomials:

sage: B.<x,y,z> = BooleanPolynomialRing(3)
sage: P.<x,y,z> = QQ[]
sage: P(B.gen(0))
x

. If everything else fails, we try to coerce to the base ring:

sage: R.<x,y,z> = GF(3)[]
sage: R(1/2)
-1

TESTS:

Coerce in a polydict where a coefficient reduces to 0 but isn’t 0.

sage: R.<x,y> = QQ[]; S.<xx,yy> = GF(5)[]; S( (5*x*y + x + 17*y)._mpoly_dict_recursive() )
xx + 2*yy

Coerce in a polynomial one of whose coefficients reduces to 0.

sage: R.<x,y> = QQ[]; S.<xx,yy> = GF(5)[]; S(5*x*y + x + 17*y)
xx + 2*yy

Some other examples that illustrate the same coercion idea:

sage: R.<x,y> = ZZ[]
sage: S.<xx,yy> = GF(25,'a')[]
sage: S(5*x*y + x + 17*y)
xx + 2*yy

sage: S.<xx,yy> = Integers(5)[]
sage: S(5*x*y + x + 17*y)
xx + 2*yy

See trac 5292:

sage: R.<x> = QQ[]; S.<q,t> = QQ[]; F = FractionField(S);
sage: x in S 
False
sage: x in F
False
__eq__()
x.__eq__(y) <==> x==y
__ge__()
x.__ge__(y) <==> x>=y
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__le__()
x.__le__(y) <==> x<=y
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__reduce__()

Serializes self.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(QQ, order=’degrevlex’) sage: P == loads(dumps(P)) True

sage: P.<x,y,z> = PolynomialRing(ZZ, order=’degrevlex’) sage: P == loads(dumps(P)) True

sage: P = PolynomialRing(GF(127), names=’abc’) sage: P == loads(dumps(P)) True

sage: P = PolynomialRing(GF(2^8,’F’), names=’abc’) sage: P == loads(dumps(P)) True

sage: P = PolynomialRing(GF(2^16,’B’), names=’abc’) sage: P == loads(dumps(P)) True sage: z = QQ[‘z’].0 sage: P = PolynomialRing(NumberField(z^2 + 3,’B’), names=’abc’) sage: P == loads(dumps(P)) True

__temporarily_change_names()

This is used by the variable names context manager.

EXAMPLES:

sage: R.<x,y> = QQ[] # indirect doctest
sage: with localvars(R, 'z,w'):
...       print x^3 + y^3 - x*y
...
z^3 + w^3 - z*w
_macaulay2_()

Create an M2 representation of this polynomial ring if Macaulay2 is installed.

INPUT:

  • macaulay2 - M2 interpreter (default: macaulay2_default)

EXAMPLES:

sage: R.<x,y> = ZZ[]
sage: macaulay2(R)        # optional
ZZ [x, y, MonomialOrder => GRevLex, MonomialSize => 16]

sage: R.<x,y> = QQ[]
sage: macaulay2(R)        # optional, indirect doctest
QQ [x, y, MonomialOrder => GRevLex, MonomialSize => 16]

sage: R.<x,y> = GF(17)[]
sage: print macaulay2(R)        # optional
ZZ
-- [x, y, MonomialOrder => GRevLex, MonomialSize => 16]
17
_macaulay2_set_ring()

Set the associated M2 ring.

INPUT:

  • macaulay2 - M2 instance

EXAMPLES:

sage: P.<x,y> = PolynomialRing(QQ)
sage: M2 = P._macaulay2_set_ring() # optional, requires M2
_repr_()

EXAMPLES:

sage: P.<x,y> = QQ[]
sage: P # indirect doctest
Multivariate Polynomial Ring in x, y over Rational Field
_singular_()

Create a SINGULAR (as in the computer algebra system) representation of this polynomial ring. The result is cached.

INPUT:

  • singular - SINGULAR interpreter (default: singular_default)

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P._singular_()
//   characteristic : 0
//   number of vars : 3
//        block   1 : ordering dp
//                  : names    x y z
//        block   2 : ordering C

sage: P._singular_() is P._singular_()
True

sage: P._singular_().name() == P._singular_().name()
True

sage: k.<a> = GF(3^3)
sage: P.<x,y,z> = PolynomialRing(k,3)
sage: P._singular_()
//   characteristic : 3
//   1 parameter    : a
//   minpoly        : (a^3-a+1)
//   number of vars : 3
//        block   1 : ordering dp
//                  : names    x y z
//        block   2 : ordering C

sage: P._singular_() is P._singular_()
True

sage: P._singular_().name() == P._singular_().name()
True
TESTS:
sage: P.<x> = QQ[] sage: P._singular_() // characteristic : 0 // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
_singular_init_()

Create a SINGULAR (as in the computer algebra system) representation of this polynomial ring. The result is NOT cached.

INPUT:

  • singular - SINGULAR interpreter (default: singular_default)

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P._singular_init_()
//   characteristic : 0
//   number of vars : 3
//        block   1 : ordering dp
//                  : names    x y z
//        block   2 : ordering C
sage: P._singular_init_() is P._singular_init_()
False

sage: P._singular_init_().name() == P._singular_init_().name()
False

sage: w = var('w')
sage: R.<x,y> = PolynomialRing(NumberField(w^2+1,'s'))
sage: singular(R)
//   characteristic : 0
//   1 parameter    : s
//   minpoly        : (s^2+1)
//   number of vars : 2
//        block   1 : ordering dp
//                  : names    x y
//        block   2 : ordering C

sage: R = PolynomialRing(GF(2**8,'a'),10,'x', order='invlex')
sage: singular(R)
//   characteristic : 2
//   1 parameter    : a
//   minpoly        : (a^8+a^4+a^3+a^2+1)
//   number of vars : 10
//        block   1 : ordering rp
//                  : names    x0 x1 x2 x3 x4 x5 x6 x7 x8 x9
//        block   2 : ordering C

sage: R = PolynomialRing(GF(127),2,'x', order='invlex')
sage: singular(R)
//   characteristic : 127
//   number of vars : 2
//        block   1 : ordering rp
//                  : names    x0 x1
//        block   2 : ordering C

sage: R = PolynomialRing(QQ,2,'x', order='invlex')
sage: singular(R)
//   characteristic : 0
//   number of vars : 2
//        block   1 : ordering rp
//                  : names    x0 x1
//        block   2 : ordering C

sage: R = PolynomialRing(QQ,'x')
sage: singular(R)
//   characteristic : 0
//   number of vars : 1
//        block   1 : ordering lp
//                  : names    x
//        block   2 : ordering C

sage: R = PolynomialRing(GF(127),'x')
sage: singular(R)
//   characteristic : 127
//   number of vars : 1
//        block   1 : ordering lp
//                  : names    x
//        block   2 : ordering C

sage: R = ZZ['x,y']
sage: singular(R)
//   coeff. ring is : Integers
//   number of vars : 2
//        block   1 : ordering dp
//                  : names    x y
//        block   2 : ordering C

sage: R = IntegerModRing(1024)['x,y']
sage: singular(R)
//   coeff. ring is : Z/2^10
//   number of vars : 2
//        block   1 : ordering dp
//                  : names    x y
//        block   2 : ordering C

sage: R = IntegerModRing(15)['x,y']
sage: singular(R)
//   coeff. ring is : Z/15
//   number of vars : 2
//        block   1 : ordering dp
//                  : names    x y
//        block   2 : ordering C

TESTS:

sage: P.<x> = QQ[]
sage: P._singular_init_()
//   characteristic : 0
//   number of vars : 1
//        block   1 : ordering lp
//                  : names    x
//        block   2 : ordering C
gen()

Returns the n-th generator of this multivariate polynomial ring.

INPUT:

  • n – an integer >= 0

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P.gen(),P.gen(1)
(x, y)          

sage: P = PolynomialRing(GF(127),1000,'x')
sage: P.gen(500)
x500

sage: P.<SAGE,SINGULAR> = QQ[] # weird names
sage: P.gen(1)
SINGULAR
ideal()

Create an ideal in this polynomial ring.

INPUT:

  • *gens - list or tuple of generators (or several input arguments)
  • coerce - bool (default: True); this must be a keyword argument. Only set it to False if you are certain that each generator is already in the ring.

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: sage.rings.ideal.Katsura(P)
Ideal (x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y) of Multivariate Polynomial Ring in x, y, z over Rational Field

sage: P.ideal([x + 2*y + 2*z-1, 2*x*y + 2*y*z-y, x^2 + 2*y^2 + 2*z^2-x])
Ideal (x + 2*y + 2*z - 1, 2*x*y + 2*y*z - y, x^2 + 2*y^2 + 2*z^2 - x) of Multivariate Polynomial Ring in x, y, z over Rational Field
monomial_all_divisors()

Return a list of all monomials that divide t.

Coefficients are ignored.

INPUT:

  • t - a monomial
OUTPUT:
a list of monomials

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P.monomial_all_divisors(x^2*z^3)
[x, x^2, z, x*z, x^2*z, z^2, x*z^2, x^2*z^2, z^3, x*z^3, x^2*z^3]

ALGORITHM: addwithcarry idea by Toon Segers

monomial_divides()

Return False if a does not divide b and True otherwise.

Coefficients are ignored.

INPUT:

  • a – monomial
  • b – monomial

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P.monomial_divides(x*y*z, x^3*y^2*z^4)
True
sage: P.monomial_divides(x^3*y^2*z^4, x*y*z)
False

TESTS:

sage: P.<x,y,z> = QQ[]
sage: P.monomial_divides(P(1), P(0))
True
sage: P.monomial_divides(P(1), x)
True
monomial_lcm()

LCM for monomials. Coefficients are ignored.

INPUT:

  • f - monomial
  • g - monomial

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P.monomial_lcm(3/2*x*y,x)
x*y

TESTS:

sage: R.<x,y,z> = QQ[]
sage: P.<x,y,z> = QQ[]
sage: P.monomial_lcm(x*y,R.gen())
x*y

sage: P.monomial_lcm(P(3/2),P(2/3))
1

sage: P.monomial_lcm(x,P(1))
x
monomial_pairwise_prime()

Return True if h and g are pairwise prime. Both are treated as monomials.

Coefficients are ignored.

INPUT:

  • h - monomial
  • g - monomial

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P.monomial_pairwise_prime(x^2*z^3, y^4)
True

sage: P.monomial_pairwise_prime(1/2*x^3*y^2, 3/4*y^3)
False

TESTS:

sage: Q.<x,y,z> = QQ[]
sage: P.<x,y,z> = QQ[]
sage: P.monomial_pairwise_prime(x^2*z^3, Q('y^4'))
True

sage: P.monomial_pairwise_prime(1/2*x^3*y^2, Q(0))
True

sage: P.monomial_pairwise_prime(P(1/2),x)
False
monomial_quotient()

Return f/g, where both f and`` g are treated as monomials.

Coefficients are ignored by default.

INPUT:

  • f - monomial
  • g - monomial
  • coeff - divide coefficients as well (default: False)

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: P.monomial_quotient(3/2*x*y,x)
y

sage: P.monomial_quotient(3/2*x*y,x,coeff=True)
3/2*y

Note, that \ZZ behaves different if coeff=True:

sage: P.monomial_quotient(2*x,3*x)
1

sage: P.<x,y> = PolynomialRing(ZZ)
sage: P.monomial_quotient(2*x,3*x,coeff=True)
...
ArithmeticError: Cannot divide these coefficients.

TESTS:

sage: R.<x,y,z> = QQ[]
sage: P.<x,y,z> = QQ[]
sage: P.monomial_quotient(x*y,x)
y

sage: P.monomial_quotient(x*y,R.gen())
y

sage: P.monomial_quotient(P(0),P(1))
0

sage: P.monomial_quotient(P(1),P(0))
...
ZeroDivisionError

sage: P.monomial_quotient(P(3/2),P(2/3), coeff=True)
9/4

sage: P.monomial_quotient(x,y) # Note the wrong result
x*y^1048575*z^1048575 # 64-bit
x*y^65535*z^65535 # 32-bit  

sage: P.monomial_quotient(x,P(1))
x

Warning

Assumes that the head term of f is a multiple of the head term of g and return the multiplicant m. If this rule is violated, funny things may happen.

monomial_reduce()

Try to find a g in G where g.lm() divides f. If found (flt,g) is returned, (0,0) otherwise, where flt is f/g.lm().

It is assumed that G is iterable and contains only elements in this polynomial ring.

Coefficients are ignored.

INPUT:

  • f - monomial
  • G - list/set of mpolynomials

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f = x*y^2
sage: G = [ 3/2*x^3 + y^2 + 1/2, 1/4*x*y + 2/7, 1/2  ]
sage: P.monomial_reduce(f,G)
(y, 1/4*x*y + 2/7)

TESTS:

sage: P.<x,y,z> = QQ[]
sage: f = x*y^2
sage: G = [ 3/2*x^3 + y^2 + 1/2, 1/4*x*y + 2/7, 1/2  ]

sage: P.monomial_reduce(P(0),G)
(0, 0)

sage: P.monomial_reduce(f,[P(0)])
(0, 0)
ngens()

Returns the number of variables in this multivariate polynomial ring.

EXAMPLES:

sage: P.<x,y> = QQ[]
sage: P.ngens()
2

sage: k.<a> = GF(2^16)
sage: P = PolynomialRing(k,1000,'x')
sage: P.ngens()
1000
class sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular

A multivariate polynomial implemented using libSINGULAR.

__call__()

Evaluate this multi-variate polynomial at x, where x is either the tuple of values to substitute in, or one can use functional notation f(a_0,a_1,a_2, \ldots) to evaluate f with the ith variable replaced by a_i.

INPUT:

  • x - a list of elements in self.parent()
  • or **kwds - a dictionary of variable-name:value pairs.

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f = 3/2*x^2*y + 1/7 * y^2 + 13/27
sage: f(0,0,0)
13/27

sage: f(1,1,1)
803/378
sage: 3/2 + 1/7 + 13/27
803/378

sage: f(45/2,19/3,1)
7281167/1512

sage: f(1,2,3).parent()
Rational Field

TESTS:

sage: P.<x,y,z> = QQ[]
sage: P(0)(1,2,3)
0
sage: P(3/2)(1,2,3)
3/2

sage: R.<a,b,y> = QQ[]
sage: f = a*y^3 + b*y - 3*a*b*y
sage: f(a=5,b=3,y=10)
4580
sage: f(5,3,10)
4580            
__eq__()
x.__eq__(y) <==> x==y
__floordiv__()

Perform division with remainder and return the quotient.

INPUT:

  • right - something coercible to an MPolynomial_libsingular in self.parent()

EXAMPLES:

sage: R.<x,y,z> = GF(32003)[]
sage: f = y*x^2 + x + 1
sage: f//x
x*y + 1
sage: f//y
x^2

sage: P.<x,y> = ZZ[]
sage: x//y
0
sage: (x+y)//y
1

sage: P.<x,y> = QQ[]
sage: (x+y)//y
1
sage: (x)//y
0

sage: P.<x,y> = Zmod(1024)[]
sage: (x+y)//x
1
sage: (x+y)//(2*x)
...
NotImplementedError: Division of multivariate polynomials over non fields by non-monomials not implemented.
__ge__()
x.__ge__(y) <==> x>=y
__getitem__()

Same as self.monomial_coefficent but for exponent vectors.

INPUT:

  • x - a tuple or, in case of a single-variable MPolynomial ring x can also be an integer.

EXAMPLES:

sage: R.<x, y> = QQ[]
sage: f = -10*x^3*y + 17*x*y
sage: f[3,1]
-10
sage: f[1,1]
17
sage: f[0,1]
0

sage: R.<x> = PolynomialRing(GF(7),1); R
Multivariate Polynomial Ring in x over Finite Field of size 7
sage: f = 5*x^2 + 3; f
-2*x^2 + 3
sage: f[2]
5
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__le__()
x.__le__(y) <==> x<=y
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
__neg__()

Return -self.

EXAMPLES:

sage: R.<x,y>=PolynomialRing(QQ,2)
sage: f = x^3 + y
sage: -f
-x^3 - y
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__nonzero__()
x.__nonzero__() <==> x != 0
__pow__()
x.__pow__(y[, z]) <==> pow(x, y[, z])
__reduce__()

Serialize this polynomial.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(QQ,3, order='degrevlex')
sage: f = 27/113 * x^2 + y*z + 1/2
sage: f == loads(dumps(f))
True

sage: P = PolynomialRing(GF(127),3,names='abc')
sage: a,b,c = P.gens()
sage: f = 57 * a^2*b + 43 * c + 1
sage: f == loads(dumps(f))
True
__rfloordiv__()
x.__rfloordiv__(y) <==> y//x
__rpow__()
y.__rpow__(x[, z]) <==> pow(x, y[, z])
_add_()

Add left and right.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: 3/2*x + 1/2*y + 1
3/2*x + 1/2*y + 1
_derivative()

Differentiates this polynomial with respect to the provided variable. This is completely symbolic so it is also defined over finite fields.

INPUT:

  • variable - the derivative is taken with respect to variable
  • have_ring - ignored, accepted for compatibility reasons

Note

See also derivative()

EXAMPLES:

sage: R.<x,y> = PolynomialRing(QQ,2)
sage: f = 3*x^3*y^2 + 5*y^2 + 3*x + 2
sage: f._derivative(x)
9*x^2*y^2 + 3
sage: f._derivative(y)
6*x^3*y + 10*y

The derivative is also defined over finite fields:

sage: R.<x,y> = PolynomialRing(GF(2**8, 'a'),2)
sage: f = x^3*y^2 + y^2 + x + 2
sage: f._derivative(x)
x^2*y^2 + 1
_div_()

Divide left by right

EXAMPLES:

sage: R.<x,y>=PolynomialRing(QQ,2)
sage: f = (x + y)/3
sage: f.parent()
Multivariate Polynomial Ring in x, y over Rational Field

Note that / is still a constructor for elements of the fraction field in all cases as long as both arguments have the same parent and right is not constant.

sage: R.<x,y>=PolynomialRing(QQ,2)
sage: f = x^3 + y
sage: g = x
sage: h = f/g; h
(x^3 + y)/x
sage: h.parent()
Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field

If we divide over \ZZ the result is the same as multiplying by 1/3 (i.e. base extension).

sage: R.<x,y> = ZZ[]
sage: f = (x + y)/3      
sage: f.parent()
Multivariate Polynomial Ring in x, y over Rational Field
sage: f = (x + y) * 1/3      
sage: f.parent()
Multivariate Polynomial Ring in x, y over Rational Field

But we get a true fraction field if the denominator is not in the fraction field of the base ring.”“

sage: f = x/y sage: f.parent() Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring

Division will fail for non-integral domains:

sage: P.<x,y> = Zmod(1024)[]
sage: x/P(3)
...
TypeError: self must be an integral domain.

sage: x/3
...
TypeError: unsupported operand parent(s) for '/': 'Multivariate Polynomial Ring in x, y over Ring of integers modulo 1024' and 'Integer Ring'

TESTS:

sage: R.<x,y>=PolynomialRing(QQ,2)
sage: x/0
...
ZeroDivisionError: rational division by zero
_homogenize()

Return self if self is homogeneous. Otherwise return a homogenized polynomial constructed by modifying the degree of the variable with index var.

INPUT:

  • var - an integer indicating which variable to use to homogenize (0 <= var < parent(self).ngens())
OUTPUT:
a multivariate polynomial

EXAMPLES:

sage: P.<x,y> = QQ[]
sage: f = x^2 + y + 1 + 5*x*y^10
sage: g = f.homogenize('z'); g # indirect doctest
5*x*y^10 + x^2*z^9 + y*z^10 + z^11
sage: g.parent()
Multivariate Polynomial Ring in x, y, z over Rational Field
sage: f._homogenize(0)
2*x^11 + x^10*y + 5*x*y^10

SEE: self.homogenize

_iadd_()

Add left and right inplace.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: 3/2*x + 1/2*y + 1
3/2*x + 1/2*y + 1
_im_gens_()

INPUT:

  • codomain
  • im_gens

EXAMPLES:

sage: R.<x,y> = PolynomialRing(QQ, 2)
sage: f = R.hom([y,x], R)
sage: f(x^2 + 3*y^5)
3*x^5 + y^2

sage: R.<a,b,c,d> = QQ[]
sage: S.<u> = QQ[]
sage: h = R.hom([0,0,0,u], S) # indirect doctest
sage: h((a+d)^3)
u^3
_imul_()

Multiply left and right inplace.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: (3/2*x - 1/2*y - 1) * (3/2*x + 1/2*y + 1)
9/4*x^2 - 1/4*y^2 - y - 1
_isub_()

Subtract left and right inplace.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: 3/2*x - 1/2*y - 1
3/2*x - 1/2*y - 1
_latex_()

Return a polynomial LaTeX representation of this polynomial.

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f = - 1*x^2*y - 25/27 * y^3 - z^2
sage: latex(f)
- x^{2} y - rac{25}{27} y^{3} - z^{2}
_lmul_()
_macaulay2_()

Return a Macaulay2 string representation of this polynomial.

Note

Two identical rings are not canonically isomorphic in M2, so we require the user to explicitly set the ring, since there is no way to know if the ring has been set or not, and setting it twice screws everything up.

EXAMPLES:

sage: R.<x,y> = PolynomialRing(GF(7), 2)
sage: f = (x^3 + 2*y^2*x)^7; f
x^21 + 2*x^7*y^14

sage: h = macaulay2(f); h               # optional
 21     7 14
x   + 2x y
sage: k = macaulay2(x+y); k             # optional
x + y
sage: k + h                             # optional
 21     7 14
x   + 2x y   + x + y
sage: R(h)                              # optional
x^21 + 2*x^7*y^14
sage: R(h^20) == f^20                   # optional
True
_mul_()

Multiply left and right.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: (3/2*x - 1/2*y - 1) * (3/2*x + 1/2*y + 1)
9/4*x^2 - 1/4*y^2 - y - 1

sage: P.<x,y> = PolynomialRing(QQ,order='lex')
sage: (x^2^30) * x^2^30
...
OverflowError: Exponent overflow.
_repr_()

EXAMPLES:

sage: R.<x,y>=PolynomialRing(QQ,2)
sage: f = x^3 + y
sage: f # indirect doctest
x^3 + y
_repr_short_()

This is a faster but less pretty way to print polynomials. If available it uses the short SINGULAR notation.

EXAMPLES:

sage: R.<x,y>=PolynomialRing(QQ,2)
sage: f = x^3 + y
sage: f._repr_short_()
'x3+y'
_repr_with_changed_varnames()

Return string representing this polynomial but change the variable names to varnames.

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f = - 1*x^2*y - 25/27 * y^3 - z^2
sage: print f._repr_with_changed_varnames(['FOO', 'BAR', 'FOOBAR'])
-FOO^2*BAR - 25/27*BAR^3 - FOOBAR^2
_rmul_()

Multiply self with a base ring element.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: 3/2*x
3/2*x
_singular_init_()

Return a SINGULAR (as in the computer algebra system) string representation for this element.

INPUT:

  • singular - interpreter (default: singular_default)

  • have_ring - should the correct ring not be set in

    SINGULAR first (default: False)

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(GF(127),3)
sage: x._singular_init_()
'x'
sage: (x^2+37*y+128)._singular_init_()
'x2+37y+1'

TESTS:

sage: P(0)._singular_init_()
'0'
_sub_()

Subtract left and right.

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: 3/2*x - 1/2*y - 1
3/2*x - 1/2*y - 1
_variable_indices_()

Return the indices of all variables occurring in self. This index is the index as Sage uses them (starting at zero), not as SINGULAR uses them (starting at one).

INPUT:

  • sort - specifies whether the indices shall be sorted

EXAMPLES:

sage: P.<x,y,z> = GF(2)[]
sage: f = x*z^2 + z + 1
sage: f._variable_indices_()
[0, 2]
add_m_mul_q()

Return self + m*q, where m must be a monomial and q a polynomial.

INPUT:

  • m - a monomial
  • q - a polynomial

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: x.add_m_mul_q(y,z)
y*z + x

TESTS:

sage: R.<x,y,z>=PolynomialRing(QQ,3)
sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: P(0).add_m_mul_q(P(0),P(1))
0
sage: x.add_m_mul_q(R.gen(),R.gen(1))
x*y + x
coefficient()

Return the coefficient of the variables with the degrees specified in the python dictionary degrees. Mathematically, this is the coefficient in the base ring adjoined by the variables of this ring not listed in degrees. However, the result has the same parent as this polynomial.

This function contrasts with the function monomial_coefficient which returns the coefficient in the base ring of a monomial.

INPUT:

  • degrees - Can be any of:
    • a dictionary of degree restrictions
    • a list of degree restrictions (with None in the unrestricted variables)
    • a monomial (very fast, but not as flexible)
OUTPUT:
element of the parent of this element.

Note

For coefficients of specific monomials, look at monomial_coefficient().

EXAMPLES:

sage: R.<x,y> = QQ[]
sage: f=x*y+y+5
sage: f.coefficient({x:0,y:1})
1
sage: f.coefficient({x:0})
y + 5
sage: f=(1+y+y^2)*(1+x+x^2)
sage: f.coefficient({x:0})
y^2 + y + 1
sage: f.coefficient([0,None])
y^2 + y + 1
sage: f.coefficient(x)
y^2 + y + 1

Be aware that this may not be what you think! The physical appearance of the variable x is deceiving – particularly if the exponent would be a variable.

sage: f.coefficient(x^0) # outputs the full polynomial
x^2*y^2 + x^2*y + x*y^2 + x^2 + x*y + y^2 + x + y + 1
sage: R.<x,y> = GF(389)[]
sage: f=x*y+5
sage: c=f.coefficient({x:0,y:0}); c
5
sage: parent(c)
Multivariate Polynomial Ring in x, y over Finite Field of size 389

AUTHOR:

  • Joel B. Mohler (2007.10.31)
coefficients()

Return the nonzero coefficients of this polynomial in a list. The returned list is decreasingly ordered by the term ordering of the parent.

EXAMPLES:

sage: R.<x,y,z> = PolynomialRing(QQ, order='degrevlex')
sage: f=23*x^6*y^7 + x^3*y+6*x^7*z
sage: f.coefficients()
[23, 6, 1]

sage: R.<x,y,z> = PolynomialRing(QQ, order='lex')
sage: f=23*x^6*y^7 + x^3*y+6*x^7*z
sage: f.coefficients()
[6, 23, 1]

AUTHOR:

  • Didier Deshommes
constant_coefficient()

Return the constant coefficient of this multivariate polynomial.

EXAMPLES:

sage: P.<x, y> = QQ[]
sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5
sage: f.constant_coefficient()
5
sage: f = 3*x^2 
sage: f.constant_coefficient()
0
degree()

Return the maximal degree of this polynomial in x, where x must be one of the generators for the parent of this polynomial.

INPUT:

  • x - multivariate polynomial (a generator of the parent of self) If x is not specified (or is None), return the total degree, which is the maximum degree of any monomial.
OUTPUT:
integer

EXAMPLES:

sage: R.<x, y> = QQ[]
sage: f = y^2 - x^9 - x
sage: f.degree(x)
9
sage: f.degree(y)
2
sage: (y^10*x - 7*x^2*y^5 + 5*x^3).degree(x)
3
sage: (y^10*x - 7*x^2*y^5 + 5*x^3).degree(y)
10

TESTS:

sage: P.<x, y> = QQ[]
sage: P(0).degree(x)
-1
sage: P(1).degree(x)
0
degrees()

Returns a tuple with the maximal degree of each variable in this polynomial. The list of degrees is ordered by the order of the generators.

EXAMPLES:

sage: R.<y0,y1,y2> = PolynomialRing(QQ,3)
sage: q = 3*y0*y1*y1*y2; q 
3*y0*y1^2*y2 
sage: q.degrees() 
(1, 2, 1)
sage: (q + y0^5).degrees()
(5, 2, 1)
dict()

Return a dictionary representing self. This dictionary is in the same format as the generic MPolynomial: The dictionary consists of ETuple:coefficient pairs.

EXAMPLES:

sage: R.<x,y,z> = QQ[]
sage: f=2*x*y^3*z^2 + 1/7*x^2 + 2/3
sage: f.dict()
{(1, 3, 2): 2, (0, 0, 0): 2/3, (2, 0, 0): 1/7}
exponents()

Return the exponents of the monomials appearing in this polynomial.

EXAMPLES:

sage: R.<a,b,c> = QQ[]
sage: f = a^3 + b + 2*b^2
sage: f.exponents()
[(3, 0, 0), (0, 2, 0), (0, 1, 0)]
factor()

Return the factorization of this polynomial.

EXAMPLES:

sage: R.<x, y> = QQ[]
sage: f = (x^3 + 2*y^2*x) * (x^2 + x + 1); f
x^5 + 2*x^3*y^2 + x^4 + 2*x^2*y^2 + x^3 + 2*x*y^2
sage: F = f.factor()
sage: F
x * (x^2 + x + 1) * (x^2 + 2*y^2)

Next we factor the same polynomial, but over the finite field of order 3.

sage: R.<x, y> = GF(3)[]
sage: f = (x^3 + 2*y^2*x) * (x^2 + x + 1); f
x^5 - x^3*y^2 + x^4 - x^2*y^2 + x^3 - x*y^2
sage: F = f.factor(proof=False)      # we use proof = False, since Singular's factorization has issues
sage: F # order is somewhat random
(-1) * x * (-x + y) * (x + y) * (x - 1)^2

Next we factor a polynomial over a number field.

sage: p = var('p')
sage: K.<s> = NumberField(p^3-2)
sage: KXY.<x,y> = K[]
sage: factor(x^3 - 2*y^3)
(x + (-s)*y) * (x^2 + (s)*x*y + (s^2)*y^2)
sage: k = (x^3-2*y^3)^5*(x+s*y)^2*(2/3 + s^2)
sage: k.factor()
((s^2 + 2/3)) * (x + (s)*y)^2 * (x + (-s)*y)^5 * (x^2 + (s)*x*y + (s^2)*y^2)^5

This shows that ticket #2780 is fixed, i.e. that the unit part of the factorization is set correctly:

sage: x = var('x')
sage: K.<a> = NumberField(x^2 + 1)
sage: R.<y, z> = PolynomialRing(K)
sage: f = 2*y^2 + 2*z^2
sage: F = f.factor(); F.unit()
2

Another example:

sage: R.<x,y,z> = GF(32003)[]
sage: f = 9*(x-1)^2*(y+z)
sage: f.factor(proof=False)
(9) * (y + z) * (x - 1)^2

sage: R.<x,w,v,u> = QQ['x','w','v','u']
sage: p = (4*v^4*u^2 - 16*v^2*u^4 + 16*u^6 - 4*v^4*u + 8*v^2*u^3 + v^4)
sage: p.factor(proof=False)
(-2*v^2*u + 4*u^3 + v^2)^2
sage: R.<a,b,c,d> = QQ[]
sage: f =  (-2) * (a - d) * (-a + b) * (b - d) * (a - c) * (b - c) * (c - d)
sage: F = f.factor(); F
(-2) * (c - d) * (b - d) * (b - c) * (-a + b) * (a - d) * (a - c)
sage: F[0][0]
c - d
sage: F.unit()
-2

Constant elements are factorized in the base rings.

sage: P.<x,y> = ZZ[]
sage: P(2^3*7).factor()
2^3 * 7

Factorization of multivariate polynomials over non-prime finite fields is only implemented in Singular, and unfortunately Singular is currently very buggy at this computation. So we disable it in Sage:

sage: k.<a> = GF(9)
sage: R.<x,y> = PolynomialRing(k)
sage: f = (x-a)*(y-a)
sage: f.factor()
...
NotImplementedError: proof = True factorization not implemented.  Call factor with proof=False.
sage: f.factor(proof=False)
(y + (-a)) * (x + (-a))

Also, factorization for finite prime fields with characteristic > 2^{29} is not supported either.

sage: q = 1073741789
sage: T.<aa, bb> = PolynomialRing(GF(q))
sage: f = aa^2 + 12124343*bb*aa + 32434598*bb^2
sage: f.factor()
...
NotImplementedError: Factorization of multivariate polynomials over prime fields with characteristic > 2^29 is not implemented.

Finally, factorization over the integers is not supported.

sage: P.<x,y> = PolynomialRing(ZZ)
sage: f = (3*x + 4)*(5*x - 2)
sage: f.factor()
...
NotImplementedError: Factorization of multivariate polynomials over non-fields is not implemented.
gcd()

Return the greatest common divisor of self and right.

INPUT:

  • right - polynomial
  • algorithm - ezgcd - EZGCD algorithm - modular - multi-modular algorithm (default)

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f = (x*y*z)^6 - 1
sage: g = (x*y*z)^4 - 1
sage: f.gcd(g)
x^2*y^2*z^2 - 1
sage: GCD([x^3 - 3*x + 2, x^4 - 1, x^6 -1])
x - 1

sage: R.<x,y> = QQ[]
sage: f = (x^3 + 2*y^2*x)^2
sage: g = x^2*y^2
sage: f.gcd(g)
x^2

We compute a gcd over a finite field:

sage: F.<u> = GF(31^2)
sage: R.<x,y,z> = F[]
sage: p = x^3 + (1+u)*y^3 + z^3
sage: q = p^3 * (x - y + z*u)
sage: gcd(p,q)
x^3 + (u + 1)*y^3 + z^3
sage: gcd(p,q)  # yes, twice -- tests that singular ring is properly set.
x^3 + (u + 1)*y^3 + z^3

We compute a gcd over a number field:

sage: x = polygen(QQ)
sage: F.<u> = NumberField(x^3 - 2)
sage: R.<x,y,z> = F[]
sage: p = x^3 + (1+u)*y^3 + z^3
sage: q = p^3 * (x - y + z*u)
sage: gcd(p,q)
x^3 + (u + 1)*y^3 + z^3        

TESTS:

sage: Q.<x,y,z> = QQ[]
sage: P.<x,y,z> = QQ[]
sage: P(0).gcd(Q(0))
0
sage: x.gcd(1)
1

sage: k.<a> = GF(9)
sage: R.<x,y> = PolynomialRing(k)
sage: f = R.change_ring(GF(3)).gen()
sage: g = x+y
sage: g.gcd(f)
1
sage: x.gcd(R.change_ring(GF(3)).gen())
x
gradient()

Return a list of partial derivatives of this polynomial, ordered by the variables of the parent.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(QQ,3)
sage: f= x*y + 1
sage: f.gradient()
[y, x, 0]
inverse_of_unit()

Return the inverse of this polynomial if it is a unit.

EXAMPLES:

sage: R.<x,y> = QQ[]
sage: x.inverse_of_unit()
...
ArithmeticError: Element is not a unit.

sage: R(1/2).inverse_of_unit()
2
is_constant()

Return True if this polynomial is constant.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(GF(127))
sage: x.is_constant()
False
sage: P(1).is_constant()
True
is_homogeneous()

Return True if this polynomial is homogeneous.

EXAMPLES:

sage: P.<x,y> = PolynomialRing(RationalField(), 2)
sage: (x+y).is_homogeneous()
True
sage: (x.parent()(0)).is_homogeneous()
True
sage: (x+y^2).is_homogeneous()
False
sage: (x^2 + y^2).is_homogeneous()
True
sage: (x^2 + y^2*x).is_homogeneous()
False
sage: (x^2*y + y^2*x).is_homogeneous()
True
is_monomial()

Return True if this polynomial is a monomial. A monomial is defined to be a product of generators with coefficient 1.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(QQ)
sage: x.is_monomial()
True
sage: (2*x).is_monomial()
False
sage: (x*y).is_monomial()
True
sage: (x*y + x).is_monomial()
False
is_squarefree()

Return True if this polynomial is square free.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(QQ)
sage: f= x^2 + 2*x*y + 1/2*z
sage: f.is_squarefree()
True
sage: h = f^2
sage: h.is_squarefree()
False
is_unit()

Return True if self is a unit.

EXAMPLES:

sage: R.<x,y> = QQ[]
sage: (x+y).is_unit()
False 
sage: R(0).is_unit()
False
sage: R(-1).is_unit()
True
sage: R(-1 + x).is_unit()
False
sage: R(2).is_unit()
True

sage: R.<x,y> = ZZ[]
sage: R(1).is_unit()
True
sage: R(2).is_unit()
False
is_univariate()

Return True if self is a univariate polynomial, that is if self contains only one variable.

EXAMPLES:

sage: P.<x,y,z> = GF(2)[]
sage: f = x^2 + 1
sage: f.is_univariate()
True
sage: f = y*x^2 + 1
sage: f.is_univariate()
False
sage: f = P(0)
sage: f.is_univariate()
True
is_zero()

Return True if this polynomial is zero.

EXAMPLES:

sage: P.<x,y> = PolynomialRing(QQ)
sage: x.is_zero()
False
sage: (x-x).is_zero()
True
lc()

Leading coefficient of this polynomial with respect to the term order of self.parent().

EXAMPLES:

sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: f = 3*x^1*y^2 + 2*y^3*z^4
sage: f.lc()
3

sage: f = 5*x^3*y^2*z^4 + 4*x^3*y^2*z^1 
sage: f.lc()
5
lcm()

Return the least common multiple of self and g.

INPUT:

  • g - polynomial
OUTPUT:
polynomial

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: p = (x+y)*(y+z)
sage: q = (z^4+2)*(y+z)
sage: lcm(p,q)
x*y*z^4 + y^2*z^4 + x*z^5 + y*z^5 + 2*x*y + 2*y^2 + 2*x*z + 2*y*z

sage: P.<x,y,z> = ZZ[]
sage: p = 2*(x+y)*(y+z)
sage: q = 3*(z^4+2)*(y+z)
sage: lcm(p,q)
6*x*y*z^4 + 6*y^2*z^4 + 6*x*z^5 + 6*y*z^5 + 12*x*y + 12*y^2 + 12*x*z + 12*y*z
lift()

given an ideal I = (f_1,...,f_r) and some g (== self) in I, find s_1,...,s_r such that g = s_1 f_1 + ... + s_r f_r.

EXAMPLES:

sage: A.<x,y> = PolynomialRing(QQ,2,order='degrevlex')
sage: I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7 ])
sage: f = x*y^13 + y^12
sage: M = f.lift(I)
sage: M
[y^7, x^7*y^2 + x^8 + x^5*y^3 + x^6*y + x^3*y^4 + x^4*y^2 + x*y^5 + x^2*y^3 + y^4]
sage: sum( map( mul , zip( M, I.gens() ) ) ) == f
True
lm()

Returns the lead monomial of self with respect to the term order of self.parent(). In Sage a monomial is a product of variables in some power without a coefficient.

EXAMPLES:

sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: f = x^1*y^2 + y^3*z^4
sage: f.lm()
x*y^2
sage: f = x^3*y^2*z^4 + x^3*y^2*z^1 
sage: f.lm()
x^3*y^2*z^4

sage: R.<x,y,z>=PolynomialRing(QQ,3,order='deglex')
sage: f = x^1*y^2*z^3 + x^3*y^2*z^0
sage: f.lm()
x*y^2*z^3
sage: f = x^1*y^2*z^4 + x^1*y^1*z^5
sage: f.lm()
x*y^2*z^4

sage: R.<x,y,z>=PolynomialRing(GF(127),3,order='degrevlex')
sage: f = x^1*y^5*z^2 + x^4*y^1*z^3
sage: f.lm()
x*y^5*z^2
sage: f = x^4*y^7*z^1 + x^4*y^2*z^3
sage: f.lm()
x^4*y^7*z
lt()

Leading term of this polynomial. In Sage a term is a product of variables in some power and a coefficient.

EXAMPLES:

sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: f = 3*x^1*y^2 + 2*y^3*z^4
sage: f.lt()
3*x*y^2

sage: f = 5*x^3*y^2*z^4 + 4*x^3*y^2*z^1 
sage: f.lt()
-2*x^3*y^2*z^4
monomial_coefficient()

Return the coefficient in the base ring of the monomial mon in self, where mon must have the same parent as self.

This function contrasts with the function coefficient which returns the coefficient of a monomial viewing this polynomial in a polynomial ring over a base ring having fewer variables.

INPUT:

  • mon - a monomial
OUTPUT:
coefficient in base ring
SEE ALSO:
For coefficients in a base ring of fewer variables, look at coefficient.

EXAMPLES:

sage: P.<x,y> = QQ[]

The parent of the return is a member of the base ring.
sage: f = 2 * x * y
sage: c = f.monomial_coefficient(x*y); c
2
sage: c.parent()
Rational Field

sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y
sage: f.monomial_coefficient(y^2)
1
sage: f.monomial_coefficient(x*y)
5
sage: f.monomial_coefficient(x^9)
-1
sage: f.monomial_coefficient(x^10)
0
monomials()

Return the list of monomials in self. The returned list is decreasingly ordered by the term ordering of self.parent().

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f = x + 3/2*y*z^2 + 2/3
sage: f.monomials()
[y*z^2, x, 1]
sage: f = P(3/2)
sage: f.monomials()
[1]

TESTS:

sage: P.<x,y,z> = QQ[]
sage: f = x
sage: f.monomials()
[x]
sage: f = P(0)
sage: f.monomials()
[0]
nvariables()

Return the number variables in this polynomial.

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(GF(127))
sage: f = x*y + z
sage: f.nvariables()
3
sage: f = x + y
sage: f.nvariables()
2
quo_rem()

Returns quotient and remainder of self and right.

EXAMPLES:

sage: R.<x,y> = QQ[]
sage: f = y*x^2 + x + 1
sage: f.quo_rem(x)
(x*y + 1, 1)
sage: f.quo_rem(y)
(x^2, x + 1)

sage: R.<x,y> = ZZ[]
sage: f = 2*y*x^2 + x + 1
sage: f.quo_rem(x)
(2*x*y + 1, 1)
sage: f.quo_rem(y)
(2*x^2, x + 1)
sage: f.quo_rem(3*x)
(0, 2*x^2*y + x + 1)

TESTS:

sage: R.<x,y> = QQ[]
sage: R(0).quo_rem(R(1))
(0, 0)
sage: R(1).quo_rem(R(0))
...
ZeroDivisionError
reduce()

Return the normal form of self w.r.t. I, i.e. return the remainder of this polynomial with respect to the polynomials in I. If the polynomial set/list I is not a (strong) Groebner basis the result is not canonical.

A strong Groebner basis G of I implies that for every leading term t of I there exists an element g of G, such that the leading term of g divides t.

INPUT:

  • I - a list/set of polynomials. If I is an ideal, the generators are used.

EXAMPLES:

sage: P.<x,y,z> = QQ[]
sage: f1 = -2 * x^2 + x^3
sage: f2 = -2 * y + x* y
sage: f3 = -x^2 + y^2
sage: F = Ideal([f1,f2,f3])
sage: g = x*y - 3*x*y^2
sage: g.reduce(F)
-6*y^2 + 2*y
sage: g.reduce(F.gens())
-6*y^2 + 2*y

\ZZ is also supported.

sage: P.<x,y,z> = ZZ[]
sage: f1 = -2 * x^2 + x^3
sage: f2 = -2 * y + x* y
sage: f3 = -x^2 + y^2
sage: F = Ideal([f1,f2,f3])
sage: g = x*y - 3*x*y^2
sage: g.reduce(F)
-6*y^2 + 2*y
sage: g.reduce(F.gens())
-6*y^2 + 2*y

sage: f = 3*x
sage: f.reduce([2*x,y])
3*x
resultant()

Compute the resultant of this polynomial and the first argument with respect to the variable given as the second argument.

If a second argument is not provide the first variable of the parent is chosen.

INPUT:

  • other - polynomial
  • variable - optional variable (default: None)

EXAMPLES:

sage: P.<x,y> = PolynomialRing(QQ,2)
sage: a = x+y
sage: b = x^3-y^3
sage: c = a.resultant(b); c
-2*y^3
sage: d = a.resultant(b,y); d
2*x^3

The SINGULAR example:

sage: R.<x,y,z> = PolynomialRing(GF(32003),3)
sage: f = 3 * (x+2)^3 + y
sage: g = x+y+z
sage: f.resultant(g,x)
3*y^3 + 9*y^2*z + 9*y*z^2 + 3*z^3 - 18*y^2 - 36*y*z - 18*z^2 + 35*y + 36*z - 24

TESTS:

sage: P.<x,y> = PolynomialRing(QQ, order='degrevlex')
sage: a = x+y
sage: b = x^3-y^3
sage: c = a.resultant(b); c
-2*y^3
sage: d = a.resultant(b,y); d
2*x^3
sub_m_mul_q()

Return self - m*q, where m must be a monomial and q a polynomial.

INPUT:

  • m - a monomial
  • q - a polynomial

EXAMPLES:

sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: x.sub_m_mul_q(y,z)
-y*z + x

TESTS:

sage: Q.<x,y,z>=PolynomialRing(QQ,3)
sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: P(0).sub_m_mul_q(P(0),P(1))
0
sage: x.sub_m_mul_q(Q.gen(1),Q.gen(2))
-y*z + x
subs()

Fixes some given variables in a given multivariate polynomial and returns the changed multivariate polynomials. The polynomial itself is not affected. The variable,value pairs for fixing are to be provided as dictionary of the form {variable:value}.

This is a special case of evaluating the polynomial with some of the variables constants and the others the original variables, but should be much faster if only few variables are to be fixed.

INPUT:

  • fixed - (optional) dict with variable:value pairs
  • **kw - names parameters
OUTPUT:
new MPolynomial

EXAMPLES:

sage: R.<x,y> = QQ[]
sage: f = x^2 + y + x^2*y^2 + 5 
sage: f(5,y) 
25*y^2 + y + 30
sage: f.subs({x:5})
25*y^2 + y + 30
sage: f.subs(x=5)
25*y^2 + y + 30

sage: P.<x,y,z> = PolynomialRing(GF(2),3)
sage: f = x + y + 1
sage: f.subs({x:y+1})
0
sage: f.subs(x=y)
1
sage: f.subs(x=x)
x + y + 1
sage: f.subs({x:z})
y + z + 1
sage: f.subs(x=z+1)
y + z

sage: f.subs(x=1/y)
(y^2 + y + 1)/y
sage: f.subs({x:1/y})
(y^2 + y + 1)/y

TESTS:

sage: P.<x,y,z> = QQ[]
sage: f = y
sage: f.subs({y:x}).subs({x:z})
z

Note

The evaluation is performed by evaluating every variable:value pair separately. This has side effects if e.g. x=y, y=z is provided. If x=y is evaluated first, all x variables will be replaced by z eventually.

total_degree()

Return the total degree of self, which is the maximum degree of all monomials in self.

EXAMPLES:

sage: R.<x,y,z> = QQ[]
sage: f=2*x*y^3*z^2
sage: f.total_degree()
6
sage: f=4*x^2*y^2*z^3
sage: f.total_degree()
7
sage: f=99*x^6*y^3*z^9
sage: f.total_degree()
18
sage: f=x*y^3*z^6+3*x^2
sage: f.total_degree()
10
sage: f=z^3+8*x^4*y^5*z
sage: f.total_degree()
10
sage: f=z^9+10*x^4+y^8*x^2
sage: f.total_degree()
10

TESTS:

sage: R.<x,y,z> = QQ[]
sage: R(0).total_degree()
-1
sage: R(1).total_degree()
0
univariate_polynomial()

Returns a univariate polynomial associated to this multivariate polynomial.

INPUT:

  • R - (default: None) PolynomialRing

If this polynomial is not in at most one variable, then a ValueError exception is raised. This is checked using the is_univariate() method. The new Polynomial is over the same base ring as the given MPolynomial and in the variable x if no ring R is provided.

EXAMPLES:

sage: R.<x, y> = QQ[]
sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5
sage: f.univariate_polynomial()
...
TypeError: polynomial must involve at most one variable
sage: g = f.subs({x:10}); g
700*y^2 - 2*y + 305
sage: g.univariate_polynomial ()
700*y^2 - 2*y + 305
sage: g.univariate_polynomial(PolynomialRing(QQ,'z'))
700*z^2 - 2*z + 305

Here’s an example with a constant multivariate polynomial:

sage: g = R(1)
sage: h = g.univariate_polynomial(); h
1
sage: h.parent()
Univariate Polynomial Ring in x over Rational Field
variable()

Return the i-th variable occurring in self. The index i is the index in self.variables().

EXAMPLES:

sage: P.<x,y,z> = GF(2)[]
sage: f = x*z^2 + z + 1
sage: f.variables()
[x, z]
sage: f.variable(1)
z
variables()

Return a list of all variables occurring in self.

EXAMPLES:

sage: P.<x,y,z> = GF(2)[]
sage: f = x*z^2 + z + 1
sage: f.variables()
[x, z]
sage.rings.polynomial.multi_polynomial_libsingular.unpickle_MPolynomialRing_libsingular()

inverse function for MPolynomialRing_libsingular.__reduce__

EXAMPLES:

sage: P.<x,y> = PolynomialRing(QQ)
sage: loads(dumps(P)) == P # indirect doctest
True
sage.rings.polynomial.multi_polynomial_libsingular.unpickle_MPolynomial_libsingular()

Deserialize an MPolynomial_libsingular object

INPUT:

EXAMPLES:

sage: P.<x,y> = PolynomialRing(QQ)
sage: loads(dumps(x)) == x # indirect doctest
True

Previous topic

Ideals in multivariate polynomial rings.

Next topic

Direct low-level access to SINGULAR’s Groebner basis engine via libSINGULAR.

This Page