Base class for elements of multivariate polynomial rings¶
- class sage.rings.polynomial.multi_polynomial.MPolynomial[source]¶
Bases:
CommutativePolynomial
- args()[source]¶
Return the names of the arguments of
self
, in the order they are accepted from call.EXAMPLES:
sage: R.<x,y> = ZZ[] sage: x.args() (x, y)
>>> from sage.all import * >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> x.args() (x, y)
R.<x,y> = ZZ[] x.args()
- change_ring(R)[source]¶
Return this polynomial with coefficients converted to
R
.INPUT:
R
– a ring or morphism; if a morphism, the coefficients are mapped to the codomain ofR
OUTPUT: a new polynomial with the base ring changed to
R
EXAMPLES:
sage: R.<x,y> = QQ[] sage: f = x^3 + 3/5*y + 1 sage: f.change_ring(GF(7)) x^3 + 2*y + 1 sage: g = x^2 + 5*y sage: g.change_ring(GF(5)) x^2
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(3) + Integer(3)/Integer(5)*y + Integer(1) >>> f.change_ring(GF(Integer(7))) x^3 + 2*y + 1 >>> g = x**Integer(2) + Integer(5)*y >>> g.change_ring(GF(Integer(5))) x^2
R.<x,y> = QQ[] f = x^3 + 3/5*y + 1 f.change_ring(GF(7)) g = x^2 + 5*y g.change_ring(GF(5))
sage: # needs sage.rings.finite_rings sage: R.<x,y> = GF(9,'a')[] sage: (x+2*y).change_ring(GF(3)) x - y
>>> from sage.all import * >>> # needs sage.rings.finite_rings >>> R = GF(Integer(9),'a')['x, y']; (x, y,) = R._first_ngens(2) >>> (x+Integer(2)*y).change_ring(GF(Integer(3))) x - y
# needs sage.rings.finite_rings R.<x,y> = GF(9,'a')[] (x+2*y).change_ring(GF(3))
sage: # needs sage.rings.finite_rings sage: F.<a> = GF(7^2) sage: R.<x,y> = F[] sage: f = x^2 + a^2*y^2 + a*x + a^3*y sage: g = f.change_ring(F.frobenius_endomorphism()); g x^2 + (-a - 2)*y^2 + (-a + 1)*x + (2*a + 2)*y sage: g.change_ring(F.frobenius_endomorphism()) == f True
>>> from sage.all import * >>> # needs sage.rings.finite_rings >>> F = GF(Integer(7)**Integer(2), names=('a',)); (a,) = F._first_ngens(1) >>> R = F['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(2) + a**Integer(2)*y**Integer(2) + a*x + a**Integer(3)*y >>> g = f.change_ring(F.frobenius_endomorphism()); g x^2 + (-a - 2)*y^2 + (-a + 1)*x + (2*a + 2)*y >>> g.change_ring(F.frobenius_endomorphism()) == f True
# needs sage.rings.finite_rings F.<a> = GF(7^2) R.<x,y> = F[] f = x^2 + a^2*y^2 + a*x + a^3*y g = f.change_ring(F.frobenius_endomorphism()); g g.change_ring(F.frobenius_endomorphism()) == f
sage: # needs sage.rings.number_field sage: K.<z> = CyclotomicField(3) sage: R.<x,y> = K[] sage: f = x^2 + z*y sage: f.change_ring(K.embeddings(CC)[1]) x^2 + (-0.500000000000000 - 0.866025403784438*I)*y
>>> from sage.all import * >>> # needs sage.rings.number_field >>> K = CyclotomicField(Integer(3), names=('z',)); (z,) = K._first_ngens(1) >>> R = K['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(2) + z*y >>> f.change_ring(K.embeddings(CC)[Integer(1)]) x^2 + (-0.500000000000000 - 0.866025403784438*I)*y
# needs sage.rings.number_field K.<z> = CyclotomicField(3) R.<x,y> = K[] f = x^2 + z*y f.change_ring(K.embeddings(CC)[1])
sage: # needs sage.rings.number_field sage: K.<w> = CyclotomicField(5) sage: R.<x,y> = K[] sage: f = x^2 + w*y sage: f.change_ring(K.embeddings(QQbar)[1]) x^2 + (-0.8090169943749474? + 0.5877852522924731?*I)*y
>>> from sage.all import * >>> # needs sage.rings.number_field >>> K = CyclotomicField(Integer(5), names=('w',)); (w,) = K._first_ngens(1) >>> R = K['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(2) + w*y >>> f.change_ring(K.embeddings(QQbar)[Integer(1)]) x^2 + (-0.8090169943749474? + 0.5877852522924731?*I)*y
# needs sage.rings.number_field K.<w> = CyclotomicField(5) R.<x,y> = K[] f = x^2 + w*y f.change_ring(K.embeddings(QQbar)[1])
- coefficients()[source]¶
Return the nonzero coefficients of this polynomial in a list.
The returned list is decreasingly ordered by the term ordering of
self.parent()
, i.e. the list of coefficients matches the list of monomials returned bysage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular.monomials()
.EXAMPLES:
sage: R.<x,y,z> = PolynomialRing(QQ, 3, 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, 3, order='lex') sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [6, 23, 1]
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(23)*x**Integer(6)*y**Integer(7) + x**Integer(3)*y+Integer(6)*x**Integer(7)*z >>> f.coefficients() [23, 6, 1] >>> R = PolynomialRing(QQ, Integer(3), order='lex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(23)*x**Integer(6)*y**Integer(7) + x**Integer(3)*y+Integer(6)*x**Integer(7)*z >>> f.coefficients() [6, 23, 1]
R.<x,y,z> = PolynomialRing(QQ, 3, order='degrevlex') f = 23*x^6*y^7 + x^3*y+6*x^7*z f.coefficients() R.<x,y,z> = PolynomialRing(QQ, 3, order='lex') f = 23*x^6*y^7 + x^3*y+6*x^7*z f.coefficients()
Test the same stuff with base ring \(\ZZ\) – different implementation:
sage: R.<x,y,z> = PolynomialRing(ZZ, 3, 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(ZZ, 3, order='lex') sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [6, 23, 1]
>>> from sage.all import * >>> R = PolynomialRing(ZZ, Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(23)*x**Integer(6)*y**Integer(7) + x**Integer(3)*y+Integer(6)*x**Integer(7)*z >>> f.coefficients() [23, 6, 1] >>> R = PolynomialRing(ZZ, Integer(3), order='lex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(23)*x**Integer(6)*y**Integer(7) + x**Integer(3)*y+Integer(6)*x**Integer(7)*z >>> f.coefficients() [6, 23, 1]
R.<x,y,z> = PolynomialRing(ZZ, 3, order='degrevlex') f = 23*x^6*y^7 + x^3*y+6*x^7*z f.coefficients() R.<x,y,z> = PolynomialRing(ZZ, 3, order='lex') f = 23*x^6*y^7 + x^3*y+6*x^7*z f.coefficients()
AUTHOR:
Didier Deshommes
- content()[source]¶
Return the content of this polynomial. Here, we define content as the gcd of the coefficients in the base ring.
See also
EXAMPLES:
sage: R.<x,y> = ZZ[] sage: f = 4*x+6*y sage: f.content() 2 sage: f.content().parent() Integer Ring
>>> from sage.all import * >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(4)*x+Integer(6)*y >>> f.content() 2 >>> f.content().parent() Integer Ring
R.<x,y> = ZZ[] f = 4*x+6*y f.content() f.content().parent()
- content_ideal()[source]¶
Return the content ideal of this polynomial, defined as the ideal generated by its coefficients.
See also
EXAMPLES:
sage: R.<x,y> = ZZ[] sage: f = 2*x*y + 6*x - 4*y + 2 sage: f.content_ideal() Principal ideal (2) of Integer Ring sage: S.<z,t> = R[] sage: g = x*z + y*t sage: g.content_ideal() Ideal (x, y) of Multivariate Polynomial Ring in x, y over Integer Ring
>>> from sage.all import * >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(2)*x*y + Integer(6)*x - Integer(4)*y + Integer(2) >>> f.content_ideal() Principal ideal (2) of Integer Ring >>> S = R['z, t']; (z, t,) = S._first_ngens(2) >>> g = x*z + y*t >>> g.content_ideal() Ideal (x, y) of Multivariate Polynomial Ring in x, y over Integer Ring
R.<x,y> = ZZ[] f = 2*x*y + 6*x - 4*y + 2 f.content_ideal() S.<z,t> = R[] g = x*z + y*t g.content_ideal()
- denominator()[source]¶
Return a denominator of
self
.First, the lcm of the denominators of the entries of
self
is computed and returned. If this computation fails, the unit of the parent ofself
is returned.Note that some subclasses may implement its own denominator function.
Warning
This is not the denominator of the rational function defined by
self
, which would always be 1 sinceself
is a polynomial.EXAMPLES:
First we compute the denominator of a polynomial with integer coefficients, which is of course 1.
sage: R.<x,y> = ZZ[] sage: f = x^3 + 17*y + x + y sage: f.denominator() 1
>>> from sage.all import * >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(3) + Integer(17)*y + x + y >>> f.denominator() 1
R.<x,y> = ZZ[] f = x^3 + 17*y + x + y f.denominator()
Next we compute the denominator of a polynomial over a number field.
sage: # needs sage.rings.number_field sage.symbolic sage: R.<x,y> = NumberField(symbolic_expression(x^2+3),'a')['x,y'] sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f 1/17*x^19 - 2/3*x + 1/6*y + 1/3 sage: f.denominator() 102
>>> from sage.all import * >>> # needs sage.rings.number_field sage.symbolic >>> R = NumberField(symbolic_expression(x**Integer(2)+Integer(3)),'a')['x,y']; (x, y,) = R._first_ngens(2) >>> f = (Integer(1)/Integer(17))*x**Integer(19) + (Integer(1)/Integer(6))*y - (Integer(2)/Integer(3))*x + Integer(1)/Integer(3); f 1/17*x^19 - 2/3*x + 1/6*y + 1/3 >>> f.denominator() 102
# needs sage.rings.number_field sage.symbolic R.<x,y> = NumberField(symbolic_expression(x^2+3),'a')['x,y'] f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f f.denominator()
Finally, we try to compute the denominator of a polynomial with coefficients in the real numbers, which is a ring whose elements do not have a denominator method.
sage: # needs sage.rings.real_mpfr sage: R.<a,b,c> = RR[] sage: f = a + b + RR('0.3'); f a + b + 0.300000000000000 sage: f.denominator() 1.00000000000000
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> R = RR['a, b, c']; (a, b, c,) = R._first_ngens(3) >>> f = a + b + RR('0.3'); f a + b + 0.300000000000000 >>> f.denominator() 1.00000000000000
# needs sage.rings.real_mpfr R.<a,b,c> = RR[] f = a + b + RR('0.3'); f f.denominator()
Check that the denominator is an element over the base whenever the base has no denominator function. This closes Issue #9063:
sage: R.<a,b,c> = GF(5)[] sage: x = R(0) sage: x.denominator() 1 sage: type(x.denominator()) <class 'sage.rings.finite_rings.integer_mod.IntegerMod_int'> sage: type(a.denominator()) <class 'sage.rings.finite_rings.integer_mod.IntegerMod_int'> sage: from sage.rings.polynomial.multi_polynomial_element import MPolynomial sage: isinstance(a / b, MPolynomial) False sage: isinstance(a.numerator() / a.denominator(), MPolynomial) True
>>> from sage.all import * >>> R = GF(Integer(5))['a, b, c']; (a, b, c,) = R._first_ngens(3) >>> x = R(Integer(0)) >>> x.denominator() 1 >>> type(x.denominator()) <class 'sage.rings.finite_rings.integer_mod.IntegerMod_int'> >>> type(a.denominator()) <class 'sage.rings.finite_rings.integer_mod.IntegerMod_int'> >>> from sage.rings.polynomial.multi_polynomial_element import MPolynomial >>> isinstance(a / b, MPolynomial) False >>> isinstance(a.numerator() / a.denominator(), MPolynomial) True
R.<a,b,c> = GF(5)[] x = R(0) x.denominator() type(x.denominator()) type(a.denominator()) from sage.rings.polynomial.multi_polynomial_element import MPolynomial isinstance(a / b, MPolynomial) isinstance(a.numerator() / a.denominator(), MPolynomial)
- derivative(*args)[source]¶
The formal derivative of this polynomial, with respect to variables supplied in
args
.Multiple variables and iteration counts may be supplied; see documentation for the global function
derivative()
for more details.See also
_derivative()
EXAMPLES:
Polynomials implemented via Singular:
sage: # needs sage.libs.singular sage: R.<x, y> = PolynomialRing(FiniteField(5)) sage: f = x^3*y^5 + x^7*y sage: type(f) <class 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'> sage: f.derivative(x) 2*x^6*y - 2*x^2*y^5 sage: f.derivative(y) x^7
>>> from sage.all import * >>> # needs sage.libs.singular >>> R = PolynomialRing(FiniteField(Integer(5)), names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = x**Integer(3)*y**Integer(5) + x**Integer(7)*y >>> type(f) <class 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'> >>> f.derivative(x) 2*x^6*y - 2*x^2*y^5 >>> f.derivative(y) x^7
# needs sage.libs.singular R.<x, y> = PolynomialRing(FiniteField(5)) f = x^3*y^5 + x^7*y type(f) f.derivative(x) f.derivative(y)
Generic multivariate polynomials:
sage: R.<t> = PowerSeriesRing(QQ) sage: S.<x, y> = PolynomialRing(R) sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 sage: type(f) <class 'sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict'> sage: f.derivative(x) # with respect to x (2*t^2 + O(t^3))*x*y^3 + (111*t^4 + O(t^5))*x^2 sage: f.derivative(y) # with respect to y (3*t^2 + O(t^3))*x^2*y^2 sage: f.derivative(t) # with respect to t (recurses into base ring) (2*t + O(t^2))*x^2*y^3 + (148*t^3 + O(t^4))*x^3 sage: f.derivative(x, y) # with respect to x and then y (6*t^2 + O(t^3))*x*y^2 sage: f.derivative(y, 3) # with respect to y three times (6*t^2 + O(t^3))*x^2 sage: f.derivative() # can't figure out the variable Traceback (most recent call last): ... ValueError: must specify which variable to differentiate with respect to
>>> from sage.all import * >>> R = PowerSeriesRing(QQ, names=('t',)); (t,) = R._first_ngens(1) >>> S = PolynomialRing(R, names=('x', 'y',)); (x, y,) = S._first_ngens(2) >>> f = (t**Integer(2) + O(t**Integer(3)))*x**Integer(2)*y**Integer(3) + (Integer(37)*t**Integer(4) + O(t**Integer(5)))*x**Integer(3) >>> type(f) <class 'sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict'> >>> f.derivative(x) # with respect to x (2*t^2 + O(t^3))*x*y^3 + (111*t^4 + O(t^5))*x^2 >>> f.derivative(y) # with respect to y (3*t^2 + O(t^3))*x^2*y^2 >>> f.derivative(t) # with respect to t (recurses into base ring) (2*t + O(t^2))*x^2*y^3 + (148*t^3 + O(t^4))*x^3 >>> f.derivative(x, y) # with respect to x and then y (6*t^2 + O(t^3))*x*y^2 >>> f.derivative(y, Integer(3)) # with respect to y three times (6*t^2 + O(t^3))*x^2 >>> f.derivative() # can't figure out the variable Traceback (most recent call last): ... ValueError: must specify which variable to differentiate with respect to
R.<t> = PowerSeriesRing(QQ) S.<x, y> = PolynomialRing(R) f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 type(f) f.derivative(x) # with respect to x f.derivative(y) # with respect to y f.derivative(t) # with respect to t (recurses into base ring) f.derivative(x, y) # with respect to x and then y f.derivative(y, 3) # with respect to y three times f.derivative() # can't figure out the variable
Polynomials over the symbolic ring (just for fun….):
sage: # needs sage.symbolic sage: x = var("x") sage: S.<u, v> = PolynomialRing(SR) sage: f = u*v*x sage: f.derivative(x) == u*v True sage: f.derivative(u) == v*x True
>>> from sage.all import * >>> # needs sage.symbolic >>> x = var("x") >>> S = PolynomialRing(SR, names=('u', 'v',)); (u, v,) = S._first_ngens(2) >>> f = u*v*x >>> f.derivative(x) == u*v True >>> f.derivative(u) == v*x True
# needs sage.symbolic x = var("x") S.<u, v> = PolynomialRing(SR) f = u*v*x f.derivative(x) == u*v f.derivative(u) == v*x
- discriminant(variable)[source]¶
Return the discriminant of
self
with respect to the given variable.INPUT:
variable
– the variable with respect to which we compute the discriminant
OUTPUT: an element of the base ring of the polynomial ring
EXAMPLES:
sage: R.<x,y,z> = QQ[] sage: f = 4*x*y^2 + 1/4*x*y*z + 3/2*x*z^2 - 1/2*z^2 sage: f.discriminant(x) # needs sage.libs.singular 1 sage: f.discriminant(y) # needs sage.libs.singular -383/16*x^2*z^2 + 8*x*z^2 sage: f.discriminant(z) # needs sage.libs.singular -383/16*x^2*y^2 + 8*x*y^2
>>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> f = Integer(4)*x*y**Integer(2) + Integer(1)/Integer(4)*x*y*z + Integer(3)/Integer(2)*x*z**Integer(2) - Integer(1)/Integer(2)*z**Integer(2) >>> f.discriminant(x) # needs sage.libs.singular 1 >>> f.discriminant(y) # needs sage.libs.singular -383/16*x^2*z^2 + 8*x*z^2 >>> f.discriminant(z) # needs sage.libs.singular -383/16*x^2*y^2 + 8*x*y^2
R.<x,y,z> = QQ[] f = 4*x*y^2 + 1/4*x*y*z + 3/2*x*z^2 - 1/2*z^2 f.discriminant(x) # needs sage.libs.singular f.discriminant(y) # needs sage.libs.singular f.discriminant(z) # needs sage.libs.singular
Note that, unlike the univariate case, the result lives in the same ring as the polynomial:
sage: R.<x,y> = QQ[] sage: f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 sage: f.discriminant(y) # needs sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 sage: f.polynomial(y).discriminant() # needs sage.libs.pari sage.modules x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 sage: f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # needs sage.libs.singular sage.modules False
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(5)*y + Integer(3)*x**Integer(2)*y**Integer(2) - Integer(2)*x + y - Integer(1) >>> f.discriminant(y) # needs sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 >>> f.polynomial(y).discriminant() # needs sage.libs.pari sage.modules x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 >>> f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # needs sage.libs.singular sage.modules False
R.<x,y> = QQ[] f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 f.discriminant(y) # needs sage.libs.singular f.polynomial(y).discriminant() # needs sage.libs.pari sage.modules f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # needs sage.libs.singular sage.modules
AUTHOR: Miguel Marco
- gcd(other)[source]¶
Return a greatest common divisor of this polynomial and
other
.INPUT:
other
– a polynomial with the same parent as this polynomial
EXAMPLES:
sage: Q.<z> = Frac(QQ['z']) sage: R.<x,y> = Q[] sage: r = x*y - (2*z-1)/(z^2+z+1) * x + y/z sage: p = r * (x + z*y - 1/z^2) sage: q = r * (x*y*z + 1) sage: gcd(p, q) (z^3 + z^2 + z)*x*y + (-2*z^2 + z)*x + (z^2 + z + 1)*y
>>> from sage.all import * >>> Q = Frac(QQ['z'], names=('z',)); (z,) = Q._first_ngens(1) >>> R = Q['x, y']; (x, y,) = R._first_ngens(2) >>> r = x*y - (Integer(2)*z-Integer(1))/(z**Integer(2)+z+Integer(1)) * x + y/z >>> p = r * (x + z*y - Integer(1)/z**Integer(2)) >>> q = r * (x*y*z + Integer(1)) >>> gcd(p, q) (z^3 + z^2 + z)*x*y + (-2*z^2 + z)*x + (z^2 + z + 1)*y
Q.<z> = Frac(QQ['z']) R.<x,y> = Q[] r = x*y - (2*z-1)/(z^2+z+1) * x + y/z p = r * (x + z*y - 1/z^2) q = r * (x*y*z + 1) gcd(p, q)
Polynomials over polynomial rings are converted to a simpler polynomial ring with all variables to compute the gcd:
sage: A.<z,t> = ZZ[] sage: B.<x,y> = A[] sage: r = x*y*z*t + 1 sage: p = r * (x - y + z - t + 1) sage: q = r * (x*z - y*t) sage: gcd(p, q) # needs sage.libs.singular z*t*x*y + 1 sage: _.parent() Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in z, t over Integer Ring
>>> from sage.all import * >>> A = ZZ['z, t']; (z, t,) = A._first_ngens(2) >>> B = A['x, y']; (x, y,) = B._first_ngens(2) >>> r = x*y*z*t + Integer(1) >>> p = r * (x - y + z - t + Integer(1)) >>> q = r * (x*z - y*t) >>> gcd(p, q) # needs sage.libs.singular z*t*x*y + 1 >>> _.parent() Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in z, t over Integer Ring
A.<z,t> = ZZ[] B.<x,y> = A[] r = x*y*z*t + 1 p = r * (x - y + z - t + 1) q = r * (x*z - y*t) gcd(p, q) # needs sage.libs.singular _.parent()
Some multivariate polynomial rings have no gcd implementation:
sage: R.<x,y> = GaussianIntegers()[] # needs sage.rings.number_field sage: x.gcd(x) Traceback (most recent call last): ... NotImplementedError: GCD is not implemented for multivariate polynomials over Gaussian Integers generated by I in Number Field in I with defining polynomial x^2 + 1 with I = 1*I
>>> from sage.all import * >>> R = GaussianIntegers()['x, y']; (x, y,) = R._first_ngens(2)# needs sage.rings.number_field >>> x.gcd(x) Traceback (most recent call last): ... NotImplementedError: GCD is not implemented for multivariate polynomials over Gaussian Integers generated by I in Number Field in I with defining polynomial x^2 + 1 with I = 1*I
R.<x,y> = GaussianIntegers()[] # needs sage.rings.number_field x.gcd(x)
- gradient()[source]¶
Return a list of partial derivatives of this polynomial, ordered by the variables of
self.parent()
.EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(ZZ, 3) sage: f = x*y + 1 sage: f.gradient() [y, x, 0]
>>> from sage.all import * >>> P = PolynomialRing(ZZ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3) >>> f = x*y + Integer(1) >>> f.gradient() [y, x, 0]
P.<x,y,z> = PolynomialRing(ZZ, 3) f = x*y + 1 f.gradient()
- homogeneous_components()[source]¶
Return the homogeneous components of this polynomial.
OUTPUT: a dictionary mapping degrees to homogeneous polynomials
EXAMPLES:
sage: R.<x,y> = QQ[] sage: (x^3 + 2*x*y^3 + 4*y^3 + y).homogeneous_components() {1: y, 3: x^3 + 4*y^3, 4: 2*x*y^3} sage: R.zero().homogeneous_components() {}
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> (x**Integer(3) + Integer(2)*x*y**Integer(3) + Integer(4)*y**Integer(3) + y).homogeneous_components() {1: y, 3: x^3 + 4*y^3, 4: 2*x*y^3} >>> R.zero().homogeneous_components() {}
R.<x,y> = QQ[] (x^3 + 2*x*y^3 + 4*y^3 + y).homogeneous_components() R.zero().homogeneous_components()
In case of weighted term orders, the polynomials are homogeneous with respect to the weights:
sage: S.<a,b,c> = PolynomialRing(ZZ, order=TermOrder('wdegrevlex', (1,2,3))) sage: (a^6 + b^3 + b*c + a^2*c + c + a + 1).homogeneous_components() {0: 1, 1: a, 3: c, 5: a^2*c + b*c, 6: a^6 + b^3}
>>> from sage.all import * >>> S = PolynomialRing(ZZ, order=TermOrder('wdegrevlex', (Integer(1),Integer(2),Integer(3))), names=('a', 'b', 'c',)); (a, b, c,) = S._first_ngens(3) >>> (a**Integer(6) + b**Integer(3) + b*c + a**Integer(2)*c + c + a + Integer(1)).homogeneous_components() {0: 1, 1: a, 3: c, 5: a^2*c + b*c, 6: a^6 + b^3}
S.<a,b,c> = PolynomialRing(ZZ, order=TermOrder('wdegrevlex', (1,2,3))) (a^6 + b^3 + b*c + a^2*c + c + a + 1).homogeneous_components()
- homogenize(var='h')[source]¶
Return the homogenization of this polynomial.
The polynomial itself is returned if it is homogeneous already. Otherwise, the monomials are multiplied with the smallest powers of
var
such that they all have the same total degree.INPUT:
var
– a variable in the polynomial ring (as a string, an element of the ring, or a zero-based index in the list of variables) or a name for a new variable (default:'h'
)
OUTPUT:
If
var
specifies a variable in the polynomial ring, then a homogeneous element in that ring is returned. Otherwise, a homogeneous element is returned in a polynomial ring with an extra last variablevar
.EXAMPLES:
sage: R.<x,y> = QQ[] sage: f = x^2 + y + 1 + 5*x*y^10 sage: f.homogenize() 5*x*y^10 + x^2*h^9 + y*h^10 + h^11
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(2) + y + Integer(1) + Integer(5)*x*y**Integer(10) >>> f.homogenize() 5*x*y^10 + x^2*h^9 + y*h^10 + h^11
R.<x,y> = QQ[] f = x^2 + y + 1 + 5*x*y^10 f.homogenize()
The parameter
var
can be used to specify the name of the variable:sage: g = f.homogenize('z'); g 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
>>> from sage.all import * >>> g = f.homogenize('z'); g 5*x*y^10 + x^2*z^9 + y*z^10 + z^11 >>> g.parent() Multivariate Polynomial Ring in x, y, z over Rational Field
g = f.homogenize('z'); g g.parent()
However, if the polynomial is homogeneous already, then that parameter is ignored and no extra variable is added to the polynomial ring:
sage: f = x^2 + y^2 sage: g = f.homogenize('z'); g x^2 + y^2 sage: g.parent() Multivariate Polynomial Ring in x, y over Rational Field
>>> from sage.all import * >>> f = x**Integer(2) + y**Integer(2) >>> g = f.homogenize('z'); g x^2 + y^2 >>> g.parent() Multivariate Polynomial Ring in x, y over Rational Field
f = x^2 + y^2 g = f.homogenize('z'); g g.parent()
If you want the ring of the result to be independent of whether the polynomial is homogenized, you can use
var
to use an existing variable to homogenize:sage: R.<x,y,z> = QQ[] sage: f = x^2 + y^2 sage: g = f.homogenize(z); g x^2 + y^2 sage: g.parent() Multivariate Polynomial Ring in x, y, z over Rational Field sage: f = x^2 - y sage: g = f.homogenize(z); g x^2 - y*z sage: g.parent() Multivariate Polynomial Ring in x, y, z over Rational Field
>>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> f = x**Integer(2) + y**Integer(2) >>> g = f.homogenize(z); g x^2 + y^2 >>> g.parent() Multivariate Polynomial Ring in x, y, z over Rational Field >>> f = x**Integer(2) - y >>> g = f.homogenize(z); g x^2 - y*z >>> g.parent() Multivariate Polynomial Ring in x, y, z over Rational Field
R.<x,y,z> = QQ[] f = x^2 + y^2 g = f.homogenize(z); g g.parent() f = x^2 - y g = f.homogenize(z); g g.parent()
The parameter
var
can also be given as a zero-based index in the list of variables:sage: g = f.homogenize(2); g x^2 - y*z
>>> from sage.all import * >>> g = f.homogenize(Integer(2)); g x^2 - y*z
g = f.homogenize(2); g
If the variable specified by
var
is not present in the polynomial, then setting it to 1 yields the original polynomial:sage: g(x,y,1) x^2 - y
>>> from sage.all import * >>> g(x,y,Integer(1)) x^2 - y
g(x,y,1)
If it is present already, this might not be the case:
sage: g = f.homogenize(x); g x^2 - x*y sage: g(1,y,z) -y + 1
>>> from sage.all import * >>> g = f.homogenize(x); g x^2 - x*y >>> g(Integer(1),y,z) -y + 1
g = f.homogenize(x); g g(1,y,z)
In particular, this can be surprising in positive characteristic:
sage: R.<x,y> = GF(2)[] sage: f = x + 1 sage: f.homogenize(x) 0
>>> from sage.all import * >>> R = GF(Integer(2))['x, y']; (x, y,) = R._first_ngens(2) >>> f = x + Integer(1) >>> f.homogenize(x) 0
R.<x,y> = GF(2)[] f = x + 1 f.homogenize(x)
- inverse_mod(I)[source]¶
Return an inverse of
self
modulo the polynomial ideal \(I\), namely a multivariate polynomial \(f\) such thatself * f - 1
belongs to \(I\).INPUT:
I
– an ideal of the polynomial ring in whichself
lives
OUTPUT: a multivariate polynomial representing the inverse of
f
modulo \(I\)EXAMPLES:
sage: R.<x1,x2> = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g # needs sage.libs.singular 1/16*x1 + 3/16 sage: (f*g).reduce(I) # needs sage.libs.singular 1
>>> from sage.all import * >>> R = QQ['x1, x2']; (x1, x2,) = R._first_ngens(2) >>> I = R.ideal(x2**Integer(2) + x1 - Integer(2), x1**Integer(2) - Integer(1)) >>> f = x1 + Integer(3)*x2**Integer(2); g = f.inverse_mod(I); g # needs sage.libs.singular 1/16*x1 + 3/16 >>> (f*g).reduce(I) # needs sage.libs.singular 1
R.<x1,x2> = QQ[] I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) f = x1 + 3*x2^2; g = f.inverse_mod(I); g # needs sage.libs.singular (f*g).reduce(I) # needs sage.libs.singular
Test a non-invertible element:
sage: R.<x1,x2> = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) sage: f = x1 + x2 sage: f.inverse_mod(I) # needs sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible
>>> from sage.all import * >>> R = QQ['x1, x2']; (x1, x2,) = R._first_ngens(2) >>> I = R.ideal(x2**Integer(2) + x1 - Integer(2), x1**Integer(2) - Integer(1)) >>> f = x1 + x2 >>> f.inverse_mod(I) # needs sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible
R.<x1,x2> = QQ[] I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) f = x1 + x2 f.inverse_mod(I) # needs sage.libs.singular
- is_gen()[source]¶
Return
True
if this polynomial is a generator of its parent.EXAMPLES:
sage: R.<x,y> = ZZ[] sage: x.is_gen() True sage: (x + y - y).is_gen() True sage: (x*y).is_gen() False sage: R.<x,y> = QQ[] sage: x.is_gen() True sage: (x + y - y).is_gen() True sage: (x*y).is_gen() False
>>> from sage.all import * >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> x.is_gen() True >>> (x + y - y).is_gen() True >>> (x*y).is_gen() False >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> x.is_gen() True >>> (x + y - y).is_gen() True >>> (x*y).is_gen() False
R.<x,y> = ZZ[] x.is_gen() (x + y - y).is_gen() (x*y).is_gen() R.<x,y> = QQ[] x.is_gen() (x + y - y).is_gen() (x*y).is_gen()
- is_generator(*args, **kwds)[source]¶
Deprecated: Use
is_gen()
instead. See Issue #38942 for details.
- is_homogeneous()[source]¶
Return
True
ifself
is a homogeneous polynomial.Note
This is a generic implementation which is likely overridden by subclasses.
- is_lorentzian(explain=False)[source]¶
Return whether this is a Lorentzian polynomial.
INPUT:
explain
– boolean (default:False
); ifTrue
return a tuple whose first element is the boolean result of the test, and the second element is a string describing the reason the test failed, orNone
if the test succeeded.
Lorentzian polynomials are a class of polynomials connected with the area of discrete convex analysis. A polynomial \(f\) with positive real coefficients is Lorentzian if:
\(f\) is homogeneous;
the support of \(f\) is \(M\)-convex
\(f\) has degree less than \(2\), or if its degree is at least two, the collection of sequential partial derivatives of \(f\) which are quadratic forms have Gram matrices with at most one positive eigenvalue.
Note in particular that the zero polynomial is Lorentzian. Examples of Lorentzian polynomials include homogeneous stable polynomials, volume polynomials of convex bodies and projective varieties, and Schur polynomials after renormalizing the coefficient of each monomial \(x^\alpha\) by \(1/\alpha!\).
EXAMPLES:
Renormalized Schur polynomials are Lorentzian, but not in general if the renormalization is skipped:
sage: P.<x,y> = QQ[] sage: p = (x^2 / 2) + x*y + (y^2 / 2) sage: p.is_lorentzian() True sage: p = x^2 + x*y + y^2 sage: p.is_lorentzian() False
>>> from sage.all import * >>> P = QQ['x, y']; (x, y,) = P._first_ngens(2) >>> p = (x**Integer(2) / Integer(2)) + x*y + (y**Integer(2) / Integer(2)) >>> p.is_lorentzian() True >>> p = x**Integer(2) + x*y + y**Integer(2) >>> p.is_lorentzian() False
P.<x,y> = QQ[] p = (x^2 / 2) + x*y + (y^2 / 2) p.is_lorentzian() p = x^2 + x*y + y^2 p.is_lorentzian()
Homogeneous linear forms and constant polynomials with positive coefficients are Lorentzian, as well as the zero polynomial:
sage: p = x + 2*y sage: p.is_lorentzian() True sage: p = P(5) sage: p.is_lorentzian() True sage: P.zero().is_lorentzian() True
>>> from sage.all import * >>> p = x + Integer(2)*y >>> p.is_lorentzian() True >>> p = P(Integer(5)) >>> p.is_lorentzian() True >>> P.zero().is_lorentzian() True
p = x + 2*y p.is_lorentzian() p = P(5) p.is_lorentzian() P.zero().is_lorentzian()
Inhomogeneous polynomials and polynomials with negative coefficients are not Lorentzian:
sage: p = x^2 + 2*x + y^2 sage: p.is_lorentzian() False sage: p = 2*x^2 - y^2 sage: p.is_lorentzian() False
>>> from sage.all import * >>> p = x**Integer(2) + Integer(2)*x + y**Integer(2) >>> p.is_lorentzian() False >>> p = Integer(2)*x**Integer(2) - y**Integer(2) >>> p.is_lorentzian() False
p = x^2 + 2*x + y^2 p.is_lorentzian() p = 2*x^2 - y^2 p.is_lorentzian()
It is an error to check if a polynomial is Lorentzian if its base ring is not a subring of the real numbers, as the notion is not defined in this case:
sage: # needs sage.rings.real_mpfr sage: Q.<z,w> = CC[] sage: q = z^2 + w^2 sage: q.is_lorentzian() Traceback (most recent call last): ... NotImplementedError: is_lorentzian only implemented for real polynomials
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> Q = CC['z, w']; (z, w,) = Q._first_ngens(2) >>> q = z**Integer(2) + w**Integer(2) >>> q.is_lorentzian() Traceback (most recent call last): ... NotImplementedError: is_lorentzian only implemented for real polynomials
# needs sage.rings.real_mpfr Q.<z,w> = CC[] q = z^2 + w^2 q.is_lorentzian()
The method can give a reason for a polynomial failing to be Lorentzian:
sage: p = x^2 + 2*x + y^2 sage: p.is_lorentzian(explain=True) (False, 'inhomogeneous')
>>> from sage.all import * >>> p = x**Integer(2) + Integer(2)*x + y**Integer(2) >>> p.is_lorentzian(explain=True) (False, 'inhomogeneous')
p = x^2 + 2*x + y^2 p.is_lorentzian(explain=True)
REFERENCES:
For full definitions and related discussion, see [BrHu2019] and [HMMS2019]. The second reference gives the characterization of Lorentzian polynomials applied in this implementation explicitly.
- is_nilpotent()[source]¶
Return
True
ifself
is nilpotent, i.e., some power ofself
is 0.EXAMPLES:
sage: R.<x,y> = QQbar[] # needs sage.rings.number_field sage: (x + y).is_nilpotent() # needs sage.rings.number_field False sage: R(0).is_nilpotent() # needs sage.rings.number_field True sage: _.<x,y> = Zmod(4)[] sage: (2*x).is_nilpotent() True sage: (2 + y*x).is_nilpotent() False sage: _.<x,y> = Zmod(36)[] sage: (4 + 6*x).is_nilpotent() False sage: (6*x + 12*y + 18*x*y + 24*(x^2+y^2)).is_nilpotent() True
>>> from sage.all import * >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2)# needs sage.rings.number_field >>> (x + y).is_nilpotent() # needs sage.rings.number_field False >>> R(Integer(0)).is_nilpotent() # needs sage.rings.number_field True >>> _ = Zmod(Integer(4))['x, y']; (x, y,) = _._first_ngens(2) >>> (Integer(2)*x).is_nilpotent() True >>> (Integer(2) + y*x).is_nilpotent() False >>> _ = Zmod(Integer(36))['x, y']; (x, y,) = _._first_ngens(2) >>> (Integer(4) + Integer(6)*x).is_nilpotent() False >>> (Integer(6)*x + Integer(12)*y + Integer(18)*x*y + Integer(24)*(x**Integer(2)+y**Integer(2))).is_nilpotent() True
R.<x,y> = QQbar[] # needs sage.rings.number_field (x + y).is_nilpotent() # needs sage.rings.number_field R(0).is_nilpotent() # needs sage.rings.number_field _.<x,y> = Zmod(4)[] (2*x).is_nilpotent() (2 + y*x).is_nilpotent() _.<x,y> = Zmod(36)[] (4 + 6*x).is_nilpotent() (6*x + 12*y + 18*x*y + 24*(x^2+y^2)).is_nilpotent()
- is_square(root=False)[source]¶
Test whether this polynomial is a square.
INPUT:
root
– if set toTrue
, return a pair(True, root)
whereroot
is a square root or(False, None)
if it is not a square.
EXAMPLES:
sage: R.<a,b> = QQ[] sage: a.is_square() False sage: ((1+a*b^2)^2).is_square() True sage: ((1+a*b^2)^2).is_square(root=True) (True, a*b^2 + 1)
>>> from sage.all import * >>> R = QQ['a, b']; (a, b,) = R._first_ngens(2) >>> a.is_square() False >>> ((Integer(1)+a*b**Integer(2))**Integer(2)).is_square() True >>> ((Integer(1)+a*b**Integer(2))**Integer(2)).is_square(root=True) (True, a*b^2 + 1)
R.<a,b> = QQ[] a.is_square() ((1+a*b^2)^2).is_square() ((1+a*b^2)^2).is_square(root=True)
- is_symmetric(group=None)[source]¶
Return whether this polynomial is symmetric.
INPUT:
group
– (default: symmetric group) if set, test whether the polynomial is invariant with respect to the given permutation group
EXAMPLES:
sage: # needs sage.groups sage: R.<x,y,z> = QQ[] sage: p = (x+y+z)**2 - 3 * (x+y)*(x+z)*(y+z) sage: p.is_symmetric() True sage: (x + y - z).is_symmetric() False sage: R.one().is_symmetric() True sage: p = (x-y)*(y-z)*(z-x) sage: p.is_symmetric() False sage: p.is_symmetric(AlternatingGroup(3)) True sage: R.<x,y> = QQ[] sage: ((x + y)**2).is_symmetric() # needs sage.groups True sage: R.one().is_symmetric() # needs sage.groups True sage: (x + 2*y).is_symmetric() # needs sage.groups False
>>> from sage.all import * >>> # needs sage.groups >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> p = (x+y+z)**Integer(2) - Integer(3) * (x+y)*(x+z)*(y+z) >>> p.is_symmetric() True >>> (x + y - z).is_symmetric() False >>> R.one().is_symmetric() True >>> p = (x-y)*(y-z)*(z-x) >>> p.is_symmetric() False >>> p.is_symmetric(AlternatingGroup(Integer(3))) True >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> ((x + y)**Integer(2)).is_symmetric() # needs sage.groups True >>> R.one().is_symmetric() # needs sage.groups True >>> (x + Integer(2)*y).is_symmetric() # needs sage.groups False
# needs sage.groups R.<x,y,z> = QQ[] p = (x+y+z)**2 - 3 * (x+y)*(x+z)*(y+z) p.is_symmetric() (x + y - z).is_symmetric() R.one().is_symmetric() p = (x-y)*(y-z)*(z-x) p.is_symmetric() p.is_symmetric(AlternatingGroup(3)) R.<x,y> = QQ[] ((x + y)**2).is_symmetric() # needs sage.groups R.one().is_symmetric() # needs sage.groups (x + 2*y).is_symmetric() # needs sage.groups
An example with a GAP permutation group (here the quaternions):
sage: R = PolynomialRing(QQ, 'x', 8) sage: x = R.gens() sage: p = sum(prod(x[i] for i in e) ....: for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), ....: (3,4,5), (3,4,6), (3,5,6), (4,5,6)]) sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) # needs sage.groups True sage: p = sum(prod(x[i] for i in e) ....: for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), ....: (3,4,5), (3,4,6), (3,5,6)]) sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) # needs sage.groups False
>>> from sage.all import * >>> R = PolynomialRing(QQ, 'x', Integer(8)) >>> x = R.gens() >>> p = sum(prod(x[i] for i in e) ... for e in [(Integer(0),Integer(1),Integer(2)), (Integer(0),Integer(1),Integer(7)), (Integer(0),Integer(2),Integer(7)), (Integer(1),Integer(2),Integer(7)), ... (Integer(3),Integer(4),Integer(5)), (Integer(3),Integer(4),Integer(6)), (Integer(3),Integer(5),Integer(6)), (Integer(4),Integer(5),Integer(6))]) >>> p.is_symmetric(libgap.TransitiveGroup(Integer(8), Integer(5))) # needs sage.groups True >>> p = sum(prod(x[i] for i in e) ... for e in [(Integer(0),Integer(1),Integer(2)), (Integer(0),Integer(1),Integer(7)), (Integer(0),Integer(2),Integer(7)), (Integer(1),Integer(2),Integer(7)), ... (Integer(3),Integer(4),Integer(5)), (Integer(3),Integer(4),Integer(6)), (Integer(3),Integer(5),Integer(6))]) >>> p.is_symmetric(libgap.TransitiveGroup(Integer(8), Integer(5))) # needs sage.groups False
R = PolynomialRing(QQ, 'x', 8) x = R.gens() p = sum(prod(x[i] for i in e) for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), (3,4,5), (3,4,6), (3,5,6), (4,5,6)]) p.is_symmetric(libgap.TransitiveGroup(8, 5)) # needs sage.groups p = sum(prod(x[i] for i in e) for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), (3,4,5), (3,4,6), (3,5,6)]) p.is_symmetric(libgap.TransitiveGroup(8, 5)) # needs sage.groups
- is_unit()[source]¶
Return
True
ifself
is a unit, that is, has a multiplicative inverse.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] 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
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> (x + y).is_unit() False >>> R(Integer(0)).is_unit() False >>> R(-Integer(1)).is_unit() True >>> R(-Integer(1) + x).is_unit() False >>> R(Integer(2)).is_unit() True
# needs sage.rings.number_field R.<x,y> = QQbar[] (x + y).is_unit() R(0).is_unit() R(-1).is_unit() R(-1 + x).is_unit() R(2).is_unit()
Check that Issue #22454 is fixed:
sage: _.<x,y> = Zmod(4)[] sage: (1 + 2*x).is_unit() True sage: (x*y).is_unit() False sage: _.<x,y> = Zmod(36)[] sage: (7+ 6*x + 12*y - 18*x*y).is_unit() True
>>> from sage.all import * >>> _ = Zmod(Integer(4))['x, y']; (x, y,) = _._first_ngens(2) >>> (Integer(1) + Integer(2)*x).is_unit() True >>> (x*y).is_unit() False >>> _ = Zmod(Integer(36))['x, y']; (x, y,) = _._first_ngens(2) >>> (Integer(7)+ Integer(6)*x + Integer(12)*y - Integer(18)*x*y).is_unit() True
_.<x,y> = Zmod(4)[] (1 + 2*x).is_unit() (x*y).is_unit() _.<x,y> = Zmod(36)[] (7+ 6*x + 12*y - 18*x*y).is_unit()
- iterator_exp_coeff(as_ETuples=True)[source]¶
Iterate over
self
as pairs of ((E)Tuple, coefficient).INPUT:
as_ETuples
– boolean (default:True
); ifTrue
, iterate over pairs whose first element is anETuple
, otherwise as a tuples
EXAMPLES:
sage: R.<a,b,c> = QQ[] sage: f = a*c^3 + a^2*b + 2*b^4 sage: list(f.iterator_exp_coeff()) [((0, 4, 0), 2), ((1, 0, 3), 1), ((2, 1, 0), 1)] sage: list(f.iterator_exp_coeff(as_ETuples=False)) [((0, 4, 0), 2), ((1, 0, 3), 1), ((2, 1, 0), 1)] sage: R.<a,b,c> = PolynomialRing(QQ, 3, order='lex') sage: f = a*c^3 + a^2*b + 2*b^4 sage: list(f.iterator_exp_coeff()) [((2, 1, 0), 1), ((1, 0, 3), 1), ((0, 4, 0), 2)]
>>> from sage.all import * >>> R = QQ['a, b, c']; (a, b, c,) = R._first_ngens(3) >>> f = a*c**Integer(3) + a**Integer(2)*b + Integer(2)*b**Integer(4) >>> list(f.iterator_exp_coeff()) [((0, 4, 0), 2), ((1, 0, 3), 1), ((2, 1, 0), 1)] >>> list(f.iterator_exp_coeff(as_ETuples=False)) [((0, 4, 0), 2), ((1, 0, 3), 1), ((2, 1, 0), 1)] >>> R = PolynomialRing(QQ, Integer(3), order='lex', names=('a', 'b', 'c',)); (a, b, c,) = R._first_ngens(3) >>> f = a*c**Integer(3) + a**Integer(2)*b + Integer(2)*b**Integer(4) >>> list(f.iterator_exp_coeff()) [((2, 1, 0), 1), ((1, 0, 3), 1), ((0, 4, 0), 2)]
R.<a,b,c> = QQ[] f = a*c^3 + a^2*b + 2*b^4 list(f.iterator_exp_coeff()) list(f.iterator_exp_coeff(as_ETuples=False)) R.<a,b,c> = PolynomialRing(QQ, 3, order='lex') f = a*c^3 + a^2*b + 2*b^4 list(f.iterator_exp_coeff())
- jacobian_ideal()[source]¶
Return the Jacobian ideal of the polynomial
self
.EXAMPLES:
sage: R.<x,y,z> = QQ[] sage: f = x^3 + y^3 + z^3 sage: f.jacobian_ideal() Ideal (3*x^2, 3*y^2, 3*z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field
>>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> f = x**Integer(3) + y**Integer(3) + z**Integer(3) >>> f.jacobian_ideal() Ideal (3*x^2, 3*y^2, 3*z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field
R.<x,y,z> = QQ[] f = x^3 + y^3 + z^3 f.jacobian_ideal()
- lift(I)[source]¶
Given an ideal \(I = (f_1,\dots,f_r)\) that contains
self
, find \(s_1,\dots,s_r\) such thatself
\(= s_1 f_1 + ... + s_r f_r\).EXAMPLES:
sage: # needs sage.rings.real_mpfr sage: A.<x,y> = PolynomialRing(CC, 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); M # needs sage.libs.singular [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 # needs sage.libs.singular True
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> A = PolynomialRing(CC, Integer(2), order='degrevlex', names=('x', 'y',)); (x, y,) = A._first_ngens(2) >>> I = A.ideal([x**Integer(10) + x**Integer(9)*y**Integer(2), y**Integer(8) - x**Integer(2)*y**Integer(7) ]) >>> f = x*y**Integer(13) + y**Integer(12) >>> M = f.lift(I); M # needs sage.libs.singular [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] >>> sum(map(mul, zip(M, I.gens()))) == f # needs sage.libs.singular True
# needs sage.rings.real_mpfr A.<x,y> = PolynomialRing(CC, 2, order='degrevlex') I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7 ]) f = x*y^13 + y^12 M = f.lift(I); M # needs sage.libs.singular sum(map(mul, zip(M, I.gens()))) == f # needs sage.libs.singular
- macaulay_resultant(*args)[source]¶
This is an implementation of the Macaulay resultant. It computes the resultant of universal polynomials as well as polynomials with constant coefficients. This is a project done in sage days 55. It’s based on the implementation in Maple by Manfred Minimair, which in turn is based on the references [CLO], [Can], [Mac]. It calculates the Macaulay resultant for a list of Polynomials, up to sign!
AUTHORS:
Hao Chen, Solomon Vishkautsan (7-2014)
INPUT:
args
– list of \(n-1\) homogeneous polynomials in \(n\) variables; works whenargs[0]
is the list of polynomials, orargs
is itself the list of polynomials
OUTPUT: the Macaulay resultant
EXAMPLES:
The number of polynomials has to match the number of variables:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: y.macaulay_resultant(x + z) # needs sage.modules Traceback (most recent call last): ... TypeError: number of polynomials(= 2) must equal number of variables (= 3)
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> y.macaulay_resultant(x + z) # needs sage.modules Traceback (most recent call last): ... TypeError: number of polynomials(= 2) must equal number of variables (= 3)
R.<x,y,z> = PolynomialRing(QQ, 3) y.macaulay_resultant(x + z) # needs sage.modules
The polynomials need to be all homogeneous:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: y.macaulay_resultant([x + z, z + x^3]) # needs sage.modules Traceback (most recent call last): ... TypeError: resultant for non-homogeneous polynomials is not supported
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> y.macaulay_resultant([x + z, z + x**Integer(3)]) # needs sage.modules Traceback (most recent call last): ... TypeError: resultant for non-homogeneous polynomials is not supported
R.<x,y,z> = PolynomialRing(QQ, 3) y.macaulay_resultant([x + z, z + x^3]) # needs sage.modules
All polynomials must be in the same ring:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: S.<x,y> = PolynomialRing(QQ, 2) sage: y.macaulay_resultant(z + x, z) # needs sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> S = PolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = S._first_ngens(2) >>> y.macaulay_resultant(z + x, z) # needs sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring
R.<x,y,z> = PolynomialRing(QQ, 3) S.<x,y> = PolynomialRing(QQ, 2) y.macaulay_resultant(z + x, z) # needs sage.modules
The following example recreates Proposition 2.10 in Ch.3 of Using Algebraic Geometry:
sage: K.<x,y> = PolynomialRing(ZZ, 2) sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) sage: flist[0].macaulay_resultant(flist[1:]) # needs sage.modules u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - 2*u0*u2*u3*u5*u9 + u0^2*u5^2*u9 - u1*u2*u3^2*u10 + u0*u2*u3*u4*u10 + u0*u1*u3*u5*u10 - u0^2*u4*u5*u10 + u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11
>>> from sage.all import * >>> K = PolynomialRing(ZZ, Integer(2), names=('x', 'y',)); (x, y,) = K._first_ngens(2) >>> flist, R = K._macaulay_resultant_universal_polynomials([Integer(1),Integer(1),Integer(2)]) >>> flist[Integer(0)].macaulay_resultant(flist[Integer(1):]) # needs sage.modules u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - 2*u0*u2*u3*u5*u9 + u0^2*u5^2*u9 - u1*u2*u3^2*u10 + u0*u2*u3*u4*u10 + u0*u1*u3*u5*u10 - u0^2*u4*u5*u10 + u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11
K.<x,y> = PolynomialRing(ZZ, 2) flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) flist[0].macaulay_resultant(flist[1:]) # needs sage.modules
The following example degenerates into the determinant of a \(3\times 3\) matrix:
sage: K.<x,y> = PolynomialRing(ZZ, 2) sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,1]) sage: flist[0].macaulay_resultant(flist[1:]) # needs sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8
>>> from sage.all import * >>> K = PolynomialRing(ZZ, Integer(2), names=('x', 'y',)); (x, y,) = K._first_ngens(2) >>> flist, R = K._macaulay_resultant_universal_polynomials([Integer(1),Integer(1),Integer(1)]) >>> flist[Integer(0)].macaulay_resultant(flist[Integer(1):]) # needs sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8
K.<x,y> = PolynomialRing(ZZ, 2) flist, R = K._macaulay_resultant_universal_polynomials([1,1,1]) flist[0].macaulay_resultant(flist[1:]) # needs sage.modules
The following example is by Patrick Ingram (arXiv 1310.4114):
sage: U = PolynomialRing(ZZ,'y',2); y0,y1 = U.gens() sage: R = PolynomialRing(U,'x',3); x0,x1,x2 = R.gens() sage: f0 = y0*x2^2 - x0^2 + 2*x1*x2 sage: f1 = y1*x2^2 - x1^2 + 2*x0*x2 sage: f2 = x0*x1 - x2^2 sage: f0.macaulay_resultant(f1, f2) # needs sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27
>>> from sage.all import * >>> U = PolynomialRing(ZZ,'y',Integer(2)); y0,y1 = U.gens() >>> R = PolynomialRing(U,'x',Integer(3)); x0,x1,x2 = R.gens() >>> f0 = y0*x2**Integer(2) - x0**Integer(2) + Integer(2)*x1*x2 >>> f1 = y1*x2**Integer(2) - x1**Integer(2) + Integer(2)*x0*x2 >>> f2 = x0*x1 - x2**Integer(2) >>> f0.macaulay_resultant(f1, f2) # needs sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27
U = PolynomialRing(ZZ,'y',2); y0,y1 = U.gens() R = PolynomialRing(U,'x',3); x0,x1,x2 = R.gens() f0 = y0*x2^2 - x0^2 + 2*x1*x2 f1 = y1*x2^2 - x1^2 + 2*x0*x2 f2 = x0*x1 - x2^2 f0.macaulay_resultant(f1, f2) # needs sage.modules
a simple example with constant rational coefficients:
sage: R.<x,y,z,w> = PolynomialRing(QQ, 4) sage: w.macaulay_resultant([z, y, x]) # needs sage.modules 1
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(4), names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = R._first_ngens(4) >>> w.macaulay_resultant([z, y, x]) # needs sage.modules 1
R.<x,y,z,w> = PolynomialRing(QQ, 4) w.macaulay_resultant([z, y, x]) # needs sage.modules
an example where the resultant vanishes:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: (x + y).macaulay_resultant([y^2, x]) # needs sage.modules 0
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> (x + y).macaulay_resultant([y**Integer(2), x]) # needs sage.modules 0
R.<x,y,z> = PolynomialRing(QQ, 3) (x + y).macaulay_resultant([y^2, x]) # needs sage.modules
an example of bad reduction at a prime
p = 5
:sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: y.macaulay_resultant([x^3 + 25*y^2*x, 5*z]) # needs sage.libs.pari sage.modules 125
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> y.macaulay_resultant([x**Integer(3) + Integer(25)*y**Integer(2)*x, Integer(5)*z]) # needs sage.libs.pari sage.modules 125
R.<x,y,z> = PolynomialRing(QQ, 3) y.macaulay_resultant([x^3 + 25*y^2*x, 5*z]) # needs sage.libs.pari sage.modules
The input can given as an unpacked list of polynomials:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: y.macaulay_resultant(x^3 + 25*y^2*x, 5*z) # needs sage.libs.pari sage.modules 125
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> y.macaulay_resultant(x**Integer(3) + Integer(25)*y**Integer(2)*x, Integer(5)*z) # needs sage.libs.pari sage.modules 125
R.<x,y,z> = PolynomialRing(QQ, 3) y.macaulay_resultant(x^3 + 25*y^2*x, 5*z) # needs sage.libs.pari sage.modules
an example when the coefficients live in a finite field:
sage: F = FiniteField(11) sage: R.<x,y,z,w> = PolynomialRing(F, 4) sage: z.macaulay_resultant([x^3, 5*y, w]) # needs sage.modules sage.rings.finite_rings 4
>>> from sage.all import * >>> F = FiniteField(Integer(11)) >>> R = PolynomialRing(F, Integer(4), names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = R._first_ngens(4) >>> z.macaulay_resultant([x**Integer(3), Integer(5)*y, w]) # needs sage.modules sage.rings.finite_rings 4
F = FiniteField(11) R.<x,y,z,w> = PolynomialRing(F, 4) z.macaulay_resultant([x^3, 5*y, w]) # needs sage.modules sage.rings.finite_rings
example when the denominator in the algorithm vanishes(in this case the resultant is the constant term of the quotient of char polynomials of numerator/denominator):
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: y.macaulay_resultant([x + z, z^2]) # needs sage.libs.pari sage.modules -1
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> y.macaulay_resultant([x + z, z**Integer(2)]) # needs sage.libs.pari sage.modules -1
R.<x,y,z> = PolynomialRing(QQ, 3) y.macaulay_resultant([x + z, z^2]) # needs sage.libs.pari sage.modules
When there are only 2 polynomials, the Macaulay resultant degenerates to the traditional resultant:
sage: R.<x> = PolynomialRing(QQ, 1) sage: f = x^2 + 1; g = x^5 + 1 sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() sage: f.resultant(g) == fh.macaulay_resultant(gh) # needs sage.modules True
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(1), names=('x',)); (x,) = R._first_ngens(1) >>> f = x**Integer(2) + Integer(1); g = x**Integer(5) + Integer(1) >>> fh = f.homogenize() >>> gh = g.homogenize() >>> RH = fh.parent() >>> f.resultant(g) == fh.macaulay_resultant(gh) # needs sage.modules True
R.<x> = PolynomialRing(QQ, 1) f = x^2 + 1; g = x^5 + 1 fh = f.homogenize() gh = g.homogenize() RH = fh.parent() f.resultant(g) == fh.macaulay_resultant(gh) # needs sage.modules
- map_coefficients(f, new_base_ring=None)[source]¶
Return the polynomial obtained by applying
f
to the nonzero coefficients ofself
.If
f
is asage.categories.map.Map
, then the resulting polynomial will be defined over the codomain off
. Otherwise, the resulting polynomial will be over the same ring asself
. Setnew_base_ring
to override this behaviour.INPUT:
f
– a callable that will be applied to the coefficients ofself
new_base_ring
– (optional) if given, the resulting polynomial will be defined over this ring
EXAMPLES:
sage: k.<a> = GF(9); R.<x,y> = k[]; f = x*a + 2*x^3*y*a + a # needs sage.rings.finite_rings sage: f.map_coefficients(lambda a: a + 1) # needs sage.rings.finite_rings (-a + 1)*x^3*y + (a + 1)*x + (a + 1)
>>> from sage.all import * >>> k = GF(Integer(9), names=('a',)); (a,) = k._first_ngens(1); R = k['x, y']; (x, y,) = R._first_ngens(2); f = x*a + Integer(2)*x**Integer(3)*y*a + a # needs sage.rings.finite_rings >>> f.map_coefficients(lambda a: a + Integer(1)) # needs sage.rings.finite_rings (-a + 1)*x^3*y + (a + 1)*x + (a + 1)
k.<a> = GF(9); R.<x,y> = k[]; f = x*a + 2*x^3*y*a + a # needs sage.rings.finite_rings f.map_coefficients(lambda a: a + 1) # needs sage.rings.finite_rings
Examples with different base ring:
sage: # needs sage.rings.finite_rings sage: R.<r> = GF(9); S.<s> = GF(81) sage: h = Hom(R,S)[0]; h Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 sage: T.<X,Y> = R[] sage: f = r*X + Y sage: g = f.map_coefficients(h); g (-s^3 - s^2 + 1)*X + Y sage: g.parent() Multivariate Polynomial Ring in X, Y over Finite Field in s of size 3^4 sage: h = lambda x: x.trace() sage: g = f.map_coefficients(h); g X - Y sage: g.parent() Multivariate Polynomial Ring in X, Y over Finite Field in r of size 3^2 sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g X - Y sage: g.parent() Multivariate Polynomial Ring in X, Y over Finite Field of size 3
>>> from sage.all import * >>> # needs sage.rings.finite_rings >>> R = GF(Integer(9), names=('r',)); (r,) = R._first_ngens(1); S = GF(Integer(81), names=('s',)); (s,) = S._first_ngens(1) >>> h = Hom(R,S)[Integer(0)]; h Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 >>> T = R['X, Y']; (X, Y,) = T._first_ngens(2) >>> f = r*X + Y >>> g = f.map_coefficients(h); g (-s^3 - s^2 + 1)*X + Y >>> g.parent() Multivariate Polynomial Ring in X, Y over Finite Field in s of size 3^4 >>> h = lambda x: x.trace() >>> g = f.map_coefficients(h); g X - Y >>> g.parent() Multivariate Polynomial Ring in X, Y over Finite Field in r of size 3^2 >>> g = f.map_coefficients(h, new_base_ring=GF(Integer(3))); g X - Y >>> g.parent() Multivariate Polynomial Ring in X, Y over Finite Field of size 3
# needs sage.rings.finite_rings R.<r> = GF(9); S.<s> = GF(81) h = Hom(R,S)[0]; h T.<X,Y> = R[] f = r*X + Y g = f.map_coefficients(h); g g.parent() h = lambda x: x.trace() g = f.map_coefficients(h); g g.parent() g = f.map_coefficients(h, new_base_ring=GF(3)); g g.parent()
- newton_polytope()[source]¶
Return the Newton polytope of this polynomial.
EXAMPLES:
sage: R.<x,y> = QQ[] sage: f = 1 + x*y + x^3 + y^3 sage: P = f.newton_polytope(); P # needs sage.geometry.polyhedron A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: P.is_simple() # needs sage.geometry.polyhedron True
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(1) + x*y + x**Integer(3) + y**Integer(3) >>> P = f.newton_polytope(); P # needs sage.geometry.polyhedron A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices >>> P.is_simple() # needs sage.geometry.polyhedron True
R.<x,y> = QQ[] f = 1 + x*y + x^3 + y^3 P = f.newton_polytope(); P # needs sage.geometry.polyhedron P.is_simple() # needs sage.geometry.polyhedron
- nth_root(n)[source]¶
Return a \(n\)-th root of this element.
If there is no such root, a
ValueError
is raised.EXAMPLES:
sage: R.<x,y,z> = QQ[] sage: a = 32 * (x*y + 1)^5 * (x+y+z)^5 sage: a.nth_root(5) 2*x^2*y + 2*x*y^2 + 2*x*y*z + 2*x + 2*y + 2*z sage: b = x + 2*y + 3*z sage: b.nth_root(42) Traceback (most recent call last): ... ValueError: not a 42nd power sage: R.<x,y> = QQ[] sage: S.<z,t> = R[] sage: T.<u,v> = S[] sage: p = (1 + x*u + y + v) * (1 + z*t) sage: (p**3).nth_root(3) (x*z*t + x)*u + (z*t + 1)*v + (y + 1)*z*t + y + 1 sage: (p**3).nth_root(3).parent() is p.parent() True sage: ((1+x+z+t)**2).nth_root(3) Traceback (most recent call last): ... ValueError: not a 3rd power
>>> from sage.all import * >>> R = QQ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> a = Integer(32) * (x*y + Integer(1))**Integer(5) * (x+y+z)**Integer(5) >>> a.nth_root(Integer(5)) 2*x^2*y + 2*x*y^2 + 2*x*y*z + 2*x + 2*y + 2*z >>> b = x + Integer(2)*y + Integer(3)*z >>> b.nth_root(Integer(42)) Traceback (most recent call last): ... ValueError: not a 42nd power >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> S = R['z, t']; (z, t,) = S._first_ngens(2) >>> T = S['u, v']; (u, v,) = T._first_ngens(2) >>> p = (Integer(1) + x*u + y + v) * (Integer(1) + z*t) >>> (p**Integer(3)).nth_root(Integer(3)) (x*z*t + x)*u + (z*t + 1)*v + (y + 1)*z*t + y + 1 >>> (p**Integer(3)).nth_root(Integer(3)).parent() is p.parent() True >>> ((Integer(1)+x+z+t)**Integer(2)).nth_root(Integer(3)) Traceback (most recent call last): ... ValueError: not a 3rd power
R.<x,y,z> = QQ[] a = 32 * (x*y + 1)^5 * (x+y+z)^5 a.nth_root(5) b = x + 2*y + 3*z b.nth_root(42) R.<x,y> = QQ[] S.<z,t> = R[] T.<u,v> = S[] p = (1 + x*u + y + v) * (1 + z*t) (p**3).nth_root(3) (p**3).nth_root(3).parent() is p.parent() ((1+x+z+t)**2).nth_root(3)
- numerator()[source]¶
Return a numerator of
self
, computed asself * self.denominator()
.Note that some subclasses may implement its own numerator function.
Warning
This is not the numerator of the rational function defined by
self
, which would always beself
sinceself
is a polynomial.EXAMPLES:
First we compute the numerator of a polynomial with integer coefficients, which is of course
self
.sage: R.<x, y> = ZZ[] sage: f = x^3 + 17*x + y + 1 sage: f.numerator() x^3 + 17*x + y + 1 sage: f == f.numerator() True
>>> from sage.all import * >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(3) + Integer(17)*x + y + Integer(1) >>> f.numerator() x^3 + 17*x + y + 1 >>> f == f.numerator() True
R.<x, y> = ZZ[] f = x^3 + 17*x + y + 1 f.numerator() f == f.numerator()
Next we compute the numerator of a polynomial over a number field.
sage: # needs sage.rings.number_field sage.symbolic sage: R.<x,y> = NumberField(symbolic_expression(x^2+3), 'a')['x,y'] sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f 1/17*y^19 - 2/3*x + 1/3 sage: f.numerator() 3*y^19 - 34*x + 17 sage: f == f.numerator() False
>>> from sage.all import * >>> # needs sage.rings.number_field sage.symbolic >>> R = NumberField(symbolic_expression(x**Integer(2)+Integer(3)), 'a')['x,y']; (x, y,) = R._first_ngens(2) >>> f = (Integer(1)/Integer(17))*y**Integer(19) - (Integer(2)/Integer(3))*x + Integer(1)/Integer(3); f 1/17*y^19 - 2/3*x + 1/3 >>> f.numerator() 3*y^19 - 34*x + 17 >>> f == f.numerator() False
# needs sage.rings.number_field sage.symbolic R.<x,y> = NumberField(symbolic_expression(x^2+3), 'a')['x,y'] f = (1/17)*y^19 - (2/3)*x + 1/3; f f.numerator() f == f.numerator()
We try to compute the numerator of a polynomial with coefficients in the finite field of 3 elements.
sage: K.<x,y,z> = GF(3)['x, y, z'] sage: f = 2*x*z + 2*z^2 + 2*y + 1; f -x*z - z^2 - y + 1 sage: f.numerator() -x*z - z^2 - y + 1
>>> from sage.all import * >>> K = GF(Integer(3))['x, y, z']; (x, y, z,) = K._first_ngens(3) >>> f = Integer(2)*x*z + Integer(2)*z**Integer(2) + Integer(2)*y + Integer(1); f -x*z - z^2 - y + 1 >>> f.numerator() -x*z - z^2 - y + 1
K.<x,y,z> = GF(3)['x, y, z'] f = 2*x*z + 2*z^2 + 2*y + 1; f f.numerator()
We check that the computation the numerator and denominator are valid.
sage: # needs sage.rings.number_field sage.symbolic sage: K = NumberField(symbolic_expression('x^3+2'), 'a')['x']['s,t'] sage: f = K.random_element() sage: f.numerator() / f.denominator() == f True sage: R = RR['x,y,z'] sage: f = R.random_element() sage: f.numerator() / f.denominator() == f True
>>> from sage.all import * >>> # needs sage.rings.number_field sage.symbolic >>> K = NumberField(symbolic_expression('x^3+2'), 'a')['x']['s,t'] >>> f = K.random_element() >>> f.numerator() / f.denominator() == f True >>> R = RR['x,y,z'] >>> f = R.random_element() >>> f.numerator() / f.denominator() == f True
# needs sage.rings.number_field sage.symbolic K = NumberField(symbolic_expression('x^3+2'), 'a')['x']['s,t'] f = K.random_element() f.numerator() / f.denominator() == f R = RR['x,y,z'] f = R.random_element() f.numerator() / f.denominator() == f
- polynomial(var)[source]¶
Let
var
be one of the variables of the parent ofself
. This returnsself
viewed as a univariate polynomial invar
over the polynomial ring generated by all the other variables of the parent.EXAMPLES:
sage: R.<x,w,z> = QQ[] sage: f = x^3 + 3*w*x + w^5 + (17*w^3)*x + z^5 sage: f.polynomial(x) x^3 + (17*w^3 + 3*w)*x + w^5 + z^5 sage: parent(f.polynomial(x)) Univariate Polynomial Ring in x over Multivariate Polynomial Ring in w, z over Rational Field sage: f.polynomial(w) w^5 + 17*x*w^3 + 3*x*w + z^5 + x^3 sage: f.polynomial(z) z^5 + w^5 + 17*x*w^3 + x^3 + 3*x*w sage: R.<x,w,z,k> = ZZ[] sage: f = x^3 + 3*w*x + w^5 + (17*w^3)*x + z^5 +x*w*z*k + 5 sage: f.polynomial(x) x^3 + (17*w^3 + w*z*k + 3*w)*x + w^5 + z^5 + 5 sage: f.polynomial(w) w^5 + 17*x*w^3 + (x*z*k + 3*x)*w + z^5 + x^3 + 5 sage: f.polynomial(z) z^5 + x*w*k*z + w^5 + 17*x*w^3 + x^3 + 3*x*w + 5 sage: f.polynomial(k) x*w*z*k + w^5 + z^5 + 17*x*w^3 + x^3 + 3*x*w + 5 sage: R.<x,y> = GF(5)[] sage: f = x^2 + x + y sage: f.polynomial(x) x^2 + x + y sage: f.polynomial(y) y + x^2 + x
>>> from sage.all import * >>> R = QQ['x, w, z']; (x, w, z,) = R._first_ngens(3) >>> f = x**Integer(3) + Integer(3)*w*x + w**Integer(5) + (Integer(17)*w**Integer(3))*x + z**Integer(5) >>> f.polynomial(x) x^3 + (17*w^3 + 3*w)*x + w^5 + z^5 >>> parent(f.polynomial(x)) Univariate Polynomial Ring in x over Multivariate Polynomial Ring in w, z over Rational Field >>> f.polynomial(w) w^5 + 17*x*w^3 + 3*x*w + z^5 + x^3 >>> f.polynomial(z) z^5 + w^5 + 17*x*w^3 + x^3 + 3*x*w >>> R = ZZ['x, w, z, k']; (x, w, z, k,) = R._first_ngens(4) >>> f = x**Integer(3) + Integer(3)*w*x + w**Integer(5) + (Integer(17)*w**Integer(3))*x + z**Integer(5) +x*w*z*k + Integer(5) >>> f.polynomial(x) x^3 + (17*w^3 + w*z*k + 3*w)*x + w^5 + z^5 + 5 >>> f.polynomial(w) w^5 + 17*x*w^3 + (x*z*k + 3*x)*w + z^5 + x^3 + 5 >>> f.polynomial(z) z^5 + x*w*k*z + w^5 + 17*x*w^3 + x^3 + 3*x*w + 5 >>> f.polynomial(k) x*w*z*k + w^5 + z^5 + 17*x*w^3 + x^3 + 3*x*w + 5 >>> R = GF(Integer(5))['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(2) + x + y >>> f.polynomial(x) x^2 + x + y >>> f.polynomial(y) y + x^2 + x
R.<x,w,z> = QQ[] f = x^3 + 3*w*x + w^5 + (17*w^3)*x + z^5 f.polynomial(x) parent(f.polynomial(x)) f.polynomial(w) f.polynomial(z) R.<x,w,z,k> = ZZ[] f = x^3 + 3*w*x + w^5 + (17*w^3)*x + z^5 +x*w*z*k + 5 f.polynomial(x) f.polynomial(w) f.polynomial(z) f.polynomial(k) R.<x,y> = GF(5)[] f = x^2 + x + y f.polynomial(x) f.polynomial(y)
- reduced_form(**kwds)[source]¶
Return a reduced form of this polynomial.
The algorithm is from Stoll and Cremona’s “On the Reduction Theory of Binary Forms” [CS2003]. This takes a two variable homogeneous polynomial and finds a reduced form. This is a \(SL(2,\ZZ)\)-equivalent binary form whose covariant in the upper half plane is in the fundamental domain. If the polynomial has multiple roots, they are removed and the algorithm is applied to the portion without multiple roots.
This reduction should also minimize the sum of the squares of the coefficients, but this is not always the case. By default the coefficient minimizing algorithm in [HS2018] is applied. The coefficients can be minimized either with respect to the sum of their squares or the maximum of their global heights.
A portion of the algorithm uses Newton’s method to find a solution to a system of equations. If Newton’s method fails to converge to a point in the upper half plane, the function will use the less precise \(z_0\) covariant from the \(Q_0\) form as defined on page 7 of [CS2003]. Additionally, if this polynomial has a root with multiplicity at least half the total degree of the polynomial, then we must also use the \(z_0\) covariant. See [CS2003] for details.
Note that, if the covariant is within
error_limit
of the boundary but outside the fundamental domain, our function will erroneously move it to within the fundamental domain, hence our conjugation will be off by 1. If you don’t want this to happen, decrease yourerror_limit
and increase your precision.Implemented by Rebecca Lauren Miller as part of GSOC 2016. Smallest coefficients added by Ben Hutz July 2018.
INPUT: keyword arguments:
prec
– integer (default: 300); sets the precisionreturn_conjugation
– boolean (default:True
); whether to return element of \(SL(2, \ZZ)\)error_limit
– sets the error tolerance (default: 0.000001)smallest_coeffs
– boolean (default:True
); whether to find the model with smallest coefficientsnorm_type
– either'norm'
or'height'
; what type of norm to use for smallest coefficientsemb
– (optional) embedding of based field intoCC
OUTPUT:
a polynomial (reduced binary form)
a matrix (element of \(SL(2, \ZZ)\))
Todo
When Newton’s Method doesn’t converge to a root in the upper half plane. Now we just return \(z_0\). It would be better to modify and find the unique root in the upper half plane.
EXAMPLES:
sage: R.<x,h> = PolynomialRing(QQ) sage: f = 19*x^8 - 262*x^7*h + 1507*x^6*h^2 - 4784*x^5*h^3 + 9202*x^4*h^4\ -10962*x^3*h^5 + 7844*x^2*h^6 - 3040*x*h^7 + 475*h^8 sage: f.reduced_form(prec=200, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field ( -x^8 - 2*x^7*h + 7*x^6*h^2 + 16*x^5*h^3 + 2*x^4*h^4 - 2*x^3*h^5 + 4*x^2*h^6 - 5*h^8, [ 1 -2] [ 1 -1] )
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'h',)); (x, h,) = R._first_ngens(2) >>> f = Integer(19)*x**Integer(8) - Integer(262)*x**Integer(7)*h + Integer(1507)*x**Integer(6)*h**Integer(2) - Integer(4784)*x**Integer(5)*h**Integer(3) + Integer(9202)*x**Integer(4)*h**Integer(4)\ -10962*x^3*h^5 + 7844*x^2*h^6 - 3040*x*h^7 + 475*h^8 >>> f.reduced_form(prec=Integer(200), smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field ( -x^8 - 2*x^7*h + 7*x^6*h^2 + 16*x^5*h^3 + 2*x^4*h^4 - 2*x^3*h^5 + 4*x^2*h^6 - 5*h^8, <BLANKLINE> [ 1 -2] [ 1 -1] )
R.<x,h> = PolynomialRing(QQ) f = 19*x^8 - 262*x^7*h + 1507*x^6*h^2 - 4784*x^5*h^3 + 9202*x^4*h^4\ f.reduced_form(prec=200, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field
An example where the multiplicity is too high:
sage: R.<x,y> = PolynomialRing(QQ) sage: f = x^3 + 378666*x^2*y - 12444444*x*y^2 + 1234567890*y^3 sage: j = f * (x-545*y)^9 sage: j.reduced_form(prec=200, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: cannot have a root with multiplicity >= 12/2
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = x**Integer(3) + Integer(378666)*x**Integer(2)*y - Integer(12444444)*x*y**Integer(2) + Integer(1234567890)*y**Integer(3) >>> j = f * (x-Integer(545)*y)**Integer(9) >>> j.reduced_form(prec=Integer(200), smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: cannot have a root with multiplicity >= 12/2
R.<x,y> = PolynomialRing(QQ) f = x^3 + 378666*x^2*y - 12444444*x*y^2 + 1234567890*y^3 j = f * (x-545*y)^9 j.reduced_form(prec=200, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field
An example where Newton’s Method does not find the right root:
sage: R.<x,y> = PolynomialRing(QQ) sage: F = x^6 + 3*x^5*y - 8*x^4*y^2 - 2*x^3*y^3 - 44*x^2*y^4 - 8*x*y^5 sage: F.reduced_form(smallest_coeffs=False, prec=400) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ArithmeticError: Newton's method converged to z not in the upper half plane
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> F = x**Integer(6) + Integer(3)*x**Integer(5)*y - Integer(8)*x**Integer(4)*y**Integer(2) - Integer(2)*x**Integer(3)*y**Integer(3) - Integer(44)*x**Integer(2)*y**Integer(4) - Integer(8)*x*y**Integer(5) >>> F.reduced_form(smallest_coeffs=False, prec=Integer(400)) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ArithmeticError: Newton's method converged to z not in the upper half plane
R.<x,y> = PolynomialRing(QQ) F = x^6 + 3*x^5*y - 8*x^4*y^2 - 2*x^3*y^3 - 44*x^2*y^4 - 8*x*y^5 F.reduced_form(smallest_coeffs=False, prec=400) # needs sage.modules sage.rings.complex_interval_field
An example with covariant on the boundary, therefore a non-unique form:
sage: R.<x,y> = PolynomialRing(QQ) sage: F = 5*x^2*y - 5*x*y^2 - 30*y^3 sage: F.reduced_form(smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field ( [1 1] 5*x^2*y + 5*x*y^2 - 30*y^3, [0 1] )
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> F = Integer(5)*x**Integer(2)*y - Integer(5)*x*y**Integer(2) - Integer(30)*y**Integer(3) >>> F.reduced_form(smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field ( [1 1] 5*x^2*y + 5*x*y^2 - 30*y^3, [0 1] )
R.<x,y> = PolynomialRing(QQ) F = 5*x^2*y - 5*x*y^2 - 30*y^3 F.reduced_form(smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field
An example where precision needs to be increased:
sage: R.<x,y> = PolynomialRing(QQ) sage: F = (-16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 ....: - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7) sage: F.reduced_form(prec=50, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: accuracy of Newton's root not within tolerance(0.000012... > 1e-06), increase precision sage: F.reduced_form(prec=100, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field ( [-1 -1] -x^5*y^2 - 24*x^3*y^4 - 3*x^2*y^5 - 2*x*y^6 + 16*y^7, [ 1 0] )
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> F = (-Integer(16)*x**Integer(7) - Integer(114)*x**Integer(6)*y - Integer(345)*x**Integer(5)*y**Integer(2) - Integer(599)*x**Integer(4)*y**Integer(3) ... - Integer(666)*x**Integer(3)*y**Integer(4) - Integer(481)*x**Integer(2)*y**Integer(5) - Integer(207)*x*y**Integer(6) - Integer(40)*y**Integer(7)) >>> F.reduced_form(prec=Integer(50), smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: accuracy of Newton's root not within tolerance(0.000012... > 1e-06), increase precision >>> F.reduced_form(prec=Integer(100), smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field ( [-1 -1] -x^5*y^2 - 24*x^3*y^4 - 3*x^2*y^5 - 2*x*y^6 + 16*y^7, [ 1 0] )
R.<x,y> = PolynomialRing(QQ) F = (-16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7) F.reduced_form(prec=50, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field F.reduced_form(prec=100, smallest_coeffs=False) # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y> = PolynomialRing(QQ) sage: F = - 8*x^4 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 1825511633*y^4 sage: F.reduced_form(return_conjugation=False) # needs sage.modules sage.rings.complex_interval_field x^4 + 9*x^3*y - 3*x*y^3 - 8*y^4
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> F = - Integer(8)*x**Integer(4) - Integer(3933)*x**Integer(3)*y - Integer(725085)*x**Integer(2)*y**Integer(2) - Integer(59411592)*x*y**Integer(3) - Integer(1825511633)*y**Integer(4) >>> F.reduced_form(return_conjugation=False) # needs sage.modules sage.rings.complex_interval_field x^4 + 9*x^3*y - 3*x*y^3 - 8*y^4
R.<x,y> = PolynomialRing(QQ) F = - 8*x^4 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 1825511633*y^4 F.reduced_form(return_conjugation=False) # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y> = QQ[] sage: F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 sage: F.reduced_form() # needs sage.modules sage.rings.complex_interval_field ( [1 4] -2*x^3 - 22*x^2*y - 77*x*y^2 + 43*y^3, [0 1] )
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> F = -Integer(2)*x**Integer(3) + Integer(2)*x**Integer(2)*y + Integer(3)*x*y**Integer(2) + Integer(127)*y**Integer(3) >>> F.reduced_form() # needs sage.modules sage.rings.complex_interval_field ( [1 4] -2*x^3 - 22*x^2*y - 77*x*y^2 + 43*y^3, [0 1] )
R.<x,y> = QQ[] F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 F.reduced_form() # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y> = QQ[] sage: F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 sage: F.reduced_form(norm_type='height') # needs sage.modules sage.rings.complex_interval_field ( [5 4] -58*x^3 - 47*x^2*y + 52*x*y^2 + 43*y^3, [1 1] )
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> F = -Integer(2)*x**Integer(3) + Integer(2)*x**Integer(2)*y + Integer(3)*x*y**Integer(2) + Integer(127)*y**Integer(3) >>> F.reduced_form(norm_type='height') # needs sage.modules sage.rings.complex_interval_field ( [5 4] -58*x^3 - 47*x^2*y + 52*x*y^2 + 43*y^3, [1 1] )
R.<x,y> = QQ[] F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 F.reduced_form(norm_type='height') # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y,z> = PolynomialRing(QQ) sage: F = x^4 + x^3*y*z + y^2*z sage: F.reduced_form() # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: (=x^3*y*z + x^4 + y^2*z) must have two variables
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> F = x**Integer(4) + x**Integer(3)*y*z + y**Integer(2)*z >>> F.reduced_form() # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: (=x^3*y*z + x^4 + y^2*z) must have two variables
R.<x,y,z> = PolynomialRing(QQ) F = x^4 + x^3*y*z + y^2*z F.reduced_form() # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y> = PolynomialRing(ZZ) sage: F = - 8*x^6 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 99*y^6 sage: F.reduced_form(return_conjugation=False) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: (=-8*x^6 - 99*y^6 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3) must be homogeneous
>>> from sage.all import * >>> R = PolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> F = - Integer(8)*x**Integer(6) - Integer(3933)*x**Integer(3)*y - Integer(725085)*x**Integer(2)*y**Integer(2) - Integer(59411592)*x*y**Integer(3) - Integer(99)*y**Integer(6) >>> F.reduced_form(return_conjugation=False) # needs sage.modules sage.rings.complex_interval_field Traceback (most recent call last): ... ValueError: (=-8*x^6 - 99*y^6 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3) must be homogeneous
R.<x,y> = PolynomialRing(ZZ) F = - 8*x^6 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 99*y^6 F.reduced_form(return_conjugation=False) # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y> = PolynomialRing(RR) sage: F = (217.992172373276*x^3 + 96023.1505442490*x^2*y ....: + 1.40987971253579e7*x*y^2 + 6.90016027113216e8*y^3) sage: F.reduced_form(smallest_coeffs=False) # tol 1e-8 # needs sage.modules sage.rings.complex_interval_field ( -39.5673942565918*x^3 + 111.874026298523*x^2*y + 231.052762985229*x*y^2 - 138.380829811096*y^3, [-147 -148] [ 1 1] )
>>> from sage.all import * >>> R = PolynomialRing(RR, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> F = (RealNumber('217.992172373276')*x**Integer(3) + RealNumber('96023.1505442490')*x**Integer(2)*y ... + RealNumber('1.40987971253579e7')*x*y**Integer(2) + RealNumber('6.90016027113216e8')*y**Integer(3)) >>> F.reduced_form(smallest_coeffs=False) # tol 1e-8 # needs sage.modules sage.rings.complex_interval_field ( -39.5673942565918*x^3 + 111.874026298523*x^2*y + 231.052762985229*x*y^2 - 138.380829811096*y^3, <BLANKLINE> [-147 -148] [ 1 1] )
R.<x,y> = PolynomialRing(RR) F = (217.992172373276*x^3 + 96023.1505442490*x^2*y + 1.40987971253579e7*x*y^2 + 6.90016027113216e8*y^3) F.reduced_form(smallest_coeffs=False) # tol 1e-8 # needs sage.modules sage.rings.complex_interval_field
sage: R.<x,y> = PolynomialRing(CC) # needs sage.rings.real_mpfr sage: F = ((0.759099196558145 + 0.845425869641446*CC.0)*x^3 # needs sage.rings.real_mpfr ....: + (84.8317207268542 + 93.8840848648033*CC.0)*x^2*y ....: + (3159.07040755858 + 3475.33037377779*CC.0)*x*y^2 ....: + (39202.5965389079 + 42882.5139724962*CC.0)*y^3) sage: F.reduced_form(smallest_coeffs=False) # tol 1e-11 # needs sage.modules sage.rings.complex_interval_field sage.rings.real_mpfr ( (-0.759099196558145 - 0.845425869641446*I)*x^3 + (-0.571709908900118 - 0.0418133346027929*I)*x^2*y + (0.856525964330103 - 0.0721403997649759*I)*x*y^2 + (-0.965531044130330 + 0.754252314465703*I)*y^3, [-1 37] [ 0 -1] )
>>> from sage.all import * >>> R = PolynomialRing(CC, names=('x', 'y',)); (x, y,) = R._first_ngens(2)# needs sage.rings.real_mpfr >>> F = ((RealNumber('0.759099196558145') + RealNumber('0.845425869641446')*CC.gen(0))*x**Integer(3) # needs sage.rings.real_mpfr ... + (RealNumber('84.8317207268542') + RealNumber('93.8840848648033')*CC.gen(0))*x**Integer(2)*y ... + (RealNumber('3159.07040755858') + RealNumber('3475.33037377779')*CC.gen(0))*x*y**Integer(2) ... + (RealNumber('39202.5965389079') + RealNumber('42882.5139724962')*CC.gen(0))*y**Integer(3)) >>> F.reduced_form(smallest_coeffs=False) # tol 1e-11 # needs sage.modules sage.rings.complex_interval_field sage.rings.real_mpfr ( (-0.759099196558145 - 0.845425869641446*I)*x^3 + (-0.571709908900118 - 0.0418133346027929*I)*x^2*y + (0.856525964330103 - 0.0721403997649759*I)*x*y^2 + (-0.965531044130330 + 0.754252314465703*I)*y^3, <BLANKLINE> [-1 37] [ 0 -1] )
R.<x,y> = PolynomialRing(CC) # needs sage.rings.real_mpfr F = ((0.759099196558145 + 0.845425869641446*CC.0)*x^3 # needs sage.rings.real_mpfr + (84.8317207268542 + 93.8840848648033*CC.0)*x^2*y + (3159.07040755858 + 3475.33037377779*CC.0)*x*y^2 + (39202.5965389079 + 42882.5139724962*CC.0)*y^3) F.reduced_form(smallest_coeffs=False) # tol 1e-11 # needs sage.modules sage.rings.complex_interval_field sage.rings.real_mpfr
- specialization(D=None, phi=None)[source]¶
Specialization of this polynomial.
Given a family of polynomials defined over a polynomial ring. A specialization is a particular member of that family. The specialization can be specified either by a dictionary or a
SpecializationMorphism
.INPUT:
D
– dictionary (optional)phi
–SpecializationMorphism
(optional)
OUTPUT: a new polynomial
EXAMPLES:
sage: R.<c> = PolynomialRing(QQ) sage: S.<x,y> = PolynomialRing(R) sage: F = x^2 + c*y^2 sage: F.specialization({c:2}) x^2 + 2*y^2
>>> from sage.all import * >>> R = PolynomialRing(QQ, names=('c',)); (c,) = R._first_ngens(1) >>> S = PolynomialRing(R, names=('x', 'y',)); (x, y,) = S._first_ngens(2) >>> F = x**Integer(2) + c*y**Integer(2) >>> F.specialization({c:Integer(2)}) x^2 + 2*y^2
R.<c> = PolynomialRing(QQ) S.<x,y> = PolynomialRing(R) F = x^2 + c*y^2 F.specialization({c:2})
sage: S.<a,b> = PolynomialRing(QQ) sage: P.<x,y,z> = PolynomialRing(S) sage: RR.<c,d> = PolynomialRing(P) sage: f = a*x^2 + b*y^3 + c*y^2 - b*a*d + d^2 - a*c*b*z^2 sage: f.specialization({a:2, z:4, d:2}) (y^2 - 32*b)*c + b*y^3 + 2*x^2 - 4*b + 4
>>> from sage.all import * >>> S = PolynomialRing(QQ, names=('a', 'b',)); (a, b,) = S._first_ngens(2) >>> P = PolynomialRing(S, names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3) >>> RR = PolynomialRing(P, names=('c', 'd',)); (c, d,) = RR._first_ngens(2) >>> f = a*x**Integer(2) + b*y**Integer(3) + c*y**Integer(2) - b*a*d + d**Integer(2) - a*c*b*z**Integer(2) >>> f.specialization({a:Integer(2), z:Integer(4), d:Integer(2)}) (y^2 - 32*b)*c + b*y^3 + 2*x^2 - 4*b + 4
S.<a,b> = PolynomialRing(QQ) P.<x,y,z> = PolynomialRing(S) RR.<c,d> = PolynomialRing(P) f = a*x^2 + b*y^3 + c*y^2 - b*a*d + d^2 - a*c*b*z^2 f.specialization({a:2, z:4, d:2})
Check that we preserve multi- versus uni-variate:
sage: R.<l> = PolynomialRing(QQ, 1) sage: S.<k> = PolynomialRing(R) sage: K.<a, b, c> = PolynomialRing(S) sage: F = a*k^2 + b*l + c^2 sage: F.specialization({b:56, c:5}).parent() Univariate Polynomial Ring in a over Univariate Polynomial Ring in k over Multivariate Polynomial Ring in l over Rational Field
>>> from sage.all import * >>> R = PolynomialRing(QQ, Integer(1), names=('l',)); (l,) = R._first_ngens(1) >>> S = PolynomialRing(R, names=('k',)); (k,) = S._first_ngens(1) >>> K = PolynomialRing(S, names=('a', 'b', 'c',)); (a, b, c,) = K._first_ngens(3) >>> F = a*k**Integer(2) + b*l + c**Integer(2) >>> F.specialization({b:Integer(56), c:Integer(5)}).parent() Univariate Polynomial Ring in a over Univariate Polynomial Ring in k over Multivariate Polynomial Ring in l over Rational Field
R.<l> = PolynomialRing(QQ, 1) S.<k> = PolynomialRing(R) K.<a, b, c> = PolynomialRing(S) F = a*k^2 + b*l + c^2 F.specialization({b:56, c:5}).parent()
- subresultants(other, variable=None)[source]¶
Return the nonzero subresultant polynomials of
self
andother
.INPUT:
other
– a polynomial
OUTPUT: list of polynomials in the same ring as
self
EXAMPLES:
sage: R.<x,y> = QQ[] sage: p = (y^2 + 6)*(x - 1) - y*(x^2 + 1) sage: q = (x^2 + 6)*(y - 1) - x*(y^2 + 1) sage: p.subresultants(q, y) [2*x^6 - 22*x^5 + 102*x^4 - 274*x^3 + 488*x^2 - 552*x + 288, -x^3 - x^2*y + 6*x^2 + 5*x*y - 11*x - 6*y + 6] sage: p.subresultants(q, x) [2*y^6 - 22*y^5 + 102*y^4 - 274*y^3 + 488*y^2 - 552*y + 288, x*y^2 + y^3 - 5*x*y - 6*y^2 + 6*x + 11*y - 6]
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> p = (y**Integer(2) + Integer(6))*(x - Integer(1)) - y*(x**Integer(2) + Integer(1)) >>> q = (x**Integer(2) + Integer(6))*(y - Integer(1)) - x*(y**Integer(2) + Integer(1)) >>> p.subresultants(q, y) [2*x^6 - 22*x^5 + 102*x^4 - 274*x^3 + 488*x^2 - 552*x + 288, -x^3 - x^2*y + 6*x^2 + 5*x*y - 11*x - 6*y + 6] >>> p.subresultants(q, x) [2*y^6 - 22*y^5 + 102*y^4 - 274*y^3 + 488*y^2 - 552*y + 288, x*y^2 + y^3 - 5*x*y - 6*y^2 + 6*x + 11*y - 6]
R.<x,y> = QQ[] p = (y^2 + 6)*(x - 1) - y*(x^2 + 1) q = (x^2 + 6)*(y - 1) - x*(y^2 + 1) p.subresultants(q, y) p.subresultants(q, x)
- sylvester_matrix(right, variable=None)[source]¶
Given two nonzero polynomials
self
andright
, return the Sylvester matrix of the polynomials with respect to a given variable.Note that the Sylvester matrix is not defined if one of the polynomials is zero.
INPUT:
self
,right
– multivariate polynomialsvariable
– (optional) compute the Sylvester matrix with respect to this variable. Ifvariable
is not provided, the first variable of the polynomial ring is used.
OUTPUT: the Sylvester matrix of
self
andright
EXAMPLES:
sage: R.<x, y> = PolynomialRing(ZZ) sage: f = (y + 1)*x + 3*x**2 sage: g = (y + 2)*x + 4*x**2 sage: M = f.sylvester_matrix(g, x) # needs sage.modules sage: M # needs sage.modules [ 3 y + 1 0 0] [ 0 3 y + 1 0] [ 4 y + 2 0 0] [ 0 4 y + 2 0]
>>> from sage.all import * >>> R = PolynomialRing(ZZ, names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = (y + Integer(1))*x + Integer(3)*x**Integer(2) >>> g = (y + Integer(2))*x + Integer(4)*x**Integer(2) >>> M = f.sylvester_matrix(g, x) # needs sage.modules >>> M # needs sage.modules [ 3 y + 1 0 0] [ 0 3 y + 1 0] [ 4 y + 2 0 0] [ 0 4 y + 2 0]
R.<x, y> = PolynomialRing(ZZ) f = (y + 1)*x + 3*x**2 g = (y + 2)*x + 4*x**2 M = f.sylvester_matrix(g, x) # needs sage.modules M # needs sage.modules
If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will be zero:
sage: M.determinant() # needs sage.modules 0 sage: f.sylvester_matrix(1 + g, x).determinant() # needs sage.modules y^2 - y + 7
>>> from sage.all import * >>> M.determinant() # needs sage.modules 0 >>> f.sylvester_matrix(Integer(1) + g, x).determinant() # needs sage.modules y^2 - y + 7
M.determinant() # needs sage.modules f.sylvester_matrix(1 + g, x).determinant() # needs sage.modules
If both polynomials are of positive degree with respect to
variable
, the determinant of the Sylvester matrix is the resultant:sage: f = R.random_element(4) or (x^2 * y^2) sage: g = R.random_element(4) or (x^2 * y^2) sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) # needs sage.libs.singular sage.modules True
>>> from sage.all import * >>> f = R.random_element(Integer(4)) or (x**Integer(2) * y**Integer(2)) >>> g = R.random_element(Integer(4)) or (x**Integer(2) * y**Integer(2)) >>> f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) # needs sage.libs.singular sage.modules True
f = R.random_element(4) or (x^2 * y^2) g = R.random_element(4) or (x^2 * y^2) f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) # needs sage.libs.singular sage.modules
- truncate(var, n)[source]¶
Return a new multivariate polynomial obtained from
self
by deleting all terms that involve the given variable to a power at leastn
.
- weighted_degree(*weights)[source]¶
Return the weighted degree of
self
, which is the maximum weighted degree of all monomials inself
; the weighted degree of a monomial is the sum of all powers of the variables in the monomial, each power multiplied with its respective weight inweights
.This method is given for convenience. It is faster to use polynomial rings with weighted term orders and the standard
degree
function.INPUT:
weights
– either individual numbers, an iterable or a dictionary, specifying the weights of each variable. If it is a dictionary, it maps each variable ofself
to its weight. If it is a sequence of individual numbers or a tuple, the weights are specified in the order of the generators as given byself.parent().gens()
.
EXAMPLES:
sage: R.<x,y,z> = GF(7)[] sage: p = x^3 + y + x*z^2 sage: p.weighted_degree({z:0, x:1, y:2}) 3 sage: p.weighted_degree(1, 2, 0) 3 sage: p.weighted_degree((1, 4, 2)) 5 sage: p.weighted_degree((1, 4, 1)) 4 sage: p.weighted_degree(2**64, 2**50, 2**128) 680564733841876926945195958937245974528 sage: q = R.random_element(100, 20) sage: q.weighted_degree(1, 1, 1) == q.total_degree() True
>>> from sage.all import * >>> R = GF(Integer(7))['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> p = x**Integer(3) + y + x*z**Integer(2) >>> p.weighted_degree({z:Integer(0), x:Integer(1), y:Integer(2)}) 3 >>> p.weighted_degree(Integer(1), Integer(2), Integer(0)) 3 >>> p.weighted_degree((Integer(1), Integer(4), Integer(2))) 5 >>> p.weighted_degree((Integer(1), Integer(4), Integer(1))) 4 >>> p.weighted_degree(Integer(2)**Integer(64), Integer(2)**Integer(50), Integer(2)**Integer(128)) 680564733841876926945195958937245974528 >>> q = R.random_element(Integer(100), Integer(20)) >>> q.weighted_degree(Integer(1), Integer(1), Integer(1)) == q.total_degree() True
R.<x,y,z> = GF(7)[] p = x^3 + y + x*z^2 p.weighted_degree({z:0, x:1, y:2}) p.weighted_degree(1, 2, 0) p.weighted_degree((1, 4, 2)) p.weighted_degree((1, 4, 1)) p.weighted_degree(2**64, 2**50, 2**128) q = R.random_element(100, 20) q.weighted_degree(1, 1, 1) == q.total_degree()
You may also work with negative weights
sage: p.weighted_degree(-1, -2, -1) -2
>>> from sage.all import * >>> p.weighted_degree(-Integer(1), -Integer(2), -Integer(1)) -2
p.weighted_degree(-1, -2, -1)
Note that only integer weights are allowed
sage: p.weighted_degree(x, 1, 1) Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to Integer Ring sage: p.weighted_degree(2/1, 1, 1) 6
>>> from sage.all import * >>> p.weighted_degree(x, Integer(1), Integer(1)) Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to Integer Ring >>> p.weighted_degree(Integer(2)/Integer(1), Integer(1), Integer(1)) 6
p.weighted_degree(x, 1, 1) p.weighted_degree(2/1, 1, 1)
The
weighted_degree()
coincides with thedegree()
of a weighted polynomial ring, but the latter is faster.sage: K = PolynomialRing(QQ, 'x,y', order=TermOrder('wdegrevlex', (2,3))) sage: p = K.random_element(10) sage: p.degree() == p.weighted_degree(2,3) True
>>> from sage.all import * >>> K = PolynomialRing(QQ, 'x,y', order=TermOrder('wdegrevlex', (Integer(2),Integer(3)))) >>> p = K.random_element(Integer(10)) >>> p.degree() == p.weighted_degree(Integer(2),Integer(3)) True
K = PolynomialRing(QQ, 'x,y', order=TermOrder('wdegrevlex', (2,3))) p = K.random_element(10) p.degree() == p.weighted_degree(2,3)
- class sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular[source]¶
Bases:
MPolynomial
Abstract base class for
MPolynomial_libsingular
.This class is defined for the purpose of
isinstance()
tests. It should not be instantiated.EXAMPLES:
sage: from sage.rings.polynomial.multi_polynomial import MPolynomial_libsingular sage: R1.<x> = QQ[] sage: isinstance(x, MPolynomial_libsingular) False sage: R2.<y,z> = QQ[] sage: isinstance(y, MPolynomial_libsingular) # needs sage.libs.singular True
>>> from sage.all import * >>> from sage.rings.polynomial.multi_polynomial import MPolynomial_libsingular >>> R1 = QQ['x']; (x,) = R1._first_ngens(1) >>> isinstance(x, MPolynomial_libsingular) False >>> R2 = QQ['y, z']; (y, z,) = R2._first_ngens(2) >>> isinstance(y, MPolynomial_libsingular) # needs sage.libs.singular True
from sage.rings.polynomial.multi_polynomial import MPolynomial_libsingular R1.<x> = QQ[] isinstance(x, MPolynomial_libsingular) R2.<y,z> = QQ[] isinstance(y, MPolynomial_libsingular) # needs sage.libs.singular
By design, there is a unique direct subclass:
sage: len(sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular.__subclasses__()) <= 1 True
>>> from sage.all import * >>> len(sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular.__subclasses__()) <= Integer(1) True
len(sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular.__subclasses__()) <= 1