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)
>>> 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: 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()[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]
>>> 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()[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
>>> 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)[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
>>> 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: 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)[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
>>> 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()[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
>>> 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: 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: (x*y^-1).divides(x^2*y^-2) True sage: (x^2).divides(x) True
>>> from sage.all import * >>> (x*y**-Integer(1)).divides(x**Integer(2)*y**-Integer(2)) True >>> (x**Integer(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)]
>>> 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()[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)
>>> 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()[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
>>> 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)[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
>>> 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()[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
>>> 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()[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
>>> 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)[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)
>>> 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()[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
>>> 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()[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
>>> 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()[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)]
>>> 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)[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
>>> 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()[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)]
>>> 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)]
dictis an alias: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()[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)
>>> 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()[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]
>>> 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()[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
>>> 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()[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
>>> 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: f.hamming_weight() 101
[Python]>>> from sage.all import * >>> 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)
>>> 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)[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
>>> 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: 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)[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
>>> 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)[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
>>> 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)[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
>>> 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)[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
>>> 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: 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)[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
>>> 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)[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)
>>> 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)