Generic Multivariate Polynomials#
AUTHORS:
David Joyner: first version
William Stein: use dict’s instead of lists
Martin Albrecht malb@informatik.uni-bremen.de: some functions added
William Stein (2006-02-11): added better __div__ behavior.
Kiran S. Kedlaya (2006-02-12): added Macaulay2 analogues of some Singular features
William Stein (2006-04-19): added e.g.,
f[1,3]
to get coeff of \(xy^3\); added examples of the newR.x,y = PolynomialRing(QQ,2)
notation.Martin Albrecht: improved singular coercions (restructured class hierarchy) and added ETuples
Robert Bradshaw (2007-08-14): added support for coercion of polynomials in a subset of variables (including multi-level univariate rings)
Joel B. Mohler (2008-03): Refactored interactions with ETuples.
EXAMPLES:
We verify Lagrange’s four squares identity:
sage: R.<a0,a1,a2,a3,b0,b1,b2,b3> = QQbar[] # needs sage.rings.number_field
sage: ((a0^2 + a1^2 + a2^2 + a3^2) * (b0^2 + b1^2 + b2^2 + b3^2) == # needs sage.rings.number_field
....: (a0*b0 - a1*b1 - a2*b2 - a3*b3)^2 + (a0*b1 + a1*b0 + a2*b3 - a3*b2)^2
....: + (a0*b2 - a1*b3 + a2*b0 + a3*b1)^2 + (a0*b3 + a1*b2 - a2*b1 + a3*b0)^2)
True
>>> from sage.all import *
>>> R = QQbar['a0, a1, a2, a3, b0, b1, b2, b3']; (a0, a1, a2, a3, b0, b1, b2, b3,) = R._first_ngens(8)# needs sage.rings.number_field
>>> ((a0**Integer(2) + a1**Integer(2) + a2**Integer(2) + a3**Integer(2)) * (b0**Integer(2) + b1**Integer(2) + b2**Integer(2) + b3**Integer(2)) == # needs sage.rings.number_field
... (a0*b0 - a1*b1 - a2*b2 - a3*b3)**Integer(2) + (a0*b1 + a1*b0 + a2*b3 - a3*b2)**Integer(2)
... + (a0*b2 - a1*b3 + a2*b0 + a3*b1)**Integer(2) + (a0*b3 + a1*b2 - a2*b1 + a3*b0)**Integer(2))
True
- class sage.rings.polynomial.multi_polynomial_element.MPolynomial_element(parent, x)[source]#
Bases:
MPolynomial
Generic multivariate polynomial.
This implementation is based on the
PolyDict
.Todo
As mentioned in their docstring,
PolyDict
objects never clear zeros. In all arithmetic operations onMPolynomial_element
there is an additional call to the methodremove_zeros
to clear them. This is not ideal because of the presence of inexact zeros, see Issue #35174.- hamming_weight()[source]#
Return the number of non-zero coefficients of this polynomial.
This is also called weight,
hamming_weight()
or sparsity.EXAMPLES:
sage: # needs sage.rings.real_mpfr sage: R.<x, y> = CC[] sage: f = x^3 - y sage: f.number_of_terms() 2 sage: R(0).number_of_terms() 0 sage: f = (x+y)^100 sage: f.number_of_terms() 101
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> R = CC['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(3) - y >>> f.number_of_terms() 2 >>> R(Integer(0)).number_of_terms() 0 >>> f = (x+y)**Integer(100) >>> f.number_of_terms() 101
The method
hamming_weight()
is an alias:sage: f.hamming_weight() # needs sage.rings.real_mpfr 101
>>> from sage.all import * >>> f.hamming_weight() # needs sage.rings.real_mpfr 101
- number_of_terms()[source]#
Return the number of non-zero coefficients of this polynomial.
This is also called weight,
hamming_weight()
or sparsity.EXAMPLES:
sage: # needs sage.rings.real_mpfr sage: R.<x, y> = CC[] sage: f = x^3 - y sage: f.number_of_terms() 2 sage: R(0).number_of_terms() 0 sage: f = (x+y)^100 sage: f.number_of_terms() 101
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> R = CC['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(3) - y >>> f.number_of_terms() 2 >>> R(Integer(0)).number_of_terms() 0 >>> f = (x+y)**Integer(100) >>> f.number_of_terms() 101
The method
hamming_weight()
is an alias:sage: f.hamming_weight() # needs sage.rings.real_mpfr 101
>>> from sage.all import * >>> f.hamming_weight() # needs sage.rings.real_mpfr 101
- class sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict(parent, x)[source]#
Bases:
Polynomial_singular_repr
,MPolynomial_element
Multivariate polynomials implemented in pure python using polydicts.
- coefficient(degrees)[source]#
Return the coefficient of the variables with the degrees specified in the python dictionary
degrees
. Mathematically, this is the coefficient in the base ring adjoined by the variables of this ring not listed indegrees
. However, the result has the same parent as this polynomial.This function contrasts with the function
monomial_coefficient
which returns the coefficient in the base ring of a monomial.INPUT:
degrees
– Can be any of:a dictionary of degree restrictions
a list of degree restrictions (with None in the unrestricted variables)
a monomial (very fast, but not as flexible)
OUTPUT: element of the parent of
self
See also
For coefficients of specific monomials, look at
monomial_coefficient()
.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x, y> = QQbar[] sage: f = 2 * x * y sage: c = f.coefficient({x: 1, y: 1}); c 2 sage: c.parent() Multivariate Polynomial Ring in x, y over Algebraic Field sage: c in PolynomialRing(QQbar, 2, names=['x', 'y']) True sage: f = y^2 - x^9 - 7*x + 5*x*y sage: f.coefficient({y: 1}) 5*x sage: f.coefficient({y: 0}) -x^9 + (-7)*x sage: f.coefficient({x: 0, y: 0}) 0 sage: f = (1+y+y^2) * (1+x+x^2) sage: f.coefficient({x: 0}) y^2 + y + 1 sage: f.coefficient([0, None]) y^2 + y + 1 sage: f.coefficient(x) y^2 + y + 1 sage: # Be aware that this may not be what you think! sage: # The physical appearance of the variable x is deceiving -- particularly if the exponent would be a variable. sage: f.coefficient(x^0) # outputs the full polynomial x^2*y^2 + x^2*y + x*y^2 + x^2 + x*y + y^2 + x + y + 1
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(2) * x * y >>> c = f.coefficient({x: Integer(1), y: Integer(1)}); c 2 >>> c.parent() Multivariate Polynomial Ring in x, y over Algebraic Field >>> c in PolynomialRing(QQbar, Integer(2), names=['x', 'y']) True >>> f = y**Integer(2) - x**Integer(9) - Integer(7)*x + Integer(5)*x*y >>> f.coefficient({y: Integer(1)}) 5*x >>> f.coefficient({y: Integer(0)}) -x^9 + (-7)*x >>> f.coefficient({x: Integer(0), y: Integer(0)}) 0 >>> f = (Integer(1)+y+y**Integer(2)) * (Integer(1)+x+x**Integer(2)) >>> f.coefficient({x: Integer(0)}) y^2 + y + 1 >>> f.coefficient([Integer(0), None]) y^2 + y + 1 >>> f.coefficient(x) y^2 + y + 1 >>> # Be aware that this may not be what you think! >>> # The physical appearance of the variable x is deceiving -- particularly if the exponent would be a variable. >>> f.coefficient(x**Integer(0)) # outputs the full polynomial x^2*y^2 + x^2*y + x*y^2 + x^2 + x*y + y^2 + x + y + 1
sage: # needs sage.rings.real_mpfr sage: R.<x,y> = RR[] sage: f = x*y + 5 sage: c = f.coefficient({x: 0, y: 0}); c 5.00000000000000 sage: parent(c) Multivariate Polynomial Ring in x, y over Real Field with 53 bits of precision
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> R = RR['x, y']; (x, y,) = R._first_ngens(2) >>> f = x*y + Integer(5) >>> c = f.coefficient({x: Integer(0), y: Integer(0)}); c 5.00000000000000 >>> parent(c) Multivariate Polynomial Ring in x, y over Real Field with 53 bits of precision
AUTHORS:
Joel B. Mohler (2007-10-31)
- constant_coefficient()[source]#
Return the constant coefficient of this multivariate polynomial.
EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.constant_coefficient() 5 sage: f = 3*x^2 sage: f.constant_coefficient() 0
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.constant_coefficient() 5 >>> f = Integer(3)*x**Integer(2) >>> f.constant_coefficient() 0
- degree(x=None, std_grading=False)[source]#
Return the degree of
self
inx
, wherex
must be one of the generators for the parent ofself
.INPUT:
x
– multivariate polynomial (a generator of the parent ofself
). Ifx
is not specified (or is None), return the total degree, which is the maximum degree of any monomial. Note that a weighted term ordering alters the grading of the generators of the ring; see the tests below. To avoid this behavior, set the optional argumentstd_grading=True
.
OUTPUT: integer
EXAMPLES:
sage: R.<x,y> = RR[] sage: f = y^2 - x^9 - x sage: f.degree(x) 9 sage: f.degree(y) 2 sage: (y^10*x - 7*x^2*y^5 + 5*x^3).degree(x) 3 sage: (y^10*x - 7*x^2*y^5 + 5*x^3).degree(y) 10
>>> from sage.all import * >>> R = RR['x, y']; (x, y,) = R._first_ngens(2) >>> f = y**Integer(2) - x**Integer(9) - x >>> f.degree(x) 9 >>> f.degree(y) 2 >>> (y**Integer(10)*x - Integer(7)*x**Integer(2)*y**Integer(5) + Integer(5)*x**Integer(3)).degree(x) 3 >>> (y**Integer(10)*x - Integer(7)*x**Integer(2)*y**Integer(5) + Integer(5)*x**Integer(3)).degree(y) 10
Note that total degree takes into account if we are working in a polynomial ring with a weighted term order.
sage: R = PolynomialRing(QQ, 'x,y', order=TermOrder('wdeglex',(2,3))) sage: x,y = R.gens() sage: x.degree() 2 sage: y.degree() 3 sage: x.degree(y), x.degree(x), y.degree(x), y.degree(y) (0, 1, 0, 1) sage: f = x^2*y + x*y^2 sage: f.degree(x) 2 sage: f.degree(y) 2 sage: f.degree() 8 sage: f.degree(std_grading=True) 3
>>> from sage.all import * >>> R = PolynomialRing(QQ, 'x,y', order=TermOrder('wdeglex',(Integer(2),Integer(3)))) >>> x,y = R.gens() >>> x.degree() 2 >>> y.degree() 3 >>> x.degree(y), x.degree(x), y.degree(x), y.degree(y) (0, 1, 0, 1) >>> f = x**Integer(2)*y + x*y**Integer(2) >>> f.degree(x) 2 >>> f.degree(y) 2 >>> f.degree() 8 >>> f.degree(std_grading=True) 3
Note that if
x
is not a generator of the parent ofself
, for example if it is a generator of a polynomial algebra which maps naturally to this one, then it is converted to an element of this algebra. (This fixes the problem reported in Issue #17366.)sage: x, y = ZZ['x','y'].gens() sage: GF(3037000453)['x','y'].gen(0).degree(x) # needs sage.rings.finite_rings 1 sage: x0, y0 = QQ['x','y'].gens() sage: GF(3037000453)['x','y'].gen(0).degree(x0) # needs sage.rings.finite_rings Traceback (most recent call last): ... TypeError: x must canonically coerce to parent sage: GF(3037000453)['x','y'].gen(0).degree(x^2) # needs sage.rings.finite_rings Traceback (most recent call last): ... TypeError: x must be one of the generators of the parent
>>> from sage.all import * >>> x, y = ZZ['x','y'].gens() >>> GF(Integer(3037000453))['x','y'].gen(Integer(0)).degree(x) # needs sage.rings.finite_rings 1 >>> x0, y0 = QQ['x','y'].gens() >>> GF(Integer(3037000453))['x','y'].gen(Integer(0)).degree(x0) # needs sage.rings.finite_rings Traceback (most recent call last): ... TypeError: x must canonically coerce to parent >>> GF(Integer(3037000453))['x','y'].gen(Integer(0)).degree(x**Integer(2)) # needs sage.rings.finite_rings Traceback (most recent call last): ... TypeError: x must be one of the generators of the parent
- degrees()[source]#
Returns a tuple (precisely - an
ETuple
) with the degree of each variable in this polynomial. The list of degrees is, of course, ordered by the order of the generators.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y,z> = PolynomialRing(QQbar) sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.degrees() (2, 2, 0) sage: f = x^2 + z^2 sage: f.degrees() (2, 0, 2) sage: f.total_degree() # this simply illustrates that total degree is not the sum of the degrees 2 sage: R.<x,y,z,u> = PolynomialRing(QQbar) sage: f = (1-x) * (1+y+z+x^3)^5 sage: f.degrees() (16, 5, 5, 0) sage: R(0).degrees() (0, 0, 0, 0)
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = PolynomialRing(QQbar, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.degrees() (2, 2, 0) >>> f = x**Integer(2) + z**Integer(2) >>> f.degrees() (2, 0, 2) >>> f.total_degree() # this simply illustrates that total degree is not the sum of the degrees 2 >>> R = PolynomialRing(QQbar, names=('x', 'y', 'z', 'u',)); (x, y, z, u,) = R._first_ngens(4) >>> f = (Integer(1)-x) * (Integer(1)+y+z+x**Integer(3))**Integer(5) >>> f.degrees() (16, 5, 5, 0) >>> R(Integer(0)).degrees() (0, 0, 0, 0)
- dict()[source]#
Return underlying dictionary with keys the exponents and values the coefficients of this polynomial.
- exponents(as_ETuples=True)[source]#
Return the exponents of the monomials appearing in
self
.INPUT:
as_ETuples
– (default:True
): return the list of exponents as a list of ETuples
OUTPUT:
The list of exponents as a list of ETuples or tuples.
EXAMPLES:
sage: R.<a,b,c> = PolynomialRing(QQbar, 3) # needs sage.rings.number_field sage: f = a^3 + b + 2*b^2 # needs sage.rings.number_field sage: f.exponents() # needs sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)]
>>> from sage.all import * >>> R = PolynomialRing(QQbar, Integer(3), names=('a', 'b', 'c',)); (a, b, c,) = R._first_ngens(3)# needs sage.rings.number_field >>> f = a**Integer(3) + b + Integer(2)*b**Integer(2) # needs sage.rings.number_field >>> f.exponents() # needs sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)]
By default the list of exponents is a list of ETuples:
sage: type(f.exponents()[0]) # needs sage.rings.number_field <class 'sage.rings.polynomial.polydict.ETuple'> sage: type(f.exponents(as_ETuples=False)[0]) # needs sage.rings.number_field <... 'tuple'>
>>> from sage.all import * >>> type(f.exponents()[Integer(0)]) # needs sage.rings.number_field <class 'sage.rings.polynomial.polydict.ETuple'> >>> type(f.exponents(as_ETuples=False)[Integer(0)]) # needs sage.rings.number_field <... 'tuple'>
- factor(proof=None)[source]#
Compute the irreducible factorization of this polynomial.
INPUT:
proof
– insist on provably correct results (default:True
unless explicitly disabled for the"polynomial"
subsystem withsage.structure.proof.proof.WithProof
.)
- global_height(prec=None)[source]#
Return the (projective) global height of the polynomial.
This returns the absolute logarithmic height of the coefficients thought of as a projective point.
INPUT:
prec
– desired floating point precision (default: defaultRealField
precision).
OUTPUT: a real number.
EXAMPLES:
sage: R.<x,y> = PolynomialRing(QQbar, 2) # needs sage.rings.number_field sage: f = QQbar(i)*x^2 + 3*x*y # needs sage.rings.number_field sage: f.global_height() # needs sage.rings.number_field 1.09861228866811
>>> from sage.all import * >>> R = PolynomialRing(QQbar, Integer(2), names=('x', 'y',)); (x, y,) = R._first_ngens(2)# needs sage.rings.number_field >>> f = QQbar(i)*x**Integer(2) + Integer(3)*x*y # needs sage.rings.number_field >>> f.global_height() # needs sage.rings.number_field 1.09861228866811
Scaling should not change the result:
sage: # needs sage.rings.number_field sage.symbolic sage: R.<x, y> = PolynomialRing(QQbar, 2) sage: f = 1/25*x^2 + 25/3*x + 1 + QQbar(sqrt(2))*y^2 sage: f.global_height() 6.43775164973640 sage: g = 100 * f sage: g.global_height() 6.43775164973640
>>> from sage.all import * >>> # needs sage.rings.number_field sage.symbolic >>> R = PolynomialRing(QQbar, Integer(2), names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(1)/Integer(25)*x**Integer(2) + Integer(25)/Integer(3)*x + Integer(1) + QQbar(sqrt(Integer(2)))*y**Integer(2) >>> f.global_height() 6.43775164973640 >>> g = Integer(100) * f >>> g.global_height() 6.43775164973640
sage: # needs sage.rings.number_field sage: R.<x> = QQ[] sage: K.<k> = NumberField(x^2 + 1) sage: Q.<q,r> = PolynomialRing(K, implementation='generic') sage: f = 12 * q sage: f.global_height() 0.000000000000000
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQ['x']; (x,) = R._first_ngens(1) >>> K = NumberField(x**Integer(2) + Integer(1), names=('k',)); (k,) = K._first_ngens(1) >>> Q = PolynomialRing(K, implementation='generic', names=('q', 'r',)); (q, r,) = Q._first_ngens(2) >>> f = Integer(12) * q >>> f.global_height() 0.000000000000000
sage: R.<x,y> = PolynomialRing(QQ, implementation='generic') sage: f = 1/123*x*y + 12 sage: f.global_height(prec=2) # needs sage.symbolic 8.0
>>> from sage.all import * >>> R = PolynomialRing(QQ, implementation='generic', names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(1)/Integer(123)*x*y + Integer(12) >>> f.global_height(prec=Integer(2)) # needs sage.symbolic 8.0
sage: R.<x,y> = PolynomialRing(QQ, implementation='generic') sage: f = 0*x*y sage: f.global_height() # needs sage.rings.real_mpfr 0.000000000000000
>>> from sage.all import * >>> R = PolynomialRing(QQ, implementation='generic', names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(0)*x*y >>> f.global_height() # needs sage.rings.real_mpfr 0.000000000000000
- integral(var=None)[source]#
Integrate
self
with respect to variablevar
.Note
The integral is always chosen so the constant term is 0.
If
var
is not one of the generators of this ring,integral(var)
is called recursively on each coefficient of this polynomial.EXAMPLES:
On polynomials with rational coefficients:
sage: x, y = PolynomialRing(QQ, 'x, y').gens() sage: ex = x*y + x - y sage: it = ex.integral(x); it 1/2*x^2*y + 1/2*x^2 - x*y sage: it.parent() == x.parent() True sage: R = ZZ['x']['y, z'] sage: y, z = R.gens() sage: R.an_element().integral(y).parent() Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in x over Rational Field
>>> from sage.all import * >>> x, y = PolynomialRing(QQ, 'x, y').gens() >>> ex = x*y + x - y >>> it = ex.integral(x); it 1/2*x^2*y + 1/2*x^2 - x*y >>> it.parent() == x.parent() True >>> R = ZZ['x']['y, z'] >>> y, z = R.gens() >>> R.an_element().integral(y).parent() Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in x over Rational Field
On polynomials with coefficients in power series:
sage: # needs sage.rings.number_field sage: R.<t> = PowerSeriesRing(QQbar) 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: f.parent() Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field sage: f.integral(x) # with respect to x (1/3*t^2 + O(t^3))*x^3*y^3 + (37/4*t^4 + O(t^5))*x^4 sage: f.integral(x).parent() Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field sage: f.integral(y) # with respect to y (1/4*t^2 + O(t^3))*x^2*y^4 + (37*t^4 + O(t^5))*x^3*y sage: f.integral(t) # with respect to t (recurses into base ring) (1/3*t^3 + O(t^4))*x^2*y^3 + (37/5*t^5 + O(t^6))*x^3
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = PowerSeriesRing(QQbar, 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) >>> f.parent() Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field >>> f.integral(x) # with respect to x (1/3*t^2 + O(t^3))*x^3*y^3 + (37/4*t^4 + O(t^5))*x^4 >>> f.integral(x).parent() Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field >>> f.integral(y) # with respect to y (1/4*t^2 + O(t^3))*x^2*y^4 + (37*t^4 + O(t^5))*x^3*y >>> f.integral(t) # with respect to t (recurses into base ring) (1/3*t^3 + O(t^4))*x^2*y^3 + (37/5*t^5 + O(t^6))*x^3
- is_constant()[source]#
Return
True
ifself
is a constant andFalse
otherwise.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.is_constant() False sage: g = 10*x^0 sage: g.is_constant() True
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.is_constant() False >>> g = Integer(10)*x**Integer(0) >>> g.is_constant() True
- is_generator()[source]#
Return
True
ifself
is a generator of its parent.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: x.is_generator() True sage: (x + y - y).is_generator() True sage: (x*y).is_generator() False
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> x.is_generator() True >>> (x + y - y).is_generator() True >>> (x*y).is_generator() False
- is_homogeneous()[source]#
Return
True
ifself
is a homogeneous polynomial.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: (x + y).is_homogeneous() True sage: (x.parent()(0)).is_homogeneous() True sage: (x + y^2).is_homogeneous() False sage: (x^2 + y^2).is_homogeneous() True sage: (x^2 + y^2*x).is_homogeneous() False sage: (x^2*y + y^2*x).is_homogeneous() True
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> (x + y).is_homogeneous() True >>> (x.parent()(Integer(0))).is_homogeneous() True >>> (x + y**Integer(2)).is_homogeneous() False >>> (x**Integer(2) + y**Integer(2)).is_homogeneous() True >>> (x**Integer(2) + y**Integer(2)*x).is_homogeneous() False >>> (x**Integer(2)*y + y**Integer(2)*x).is_homogeneous() True
- is_monomial()[source]#
Return
True
ifself
is a monomial, which we define to be a product of generators with coefficient 1.Use
is_term()
to allow the coefficient to not be 1.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: x.is_monomial() True sage: (x + 2*y).is_monomial() False sage: (2*x).is_monomial() False sage: (x*y).is_monomial() True
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> x.is_monomial() True >>> (x + Integer(2)*y).is_monomial() False >>> (Integer(2)*x).is_monomial() False >>> (x*y).is_monomial() True
To allow a non-1 leading coefficient, use
is_term()
:sage: (2*x*y).is_term() # needs sage.rings.number_field True sage: (2*x*y).is_monomial() # needs sage.rings.number_field False
>>> from sage.all import * >>> (Integer(2)*x*y).is_term() # needs sage.rings.number_field True >>> (Integer(2)*x*y).is_monomial() # needs sage.rings.number_field False
- is_term()[source]#
Return
True
ifself
is a term, which we define to be a product of generators times some coefficient, which need not be 1.Use
is_monomial()
to require that the coefficient be 1.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: x.is_term() True sage: (x + 2*y).is_term() False sage: (2*x).is_term() True sage: (7*x^5*y).is_term() True
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> x.is_term() True >>> (x + Integer(2)*y).is_term() False >>> (Integer(2)*x).is_term() True >>> (Integer(7)*x**Integer(5)*y).is_term() True
To require leading coefficient 1, use
is_monomial()
:sage: (2*x*y).is_monomial() # needs sage.rings.number_field False sage: (2*x*y).is_term() # needs sage.rings.number_field True
>>> from sage.all import * >>> (Integer(2)*x*y).is_monomial() # needs sage.rings.number_field False >>> (Integer(2)*x*y).is_term() # needs sage.rings.number_field True
- is_univariate()[source]#
Return
True
if this multivariate polynomial is univariate and False otherwise.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.is_univariate() False sage: g = f.subs({x: 10}); g 700*y^2 + (-2)*y + 305 sage: g.is_univariate() True sage: f = x^0 sage: f.is_univariate() True
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.is_univariate() False >>> g = f.subs({x: Integer(10)}); g 700*y^2 + (-2)*y + 305 >>> g.is_univariate() True >>> f = x**Integer(0) >>> f.is_univariate() True
- iterator_exp_coeff(as_ETuples=True)[source]#
Iterate over
self
as pairs of ((E)Tuple, coefficient).INPUT:
as_ETuples
– (default:True
) ifTrue
iterate over pairs whose first element is an ETuple, otherwise as a tuples
EXAMPLES:
sage: R.<x,y,z> = PolynomialRing(QQbar, order='lex') # needs sage.rings.number_field sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # needs sage.rings.number_field sage: list(f.iterator_exp_coeff()) # needs sage.rings.number_field [((4, 1, 3), 1), ((2, 0, 1), 1), ((1, 5, 2), 1)] sage: R.<x,y,z> = PolynomialRing(QQbar, order='deglex') # needs sage.rings.number_field sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # needs sage.rings.number_field sage: list(f.iterator_exp_coeff(as_ETuples=False)) # needs sage.rings.number_field [((4, 1, 3), 1), ((1, 5, 2), 1), ((2, 0, 1), 1)]
>>> from sage.all import * >>> R = PolynomialRing(QQbar, order='lex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)# needs sage.rings.number_field >>> f = (x**Integer(1)*y**Integer(5)*z**Integer(2) + x**Integer(2)*z + x**Integer(4)*y**Integer(1)*z**Integer(3)) # needs sage.rings.number_field >>> list(f.iterator_exp_coeff()) # needs sage.rings.number_field [((4, 1, 3), 1), ((2, 0, 1), 1), ((1, 5, 2), 1)] >>> R = PolynomialRing(QQbar, order='deglex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3)# needs sage.rings.number_field >>> f = (x**Integer(1)*y**Integer(5)*z**Integer(2) + x**Integer(2)*z + x**Integer(4)*y**Integer(1)*z**Integer(3)) # needs sage.rings.number_field >>> list(f.iterator_exp_coeff(as_ETuples=False)) # needs sage.rings.number_field [((4, 1, 3), 1), ((1, 5, 2), 1), ((2, 0, 1), 1)]
- lc()[source]#
Returns the leading coefficient of
self
, i.e.,self.coefficient(self.lm())
EXAMPLES:
sage: R.<x,y,z> = QQbar[] # needs sage.rings.number_field sage: f = 3*x^2 - y^2 - x*y # needs sage.rings.number_field sage: f.lc() # needs sage.rings.number_field 3
>>> from sage.all import * >>> R = QQbar['x, y, z']; (x, y, z,) = R._first_ngens(3)# needs sage.rings.number_field >>> f = Integer(3)*x**Integer(2) - y**Integer(2) - x*y # needs sage.rings.number_field >>> f.lc() # needs sage.rings.number_field 3
- lift(I)[source]#
Given an ideal \(I = (f_1,...,f_r)\) and some \(g\) (=
self
) in \(I\), find \(s_1,...,s_r\) such that \(g = s_1 f_1 + ... + s_r f_r\).ALGORITHM: Use Singular.
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
- lm()[source]#
Return the lead monomial of
self
with respect to the term order ofself.parent()
.EXAMPLES:
sage: R.<x,y,z> = PolynomialRing(GF(7), 3, order='lex') sage: (x^1*y^2 + y^3*z^4).lm() x*y^2 sage: (x^3*y^2*z^4 + x^3*y^2*z^1).lm() x^3*y^2*z^4
>>> from sage.all import * >>> R = PolynomialRing(GF(Integer(7)), Integer(3), order='lex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> (x**Integer(1)*y**Integer(2) + y**Integer(3)*z**Integer(4)).lm() x*y^2 >>> (x**Integer(3)*y**Integer(2)*z**Integer(4) + x**Integer(3)*y**Integer(2)*z**Integer(1)).lm() x^3*y^2*z^4
sage: # needs sage.rings.real_mpfr sage: R.<x,y,z> = PolynomialRing(CC, 3, order='deglex') sage: (x^1*y^2*z^3 + x^3*y^2*z^0).lm() x*y^2*z^3 sage: (x^1*y^2*z^4 + x^1*y^1*z^5).lm() x*y^2*z^4
>>> from sage.all import * >>> # needs sage.rings.real_mpfr >>> R = PolynomialRing(CC, Integer(3), order='deglex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> (x**Integer(1)*y**Integer(2)*z**Integer(3) + x**Integer(3)*y**Integer(2)*z**Integer(0)).lm() x*y^2*z^3 >>> (x**Integer(1)*y**Integer(2)*z**Integer(4) + x**Integer(1)*y**Integer(1)*z**Integer(5)).lm() x*y^2*z^4
sage: # needs sage.rings.number_field sage: R.<x,y,z> = PolynomialRing(QQbar, 3, order='degrevlex') sage: (x^1*y^5*z^2 + x^4*y^1*z^3).lm() x*y^5*z^2 sage: (x^4*y^7*z^1 + x^4*y^2*z^3).lm() x^4*y^7*z
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = PolynomialRing(QQbar, Integer(3), order='degrevlex', names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> (x**Integer(1)*y**Integer(5)*z**Integer(2) + x**Integer(4)*y**Integer(1)*z**Integer(3)).lm() x*y^5*z^2 >>> (x**Integer(4)*y**Integer(7)*z**Integer(1) + x**Integer(4)*y**Integer(2)*z**Integer(3)).lm() x^4*y^7*z
- local_height(v, prec=None)[source]#
Return the maximum of the local height of the coefficients of this polynomial.
INPUT:
v
– a prime or prime ideal of the base ring.prec
– desired floating point precision (default: default RealField precision).
OUTPUT: a real number.
EXAMPLES:
sage: R.<x,y> = PolynomialRing(QQ, implementation='generic') sage: f = 1/1331*x^2 + 1/4000*y sage: f.local_height(1331) # needs sage.rings.real_mpfr 7.19368581839511
>>> from sage.all import * >>> R = PolynomialRing(QQ, implementation='generic', names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(1)/Integer(1331)*x**Integer(2) + Integer(1)/Integer(4000)*y >>> f.local_height(Integer(1331)) # needs sage.rings.real_mpfr 7.19368581839511
sage: # needs sage.rings.number_field sage: R.<x> = QQ[] sage: K.<k> = NumberField(x^2 - 5) sage: T.<t,w> = PolynomialRing(K, implementation='generic') sage: I = K.ideal(3) sage: f = 1/3*t*w + 3 sage: f.local_height(I) # needs sage.symbolic 1.09861228866811
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQ['x']; (x,) = R._first_ngens(1) >>> K = NumberField(x**Integer(2) - Integer(5), names=('k',)); (k,) = K._first_ngens(1) >>> T = PolynomialRing(K, implementation='generic', names=('t', 'w',)); (t, w,) = T._first_ngens(2) >>> I = K.ideal(Integer(3)) >>> f = Integer(1)/Integer(3)*t*w + Integer(3) >>> f.local_height(I) # needs sage.symbolic 1.09861228866811
sage: R.<x,y> = PolynomialRing(QQ, implementation='generic') sage: f = 1/2*x*y + 2 sage: f.local_height(2, prec=2) # needs sage.rings.real_mpfr 0.75
>>> from sage.all import * >>> R = PolynomialRing(QQ, implementation='generic', names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(1)/Integer(2)*x*y + Integer(2) >>> f.local_height(Integer(2), prec=Integer(2)) # needs sage.rings.real_mpfr 0.75
- local_height_arch(i, prec=None)[source]#
Return the maximum of the local height at the
i
-th infinite place of the coefficients of this polynomial.INPUT:
i
– an integer.prec
– desired floating point precision (default: defaultRealField
precision).
OUTPUT: a real number.
EXAMPLES:
sage: R.<x,y> = PolynomialRing(QQ, implementation='generic') sage: f = 210*x*y sage: f.local_height_arch(0) # needs sage.rings.real_mpfr 5.34710753071747
>>> from sage.all import * >>> R = PolynomialRing(QQ, implementation='generic', names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(210)*x*y >>> f.local_height_arch(Integer(0)) # needs sage.rings.real_mpfr 5.34710753071747
sage: # needs sage.rings.number_field sage: R.<x> = QQ[] sage: K.<k> = NumberField(x^2 - 5) sage: T.<t,w> = PolynomialRing(K, implementation='generic') sage: f = 1/2*t*w + 3 sage: f.local_height_arch(1, prec=52) 1.09861228866811
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQ['x']; (x,) = R._first_ngens(1) >>> K = NumberField(x**Integer(2) - Integer(5), names=('k',)); (k,) = K._first_ngens(1) >>> T = PolynomialRing(K, implementation='generic', names=('t', 'w',)); (t, w,) = T._first_ngens(2) >>> f = Integer(1)/Integer(2)*t*w + Integer(3) >>> f.local_height_arch(Integer(1), prec=Integer(52)) 1.09861228866811
sage: R.<x,y> = PolynomialRing(QQ, implementation='generic') sage: f = 1/2*x*y + 3 sage: f.local_height_arch(0, prec=2) # needs sage.rings.real_mpfr 1.0
>>> from sage.all import * >>> R = PolynomialRing(QQ, implementation='generic', names=('x', 'y',)); (x, y,) = R._first_ngens(2) >>> f = Integer(1)/Integer(2)*x*y + Integer(3) >>> f.local_height_arch(Integer(0), prec=Integer(2)) # needs sage.rings.real_mpfr 1.0
- lt()[source]#
Return the leading term of
self
i.e.,self.lc()*self.lm()
. The notion of “leading term” depends on the ordering defined in the parent ring.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y,z> = PolynomialRing(QQbar) sage: f = 3*x^2 - y^2 - x*y sage: f.lt() 3*x^2 sage: R.<x,y,z> = PolynomialRing(QQbar, order="invlex") sage: f = 3*x^2 - y^2 - x*y sage: f.lt() -y^2
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = PolynomialRing(QQbar, names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(3)*x**Integer(2) - y**Integer(2) - x*y >>> f.lt() 3*x^2 >>> R = PolynomialRing(QQbar, order="invlex", names=('x', 'y', 'z',)); (x, y, z,) = R._first_ngens(3) >>> f = Integer(3)*x**Integer(2) - y**Integer(2) - x*y >>> f.lt() -y^2
- monomial_coefficient(mon)[source]#
Return the coefficient in the base ring of the monomial
mon
inself
, wheremon
must have the same parent asself
.This function contrasts with the function
coefficient
which returns the coefficient of a monomial viewing this polynomial in a polynomial ring over a base ring having fewer variables.INPUT:
mon
– a monomial
OUTPUT: coefficient in base ring
See also
For coefficients in a base ring of fewer variables, look at
coefficient()
.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 2 * x * y sage: c = f.monomial_coefficient(x*y); c 2 sage: c.parent() Algebraic Field
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(2) * x * y >>> c = f.monomial_coefficient(x*y); c 2 >>> c.parent() Algebraic Field
sage: # needs sage.rings.number_field sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y sage: f.monomial_coefficient(y^2) 1 sage: f.monomial_coefficient(x*y) 5 sage: f.monomial_coefficient(x^9) -1 sage: f.monomial_coefficient(x^10) 0
>>> from sage.all import * >>> # needs sage.rings.number_field >>> f = y**Integer(2) + y**Integer(2)*x - x**Integer(9) - Integer(7)*x + Integer(5)*x*y >>> f.monomial_coefficient(y**Integer(2)) 1 >>> f.monomial_coefficient(x*y) 5 >>> f.monomial_coefficient(x**Integer(9)) -1 >>> f.monomial_coefficient(x**Integer(10)) 0
sage: # needs sage.rings.number_field sage: a = polygen(ZZ, 'a') sage: K.<a> = NumberField(a^2 + a + 1) sage: P.<x,y> = K[] sage: f = (a*x - 1) * ((a+1)*y - 1); f -x*y + (-a)*x + (-a - 1)*y + 1 sage: f.monomial_coefficient(x) -a
>>> from sage.all import * >>> # needs sage.rings.number_field >>> a = polygen(ZZ, 'a') >>> K = NumberField(a**Integer(2) + a + Integer(1), names=('a',)); (a,) = K._first_ngens(1) >>> P = K['x, y']; (x, y,) = P._first_ngens(2) >>> f = (a*x - Integer(1)) * ((a+Integer(1))*y - Integer(1)); f -x*y + (-a)*x + (-a - 1)*y + 1 >>> f.monomial_coefficient(x) -a
- monomials()[source]#
Return the list of monomials in
self
. The returned list is decreasingly ordered by the term ordering ofself.parent()
.OUTPUT: list of
MPolynomial
instances, representing monomialsEXAMPLES:
sage: R.<x,y> = QQbar[] # needs sage.rings.number_field sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # needs sage.rings.number_field sage: f.monomials() # needs sage.rings.number_field [x^2*y^2, x^2, y, 1]
>>> from sage.all import * >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2)# needs sage.rings.number_field >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) # needs sage.rings.number_field >>> f.monomials() # needs sage.rings.number_field [x^2*y^2, x^2, y, 1]
sage: # needs sage.rings.number_field sage: R.<fx,fy,gx,gy> = QQbar[] sage: F = (fx*gy - fy*gx)^3; F -fy^3*gx^3 + 3*fx*fy^2*gx^2*gy + (-3)*fx^2*fy*gx*gy^2 + fx^3*gy^3 sage: F.monomials() [fy^3*gx^3, fx*fy^2*gx^2*gy, fx^2*fy*gx*gy^2, fx^3*gy^3] sage: F.coefficients() [-1, 3, -3, 1] sage: sum(map(mul, zip(F.coefficients(), F.monomials()))) == F True
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['fx, fy, gx, gy']; (fx, fy, gx, gy,) = R._first_ngens(4) >>> F = (fx*gy - fy*gx)**Integer(3); F -fy^3*gx^3 + 3*fx*fy^2*gx^2*gy + (-3)*fx^2*fy*gx*gy^2 + fx^3*gy^3 >>> F.monomials() [fy^3*gx^3, fx*fy^2*gx^2*gy, fx^2*fy*gx*gy^2, fx^3*gy^3] >>> F.coefficients() [-1, 3, -3, 1] >>> sum(map(mul, zip(F.coefficients(), F.monomials()))) == F True
- nvariables()[source]#
Return the number of variables in this polynomial.
EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.nvariables() 2 sage: g = f.subs({x: 10}); g 700*y^2 + (-2)*y + 305 sage: g.nvariables() 1
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.nvariables() 2 >>> g = f.subs({x: Integer(10)}); g 700*y^2 + (-2)*y + 305 >>> g.nvariables() 1
- quo_rem(right)[source]#
Returns quotient and remainder of
self
andright
.EXAMPLES:
sage: R.<x,y> = CC[] # needs sage.rings.real_mpfr sage: f = y*x^2 + x + 1 # needs sage.rings.real_mpfr sage: f.quo_rem(x) # needs sage.libs.singular sage.rings.real_mpfr (x*y + 1.00000000000000, 1.00000000000000) sage: R = QQ['a','b']['x','y','z'] sage: p1 = R('a + (1+2*b)*x*y + (3-a^2)*z') sage: p2 = R('x-1') sage: p1.quo_rem(p2) # needs sage.libs.singular ((2*b + 1)*y, (2*b + 1)*y + (-a^2 + 3)*z + a) sage: R.<x,y> = Qp(5)[] # needs sage.rings.padics sage: x.quo_rem(y) # needs sage.libs.singular sage.rings.padics Traceback (most recent call last): ... TypeError: no conversion of this ring to a Singular ring defined
>>> from sage.all import * >>> R = CC['x, y']; (x, y,) = R._first_ngens(2)# needs sage.rings.real_mpfr >>> f = y*x**Integer(2) + x + Integer(1) # needs sage.rings.real_mpfr >>> f.quo_rem(x) # needs sage.libs.singular sage.rings.real_mpfr (x*y + 1.00000000000000, 1.00000000000000) >>> R = QQ['a','b']['x','y','z'] >>> p1 = R('a + (1+2*b)*x*y + (3-a^2)*z') >>> p2 = R('x-1') >>> p1.quo_rem(p2) # needs sage.libs.singular ((2*b + 1)*y, (2*b + 1)*y + (-a^2 + 3)*z + a) >>> R = Qp(Integer(5))['x, y']; (x, y,) = R._first_ngens(2)# needs sage.rings.padics >>> x.quo_rem(y) # needs sage.libs.singular sage.rings.padics Traceback (most recent call last): ... TypeError: no conversion of this ring to a Singular ring defined
ALGORITHM: Use Singular.
- reduce(I)[source]#
Reduce this polynomial by the polynomials in \(I\).
INPUT:
I
– a list of polynomials or an ideal
EXAMPLES:
sage: # needs sage.rings.number_field sage: P.<x,y,z> = QQbar[] sage: f1 = -2 * x^2 + x^3 sage: f2 = -2 * y + x * y sage: f3 = -x^2 + y^2 sage: F = Ideal([f1, f2, f3]) sage: g = x*y - 3*x*y^2 sage: g.reduce(F) # needs sage.libs.singular (-6)*y^2 + 2*y sage: g.reduce(F.gens()) # needs sage.libs.singular (-6)*y^2 + 2*y
>>> from sage.all import * >>> # needs sage.rings.number_field >>> P = QQbar['x, y, z']; (x, y, z,) = P._first_ngens(3) >>> f1 = -Integer(2) * x**Integer(2) + x**Integer(3) >>> f2 = -Integer(2) * y + x * y >>> f3 = -x**Integer(2) + y**Integer(2) >>> F = Ideal([f1, f2, f3]) >>> g = x*y - Integer(3)*x*y**Integer(2) >>> g.reduce(F) # needs sage.libs.singular (-6)*y^2 + 2*y >>> g.reduce(F.gens()) # needs sage.libs.singular (-6)*y^2 + 2*y
sage: f = 3*x # needs sage.rings.number_field sage: f.reduce([2*x, y]) # needs sage.rings.number_field 0
>>> from sage.all import * >>> f = Integer(3)*x # needs sage.rings.number_field >>> f.reduce([Integer(2)*x, y]) # needs sage.rings.number_field 0
sage: # needs sage.rings.number_field sage: k.<w> = CyclotomicField(3) sage: A.<y9,y12,y13,y15> = PolynomialRing(k) sage: J = [y9 + y12] sage: f = y9 - y12; f.reduce(J) -2*y12 sage: f = y13*y15; f.reduce(J) y13*y15 sage: f = y13*y15 + y9 - y12; f.reduce(J) y13*y15 - 2*y12
>>> from sage.all import * >>> # needs sage.rings.number_field >>> k = CyclotomicField(Integer(3), names=('w',)); (w,) = k._first_ngens(1) >>> A = PolynomialRing(k, names=('y9', 'y12', 'y13', 'y15',)); (y9, y12, y13, y15,) = A._first_ngens(4) >>> J = [y9 + y12] >>> f = y9 - y12; f.reduce(J) -2*y12 >>> f = y13*y15; f.reduce(J) y13*y15 >>> f = y13*y15 + y9 - y12; f.reduce(J) y13*y15 - 2*y12
Make sure the remainder returns the correct type, fixing Issue #13903:
sage: R.<y1,y2> = PolynomialRing(Qp(5), 2, order='lex') # needs sage.rings.padics sage: G = [y1^2 + y2^2, y1*y2 + y2^2, y2^3] # needs sage.rings.padics sage: type((y2^3).reduce(G)) # needs sage.rings.padics <class 'sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict'>
>>> from sage.all import * >>> R = PolynomialRing(Qp(Integer(5)), Integer(2), order='lex', names=('y1', 'y2',)); (y1, y2,) = R._first_ngens(2)# needs sage.rings.padics >>> G = [y1**Integer(2) + y2**Integer(2), y1*y2 + y2**Integer(2), y2**Integer(3)] # needs sage.rings.padics >>> type((y2**Integer(3)).reduce(G)) # needs sage.rings.padics <class 'sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict'>
- resultant(other, variable=None)[source]#
Compute the resultant of
self
andother
with respect tovariable
.If a second argument is not provided, the first variable of
self.parent()
is chosen.For inexact rings or rings not available in Singular, this computes the determinant of the Sylvester matrix.
INPUT:
other
– polynomial inself.parent()
variable
– (optional) variable (of type polynomial) inself.parent()
EXAMPLES:
sage: P.<x,y> = PolynomialRing(QQ, 2) sage: a = x + y sage: b = x^3 - y^3 sage: a.resultant(b) # needs sage.libs.singular -2*y^3 sage: a.resultant(b, y) # needs sage.libs.singular 2*x^3
>>> from sage.all import * >>> P = PolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = P._first_ngens(2) >>> a = x + y >>> b = x**Integer(3) - y**Integer(3) >>> a.resultant(b) # needs sage.libs.singular -2*y^3 >>> a.resultant(b, y) # needs sage.libs.singular 2*x^3
- subresultants(other, variable=None)[source]#
Return the nonzero subresultant polynomials of
self
andother
.INPUT:
other
– a polynomial
OUTPUT: a list of polynomials in the same ring as
self
EXAMPLES:
sage: # needs sage.libs.singular sage.rings.number_field sage: R.<x,y> = QQbar[] 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 * >>> # needs sage.libs.singular sage.rings.number_field >>> R = QQbar['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]
- subs(fixed=None, **kwds)[source]#
Fix some given variables in a given multivariate polynomial and return the changed multivariate polynomials. The polynomial itself is not affected. The variable, value pairs for fixing are to be provided as a dictionary of the form
{variable: value}
.This is a special case of evaluating the polynomial with some of the variables constants and the others the original variables.
INPUT:
fixed
– (optional) dictionary of inputs**kwds
– named parameters
OUTPUT: new
MPolynomial
EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = x^2 + y + x^2*y^2 + 5 sage: f((5, y)) 25*y^2 + y + 30 sage: f.subs({x: 5}) 25*y^2 + y + 30
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = x**Integer(2) + y + x**Integer(2)*y**Integer(2) + Integer(5) >>> f((Integer(5), y)) 25*y^2 + y + 30 >>> f.subs({x: Integer(5)}) 25*y^2 + y + 30
- total_degree()[source]#
Return the total degree of
self
, which is the maximum degree of any monomial inself
.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y,z> = QQbar[] sage: f = 2*x*y^3*z^2 sage: f.total_degree() 6 sage: f = 4*x^2*y^2*z^3 sage: f.total_degree() 7 sage: f = 99*x^6*y^3*z^9 sage: f.total_degree() 18 sage: f = x*y^3*z^6 + 3*x^2 sage: f.total_degree() 10 sage: f = z^3 + 8*x^4*y^5*z sage: f.total_degree() 10 sage: f = z^9 + 10*x^4 + y^8*x^2 sage: f.total_degree() 10
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y, z']; (x, y, z,) = R._first_ngens(3) >>> f = Integer(2)*x*y**Integer(3)*z**Integer(2) >>> f.total_degree() 6 >>> f = Integer(4)*x**Integer(2)*y**Integer(2)*z**Integer(3) >>> f.total_degree() 7 >>> f = Integer(99)*x**Integer(6)*y**Integer(3)*z**Integer(9) >>> f.total_degree() 18 >>> f = x*y**Integer(3)*z**Integer(6) + Integer(3)*x**Integer(2) >>> f.total_degree() 10 >>> f = z**Integer(3) + Integer(8)*x**Integer(4)*y**Integer(5)*z >>> f.total_degree() 10 >>> f = z**Integer(9) + Integer(10)*x**Integer(4) + y**Integer(8)*x**Integer(2) >>> f.total_degree() 10
- univariate_polynomial(R=None)[source]#
Returns a univariate polynomial associated to this multivariate polynomial.
INPUT:
R
– (default: None)PolynomialRing
If this polynomial is not in at most one variable, then a
ValueError
exception is raised. This is checked using the methodis_univariate()
. The newPolynomial
is over the same base ring as the givenMPolynomial
.EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.univariate_polynomial() Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable sage: g = f.subs({x: 10}); g 700*y^2 + (-2)*y + 305 sage: g.univariate_polynomial() 700*y^2 - 2*y + 305 sage: g.univariate_polynomial(PolynomialRing(QQ, 'z')) 700*z^2 - 2*z + 305
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.univariate_polynomial() Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable >>> g = f.subs({x: Integer(10)}); g 700*y^2 + (-2)*y + 305 >>> g.univariate_polynomial() 700*y^2 - 2*y + 305 >>> g.univariate_polynomial(PolynomialRing(QQ, 'z')) 700*z^2 - 2*z + 305
- variable(i)[source]#
Return the \(i\)-th variable occurring in this polynomial.
EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.variable(0) x sage: f.variable(1) y
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.variable(Integer(0)) x >>> f.variable(Integer(1)) y
- variables()[source]#
Returns the tuple of variables occurring in this polynomial.
EXAMPLES:
sage: # needs sage.rings.number_field sage: R.<x,y> = QQbar[] sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 sage: f.variables() (x, y) sage: g = f.subs({x: 10}); g 700*y^2 + (-2)*y + 305 sage: g.variables() (y,)
>>> from sage.all import * >>> # needs sage.rings.number_field >>> R = QQbar['x, y']; (x, y,) = R._first_ngens(2) >>> f = Integer(3)*x**Integer(2) - Integer(2)*y + Integer(7)*x**Integer(2)*y**Integer(2) + Integer(5) >>> f.variables() (x, y) >>> g = f.subs({x: Integer(10)}); g 700*y^2 + (-2)*y + 305 >>> g.variables() (y,)
- sage.rings.polynomial.multi_polynomial_element.degree_lowest_rational_function(r, x)[source]#
Return the difference of valuations of
r
with respect to variablex
.INPUT:
r
– a multivariate rational functionx
– a multivariate polynomial ring generator
OUTPUT: integer – the difference \(val_x(p) - val_x(q)\) where \(r = p/q\)
Note
This function should be made a method of the
FractionFieldElement
class.EXAMPLES:
sage: R1 = PolynomialRing(FiniteField(5), 3, names=["a", "b", "c"]) sage: F = FractionField(R1) sage: a,b,c = R1.gens() sage: f = 3*a*b^2*c^3 + 4*a*b*c sage: g = a^2*b*c^2 + 2*a^2*b^4*c^7
>>> from sage.all import * >>> R1 = PolynomialRing(FiniteField(Integer(5)), Integer(3), names=["a", "b", "c"]) >>> F = FractionField(R1) >>> a,b,c = R1.gens() >>> f = Integer(3)*a*b**Integer(2)*c**Integer(3) + Integer(4)*a*b*c >>> g = a**Integer(2)*b*c**Integer(2) + Integer(2)*a**Integer(2)*b**Integer(4)*c**Integer(7)
Consider the quotient \(f/g = \frac{4 + 3 bc^{2}}{ac + 2 ab^{3}c^{6}}\) (note the cancellation).
sage: # needs sage.rings.finite_rings sage: r = f/g; r (-2*b*c^2 - 1)/(2*a*b^3*c^6 + a*c) sage: degree_lowest_rational_function(r, a) -1 sage: degree_lowest_rational_function(r, b) 0 sage: degree_lowest_rational_function(r, c) -1
>>> from sage.all import * >>> # needs sage.rings.finite_rings >>> r = f/g; r (-2*b*c^2 - 1)/(2*a*b^3*c^6 + a*c) >>> degree_lowest_rational_function(r, a) -1 >>> degree_lowest_rational_function(r, b) 0 >>> degree_lowest_rational_function(r, c) -1