Base class for multivariate polynomial rings¶
- class sage.rings.polynomial.multi_polynomial_ring_base.BooleanPolynomialRing_base[source]¶
Bases:
MPolynomialRing_base
Abstract base class for
BooleanPolynomialRing
.This class is defined for the purpose of
isinstance
tests. It should not be instantiated.EXAMPLES:
sage: from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base sage: R.<x, y, z> = BooleanPolynomialRing() # needs sage.rings.polynomial.pbori sage: isinstance(R, BooleanPolynomialRing_base) # needs sage.rings.polynomial.pbori True
>>> from sage.all import * >>> from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base >>> R = BooleanPolynomialRing(names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)# needs sage.rings.polynomial.pbori >>> isinstance(R, BooleanPolynomialRing_base) # needs sage.rings.polynomial.pbori True
By design, there is only one direct implementation subclass:
sage: len(BooleanPolynomialRing_base.__subclasses__()) <= 1 True
>>> from sage.all import * >>> len(BooleanPolynomialRing_base.__subclasses__()) <= Integer(1) True
- class sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base[source]¶
Bases:
CommutativeRing
Create a polynomial ring in several variables over a commutative ring.
EXAMPLES:
sage: R.<x,y> = ZZ['x,y']; R Multivariate Polynomial Ring in x, y over Integer Ring sage: cat = Rings().Commutative() sage: class CR(Parent): ....: def __init__(self): ....: Parent.__init__(self, self, category=cat) ....: def __call__(self, x): ....: return None sage: cr = CR() sage: cr.is_commutative() True sage: cr['x,y'] Multivariate Polynomial Ring in x, y over <__main__.CR_with_category object at ...>
>>> from sage.all import * >>> R = ZZ['x,y']; (x, y,) = R._first_ngens(2); R Multivariate Polynomial Ring in x, y over Integer Ring >>> cat = Rings().Commutative() >>> class CR(Parent): ... def __init__(self): ... Parent.__init__(self, self, category=cat) ... def __call__(self, x): ... return None >>> cr = CR() >>> cr.is_commutative() True >>> cr['x,y'] Multivariate Polynomial Ring in x, y over <__main__.CR_with_category object at ...>
- change_ring(base_ring=None, names=None, order=None)[source]¶
Return a new multivariate polynomial ring which is isomorphic to
self
, but has a different ordering given by the parameterorder
or names given by the parameternames
.INPUT:
base_ring
– a base ringnames
– variable namesorder
– a term order
EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(GF(127), 3, order='lex') sage: x > y^2 True sage: Q.<x,y,z> = P.change_ring(order='degrevlex') sage: x > y^2 False
>>> from sage.all import * >>> P = PolynomialRing(GF(Integer(127)), Integer(3), order='lex', names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3) >>> x > y**Integer(2) True >>> Q = P.change_ring(order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = Q._first_ngens(3) >>> x > y**Integer(2) False
- characteristic()[source]¶
Return the characteristic of this polynomial ring.
EXAMPLES:
sage: R = PolynomialRing(QQ, 'x', 3) sage: R.characteristic() 0 sage: R = PolynomialRing(GF(7), 'x', 20) sage: R.characteristic() 7
>>> from sage.all import * >>> R = PolynomialRing(QQ, 'x', Integer(3)) >>> R.characteristic() 0 >>> R = PolynomialRing(GF(Integer(7)), 'x', Integer(20)) >>> R.characteristic() 7
- completion(names=None, prec=20, extras={}, **kwds)[source]¶
Return the completion of
self
with respect to the ideal generated by the variable(s)names
.INPUT:
names
– (optional) variable or list/tuple of variables (given either as elements of the polynomial ring or as strings); the default is all variables ofself
prec
– default precision of resulting power series ring, possibly infiniteextras
– passed as keywords toPowerSeriesRing
orLazyPowerSeriesRing
; can also be keyword arguments
EXAMPLES:
sage: P.<x,y,z,w> = PolynomialRing(ZZ) sage: P.completion('w') Power Series Ring in w over Multivariate Polynomial Ring in x, y, z over Integer Ring sage: P.completion((w,x,y)) Multivariate Power Series Ring in w, x, y over Univariate Polynomial Ring in z over Integer Ring sage: Q.<w,x,y,z> = P.completion(); Q Multivariate Power Series Ring in w, x, y, z over Integer Ring sage: H = PolynomialRing(PolynomialRing(ZZ,3,'z'),4,'f'); H Multivariate Polynomial Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: H.completion(H.gens()) Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: H.completion(H.gens()[2]) Power Series Ring in f2 over Multivariate Polynomial Ring in f0, f1, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: P.<x,y,z,w> = PolynomialRing(ZZ) sage: P.completion(prec=oo) # needs sage.combinat Multivariate Lazy Taylor Series Ring in x, y, z, w over Integer Ring sage: P.completion((w,x,y), prec=oo) # needs sage.combinat Multivariate Lazy Taylor Series Ring in w, x, y over Univariate Polynomial Ring in z over Integer Ring
>>> from sage.all import * >>> P = PolynomialRing(ZZ, names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = P._first_ngens(4) >>> P.completion('w') Power Series Ring in w over Multivariate Polynomial Ring in x, y, z over Integer Ring >>> P.completion((w,x,y)) Multivariate Power Series Ring in w, x, y over Univariate Polynomial Ring in z over Integer Ring >>> Q = P.completion(names=('w', 'x', 'y', 'z',)); (w, x, y, z,) = Q._first_ngens(4); Q Multivariate Power Series Ring in w, x, y, z over Integer Ring >>> H = PolynomialRing(PolynomialRing(ZZ,Integer(3),'z'),Integer(4),'f'); H Multivariate Polynomial Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring >>> H.completion(H.gens()) Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring >>> H.completion(H.gens()[Integer(2)]) Power Series Ring in f2 over Multivariate Polynomial Ring in f0, f1, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring >>> P = PolynomialRing(ZZ, names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = P._first_ngens(4) >>> P.completion(prec=oo) # needs sage.combinat Multivariate Lazy Taylor Series Ring in x, y, z, w over Integer Ring >>> P.completion((w,x,y), prec=oo) # needs sage.combinat Multivariate Lazy Taylor Series Ring in w, x, y over Univariate Polynomial Ring in z over Integer Ring
- construction()[source]¶
Return a functor
F
and base ringR
such thatF(R) == self
.EXAMPLES:
sage: S = ZZ['x,y'] sage: F, R = S.construction(); R Integer Ring sage: F MPoly[x,y] sage: F(R) == S True sage: F(R) == ZZ['x']['y'] False
>>> from sage.all import * >>> S = ZZ['x,y'] >>> F, R = S.construction(); R Integer Ring >>> F MPoly[x,y] >>> F(R) == S True >>> F(R) == ZZ['x']['y'] False
- flattening_morphism()[source]¶
Return the flattening morphism of this polynomial ring.
EXAMPLES:
sage: QQ['a','b']['x','y'].flattening_morphism() Flattening morphism: From: Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Rational Field To: Multivariate Polynomial Ring in a, b, x, y over Rational Field sage: QQ['x,y'].flattening_morphism() Identity endomorphism of Multivariate Polynomial Ring in x, y over Rational Field
>>> from sage.all import * >>> QQ['a','b']['x','y'].flattening_morphism() Flattening morphism: From: Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Rational Field To: Multivariate Polynomial Ring in a, b, x, y over Rational Field >>> QQ['x,y'].flattening_morphism() Identity endomorphism of Multivariate Polynomial Ring in x, y over Rational Field
- interpolation(bound, *args)[source]¶
Create a polynomial with specified evaluations.
CALL FORMATS:
This function can be called in two ways:
interpolation(bound, points, values)
interpolation(bound, function)
INPUT:
bound
– either an integer bounding the total degree or a list/tuple of integers bounding the degree of the variablespoints
– list/tuple containing the evaluation pointsvalues
– list/tuple containing the desired values atpoints
function
– evaluable function in \(n\) variables, where \(n\) is the number of variables of the polynomial ring
OUTPUT:
A polynomial respecting the bounds and having
values
as values when evaluated atpoints
.A polynomial respecting the bounds and having the same values as
function
at exactly so many points so that the polynomial is unique.
EXAMPLES:
sage: def F(a, b, c): ....: return a^3*b + b + c^2 + 25 ....: sage: R.<x,y,z> = PolynomialRing(QQ) sage: R.interpolation(4, F) # needs sage.modules x^3*y + z^2 + y + 25 sage: def F(a, b, c): ....: return a^3*b + b + c^2 + 25 ....: sage: R.<x,y,z> = PolynomialRing(QQ) sage: R.interpolation([3,1,2], F) # needs sage.modules x^3*y + z^2 + y + 25 sage: def F(a, b, c): ....: return a^3*b + b + c^2 + 25 ....: sage: R.<x,y,z> = PolynomialRing(QQ) sage: points = [(5,1,1),(7,2,2),(8,5,-1),(2,5,3),(1,4,0),(5,9,0), ....: (2,7,0),(1,10,13),(0,0,1),(-1,1,0),(2,5,3),(1,1,1),(7,4,11), ....: (12,1,9),(1,1,3),(4,-1,2),(0,1,5),(5,1,3),(3,1,-2),(2,11,3), ....: (4,12,19),(3,1,1),(5,2,-3),(12,1,1),(2,3,4)] sage: R.interpolation([3,1,2], points, [F(*x) for x in points]) # needs sage.modules x^3*y + z^2 + y + 25
>>> from sage.all import * >>> def F(a, b, c): ... return a**Integer(3)*b + b + c**Integer(2) + Integer(25) ....: >>> R = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> R.interpolation(Integer(4), F) # needs sage.modules x^3*y + z^2 + y + 25 >>> def F(a, b, c): ... return a**Integer(3)*b + b + c**Integer(2) + Integer(25) ....: >>> R = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> R.interpolation([Integer(3),Integer(1),Integer(2)], F) # needs sage.modules x^3*y + z^2 + y + 25 >>> def F(a, b, c): ... return a**Integer(3)*b + b + c**Integer(2) + Integer(25) ....: >>> R = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> points = [(Integer(5),Integer(1),Integer(1)),(Integer(7),Integer(2),Integer(2)),(Integer(8),Integer(5),-Integer(1)),(Integer(2),Integer(5),Integer(3)),(Integer(1),Integer(4),Integer(0)),(Integer(5),Integer(9),Integer(0)), ... (Integer(2),Integer(7),Integer(0)),(Integer(1),Integer(10),Integer(13)),(Integer(0),Integer(0),Integer(1)),(-Integer(1),Integer(1),Integer(0)),(Integer(2),Integer(5),Integer(3)),(Integer(1),Integer(1),Integer(1)),(Integer(7),Integer(4),Integer(11)), ... (Integer(12),Integer(1),Integer(9)),(Integer(1),Integer(1),Integer(3)),(Integer(4),-Integer(1),Integer(2)),(Integer(0),Integer(1),Integer(5)),(Integer(5),Integer(1),Integer(3)),(Integer(3),Integer(1),-Integer(2)),(Integer(2),Integer(11),Integer(3)), ... (Integer(4),Integer(12),Integer(19)),(Integer(3),Integer(1),Integer(1)),(Integer(5),Integer(2),-Integer(3)),(Integer(12),Integer(1),Integer(1)),(Integer(2),Integer(3),Integer(4))] >>> R.interpolation([Integer(3),Integer(1),Integer(2)], points, [F(*x) for x in points]) # needs sage.modules x^3*y + z^2 + y + 25
ALGORITHM:
Solves a linear system of equations with the linear algebra module. If the points are not specified, it samples exactly as many points as needed for a unique solution.
Note
It will only run if the base ring is a field, even though it might work otherwise as well. If your base ring is an integral domain, let it run over the fraction field.
Also, if the solution is not unique, it spits out one solution, without any notice that there are more.
Lastly, the interpolation function for univariate polynomial rings is called
lagrange_polynomial()
.Warning
If you don’t provide point/value pairs but just a function, it will only use as many points as needed for a unique solution with the given bounds. In particular it will not notice or check whether the result yields the correct evaluation for other points as well. So if you give wrong bounds, you will get a wrong answer without any warning.
sage: def F(a, b, c): ....: return a^3*b + b + c^2 + 25 ....: sage: R.<x,y,z> = PolynomialRing(QQ) sage: R.interpolation(3, F) # needs sage.modules 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25
>>> from sage.all import * >>> def F(a, b, c): ... return a**Integer(3)*b + b + c**Integer(2) + Integer(25) ....: >>> R = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> R.interpolation(Integer(3), F) # needs sage.modules 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25
See also
- irrelevant_ideal()[source]¶
Return the irrelevant ideal of this multivariate polynomial ring.
This is the ideal generated by all of the indeterminate generators of this ring.
EXAMPLES:
sage: R.<x,y,z> = QQ[] sage: R.irrelevant_ideal() Ideal (x, y, z) 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) >>> R.irrelevant_ideal() Ideal (x, y, z) of Multivariate Polynomial Ring in x, y, z over Rational Field
- is_exact()[source]¶
Test whether this multivariate polynomial ring is defined over an exact base ring.
EXAMPLES:
sage: PolynomialRing(QQ, 2, 'x').is_exact() True sage: PolynomialRing(RDF, 2, 'x').is_exact() False
>>> from sage.all import * >>> PolynomialRing(QQ, Integer(2), 'x').is_exact() True >>> PolynomialRing(RDF, Integer(2), 'x').is_exact() False
- is_field(proof=True)[source]¶
Test whether this multivariate polynomial ring is a field.
A polynomial ring is a field when there are no variable and the base ring is a field.
EXAMPLES:
sage: PolynomialRing(QQ, 'x', 2).is_field() False sage: PolynomialRing(QQ, 'x', 0).is_field() True sage: PolynomialRing(ZZ, 'x', 0).is_field() False sage: PolynomialRing(Zmod(1), names=['x','y']).is_finite() True
>>> from sage.all import * >>> PolynomialRing(QQ, 'x', Integer(2)).is_field() False >>> PolynomialRing(QQ, 'x', Integer(0)).is_field() True >>> PolynomialRing(ZZ, 'x', Integer(0)).is_field() False >>> PolynomialRing(Zmod(Integer(1)), names=['x','y']).is_finite() True
- is_integral_domain(proof=True)[source]¶
EXAMPLES:
sage: ZZ['x,y'].is_integral_domain() True sage: Integers(8)['x,y'].is_integral_domain() False
>>> from sage.all import * >>> ZZ['x,y'].is_integral_domain() True >>> Integers(Integer(8))['x,y'].is_integral_domain() False
- is_noetherian()[source]¶
EXAMPLES:
sage: ZZ['x,y'].is_noetherian() True sage: Integers(8)['x,y'].is_noetherian() True
>>> from sage.all import * >>> ZZ['x,y'].is_noetherian() True >>> Integers(Integer(8))['x,y'].is_noetherian() True
- macaulay_resultant(*args, **kwds)[source]¶
Return the Macaulay resultant.
This computes the resultant of universal polynomials as well as polynomials with constant coefficients. This is a project done in sage days 55. It is based on the implementation in Maple by Manfred Minimair, which in turn is based on the references listed below. It calculates the Macaulay resultant for a list of polynomials, up to sign!
REFERENCES:
AUTHORS:
Hao Chen, Solomon Vishkautsan (7-2014)
INPUT:
args
– list of \(n\) homogeneous polynomials in \(n\) variables works whenargs[0]
is the list of polynomials, orargs
is itself the list of polynomials
kwds:
sparse
– boolean (default:False
); ifTrue
, the function creates sparse matrices
OUTPUT: the Macaulay resultant, an element of the base ring of
self
Todo
Working with sparse matrices should usually give faster results, but with the current implementation it actually works slower. There should be a way to improve performance with regards to this.
EXAMPLES:
The number of polynomials has to match the number of variables:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: R.macaulay_resultant([y, 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) >>> R.macaulay_resultant([y, x + z]) # needs sage.modules Traceback (most recent call last): ... TypeError: number of polynomials(= 2) must equal number of variables (= 3)
The polynomials need to be all homogeneous:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: R.macaulay_resultant([y, 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) >>> R.macaulay_resultant([y, x + z, z + x**Integer(3)]) # needs sage.modules Traceback (most recent call last): ... TypeError: resultant for non-homogeneous polynomials is not supported
All polynomials must be in the same ring:
sage: S.<x,y> = PolynomialRing(QQ, 2) sage: R.<x,y,z> = PolynomialRing(QQ,3) sage: S.macaulay_resultant([y, z+x]) # needs sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring
>>> from sage.all import * >>> S = PolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = S._first_ngens(2) >>> R = PolynomialRing(QQ,Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> S.macaulay_resultant([y, z+x]) # needs sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring
The following example recreates Proposition 2.10 in Ch.3 in [CLO2005]:
sage: K.<x,y> = PolynomialRing(ZZ, 2) sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) sage: R.macaulay_resultant(flist) # 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)]) >>> R.macaulay_resultant(flist) # 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
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: R.macaulay_resultant(flist) # 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)]) >>> R.macaulay_resultant(flist) # needs sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8
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: flist = [f0,f1,f2] sage: R.macaulay_resultant([f0,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) >>> flist = [f0,f1,f2] >>> R.macaulay_resultant([f0,f1,f2]) # needs sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27
A simple example with constant rational coefficients:
sage: R.<x,y,z,w> = PolynomialRing(QQ, 4) sage: R.macaulay_resultant([w, 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) >>> R.macaulay_resultant([w, z, y, x]) # needs sage.modules 1
An example where the resultant vanishes:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: R.macaulay_resultant([x + y, 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) >>> R.macaulay_resultant([x + y, y**Integer(2), x]) # needs sage.modules 0
An example of bad reduction at a prime \(p = 5\):
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: R.macaulay_resultant([y, 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) >>> R.macaulay_resultant([y, x**Integer(3) + Integer(25)*y**Integer(2)*x, Integer(5)*z]) # needs sage.libs.pari sage.modules 125
The input can given as an unpacked list of polynomials:
sage: R.<x,y,z> = PolynomialRing(QQ, 3) sage: R.macaulay_resultant(y, 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) >>> R.macaulay_resultant(y, x**Integer(3) + Integer(25)*y**Integer(2)*x, Integer(5)*z) # needs sage.libs.pari sage.modules 125
An example when the coefficients live in a finite field:
sage: F = FiniteField(11) sage: R.<x,y,z,w> = PolynomialRing(F, 4) sage: R.macaulay_resultant([z, 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) >>> R.macaulay_resultant([z, x**Integer(3), Integer(5)*y, w]) # needs sage.modules sage.rings.finite_rings 4
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: R.macaulay_resultant([y, 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) >>> R.macaulay_resultant([y, x + z, z**Integer(2)]) # needs sage.libs.pari sage.modules -1
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) == RH.macaulay_resultant([fh, 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) == RH.macaulay_resultant([fh, gh]) # needs sage.modules True
- monomial(*exponents)[source]¶
Return the monomial with given exponents.
EXAMPLES:
sage: R.<x,y,z> = PolynomialRing(ZZ, 3) sage: R.monomial(1,1,1) x*y*z sage: e=(1,2,3) sage: R.monomial(*e) x*y^2*z^3 sage: m = R.monomial(1,2,3) sage: R.monomial(*m.degrees()) == m True
>>> from sage.all import * >>> R = PolynomialRing(ZZ, Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> R.monomial(Integer(1),Integer(1),Integer(1)) x*y*z >>> e=(Integer(1),Integer(2),Integer(3)) >>> R.monomial(*e) x*y^2*z^3 >>> m = R.monomial(Integer(1),Integer(2),Integer(3)) >>> R.monomial(*m.degrees()) == m True
We also allow to specify the exponents in a single tuple:
sage: R.monomial(e) x*y^2*z^3
>>> from sage.all import * >>> R.monomial(e) x*y^2*z^3
- monomials_of_degree(degree)[source]¶
Return a list of all monomials of the given total degree in this multivariate polynomial ring.
EXAMPLES:
sage: # needs sage.combinat sage: R.<x,y,z> = ZZ[] sage: mons = R.monomials_of_degree(2) sage: mons [z^2, y*z, x*z, y^2, x*y, x^2] sage: P = PolynomialRing(QQ, 3, 'x, y, z', order=TermOrder('wdeglex', [1, 2, 1])) sage: P.monomials_of_degree(2) [z^2, y, x*z, x^2] sage: P = PolynomialRing(QQ, 3, 'x, y, z', order='lex') sage: P.monomials_of_degree(3) [z^3, y*z^2, y^2*z, y^3, x*z^2, x*y*z, x*y^2, x^2*z, x^2*y, x^3] sage: P = PolynomialRing(QQ, 3, 'x, y, z', order='invlex') sage: P.monomials_of_degree(3) [x^3, x^2*y, x*y^2, y^3, x^2*z, x*y*z, y^2*z, x*z^2, y*z^2, z^3]
>>> from sage.all import * >>> # needs sage.combinat >>> R = ZZ['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> mons = R.monomials_of_degree(Integer(2)) >>> mons [z^2, y*z, x*z, y^2, x*y, x^2] >>> P = PolynomialRing(QQ, Integer(3), 'x, y, z', order=TermOrder('wdeglex', [Integer(1), Integer(2), Integer(1)])) >>> P.monomials_of_degree(Integer(2)) [z^2, y, x*z, x^2] >>> P = PolynomialRing(QQ, Integer(3), 'x, y, z', order='lex') >>> P.monomials_of_degree(Integer(3)) [z^3, y*z^2, y^2*z, y^3, x*z^2, x*y*z, x*y^2, x^2*z, x^2*y, x^3] >>> P = PolynomialRing(QQ, Integer(3), 'x, y, z', order='invlex') >>> P.monomials_of_degree(Integer(3)) [x^3, x^2*y, x*y^2, y^3, x^2*z, x*y*z, y^2*z, x*z^2, y*z^2, z^3]
The number of such monomials equals \(\binom{n+k-1}{k}\) where \(n\) is the number of variables and \(k\) the degree:
sage: len(mons) == binomial(3 + 2 - 1, 2) # needs sage.combinat True
>>> from sage.all import * >>> len(mons) == binomial(Integer(3) + Integer(2) - Integer(1), Integer(2)) # needs sage.combinat True
- random_element(degree=2, terms=None, choose_degree=False, *args, **kwargs)[source]¶
Return a random polynomial of at most degree \(d\) and at most \(t\) terms.
First monomials are chosen uniformly random from the set of all possible monomials of degree up to \(d\) (inclusive). This means that it is more likely that a monomial of degree \(d\) appears than a monomial of degree \(d-1\) because the former class is bigger.
Exactly \(t\) distinct monomials are chosen this way and each one gets a random coefficient (possibly zero) from the base ring assigned.
The returned polynomial is the sum of this list of terms.
INPUT:
degree
– maximal degree (likely to be reached) (default: 2)terms
– number of terms requested (default: 5). If more terms are requested than exist, then this parameter is silently reduced to the maximum number of available terms.choose_degree
– choose degrees of monomials randomly first rather than monomials uniformly random**kwargs
– passed to the random element generator of the base ring
EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(QQ) sage: f = P.random_element(2, 5) sage: f.degree() <= 2 True sage: f.parent() is P True sage: len(list(f)) <= 5 True sage: f = P.random_element(2, 5, choose_degree=True) sage: f.degree() <= 2 True sage: f.parent() is P True sage: len(list(f)) <= 5 True
>>> from sage.all import * >>> P = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3) >>> f = P.random_element(Integer(2), Integer(5)) >>> f.degree() <= Integer(2) True >>> f.parent() is P True >>> len(list(f)) <= Integer(5) True >>> f = P.random_element(Integer(2), Integer(5), choose_degree=True) >>> f.degree() <= Integer(2) True >>> f.parent() is P True >>> len(list(f)) <= Integer(5) True
Stacked rings:
sage: R = QQ['x,y'] sage: S = R['t,u'] sage: f = S._random_nonzero_element(degree=2, terms=1) sage: len(list(f)) 1 sage: f.degree() <= 2 True sage: f.parent() is S True
>>> from sage.all import * >>> R = QQ['x,y'] >>> S = R['t,u'] >>> f = S._random_nonzero_element(degree=Integer(2), terms=Integer(1)) >>> len(list(f)) 1 >>> f.degree() <= Integer(2) True >>> f.parent() is S True
Default values apply if no degree and/or number of terms is provided:
sage: # needs sage.modules sage: M = random_matrix(QQ['x,y,z'], 2, 2) sage: all(a.degree() <= 2 for a in M.list()) True sage: all(len(list(a)) <= 5 for a in M.list()) True sage: M = random_matrix(QQ['x,y,z'], 2, 2, terms=1, degree=2) sage: all(a.degree() <= 2 for a in M.list()) True sage: all(len(list(a)) <= 1 for a in M.list()) True sage: P.random_element(0, 1) in QQ True sage: P.random_element(2, 0) 0 sage: R.<x> = PolynomialRing(Integers(3), 1) sage: f = R.random_element() sage: f.degree() <= 2 True sage: len(list(f)) <= 3 True
>>> from sage.all import * >>> # needs sage.modules >>> M = random_matrix(QQ['x,y,z'], Integer(2), Integer(2)) >>> all(a.degree() <= Integer(2) for a in M.list()) True >>> all(len(list(a)) <= Integer(5) for a in M.list()) True >>> M = random_matrix(QQ['x,y,z'], Integer(2), Integer(2), terms=Integer(1), degree=Integer(2)) >>> all(a.degree() <= Integer(2) for a in M.list()) True >>> all(len(list(a)) <= Integer(1) for a in M.list()) True >>> P.random_element(Integer(0), Integer(1)) in QQ True >>> P.random_element(Integer(2), Integer(0)) 0 >>> R = PolynomialRing(Integers(Integer(3)), Integer(1), names=('x',)); (x,) = R._first_ngens(1) >>> f = R.random_element() >>> f.degree() <= Integer(2) True >>> len(list(f)) <= Integer(3) True
To produce a dense polynomial, pick
terms=Infinity
:sage: P.<x,y,z> = GF(127)[] sage: f = P.random_element(degree=2, terms=Infinity) sage: while len(list(f)) != 10: ....: f = P.random_element(degree=2, terms=Infinity) sage: f = P.random_element(degree=3, terms=Infinity) sage: while len(list(f)) != 20: ....: f = P.random_element(degree=3, terms=Infinity) sage: f = P.random_element(degree=3, terms=Infinity, choose_degree=True) sage: while len(list(f)) != 20: ....: f = P.random_element(degree=3, terms=Infinity)
>>> from sage.all import * >>> P = GF(Integer(127))['x, y, z']; (x, y, z,) = P._first_ngens(3) >>> f = P.random_element(degree=Integer(2), terms=Infinity) >>> while len(list(f)) != Integer(10): ... f = P.random_element(degree=Integer(2), terms=Infinity) >>> f = P.random_element(degree=Integer(3), terms=Infinity) >>> while len(list(f)) != Integer(20): ... f = P.random_element(degree=Integer(3), terms=Infinity) >>> f = P.random_element(degree=Integer(3), terms=Infinity, choose_degree=True) >>> while len(list(f)) != Integer(20): ... f = P.random_element(degree=Integer(3), terms=Infinity)
The number of terms is silently reduced to the maximum available if more terms are requested:
sage: P.<x,y,z> = GF(127)[] sage: f = P.random_element(degree=2, terms=1000) sage: len(list(f)) <= 10 True
>>> from sage.all import * >>> P = GF(Integer(127))['x, y, z']; (x, y, z,) = P._first_ngens(3) >>> f = P.random_element(degree=Integer(2), terms=Integer(1000)) >>> len(list(f)) <= Integer(10) True
- remove_var(order=None, *var)[source]¶
Remove a variable or sequence of variables from
self
.If
order
is not specified, then the subring inherits the term order of the original ring, if possible.EXAMPLES:
sage: P.<x,y,z,w> = PolynomialRing(ZZ) sage: P.remove_var(z) Multivariate Polynomial Ring in x, y, w over Integer Ring sage: P.remove_var(z, x) Multivariate Polynomial Ring in y, w over Integer Ring sage: P.remove_var(y, z, x) Univariate Polynomial Ring in w over Integer Ring
>>> from sage.all import * >>> P = PolynomialRing(ZZ, names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = P._first_ngens(4) >>> P.remove_var(z) Multivariate Polynomial Ring in x, y, w over Integer Ring >>> P.remove_var(z, x) Multivariate Polynomial Ring in y, w over Integer Ring >>> P.remove_var(y, z, x) Univariate Polynomial Ring in w over Integer Ring
Removing all variables results in the base ring:
sage: P.remove_var(y, z, x, w) Integer Ring
>>> from sage.all import * >>> P.remove_var(y, z, x, w) Integer Ring
If possible, the term order is kept:
sage: R.<x,y,z,w> = PolynomialRing(ZZ, order='deglex') sage: R.remove_var(y).term_order() Degree lexicographic term order sage: R.<x,y,z,w> = PolynomialRing(ZZ, order='lex') sage: R.remove_var(y).term_order() Lexicographic term order
>>> from sage.all import * >>> R = PolynomialRing(ZZ, order='deglex', names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = R._first_ngens(4) >>> R.remove_var(y).term_order() Degree lexicographic term order >>> R = PolynomialRing(ZZ, order='lex', names=('x', 'y', 'z', 'w',)); (x, y, z, w,) = R._first_ngens(4) >>> R.remove_var(y).term_order() Lexicographic term order
Be careful with block orders when removing variables:
sage: R.<x,y,z,u,v> = PolynomialRing(ZZ, order='deglex(2),lex(3)') sage: R.remove_var(x, y, z) Traceback (most recent call last): ... ValueError: impossible to use the original term order (most likely because it was a block order). Please specify the term order for the subring sage: R.remove_var(x,y,z, order='degrevlex') Multivariate Polynomial Ring in u, v over Integer Ring
>>> from sage.all import * >>> R = PolynomialRing(ZZ, order='deglex(2),lex(3)', names=('x', 'y', 'z', 'u', 'v',)); (x, y, z, u, v,) = R._first_ngens(5) >>> R.remove_var(x, y, z) Traceback (most recent call last): ... ValueError: impossible to use the original term order (most likely because it was a block order). Please specify the term order for the subring >>> R.remove_var(x,y,z, order='degrevlex') Multivariate Polynomial Ring in u, v over Integer Ring
- repr_long()[source]¶
Return structured string representation of
self
.EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(QQ, order=TermOrder('degrevlex',1) ....: + TermOrder('lex',2)) sage: print(P.repr_long()) Polynomial Ring Base Ring : Rational Field Size : 3 Variables Block 0 : Ordering : degrevlex Names : x Block 1 : Ordering : lex Names : y, z
>>> from sage.all import * >>> P = PolynomialRing(QQ, order=TermOrder('degrevlex',Integer(1)) ... + TermOrder('lex',Integer(2)), names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3) >>> print(P.repr_long()) Polynomial Ring Base Ring : Rational Field Size : 3 Variables Block 0 : Ordering : degrevlex Names : x Block 1 : Ordering : lex Names : y, z
- some_elements()[source]¶
Return a list of polynomials.
This is typically used for running generic tests.
EXAMPLES:
sage: R.<x,y> = QQ[] sage: R.some_elements() [x, y, x + y, x^2 + x*y, 0, 1]
>>> from sage.all import * >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> R.some_elements() [x, y, x + y, x^2 + x*y, 0, 1]
- univariate_ring(x)[source]¶
Return a univariate polynomial ring whose base ring comprises all but one variables of
self
.INPUT:
x
– a variable ofself
EXAMPLES:
sage: P.<x,y,z> = QQ[] sage: P.univariate_ring(y) Univariate Polynomial Ring in y over Multivariate Polynomial Ring in x, z over Rational Field
>>> from sage.all import * >>> P = QQ['x, y, z']; (x, y, z,) = P._first_ngens(3) >>> P.univariate_ring(y) Univariate Polynomial Ring in y over Multivariate Polynomial Ring in x, z over Rational Field
- variable_names_recursive(depth=None)[source]¶
Return the list of variable names of this and its base rings, as if it were a single multi-variate polynomial.
EXAMPLES:
sage: R = QQ['x,y']['z,w'] sage: R.variable_names_recursive() ('x', 'y', 'z', 'w') sage: R.variable_names_recursive(3) ('y', 'z', 'w')
>>> from sage.all import * >>> R = QQ['x,y']['z,w'] >>> R.variable_names_recursive() ('x', 'y', 'z', 'w') >>> R.variable_names_recursive(Integer(3)) ('y', 'z', 'w')
- weyl_algebra()[source]¶
Return the Weyl algebra generated from
self
.EXAMPLES:
sage: R = QQ['x,y,z'] sage: W = R.weyl_algebra(); W # needs sage.modules Differential Weyl algebra of polynomials in x, y, z over Rational Field sage: W.polynomial_ring() == R # needs sage.modules True
>>> from sage.all import * >>> R = QQ['x,y,z'] >>> W = R.weyl_algebra(); W # needs sage.modules Differential Weyl algebra of polynomials in x, y, z over Rational Field >>> W.polynomial_ring() == R # needs sage.modules True