Multivariate Polynomial Rings over Generic Rings#

Sage implements multivariate polynomial rings through several backends. This generic implementation uses the classes PolyDict and ETuple to construct a dictionary with exponent tuples as keys and coefficients as values.

AUTHORS:

  • David Joyner and William Stein

  • Kiran S. Kedlaya (2006-02-12): added Macaulay2 analogues of Singular features

  • Martin Albrecht (2006-04-21): reorganize class hierarchy for singular rep

  • Martin Albrecht (2007-04-20): reorganized class hierarchy to support Pyrex implementations

  • Robert Bradshaw (2007-08-15): Coercions from rings in a subset of the variables.

EXAMPLES:

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

sage: R.<x,y,z> = GF(5)[]
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)                                                             # needs sage.rings.finite_rings
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15
sage: (x^5 + 2*y^5)^3                                                               # needs sage.rings.finite_rings
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15
>>> from sage.all import *
>>> R = GF(Integer(5))['x, y, z']; (x, y, z,) = R._first_ngens(3)
>>> frob = R.hom([x**Integer(5), y**Integer(5), z**Integer(5)])
>>> frob(x**Integer(2) + Integer(2)*y - z**Integer(4))
-z^20 + x^10 + 2*y^5
>>> frob((x + Integer(2)*y)**Integer(3))                                                             # needs sage.rings.finite_rings
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15
>>> (x**Integer(5) + Integer(2)*y**Integer(5))**Integer(3)                                                               # needs sage.rings.finite_rings
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
>>> from sage.all import *
>>> R = PolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> S = PowerSeriesRing(R, names=('t',)); (t,) = S._first_ngens(1)
>>> t*(x+y)
(x + y)*t
class sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_macaulay2_repr[source]#

Bases: object

A mixin class for polynomial rings that support conversion to Macaulay2.

class sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict(base_ring, n, names, order)[source]#

Bases: MPolynomialRing_macaulay2_repr, PolynomialRing_singular_repr, MPolynomialRing_base

Multivariable polynomial ring.

EXAMPLES:

sage: R = PolynomialRing(Integers(12), 'x', 5); R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Ring of integers modulo 12
sage: loads(R.dumps()) == R
True
>>> from sage.all import *
>>> R = PolynomialRing(Integers(Integer(12)), 'x', Integer(5)); R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Ring of integers modulo 12
>>> loads(R.dumps()) == R
True
Element_hidden[source]#

alias of MPolynomial_polydict

monomial_all_divisors(t)[source]#

Return a list of all monomials that divide t, coefficients are ignored.

INPUT:

  • t – a monomial.

OUTPUT: a list of monomials.

EXAMPLES:

sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
sage: P.<x,y,z> = MPolynomialRing_polydict_domain(QQ,3, order='degrevlex')
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]
>>> from sage.all import *
>>> from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
>>> P = MPolynomialRing_polydict_domain(QQ,Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> P.monomial_all_divisors(x**Integer(2)*z**Integer(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(a, b)[source]#

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

INPUT:

  • a – monomial

  • b – monomial

OUTPUT: Boolean

EXAMPLES:

sage: P.<x,y,z> = PolynomialRing(ZZ,3, order='degrevlex')
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
>>> from sage.all import *
>>> P = PolynomialRing(ZZ,Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> P.monomial_divides(x*y*z, x**Integer(3)*y**Integer(2)*z**Integer(4))
True
>>> P.monomial_divides(x**Integer(3)*y**Integer(2)*z**Integer(4), x*y*z)
False
monomial_lcm(f, g)[source]#

LCM for monomials. Coefficients are ignored.

INPUT:

  • f – monomial.

  • g – monomial.

OUTPUT: monomial.

EXAMPLES:

sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
sage: P.<x,y,z> = MPolynomialRing_polydict_domain(QQ,3, order='degrevlex')
sage: P.monomial_lcm(3/2*x*y, x)
x*y
>>> from sage.all import *
>>> from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
>>> P = MPolynomialRing_polydict_domain(QQ,Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> P.monomial_lcm(Integer(3)/Integer(2)*x*y, x)
x*y
monomial_pairwise_prime(h, g)[source]#

Return True if h and g are pairwise prime.

Both are treated as monomials.

INPUT:

  • h – monomial.

  • g – monomial.

OUTPUT: Boolean.

EXAMPLES:

sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
sage: P.<x,y,z> = MPolynomialRing_polydict_domain(QQ,3, order='degrevlex')
sage: P.monomial_pairwise_prime(x^2*z^3, y^4)
True
>>> from sage.all import *
>>> from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
>>> P = MPolynomialRing_polydict_domain(QQ,Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> P.monomial_pairwise_prime(x**Integer(2)*z**Integer(3), y**Integer(4))
True
sage: P.monomial_pairwise_prime(1/2*x^3*y^2, 3/4*y^3)
False
>>> from sage.all import *
>>> P.monomial_pairwise_prime(Integer(1)/Integer(2)*x**Integer(3)*y**Integer(2), Integer(3)/Integer(4)*y**Integer(3))
False
monomial_quotient(f, g, coeff=False)[source]#

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).

OUTPUT: monomial.

EXAMPLES:

sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
sage: P.<x,y,z> = MPolynomialRing_polydict_domain(QQ, 3, order='degrevlex')
sage: P.monomial_quotient(3/2*x*y, x)
y
>>> from sage.all import *
>>> from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
>>> P = MPolynomialRing_polydict_domain(QQ, Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> P.monomial_quotient(Integer(3)/Integer(2)*x*y, x)
y
sage: P.monomial_quotient(3/2*x*y, 2*x, coeff=True)
3/4*y
>>> from sage.all import *
>>> P.monomial_quotient(Integer(3)/Integer(2)*x*y, Integer(2)*x, coeff=True)
3/4*y

Note

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(f, G)[source]#

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 ring.

INPUT:

  • f – monomial

  • G – list/set of mpolynomials

EXAMPLES:

sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
sage: P.<x,y,z>=MPolynomialRing_polydict_domain(QQ,3, order='degrevlex')
sage: f = x*y^2
sage: G = [3/2*x^3 + y^2 + 1/2, 1/4*x*y + 2/7, P(1/2)]
sage: P.monomial_reduce(f,G)
(y, 1/4*x*y + 2/7)
>>> from sage.all import *
>>> from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
>>> P = MPolynomialRing_polydict_domain(QQ,Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> f = x*y**Integer(2)
>>> G = [Integer(3)/Integer(2)*x**Integer(3) + y**Integer(2) + Integer(1)/Integer(2), Integer(1)/Integer(4)*x*y + Integer(2)/Integer(7), P(Integer(1)/Integer(2))]
>>> P.monomial_reduce(f,G)
(y, 1/4*x*y + 2/7)
sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
sage: P.<x,y,z> = MPolynomialRing_polydict_domain(Zmod(23432),3, order='degrevlex')
sage: f = x*y^2
sage: G = [3*x^3 + y^2 + 2, 4*x*y + 7, P(2)]
sage: P.monomial_reduce(f,G)
(y, 4*x*y + 7)
>>> from sage.all import *
>>> from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict_domain
>>> P = MPolynomialRing_polydict_domain(Zmod(Integer(23432)),Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3)
>>> f = x*y**Integer(2)
>>> G = [Integer(3)*x**Integer(3) + y**Integer(2) + Integer(2), Integer(4)*x*y + Integer(7), P(Integer(2))]
>>> P.monomial_reduce(f,G)
(y, 4*x*y + 7)
sum(terms)[source]#

Return a sum of elements of this multipolynomial ring.

This is method is much faster than the Python builtin sum().

EXAMPLES:

sage: R = QQ['x']
sage: S = R['y, z']
sage: x = R.gen()
sage: y, z = S.gens()
sage: S.sum([x*y, 2*x^2*z - 2*x*y, 1 + y + z])
(-x + 1)*y + (2*x^2 + 1)*z + 1
>>> from sage.all import *
>>> R = QQ['x']
>>> S = R['y, z']
>>> x = R.gen()
>>> y, z = S.gens()
>>> S.sum([x*y, Integer(2)*x**Integer(2)*z - Integer(2)*x*y, Integer(1) + y + z])
(-x + 1)*y + (2*x^2 + 1)*z + 1

Comparison with builtin sum():

sage: sum([x*y, 2*x^2*z - 2*x*y, 1 + y + z])
(-x + 1)*y + (2*x^2 + 1)*z + 1
>>> from sage.all import *
>>> sum([x*y, Integer(2)*x**Integer(2)*z - Integer(2)*x*y, Integer(1) + y + z])
(-x + 1)*y + (2*x^2 + 1)*z + 1
class sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain(base_ring, n, names, order)[source]#

Bases: IntegralDomain, MPolynomialRing_polydict

ideal(*gens, **kwds)[source]#

Create an ideal in this polynomial ring.

is_field(proof=True)[source]#
is_integral_domain(proof=True)[source]#