Elements of multivariate Laurent polynomial rings - Polynomials

Skip to content
Back to top
View this page
Edit this page

# Elements of multivariate Laurent polynomial rings

class sage.rings.polynomial.laurent_polynomial_mpair.LaurentPolynomial_mpair

  Bases: `LaurentPolynomial`

  Multivariate Laurent polynomials.

  coefficient(mon)

    Return the coefficient of `mon` in `self`, where `mon` must have the same parent as `self`.

    The coefficient is defined as follows. If \(f\) is this polynomial, then the coefficient \(c_m\) is sum:

    \[c_m := \sum_T \frac{T}{m}\]

    where the sum is over terms \(T\) in \(f\) that are exactly divisible by \(m\).

    A monomial \(m(x,y)\) ‘exactly divides’ \(f(x,y)\) if \(m(x,y) | f(x,y)\) and neither \(x \cdot m(x,y)\) nor \(y \cdot m(x,y)\) divides \(f(x,y)\).

    INPUT:

    - `mon` – a monomial

    OUTPUT: element of the parent of `self`

    Note

    To get the constant coefficient, call `constant_coefficient()`.

    EXAMPLES:

    Sage

        sage: P.<x,y> = LaurentPolynomialRing(QQ)

    Python

        >>> from sage.all import *
        >>> P = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = P._first_ngens(2)

    The coefficient returned is an element of the parent of `self`; in this case, `P`.

    Sage

        sage: f = 2 * x * y
        sage: c = f.coefficient(x*y); c
        2
        sage: c.parent()
        Multivariate Laurent Polynomial Ring in x, y over Rational Field

        sage: P.<x,y> = LaurentPolynomialRing(QQ)
        sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f
        -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2
        sage: f.coefficient(y)
        5*x^-2
        sage: f.coefficient(y^2)
        -7*x^-2 + x^-3
        sage: f.coefficient(x*y)
        0
        sage: f.coefficient(x^-2)
        -7*y^2 + 5*y
        sage: f.coefficient(x^-2*y^2)
        -7
        sage: f.coefficient(1)
        -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2

    [Python]

        >>> from sage.all import *
        >>> f = Integer(2) * x * y
        >>> c = f.coefficient(x*y); c
        2
        >>> c.parent()
        Multivariate Laurent Polynomial Ring in x, y over Rational Field

        >>> P = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = P._first_ngens(2)
        >>> f = (y**Integer(2) - x**Integer(9) - Integer(7)*x*y**Integer(2) + Integer(5)*x*y)*x**-Integer(3); f
        -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2
        >>> f.coefficient(y)
        5*x^-2
        >>> f.coefficient(y**Integer(2))
        -7*x^-2 + x^-3
        >>> f.coefficient(x*y)
        0
        >>> f.coefficient(x**-Integer(2))
        -7*y^2 + 5*y
        >>> f.coefficient(x**-Integer(2)*y**Integer(2))
        -7
        >>> f.coefficient(Integer(1))
        -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2

  coefficients()

    Return the nonzero coefficients of `self` in a list.

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

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ, order='degrevlex')
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.coefficients()
        [4, 3, 2, 1]
        sage: L.<x,y,z> = LaurentPolynomialRing(QQ,order='lex')
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.coefficients()
        [4, 1, 2, 3]

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.coefficients()
        [4, 3, 2, 1]
        >>> L = LaurentPolynomialRing(QQ,order='lex', names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.coefficients()
        [4, 1, 2, 3]

  constant_coefficient()

    Return the constant coefficient of `self`.

    EXAMPLES:

    Sage

        sage: P.<x,y> = LaurentPolynomialRing(QQ)
        sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f
        -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2
        sage: f.constant_coefficient()
        0
        sage: f = (x^3 + 2*x^-2*y+y^3)*y^-3; f
        x^3*y^-3 + 1 + 2*x^-2*y^-2
        sage: f.constant_coefficient()
        1

    Python

        >>> from sage.all import *
        >>> P = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = P._first_ngens(2)
        >>> f = (y**Integer(2) - x**Integer(9) - Integer(7)*x*y**Integer(2) + Integer(5)*x*y)*x**-Integer(3); f
        -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2
        >>> f.constant_coefficient()
        0
        >>> f = (x**Integer(3) + Integer(2)*x**-Integer(2)*y+y**Integer(3))*y**-Integer(3); f
        x^3*y^-3 + 1 + 2*x^-2*y^-2
        >>> f.constant_coefficient()
        1

  degree(x=None)

    Return the degree of `self`.

    INPUT:

    - `x` – (default: `None`) a generator of the parent ring

    OUTPUT:

    If `x` is `None`, return the total degree of `self`. If `x` is a given generator of the parent ring, the output is the maximum degree of `x` in `self`.

    EXAMPLES:

    Sage

        sage: R.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.degree()
        6
        sage: f.degree(x)
        7
        sage: f.degree(y)
        1
        sage: f.degree(z)
        0

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.degree()
        6
        >>> f.degree(x)
        7
        >>> f.degree(y)
        1
        >>> f.degree(z)
        0

    The zero polynomial is defined to have degree \(-\infty\):

    Sage

        sage: R.<x, y, z> = LaurentPolynomialRing(ZZ)
        sage: R.zero().degree()
        -Infinity
        sage: R.zero().degree(x)
        -Infinity
        sage: R.zero().degree(x) == R.zero().degree(y) == R.zero().degree(z)
        True

    [Python]

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(ZZ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)
        >>> R.zero().degree()
        -Infinity
        >>> R.zero().degree(x)
        -Infinity
        >>> R.zero().degree(x) == R.zero().degree(y) == R.zero().degree(z)
        True

  derivative(*args)

    The formal derivative of this Laurent polynomial, with respect to variables supplied in args.

    Multiple variables and iteration counts may be supplied; see documentation for the global `derivative()` function for more details.

    See also

    `_derivative()`

    EXAMPLES:

    Sage

        sage: R = LaurentPolynomialRing(ZZ,'x, y')
        sage: x, y = R.gens()
        sage: t = x**4*y + x*y + y + x**(-1) + y**(-3)
        sage: t.derivative(x, x)
        12*x^2*y + 2*x^-3
        sage: t.derivative(y, 2)
        12*y^-5

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(ZZ,'x, y')
        >>> x, y = R.gens()
        >>> t = x**Integer(4)*y + x*y + y + x**(-Integer(1)) + y**(-Integer(3))
        >>> t.derivative(x, x)
        12*x^2*y + 2*x^-3
        >>> t.derivative(y, Integer(2))
        12*y^-5

  dict()

    alias of `monomial_coefficients()`.

  diff(*args)

    alias of `derivative()`.

  differentiate(*args)

    alias of `derivative()`.

  divides(other)

    Check if `self` divides `other`.

    EXAMPLES:

    Sage

        sage: R.<x,y> = LaurentPolynomialRing(QQ)
        sage: f1 = x^-2*y^3 - 9 - 1/14*x^-1*y - 1/3*x^-1
        sage: h = 3*x^-1 - 3*x^-2*y - 1/2*x^-3*y^2 - x^-3*y + x^-3
        sage: f2 = f1 * h
        sage: f3 = f2 + x * y
        sage: f1.divides(f2)
        True
        sage: f1.divides(f3)
        False
        sage: f1.divides(3)
        False

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> f1 = x**-Integer(2)*y**Integer(3) - Integer(9) - Integer(1)/Integer(14)*x**-Integer(1)*y - Integer(1)/Integer(3)*x**-Integer(1)
        >>> h = Integer(3)*x**-Integer(1) - Integer(3)*x**-Integer(2)*y - Integer(1)/Integer(2)*x**-Integer(3)*y**Integer(2) - x**-Integer(3)*y + x**-Integer(3)
        >>> f2 = f1 * h
        >>> f3 = f2 + x * y
        >>> f1.divides(f2)
        True
        >>> f1.divides(f3)
        False
        >>> f1.divides(Integer(3))
        False

    Zero is divisible by everything, and only zero is divisible by zero:

    Sage

        sage: R.<x,y> = LaurentPolynomialRing(ZZ)
        sage: x.divides(R(0))
        True
        sage: R(0).divides(x)
        False
        sage: R(0).divides(R(0))
        True

    [Python]

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> x.divides(R(Integer(0)))
        True
        >>> R(Integer(0)).divides(x)
        False
        >>> R(Integer(0)).divides(R(Integer(0)))
        True

    Monomials divide when the exponents allow:

    Sage

        sage: (x*y^-1).divides(x^2*y^-2)
        True
        sage: (x^2).divides(x)
        True

    Python

        >>> from sage.all import *
        >>> (x*y**-Integer(1)).divides(x**Integer(2)*y**-Integer(2))
        True
        >>> (x**Integer(2)).divides(x)
        True

  exponents()

    Return a list of the exponents of `self`.

    EXAMPLES:

    Sage

        sage: L.<w,z> = LaurentPolynomialRing(QQ)
        sage: a = w^2*z^-1 + 3; a
        w^2*z^-1 + 3
        sage: e = a.exponents()
        sage: e.sort(); e
        [(0, 0), (2, -1)]

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('w', 'z',)); (w, z,) = L._first_ngens(2)
        >>> a = w**Integer(2)*z**-Integer(1) + Integer(3); a
        w^2*z^-1 + 3
        >>> e = a.exponents()
        >>> e.sort(); e
        [(0, 0), (2, -1)]

  factor()

    Return a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial.

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.factor()
        (x^3*y^-7*z^-2) * (4*x^4*y^7*z + 3*y^8*z^2 + 2*x*y^7 + x^3*z^2)

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.factor()
        (x^3*y^-7*z^-2) * (4*x^4*y^7*z + 3*y^8*z^2 + 2*x*y^7 + x^3*z^2)

  has_any_inverse()

    Return `True` if `self` contains any monomials with a negative exponent, `False` otherwise.

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.has_any_inverse()
        True
        sage: g = x^2 + y^2
        sage: g.has_any_inverse()
        False

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.has_any_inverse()
        True
        >>> g = x**Integer(2) + y**Integer(2)
        >>> g.has_any_inverse()
        False

  has_inverse_of(i)

    INPUT:

    - `i` – the index of a generator of `self.parent()`

    OUTPUT:

    Return `True` if `self` contains a monomial including the inverse of `self.parent().gen(i)`, `False` otherwise.

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.has_inverse_of(0)
        False
        sage: f.has_inverse_of(1)
        True
        sage: f.has_inverse_of(2)
        True

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.has_inverse_of(Integer(0))
        False
        >>> f.has_inverse_of(Integer(1))
        True
        >>> f.has_inverse_of(Integer(2))
        True

  is_constant()

    Return whether this Laurent polynomial is constant.

    EXAMPLES:

    Sage

        sage: L.<a, b> = LaurentPolynomialRing(QQ)
        sage: L(0).is_constant()
        True
        sage: L(42).is_constant()
        True
        sage: a.is_constant()
        False
        sage: (1/b).is_constant()
        False

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('a', 'b',)); (a, b,) = L._first_ngens(2)
        >>> L(Integer(0)).is_constant()
        True
        >>> L(Integer(42)).is_constant()
        True
        >>> a.is_constant()
        False
        >>> (Integer(1)/b).is_constant()
        False

  is_monomial()

    Return `True` if `self` is a monomial.

    EXAMPLES:

    Sage

        sage: k.<y,z> = LaurentPolynomialRing(QQ)
        sage: z.is_monomial()
        True
        sage: k(1).is_monomial()
        True
        sage: (z+1).is_monomial()
        False
        sage: (z^-2909).is_monomial()
        True
        sage: (38*z^-2909).is_monomial()
        False

    Python

        >>> from sage.all import *
        >>> k = LaurentPolynomialRing(QQ, names=('y', 'z',)); (y, z,) = k._first_ngens(2)
        >>> z.is_monomial()
        True
        >>> k(Integer(1)).is_monomial()
        True
        >>> (z+Integer(1)).is_monomial()
        False
        >>> (z**-Integer(2909)).is_monomial()
        True
        >>> (Integer(38)*z**-Integer(2909)).is_monomial()
        False

  is_square(root=False)

    Test whether this Laurent polynomial is a square.

    INPUT:

    - `root` – boolean (default: `False`); if set to `True` then return a pair `(True, sqrt)` with `sqrt` a square root of this Laurent polynomial when it exists or `(False, None)`

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: p = 1 + x*y + z^-3
        sage: (p**2).is_square()
        True
        sage: (p**2).is_square(root=True)
        (True, x*y + 1 + z^-3)

        sage: x.is_square()
        False
        sage: x.is_square(root=True)
        (False, None)

        sage: (x**-4 * (1 + z)).is_square(root=False)
        False
        sage: (x**-4 * (1 + z)).is_square(root=True)
        (False, None)

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> p = Integer(1) + x*y + z**-Integer(3)
        >>> (p**Integer(2)).is_square()
        True
        >>> (p**Integer(2)).is_square(root=True)
        (True, x*y + 1 + z^-3)

        >>> x.is_square()
        False
        >>> x.is_square(root=True)
        (False, None)

        >>> (x**-Integer(4) * (Integer(1) + z)).is_square(root=False)
        False
        >>> (x**-Integer(4) * (Integer(1) + z)).is_square(root=True)
        (False, None)

  is_unit()

    Return `True` if `self` is a unit.

    The ground ring is assumed to be an integral domain.

    This means that the Laurent polynomial is a monomial with unit coefficient.

    EXAMPLES:

    Sage

        sage: L.<x,y> = LaurentPolynomialRing(QQ)
        sage: (x*y/2).is_unit()
        True
        sage: (x + y).is_unit()
        False
        sage: (L.zero()).is_unit()
        False
        sage: (L.one()).is_unit()
        True

        sage: L.<x,y> = LaurentPolynomialRing(ZZ)
        sage: (2*x*y).is_unit()
        False

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = L._first_ngens(2)
        >>> (x*y/Integer(2)).is_unit()
        True
        >>> (x + y).is_unit()
        False
        >>> (L.zero()).is_unit()
        False
        >>> (L.one()).is_unit()
        True

        >>> L = LaurentPolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = L._first_ngens(2)
        >>> (Integer(2)*x*y).is_unit()
        False

  is_univariate()

    Return `True` if this is a univariate or constant Laurent polynomial, and `False` otherwise.

    EXAMPLES:

    Sage

        sage: R.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = (x^3 + y^-3)*z
        sage: f.is_univariate()
        False
        sage: g = f(1, y, 4)
        sage: g.is_univariate()
        True
        sage: R(1).is_univariate()
        True

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)
        >>> f = (x**Integer(3) + y**-Integer(3))*z
        >>> f.is_univariate()
        False
        >>> g = f(Integer(1), y, Integer(4))
        >>> g.is_univariate()
        True
        >>> R(Integer(1)).is_univariate()
        True

  iterator_exp_coeff()

    Iterate over `self` as pairs of (ETuple, coefficient).

    EXAMPLES:

    Sage

        sage: P.<x,y> = LaurentPolynomialRing(QQ)
        sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3
        sage: list(f.iterator_exp_coeff())
        [((6, 0), -1), ((-2, 3), -7), ((-2, 1), 5), ((-3, 2), 1)]

    Python

        >>> from sage.all import *
        >>> P = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = P._first_ngens(2)
        >>> f = (y**Integer(2) - x**Integer(9) - Integer(7)*x*y**Integer(3) + Integer(5)*x*y)*x**-Integer(3)
        >>> list(f.iterator_exp_coeff())
        [((6, 0), -1), ((-2, 3), -7), ((-2, 1), 5), ((-3, 2), 1)]

  monomial_coefficient(mon)

    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

    See also

    For coefficients in a base ring of fewer variables, see `coefficient()`.

    EXAMPLES:

    Sage

        sage: P.<x,y> = LaurentPolynomialRing(QQ)
        sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3
        sage: f.monomial_coefficient(x^-2*y^3)
        -7
        sage: f.monomial_coefficient(x^2)
        0

    Python

        >>> from sage.all import *
        >>> P = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = P._first_ngens(2)
        >>> f = (y**Integer(2) - x**Integer(9) - Integer(7)*x*y**Integer(3) + Integer(5)*x*y)*x**-Integer(3)
        >>> f.monomial_coefficient(x**-Integer(2)*y**Integer(3))
        -7
        >>> f.monomial_coefficient(x**Integer(2))
        0

  monomial_coefficients()

    Return `self` represented as a `dict`.

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: sorted(f.monomial_coefficients().items())
        [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)]

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> sorted(f.monomial_coefficients().items())
        [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)]

    `dict` is an alias:

    Sage

        sage: sorted(f.dict().items())
        [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)]

    [Python]

        >>> from sage.all import *
        >>> sorted(f.dict().items())
        [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)]

  monomial_reduction()

    Factor `self` into a polynomial and a monomial.

    OUTPUT:

    A tuple `(p, v)` where `p` is the underlying polynomial and `v` is a monomial.

    EXAMPLES:

    Sage

        sage: R.<x, y> = LaurentPolynomialRing(QQ)
        sage: f = y / x + x^2 / y + 3 * x^4 * y^-2
        sage: f.monomial_reduction()
        (3*x^5 + x^3*y + y^3, x^-1*y^-2)
        sage: f = y * x + x^2 / y + 3 * x^4 * y^-2
        sage: f.monomial_reduction()
         (3*x^3 + y^3 + x*y, x*y^-2)
        sage: x.monomial_reduction()
        (1, x)
        sage: (y^-1).monomial_reduction()
        (1, y^-1)

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> f = y / x + x**Integer(2) / y + Integer(3) * x**Integer(4) * y**-Integer(2)
        >>> f.monomial_reduction()
        (3*x^5 + x^3*y + y^3, x^-1*y^-2)
        >>> f = y * x + x**Integer(2) / y + Integer(3) * x**Integer(4) * y**-Integer(2)
        >>> f.monomial_reduction()
         (3*x^3 + y^3 + x*y, x*y^-2)
        >>> x.monomial_reduction()
        (1, x)
        >>> (y**-Integer(1)).monomial_reduction()
        (1, y^-1)

  monomials()

    Return the list of monomials in `self`.

    EXAMPLES:

    Sage

        sage: P.<x,y> = LaurentPolynomialRing(QQ)
        sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3
        sage: sorted(f.monomials())
        [x^-3*y^2, x^-2*y, x^-2*y^3, x^6]

    Python

        >>> from sage.all import *
        >>> P = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = P._first_ngens(2)
        >>> f = (y**Integer(2) - x**Integer(9) - Integer(7)*x*y**Integer(3) + Integer(5)*x*y)*x**-Integer(3)
        >>> sorted(f.monomials())
        [x^-3*y^2, x^-2*y, x^-2*y^3, x^6]

  newton_polytope()

    Return the Newton polytope of this Laurent polynomial.

    EXAMPLES:

    Sage

        sage: R.<x, y> = LaurentPolynomialRing(QQ)
        sage: f = 1 + x*y + y**2 + 33 * x^-3
        sage: P = f.newton_polytope(); P                                            # needs sage.geometry.polyhedron
        A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 4 vertices

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> f = Integer(1) + x*y + y**Integer(2) + Integer(33) * x**-Integer(3)
        >>> P = f.newton_polytope(); P                                            # needs sage.geometry.polyhedron
        A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 4 vertices

  number_of_terms()

    Return the number of nonzero coefficients of `self`.

    Also called weight, hamming weight or sparsity.

    EXAMPLES:

    Sage

        sage: R.<x, y> = LaurentPolynomialRing(ZZ)
        sage: f = x^3 - y
        sage: f.number_of_terms()
        2
        sage: R(0).number_of_terms()
        0
        sage: f = (x+1/y)^100
        sage: f.number_of_terms()
        101

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> f = x**Integer(3) - y
        >>> f.number_of_terms()
        2
        >>> R(Integer(0)).number_of_terms()
        0
        >>> f = (x+Integer(1)/y)**Integer(100)
        >>> f.number_of_terms()
        101

    The method `hamming_weight()` is an alias:

    Sage

        sage: f.hamming_weight()
        101

    [Python]

        >>> from sage.all import *
        >>> f.hamming_weight()
        101

  quo_rem(right)

    Divide this Laurent polynomial by `right` and return a quotient and a remainder.

    INPUT:

    - `right` – a Laurent polynomial

    OUTPUT: a pair of Laurent polynomials

    EXAMPLES:

    Sage

        sage: R.<s, t> = LaurentPolynomialRing(QQ)
        sage: (s^2 - t^2).quo_rem(s - t)                                            # needs sage.libs.singular
        (s + t, 0)
        sage: (s^-2 - t^2).quo_rem(s - t)                                           # needs sage.libs.singular
        (s + t, -s^2 + s^-2)
        sage: (s^-2 - t^2).quo_rem(s^-1 - t)                                        # needs sage.libs.singular
        (t + s^-1, 0)

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(QQ, names=('s', 't',)); (s, t,) = R._first_ngens(2)
        >>> (s**Integer(2) - t**Integer(2)).quo_rem(s - t)                                            # needs sage.libs.singular
        (s + t, 0)
        >>> (s**-Integer(2) - t**Integer(2)).quo_rem(s - t)                                           # needs sage.libs.singular
        (s + t, -s^2 + s^-2)
        >>> (s**-Integer(2) - t**Integer(2)).quo_rem(s**-Integer(1) - t)                                        # needs sage.libs.singular
        (t + s^-1, 0)

  rescale_vars(d, h=None, new_ring=None)

    Rescale variables in a Laurent polynomial.

    INPUT:

    - `d` – a `dict` whose keys are the generator indices and values are the coefficients; so a pair `(i, v)` means \(x_i \mapsto v x_i\)

    - `h` – (optional) a map to be applied to coefficients done after rescaling

    - `new_ring` – (optional) a new ring to map the result into

    EXAMPLES:

    Sage

        sage: L.<x,y> = LaurentPolynomialRing(QQ, 2)
        sage: p = x^-2*y + x*y^-2
        sage: p.rescale_vars({0: 2, 1: 3})
        2/9*x*y^-2 + 3/4*x^-2*y
        sage: F = GF(2)
        sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F))
        x*y^-2 + x^-2*y

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = L._first_ngens(2)
        >>> p = x**-Integer(2)*y + x*y**-Integer(2)
        >>> p.rescale_vars({Integer(0): Integer(2), Integer(1): Integer(3)})
        2/9*x*y^-2 + 3/4*x^-2*y
        >>> F = GF(Integer(2))
        >>> p.rescale_vars({Integer(0): Integer(3), Integer(1): Integer(7)}, new_ring=L.change_ring(F))
        x*y^-2 + x^-2*y

    Test for Issue #30331:

    Sage

        sage: F.<z> = CyclotomicField(3)                                            # needs sage.rings.number_field
        sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F))               # needs sage.rings.number_field
        2*z*x*y^-2 + 1/4*z*x^-2*y

    [Python]

        >>> from sage.all import *
        >>> F = CyclotomicField(Integer(3), names=('z',)); (z,) = F._first_ngens(1)# needs sage.rings.number_field
        >>> p.rescale_vars({Integer(0): Integer(2), Integer(1): z}, new_ring=L.change_ring(F))               # needs sage.rings.number_field
        2*z*x*y^-2 + 1/4*z*x^-2*y

  subs(in_dict=None, **kwds)

    Substitute some variables in this Laurent polynomial.

    Variable/value pairs for the substitution may be given as a dictionary or via keyword-value pairs. If both are present, the latter take precedence.

    INPUT:

    - `in_dict` – dictionary (optional)

    - `**kwds` – keyword arguments

    OUTPUT: a Laurent polynomial

    EXAMPLES:

    Sage

        sage: L.<x, y, z> = LaurentPolynomialRing(QQ)
        sage: f = x + 2*y + 3*z
        sage: f.subs(x=1)
        2*y + 3*z + 1
        sage: f.subs(y=1)
        x + 3*z + 2
        sage: f.subs(z=1)
        x + 2*y + 3
        sage: f.subs(x=1, y=1, z=1)
        6

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

        sage: f = x + 2*y + 3*z
        sage: f.subs({x: 1, y: 1, z: 1})
        6
        sage: f.substitute(x=1, y=1, z=1)
        6

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = x + Integer(2)*y + Integer(3)*z
        >>> f.subs(x=Integer(1))
        2*y + 3*z + 1
        >>> f.subs(y=Integer(1))
        x + 3*z + 2
        >>> f.subs(z=Integer(1))
        x + 2*y + 3
        >>> f.subs(x=Integer(1), y=Integer(1), z=Integer(1))
        6

        >>> f = x**-Integer(1)
        >>> f.subs(x=Integer(2))
        1/2
        >>> f.subs({x: Integer(2)})
        1/2

        >>> f = x + Integer(2)*y + Integer(3)*z
        >>> f.subs({x: Integer(1), y: Integer(1), z: Integer(1)})
        6
        >>> f.substitute(x=Integer(1), y=Integer(1), z=Integer(1))
        6

  toric_coordinate_change(M, h=None, new_ring=None)

    Apply a matrix to the exponents in a Laurent polynomial.

    For efficiency, we implement this directly, rather than as a substitution.

    The optional argument `h` is a map to be applied to coefficients.

    EXAMPLES:

    Sage

        sage: L.<x,y> = LaurentPolynomialRing(QQ, 2)
        sage: p = 2*x^2 + y - x*y
        sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]]))
        2*x^2*y^2 - x^-2*y^2 + x^-3*y
        sage: F = GF(2)
        sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]]),
        ....:                           new_ring=L.change_ring(F))
        x^-2*y^2 + x^-3*y

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = L._first_ngens(2)
        >>> p = Integer(2)*x**Integer(2) + y - x*y
        >>> p.toric_coordinate_change(Matrix([[Integer(1),-Integer(3)], [Integer(1),Integer(1)]]))
        2*x^2*y^2 - x^-2*y^2 + x^-3*y
        >>> F = GF(Integer(2))
        >>> p.toric_coordinate_change(Matrix([[Integer(1),-Integer(3)], [Integer(1),Integer(1)]]),
        ...                           new_ring=L.change_ring(F))
        x^-2*y^2 + x^-3*y

  toric_substitute(v, v1, a, h=None, new_ring=None)

    Perform a single-variable substitution up to a toric coordinate change.

    The optional argument `h` is a map to be applied to coefficients.

    EXAMPLES:

    Sage

        sage: L.<x,y> = LaurentPolynomialRing(QQ, 2)
        sage: p = x + y
        sage: p.toric_substitute((2,3), (-1,1), 2)
        1/2*x^3*y^3 + 2*x^-2*y^-2
        sage: F = GF(5)
        sage: p.toric_substitute((2,3), (-1,1), 2, new_ring=L.change_ring(F))
        3*x^3*y^3 + 2*x^-2*y^-2

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = L._first_ngens(2)
        >>> p = x + y
        >>> p.toric_substitute((Integer(2),Integer(3)), (-Integer(1),Integer(1)), Integer(2))
        1/2*x^3*y^3 + 2*x^-2*y^-2
        >>> F = GF(Integer(5))
        >>> p.toric_substitute((Integer(2),Integer(3)), (-Integer(1),Integer(1)), Integer(2), new_ring=L.change_ring(F))
        3*x^3*y^3 + 2*x^-2*y^-2

  univariate_polynomial(R=None)

    Return a univariate polynomial associated to this multivariate polynomial.

    INPUT:

    - `R` – (default: `None`) a univariate Laurent polynomial ring

    If this polynomial is not in at most one variable, then a `ValueError` exception is raised. The new polynomial is over the same base ring as the given `LaurentPolynomial` and in the variable `x` if no ring `R` is provided.

    EXAMPLES:

    Sage

        sage: R.<x, y> = LaurentPolynomialRing(ZZ)
        sage: f = 3*x^2 - 2*y^-1 + 7*x^2*y^2 + 5
        sage: f.univariate_polynomial()
        Traceback (most recent call last):
        ...
        TypeError: polynomial must involve at most one variable
        sage: g = f(10, y); g
        700*y^2 + 305 - 2*y^-1
        sage: h = g.univariate_polynomial(); h
        -2*y^-1 + 305 + 700*y^2
        sage: h.parent()
        Univariate Laurent Polynomial Ring in y over Integer Ring
        sage: g.univariate_polynomial(LaurentPolynomialRing(QQ,'z'))
        -2*z^-1 + 305 + 700*z^2

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> f = Integer(3)*x**Integer(2) - Integer(2)*y**-Integer(1) + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5)
        >>> f.univariate_polynomial()
        Traceback (most recent call last):
        ...
        TypeError: polynomial must involve at most one variable
        >>> g = f(Integer(10), y); g
        700*y^2 + 305 - 2*y^-1
        >>> h = g.univariate_polynomial(); h
        -2*y^-1 + 305 + 700*y^2
        >>> h.parent()
        Univariate Laurent Polynomial Ring in y over Integer Ring
        >>> g.univariate_polynomial(LaurentPolynomialRing(QQ,'z'))
        -2*z^-1 + 305 + 700*z^2

    Here’s an example with a constant multivariate polynomial:

    Sage

        sage: g = R(1)
        sage: h = g.univariate_polynomial(); h
        1
        sage: h.parent()
        Univariate Laurent Polynomial Ring in x over Integer Ring

    [Python]

        >>> from sage.all import *
        >>> g = R(Integer(1))
        >>> h = g.univariate_polynomial(); h
        1
        >>> h.parent()
        Univariate Laurent Polynomial Ring in x over Integer Ring

  valuation(x=None)

    Return the valuation of `self`.

    If `x` is `None`, the returned valuation is the minimal total degree of the monomials occurring in `self`. Geometrically, this is the order of vanishing of `self` at the generic point of the blow-up of the point \((0,0,\ldots,0)\).

    If `x` is not `None`, then it must be a generator. In that case, the minimum degree of that generator occurring in `self` is returned. Geometrically, this is the order of vanishing of `self` at the generic point of the curve \(x = 0\).

    INPUT:

    - `x` – (optional) a generator; if given, return the valuation with respect to this generator

    EXAMPLES:

    Sage

        sage: R.<x,y> = LaurentPolynomialRing(ZZ)
        sage: f = 2*x^2*y^-3 - 13*x^-1*y^-3 + 2*x^2*y^-5 - 2*x^-3*y^2
        sage: f.valuation()
        -4
        sage: f.valuation(x)
        -3
        sage: f.valuation(y)
        -5
        sage: R.zero().valuation()
        +Infinity

    Python

        >>> from sage.all import *
        >>> R = LaurentPolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
        >>> f = Integer(2)*x**Integer(2)*y**-Integer(3) - Integer(13)*x**-Integer(1)*y**-Integer(3) + Integer(2)*x**Integer(2)*y**-Integer(5) - Integer(2)*x**-Integer(3)*y**Integer(2)
        >>> f.valuation()
        -4
        >>> f.valuation(x)
        -3
        >>> f.valuation(y)
        -5
        >>> R.zero().valuation()
        +Infinity

  variables(sort=True)

    Return a tuple of all variables occurring in `self`.

    INPUT:

    - `sort` – specifies whether the indices shall be sorted

    EXAMPLES:

    Sage

        sage: L.<x,y,z> = LaurentPolynomialRing(QQ)
        sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
        sage: f.variables()
        (z, y, x)
        sage: f.variables(sort=False) #random
        (y, z, x)

    Python

        >>> from sage.all import *
        >>> L = LaurentPolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = L._first_ngens(3)
        >>> f = Integer(4)*x**Integer(7)*z**-Integer(1) + Integer(3)*x**Integer(3)*y + Integer(2)*x**Integer(4)*z**-Integer(2) + x**Integer(6)*y**-Integer(7)
        >>> f.variables()
        (z, y, x)
        >>> f.variables(sort=False) #random
        (y, z, x)