Elements of multivariate Laurent polynomial rings¶
- class sage.rings.polynomial.laurent_polynomial_mpair.LaurentPolynomial_mpair[source]¶
Bases:
LaurentPolynomialMultivariate Laurent polynomials.
- coefficient(mon)[source]¶
Return the coefficient of
moninself, wheremonmust have the same parent asself.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
selfNote
To get the constant coefficient, call
constant_coefficient().EXAMPLES:
sage: P.<x,y> = LaurentPolynomialRing(QQ)
The coefficient returned is an element of the parent of
self; in this case,P.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
- coefficients()[source]¶
Return the nonzero coefficients of
selfin a list.The returned list is decreasingly ordered by the term ordering of
self.parent().EXAMPLES:
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]
- constant_coefficient()[source]¶
Return the constant coefficient of
self.EXAMPLES:
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
- degree(x=None)[source]¶
Return the degree of
self.INPUT:
x– (default:None) a generator of the parent ring
OUTPUT:
If
xisNone, return the total degree ofself. Ifxis a given generator of the parent ring, the output is the maximum degree ofxinself.EXAMPLES:
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
The zero polynomial is defined to have degree \(-\infty\):
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
- derivative(*args)[source]¶
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: 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
- dict()[source]¶
alias of
monomial_coefficients().
- diff(*args)[source]¶
alias of
derivative().
- differentiate(*args)[source]¶
alias of
derivative().
- divides(other)[source]¶
Check if
selfdividesother.EXAMPLES:
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
Zero is divisible by everything, and only zero is divisible by zero:
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
Monomials divide when the exponents allow:
sage: (x*y^-1).divides(x^2*y^-2) True sage: (x^2).divides(x) True
- exponents()[source]¶
Return a list of the exponents of
self.EXAMPLES:
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)]
- factor()[source]¶
Return a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial.
EXAMPLES:
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)
- has_any_inverse()[source]¶
Return
Trueifselfcontains any monomials with a negative exponent,Falseotherwise.EXAMPLES:
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
- has_inverse_of(i)[source]¶
INPUT:
i– the index of a generator ofself.parent()
OUTPUT:
Return
Trueifselfcontains a monomial including the inverse ofself.parent().gen(i),Falseotherwise.EXAMPLES:
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
- is_constant()[source]¶
Return whether this Laurent polynomial is constant.
EXAMPLES:
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
- is_monomial()[source]¶
Return
Trueifselfis a monomial.EXAMPLES:
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
- is_square(root=False)[source]¶
Test whether this Laurent polynomial is a square.
INPUT:
root– boolean (default:False); if set toTruethen return a pair(True, sqrt)withsqrta square root of this Laurent polynomial when it exists or(False, None)
EXAMPLES:
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)
- is_unit()[source]¶
Return
Trueifselfis 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: 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
- is_univariate()[source]¶
Return
Trueif this is a univariate or constant Laurent polynomial, andFalseotherwise.EXAMPLES:
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
- iterator_exp_coeff()[source]¶
Iterate over
selfas pairs of (ETuple, coefficient).EXAMPLES:
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)]
- monomial_coefficient(mon)[source]¶
Return the coefficient in the base ring of the monomial
moninself, wheremonmust have the same parent asself.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: 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
- monomial_coefficients()[source]¶
Return
selfrepresented as adict.EXAMPLES:
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)]
dictis an alias:sage: sorted(f.dict().items()) [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)]
- monomial_reduction()[source]¶
Factor
selfinto a polynomial and a monomial.OUTPUT:
A tuple
(p, v)wherepis the underlying polynomial andvis a monomial.EXAMPLES:
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)
- monomials()[source]¶
Return the list of monomials in
self.EXAMPLES:
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]
- newton_polytope()[source]¶
Return the Newton polytope of this Laurent polynomial.
EXAMPLES:
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
- number_of_terms()[source]¶
Return the number of nonzero coefficients of
self.Also called weight, hamming weight or sparsity.
EXAMPLES:
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
The method
hamming_weight()is an alias:sage: f.hamming_weight() 101
- quo_rem(right)[source]¶
Divide this Laurent polynomial by
rightand return a quotient and a remainder.INPUT:
right– a Laurent polynomial
OUTPUT: a pair of Laurent polynomials
EXAMPLES:
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)
- rescale_vars(d, h=None, new_ring=None)[source]¶
Rescale variables in a Laurent polynomial.
INPUT:
d– adictwhose 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 rescalingnew_ring– (optional) a new ring to map the result into
EXAMPLES:
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
Test for Issue #30331:
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
- subs(in_dict=None, **kwds)[source]¶
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: 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
- toric_coordinate_change(M, h=None, new_ring=None)[source]¶
Apply a matrix to the exponents in a Laurent polynomial.
For efficiency, we implement this directly, rather than as a substitution.
The optional argument
his a map to be applied to coefficients.EXAMPLES:
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
- toric_substitute(v, v1, a, h=None, new_ring=None)[source]¶
Perform a single-variable substitution up to a toric coordinate change.
The optional argument
his a map to be applied to coefficients.EXAMPLES:
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
- univariate_polynomial(R=None)[source]¶
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
ValueErrorexception is raised. The new polynomial is over the same base ring as the givenLaurentPolynomialand in the variablexif no ringRis provided.EXAMPLES:
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
Here’s an example with a constant multivariate polynomial:
sage: g = R(1) sage: h = g.univariate_polynomial(); h 1 sage: h.parent() Univariate Laurent Polynomial Ring in x over Integer Ring
- valuation(x=None)[source]¶
Return the valuation of
self.If
xisNone, the returned valuation is the minimal total degree of the monomials occurring inself. Geometrically, this is the order of vanishing ofselfat the generic point of the blow-up of the point \((0,0,\ldots,0)\).If
xis notNone, then it must be a generator. In that case, the minimum degree of that generator occurring inselfis returned. Geometrically, this is the order of vanishing ofselfat 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: 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
- variables(sort=True)[source]¶
Return a tuple of all variables occurring in
self.INPUT:
sort– specifies whether the indices shall be sorted
EXAMPLES:
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)