Sage Reference Manual: Polynomials: Release 8.6
Sage Reference Manual: Polynomials: Release 8.6
Sage Reference Manual: Polynomials: Release 8.6
Release 8.6
1 Polynomial Rings 1
1.1 Constructors for polynomial rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Univariate Polynomials 9
2.1 Univariate Polynomials and Polynomial Rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Generic Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
2.3 Fast calculation of cyclotomic polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
i
Bibliography 661
Index 665
ii
CHAPTER
ONE
POLYNOMIAL RINGS
This module provides the function PolynomialRing(), which constructs rings of univariate and multivariate poly-
nomials, and implements caching to prevent the same ring being created in memory multiple times (which is wasteful
and breaks the general assumption in Sage that parents are unique).
There is also a function BooleanPolynomialRing_constructor(), used for constructing Boolean polyno-
mial rings, which are not technically polynomial rings but rather quotients of them (see module sage.rings.
polynomial.pbori for more details).
sage.rings.polynomial.polynomial_ring_constructor.BooleanPolynomialRing_constructor(n=None,
names=N
or-
der=’lex’
Construct a boolean polynomial ring with the following parameters:
INPUT:
• n – number of variables (an integer > 1)
• names – names of ring variables, may be a string or list/tuple of strings
• order – term order (default: lex)
EXAMPLES:
sage: R.<x, y, z> = BooleanPolynomialRing() # indirect doctest
sage: R
Boolean PolynomialRing in x, y, z
sage: R.term_order()
Lexicographic term order
sage: R = BooleanPolynomialRing(5,'x',order='deglex(3),deglex(2)')
sage: R.term_order()
Block term order with blocks:
(Degree lexicographic term order of length 3,
Degree lexicographic term order of length 2)
sage: R = BooleanPolynomialRing(3,'x',order='degneglex')
sage: R.term_order()
(continues on next page)
1
Sage Reference Manual: Polynomials, Release 8.6
sage: BooleanPolynomialRing(names=('x','y'))
Boolean PolynomialRing in x, y
sage: BooleanPolynomialRing(names='x,y')
Boolean PolynomialRing in x, y
sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing(base_ring,
*args,
**kwds)
Return the globally unique univariate or multivariate polynomial ring with given properties and variable name
or names.
There are many ways to specify the variables for the polynomial ring:
1. PolynomialRing(base_ring, name, ...)
2. PolynomialRing(base_ring, names, ...)
3. PolynomialRing(base_ring, n, names, ...)
4. PolynomialRing(base_ring, n, ..., var_array=var_array, ...)
The ... at the end of these commands stands for additional keywords, like sparse or order.
INPUT:
• base_ring – a ring
• n – an integer
• name – a string
• names – a list or tuple of names (strings), or a comma separated string
• var_array – a list or tuple of names, or a comma separated string
• sparse – bool: whether or not elements are sparse. The default is a dense representation
(sparse=False) for univariate rings and a sparse representation (sparse=True) for multivariate
rings.
• order – string or TermOrder object, e.g.,
– 'degrevlex' (default) – degree reverse lexicographic
– 'lex' – lexicographic
– 'deglex' – degree lexicographic
– TermOrder('deglex',3) + TermOrder('deglex',3) – block ordering
• implementation – string or None; selects an implementation in cases where Sage includes mul-
tiple choices (currently Z[𝑥] can be implemented with 'NTL' or 'FLINT'; default is 'FLINT').
For many base rings, the "singular" implementation is available. One can always specify
implementation="generic" for a generic Sage implementation which does not use any special-
ized library.
Note: If the given implementation does not exist for rings with the given number of generators and the given
sparsity, then an error results.
OUTPUT:
Use the diamond brackets notation to make the variable ready for use after you define the ring:
sage: PolynomialRing(QQ)
Traceback (most recent call last):
...
TypeError: you must specify the names of the variables
In fact, since the diamond brackets on the left determine the variable name, you can omit the variable from the
square brackets:
sage: R is PolynomialRing(QQ,'zz')
True
Sage has two implementations of univariate polynomials over the integers, one based on NTL and one based
on FLINT. The default is FLINT. Note that FLINT uses a “more dense” representation for its polynomials than
NTL, so in particular, creating a polynomial like 2^1000000 * x^1000000 in FLINT may be unwise.
There is a coercion from the non-default to the default implementation, so the values can be mixed in a single
expression:
The result of such an expression will use the default, i.e., the FLINT implementation:
2. PolynomialRing(base_ring, names, . . . )
sage: R is S
True
sage: S is T
True
Note that a univariate polynomial ring is returned, if the list of names is of length one. If it is of length zero, a
multivariate polynomial ring with no variables is returned.
sage: PolynomialRing(QQ,["x"])
Univariate Polynomial Ring in x over Rational Field
sage: PolynomialRing(QQ,[])
Multivariate Polynomial Ring in no variables over Rational Field
The Singular implementation always returns a multivariate ring, even for 1 variable:
Note that a multivariate polynomial ring is returned when an explicit number is given.
sage: PolynomialRing(QQ,"x",1)
Multivariate Polynomial Ring in x over Rational Field
sage: PolynomialRing(QQ,"x",0)
Multivariate Polynomial Ring in no variables over Rational Field
It is easy in Python to create fairly arbitrary variable names. For example, here is a ring with generators labeled
by the primes less than 100:
˓→Integer Ring
By calling the inject_variables() method, all those variable names are available for interactive use:
sage: R.inject_variables()
Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47,
˓→x53, x59, x61, x67, x71, x73, x79, x83, x89, x97
4. PolynomialRing(base_ring, n, . . . , var_array=var_array, . . . )
This creates an array of variables where each variables begins with an entry in var_array and is indexed from
0 to 𝑛 − 1.
The array is always at least 2-dimensional. So, if var_array is a single string and only a single number 𝑛 is
given, this creates an 𝑛 × 𝑛 array of variables:
sage: RR["x"]
Univariate Polynomial Ring in x over Real Field with 53 bits of precision
sage: RR["x,y"]
Multivariate Polynomial Ring in x, y over Real Field with 53 bits of precision
sage: P.<x,y> = RR[]; P
Multivariate Polynomial Ring in x, y over Real Field with 53 bits of precision
This notation does not allow to set any of the optional arguments.
Changing variable names
Consider
You can’t just globally change the names of those variables. This is because objects all over Sage could have
pointers to that polynomial ring.
sage: R._assign_names(['z','w'])
Traceback (most recent call last):
...
ValueError: variable names cannot be changed after object creation.
However, you can very easily change the names within a with block:
After the with block the names revert to what they were before:
sage: print(f)
x^2 - 2*y^2
sage.rings.polynomial.polynomial_ring_constructor.polynomial_default_category(base_ring_categor
n_variables)
Choose an appropriate category for a polynomial ring.
It is assumed that the corresponding base ring is nonzero.
INPUT:
• base_ring_category – The category of ring over which the polynomial ring shall be defined
• n_variables – number of variables
EXAMPLES:
True
sage: polynomial_default_category(Fields(),1) is EuclideanDomains() &
˓→Algebras(Fields()).Infinite()
True
sage: polynomial_default_category(Fields(),2) is UniqueFactorizationDomains() &
˓→CommutativeAlgebras(Fields()).Infinite()
True
True
sage: QQ['s','t'].category() is UniqueFactorizationDomains() &
˓→CommutativeAlgebras(QQ.category()).Infinite()
True
sage: QQ['s']['t'].category() is UniqueFactorizationDomains() &
˓→CommutativeAlgebras(QQ['s'].category()).Infinite()
True
sage.rings.polynomial.polynomial_ring_constructor.unpickle_PolynomialRing(base_ring,
arg1=None,
arg2=None,
sparse=False)
Custom unpickling function for polynomial rings.
This has the same positional arguments as the old PolynomialRing constructor before trac ticket #23338.
TWO
UNIVARIATE POLYNOMIALS
Sage’s architecture for polynomials ‘under the hood’ is complex, interfacing to a variety of C/C++ libraries for poly-
nomials over specific rings. In practice, the user rarely has to worry about which backend is being used.
The hierarchy of class inheritance is somewhat confusing, since most of the polynomial element classes are imple-
mented as Cython extension types rather than pure Python classes and thus can only inherit from a single base class,
whereas others have multiple bases.
Sage implements sparse and dense polynomials over commutative and non-commutative rings. In the non-
commutative case, the polynomial variable commutes with the elements of the base ring.
AUTHOR:
• William Stein
• Kiran Kedlaya (2006-02-13): added macaulay2 option
• Martin Albrecht (2006-08-25): removed it again as it isn’t needed anymore
• Simon King (2011-05): Dense and sparse polynomial rings must not be equal.
• Simon King (2011-10): Choice of categories for polynomial rings.
EXAMPLES:
sage: z = QQ['z'].0
sage: (z^3 + z - 1)^3
z^9 + 3*z^7 - 3*z^6 + 3*z^5 - 6*z^4 + 4*z^3 - 3*z^2 + 3*z - 1
Rings with different variable names are not equal; in fact, by trac ticket #9944, polynomial rings are equal if and only
if they are identical (which should be the case for all parent structures in Sage):
9
Sage Reference Manual: Polynomials, Release 8.6
trac ticket #9944 introduced some changes related with coercion. Previously, a dense and a sparse polynomial ring
with the same variable name over the same base ring evaluated equal, but of course they were not identical.Coercion
maps are cached - but if a coercion to a dense ring is requested and a coercion to a sparse ring is returned instead (since
the cache keys are equal!), all hell breaks loose.
Therefore, the coercion between rings of sparse and dense polynomials works as follows:
It may be that one has rings of dense or sparse polynomials over different base rings. In that situation, coercion works
by means of the pushout() formalism:
Similarly, there is a coercion from the (non-default) NTL implementation for univariate polynomials over the integers
to the default FLINT implementation, but not vice versa:
class sage.rings.polynomial.polynomial_ring.PolynomialRing_cdvf(base_ring,
name=None,
sparse=False,
ele-
ment_class=None,
cate-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_cdvr, sage.rings.
polynomial.polynomial_ring.PolynomialRing_field
A class for polynomial ring over complete discrete valuation fields
class sage.rings.polynomial.polynomial_ring.PolynomialRing_cdvr(base_ring,
name=None,
sparse=False,
ele-
ment_class=None,
cate-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_integral_domain
A class for polynomial ring over complete discrete valuation rings
class sage.rings.polynomial.polynomial_ring.PolynomialRing_commutative(base_ring,
name=None,
sparse=False,
ele-
ment_class=None,
cat-
e-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_general, sage.
rings.ring.CommutativeAlgebra
Univariate polynomial ring over a commutative ring.
quotient_by_principal_ideal(f, names=None)
Return the quotient of this polynomial ring by the principal ideal (generated by) 𝑓 .
INPUT:
• f - either a polynomial in self, or a principal ideal of self.
EXAMPLES:
The same example, using the polynomial instead of the ideal, and customizing the variable name:
weyl_algebra()
Return the Weyl algebra generated from self.
EXAMPLES:
sage: R = QQ['x']
sage: W = R.weyl_algebra(); W
Differential Weyl algebra of polynomials in x over Rational Field
sage: W.polynomial_ring() == R
True
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_finite_field(base_ring,
name=’x’,
el-
e-
ment_class=None,
im-
ple-
men-
ta-
tion=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_field
Univariate polynomial ring over a finite field.
EXAMPLES:
irreducible_element(n, algorithm=None)
Construct a monic irreducible polynomial of degree 𝑛.
INPUT:
• n – integer: degree of the polynomial to construct
• algorithm – string: algorithm to use, or None
– 'random': try random polynomials until an irreducible one is found.
– 'first_lexicographic': try polynomials in lexicographic order until an irreducible one
is found.
OUTPUT:
A monic irreducible polynomial of degree 𝑛 in self.
EXAMPLES:
AUTHORS:
• Peter Bruin (June 2013)
• Jean-Pierre Flori (May 2014)
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_mod_n(base_ring,
name=None,
ele-
ment_class=None,
im-
ple-
men-
ta-
tion=None,
cat-
e-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_commutative
modulus()
EXAMPLES:
residue_field(ideal, names=None)
Return the residue finite field at the given ideal.
EXAMPLES:
sage: k.list()
[0, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1, 1]
sage: R.residue_field(t)
Residue field of Principal ideal (t) of Univariate Polynomial Ring in t over
˓→Finite Field of size 2 (using GF2X)
sage: P = R.irreducible_element(8) * R
sage: P
Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in
˓→t over Finite Field of size 2 (using GF2X)
sage: k.cardinality()
256
sage: R.residue_field(t^2 + 1)
Traceback (most recent call last):
...
ArithmeticError: ideal is not maximal
sage: R.residue_field(0)
Traceback (most recent call last):
...
ArithmeticError: ideal is not maximal
sage: R.residue_field(1)
Traceback (most recent call last):
...
ArithmeticError: ideal is not maximal
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_mod_p(base_ring,
name=’x’,
im-
ple-
men-
ta-
tion=None,
cat-
e-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_finite_field,
sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_mod_n, sage.
rings.polynomial.polynomial_singular_interface.PolynomialRing_singular_repr
irreducible_element(n, algorithm=None)
Construct a monic irreducible polynomial of degree 𝑛.
INPUT:
• n – integer: the degree of the polynomial to construct
• algorithm – string: algorithm to use, or None. Currently available options are:
– 'adleman-lenstra': a variant of the Adleman–Lenstra algorithm as implemented in
PARI.
– 'conway': look up the Conway polynomial of degree 𝑛 over the field of 𝑝 elements in the
database; raise a RuntimeError if it is not found.
– 'ffprimroot': use the ffprimroot() function from PARI.
– 'first_lexicographic': return the lexicographically smallest irreducible polynomial of
degree 𝑛.
– 'minimal_weight': return an irreducible polynomial of degree 𝑛 with minimal number of
non-zero coefficients. Only implemented for 𝑝 = 2.
– 'primitive': return a polynomial 𝑓 such that a root of 𝑓 generates the multiplicative group
of the finite field extension defined by 𝑓 . This uses the Conway polynomial if possible, otherwise
it uses ffprimroot.
– 'random': try random polynomials until an irreducible one is found.
If algorithm is None, use 𝑥 − 1 in degree 1. In degree > 1, the Conway polynomial is used if
it is found in the database. Otherwise, the algorithm minimal_weight is used if 𝑝 = 2, and the
algorithm adleman-lenstra if 𝑝 > 2.
OUTPUT:
A monic irreducible polynomial of degree 𝑛 in self.
EXAMPLES:
sage: GF(5)['x'].irreducible_element(2)
x^2 + 4*x + 2
sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra")
x^2 + x + 1
sage: GF(5)['x'].irreducible_element(2, algorithm="primitive")
x^2 + 4*x + 2
sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic")
x^32 + 2
sage: GF(5)['x'].irreducible_element(32, algorithm="conway")
Traceback (most recent call last):
...
RuntimeError: requested Conway polynomial not in database.
sage: GF(5)['x'].irreducible_element(32, algorithm="primitive")
x^32 + ...
In characteristic 2:
sage: GF(2)['x'].irreducible_element(33)
x^33 + x^13 + x^12 + x^11 + x^10 + x^8 + x^6 + x^3 + 1
sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight")
x^33 + x^10 + 1
In degree 1:
sage: GF(97)['x'].irreducible_element(1)
x + 96
sage: GF(97)['x'].irreducible_element(1, algorithm="conway")
x + 92
sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra")
x
AUTHORS:
• Peter Bruin (June 2013)
• Jeroen Demeyer (September 2014): add “ffprimroot” algorithm, see trac ticket #8373.
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_field_capped_relativ
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_field_generic
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_field_generic(base_rin
name=N
el-
e-
ment_cla
cat-
e-
gory=No
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_cdvf
A class for dense polynomial ring over padic fields
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_capped_absolute
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_generic
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_capped_relative
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_generic
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_fixed_mod(base_r
name=
el-
e-
ment_c
cat-
e-
gory=N
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_generic
class sage.rings.polynomial.polynomial_ring.PolynomialRing_dense_padic_ring_generic(base_ring
name=No
el-
e-
ment_clas
cat-
e-
gory=Non
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_cdvr
A class for dense polynomial ring over padic rings
class sage.rings.polynomial.polynomial_ring.PolynomialRing_field(base_ring,
name=’x’,
sparse=False,
ele-
ment_class=None,
cate-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_integral_domain,
sage.rings.ring.PrincipalIdealDomain
divided_difference(points, full_table=False)
Return the Newton divided-difference coefficients of the Lagrange interpolation polynomial through
points.
INPUT:
• points – a list of pairs (𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), . . . , (𝑥𝑛 , 𝑦𝑛 ) of elements of the base ring of self, where
𝑥𝑖 − 𝑥𝑗 is invertible for 𝑖 ̸= 𝑗. This method converts the 𝑥𝑖 and 𝑦𝑖 into the base ring of 𝑠𝑒𝑙𝑓 .
• full_table – boolean (default: False): If True, return the full divided-difference table. If
False, only return entries along the main diagonal; these are the Newton divided-difference coeffi-
cients 𝐹𝑖,𝑖 .
OUTPUT:
The Newton divided-difference coefficients of the 𝑛-th Lagrange interpolation polynomial 𝑃𝑛 (𝑥) that
passes through the points in points (see lagrange_polynomial()). These are the coefficients
𝐹0,0 , 𝐹1,1 , . . . , ‘𝐹𝑛,𝑛 in the base ring of self such that
𝑛
∑︁ 𝑖−1
∏︁
𝑃𝑛 (𝑥) = 𝐹𝑖,𝑖 (𝑥 − 𝑥𝑗 )
𝑖=0 𝑗=0
EXAMPLES:
Only return the divided-difference coefficients 𝐹𝑖,𝑖 . This example is taken from Example 1, page 121 of
[BF05]:
sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), (1.9, 0.
˓→2818186), (2.2, 0.1103623)]
The following example is taken from Example 4.12, page 225 of [MF99]:
sage: points = [(1, -3), (2, 0), (3, 15), (4, 48), (5, 105), (6, 192)]
sage: R = PolynomialRing(QQ, "x")
sage: R.divided_difference(points)
[-3, 3, 6, 1, 0, 0]
sage: R.divided_difference(points, full_table=True)
[[-3],
[0, 3],
[15, 15, 6],
[48, 33, 9, 1],
[105, 57, 12, 1, 0],
[192, 87, 15, 1, 0, 0]]
REFERENCES:
fraction_field()
Returns the fraction field of self.
EXAMPLES:
EXAMPLES:
By default, we use the method of divided differences:
REFERENCES:
class sage.rings.polynomial.polynomial_ring.PolynomialRing_general(base_ring,
name=None,
sparse=False,
ele-
ment_class=None,
cate-
gory=None)
Bases: sage.rings.ring.Algebra
Univariate polynomial ring over a ring.
base_extend(R)
Return the base extension of this polynomial ring to R.
EXAMPLES:
change_ring(R)
Return the polynomial ring in the same variable as self over R.
EXAMPLES:
sage: R.change_ring(GF(19^2,'b'))
Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2
change_var(var)
Return the polynomial ring in variable var over the same base ring.
EXAMPLES:
characteristic()
Return the characteristic of this polynomial ring, which is the same as that of its base ring.
EXAMPLES:
sage: R.characteristic()
0
sage: S = R.change_ring(GF(19^2,'b')); S
(continues on next page)
construction()
cyclotomic_polynomial(n)
Return the nth cyclotomic polynomial as a polynomial in this polynomial ring. For details
of the implementation, see the documentation for sage.rings.polynomial.cyclotomic.
cyclotomic_coeffs().
EXAMPLES:
sage: R = ZZ['x']
sage: R.cyclotomic_polynomial(8)
x^4 + 1
sage: R.cyclotomic_polynomial(12)
x^4 - x^2 + 1
sage: S = PolynomialRing(FiniteField(7), 'x')
sage: S.cyclotomic_polynomial(12)
x^4 + 6*x^2 + 1
sage: S.cyclotomic_polynomial(1)
x + 6
extend_variables(added_names, order=’degrevlex’)
Returns a multivariate polynomial ring with the same base ring but with added_names as additional vari-
ables.
EXAMPLES:
sage: R.<x> = ZZ[]; R
Univariate Polynomial Ring in x over Integer Ring
sage: R.extend_variables('y, z')
Multivariate Polynomial Ring in x, y, z over Integer Ring
sage: R.extend_variables(('y', 'z'))
Multivariate Polynomial Ring in x, y, z over Integer Ring
flattening_morphism()
Return the flattening morphism of this polynomial ring
EXAMPLES:
sage: QQ['a','b']['x'].flattening_morphism()
Flattening morphism:
From: Univariate Polynomial Ring in x over Multivariate Polynomial Ring in
˓→a, b over Rational Field
sage: QQ['x'].flattening_morphism()
Identity endomorphism of Univariate Polynomial Ring in x over Rational Field
gen(n=0)
Return the indeterminate generator of this polynomial ring.
EXAMPLES:
sage: t is R.gen()
True
gens_dict()
Return a dictionary whose entries are {name:variable,...}, where name stands for the variable
names of this object (as strings) and variable stands for the corresponding generators (as elements of
this object).
EXAMPLES:
is_exact()
EXAMPLES:
is_field(proof=True)
Return False, since polynomial rings are never fields.
EXAMPLES:
is_finite()
Return False since polynomial rings are not finite (unless the base ring is 0.)
EXAMPLES:
sage: R = Integers(1)['x']
sage: R.is_finite()
True
sage: R = GF(7)['x']
sage: R.is_finite()
False
sage: R['x']['y'].is_finite()
False
is_integral_domain(proof=True)
EXAMPLES:
sage: ZZ['x'].is_integral_domain()
True
sage: Integers(8)['x'].is_integral_domain()
False
is_noetherian()
is_sparse()
Return true if elements of this polynomial ring have a sparse representation.
EXAMPLES:
is_unique_factorization_domain(proof=True)
EXAMPLES:
sage: ZZ['x'].is_unique_factorization_domain()
True
sage: Integers(8)['x'].is_unique_factorization_domain()
False
karatsuba_threshold()
Return the Karatsuba threshold used for this ring by the method _mul_karatsuba to fall back to the school-
book algorithm.
EXAMPLES:
sage: K = QQ['x']
sage: K.karatsuba_threshold()
8
sage: K = QQ['x']['y']
sage: K.karatsuba_threshold()
0
krull_dimension()
Return the Krull dimension of this polynomial ring, which is one more than the Krull dimension of the
base ring.
EXAMPLES:
sage: R.<x> = QQ[]
sage: R.krull_dimension()
1
sage: R.<z> = GF(9,'a')[]; R
Univariate Polynomial Ring in z over Finite Field in a of size 3^2
sage: R.krull_dimension()
1
sage: S.<t> = R[]
sage: S.krull_dimension()
2
sage: for n in range(10):
....: S = PolynomialRing(S,'w')
sage: S.krull_dimension()
12
monics(of_degree=None, max_degree=None)
Return an iterator over the monic polynomials of specified degree.
INPUT: Pass exactly one of:
• max_degree - an int; the iterator will generate all monic polynomials which have degree less than
or equal to max_degree
• of_degree - an int; the iterator will generate all monic polynomials which have degree of_degree
OUTPUT: an iterator
EXAMPLES:
sage: P = PolynomialRing(GF(4,'a'),'y')
sage: for p in P.monics( of_degree = 2 ): print(p)
y^2
y^2 + a
y^2 + a + 1
y^2 + 1
y^2 + a* y
y^2 + a* y + a
y^2 + a* y + a + 1
y^2 + a* y + 1
y^2 + (a + 1)*y
y^2 + (a + 1)*y + a
y^2 + (a + 1)*y + a + 1
y^2 + (a + 1)*y + 1
y^2 + y
y^2 + y + a
(continues on next page)
AUTHORS:
• Joel B. Mohler
ngens()
Return the number of generators of this polynomial ring, which is 1 since it is a univariate polynomial ring.
EXAMPLES:
sage: R.<z> = Integers(8)[]; R
Univariate Polynomial Ring in z over Ring of integers modulo 8
sage: R.ngens()
1
parameter()
Return the generator of this polynomial ring.
This is the same as self.gen().
polynomials(of_degree=None, max_degree=None)
Return an iterator over the polynomials of specified degree.
INPUT: Pass exactly one of:
• max_degree - an int; the iterator will generate all polynomials which have degree less than or equal
to max_degree
• of_degree - an int; the iterator will generate all polynomials which have degree of_degree
OUTPUT: an iterator
EXAMPLES:
sage: P = PolynomialRing(GF(3),'y')
sage: for p in P.polynomials( of_degree = 2 ): print(p)
y^2
y^2 + 1
y^2 + 2
y^2 + y
y^2 + y + 1
y^2 + y + 2
y^2 + 2* y
y^2 + 2* y + 1
y^2 + 2* y + 2
2*y^2
2*y^2 + 1
2*y^2 + 2
(continues on next page)
AUTHORS:
• Joel B. Mohler
random_element(degree=(-1, 2), *args, **kwds)
Return a random polynomial of given degree or with given degree bounds.
INPUT:
• degree - optional integer for fixing the degree or or a tuple of minimum and maximum degrees. By
default set to (-1,2).
• *args, **kwds - Passed on to the random_element method for the base ring
EXAMPLES:
sage: R.random_element(6)
x^6 - 2*x^5 - 2*x^3 + 2*x^2 - 3*x
sage: R.random_element(6)
-x^6 + x^5 + x^2 - x
sage: R.random_element(6)
-5*x^6 + x^5 + 14*x^4 - x^3 + x^2 - x + 4
If a tuple of two integers is given for the degree argument, a degree is first uniformly chosen, then a
polynomial of that degree is given:
sage: R.random_element(degree=(0,8))
4*x^4 + 2*x^3 - x + 4
sage: R.random_element(degree=(0,8))
x + 1
Note that the zero polynomial has degree -1, so if you want to consider it set the minimum degree to -1:
True
set_karatsuba_threshold(Karatsuba_threshold)
Changes the default threshold for this ring in the method _mul_karatsuba to fall back to the schoolbook
algorithm.
Warning: This method may have a negative performance impact in polynomial arithmetic. So use it
at your own risk.
EXAMPLES:
sage: K = QQ['x']
sage: K.karatsuba_threshold()
8
sage: K.set_karatsuba_threshold(0)
sage: K.karatsuba_threshold()
0
some_elements()
Return a list of polynomials.
This is typically used for running generic tests.
EXAMPLES:
variable_names_recursive(depth=+Infinity)
Return the list of variable names of this ring and its base rings, as if it were a single multi-variate polyno-
mial.
INPUT:
• depth – an integer or Infinity.
OUTPUT:
A tuple of strings.
EXAMPLES:
sage: R = QQ['x']['y']['z']
sage: R.variable_names_recursive()
('x', 'y', 'z')
sage: R.variable_names_recursive(2)
('y', 'z')
class sage.rings.polynomial.polynomial_ring.PolynomialRing_integral_domain(base_ring,
name=’x’,
sparse=False,
im-
ple-
men-
ta-
tion=None,
el-
e-
ment_class=None,
cat-
e-
gory=None)
Bases: sage.rings.polynomial.polynomial_ring.PolynomialRing_commutative,
sage.rings.polynomial.polynomial_singular_interface.PolynomialRing_singular_repr,
sage.rings.ring.IntegralDomain
sage.rings.polynomial.polynomial_ring.is_PolynomialRing(x)
Return True if x is a univariate polynomial ring (and not a sparse multivariate polynomial ring in one variable).
EXAMPLES:
sage: is_PolynomialRing(ZZ['x,y,z'])
False
sage: is_MPolynomialRing(ZZ['x,y,z'])
True
sage: is_PolynomialRing(ZZ['w'])
True
Univariate means not only in one variable, but is a specific data type. There is a multivariate (sparse) polynomial
ring data type, which supports a single variable as a special case.
sage.rings.polynomial.polynomial_ring.polygen(ring_or_element, name=’x’)
Return a polynomial indeterminate.
INPUT:
• polygen(base_ring, name=”x”)
• polygen(ring_element, name=”x”)
If the first input is a ring, return a polynomial generator over that ring. If it is a ring element, return a polynomial
generator over the parent of the element.
EXAMPLES:
sage: z = polygen(QQ,'z')
sage: z^3 + z +1
z^3 + z + 1
sage: parent(z)
Univariate Polynomial Ring in z over Rational Field
Note: If you give a list or comma separated string to polygen, you’ll get a tuple of indeterminates, exactly as if
you called polygens.
sage.rings.polynomial.polynomial_ring.polygens(base_ring, names=’x’)
Return indeterminates over the given base ring with the given names.
EXAMPLES:
This module currently implements the canonical ring homomorphism from 𝐴[𝑥] to 𝐵[𝑥] induced by a ring homomor-
phism from 𝐴 to 𝐵.
Todo: Implement homomorphisms from 𝐴[𝑥] to an arbitrary ring 𝑅, given by a ring homomorphism from 𝐴 to 𝑅
and the image of 𝑥 in 𝑅.
AUTHORS:
• Peter Bruin (March 2014): initial version
class sage.rings.polynomial.polynomial_ring_homomorphism.PolynomialRingHomomorphism_from_ba
Bases: sage.rings.morphism.RingHomomorphism_from_base
The canonical ring homomorphism from 𝑅[𝑥] to 𝑆[𝑥] induced by a ring homomorphism from 𝑅 to 𝑆.
EXAMPLES:
sage: QQ['x'].coerce_map_from(ZZ['x'])
Ring morphism:
From: Univariate Polynomial Ring in x over Integer Ring
To: Univariate Polynomial Ring in x over Rational Field
Defn: Induced from base ring by
Natural morphism:
From: Integer Ring
To: Rational Field
is_injective()
Return whether this morphism is injective.
EXAMPLES:
is_surjective()
Return whether this morphism is surjective.
EXAMPLES:
AUTHORS:
• William Stein: first version.
• Martin Albrecht: Added singular coercion.
• Robert Bradshaw: Move Polynomial_generic_dense to Cython.
• Miguel Marco: Implemented resultant in the case where PARI fails.
• Simon King: Use a faster way of conversion from the base ring.
• Julian Rueth (2012-05-25,2014-05-09): Fixed is_squarefree() for imperfect fields, fixed division without re-
mainder over QQbar; added _cache_key for polynomials with unhashable coefficients
• Simon King (2013-10): Implement copying of PolynomialBaseringInjection.
• Kiran Kedlaya (2016-03): Added root counting.
• Edgar Costa (2017-07): Added rational reconstruction.
• Kiran Kedlaya (2017-09): Added reciprocal transform, trace polynomial.
• David Zureick-Brown (2017-09): Added is_weil_polynomial.
class sage.rings.polynomial.polynomial_element.ConstantPolynomialSection
Bases: sage.categories.map.Map
This class is used for conversion from a polynomial ring to its base ring.
Since trac ticket #9944, it calls the constant_coefficient method, which can be optimized for a particular poly-
nomial type.
EXAMPLES:
class sage.rings.polynomial.polynomial_element.Polynomial
Bases: sage.structure.element.CommutativeAlgebraElement
A polynomial.
EXAMPLES:
_add_(right)
Add two polynomials.
EXAMPLES:
sage: R = ZZ['x']
sage: p = R([1,2,3,4])
sage: q = R([4,-3,2,-1])
sage: p + q # indirect doctest
3*x^3 + 5*x^2 - x + 5
_sub_(other)
Default implementation of subtraction using addition and negation.
_lmul_(left)
Multiply self on the left by a scalar.
EXAMPLES:
_rmul_(right)
Multiply self on the right by a scalar.
EXAMPLES:
_mul_(right)
EXAMPLES:
_mul_trunc_(right, n)
Return the truncated multiplication of two polynomials up to n.
This is the default implementation that does the multiplication and then truncate! There are custom imple-
mentations in several subclasses:
• on dense polynomial over integers (via FLINT)
• on dense polynomial over Z/nZ (via FLINT)
• on dense rational polynomial (via FLINT)
• on dense polynomial on Z/nZ (via NTL)
EXAMPLES:
sage: R = QQ['x']['y']
sage: y = R.gen()
sage: x = R.base_ring().gen()
sage: p1 = 1 - x*y + 2*y**3
sage: p2 = -1/3 + y**5
sage: p1._mul_trunc_(p2, 5)
-2/3*y^3 + 1/3*x*y - 1/3
adams_operator(n, monic=False)
Return the polynomial whose roots are the 𝑛-th power of the roots of this.
INPUT:
• 𝑛 – an integer
• monic – boolean (default False) if set to True, force the output to be monic
EXAMPLES:
sage: f = cyclotomic_polynomial(30)
sage: f.adams_operator(7)==f
True
sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2
True
sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4
True
sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8
True
sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8
True
sage: x = polygen(QQ)
sage: f = x^2-2*x+2
sage: f.adams_operator(10)
x^2 + 1024
When f is monic the output will have leading coefficient ±1 depending on the degree, but we can force it
to be monic:
sage: R.<a,b,c> = ZZ[]
sage: x = polygen(R)
sage: f = (x-a)*(x-b)*(x-c)
sage: f.adams_operator(3).factor()
(-1) * (x - c^3) * (x - b^3) * (x - a^3)
sage: f.adams_operator(3,monic=True).factor()
(x - c^3) * (x - b^3) * (x - a^3)
add_bigoh(prec)
Returns the power series of precision at most prec got by adding 𝑂(𝑞 prec ) to self, where q is its variable.
EXAMPLES:
sage: R.<x> = ZZ[]
sage: f = 1 + 4*x + x^3
sage: f.add_bigoh(7)
1 + 4*x + x^3 + O(x^7)
sage: f.add_bigoh(2)
1 + 4*x + O(x^2)
sage: f.add_bigoh(2).parent()
Power Series Ring in x over Integer Ring
all_roots_in_interval(a=None, b=None)
Return True if the roots of this polynomial are all real and contained in the given interval.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: pol = (x-1)^2 * (x-2)^2 * (x-3)
(continues on next page)
˓→6*a + 2, 1), (a^5 + 3*a^4 + 8*a^3 + 2*a^2 + 3*a + 4, 1), (10*a^5 + 3*a^4 +
args()
Returns the generator of this polynomial ring, which is the (only) argument used when calling self.
EXAMPLES:
sage: R(2).args()
(x,)
base_extend(R)
Return a copy of this polynomial but with coefficients in R, if there is a natural map from coefficient ring
of self to R.
EXAMPLES:
base_ring()
Return the base ring of the parent of self.
EXAMPLES:
change_ring(R)
Return a copy of this polynomial but with coefficients in R, if at all possible.
INPUT:
• R - a ring or morphism.
EXAMPLES:
change_variable_name(var)
Return a new polynomial over the same base ring but in a different variable.
EXAMPLES:
sage: x = polygen(QQ,'x')
sage: f = -2/7*x^3 + (2/3)*x - 19/993; f
-2/7*x^3 + 2/3*x - 19/993
sage: f.change_variable_name('theta')
-2/7*theta^3 + 2/3*theta - 19/993
coefficients(sparse=True)
Return the coefficients of the monomials appearing in self. If sparse=True (the default), it returns only
the non-zero coefficients. Otherwise, it returns the same value as self.list(). (In this case, it may be
slightly faster to invoke self.list() directly.)
EXAMPLES:
complex_roots()
Return the complex roots of this polynomial, without multiplicities.
Calls self.roots(ring=CC), unless this is a polynomial with floating-point coefficients, in which case it is
uses the appropriate precision from the input coefficients.
EXAMPLES:
sage: x = polygen(ZZ)
sage: (x^3 - 1).complex_roots() # note: low order bits slightly different
˓→on ppc.
sage: x = polygen(QQ)
sage: f = x^2-2*x+2
sage: f2 = f.compose_power(2); f2
x^4 - 4*x^3 + 8*x^2 - 16*x + 16
sage: f2 == f.composed_op(f,operator.mul)
True
sage: f3 = f.compose_power(3); f3
x^8 - 8*x^7 + 32*x^6 - 64*x^5 + 128*x^4 - 512*x^3 + 2048*x^2 - 4096*x + 4096
sage: f3 == f2.composed_op(f,operator.mul)
True
sage: f4 = f.compose_power(4)
sage: f4 == f3.composed_op(f,operator.mul)
True
compose_trunc(other, n)
Return the composition of self and other, truncated to 𝑂(𝑥𝑛 ).
This method currently works for some specific coefficient rings only.
EXAMPLES:
where the roots 𝑎 and 𝑏 are to be considered in the algebraic closure of the fraction field of the coefficients
and counted with multiplicities. If the polynomials are not monic this quantity is multiplied by
𝑑𝑒𝑔(𝑝2 )
𝑎𝑙𝑝ℎ𝑎1
𝑑𝑒𝑔(𝑝1 )
𝑎𝑙𝑝ℎ𝑎2 where
𝑎𝑙𝑝ℎ𝑎1 and
𝑎𝑙𝑝ℎ𝑎2 are the leading coefficients of 𝑝1 and 𝑝2 respectively.
INPUT:
• p2 – univariate polynomial belonging to the same polynomial ring as this polynomial
• op – operator.OP where OP=add or sub or mul or truediv.
• algorithm – can be “resultant” or “BFSS”; by default the former is used when the polynomials
have few nonzero coefficients and small degrees or if the base ring is not Z or Q. Otherwise the latter
is used.
• monic – whether to return a monic polynomial. If True the coefficients of the result belong to the
fraction field of the coefficients.
ALGORITHM:
The computation is straightforward using resultants. Indeed for the composed sum it would be
𝑅𝑒𝑠𝑦 (𝑝1(𝑥 − 𝑦), 𝑝2(𝑦)). However, the method from [BFSS] using series expansions is asymptotically
much faster.
Note that the algorithm BFSS with polynomials with coefficients in Z needs to perform operations over
Q.
Todo:
• The [BFSS] algorithm has been implemented here only in the case of polynomials over rationals. For
other rings of zero characteristic (or if the characteristic is larger than the product of the degrees), one
needs to implement a generic method _exp_series. In the general case of non-zero characteristic
there is an alternative algorithm in the same paper.
• The Newton series computation can be done much more efficiently! See [BFSS].
EXAMPLES:
sage: x = polygen(ZZ)
sage: p1 = x^2 - 1
sage: p2 = x^4 - 1
sage: p1.composed_op(p2, operator.add)
x^8 - 4*x^6 + 4*x^4 - 16*x^2
sage: p1.composed_op(p2, operator.mul)
x^8 - 2*x^4 + 1
sage: p1.composed_op(p2, operator.truediv)
x^8 - 2*x^4 + 1
This function works over any field. However for base rings other than Z and Q only the resultant algorithm
is available:
sage: x = polygen(QQbar)
sage: p1 = x**2 - AA(2).sqrt()
sage: p2 = x**3 - AA(3).sqrt()
sage: r1 = p1.roots(multiplicities=False)
sage: r2 = p2.roots(multiplicities=False)
sage: p = p1.composed_op(p2, operator.add)
sage: p
x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 - 14.
˓→69693845669907?*x + 0.1715728752538099?
sage: x = polygen(GF(2))
sage: p1 = x**2 + x - 1
sage: p2 = x**3 + x - 1
sage: p_add = p1.composed_op(p2, operator.add)
sage: p_add
x^6 + x^5 + x^3 + x^2 + 1
(continues on next page)
sage: y = polygen(ZZ)
sage: for p1 in [2*y^3 - y + 3, -y^5 - 2, 4*y - 3]:
....: for p2 in [5*y^2 - 7, -3*y - 1]:
....: for monic in [True,False]:
....: for op in [operator.add, operator.sub, operator.mul, operator.
˓→truediv]:
REFERENCES:
constant_coefficient()
Return the constant coefficient of this polynomial.
OUTPUT: element of base ring
EXAMPLES:
content(*args, **kwds)
Deprecated: Use content_ideal() instead. See trac ticket #16613 for details.
content_ideal()
Return the content ideal of this polynomial, defined as the ideal generated by its coefficients.
EXAMPLES:
When the base ring is a gcd ring, the content as a ring element is the generator of the content ideal:
cyclotomic_part()
Return the product of the irreducible factors of this polynomial which are cyclotomic polynomials.
The algorithm assumes that the polynomial has rational coefficients.
See also:
is_cyclotomic() is_cyclotomic_product() has_cyclotomic_factor()
EXAMPLES:
sage: pol = (x - 1) * x * (x + 2)
sage: pol.cyclotomic_part()
x - 1
degree(gen=None)
Return the degree of this polynomial. The zero polynomial has degree -1.
EXAMPLES:
sage: x = ZZ['x'].0
sage: f = x^93 + 2*x + 1
sage: f.degree()
93
sage: x = PolynomialRing(QQ, 'x', sparse=True).0
sage: f = x^100000
sage: f.degree()
100000
sage: x = QQ['x'].0
sage: f = 2006*x^2006 - x^2 + 3
sage: f.degree()
2006
sage: f = 0*x
sage: f.degree()
-1
sage: f = x + 33
(continues on next page)
AUTHORS:
• Naqi Jaffery (2006-01-24): examples
denominator()
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 of self is returned.
Note that some subclasses may implement their own denominator function. For example, see sage.
rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint
Warning: This is not the denominator of the rational function defined by self, which would always
be 1 since self is a polynomial.
EXAMPLES:
First we compute the denominator of a polynomial with integer coefficients, which is of course 1.
sage: R.<x> = ZZ[]
sage: f = x^3 + 17*x + 1
sage: f.denominator()
1
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: R.<x> = RR[]
sage: f = x + RR('0.3'); f
x + 0.300000000000000
sage: f.denominator()
1.00000000000000
Check that the denominator is an element over the base whenever the base has no denominator function.
This closes trac ticket #9063.
sage: R.<a> = GF(5)[]
sage: x = R(0)
sage: x.denominator()
1
sage: type(x.denominator())
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
sage: isinstance(x.numerator() / x.denominator(), Polynomial)
True
(continues on next page)
derivative(*args)
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 derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
dict()
Return a sparse dictionary representation of this univariate polynomial.
EXAMPLES:
diff(*args)
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 derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
differentiate(*args)
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 derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
discriminant()
Return the discriminant of self.
The discriminant is
∏︁
𝑅𝑛 := 𝑎2𝑛−2
𝑛 (𝑟𝑖 − 𝑟𝑗 )2 ,
1<𝑖<𝑗<𝑛
where 𝑛 is the degree of self, 𝑎𝑛 is the leading coefficient of self and the roots of self are 𝑟1 , . . . , 𝑟𝑛 .
OUTPUT: An element of the base ring of the polynomial ring.
ALGORITHM:
Uses the identity 𝑅𝑛 (𝑓 ) := (−1)𝑛(𝑛−1)/2 𝑅(𝑓, 𝑓 ′ )𝑎𝑛−𝑘−2 𝑛 , where 𝑛 is the degree of self, 𝑎𝑛 is the leading
coefficient of self, 𝑓 ′ is the derivative of 𝑓 , and 𝑘 is the degree of 𝑓 ′ . Calls resultant().
EXAMPLES:
In the case of elliptic curves in special form, the discriminant is easy to calculate:
dispersion(other=None)
Compute the dispersion of a pair of polynomials.
The dispersion of 𝑓 and 𝑔 is the largest nonnegative integer 𝑛 such that 𝑓 (𝑥 + 𝑛) and 𝑔(𝑥) have a noncon-
stant common factor.
When other is None, compute the auto-dispersion of self, i.e., its dispersion with itself.
See also:
dispersion_set()
EXAMPLES:
dispersion_set(other=None)
Compute the dispersion set of two polynomials.
The dispersion set of 𝑓 and 𝑔 is the set of nonnegative integers 𝑛 such that 𝑓 (𝑥 + 𝑛) and 𝑔(𝑥) have a
nonconstant common factor.
When other is None, compute the auto-dispersion set of self, i.e., its dispersion set with itself.
ALGORITHM:
See Section 4 of Man & Wright [ManWright1994].
See also:
dispersion()
EXAMPLES:
divides(p)
Return 𝑇 𝑟𝑢𝑒 if this polynomial divides 𝑝.
This method is only implemented for polynomials over an integral domain.
EXAMPLES:
euclidean_degree()
Return the degree of this element as an element of an Euclidean domain.
If this polynomial is defined over a field, this is simply its degree().
EXAMPLES:
exponents()
Return the exponents of the monomials appearing in self.
EXAMPLES:
factor(**kwargs)
Return the factorization of self over its base ring.
INPUT:
• kwargs – any keyword arguments are passed to the method
_factor_univariate_polynomial() of the base ring if it defines such a method.
OUTPUT:
• A factorization of self over its parent into a unit and irreducible factors. If the parent is a polynomial
ring over a field, these factors are monic.
EXAMPLES:
Factorization is implemented over various rings. Over Q:
sage: x = QQ['x'].0
sage: f = (x^3 - 1)^2
sage: f.factor()
(x - 1)^2 * (x^2 + x + 1)^2
Notice that the unit factor is included when we multiply 𝐹 back out:
sage: expand(F)
2*x^10 + 2*x + 2*a
sage: (x^2).factor()
x^2
sage: del R.base_ring()._factor_univariate_polynomial # clean up
sage: expand(F)
x^2 + 3.0000000000000000000000000000
sage: factor(x^2+1)
(x - I) * (x + I)
sage: f = R(I) * (x^2 + 1) ; f
I*x^2 + I
sage: F = factor(f); F
(1.0000000000000000000000000000*I) * (x - I) * (x + I)
sage: expand(F)
I*x^2 + I
sage: x = polygen(QQ)
sage: K.<z> = CyclotomicField(3)
sage: L.<a> = K.extension(x^3 - 2)
sage: t = polygen(L, 't')
sage: f = (t^3 + t + a)*(t^5 + t + z); f
t^8 + t^6 + a*t^5 + t^4 + z*t^3 + t^2 + (a + z)*t + z*a
sage: f.factor()
(t^3 + t + a) * (t^5 + t + z)
The above output is incorrect because it relies on the roots() method, which does not detect that all the
roots are real:
Over the complex double field the factors are approximate and therefore occur with multiplicity 1:
Factoring polynomials over the algebraic numbers (see trac ticket #8544):
˓→7071067811865475?*I) * (x + 1)
Factoring polynomials over the algebraic reals (see trac ticket #8544):
sage: f = x0^0
sage: f.factor()
1
sage: F = ff.factor()
sage: len(F)
4
sage: F[:2]
[(T - a, 1), (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^
˓→4 + 527617096480/924556084127*a^3 + 1289745809920/924556084127*a^2 -
sage: expand(F)
T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/
˓→1225
Entering nffactor:
...
sage: pari.default("debug", 0)
50 Chapter
˓→49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49) 2. +
*t^6 Univariate
(90/49*a^5Polynomials
+ 110/
˓→49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 +
sage: pol.factor()
(1/7*a^2 - 1/7*a) * t^5 * (t^5 + (-40/7*a^5 - 38/7*a^4 - 36/7*a^3 - 34/7*a^2 -
˓→ 32/7*a - 30/7)*t^4 + (60/7*a^5 - 30/7*a^4 - 18/7*a^3 - 9/7*a^2 - 3/7*a)*t^
sage: pol.factor()
x^5 * (x^5 + (4/7*a - 6/7)*x^4 + (9/49*a^2 - 3/7*a + 15/49)*x^3 + (8/343*a^3 -
˓→ 32/343*a^2 + 40/343*a - 20/343)*x^2 + (5/2401*a^4 - 20/2401*a^3 + 40/
Factoring over a number field over which we cannot factor the discriminant by trial division:
sage: x = polygen(QQ)
sage: K.<a> = NumberField(x^16 - x - 6)
sage: R.<x> = PolynomialRing(K)
sage: f = (x+a)^50 - (a-1)^50
sage: len(factor(f))
6
sage: pari(K.discriminant()).factor(limit=10^6)
[-1, 1; 3, 15; 23, 1; 887, 1; 12583, 1; 2354691439917211, 1]
sage: factor(K.discriminant())
-1 * 3^15 * 23 * 887 * 12583 * 6335047 * 371692813
Factoring over a number field over which we cannot factor the discriminant and over which 𝑛𝑓 𝑓 𝑎𝑐𝑡𝑜𝑟()
fails:
sage: x = polygen(QQ)
(continues on next page)
sage: x1 = ZZ['x'].gen()
sage: x2 = ZZ['x']['x'].gen()
sage: (x1 - x2).factor()
-x + x
gcd(other)
Return a greatest common divisor of this polynomial and other.
INPUT:
• other – a polynomial in the same ring as this polynomial
OUTPUT:
A greatest common divisor as a polynomial in the same ring as this polynomial. If the base ring is a field,
the return value is a monic polynomial.
Note: The actual algorithm for computing greatest common divisors depends on the base ring underlying
the polynomial ring. If the base ring defines a method _gcd_univariate_polynomial, then this
method will be called (see examples below).
EXAMPLES:
One can easily add gcd functionality to new rings by providing a method
_gcd_univariate_polynomial:
sage: O = ZZ[-sqrt(5)]
sage: R.<x> = O[]
sage: a = O.1
sage: p = x + a
sage: q = x^2 - 5
sage: p.gcd(q)
Traceback (most recent call last):
...
NotImplementedError: Order in Number Field in a with defining polynomial x^2 -
˓→ 5 does not provide a gcd implementation for univariate polynomials
gradient()
Return a list of the partial derivative of self with respect to the variable of this univariate polynomial.
There is only one partial derivative.
EXAMPLES:
hamming_weight()
Returns the number of non-zero coefficients of self. Also called weight, hamming weight or sparsity.
EXAMPLES:
sage: f.hamming_weight()
101
has_cyclotomic_factor()
Return True if the given polynomial has a nontrivial cyclotomic factor.
The algorithm assumes that the polynomial has rational coefficients.
If the polynomial is known to be irreducible, it may be slightly more efficient to call 𝑖𝑠𝑐 𝑦𝑐𝑙𝑜𝑡𝑜𝑚𝑖𝑐 instead.
See also:
is_cyclotomic() is_cyclotomic_product() cyclotomic_part()
EXAMPLES:
homogenize(var=’h’)
Return the homogenization of this polynomial.
The polynomial itself is returned if it is homogeneous already. Otherwise, its 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 0) or a name for a new
variable (default: 'h')
OUTPUT:
If var specifies the 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 variable var.
EXAMPLES:
The parameter var can be used to specify the name of the variable:
sage: g = f.homogenize('z'); g
x^2 + z^2
sage: g.parent()
Multivariate Polynomial Ring in x, z over Rational Field
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
sage: g = f.homogenize('z'); g
x^2
sage: g.parent()
Univariate Polynomial Ring in x over Rational Field
For compatibility with the multivariate case, if var specifies the variable of the polynomial ring, then
the monomials are multiplied with the smallest powers of var such that the result is homogeneous; in
other words, we end up with a monomial whose leading coefficient is the sum of the coefficients of the
polynomial:
sage: f = x^2 + x + 1
sage: f.homogenize('x')
3*x^2
For compatibility with the multivariate case, the parameter var can also be 0 to specify the variable in the
polynomial ring:
integral(var=None)
Return the integral of this polynomial.
By default, the integration variable is the variable of the polynomial.
Otherwise, the integration variable is the optional parameter var
EXAMPLES:
Note that the integral lives over the fraction field of the scalar coefficients:
sage: f.parent()
Univariate Polynomial Ring in x over Rational Field
sage: R(0).integral().parent()
Univariate Polynomial Ring in x over Rational Field
sage: f = x^3 + x - 2
sage: g = f.integral(); g
1/4*x^4 + 1/2*x^2 - 2*x
sage: g.parent()
Univariate Polynomial Ring in x over Rational Field
inverse_mod(a, m)
Inverts the polynomial a with respect to m, or raises a ValueError if no such inverse exists. The parameter
m may be either a single polynomial or an ideal (for consistency with inverse_mod in other rings).
See also:
If you are only interested in the inverse modulo a monomial 𝑥𝑘 then you might use the specialized method
inverse_series_trunc() which is much faster.
EXAMPLES:
This also works over inexact rings, but note that due to rounding error the product may not always exactly
equal the constant polynomial 1 and have extra terms with coefficients close to zero.
1.0
sage: f = inverse_mod(x^3 - x + 1, x - 2); f
0.14285714285714285
sage: f * (x^3 - x + 1) % (x - 2)
1.0
sage: g = 5*x^3+x-7; m = x^4-12*x+13; f = inverse_mod(g, m); f
-0.0319636125...*x^3 - 0.0383269759...*x^2 - 0.0463050900...*x + 0.346479687..
˓→.
AUTHORS:
• Robert Bradshaw (2007-05-31)
inverse_of_unit()
EXAMPLES:
inverse_series_trunc(prec)
Return a polynomial approximation of precision prec of the inverse series of this polynomial.
See also:
The method inverse_mod() allows more generally to invert this polynomial with respect to any ideal.
EXAMPLES:
sage: x = polygen(ZZ)
sage: s = (1+x).inverse_series_trunc(5)
sage: s
x^4 - x^3 + x^2 - x + 1
sage: s * (1+x)
x^5 + 1
sage: R = Zmod(4)
sage: Rx.<x> = R[]
sage: Rxy.<y> = Rx[]
sage: M = MatrixSpace(ZZ,2)
sage: x = polygen(M)
sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one()
sage: q = p.inverse_series_trunc(5)
sage: (p*q).truncate(5) == M.one()
True
sage: q = p.inverse_series_trunc(13)
sage: (p*q).truncate(13) == M.one()
True
AUTHORS:
• David Harvey (2006-09-09): Newton’s method implementation for power series
• Vincent Delecroix (2014-2015): move the implementation directly in polynomial
is_constant()
Return True if this is a constant polynomial.
OUTPUT:
• bool - True if and only if this polynomial is constant
EXAMPLES:
is_cyclotomic(certificate=False, algorithm=’pari’)
Test if this polynomial is a cyclotomic polynomial.
A cyclotomic polynomial is a monic, irreducible polynomial such that all roots are roots of unity.
By default the answer is a boolean. But if certificate is True, the result is a non-negative integer: it
is 0 if self is not cyclotomic, and a positive integer n if self is the 𝑛-th cyclotomic polynomial.
See also:
is_cyclotomic_product() cyclotomic_part() has_cyclotomic_factor()
INPUT:
• certificate – boolean, default to False. Only works with algorithm set to “pari”.
• algorithm – either “pari” or “sage” (default is “pari”)
ALGORITHM:
The native algorithm implemented in Sage uses the first algorithm of [BD89]. The algorithm in pari (using
pari:poliscyclo) is more subtle since it does compute the inverse of the Euler 𝜑 function to determine the
𝑛 such that the polynomial is the 𝑛-th cyclotomic polynomial.
EXAMPLES:
Quick tests:
False
sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage
˓→")
False
True
sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage
˓→")
True
sage: y = polygen(QQ)
sage: (y/2 - 1/2).is_cyclotomic()
False
sage: (2*(y/2 - 1/2)).is_cyclotomic()
True
Invalid arguments:
sage: z = polygen(GF(5))
sage: (z - 1).is_cyclotomic()
Traceback (most recent call last):
...
NotImplementedError: not implemented in non-zero characteristic
REFERENCES:
is_cyclotomic_product()
Test whether this polynomial is a product of cyclotomic polynomials.
This method simply calls the function pari:poliscycloprod from the Pari library.
See also:
is_cyclotomic() cyclotomic_part() has_cyclotomic_factor()
EXAMPLES:
sage: x = polygen(ZZ)
sage: (x^5 - 1).is_cyclotomic_product()
True
sage: (x^5 + x^4 - x^2 + 1).is_cyclotomic_product()
False
sage: x = polygen(Zmod(5))
sage: (x-1).is_cyclotomic_product()
Traceback (most recent call last):
...
NotImplementedError: not implemented in non-zero characteristic
is_gen()
Return True if this polynomial is the distinguished generator of the parent polynomial ring.
EXAMPLES:
Important - this function doesn’t return True if self equals the generator; it returns True if self is the
generator.
sage: f = R([0,1]); f
x
sage: f.is_gen()
False
sage: f is x
False
sage: f == x
True
is_homogeneous()
Return True if this polynomial is homogeneous.
EXAMPLES:
is_irreducible()
Return whether this polynomial is irreducible.
EXAMPLES:
The base ring does matter: for example, 2𝑥 is irreducible as a polynomial in Q[𝑥], but not in Z[𝑥]:
is_monic()
Returns True if this polynomial is monic. The zero polynomial is by definition not monic.
EXAMPLES:
sage: x = QQ['x'].0
sage: f = x + 33
sage: f.is_monic()
True
sage: f = 0*x
sage: f.is_monic()
False
sage: f = 3*x^3 + x^4 + x^2
sage: f.is_monic()
True
sage: f = 2*x^2 + x^3 + 56*x^5
sage: f.is_monic()
False
AUTHORS:
• Naqi Jaffery (2006-01-24): examples
is_monomial()
Returns True if self is a monomial, i.e., a power of the generator.
EXAMPLES:
sage: (2*x^5).is_monomial()
False
sage: (2*x^5).is_term()
True
Warning: The definition of is_monomial in Sage up to 4.7.1 was the same as is_term, i.e., it allowed
a coefficient not equal to 1.
is_nilpotent()
Return True if this polynomial is nilpotent.
EXAMPLES:
sage: R = Integers(12)
sage: S.<x> = R[]
sage: f = 5 + 6 *x
sage: f.is_nilpotent()
False
sage: f = 6 + 6*x^2
sage: f.is_nilpotent()
True
sage: f^2
0
𝑎𝑖 𝑥𝑖 ∈
∑︀
EXERCISE (Atiyah-McDonald, Ch 1): Let 𝐴[𝑥] be a polynomial ring in one variable. Then 𝑓 =
𝐴[𝑥] is nilpotent if and only if every 𝑎𝑖 is nilpotent.
is_one()
Test whether this polynomial is 1.
EXAMPLES:
is_primitive(n=None, n_prime_divs=None)
Returns True if the polynomial is primitive. The semantics of “primitive” depend on the polynomial
coefficients.
• (field theory) A polynomial of degree 𝑚 over a finite field F𝑞 is primitive if it is irreducible and its
root in F𝑞𝑚 generates the multiplicative group F*𝑞𝑚 .
• (ring theory) A polynomial over a ring is primitive if its coefficients generate the unit ideal.
Calling 𝑖𝑠𝑝 𝑟𝑖𝑚𝑖𝑡𝑖𝑣𝑒 on a polynomial over an infinite field will raise an error.
The additional inputs to this function are to speed up computation for field semantics (see note).
INPUT:
• n (default: None) - if provided, should equal 𝑞 − 1 where self.parent() is the field with 𝑞
elements; otherwise it will be computed.
• n_prime_divs (default: None) - if provided, should be a list of the prime divisors of n; otherwise
it will be computed.
Note: Computation of the prime divisors of n can dominate the running time of this method, so performing
this computation externally (e.g. pdivs=n.prime_divisors()) is a good idea for repeated calls to
is_primitive for polynomials of the same degree.
Results may be incorrect if the wrong n and/or factorization are provided.
EXAMPLES:
::
::
sage: x=polygen(ZZ)
sage: f = 5*x^2+2
sage: f.is_primitive()
True
sage: f = 5*x^2+5
sage: f.is_primitive()
False
sage: K=NumberField(x^2+5,'a')
sage: R=K.ring_of_integers()
sage: a=R.gen(1)
sage: a^2
-5
sage: f=a*x+2
sage: f.is_primitive()
True
sage: f=(1+a)*x+2
sage: f.is_primitive()
False
sage: x = polygen(Integers(10))
sage: f = 5*x^2+2
sage: #f.is_primitive() #BUG:: elsewhere in Sage, should return True
sage: f=4*x^2+2
sage: #f.is_primitive() #BUG:: elsewhere in Sage, should return False
is_real_rooted()
Return True if the roots of this polynomial are all real.
EXAMPLES:
is_square(root=False)
Returns whether or not polynomial is square. If the optional argument root is set to True, then also
returns the square root (or None, if the polynomial is not square).
INPUT:
• root - whether or not to also return a square root (default: False)
OUTPUT:
• bool - whether or not a square
• root - (optional) an actual square root if found, and None otherwise.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: (x^2 + 2*x + 1).is_square()
True
sage: (x^4 + 2*x^3 - x^2 - 2*x + 1).is_square(root=True)
(True, x^2 + x - 1)
sage: h = f/3; h
4*x^4 + 32*x^3 + 88*x^2 + 96*x + 36
sage: h.is_square(root=True)
(True, 2*x^2 + 8*x + 6)
sage: g.is_square()
True
is_squarefree()
Return False if this polynomial is not square-free, i.e., if there is a non-unit 𝑔 in the polynomial ring such
that 𝑔 2 divides self.
Warning: This method is not consistent with squarefree_decomposition() since the latter
does not factor the content of a polynomial. See the examples below.
EXAMPLES:
sage: R.<x> = QQ[]
sage: f = (x-1)*(x-2)*(x^2-5)*(x^17-3); f
x^21 - 3*x^20 - 3*x^19 + 15*x^18 - 10*x^17 - 3*x^4 + 9*x^3 + 9*x^2 - 45*x + 30
sage: f.is_squarefree()
True
sage: (f*(x^2-5)).is_squarefree()
False
If you want this method equally not to consider the content, you can remove it as in the following example:
sage: c = f.content()
sage: (f/c).is_squarefree()
True
If the base ring is not an integral domain, the question is not mathematically well-defined:
sage: R.<x> = IntegerModRing(9)[]
sage: pol = (x + 3)*(x + 6); pol
x^2
sage: pol.is_squarefree()
Traceback (most recent call last):
...
TypeError: is_squarefree() is not defined for polynomials over Ring of
˓→integers modulo 9
is_term()
Return True if this polynomial is a nonzero element of the base ring times a power of the variable.
EXAMPLES:
sage: (3*x^5).is_monomial()
False
is_unit()
Return True if this polynomial is a unit.
EXAMPLES:
sage: a = Integers(90384098234^3)
sage: b = a(2*191*236607587)
sage: b.is_nilpotent()
True
sage: R.<x> = a[]
sage: f = 3 + b*x + b^2*x^2
sage: f.is_unit()
True
sage: f = 3 + b*x + b^2*x^2 + 17*x^3
sage: f.is_unit()
False
𝑎𝑖 𝑥𝑖 ∈
∑︀
EXERCISE (Atiyah-McDonald, Ch 1): Let 𝐴[𝑥] be a polynomial ring in one variable. Then 𝑓 =
𝐴[𝑥] is a unit if and only if 𝑎0 is a unit and 𝑎1 , . . . , 𝑎𝑛 are nilpotent.
is_weil_polynomial(return_q=False)
Return True if this is a Weil polynomial.
This polynomial must have rational or integer coefficients.
INPUT:
• self – polynomial with rational or integer coefficients
• return_q – (default False) if True, return a second value 𝑞 which is the prime power with re-
spect to which this is 𝑞-Weil, or 0 if there is no such value.
EXAMPLES:
AUTHORS:
David Zureick-Brown (2017-10-01)
is_zero()
Test whether this polynomial is zero.
EXAMPLES:
sage: R = GF(2)['x']['y']
sage: R([0,1]).is_zero()
False
sage: R([0]).is_zero()
True
sage: R([-1]).is_zero()
False
lc()
Return the leading coefficient of this polynomial.
OUTPUT: element of the base ring This method is same as leading_coefficient().
EXAMPLES:
sage: R.<x> = QQ[]
sage: f = (-2/5)*x^3 + 2*x - 1/3
sage: f.lc()
-2/5
lcm(other)
Let f and g be two polynomials. Then this function returns the monic least common multiple of f and g.
leading_coefficient()
Return the leading coefficient of this polynomial.
OUTPUT: element of the base ring
EXAMPLES:
sage: R.<x> = QQ[]
sage: f = (-2/5)*x^3 + 2*x - 1/3
sage: f.leading_coefficient()
-2/5
list(copy=True)
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
sage: R.<x> = QQ[]
sage: f = (-2/5)*x^3 + 2*x - 1/3
sage: v = f.list(); v
[-1/3, 2, 0, -2/5]
Note that v is a list, it is mutable, and each call to the list method returns a new list:
sage: type(v)
<... 'list'>
sage: v[0] = 5
sage: f.list()
[-1/3, 2, 0, -2/5]
lm()
Return the leading monomial of this polynomial.
EXAMPLES:
lt()
Return the leading term of this polynomial.
EXAMPLES:
map_coefficients(f, new_base_ring=None)
Returns the polynomial obtained by applying f to the non-zero coefficients of self.
If f is a sage.categories.map.Map, then the resulting polynomial will be defined over the
codomain of f. Otherwise, the resulting polynomial will be over the same ring as self. Set
mod(other)
Remainder of division of self by other.
EXAMPLES:
monic()
Return this polynomial divided by its leading coefficient. Does not change this polynomial.
EXAMPLES:
sage: x = QQ['x'].0
sage: f = 2*x^2 + x^3 + 56*x^5
sage: f.monic()
x^5 + 1/56*x^3 + 1/28*x^2
sage: f = (1/4)*x^2 + 3*x + 1
sage: f.monic()
x^2 + 12*x + 4
sage: f = 0*x
sage: f.monic()
Traceback (most recent call last):
...
ZeroDivisionError: rational division by zero
Notice that the monic version of a polynomial over the integers is defined over the rationals.
sage: x = ZZ['x'].0
sage: f = 3*x^19 + x^2 - 37
sage: g = f.monic(); g
x^19 + 1/3*x^2 - 37/3
sage: g.parent()
Univariate Polynomial Ring in x over Rational Field
AUTHORS:
• Naqi Jaffery (2006-01-24): examples
monomial_coefficient(m)
Return the coefficient in the base ring of the monomial m in self, where m must have the same parent as
self.
INPUT:
• m - a monomial
OUTPUT:
Coefficient in base ring.
EXAMPLES:
monomials()
Return the list of the monomials in self in a decreasing order of their degrees.
EXAMPLES:
multiplication_trunc(other, n)
Truncated multiplication
EXAMPLES:
sage: R2 = QQ['x']
sage: x2 = R2.gen()
sage: p1 = (x^3 + 1).multiplication_trunc(x2^3 - 2, 5); p1
-x^3 - 2
sage: p2 = (x2^3 + 1).multiplication_trunc(x^3 - 2, 5); p2
-x^3 - 2
sage: parent(p1) == parent(p2) == R2
True
newton_raphson(n, x0)
Return a list of n iterative approximations to a root of this polynomial, computed using the Newton-
Raphson method.
The Newton-Raphson method is an iterative root-finding algorithm. For f(x) a polynomial, as is the case
here, this is essentially the same as Horner’s method.
INPUT:
• n - an integer (=the number of iterations),
• x0 - an initial guess x0.
OUTPUT: A list of numbers hopefully approximating a root of f(x)=0.
If one of the iterates is a critical point of f then a ZeroDivisionError exception is raised.
EXAMPLES:
AUTHORS:
• David Joyner and William Stein (2005-11-28)
newton_slopes(p, lengths=False)
Return the 𝑝-adic slopes of the Newton polygon of self, when this makes sense.
OUTPUT:
If 𝑙𝑒𝑛𝑔𝑡ℎ𝑠 is 𝐹 𝑎𝑙𝑠𝑒, a list of rational numbers. If 𝑙𝑒𝑛𝑔𝑡ℎ𝑠 is 𝑇 𝑟𝑢𝑒, a list of couples (𝑠, 𝑙) where 𝑠 is the
slope and 𝑙 the length of the corresponding segment in the Newton polygon.
EXAMPLES:
sage: x = QQ['x'].0
sage: f = x^3 + 2
sage: f.newton_slopes(2)
[1/3, 1/3, 1/3]
sage: R.<x> = PolynomialRing(ZZ, sparse=True)
sage: p = x^5 + 6*x^2 + 4
sage: p.newton_slopes(2)
[1/2, 1/2, 1/3, 1/3, 1/3]
sage: p.newton_slopes(2, lengths=True)
[(1/2, 2), (1/3, 3)]
sage: (x^2^100 + 27).newton_slopes(3, lengths=True)
[(3/1267650600228229401496703205376, 1267650600228229401496703205376)]
sage: f.norm(1)
5.00000000000000
sage: f.norm(infinity)
2.00000000000000
sage: f.norm(-1)
Traceback (most recent call last):
...
ValueError: The degree of the norm must be positive
AUTHORS:
• Didier Deshommes
• William Stein: fix bugs, add definition, etc.
nth_root(n)
Return a 𝑛-th root of this polynomial.
This is computed using Newton method in the ring of power series. This method works only when the base
ring is an integral domain. Morever, for polynomial whose coefficient of lower degree is different from 1,
the elements of the base ring should have a method nth_root implemented.
EXAMPLES:
sage: b = 25 * (x^2 + x + 1)
sage: b.nth_root(2)
Traceback (most recent call last):
...
ValueError: not a 2nd power
sage: R(0).nth_root(3)
0
sage: R.<x> = QQ[]
sage: a = 1/4 * (x/7 + 3/2)^2 * (x/2 + 5/3)^4
sage: a.nth_root(2)
1/56*x^3 + 103/336*x^2 + 365/252*x + 25/12
sage: z = GF(4).gen()
sage: R.<x> = GF(4)[]
sage: p = z*x**4 + 2*x - 1
sage: r = (p**15).nth_root(15)
sage: r * p[0] == p * r[0]
True
sage: ((x+1)**2).nth_root(2)
x + 1
sage: ((x+1)**4).nth_root(4)
x + 1
sage: ((x+1)**12).nth_root(12)
x + 1
sage: (x^4 + x^3 + 1).nth_root(2)
Traceback (most recent call last):
...
ValueError: not a 2nd power
sage: p = (x+1)^17 + x^17
sage: r = p.nth_root(17)
Traceback (most recent call last):
...
ValueError: not a 17th power
Here we consider a base ring without nth_root method. The third example with a non-trivial coefficient
of lowest degree raises an error:
number_of_real_roots()
Return the number of real roots of this polynomial, counted without multiplicity.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: pol = (x-1)^2 * (x-2)^2 * (x-3)
sage: pol.number_of_real_roots()
3
sage: pol = (x-1)*(x-2)*(x-3)
sage: pol2 = pol.change_ring(CC)
sage: pol2.number_of_real_roots()
3
sage: R.<x> = PolynomialRing(CC)
sage: pol = (x-1)*(x-CC(I))
sage: pol.number_of_real_roots()
1
number_of_roots_in_interval(a=None, b=None)
Return the number of roots of this polynomial in the interval [a,b], counted without multiplicity. The
endpoints a, b default to -Infinity, Infinity (which are also valid input values).
Calls the PARI routine polsturm. Note that as of version 2.8, PARI includes the left endpoint of the
interval (and no longer uses Sturm’s algorithm on exact inputs). polsturm requires a polynomial with real
coefficients; in case PARI returns an error, we try again after taking the GCD of 𝑠𝑒𝑙𝑓 with its complex
conjugate.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: pol = (x-1)^2 * (x-2)^2 * (x-3)
sage: pol.number_of_roots_in_interval(1, 2)
2
sage: pol.number_of_roots_in_interval(1.01, 2)
1
sage: pol.number_of_roots_in_interval(None, 2)
2
sage: pol.number_of_roots_in_interval(1, Infinity)
3
sage: pol.number_of_roots_in_interval()
3
sage: pol = (x-1)*(x-2)*(x-3)
sage: pol2 = pol.change_ring(CC)
sage: pol2.number_of_roots_in_interval()
3
sage: R.<x> = PolynomialRing(CC)
sage: pol = (x-1)*(x-CC(I))
sage: pol.number_of_roots_in_interval(0,2)
1
number_of_terms()
Returns the number of non-zero coefficients of self. Also called weight, hamming weight or sparsity.
EXAMPLES:
sage: R.<x> = ZZ[]
sage: f = x^3 - x
sage: f.number_of_terms()
2
sage: R(0).number_of_terms()
(continues on next page)
sage: f.hamming_weight()
101
numerator()
Return a numerator of self computed as self * self.denominator()
Note that some subclasses may implement its own numerator function. For example, see sage.rings.
polynomial.polynomial_rational_flint.Polynomial_rational_flint
Warning: This is not the numerator of the rational function defined by self, which would always be
self since self is a polynomial.
EXAMPLES:
First we compute the numerator of a polynomial with integer coefficients, which is of course self.
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.
We check that the computation the numerator and denominator are valid
sage: K=NumberField(symbolic_expression('x^3+2'),'a')['s,t']['x']
sage: f=K.random_element()
sage: f.numerator() / f.denominator() == f
True
sage: R=RR['x']
sage: f=R.random_element()
sage: f.numerator() / f.denominator() == f
True
ord(p=None)
This is the same as the valuation of self at p. See the documentation for self.valuation.
EXAMPLES:
padded_list(n=None)
Return list of coefficients of self up to (but not including) 𝑞 𝑛 .
Includes 0’s in the list on the right so that the list has length 𝑛.
INPUT:
• n - (default: None); if given, an integer that is at least 0
EXAMPLES:
sage: x = polygen(QQ)
sage: f = 1 + x^3 + 23*x^5
sage: f.padded_list()
[1, 0, 0, 1, 0, 23]
sage: f.padded_list(10)
[1, 0, 0, 1, 0, 23, 0, 0, 0, 0]
sage: len(f.padded_list(10))
10
sage: f.padded_list(3)
[1, 0, 0]
sage: f.padded_list(0)
[]
sage: f.padded_list(-1)
Traceback (most recent call last):
...
ValueError: n must be at least 0
sage: x = polygen(GF(389))
sage: plot(x^2 + 1, rgbcolor=(0,0,1))
Graphics object consisting of 1 graphics primitive
sage: x = polygen(QQ)
sage: plot(x^2 + 1, rgbcolor=(1,0,0))
Graphics object consisting of 1 graphics primitive
polynomial(var)
Let var be one of the variables of the parent of self. This returns self viewed as a univariate polynomial in
var over the polynomial ring generated by all the other variables of the parent.
For univariate polynomials, if var is the generator of the parent ring, we return this polynomial, otherwise
raise an error.
EXAMPLES:
power_trunc(n, prec)
Truncated n-th power of this polynomial up to precision prec
INPUT:
• n – (non-negative integer) power to be taken
• prec – (integer) the precision
EXAMPLES:
prec()
Return the precision of this polynomial. This is always infinity, since polynomials are of infinite precision
by definition (there is no big-oh).
EXAMPLES:
sage: x = polygen(ZZ)
sage: (x^5 + x + 1).prec()
+Infinity
sage: x.prec()
+Infinity
pseudo_quo_rem(other)
Compute the pseudo-division of two polynomials.
INPUT:
• other – a nonzero polynomial
OUTPUT:
𝑄 and 𝑅 such that 𝑙𝑚−𝑛+1 self = 𝑄 · other + 𝑅 where 𝑚 is the degree of this polynomial, 𝑛 is the degree
of other, 𝑙 is the leading coefficient of other. The result is such that deg(𝑅) < deg(other).
ALGORITHM:
Algorithm 3.1.2 in [Coh1993].
EXAMPLES:
radical()
Returns the radical of self; over a field, this is the product of the distinct irreducible factors of self. (This
is also sometimes called the “square-free part” of self, but that term is ambiguous; it is sometimes used to
mean the quotient of self by its maximal square factor.)
EXAMPLES:
If self has a factor of multiplicity divisible by the characteristic (see trac ticket #8736):
sage: m = z**21
sage: n, d = p.rational_reconstruct(m)
sage: print((n ,d))
(z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^
˓→3 + z^2 + z + 1)
Over Z[𝑧]:
sage: m = z**21
sage: n, d = p.rational_reconstruct(m)
sage: print((n ,d))
(z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^
˓→3 + z^2 + z + 1)
sage: P = PolynomialRing(ZZ,'x')
sage: x = P.gen()
sage: p = 7*x^5 - 10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256
sage: m = x^5
sage: n, d = p.rational_reconstruct(m, 3, 2)
sage: print((n ,d))
(-32*x^3 + 384*x^2 + 2304*x + 2048, 5*x + 8)
sage: print(((p*d - n) % m ).is_zero())
True
sage: n, d = p.rational_reconstruct(m, 4, 0)
sage: print((n ,d))
(-10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256, 1)
sage: print(((p*d - n) % m ).is_zero())
True
Over Q(𝑡)[𝑧]:
Over Q[𝑡][𝑧]:
Over Q5 :
sage: x = PolynomialRing(Qp(5),'x').gen()
sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2
sage: m = x^6
(continues on next page)
Over R[𝑧]:
See also:
• sage.matrix.berlekamp_massey,
• sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint.
rational_reconstruct()
real_roots()
Return the real roots of this polynomial, without multiplicities.
Calls self.roots(ring=RR), unless this is a polynomial with floating-point real coefficients, in which case it
calls self.roots().
EXAMPLES:
sage: x = polygen(ZZ)
sage: (x^2 - x - 1).real_roots()
[-0.618033988749895, 1.61803398874989]
reciprocal_transform(R=1, q=1)
Transform a general polynomial into a self-reciprocal polynomial.
The input 𝑄 and output 𝑃 satisfy the relation
resultant(other)
Return the resultant of self and other.
INPUT:
• other – a polynomial
OUTPUT: an element of the base ring of the polynomial ring
ALGORITHM:
Uses PARI’s polresultant function. For base rings that are not supported by PARI, the resultant is
computed as the determinant of the Sylvester matrix.
EXAMPLES:
reverse(degree=None)
Return polynomial but with the coefficients reversed.
If an optional degree argument is given the coefficient list will be truncated or zero padded as necessary
before reversing it. Assuming that the constant coefficient of self is nonzero, the reverse polynomial will
have the specified degree.
EXAMPLES:
sage: R.<x> = ZZ[]; S.<y> = R[]
sage: f = y^3 + x*y -3*x; f
y^3 + x*y - 3*x
sage: f.reverse()
-3*x*y^3 + x*y^2 + 1
sage: f.reverse(degree=2)
-3*x*y^2 + x*y
sage: f.reverse(degree=5)
-3*x*y^5 + x*y^4 + y^2
revert_series(n)
Return a polynomial f such that f(self(x)) = self(f(x)) = x mod x^n.
Currently, this is only implemented over some coefficient rings.
EXAMPLES:
sage: Pol.<x> = QQ[]
sage: (x + x^3/6 + x^5/120).revert_series(6)
3/40*x^5 - 1/6*x^3 + x
sage: Pol.<x> = CBF[]
sage: (x + x^3/6 + x^5/120).revert_series(6)
([0.075000000000000 +/- ...e-17])*x^5 + ([-0.166666666666667 +/- ...e-16])*x^
˓→3 + x
root_field(names, check_irreducible=True)
Return the field generated by the roots of the irreducible polynomial self. The output is either a number
field, relative number field, a quotient of a polynomial ring over a field, or the fraction field of the base
ring.
EXAMPLES:
sage: R.<x> = QQ['x']
sage: f = x^3 + x + 17
sage: f.root_field('a')
Number Field in a with defining polynomial x^3 + x + 17
sage: y = QQ['x'].0
sage: L.<a> = NumberField(y^3-2)
sage: R.<x> = L['x']
sage: f = x^3 + x + 17
sage: f.root_field('c')
Number Field in c with defining polynomial x^3 + x + 17 over its base field
sage: alpha^2 + 1
alpha^2 + 1
sage: alpha^3 + alpha^2
1
sage: x = QQ['x'].0
sage: f = x^3 - 1
sage: f.roots()
[(1, 1)]
sage: f.roots(ring=CC) # note -- low order bits slightly different on ppc.
[(1.00000000000000, 1), (-0.500000000000000 - 0.86602540378443...*I, 1), (-0.
˓→500000000000000 + 0.86602540378443...*I, 1)]
A new ring. In the example below, we add the special method _roots_univariate_polynomial to the base
ring, and observe that this method is called instead to find roots of polynomials over this ring. This facility
can be used to easily extend root finding to work over new rings you introduce:
sage: R.<x> = QQ[]
sage: (x^2 + 1).roots()
[]
sage: g = lambda f, *args, **kwds: f.change_ring(CDF).roots()
sage: QQ._roots_univariate_polynomial = g
sage: (x^2 + 1).roots() # abs tol 1e-14
[(2.7755575615628914e-17 - 1.0*I, 1), (0.9999999999999997*I, 1)]
sage: del QQ._roots_univariate_polynomial
An example over RR, which illustrates that only the roots in RR are returned:
sage: x = RR['x'].0
sage: f = x^3 -2
sage: f.roots()
[(1.25992104989487, 1)]
sage: f.factor()
(x - 1.25992104989487) * (x^2 + 1.25992104989487*x + 1.58740105196820)
sage: x = RealField(100)['x'].0
sage: f = x^3 -2
sage: f.roots()
[(1.2599210498948731647672106073, 1)]
sage: x = CC['x'].0
sage: f = x^3 -2
sage: f.roots()
[(1.25992104989487, 1), (-0.62996052494743... - 1.09112363597172*I, 1), (-0.
˓→62996052494743... + 1.09112363597172*I, 1)]
sage: f.roots(algorithm='pari')
[(1.25992104989487, 1), (-0.629960524947437 - 1.09112363597172*I, 1), (-0.
˓→629960524947437 + 1.09112363597172*I, 1)]
Another example showing that only roots in the base ring are returned:
sage: x = polygen(ZZ)
sage: f = (2*x-3) * (x-1) * (x+1)
sage: f.roots()
[(1, 1), (-1, 1)]
sage: f.roots(ring=QQ)
[(3/2, 1), (1, 1), (-1, 1)]
sage: x = CC['x'].0
sage: i = CC.0
sage: f = (x - 1)*(x - i)
(continues on next page)
sage: x = QQ['x'].0
sage: f = x^2 + 2
sage: f.roots(SR)
[(-I*sqrt(2), 1), (I*sqrt(2), 1)]
sage: f.roots(SR, multiplicities=False)
[-I*sqrt(2), I*sqrt(2)]
For some other polynomials, no roots can be found at the moment due to the way roots are computed. trac
ticket #17516 addresses these defecits. Until that gets implemented, one such example is the following:
sage: f = x^6-300*x^5+30361*x^4-1061610*x^3+1141893*x^2-915320*x+101724
sage: f.roots()
[]
sage: X = var('X')
sage: f = expand((X-1)*(X-I)^3*(X^2 - sqrt(2))); f
X^6 - (3*I + 1)*X^5 - sqrt(2)*X^4 + (3*I - 3)*X^4 + (3*I + 1)*sqrt(2)*X^3 +
˓→(I + 3)*X^3 - (3*I - 3)*sqrt(2)*X^2 - I*X^2 - (I + 3)*sqrt(2)*X + I*sqrt(2)
sage: f.roots()
[(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)]
The same operation, performed over a polynomial ring with symbolic coefficients:
sage: X = SR['X'].0
sage: f = (X-1)*(X-I)^3*(X^2 - sqrt(2)); f
X^6 + (-3*I - 1)*X^5 + (-sqrt(2) + 3*I - 3)*X^4 + ((3*I + 1)*sqrt(2) + I +
˓→3)*X^3 + (-(3*I - 3)*sqrt(2) - I)*X^2 + (-(I + 3)*sqrt(2))*X + I*sqrt(2)
sage: f.roots()
[(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)]
sage: f.roots(multiplicities=False)
[I, -2^(1/4), 2^(1/4), 1]
A couple of examples where the base ring does not have a factorization algorithm (yet). Note that this is
currently done via a rather naive enumeration, so could be very slow:
sage: R = Integers(6)
sage: S.<x> = R['x']
sage: p = x^2-1
sage: p.roots()
Traceback (most recent call last):
...
(continues on next page)
sage: p.roots(multiplicities=False)
[5, 1]
sage: R = Integers(9)
sage: A = PolynomialRing(R, 'y')
sage: y = A.gen()
sage: f = 10*y^2 - y^3 - 9
sage: f.roots(multiplicities=False)
[1, 0, 3, 6]
An example over the complex double field (where root finding is fast, thanks to NumPy):
sage: R.<x> = CDF[]
sage: f = R.cyclotomic_polynomial(5); f
x^4 + x^3 + x^2 + x + 1.0
sage: f.roots(multiplicities=False) # abs tol 1e-9
[-0.8090169943749469 - 0.5877852522924724*I, -0.8090169943749473 + 0.
˓→5877852522924724*I, 0.30901699437494773 - 0.951056516295154*I, 0.
˓→30901699437494756 + 0.9510565162951525*I]
˓→9999999999999953 - 2.0212861992297117e-15*I]
sage: f = CDF['x']([1,2,3,4]); f
4.0*x^3 + 3.0*x^2 + 2.0*x + 1.0
sage: r = f.roots(multiplicities=False)
sage: [f(a).abs() for a in r] # abs tol 1e-14
[2.574630599127759e-15, 1.457101633618084e-15, 1.1443916996305594e-15]
sage: f.roots(ring=AA)
[(-0.618033988749895?, 1), (1.618033988749895?, 1)]
sage: f = f^2 * (x - 1)
sage: f.roots(ring=RIF)
[(-0.6180339887498948482045868343657?, 2), (1.0000000000000000000000000000000?
˓→, 1), (1.6180339887498948482045868343657?, 2)]
sage: p.roots(ring=ComplexIntervalField(200))
[(1.167303978261418684256045899854842180720560371525489039140082?, 1), (-0.
˓→76488443360058472602982318770854173032899665194736756700778? - 0.
˓→76488443360058472602982318770854173032899665194736756700778? + 0.
˓→18123244446987538390180023778112063996871646618462304743774? - 1.
˓→18123244446987538390180023778112063996871646618462304743774? + 1.
˓→08395410131771066843034449298076657427364024315511565430114?*I, 1)]
sage: p.roots(ring=AA)
[(1.167303978261419?, 1)]
sage: p = (x - rts[4][0])^2 * (3*x^2 + x + 1)
sage: p.roots(ring=QQbar)
[(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.
˓→552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)]
(continues on next page)
In some cases, it is possible to isolate the roots of polynomials over complex ball fields:
Note that coefficients in a number field with defining polynomial 𝑥2 + 1 are considered to be Gaussian
rationals (with the generator mapping to +I), if you ask for complex roots.
˓→141425052582394?*I, 2)]
Note that one should not use NumPy when wanting high precision output as it does not support any of the
high precision types:
sage: f.roots(algorithm='numpy')
doctest... UserWarning: NumPy does not support arbitrary precision arithmetic.
˓→ The roots found will likely have less precision than you expect.
[(-1.77245385090551..., 1), (1.77245385090551..., 1)]
There are many combinations of floating-point input and output types that work. (Note that some of them
are quite pointless like using algorithm='numpy' with high-precision types.)
˓→62996052494743658238360530364 + 1.0911236359717214035600726142*I]
Note that we can find the roots of a polynomial with algebraic coefficients:
sage: rt2 = sqrt(AA(2))
sage: rt3 = sqrt(AA(3))
sage: x = polygen(AA)
sage: f = (x - rt2) * (x - rt3); f
x^2 - 3.146264369941973?*x + 2.449489742783178?
sage: rts = f.roots(); rts
[(1.414213562373095?, 1), (1.732050807568878?, 1)]
sage: rts[0][0] == rt2
True
sage: f.roots(ring=RealIntervalField(150))
[(1.414213562373095048801688724209698078569671875376948073176679738?, 1), (1.
˓→732050807568877293527446341505872366942805253810380628055806980?, 1)]
Polynomials using such large coefficients can’t be handled by numpy, but pari can deal with them:
sage: x = polygen(QQ)
sage: p = x + bigc
(continues on next page)
Algorithms used:
For brevity, we will use RR to mean any RealField of any precision; similarly for RIF, CC, and CIF. Since
Sage has no specific implementation of Gaussian rationals (or of number fields with embedding, at all),
when we refer to Gaussian rationals below we will accept any number field with defining polynomial
𝑥2 + 1, mapping the field generator to +I.
We call the base ring of the polynomial K, and the ring given by the ring= argument L. (If ring= is not
specified, then L is the same as K.)
If K and L are floating-point (RDF, CDF, RR, or CC), then a floating-point root-finder is used. If L is RDF
or CDF then we default to using NumPy’s roots(); otherwise, we use PARI’s polroots(). This choice can
be overridden with algorithm=’pari’ or algorithm=’numpy’. If the algorithm is unspecified and NumPy’s
roots() algorithm fails, then we fall back to pari (numpy will fail if some coefficient is infinite, for instance).
If L is SR, then the roots will be radical expressions, computed as the solutions of a symbolic polyno-
mial expression. At the moment this delegates to sage.symbolic.expression.Expression.
solve() which in turn uses Maxima to find radical solutions. Some solutions may be lost in this ap-
proach. Once trac ticket #17516 gets implemented, all possible radical solutions should become available.
If L is AA or RIF, and K is ZZ, QQ, or AA, then the root isolation algorithm
sage.rings.polynomial.real_roots.real_roots() is used. (You can call real_roots() directly to get more
control than this method gives.)
If L is QQbar or CIF, and K is ZZ, QQ, AA, QQbar, or the Gaussian rationals, then the root isolation
algorithm sage.rings.polynomial.complex_roots.complex_roots() is used. (You can call complex_roots()
directly to get more control than this method gives.)
If L is AA and K is QQbar or the Gaussian rationals, then complex_roots() is used (as above) to find roots
in QQbar, then these roots are filtered to select only the real roots.
If L is floating-point and K is not, then we attempt to change the polynomial ring to L (using
.change_ring()) (or, if L is complex and K is not, to the corresponding real field). Then we use either
PARI or numpy as specified above.
For all other cases where K is different than L, we just use .change_ring(L) and proceed as below.
The next method, which is used if K is an integral domain, is to attempt to factor the polynomial. If this
succeeds, then for every degree-one factor a*x+b, we add -b/a as a root (as long as this quotient is actually
in the desired ring).
If factoring over K is not implemented (or K is not an integral domain), and K is finite, then we find the
roots by enumerating all elements of K and checking whether the polynomial evaluates to zero at that
value.
Note: We mentioned above that polynomials with multiple roots are always ill-conditioned; if your input
is given to n bits of precision, you should not expect more than n/k good bits for a k-fold root. (You can
get solutions that make the polynomial evaluate to a number very close to zero; basically the problem is
that with a multiple root, there are many such numbers, and it’s difficult to choose between them.)
To see why this is true, consider the naive floating-point error analysis model where you just pretend that
all floating-point numbers are somewhat imprecise - a little ‘fuzzy’, if you will. Then the graph of a
floating-point polynomial will be a fuzzy line. Consider the graph of (𝑥 − 1)3 ; this will be a fuzzy line
with a horizontal tangent at 𝑥 = 1, 𝑦 = 0. If the fuzziness extends up and down by about j, then it will
extend left and right by about cube_root(j).
shift(n)
Returns this polynomial multiplied by the power 𝑥𝑛 . If 𝑛 is negative, terms below 𝑥𝑛 will be discarded.
Does not change this polynomial (since polynomials are immutable).
EXAMPLES:
sage: f = x^3 + x
sage: f >> 2
x
sage: f << 2
x^5 + x^3
AUTHORS:
• David Harvey (2006-08-06)
• Robert Bradshaw (2007-04-18): Added support for infix operator.
specialization(D=None, phi=None)
Specialization of this polynomial.
Given a family of polynomials defined over a polynomial ring. A specialization is a partic-
ular 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:
Relative situation:
With map=True, we also get the embedding of the base field into the splitting field:
If the extension is trivial and the generators have the same name, the map will be the identity:
See also:
sage.rings.number_field.splitting_field.splitting_field() for more examples
over number fields
square()
Returns the square of this polynomial.
Todo:
• This is just a placeholder; for now it just uses ordinary multiplication. But generally speaking, squar-
ing is faster than ordinary multiplication, and it’s frequently used, so subclasses may choose to provide
a specialised squaring routine.
• Perhaps this even belongs at a lower level? RingElement or something?
AUTHORS:
• David Harvey (2006-09-09)
EXAMPLES:
squarefree_decomposition()
Return the square-free decomposition of this polynomial. This is a partial factorization into square-free,
coprime polynomials.
EXAMPLES:
sage: x = polygen(QQ)
sage: p = 37 * (x-1)^3 * (x-2)^3 * (x-1/3)^7 * (x-3/7)
sage: p.squarefree_decomposition()
(37*x - 111/7) * (x^2 - 3*x + 2)^3 * (x - 1/3)^7
sage: p = 37 * (x-2/3)^2
sage: p.squarefree_decomposition()
(37) * (x - 2/3)^2
sage: x = polygen(GF(3))
sage: x.squarefree_decomposition()
x
sage: f = QQbar['x'](1)
sage: f.squarefree_decomposition()
1
subs(*x, **kwds)
Identical to self(*x).
See the docstring for self.__call__.
EXAMPLES:
substitute(*x, **kwds)
Identical to self(*x).
See the docstring for self.__call__.
EXAMPLES:
sylvester_matrix(right, variable=None)
Returns the Sylvester matrix of self and right.
Note that the Sylvester matrix is not defined if one of the polynomials is zero.
INPUT:
• right: a polynomial in the same ring as self.
• variable: optional, included for compatibility with the multivariate case only. The variable of the
polynomials.
EXAMPLES:
If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will
be zero:
sage: M.determinant()
0
If self and right are polynomials of positive degree, the determinant of the Sylvester matrix is the resultant
of the polynomials.:
sage: h1 = R._random_nonzero_element()
sage: h2 = R._random_nonzero_element()
sage: M1 = h1.sylvester_matrix(h2)
sage: M1.determinant() == h1.resultant(h2)
True
The rank of the Sylvester matrix is related to the degree of the gcd of self and right:
symmetric_power(k, monic=False)
Return the polynomial whose roots are products of 𝑘-th distinct roots of this.
EXAMPLES:
sage: x = polygen(QQ)
sage: f = x^4-x+2
sage: [f.symmetric_power(k) for k in range(5)]
[x - 1, x^4 - x + 2, x^6 - 2*x^4 - x^3 - 4*x^2 + 8, x^4 - x^3 + 8, x - 2]
sage: f = x^5-2*x+2
sage: [f.symmetric_power(k) for k in range(6)]
[x - 1,
x^5 - 2*x + 2,
x^10 + 2*x^8 - 4*x^6 - 8*x^5 - 8*x^4 - 8*x^3 + 16,
x^10 + 4*x^7 - 8*x^6 + 16*x^5 - 16*x^4 + 32*x^2 + 64,
x^5 + 2*x^4 - 16,
x + 2]
trace_polynomial()
Compute the trace polynomial and cofactor.
The input 𝑃 and output 𝑄 satisfy the relation
We check that this function works for rings that have a coercion to the reals:
sage: K.<a> = NumberField(x^2-2,embedding=1.4)
sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4
(continues on next page)
truncate(n)
Returns the polynomial of degree ‘ < n‘ which is equivalent to self modulo 𝑥𝑛 .
EXAMPLES:
valuation(p=None)
If 𝑓 = 𝑎𝑟 𝑥𝑟 + 𝑎𝑟+1 𝑥𝑟+1 + · · ·, with 𝑎𝑟 nonzero, then the valuation of 𝑓 is 𝑟. The valuation of the zero
polynomial is ∞.
If a prime (or non-prime) 𝑝 is given, then the valuation is the largest power of 𝑝 which divides self.
The valuation at ∞ is -self.degree().
EXAMPLES:
variable_name()
Return name of variable used in this polynomial as a string.
OUTPUT: string
EXAMPLES:
variables()
Returns the tuple of variables occurring in this polynomial.
EXAMPLES:
sage: R(2).variables()
()
xgcd(other)
Return an extended gcd of this polynomial and other.
INPUT:
• other – a polynomial in the same ring as this polynomial
OUTPUT:
A tuple (r, s, t) where r is a greatest common divisor of this polynomial and other, and s and t
are such that r = s*self + t*other holds.
Note: The actual algorithm for computing the extended gcd depends on the base ring underlying the
polynomial ring. If the base ring defines a method _xgcd_univariate_polynomial, then this
method will be called (see examples below).
EXAMPLES:
One can easily add xgcd functionality to new rings by providing a method
_xgcd_univariate_polynomial:
class sage.rings.polynomial.polynomial_element.PolynomialBaseringInjection
Bases: sage.categories.morphism.Morphism
This class is used for conversion from a ring to a polynomial over that ring.
It calls the _new_constant_poly method on the generator, which should be optimized for a particular polynomial
type.
Technically, it should be a method of the polynomial ring, but few polynomial rings are cython classes, and so,
as a method of a cython polynomial class, it is faster.
EXAMPLES:
We demonstrate that most polynomial ring classes use polynomial base injection maps for coercion. They are
supposed to be the fastest maps for that purpose. See trac ticket #9944.
By trac ticket #9944, there are now only very few exceptions:
sage: PolynomialRing(QQ,names=[]).coerce_map_from(QQ)
Generic morphism:
From: Rational Field
To: Multivariate Polynomial Ring in no variables over Rational Field
is_injective()
Return whether this morphism is injective.
EXAMPLES:
is_surjective()
Return whether this morphism is surjective.
EXAMPLES:
section()
class sage.rings.polynomial.polynomial_element.Polynomial_generic_dense
Bases: sage.rings.polynomial.polynomial_element.Polynomial
A generic dense polynomial.
EXAMPLES:
sage: f = QQ['x']['y'].random_element()
sage: loads(f.dumps()) == f
True
constant_coefficient()
Return the constant coefficient of this polynomial.
OUTPUT: element of base ring
EXAMPLES: sage: R.<t> = QQ[] sage: S.<x> = R[] sage: f = x*t + x + t sage: f.constant_coefficient() t
degree(gen=None)
EXAMPLES:
is_term()
Return True if this polynomial is a nonzero element of the base ring times a power of the variable.
EXAMPLES:
list(copy=True)
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
sage: R.<x> = GF(17)[]
sage: f = (1+2*x)^3 + 3*x; f
8*x^3 + 12*x^2 + 9*x + 1
sage: f.list()
[1, 9, 12, 8]
quo_rem(other)
Return the quotient and remainder of the Euclidean division of self and other.
Raises a ZerodivisionError if other is zero. Raises an ArithmeticError if the division is not
exact.
AUTHORS:
• Kwankyu Lee (2013-06-02)
• Bruno Grenet (2014-07-13)
EXAMPLES:
sage: P.<x> = QQ[]
sage: R.<y> = P[]
sage: f = R.random_element(10)
sage: g = y^5+R.random_element(4)
sage: q,r = f.quo_rem(g)
sage: f == q*g + r
True
sage: g = x*y^5
sage: f.quo_rem(g)
Traceback (most recent call last):
...
ArithmeticError: division non exact (consider coercing to polynomials over
˓→the fraction field)
sage: g = 0
sage: f.quo_rem(g)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero polynomial
shift(n)
Returns this polynomial multiplied by the power 𝑥𝑛 . If 𝑛 is negative, terms below 𝑥𝑛 will be discarded.
Does not change this polynomial.
EXAMPLES:
sage: R.<x> = PolynomialRing(PolynomialRing(QQ,'y'), 'x')
sage: p = x^2 + 2*x + 4
sage: type(p)
<type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>
sage: p.shift(0)
(continues on next page)
AUTHORS:
• David Harvey (2006-08-06)
truncate(n)
Returns the polynomial of degree ‘ < n‘ which is equivalent to self modulo 𝑥𝑛 .
EXAMPLES:
sage: type(f)
<type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>
class sage.rings.polynomial.polynomial_element.Polynomial_generic_dense_inexact
Bases: sage.rings.polynomial.polynomial_element.Polynomial_generic_dense
A dense polynomial over an inexact ring.
AUTHOR:
• Xavier Caruso (2013-03)
degree(secure=False)
INPUT:
• secure – a boolean (default: False)
OUTPUT:
The degree of self.
If secure is True and the degree of this polynomial is not determined (because the leading coefficient is
indistinguishable from 0), an error is raised
If secure is False, the returned value is the largest 𝑛 so that the coefficient of 𝑥𝑛 does not compare equal
to 0.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.degree()
1
(continues on next page)
sage: x = O(3^5)
sage: li = [3^i * x for i in range(0,5)]; li
[O(3^5), O(3^6), O(3^7), O(3^8), O(3^9)]
sage: f = R(li); f
O(3^9)*T^4 + O(3^8)*T^3 + O(3^7)*T^2 + O(3^6)*T + O(3^5)
sage: f.degree()
-1
sage: f.degree(secure=True)
Traceback (most recent call last):
...
PrecisionError: the leading coefficient is indistinguishable from 0
AUTHOR:
• Xavier Caruso (2013-03)
prec_degree()
Returns the largest 𝑛 so that precision information is stored about the coefficient of 𝑥𝑛 .
Always greater than or equal to degree.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.degree()
1
sage: f.prec_degree()
1
sage: g = f - T; g
O(3^10)*T + 2 + O(3^10)
sage: g.degree()
0
sage: g.prec_degree()
1
AUTHOR:
• Xavier Caruso (2013-03)
sage.rings.polynomial.polynomial_element.generic_power_trunc(p, n, prec)
Generic truncated power algorithm
INPUT:
• p - a polynomial
• n - an integer (of type sage.rings.integer.Integer)
• prec - a precision (should fit into a C long)
sage.rings.polynomial.polynomial_element.is_Polynomial(f )
Return True if f is of type univariate polynomial.
INPUT:
• f - an object
EXAMPLES:
However this function does not return True for genuine multivariate polynomial type objects or symbolic poly-
nomials, since those are not of the same data type as univariate polynomials:
sage.rings.polynomial.polynomial_element.make_generic_polynomial(parent,
coeffs)
sage.rings.polynomial.polynomial_element.universal_discriminant(n)
Return the discriminant of the ‘universal’ univariate polynomial 𝑎𝑛 𝑥𝑛 + · · · + 𝑎1 𝑥 + 𝑎0 in Z[𝑎0 , . . . , 𝑎𝑛 ][𝑥].
INPUT:
• n - degree of the polynomial
OUTPUT:
The discriminant as a polynomial in 𝑛 + 1 variables over Z. The result will be cached, so subsequent computa-
tions of discriminants of the same degree will be faster.
EXAMPLES:
See also:
Polynomial.discriminant()
AUTHORS:
• William Stein: first version
• Martin Albrecht: Added singular coercion.
• David Harvey: split off polynomial_integer_dense_ntl.pyx (2007-09)
• Robert Bradshaw: split off polynomial_modn_dense_ntl.pyx (2007-09)
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdv(parent,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_domain
A generic class for polynomials over complete discrete valuation domains and fields.
AUTHOR:
• Xavier Caruso (2013-03)
factor_of_slope(slope=None)
INPUT:
• slope – a rational number (default: the first slope in the Newton polygon of self)
OUTPUT:
The factor of self corresponding to the slope slope (i.e. the unique monic divisor of self whose slope
is slope and degree is the length of slope in the Newton polygon).
EXAMPLES:
sage: K = Qp(5)
sage: R.<x> = K[]
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 3*t + t^4 + 25*t^10
sage: f.newton_slopes()
[1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
sage: g = f.factor_of_slope(0)
sage: g.newton_slopes()
[0, 0, 0]
sage: (f % g).is_zero()
True
sage: h = f.factor_of_slope()
sage: h.newton_slopes()
[1]
sage: (f % h).is_zero()
True
sage: f.factor_of_slope(-1)
1 + O(5^20)
AUTHOR:
• Xavier Caruso (2013-03-20)
hensel_lift(a)
Lift 𝑎 to a root of this polynomial (using Newton iteration).
If 𝑎 is not close enough to a root (so that Newton iteration does not converge), an error is raised.
EXAMPLES:
sage: K = Qp(5, 10)
sage: P.<x> = PolynomialRing(K)
sage: f = x^2 + 1
sage: root = f.hensel_lift(2); root
2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10)
sage: f(root)
O(5^10)
AUTHOR:
• Xavier Caruso (2013-03-23)
newton_polygon()
Returns a list of vertices of the Newton polygon of this polynomial.
EXAMPLES:
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 3*t + t^4 + 25*t^10
sage: f.newton_polygon()
Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2)
sage: g = f + K(0,0)*t^4; g
(5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21)
sage: g.newton_polygon()
Traceback (most recent call last):
...
PrecisionError: The coefficient of t^4 has not enough precision
AUTHOR:
• Xavier Caruso (2013-03-20)
newton_slopes(repetition=True)
Returns a list of the Newton slopes of this polynomial.
These are the valuations of the roots of this polynomial.
If repetition is True, each slope is repeated a number of times equal to its multiplicity. Otherwise it
appears only one time.
EXAMPLES:
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 3*t + t^4 + 25*t^10
sage: f.newton_polygon()
Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2)
sage: f.newton_slopes()
[1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
sage: f.newton_slopes(repetition=False)
[1, 0, -1/3]
AUTHOR:
• Xavier Caruso (2013-03-20)
slope_factorization()
Return a factorization of self into a product of factors corresponding to each slope in the Newton poly-
gon.
EXAMPLES:
sage: K = Qp(5)
sage: R.<x> = K[]
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 3*t + t^4 + 25*t^10
sage: f.newton_slopes()
[1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
sage: F = f.slope_factorization()
sage: F.prod() == f
True
sage: for (f,_) in F:
....: print(f.newton_slopes())
[-1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
[0, 0, 0]
[1]
AUTHOR:
• Xavier Caruso (2013-03-20)
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdvf(parent,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_cdv, sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_field
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdvr(parent,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_cdv
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_cdv
Bases: sage.rings.polynomial.polynomial_element.Polynomial_generic_dense_inexact,
sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdv
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_cdvf
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_dense_cdv, sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_cdvf
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_cdvr
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_dense_cdv, sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_cdvr
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field(parent,
x=Non
check=
is_gen=
con-
struct=
Bases: sage.rings.polynomial.polynomial_element.Polynomial_generic_dense,
sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_field
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_domain(parent,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_element.Polynomial, sage.structure.
element.IntegralDomainElement
is_unit()
Return True if this polynomial is a unit.
𝑎𝑖 𝑥𝑖 ∈
∑︀
EXERCISE (Atiyah-McDonald, Ch 1): Let 𝐴[𝑥] be a polynomial ring in one variable. Then 𝑓 =
𝐴[𝑥] is a unit if and only if 𝑎0 is a unit and 𝑎1 , . . . , 𝑎𝑛 are nilpotent.
EXAMPLES:
sage: R.<z> = PolynomialRing(ZZ, sparse=True)
sage: (2 + z^3).is_unit()
False
sage: f = -1 + 3*z^3; f
3*z^3 - 1
sage: f.is_unit()
False
sage: R(-3).is_unit()
False
sage: R(-1).is_unit()
True
sage: R(0).is_unit()
False
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_field(parent,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_singular_interface.
Polynomial_singular_repr, sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_domain, sage.structure.element.EuclideanDomainElement
quo_rem(other)
Returns a tuple (quotient, remainder) where self = quotient * other + remainder.
EXAMPLES:
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse(parent,
x=None,
check=True,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_element.Polynomial
A generic sparse polynomial.
The Polynomial_generic_sparse class defines functionality for sparse polynomials over any base ring.
A sparse polynomial is represented using a dictionary which maps each exponent to the corresponding coeffi-
cient. The coefficients must never be zero.
EXAMPLES:
sage: loads(f.dumps()) == f
True
sage: s + T
s + Tbar
sage: (s + T)**2
s^2 + 2*Tbar*s + 4
coefficients(sparse=True)
Return the coefficients of the monomials appearing in self.
EXAMPLES:
degree(gen=None)
Return the degree of this sparse polynomial.
EXAMPLES:
dict()
Return a new copy of the dict of the underlying elements of self.
EXAMPLES:
exponents()
Return the exponents of the monomials appearing in self.
EXAMPLES:
gcd(other, algorithm=None)
Return the gcd of this polynomial and other
INPUT:
• other – a polynomial defined over the same ring as this polynomial.
ALGORITHM:
Two algorithms are provided:
• generic: Uses the generic implementation, which depends on the base ring being a UFD or a field.
• dense: The polynomials are converted to the dense representation, their gcd is computed and is
converted back to the sparse representation.
Default is dense for polynomials over ZZ and generic in the other cases.
EXAMPLES:
integral(var=None)
Return the integral of this polynomial.
By default, the integration variable is the variable of the polynomial.
Otherwise, the integration variable is the optional parameter var
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ, sparse=True)
sage: (1 + 3*x^10 - 2*x^100).integral()
-2/101*x^101 + 3/11*x^11 + x
list(copy=True)
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
sage: R.<z> = PolynomialRing(Integers(100), sparse=True)
sage: f = 13*z^5 + 15*z^2 + 17*z
sage: f.list()
[0, 17, 15, 0, 0, 13]
number_of_terms()
Return the number of nonzero terms.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ,sparse=True)
sage: p = x^100 - 3*x^10 + 12
sage: p.number_of_terms()
3
quo_rem(other)
Returns the quotient and remainder of the Euclidean division of self and other.
Raises ZerodivisionError if other is zero. Raises ArithmeticError if other has a nonunit leading coef-
ficient.
EXAMPLES:
sage: P.<x> = PolynomialRing(ZZ,sparse=True)
sage: R.<y> = PolynomialRing(P,sparse=True)
sage: f = R.random_element(10)
sage: g = y^5+R.random_element(4)
sage: q,r = f.quo_rem(g)
sage: f == q*g + r and r.degree() < g.degree()
(continues on next page)
sage: g = 0
sage: f.quo_rem(g)
Traceback (most recent call last):
...
ZeroDivisionError: Division by zero polynomial
AUTHORS:
• Bruno Grenet (2014-07-09)
reverse(degree=None)
Return this polynomial but with the coefficients reversed.
If an optional degree argument is given the coefficient list will be truncated or zero padded as necessary
and the reverse polynomial will have the specified degree.
EXAMPLES:
shift(n)
Returns this polynomial multiplied by the power 𝑥𝑛 .
If 𝑛 is negative, terms below 𝑥𝑛 will be discarded. Does not change this polynomial.
EXAMPLES:
sage: p.shift(0)
x^100000 + 2*x + 4
sage: p.shift(-1)
x^99999 + 2
sage: p.shift(-100002)
0
sage: p.shift(2)
x^100002 + 2*x^3 + 4*x^2
valuation()
Return the valuation of self.
EXAMPLES:
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse_cdv(parent,
x=None
check=T
is_gen=
con-
struct=F
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_sparse, sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_cdv
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse_cdvf(parent,
x=Non
check=
is_gen=
con-
struct=
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_sparse_cdv, sage.rings.polynomial.
polynomial_element_generic.Polynomial_generic_cdvf
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse_cdvr(parent,
x=Non
check=
is_gen=
con-
struct=
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_sparse_cdv, sage.rings.polynomial.
polynomial_element_generic.Polynomial_generic_cdvr
class sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse_field(paren
x=No
check
is_ge
con-
struct
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_sparse, sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_field
EXAMPLES:
sage: loads(f.dumps()) == f
True
sage.rings.polynomial.polynomial_gf2x.GF2X_BuildRandomIrred_list(n)
Return the list of coefficients of an irreducible polynomial of degree 𝑛 of minimal weight over the field of 2
elements.
EXAMPLES:
sage.rings.polynomial.polynomial_gf2x.GF2X_BuildSparseIrred_list(n)
Return the list of coefficients of an irreducible polynomial of degree 𝑛 of minimal weight over the field of 2
elements.
EXAMPLES:
class sage.rings.polynomial.polynomial_gf2x.Polynomial_GF2X
Bases: sage.rings.polynomial.polynomial_gf2x.Polynomial_template
Univariate Polynomials over GF(2) via NTL’s GF2X.
EXAMPLES:
sage: P.<x> = GF(2)[]
sage: x^3 + x^2 + 1
x^3 + x^2 + 1
is_irreducible()
Return whether this polynomial is irreducible over F2 .‘
EXAMPLES:
sage: R.<x> = GF(2)[]
sage: (x^2 + 1).is_irreducible()
False
sage: (x^3 + x + 1).is_irreducible()
True
modular_composition(g, h, algorithm=None)
Compute 𝑓 (𝑔) (mod ℎ).
Both implementations use Brent-Kung’s Algorithm 2.1 (Fast Algorithms for Manipulation of Formal
Power Series, JACM 1978).
INPUT:
• g – a polynomial
• h – a polynomial
• algorithm – either ‘native’ or ‘ntl’ (default: ‘native’)
EXAMPLES:
sage: P.<x> = GF(2)[]
sage: r = 279
sage: f = x^r + x +1
sage: g = x^r
sage: g.modular_composition(g, f) == g(g) % f
True
sage: g = x^31 + x^30 + x^28 + x^26 + x^24 + x^21 + x^19 + x^18 + x^11 + x^10
˓→+ x^9 + x^8 + x^5 + x^2 + 1
sage: h = x^30 + x^28 + x^26 + x^25 + x^24 + x^22 + x^21 + x^18 + x^17 + x^15
˓→+ x^13 + x^12 + x^11 + x^10 + x^9 + x^4
(continues on next page)
AUTHORS:
• Paul Zimmermann (2008-10) initial implementation
• Martin Albrecht (2008-10) performance improvements
class sage.rings.polynomial.polynomial_gf2x.Polynomial_template
Bases: sage.rings.polynomial.polynomial_element.Polynomial
Template for interfacing to external C / C++ libraries for implementations of polynomials.
AUTHORS:
• Robert Bradshaw (2008-10): original idea for templating
• Martin Albrecht (2008-10): initial implementation
This file implements a simple templating engine for linking univariate polynomials to their C/C++ library imple-
mentations. It requires a ‘linkage’ file which implements the celement_ functions (see sage.libs.ntl.
ntl_GF2X_linkage for an example). Both parts are then plugged together by inclusion of the linkage file
when inheriting from this class. See sage.rings.polynomial.polynomial_gf2x for an example.
We illustrate the generic glueing using univariate polynomials over GF(2).
Note: Implementations using this template MUST implement coercion from base ring elements and
get_unsafe(). See Polynomial_GF2X for an example.
degree()
EXAMPLES:
gcd(other)
Return the greatest common divisor of self and other.
EXAMPLES:
get_cparent()
is_gen()
EXAMPLES:
is_one()
EXAMPLES:
is_zero()
EXAMPLES:
list(copy=True)
EXAMPLES:
quo_rem(right)
EXAMPLES:
shift(n)
EXAMPLES:
truncate(n)
Returns this polynomial mod 𝑥𝑛 .
EXAMPLES:
If the precision is higher than the degree of the polynomial then the polynomial itself is returned:
sage: f.truncate(10) is f
True
xgcd(other)
Computes extended gcd of self and other.
EXAMPLES:
sage.rings.polynomial.polynomial_gf2x.make_element(parent, args)
AUTHOR:
• Luis Felipe Tabera Alonso (2014-02): initial version.
EXAMPLES:
Define a polynomial over an absolute number field and perform basic operations with them:
sage: x = var('x')
sage: Q7 = Qp(7)
sage: r1 = Q7(3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 +\
6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 +\
4*7^18 + 6*7^19)
sage: N.<b> = NumberField(x^2-2, embedding = r1)
sage: K.<t> = N[]
sage: f = t^3-2*t+1
sage: f(r1)
1 + O(7^20)
class sage.rings.polynomial.polynomial_number_field.Polynomial_absolute_number_field_dense(
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_dense_field
Class of dense univariate polynomials over an absolute number field.
gcd(other)
Compute the monic gcd of two univariate polynomials using PARI.
INPUT:
• other – a polynomial with the same parent as self.
OUTPUT:
• The monic gcd of self and other.
EXAMPLES:
class sage.rings.polynomial.polynomial_number_field.Polynomial_relative_number_field_dense(
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_dense_field
Class of dense univariate polynomials over a relative number field.
gcd(other)
Compute the monic gcd of two polynomials.
Currently, the method checks corner cases in which one of the polynomials is zero or a constant. Then,
computes an absolute extension and performs the computations there.
INPUT:
• other – a polynomial with the same parent as self.
OUTPUT:
• The monic gcd of self and other.
See Polynomial_absolute_number_field_dense.gcd() for more details.
EXAMPLES:
AUTHORS:
• David Harvey: rewrote to talk to NTL directly, instead of via ntl.pyx (2007-09); a lot of this was based on Joel
Mohler’s recent rewrite of the NTL wrapper
• David Harvey: split off from polynomial_element_generic.py (2007-09)
• Burcin Erocal: rewrote to use FLINT (2008-06-16)
class sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint
Bases: sage.rings.polynomial.polynomial_element.Polynomial
A dense polynomial over the integers, implemented via FLINT.
_add_(right)
Returns self plus right.
EXAMPLES:
_sub_(right)
Return self minus right.
EXAMPLES:
_lmul_(right)
Returns self multiplied by right, where right is a scalar (integer).
EXAMPLES:
_rmul_(right)
Returns self multiplied by right, where right is a scalar (integer).
EXAMPLES:
_mul_(right)
Returns self multiplied by right.
EXAMPLES:
_mul_trunc_(right, n)
Truncated multiplication
See also:
_mul_() for standard multiplication
EXAMPLES:
sage: x = polygen(ZZ)
sage: p1 = 1 + x + x^2 + x^4
sage: p2 = -2 + 3*x^2 + 5*x^4
sage: p1._mul_trunc_(p2, 4)
3*x^3 + x^2 - 2*x - 2
sage: (p1*p2).truncate(4)
3*x^3 + x^2 - 2*x - 2
sage: p1._mul_trunc_(p2, 6)
5*x^5 + 6*x^4 + 3*x^3 + x^2 - 2*x - 2
content()
Return the greatest common divisor of the coefficients of this polynomial. The sign is the sign of the
leading coefficient. The content of the zero polynomial is zero.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: (2*x^2 - 4*x^4 + 14*x^7).content()
2
sage: x.content()
1
sage: R(1).content()
1
sage: R(0).content()
0
degree(gen=None)
Return the degree of this polynomial.
The zero polynomial has degree -1.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: x.degree()
1
sage: (x^2).degree()
2
sage: R(1).degree()
0
sage: R(0).degree()
-1
disc(proof=True)
Return the discriminant of self, which is by definition
where 𝑚 = deg(𝑎), and lc(𝑎) is the leading coefficient of a. If proof is False (the default is True), then
this function may use a randomized strategy that errors with probability no more than 2−80 .
EXAMPLES:
sage: R.<x> = ZZ[]
sage: f = 3*x^3 + 2*x + 1
sage: f.discriminant()
-339
sage: f.discriminant(proof=False)
-339
discriminant(proof=True)
Return the discriminant of self, which is by definition
where 𝑚 = deg(𝑎), and lc(𝑎) is the leading coefficient of a. If proof is False (the default is True), then
this function may use a randomized strategy that errors with probability no more than 2−80 .
EXAMPLES:
factor()
This function overrides the generic polynomial factorization to make a somewhat intelligent decision to
use Pari or NTL based on some benchmarking.
Note: This function factors the content of the polynomial, which can take very long if it’s a really big
integer. If you do not need the content factored, divide it out of your polynomial before calling this
function.
EXAMPLES:
sage: R.<x>=ZZ[]
sage: f=x^4-1
sage: f.factor()
(x - 1) * (x + 1) * (x^2 + 1)
sage: f=1-x
sage: f.factor()
(-1) * (x - 1)
sage: f.factor().unit()
-1
sage: f = -30*x; f.factor()
(-1) * 2 * 3 * 5 * x
factor_mod(p)
Return the factorization of self modulo the prime 𝑝.
INPUT:
• p – prime
OUTPUT:
factorization of self reduced modulo p.
EXAMPLES:
sage: f = 2*x*(x-2)*(x-9)
sage: f.factor_mod(7)
(2) * x * (x + 5)^2
factor_padic(p, prec=10)
Return 𝑝-adic factorization of self to given precision.
INPUT:
• p – prime
• prec – integer; the precision
OUTPUT:
• factorization of self over the completion at 𝑝.
EXAMPLES:
gcd(right)
Return the GCD of self and right. The leading coefficient need not be 1.
EXAMPLES:
inverse_series_trunc(prec)
Return a polynomial approximation of precision prec of the inverse series of this polynomial.
EXAMPLES:
sage: x = polygen(ZZ)
sage: p = 1+x+2*x^2
sage: q5 = p.inverse_series_trunc(5)
sage: q5
-x^4 + 3*x^3 - x^2 - x + 1
sage: p*q5
-2*x^6 + 5*x^5 + 1
sage: (x-1).inverse_series_trunc(5)
(continues on next page)
is_one()
Returns True if self is equal to one.
EXAMPLES:
is_zero()
Returns True if self is equal to zero.
EXAMPLES:
lcm(right)
Return the LCM of self and right.
EXAMPLES:
list(copy=True)
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
sage: x = PolynomialRing(ZZ,'x').0
sage: f = x^3 + 3*x - 17
sage: f.list()
[-17, 3, 0, 1]
sage: f = PolynomialRing(ZZ,'x')(0)
sage: f.list()
[]
pseudo_divrem(B)
Write A = self. This function computes polynomials 𝑄 and 𝑅 and an integer 𝑑 such that
lead(𝐵)𝑑 𝐴 = 𝐵𝑄 + 𝑅
quo_rem(right)
Attempts to divide self by right, and return a quotient and remainder.
EXAMPLES:
sage: f = x^2
sage: f.quo_rem(0)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero polynomial
sage: f = x^2
sage: f.quo_rem(2*x - 1)
(0, x^2)
real_root_intervals()
Returns isolating intervals for the real roots of this polynomial.
EXAMPLES: We compute the roots of the characteristic polynomial of some Salem numbers:
resultant(other, proof=True)
Returns the resultant of self and other, which must lie in the same polynomial ring.
If proof = False (the default is proof=True), then this function may use a randomized strategy
that errors with probability no more than 2−80 .
INPUT:
• other – a polynomial
OUTPUT:
an element of the base ring of the polynomial ring
EXAMPLES:
sage: x = PolynomialRing(ZZ,'x').0
sage: f = x^3 + x + 1; g = x^3 - x - 1
sage: r = f.resultant(g); r
-8
sage: r.parent() is ZZ
True
reverse(degree=None)
Return a polynomial with the coefficients of this polynomial reversed.
If an optional degree argument is given the coefficient list will be truncated or zero padded as necessary
and the reverse polynomial will have the specified degree.
EXAMPLES:
revert_series(n)
Return a polynomial 𝑓 such that 𝑓 (𝑠𝑒𝑙𝑓 (𝑥)) = 𝑠𝑒𝑙𝑓 (𝑓 (𝑥)) = 𝑥𝑚𝑜𝑑𝑥𝑛 .
EXAMPLES:
sage: f.revert_series(-1)
Traceback (most recent call last):
...
ValueError: argument n must be a non-negative integer, got -1
(continues on next page)
squarefree_decomposition()
Return the square-free decomposition of self. This is a partial factorization of self into square-free, rela-
tively prime polynomials.
This is a wrapper for the NTL function SquareFreeDecomp.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ)
sage: p = (x-1)^2 * (x-2)^2 * (x-3)^3 * (x-4)
sage: p.squarefree_decomposition()
(x - 4) * (x^2 - 3*x + 2)^2 * (x - 3)^3
sage: p = 37 * (x-1)^2 * (x-2)^2 * (x-3)^3 * (x-4)
sage: p.squarefree_decomposition()
(37) * (x - 4) * (x^2 - 3*x + 2)^2 * (x - 3)^3
xgcd(right)
Return a triple (g,s,t) such that 𝑔 = 𝑠 * 𝑠𝑒𝑙𝑓 + 𝑡 * 𝑟𝑖𝑔ℎ𝑡 and such that 𝑔 is the 𝑔𝑐𝑑 of self and right
up to a divisor of the resultant of self and other.
As integer polynomials do not form a principal ideal domain, it is not always possible given 𝑎 and 𝑏 to find
a pair 𝑠, 𝑡 such that 𝑔𝑐𝑑(𝑎, 𝑏) = 𝑠𝑎 + 𝑡𝑏. Take 𝑎 = 𝑥 + 2 and 𝑏 = 𝑥 + 4 as an example for which the gcd
is 1 but the best you can achieve in the Bezout identity is 2.
If self and right are coprime as polynomials over the rationals, then g is guaranteed to be the resultant
of self and right, as a constant polynomial.
EXAMPLES:
sage: P.<x> = PolynomialRing(ZZ)
sage: (x+2).xgcd(x+4)
(2, -1, 1)
sage: (x+2).resultant(x+4)
2
sage: (x+2).gcd(x+4)
1
AUTHORS:
• David Harvey: split off from polynomial_element_generic.py (2007-09)
• David Harvey: rewrote to talk to NTL directly, instead of via ntl.pyx (2007-09); a lot of this was based on Joel
Mohler’s recent rewrite of the NTL wrapper
Sage includes two implementations of dense univariate polynomials over Z; this file contains the implemen-
tation based on NTL, but there is also an implementation based on FLINT in sage.rings.polynomial.
polynomial_integer_dense_flint.
The FLINT implementation is preferred (FLINT’s arithmetic operations are generally faster), so it is the default; to
use the NTL implementation, you can do:
class sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl
Bases: sage.rings.polynomial.polynomial_element.Polynomial
A dense polynomial over the integers, implemented via NTL.
content()
Return the greatest common divisor of the coefficients of this polynomial. The sign is the sign of the
leading coefficient. The content of the zero polynomial is zero.
EXAMPLES:
degree(gen=None)
Return the degree of this polynomial. The zero polynomial has degree -1.
EXAMPLES:
discriminant(proof=True)
Return the discriminant of self, which is by definition
where 𝑚 = 𝑑𝑒𝑔(𝑎), and 𝑙𝑐(𝑎) is the leading coefficient of a. If proof is False (the default is True), then
this function may use a randomized strategy that errors with probability no more than 2−80 .
EXAMPLES:
sage: f = ntl.ZZX([1,2,0,3])
sage: f.discriminant()
-339
sage: f.discriminant(proof=False)
-339
factor()
This function overrides the generic polynomial factorization to make a somewhat intelligent decision to
use Pari or NTL based on some benchmarking.
Note: This function factors the content of the polynomial, which can take very long if it’s a really big
integer. If you do not need the content factored, divide it out of your polynomial before calling this
function.
EXAMPLES:
sage: R.<x>=ZZ[]
sage: f=x^4-1
sage: f.factor()
(x - 1) * (x + 1) * (x^2 + 1)
sage: f=1-x
sage: f.factor()
(-1) * (x - 1)
sage: f.factor().unit()
-1
sage: f = -30*x; f.factor()
(-1) * 2 * 3 * 5 * x
factor_mod(p)
Return the factorization of self modulo the prime p.
INPUT:
• p – prime
OUTPUT: factorization of self reduced modulo p.
EXAMPLES:
sage: f = 2*x*(x-2)*(x-9)
sage: f.factor_mod(7)
(2) * x * (x + 5)^2
factor_padic(p, prec=10)
Return 𝑝-adic factorization of self to given precision.
INPUT:
• p – prime
• prec – integer; the precision
OUTPUT:
• factorization of self over the completion at 𝑝.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ, implementation='NTL')
sage: f = x^2 + 1
sage: f.factor_padic(5, 4)
((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) * ((1 + O(5^4))*x + 3 + 3*5 +
˓→2*5^2 + 3*5^3 + O(5^4))
gcd(right)
Return the GCD of self and right. The leading coefficient need not be 1.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ, implementation='NTL')
sage: f = (6*x + 47)*(7*x^2 - 2*x + 38)
sage: g = (6*x + 47)*(3*x^3 + 2*x + 1)
sage: f.gcd(g)
6*x + 47
lcm(right)
Return the LCM of self and right.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ, implementation='NTL')
sage: f = (6*x + 47)*(7*x^2 - 2*x + 38)
(continues on next page)
list(copy=True)
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
sage: x = PolynomialRing(ZZ,'x',implementation='NTL').0
sage: f = x^3 + 3*x - 17
sage: f.list()
[-17, 3, 0, 1]
sage: f = PolynomialRing(ZZ,'x',implementation='NTL')(0)
sage: f.list()
[]
quo_rem(right)
Attempts to divide self by right, and return a quotient and remainder.
If right is monic, then it returns (q, r) where 𝑠𝑒𝑙𝑓 = 𝑞 * 𝑟𝑖𝑔ℎ𝑡 + 𝑟 and 𝑑𝑒𝑔(𝑟) < 𝑑𝑒𝑔(𝑟𝑖𝑔ℎ𝑡).
If right is not monic, then it returns (𝑞, 0) where q = self/right if right exactly divides self, otherwise it
raises an exception.
EXAMPLES:
sage: 0//(2*x)
0
sage: f = x^2
sage: f.quo_rem(0)
Traceback (most recent call last):
...
ArithmeticError: division by zero polynomial
sage: f = x^2
sage: f.quo_rem(2*x - 1)
Traceback (most recent call last):
...
ArithmeticError: division not exact in Z[x] (consider coercing to Q[x] first)
real_root_intervals()
Returns isolating intervals for the real roots of this polynomial.
EXAMPLES: We compute the roots of the characteristic polynomial of some Salem numbers:
sage: R.<x> = PolynomialRing(ZZ, implementation='NTL')
sage: f = 1 - x^2 - x^3 - x^4 + x^6
sage: f.real_root_intervals()
[((1/2, 3/4), 1), ((1, 3/2), 1)]
resultant(other, proof=True)
Returns the resultant of self and other, which must lie in the same polynomial ring.
If proof = False (the default is proof=True), then this function may use a randomized strategy that errors
with probability no more than 2−80 .
INPUT:
• other – a polynomial
OUTPUT:
an element of the base ring of the polynomial ring
EXAMPLES:
sage: x = PolynomialRing(ZZ,'x',implementation='NTL').0
sage: f = x^3 + x + 1; g = x^3 - x - 1
sage: r = f.resultant(g); r
-8
sage: r.parent() is ZZ
True
squarefree_decomposition()
Return the square-free decomposition of self. This is a partial factorization of self into square-free, rela-
tively prime polynomials.
This is a wrapper for the NTL function SquareFreeDecomp.
EXAMPLES:
sage: R.<x> = PolynomialRing(ZZ, implementation='NTL')
sage: p = 37 * (x-1)^2 * (x-2)^2 * (x-3)^3 * (x-4)
sage: p.squarefree_decomposition()
(37) * (x - 4) * (x^2 - 3*x + 2)^2 * (x - 3)^3
xgcd(right)
This function can’t in general return (g,s,t) as above, since they need not exist. Instead, over the
integers, we first multiply 𝑔 by a divisor of the resultant of 𝑎/𝑔 and 𝑏/𝑔, up to sign, and return g, u, v
such that g = s*self + s*right. But note that this 𝑔 may be a multiple of the gcd.
If self and right are coprime as polynomials over the rationals, then g is guaranteed to be the resultant
of self and right, as a constant polynomial.
EXAMPLES:
sage: P.<x> = PolynomialRing(ZZ, implementation='NTL')
sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3)
sage: g, u, v = F.xgcd(G)
sage: g, u, v
(27*x^2 + 54, 1, -x^2 - 3*x - 9)
sage: u*F + v*G
27*x^2 + 54
sage: x.xgcd(P(0))
(continues on next page)
AUTHOR:
• Sebastian Pancratz
class sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint
Bases: sage.rings.polynomial.polynomial_element.Polynomial
Univariate polynomials over the rationals, implemented via FLINT.
Internally, we represent rational polynomial as the quotient of an integer polynomial and a positive denominator
which is coprime to the content of the numerator.
_add_(right)
Returns the sum of two rational polynomials.
EXAMPLES:
_sub_(right)
Returns the difference of two rational polynomials.
EXAMPLES:
_lmul_(right)
Returns self * right, where right is a rational number.
EXAMPLES:
_rmul_(left)
Returns left * self, where left is a rational number.
EXAMPLES:
_mul_(right)
Returns the product of self and right.
EXAMPLES:
_mul_trunc_(right, n)
Truncated multiplication.
EXAMPLES:
sage: x = polygen(QQ)
sage: p1 = 1/2 - 3*x + 2/7*x**3
sage: p2 = x + 2/5*x**5 + x**7
sage: p1._mul_trunc_(p2, 5)
2/7*x^4 - 3*x^2 + 1/2*x
sage: (p1*p2).truncate(5)
2/7*x^4 - 3*x^2 + 1/2*x
sage: p1._mul_trunc_(p2, 1)
0
sage: p1._mul_trunc_(p2, 0)
Traceback (most recent call last):
...
ValueError: n must be > 0
ALGORITHM:
Call the FLINT method fmpq_poly_mullow.
degree()
Return the degree of self.
By convention, the degree of the zero polynomial is -1.
EXAMPLES:
denominator()
Returns the denominator of self.
EXAMPLES:
disc()
Returns the discriminant of this polynomial.
The discriminant 𝑅𝑛 is defined as
∏︁
𝑅𝑛 = 𝑎2𝑛−2
𝑛 (𝑟𝑖 − 𝑟𝑗 )2 ,
1≤𝑖<𝑗≤𝑛
where 𝑛 is the degree of this polynomial, 𝑎𝑛 is the leading coefficient and the roots over Q are 𝑟1 , . . . , 𝑟𝑛 .
The discriminant of constant polynomials is defined to be 0.
OUTPUT:
• Discriminant, an element of the base ring of the polynomial ring
(
Note: Note the identity 𝑅𝑛 (𝑓 ) := (−1)( 𝑛(𝑛 − 1)/2)𝑅(𝑓, 𝑓 ′ )𝑎𝑛 𝑛 − 𝑘 − 2), where 𝑛 is the degree of
this polynomial, 𝑎𝑛 is the leading coefficient, 𝑓 ′ is the derivative of 𝑓 , and 𝑘 is the degree of 𝑓 ′ . Calls
resultant().
ALGORITHM:
Use PARI.
EXAMPLES:
In the case of elliptic curves in special form, the discriminant is easy to calculate:
discriminant()
Returns the discriminant of this polynomial.
where 𝑛 is the degree of this polynomial, 𝑎𝑛 is the leading coefficient and the roots over Q are 𝑟1 , . . . , 𝑟𝑛 .
The discriminant of constant polynomials is defined to be 0.
OUTPUT:
• Discriminant, an element of the base ring of the polynomial ring
(
Note: Note the identity 𝑅𝑛 (𝑓 ) := (−1)( 𝑛(𝑛 − 1)/2)𝑅(𝑓, 𝑓 ′ )𝑎𝑛 𝑛 − 𝑘 − 2), where 𝑛 is the degree of
this polynomial, 𝑎𝑛 is the leading coefficient, 𝑓 ′ is the derivative of 𝑓 , and 𝑘 is the degree of 𝑓 ′ . Calls
resultant().
ALGORITHM:
Use PARI.
EXAMPLES:
In the case of elliptic curves in special form, the discriminant is easy to calculate:
factor_mod(p)
Returns the factorization of self modulo the prime p.
Assumes that the degree of this polynomial is at least one, and raises a ValueError otherwise.
INPUT:
• p - Prime number
OUTPUT:
• Factorization of this polynomial modulo p
EXAMPLES:
Variable names that are reserved in PARI, such as zeta, are supported (see trac ticket #20631):
factor_padic(p, prec=10)
Return the 𝑝-adic factorization of this polynomial to the given precision.
INPUT:
• p - Prime number
• prec - Integer; the precision
OUTPUT:
• factorization of self viewed as a 𝑝-adic polynomial
EXAMPLES:
sage: f.factor_padic(3)
(1 + O(3^10))*x^3 + O(3^10)*x^2 + O(3^10)*x + 1 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4
˓→+ 2*3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + O(3^10)
sage: f.factor_padic(5)
((1 + O(5^10))*x + 2 + 4*5 + 2*5^2 + 2*5^3 + 5^4 + 3*5^5 + 4*5^7 + 2*5^8 + 5^
˓→9 + O(5^10)) * ((1 + O(5^10))*x^2 + (3 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^
The input polynomial is considered to have “infinite” precision, therefore the 𝑝-adic factorization of the
polynomial is not the same as first coercing to 𝑄𝑝 and then factoring (see also trac ticket #15422):
sage: f.factor_padic(3,-1)
Traceback (most recent call last):
...
ValueError: prec_cap must be non-negative.
sage: f.factor_padic(6,10)
Traceback (most recent call last):
...
ValueError: p must be prime
sage: f.factor_padic('hello', 'world')
Traceback (most recent call last):
...
TypeError: unable to convert 'hello' to an integer
galois_group(pari_group=False, algorithm=’pari’)
Returns the Galois group of self as a permutation group.
INPUT:
• self - Irreducible polynomial
• pari_group - bool (default: False); if True instead return the Galois group as a PARI group.
This has a useful label in it, and may be slightly faster since it doesn’t require looking up a group in
Gap. To get a permutation group from a PARI group P, type PermutationGroup(P).
• algorithm - 'pari', 'kash', 'magma' (default: 'pari', except when the degree is at least
12 in which case 'kash' is tried).
OUTPUT:
• Galois group
ALGORITHM:
The Galois group is computed using PARI in C library mode, or possibly KASH or MAGMA.
Note: The PARI documentation contains the following warning: The method used is that of resolvent
polynomials and is sensitive to the current precision. The precision is updated internally but, in very rare
cases, a wrong result may be returned if the initial precision was not sufficient.
MAGMA does not return a provably correct result. Please see the MAGMA documentation for how to
obtain a provably correct result.
EXAMPLES:
It is potentially useful to instead obtain the corresponding PARI group, which is little more than a 4-tuple.
See the PARI manual for the exact details. (Note that the third entry in the tuple is in the new standard
ordering.)
You can use KASH to compute Galois groups as well. The advantage is that KASH can compute Galois
groups of fields up to degree 21, whereas PARI only goes to degree 11. (In my not-so-thorough experiments
PARI is faster than KASH.)
gcd(right)
Returns the (monic) greatest common divisor of self and right.
Corner cases: if self and right are both zero, returns zero. If only one of them is zero, returns the other
polynomial, up to normalisation.
EXAMPLES:
hensel_lift(p, e)
Assuming that this polynomial factors modulo 𝑝 into distinct monic factors, computes the Hensel lifts of
these factors modulo 𝑝𝑒 . We assume that self has integer coefficients.
Returns an empty list if this polynomial has degree less than one.
INPUT:
• p - Prime number; coerceable to Integer
• e - Exponent; coerceable to Integer
OUTPUT:
• Hensel lifts; list of polynomials over Z/𝑝𝑒 Z
EXAMPLES:
inverse_series_trunc(prec)
Return a polynomial approximation of precision prec of the inverse series of this polynomial.
EXAMPLES:
sage: x = polygen(QQ)
sage: p = 2 + x - 3/5*x**2
sage: q5 = p.inverse_series_trunc(5)
sage: q5
151/800*x^4 - 17/80*x^3 + 11/40*x^2 - 1/4*x + 1/2
sage: q5 * p
-453/4000*x^6 + 253/800*x^5 + 1
is_irreducible()
Return whether this polynomial is irreducible.
This method computes the primitive part as an element of Z[𝑡] and calls the method is_irreducible
for elements of that polynomial ring.
By definition, over any integral domain, an element 𝑟 is irreducible if and only if it is non-zero, not a unit
and whenever 𝑟 = 𝑎𝑏 then 𝑎 or 𝑏 is a unit.
EXAMPLES:
is_one()
Returns whether or not this polynomial is one.
EXAMPLES:
is_zero()
Returns whether or not self is the zero polynomial.
EXAMPLES:
lcm(right)
Returns the monic (or zero) least common multiple of self and right.
Corner cases: if either of self and right are zero, returns zero. This behaviour is ensures that the relation
lcm(a,b) gcd(a,b) == a b holds up to multiplication by rationals.
EXAMPLES:
list(copy=True)
Return a list with the coefficients of self.
EXAMPLES:
numerator()
Returns the numerator of self.
Representing self as the quotient of an integer polynomial and a positive integer denominator (coprime to
the content of the polynomial), returns the integer polynomial.
EXAMPLES:
quo_rem(right)
Returns the quotient and remainder of the Euclidean division of self and right.
Raises a ZerodivisionError if right is zero.
EXAMPLES:
real_root_intervals()
Returns isolating intervals for the real roots of self.
EXAMPLES:
We compute the roots of the characteristic polynomial of some Salem numbers:
resultant(right)
Returns the resultant of self and right.
Enumerating the roots over Q as 𝑟1 , · · · , 𝑟𝑚 and 𝑠1 , · · · , 𝑠𝑛 and letting 𝑥 and 𝑦 denote the leading coeffi-
cients of 𝑓 and 𝑔, the resultant of the two polynomials is defined by
∏︁
𝑥deg 𝑔 𝑦 deg 𝑓 (𝑟𝑖 − 𝑠𝑗 ).
𝑖,𝑗
Corner cases: if one of the polynomials is zero, the resultant is zero. Note that otherwise if one of the
polynomials is constant, the last term in the above is the empty product.
EXAMPLES:
reverse(degree=None)
Reverse the coefficients of this polynomial (thought of as a polynomial of degree degree).
INPUT:
• degree (None or integral value that fits in an unsigned long, default: degree of self) - if
specified, truncate or zero pad the list of coefficients to this degree before reversing it.
EXAMPLES:
We first consider the simplest case, where we reverse all coefficients of a polynomial and obtain a polyno-
mial of the same degree:
Next, an example we the returned polynomial has lower degree because the original polynomial has low
coefficients equal to zero:
The next example illustrates the passing of a value for degree less than the length of self, notationally
resulting in truncation prior to reversing:
Now we illustrate the passing of a value for degree greater than the length of self, notationally resulting
in zero padding at the top end prior to reversing:
revert_series(n)
Return a polynomial 𝑓 such that 𝑓 (𝑠𝑒𝑙𝑓 (𝑥)) = 𝑠𝑒𝑙𝑓 (𝑓 (𝑥)) = 𝑥𝑚𝑜𝑑𝑥𝑛 .
EXAMPLES:
sage: f.revert_series(-1)
Traceback (most recent call last):
ValueError: argument n must be a non-negative integer, got -1
truncate(n)
Returns self truncated modulo 𝑡𝑛 .
INPUT:
• n - The power of 𝑡 modulo which self is truncated
EXAMPLES:
xgcd(right)
Returns polynomials d, s, and t such that d == s * self + t * right, where d is the (monic) greatest common
divisor of self and right. The choice of s and t is not specified any further.
Corner cases: if self and right are zero, returns zero polynomials. Otherwise, if only self is zero, returns
(d, s, t) = (right, 0, 1) up to normalisation, and similarly if only right is zero.
EXAMPLES:
This module gives a fast implementation of (Z/𝑛Z)[𝑥] whenever 𝑛 is at most sys.maxsize. We use it by default
in preference to NTL when the modulus is small, falling back to NTL if the modulus is too large, as in the example
below.
EXAMPLES:
AUTHORS:
• Burcin Erocal (2008-11) initial implementation
• Martin Albrecht (2009-01) another initial implementation
class sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template
Bases: sage.rings.polynomial.polynomial_element.Polynomial
Template for interfacing to external C / C++ libraries for implementations of polynomials.
AUTHORS:
• Robert Bradshaw (2008-10): original idea for templating
• Martin Albrecht (2008-10): initial implementation
This file implements a simple templating engine for linking univariate polynomials to their C/C++ library imple-
mentations. It requires a ‘linkage’ file which implements the celement_ functions (see sage.libs.ntl.
ntl_GF2X_linkage for an example). Both parts are then plugged together by inclusion of the linkage file
when inheriting from this class. See sage.rings.polynomial.polynomial_gf2x for an example.
We illustrate the generic glueing using univariate polynomials over GF(2).
Note: Implementations using this template MUST implement coercion from base ring elements and
get_unsafe(). See Polynomial_GF2X for an example.
degree()
EXAMPLES:
gcd(other)
Return the greatest common divisor of self and other.
EXAMPLES:
get_cparent()
is_gen()
EXAMPLES:
is_one()
EXAMPLES:
is_zero()
EXAMPLES:
list(copy=True)
EXAMPLES:
quo_rem(right)
EXAMPLES:
shift(n)
EXAMPLES:
truncate(n)
Returns this polynomial mod 𝑥𝑛 .
EXAMPLES:
If the precision is higher than the degree of the polynomial then the polynomial itself is returned:
sage: f.truncate(10) is f
True
xgcd(other)
Computes extended gcd of self and other.
EXAMPLES:
class sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint
Bases: sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template
Polynomial on Z/𝑛Z implemented via FLINT.
_add_(right)
EXAMPLES:
_sub_(right)
EXAMPLES:
_lmul_(left)
EXAMPLES:
_rmul_(right)
Multiply self on the right by a scalar.
EXAMPLES:
_mul_(right)
EXAMPLES:
_mul_trunc_(right, n)
Return the product of this polynomial and other truncated to the given length 𝑛.
This function is usually more efficient than simply doing the multiplication and then truncating. The
function is tuned for length 𝑛 about half the length of a full product.
EXAMPLES:
sage: P.<a>=GF(7)[]
sage: a = P(range(10)); b = P(range(5, 15))
sage: a._mul_trunc_(b, 5)
4*a^4 + 6*a^3 + 2*a^2 + 5*a
factor()
Returns the factorization of the polynomial.
EXAMPLES:
is_irreducible()
Return whether this polynomial is irreducible.
EXAMPLES:
monic()
Return this polynomial divided by its leading coefficient.
Raises ValueError if the leading coefficient is not invertible in the base ring.
EXAMPLES:
resultant(other)
Returns the resultant of self and other, which must lie in the same polynomial ring.
INPUT:
• other – a polynomial
OUTPUT: an element of the base ring of the polynomial ring
EXAMPLES:
The following example shows that trac ticket #11782 has been fixed:
reverse(degree=None)
Return a polynomial with the coefficients of this polynomial reversed.
If an optional degree argument is given the coefficient list will be truncated or zero padded as necessary
and the reverse polynomial will have the specified degree.
EXAMPLES:
Note that if 𝑓 has zero constant coefficient, its reverse will have lower degree.
sage: f = x^3 + 2*x
sage: f.reverse()
2*x^2 + 1
revert_series(n)
Return a polynomial 𝑓 such that 𝑓 (𝑠𝑒𝑙𝑓 (𝑥)) = 𝑠𝑒𝑙𝑓 (𝑓 (𝑥)) = 𝑥𝑚𝑜𝑑𝑥𝑛 .
EXAMPLES:
sage: R.<t> = GF(5)[]
sage: f = t + 2*t^2 - t^3 - 3*t^4
sage: f.revert_series(5)
3*t^4 + 4*t^3 + 3*t^2 + t
sage: f.revert_series(-1)
Traceback (most recent call last):
...
ValueError: argument n must be a non-negative integer, got -1
small_roots(*args, **kwds)
See sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots() for the
documentation of this function.
EXAMPLES:
sage: N = 10001
sage: K = Zmod(10001)
sage: P.<x> = PolynomialRing(K)
sage: f = x^3 + 10*x^2 + 5000*x - 222
(continues on next page)
squarefree_decomposition()
Returns the squarefree decomposition of this polynomial.
EXAMPLES:
sage.rings.polynomial.polynomial_zmod_flint.make_element(parent, args)
This implementation is generally slower than the FLINT implementation in polynomial_zmod_flint, so we use
FLINT by default when the modulus is small enough; but NTL does not require that 𝑛 be int-sized, so we use it as
default when 𝑛 is too large for FLINT.
Note that the classes Polynomial_dense_modn_ntl_zz and Polynomial_dense_modn_ntl_ZZ are dif-
ferent; the former is limited to moduli less than a certain bound, while the latter supports arbitrarily large moduli.
AUTHORS:
• Robert Bradshaw: Split off from polynomial_element_generic.py (2007-09)
• Robert Bradshaw: Major rewrite to use NTL directly (2007-09)
class sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_n
Bases: sage.rings.polynomial.polynomial_element.Polynomial
A dense polynomial over the integers modulo n, where n is composite, with the underlying arithmetic done
using NTL.
EXAMPLES:
sage: loads(f.dumps()) == f
True
degree(gen=None)
Return the degree of this polynomial.
The zero polynomial has degree -1.
EXAMPLES:
int_list()
list(copy=True)
Return a new copy of the list of the underlying elements of self.
EXAMPLES:
ntl_ZZ_pX()
Return underlying NTL representation of this polynomial. Additional ‘’bonus” functionality is available
through this function.
Warning: You must call ntl.set_modulus(ntl.ZZ(n)) before doing arithmetic with this
object!
ntl_set_directly(v)
Set the value of this polynomial directly from a vector or string.
Polynomials over the integers modulo n are stored internally using NTL’s ZZ_pX class. Use this function
to set the value of this polynomial using the NTL constructor, which is potentially very fast. The input v
is either a vector of ints or a string of the form [ n1 n2 n3 ... ] where the ni are integers and there
are no commas between them. The optimal input format is the string format, since that’s what NTL uses
by default.
EXAMPLES:
quo_rem(right)
Returns a tuple (quotient, remainder) where self = quotient*other + remainder.
shift(n)
Returns this polynomial multiplied by the power 𝑥𝑛 . If 𝑛 is negative, terms below 𝑥𝑛 will be discarded.
Does not change this polynomial.
EXAMPLES:
AUTHOR:
• David Harvey (2006-08-06)
small_roots(*args, **kwds)
See sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots() for the
documentation of this function.
EXAMPLES:
sage: N = 10001
sage: K = Zmod(10001)
sage: P.<x> = PolynomialRing(K, implementation='NTL')
sage: f = x^3 + 10*x^2 + 5000*x - 222
sage: f.small_roots()
[4]
class sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_p
Bases: sage.rings.polynomial.polynomial_modn_dense_ntl.
Polynomial_dense_mod_n
A dense polynomial over the integers modulo p, where p is prime.
discriminant()
EXAMPLES:
gcd(right)
Return the greatest common divisor of this polynomial and other, as a monic polynomial.
INPUT:
• other – a polynomial defined over the same ring as self
EXAMPLES:
resultant(other)
Returns the resultant of self and other, which must lie in the same polynomial ring.
INPUT:
• other – a polynomial
OUTPUT: an element of the base ring of the polynomial ring
EXAMPLES:
xgcd(other)
Compute the extended gcd of this element and other.
INPUT:
• other – an element in the same polynomial ring
OUTPUT:
A tuple (r,s,t) of elements in the polynomial ring such that r = s*self + t*other.
EXAMPLES:
class sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ
Bases: sage.rings.polynomial.polynomial_modn_dense_ntl.
Polynomial_dense_mod_n
degree()
EXAMPLES:
is_gen()
list(copy=True)
quo_rem(right)
Returns 𝑞 and 𝑟, with the degree of 𝑟 less than the degree of 𝑟𝑖𝑔ℎ𝑡, such that 𝑞 * 𝑟𝑖𝑔ℎ𝑡 + 𝑟 = 𝑠𝑒𝑙𝑓 .
EXAMPLES:
sage: r
5*x + 5
sage: q*g + r
x^5 + 1
reverse()
Reverses the coefficients of self. The reverse of 𝑓 (𝑥) is 𝑥𝑛 𝑓 (1/𝑥).
The degree will go down if the constant term is zero.
EXAMPLES:
shift(n)
Shift self to left by 𝑛, which is multiplication by 𝑥𝑛 , truncating if 𝑛 is negative.
EXAMPLES:
truncate(n)
Returns this polynomial mod 𝑥𝑛 .
EXAMPLES:
valuation()
Returns the valuation of self, that is, the power of the lowest non-zero monomial of self.
EXAMPLES:
sage: R.<x> = PolynomialRing(Integers(10^50), implementation='NTL')
sage: x.valuation()
1
sage: f = x-3; f.valuation()
0
sage: f = x^99; f.valuation()
99
sage: f = x-x; f.valuation()
+Infinity
class sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz
Bases: sage.rings.polynomial.polynomial_modn_dense_ntl.
Polynomial_dense_mod_n
Polynomial on Z/𝑛Z implemented via NTL.
_add_(_right)
_sub_(_right)
_lmul_(c)
_rmul_(c)
_mul_(_right)
_mul_trunc_(right, n)
Return the product of self and right truncated to the given length 𝑛
EXAMPLES:
sage: R.<x> = PolynomialRing(Integers(100), implementation="NTL")
sage: f = x - 2
sage: g = x^2 - 8*x + 16
sage: f*g
x^3 + 90*x^2 + 32*x + 68
sage: f._mul_trunc_(g, 42)
x^3 + 90*x^2 + 32*x + 68
sage: f._mul_trunc_(g, 3)
90*x^2 + 32*x + 68
sage: f._mul_trunc_(g, 2)
32*x + 68
sage: f._mul_trunc_(g, 1)
68
sage: f._mul_trunc_(g, 0)
0
sage: f = x^2 - 8*x + 16
sage: f._mul_trunc_(f, 2)
44*x + 56
degree()
EXAMPLES:
sage: R.<x> = PolynomialRing(Integers(77), implementation='NTL')
sage: f = x^4 - x - 1
sage: f.degree()
(continues on next page)
int_list()
Returns the coefficients of self as efficiently as possible as a list of python ints.
EXAMPLES:
sage: f = poly_modn_dense(R,[5,0,0,1])
sage: f.int_list()
[5, 0, 0, 1]
sage: [type(a) for a in f.int_list()]
[<... 'int'>, <... 'int'>, <... 'int'>, <... 'int'>]
is_gen()
ntl_set_directly(v)
quo_rem(right)
Returns 𝑞 and 𝑟, with the degree of 𝑟 less than the degree of 𝑟𝑖𝑔ℎ𝑡, such that 𝑞 * 𝑟𝑖𝑔ℎ𝑡 + 𝑟 = 𝑠𝑒𝑙𝑓 .
EXAMPLES:
reverse()
Reverses the coefficients of self. The reverse of 𝑓 (𝑥) is 𝑥𝑛 𝑓 (1/𝑥).
The degree will go down if the constant term is zero.
EXAMPLES:
shift(n)
Shift self to left by 𝑛, which is multiplication by 𝑥𝑛 , truncating if 𝑛 is negative.
EXAMPLES:
truncate(n)
Returns this polynomial mod 𝑥𝑛 .
EXAMPLES:
valuation()
Returns the valuation of self, that is, the power of the lowest non-zero monomial of self.
EXAMPLES:
sage.rings.polynomial.polynomial_modn_dense_ntl.make_element(parent, args)
sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots(self, X=None,
beta=1.0, ep-
silon=None,
**kwds)
Let 𝑁 be the characteristic of the base ring this polynomial is defined over: N = self.base_ring().
characteristic(). This method returns small roots of this polynomial modulo some factor 𝑏 of 𝑁 with
the constraint that 𝑏 >= 𝑁 𝛽 . Small in this context means that if 𝑥 is a root of 𝑓 modulo 𝑏 then |𝑥| < 𝑋. This
𝑋 is either provided by the user or the maximum 𝑋 is chosen such that this algorithm terminates in polynomial
2
time. If 𝑋 is chosen automatically it is 𝑋 = 𝑐𝑒𝑖𝑙(1/2𝑁 𝛽 /𝛿−𝜖 ). The algorithm may also return some roots
which are larger than 𝑋. ‘This algorithm’ in this context means Coppersmith’s algorithm for finding small roots
using the LLL algorithm. The implementation of this algorithm follows Alexander May’s PhD thesis referenced
below.
INPUT:
• X – an absolute bound for the root (default: see above)
• beta – compute a root mod 𝑏 where 𝑏 is a factor of 𝑁 and 𝑏 ≥ 𝑁 𝛽 . (Default: 1.0, so 𝑏 = 𝑁 .)
• epsilon – the parameter 𝜖 described above. (Default: 𝛽/8)
• **kwds – passed through to method Matrix_integer_dense.LLL().
EXAMPLES:
First consider a small example:
sage: N = 10001
sage: K = Zmod(10001)
sage: P.<x> = PolynomialRing(K, implementation='NTL')
sage: f = x^3 + 10*x^2 + 5000*x - 222
This polynomial has no roots without modular reduction (i.e. over Z):
sage: f.change_ring(ZZ).roots()
[]
To compute its roots we need to factor the modulus 𝑁 and use the Chinese remainder theorem:
sage: crt(4, 4, p, q)
4
This root is quite small compared to 𝑁 , so we can attempt to recover it without factoring 𝑁 using Coppersmith’s
small root method:
sage: f.small_roots()
[4]
An application of this method is to consider RSA. We are using 512-bit RSA with public exponent 𝑒 = 3 to
encrypt a 56-bit DES key. Because it would be easy to attack this setting if no padding was used we pad the key
𝐾 with 1s to get a large number:
sage: M = ZZ(M, 2)
sage: C = ZmodN(M)^e
The same algorithm can be used to factor 𝑁 = 𝑝𝑞 if partial knowledge about 𝑞 is available. This example is
from the Magma handbook:
First, we set up 𝑝, 𝑞 and 𝑁 :
sage: length = 512
sage: hidden = 110
sage: p = next_prime(2^int(round(length/2)))
sage: q = next_prime( round(pi.n()*p) )
sage: N = p*q
REFERENCES:
Don Coppersmith. Finding a small root of a univariate modular equation. In Advances in Cryptology, Eu-
roCrypt 1996, volume 1070 of Lecture Notes in Computer Science, p. 155–165. Springer, 1996. http:
//cr.yp.to/bib/2001/coppersmith.pdf
Alexander May. New RSA Vulnerabilities Using Lattice Reduction Methods. PhD thesis, University of Pader-
born, 2003. http://www.cs.uni-paderborn.de/uploads/tx_sibibtex/bp.pdf
class sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense
Bases: sage.rings.polynomial.polynomial_element.Polynomial
change_ring(R)
EXAMPLES:
degree()
Return the degree of the polynomial.
EXAMPLES:
integral()
EXAMPLES:
list(copy=True)
EXAMPLES:
quo_rem(other)
Return the quotient with remainder of self by other.
EXAMPLES:
reverse()
Returns 𝑥𝑑 𝑓 (1/𝑥) where 𝑑 is the degree of 𝑓 .
EXAMPLES:
sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import
˓→PolynomialRealDense
shift(n)
Returns this polynomial multiplied by the power 𝑥𝑛 . If 𝑛 is negative, terms below 𝑥𝑛 will be discarded.
Does not change this polynomial.
EXAMPLES:
sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import
˓→PolynomialRealDense
truncate(n)
Returns the polynomial of degree < 𝑛 which is equivalent to self modulo 𝑥𝑛 .
EXAMPLES:
sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import
˓→PolynomialRealDense
truncate_abs(bound)
Truncate all high order coefficients below bound.
EXAMPLES:
sage: f.truncate_abs(0.5e-6)
1.0e-6*x^6 + 0.000010*x^5 + 0.00010*x^4 + 0.0010*x^3 + 0.010*x^2 + 0.10*x + 1.
˓→0
sage: f.truncate_abs(10.0)
0
sage: f.truncate_abs(1e-100) == f
True
sage.rings.polynomial.polynomial_real_mpfr_dense.make_PolynomialRealDense(parent,
data)
EXAMPLES:
AUTHORS:
• Martin Albrecht <[email protected]> (2006-04-21)
• Robert Bradshaw: Re-factor to avoid multiple inheritance vs. Cython (2007-09)
• Syed Ahmad Lavasani: Added function field to _singular_init_ (2011-12-16) Added non-prime finite fields
to _singular_init_ (2012-1-22)
class sage.rings.polynomial.polynomial_singular_interface.PolynomialRing_singular_repr
Implements methods to convert polynomial rings to Singular.
This class is a base class for all univariate and multivariate polynomial rings which support conversion from and
to Singular rings.
class sage.rings.polynomial.polynomial_singular_interface.Polynomial_singular_repr
Implements coercion of polynomials to Singular polynomials.
This class is a base class for all (univariate and multivariate) polynomial classes which support conversion from
and to Singular polynomials.
Due to the incompatibility of Python extension classes and multiple inheritance, this just defers to module-level
functions.
sage.rings.polynomial.polynomial_singular_interface.can_convert_to_singular(R)
Returns True if this ring’s base field or ring can be represented in Singular, and the polynomial ring has at least
one generator. If this is True then this polynomial ring can be represented in Singular.
The following base rings are supported: finite fields, rationals, number fields, and real and complex fields.
EXAMPLES:
This provides common functionality for all 𝑝-adic polynomials, such as printing and factoring.
AUTHORS:
• Jeroen Demeyer (2013-11-22): initial version, split off from other files, made Polynomial_padic the common
base class for all p-adic polynomials.
class sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic(parent,
x=None,
check=True,
is_gen=False,
con-
struct=False)
Bases: sage.rings.polynomial.polynomial_element.Polynomial
content()
Compute the content of this polynomial.
OUTPUT:
If this is the zero polynomial, return the constant coefficient. Otherwise, since the content is only defined
up to a unit, return the content as 𝜋 𝑘 with maximal precision where 𝑘 is the minimal valuation of any of
the coefficients.
EXAMPLES:
sage: K = Zp(13,7)
sage: R.<t> = K[]
sage: f = 13^7*t^3 + K(169,4)*t - 13^4
sage: f.content()
13^2 + O(13^9)
sage: R(0).content()
0
sage: f = R(K(0,3)); f
O(13^3)
sage: f.content()
O(13^3)
Over a field it would be sufficient to return only zero or one, as the content is only defined up to multipli-
cation with a unit. However, we return 𝜋 𝑘 where 𝑘 is the minimal valuation of any coefficient:
sage: K = Qp(13,7)
sage: R.<t> = K[]
sage: f = 13^7*t^3 + K(169,4)*t - 13^-4
sage: f.content()
13^-4 + O(13^3)
sage: f = R.zero()
sage: f.content()
0
sage: f = R(K(0,3))
sage: f.content()
O(13^3)
sage: f = 13*t^3 + K(0,1)*t
sage: f.content()
13 + O(13^8)
factor()
Return the factorization of this polynomial.
EXAMPLES:
sage: R.<t> = PolynomialRing(Qp(3,3,print_mode='terse',print_pos=False))
sage: pol = t^8 - 1
sage: for p,e in pol.factor():
....: print("{} {}".format(e, p))
1 (1 + O(3^3))*t + 1 + O(3^3)
1 (1 + O(3^3))*t - 1 + O(3^3)
1 (1 + O(3^3))*t^2 + (5 + O(3^3))*t - 1 + O(3^3)
1 (1 + O(3^3))*t^2 + (-5 + O(3^3))*t - 1 + O(3^3)
1 (1 + O(3^3))*t^2 + O(3^3)*t + 1 + O(3^3)
sage: R.<t> = PolynomialRing(Qp(5,6,print_mode='terse',print_pos=False))
sage: pol = 100 * (5*t - 1) * (t - 5)
sage: pol
(500 + O(5^9))*t^2 + (-2600 + O(5^8))*t + 500 + O(5^9)
sage: pol.factor()
(500 + O(5^9)) * ((1 + O(5^5))*t - 1/5 + O(5^5)) * ((1 + O(5^6))*t - 5 + O(5^
˓→6))
sage: pol.factor().value()
(500 + O(5^8))*t^2 + (-2600 + O(5^8))*t + 500 + O(5^8)
The same factorization over Z𝑝 . In this case, the “unit” part is a 𝑝-adic unit and the power of 𝑝 is considered
to be a factor:
sage: R.<t> = PolynomialRing(Zp(5,6,print_mode='terse',print_pos=False))
sage: pol = 100 * (5*t - 1) * (t - 5)
sage: pol
(500 + O(5^9))*t^2 + (-2600 + O(5^8))*t + 500 + O(5^9)
sage: pol.factor()
(4 + O(5^6)) * (5 + O(5^7))^2 * ((1 + O(5^6))*t - 5 + O(5^6)) * ((5 + O(5^
˓→6))*t - 1 + O(5^6))
sage: pol.factor().value()
(continues on next page)
In the following example, the discriminant is zero, so the 𝑝-adic factorization is not well defined:
sage: factor(t^2)
Traceback (most recent call last):
...
PrecisionError: p-adic factorization not well-defined since the discriminant
˓→is zero up to the requestion p-adic precision
sage: f = w^5-1
sage: f.factor()
((1 + O(5^6))*w + 3124 + O(5^6)) * ((1 + O(5^6))*w^4 + (12501 + O(5^6))*w^3 +
˓→(9376 + O(5^6))*w^2 + (6251 + O(5^6))*w + 3126 + O(5^6))
sage: E = EllipticCurve('37a1')
sage: K =Qp(7,10)
sage: EK = E.base_extend(K)
sage: E = EllipticCurve('37a1')
sage: K = Qp(7,10)
sage: EK = E.base_extend(K)
sage: g = EK.division_polynomial_0(3)
sage: g.factor()
(3 + O(7^10)) * ((1 + O(7^10))*x + 1 + 2*7 + 4*7^2 + 2*7^3 + 5*7^4 + 7^5 +
˓→5*7^6 + 3*7^7 + 5*7^8 + 3*7^9 + O(7^10)) * ((1 + O(7^10))*x^3 + (6 + 4*7 +
˓→+ 3*7 + 5*7^2 + 2*7^4 + 7^5 + 7^6 + 2*7^8 + 3*7^9 + O(7^10))*x + 2 + 5*7 +
class sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_
Bases: sage.rings.polynomial.polynomial_element_generic.
Polynomial_generic_cdv, sage.rings.polynomial.padics.polynomial_padic.
Polynomial_padic
degree(secure=False)
Return the degree of self.
INPUT:
• secure – a boolean (default: False)
If secure is True and the degree of this polynomial is not determined (because the leading coefficient
is indistinguishable from 0), an error is raised.
If secure is False, the returned value is the largest 𝑛 so that the coefficient of 𝑥𝑛 does not compare
equal to 0.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.degree()
1
sage: (f-T).degree()
0
sage: (f-T).degree(secure=True)
Traceback (most recent call last):
...
PrecisionError: the leading coefficient is indistinguishable from 0
disc()
factor_mod()
Return the factorization of self modulo 𝑝.
is_eisenstein(secure=False)
Return True if this polynomial is an Eisenstein polynomial.
EXAMPLES:
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 5*t + t^4
sage: f.is_eisenstein()
True
AUTHOR:
• Xavier Caruso (2013-03)
lift()
Return an integer polynomial congruent to this one modulo the precision of each coefficient.
Note: The lift that is returned will not necessarily be the same for polynomials with the same coefficients
(i.e. same values and precisions): it will depend on how the polynomials are created.
EXAMPLES:
sage: K = Qp(13,7)
sage: R.<t> = K[]
sage: a = 13^7*t^3 + K(169,4)*t - 13^4
sage: a.lift()
62748517*t^3 + 169*t - 28561
list(copy=True)
Return a list of coefficients of self.
Note: The length of the list returned may be greater than expected since it includes any leading zeros that
have finite absolute precision.
EXAMPLES:
sage: K = Qp(13,7)
sage: R.<t> = K[]
sage: a = 2*t^3 + 169*t - 1
sage: a
(2 + O(13^7))*t^3 + (13^2 + O(13^9))*t + 12 + 12*13 + 12*13^2 + 12*13^3 +
˓→12*13^4 + 12*13^5 + 12*13^6 + O(13^7)
sage: a.list()
[12 + 12*13 + 12*13^2 + 12*13^3 + 12*13^4 + 12*13^5 + 12*13^6 + O(13^7),
13^2 + O(13^9),
0,
2 + O(13^7)]
lshift_coeffs(shift, no_list=False)
Return a new polynomials whose coefficients are multiplied by p^shift.
EXAMPLES:
sage: K = Qp(13, 4)
sage: R.<t> = K[]
sage: a = t + 52
sage: a.lshift_coeffs(3)
(13^3 + O(13^7))*t + 4*13^4 + O(13^8)
newton_polygon()
Return the Newton polygon of this polynomial.
OUTPUT:
• a Newton polygon
EXAMPLES:
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 3*t + t^4 + 25*t^10
sage: f.newton_polygon()
Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2)
Here is an example where the computation fails because precision is not sufficient:
sage: g = f + K(0,0)*t^4; g
(5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21)
sage: g.newton_polygon()
Traceback (most recent call last):
...
PrecisionError: The coefficient of t^4 has not enough precision
AUTHOR:
• Xavier Caruso (2013-03-20)
newton_slopes(repetition=True)
Return a list of the Newton slopes of this polynomial.
These are the valuations of the roots of this polynomial.
If repetition is True, each slope is repeated a number of times equal to its multiplicity. Otherwise it
appears only one time.
INPUT:
• repetition – boolean (default True)
OUTPUT:
• a list of rationals
EXAMPLES:
sage: K = Qp(5)
sage: R.<t> = K[]
sage: f = 5 + 3*t + t^4 + 25*t^10
sage: f.newton_polygon()
Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0),
(10, 2)
sage: f.newton_slopes()
[1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3]
sage: f.newton_slopes(repetition=False)
[1, 0, -1/3]
AUTHOR:
• Xavier Caruso (2013-03-20)
prec_degree()
Return the largest 𝑛 so that precision information is stored about the coefficient of 𝑥𝑛 .
Always greater than or equal to degree.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.prec_degree()
1
precision_absolute(n=None)
Return absolute precision information about self.
INPUT:
self – a p-adic polynomial
n – None or an integer (default None).
OUTPUT:
If n == None, returns a list of absolute precisions of coefficients. Otherwise, returns the absolute precision
of the coefficient of x^n.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.precision_absolute()
[10, 10]
precision_relative(n=None)
Return relative precision information about self.
INPUT:
self – a p-adic polynomial
n – None or an integer (default None).
OUTPUT:
If n == None, returns a list of relative precisions of coefficients. Otherwise, returns the relative precision
of the coefficient of x^n.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.precision_relative()
[10, 10]
quo_rem(right, secure=False)
Return the quotient and remainder in division of self by right.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2
sage: g = T**4 + 3*T+22
sage: g.quo_rem(f)
((1 + O(3^10))*T^3 + (1 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7
˓→+ 2*3^8 + 2*3^9 + O(3^10))*T^2 + (1 + 3 + O(3^10))*T + 1 + 3 + 2*3^2 + 2*3^
2 + 3 + 3^3 + O(3^10))
rescale(a)
Return f(a*X)
Todo: Need to write this function for integer polynomials before this works.
EXAMPLES:
sage: K = Zp(13, 5)
sage: R.<t> = K[]
sage: f = t^3 + K(13, 3) * t
sage: f.rescale(2) # not implemented
reverse(n=None)
Return a new polynomial whose coefficients are the reversed coefficients of self, where self is consid-
ered as a polynomial of degree n.
If n is None, defaults to the degree of self.
If n is smaller than the degree of self, some coefficients will be discarded.
EXAMPLES:
sage: K = Qp(13,7)
sage: R.<t> = K[]
sage: f = t^3 + 4*t; f
(1 + O(13^7))*t^3 + (4 + O(13^7))*t
sage: f.reverse()
0*t^3 + (4 + O(13^7))*t^2 + 1 + O(13^7)
sage: f.reverse(3)
0*t^3 + (4 + O(13^7))*t^2 + 1 + O(13^7)
sage: f.reverse(2)
0*t^2 + (4 + O(13^7))*t
sage: f.reverse(4)
0*t^4 + (4 + O(13^7))*t^3 + (1 + O(13^7))*t
sage: f.reverse(6)
0*t^6 + (4 + O(13^7))*t^5 + (1 + O(13^7))*t^3
rshift_coeffs(shift, no_list=False)
Return a new polynomial whose coefficients are p-adically shifted to the right by shift.
EXAMPLES:
sage: K = Zp(13, 4)
sage: R.<t> = K[]
sage: a = t^2 + K(13,3)*t + 169; a
(1 + O(13^4))*t^2 + (13 + O(13^3))*t + 13^2 + O(13^6)
sage: b = a.rshift_coeffs(1); b
O(13^3)*t^2 + (1 + O(13^2))*t + 13 + O(13^5)
sage: b.list()
[13 + O(13^5), 1 + O(13^2), O(13^3)]
sage: b = a.rshift_coeffs(2); b
O(13^2)*t^2 + O(13)*t + 1 + O(13^4)
sage: b.list()
[1 + O(13^4), O(13), O(13^2)]
valuation(val_of_var=None)
Return the valuation of self.
INPUT:
self – a p-adic polynomial
val_of_var – None or a rational (default None).
OUTPUT:
If val_of_var == None, returns the largest power of the variable dividing self. Otherwise, returns the
valuation of self where the variable is assigned valuation val_of_var
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.valuation()
0
valuation_of_coefficient(n=None)
Return valuation information about self’s coefficients.
INPUT:
self – a p-adic polynomial
n – None or an integer (default None).
OUTPUT:
If n == None, returns a list of valuations of coefficients. Otherwise, returns the valuation of the coefficient
of x^n.
EXAMPLES:
sage: K = Qp(3,10)
sage: R.<T> = K[]
sage: f = T + 2; f
(1 + O(3^10))*T + 2 + O(3^10)
sage: f.valuation_of_coefficient(1)
0
xgcd(right)
Extended gcd of self and other.
INPUT:
• other – an element with the same parent as self
OUTPUT:
Polynomials g, u, and v such that g = u*self + v*other
Warning: The computations are performed using the standard Euclidean algorithm which might
produce mathematically incorrect results in some cases. See trac ticket #13439.
EXAMPLES:
sage: R.<x> = Qp(3,3)[]
sage: f = x + 1
sage: f.xgcd(f^2)
((1 + O(3^3))*x + 1 + O(3^3), 1 + O(3^3), 0)
In these examples the results are incorrect, see trac ticket #13439:
sage: R.<x> = Qp(3,3)[]
sage: f = 3*x + 7
sage: g = 5*x + 9
sage: f.xgcd(f*g) # known bug
((3 + O(3^4))*x + (1 + 2*3 + O(3^3)), (1 + O(3^3)), 0)
˓→+ 2*3^2 + 2*3^3 + 2*3^4 + 3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^10 + 3^11 + O(3^
˓→14)), (1 + O(3^20)), 0)
sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.make_padic_poly(parent,
x,
ver-
sion)
class sage.rings.polynomial.padics.polynomial_padic_flat.Polynomial_padic_flat(parent,
x=None,
check=True,
is_gen=False,
con-
struct=False,
ab-
sprec=None)
Bases: sage.rings.polynomial.polynomial_element.Polynomial_generic_dense,
sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic
AUTHOR:
• Yann Laigle-Chapuy (2010-01) initial implementation
class sage.rings.polynomial.polynomial_zz_pex.Polynomial_ZZ_pEX
Bases: sage.rings.polynomial.polynomial_zz_pex.Polynomial_template
Univariate Polynomials over GF(p^n) via NTL’s ZZ_pEX.
EXAMPLES:
sage: K.<a>=GF(next_prime(2**60)**3)
sage: R.<x> = PolynomialRing(K,implementation='NTL')
sage: (x^3 + a*x^2 + 1) * (x + a)
x^4 + 2*a*x^3 + a^2*x^2 + x + a
is_irreducible(algorithm=’fast_when_false’, iter=1)
Returns 𝑇 𝑟𝑢𝑒 precisely when self is irreducible over its base ring.
INPUT:
Parameters
• algorithm – a string (default “fast_when_false”), there are 3 available algorithms:
“fast_when_true”, “fast_when_false” and “probabilistic”.
• iter – (default: 1) if the algorithm is “probabilistic” defines the number of iterations.
The error probability is bounded by 𝑞 * * − 𝑖𝑡𝑒𝑟 for polynomials in 𝐺𝐹 (𝑞)[𝑥].
EXAMPLES:
sage: K.<a>=GF(next_prime(2**60)**3)
sage: R.<x> = PolynomialRing(K,implementation='NTL')
sage: P = x^3+(2-a)*x+1
sage: P.is_irreducible(algorithm="fast_when_false")
True
sage: P.is_irreducible(algorithm="fast_when_true")
True
sage: P.is_irreducible(algorithm="probabilistic")
True
sage: Q = (x^2+a)*(x+a^3)
sage: Q.is_irreducible(algorithm="fast_when_false")
False
sage: Q.is_irreducible(algorithm="fast_when_true")
False
sage: Q.is_irreducible(algorithm="probabilistic")
False
list(copy=True)
Returs the list of coefficients.
EXAMPLES:
resultant(other)
Returns the resultant of self and other, which must lie in the same polynomial ring.
INPUT:
Parameters other – a polynomial
OUTPUT: an element of the base ring of the polynomial ring
EXAMPLES:
sage: K.<a>=GF(next_prime(2**60)**3)
sage: R.<x> = PolynomialRing(K,implementation='NTL')
sage: f=(x-a)*(x-a**2)*(x+1)
sage: g=(x-a**3)*(x-a**4)*(x+a)
sage: r = f.resultant(g)
sage: r == prod(u-v for (u,eu) in f.roots() for (v,ev) in g.roots())
True
shift(n)
EXAMPLES:
sage: K.<a>=GF(next_prime(2**60)**3)
sage: R.<x> = PolynomialRing(K,implementation='NTL')
sage: f = x^3 + x^2 + 1
sage: f.shift(1)
x^4 + x^3 + x
(continues on next page)
class sage.rings.polynomial.polynomial_zz_pex.Polynomial_ZZ_pX
Bases: sage.rings.polynomial.polynomial_zz_pex.Polynomial_template
class sage.rings.polynomial.polynomial_zz_pex.Polynomial_template
Bases: sage.rings.polynomial.polynomial_element.Polynomial
Template for interfacing to external C / C++ libraries for implementations of polynomials.
AUTHORS:
• Robert Bradshaw (2008-10): original idea for templating
• Martin Albrecht (2008-10): initial implementation
This file implements a simple templating engine for linking univariate polynomials to their C/C++ library imple-
mentations. It requires a ‘linkage’ file which implements the celement_ functions (see sage.libs.ntl.
ntl_GF2X_linkage for an example). Both parts are then plugged together by inclusion of the linkage file
when inheriting from this class. See sage.rings.polynomial.polynomial_gf2x for an example.
We illustrate the generic glueing using univariate polynomials over GF(2).
Note: Implementations using this template MUST implement coercion from base ring elements and
get_unsafe(). See Polynomial_GF2X for an example.
degree()
EXAMPLES:
gcd(other)
Return the greatest common divisor of self and other.
EXAMPLES:
get_cparent()
is_gen()
EXAMPLES:
is_one()
EXAMPLES:
is_zero()
EXAMPLES:
list(copy=True)
EXAMPLES:
quo_rem(right)
EXAMPLES:
shift(n)
EXAMPLES:
truncate(n)
Returns this polynomial mod 𝑥𝑛 .
EXAMPLES:
If the precision is higher than the degree of the polynomial then the polynomial itself is returned:
sage: f.truncate(10) is f
True
xgcd(other)
Computes extended gcd of self and other.
EXAMPLES:
sage.rings.polynomial.polynomial_zz_pex.make_element(parent, args)
AUTHOR:
• Carl Witty (2007-09-19): initial version
This is an implementation of real root isolation. That is, given a polynomial with exact real coefficients, we compute
isolating intervals for the real roots of the polynomial. (Polynomials with integer, rational, or algebraic real coefficients
are supported.)
We convert the polynomials into the Bernstein basis, and then use de Casteljau’s algorithm and Descartes’ rule of signs
on the Bernstein basis polynomial (using interval arithmetic) to locate the roots. The algorithm is similar to that in
“A Descartes Algorithm for Polynomials with Bit-Stream Coefficients”, by Eigenwillig, Kettner, Krandick, Mehlhorn,
Schmitt, and Wolpert, but has three crucial optimizations over the algorithm in that paper:
• Precision reduction: at certain points in the computation, we discard the low-order bits of the coefficients,
widening the intervals.
• Degree reduction: at certain points in the computation, we find lower-degree polynomials that are approximately
equal to our high-degree polynomial over the region of interest.
• When the intervals are too wide to continue (either because of a too-low initial precision, or because of precision
or degree reduction), and we need to restart with higher precision, we recall which regions have already been
proven not to have any roots and do not examine them again.
The best description of the algorithms used (other than this source code itself) is in the slides for my Sage Days 4 talk,
currently available from https://wiki.sagemath.org/days4schedule .
exception sage.rings.polynomial.real_roots.PrecisionError
Bases: exceptions.ValueError
sage.rings.polynomial.real_roots.bernstein_down(d1, d2, s)
Given polynomial degrees d1 and d2 (where d1 < d2), and a number of samples s, computes a matrix bd.
If you have a Bernstein polynomial of formal degree d2, and select s of its coefficients (according to subsam-
ple_vec), and multiply the resulting vector by bd, then you get the coefficients of a Bernstein polynomial of
formal degree d1, where this second polynomial is a good approximation to the first polynomial over the region
of the Bernstein basis.
EXAMPLES:
sage.rings.polynomial.real_roots.bernstein_expand(c, d2)
Given an integer vector representing a Bernstein polynomial p, and a degree d2, compute the representation of
p as a Bernstein polynomial of formal degree d2.
This is similar to multiplying by the result of bernstein_up, but should be faster for large d2 (this has about the
same number of multiplies, but in this version all the multiplies are by single machine words).
Returns a pair consisting of the expanded polynomial, and the maximum error E. (So if an element of the
returned polynomial is a, and the true value of that coefficient is b, then a <= b < a + E.)
EXAMPLES:
class sage.rings.polynomial.real_roots.bernstein_polynomial_factory
An abstract base class for bernstein_polynomial factories. That is, elements of subclasses represent Bernstein
polynomials (exactly), and are responsible for creating interval_bernstein_polynomial_integer approximations
at arbitrary precision.
Supports four methods, coeffs_bitsize(), bernstein_polynomial(), lsign(), and usign(). The coeffs_bitsize()
method gives an integer approximation to the log2 of the max of the absolute values of the Bernstein coeffi-
cients. The bernstein_polynomial(scale_log2) method gives an approximation where the maximum coefficient
has approximately coeffs_bitsize() - scale_log2 bits. The lsign() and usign() methods give the (exact) sign of
the first and last coefficient, respectively.
lsign()
Returns the sign of the first coefficient of this Bernstein polynomial.
usign()
Returns the sign of the last coefficient of this Bernstein polynomial.
class sage.rings.polynomial.real_roots.bernstein_polynomial_factory_ar(poly,
neg)
Bases: sage.rings.polynomial.real_roots.bernstein_polynomial_factory
This class holds an exact Bernstein polynomial (represented as a list of algebraic real coefficients), and returns
arbitrarily-precise interval approximations of this polynomial on demand.
bernstein_polynomial(scale_log2)
Compute an interval_bernstein_polynomial_integer that approximates this polynomial, using the given
scale_log2. (Smaller scale_log2 values give more accurate approximations.)
EXAMPLES:
coeffs_bitsize()
Computes the approximate log2 of the maximum of the absolute values of the coefficients.
EXAMPLES:
class sage.rings.polynomial.real_roots.bernstein_polynomial_factory_intlist(coeffs)
Bases: sage.rings.polynomial.real_roots.bernstein_polynomial_factory
This class holds an exact Bernstein polynomial (represented as a list of integer coefficients), and returns
arbitrarily-precise interval approximations of this polynomial on demand.
bernstein_polynomial(scale_log2)
Compute an interval_bernstein_polynomial_integer that approximates this polynomial, using the given
scale_log2. (Smaller scale_log2 values give more accurate approximations.)
EXAMPLES:
coeffs_bitsize()
Computes the approximate log2 of the maximum of the absolute values of the coefficients.
EXAMPLES:
class sage.rings.polynomial.real_roots.bernstein_polynomial_factory_ratlist(coeffs)
Bases: sage.rings.polynomial.real_roots.bernstein_polynomial_factory
This class holds an exact Bernstein polynomial (represented as a list of rational coefficients), and returns
arbitrarily-precise interval approximations of this polynomial on demand.
bernstein_polynomial(scale_log2)
Compute an interval_bernstein_polynomial_integer that approximates this polynomial, using the given
scale_log2. (Smaller scale_log2 values give more accurate approximations.)
EXAMPLES:
sage: print(bpf.bernstein_polynomial(0))
degree 3 IBP with 3-bit coefficients
sage: bpf.bernstein_polynomial(20)
<IBP: ((0, -1, 0, -1) + [0 .. 1)) * 2^20; lsign 1>
sage: bpf.bernstein_polynomial(0)
<IBP: (0, -4, 2, -2) + [0 .. 1); lsign 1>
sage: bpf.bernstein_polynomial(-20)
<IBP: ((349525, -3295525, 2850354, -1482835) + [0 .. 1)) * 2^-20>
coeffs_bitsize()
Computes the approximate log2 of the maximum of the absolute values of the coefficients.
EXAMPLES:
sage.rings.polynomial.real_roots.bitsize_doctest(n)
sage.rings.polynomial.real_roots.cl_maximum_root(cl)
Given a polynomial represented by a list of its coefficients (as RealIntervalFieldElements), compute an upper
bound on its largest real root.
Uses two algorithms of Akritas, Strzebo’nski, and Vigklas, and picks the better result.
EXAMPLES:
sage.rings.polynomial.real_roots.cl_maximum_root_first_lambda(cl)
Given a polynomial represented by a list of its coefficients (as RealIntervalFieldElements), compute an upper
bound on its largest real root.
Uses the first-lambda algorithm from “Implementations of a New Theorem for Computing Bounds for Positive
Roots of Polynomials”, by Akritas, Strzebo’nski, and Vigklas.
EXAMPLES:
sage.rings.polynomial.real_roots.cl_maximum_root_local_max(cl)
Given a polynomial represented by a list of its coefficients (as RealIntervalFieldElements), compute an upper
bound on its largest real root.
Uses the local-max algorithm from “Implementations of a New Theorem for Computing Bounds for Positive
Roots of Polynomials”, by Akritas, Strzebo’nski, and Vigklas.
EXAMPLES:
class sage.rings.polynomial.real_roots.context
Bases: object
A simple context class, which is passed through parts of the real root isolation algorithm to avoid global vari-
ables.
Holds logging information, a random number generator, and the target machine wordsize.
get_be_log()
get_dc_log()
sage.rings.polynomial.real_roots.de_casteljau_doublevec(c, x)
Given a polynomial in Bernstein form with floating-point coefficients over the region [0 .. 1], and a split point
x, use de Casteljau’s algorithm to give polynomials in Bernstein form over [0 .. x] and [x .. 1].
This function will work for an arbitrary rational split point x, as long as 0 < x < 1; but it has a specialized code
path for x==1/2.
INPUT:
• c – vector of coefficients of polynomial in Bernstein form
• x – rational splitting point; 0 < x < 1
OUTPUT:
• c1 – coefficients of polynomial over range [0 .. x]
• c2 – coefficients of polynomial over range [x .. 1]
sage.rings.polynomial.real_roots.degree_reduction_next_size(n)
Given n (a polynomial degree), returns either a smaller integer or None. This defines the sequence of degrees
followed by our degree reduction implementation.
EXAMPLES:
sage.rings.polynomial.real_roots.dprod_imatrow_vec(m, v, k)
Computes the dot product of row k of the matrix m with the vector v (that is, compute one element of the product
m*v).
If v has more elements than m has columns, then elements of v are selected using subsample_vec.
EXAMPLES:
sage.rings.polynomial.real_roots.get_realfield_rndu(n)
A simple cache for RealField fields (with rounding set to round-to-positive-infinity).
EXAMPLES:
class sage.rings.polynomial.real_roots.interval_bernstein_polynomial
Bases: object
An interval_bernstein_polynomial is an approximation to an exact polynomial. This approximation is in the
form of a Bernstein polynomial (a polynomial given as coefficients over a Bernstein basis) with interval coeffi-
cients.
The Bernstein basis of degree n over the region [a .. b] is the set of polynomials
(︂ )︂
𝑛
(𝑥 − 𝑎)𝑘 (𝑏 − 𝑥)𝑛−𝑘 /(𝑏 − 𝑎)𝑛
𝑘
for 0 ≤ 𝑘 ≤ 𝑛.
A degree-n interval Bernstein polynomial P with its region [a .. b] can represent an exact polynomial p in two
different ways: it can “contain” the polynomial or it can “bound” the polynomial.
We say that P contains p if, when p is represented as a degree-n Bernstein polynomial over [a .. b], its coefficients
are contained in the corresponding interval coefficients of P. For instance, [0.9 .. 1.1]*x^2 (which is a degree-2
interval Bernstein polynomial over [0 .. 1]) contains x^2.
We say that P bounds p if, for all a <= x <= b, there exists a polynomial p’ contained in P such that p(x) ==
p’(x). For instance, [0 .. 1]*x is a degree-1 interval Bernstein polynomial which bounds x^2 over [0 .. 1].
If P contains p, then P bounds p; but the converse is not necessarily true. In particular, if n < m, it is possible for
a degree-n interval Bernstein polynomial to bound a degree-m polynomial; but it cannot contain the polynomial.
In the case where P bounds p, we maintain extra information, the “slope error”. We say that P (over [a .. b])
bounds p with a slope error of E (where E is an interval) if there is a polynomial p’ contained in P such that the
derivative of (p - p’) is bounded by E in the range [a .. b]. If P bounds p with a slope error of 0 then P contains
p.
(Note that “contains” and “bounds” are not standard terminology; I just made them up.)
Interval Bernstein polynomials are useful in finding real roots because of the following properties:
• Given an exact real polynomial p, we can compute an interval Bernstein polynomial over an arbitrary
region containing p.
• Given an interval Bernstein polynomial P over [a .. c], where a < b < c, we can compute interval Bernstein
polynomials P1 over [a .. b] and P2 over [b .. c], where P1 and P2 contain (or bound) all polynomials that
P contains (or bounds).
• Given a degree-n interval Bernstein polynomial P over [a .. b], and m < n, we can compute a degree-m
interval Bernstein polynomial P’ over [a .. b] that bounds all polynomials that P bounds.
• It is sometimes possible to prove that no polynomial bounded by P over [a .. b] has any roots in [a .. b].
(Roughly, this is possible when no polynomial contained by P has any complex roots near the line segment
[a .. b], where “near” is defined relative to the length b-a.)
• It is sometimes possible to prove that every polynomial bounded by P over [a .. b] with slope error E has
exactly one root in [a .. b]. (Roughly, this is possible when every polynomial contained by P over [a .. b]
has exactly one root in [a .. b], there are no other complex roots near the line segment [a .. b], and every
polynomial contained in P has a derivative which is bounded away from zero over [a .. b] by an amount
which is large relative to E.)
• Starting from a sufficiently precise interval Bernstein polynomial, it is always possible to split it into
polynomials which provably have 0 or 1 roots (as long as your original polynomial has no multiple real
roots).
So a rough outline of a family of algorithms would be:
• Given a polynomial p, compute a region [a .. b] in which any real roots must lie.
• Compute an interval Bernstein polynomial P containing p over [a .. b].
• Keep splitting P until you have isolated all the roots. Optionally, reduce the degree or the precision of the
interval Bernstein polynomials at intermediate stages (to reduce computation time). If this seems not to be
working, go back and try again with higher precision.
Obviously, there are many details to be worked out to turn this into a full algorithm, like:
• What initial precision is selected for computing P?
• How do you decide when to reduce the degree of intermediate polynomials?
• How do you decide when to reduce the precision of intermediate polynomials?
• How do you decide where to split the interval Bernstein polynomial regions?
• How do you decide when to give up and start over with higher precision?
Each set of answers to these questions gives a different algorithm (potentially with very different performance
characteristics), but all of them can use this interval_bernstein_polynomial class as their basic
building block.
To save computation time, all coefficients in an interval_bernstein_polynomial share the same
interval width. (There is one exception: when creating an interval_bernstein_polynomial, the
first and last coefficients can be marked as “known positive” or “known negative”. This has some of the
same effect as having a (potentially) smaller interval width for these two coefficients, although it does not
affect de Casteljau splitting.) To allow for widely varying coefficient magnitudes, all coefficients in an inter-
val_bernstein_polynomial are scaled by 2𝑛 (where 𝑛 may be positive, negative, or zero).
There are two representations for interval_bernstein_polynomials, integer and floating-point. These are the two
subclasses of this class; interval_bernstein_polynomial itself is an abstract class.
interval_bernstein_polynomial and its subclasses are not expected to be used outside this file.
region()
region_width()
try_rand_split(ctx, logging_note)
Compute a random split point r (using the random number generator embedded in ctx). We require 1/4 <=
r < 3/4 (to ensure that recursive algorithms make progress).
Then, try doing a de Casteljau split of this polynomial at r, resulting in polynomials p1 and p2. If we see
that the sign of this polynomial is determined at r, then return (p1, p2, r); otherwise, return None.
EXAMPLES:
sage: from sage.rings.polynomial.real_roots import *
sage: bp = mk_ibpi([50, 20, -90, -70, 200], error=5)
sage: bp1, bp2, _ = bp.try_rand_split(mk_context(), None)
sage: bp1
<IBP: (50, 29, -27, -56, -11) + [0 .. 6) over [0 .. 43/64]>
sage: bp2
<IBP: (-11, 10, 49, 111, 200) + [0 .. 6) over [43/64 .. 1]>
sage: bp1, bp2, _ = bp.try_rand_split(mk_context(seed=42), None)
sage: bp1
<IBP: (50, 32, -11, -41, -29) + [0 .. 6) over [0 .. 583/1024]>
sage: bp2
<IBP: (-29, -20, 13, 83, 200) + [0 .. 6) over [583/1024 .. 1]>
sage: bp = mk_ibpf([0.5, 0.2, -0.9, -0.7, 0.99], neg_err=-0.1, pos_err=0.01)
sage: bp1, bp2, _ = bp.try_rand_split(mk_context(), None)
sage: bp1 # rel tol
<IBP: (0.5, 0.2984375, -0.2642578125, -0.5511661529541015, -0.
˓→3145806974172592) + [-0.10000000000000069 .. 0.010000000000000677] over [0 .
˓→. 43/64]>
(continues on next page)
˓→64 .. 1]>
try_split(ctx, logging_note)
Try doing a de Casteljau split of this polynomial at 1/2, resulting in polynomials p1 and p2. If we see that
the sign of this polynomial is determined at 1/2, then return (p1, p2, 1/2); otherwise, return None.
EXAMPLES:
sage: bp2
<IBP: (-0.369375, -0.45125, -0.3275, 0.14500000000000002, 0.99) + [-0.
˓→10000000000000023 .. 0.010000000000000226] over [1/2 .. 1]>
variations()
Consider a polynomial (written in either the normal power basis or the Bernstein basis). Take its list of
coefficients, omitting zeroes. Count the number of positions in the list where the sign of one coefficient is
opposite the sign of the next coefficient.
This count is the number of sign variations of the polynomial. According to Descartes’ rule of signs, the
number of real roots of the polynomial (counted with multiplicity) in a certain interval is always less than
or equal to the number of sign variations, and the difference is always even. (If the polynomial is written
in the power basis, the region is the positive reals; if the polynomial is written in the Bernstein basis over
a particular region, then we count roots in that region.)
In particular, a polynomial with no sign variations has no real roots in the region, and a polynomial with
one sign variation has one real root in the region.
In an interval Bernstein polynomial, we do not necessarily know the signs of the coefficients (if some of
the coefficient intervals contain zero), so the polynomials contained by this interval polynomial may not
all have the same number of sign variations. However, we can compute a range of possible numbers of
sign variations.
This function returns the range, as a 2-tuple of integers.
class sage.rings.polynomial.real_roots.interval_bernstein_polynomial_float
Bases: sage.rings.polynomial.real_roots.interval_bernstein_polynomial
This is the subclass of interval_bernstein_polynomial where polynomial coefficients are represented using
floating-point numbers.
In the floating-point representation, each coefficient is represented as an IEEE double-precision float A, and
the (shared) lower and upper interval widths E1 and E2. These represent the coefficients (A+E1)*2^n <= c <=
(A+E2)*2^n.
Note that we always have E1 <= 0 <= E2. Also, each floating-point coefficient has absolute value less than one.
(Note that mk_ibpf is a simple helper function for creating elements of interval_bernstein_polynomial_float in
doctests.)
EXAMPLES:
sage: bp.variations()
(3, 3)
as_float()
de_casteljau(ctx, mid, msign=0)
Uses de Casteljau’s algorithm to compute the representation of this polynomial in a Bernstein basis over
new regions.
INPUT:
• mid – where to split the Bernstein basis region; 0 < mid < 1
• msign – default 0 (unknown); the sign of this polynomial at mid
OUTPUT:
• bp1, bp2 – the new interval Bernstein polynomials
• ok – a boolean; True if the sign of the original polynomial at mid is known
EXAMPLES:
sage: bp2
<IBP: (-0.369375, -0.45125, -0.3275, 0.14500000000000002, 0.99) + [-0.
˓→10000000000000023 .. 0.010000000000000226] over [1/2 .. 1]>
˓→.. 2/3]>
˓→. 7/39]>
get_msb_bit()
Returns an approximation of the log2 of the maximum of the absolute values of the coefficients, as an
integer.
slope_range()
Compute a bound on the derivative of this polynomial, over its region.
EXAMPLES:
class sage.rings.polynomial.real_roots.interval_bernstein_polynomial_integer
Bases: sage.rings.polynomial.real_roots.interval_bernstein_polynomial
This is the subclass of interval_bernstein_polynomial where polynomial coefficients are represented using inte-
gers.
In this integer representation, each coefficient is represented by a GMP arbitrary-precision integer A, and
a (shared) interval width E (which is a machine integer). These represent the coefficients A*2^n <= c <
(A+E)*2^n.
(Note that mk_ibpi is a simple helper function for creating elements of interval_bernstein_polynomial_integer
in doctests.)
EXAMPLES:
sage: bp.variations()
(3, 3)
as_float()
Compute an interval_bernstein_polynomial_float which contains (or bounds) all the polynomials this in-
terval polynomial contains (or bounds).
EXAMPLES:
down_degree_iter(ctx, max_scale)
Compute a degree-reduced version of this interval polynomial, by iterating down_degree.
We stop when degree reduction would give a polynomial which is too inaccurate, meaning that either we
think the current polynomial may have more roots in its region than the degree of the reduced polynomial,
or that the least significant accurate bit in the result (on the absolute scale) would be larger than 1 <<
max_scale.
EXAMPLES:
downscale(bits)
Compute an interval_bernstein_polynomial_integer which contains (or bounds) all the polynomials this
interval polynomial contains (or bounds), but uses “bits” fewer bits.
EXAMPLES:
get_msb_bit()
Returns an approximation of the log2 of the maximum of the absolute values of the coefficients, as an
integer.
slope_range()
Compute a bound on the derivative of this polynomial, over its region.
EXAMPLES:
sage.rings.polynomial.real_roots.intvec_to_doublevec(b, err)
Given a vector of integers A = [a1, . . . , an], and an integer error bound E, returns a vector of floating-point
numbers B = [b1, . . . , bn], lower and upper error bounds F1 and F2, and a scaling factor d, such that
(𝑏𝑘 + 𝐹 1) * 2𝑑 ≤ 𝑎𝑘
and
𝑎𝑘 + 𝐸 ≤ (𝑏𝑘 + 𝐹 2) * 2𝑑
If bj is the element of B with largest absolute value, then 0.5 <= abs(bj) < 1.0 .
EXAMPLES:
class sage.rings.polynomial.real_roots.island
Bases: object
This implements the island portion of my ocean-island root isolation algorithm. See the documentation for class
ocean, for more information on the overall algorithm.
Island root refinement starts with a Bernstein polynomial whose region is the whole island (or perhaps slightly
more than the island in certain cases). There are two subalgorithms; one when looking at a Bernstein polynomial
covering a whole island (so we know that there are gaps on the left and right), and one when looking at a
Bernstein polynomial covering the left segment of an island (so we know that there is a gap on the left, but the
right is in the middle of an island). An important invariant of the left-segment subalgorithm over the region [l ..
r] is that it always finds a gap [r0 .. r] ending at its right endpoint.
Ignoring degree reduction, downscaling (precision reduction), and failures to split, the algorithm is roughly:
Whole island:
1. If the island definitely has exactly one root, then return.
2. Split the island in (approximately) half.
3. If both halves definitely have no roots, then remove this island from its doubly-linked list (merging its left
and right gaps) and return.
4. If either half definitely has no roots, then discard that half and call the whole-island algorithm with the
other half, then return.
5. If both halves may have roots, then call the left-segment algorithm on the left half.
6. We now know that there is a gap immediately to the left of the right half, so call the whole-island algorithm
on the right half, then return.
Left segment:
1. Split the left segment in (approximately) half.
2. If both halves definitely have no roots, then extend the left gap over the segment and return.
3. If the left half definitely has no roots, then extend the left gap over this half and call the left-segment
algorithm on the right half, then return.
4. If the right half definitely has no roots, then split the island in two, creating a new gap. Call the whole-
island algorithm on the left half, then return.
5. Both halves may have roots. Call the left-segment algorithm on the left half.
6. We now know that there is a gap immediately to the left of the right half, so call the left-segment algorithm
on the right half, then return.
Degree reduction complicates this picture only slightly. Basically, we use heuristics to decide when degree
reduction might be likely to succeed and be helpful; whenever this is the case, we attempt degree reduction.
Precision reduction and split failure add more complications. The algorithm maintains a stack of different-
precision representations of the interval Bernstein polynomial. The base of the stack is at the highest (currently
known) precision; each stack entry has approximately half the precision of the entry below it. When we do a
split, we pop off the top of the stack, split it, then push whichever half we’re interested in back on the stack (so
the different Bernstein polynomials may be over different regions). When we push a polynomial onto the stack,
we may heuristically decide to push further lower-precision versions of the same polynomial onto the stack.
In the algorithm above, whenever we say “split in (approximately) half”, we attempt to split the top-of-stack
polynomial using try_split() and try_rand_split(). However, these will fail if the sign of the polynomial at
the chosen split point is unknown (if the polynomial is not known to high enough precision, or if the chosen
split point actually happens to be a root of the polynomial). If this fails, then we discard the top-of-stack
polynomial, and try again with the next polynomial down (which has approximately twice the precision). This
next polynomial may not be over the same region; if not, we split it using de Casteljau’s algorithm to get a
polynomial over (approximately) the same region first.
If we run out of higher-precision polynomials (if we empty out the entire stack), then we give up on root
refinement for this island. The ocean class will notice this, provide the island with a higher-precision polynomial,
and restart root refinement. Basically the only information kept in that case is the lower and upper bounds on
the island. Since these are updated whenever we discover a “half” (of an island or a segment) that definitely
contains no roots, we never need to re-examine these gaps. (We could keep more information. For example, we
could keep a record of split points that succeeded and failed. However, a split point that failed at lower precision
is likely to succeed at higher precision, so it’s not worth avoiding. It could be useful to select split points that
are known to succeed, but starting from a new Bernstein polynomial over a slightly different region, hitting
such split points would require de Casteljau splits with non-power-of-two denominators, which are much much
slower.)
bp_done(bp)
Examine the given Bernstein polynomial to see if it is known to have exactly one root in its region. (In
addition, we require that the polynomial region not include 0 or 1. This makes things work if the user gives
explicit bounds to real_roots(), where the lower or upper bound is a root of the polynomial. real_roots()
deals with this by explicitly detecting it, dividing out the appropriate linear polynomial, and adding the
root to the returned list of roots; but then if the island considers itself “done” with a region including 0 or
1, the returned root regions can overlap with each other.)
done(ctx)
Check to see if the island is known to contain zero roots or is known to contain one root.
has_root()
Assuming that the island is done (has either 0 or 1 roots), reports whether the island has a root.
less_bits(ancestors, bp)
Heuristically pushes lower-precision polynomials on the polynomial stack. See the class documentation
for class island for more information.
more_bits(ctx, ancestors, bp, rightmost)
Find a Bernstein polynomial on the “ancestors” stack with more precision than bp; if it is over a different
region, then shrink its region to (approximately) match that of bp. (If this is rightmost – if bp covers the
whole island – then we only require that the new region cover the whole island fairly tightly; if this is not
rightmost, then the new region will have exactly the same right boundary as bp, although the left boundary
may vary slightly.)
refine(ctx)
Attempts to shrink and/or split this island into sub-island that each definitely contain exactly one root.
refine_recurse(ctx, bp, ancestors, history, rightmost)
This implements the root isolation algorithm described in the class documentation for class island. This is
the implementation of both the whole-island and the left-segment algorithms; if the flag rightmost is True,
then it is the whole-island algorithm, otherwise the left-segment algorithm.
The precision-reduction stack is (ancestors + [bp]); that is, the top-of-stack is maintained separately.
reset_root_width(target_width)
Modify the criteria for this island to require that it is not “done” until its width is less than or equal to
target_width.
shrink_bp(ctx)
If the island’s Bernstein polynomial covers a region much larger than the island itself (in particular, if
either the island’s left gap or right gap are totally contained in the polynomial’s region) then shrink the
polynomial down to cover the island more tightly.
class sage.rings.polynomial.real_roots.linear_map(lower, upper)
A simple class to map linearly between original coordinates (ranging from [lower .. upper]) and ocean coordi-
nates (ranging from [0 .. 1]).
from_ocean(region)
to_ocean(region)
sage.rings.polynomial.real_roots.max_abs_doublevec(c)
Given a floating-point vector, return the maximum of the absolute values of its elements.
EXAMPLES:
sage.rings.polynomial.real_roots.max_bitsize_intvec_doctest(b)
sage.rings.polynomial.real_roots.maximum_root_first_lambda(p)
Given a polynomial with real coefficients, computes an upper bound on its largest real root, using the first-
lambda algorithm from “Implementations of a New Theorem for Computing Bounds for Positive Roots of
Polynomials”, by Akritas, Strzebo’nski, and Vigklas.
EXAMPLES:
sage.rings.polynomial.real_roots.maximum_root_local_max(p)
Given a polynomial with real coefficients, computes an upper bound on its largest real root, using the local-max
algorithm from “Implementations of a New Theorem for Computing Bounds for Positive Roots of Polynomials”,
by Akritas, Strzebo’nski, and Vigklas.
EXAMPLES:
sage.rings.polynomial.real_roots.min_max_delta_intvec(a, b)
Given two integer vectors a and b (of equal, nonzero length), return a pair of the minimum and maximum values
taken on by a[i] - b[i].
EXAMPLES:
sage.rings.polynomial.real_roots.min_max_diff_doublevec(c)
Given a floating-point vector b = (b0, . . . , bn), compute the minimum and maximum values of b_{j+1} - b_j.
EXAMPLES:
sage.rings.polynomial.real_roots.min_max_diff_intvec(b)
Given an integer vector b = (b0, . . . , bn), compute the minimum and maximum values of b_{j+1} - b_j.
EXAMPLES:
class sage.rings.polynomial.real_roots.ocean
Bases: object
Given the tools we’ve defined so far, there are many possible root isolation algorithms that differ on where to
select split points, what precision to work at when, and when to attempt degree reduction.
Here we implement one particular algorithm, which I call the ocean-island algorithm. We start with an interval
Bernstein polynomial defined over the region [0 .. 1]. This region is the “ocean”. Using de Casteljau’s algorithm
and Descartes’ rule of signs, we divide this region into subregions which may contain roots, and subregions
which are guaranteed not to contain roots. Subregions which may contain roots are “islands”; subregions known
not to contain roots are “gaps”.
All the real root isolation work happens in class island. See the documentation of that class for more information.
An island can be told to refine itself until it contains only a single root. This may not succeed, if the island’s
interval Bernstein polynomial does not have enough precision. The ocean basically loops, refining each of its
islands, then increasing the precision of islands which did not succeed in isolating a single root; until all islands
are done.
Increasing the precision of unsuccessful islands is done in a single pass using split_for_target(); this means it is
possible to share work among multiple islands.
all_done()
Returns true iff all islands are known to contain exactly one root.
EXAMPLES:
sage: oc.all_done()
False
sage: oc.find_roots()
sage: oc.all_done()
True
approx_bp(scale_log2)
Returns an approximation to our Bernstein polynomial with the given scale_log2.
EXAMPLES:
sage: oc.approx_bp(0)
<IBP: (0, -4, 2, -2) + [0 .. 1); lsign 1>
sage: oc.approx_bp(-20)
<IBP: ((349525, -3295525, 2850354, -1482835) + [0 .. 1)) * 2^-20>
find_roots()
Isolate all roots in this ocean.
EXAMPLES:
sage: oc
ocean with precision 120 and 1 island(s)
sage: oc.find_roots()
sage: oc
ocean with precision 120 and 3 island(s)
sage: oc = ocean(mk_context(), bernstein_polynomial_factory_ratlist([1, 0, -
˓→1111/2, 0, 11108889/14, 0, 0, 0, 0, -1]), lmap)
sage: oc.find_roots()
sage: oc
ocean with precision 240 and 3 island(s)
increase_precision()
Increase the precision of the interval Bernstein polynomial held by any islands which are not done. (In
normal use, calls to this function are separated by calls to self.refine_all().)
EXAMPLES:
sage: oc
ocean with precision 120 and 1 island(s)
sage: oc.increase_precision()
sage: oc.increase_precision()
sage: oc.increase_precision()
sage: oc
ocean with precision 960 and 1 island(s)
refine_all()
Refine all islands which are not done (which are not known to contain exactly one root).
EXAMPLES:
sage: oc
ocean with precision 120 and 1 island(s)
sage: oc.refine_all()
sage: oc
ocean with precision 120 and 3 island(s)
reset_root_width(isle_num, target_width)
Require that the isle_num island have a width at most target_width.
If this is followed by a call to find_roots(), then the corresponding root will be refined to the specified
width.
EXAMPLES:
sage: oc.find_roots()
sage: oc.roots()
(continues on next page)
roots()
Return the locations of all islands in this ocean. (If run after find_roots(), this is the location of all roots in
the ocean.)
EXAMPLES:
sage: oc.find_roots()
sage: oc.roots()
[(1/32, 1/16), (1/2, 5/8), (3/4, 7/8)]
sage: oc = ocean(mk_context(), bernstein_polynomial_factory_ratlist([1, 0, -
˓→1111/2, 0, 11108889/14, 0, 0, 0, 0, -1]), lmap)
sage: oc.find_roots()
sage: oc.roots()
[(95761241267509487747625/9671406556917033397649408, 191522482605387719863145/
˓→19342813113834066795298816), (1496269395904347376805/
˓→151115727451828646838272, 374067366568272936175/37778931862957161709568),
˓→(31/32, 63/64)]
sage.rings.polynomial.real_roots.precompute_degree_reduction_cache(n)
Compute and cache the matrices used for degree reduction, starting from degree n.
EXAMPLES:
sage.rings.polynomial.real_roots.pseudoinverse(m)
sage.rings.polynomial.real_roots.rational_root_bounds(p)
Given a polynomial p with real coefficients, computes rationals a and b, such that for every real root r of p, a < r
< b. We try to find rationals which bound the roots somewhat tightly, yet are simple (have small numerators and
denominators).
EXAMPLES:
If we can see that the polynomial has no real roots, return None. sage: rational_root_bounds(x^2 + 7) is
None True
The precision of the results can be improved (at the expense of time, of course) by specifying the max_diameter
parameter. If specified, this sets the maximum diameter() of the intervals returned. (Sage defines diameter() to
be the relative diameter for intervals that do not contain 0, and the absolute diameter for intervals containing
0.) This directly affects the results in rational or interval return mode; in algebraic_real mode, it increases the
precision of the intervals passed to the algebraic number package, which may speed up some operations on that
algebraic real.
Some logging can be enabled with do_logging=True. If logging is enabled, then the normal values are not
returned; instead, a pair of the internal context object and a list of all the roots in their internal form is returned.
ALGORITHM: We convert the polynomial into the Bernstein basis, and then use de Casteljau’s algorithm and
Descartes’ rule of signs (using interval arithmetic) to locate the roots.
EXAMPLES:
˓→21267647932558653966460912964485513216,
˓→4253316902721330018853696359533061621799/
˓→42535295865117307932921825928971026432), 1),
˓→((1063329226287740282451317352558954186101/
˓→10633823966279326983230456482242756608, 531664614358685696701445201630854654353/
˓→5316911983139663491615228241121378304), 1)]
˓→16614519150981033789137940378745325503/166153499473114484112975882535043072),
˓→1), ((519203723562592617581015249797434335/5192296858534827628530496329220096,
˓→60443268924081068060312183/604462909807314587353088), 1)]
˓→5444517870735015415413993718908291383296,
˓→1088849127096660194637118845654929064385439/
˓→10889035741470030830827987437816582766592), 1),
˓→((272212281929661439711063928866060007142141/
˓→2722258935367507707706996859454145691648,
˓→136106141275823501959100399337685485662633/
˓→1361129467683753853853498429727072845824), 1)]
sage: real_roots(x)
[((-47/256, 81/512), 1)]
sage: real_roots(x * (x-1))
[((-47/256, 81/512), 1), ((1/2, 1201/1024), 1)]
sage: real_roots(x-1)
[((209/256, 593/512), 1)]
sage: real_roots(x*(x-1)*(x-2), bounds=(0, 2))
[((0, 0), 1), ((81/128, 337/256), 1), ((2, 2), 1)]
sage: real_roots(x*(x-1)*(x-2), bounds=(0, 2), retval='algebraic_real')
[(0, 1), (1, 1), (2, 1)]
sage: v = 2^40
(continues on next page)
˓→6427752177038884105442509510587059395588605840418680645585479/
˓→((62165404551223330269422781018352603934643403586760330761772204409982940218804935733653/
˓→62165404551223330269422781018352605012557018849668464680057997111644937126566671941632,
˓→
˓→ 3885337784451458141838923813647037871787041539340705594199885610069035709862106085785/
˓→ 3885337784451458141838923813647037813284813678104279042503624819477808570410416996352),
˓→ 2),
˓→((509258994083853105745586001837045839749063767798922046787130823804169826426726965449697819/
˓→509258994083621521567111422102344540262867098416484062659035112338595324940834176545849344,
˓→ 25711008708155536421770038042348240136257704305733983563630791/
˓→25711008708143844408671393477458601640355247900524685364822016), 1)]
sage: real_roots(x^2 - 2)
[((-3/2, -1), 1), ((1, 3/2), 1)]
sage: real_roots(x^2 - 2, retval='interval')
[(-2.?, 1), (2.?, 1)]
sage: real_roots(x^2 - 2, max_diameter=1/2^30)
[((-
˓→22506280506048041472675379598886543645348790970912519198456805737131269246430553365310109/
˓→15914343565113172548972231940698266883214596825515126958094847260581103904401068017057792,
˓→ -
˓→45012561012096082945350759197773086524448972309421182031053065599548946985601579935498343/
˓→31828687130226345097944463881396533766429193651030253916189694521162207808802136034115584),
˓→ 1),
˓→((45012561012096082945350759197773086524448972309421182031053065599548946985601579935498343/
˓→31828687130226345097944463881396533766429193651030253916189694521162207808802136034115584,
˓→
˓→ 22506280506048041472675379598886543645348790970912519198456805737131269246430553365310109/
˓→ 15914343565113172548972231940698266883214596825515126958094847260581103904401068017057792),
˓→ 1)]
˓→4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276
˓→, 1)]
sage: p = x^71 - x^69 - 2*x^68 - x^67 + 2*x^66 + 2*x^65 + x^64 - x^63 - x^62 - x^
˓→61 - x^60 - x^59 + 2*x^58 + 5*x^57 + 3*x^56 - 2*x^55 - 10*x^54 - 3*x^53 - 2*x^
˓→52 + 6*x^51 + 6*x^50 + x^49 + 9*x^48 - 3*x^47 - 7*x^46 - 8*x^45 - 8*x^44 + 10*x^
˓→43 + 6*x^42 + 8*x^41 - 5*x^40 - 12*x^39 + 7*x^38 - 7*x^37 + 7*x^36 + x^35 - 3*x^
˓→16 + 12*x^15 + 7*x^14 + 2*x^13 - 12*x^12 - 4*x^11 - 2*x^10 + 5*x^9 + x^7 - 7*x^
sage: x = polygen(AA)
sage: p = (x - 1) * (x - sqrt(AA(2))) * (x - 2)
sage: real_roots(p)
[((499/525, 2171/1925), 1), ((1173/875, 2521/1575), 1), ((337/175, 849/175), 1)]
sage: ar_rts = real_roots(p, retval='algebraic_real'); ar_rts
[(1.000000000000000?, 1), (1.414213562373095?, 1), (2.000000000000000?, 1)]
sage: ar_rts[1][0]^2 == 2
True
sage: ar_rts = real_roots(x*(x-1), retval='algebraic_real')
sage: ar_rts[0][0] == 0
True
sage: p2 = p * (p - 1/100); p2
x^6 - 8.82842712474619?*x^5 + 31.97056274847714?*x^4 - 60.77955262170047?*x^3 +
˓→63.98526763257801?*x^2 - 35.37613490585595?*x + 8.028284271247462?
sage.rings.polynomial.real_roots.relative_bounds(a, b)
INPUT:
• (al, ah) – pair of rationals
• (bl, bh) – pair of rationals
OUTPUT:
• (cl, ch) – pair of rationals
Computes the linear transformation that maps (al, ah) to (0, 1); then applies this transformation to (bl, bh) and
returns the result.
EXAMPLES:
sage.rings.polynomial.real_roots.reverse_intvec(c)
Given a vector of integers, reverse the vector (like the reverse() method on lists).
Modifies the input vector; has no return value.
EXAMPLES:
sage.rings.polynomial.real_roots.root_bounds(p)
Given a polynomial with real coefficients, computes a lower and upper bound on its real roots. Uses algorithms
of Akritas, Strzebo’nski, and Vigklas.
EXAMPLES:
If we can see that the polynomial has no real roots, return None.
class sage.rings.polynomial.real_roots.rr_gap
Bases: object
A simple class representing the gaps between islands, in my ocean-island root isolation algorithm. Named
“rr_gap” for “real roots gap”, because “gap” seemed too short and generic.
region()
sage.rings.polynomial.real_roots.scale_intvec_var(c, k)
Given a vector of integers c of length n+1, and a rational k == kn / kd, multiplies each element c[i] by
(kd^i)*(kn^(n-i)).
sage: bps[0]
<IBP: (999992, 999992, 999992) + [0 .. 15) over [8613397477114467984778830327/
˓→10633823966279326983230456482242756608 ..
˓→591908168025934394813836527495938294787/
sage: bps[1]
<IBP: (-1562500, -1875001, -2222223, -2592593, -2969137, -3337450) + [0 .. 4)
˓→over [1/2 .. 2863311531/4294967296]>
sage.rings.polynomial.real_roots.to_bernstein_warp(p)
Given a polynomial p with rational coefficients, compute the exact rational Bernstein coefficients of p(x/(x+1)).
EXAMPLES:
class sage.rings.polynomial.real_roots.warp_map(neg)
A class to map between original coordinates and ocean coordinates. If neg is False, then the original->ocean
transform is x -> x/(x+1), and the ocean->original transform is x/(1-x); this maps between [0 .. infinity] and [0
.. 1]. If neg is True, then the original->ocean transform is x -> -x/(1-x), and the ocean->original transform is the
same thing: -x/(1-x). This maps between [0 .. -infinity] and [0 .. 1].
from_ocean(region)
to_ocean(region)
sage.rings.polynomial.real_roots.wordsize_rational(a, b, wordsize)
Given rationals a and b, selects a de Casteljau split point r between a and b. An attempt is made to select an
efficient split point (according to the criteria mentioned in the documentation for de_casteljau_intvec), with a
bias towards split points near a.
In full detail:
Takes as input two rationals, a and b, such that 0<=a<=1, 0<=b<=1, and a!=b. Returns rational r, such that
a<=r<=b or b<=r<=a. The denominator of r is a power of 2. Let m be min(r, 1-r), nm be numerator(m), and
dml be log2(denominator(m)). The return value r is taken from the first of the following classes to have any
members between a and b (except that if a <= 1/8, or 7/8 <= a, then class 2 is preferred to class 1).
1. dml < wordsize
2. bitsize(nm) <= wordsize
3. bitsize(nm) <= 2*wordsize
4. bitsize(nm) <= 3*wordsize
...
11. bitsize(nm) <= (k-1)*wordsize
From the first class to have members between a and b, r is chosen as the element of the class which is closest to
a.
EXAMPLES:
AUTHOR:
• Carl Witty (2007-11-18): initial version
This is an implementation of complex root isolation. That is, given a polynomial with exact complex coefficients, we
compute isolating intervals for the complex roots of the polynomial. (Polynomials with integer, rational, Gaussian
rational, or algebraic coefficients are supported.)
We use a simple algorithm. First, we compute a squarefree decomposition of the input polynomial; the resulting
polynomials have no multiple roots. Then, we find the roots numerically, using NumPy (at low precision) or Pari (at
high precision). Then, we verify the roots using interval arithmetic.
EXAMPLES:
sage: x = polygen(ZZ)
sage: (x^5 - x - 1).roots(ring=CIF)
[(1.167303978261419?, 1), (-0.764884433600585? - 0.352471546031727?*I, 1), (-0.
˓→764884433600585? + 0.352471546031727?*I, 1), (0.181232444469876? - 1.
Unfortunately due to numerical noise there can be a small imaginary part to each root depending on CPU,
compiler, etc, and that affects the printing order. So we verify the real part of each root and check that the
imaginary part is small in both cases:
sage: v # random
[(-14.61803398874990?..., 1), (-12.3819660112501...? + 0.?e-27*I, 1)]
sage: sorted((v[0][0].real(),v[1][0].real()))
[-14.61803398874989?, -12.3819660112501...?]
sage: v[0][0].imag() < 1e25
True
sage: v[1][0].imag() < 1e25
True
This polynomial actually has all-real coefficients, and is very, very close to (x-1)^5:
sage: p = (x^2 + x - 1)
sage: p = p * p(x*im)
sage: p
-x^4 + (im - 1)*x^3 + im*x^2 + (-im - 1)*x + 1
Two of the roots have a zero real component; two have a zero imaginary component. These zero components
will be found slightly inaccurately, and the exact values returned are very sensitive to the (non-portable) results
of NumPy. So we post-process the roots for printing, to get predictable doctest results.
˓→618033988749895?])
sage: x = polygen(ZZ)
sage: p = x^3 - 1
sage: rts = [CC.zeta(3)^i for i in range(0, 3)]
sage: from sage.rings.polynomial.complex_roots import interval_roots
sage: interval_roots(p, rts, 53)
[1, -0.500000000000000? + 0.866025403784439?*I, -0.500000000000000? - 0.
˓→866025403784439?*I]
˓→500000000000000000000000000000000000000000000000000000000000? - 0.
˓→866025403784438646763723170752936183471402626905190314027904?*I]
sage.rings.polynomial.complex_roots.intervals_disjoint(intvs)
Given a list of complex intervals, check whether they are pairwise disjoint.
EXAMPLES:
This is an implementation of the Newton–Raphson algorithm to approximate roots of complex polynomials. The
implementation is based on interval arithmetic
AUTHORS:
• Carl Witty (2007-11-18): initial version
sage.rings.polynomial.refine_root.refine_root(ip, ipd, irt, fld)
We are given a polynomial and its derivative (with complex interval coefficients), an estimated root, and a
complex interval field to use in computations. We use interval arithmetic to refine the root and prove that we
have in fact isolated a unique root.
If we succeed, we return the isolated root; if we fail, we return None.
EXAMPLES:
AUTHORS:
• David Roe (2009-12-14) – initial version.
class sage.rings.polynomial.ideal.Ideal_1poly_field(ring, gen)
Bases: sage.rings.ideal.Ideal_pid
An ideal in a univariate polynomial ring over a field.
groebner_basis(algorithm=None)
Return a Gröbner basis for this ideal.
The Gröbner basis has 1 element, namely the generator of the ideal. This trivial method exists for compat-
ibility with multi-variate polynomial rings.
INPUT:
• algorithm – ignored
EXAMPLES:
sage: list(G)
[x - 1]
residue_class_degree()
Returns the degree of the generator of this ideal.
This function is included for compatibility with ideals in rings of integers of number fields.
EXAMPLES:
residue_field(names=None, check=True)
If this ideal is 𝑃 ⊂ 𝐹𝑝 [𝑡], returns the quotient 𝐹𝑝 [𝑡]/𝑃 .
EXAMPLES:
EXAMPLES:
class sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRingFactory
Bases: sage.structure.factory.UniqueFactory
Create a quotient of a polynomial ring.
INPUT:
• ring - a univariate polynomial ring
• polynomial - an element of ring with a unit leading coefficient
• names - (optional) name for the variable
OUTPUT: Creates the quotient ring 𝑅/𝐼, where 𝑅 is the ring and 𝐼 is the principal ideal generated by
polynomial.
EXAMPLES:
We create the quotient ring Z[𝑥]/(𝑥3 + 7), and demonstrate many basic functions with it:
sage: Z = IntegerRing()
sage: R = PolynomialRing(Z,'x'); x = R.gen()
sage: S = R.quotient(x^3 + 7, 'a'); a = S.gen()
sage: S
Univariate Quotient Polynomial Ring in a over Integer Ring with modulus x^3 + 7
sage: a^3
-7
sage: S.is_field()
False
sage: a in S
True
sage: x in S
True
sage: a in R
False
sage: S.polynomial_ring()
Univariate Polynomial Ring in x over Integer Ring
sage: S.modulus()
x^3 + 7
sage: S.degree()
3
˓→3 + 1
Next we create a number field, but viewed as a quotient of a polynomial ring over Q:
sage: S.is_field()
True
sage: S.degree()
3
There are conversion functions for easily going back and forth between quotients of polynomial rings over Q
and number fields:
sage: K = S.number_field(); K
Number Field in a with defining polynomial x^3 + 2*x - 5
sage: K.polynomial_quotient_ring()
Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^3 +
˓→2*x - 5
Another example:
create_object(version, key)
Return the quotient ring specified by key.
EXAMPLES:
class sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_coercion
Bases: sage.structure.coerce_maps.DefaultConvertMap_unique
A coercion map from a PolynomialQuotientRing to a PolynomialQuotientRing that restricts to
the coercion map on the underlying ring of constants.
EXAMPLES:
To: Univariate Quotient Polynomial Ring in xbar over Rational Field with
˓→modulus x^2 + 1
is_injective()
Return whether this coercion is injective.
EXAMPLES:
If the modulus of the domain and the codomain is the same and the leading coefficient is a unit in the
domain, then the map is injective if the underlying map on the constants is:
is_surjective()
Return whether this coercion is surjective.
EXAMPLES:
If the underlying map on constants is surjective, then this coercion is surjective since the modulus of the
codomain divides the modulus of the domain:
If the modulus of the domain and the codomain is the same, then the map is surjective iff the underlying
map on the constants is:
class sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_domain(ring,
poly-
no-
mial,
name=Non
cat-
e-
gory=None
Bases: sage.rings.polynomial.polynomial_quotient_ring.
PolynomialQuotientRing_generic, sage.rings.ring.IntegralDomain
EXAMPLES:
field_extension(names)
Takes a polynomial quotient ring, and returns a tuple with three elements: the NumberField defined by
the same polynomial quotient ring, a homomorphism from its parent to the NumberField sending the
generators to one another, and the inverse isomorphism.
OUTPUT:
• field
• homomorphism from self to field
• homomorphism from field to self
EXAMPLES:
sage: R.<x> = PolynomialRing(Rationals())
sage: S.<alpha> = R.quotient(x^3-2)
sage: F.<b>, f, g = S.field_extension()
sage: F
Number Field in b with defining polynomial x^3 - 2
sage: a = F.gen()
sage: f(alpha)
b
sage: g(a)
alpha
Over a finite field, the corresponding field extension is not a number field:
sage: R.<x> = GF(25, 'a')['x']
sage: S.<a> = R.quo(x^3 + 2*x + 1)
sage: F, g, h = S.field_extension('b')
sage: h(F.0^2 + 3)
a^2 + 3
sage: g(x^2 + 2)
b^2 + 2
Defn: b |--> b
a |--> a)
AUTHORS:
• Craig Citro (2006-08-07)
• William Stein (2006-08-06)
class sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_field(ring,
poly-
no-
mial,
name=None)
Bases: sage.rings.polynomial.polynomial_quotient_ring.
PolynomialQuotientRing_domain, sage.rings.ring.Field
EXAMPLES:
sage: loads(S.dumps()) == S
True
sage: loads(xbar.dumps()) == xbar
True
base_field()
˓→9025410530350528612407363802*I, 0.92103906697304693634806949137 - 3.
˓→0755331188457794473265418086*I, 0.92103906697304693634806949137 + 3.
˓→0755331188457794473265418086*I]
class sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic(ring,
poly-
no-
mial,
name=No
cat-
e-
gory=Non
Bases: sage.rings.ring.CommutativeRing
Quotient of a univariate polynomial ring by an ideal.
EXAMPLES:
sage: R.<x> = PolynomialRing(Integers(8)); R
Univariate Polynomial Ring in x over Ring of integers modulo 8
sage: S.<xbar> = R.quotient(x^2 + 1); S
Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 8 with
˓→modulus x^2 + 1
Element
alias of PolynomialQuotientRingElement
S_class_group(S, proof=True)
If self is an étale algebra 𝐷 over a number field 𝐾 (i.e. a quotient of 𝐾[𝑥] by a squarefree polynomial)
and 𝑆 is a finite set of places of 𝐾, return a list of generators of the 𝑆-class group of 𝐷.
NOTE:
Since the ideal function behaves differently over number fields than over polynomial quotient rings (the
quotient does not even know its ring of integers), we return a set of pairs (gen, order), where gen is
a tuple of generators of an ideal 𝐼 and order is the order of 𝐼 in the 𝑆-class group.
INPUT:
• S - a set of primes of the coefficient ring
• proof - if False, assume the GRH in computing the class group
OUTPUT:
A list of generators of the 𝑆-class group, in the form (gen, order), where gen is a tuple of elements
generating a fractional ideal 𝐼 and order is the order of 𝐼 in the 𝑆-class group.
EXAMPLES:
√
A trivial algebra over Q( −5) has the same class group as its base:
When we include the prime (2, −𝑎 + 1), the 𝑆-class group becomes trivial:
Here is an example where the base and the extension both contribute to the class group:
Now we take an example over a nontrivial base with two factors, each contributing to the class group:
sage: K.<a> = QuadraticField(-5)
sage: R.<x> = K[]
sage: S.<xbar> = R.quotient((x^2 + 23)*(x^2 + 31))
sage: S.S_class_group([])
[((1/4*xbar^2 + 31/4,
(-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8,
1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16,
-1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8),
6),
((-1/4*xbar^2 - 23/4,
(1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8,
-1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16,
1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8),
6),
((-5/4*xbar^2 - 115/4,
1/4*a*xbar^2 + 23/4*a,
-1/16*xbar^3 - 7/16*xbar^2 - 23/16*xbar - 161/16,
1/16*a*xbar^3 - 1/16*a*xbar^2 + 23/16*a*xbar - 23/16*a),
2)]
By using the ideal (𝑎), we cut the part of the class group coming from 𝑥2 + 31 from 12 to 2, i.e. we lose a
generator of order 6 (this was fixed in trac ticket #14489):
sage: S.S_class_group([K.ideal(a)])
[((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/
˓→16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/
Note that all the returned values live where we expect them to:
sage: CG = S.S_class_group([])
sage: type(CG[0][0][1])
<class 'sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_
˓→generic_with_category.element_class'>
sage: type(CG[0][1])
<type 'sage.rings.integer.Integer'>
S_units(S, proof=True)
If self is an étale algebra 𝐷 over a number field 𝐾 (i.e. a quotient of 𝐾[𝑥] by a squarefree polynomial)
and 𝑆 is a finite set of places of 𝐾, return a list of generators of the group of 𝑆-units of 𝐷.
INPUT:
• S - a set of primes of the base field
• proof - if False, assume the GRH in computing the class group
OUTPUT:
A list of generators of the 𝑆-unit group, in the form (gen, order), where gen is a unit of order
order.
EXAMPLES:
sage: K.<a> = QuadraticField(-3)
sage: K.unit_group()
(continues on next page)
Note that all the returned values live where we expect them to:
sage: U = L.S_units([])
sage: type(U[0][0])
<class 'sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_
˓→field_with_category.element_class'>
sage: type(U[0][1])
<type 'sage.rings.integer.Integer'>
sage: type(U[1][1])
<class 'sage.rings.infinity.PlusInfinity'>
ambient()
base_ring()
Return the base ring of the polynomial ring, of which this ring is a quotient.
EXAMPLES:
The base ring of Z[𝑧]/(𝑧 3 + 𝑧 2 + 𝑧 + 1) is Z.
Next we make a polynomial quotient ring over 𝑆 and ask for its base ring.
cardinality()
Return the number of elements of this quotient ring.
order is an alias of cardinality.
EXAMPLES:
sage: R.quo(1).order()
1
sage: R.quo(x^3-2).order()
+Infinity
characteristic()
Return the characteristic of this quotient ring.
This is always the same as the characteristic of the base ring.
EXAMPLES:
class_group(proof=True)
If self is a quotient ring of a polynomial ring over a number field 𝐾, by a polynomial of nonzero discrimi-
nant, return a list of generators of the class group.
NOTE:
Since the ideal function behaves differently over number fields than over polynomial quotient rings (the
quotient does not even know its ring of integers), we return a set of pairs (gen, order), where gen is
a tuple of generators of an ideal 𝐼 and order is the order of 𝐼 in the class group.
INPUT:
• proof - if False, assume the GRH in computing the class group
OUTPUT:
A list of pairs (gen, order), where gen is a tuple of elements generating a fractional ideal and order
is the order of 𝐼 in the class group.
EXAMPLES:
Here is an example where the base and the extension both contribute to the class group:
Here is an example of a product of number fields, both of which contribute to the class group:
˓→5)]
Now we take an example over a nontrivial base with two factors, each contributing to the class group:
Note that all the returned values live where we expect them to:
sage: CG = S.class_group()
sage: type(CG[0][0][1])
<class 'sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_
˓→generic_with_category.element_class'>
sage: type(CG[0][1])
<type 'sage.rings.integer.Integer'>
construction()
Functorial construction of self
EXAMPLES:
sage: P.<t>=ZZ[]
sage: Q = P.quo(5+t^2)
sage: F, R = Q.construction()
sage: F(R) == Q
True
sage: P.<t> = GF(3)[]
sage: Q = P.quo([2+t^2])
sage: F, R = Q.construction()
sage: F(R) == Q
True
AUTHOR:
– Simon King (2010-05)
cover_ring()
Return the polynomial ring of which this ring is the quotient.
EXAMPLES:
degree()
Return the degree of this quotient ring. The degree is the degree of the polynomial that we quotiented out
by.
EXAMPLES:
discriminant(v=None)
Return the discriminant of this ring over the base ring. This is by definition the discriminant of the poly-
nomial that we quotiented out by.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S = R.quotient(x^3 + x^2 + x + 1)
sage: S.discriminant()
-16
sage: S = R.quotient((x + 1) * (x + 1))
sage: S.discriminant()
0
The discriminant of the quotient polynomial ring need not equal the discriminant of the corresponding
number field, since the discriminant of a number field is by definition the discriminant of the ring of
integers of the number field:
sage: S = R.quotient(x^2 - 8)
sage: S.number_field().discriminant()
8
sage: S.discriminant()
32
gen(n=0)
Return the generator of this quotient ring. This is the equivalence class of the image of the generator of the
polynomial ring.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S = R.quotient(x^2 - 8, 'gamma')
sage: S.gen()
gamma
is_field(proof=True)
Return whether or not this quotient ring is a field.
EXAMPLES:
sage: R.<z> = PolynomialRing(ZZ)
sage: S = R.quo(z^2-2)
sage: S.is_field()
False
sage: R.<x> = PolynomialRing(QQ)
sage: S = R.quotient(x^2 - 2)
sage: S.is_field()
True
is_finite()
Return whether or not this quotient ring is finite.
EXAMPLES:
krull_dimension()
lift(x)
Return an element of the ambient ring mapping to the given argument.
EXAMPLES:
modulus()
Return the polynomial modulus of this quotient ring.
EXAMPLES:
ngens()
Return the number of generators of this quotient ring over the base ring. This function always returns 1.
EXAMPLES:
sage: T.ngens()
1
number_field()
Return the number field isomorphic to this quotient polynomial ring, if possible.
EXAMPLES:
order()
Return the number of elements of this quotient ring.
order is an alias of cardinality.
EXAMPLES:
sage: R.quo(1).order()
1
sage: R.quo(x^3-2).order()
+Infinity
polynomial_ring()
Return the polynomial ring of which this ring is the quotient.
EXAMPLES:
random_element(*args, **kwds)
Return a random element of this quotient ring.
INPUT:
• *args, **kwds - Arguments for randomization that are passed on to the random_element
method of the polynomial ring, and from there to the base ring
OUTPUT:
• Element of this quotient ring
EXAMPLES:
sage: F1.<a> = GF(2^7)
sage: P1.<x> = F1[]
sage: F2 = F1.extension(x^2+x+1, 'u')
sage: F2.random_element()
(a^6 + a^5 + a^2 + a)*u + a^6 + a^4 + a^3 + a^2 + 1
retract(x)
Return the coercion of x into this polynomial quotient ring.
The rings that coerce into the quotient ring canonically are:
• this ring
• any canonically isomorphic ring
• anything that coerces into the ring of which this is the quotient
selmer_group(S, m, proof=True)
If self is an étale algebra 𝐷 over a number field 𝐾 (i.e. a quotient of 𝐾[𝑥] by a squarefree polynomial) and
𝑆 is a finite set of places of 𝐾, compute
√ the Selmer group 𝐷(𝑆, 𝑚). This is the subgroup of 𝐷* /(𝐷* )𝑚
consisting of elements 𝑎 such that 𝐷( 𝑚 𝑎)/𝐷 is unramified at all primes of 𝐷 lying above a place outside
of 𝑆.
INPUT:
• S - A set of primes of the coefficient ring (which is a number field).
• m - a positive integer
• proof - if False, assume the GRH in computing the class group
OUTPUT:
A list of generators of 𝐷(𝑆, 𝑚).
EXAMPLES:
sage: K.<a> = QuadraticField(-5)
sage: R.<x> = K[]
sage: D.<T> = R.quotient(x)
sage: D.selmer_group((), 2)
[-1, 2]
sage: D.selmer_group([K.ideal(2, -a+1)], 2)
[2, -1]
(continues on next page)
units(proof=True)
If this quotient ring is over a number field K, by a polynomial of nonzero discriminant, returns a list of
generators of the units.
INPUT:
• proof - if False, assume the GRH in computing the class group
OUTPUT:
A list of generators of the unit group, in the form (gen, order), where gen is a unit of order order.
EXAMPLES:
Note that all the returned values live where we expect them to:
sage: type(U[0][1])
<type 'sage.rings.integer.Integer'>
sage: type(U[1][1])
<class 'sage.rings.infinity.PlusInfinity'>
sage.rings.polynomial.polynomial_quotient_ring.is_PolynomialQuotientRing(x)
sage: z^2
-a
sage: z^6
3*a - 1
For the purposes of comparison in Sage the quotient element 𝑎3 is equal to 𝑥3 . This is because when the comparison
is performed, the right element is coerced into the parent of the left element, and 𝑥3 coerces to 𝑎3 .
sage: a == x
True
sage: a^3 == x^3
True
sage: x^3
x^3
sage: S(x^3)
2
AUTHORS:
• William Stein
class sage.rings.polynomial.polynomial_quotient_ring_element.PolynomialQuotientRingElement(
Bases: sage.rings.polynomial.polynomial_singular_interface.
Polynomial_singular_repr, sage.structure.element.CommutativeRingElement
Element of a quotient of a polynomial ring.
EXAMPLES:
charpoly(var)
The characteristic polynomial of this element, which is by definition the characteristic polynomial of right
multiplication by this element.
INPUT:
• var - string - the variable name
EXAMPLES:
fcp(var=’x’)
Return the factorization of the characteristic polynomial of this element.
EXAMPLES:
field_extension(names)
Given a polynomial with base ring a quotient ring, return a 3-tuple: a number field defined by the same
polynomial, a homomorphism from its parent to the number field sending the generators to one another,
and the inverse isomorphism.
INPUT:
• names - name of generator of output field
OUTPUT:
• field
• homomorphism from self to field
• homomorphism from field to self
EXAMPLES:
Over a finite field, the corresponding field extension is not a number field:
AUTHORS:
• Craig Citro (2006-08-06)
• William Stein (2006-08-06)
is_unit()
Return True if self is invertible.
EXAMPLES:
lift()
Return lift of this polynomial quotient ring element to the unique equivalent polynomial of degree less
than the modulus.
EXAMPLES:
list(copy=True)
Return list of the elements of self, of length the same as the degree of the quotient polynomial ring.
EXAMPLES:
matrix()
The matrix of right multiplication by this element on the power basis for the quotient ring.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3 + 2*x - 5)
sage: a.matrix()
[ 0 1 0]
[ 0 0 1]
[ 5 -2 0]
minpoly()
The minimal polynomial of this element, which is by definition the minimal polynomial of right multipli-
cation by this element.
norm()
The norm of this element, which is the norm of the matrix of right multiplication by this element.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3 -389*x^2 + 2*x - 5)
sage: a.norm()
5
trace()
The trace of this element, which is the trace of the matrix of right multiplication by this element.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3 -389*x^2 + 2*x - 5)
sage: a.trace()
389
AUTHORS:
• Tom Boothby, initial design & implementation
• Robert Bradshaw, bug fixes / suggested & assisted with significant design improvements
class sage.rings.polynomial.polynomial_compiled.CompiledPolynomialFunction
Bases: object
Builds a reasonably optimized directed acyclic graph representation for a given polynomial. A CompiledPoly-
nomialFunction is callable from python, though it is a little faster to call the eval function from pyrex.
This class is not intended to be called by a user, rather, it is intended to improve the performance of immutable
polynomial objects.
Todo:
• Recursive calling
• Faster casting of coefficients / argument
• Multivariate polynomials
• Cython implementation of Pippenger’s Algorithm that doesn’t depend heavily upon dicts.
• Computation of parameter sequence suggested by Pippenger
• Univariate exponentiation can use Brauer’s method to improve extremely sparse polynomials of very high
degree
class sage.rings.polynomial.polynomial_compiled.abc_pd
Bases: sage.rings.polynomial.polynomial_compiled.binary_pd
class sage.rings.polynomial.polynomial_compiled.add_pd
Bases: sage.rings.polynomial.polynomial_compiled.binary_pd
class sage.rings.polynomial.polynomial_compiled.binary_pd
Bases: sage.rings.polynomial.polynomial_compiled.generic_pd
class sage.rings.polynomial.polynomial_compiled.coeff_pd
Bases: sage.rings.polynomial.polynomial_compiled.generic_pd
class sage.rings.polynomial.polynomial_compiled.dummy_pd
Bases: sage.rings.polynomial.polynomial_compiled.generic_pd
class sage.rings.polynomial.polynomial_compiled.generic_pd
Bases: object
class sage.rings.polynomial.polynomial_compiled.mul_pd
Bases: sage.rings.polynomial.polynomial_compiled.binary_pd
class sage.rings.polynomial.polynomial_compiled.pow_pd
Bases: sage.rings.polynomial.polynomial_compiled.unary_pd
class sage.rings.polynomial.polynomial_compiled.sqr_pd
Bases: sage.rings.polynomial.polynomial_compiled.unary_pd
class sage.rings.polynomial.polynomial_compiled.unary_pd
Bases: sage.rings.polynomial.polynomial_compiled.generic_pd
class sage.rings.polynomial.polynomial_compiled.univar_pd
Bases: sage.rings.polynomial.polynomial_compiled.generic_pd
class sage.rings.polynomial.polynomial_compiled.var_pd
Bases: sage.rings.polynomial.polynomial_compiled.generic_pd
Asymptotically fast convolution of lists over any commutative ring in which the multiply-by-two map is injective.
(More precisely, if 𝑥 ∈ 𝑅, and 𝑥 = 2𝑘 * 𝑦 for some 𝑘 ≥ 0, we require that 𝑅(𝑥/2𝑘 ) returns 𝑦.)
The main function to be exported is convolution().
EXAMPLES:
The convolution function is reasonably fast, even though it is written in pure Python. For example, the following takes
less than a second:
ALGORITHM: Converts the problem to multiplication in the ring 𝑆[𝑥]/(𝑥𝑀 − 1), where 𝑆 = 𝑅[𝑦]/(𝑦 𝐾 + 1) (where
𝑅 is the original base ring). Performs FFT with respect to the roots of unity 1, 𝑦, 𝑦 2 , . . . , 𝑦 2𝐾−1 in 𝑆. The FFT/IFFT
are accomplished with just additions and subtractions and rotating python lists. (I think this algorithm is essentially
due to Schonhage, not completely sure.) The pointwise multiplications are handled recursively, switching to a classical
algorithm at some point.
Complexity is O(n log(n) log(log(n))) additions/subtractions in R and O(n log(n)) multiplications in R.
AUTHORS:
• David Harvey (2007-07): first implementation
• William Stein: editing the docstrings for inclusion in Sage.
sage.rings.polynomial.convolution.convolution(L1, L2)
Returns convolution of non-empty lists L1 and L2. L1 and L2 may have arbitrary lengths.
EXAMPLES:
sage: R = Integers(47)
sage: L1 = [R.random_element() for _ in range(1000)]
sage: L2 = [R.random_element() for _ in range(3756)]
sage: L3 = convolution(L1, L2)
sage: L3[2000] == sum([L1[i] * L2[2000-i] for i in range(1000)])
True
sage: len(L3) == 1000 + 3756 - 1
True
This module provides a function cyclotomic_coeffs(), which calculates the coefficients of cyclo-
tomic polynomials. This is not intended to be invoked directly by the user, but it is called by the
method cyclotomic_polynomial() method of univariate polynomial ring objects and the top-level
cyclotomic_polynomial() function.
sage.rings.polynomial.cyclotomic.bateman_bound(nn)
Reference:
Bateman, P. T.; Pomerance, C.; Vaughan, R. C. On the size of the coefficients of the cyclotomic polynomial.
sage.rings.polynomial.cyclotomic.cyclotomic_coeffs(nn, sparse=None)
This calculates the coefficients of the n-th cyclotomic polynomial by using the formula
∏︁
Φ𝑛 (𝑥) = (1 − 𝑥𝑛/𝑑 )𝜇(𝑑)
𝑑|𝑛
where 𝜇(𝑑) is the Möbius function that is 1 if d has an even number of distinct prime divisors, -1 if it has an odd
number of distinct prime divisors, and 0 if d is not squarefree.
Multiplications and divisions by polynomials of the form 1 − 𝑥𝑛 can be done very quickly in a single pass.
If sparse is True, the result is returned as a dictionary of the non-zero entries, otherwise the result is returned as
a list of python ints.
EXAMPLES:
sage: euler_phi(30)
8
sage: R(cyclotomic_coeffs(14)).factor()
x^6 - x^5 + x^4 - x^3 + x^2 - x + 1
sage: cyclotomic_coeffs(105)
[1, 1, 1, 0, 0, -1, -1, -2, -1, -1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, -1, 0, -1, 0, -
˓→1, 0, -1, 0, -1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, -1, -1, -2, -1, -1, 0, 0, 1, 1,
˓→1]
In fact the height is not bounded by any polynomial in n (Erdos), although takes a while just to exceed linear:
sage: v = cyclotomic_coeffs(1181895)
sage: max(v)
14102773
sage: n = ZZ.random_element(50000)
sage: factor(n)
3 * 10009
sage: v = cyclotomic_coeffs(n, sparse=False)
sage: v == list(reversed(v))
True
AUTHORS:
• Robert Bradshaw (2007-10-27): initial version (inspired by work of Andrew Arnold and Michael Mona-
gan)
sage.rings.polynomial.cyclotomic.cyclotomic_value(n, x)
Return the value of the 𝑛-th cyclotomic polynomial evaluated at 𝑥.
INPUT:
• n – an Integer, specifying which cyclotomic polynomial is to be evaluated.
• x – an element of a ring.
OUTPUT:
• the value of the cyclotomic polynomial Φ𝑛 at 𝑥.
ALGORITHM:
• Reduce to the case that 𝑛 is squarefree: use the identity
Φ𝑛 (𝑥) = Φ𝑞 (𝑥𝑛/𝑞 )
where 𝑞 is the radical of 𝑛.
• Use the identity
∏︁
Φ𝑛 (𝑥) = (𝑥𝑑 − 1)𝜇(𝑛/𝑑) ,
𝑑|𝑛
sage: cyclotomic_value(51, 3)
1282860140677441
sage: cyclotomic_polynomial(51)(3)
1282860140677441
THREE
MULTIVARIATE POLYNOMIALS
Sage implements multivariate polynomial rings through several backends. The most generic implementation uses the
classes sage.rings.polynomial.polydict.PolyDict and sage.rings.polynomial.polydict.
ETuple to construct a dictionary with exponent tuples as keys and coefficients as values.
Additionally, specialized and optimized implementations over many specific coefficient rings are implemented via a
shared library interface to SINGULAR; and polynomials in the boolean polynomial ring
Degree reverse lexicographic (degrevlex) Let deg(𝑥𝑎 ) = 𝑎1 + 𝑎2 + · · · + 𝑎𝑛 , then 𝑥𝑎 < 𝑥𝑏 if and only if deg(𝑥𝑎 ) <
deg(𝑥𝑏 ) or deg(𝑥𝑎 ) = deg(𝑥𝑏 ) and there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎𝑛 = 𝑏𝑛 , . . . , 𝑎𝑖+1 = 𝑏𝑖+1 , 𝑎𝑖 > 𝑏𝑖 . This
term order is called ‘dp’ in Singular.
EXAMPLES:
243
Sage Reference Manual: Polynomials, Release 8.6
Degree lexicographic (deglex) Let deg(𝑥𝑎 ) = 𝑎1 + 𝑎2 + · · · + 𝑎𝑛 , then 𝑥𝑎 < 𝑥𝑏 if and only if deg(𝑥𝑎 ) < deg(𝑥𝑏 )
or deg(𝑥𝑎 ) = deg(𝑥𝑏 ) and there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎1 = 𝑏1 , . . . , 𝑎𝑖−1 = 𝑏𝑖−1 , 𝑎𝑖 < 𝑏𝑖 . This term order
is called ‘Dp’ in Singular.
EXAMPLES:
Inverse lexicographic (invlex) 𝑥𝑎 < 𝑥𝑏 if and only if there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎𝑛 = 𝑏𝑛 , . . . , 𝑎𝑖+1 =
𝑏𝑖+1 , 𝑎𝑖 < 𝑏𝑖 . This order is called ‘rp’ in Singular.
EXAMPLES:
This term order only makes sense in a non-commutative setting because if P is the ring 𝑘[𝑥1 , . . . , 𝑥𝑛 ] and term
order ‘invlex’ then it is equivalent to the ring 𝑘[𝑥𝑛 , . . . , 𝑥1 ] with term order ‘lex’.
Negative lexicographic (neglex) 𝑥𝑎 < 𝑥𝑏 if and only if there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎1 = 𝑏1 , . . . , 𝑎𝑖−1 =
𝑏𝑖−1 , 𝑎𝑖 > 𝑏𝑖 . This term order is called ‘ls’ in Singular.
EXAMPLES:
Negative degree reverse lexicographic (negdegrevlex) Let deg(𝑥𝑎 ) = 𝑎1 + 𝑎2 + · · · + 𝑎𝑛 , then 𝑥𝑎 < 𝑥𝑏 if and
only if deg(𝑥𝑎 ) > deg(𝑥𝑏 ) or deg(𝑥𝑎 ) = deg(𝑥𝑏 ) and there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎𝑛 = 𝑏𝑛 , . . . , 𝑎𝑖+1 =
𝑏𝑖+1 , 𝑎𝑖 > 𝑏𝑖 . This term order is called ‘ds’ in Singular.
EXAMPLES:
Negative degree lexicographic (negdeglex) Let deg(𝑥𝑎 ) = 𝑎1 +𝑎2 +· · ·+𝑎𝑛 , then 𝑥𝑎 < 𝑥𝑏 if and only if deg(𝑥𝑎 ) >
deg(𝑥𝑏 ) or deg(𝑥𝑎 ) = deg(𝑥𝑏 ) and there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎1 = 𝑏1 , . . . , 𝑎𝑖−1 = 𝑏𝑖−1 , 𝑎𝑖 < 𝑏𝑖 . This
term order is called ‘Ds’ in Singular.
EXAMPLES:
Weighted degree reverse lexicographic (wdegrevlex), positive integral weights Let deg𝑤 (𝑥𝑎 ) = 𝑎1 𝑤1 + 𝑎2 𝑤2 +
· · · + 𝑎𝑛 𝑤𝑛 with weights 𝑤, then 𝑥𝑎 < 𝑥𝑏 if and only if deg𝑤 (𝑥𝑎 ) < deg𝑤 (𝑥𝑏 ) or deg𝑤 (𝑥𝑎 ) = deg𝑤 (𝑥𝑏 ) and
there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎𝑛 = 𝑏𝑛 , . . . , 𝑎𝑖+1 = 𝑏𝑖+1 , 𝑎𝑖 > 𝑏𝑖 . This term order is called ‘wp’ in Singular.
EXAMPLES:
Weighted degree lexicographic (wdeglex), positive integral weights Let deg𝑤 (𝑥𝑎 ) = 𝑎1 𝑤1 + 𝑎2 𝑤2 + · · · + 𝑎𝑛 𝑤𝑛
with weights 𝑤, then 𝑥𝑎 < 𝑥𝑏 if and only if deg𝑤 (𝑥𝑎 ) < deg𝑤 (𝑥𝑏 ) or deg𝑤 (𝑥𝑎 ) = deg𝑤 (𝑥𝑏 ) and there exists
1 ≤ 𝑖 ≤ 𝑛 such that 𝑎1 = 𝑏1 , . . . , 𝑎𝑖−1 = 𝑏𝑖−1 , 𝑎𝑖 < 𝑏𝑖 . This term order is called ‘Wp’ in Singular.
EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(QQ, 3, order=TermOrder('wdeglex',(1,2,3)))
sage: x > y
False
sage: x > x^2
False
sage: x > 1
True
sage: x^1*y^2 > x^2*z
False
sage: y*z > x^3*y
False
Negative weighted degree reverse lexicographic (negwdegrevlex), positive integral weights Let deg𝑤 (𝑥𝑎 ) =
𝑎1 𝑤1 + 𝑎2 𝑤2 + · · · + 𝑎𝑛 𝑤𝑛 with weights 𝑤, then 𝑥𝑎 < 𝑥𝑏 if and only if deg𝑤 (𝑥𝑎 ) > deg𝑤 (𝑥𝑏 ) or
deg𝑤 (𝑥𝑎 ) = deg𝑤 (𝑥𝑏 ) and there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎𝑛 = 𝑏𝑛 , . . . , 𝑎𝑖+1 = 𝑏𝑖+1 , 𝑎𝑖 > 𝑏𝑖 . This
term order is called ‘ws’ in Singular.
EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(QQ, 3, order=TermOrder('negwdegrevlex',(1,2,3)))
sage: x > y
True
sage: x > x^2
True
sage: x > 1
False
sage: x^1*y^2 > x^2*z
True
sage: y*z > x^3*y
False
Degree negative lexicographic (degneglex) Let deg(𝑥𝑎 ) = 𝑎1 +𝑎2 +· · ·+𝑎𝑛 , then 𝑥𝑎 < 𝑥𝑏 if and only if deg(𝑥𝑎 ) <
deg(𝑥𝑏 ) or deg(𝑥𝑎 ) = deg(𝑥𝑏 ) and there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎1 = 𝑏1 , . . . , 𝑎𝑖−1 = 𝑏𝑖−1 , 𝑎𝑖 > 𝑏𝑖 . This
term order is called ‘dp_asc’ in PolyBoRi. Singular has the extra weight vector ordering ‘(r(1:n),rp)’ for this
purpose.
EXAMPLES:
sage: t = TermOrder('degneglex')
sage: P.<x,y,z> = PolynomialRing(QQ, order=t)
sage: x*y > y*z # indirect doctest
False
sage: x*y > x
True
Negative weighted degree lexicographic (negwdeglex), positive integral weights Let deg𝑤 (𝑥𝑎 ) = 𝑎1 𝑤1 +𝑎2 𝑤2 +
· · · + 𝑎𝑛 𝑤𝑛 with weights 𝑤, then 𝑥𝑎 < 𝑥𝑏 if and only if deg𝑤 (𝑥𝑎 ) > deg𝑤 (𝑥𝑏 ) or deg𝑤 (𝑥𝑎 ) = deg𝑤 (𝑥𝑏 ) and
there exists 1 ≤ 𝑖 ≤ 𝑛 such that 𝑎1 = 𝑏1 , . . . , 𝑎𝑖−1 = 𝑏𝑖−1 , 𝑎𝑖 < 𝑏𝑖 . This term order is called ‘Ws’ in Singular.
EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(QQ, 3, order=TermOrder('negwdeglex',(1,2,3)))
sage: x > y
True
sage: x > x^2
True
sage: x > 1
False
sage: x^1*y^2 > x^2*z
False
sage: y*z > x^3*y
False
Of these, only ‘degrevlex’, ‘deglex’, ‘degneglex’, ‘wdegrevlex’, ‘wdeglex’, ‘invlex’ and ‘lex’ are global orders.
Sage also supports matrix term order. Given a square matrix 𝐴,
𝑥𝑎 <𝐴 𝑥𝑏 if and only if 𝐴𝑎 < 𝐴𝑏
where < is the lexicographic term order.
EXAMPLES:
sage: m = matrix(2,[2,3,0,1]); m
[2 3]
[0 1]
sage: T = TermOrder(m); T
Matrix term order with matrix
[2 3]
[0 1]
sage: P.<a,b> = PolynomialRing(QQ,2,order=T)
sage: P
Multivariate Polynomial Ring in a, b over Rational Field
sage: a > b
False
sage: a^3 < b^2
True
sage: S = TermOrder('M(2,3,0,1)')
sage: T == S
True
Additionally all these monomial orders may be combined to product or block orders, defined as:
Let 𝑥 = (𝑥1 , 𝑥2 , . . . , 𝑥𝑛 ) and 𝑦 = (𝑦1 , 𝑦2 , . . . , 𝑦𝑚 ) be two ordered sets of variables, <1 a monomial order on 𝑘[𝑥] and
<2 a monomial order on 𝑘[𝑦].
The product order (or block order) < := (<1 , <2 ) on 𝑘[𝑥, 𝑦] is defined as: 𝑥𝑎 𝑦 𝑏 < 𝑥𝐴 𝑦 𝐵 if and only if 𝑥𝑎 <1 𝑥𝐴 or
(𝑥𝑎 = 𝑥𝐴 and 𝑦 𝑏 <2 𝑦 𝐵 ).
These block orders are constructed in Sage by giving a comma separated list of monomial orders with the length of
each block attached to them.
EXAMPLES:
As an example, consider constructing a block order where the first four variables are compared using the degree reverse
lexicographical order while the last two variables in the second block are compared using negative lexicographical
order.
sage: P.<a,b,c,d,e,f> = PolynomialRing(QQ, 6,order='degrevlex(4),neglex(2)')
sage: a > c^4
(continues on next page)
sage: T1 = TermOrder('degrevlex',4)
sage: T2 = TermOrder('neglex',2)
sage: T = T1 + T2
sage: P.<a,b,c,d,e,f> = PolynomialRing(QQ, 6, order=T)
sage: a > c^4
False
sage: a > e^4
True
If any other unsupported term order is given the provided string can be forced to be passed through as is to Singular,
Macaulay2, and Magma. This ensures that it is for example possible to calculate a Groebner basis with respect to
some term order Singular supports but Sage doesn’t:
sage: T = TermOrder("royalorder")
Traceback (most recent call last):
...
ValueError: unknown term order 'royalorder'
sage: T = TermOrder("royalorder",force=True)
sage: T
royalorder term order
sage: T.singular_str()
'royalorder'
AUTHORS:
• David Joyner and William Stein: initial version of multi_polynomial_ring
• Kiran S. Kedlaya: added macaulay2 interface
• Martin Albrecht: implemented native term orders, refactoring
• Kwankyu Lee: implemented matrix and weighted degree term orders, refactoring
class sage.rings.polynomial.term_order.TermOrder(name=’lex’, n=0, force=False)
Bases: sage.structure.sage_object.SageObject
A term order.
See sage.rings.polynomial.term_order for details on supported term orders.
blocks()
Return the term order blocks of self.
NOTE:
This method has been added in trac ticket #11316. There used to be an attribute of the same name and the
same content. So, it is a backward incompatible syntax change.
EXAMPLES:
sage: t=TermOrder('deglex',2)+TermOrder('lex',2)
sage: t.blocks()
(Degree lexicographic term order, Lexicographic term order)
greater_tuple
The default greater_tuple method for this term order.
EXAMPLES:
sage: O = TermOrder()
sage: O.greater_tuple.__func__ is O.greater_tuple_lex.__func__
True
sage: O = TermOrder('deglex')
sage: O.greater_tuple.__func__ is O.greater_tuple_deglex.__func__
True
greater_tuple_block(f, g)
Return the greater exponent tuple with respect to the block order as specified when constructing this ele-
ment.
This method is called by the lm/lc/lt methods of MPolynomial_polydict.
INPUT:
• f - exponent tuple
• g - exponent tuple
EXAMPLES:
greater_tuple_deglex(f, g)
Return the greater exponent tuple with respect to the total degree lexicographical term order.
INPUT:
• f - exponent tuple
• g - exponent tuple
EXAMPLES:
• g - exponent tuple
EXAMPLES:
greater_tuple_negdeglex(f, g)
Return the greater exponent tuple with respect to the negative degree lexicographical term order.
INPUT:
• f - exponent tuple
• g - exponent tuple
EXAMPLES:
greater_tuple_negwdeglex(f, g)
Return the greater exponent tuple with respect to the negative weighted degree lexicographical term order.
INPUT:
• f - exponent tuple
• g - exponent tuple
EXAMPLES:
sage: t = TermOrder('negwdeglex',(1,2,3))
sage: P.<x,y,z> = PolynomialRing(QQbar, 3, order=t)
sage: f = x + y; f.lm() # indirect doctest
x
sage: f = x + x^2; f.lm()
x
sage: f = x^3 + z; f.lm()
x^3
sage: t = TermOrder('negwdegrevlex',(1,2,3))
sage: P.<x,y,z> = PolynomialRing(QQbar, 3, order=t)
sage: f = x + y; f.lm() # indirect doctest
x
sage: f = x + x^2; f.lm()
x
sage: f = x^3 + z; f.lm()
x^3
greater_tuple_wdeglex(f, g)
Return the greater exponent tuple with respect to the weighted degree lexicographical term order.
INPUT:
• f - exponent tuple
• g - exponent tuple
EXAMPLES:
sage: t = TermOrder('wdeglex',(1,2,3))
sage: P.<x,y,z> = PolynomialRing(QQbar, 3, order=t)
sage: f = x + y; f.lm() # indirect doctest
y
sage: f = x*y + z; f.lm()
x*y
is_global()
Return true if this term order is definitely global. Return false otherwise, which includes unknown term
orders.
EXAMPLES:
sage: T = TermOrder('lex')
sage: T.is_global()
True
sage: T = TermOrder('degrevlex', 3) + TermOrder('degrevlex', 3)
sage: T.is_global()
True
sage: T = TermOrder('degrevlex', 3) + TermOrder('negdegrevlex', 3)
(continues on next page)
is_local()
Return true if this term order is definitely local. Return false otherwise, which includes unknown term
orders.
EXAMPLES:
sage: T = TermOrder('lex')
sage: T.is_local()
False
sage: T = TermOrder('negdeglex', 3) + TermOrder('negdegrevlex', 3)
sage: T.is_local()
True
sage: T = TermOrder('degrevlex', 3) + TermOrder('negdegrevlex', 3)
sage: T.is_local()
False
is_weighted_degree_order()
Return true if self is a weighted degree term order.
EXAMPLES:
sage: t=TermOrder('wdeglex',(2,3))
sage: t.is_weighted_degree_order()
True
macaulay2_str()
Return a Macaulay2 representation of self.
Used to convert polynomial rings to their Macaulay2 representation.
EXAMPLES:
127
˓→ {GRevLex => {3:1} }
˓→ {Lex => 5 }
˓→ {Position => Up }
magma_str()
Return a MAGMA representation of self.
Used to convert polynomial rings to their MAGMA representation.
EXAMPLES:
sage: T = P.term_order()
sage: T.magma_str()
'"grevlex"'
matrix()
Return the matrix defining matrix term order.
EXAMPLES:
sage: t = TermOrder("M(1,2,0,1)")
sage: t.matrix()
[1 2]
[0 1]
name()
EXAMPLES:
sage: TermOrder('lex').name()
'lex'
singular_moreblocks()
Return a the number of additional blocks SINGULAR needs to allocate for handling non-native orderings
like 𝑑𝑒𝑔𝑛𝑒𝑔𝑙𝑒𝑥.
EXAMPLES:
sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),deglex(5),lex(2)')
sage: T = P.term_order()
sage: T.singular_moreblocks()
0
sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),degneglex(5),
˓→lex(2)')
sage: T = P.term_order()
sage: T.singular_moreblocks()
1
sage: P = PolynomialRing(GF(127),10,names='x',order='degneglex(5),degneglex(5)
˓→')
sage: T = P.term_order()
sage: T.singular_moreblocks()
2
singular_str()
Return a SINGULAR representation of self.
Used to convert polynomial rings to their SINGULAR representation.
EXAMPLES:
sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),deglex(5),lex(2)')
sage: T = P.term_order()
sage: T.singular_str()
(continues on next page)
sortkey
The default sortkey method for this term order.
EXAMPLES:
sage: O = TermOrder()
sage: O.sortkey.__func__ is O.sortkey_lex.__func__
True
sage: O = TermOrder('deglex')
sage: O.sortkey.__func__ is O.sortkey_deglex.__func__
True
sortkey_block(f )
Return the sortkey of an exponent tuple with respect to the block order as specified when constructing this
element.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_deglex(f )
Return the sortkey of an exponent tuple with respect to the degree lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_degneglex(f )
Return the sortkey of an exponent tuple with respect to the degree negative lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_degrevlex(f )
Return the sortkey of an exponent tuple with respect to the degree reversed lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_invlex(f )
Return the sortkey of an exponent tuple with respect to the inversed lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_lex(f )
Return the sortkey of an exponent tuple with respect to the lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_matrix(f )
Return the sortkey of an exponent tuple with respect to the matrix term order.
INPUT:
• f - exponent tuple
EXAMPLES:
sortkey_negdeglex(f )
Return the sortkey of an exponent tuple with respect to the negative degree lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_negdegrevlex(f )
Return the sortkey of an exponent tuple with respect to the negative degree reverse lexicographical term
order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_neglex(f )
Return the sortkey of an exponent tuple with respect to the negative lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sortkey_negwdeglex(f )
Return the sortkey of an exponent tuple with respect to the negative weighted degree lexicographical term
order.
INPUT:
• f – exponent tuple
EXAMPLES:
sage: t = TermOrder('negwdeglex',(3,2))
sage: P.<x,y> = PolynomialRing(QQbar, 2, order=t)
sage: x > y^2 # indirect doctest
True
sage: x^2 > y^3
True
sortkey_negwdegrevlex(f )
Return the sortkey of an exponent tuple with respect to the negative weighted degree reverse lexicograph-
ical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sage: t = TermOrder('negwdegrevlex',(3,2))
sage: P.<x,y> = PolynomialRing(QQbar, 2, order=t)
sage: x > y^2 # indirect doctest
True
sage: x^2 > y^3
True
sortkey_wdeglex(f )
Return the sortkey of an exponent tuple with respect to the weighted degree lexicographical term order.
INPUT:
• f – exponent tuple
EXAMPLES:
sage: t = TermOrder('wdeglex',(3,2))
sage: P.<x,y> = PolynomialRing(QQbar, 2, order=t)
sage: x > y^2 # indirect doctest
False
sage: x > y
True
sortkey_wdegrevlex(f )
Return the sortkey of an exponent tuple with respect to the weighted degree reverse lexicographical term
order.
INPUT:
• f – exponent tuple
EXAMPLES:
sage: t = TermOrder('wdegrevlex',(3,2))
sage: P.<x,y> = PolynomialRing(QQbar, 2, order=t)
sage: x > y^2 # indirect doctest
False
sage: x^2 > y^3
True
tuple_weight(f )
Return the weight of tuple f.
INPUT:
• f - exponent tuple
EXAMPLES:
sage: t=TermOrder('wdeglex',(1,2,3))
sage: P.<a,b,c>=PolynomialRing(QQbar, order=t)
sage: P.term_order().tuple_weight([3,2,1])
10
weights()
Return the weights for weighted term orders.
EXAMPLES:
sage: t=TermOrder('wdeglex',(2,3))
sage: t.weights()
(2, 3)
sage.rings.polynomial.term_order.termorder_from_singular(S)
Return the Sage term order of the basering in the given Singular interface
INPUT:
An instance of the Singular interface.
NOTE:
A term order in Singular also involves information on orders for modules. This is not taken into account in Sage.
EXAMPLES:
AUTHOR:
• Simon King (2011-06-06)
class sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base
Bases: sage.rings.ring.CommutativeRing
Create a polynomial ring in several variables over a commutative ring.
EXAMPLES:
characteristic()
Return the characteristic of this polynomial ring.
EXAMPLES:
completion(names, prec=20)
Return the completion of self with respect to the ideal generated by the variable(s) names.
INPUT:
• names – variable or list/tuple of variables (given either as elements of the polynomial ring or as
strings)
• prec – default precision of resulting power series ring
• extras – deprecated and ignored
EXAMPLES:
sage: P.completion((w,x,y))
Multivariate Power Series Ring in w, x, y over Univariate Polynomial Ring in
˓→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
construction()
Returns a functor F and base ring R such that F(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
flattening_morphism()
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
sage: QQ['x,y'].flattening_morphism()
Identity endomorphism of Multivariate Polynomial Ring in x, y over Rational
˓→Field
gen(n=0)
irrelevant_ideal()
Return the irrelevant ideal of this multivariate polynomial ring.
This is the ideal generated by all of the indeterminate generators of this ring.
EXAMPLES:
is_field(proof=True)
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:
is_finite()
Test whether this multivariate polynomial ring is finite.
Todo: This should be handled by categories but sage.rings.Ring does implement a is_finite
method that overrides that category implementation.
EXAMPLES:
is_integral_domain(proof=True)
EXAMPLES:
sage: ZZ['x,y'].is_integral_domain()
True
sage: Integers(8)['x,y'].is_integral_domain()
False
is_noetherian()
EXAMPLES:
sage: ZZ['x,y'].is_noetherian()
True
sage: Integers(8)['x,y'].is_noetherian()
True
krull_dimension()
macaulay_resultant(*args, **kwds)
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 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 – a list of 𝑛 homogeneous polynomials in 𝑛 variables. works when args[0] is the list of
polynomials, or args is itself the list of polynomials
kwds:
• sparse – boolean (optional - default: False) if True 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 implementa-
tion 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])
Traceback (most recent call last):
...
TypeError: number of polynomials(= 2) must equal number of variables (= 3)
sage: F = FiniteField(11)
sage: R.<x,y,z,w> = PolynomialRing(F,4)
sage: R.macaulay_resultant([z,x^3,5*y,w])
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):
when there are only 2 polynomials, macaulay resultant degenerates to the traditional resultant:
monomial(*exponents)
Return the monomial with given exponents.
EXAMPLES:
ngens()
random_element(degree=2, terms=None, choose_degree=False, *args, **kwargs)
Return a random polynomial of at most degree 𝑑 and at most 𝑡 terms.
First monomials are chosen uniformly random from the set of all possible monomials of degree up to 𝑑
(inclusive). This means that it is more likely that a monomial of degree 𝑑 appears than a monomial of
degree 𝑑 − 1 because the former class is bigger.
Exactly 𝑡 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:
Stacked rings:
sage: R = QQ['x,y']
sage: S = R['t,u']
sage: S.random_element(degree=2, terms=1)
-1/2*x^2 - 1/4*x*y - 3*y^2 + 4*y
sage: S.random_element(degree=2, terms=1)
(-x^2 - 2*y^2 - 1/3*x + 2*y + 9)*u^2
sage: P.random_element(0, 1)
1
sage: P.random_element(2, 0)
0
The number of terms is silently reduced to the maximum available if more terms are requested:
sage: P.<x,y,z> = GF(127)[]
sage: P.random_element(degree=2, terms=1000)
5*x^2 - 10*x*y + 10*y^2 - 44*x*z + 31*y*z + 19*z^2 - 42*x - 50*y - 49*z - 60
remove_var(order=None, *var)
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)
(continues on next page)
sage: P.remove_var(y,z,x,w)
Integer Ring
repr_long()
Return structured string representation of self.
EXAMPLES:
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
term_order()
univariate_ring(x)
Return a univariate polynomial ring whose base ring comprises all but one variables of self.
INPUT:
• x – a variable of self.
EXAMPLES:
variable_names_recursive(depth=None)
Returns 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')
weyl_algebra()
Return the Weyl algebra generated from self.
EXAMPLES:
sage: R = QQ['x,y,z']
sage: W = R.weyl_algebra(); W
Differential Weyl algebra of polynomials in x, y, z over Rational Field
sage: W.polynomial_ring() == R
True
sage.rings.polynomial.multi_polynomial_ring_base.is_MPolynomialRing(x)
sage.rings.polynomial.multi_polynomial_ring_base.unpickle_MPolynomialRing_generic(base_ring,
n,
names,
or-
der)
sage.rings.polynomial.multi_polynomial_ring_base.unpickle_MPolynomialRing_generic_v1(base_rin
n,
names,
or-
der)
class sage.rings.polynomial.multi_polynomial.MPolynomial
Bases: sage.structure.element.CommutativeRingElement
args()
Returns the named of the arguments of self, in the order they are accepted from call.
EXAMPLES:
sage: R.<x,y> = ZZ[]
sage: x.args()
(x, y)
change_ring(R)
Return a copy of this polynomial but with coefficients in R, if at all possible.
INPUT:
• R – a ring or morphism.
EXAMPLES:
coefficients()
Return the nonzero coefficients of this polynomial in a list. The returned list is decreasingly or-
dered by the term ordering of self.parent(), i.e. the list of coefficients matches the list
of monomials returned by sage.rings.polynomial.multi_polynomial_libsingular.
MPolynomial_libsingular.monomials().
EXAMPLES:
AUTHOR:
• Didier Deshommes
content()
Returns the content of this polynomial. Here, we define content as the gcd of the coefficients in the base
ring.
See also:
content_ideal()
EXAMPLES:
content_ideal()
Return the content ideal of this polynomial, defined as the ideal generated by its coefficients.
See also:
content()
EXAMPLES:
denominator()
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 of self 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 since self is a polynomial.
EXAMPLES:
First we compute the denominator of a polynomial with integer coefficients, which is of course 1.
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.
Check that the denominator is an element over the base whenever the base has no denominator function.
This closes trac ticket #9063:
sage: R.<a,b,c> = GF(5)[]
sage: x = R(0)
sage: x.denominator()
1
sage: type(x.denominator())
<type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'>
sage: type(a.denominator())
<type '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
derivative(*args)
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 derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
Polynomials implemented via Singular:
sage: R.<x, y> = PolynomialRing(FiniteField(5))
sage: f = x^3*y^5 + x^7*y
sage: type(f)
<type '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
discriminant(variable)
Returns 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)
1
sage: f.discriminant(y)
-383/16*x^2*z^2 + 8*x*z^2
sage: f.discriminant(z)
-383/16*x^2*y^2 + 8*x*y^2
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)
x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1
sage: f.polynomial(y).discriminant()
x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1
sage: f.discriminant(y).parent()==f.polynomial(y).discriminant().parent()
False
gcd(other)
Return a greatest common divisor of this polynomial and other.
INPUT:
Polynomials over polynomial rings are converted to a simpler polynomial ring with all variables to compute
the gcd:
gradient()
Return a list of partial derivatives of this polynomial, ordered by the variables of self.parent().
EXAMPLES:
homogenize(var=’h’)
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 variable var.
EXAMPLES:
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
However, if the polynomial is homogeneous already, then that parameter is ignored and no extra variable
is added to the polynomial ring:
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:
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
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
sage: g = f.homogenize(x); g
x^2 - x*y
sage: g(1,y,z)
-y + 1
inverse_mod(I)
Returns an inverse of self modulo the polynomial ideal 𝐼, namely a multivariate polynomial 𝑓 such that
self * f - 1 belongs to 𝐼.
INPUT:
• I – an ideal of the polynomial ring in which self lives
OUTPUT:
• a multivariate polynomial representing the inverse of f modulo I
EXAMPLES:
is_generator()
Returns True if this polynomial is a generator of its parent.
EXAMPLES:
sage: R.<x,y>=ZZ[]
sage: x.is_generator()
True
sage: (x+y-y).is_generator()
True
sage: (x*y).is_generator()
False
sage: R.<x,y>=QQ[]
sage: x.is_generator()
True
sage: (x+y-y).is_generator()
True
sage: (x*y).is_generator()
False
is_homogeneous()
Return True if self is a homogeneous polynomial.
is_nilpotent()
Return True if self is nilpotent, i.e., some power of self is 0.
EXAMPLES:
is_square(root=False)
Test whether this polynomial is a square root.
INPUT:
• root - if set to True return a pair (True, root) where root is a square root or (False,
None) if it is not a square.
EXAMPLES:
is_unit()
Return True if self is a unit, that is, has a multiplicative inverse.
EXAMPLES:
jacobian_ideal()
Return the Jacobian ideal of the polynomial self.
EXAMPLES:
lift(I)
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.
EXAMPLES:
macaulay_resultant(*args)
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 – a list of 𝑛 − 1 homogeneous polynomials in 𝑛 variables. works when args[0] is the list
of polynomials, or args is itself the list of polynomials
OUTPUT:
• the macaulay resultant
EXAMPLES:
The number of polynomials has to match the number of variables:
The following example recreates Proposition 2.10 in Ch.3 of Using Algebraic Geometry:
sage: F = FiniteField(11)
sage: R.<x,y,z,w> = PolynomialRing(F,4)
sage: z.macaulay_resultant([x^3,5*y,w])
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):
when there are only 2 polynomials, macaulay resultant degenerates to the traditional resultant:
map_coefficients(f, new_base_ring=None)
Returns the polynomial obtained by applying f to the non-zero coefficients of self.
If f is a sage.categories.map.Map, then the resulting polynomial will be defined over the
codomain of f. Otherwise, the resulting polynomial will be over the same ring as self. Set
new_base_ring to override this behaviour.
INPUT:
• f – a callable that will be applied to the coefficients of self.
• new_base_ring (optional) – if given, the resulting polynomial will be defined over this ring.
EXAMPLES:
newton_polytope()
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()
sage: P
A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices
sage: P.is_simple()
True
nth_root(n)
Return a 𝑛-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
numerator()
Return a numerator of self computed as self * 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 be
self since self is a polynomial.
EXAMPLES:
First we compute the numerator of a polynomial with integer coefficients, which is of course self.
We try to compute the numerator of a polynomial with coefficients in the finite field of 3 elements.
We check that the computation the numerator and denominator are valid
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
polynomial(var)
Let var be one of the variables of the parent of self. This returns self viewed as a univariate polynomial in
var over the polynomial ring generated by all the other variables of the parent.
EXAMPLES:
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
reduced_form(**kwds)
Returns 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 homogenous polynomial and finds a reduced form. This is a 𝑆𝐿(2, Z)-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 of 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 𝑧0 covariant
from the 𝑄0 form as defined on page 7 of [CS2003]. Additionally, if this polynomial has a root with
multiplicity at lease half the total degree of the polynomial, then we must also use the 𝑧0 covariant. See
[CS2003] for details.
Note that, if the covariant is within error_limit of the boundry 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 your error_limit and increase your precision.
Implemented by Rebecca Lauren Miller as part of GSOC 2016. Smallest coefficients added by Ben Hutz
July 2018.
INPUT:
keywords:
• prec – integer, sets the precision (default:300)
• return_conjugation – boolean. Returns element of 𝑆𝐿(2, Z) (default:True)
• error_limit – sets the error tolerance (default:0.000001)
• smallest_coeffs – (default: True), boolean, whether to find the model with smallest coefficients
• norm_type – either 'norm' or 'height'. What type of norm to use for smallest coefficients
• emb – (optional) embedding of based field into CC
OUTPUT:
• a polynomial (reduced binary form)
• a matrix (element of 𝑆𝐿(2, Z))
TODO: When Newton’s Method doesn’t converge to a root in the upper half plane. Now we just re-
turn z0. It would be better to modify and find the unique root in the upper half plane.
EXAMPLES:
[ 1 -2]
[ 1 -1]
)
sage: F.reduced_form(return_conjugation=False)
x^4 + 9*x^3*y - 3*x*y^3 - 8*y^4
+ 6.90016027113216e8*y^3
sage: F.reduced_form(smallest_coeffs=False)
(
-39.5673942565918*x^3 + 111.874026298523*x^2*y + 231.052762985229*x*y^2 - 138.
˓→380829811096*y^3,
[-147 -148]
[ 1 1]
)
sage: F.reduced_form(smallest_coeffs=False)
(
(-0.759099196558145 - 0.845425869641446*I)*x^3 + (-0.571709908900118 - 0.
˓→0418133346027929*I)*x^2*y
[-1 37]
[ 0 -1]
)
specialization(D=None, phi=None)
Specialization of this polynomial.
Given a family of polynomials defined over a polynomial ring. A specialization is a partic-
ular 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:
sylvester_matrix(right, variable=None)
Given two nonzero polynomials self and right, returns 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 polynomials
• variable: optional, compute the Sylvester matrix with respect to this variable. If variable is not pro-
vided, the first variable of the polynomial ring is used.
OUTPUT:
• The Sylvester matrix of self and right.
EXAMPLES:
If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will
be zero:
sage: M.determinant()
0
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)
sage: g = R.random_element(4)
sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x)
True
truncate(var, n)
Returns a new multivariate polynomial obtained from self by deleting all terms that involve the given
variable to a power at least n.
weighted_degree(*weights)
Return the weighted degree of self, which is the maximum weighted degree of all monomials in self;
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 in weights.
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 of self 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 by
self.parent().gens():
EXAMPLES:
sage: p.weighted_degree(x,1,1)
Traceback (most recent call last):
...
TypeError: unable to convert non-constant polynomial x to an integer
sage: p.weighted_degree(2/1,1,1)
6
The weighted_degree coincides with the degree of a weighted polynomial ring, but the later is
faster.
sage.rings.polynomial.multi_polynomial.is_MPolynomial(x)
Sage implements multivariate polynomial rings through several backends. This generic implementation uses the
classes PolyDict and ETuple to construct a dictionary with exponent tuples as keys and coefficients as values.
AUTHORS:
• David Joyner and William Stein
• Kiran S. Kedlaya (2006-02-12): added Macaulay2 analogues of Singular features
• Martin Albrecht (2006-04-21): reorganize class hierarchy for singular rep
• Martin Albrecht (2007-04-20): reorganized class hierarchy to support Pyrex implementations
• Robert Bradshaw (2007-08-15): Coercions from rings in a subset of the variables.
EXAMPLES:
We construct the Frobenius morphism on F5 [𝑥, 𝑦, 𝑧] over F5 :
sage: R.<x,y,z> = GF(5)[]
sage: frob = R.hom([x^5, y^5, z^5])
sage: frob(x^2 + 2*y - z^4)
-z^20 + x^10 + 2*y^5
sage: frob((x + 2*y)^3)
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15
sage: (x^5 + 2*y^5)^3
x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15
We make a polynomial ring in one variable over a polynomial ring in two variables:
sage: R.<x, y> = PolynomialRing(QQ, 2)
sage: S.<t> = PowerSeriesRing(R)
sage: t*(x+y)
(x + y)*t
class sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_macaulay2_repr
is_exact()
class sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict(base_ring,
n,
names,
or-
der)
Bases: sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_macaulay2_repr,
sage.rings.polynomial.polynomial_singular_interface.PolynomialRing_singular_repr,
sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base
Multivariable polynomial ring.
EXAMPLES:
monomial_all_divisors(t)
Return a list of all monomials that divide t, coefficients are ignored.
INPUT:
• t - a monomial.
OUTPUT: a list of monomials.
EXAMPLES:
monomial_lcm(f, g)
LCM for monomials. Coefficients are ignored.
INPUT:
• f - monomial.
• g - monomial.
OUTPUT: monomial.
EXAMPLES:
monomial_pairwise_prime(h, g)
Return True if h and g are pairwise prime.
Both are treated as monomials.
INPUT:
• h - monomial.
• g - monomial.
OUTPUT: Boolean.
EXAMPLES:
sage: P.monomial_pairwise_prime(P(1/2),x)
False
monomial_quotient(f, g, coeff=False)
Return f/g, where both f and g are treated as monomials.
Coefficients are ignored by default.
INPUT:
• f - monomial.
• g - monomial.
• coeff - divide coefficients as well (default: False).
OUTPUT: monomial.
EXAMPLES:
Note: Assumes that the head term of f is a multiple of the head term of g and return the multiplicant m.
If this rule is violated, funny things may happen.
monomial_reduce(f, G)
Try to find a g in G where g.lm() divides f.
If found, (flt,g) is returned, (0,0) otherwise, where flt is f/g.lm(). It is assumed that G is
iterable and contains ONLY elements in this ring.
INPUT:
• f - monomial
• G - list/set of mpolynomials
EXAMPLES:
sage: f = x*y^2
sage: G = [3*x^3 + y^2 + 2, 4*x*y + 7, P(2)]
(continues on next page)
sage: P.monomial_reduce(P(0),G)
(0, 0)
sage: P.monomial_reduce(f,[P(0)])
(0, 0)
class sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain(base_ring,
n,
names,
or-
der)
Bases: sage.rings.ring.IntegralDomain, sage.rings.polynomial.
multi_polynomial_ring.MPolynomialRing_polydict
ideal(*gens, **kwds)
Create an ideal in this polynomial ring.
is_field(proof=True)
is_integral_domain(proof=True)
AUTHORS:
• David Joyner: first version
• William Stein: use dict’s instead of lists
• Martin Albrecht [email protected]: 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 𝑥𝑦 3 ; added examples of the new R.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:
True
class sage.rings.polynomial.multi_polynomial_element.MPolynomial_element(parent,
x)
Bases: sage.rings.polynomial.multi_polynomial.MPolynomial
EXAMPLES:
change_ring(R)
Change the base ring of this polynomial to R.
INPUT:
• R – ring or morphism.
OUTPUT: a new polynomial converted to R.
EXAMPLES:
element()
hamming_weight()
Return the number of non-zero coefficients of this polynomial.
This is also called weight, hamming_weight() or sparsity.
EXAMPLES:
sage: f.hamming_weight()
101
number_of_terms()
Return the number of non-zero coefficients of this polynomial.
sage: f.hamming_weight()
101
class sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict(parent,
x)
Bases: sage.rings.polynomial.polynomial_singular_interface.
Polynomial_singular_repr, sage.rings.polynomial.multi_polynomial_element.
MPolynomial_element
Multivariate polynomials implemented in pure python using polydicts.
coefficient(degrees)
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
in degrees. 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:
AUTHORS:
• Joel B. Mohler (2007-10-31)
constant_coefficient()
Return the constant coefficient of this multivariate polynomial.
EXAMPLES:
degree(x=None, std_grading=False)
Return the degree of self in x, where x must be one of the generators for the parent of self.
INPUT:
• x - multivariate polynomial (a generator of the parent of self). If x 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 argument std_grading=True.
OUTPUT: integer
EXAMPLES:
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
Note that if x is not a generator of the parent of self, 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 trac ticket #17366.)
sage: x, y = ZZ['x','y'].gens()
sage: GF(3037000453)['x','y'].gen(0).degree(x)
1
sage: GF(3037000453)['x','y'].gen(0).degree(x^2)
Traceback (most recent call last):
...
TypeError: x must be one of the generators of the parent
degrees()
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: 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)
dict()
Return underlying dictionary with keys the exponents and values the coefficients of this polynomial.
exponents(as_ETuples=True)
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:
Return the list of exponents as a list of ETuples or tuples.
EXAMPLES:
sage: type(f.exponents()[0])
<type 'sage.rings.polynomial.polydict.ETuple'>
sage: type(f.exponents(as_ETuples=False)[0])
<... 'tuple'>
factor(proof=None)
Compute the irreducible factorization of this polynomial.
INPUT:
• proof'' - insist on provably correct results (default: ``True unless
explicitly disabled for the "polynomial" subsystem with sage.structure.proof.proof.
WithProof.)
integral(var=None)
Integrates self with respect to variable var.
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:
inverse_of_unit()
is_constant()
True if polynomial is constant, and False otherwise.
EXAMPLES:
is_generator()
Returns True if self is a generator of it’s parent.
EXAMPLES:
sage: R.<x,y>=QQbar[]
sage: x.is_generator()
True
sage: (x+y-y).is_generator()
True
sage: (x*y).is_generator()
False
is_homogeneous()
Return True if self is a homogeneous polynomial.
EXAMPLES:
is_monomial()
Returns True if self 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: 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
sage: (2*x*y).is_term()
True
sage: (2*x*y).is_monomial()
False
is_term()
Returns True if self 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: 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
sage: (2*x*y).is_monomial()
False
sage: (2*x*y).is_term()
True
is_univariate()
Returns True if this multivariate polynomial is univariate and False otherwise.
EXAMPLES:
lc()
Returns the leading coefficient of self i.e., self.coefficient(self.lm())
EXAMPLES:
sage: R.<x,y,z>=QQbar[]
sage: f=3*x^2-y^2-x*y
sage: f.lc()
3
lift(I)
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:
lm()
Returns the lead monomial of self with respect to the term order of self.parent().
EXAMPLES:
sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: (x^1*y^2 + y^3*z^4).lm()
(continues on next page)
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
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
lt()
Returns 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: 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
monomial_coefficient(mon)
Return the coefficient in the base ring of the monomial mon in self, where mon must have the same parent
as self.
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:
The parent of the return is a member of the base ring.
sage: R.<x,y>=QQbar[]
sage: f = 2 * x * y
sage: c = f.monomial_coefficient(x*y); c
(continues on next page)
sage: var('a')
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
monomials()
Returns the list of monomials in self. The returned list is decreasingly ordered by the term ordering of
self.parent().
OUTPUT: list of MPolynomials representing Monomials
EXAMPLES:
nvariables()
Number of variables in this polynomial
EXAMPLES:
quo_rem(right)
Returns quotient and remainder of self and right.
EXAMPLES:
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)
((2*b + 1)*y, (2*b + 1)*y + (-a^2 + 3)*z + a)
sage: f = 3*x
sage: f.reduce([2*x,y])
0
Make sure the remainder returns the correct type, fixing trac ticket #13903:
resultant(other, variable=None)
Compute the resultant of self and other with respect to variable.
If a second argument is not provided, the first variable of self.parent() is chosen.
INPUT:
• other – polynomial in self.parent()
• variable – (optional) variable (of type polynomial) in self.parent()
EXAMPLES:
subs(fixed=None, **kw)
Fixes some given variables in a given multivariate polynomial and returns the changed multivariate poly-
nomials. 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
• **kw - named parameters
OUTPUT: new MPolynomial
EXAMPLES:
total_degree()
Return the total degree of self, which is the maximum degree of any monomial in self.
EXAMPLES:
univariate_polynomial(R=None)
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 us-
ing the is_univariate() method. The new Polynomial is over the same base ring as the given MPolynomial.
EXAMPLES:
variable(i)
Returns 𝑖-th variable occurring in this polynomial.
EXAMPLES:
variables()
Returns the tuple of variables occurring in this polynomial.
EXAMPLES:
sage.rings.polynomial.multi_polynomial_element.degree_lowest_rational_function(r,
x)
INPUT:
• r - a multivariate rational function
• x - a multivariate polynomial ring generator x
OUTPUT:
• integer - the degree of r in x and its “leading” (in the x-adic sense) coefficient.
Note: This function is dependent on the ordering of a python dict. Thus, it isn’t really mathematically well-
defined. I think that it should made a method of the FractionFieldElement class and rewritten.
EXAMPLES:
4+3𝑏𝑐2
Consider the quotient 𝑓 /𝑔 = 𝑎𝑐+2𝑎𝑏3 𝑐6 (note the cancellation).
sage: r = f/g; r
(-b*c^2 + 2)/(a*b^3*c^6 - 2*a*c)
sage: degree_lowest_rational_function(r,a)
(-1, 3)
sage: degree_lowest_rational_function(r,b)
(0, 4)
sage: degree_lowest_rational_function(r,c)
(-1, 4)
sage.rings.polynomial.multi_polynomial_element.is_MPolynomial(x)
Sage has a powerful system to compute with multivariate polynomial rings. Most algorithms dealing with these
ideals are centered on the computation of Groebner bases. Sage mainly uses Singular to implement this functionality.
Singular is widely regarded as the best open-source system for Groebner basis calculation in multivariate polynomial
rings over fields.
AUTHORS:
• William Stein
• Kiran S. Kedlaya (2006-02-12): added Macaulay2 analogues of some Singular features
• Martin Albrecht (2008,2007): refactoring, many Singular related functions
• Martin Albrecht (2009): added Groebner basis over rings functionality from Singular 3.1
• John Perry (2012): bug fixing equality & containment of ideals
EXAMPLES:
We compute a Groebner basis for some given ideal. The type returned by the groebner_basis method is
PolynomialSequence, i.e. it is not a MPolynomialIdeal:
sage: f,g,h = B
sage: (2*x*f + g).reduce(B)
0
sage: (2*x*f + g) in I
True
We compute a Groebner basis for Cyclic 6, which is a standard benchmark and test ideal.
sage: (a+b)^17
256*a*b^16 + 256*b^17
sage: S(17) == 0
True
sage: i.groebner_basis()
[y^3 + (2*zeta + 1)*y^2 + (zeta - 1)*y + (-1/3*zeta - 2/3), x + (-zeta)*y + 1]
sage: S = R.quotient(i); S
Quotient of Multivariate Polynomial Ring in x, y, z over
Cyclotomic Field of order 3 and degree 2 by the ideal (x +
(-zeta)*y + 1, x^3 + (-zeta)*y^3)
The next example shows how we can use Groebner bases over Z to find the primes modulo which a system of equations
has a solution, when the system has no solutions over the rationals.
We first form a certain ideal 𝐼 in Z[𝑥, 𝑦, 𝑧], and note that the Groebner basis of 𝐼 over Q contains 1, so
there are no solutions over Q or an algebraic closure of it (this is not surprising as there are 4 equations
in 3 unknowns).
However, when we compute the Groebner basis of I (defined over Z), we note that there is a certain integer
in the ideal which is not 1.
sage: I.groebner_basis()
[x + 130433*y + 59079*z, y^2 + 3*y + 17220, y*z + 5*y + 14504, 2*y + 158864,
˓→z^2 + 17223, 2*z + 41856, 164878]
Now for each prime 𝑝 dividing this integer 164878, the Groebner basis of I modulo 𝑝 will be non-trivial
and will thus give a solution of the original system modulo 𝑝.
sage: factor(164878)
2 * 7 * 11777
The Groebner basis modulo any product of the prime factors is also non-trivial:
Modulo any other prime the Groebner basis is trivial so there are no other solutions. For example:
Note: Sage distinguishes between lists or sequences of polynomials and ideals. Thus an ideal is not identified
with a particular set of generators. For sequences of multivariate polynomials see sage.rings.polynomial.
multi_polynomial_sequence.PolynomialSequence_generic.
class sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal(ring,
gens, co-
erce=True)
Bases: sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr,
sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_macaulay2_repr,
sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_magma_repr,
sage.rings.ideal.Ideal_generic
Create an ideal in a multivariate polynomial ring.
INPUT:
• ring - the ring the ideal is defined in
• gens - a list of generators for the ideal
• coerce - coerce elements to the ring ring?
EXAMPLES:
basis
Shortcut to gens().
EXAMPLES:
change_ring(P)
Return the ideal I in P spanned by the generators 𝑔1 , ..., 𝑔𝑛 of self as returned by self.gens().
INPUT:
• P - a multivariate polynomial ring
EXAMPLES:
sage: I.groebner_basis()
[x + y + z, y^2 + y*z + z^2, z^3 - 1]
sage: J = I.change_ring(Q); J
Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) of
Multivariate Polynomial Ring in x, y, z over Rational Field
sage: J.groebner_basis()
[z^3 - 1, y^2 + y*z + z^2, x + y + z]
degree_of_semi_regularity()
Return the degree of semi-regularity of this ideal under the assumption that it is semi-regular.
Let {𝑓1 , ..., 𝑓𝑚 } ⊂ 𝐾[𝑥1 , ..., 𝑥𝑛 ] be homogeneous polynomials of degrees 𝑑1 , ..., 𝑑𝑚 respectively. This
sequence is semi-regular if:
• {𝑓1 , ..., 𝑓𝑚 } =
̸ 𝐾[𝑥1 , ..., 𝑥𝑛 ]
• for all 1 ≤ 𝑖 ≤ 𝑚 and 𝑔 ∈ 𝐾[𝑥1 , . . . , 𝑥𝑛 ]: 𝑑𝑒𝑔(𝑔 · 𝑝𝑖) < 𝐷 and 𝑔 · 𝑓𝑖 ∈< 𝑓1 , . . . , 𝑓𝑖−1 > implies that
𝑔 ∈< 𝑓1 , ..., 𝑓𝑖−1 > where 𝐷 is the degree of regularity.
This notion can be extended to affine polynomials by considering their homogeneous components of high-
est degree.
The degree of regularity of a semi-regular sequence 𝑓1 , ..., 𝑓𝑚 of respective degrees 𝑑1 , ..., 𝑑𝑚 is given by
the index of the first non-positive coefficient of:
(1−𝑧 𝑑𝑖 )
∏︀
𝑐𝑘 𝑧 𝑘 = (1−𝑧)
∑︀
𝑛
EXAMPLES:
We consider a homogeneous example:
sage: n = 8
sage: K = GF(127)
sage: P = PolynomialRing(K,n,'x')
sage: s = [K.random_element() for _ in range(n)]
sage: L = []
sage: for i in range(2*n):
....: f = P.random_element(degree=2, terms=binomial(n,2))
....: f -= f(*s)
....: L.append(f.homogenize())
sage: I = Ideal(L)
sage: I.degree_of_semi_regularity()
4
From this, we expect a Groebner basis computation to reach at most degree 4. For homogeneous systems
this is equivalent to the largest degree in the Groebner basis:
We increase the number of polynomials and observe a decrease the degree of regularity:
The degree of regularity approaches 2 for quadratic systems as the number of polynomials approaches 𝑛2 :
Note: It is unknown whether semi-regular sequences exist. However, it is expected that random systems
are semi-regular sequences. For more details about semi-regular sequences see [BFS04].
REFERENCES:
gens()
Return a set of generators / a basis of this ideal. This is usually the set of generators provided during object
creation.
EXAMPLES:
• mult_bound - the computation is stopped if the ideal is zero-dimensional in a ring with local order-
ing and its multiplicity is lower than mult_bound. Singular only. (default: None)
• prot - if set to True the computation protocol of the underlying implementation is printed. If an
algorithm from the singular: or magma: family is used, prot may also be sage in which case
the output is parsed and printed in a common format where the amount of information printed can be
controlled via calls to set_verbose().
• *args - additional parameters passed to the respective implementations
• **kwds - additional keyword parameters passed to the respective implementations
ALGORITHMS:
‘’ autoselect (default)
‘singular:groebner’ Singular’s groebner command
‘singular:std’ Singular’s std command
‘singular:stdhilb’ Singular’s stdhib command
‘singular:stdfglm’ Singular’s stdfglm command
‘singular:slimgb’ Singular’s slimgb command
‘libsingular:groebner’ libSingular’s groebner command
‘libsingular:std’ libSingular’s std command
‘libsingular:slimgb’ libSingular’s slimgb command
‘libsingular:stdhilb’ libSingular’s stdhib command
‘libsingular:stdfglm’ libSingular’s stdfglm command
‘toy:buchberger’ Sage’s toy/educational buchberger without Buchberger criteria
‘toy:buchberger2’ Sage’s toy/educational buchberger with Buchberger criteria
‘toy:d_basis’ Sage’s toy/educational algorithm for computation over PIDs
‘macaulay2:gb’ Macaulay2’s gb command (if available)
‘magma:GroebnerBasis’ Magma’s Groebnerbasis command (if available)
‘ginv:TQ’, ‘ginv:TQBlockHigh’, ‘ginv:TQBlockLow’ and ‘ginv:TQDegree’ One of GINV’s imple-
mentations (if available)
‘giac:gbasis’ Giac’s gbasis command (if available)
If only a system is given - e.g. ‘magma’ - the default algorithm is chosen for that system.
Note: The Singular and libSingular versions of the respective algorithms are identical, but the former
calls an external Singular process while the later calls a C function, i.e. the calling overhead is smaller.
However, the libSingular interface does not support pretty printing of computation protocols.
EXAMPLES:
Consider Katsura-3 over Q with lexicographical term ordering. We compute the reduced Groebner basis
using every available implementation and check their equality.
Giac’s gbasis over Q can benefit from a probabilistic lifting and multi threaded operations:
Note that toy:buchberger does not return the reduced Groebner basis,
Singular and libSingular can compute Groebner basis with degree restrictions.:
A protocol is printed, if the verbosity level is at least 2, or if the argument prot is provided. Historically,
the protocol did not appear during doctests, so, we skip the examples with protocol output.
sage: set_verbose(2)
sage: I = R*[x^3+y^2,x^2*y+1]
sage: I.groebner_basis() # not tested
std in (QQ),(x,y),(dp(2),C)
[...:2]3ss4s6
(S:2)--
product criterion:1 chain criterion:0
[x^3 + y^2, x^2*y + 1, y^3 - x]
sage: I.groebner_basis(prot=False)
std in (QQ),(x,y),(dp(2),C)
[...:2]3ss4s6
(S:2)--
(continues on next page)
We can represent every element in the ideal as a combination of the generators using the lift() method:
sage: f.lift(I.gens())
[2*x + 95*z, 1/2*y^2 - 1/4*y*z, 0]
sage: l = f.lift(J.gens()); l
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1/2*y^2 + 1/4*y*z, 1/2*y^2*z^2 - 1/
˓→4*y*z^3 + 2*x + 95*z]
Groebner bases over fraction fields of polynomial rings are also supported:
sage: I.groebner_basis()
[Z^3 + (-79/105*t - 79/70)*Z^2 + (2/15*t^2 - 74/315*t + 94/105)*Y + (2/35*t^2
˓→+ 194/315*t + 1/105)*Z - 4/105*t^2 - 17/210*t - 1/28, Y^2 + (-3/5)*Z^2 + (-
In cases where a characteristic cannot be determined, we use a toy implementation of Buchberger’s algo-
rithm (see trac ticket #6581):
[x + y]
ALGORITHM:
Uses Singular, Magma (if available), Macaulay2 (if available), Giac (if available), or a toy implementation.
groebner_fan(is_groebner_basis=False, symmetry=None, verbose=False)
Return the Groebner fan of this ideal.
The base ring must be Q or a finite field F𝑝 of with 𝑝 ≤ 32749.
EXAMPLES:
INPUT:
• is_groebner_basis - bool (default False). if True, then I.gens() must be a Groebner basis with
respect to the standard degree lexicographic term order.
• symmetry - default: None; if not None, describes symmetries of the ideal
• verbose - default: False; if True, printout useful info during computations
homogenize(var=’h’)
Return homogeneous ideal spanned by the homogeneous polynomials generated by homogenizing the
generators of this ideal.
INPUT:
• h - variable name or variable in cover ring (default: ‘h’)
EXAMPLES:
sage: I.homogenize()
Ideal (x^2*y + z*h^2 + h^3, y^2 + x*h + h^2) of
Multivariate Polynomial Ring in x, y, z, h over Finite
Field of size 2
sage: I.homogenize(y)
Ideal (x^2*y + y^3 + y^2*z, x*y) of Multivariate
Polynomial Ring in x, y, z over Finite Field of size 2
is_homogeneous()
Return True if this ideal is spanned by homogeneous polynomials, i.e. if it is a homogeneous ideal.
EXAMPLES:
sage: I.is_homogeneous()
False
sage: J = I.homogenize()
sage: J
Ideal (x + 2*y + 2*z - h, x^2 + 2*y^2 + 2*z^2 - x*h, 2*x*y
+ 2*y*z - y*h) of Multivariate Polynomial Ring in x, y, z,
h over Rational Field
sage: J.is_homogeneous()
True
plot(*args, **kwds)
Plot the real zero locus of this principal ideal.
INPUT:
• self - a principal ideal in 2 variables
• algorithm - set this to ‘surf’ if you want ‘surf’ to plot the ideal (default: None)
• *args - optional tuples (variable, minimum, maximum) for plotting dimensions
• **kwds - optional keyword arguments passed on to implicit_plot
EXAMPLES:
Implicit plotting in 2-d:
sage: I = R.ideal([y^2-(x^2-1)*(x-2)])
sage: I.plot() # elliptic curve
Graphics object consisting of 1 graphics primitive
sage: I = R.ideal([-x^2*y+1])
sage: I.plot()
Graphics object consisting of 1 graphics primitive
AUTHORS:
• Martin Albrecht (2008-09)
random_element(degree, compute_gb=False, *args, ∑︀ **kwds)
Return a random element in this ideal as 𝑟 = ℎ𝑖 · 𝑓𝑖 .
INPUT:
• compute_gb - if True then a Gröbner basis is computed first and 𝑓𝑖 are the elements in the Gröbner
basis. Otherwise whatever basis is returned by self.gens() is used.
Note that sampling uniformly at random from the ideal at some large enough degree is equivalent to
computing a Gröbner basis. We give an example showing how to compute a Gröbner basis if we can
sample uniformly at random from an ideal:
sage: n = 3; d = 4
sage: P = PolynomialRing(GF(127), n, 'x')
sage: I = sage.rings.ideal.Cyclic(P)
sage: G = Sequence((A*v).list())
sage: G.is_groebner()
True
sage: Ideal(G) == I
True
We show that the default method does not sample uniformly at random from the ideal:
If degree equals the degree of the generators a random linear combination of the generators is returned:
reduce(f )
Reduce an element modulo the reduced Groebner basis for this ideal. This returns 0 if and only if the
element is in this ideal. In any case, this reduction is unique up to monomial orders.
EXAMPLES:
Note: Requires computation of a Groebner basis, which can be a very expensive operation.
subs(in_dict=None, **kwds)
Substitute variables.
This method substitutes some variables in the polynomials that generate the ideal with given values. Vari-
ables that are not specified in the input remain unchanged.
INPUT:
• in_dict – (optional) dictionary of inputs
• **kwds – named parameters
OUTPUT:
A new ideal with modified generators. If possible, in the same polynomial ring. Raises a TypeError if
no common polynomial ring of the substituted generators can be found.
EXAMPLES:
sage: I.subs(x=y)
Ideal (2*y^5, y^4 + y^2 + y + 5) of Multivariate Polynomial Ring in x, y over
˓→Integer Ring
sage: var("z")
z
sage: I.subs(a=z, b=z)
Principal ideal (2*z^2 + 2) of Symbolic Ring
sage: I.subs(x=1)
Ideal (y^2 - y + 4) of Multivariate Polynomial Ring in x, y over Rational
˓→Field
weil_restriction()
Compute the Weil restriction of this ideal over some extension field. If the field is a finite field, then this
computes the Weil restriction to the prime subfield.
A Weil restriction of scalars - denoted 𝑅𝑒𝑠𝐿/𝑘 - is a functor which, for any finite extension of fields 𝐿/𝑘
and any algebraic variety 𝑋 over 𝐿, produces another corresponding variety 𝑅𝑒𝑠𝐿/𝑘 (𝑋), defined over 𝑘.
It is useful for reducing questions about varieties over large fields to questions about more complicated
varieties over smaller fields.
This function does not compute this Weil restriction directly but computes on generating sets of polynomial
ideals:
Let 𝑑 be the degree of the field extension 𝐿/𝑘, let 𝑎 a generator of 𝐿/𝑘 and 𝑝 the minimal polynomial of
𝐿/𝑘. Denote this ideal by 𝐼.
∑︀𝑑−1
Specifically, this function first maps each variable 𝑥 to its representation over 𝑘: 𝑖=0 𝑎𝑖 𝑥𝑖 . Then each
generator of 𝐼 is evaluated over these representations and reduced modulo the minimal polynomial 𝑝.
The result is interpreted as a univariate polynomial in 𝑎 and its coefficients are the new generators of the
returned ideal.
If the input and the output ideals are radical, this is equivalent to the statement about algebraic varieties
above.
OUTPUT: MPolynomial Ideal
EXAMPLES:
sage: J = I.weil_restriction(); J
Ideal (x0 - y0 - z0 - 1, x1 - y1 - z1, x2 - y2 - z2, x3 - y3 - z3, x4 -
y4 - z4, x0^2 + x2*x3 + x1*x4 - y0^2 - y2*y3 - y1*y4 - z0^2 - z2*z3 -
z1*z4 - x0, -x0*x1 - x2*x3 - x3^2 - x1*x4 + x2*x4 + y0*y1 + y2*y3 + y3^2
+ y1*y4 - y2*y4 + z0*z1 + z2*z3 + z3^2 + z1*z4 - z2*z4 - x1, x1^2 -
x0*x2 + x3^2 - x2*x4 + x3*x4 - y1^2 + y0*y2 - y3^2 + y2*y4 - y3*y4 -
z1^2 + z0*z2 - z3^2 + z2*z4 - z3*z4 - x2, -x1*x2 - x0*x3 - x3*x4 - x4^2
+ y1*y2 + y0*y3 + y3*y4 + y4^2 + z1*z2 + z0*z3 + z3*z4 + z4^2 - x3, x2^2
- x1*x3 - x0*x4 + x4^2 - y2^2 + y1*y3 + y0*y4 - y4^2 - z2^2 + z1*z3 +
z0*z4 - z4^2 - x4, -x0*y0 + x4*y1 + x3*y2 + x2*y3 + x1*y4 - y0*z0 +
y4*z1 + y3*z2 + y2*z3 + y1*z4 - y0, -x1*y0 - x0*y1 - x4*y1 - x3*y2 +
x4*y2 - x2*y3 + x3*y3 - x1*y4 + x2*y4 - y1*z0 - y0*z1 - y4*z1 - y3*z2 +
y4*z2 - y2*z3 + y3*z3 - y1*z4 + y2*z4 - y1, -x2*y0 - x1*y1 - x0*y2 -
x4*y2 - x3*y3 + x4*y3 - x2*y4 + x3*y4 - y2*z0 - y1*z1 - y0*z2 - y4*z2 -
y3*z3 + y4*z3 - y2*z4 + y3*z4 - y2, -x3*y0 - x2*y1 - x1*y2 - x0*y3 -
x4*y3 - x3*y4 + x4*y4 - y3*z0 - y2*z1 - y1*z2 - y0*z3 - y4*z3 - y3*z4 +
y4*z4 - y3, -x4*y0 - x3*y1 - x2*y2 - x1*y3 - x0*y4 - x4*y4 - y4*z0 -
y3*z1 - y2*z2 - y1*z3 - y0*z4 - y4*z4 - y4) of Multivariate Polynomial
Ring in x0, x1, x2, x3, x4, y0, y1, y2, y3, y4, z0, z1, z2, z3, z4 over
Finite Field of size 3
sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal
sage: from sage.doctest.fixtures import reproducible_repr
sage: print(reproducible_repr(J.variety()))
[{x0: 1, x1: 0, x2: 0, x3: 0, x4: 0, y0: 0, y1: 0, y2: 0, y3: 0, y4: 0, z0: 0,
˓→ z1: 0, z2: 0, z3: 0, z4: 0}]
Weil restrictions are often used to study elliptic curves over extension fields so we give a simple example
involving those:
sage: K.<a> = QuadraticField(1/3)
sage: E = EllipticCurve(K,[1,2,3,4,5])
We pick a point on E:
sage: p = E.lift_x(1); p
(1 : 2 : 1)
sage: I = E.defining_ideal(); I
Ideal (-x^3 - 2*x^2*z + x*y*z + y^2*z - 4*x*z^2 + 3*y*z^2 - 5*z^3)
of Multivariate Polynomial Ring in x, y, z over Number Field in a with
˓→defining polynomial x^2 - 1/3
sage: I.subs(x=1,y=2,z=1)
Ideal (0) of Multivariate Polynomial Ring in x, y, z over
Number Field in a with defining polynomial x^2 - 1/3
I is also radical:
sage: I.radical() == I
True
sage: J = I.weil_restriction()
sage: J
Ideal (-x0^3 - x0*x1^2 - 2*x0^2*z0 - 2/3*x1^2*z0 + x0*y0*z0 + y0^2*z0 +
1/3*x1*y1*z0 + 1/3*y1^2*z0 - 4*x0*z0^2 + 3*y0*z0^2 - 5*z0^3 -
4/3*x0*x1*z1 + 1/3*x1*y0*z1 + 1/3*x0*y1*z1 + 2/3*y0*y1*z1 - 8/3*x1*z0*z1
+ 2*y1*z0*z1 - 4/3*x0*z1^2 + y0*z1^2 - 5*z0*z1^2, -3*x0^2*x1 - 1/3*x1^3
- 4*x0*x1*z0 + x1*y0*z0 + x0*y1*z0 + 2*y0*y1*z0 - 4*x1*z0^2 + 3*y1*z0^2
- 2*x0^2*z1 - 2/3*x1^2*z1 + x0*y0*z1 + y0^2*z1 + 1/3*x1*y1*z1 +
1/3*y1^2*z1 - 8*x0*z0*z1 + 6*y0*z0*z1 - 15*z0^2*z1 - 4/3*x1*z1^2 +
y1*z1^2 - 5/3*z1^3) of Multivariate Polynomial Ring in x0, x1, y0, y1,
z0, z1 over Rational Field
sage: J.subs(x0=1,y0=2,z0=1,x1=0,y1=0,z1=0)
Ideal (0, 0) of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 over
˓→Rational Field
class sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_macaulay2_repr
An ideal in a multivariate polynomial ring, which has an underlying Macaulay2 ring associated to it.
EXAMPLES:
class sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_magma_repr
class sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_base_repr
syzygy_module()
Computes the first syzygy (i.e., the module of relations of the given generators) of the ideal.
EXAMPLES:
ALGORITHM:
Uses Singular.
REFERENCES:
• Thomas Becker and Volker Weispfenning. Groebner Bases - A Computational Approach To Commu-
tative Algebra. Springer, New York 1993.
basis_is_groebner(singular=Singular)
Returns True if the generators of this ideal (self.gens()) form a Groebner basis.
Let 𝐼 be the set of generators of this ideal. The check is performed by trying to lift 𝑆𝑦𝑧(𝐿𝑀 (𝐼)) to 𝑆𝑦𝑧(𝐼)
as 𝐼 forms a Groebner basis if and only if for every element 𝑆 in 𝑆𝑦𝑧(𝐿𝑀 (𝐼)):
𝑚
∑︁
𝑆*𝐺= ℎ𝑖 𝑔𝑖 − − − − >𝐺 0.
𝑖=0
ALGORITHM:
Uses Singular.
EXAMPLES:
sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10)
sage: I = sage.rings.ideal.Cyclic(R,4)
sage: I.basis_is_groebner()
False
sage: I2 = Ideal(I.groebner_basis())
sage: I2.basis_is_groebner()
True
˓→947*U2*h^2 + 2370*h^3, \
˓→2 - 2842*u4*u3*h^2, \
˓→2*U3*h \
˓→1897*U5*U4*h^2 \
˓→2*u2*h^2 \
+ 2*u5*u3*u2*h^2 + 1899*u4*u3*u2*h^2, \
U5^2*U4*U3*u2 + U5*U4^2*U3*u2 + U5*U4*U3^2*u2 - 3791*U5^2*U4*U3*h -
˓→ 3791*U5*U4^2*U3*h - 3791*U5*U4*U3^2*h - 3791*U5*U4*U3*U2*h \
˓→3, \
sage: Ideal(l).basis_is_groebner()
False
sage: gb = Ideal(l).groebner_basis()
sage: Ideal(gb).basis_is_groebner()
True
Note: From the Singular Manual for the reduce function we use in this method: ‘The result may have
no meaning if the second argument (self) is not a standard basis’. I (malb) believe this refers to the
mathematical fact that the results may have no meaning if self is no standard basis, i.e., Singular doesn’t
‘add’ any additional ‘nonsense’ to the result. So we may actually use reduce to determine if self is a
Groebner basis.
complete_primary_decomposition(algorithm=’sy’)
Return a list of primary ideals such that their intersection is self, together with the associated prime
ideals.
An ideal 𝑄 is called primary if it is a proper ideal of the ring 𝑅, and if whenever 𝑎𝑏 ∈ 𝑄 and 𝑎 ̸∈ 𝑄, then
𝑏𝑛 ∈ 𝑄 for some 𝑛 ∈ Z.
If 𝑄 is a primary ideal of the ring 𝑅, then the radical ideal 𝑃 of 𝑄 (i.e. the ideal consisting of all 𝑎 ∈ 𝑅
with a^n in Q‘ for some 𝑛 ∈ Z), is called the associated prime of 𝑄.
If 𝐼 is a proper ideal of a Noetherian ring 𝑅, then there exists a finite collection of primary ideals 𝑄𝑖 such
that the following hold:
• the intersection of the 𝑄𝑖 is 𝐼;
• none of the 𝑄𝑖 contains the intersection of the others;
• the associated prime ideals 𝑃𝑖 of the 𝑄𝑖 are pairwise distinct.
INPUT:
• algorithm – string:
– 'sy' – (default) use the Shimoyama-Yokoyama algorithm
– 'gtz' – use the Gianni-Trager-Zacharias algorithm
OUTPUT:
• a list of pairs (𝑄𝑖 , 𝑃𝑖 ), where the 𝑄𝑖 form a primary decomposition of self and 𝑃𝑖 is the associated
prime of 𝑄𝑖 .
EXAMPLES:
True
ALGORITHM:
Uses Singular.
dimension(singular=’singular_default’)
The dimension of the ring modulo this ideal.
EXAMPLES:
-1
sage: I=ideal([x*(x*y+1),y*(x*y+1)])
sage: I.dimension()
verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back
˓→to very slow toy implementation.
1
sage: I = R.ideal([x^3*y,x*y^2])
sage: I.dimension()
verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back
˓→to very slow toy implementation.
1
sage: R.<x,y> = PolynomialRing(GF(2147483659),order='lex')
sage: I = R.ideal(0)
sage: I.dimension()
verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back
˓→to very slow toy implementation.
ALGORITHM:
Uses Singular, unless the characteristic is too large.
Note: Requires computation of a Groebner basis, which can be a very expensive operation.
elimination_ideal(variables)
Return the elimination ideal of this ideal with respect to the variables given in variables.
INPUT:
• variables – a list or tuple of variables in self.ring()
EXAMPLES:
sage: R.<x,y,t,s,z> = PolynomialRing(QQ,5)
sage: I = R * [x-t,y-t^2,z-t^3,s-x+y^3]
sage: I.elimination_ideal([t,s])
Ideal (y^2 - x*z, x*y - z, x^2 - y) of Multivariate
Polynomial Ring in x, y, t, s, z over Rational Field
ALGORITHM:
Uses Singular.
Note: Requires computation of a Groebner basis, which can be a very expensive operation.
genus()
Return the genus of the projective curve defined by this ideal, which must be 1 dimensional.
EXAMPLES:
Consider the hyperelliptic curve 𝑦 2 = 4𝑥5 − 30𝑥3 + 45𝑥 − 22 over Q, it has genus 2:
sage: P.<x> = QQ[]
sage: f = 4*x^5 - 30*x^3 + 45*x - 22
sage: C = HyperellipticCurve(f); C
Hyperelliptic Curve over Rational Field defined by y^2 = 4*x^5 - 30*x^3 +
˓→45*x - 22
sage: C.genus()
2
hilbert_numerator(grading=None, algorithm=’sage’)
Return the Hilbert numerator of this ideal.
INPUT:
• grading – (optional) a list or tuple of integers
• algorithm – (default: 'sage') must be either 'sage' or 'singular'
⨁︀
Let 𝐼 (which is self) be a homogeneous ideal and 𝑅 = 𝑑 𝑅𝑑 (which is self.ring()) be a graded
commutative algebra over a field 𝐾. Then the Hilbert function is∑︀defined as 𝐻(𝑑) = 𝑑𝑖𝑚𝐾 𝑅𝑑 and the
∞
Hilbert series of 𝐼 is defined as the formal power series 𝐻𝑆(𝑡) = 𝑑=0 𝐻(𝑑)𝑡𝑑 .
This power series can be expressed as 𝐻𝑆(𝑡) = 𝑄(𝑡)/(1 − 𝑡)𝑛 where 𝑄(𝑡) is a polynomial over
𝑍 and 𝑛 the number of variables in 𝑅. This method returns 𝑄(𝑡), the numerator; hence the name,
hilbert_numerator. An optional grading can be given, in which case the graded (or weighted)
Hilbert numerator is given.
EXAMPLES:
hilbert_polynomial(algorithm=’sage’)
Return the Hilbert polynomial of this ideal.
INPUT:
• algorithm – (default: 'sage') must be either 'sage' or 'singular'
⨁︀
Let 𝐼 (which is self) be a homogeneous ideal and 𝑅 = 𝑑 𝑅𝑑 (which is self.ring()) be a graded
commutative algebra over a field 𝐾. The Hilbert polynomial is the unique polynomial 𝐻𝑃 (𝑡) with rational
coefficients such that 𝐻𝑃 (𝑑) = 𝑑𝑖𝑚𝐾 𝑅𝑑 for all but finitely many positive integers 𝑑.
EXAMPLES:
Because Singular uses 32-bit integers, the above example would fail with Singular. We don’t test it here,
as it has a side-effect on other tests that is not understood yet (see trac ticket #26300):
Note that in this example, the Hilbert polynomial gives the coefficients of the Hilbert-Poincaré series in all
degrees:
True
hilbert_series(grading=None, algorithm=’sage’)
Return the Hilbert series of this ideal.
INPUT:
• grading – (optional) a list or tuple of integers
• algorithm – (default: 'sage') must be either 'sage' or 'singular'
⨁︀
Let 𝐼 (which is self) be a homogeneous ideal and 𝑅 = 𝑑 𝑅𝑑 (which is self.ring()) be a graded
commutative algebra over a field 𝐾. Then the Hilbert function is∑︀defined as 𝐻(𝑑) = 𝑑𝑖𝑚𝐾 𝑅𝑑 and the
∞
Hilbert series of 𝐼 is defined as the formal power series 𝐻𝑆(𝑡) = 𝑑=0 𝐻(𝑑)𝑡𝑑 .
This power series can be expressed as 𝐻𝑆(𝑡) = 𝑄(𝑡)/(1 − 𝑡)𝑛 where 𝑄(𝑡) is a polynomial over 𝑍 and 𝑛
the number of variables in 𝑅. This method returns 𝑄(𝑡)/(1−𝑡)𝑛 , normalised so that the leading monomial
of the numerator is positive.
An optional grading can be given, in which case the graded (or weighted) Hilbert series is given.
EXAMPLES:
ALGORITHM:
Uses libSINGULAR.
interreduced_basis()
If this ideal is spanned by (𝑓1 , ..., 𝑓𝑛 ) this method returns (𝑔1 , ..., 𝑔𝑠 ) such that:
• (𝑓1 , ..., 𝑓𝑛 ) = (𝑔1 , ..., 𝑔𝑠 )
• 𝐿𝑇 (𝑔𝑖 )! = 𝐿𝑇 (𝑔𝑗 ) for all 𝑖! = 𝑗
• 𝐿𝑇 (𝑔𝑖 ) does not divide 𝑚 for all monomials 𝑚 of {𝑔1 , ..., 𝑔𝑖−1 , 𝑔𝑖+1 , ..., 𝑔𝑠 }
• 𝐿𝐶(𝑔𝑖 ) == 1 for all 𝑖 if the coefficient ring is a field.
EXAMPLES:
sage: R.<t>=QQ['t']
sage: K.<x,y>=R.fraction_field()['x,y']
sage: I=t*x*K
sage: I.interreduced_basis()
[x]
ALGORITHM:
Uses Singular’s interred command or sage.rings.polynomial.toy_buchberger.
inter_reduction() if conversion to Singular fails.
intersection(*others)
Return the intersection of the arguments with this ideal.
EXAMPLES:
The following simple example illustrates that the product need not equal the intersection.
sage: IJ = I*J; IJ
Ideal (x^2*y^2, x^3, y^3, x*y) of Multivariate Polynomial Ring in x, y over
˓→Rational Field
sage: IJ == K
False
is_prime(**kwds)
Return True if this ideal is prime.
INPUT:
• keyword arguments are passed on to complete_primary_decomposition; in this way you
can specify the algorithm to use.
EXAMPLES:
sage: (I * J).is_prime()
False
The following is trac ticket #5982. Note that the quotient ring is not recognized as being a field at this
time, so the fraction field is not the quotient ring itself:
sage: Q = R.quotient(I); Q
Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the
˓→ideal (x^2 - y^2 - 1)
sage: Q.fraction_field()
Fraction Field of Quotient of Multivariate Polynomial Ring in x, y over
˓→Rational Field by the ideal (x^2 - y^2 - 1)
minimal_associated_primes()
OUTPUT:
• list - a list of prime ideals
EXAMPLES:
ALGORITHM:
Uses Singular.
normal_basis(algorithm=’libsingular’, singular=’singular_default’)
Returns a vector space basis (consisting of monomials) of the quotient ring by the ideal, resp. of a free
module by the module, in case it is finite dimensional and if the input is a standard basis with respect to
the ring ordering.
INPUT:
algorithm - defaults to use libsingular, if it is anything else we will use the kbase() command
EXAMPLES:
plot(singular=Singular)
If you somehow manage to install surf, perhaps you can use this function to implicitly plot the real zero
locus of this ideal (if principal).
INPUT:
• self - must be a principal ideal in 2 or 3 vars over Q.
EXAMPLES:
Implicit plotting in 2-d:
AUTHORS:
• David Joyner (2006-02-12)
primary_decomposition(algorithm=’sy’)
Return a list of primary ideals such that their intersection is self.
An ideal 𝑄 is called primary if it is a proper ideal of the ring 𝑅, and if whenever 𝑎𝑏 ∈ 𝑄 and 𝑎 ̸∈ 𝑄, then
𝑏𝑛 ∈ 𝑄 for some 𝑛 ∈ Z.
If 𝑄 is a primary ideal of the ring 𝑅, then the radical ideal 𝑃 of 𝑄 (i.e. the ideal consisting of all 𝑎 ∈ 𝑅
with a^n in Q‘ for some 𝑛 ∈ Z), is called the associated prime of 𝑄.
If 𝐼 is a proper ideal of a Noetherian ring 𝑅, then there exists a finite collection of primary ideals 𝑄𝑖 such
that the following hold:
• the intersection of the 𝑄𝑖 is 𝐼;
• none of the 𝑄𝑖 contains the intersection of the others;
• the associated prime ideals of the 𝑄𝑖 are pairwise distinct.
INPUT:
• algorithm – string:
– 'sy' – (default) use the Shimoyama-Yokoyama algorithm
– 'gtz' – use the Gianni-Trager-Zacharias algorithm
OUTPUT:
• a list of primary ideals 𝑄𝑖 forming a primary decomposition of self.
EXAMPLES:
ALGORITHM:
Uses Singular.
REFERENCES:
• Thomas Becker and Volker Weispfenning. Groebner Bases - A Computational Approach To Commu-
tative Algebra. Springer, New York 1993.
primary_decomposition_complete(algorithm=’sy’)
Return a list of primary ideals such that their intersection is self, together with the associated prime
ideals.
An ideal 𝑄 is called primary if it is a proper ideal of the ring 𝑅, and if whenever 𝑎𝑏 ∈ 𝑄 and 𝑎 ̸∈ 𝑄, then
𝑏𝑛 ∈ 𝑄 for some 𝑛 ∈ Z.
If 𝑄 is a primary ideal of the ring 𝑅, then the radical ideal 𝑃 of 𝑄 (i.e. the ideal consisting of all 𝑎 ∈ 𝑅
with a^n in Q‘ for some 𝑛 ∈ Z), is called the associated prime of 𝑄.
If 𝐼 is a proper ideal of a Noetherian ring 𝑅, then there exists a finite collection of primary ideals 𝑄𝑖 such
that the following hold:
• the intersection of the 𝑄𝑖 is 𝐼;
True
ALGORITHM:
Uses Singular.
quotient(J)
Given ideals 𝐼 = self and 𝐽 in the same polynomial ring 𝑃 , return the ideal quotient of 𝐼 by 𝐽 consisting
of the polynomials 𝑎 of 𝑃 such that {𝑎𝐽 ⊂ 𝐼}.
This is also referred to as the colon ideal (𝐼:𝐽).
INPUT:
• J - multivariate polynomial ideal
EXAMPLES:
sage: R.<x,y,z> = PolynomialRing(GF(181),3)
sage: I = Ideal([x^2+x*y*z,y^2-z^3*y,z^3+y^5*x*z])
sage: J = Ideal([x])
sage: Q = I.quotient(J)
sage: y*z + x in I
False
sage: x in J
True
sage: x * (y*z + x) in I
True
radical()
The radical of this ideal.
EXAMPLES:
This is an obviously not radical ideal:
sage: R.<x,y,z> = PolynomialRing(QQ, 3)
sage: I = (x^2, y^3, (x*z)^4 + y^3 + 10*x^2)*R
sage: I.radical()
Ideal (y, x) of Multivariate Polynomial Ring in x, y, z over Rational Field
Note: From the Singular manual: A combination of the algorithms of Krick/Logar and Kemper is used.
Works also in positive characteristic (Kempers algorithm).
saturation(other)
Returns the saturation (and saturation exponent) of the ideal self with respect to the ideal other
INPUT:
• other – another ideal in the same ring
OUTPUT:
• a pair (ideal, integer)
EXAMPLES:
syzygy_module()
Computes the first syzygy (i.e., the module of relations of the given generators) of the ideal.
EXAMPLES:
ALGORITHM:
Uses Singular’s syz command.
transformed_basis(algorithm=’gwalk’, other_ring=None, singular=’singular_default’)
Returns a lex or other_ring Groebner Basis for this ideal.
INPUT:
• algorithm - see below for options.
• other_ring - only valid for algorithm ‘fglm’, if provided conversion will be performed to this ring.
Otherwise a lex Groebner basis will be returned.
ALGORITHMS:
• fglm - FGLM algorithm. The input ideal must be given with a reduced Groebner Basis of a zero-
dimensional ideal
• gwalk - Groebner Walk algorithm (default)
sage: R.<z,y,x>=PolynomialRing(GF(32003),3,order='lex')
sage: I=Ideal([y^3+x*y*z+y^2*z+x*z^3,3+x*y+x^2*y+y^2*z])
sage: I.transformed_basis('gwalk')
[z*y^2 + y*x^2 + y*x + 3,
z*x + 8297*y^8*x^2 + 8297*y^8*x + 3556*y^7 - 8297*y^6*x^4 + 15409*y^6*x^3 -
˓→8297*y^6*x^2
ALGORITHM:
Uses Singular.
triangular_decomposition(algorithm=None, singular=’singular_default’)
Decompose zero-dimensional ideal self into triangular sets.
This requires that the given basis is reduced w.r.t. to the lexicographical monomial ordering. If the basis
of self does not have this property, the required Groebner basis is computed implicitly.
INPUT:
• algorithm - string or None (default: None)
ALGORITHMS:
• singular:triangL - decomposition of self into triangular systems (Lazard).
• singular:triangLfak - decomp. of self into tri. systems plus factorization.
– singular:triangM - decomposition of self into triangular systems (Moeller).
OUTPUT: a list 𝑇 of lists 𝑡 such that the variety of self is the union of the varieties of 𝑡 in 𝐿 and each 𝑡
is in triangular form.
EXAMPLES:
Ideal (a^4 + a^3 + a^2 + a + 1, b^3 + b^2*a + b^2 + b*a^2 + b*a + b + a^3 + a^
˓→2 + a + 1, c + b^2*a^3 + b^2*a^2 + b^2*a + b^2, -d + b^2*a^2 + b^2*a + b^2
variety(ring=None)
Return the variety of this ideal.
Given a zero-dimensional ideal 𝐼 (== self) of a polynomial ring 𝑃 whose order is lexicographic, return
the variety of 𝐼 as a list of dictionaries with (variable, value) pairs. By default, the variety of the
ideal over its coefficient field 𝐾 is returned; ring can be specified to find the variety over a different ring.
These dictionaries have cardinality equal to the number of variables in 𝑃 and represent assignments of
values to these variables such that all polynomials in 𝐼 vanish.
If ring is specified, then a triangular decomposition of self is found over the original coefficient field
𝐾; then the triangular systems are solved using root-finding over ring. This is particularly useful when
𝐾 is QQ (to allow fast symbolic computation of the triangular decomposition) and ring is RR, AA, CC, or
QQbar (to compute the whole real or complex variety of the ideal).
Note that with ring=RR or CC, computation is done numerically and potentially inaccurately; in particu-
lar, the number of points in the real variety may be miscomputed. With ring=AA or QQbar, computation
is done exactly (which may be much slower, of course).
INPUT:
• ring - return roots in the ring instead of the base ring of this ideal (default: None)
• proof - return a provably correct result (default: True)
EXAMPLES:
sage: V = I.variety(); V
[{y: w^2 + 2, x: 2*w}, {y: w^2 + w, x: 2*w + 1}, {y: w^2 + 2*w, x: 2*w + 2}]
[0, 0, 0, 0, 0, 0]
sage: [I.subs(v).is_zero() for v in V] # same test, but nicer syntax
[True, True, True]
However, we only account for solutions in the ground field and not in the algebraic closure:
sage: I.vector_space_dimension()
48
Here we compute the points of intersection of a hyperbola and a circle, in several fields:
sage: I.variety()
[{y: 1, x: 1}]
sage: I.variety(ring=RR)
[{y: 0.361103080528647, x: 2.76929235423863},
{y: 1.00000000000000, x: 1.00000000000000}]
sage: I.variety(ring=AA)
[{x: 2.769292354238632?, y: 0.3611030805286474?},
{x: 1, y: 1}]
sage: I.variety(ring=CC)
[{y: 0.31944845973567... - 1.6331702409152...*I,
x: 0.11535382288068... + 0.58974280502220...*I},
{y: 0.31944845973567... + 1.6331702409152...*I,
x: 0.11535382288068... - 0.58974280502220...*I},
{y: 0.36110308052864..., x: 2.7692923542386...},
{y: 1.00000000000000, x: 1.00000000000000}]
sage: I.variety(ring=QQbar)
[{y: 0.3194484597356763? - 1.633170240915238?*I,
x: 0.11535382288068429? + 0.5897428050222055?*I},
{y: 0.3194484597356763? + 1.633170240915238?*I,
x: 0.11535382288068429? - 0.5897428050222055?*I},
{y: 0.3611030805286474?, x: 2.769292354238632?},
{y: 1, x: 1}]
Computation over floating point numbers may compute only a partial solution, or even none at all. Notice
that x values are missing from the following variety:
˓→incorrectly.
This is due to precision error, which causes the computation of an intermediate Groebner basis to fail.
If the ground field’s characteristic is too large for Singular, we resort to a toy implementation:
[{y: 0, x: 0}]
The dictionary expressing the variety will be indexed by generators of the polynomial ring after changing
to the target field. But the mapping will also accept generators of the original ring, or even generator names
ALGORITHM:
Uses triangular decomposition.
vector_space_dimension()
Return the vector space dimension of the ring modulo this ideal. If the ideal is not zero-dimensional, a
TypeError is raised.
ALGORITHM:
Uses Singular.
EXAMPLES:
class sage.rings.polynomial.multi_polynomial_ideal.NCPolynomialIdeal(ring,
gens,
co-
erce=True,
side=’left’)
Bases: sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr,
sage.rings.noncommutative_ideals.Ideal_nc
Creates a non-commutative polynomial ideal.
INPUT:
• ring - the g-algebra to which this ideal belongs
• gens - the generators of this ideal
• coerce (optional - default True) - generators are coerced into the ring before creating the ideal
• side - optional string, either “left” (default) or “twosided”; defines whether this ideal is left of two-sided.
EXAMPLES:
˓→y*x: x*y - z}
sage: sorted(I.gens(),key=str)
[x^2, y^2, z^2 - 1]
sage: H.ideal([y^2, x^2, z^2-H.one()], side="twosided") #random
Twosided Ideal (y^2, x^2, z^2 - 1) of Noncommutative Multivariate Polynomial Ring
˓→in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y,
˓→y*x: x*y - z}
reduce(p)
Reduce an element modulo a Groebner basis for this ideal.
It returns 0 if and only if the element is in this ideal. In any case, this reduction is unique up to monomial
orders.
NOTE:
There are left and two-sided ideals. Hence,
EXAMPLES:
Here, we see that the relation that we just found in the quotient is actually a consequence of the given
relations:
sage: I.reduce(z^2)
1
res(length)
Compute the resolution up to a given length of the ideal.
NOTE:
Only left syzygies can be computed. So, even if the ideal is two-sided, then the resolution is only one-sided.
In that case, a warning is printed.
EXAMPLES:
std()
Computes a GB of the ideal. It is two-sided if and only if the ideal is two-sided.
EXAMPLES:
sage: sorted(I.std().gens(),key=str)
[2*x*y - z - 1, x*z + x, x^2, y*z - y, y^2, z^2 - 1]
If the ideal is a left ideal, then std returns a left Groebner basis. But if it is a two-sided ideal, then the
output of std and twostd() coincide:
sage: sorted(JL.gens(),key=str)
[x^3, y^3, z^3 - 4*z]
sage: JL.std() #random
Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3,
˓→ x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over
˓→Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z}
sage: sorted(JL.std().gens(),key=str)
[2*x*y*z - z^2 - 2*z, x*z^2 + 2*x*z, x^3, y*z^2 - 2*y*z, y^3, z^3 - 4*z]
sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided')
sage: JT #random
Twosided Ideal (x^3, y^3, z^3 - 4*z) of Noncommutative Multivariate
˓→Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z +
sage: sorted(JT.gens(),key=str)
[x^3, y^3, z^3 - 4*z]
sage: JT.std() #random
(continues on next page)
˓→Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z}
sage: sorted(JT.std().gens(),key=str)
[2*x*y*z - z^2 - 2*z, x*y^2 - y*z, x*z^2 + 2*x*z, x^2*y - x*z - 2*x, x^2*z +
˓→2*x^2, x^3, y*z^2 - 2*y*z, y^2*z - 2*y^2, y^3, z^3 - 4*z]
˓→ 0
˓→ y^2]
[
˓→ 0
˓→ -z^2 + 8*z - 15
˓→ x^2]
[ x^2*z^2 + 8*x^
˓→2*z + 15*x^2 -
˓→y^2*z^2 + 8*y^2*z - 15*y^2
˓→ 6*y*z^2]
[ x^3*z^2 + 7*x^
˓→3*z + 12*x^3 -x*y^2*z^2 + 9*x*y^2*z - 4*y*z^3 - 20*x*y^2 +
˓→52*y*z^2 - 224*y*z + 320*y (continues on next page)
˓→ -6*x*z^2]
˓→ -y^4*z + 4*y^4
˓→ 0]
[ 2*x^3*y*z + 8*x^3*y + 9*x^
˓→2*z + 27*x^2 -2*x*y^3*z + 8*x*y^3 - 12*y^
˓→2*z^2 + 99*y^2*z - 195*y^2
˓→ 0]
[x^3*y^2*z + 4*x^3*y^2 + 18*x^2*y*z - 36*x*z^3 + 66*x^2*y - 432*x*z^2 -
˓→1656*x*z - 2052*x -x*y^4*z + 4*x*y^4 -
˓→8*y^3*z^2 + 62*y^3*z - 114*y^3
˓→ 48*y*z^2 - 36*y*z]
sage: M*G
(0, 0, 0, 0, 0, 0, 0, 0, 0)
˓→.
sage: sorted(I.twostd().gens(),key=str)
[2*x*y - z - 1, x*z + x, x^2, y*z - y, y^2, z^2 - 1]
Note: This decorator is used automatically internally so the user does not need to use it manually.
sage.rings.polynomial.multi_polynomial_ideal.is_MPolynomialIdeal(x)
Return True if the provided argument x is an ideal in the multivariate polynomial ring.
INPUT:
• x - an arbitrary object
EXAMPLES:
Sage distinguishes between a list of generators for an ideal and the ideal itself. This distinction is inconsistent
with Singular but matches Magma’s behavior.
sage: is_MPolynomialIdeal(I)
False
sage: I = Ideal(I)
sage: is_MPolynomialIdeal(I)
True
sage.rings.polynomial.multi_polynomial_ideal.require_field
alias of RequireField
sage: sr = mq.SR(2,1,2,4,gf2=True,polybori=True)
sage: sr
SR(2,1,2,4)
We can construct a polynomial sequence for a random plaintext-ciphertext pair and study it:
sage: set_random_seed(1)
sage: F,s = sr.polynomial_system()
sage: F
Polynomial Sequence with 112 Polynomials in 64 Variables
sage: r2 = F.part(2); r2
(w200 + k100 + x100 + x102 + x103,
w201 + k101 + x100 + x101 + x103 + 1,
w202 + k102 + x100 + x101 + x102 + 1,
(continues on next page)
sage: C[0].groebner_basis()
Polynomial Sequence with 30 Polynomials in 16 Variables
sage: A.rank()
4056
(continues on next page)
Note: In many other computer algebra systems (cf. Singular) this class would be called Ideal but an ideal is a very
distinct object from its generators and thus this is not an ideal in Sage.
Classes
sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence(arg1,
arg2=None,
im-
mutable=False,
cr=False,
cr_str=None)
Construct a new polynomial sequence object.
INPUT:
• arg1 - a multivariate polynomial ring, an ideal or a matrix
• arg2 - an iterable object of parts or polynomials (default:None)
– immutable - if True the sequence is immutable (default: False)
– cr - print a line break after each element (default: False)
– cr_str - print a line break after each element if ‘str’ is called (default: None)
EXAMPLES:
sage: Sequence(I)
[a + 2*b + 2*c + 2*d - 1,
a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a,
2*a*b + 2*b*c + 2*c*d - b,
b^2 + 2*a*c + 2*b*d - c]
sage: PolynomialSequence([1,x,y]).ring()
Multivariate Polynomial Ring in x, y, z over Finite Field of size 2
class sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic(parts,
ring,
im-
mutable=False
cr=False,
cr_str=None)
Bases: sage.structure.sequence.Sequence_generic
Construct a new system of multivariate polynomials.
INPUT:
• part - a list of lists with polynomials
• ring - a multivariate polynomial ring
• immutable - if True the sequence is immutable (default: False)
• cr - print a line break after each element (default: False)
• cr_str - print a line break after each element if ‘str’ is called (default: None)
EXAMPLES:
sage: P.<a,b,c,d> = PolynomialRing(GF(127),4)
sage: I = sage.rings.ideal.Katsura(P)
algebraic_dependence()
Returns the ideal of annihilating polynomials for the polynomials in self, if those polynomials are alge-
braically dependent. Otherwise, returns the zero ideal.
OUTPUT:
If the polynomials 𝑓1 , . . . , 𝑓𝑟 in self are algebraically dependent, then the output is the ideal {𝐹 ∈
𝐾[𝑇1 , . . . , 𝑇𝑟 ] : 𝐹 (𝑓1 , . . . , 𝑓𝑟 ) = 0} of annihilating polynomials of 𝑓1 , . . . , 𝑓𝑟 . Here 𝐾 is the coefficient
ring of polynomial ring of 𝑓1 , . . . , 𝑓𝑟 and 𝑇1 , . . . , 𝑇𝑟 are new indeterminates. If 𝑓1 , . . . , 𝑓𝑟 are algebraically
independent, then the output is the zero ideal in 𝐾[𝑇1 , . . . , 𝑇𝑟 ].
EXAMPLES:
Note: This function’s code also works for sequences of polynomials from a univariate polynomial ring,
but i don’t know where in the Sage codebase to put it to use it to that effect.
AUTHORS:
• Alex Raichev (2011-06-22)
coefficient_matrix(sparse=True)
Return tuple (A,v) where A is the coefficient matrix of this system and v the matching monomial vector.
Thus value of A[i,j] corresponds the coefficient of the monomial v[j] in the i-th polynomial in this
system.
Monomials are order w.r.t. the term ordering of self.ring() in reverse order, i.e. such that the smallest
entry comes last.
INPUT:
• sparse - construct a sparse matrix (default: True)
EXAMPLES:
sage: F = Sequence(I)
sage: A,v = F.coefficient_matrix()
sage: A
[ 0 0 0 0 0 0 0 0 0 1 2 2 2 126]
[ 1 0 2 0 0 2 0 0 2 126 0 0 0 0]
[ 0 2 0 0 2 0 0 2 0 0 126 0 0 0]
[ 0 0 1 2 0 0 2 0 0 0 0 126 0 0]
sage: v
[a^2]
[a*b]
[b^2]
[a*c]
[b*c]
[c^2]
[b*d]
[c*d]
[d^2]
[ a]
[ b]
[ c]
[ d]
[ 1]
sage: A*v
[ a + 2*b + 2*c + 2*d - 1]
[a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a]
[ 2*a*b + 2*b*c + 2*c*d - b]
[ b^2 + 2*a*c + 2*b*d - c]
connected_components()
Split the polynomial system in systems which do not share any variables.
EXAMPLES:
As an example consider one part of AES, which naturally splits into four subsystems which are indepen-
dent:
sage: sr = mq.SR(2,4,4,8,gf2=True,polybori=True)
sage: F,s = sr.polynomial_system()
sage: Fz = Sequence(F.part(2))
sage: Fz.connected_components()
[Polynomial Sequence with 128 Polynomials in 128 Variables,
Polynomial Sequence with 128 Polynomials in 128 Variables,
Polynomial Sequence with 128 Polynomials in 128 Variables,
Polynomial Sequence with 128 Polynomials in 128 Variables]
connection_graph()
Return the graph which has the variables of this system as vertices and edges between two variables if they
groebner_basis(*args, **kwargs)
Compute and return a Groebner basis for the ideal spanned by the polynomials in this system.
INPUT:
• args - list of arguments passed to MPolynomialIdeal.groebner_basis call
• kwargs - dictionary of arguments passed to MPolynomialIdeal.groebner_basis call
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: gb = F.groebner_basis()
sage: Ideal(gb).basis_is_groebner()
True
ideal()
Return ideal spanned by the elements of this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: P = F.ring()
sage: I = F.ideal()
sage: I.elimination_ideal(P(
˓→'s000*s001*s002*s003*w100*w101*w102*w103*x100*x101*x102*x103'))
w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, k003 over
˓→Finite Field in a of size 2^4
is_groebner(singular=Singular)
Returns True if the generators of this ideal (self.gens()) form a Groebner basis.
Let 𝐼 be the set of generators of this ideal. The check is performed by trying to lift 𝑆𝑦𝑧(𝐿𝑀 (𝐼)) to 𝑆𝑦𝑧(𝐼)
as 𝐼 forms a Groebner basis if and only if for every element 𝑆 in 𝑆𝑦𝑧(𝐿𝑀 (𝐼)):
∑︀𝑚
𝑆 * 𝐺 = 𝑖=0 ℎ𝑖 𝑔𝑖 − − − − >𝐺 0.
EXAMPLES:
sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10)
sage: I = sage.rings.ideal.Cyclic(R,4)
(continues on next page)
maximal_degree()
Return the maximal degree of any polynomial in this sequence.
EXAMPLES:
monomials()
Return an unordered tuple of monomials in this polynomial system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: len(F.monomials())
49
nmonomials()
Return the number of monomials present in this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: F.nmonomials()
49
nparts()
Return number of parts of this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: F.nparts()
4
nvariables()
Return number of variables present in this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
(continues on next page)
part(i)
Return i-th part of this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: R0 = F.part(1)
sage: R0
(k000^2 + k001, k001^2 + k002, k002^2 + k003, k003^2 + k000)
parts()
Return a tuple of parts of this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: l = F.parts()
sage: len(l)
4
reduced()
If this sequence is (𝑓1 , ..., 𝑓𝑛 ) then this method returns (𝑔1 , ..., 𝑔𝑠 ) such that:
• (𝑓1 , ..., 𝑓𝑛 ) = (𝑔1 , ..., 𝑔𝑠 )
• 𝐿𝑇 (𝑔𝑖 )! = 𝐿𝑇 (𝑔𝑗 ) for all 𝑖! = 𝑗
• 𝐿𝑇 (𝑔𝑖 ) does not divide 𝑚 for all monomials 𝑚 of {𝑔1 , ..., 𝑔𝑖−1 , 𝑔𝑖+1 , ..., 𝑔𝑠 }
• 𝐿𝐶(𝑔𝑖 ) == 1 for all 𝑖 if the coefficient ring is a field.
EXAMPLES:
sage: R.<t>=QQ['t']
sage: K.<x,y>=R.fraction_field()['x,y']
sage: I=t*x*K
sage: I.basis.reduced()
[x]
ALGORITHM:
Uses Singular’s interred command or sage.rings.polynomial.toy_buchberger.
inter_reduction() if conversion to Singular fails.
ring()
Return the polynomial ring all elements live in.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block')
sage: F,s = sr.polynomial_system()
sage: print(F.ring().repr_long())
Polynomial Ring
Base Ring : Finite Field of size 2
Size : 20 Variables
Block 0 : Ordering : deglex
Names : k100, k101, k102, k103, x100, x101, x102, x103, w100,
˓→w101, w102, w103, s000, s001, s002, s003
subs(*args, **kwargs)
Substitute variables for every polynomial in this system and return a new system. See MPolynomial.
subs for calling convention.
INPUT:
• args - arguments to be passed to MPolynomial.subs
• kwargs - keyword arguments to be passed to MPolynomial.subs
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system(); F
Polynomial Sequence with 40 Polynomials in 20 Variables
sage: F = F.subs(s); F
Polynomial Sequence with 40 Polynomials in 16 Variables
universe()
Return the polynomial ring all elements live in.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block')
sage: F,s = sr.polynomial_system()
sage: print(F.ring().repr_long())
Polynomial Ring
Base Ring : Finite Field of size 2
Size : 20 Variables
Block 0 : Ordering : deglex
Names : k100, k101, k102, k103, x100, x101, x102, x103, w100,
˓→w101, w102, w103, s000, s001, s002, s003
variables()
Return all variables present in this system. This tuple may or may not be equal to the generators of the ring
of this system.
EXAMPLES:
sage: sr = mq.SR(allow_zero_inversions=True)
sage: F,s = sr.polynomial_system()
sage: F.variables()[:10]
(k003, k002, k001, k000, s003, s002, s001, s000, w103, w102)
class sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_gf2(parts,
ring,
im-
mutable=False,
cr=False,
cr_str=None)
Bases: sage.rings.polynomial.multi_polynomial_sequence.
PolynomialSequence_generic
Polynomial Sequences over F2 .
eliminate_linear_variables(maxlength=+Infinity, skip=None, return_reductors=False,
use_polybori=False)
Return a new system where linear leading variables are eliminated if the tail of the polynomial has length
at most maxlength.
INPUT:
• maxlength - an optional upper bound on the number of monomials by which a variable is replaced.
If maxlength==+Infinity then no condition is checked. (default: +Infinity).
• skip - an optional callable to skip eliminations. It must accept two parameters and return either
True or False. The two parameters are the leading term and the tail of a polynomial (default:
None).
• return_reductors - if True the list of polynomials with linear leading terms which were used
for reduction is also returned (default: False).
• `use_polybori - if True then polybori.ll.eliminate is called. While this is typically
faster what is implemented here, it is less flexible (skip` is not supported) and may
increase the degree (default: ``False)
OUTPUT:
When return_reductors==True, then a pair of sequences of boolean polynomials are returned,
along with the promises that:
1. The union of the two sequences spans the same boolean ideal as the argument of the method
2. The second sequence only contains linear polynomials, and it forms a reduced groebner basis (they
all have pairwise distinct leading variables, and the leading variable of a polynomial does not occur
anywhere in other polynomials).
3. The leading variables of the second sequence do not occur anywhere in the first sequence (these
variables have been eliminated).
When return_reductors==False, only the first sequence is returned.
EXAMPLES:
If the input system is detected to be inconsistent then [1] is returned and the list of reductors is empty:
REFERENCES:
reduced()
If this sequence is (𝑓1 , ..., 𝑓𝑛 ) this method returns (𝑔1 , ..., 𝑔𝑠 ) such that:
• < 𝑓1 , ..., 𝑓𝑛 >=< 𝑔1 , ..., 𝑔𝑠 >
• 𝐿𝑇 (𝑔𝑖 )! = 𝐿𝑇 (𝑔𝑗 ) for all 𝑖! = 𝑗‘
• 𝐿𝑇 (𝑔𝑖 ) does not divide 𝑚 for all monomials 𝑚 of 𝑔1 , ..., 𝑔𝑖−1 , 𝑔𝑖+1 , ..., 𝑔𝑠
EXAMPLES:
We can force the use of exhaustive search if the optional package FES is present:
class sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_gf2e(parts,
ring,
im-
mutable=False,
cr=False,
cr_str=None)
Bases: sage.rings.polynomial.multi_polynomial_sequence.
PolynomialSequence_generic
PolynomialSequence over F2𝑒 , i.e extensions over F( 2).
weil_restriction()
Project this polynomial system to F2 .
That is, compute the Weil restriction of scalars for the variety corresponding to this polynomial system and
express it as a polynomial system over F2 .
EXAMPLES:
sage: sr = mq.SR(1,1,1,4,gf2=False)
sage: F,s = sr.polynomial_system(); F
Polynomial Sequence with 40 Polynomials in 20 Variables
sage: F2 = F.weil_restriction(); F2
Polynomial Sequence with 240 Polynomials in 80 Variables
sage.rings.polynomial.multi_polynomial_sequence.is_PolynomialSequence(F)
Return True if F is a PolynomialSequence.
INPUT:
• F - anything
EXAMPLES:
sage: is_PolynomialSequence(F)
True
This module implements specialized and optimized implementations for multivariate polynomials over many coeffi-
cient rings, via a shared library interface to SINGULAR. In particular, the following coefficient rings are supported by
this implementation:
• the rational numbers Q,
• the ring of integers Z,
• Z/𝑛Z for any integer 𝑛,
• finite fields F𝑝𝑛 for 𝑝 prime and 𝑛 > 0,
• and absolute number fields Q(𝑎).
AUTHORS:
The libSINGULAR interface was implemented by
• Martin Albrecht (2007-01): initial implementation
• Joel Mohler (2008-01): misc improvements, polishing
• Martin Albrecht (2008-08): added Q(𝑎) and Z support
• Simon King (2009-04): improved coercion
• Martin Albrecht (2009-05): added Z/𝑛Z support, refactoring
• Martin Albrecht (2009-06): refactored the code to allow better re-use
• Simon King (2011-03): Use a faster way of conversion from the base ring.
• Volker Braun (2011-06): Major cleanup, refcount singular rings, bugfixes.
EXAMPLES:
We show how to construct various multivariate polynomial rings:
sage: P.term_order()
Degree reverse lexicographic term order
(continues on next page)
sage: P.term_order()
Lexicographic term order
sage: z = QQ['z'].0
sage: K.<s> = NumberField(z^2 - 2)
sage: P.<x,y> = PolynomialRing(K, 2)
sage: 1/2*s*x^2 + 3/4*s
(1/2*s)*x^2 + (3/4*s)
We make a polynomial ring in one variable over a polynomial ring in two variables:
class sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular
Bases: sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base
Construct a multivariate polynomial ring subject to the following conditions:
INPUT:
• base_ring - base ring (must be either GF(q), ZZ, ZZ/nZZ, QQ or absolute number field)
• n - number of variables (must be at least 1)
• names - names of ring variables, may be string of list/tuple
• order - term order (default: degrevlex)
EXAMPLES:
sage: P.<x,y,z> = QQ[]
sage: P
Multivariate Polynomial Ring in x, y, z over Rational Field
sage: P.term_order()
Degree reverse lexicographic term order
sage: P.term_order()
Lexicographic term order
sage: z = QQ['z'].0
sage: K.<s> = NumberField(z^2 - 2)
sage: P.<x,y> = PolynomialRing(K, 2)
sage: 1/2*s*x^2 + 3/4*s
(1/2*s)*x^2 + (3/4*s)
sage: type(P)
<class 'sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_with_
˓→category'>
Element
alias of MPolynomial_libsingular
gen(n=0)
Returns the n-th generator of this multivariate polynomial ring.
INPUT:
• n – an integer >= 0
EXAMPLES:
sage: P = PolynomialRing(GF(127),1000,'x')
sage: P.gen(500)
x500
ideal(*gens, **kwds)
Create an ideal in this polynomial ring.
INPUT:
• *gens - list or tuple of generators (or several input arguments)
• coerce - bool (default: True); this must be a keyword argument. Only set it to False if you are
certain that each generator is already in the ring.
EXAMPLES:
monomial_all_divisors(t)
Return a list of all monomials that divide t.
Coefficients are ignored.
INPUT:
• t - a monomial
EXAMPLES:
monomial_lcm(f, g)
LCM for monomials. Coefficients are ignored.
INPUT:
• f - monomial
• g - monomial
EXAMPLES:
monomial_pairwise_prime(g, h)
Return True if h and g are pairwise prime. Both are treated as monomials.
Coefficients are ignored.
INPUT:
• h - monomial
• g - monomial
EXAMPLES:
monomial_quotient(f, g, coeff=False)
Return f/g, where both f and‘‘ g are treated as monomials.
Coefficients are ignored by default.
INPUT:
• f - monomial
• g - monomial
• coeff - divide coefficients as well (default: False)
EXAMPLES:
sage: P.monomial_quotient(3/2*x*y,x,coeff=True)
3/2*y
sage: P.monomial_quotient(2*x,3*x)
1
Warning: Assumes that the head term of f is a multiple of the head term of g and return the multipli-
cant m. If this rule is violated, funny things may happen.
monomial_reduce(f, G)
Try to find a g in G where g.lm() divides f. If found (flt,g) is returned, (0,0) otherwise, where
flt is f/g.lm().
It is assumed that G is iterable and contains only elements in this polynomial ring.
Coefficients are ignored.
INPUT:
• f - monomial
• G - list/set of mpolynomials
EXAMPLES:
ngens()
Returns the number of variables in this multivariate polynomial ring.
EXAMPLES:
class sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular
Bases: sage.rings.polynomial.multi_polynomial.MPolynomial
A multivariate polynomial implemented using libSINGULAR.
add_m_mul_q(m, q)
Return self + m*q, where m must be a monomial and q a polynomial.
INPUT:
• m - a monomial
• q - a polynomial
EXAMPLES:
sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: x.add_m_mul_q(y,z)
y*z + x
coefficient(degrees)
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
in degrees. 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)
EXAMPLES:
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.
AUTHOR:
• Joel B. Mohler (2007.10.31)
coefficients()
Return the nonzero coefficients of this polynomial in a list. The returned list is decreasingly ordered by
the term ordering of the parent.
EXAMPLES:
AUTHOR:
• Didier Deshommes
constant_coefficient()
Return the constant coefficient of this multivariate polynomial.
EXAMPLES:
degree(x=None, std_grading=False)
Return the maximal degree of this polynomial in x, where x must be one of the generators for the parent
of this polynomial.
INPUT:
• x - (default: None) a multivariate polynomial which is (or coerces to) a generator of the parent of
self. If x is None, return the total degree, which is the maximum degree of any monomial. Note that
a matrix term ordering alters the grading of the generators of the ring; see the tests below. To avoid
this behavior, use either exponents() for the exponents themselves, or the optional argument
std_grading=False.
OUTPUT: integer
EXAMPLES:
degrees()
Returns a tuple with the maximal degree of each variable in this polynomial. The list of degrees is ordered
by the order of the generators.
EXAMPLES:
dict()
Return a dictionary representing self. This dictionary is in the same format as the generic MPolynomial:
The dictionary consists of ETuple:coefficient pairs.
EXAMPLES:
divides(other)
Return True if this polynomial divides other.
EXAMPLES:
exponents(as_ETuples=True)
Return the exponents of the monomials appearing in this polynomial.
INPUT:
• as_ETuples - (default: True) if true returns the result as an list of ETuples otherwise returns
a list of tuples
EXAMPLES:
factor(proof=None)
Return the factorization of this polynomial.
INPUT:
• proof - ignored.
EXAMPLES:
Next we factor the same polynomial, but over the finite field of order 3.:
This shows that ticket trac ticket #2780 is fixed, i.e. that the unit part of the factorization is set correctly:
sage: x = var('x')
sage: K.<a> = NumberField(x^2 + 1)
sage: R.<y, z> = PolynomialRing(K)
sage: f = 2*y^2 + 2*z^2
sage: F = f.factor(); F.unit()
2
Another example:
sage: R.<x,y,z> = GF(32003)[]
sage: f = 9*(x-1)^2*(y+z)
sage: f.factor()
(9) * (y + z) * (x - 1)^2
Factorization for finite prime fields with characteristic > 229 is not supported
sage: q = 1073741789
sage: T.<aa, bb> = PolynomialRing(GF(q))
sage: f = aa^2 + 12124343*bb*aa + 32434598*bb^2
sage: f.factor()
Traceback (most recent call last):
...
NotImplementedError: Factorization of multivariate polynomials over prime
˓→fields with characteristic > 2^29 is not implemented.
Factorization over the integers is now supported, see trac ticket #17840:
The following examples used to give a Segmentation Fault, see trac ticket #12918 and trac ticket #13129:
sage: R.<x,y> = GF(2)[]
sage: f = x^6 + x^5 + y^5 + y^4
sage: f.factor()
x^6 + x^5 + y^5 + y^4
sage: f = x^16*y + x^10*y + x^9*y + x^6*y + x^5 + x*y + y^2
sage: f.factor()
x^16*y + x^10*y + x^9*y + x^6*y + x^5 + x*y + y^2
The following used to sometimes take a very long time or get stuck, see trac ticket #12846. These 100
iterations should take less than 1 second:
sage: K.<a> = GF(4)
sage: R.<x,y> = K[]
sage: f = (a + 1)*x^145*y^84 + (a + 1)*x^205*y^17 + x^32*y^112 + x^92*y^45
sage: for i in range(100):
....: assert len(f.factor()) == 4
˓→2*o^6-109350000*a^2*r^6*o^6+42282000*a^2*r^5*n*o^5-3406050*a^2*r^4*n^2*o^4-
˓→22457088*a*r^2*v*n^2*o^6+12150000*a^2*r^4*o^4-3132000*a^2*r^3*n*o^
˓→3+189225*a^2*r^2*n^2*o^2+2495232*a*v*n^2*o^4-450000*a^2*r^2*o^2+87000*a^
˓→2*r*n*o-4205*a^2*n^2
sage: len(factor(f))
4
˓→2*a^2*b^2 - b^4
sage: N.factor()
(-1) * (-a + b) * (a + b) * (-z^4*a + z^4*b - 4*z^3*a - 4*z^3*b + 6*z^2*a -
˓→6*z^2*b + 4*z*a + 4*z*b - a + b) * (z^4*a + z^4*b - 4*z^3*a + 4*z^3*b - 6*z^
sage: x = polygen(QQ)
sage: F.<u> = NumberField(x^3 - 2)
sage: R.<x,y,z> = F[]
sage: p = x^3 + (1+u)*y^3 + z^3
sage: q = p^3 * (x - y + z*u)
sage: gcd(p,q)
x^3 + (u + 1)*y^3 + z^3
gradient()
Return a list of partial derivatives of this polynomial, ordered by the variables of the parent.
EXAMPLES:
hamming_weight()
Return the number of non-zero coefficients of this polynomial.
This is also called weight, hamming_weight() or sparsity.
EXAMPLES:
sage: f.hamming_weight()
101
integral(var)
Integrates this polynomial with respect to the provided variable.
One requires that Q is contained in the ring.
INPUT:
• variable - the integral is taken with respect to variable
EXAMPLES:
sage: s = x+y
sage: s.integral(x)+x
1/2*x^2 + x*y + x
sage: s.integral(x)*s
1/2*x^3 + 3/2*x^2*y + x*y^2
inverse_of_unit()
Return the inverse of this polynomial if it is a unit.
EXAMPLES:
sage: R(1/2).inverse_of_unit()
2
is_constant()
Return True if this polynomial is constant.
EXAMPLES:
is_homogeneous()
Return True if this polynomial is homogeneous.
EXAMPLES:
is_monomial()
Return True if this polynomial is a monomial. A monomial is defined to be a product of generators with
coefficient 1.
EXAMPLES:
is_squarefree()
Return True if this polynomial is square free.
EXAMPLES:
is_univariate()
Return True if self is a univariate polynomial, that is if self contains only one variable.
EXAMPLES:
is_zero()
Return True if this polynomial is zero.
EXAMPLES:
lc()
Leading coefficient of this polynomial with respect to the term order of self.parent().
EXAMPLES:
sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: f = 3*x^1*y^2 + 2*y^3*z^4
sage: f.lc()
3
lcm(g)
Return the least common multiple of self and 𝑔.
EXAMPLES:
sage: w = var('w')
sage: r.<x,y> = PolynomialRing(NumberField(w^4 + 1, 'a'), 2)
sage: a = r.base_ring().0
sage: f = (a^2+a)*x^2*y + (a^4+a^3+a)*y + a^5
sage: f.lcm(x^4)
(a^2 + a)*x^6*y + (a^3 + a - 1)*x^4*y + (-a)*x^4
lift(I)
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.
A ValueError exception is raised if g (== self) does not belong to I.
EXAMPLES:
lm()
Returns the lead monomial of self with respect to the term order of self.parent(). In Sage a mono-
mial is a product of variables in some power without a coefficient.
EXAMPLES:
sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: f = x^1*y^2 + y^3*z^4
sage: f.lm()
x*y^2
sage: f = x^3*y^2*z^4 + x^3*y^2*z^1
sage: f.lm()
x^3*y^2*z^4
sage: R.<x,y,z>=PolynomialRing(QQ,3,order='deglex')
sage: f = x^1*y^2*z^3 + x^3*y^2*z^0
sage: f.lm()
x*y^2*z^3
sage: f = x^1*y^2*z^4 + x^1*y^1*z^5
sage: f.lm()
x*y^2*z^4
sage: R.<x,y,z>=PolynomialRing(GF(127),3,order='degrevlex')
sage: f = x^1*y^5*z^2 + x^4*y^1*z^3
sage: f.lm()
x*y^5*z^2
sage: f = x^4*y^7*z^1 + x^4*y^2*z^3
sage: f.lm()
x^4*y^7*z
lt()
Leading term of this polynomial. In Sage a term is a product of variables in some power and a coefficient.
EXAMPLES:
sage: R.<x,y,z>=PolynomialRing(GF(7),3,order='lex')
sage: f = 3*x^1*y^2 + 2*y^3*z^4
sage: f.lt()
3*x*y^2
monomial_coefficient(mon)
Return the coefficient in the base ring of the monomial mon in self, where mon must have the same
parent as self.
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:
monomials()
Return the list of monomials in self. The returned list is decreasingly ordered by the term ordering of
self.parent().
EXAMPLES:
number_of_terms()
Return the number of non-zero coefficients of this polynomial.
sage: f.hamming_weight()
101
numerator()
Return a numerator of self computed as self * self.denominator()
If the base_field of self is the Rational Field then the numerator is a polynomial whose base_ring is the
Integer Ring, this is done for compatibility to the univariate case.
Warning: This is not the numerator of the rational function defined by self, which would always be
self since self is a polynomial.
EXAMPLES:
First we compute the numerator of a polynomial with integer coefficients, which is of course self.
sage: K=QQ['x,y']
sage: f=K.random_element()
sage: f.numerator() / f.denominator() == f
True
nvariables()
Return the number variables in this polynomial.
EXAMPLES:
quo_rem(right)
Returns quotient and remainder of self and right.
EXAMPLES:
reduce(I)
Return a remainder of this polynomial modulo the polynomials in I.
INPUT:
• I - an ideal or a list/set/iterable of polynomials.
OUTPUT:
A polynomial r such that:
• self - r is in the ideal generated by I.
• No term in r is divisible by any of the leading monomials of I.
The result r is canonical if:
• I is an ideal, and Sage can compute a Groebner basis of it.
• I is a list/set/iterable that is a (strong) Groebner basis for the term order of self. (A strong Groebner
basis is such that for every leading term t of the ideal generated by I, there exists an element g of I
such that the leading term of g divides t.)
The result r is implementation-dependent (and possibly order-dependent) otherwise. If I is an ideal and
no Groebner basis can be computed, its list of generators I.gens() is used for the reduction.
EXAMPLES:
Z is also supported.
sage: f = 3*x
sage: f.reduce([2*x,y])
3*x
resultant(other, variable=None)
Compute the resultant of this polynomial and the first argument with respect to the variable given as the
second argument.
If a second argument is not provide the first variable of the parent is chosen.
INPUT:
• other - polynomial
• variable - optional variable (default: None)
EXAMPLES:
sub_m_mul_q(m, q)
Return self - m*q, where m must be a monomial and q a polynomial.
INPUT:
• m - a monomial
• q - a polynomial
EXAMPLES:
sage: P.<x,y,z>=PolynomialRing(QQ,3)
sage: x.sub_m_mul_q(y,z)
-y*z + x
subs(fixed=None, **kw)
Fixes some given variables in a given multivariate polynomial and returns the changed multivariate poly-
nomials. The polynomial itself is not affected. The variable,value pairs for fixing are to be provided as
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, but should be much faster if only few variables are to be fixed.
INPUT:
• fixed - (optional) dict with variable:value pairs
• **kw - names parameters
EXAMPLES:
sage: R.<x,y> = QQ[]
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
sage: f.subs(x=5)
25*y^2 + y + 30
sage: f.subs(x=1/y)
(y^2 + y + 1)/y
sage: f.subs({x:1/y})
(y^2 + y + 1)/y
total_degree(std_grading=False)
Return the total degree of self, which is the maximum degree of all monomials in self.
EXAMPLES:
sage: R.<x,y,z> = QQ[]
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
(continues on next page)
univariate_polynomial(R=None)
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 is_univariate() method. The new Polynomial is over the same base ring as the given
MPolynomial and in the variable x if no ring R is provided.
EXAMPLES:
sage: g = R(1)
sage: h = g.univariate_polynomial(); h
1
sage: h.parent()
Univariate Polynomial Ring in x over Rational Field
variable(i=0)
Return the i-th variable occurring in self. The index i is the index in self.variables().
EXAMPLES:
variables()
Return a tuple of all variables occurring in self.
EXAMPLES:
sage.rings.polynomial.multi_polynomial_libsingular.unpickle_MPolynomialRing_libsingular(base
nam
term
inverse function for MPolynomialRing_libsingular.__reduce__
EXAMPLES:
sage.rings.polynomial.multi_polynomial_libsingular.unpickle_MPolynomial_libsingular(R,
d)
Deserialize an MPolynomial_libsingular object
INPUT:
• R - the base ring
• d - a Python dictionary as returned by MPolynomial_libsingular.dict()
EXAMPLES:
3.1.9 Direct low-level access to SINGULAR’s Groebner basis engine via libSINGU-
LAR.
AUTHOR:
• Martin Albrecht (2007-08-08): initial version
EXAMPLES:
We compute a Groebner basis for cyclic 6, which is a standard benchmark and test ideal:
sage.rings.polynomial.multi_polynomial_ideal_libsingular.interred_libsingular(I)
SINGULAR’s interred() command.
INPUT:
• I – a Sage ideal
EXAMPLES:
sage.rings.polynomial.multi_polynomial_ideal_libsingular.kbase_libsingular(I)
SINGULAR’s kbase() algorithm.
INPUT:
• I – a groebner basis of an ideal
OUTPUT:
Computes a vector space basis (consisting of monomials) of the quotient ring by the ideal, resp. of a free module
by the module, in case it is finite dimensional and if the input is a standard basis with respect to the ring ordering.
If the input is not a standard basis, the leading terms of the input are used and the result may have no meaning.
EXAMPLES:
sage.rings.polynomial.multi_polynomial_ideal_libsingular.slimgb_libsingular(I)
SINGULAR’s slimgb() algorithm.
INPUT:
• I – a Sage ideal
sage.rings.polynomial.multi_polynomial_ideal_libsingular.std_libsingular(I)
SINGULAR’s std() algorithm.
INPUT:
• I – a Sage ideal
This module provides an implementation of the underlying arithmetic for multi-variate polynomial rings using Python
dicts.
This class is not meant for end users, but instead for implementing multivariate polynomial rings over a completely
general base. It does not do strong type checking or have parents, etc. For speed, it has been implemented in Cython.
The functions in this file use the ‘dictionary representation’ of multivariate polynomials
{(e1,...,er):c1,...} <-> c1*x1^e1*...*xr^er+...,
which we call a polydict. The exponent tuple (e1,...,er) in this representation is an instance of the class
ETuple. This class behaves like a normal Python tuple but also offers advanced access methods for sparse monomials
like positions of non-zero exponents etc.
AUTHORS:
• William Stein
• David Joyner
• Martin Albrecht (ETuple)
• Joel B. Mohler (2008-03-17) – ETuple rewrite as sparse C array
class sage.rings.polynomial.polydict.ETuple
Bases: object
Representation of the exponents of a polydict monomial. If (0,0,3,0,5) is the exponent tuple of x_2^3*x_4^5
then this class only stores {2:3, 4:5} instead of the full tuple. This sparse information may be obtained by
provided methods.
The index/value data is all stored in the _data C int array member variable. For the example above, the C array
would contain 2,3,4,5. The indices are interlaced with the values.
This data structure is very nice to work with for some functions implemented in this class, but tricky for others.
One reason that I really like the format is that it requires a single memory allocation for all of the values. A hash
table would require more allocations and presumably be slower. I didn’t benchmark this question (although,
there is no question that this is much faster than the prior use of python dicts).
combine_to_positives(other)
Given a pair of ETuples (self, other), returns a triple of ETuples (a, b, c) so that self = a + b, other = a + c
and b and c have all positive entries.
EXAMPLES:
common_nonzero_positions(other, sort=False)
Returns an optionally sorted list of non zero positions either in self or other, i.e. the only positions that
need to be considered for any vector operation.
EXAMPLES:
dotprod(other)
Return the dot product of this tuple by other.
EXAMPLES:
eadd(other)
Vector addition of self with other.
EXAMPLES:
eadd_p(other, pos)
Add other to self at position pos.
EXAMPLES:
emax(other)
Vector of maximum of components of self and other.
EXAMPLES:
emin(other)
Vector of minimum of components of self and other.
EXAMPLES:
emul(factor)
Scalar Vector multiplication of self.
EXAMPLES:
escalar_div(n)
Divide each exponent by n.
EXAMPLES:
sage: ETuple([1,5,2]).escalar_div(0)
Traceback (most recent call last):
...
ZeroDivisionError
esub(other)
Vector subtraction of self with other.
EXAMPLES:
sage: from sage.rings.polynomial.polydict import ETuple
sage: e = ETuple([1,0,2])
sage: f = ETuple([0,1,1])
sage: e.esub(f)
(1, -1, 1)
is_constant()
Return if all exponents are zero in the tuple.
EXAMPLES:
sage: from sage.rings.polynomial.polydict import ETuple
sage: e = ETuple([1,0,2])
sage: e.is_constant()
False
sage: e = ETuple([0,0])
sage: e.is_constant()
True
is_multiple_of(n)
Test whether each entry is a multiple of n.
EXAMPLES:
sage: from sage.rings.polynomial.polydict import ETuple
sage: ETuple([0,0]).is_multiple_of(3)
True
sage: ETuple([0,3,12,0,6]).is_multiple_of(3)
True
sage: ETuple([0,0,2]).is_multiple_of(3)
False
nonzero_positions(sort=False)
Return the positions of non-zero exponents in the tuple.
INPUT:
• sort – (default: False) if True a sorted list is returned; if False an unsorted list is returned
EXAMPLES:
sage: from sage.rings.polynomial.polydict import ETuple
sage: e = ETuple([1,0,2])
sage: e.nonzero_positions()
[0, 2]
nonzero_values(sort=True)
Return the non-zero values of the tuple.
INPUT:
• sort – (default: True) if True the values are sorted by their indices; otherwise the values are
returned unsorted
EXAMPLES:
reversed()
Return the reversed ETuple of self.
EXAMPLES:
sparse_iter()
Iterator over the elements of self where the elements are returned as (i, e) where i is the position of
e in the tuple.
EXAMPLES:
unweighted_degree()
Return the sum of entries.
ASSUMPTION:
All entries are non-negative.
EXAMPLES:
class sage.rings.polynomial.polydict.ETupleIter
Bases: object
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.polynomial.polydict.PolyDict
Bases: object
INPUT:
• pdict – dict or list, which represents a multi-variable polynomial with the distribute representation (a
copy is not made)
• zero – (optional) zero in the base ring
• force_int_exponents – bool (optional) arithmetic with int exponents is much faster than some of
the alternatives, so this is True by default.
• force_etuples – bool (optional) enforce that the exponent tuples are instances of ETuple class
EXAMPLES:
coefficient(mon)
Return a polydict that defines a polynomial in 1 less number of variables that gives the coefficient of mon
in this polynomial.
The coefficient is defined as follows. If f is this polynomial, then the coefficient is the sum T/mon where
the sum is over terms T in f that are exactly divisible by mon.
coefficients()
Return the coefficients of self.
EXAMPLES:
degree(x=None)
dict()
Return a copy of the dict that defines self. It is safe to change this. For a reference, use dictref.
EXAMPLES:
exponents()
Return the exponents of self.
EXAMPLES:
homogenize(var)
is_homogeneous()
latex(vars, atomic_exponents=True, atomic_coefficients=True, sortkey=None)
Return a nice polynomial latex representation of this PolyDict, where the vars are substituted in.
INPUT:
• vars – list
• atomic_exponents – bool (default: True)
• atomic_coefficients – bool (default: True)
EXAMPLES:
When atomic_exponents is False, the exponents are surrounded in parenthesis, since ^ has such high
precedence:
lcmt(greater_etuple)
Provides functionality of lc, lm, and lt by calling the tuple compare function on the provided term order T.
INPUT:
• greater_etuple – a term order
list()
Return a list that defines self. It is safe to change this.
EXAMPLES:
max_exp()
Returns an ETuple containing the maximum exponents appearing. If there are no terms at all in the
PolyDict, it returns None.
The nvars parameter is necessary because a PolyDict doesn’t know it from the data it has (and an empty
PolyDict offers no clues).
EXAMPLES:
min_exp()
Returns an ETuple containing the minimum exponents appearing. If there are no terms at all in the Poly-
Dict, it returns None.
The nvars parameter is necessary because a PolyDict doesn’t know it from the data it has (and an empty
PolyDict offers no clues).
EXAMPLES:
monomial_coefficient(mon)
INPUT:
a PolyDict with a single key
EXAMPLES:
When atomic_exponents is False, the exponents are surrounded in parenthesis, since ^ has such high
precedence.
We check to make sure that when we are in characteristic two, we don’t put negative signs on the genera-
tors.
polynomial_coefficient(degrees)
Return a polydict that defines the coefficient in the current polynomial viewed as a tower of polynomial
extensions.
INPUT:
• degrees – a list of degree restrictions; list elements are None if the variable in that position should
be unrestricted
EXAMPLES:
sage: O = TermOrder()
sage: p1.rich_compare(p2, op_LT, O.sortkey)
True
scalar_lmult(s)
Left Scalar Multiplication
EXAMPLES:
sage: f = PolyDict({(2,3):x})
sage: f.scalar_lmult(y)
PolyDict with representation {(2, 3): y*x}
sage: f = PolyDict({(2,3):2, (1,2):3, (2,1):4})
sage: f.scalar_lmult(-2)
PolyDict with representation {(1, 2): -6, (2, 1): -8, (2, 3): -4}
sage: f.scalar_lmult(RIF(-1,1))
PolyDict with representation {(1, 2): 0.?e1, (2, 1): 0.?e1, (2, 3): 0.?e1}
scalar_rmult(s)
Right Scalar Multiplication
EXAMPLES:
sage: f = PolyDict({(2,3):x})
sage: f.scalar_rmult(y)
PolyDict with representation {(2, 3): x*y}
sage: f = PolyDict({(2,3):2, (1,2):3, (2,1):4})
sage: f.scalar_rmult(-2)
PolyDict with representation {(1, 2): -6, (2, 1): -8, (2, 3): -4}
sage: f.scalar_rmult(RIF(-1,1))
PolyDict with representation {(1, 2): 0.?e1, (2, 1): 0.?e1, (2, 3): 0.?e1}
term_lmult(exponent, s)
Return this element multiplied by s on the left and with exponents shifted by exponent.
INPUT:
• exponent – a ETuple
• s – a scalar
EXAMPLES:
term_rmult(exponent, s)
Return this element multiplied by s on the right and with exponents shifted by exponent.
INPUT:
• exponent – a ETuple
• s – a scalar
EXAMPLES:
total_degree()
valuation(x=None)
sage.rings.polynomial.polydict.make_ETuple(data, length)
sage.rings.polynomial.polydict.make_PolyDict(data)
This implementation was provided at trac ticket #26243 and is supposed to be a way out when Singular fails with an
int overflow, which will regularly be the case in any example with more than 34 variables.
class sage.rings.polynomial.hilbert.Node
Bases: object
A node of a binary tree
It has slots for data that allow to recursively compute the first Hilbert series of a monomial ideal.
sage.rings.polynomial.hilbert.first_hilbert_series(I, grading=None, re-
turn_grading=False)
Return the first Hilbert series of the given monomial ideal.
INPUT:
• I – a monomial ideal (possibly defined in singular)
• grading – (optional) a list or tuple of integers used as degree weights
• return_grading – (default: False) whether to return the grading
OUTPUT:
A univariate polynomial, namely the first Hilbert function of I, and if return_grading==True also the
grading used to compute the series.
EXAMPLES:
sage.rings.polynomial.hilbert.hilbert_poincare_series(I, grading=None)
Return the Hilbert Poincaré series of the given monomial ideal.
INPUT:
• I – a monomial ideal (possibly defined in Singular)
• grading – (optional) a tuple of degree weights
EXAMPLES:
sage: J.hilbert_numerator(algorithm='singular')
Traceback (most recent call last):
...
RuntimeError: error in Singular function call 'hilb':
int overflow in hilb 1
sage: R = QQ['x']['y']['s','t']['X']
sage: from sage.rings.polynomial.flatten import FlatteningMorphism
(continues on next page)
˓→Rational Field
Authors:
Vincent Delecroix, Ben Hutz (July 2016): initial implementation
class sage.rings.polynomial.flatten.FlatteningMorphism(domain)
Bases: sage.categories.morphism.Morphism
EXAMPLES:
sage: R = QQ['a','b']['x','y','z']['t1','t2']
sage: from sage.rings.polynomial.flatten import FlatteningMorphism
sage: f = FlatteningMorphism(R)
sage: f.codomain()
Multivariate Polynomial Ring in a, b, x, y, z, t1, t2 over Rational Field
sage: p = R('(a+b)*x + (a^2-b)*t2*(z+y)')
sage: p
((a^2 - b)*y + (a^2 - b)*z)*t2 + (a + b)*x
sage: f(p)
a^2*y*t2 + a^2*z*t2 - b*y*t2 - b*z*t2 + a*x + b*x
sage: f(p).parent()
Multivariate Polynomial Ring in a, b, x, y, z, t1, t2 over Rational Field
section()
Inverse of this flattening morphism.
EXAMPLES:
sage: R = QQ['a','b','c']['x','y','z']
sage: from sage.rings.polynomial.flatten import FlatteningMorphism
sage: h = FlatteningMorphism(R)
sage: h.section()
Unflattening morphism:
From: Multivariate Polynomial Ring in a, b, c, x, y, z over Rational Field
To: Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial
˓→Ring in a, b, c over Rational Field (continues on next page)
sage: R = ZZ['a']['b']['c']
sage: from sage.rings.polynomial.flatten import FlatteningMorphism
sage: FlatteningMorphism(R).section()
Unflattening morphism:
From: Multivariate Polynomial Ring in a, b, c over Integer Ring
To: Univariate Polynomial Ring in c over Univariate Polynomial Ring in b
˓→over Univariate Polynomial Ring in a over Integer Ring
class sage.rings.polynomial.flatten.SpecializationMorphism(domain, D)
Bases: sage.categories.morphism.Morphism
Morphisms to specialize parameters in (stacked) polynomial rings
EXAMPLES:
sage: xi(a*(x*z+y^2)*u+b*v*u*(x*z+y^2)*y^2*c+c*y^2*z^2)
2*v*c*y^4 + c*y^2*z^2 + y^2
sage: R = QQ['c','x','y','z']
sage: S = QQ['c']['x','y','z']
sage: from sage.rings.polynomial.flatten import UnflatteningMorphism
sage: f = UnflatteningMorphism(R, S)
sage: g = f(R('x^2 + c*y^2 - z^2'));g
x^2 + c*y^2 - z^2
sage: g.parent()
Multivariate Polynomial Ring in x, y, z over Univariate Polynomial Ring in c over
˓→Rational Field
3.1.13 Monomials
sage.rings.monomials.monomials(v, n)
Given two lists v and n, of exactly the same length, return all monomials in the elements of v, where variable i
(i.e., v[i]) in the monomial appears to degree strictly less than n[i].
INPUT:
• v – list of ring elements
• n – list of integers
EXAMPLES:
˓→4*y^4]
This module lists classical invariants and covariants of homogeneous polynomials (also called algebraic forms) under
the action of the special linear group. That is, we are dealing with polynomials of degree 𝑑 in 𝑛 variables. The special
linear group 𝑆𝐿(𝑛, C) acts on the variables (𝑥1 , . . . , 𝑥𝑛 ) linearly,
The linear action on the variables transforms a polynomial 𝑝 generally into a different polynomial 𝑔𝑝. We can think of
it as an action on the space of coefficients in 𝑝. An invariant is a polynomial in the coefficients that is invariant under
this action. A covariant is a polynomial in the coefficients and the variables (𝑥1 , . . . , 𝑥𝑛 ) that is invariant under the
combined action.
For example, the binary quadratic 𝑝(𝑥, 𝑦) = 𝑎𝑥2 + 𝑏𝑥𝑦 + 𝑐𝑦 2 has as its invariant the discriminant 𝑑𝑖𝑠𝑐(𝑝) = 𝑏2 − 4𝑎𝑐.
This means that for any 𝑆𝐿(2, C) coordinate change
(︂ ′ )︂ (︂ )︂ (︂ )︂
𝑥 𝛼 𝛽 𝑥
= 𝛼𝛿 − 𝛽𝛾 = 1
𝑦′ 𝛾 𝛿 𝑦
To use this module, you should use the factory object invariant_theory. For example, take the quartic:
One invariant of a quartic is known as the Eisenstein D-invariant. Since it is an invariant, it is a polynomial in the
coefficients (which are integers in this example):
sage: quartic.EisensteinD()
1
One example of a covariant of a quartic is the so-called g-covariant (actually, the Hessian). As with all covariants, it is
a polynomial in 𝑥, 𝑦 and the coefficients:
sage: quartic.g_covariant()
-x^2*y^2
As usual, use tab completion and the online help to discover the implemented invariants and covariants.
In general, the variables of the defining polynomial cannot be guessed. For example, the zero polynomial can be
thought of as a homogeneous polynomial of any degree. Also, since we also want to allow polynomial coefficients we
cannot just take all variables of the polynomial ring as the variables of the form. This is why you will have to specify
the variables explicitly if there is any potential ambiguity. For example:
Finally, it is often convenient to use inhomogeneous polynomials where it is understood that one wants to homogenize
them. This is also supported, just define the form with an inhomogeneous polynomial and specify one less variable:
REFERENCES:
AUTHORS:
coefficients()
Alias for coeffs().
See the documentation for coeffs() for details.
EXAMPLES:
form()
Return the defining polynomial.
OUTPUT:
The polynomial used to define the algebraic form.
EXAMPLES:
homogenized(var=’h’)
Return form as defined by a homogeneous polynomial.
INPUT:
• var – either a variable name, variable index or a variable (default: 'h').
OUTPUT:
The same algebraic form, but defined by a homogeneous polynomial.
EXAMPLES:
polynomial()
Return the defining polynomial.
OUTPUT:
The polynomial used to define the algebraic form.
EXAMPLES:
transformed(g)
Return the image under a linear transformation of the variables.
INPUT:
• g – a 𝐺𝐿(𝑛, C) matrix or a dictionary with the variables as keys. A matrix is used to define the
linear transformation of homogeneous variables, a dictionary acts by substitution of the variables.
OUTPUT:
A new instance of a subclass of AlgebraicForm obtained by replacing the variables of the homoge-
neous polynomial by their image under g.
EXAMPLES:
EisensteinD()
One of the Eisenstein invariants of a binary quartic.
OUTPUT:
The Eisenstein D-invariant of the quartic.
𝑓 (𝑥) = 𝑎0 𝑥41 + 4𝑎1 𝑥0 𝑥31 + 6𝑎2 𝑥20 𝑥21 + 4𝑎3 𝑥30 𝑥1 + 𝑎4 𝑥40
⇒ 𝐷(𝑓 ) = 𝑎0 𝑎4 + 3𝑎22 − 4𝑎1 𝑎3
EXAMPLES:
EisensteinE()
One of the Eisenstein invariants of a binary quartic.
OUTPUT:
The Eisenstein E-invariant of the quartic.
𝑓 (𝑥) = 𝑎0 𝑥41 + 4𝑎1 𝑥0 𝑥31 + 6𝑎2 𝑥20 𝑥21 + 4𝑎3 𝑥30 𝑥1 + 𝑎4 𝑥40
⇒ 𝐸(𝑓 ) = 𝑎0 𝑎23 + 𝑎21 𝑎4 − 𝑎0 𝑎2 𝑎4 − 2𝑎1 𝑎2 𝑎3 + 𝑎32
EXAMPLES:
coeffs()
The coefficients of a binary quartic.
Given
g_covariant()
The g-covariant of a binary quartic.
OUTPUT:
The g-covariant of the quartic.
𝑓 (𝑥) = 𝑎0 𝑥41 + 4𝑎1 𝑥0 𝑥31 + 6𝑎2 𝑥20 𝑥21 + 4𝑎3 𝑥30 𝑥1 + 𝑎4 𝑥40
1 (︁ 𝜕 2 𝑓 )︁
⇒ 𝐷(𝑓 ) =
144 𝜕𝑥𝜕𝑥
EXAMPLES:
h_covariant()
The h-covariant of a binary quartic.
OUTPUT:
The h-covariant of the quartic.
𝑓 (𝑥) = 𝑎0 𝑥41 + 4𝑎1 𝑥0 𝑥31 + 6𝑎2 𝑥20 𝑥21 + 4𝑎3 𝑥30 𝑥1 + 𝑎4 𝑥40
1 (︁ 𝜕 2 𝑓 )︁
⇒ 𝐷(𝑓 ) =
144 𝜕𝑥𝜕𝑥
EXAMPLES:
sage: g = inv.g_covariant()
sage: h == 1/8 * (p.derivative(x)*g.derivative(y)-p.derivative(y)*g.
˓→derivative(x))
True
monomials()
List the basis monomials in the form.
OUTPUT:
A tuple of monomials. They are in the same order as coeffs().
EXAMPLES:
scaled_coeffs()
The coefficients of a binary quartic.
Given
𝑓 (𝑥) = 𝑎0 𝑥41 + 4𝑎1 𝑥0 𝑥31 + 6𝑎2 𝑥20 𝑥21 + 4𝑎3 𝑥30 𝑥1 + 𝑎4 𝑥40
OUTPUT:
The 𝐴-invariant of the binary quintic.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
B_invariant()
Return the invariant 𝐵 of a binary quintic.
OUTPUT:
The 𝐵-invariant of the binary quintic.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
C_invariant()
Return the invariant 𝐶 of a binary quintic.
OUTPUT:
The 𝐶-invariant of the binary quintic.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
H_covariant(as_form=False)
Return the covariant 𝐻 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝐻-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.H_covariant(as_form=True)
Binary sextic given by ...
R_invariant()
Return the invariant 𝑅 of a binary quintic.
OUTPUT:
The 𝑅-invariant of the binary quintic.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
T_covariant(as_form=False)
Return the covariant 𝑇 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝑇 -covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.T_covariant(as_form=True)
Binary nonic given by ...
alpha_covariant(as_form=False)
Return the covariant 𝛼 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝛼-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.alpha_covariant(as_form=True)
Binary monic given by ...
arithmetic_invariants()
Return a set of generating arithmetic invariants of a binary quintic.
An arithmetic invariants is an invariant whose coefficients are integers for a general binary quintic. They
are linear combinations of the Clebsch invariants, such that they still generate the ring of invariants.
OUTPUT:
𝐼4 = 2−1 · 54 · 𝐴
𝐼8 = 55 · (2−1 · 47 · 𝐴2 − 22 · 𝐵)
𝐼12 = 510 · (2−1 · 3 · 𝐴3 − 25 · 3−1 · 𝐶)
𝐼18 = 28 · 3−1 · 515 · 𝑅
We can check that the coefficients of the invariants have no common divisor for a general quintic form:
beta_covariant(as_form=False)
Return the covariant 𝛽 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝛽-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.beta_covariant(as_form=True)
Binary monic given by ...
clebsch_invariants(as_tuple=False)
Return the invariants of a binary quintic as described by Clebsch.
The following invariants are returned: 𝐴, 𝐵, 𝐶 and 𝑅.
OUTPUT:
The Clebsch invariants of the binary quintic.
EXAMPLES:
sage: R.<x0, x1> = QQ[]
sage: p = 2*x1^5 + 4*x1^4*x0 + 5*x1^3*x0^2 + 7*x1^2*x0^3 - 11*x1*x0^4 + x0^5
sage: quintic = invariant_theory.binary_quintic(p, x0, x1)
sage: quintic.clebsch_invariants()
{'A': -276032/625,
'B': 4983526016/390625,
'C': -247056495846408/244140625,
'R': -148978972828696847376/30517578125}
sage: quintic.clebsch_invariants(as_tuple=True)
(-276032/625,
4983526016/390625,
-247056495846408/244140625,
-148978972828696847376/30517578125)
coeffs()
The coefficients of a binary quintic.
Given
delta_covariant(as_form=False)
Return the covariant 𝛿 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝛿-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.delta_covariant(as_form=True)
Binary monic given by ...
gamma_covariant(as_form=False)
Return the covariant 𝛾 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝛾-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.gamma_covariant(as_form=True)
Binary monic given by ...
i_covariant(as_form=False)
Return the covariant 𝑖 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝑖-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.i_covariant(as_form=True)
Binary quadratic given by ...
j_covariant(as_form=False)
Return the covariant 𝑗 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝑗-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.j_covariant(as_form=True)
Binary cubic given by ...
monomials()
List the basis monomials of the form.
This functions lists a basis of monomials of the space of binary quintics of which this form is an element.
OUTPUT: A tuple of monomials. They are in the same order as coeffs().
EXAMPLES:
scaled_coeffs()
The coefficients of a binary quintic.
Given
𝑓 (𝑥) = 𝑎0 𝑥51 + 5𝑎1 𝑥0 𝑥41 + 10𝑎2 𝑥20 𝑥31 + 10𝑎3 𝑥30 𝑥21 + 5𝑎4 𝑥40 𝑥1 + 𝑎5 𝑥51
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + 5*a1*x1^4*x0 + 10*a2*x1^3*x0^2 + 10*a3*x1^2*x0^3 +
˓→5*a4*x1*x0^4 + a5*x0^5
tau_covariant(as_form=False)
Return the covariant 𝜏 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝜏 -covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.tau_covariant(as_form=True)
Binary quadratic given by ...
theta_covariant(as_form=False)
Return the covariant 𝜃 of a binary quintic.
INPUT:
• as_form – if as_form is False, the result will be returned as polynomial (default). If it is True
the result is returned as an object of the class AlgebraicForm.
OUTPUT:
The 𝜃-covariant of the binary quintic as polynomial or as binary form.
EXAMPLES:
sage: R.<a0, a1, a2, a3, a4, a5, x0, x1> = QQ[]
sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 +
˓→a5*x0^5
sage: quintic.theta_covariant(as_form=True)
Binary quadratic given by ...
ring()
Return the polynomial ring.
OUTPUT:
A polynomial ring. This is where the defining polynomial(s) live. Note that the polynomials may be
homogeneous or inhomogeneous, depending on how the user constructed the object.
EXAMPLES:
variables()
Return the variables of the form.
OUTPUT:
A tuple of variables. If inhomogeneous notation is used for the defining polynomial then the last entry will
be None.
EXAMPLES:
sage: R.<x,y,t> = QQ[]
sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y])
sage: quartic.variables()
(x, y)
class sage.rings.invariants.invariant_theory.InvariantTheoryFactory
Bases: object
Factory object for invariants of multilinear forms.
EXAMPLES:
sage: R.<x,y,z> = QQ[]
sage: invariant_theory.ternary_cubic(x^3+y^3+z^3)
Ternary cubic with coefficients (1, 1, 1, 0, 0, 0, 0, 0, 0, 0)
binary_quadratic(quadratic, *args)
Invariant theory of a quadratic in two variables.
INPUT:
• quadratic – a quadratic form.
• x, y – the homogeneous variables. If y is None, the quadratic is assumed to be inhomogeneous.
REFERENCES:
• Wikipedia article Invariant_of_a_binary_form
EXAMPLES:
sage: R.<x,y> = QQ[]
sage: invariant_theory.binary_quadratic(x^2+y^2)
Binary quadratic with coefficients (1, 1, 0)
𝑗𝑓 3 − 𝑔𝑓 2 𝑖 + 4𝑔 3 + ℎ2 = 0
If only one variable is given, the quintic is the homogenisation of the provided polynomial:
If the polynomial has three or more variables, the variables should be specified:
sage: type(quintic)
<class 'sage.rings.invariants.invariant_theory.BinaryQuintic'>
inhomogeneous_quadratic_form(polynomial, *args)
Invariants of an inhomogeneous quadratic form.
INPUT:
• polynomial – an inhomogeneous quadratic form.
• *args – the variables as multiple arguments, or as a single list/tuple.
EXAMPLES:
quadratic_form(polynomial, *args)
Invariants of a homogeneous quadratic form.
INPUT:
• polynomial – a homogeneous or inhomogeneous quadratic form.
• *args – the variables as multiple arguments, or as a single list/tuple. If the last argument is None,
the cubic is assumed to be inhomogeneous.
EXAMPLES:
If some of the ring variables are to be treated as coefficients you need to specify the polynomial variables:
quaternary_quadratic(quadratic, *args)
Invariant theory of a quadratic in four variables.
INPUT:
• quadratic – a quadratic form.
• w, x, y, z – the homogeneous variables. If z is None, the quadratic is assumed to be inhomogeneous.
REFERENCES:
EXAMPLES:
coeffs()
The coefficients of a quadratic form.
Given
∑︁ ∑︁
𝑓 (𝑥) = 𝑎𝑖 𝑥2𝑖 + 𝑎𝑗𝑘 𝑥𝑗 𝑥𝑘
0≤𝑖<𝑛 0≤𝑗<𝑘<𝑛
discriminant()
Return the discriminant of the quadratic form.
Up to an overall constant factor, this is just the determinant of the defining matrix, see matrix(). For a
quadratic form in 𝑛 variables, the overall constant is 2𝑛−1 if 𝑛 is odd and (−1)𝑛/2 2𝑛 if 𝑛 is even.
EXAMPLES:
dual()
Return the dual quadratic form.
OUTPUT:
A new quadratic form (with the same number of variables) defined by the adjoint matrix.
EXAMPLES:
sage: quadratic.form()
a*x^2 + b*y^2 + c*z^2
sage: quadratic.dual().form()
b*c*x^2 + a*c*y^2 + a*b*z^2
sage: quadratic.dual()
Ternary quadratic with coefficients (1, 1, -1/4*t^2 + 1, -t, 0, 0)
matrix()
Return the quadratic form as a symmetric matrix
OUTPUT:
This method returns a symmetric matrix 𝐴 such that the quadratic 𝑄 equals
EXAMPLES:
monomials()
List the basis monomials in the form.
OUTPUT:
A tuple of monomials. They are in the same order as coeffs().
EXAMPLES:
scaled_coeffs()
The scaled coefficients of a quadratic form.
Given
∑︁ ∑︁
𝑓 (𝑥) = 𝑎𝑖 𝑥2𝑖 + 2𝑎𝑗𝑘 𝑥𝑗 𝑥𝑘
0≤𝑖<𝑛 0≤𝑗<𝑘<𝑛
class sage.rings.invariants.invariant_theory.SeveralAlgebraicForms(forms)
Bases: sage.rings.invariants.invariant_theory.FormsBase
The base class of multiple algebraic forms (i.e. homogeneous polynomials).
You should only instantiate the derived classes of this base class.
See AlgebraicForm for the base class of a single algebraic form.
INPUT:
• forms – a list/tuple/iterable of at least one AlgebraicForm object, all with the same number of vari-
ables. Interpreted as multiple homogeneous polynomials in a common polynomial ring.
EXAMPLES:
get_form(i)
Return the 𝑖-th form.
EXAMPLES:
homogenized(var=’h’)
Return form as defined by a homogeneous polynomial.
INPUT:
• var – either a variable name, variable index or a variable (default: 'h').
OUTPUT:
The same algebraic form, but defined by a homogeneous polynomial.
EXAMPLES:
n_forms()
Return the number of forms.
EXAMPLES:
J_covariant()
Return the J-covariant of the ternary cubic.
EXAMPLES:
S_invariant()
Return the S-invariant.
EXAMPLES:
T_invariant()
Return the T-invariant.
EXAMPLES:
Theta_covariant()
Return the Θ covariant.
EXAMPLES:
coeffs()
Return the coefficients of a cubic.
Given
𝑝(𝑥, 𝑦) = 𝑎30 𝑥3 + 𝑎21 𝑥2 𝑦 + 𝑎12 𝑥𝑦 2 + 𝑎03 𝑦 3 + 𝑎20 𝑥2 +
𝑎11 𝑥𝑦 + 𝑎02 𝑦 2 + 𝑎10 𝑥 + 𝑎01 𝑦 + 𝑎00
this function returns 𝑎 = (𝑎30 , 𝑎03 , 𝑎00 , 𝑎21 , 𝑎20 , 𝑎12 , 𝑎02 , 𝑎10 , 𝑎01 , 𝑎11 )
EXAMPLES:
monomials()
List the basis monomials of the form.
OUTPUT:
A tuple of monomials. They are in the same order as coeffs().
EXAMPLES:
sage: R.<x,y,z> = QQ[]
sage: cubic = invariant_theory.ternary_cubic(x^3+y*z^2)
sage: cubic.monomials()
(x^3, y^3, z^3, x^2*y, x^2*z, x*y^2, y^2*z, x*z^2, y*z^2, x*y*z)
polar_conic()
Return the polar conic of the cubic.
OUTPUT:
Given the ternary cubic 𝑓 (𝑋, 𝑌, 𝑍), this method returns the symmetric matrix 𝐴(𝑥, 𝑦, 𝑧) defined by
EXAMPLES:
sage: R.<x,y,z,X,Y,Z,a30,a21,a12,a03,a20,a11,a02,a10,a01,a00> = QQ[]
sage: p = ( a30*x^3 + a21*x^2*y + a12*x*y^2 + a03*y^3 + a20*x^2*z +
....: a11*x*y*z + a02*y^2*z + a10*x*z^2 + a01*y*z^2 + a00*z^3 )
sage: cubic = invariant_theory.ternary_cubic(p, x,y,z)
sage: cubic.polar_conic()
[ 3*x*a30 + y*a21 + z*a20 x*a21 + y*a12 + 1/2*z*a11 x*a20 + 1/2*y*a11 +
˓→z*a10]
scaled_coeffs()
Return the coefficients of a cubic.
Compared to coeffs(), this method returns rescaled coefficients that are often used in invariant theory.
Given
𝑝(𝑥, 𝑦) = 𝑎30 𝑥3 + 𝑎21 𝑥2 𝑦 + 𝑎12 𝑥𝑦 2 + 𝑎03 𝑦 3 + 𝑎20 𝑥2 +
𝑎11 𝑥𝑦 + 𝑎02 𝑦 2 + 𝑎10 𝑥 + 𝑎01 𝑦 + 𝑎00
this function returns 𝑎 = (𝑎30 , 𝑎03 , 𝑎00 , 𝑎21 /3, 𝑎20 /3, 𝑎12 /3, 𝑎02 /3, 𝑎10 /3, 𝑎01 /3, 𝑎11 /6)
EXAMPLES:
sage: R.<x,y,z,a30,a21,a12,a03,a20,a11,a02,a10,a01,a00> = QQ[]
sage: p = ( a30*x^3 + a21*x^2*y + a12*x*y^2 + a03*y^3 + a20*x^2*z +
....: a11*x*y*z + a02*y^2*z + a10*x*z^2 + a01*y*z^2 + a00*z^3 )
sage: invariant_theory.ternary_cubic(p, x,y,z).scaled_coeffs()
(a30, a03, a00, 1/3*a21, 1/3*a20, 1/3*a12, 1/3*a02, 1/3*a10, 1/3*a01, 1/6*a11)
syzygy(U, S, T, H, Theta, J)
Return the syzygy of the cubic evaluated on the invariants and covariants.
INPUT:
• U, S, T, H, Theta, J – polynomials from the same polynomial ring.
OUTPUT:
0 if evaluated for the form, the S invariant, the T invariant, the Hessian, the Θ covariant and the J-covariant
of a ternary cubic.
EXAMPLES:
covariant_conic(other)
Return the ternary quadratic covariant to self and other.
INPUT:
• other – Another ternary quadratic.
OUTPUT:
The so-called covariant conic, a ternary quadratic. It is symmetric under exchange of self and other.
EXAMPLES:
sage: ring.<x,y,z> = QQ[]
sage: Q = invariant_theory.ternary_quadratic(x^2+y^2+z^2)
sage: R = invariant_theory.ternary_quadratic(x*y+x*z+y*z)
sage: Q.covariant_conic(R)
-x*y - x*z - y*z
sage: R.covariant_conic(Q)
-x*y - x*z - y*z
monomials()
List the basis monomials of the form.
OUTPUT:
A tuple of monomials. They are in the same order as coeffs().
EXAMPLES:
sage: R.<x,y,z> = QQ[]
sage: quadratic = invariant_theory.ternary_quadratic(x^2+y*z)
sage: quadratic.monomials()
(x^2, y^2, z^2, x*y, x*z, y*z)
scaled_coeffs()
Return the scaled coefficients of a quadratic.
Given
this function returns 𝑎 = (𝑎20 , 𝑎02 , 𝑎00 , 𝑎11 /2, 𝑎10 /2, 𝑎01 /2, )
EXAMPLES:
sage: R.<x,y,z,a20,a11,a02,a10,a01,a00> = QQ[]
sage: p = ( a20*x^2 + a11*x*y + a02*y^2 +
....: a10*x*z + a01*y*z + a00*z^2 )
sage: invariant_theory.ternary_quadratic(p, x,y,z).scaled_coeffs()
(a20, a02, a00, 1/2*a11, 1/2*a10, 1/2*a01)
sage: invariant_theory.ternary_quadratic(p.subs(z=1), x, y).scaled_coeffs()
(a20, a02, a00, 1/2*a11, 1/2*a10, 1/2*a01)
class sage.rings.invariants.invariant_theory.TwoAlgebraicForms(forms)
Bases: sage.rings.invariants.invariant_theory.SeveralAlgebraicForms
first()
Return the first of the two forms.
OUTPUT:
The first algebraic form used in the definition.
EXAMPLES:
sage: R.<x,y> = QQ[]
sage: q0 = invariant_theory.quadratic_form(x^2 + y^2)
sage: q1 = invariant_theory.quadratic_form(x*y)
sage: from sage.rings.invariants.invariant_theory import TwoAlgebraicForms
sage: q = TwoAlgebraicForms([q0, q1])
sage: q.first() is q0
(continues on next page)
second()
Return the second of the two forms.
OUTPUT:
The second form used in the definition.
EXAMPLES:
class sage.rings.invariants.invariant_theory.TwoQuaternaryQuadratics(forms)
Bases: sage.rings.invariants.invariant_theory.TwoAlgebraicForms
Invariant theory of two quaternary quadratics.
You should use the invariant_theory factory object to construct instances of this class. See
quaternary_biquadratics() for details.
REFERENCES:
Delta_invariant()
Return the ∆ invariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
Delta_prime_invariant()
Return the ∆′ invariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
J_covariant()
The 𝐽-covariant.
This is the Jacobian determinant of the two biquadratics, the 𝑇 -covariant, and the 𝑇 ′ -covariant with respect
to the four homogeneous variables.
EXAMPLES:
sage: R.<w,x,y,z,a0,a1,a2,a3,A0,A1,A2,A3> = QQ[]
sage: p1 = a0*x^2 + a1*y^2 + a2*z^2 + a3*w^2
sage: p2 = A0*x^2 + A1*y^2 + A2*z^2 + A3*w^2
sage: q = invariant_theory.quaternary_biquadratic(p1, p2, [w, x, y, z])
sage: q.J_covariant().factor()
z * y * x * w * (a3*A2 - a2*A3) * (a3*A1 - a1*A3) * (-a2*A1 + a1*A2)
* (a3*A0 - a0*A3) * (-a2*A0 + a0*A2) * (-a1*A0 + a0*A1)
Phi_invariant()
Return the Φ′ invariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
T_covariant()
The 𝑇 -covariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
T_prime_covariant()
The 𝑇 ′ -covariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
Theta_invariant()
Return the Θ invariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
Theta_prime_invariant()
Return the Θ′ invariant.
EXAMPLES:
sage: R.<x,y,z,t,a0,a1,a2,a3,b0,b1,b2,b3,b4,b5,A0,A1,A2,A3,B0,B1,B2,B3,B4,B5>
˓→= QQ[]
If the arguments are not the invariants and covariants then the output is some (generically non-zero) poly-
nomial:
sage: biquadratic.syzygy(1, 1, 1, 1, 1, 1, 1, 1, 1, x)
-x^2 + 1
class sage.rings.invariants.invariant_theory.TwoTernaryQuadratics(forms)
Bases: sage.rings.invariants.invariant_theory.TwoAlgebraicForms
Invariant theory of two ternary quadratics.
You should use the invariant_theory factory object to construct instances of this class. See
ternary_biquadratics() for details.
REFERENCES:
Delta_invariant()
Return the ∆ invariant.
EXAMPLES:
sage: R.<a00, a01, a11, a02, a12, a22, b00, b01, b11, b02, b12, b22, y0, y1,
˓→y2, t> = QQ[]
Delta_prime_invariant()
Return the ∆′ invariant.
EXAMPLES:
sage: R.<a00, a01, a11, a02, a12, a22, b00, b01, b11, b02, b12, b22, y0, y1,
˓→y2, t> = QQ[]
F_covariant()
Return the 𝐹 covariant.
EXAMPLES:
sage: R.<a00, a01, a11, a02, a12, a22, b00, b01, b11, b02, b12, b22, x, y> =
˓→QQ[]
J_covariant()
Return the 𝐽 covariant.
EXAMPLES:
sage: R.<a00, a01, a11, a02, a12, a22, b00, b01, b11, b02, b12, b22, x, y> =
˓→QQ[]
Theta_invariant()
Return the Θ invariant.
EXAMPLES:
sage: R.<a00, a01, a11, a02, a12, a22, b00, b01, b11, b02, b12, b22, y0, y1,
˓→y2, t> = QQ[]
Theta_prime_invariant()
Return the Θ′ invariant.
EXAMPLES:
sage: R.<a00, a01, a11, a02, a12, a22, b00, b01, b11, b02, b12, b22, y0, y1,
˓→y2, t> = QQ[]
If the arguments are not the invariants and covariants then the output is some (generically non-zero) poly-
nomial:
sage: biquadratic.syzygy(1, 1, 1, 1, 1, 1, 1, x)
1/64*x^2 + 1
EXAMPLES:
The default scaling will yield an error for fields of positive characteristic below 𝑑𝑓 ! or 𝑑𝑔 ! as the denominator
of the scaling factor will not be invertible in that case. The scale argument 'none' can be used to compute the
transvectant in this case:
The additional factors that appear when scale='none' is used can be seen if we consider the same transvec-
tant over the rationals and compare it to the scaled version:
If the forms are given as inhomogeneous polynomials, the homogenisation might fail if the polynomial ring
has multiple variables. You can circumvent this by making sure the base ring of the polynomial has only one
variable:
Following [BW93] the original Buchberger algorithm (c.f. algorithm GROEBNER in [BW93]) and an improved
version of Buchberger’s algorithm (c.g. algorithm GROEBNERNEW2 in [BW93]) are implemented.
No attempt was made to optimize either algorithm as the emphasis of these implementations is a clean and
easy presentation. To compute a Groebner basis in Sage efficiently use the sage.rings.polynomial.
multi_polynomial_ideal.MPolynomialIdeal.groebner_basis() method on multivariate polyno-
mial objects.
Note: The notion of ‘term’ and ‘monomial’ in [BW93] is swapped from the notion of those words in Sage (or the
other way around, however you prefer it). In Sage a term is a monomial multiplied by a coefficient, while in [BW93] a
monomial is a term multiplied by a coefficient. Also, what is called LM (the leading monomial) in Sage is called HT
(the head term) in [BW93].
EXAMPLES:
Consider Katsura-6 w.r.t. a degrevlex ordering.:
sage: g1 = buchberger(I)
sage: g2 = buchberger_improved(I)
sage: g3 = I.groebner_basis()
sage: Ideal(g1).basis_is_groebner()
True
sage: Ideal(g2).basis_is_groebner()
True
sage: Ideal(g3).basis_is_groebner()
True
sage: set_verbose(1)
sage: P.<a,b,c> = PolynomialRing(GF(127),3)
sage: I = sage.rings.ideal.Katsura(P)
// sage... ideal
sage: I
Ideal (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a, 2*a*b + 2*b*c - b) of Multivariate
˓→Polynomial Ring in a, b, c over Finite Field of size 127
The original Buchberger algorithm performs 15 useless reductions to zero for this example:
sage: buchberger(I)
(a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a) => -2*b^2 - 6*b*c - 6*c^2 + b + 2*c
G: set([a + 2*b + 2*c - 1, 2*a*b + 2*b*c - b, a^2 + 2*b^2 + 2*c^2 - a, -2*b^2 - 6*b*c
˓→- 6*c^2 + b + 2*c])
(2*a*b + 2*b*c - b, -5*b*c - 6*c^2 - 63*b + 2*c) => -22*c^3 + 24*c^2 - 60*b - 62*c
G: set([a + 2*b + 2*c - 1, -22*c^3 + 24*c^2 - 60*b - 62*c, 2*a*b + 2*b*c - b, a^2 +
˓→2*b^2 + 2*c^2 - a, -2*b^2 - 6*b*c - 6*c^2 + b + 2*c, -5*b*c - 6*c^2 - 63*b + 2*c])
15 reductions to zero.
[a + 2*b + 2*c - 1, -22*c^3 + 24*c^2 - 60*b - 62*c, 2*a*b + 2*b*c - b, a^2 + 2*b^2 +
˓→2*c^2 - a, -2*b^2 - 6*b*c - 6*c^2 + b + 2*c, -5*b*c - 6*c^2 - 63*b + 2*c]
sage: buchberger_improved(I)
(b^2 - 26*c^2 - 51*b + 51*c, b*c + 52*c^2 + 38*b + 25*c) => 11*c^3 - 12*c^2 + 30*b +
˓→31*c
G: set([a + 2*b + 2*c - 1, b^2 - 26*c^2 - 51*b + 51*c, 11*c^3 - 12*c^2 + 30*b + 31*c,
˓→b*c + 52*c^2 + 38*b + 25*c])
1 reductions to zero.
[a + 2*b + 2*c - 1, b^2 - 26*c^2 - 51*b + 51*c, c^3 + 22*c^2 - 55*b + 49*c, b*c +
˓→52*c^2 + 38*b + 25*c]
REFERENCES:
AUTHOR:
• Martin Albrecht (2007-05-24): initial version
• Marshall Hampton (2009-07-08): some doctest additions
sage.rings.polynomial.toy_buchberger.LCM(f, g)
sage.rings.polynomial.toy_buchberger.LM(f )
sage.rings.polynomial.toy_buchberger.LT(f )
sage.rings.polynomial.toy_buchberger.buchberger(F)
The original version of Buchberger’s algorithm as presented in [BW93], page 214.
INPUT:
• F - an ideal in a multivariate polynomial ring
OUTPUT:
a Groebner basis for F
Note: The verbosity of this function may be controlled with a set_verbose() call. Any value >=1 will
result in this function printing intermediate bases.
EXAMPLES:
sage.rings.polynomial.toy_buchberger.buchberger_improved(F)
An improved version of Buchberger’s algorithm as presented in [BW93], page 232.
This variant uses the Gebauer-Moeller Installation to apply Buchberger’s first and second criterion to avoid
useless pairs.
INPUT:
• F - an ideal in a multivariate polynomial ring
OUTPUT:
Note: The verbosity of this function may be controlled with a set_verbose() call. Any value >=1 will
result in this function printing intermediate Groebner bases.
EXAMPLES:
sage.rings.polynomial.toy_buchberger.inter_reduction(Q)
If Q is the set (𝑓1 , ..., 𝑓𝑛 ) this method returns (𝑔1 , ..., 𝑔𝑠 ) such that:
• < 𝑓1 , ..., 𝑓𝑛 >=< 𝑔1 , ..., 𝑔𝑠 >
• 𝐿𝑀 (𝑔𝑖 )! = 𝐿𝑀 (𝑔𝑗 ) for all 𝑖! = 𝑗
• 𝐿𝑀 (𝑔𝑖 ) does not divide 𝑚 for all monomials 𝑚 of {𝑔1 , ..., 𝑔𝑖−1 , 𝑔𝑖+1 , ..., 𝑔𝑠 }
• 𝐿𝐶(𝑔𝑖 ) == 1 for all 𝑖.
INPUT:
• Q - a set of polynomials
EXAMPLES:
sage.rings.polynomial.toy_buchberger.select(P)
The normal selection strategy
INPUT:
• P - a list of critical pairs
OUTPUT:
an element of P
EXAMPLES:
sage.rings.polynomial.toy_buchberger.spol(f, g)
Computes the S-polynomial of f and g.
INPUT:
• f,g - polynomials
OUTPUT:
• The S-polynomial of f and g.
EXAMPLES:
sage.rings.polynomial.toy_buchberger.update(G, B, h)
Update G using the list of critical pairs B and the polynomial h as presented in [BW93], page 230. For this,
Buchberger’s first and second criterion are tested.
This function implements the Gebauer-Moeller Installation.
INPUT:
• G - an intermediate Groebner basis
• B - a list of critical pairs
• h - a polynomial
OUTPUT:
a tuple of an intermediate Groebner basis and a list of critical pairs
EXAMPLES:
The implementations are not hard, and the choice of algorithm is described with the relevant function.
No attempt was made to optimize these algorithms as the emphasis of this implementation is a clean and easy presen-
tation.
Examples appear with the appropriate function.
AUTHORS:
• John Perry (2009-02-24): initial version, but some words of documentation were stolen shamelessly from Martin
Albrecht’s toy_buchberger.py.
REFERENCES:
sage.rings.polynomial.toy_variety.coefficient_matrix(polys)
Generates the matrix M whose entries are the coefficients of polys. The entries of row i of M consist of the
coefficients of polys[i].
INPUT:
• polys - a list/tuple of polynomials
OUTPUT:
A matrix M of the coefficients of polys.
EXAMPLES:
sage: from sage.rings.polynomial.toy_variety import coefficient_matrix
sage: R.<x,y> = PolynomialRing(QQ)
sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1])
[1 0 0 1]
[0 0 1 1]
[0 1 0 1]
sage.rings.polynomial.toy_variety.elim_pol(B, n=-1)
Finds the unique monic polynomial of lowest degree and lowest variable in the ideal described by B.
For the purposes of the triangularization algorithm, it is necessary to preserve the ring, so n specifies which
variable to check. By default, we check the last one, which should also be the smallest.
The algorithm may not work if you are trying to cheat: B should describe the Groebner basis of a zero-
dimensional ideal. However, it is not necessary for the Groebner basis to be lexicographic.
The algorithm is taken from a 1993 paper by Lazard [Laz92].
INPUT:
• B - a list/tuple of polynomials or a multivariate polynomial ideal
• n - the variable to check (see above) (default: -1)
EXAMPLES:
sage: set_verbose(0)
sage: from sage.rings.polynomial.toy_variety import elim_pol
sage: R.<x,y,z> = PolynomialRing(GF(32003))
sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3
(continues on next page)
sage.rings.polynomial.toy_variety.is_linearly_dependent(polys)
Decides whether the polynomials of polys are linearly dependent. Here polys is a collection of polynomials.
The algorithm creates a matrix of coefficients of the monomials of polys. It computes the echelon form of the
matrix, then checks whether any of the rows is the zero vector.
Essentially this relies on the fact that the monomials are linearly independent, and therefore is building a linear
map from the vector space of the monomials to the canonical basis of R^n, where n is the number of distinct
monomials in polys. There is a zero vector iff there is a linear dependence among polys.
The case where polys=[] is considered to be not linearly dependent.
INPUT:
• polys - a list/tuple of polynomials
OUTPUT:
True if the elements of polys are linearly dependent; False otherwise.
EXAMPLES:
sage.rings.polynomial.toy_variety.is_triangular(B)
Check whether the basis B of an ideal is triangular. That is: check whether the largest variable in B[i] with
respect to the ordering of the base ring R is R.gens()[i].
The algorithm is based on the definition of a triangular basis, given by Lazard in 1992 in [Laz92].
INPUT:
• B - a list/tuple of polynomials or a multivariate polynomial ideal
OUTPUT:
True if the basis is triangular; False otherwise.
EXAMPLES:
sage.rings.polynomial.toy_variety.linear_representation(p, polys)
Assuming that p is a linear combination of polys, determines coefficients that describe the linear combination.
This probably doesn’t work for any inputs except p, a polynomial, and polys, a sequence of polynomials. If p
is not in fact a linear combination of polys, the function raises an exception.
The algorithm creates a matrix of coefficients of the monomials of polys and p, with the coefficients of p in
the last row. It augments this matrix with the appropriate identity matrix, then computes the echelon form of the
augmented matrix. The last row should contain zeroes in the first columns, and the last columns contain a linear
dependence relation. Solving for the desired linear relation is straightforward.
INPUT:
• p - a polynomial
• polys - a list/tuple of polynomials
OUTPUT:
If n == len(polys), returns [a[0],a[1],...,a[n-1]] such that p ==
a[0]*poly[0] + ... + a[n-1]*poly[n-1].
EXAMPLES:
sage.rings.polynomial.toy_variety.triangular_factorization(B, n=-1)
Compute the triangular factorization of the Groebner basis B of an ideal.
This will not work properly if B is not a Groebner basis!
The algorithm used is that described in a 1992 paper by Daniel Lazard [Laz92]. It is not necessary for the term
ordering to be lexicographic.
INPUT:
• B - a list/tuple of polynomials or a multivariate polynomial ideal
• n - the recursion parameter (default: -1)
OUTPUT:
A list T of triangular sets T_0, T_1, etc.
EXAMPLES:
sage: set_verbose(0)
sage: from sage.rings.polynomial.toy_variety import triangular_factorization
sage: R.<x,y,z> = PolynomialRing(GF(32003))
sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3
sage: p2 = z^2 - z
(continues on next page)
No attempt was made to optimize this algorithm as the emphasis of this implementation is a clean and easy presenta-
tion.
Note: The notion of ‘term’ and ‘monomial’ in [BW93] is swapped from the notion of those words in Sage (or the
other way around, however you prefer it). In Sage a term is a monomial multiplied by a coefficient, while in [BW93] a
monomial is a term multiplied by a coefficient. Also, what is called LM (the leading monomial) in Sage is called HT
(the head term) in [BW93].
EXAMPLES:
sage: I = A.ideal([f,fx,fy])
sage: gb = d_basis(I); gb
[x - 2020, y - 11313, 22627]
sage: gb[-1].factor()
11^3 * 17
This Groebner Basis gives a lot of information. First, the only fibers (over Z) that are not smooth are at 11 = 0, and
17 = 0. Examining the Groebner Basis, we see that we have a simple node in both the fiber at 11 and at 17. From the
factorization, we see that the node at 17 is regular on the surface (an 𝐼1 node), but the node at 11 is not. After blowing
up this non-regular point, we find that it is an 𝐼3 node.
Another example. This one is from the Magma Handbook:
However, when we compute the Groebner basis of I (defined over Z), we note that there is a certain integer in the ideal
which is not 1:
sage: gb = d_basis(I); gb
[z ..., y ..., x ..., 282687803443]
Now for each prime 𝑝 dividing this integer 282687803443, the Groebner basis of I modulo 𝑝 will be non-trivial and
will thus give a solution of the original system modulo 𝑝.:
sage: factor(282687803443)
101 * 103 * 27173681
Of course, modulo any other prime the Groebner basis is trivial so there are no other solutions. For example:
AUTHOR:
• Martin Albrecht (2008-08): initial version
sage.rings.polynomial.toy_d_basis.LC(f )
sage.rings.polynomial.toy_d_basis.LM(f )
sage.rings.polynomial.toy_d_basis.d_basis(F, strat=True)
Return the 𝑑-basis for the Ideal F as defined in [BW93].
INPUT:
• F – an ideal
• strat – use update strategy (default: True)
EXAMPLES:
sage.rings.polynomial.toy_d_basis.gpol(g1, g2)
Return the G-Polynomial of g_1 and g_2.
Let 𝑎𝑖 𝑡𝑖 be 𝐿𝑇 (𝑔𝑖 ), 𝑎 = 𝑎𝑖 * 𝑐𝑖 + 𝑎𝑗 * 𝑐𝑗 with 𝑎 = 𝐺𝐶𝐷(𝑎𝑖 , 𝑎𝑗 ), and 𝑠𝑖 = 𝑡/𝑡𝑖 with 𝑡 = 𝐿𝐶𝑀 (𝑡𝑖 , 𝑡𝑗 ). Then
the G-Polynomial is defined as: 𝑐1 𝑠1 𝑔1 − 𝑐2 𝑠2 𝑔2 .
INPUT:
• g1 – polynomial
• g2 – polynomial
EXAMPLES:
sage.rings.polynomial.toy_d_basis.select(P)
The normal selection strategy.
INPUT:
• P – a list of critical pairs
OUTPUT:
an element of P
EXAMPLES:
sage.rings.polynomial.toy_d_basis.spol(g1, g2)
Return the S-Polynomial of g_1 and g_2.
Let 𝑎𝑖 𝑡𝑖 be 𝐿𝑇 (𝑔𝑖 ), 𝑏𝑖 = 𝑎/𝑎𝑖 with 𝑎 = 𝐿𝐶𝑀 (𝑎𝑖 , 𝑎𝑗 ), and 𝑠𝑖 = 𝑡/𝑡𝑖 with 𝑡 = 𝐿𝐶𝑀 (𝑡𝑖 , 𝑡𝑗 ). Then the
S-Polynomial is defined as: 𝑏1 𝑠1 𝑔1 − 𝑏2 𝑠2 𝑔2 .
INPUT:
• g1 – polynomial
• g2 – polynomial
EXAMPLES:
sage.rings.polynomial.toy_d_basis.update(G, B, h)
Update G using the list of critical pairs B and the polynomial h as presented in [BW93], page 230. For this,
Buchberger’s first and second criterion are tested.
This function uses the Gebauer-Moeller Installation.
INPUT:
• G – an intermediate Groebner basis
• B – a list of critical pairs
• h – a polynomial
OUTPUT:
G,B where G and B are updated
EXAMPLES:
FOUR
SKEW POLYNOMIALS
This module provides the SkewPolynomial, which constructs a single univariate skew polynomial over commu-
tative base rings and an automorphism over the base ring. Skew polynomials are non-commutative and so principal
methods such as gcd, lcm, monic, multiplication, and division are given in left and right forms.
The generic implementation of dense skew polynomials is SkewPolynomial_generic_dense. The classes
ConstantSkewPolynomialSection and SkewPolynomialBaseringInjection handle conversion
from a skew polynomial ring to its base ring and vice versa respectively.
Warning: The current semantics of __call__() are experimental, so a warning is thrown when a skew poly-
nomial is evaluated for the first time in a session. See the method documentation for details.
AUTHORS:
• Xavier Caruso (2012-06-29): initial version
• Arpit Merchant (2016-08-04): improved docstrings, fixed doctests and refactored classes and methods
• Johan Rosenkilde (2016-08-03): changes for bug fixes, docstring and doctest errors
class sage.rings.polynomial.skew_polynomial_element.ConstantSkewPolynomialSection
Bases: sage.categories.map.Map
Representation of the canonical homomorphism from the constants of a skew polynomial ring to the base ring.
This class is necessary for automatic coercion from zero-degree skew polynomial ring into the base ring.
EXAMPLES:
class sage.rings.polynomial.skew_polynomial_element.SkewPolynomial
Bases: sage.structure.element.AlgebraElement
461
Sage Reference Manual: Polynomials, Release 8.6
Definition
𝐹 (𝑋) = 𝑎𝑛 𝑋 𝑛 + · · · + 𝑎0 ,
Properties
Keeping the previous notation, if the leading coefficient of 𝑏 is a unit (e.g. if 𝑏 is monic) then the quotient and
the remainder in the right euclidean division exist and are unique.
The same result holds for the left euclidean division if in addition the twist map defining the skew polynomial
ring is invertible.
Evaluation
∑︀𝑑
The value of a given a skew polynomial 𝑝(𝑥) = 𝑖=0 𝑎𝑖 𝑥𝑖 at 𝑟 is calculated using the formula:
𝑑
∑︁
𝑝(𝑟) = 𝑎𝑖 𝜎 𝑖 (𝑟)
𝑖=0
where 𝜎 is the base ring automorphism. This is called the operator evaluation method.
EXAMPLES:
We illustrate some functionalities implemented in this class.
We create the skew polynomial ring:
sage: a = t + x + 1; a
x + t + 1
sage: b = S([t^2,t+1,1]); b
x^2 + (t + 1)*x + t^2
sage: c = S.random_element(degree=3,monic=True); c
x^3 + (2*t - 1)*x
sage: a * b
x^3 + (2*t + 3)*x^2 + (2*t^2 + 4*t + 2)*x + t^3 + t^2
sage: b * a
x^3 + (2*t + 4)*x^2 + (2*t^2 + 3*t + 2)*x + t^3 + t^2
sage: a * b == b * a
False
sage: b^2
x^4 + (2*t + 4)*x^3 + (3*t^2 + 7*t + 6)*x^2
+ (2*t^3 + 4*t^2 + 3*t + 1)*x + t^4
sage: b^2 == b*b
True
Sage also implements arithmetic over skew polynomial rings. You will find below a short panorama:
sage: q,r = c.right_quo_rem(b)
sage: q
x - t - 2
sage: r
3*t*x + t^3 + 2*t^2
sage: c == q*b + r
True
The operators // and % give respectively the quotient and the remainder of the right euclidean division:
sage: q == c // b
True
sage: r == c % b
True
Left euclidean division won’t work over our current 𝑆 because Sage can’t invert the twist map:
sage: q,r = c.left_quo_rem(b)
Traceback (most recent call last):
...
NotImplementedError: inversion of the twist map Ring endomorphism of Univariate
˓→Polynomial Ring in t over Integer Ring
Defn: t |--> t + 1
Here we can see the effect of the operator evaluation compared to the usual polynomial evaluation:
sage: a = x^2
sage: a(t)
t + 2
Once we have euclidean divisions, we have for free gcd and lcm (at least if the base ring is a field):
sage: a = (x + t) * (x + t^2)^2
sage: b = (x + t) * (t*x + t + 1) * (x + t^2)
sage: a.right_gcd(b)
x + t^2
sage: a.left_gcd(b)
x + t
The left lcm has the following meaning: given skew polynomials 𝑎 and 𝑏, their left lcm is the least degree
polynomial 𝑐 = 𝑢𝑎 = 𝑣𝑏 for some skew polynomials 𝑢, 𝑣. Such a 𝑐 always exist if the base ring is a field:
sage: c = a.left_lcm(b); c
x^5 + (4*t^2 + t + 3)*x^4 + (3*t^2 + 4*t)*x^3 + 2*t^2*x^2 + (2*t^2 + t)*x + 4*t^2
˓→+ 4
sage: c.is_right_divisible_by(a)
True
sage: c.is_right_divisible_by(b)
True
The right lcm is defined similarly as the least degree polynomial 𝑐 = 𝑎𝑢 = 𝑏𝑣 for some 𝑢, 𝑣:
sage: d = a.right_lcm(b); d
x^5 + (t^2 + 1)*x^4 + (3*t^2 + 3*t + 3)*x^3 + (3*t^2 + t + 2)*x^2 + (4*t^2 +
˓→3*t)*x + 4*t + 4
sage: d.is_left_divisible_by(a)
True
sage: d.is_left_divisible_by(b)
True
See also:
• sage.rings.polynomial.skew_polynomial_ring
• sage.rings.polynomial.skew_polynomial_ring_constructor
base_ring()
Return the base ring of self.
EXAMPLES:
change_variable_name(var)
Change the name of the variable of self.
This will create the skew polynomial ring with the new name but same base ring and twist map. The
returned skew polynomial will be an element of that skew polynomial ring.
INPUT:
• var – the name of the new variable
EXAMPLES:
sage: b.parent()
Skew Polynomial Ring in y over Univariate Polynomial Ring in t over Integer
˓→Ring
twisted by t |--> t + 1
coefficients(sparse=True)
Return the coefficients of the monomials appearing in self.
If sparse=True (the default), return only the non-zero coefficients. Otherwise, return the same value as
self.list().
EXAMPLES:
conjugate(n)
Return self conjugated by 𝑥𝑛 , where 𝑥 is the variable of self.
The conjugate is obtained from self by applying the 𝑛-th iterate of the twist map to each of its coeffi-
cients.
INPUT:
• 𝑛 – an integer, the power of conjugation
EXAMPLES:
sage: R.<t> = QQ[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]
sage: a = t*x^3 + (t^2 + 1)*x^2 + 2*t
sage: b = a.conjugate(2); b
(t + 2)*x^3 + (t^2 + 4*t + 5)*x^2 + 2*t + 4
sage: x^2*a == b*x^2
True
In principle, negative values for 𝑛 are allowed, but Sage needs to be able to invert the twist map:
sage: b = a.conjugate(-1)
Traceback (most recent call last):
...
NotImplementedError: inversion of the twist map Ring endomorphism of
˓→Univariate Polynomial Ring in t over Rational Field
Defn: t |--> t + 1
constant_coefficient()
Return the constant coefficient (i.e. the coefficient of term of degree 0) of self.
EXAMPLES:
sage: R.<t> = ZZ[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]
sage: a = x + t^2 + 2
sage: a.constant_coefficient()
t^2 + 2
degree()
Return the degree of self.
By convention, the zero skew polynomial has degree −1.
EXAMPLES:
sage: R.<t> = ZZ[]
sage: sigma = R.hom([t+1])
(continues on next page)
exponents()
Return the exponents of the monomials appearing in self.
EXAMPLES:
hamming_weight()
Return the number of non-zero coefficients of self.
This is also known as the weight, hamming weight or sparsity.
EXAMPLES:
sage: a.hamming_weight()
3
is_constant()
Return whether self is a constant polynomial.
EXAMPLES:
is_left_divisible_by(other)
Check if self is divisible by other on the left.
INPUT:
• other – a skew polynomial in the same ring as self
OUTPUT:
Return True or False.
EXAMPLES:
sage: c.is_left_divisible_by(S(0))
Traceback (most recent call last):
...
ZeroDivisionError: division by zero is not valid
is_monic()
Return True if this skew polynomial is monic.
The zero polynomial is by definition not monic.
EXAMPLES:
is_monomial()
Return True if self is a monomial, i.e., a power of the generator.
EXAMPLES:
sage: (2*x^5).is_monomial()
False
sage: S(t).is_monomial()
False
sage: (2*x^5).is_term()
True
sage: S(t).is_term()
True
is_nilpotent()
Check if self is nilpotent.
Given a commutative ring 𝑅 and a base ring automorphism 𝜎 of order 𝑛, an element 𝑓 of 𝑅[𝑋, 𝜎] is
nilpotent if and only if all coefficients of 𝑓 𝑛 are nilpotent in 𝑅.
Note: The paper “Nilpotents and units in skew polynomial rings over commutative rings” by M. Rimmer
and K.R. Pearson describes the method to check whether a given skew polynomial is nilpotent. That
method however, requires one to know the order of the automorphism which is not available in Sage. This
method is thus not yet implemented.
EXAMPLES:
is_one()
Test whether this polynomial is 1.
EXAMPLES:
is_right_divisible_by(other)
Check if self is divisible by other on the right.
INPUT:
• other – a skew polynomial in the same ring as self
OUTPUT:
Return True or False.
EXAMPLES:
sage: c.is_right_divisible_by(S(0))
Traceback (most recent call last):
...
ZeroDivisionError: division by zero is not valid
This function does not work if the leading coefficient of the divisor is not a unit:
is_term()
Return True if self is an element of the base ring times a power of the generator.
EXAMPLES:
If you want to test that self also has leading coefficient 1, use is_monomial() instead:
sage: (3*x^5).is_monomial()
False
is_unit()
Return True if this skew polynomial is a unit.
When the base ring 𝑅 is an integral domain, then a skew polynomial 𝑓 is a unit if and only if degree of 𝑓
is 0 and 𝑓 is then a unit in 𝑅.
Note: The case when 𝑅 is not an integral domain is not yet implemented.
EXAMPLES:
is_zero()
Return True if self is the zero polynomial.
EXAMPLES:
leading_coefficient()
Return the coefficient of the highest-degree monomial of self.
EXAMPLES:
left_divides(other)
Check if self divides other on the left.
INPUT:
• other – a skew polynomial in the same ring as self
OUTPUT:
Return True or False.
EXAMPLES:
sage: S(0).left_divides(c)
Traceback (most recent call last):
...
ZeroDivisionError: division by zero is not valid
left_gcd(other, monic=True)
Return the left gcd of self and other.
INPUT:
• other – a skew polynomial in the same ring as self
• monic – boolean (default: True). Return whether the left gcd should be normalized to be monic.
OUTPUT:
The left gcd of self and other, that is a skew polynomial 𝑔 with the following property: any skew
polynomial is divisible on the left by 𝑔 iff it is divisible on the left by both self and other. If monic is
True, 𝑔 is in addition monic. (With this extra condition, it is uniquely determined.)
Note: Works only if two following conditions are fulfilled (otherwise left gcd do not exist in general): 1)
the base ring is a field and 2) the twist map on this field is bijective.
EXAMPLES:
sage: a.left_gcd(b,monic=False)
2*t*x + 4*t + 2
sage: FR = R.fraction_field()
sage: f = FR.hom([FR(t)^2])
sage: S.<x> = FR['x',f]
sage: a = (x + t) * (x^2 + t*x + 1)
sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2)
sage: a.left_gcd(b)
Traceback (most recent call last):
...
NotImplementedError: inversion of the twist map Ring endomorphism of Fraction
˓→Field of Univariate Polynomial Ring in t over Rational Field
left_lcm(other, monic=True)
Return the left lcm of self and other.
INPUT:
• other – a skew polynomial in the same ring as self
• monic – boolean (default: True). Return whether the left lcm should be normalized to be monic.
OUTPUT:
The left lcm of self and other, that is a skew polynomial 𝑔 with the following property: any skew
polynomial divides 𝑔 on the right iff it divides both self and other on the right. If monic is True, 𝑔 is
in addition monic. (With this extra condition, it is uniquely determined.)
Note: Works only if the base ring is a field (otherwise left lcm do not exist in general).
EXAMPLES:
sage: a.left_lcm(b,monic=False)
(t^2 + t)*x^5 + (4*t^2 + 4*t + 1)*x^4 + (t + 1)*x^3 + (t^2 + 2)*x^2 + (3*t +
˓→4)*x
left_mod(other)
Return the remainder of left division of self by other.
EXAMPLES:
left_monic()
Return the unique monic skew polynomial 𝑚 which divides self on the left and has the same degree.
Given a skew polynomial 𝑝 of degree 𝑛, its left monic is given by 𝑚 = 𝑝𝜎 −𝑛 (1/𝑘), where 𝑘 is the leading
coefficient of 𝑝, i.e. by the appropriate scalar multiplication on the right.
EXAMPLES:
sage: b = a.left_monic(); b
x^3 + (4*t^2 + 3*t)*x^2 + (4*t + 2)*x + 2*t^2 + 4*t + 3
Check list:
sage: a.is_right_divisible_by(b)
False
This function does not work if the leading coefficient is not a unit:
sage: R.<t> = QQ[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]
sage: a = t*x
sage: a.left_monic()
Traceback (most recent call last):
...
NotImplementedError: the leading coefficient is not a unit
left_xgcd(other, monic=True)
Return the left gcd of self and other along with the coefficients for the linear combination.
If 𝑎 is self and 𝑏 is other, then there are skew polynomials 𝑢 and 𝑣 such that 𝑔 = 𝑎𝑢 + 𝑏𝑣, where 𝑔 is
the left gcd of 𝑎 and 𝑏. This method returns (𝑔, 𝑢, 𝑣).
INPUT:
• other – a skew polynomial in the same ring as self
• monic – boolean (default: True). Return whether the left gcd should be normalized to be monic.
OUTPUT:
• The left gcd of self and other, that is a skew polynomial 𝑔 with the following property: any skew
polynomial is divisible on the left by 𝑔 iff it is divisible on the left by both self and other. If
monic is True, 𝑔 is in addition monic. (With this extra condition, it is uniquely determined.)
• Two skew polynomials 𝑢 and 𝑣 such that:
𝑔 = 𝑎 * 𝑢 + 𝑏 * 𝑣,
Note: Works only if following two conditions are fulfilled (otherwise left gcd do not exist in general): 1)
the base ring is a field and 2) the twist map on this field is bijective.
EXAMPLES:
sage: k.<t> = GF(5^3)
sage: Frob = k.frobenius_endomorphism()
sage: S.<x> = k['x',Frob]
sage: a = (x + t) * (x^2 + t*x + 1)
sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2)
sage: g,u,v = a.left_xgcd(b); g
x + t
sage: a*u + b*v == g
True
sage: FR = R.fraction_field()
sage: f = FR.hom([FR(t)^2])
sage: S.<x> = FR['x',f]
sage: a = (x + t) * (x^2 + t*x + 1)
sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2)
sage: a.left_xgcd(b)
Traceback (most recent call last):
...
NotImplementedError: inversion of the twist map Ring endomorphism of Fraction
˓→Field of Univariate Polynomial Ring in t over Rational Field
multi_point_evaluation(eval_pts)
Evaluate self at list of evaluation points.
INPUT:
• eval_pts – list of points at which self is to be evaluated
OUTPUT:
List of values of self at the eval_pts.
Todo: This method currently trivially calls the evaluation function repeatedly. If fast skew
polynomial multiplication is available, an asymptotically faster method is possible using stan-
dard divide and conquer techniques and sage.rings.polynomial.skew_polynomial_ring.
SkewPolynomialRing_general.minimal_vanishing_polynomial().
EXAMPLES:
number_of_terms()
Return the number of non-zero coefficients of self.
This is also known as the weight, hamming weight or sparsity.
EXAMPLES:
sage: a.hamming_weight()
3
operator_eval(eval_pt)
Evaluate self at eval_pt by the operator evaluation method.
INPUT:
• eval_pt – element of the base ring of self
OUTPUT:
The value of the polynomial at the point specified by the argument.
EXAMPLES:
Evaluation points outside the base ring is usually not possible due to the twist map:
˓→implemented
padded_list(n=None)
Return list of coefficients of self up to (but not including) degree 𝑛.
Includes 0‘𝑠𝑖𝑛𝑡ℎ𝑒𝑙𝑖𝑠𝑡𝑜𝑛𝑡ℎ𝑒𝑟𝑖𝑔ℎ𝑡𝑠𝑜𝑡ℎ𝑎𝑡𝑡ℎ𝑒𝑙𝑖𝑠𝑡𝑎𝑙𝑤𝑎𝑦𝑠ℎ𝑎𝑠𝑙𝑒𝑛𝑔𝑡ℎ𝑒𝑥𝑎𝑐𝑡𝑙𝑦‘𝑛.
INPUT:
• n – (default: None); if given, an integer that is at least 0
EXAMPLES:
prec()
Return the precision of self.
This is always infinity, since polynomials are of infinite precision by definition (there is no big-oh).
EXAMPLES:
sage: R.<t> = QQ[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]
sage: x.prec()
+Infinity
right_divides(other)
Check if self divides other on the right.
INPUT:
• other – a skew polynomial in the same ring as self
OUTPUT:
Return True or False.
EXAMPLES:
sage: k.<t> = GF(5^3)
sage: Frob = k.frobenius_endomorphism()
sage: S.<x> = k['x',Frob]
sage: a = x^2 + t*x + t^2 + 3
sage: b = x^3 + (t + 1)*x^2 + 1
sage: c = a*b
sage: a.right_divides(c)
False
sage: b.right_divides(c)
True
This function does not work if the leading coefficient of the divisor is not a unit:
right_gcd(other, monic=True)
Return the right gcd of self and other.
INPUT:
• other – a skew polynomial in the same ring as self
• monic – boolean (default: True). Return whether the right gcd should be normalized to be monic.
OUTPUT:
The right gcd of self and other, that is a skew polynomial 𝑔 with the following property: any skew
polynomial is divisible on the right by 𝑔 iff it is divisible on the right by both self and other. If monic
is True, 𝑔 is in addition monic. (With this extra condition, it is uniquely determined.)
Note: Works only if the base ring is a field (otherwise right gcd do not exist in general).
EXAMPLES:
sage: a.right_gcd(b,monic=False)
(4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3
right_lcm(other, monic=True)
Return the right lcm of self and other.
INPUT:
• other – a skew polynomial in the same ring as self
• monic – boolean (default: True). Return whether the right lcm should be normalized to be monic.
OUTPUT:
The right lcm of self and other, that is a skew polynomial 𝑔 with the following property: any skew
polynomial divides 𝑔 on the left iff it divides both self and other on the left. If monic is True, 𝑔 is in
addition monic. (With this extra condition, it is uniquely determined.)
Note: Works only if two following conditions are fulfilled (otherwise right lcm do not exist in general):
1) the base ring is a field and 2) the twist map on this field is bijective.
EXAMPLES:
sage: c.is_left_divisible_by(a)
True
sage: c.is_left_divisible_by(b)
True
sage: a.degree() + b.degree() == c.degree() + a.left_gcd(b).degree()
True
sage: a.right_lcm(b,monic=False)
2*t*x^4 + (3*t + 1)*x^3 + (4*t^2 + 4*t + 3)*x^2
+ (3*t^2 + 4*t + 2)*x + 3*t^2 + 2*t + 3
right_mod(other)
Return the remainder of right division of self by other.
EXAMPLES:
sage: R.<t> = QQ[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]
sage: a = 1 + t*x^2
sage: b = x + 1
sage: a % b
t + 1
sage: (x^3 + x - 1).right_mod(x^2 - 1)
2*x - 1
right_monic()
Return the unique monic skew polynomial 𝑚 which divides self on the right and has the same degree.
Given a skew polynomial 𝑝 of degree 𝑛, its left monic is given by 𝑚 = (1/𝑘) * 𝑝, where 𝑘 is the leading
coefficient of 𝑝, i.e. by the appropriate scalar multiplication on the left.
EXAMPLES:
sage: k.<t> = GF(5^3)
sage: Frob = k.frobenius_endomorphism()
sage: S.<x> = k['x',Frob]
sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2
˓→+ 2
sage: b = a.right_monic(); b
x^3 + (2*t^2 + 3*t + 4)*x^2 + (3*t^2 + 4*t + 1)*x + 2*t^2 + 4*t + 3
Check list:
sage: b.degree() == a.degree()
True
sage: b.is_right_divisible_by(a)
True
sage: a == a.leading_coefficient() * b
True
This function does not work if the leading coefficient is not a unit:
right_xgcd(other, monic=True)
Return the right gcd of self and other along with the coefficients for the linear combination.
If 𝑎 is self and 𝑏 is other, then there are skew polynomials 𝑢 and 𝑣 such that 𝑔 = 𝑢𝑎 + 𝑣𝑏, where 𝑔 is
the right gcd of 𝑎 and 𝑏. This method returns (𝑔, 𝑢, 𝑣).
INPUT:
• other – a skew polynomial in the same ring as self
• monic – boolean (default: True). Return whether the right gcd should be normalized to be monic.
OUTPUT:
• The right gcd of self and other, that is a skew polynomial 𝑔 with the following property: any
skew polynomial is divisible on the right by 𝑔 iff it is divisible on the right by both self and other.
If monic is True, 𝑔 is in addition monic. (With this extra condition, it is uniquely determined.)
• Two skew polynomials 𝑢 and 𝑣 such that:
𝑔 =𝑢*𝑎+𝑣*𝑏
Note: Works only if the base ring is a field (otherwise right gcd do not exist in general).
EXAMPLES:
shift(n)
Return self multiplied on the right by the power 𝑥𝑛 .
If 𝑛 is negative, terms below 𝑥𝑛 will be discarded.
EXAMPLES:
sage: a >> 2
x^3 + t^4*x^2 + t^2
sage: a << 2
x^7 + t^4*x^6 + t^2*x^4 + t^10*x^2
square()
Return the square of self.
EXAMPLES:
variable_name()
Return the string name of the variable used in self.
EXAMPLES:
class sage.rings.polynomial.skew_polynomial_element.SkewPolynomialBaseringInjection
Bases: sage.categories.morphism.Morphism
Representation of the canonical homomorphism from a ring 𝑅 into a skew polynomial ring over 𝑅.
This class is necessary for automatic coercion from the base ring to the skew polynomial ring.
See also:
PolynomialBaseringInjection
EXAMPLES:
an_element()
Return an element of the codomain of the ring homomorphism.
EXAMPLES:
section()
Return the canonical homomorphism from the constants of a skew polynomial ring to the base ring ac-
cording to self.
class sage.rings.polynomial.skew_polynomial_element.SkewPolynomial_generic_dense
Bases: sage.rings.polynomial.skew_polynomial_element.SkewPolynomial
Generic implementation of dense skew polynomial supporting any valid base ring and twist map.
coefficients(sparse=True)
Return the coefficients of the monomials appearing in self.
If sparse=True (the default), return only the non-zero coefficients. Otherwise, return the same value as
self.list().
EXAMPLES:
degree()
Return the degree of self.
By convention, the zero skew polynomial has degree −1.
EXAMPLES:
sage: S(0).degree()
-1
dict()
Return a dictionary representation of self.
EXAMPLES:
left_power_mod(exp, modulus)
Return the remainder of self**exp in the left euclidean division by modulus.
INPUT:
• exp – an Integer
• modulus – a skew polynomial in the same ring as self
OUTPUT:
Remainder of self**exp in the left euclidean division by modulus.
REMARK:
The quotient of the underlying skew polynomial ring by the principal ideal generated by modulus is in
general not a ring.
As a consequence, Sage first computes exactly self**exp and then reduce it modulo modulus.
EXAMPLES:
left_quo_rem(other)
Return the quotient and remainder of the left euclidean division of self by other.
INPUT:
• other – a skew polynomial in the same ring as self
OUTPUT:
• the quotient and the remainder of the left euclidean division of this skew polynomial by other
Note: This will fail if the leading coefficient of other is not a unit or if Sage can’t invert the twist map.
EXAMPLES:
In the following example, Sage does not know the inverse of the twist map:
Defn: t |--> t + 1
list(copy=True)
Return a list of the coefficients of self.
EXAMPLES:
Note that 𝑙 is a list, it is mutable, and each call to the list method returns a new list:
sage: type(l)
<... 'list'>
sage: l[0] = 5
sage: a.list()
[t^2 + 1, 0, t + 1, 0, 1]
right_power_mod(exp, modulus)
Return the remainder of self**exp in the right euclidean division by modulus.
INPUT:
• exp – an Integer
• modulus – a skew polynomial in the same ring as self
OUTPUT:
Remainder of self**exp in the right euclidean division by modulus.
REMARK:
The quotient of the underlying skew polynomial ring by the principal ideal generated by modulus is in
general not a ring.
As a consequence, Sage first computes exactly self**exp and then reduce it modulo modulus.
EXAMPLES:
right_quo_rem(other)
Return the quotient and remainder of the right euclidean division of self by other.
INPUT:
• other – a skew polynomial in the same ring as self
OUTPUT:
• the quotient and the remainder of the left euclidean division of this skew polynomial by other
Note: This will fail if the leading coefficient of the divisor is not a unit.
EXAMPLES:
sage: c = S.random_element(); c
(t - 1)*x^2 + t^2*x
sage: a.right_quo_rem(c)
Traceback (most recent call last):
...
NotImplementedError: the leading coefficient of the divisor is not invertible
truncate(n)
Return the polynomial resulting from discarding all monomials of degree at least 𝑛.
EXAMPLES:
valuation()
Return the minimal degree of a non-zero monomial of self.
By convention, the zero skew polynomial has valuation +∞.
EXAMPLES:
sage: S(0).valuation()
+Infinity
This module provides the function SkewPolynomialRing(), which constructs rings of univariate skew polyno-
mials, and implements caching to prevent the same ring being created in memory multiple times (which is wasteful
and breaks the general assumption in Sage that parents are unique).
AUTHOR:
• Xavier Caruso (2012-06-29): initial version
• Arpit Merchant (2016-08-04): improved docstrings, added doctests and refactored method
• Johan Rosenkilde (2016-08-03): changes to import format
sage.rings.polynomial.skew_polynomial_ring_constructor.SkewPolynomialRing(base_ring,
base_ring_automorphism
names=None,
sparse=False)
Return the globally unique skew polynomial ring with the given properties and variable names.
Given a ring 𝑅 and a ring automorphism 𝜎 of 𝑅, the ring of skew polynomials 𝑅[𝑋, 𝜎] is the usual abelian
group polynomial 𝑅[𝑋] equipped with the modification multiplication deduced from the rule 𝑋𝑎 = 𝜎(𝑎)𝑋.
See also:
• sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general
• sage.rings.polynomial.skew_polynomial_element.SkewPolynomial
INPUT:
• base_ring – a commutative ring
• base_ring_automorphism – an automorphism of the base ring (also called twisting map)
• names – a string or a list of strings
• sparse – a boolean (default: False). Currently not supported.
Note: The current implementation of skew polynomial rings does not support derivations. Sparse skew poly-
nomials and multivariate skew polynomials are also not implemented.
OUTPUT:
A univariate skew polynomial ring over base_ring twisted by base_ring_automorphism when names
is a string with no commas (,) or a list of length 1. Otherwise we raise a NotImplementedError as
multivariate skew polynomial rings are not yet implemented.
UNIQUENESS and IMMUTABILITY:
In Sage, there is exactly one skew polynomial ring for each triple (base ring, twisting map, name of the variable).
EXAMPLES of VARIABLE NAME CONTEXT:
twisted by t |--> t + 1
The names of the variables defined above cannot be arbitrarily modified because each skew polyno-
mial ring is unique in Sage and other objects in Sage could have pointers to that skew polynomial
ring.
However, the variable can be changed within the scope of a with block using the localvars context:
sage: with localvars(S, ['y']):
....: print(S)
Skew Polynomial Ring in y over Univariate Polynomial Ring in t over
˓→Integer Ring
twisted by t |--> t + 1
Use the diamond brackets notation to make the variable ready for use after you define the ring:
sage: S.<x> = SkewPolynomialRing(R, base_ring_automorphism)
sage: (x + t)^2
x^2 + (2*t + 1)*x + t^2
Todo:
• Sparse Skew Polynomial Ring
• Multivariate Skew Polynomial Ring
• Add derivations.
This module provides the SkewPolynomialRing_general, which constructs a general dense univariate skew
polynomials over commutative base rings with automorphisms over the base rings. This is usual accessed
only indirectly through the constructor sage.rings.polynomial.skew_polynomial_constructor.
SkewPolynomialRing().
See SkewPolynomialRing_general for a definition of a univariate skew polynomial ring.
AUTHOR:
• Xavier Caruso (2012-06-29): initial version
• Arpit Merchant (2016-08-04): improved docstrings, fixed doctests and refactored classes and methods
• Johan Rosenkilde (2016-08-03): changes for bug fixes, docstring and doctest errors
class sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general(base_ring,
twist_map,
name,
sparse,
el-
e-
ment_class)
Bases: sage.rings.ring.Algebra, sage.structure.unique_representation.
UniqueRepresentation
A general implementation of univariate skew polynomialring over a commutative ring.
Let 𝑅 be a commutative ring, and let 𝜎 be an automorphism of 𝑅. The ring of skew polynomials 𝑅[𝑋, 𝜎] is the
polynomial ring 𝑅[𝑋], where the addition is the usual polynomial addition, but the multiplication operation is
defined by the modified rule
𝑋 * 𝑎 = 𝜎(𝑎)𝑋.
This means that 𝑅[𝑋, 𝜎] is a non-commutative ring. Skew polynomials were first introduced by Ore [Ore33].
EXAMPLES:
If we omit the diamond notation, the variable holding the indeterminate is not assigned:
sage: Sy = R['y',sigma]
sage: y
Traceback (most recent call last):
(continues on next page)
Note however that contrary to usual polynomial rings, we cannot omit the variable name on the RHS, since this
collides with the notation for creating polynomial rings:
Of course, skew polynomial rings with different twist maps are not equal either:
There is a coercion map from the base ring of the skew polynomial rings:
sage: S.has_coerce_map_from(R)
True
sage: x.parent()
Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Integer Ring
twisted by t |--> t + 1
sage: t.parent()
Univariate Polynomial Ring in t over Integer Ring
sage: y = x+t; y
x + t
sage: y.parent() is S
True
See also:
sage.rings.polynomial.skew_polynomial_ring_constructor.
SkewPolynomialRing() sage.rings.polynomial.skew_polynomial_element
REFERENCES:
change_var(var)
Return the skew polynomial ring in variable var with the same base ring and twist map as self.
INPUT:
• var – a string representing the name of the new variable.
OUTPUT:
self with variable name changed to var.
EXAMPLES:
sage: Ry = R.change_var('y'); Ry
Skew Polynomial Ring in y over Finite Field in t of size 5^3 twisted by t |-->
˓→ t^5
sage: Ry is R.change_var('y')
True
characteristic()
Return the characteristic of the base ring of self.
EXAMPLES:
gen(n=0)
Return the indeterminate generator of this skew polynomial ring.
INPUT:
• n – index of generator to return (default: 0). Exists for compatibility with other polynomial rings.
EXAMPLES:
sage: y = S.gen(); y
x
sage: y == x
True
sage: y is x
True
sage: S.gen(0)
x
gens_dict()
Return a {name: variable} dictionary of the generators of self.
EXAMPLES:
is_commutative()
Return True if this skew polynomial ring is commutative, i.e. if the twist map is the identity.
EXAMPLES:
is_exact()
Return True if elements of this skew polynomial ring are exact. This happens if and only if elements of
the base ring are exact.
EXAMPLES:
is_finite()
Return False since skew polynomial rings are not finite (unless the base ring is 0.)
EXAMPLES:
is_sparse()
Return True if the elements of this polynomial ring are sparsely represented.
Warning: Since sparse skew polynomials are not yet implemented, this function always returns
False.
EXAMPLES:
sage: R.<t> = RR[] sage: sigma = R.hom([t+1]) sage: S.<x> = R[‘x’,sigma] sage: S.is_sparse()
False
lagrange_polynomial(points)
Return the minimal-degree polynomial which interpolates the given points.
More precisely, given 𝑛 pairs (𝑥1 , 𝑦1 ), ..., (𝑥𝑛 , 𝑦𝑛 ) ∈ 𝑅2 , where 𝑅 is self.base_ring(), compute
a skew polynomial 𝑝(𝑥) such that 𝑝(𝑥𝑖 ) = 𝑦𝑖 for each 𝑖, under the condition that the 𝑥𝑖 are linearly
independent over the fixed field of self.twist_map().
If the 𝑥𝑖 are linearly independent over the fixed field of self.twist_map() then such a polynomial is
guaranteed to exist. Otherwise, it might exist depending on the 𝑦𝑖 , but the algorithm used in this imple-
mentation does not support that, and so an error is always raised.
INPUT:
• points – a list of pairs (x_1, y_1),..., (x_n, y_n) of elements of the base ring of self.
The 𝑥𝑖 should be linearly independent over the fixed field of self.twist_map().
OUTPUT:
The Lagrange polynomial.
EXAMPLES:
sage: p = T.lagrange_polynomial(points); p
((-t^4 - 2*t - 3)/-2)*x^2 + (-t^4 - t^3 - t^2 - 3*t - 2)*x + (-t^4 - 2*t^3 -
˓→4*t^2 - 10*t - 9)/-2
True
If the 𝑥𝑖 are linearly dependent over the fixed field of self.twist_map(), then an error is raised:
minimal_vanishing_polynomial(eval_pts)
Return the minimal-degree, monic skew polynomial which vanishes at all the given evaluation points.
The degree of the vanishing polynomial is at most the length of eval_pts. Equality holds if and only if
the elements of eval_pts are linearly independent over the fixed field of self.twist_map().
INPUT:
• eval_pts – list of evaluation points which are linearly independent over the fixed field of the twist
map of the associated skew polynomial ring
OUTPUT:
The minimal vanishing polynomial.
EXAMPLES:
sage: k.<t> = GF(5^3)
sage: Frob = k.frobenius_endomorphism()
sage: S.<x> = k['x',Frob]
sage: eval_pts = [1, t, t^2]
sage: b = S.minimal_vanishing_polynomial(eval_pts); b
x^3 + 4
If the evaluation points are linearly dependent over the fixed field of the twist map, then the returned
polynomial has lower degree than the number of evaluation points:
sage: S.minimal_vanishing_polynomial([t])
x + 3*t^2 + 3*t
sage: S.minimal_vanishing_polynomial([t, 3*t])
x + 3*t^2 + 3*t
ngens()
Return the number of generators of this skew polynomial ring, which is 1.
EXAMPLES:
sage: R.<t> = RR[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]
sage: S.ngens()
1
parameter(n=0)
Return the indeterminate generator of this skew polynomial ring.
INPUT:
• n – index of generator to return (default: 0). Exists for compatibility with other polynomial rings.
EXAMPLES:
sage: R.<t> = QQ[]
sage: sigma = R.hom([t+1])
sage: S.<x> = R['x',sigma]; S
Skew Polynomial Ring in x over Univariate Polynomial Ring in t over Rational
˓→Field twisted by t |--> t + 1
sage: y = S.gen(); y
x
(continues on next page)
If a tuple of two integers is given for the degree argument, a random integer will be chosen between the
first and second element of the tuple as the degree, both inclusive:
If the first tuple element is greater than the second, a a ValueError is raised:
sage: S.random_element(degree=(5,4))
Traceback (most recent call last):
...
ValueError: first degree argument must be less or equal to the second
twist_map(n=1)
Return the twist map, the automorphism of the base ring of self, iterated n times.
INPUT:
• n - an integer (default: 1)
OUTPUT:
n-th iterative of the twist map of this skew polynomial ring.
EXAMPLES:
sage: S.twist_map(-1)
Traceback (most recent call last):
...
NotImplementedError: inversion of the twist map Ring endomorphism of
˓→Univariate Polynomial Ring in t over Rational Field
Defn: t |--> t + 1
FIVE
RATIONAL FUNCTIONS
AUTHORS:
• William Stein (with input from David Joyner, David Kohel, and Joe Wetherell)
• Burcin Erocal
• Julian Rüth (2017-06-27): embedding into the field of fractions and its section
EXAMPLES:
Quotienting is a constructor for an element of the fraction field:
The GCD is not taken (since it doesn’t converge sometimes) in the inexact case:
sage: F = FractionField(PolynomialRing(RationalField(),'x'))
sage: F == loads(dumps(F))
True
sage: F = FractionField(PolynomialRing(IntegerRing(),'x'))
sage: F == loads(dumps(F))
True
sage: F = FractionField(PolynomialRing(RationalField(),2,'x'))
sage: F == loads(dumps(F))
True
sage.rings.fraction_field.FractionField(R, names=None)
Create the fraction field of the integral domain R.
499
Sage Reference Manual: Polynomials, Release 8.6
INPUT:
• R – an integral domain
• names – ignored
EXAMPLES:
We create some example fraction fields:
sage: FractionField(IntegerRing())
Rational Field
sage: FractionField(PolynomialRing(RationalField(),'x'))
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: FractionField(PolynomialRing(IntegerRing(),'x'))
Fraction Field of Univariate Polynomial Ring in x over Integer Ring
sage: FractionField(PolynomialRing(RationalField(),2,'x'))
Fraction Field of Multivariate Polynomial Ring in x0, x1 over Rational Field
sage: Frac(Integers(4))
Traceback (most recent call last):
...
TypeError: R must be an integral domain.
class sage.rings.fraction_field.FractionFieldEmbedding
Bases: sage.structure.coerce_maps.DefaultConvertMap_unique
The embedding of an integral domain into its field of fractions.
EXAMPLES:
is_injective()
Return whether this map is injective.
EXAMPLES:
The map from an integral domain to its fraction field is always injective:
is_surjective()
Return whether this map is surjective.
EXAMPLES:
section()
Return a section of this map.
EXAMPLES:
class sage.rings.fraction_field.FractionFieldEmbeddingSection
Bases: sage.categories.map.Section
The section of the embedding of an integral domain into its field of fractions.
EXAMPLES:
function_field()
Return the isomorphic function field.
EXAMPLES:
See also:
sage.rings.function_field.RationalFunctionField.field()
maximal_order()
Return the maximal order in this fraction field.
EXAMPLES:
sage: K = FractionField(GF(5)['t'])
sage: K.maximal_order()
Univariate Polynomial Ring in t over Finite Field of size 5
ring_of_integers()
Return the ring of integers in this fraction field.
EXAMPLES:
sage: K = FractionField(GF(5)['t'])
sage: K.ring_of_integers()
Univariate Polynomial Ring in t over Finite Field of size 5
sage: R = Frac(ZZ['t'])
sage: R.base_ring()
Integer Ring
characteristic()
Return the characteristic of this fraction field.
EXAMPLES:
sage: R = Frac(ZZ['t'])
sage: R.base_ring()
Integer Ring
sage: R = Frac(ZZ['t']); R.characteristic()
0
sage: R = Frac(GF(5)['w']); R.characteristic()
5
construction()
EXAMPLES:
sage: Frac(ZZ['x']).construction()
(FractionField, Univariate Polynomial Ring in x over Integer Ring)
sage: K = Frac(GF(3)['t'])
(continues on next page)
gen(i=0)
Return the i-th generator of self.
EXAMPLES:
sage: R = Frac(PolynomialRing(QQ,'z',10)); R
Fraction Field of Multivariate Polynomial Ring in z0, z1, z2, z3, z4, z5, z6,
˓→z7, z8, z9 over Rational Field
sage: R.0
z0
sage: R.gen(3)
z3
sage: R.3
z3
is_exact()
Return if self is exact which is if the underlying ring is exact.
EXAMPLES:
sage: Frac(ZZ['x']).is_exact()
True
sage: Frac(CDF['x']).is_exact()
False
is_field(proof=True)
Return True, since the fraction field is a field.
EXAMPLES:
sage: Frac(ZZ).is_field()
True
is_finite()
Tells whether this fraction field is finite.
Note: A fraction field is finite if and only if the associated integral domain is finite.
EXAMPLES:
sage: Frac(QQ['a','b','c']).is_finite()
False
ngens()
This is the same as for the parent object.
EXAMPLES:
sage: R = Frac(PolynomialRing(QQ,'z',10)); R
Fraction Field of Multivariate Polynomial Ring in z0, z1, z2, z3, z4, z5, z6,
˓→z7, z8, z9 over Rational Field
(continues on next page)
random_element(*args, **kwds)
Return a random element in this fraction field.
The arguments are passed to the random generator of the underlying ring.
EXAMPLES:
sage: F = ZZ['x'].fraction_field()
sage: F.random_element() # random
(2*x - 8)/(-x^2 + x)
sage: f = F.random_element(degree=5)
sage: f.numerator().degree()
5
sage: f.denominator().degree()
5
ring()
Return the ring that this is the fraction field of.
EXAMPLES:
sage: R = Frac(QQ['x,y'])
sage: R
Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field
sage: R.ring()
Multivariate Polynomial Ring in x, y over Rational Field
some_elements()
Return some elements in this field.
EXAMPLES:
sage.rings.fraction_field.is_FractionField(x)
Test whether or not x inherits from FractionField_generic.
EXAMPLES:
AUTHORS:
• William Stein (input from David Joyner, David Kohel, and Joe Wetherell)
• Sebastian Pancratz (2010-01-06): Rewrite of addition, multiplication and derivative to use Henrici’s algorithms
[Ho72]
REFERENCES:
class sage.rings.fraction_field_element.FractionFieldElement
Bases: sage.structure.element.FieldElement
EXAMPLES:
denominator()
Return the denominator of self.
EXAMPLES:
is_one()
Return True if this element is equal to one.
EXAMPLES:
sage: F = ZZ['x,y'].fraction_field()
sage: x,y = F.gens()
sage: (x/x).is_one()
True
sage: (x/y).is_one()
False
is_square(root=False)
Return whether or not self is a perfect square.
If the optional argument root is True, then also returns a square root (or None, if the fraction field
element is not square).
INPUT:
• root – whether or not to also return a square root (default: False)
OUTPUT:
• bool - whether or not a square
• object - (optional) an actual square root if found, and None otherwise.
EXAMPLES:
sage: (4*(1+t)^4/t^6).is_square(root=True)
(True, (2*t^2 + 4*t + 2)/t^3)
sage: (2*(1+t)^4/t^6).is_square(root=True)
(False, None)
is_zero()
Return True if this element is equal to zero.
EXAMPLES:
sage: F = ZZ['x,y'].fraction_field()
sage: x,y = F.gens()
sage: t = F(0)/x
sage: t.is_zero()
True
sage: u = 1/x - 1/x
sage: u.is_zero()
True
sage: u.parent() is F
True
nth_root(n)
Return a n-th root of this element.
EXAMPLES:
sage: R = QQ['t'].fraction_field()
sage: t = R.gen()
sage: p = (t+1)^3 / (t^2+t-1)^3
sage: p.nth_root(3)
(t + 1)/(t^2 + t - 1)
numerator()
Return the numerator of self.
EXAMPLES:
reduce()
Reduce this fraction.
Divides out the gcd of the numerator and denominator. If the denominator becomes a unit, it becomes 1.
Additionally, depending on the base ring, the leading coefficients of the numerator and the denominator
may be normalized to 1.
Automatically called for exact rings, but because it may be numerically unstable for inexact rings it must
be called manually in that case.
EXAMPLES:
valuation(v=None)
Return the valuation of self, assuming that the numerator and denominator have valuation functions
defined on them.
EXAMPLES:
sage: x = PolynomialRing(RationalField(),'x').gen()
sage: f = (x^3 + x)/(x^2 - 2*x^3)
sage: f
(-1/2*x^2 - 1/2)/(x^2 - 1/2*x)
sage: f.valuation()
-1
sage: f.valuation(x^2+1)
1
class sage.rings.fraction_field_element.FractionFieldElement_1poly_field
Bases: sage.rings.fraction_field_element.FractionFieldElement
A fraction field element where the parent is the fraction field of a univariate polynomial ring over a field.
Many of the functions here are included for coherence with number fields.
is_integral()
Returns whether this element is actually a polynomial.
EXAMPLES:
reduce()
Pick a normalized representation of self.
In particular, for any a == b, after normalization they will have the same numerator and denominator.
EXAMPLES:
For univariate rational functions over a field, we have:
Compare with:
support()
Returns a sorted list of primes dividing either the numerator or denominator of this element.
EXAMPLES:
sage: h.support()
[t - 1, t + 3, t^2 + 2, t^2 + t + 1, t^4 - 2]
sage.rings.fraction_field_element.is_FractionFieldElement(x)
Return whether or not x is a FractionFieldElement.
EXAMPLES:
sage.rings.fraction_field_element.make_element_old(parent, cdict)
Used for unpickling old FractionFieldElement pickles.
EXAMPLES:
(x + y)/(x - y)
iter(bound=None, start=None)
EXAMPLES:
class sage.rings.fraction_field_FpT.FpTElement
Bases: sage.structure.element.RingElement
An element of an FpT fraction field.
denom()
Returns the denominator of this element, as an element of the polynomial ring.
EXAMPLES:
sage: K = GF(11)['t'].fraction_field()
sage: t = K.gen(0); a = (t + 1/t)^3 - 1
sage: a.denom()
t^3
denominator()
Returns the denominator of this element, as an element of the polynomial ring.
EXAMPLES:
sage: K = GF(11)['t'].fraction_field()
sage: t = K.gen(0); a = (t + 1/t)^3 - 1
sage: a.denominator()
t^3
factor()
EXAMPLES:
sage: K = Frac(GF(5)['t'])
sage: t = K.gen()
sage: f = 2 * (t+1) * (t^2+t+1)^2 / (t-1)
sage: factor(f)
(2) * (t + 4)^-1 * (t + 1) * (t^2 + t + 1)^2
is_square()
Returns True if this element is the square of another element of the fraction field.
EXAMPLES:
next()
This function iterates through all polynomials, returning the “next” polynomial after this one.
The strategy is as follows:
• We always leave the denominator monic.
• We progress through the elements with both numerator and denominator monic, and with the denom-
inator less than the numerator. For each such, we output all the scalar multiples of it, then all of the
scalar multiples of its inverse.
• So if the leading coefficient of the numerator is less than p-1, we scale the numerator to increase it by
1.
numer()
Returns the numerator of this element, as an element of the polynomial ring.
EXAMPLES:
sage: K = GF(11)['t'].fraction_field()
sage: t = K.gen(0); a = (t + 1/t)^3 - 1
sage: a.numer()
t^6 + 3*t^4 + 10*t^3 + 3*t^2 + 1
numerator()
Returns the numerator of this element, as an element of the polynomial ring.
EXAMPLES:
sage: K = GF(11)['t'].fraction_field()
sage: t = K.gen(0); a = (t + 1/t)^3 - 1
sage: a.numerator()
t^6 + 3*t^4 + 10*t^3 + 3*t^2 + 1
sqrt(extend=True, all=False)
Returns the square root of this element.
INPUT:
• extend - bool (default: True); if True, return a square root in an extension ring, if necessary. Other-
wise, raise a ValueError if the square is not in the base ring.
• all - bool (default: False); if True, return all square roots of self, instead of just one.
EXAMPLES:
subs(*args, **kwds)
EXAMPLES:
sage: K = Frac(GF(11)['t'])
sage: t = K.gen()
sage: f = (t+1)/(t-1)
sage: f.subs(t=2)
3
sage: f.subs(X=2)
(t + 1)/(t + 10)
valuation(v)
Returns the valuation of self at 𝑣.
EXAMPLES:
class sage.rings.fraction_field_FpT.FpT_Fp_section
Bases: sage.categories.map.Section
This class represents the section from GF(p)(t) back to GF(p)[t]
EXAMPLES:
Warning: Comparison of FpT_Fp_section objects is not currently implemented. See :trac: 23469.
sage: fprime = loads(dumps(f))
sage: fprime == f
False
class sage.rings.fraction_field_FpT.FpT_Polyring_section
Bases: sage.categories.map.Section
This class represents the section from GF(p)(t) back to GF(p)[t]
EXAMPLES:
class sage.rings.fraction_field_FpT.FpT_iter
Bases: object
Returns a class that iterates over all elements of an FpT.
EXAMPLES:
sage: K = GF(3)['t'].fraction_field()
sage: I = K.iter(1)
sage: list(I)
[0,
1,
2,
t,
t + 1,
t + 2,
2*t,
2*t + 1,
2*t + 2,
1/t,
2/t,
(t + 1)/t,
(t + 2)/t,
(2*t + 1)/t,
(2*t + 2)/t,
1/(t + 1),
2/(t + 1),
t/(t + 1),
(t + 2)/(t + 1),
2*t/(t + 1),
(2*t + 1)/(t + 1),
1/(t + 2),
2/(t + 2),
t/(t + 2),
(t + 1)/(t + 2),
2*t/(t + 2),
(2*t + 2)/(t + 2)]
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.fraction_field_FpT.Fp_FpT_coerce
Bases: sage.rings.morphism.RingHomomorphism
This class represents the coercion map from GF(p) to GF(p)(t)
EXAMPLES:
sage: type(f)
<type 'sage.rings.fraction_field_FpT.Fp_FpT_coerce'>
section()
Returns the section of this inclusion: the partially defined map from GF(p)(t) back to GF(p), defined
on constant elements.
EXAMPLES:
class sage.rings.fraction_field_FpT.Polyring_FpT_coerce
Bases: sage.rings.morphism.RingHomomorphism
This class represents the coercion map from GF(p)[t] to GF(p)(t)
EXAMPLES:
sage: type(f)
<type 'sage.rings.fraction_field_FpT.Polyring_FpT_coerce'>
section()
Returns the section of this inclusion: the partially defined map from GF(p)(t) back to GF(p)[t],
defined on elements with unit denominator.
EXAMPLES:
class sage.rings.fraction_field_FpT.ZZ_FpT_coerce
Bases: sage.rings.morphism.RingHomomorphism
This class represents the coercion map from ZZ to GF(p)(t)
EXAMPLES:
sage: type(f)
<type 'sage.rings.fraction_field_FpT.ZZ_FpT_coerce'>
section()
Returns the section of this inclusion: the partially defined map from GF(p)(t) back to ZZ, defined on
constant elements.
EXAMPLES:
SIX
LAURENT POLYNOMIALS
If 𝑅 is a commutative ring, then the ring of Laurent polynomials in 𝑛 variables over 𝑅 is 𝑅[𝑥±1 ±1 ±1
1 , 𝑥2 , . . . , 𝑥𝑛 ]. We
implement it as a quotient ring
AUTHORS:
• David Roe (2008-2-23): created
• David Loeffler (2009-07-10): cleaned up docstrings
sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing(base_ring,
*args,
**kwds)
Return the globally unique univariate or multivariate Laurent polynomial ring with given properties and variable
name or names.
There are four ways to call the Laurent polynomial ring constructor:
1. LaurentPolynomialRing(base_ring, name, sparse=False)
2. LaurentPolynomialRing(base_ring, names, order='degrevlex')
3. LaurentPolynomialRing(base_ring, name, n, order='degrevlex')
4. LaurentPolynomialRing(base_ring, n, name, order='degrevlex')
The optional arguments sparse and order must be explicitly named, and the other arguments must be given
positionally.
INPUT:
• base_ring – a commutative ring
• name – a string
• names – a list or tuple of names, or a comma separated string
• n – a positive integer
• sparse – bool (default: False), whether or not elements are sparse
• order – string or TermOrder, e.g.,
– 'degrevlex' (default) – degree reverse lexicographic
– 'lex' – lexicographic
517
Sage Reference Manual: Polynomials, Release 8.6
You can’t just globally change the names of those variables. This is because objects all over Sage could have
pointers to that polynomial ring.
sage: R._assign_names(['z','w'])
Traceback (most recent call last):
...
ValueError: variable names cannot be changed after object creation.
EXAMPLES:
1. LaurentPolynomialRing(base_ring, name, sparse=False)
Use the diamond brackets notation to make the variable ready for use after you define the ring:
sage: LaurentPolynomialRing(QQ)
Traceback (most recent call last):
...
TypeError: you must specify the names of the variables
sage: (R is S) and (S is T)
True
By calling the inject_variables() method, all those variable names are available for interactive
use:
sage: R = LaurentPolynomialRing(GF(7),15,'w'); R
Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, w8,
˓→w9, w10, w11, w12, w13, w14 over Finite Field of size 7
sage: R.inject_variables()
Defining w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14
sage: (w0 + 2*w8 + w13)^2
w0^2 + 4*w0*w8 + 4*w8^2 + 2*w0*w13 + 4*w8*w13 + w13^2
class sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic(R)
Bases: sage.rings.ring.CommutativeRing, sage.structure.parent.Parent
Laurent polynomial ring (base class).
EXAMPLES:
This base class inherits from CommutativeRing. Since trac ticket #11900, it is also initialised as such:
sage: R = LaurentPolynomialRing(QQ,2,'x')
sage: R.change_ring(ZZ)
Multivariate Laurent Polynomial Ring in x0, x1 over Integer Ring
characteristic()
Returns the characteristic of the base ring.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').characteristic()
0
sage: LaurentPolynomialRing(GF(3),2,'x').characteristic()
3
sage: P.<x>=LaurentPolynomialRing(QQ)
sage: P
Univariate Laurent Polynomial Ring in x over Rational Field
sage: PP=P.completion(x)
sage: PP
Laurent Series Ring in x over Rational Field
sage: f=1-1/x
sage: PP(f)
-x^-1 + 1
sage: 1/PP(f)
-x - x^2 - x^3 - x^4 - x^5 - x^6 - x^7 - x^8 - x^9 - x^10 - x^11 - x^12 - x^
˓→13 - x^14 - x^15 - x^16 - x^17 - x^18 - x^19 - x^20 + O(x^21)
construction()
Return the construction of self.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x,y').construction()
(LaurentPolynomialFunctor,
Univariate Laurent Polynomial Ring in x over Rational Field)
fraction_field()
The fraction field is the same as the fraction field of the polynomial ring.
EXAMPLES:
gen(i=0)
Returns the 𝑖𝑡ℎ generator of self. If i is not specified, then the first generator will be returned.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').gen()
x0
sage: LaurentPolynomialRing(QQ,2,'x').gen(0)
x0
sage: LaurentPolynomialRing(QQ,2,'x').gen(1)
x1
ideal()
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').ideal()
Traceback (most recent call last):
...
NotImplementedError
is_exact()
Returns True if the base ring is exact.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').is_exact()
True
sage: LaurentPolynomialRing(RDF,2,'x').is_exact()
False
is_field(proof=True)
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').is_field()
False
is_finite()
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').is_finite()
False
is_integral_domain(proof=True)
Returns True if self is an integral domain.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').is_integral_domain()
True
is_noetherian()
Returns True if self is Noetherian.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').is_noetherian()
Traceback (most recent call last):
...
NotImplementedError
krull_dimension()
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').krull_dimension()
Traceback (most recent call last):
...
NotImplementedError
ngens()
Return the number of generators of self.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').ngens()
2
sage: LaurentPolynomialRing(QQ,1,'x').ngens()
1
polynomial_ring()
Returns the polynomial ring associated with self.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').polynomial_ring()
Multivariate Polynomial Ring in x0, x1 over Rational Field
sage: LaurentPolynomialRing(QQ,1,'x').polynomial_ring()
Multivariate Polynomial Ring in x over Rational Field
remove_var(var)
EXAMPLES:
sage: R = LaurentPolynomialRing(QQ,'x,y,z')
sage: R.remove_var('x')
Multivariate Laurent Polynomial Ring in y, z over Rational Field
sage: R.remove_var('x').remove_var('y')
Univariate Laurent Polynomial Ring in z over Rational Field
term_order()
Returns the term order of self.
EXAMPLES:
sage: LaurentPolynomialRing(QQ,2,'x').term_order()
Degree reverse lexicographic term order
variable_names_recursive(depth=+Infinity)
Return the list of variable names of this ring and its base rings, as if it were a single multi-variate Laurent
polynomial.
INPUT:
• depth – an integer or Infinity.
OUTPUT:
A tuple of strings.
EXAMPLES:
class sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_mpair(R)
Bases: sage.rings.polynomial.laurent_polynomial_ring.
LaurentPolynomialRing_generic
EXAMPLES:
sage: L = LaurentPolynomialRing(QQ,2,'x')
sage: type(L)
<class
'sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_mpair_with_
˓→category'>
sage: L == loads(dumps(L))
True
Element
alias of LaurentPolynomial_mpair
monomial(*args)
Return the monomial whose exponents are given in argument.
EXAMPLES:
sage: L.monomial(1, 2, 3)
Traceback (most recent call last):
(continues on next page)
class sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_univariate(R)
Bases: sage.rings.polynomial.laurent_polynomial_ring.
LaurentPolynomialRing_generic
EXAMPLES:
sage: L = LaurentPolynomialRing(QQ,'x')
sage: type(L)
<class 'sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_
˓→univariate_with_category'>
sage: L == loads(dumps(L))
True
Element
alias of LaurentPolynomial_univariate
sage.rings.polynomial.laurent_polynomial_ring.is_LaurentPolynomialRing(R)
Returns True if and only if R is a Laurent polynomial ring.
EXAMPLES:
sage: P = PolynomialRing(QQ,2,'x')
sage: is_LaurentPolynomialRing(P)
False
sage: R = LaurentPolynomialRing(QQ,3,'x')
sage: is_LaurentPolynomialRing(R)
True
class sage.rings.polynomial.laurent_polynomial.LaurentPolynomial
Bases: sage.structure.element.CommutativeAlgebraElement
Base class for Laurent polynomials.
change_ring(R)
Return a copy of this Laurent polynomial, with coefficients in R.
EXAMPLES:
dict()
Abstract dict method.
EXAMPLES:
hamming_weight()
Return the hamming weight of self.
The hamming weight is number of non-zero coefficients and also known as the weight or sparsity.
EXAMPLES:
number_of_terms()
Abstract method for number of terms
EXAMPLES:
class sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair
Bases: sage.rings.polynomial.laurent_polynomial.LaurentPolynomial
Multivariate Laurent polynomials.
coefficient(mon)
Return the coefficient of mon in self, where mon must have the same parent as self.
The coefficient is defined as follows. If 𝑓 is this polynomial, then the coefficient 𝑐𝑚 is sum:
∑︁ 𝑇
𝑐𝑚 :=
𝑚
𝑇
OUTPUT:
Element of the parent of self.
EXAMPLES:
sage: P.<x,y> = LaurentPolynomialRing(QQ)
coefficients()
Return the nonzero coefficients of self in a list.
The returned list is decreasingly ordered by the term ordering of self.parent().
EXAMPLES:
sage: L.<x,y,z> = LaurentPolynomialRing(QQ,order='degrevlex')
sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
sage: f.coefficients()
[4, 3, 2, 1]
sage: L.<x,y,z> = LaurentPolynomialRing(QQ,order='lex')
sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7
sage: f.coefficients()
[4, 1, 2, 3]
constant_coefficient()
Return the constant coefficient of self.
EXAMPLES:
sage: P.<x,y> = LaurentPolynomialRing(QQ)
sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f
-x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2
(continues on next page)
degree(x=None)
Return the degree of x in self.
EXAMPLES:
derivative(*args)
The formal derivative of this Laurent polynomial, with respect to variables supplied in args.
Multiple variables and iteration counts may be supplied; see documentation for the global derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
dict()
EXAMPLES:
diff(*args)
The formal derivative of this Laurent polynomial, with respect to variables supplied in args.
Multiple variables and iteration counts may be supplied; see documentation for the global derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
differentiate(*args)
The formal derivative of this Laurent polynomial, with respect to variables supplied in args.
Multiple variables and iteration counts may be supplied; see documentation for the global derivative()
function for more details.
See also:
_derivative()
EXAMPLES:
exponents()
Return a list of the exponents of self.
EXAMPLES:
factor()
Returns a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial.
EXAMPLES:
has_any_inverse()
Returns True if self contains any monomials with a negative exponent, False otherwise.
EXAMPLES:
has_inverse_of(i)
INPUT:
• i – The index of a generator of self.parent()
OUTPUT:
Returns True if self contains a monomial including the inverse of self.parent().gen(i), False
otherwise.
EXAMPLES:
is_constant()
Return whether this Laurent polynomial is constant.
EXAMPLES:
is_monomial()
Return True if self is a monomial.
EXAMPLES:
is_square(root=False)
Test whether this Laurent polynomial is a square root.
INPUT:
• root - boolean (default False) - if set to True then return a pair (True, sqrt) with sqrt a
square root of this Laurent polynomial when it exists or (False, None).
EXAMPLES:
sage: x.is_square()
False
sage: x.is_square(root=True)
(False, None)
is_unit()
Return True if self is a unit.
The ground ring is assumed to be an integral domain.
This means that the Laurent polynomial is a monomial with unit coefficient.
EXAMPLES:
is_univariate()
Return True if this is a univariate or constant Laurent polynomial, and False otherwise.
EXAMPLES:
monomial_coefficient(mon)
Return the coefficient in the base ring of the monomial mon in self, where mon must have the same
parent as self.
This function contrasts with the function coefficient() which returns the coefficient of a monomial
viewing this polynomial in a polynomial ring over a base ring having fewer variables.
INPUT:
• mon – a monomial
See also:
For coefficients in a base ring of fewer variables, see coefficient().
EXAMPLES:
monomials()
Return the list of monomials in self.
EXAMPLES:
number_of_terms()
Return the number of non-zero coefficients of self.
Also called weight, hamming weight or sparsity.
EXAMPLES:
sage: f.hamming_weight()
101
quo_rem(right)
Divide this Laurent polynomial by right and return a quotient and a remainder.
INPUT:
• right – a Laurent polynomial
OUTPUT:
A pair of Laurent polynomials.
EXAMPLES:
subs(in_dict=None, **kwds)
Substitute some variables in this Laurent polynomial.
Variable/value pairs for the substitution may be given as a dictionary or via keyword-value pairs. If both
are present, the latter take precedence.
INPUT:
• in_dict – dictionary (optional)
• **kwargs – keyword arguments
OUTPUT:
A Laurent polynomial.
EXAMPLES:
sage: f = x^-1
sage: f.subs(x=2)
1/2
sage: f.subs({x: 2})
1/2
univariate_polynomial(R=None)
Returns a univariate polynomial associated to this multivariate polynomial.
INPUT:
• R - (default: None) a univariate Laurent polynomial ring
If this polynomial is not in at most one variable, then a ValueError exception is raised. The new
polynomial is over the same base ring as the given LaurentPolynomial and in the variable x if no
ring R is provided.
EXAMPLES:
sage: g = R(1)
sage: h = g.univariate_polynomial(); h
1
sage: h.parent()
Univariate Laurent Polynomial Ring in x over Integer Ring
variables(sort=True)
Return a tuple of all variables occurring in self.
INPUT:
• sort – specifies whether the indices shall be sorted
EXAMPLES:
class sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate
Bases: sage.rings.polynomial.laurent_polynomial.LaurentPolynomial
A univariate Laurent polynomial in the form of 𝑡𝑛 · 𝑓 where 𝑓 is a polynomial in 𝑡.
INPUT:
• parent – a Laurent polynomial ring
• f – a polynomial (or something can be coerced to one)
• n – (default: 0) an integer
AUTHORS:
• Tom Boothby (2011) copied this class almost verbatim from laurent_series_ring_element.
pyx, so most of the credit goes to William Stein, David Joyner, and Robert Bradshaw
• Travis Scrimshaw (09-2013): Cleaned-up and added a few extra methods
coefficients()
Return the nonzero coefficients of self.
EXAMPLES:
constant_coefficient()
Return the coefficient of the constant term of self.
EXAMPLES:
degree()
Return the degree of self.
EXAMPLES:
derivative(*args)
The formal derivative of this Laurent polynomial, with respect to variables supplied in args.
Multiple variables and iteration counts may be supplied. See documentation for the global
derivative() function for more details.
See also:
_derivative()
EXAMPLES:
dict()
Return a dictionary representing self.
EXAMPLES:: sage: R.<x,y> = ZZ[] sage: Q.<t> = LaurentPolynomialRing(R) sage: f = (x^3 +
y/t^3)^3 + t^2; f y^3*t^-9 + 3*x^3*y^2*t^-6 + 3*x^6*y*t^-3 + x^9 + t^2 sage: f.dict() {-9: y^3,
-6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
exponents()
Return the exponents appearing in self with nonzero coefficients.
EXAMPLES:
factor()
Return a Laurent monomial (the unit part of the factorization) and a factored polynomial.
EXAMPLES:
gcd(right)
Return the gcd of self with right where the common divisor d makes both self and right into
polynomials with the lowest possible degree.
EXAMPLES:
integral()
The formal integral of this Laurent series with 0 constant term.
EXAMPLES:
The integral may or may not be defined if the base ring is not a field.
sage: f = t^3
sage: f.integral()
Traceback (most recent call last):
...
ArithmeticError: coefficients of integral cannot be coerced into the base ring
sage: t = LaurentPolynomialRing(ZZ,'t').0
sage: f = -1/t^3 - 31/t
sage: f.integral()
Traceback (most recent call last):
...
ArithmeticError: the integral of is not a Laurent polynomial, since t^-1 has
˓→nonzero coefficient
inverse_of_unit()
Return the inverse of self if a unit.
EXAMPLES:
is_constant()
Return whether this Laurent polynomial is constant.
EXAMPLES:
is_monomial()
Return True if self is a monomial; that is, if self is 𝑥𝑛 for some integer 𝑛.
EXAMPLES:
is_square(root=False)
Return whether this Laurent polynomial is a square.
If root is set to True then return a pair made of the boolean answer together with None or a square root.
EXAMPLES:
sage: R.one().is_square()
True
sage: R(2).is_square()
False
sage: t.is_square()
False
sage: (t**-2).is_square()
True
is_unit()
Return True if this Laurent polynomial is a unit in this ring.
EXAMPLES:
ALGORITHM: A Laurent polynomial is a unit if and only if its “unit part” is a unit.
is_zero()
Return 1 if self is 0, else return 0.
EXAMPLES:
number_of_terms()
Return the number of non-zero coefficients of self.
Also called weight, hamming weight or sparsity.
EXAMPLES:
sage: f.hamming_weight()
101
polynomial_construction()
Return the polynomial and the shift in power used to construct the Laurent polynomial 𝑡𝑛 𝑢.
OUTPUT:
A tuple (u, n) where u is the underlying polynomial and n is the power of the exponent shift.
EXAMPLES:
quo_rem(right_r)
Attempts to divide self by right and returns a quotient and a remainder.
EXAMPLES:
residue()
Return the residue of self.
The residue is the coefficient of 𝑡− 1.
EXAMPLES:
shift(k)
Return this Laurent polynomial multiplied by the power 𝑡𝑛 . Does not change this polynomial.
EXAMPLES:
truncate(n)
Return a polynomial with degree at most 𝑛 − 1 whose 𝑗-th coefficients agree with self for all 𝑗 < 𝑛.
EXAMPLES:
valuation(p=None)
Return the valuation of self.
The valuation of a Laurent polynomial 𝑡𝑛 𝑢 is 𝑛 plus the valuation of 𝑢.
EXAMPLES:
variable_name()
Return the name of variable of self as a string.
EXAMPLES:
variables()
Return the tuple of variables occuring in this Laurent polynomial.
EXAMPLES:
This module implements MacMahon's Omega Operator [Mac1915], which takes a quotient of Laurent polyno-
mials and removes all negative exponents in the corresponding power series.
6.3.1 Examples
In the following example, all negative exponents of 𝜇 are removed. The formula
1 1
Ω≥ =
(1 − 𝑥𝜇)(1 − 𝑦/𝜇) (1 − 𝑥)(1 − 𝑥𝑦)
6.3.2 Various
AUTHORS:
• Daniel Krenn (2016)
ACKNOWLEDGEMENT:
• Daniel Krenn is supported by the Austrian Science Fund (FWF): P 24644-N26.
6.3.3 Functions
REFERENCES:
• [Mac1915]
• [APR2001]
EXAMPLES:
sage: MacMahonOmega(mu,
....: Factorization([(mu, 2), (1 - x*mu, -1), (1 - y/mu, -1)]))
(-x*y^2 - x*y + y^2 + y + 1) * (-x + 1)^-1 * (-x*y + 1)^-1
sage: MacMahonOmega(mu, mu^2 / ((1 - x*mu)*(1 - y/mu))) # not tested because not
˓→fully implemented
sage.rings.polynomial.omega.Omega_ge(a, exponents)
Return Ω≥ of the expression specified by the input.
To be more precise, calculate
𝜇𝑎
Ω≥
(1 − 𝑧0 𝜇𝑒0 ) . . . (1 − 𝑧𝑛−1 𝜇𝑒𝑛−1 )
and return its numerator and a factorization of its denominator. Note that 𝑧0 , . . . , 𝑧𝑛−1 only appear in the output,
but not in the input.
INPUT:
• a – an integer
• exponents – a tuple of integers
OUTPUT:
A pair representing a quotient as follows: Its first component is the numerator as a Laurent polynomial, its
second component a factorization of the denominator as a tuple of Laurent polynomials, where each Laurent
polynomial 𝑧 represents a factor 1 − 𝑧.
The parents of these Laurent polynomials is always a Laurent polynomial ring in 𝑧0 , . . . , 𝑧𝑛−1 over Z, where 𝑛
is the length of exponents.
EXAMPLES:
sage: from sage.rings.polynomial.omega import Omega_ge
sage: Omega_ge(0, (1, -2))
(1, (z0, z0^2*z1))
sage: Omega_ge(0, (1, -3))
(continues on next page)
sage.rings.polynomial.omega.homogenous_symmetric_function(j, x)
Return a complete homogeneous symmetric polynomial (Wikipedia article Com-
plete_homogeneous_symmetric_polynomial).
INPUT:
• j – the degree as a nonnegative integer
• x – an iterable of variables
OUTPUT:
A polynomial of the common parent of all entries of x
EXAMPLES:
SEVEN
By Infinite Polynomial Rings, we mean polynomial rings in a countably infinite number of variables. The implemen-
tation consists of a wrapper around the current finite polynomial rings in Sage.
AUTHORS:
• Simon King <[email protected]>
• Mike Hansen <[email protected]>
An Infinite Polynomial Ring has finitely many generators 𝑥* , 𝑦* , ... and infinitely many variables of the form
𝑥0 , 𝑥1 , 𝑥2 , ..., 𝑦0 , 𝑦1 , 𝑦2 , ..., .... We refer to the natural number 𝑛 as the index of the variable 𝑥𝑛 .
INPUT:
• R, the base ring. It has to be a commutative ring, and in some applications it must even be a field
• names, a list of generator names. Generator names must be alpha-numeric.
• order (optional string). The default order is 'lex' (lexicographic). 'deglex' is degree lexicographic, and
'degrevlex' (degree reverse lexicographic) is possible but discouraged.
Each generator x produces an infinite sequence of variables x[1], x[2], ... which are printed on screen as
x_1, x_2, ... and are latex typeset as 𝑥1 , 𝑥2 . Then, the Infinite Polynomial Ring is formed by polynomials in
these variables.
By default, the monomials are ordered lexicographically. Alternatively, degree (reverse) lexicographic ordering is
possible as well. However, we do not guarantee that the computation of Groebner bases will terminate in this case.
In either case, the variables of a Infinite Polynomial Ring X are ordered according to the following rule:
X.gen(i)[m] > X.gen(j)[n] if and only if i<j or (i==j and m>n)
We provide a ‘dense’ and a ‘sparse’ implementation. In the dense implementation, the Infinite Polynomial Ring
carries a finite polynomial ring that comprises all variables up to the maximal index that has been used so far. This is
potentially a very big ring and may also comprise many variables that are not used.
In the sparse implementation, we try to keep the underlying finite polynomial rings small, using only those variables
that are really needed. By default, we use the dense implementation, since it usually is much faster.
EXAMPLES:
sage: f = x[5] + 2; f
(continues on next page)
547
Sage Reference Manual: Polynomials, Release 8.6
It has some advantages to have an underlying ring that is not univariate. Hence, we always have at least two variables:
sage: g._p.parent()
Multivariate Polynomial Ring in y_1, y_0 over Integer Ring
sage: f2 = alpha[5] + 2; f2
alpha_5 + 2
sage: g2 = 3*beta[1]; g2
3*beta_1
sage: A.polynomial_ring()
Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0,
˓→beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field
sage: f+g
x_5 + 3*y_1 + 2
sage: p = x[10]^2*(f+g); p
x_10^2*x_5 + 3*x_10^2*y_1 + 2*x_10^2
sage: p2 = alpha[10]^2*(f2+g2); p2
alpha_10^2*alpha_5 + 3*alpha_10^2*beta_1 + 2*alpha_10^2
sage: P = Permutation(((10,1)))
sage: p^P
x_5*x_1^2 + 3*x_1^2*y_10 + 2*x_1^2
sage: p2^P
alpha_5*alpha_1^2 + 3*alpha_1^2*beta_10 + 2*alpha_1^2
Note that 𝑥𝑃
0 = 𝑥0 , since the permutations only change positive variable indices.
We also implemented ideals of Infinite Polynomial Rings. Here, it is thoroughly assumed that the ideals are set-wise
invariant under the permutation action. We therefore refer to these ideals as Symmetric Ideals. Symmetric Ideals are
finitely generated modulo addition, multiplication by ring elements and permutation of variables. If the base ring is a
field, one can compute Symmetric Groebner Bases:
sage: J = A*(alpha[1]*beta[2])
sage: J.groebner_basis()
[alpha_1*beta_2, alpha_2*beta_1]
It is no problem if one generator of the Infinite Polynomial Ring is called x and one variable of the base ring is also
called x. This is since no variable of the Infinite Polynomial Ring will be called x. However, a problem arises if the
underlying classical Polynomial Ring has a variable x_1, since this can be confused with a variable of the Infinite
Polynomial Ring. In this case, an error will be raised:
Note that X is not merged into Y; this is since the monomial order of X is ‘degrevlex’, but of Y is ‘lex’.
sage: Y
Infinite polynomial ring in x, z over Multivariate Polynomial Ring in x, y_1 over
˓→Integer Ring
The variable x of X can still be interpreted in Y, although the first generator of Y is called x as well:
sage: x
x_*
sage: X('x')
x
sage: Y(X('x'))
x
sage: Y('x')
x
But there is only merging if the resulting monomial order is uniquely determined. This is not the case in the following
examples, and thus an error is raised:
If the type of monomial orderings (e.g., ‘degrevlex’ versus ‘lex’) or if the implementations don’t match, there is no
simplified construction available:
class sage.rings.polynomial.infinite_polynomial_ring.GenDictWithBasering(parent,
start)
A dictionary-like class that is suitable for usage in sage_eval.
This pseudo-dictionary accepts strings as index, and then walks down a chain of base rings of (infinite) polyno-
mial rings until it finds one ring that has the given string as variable name, which is then returned.
EXAMPLES:
sage: sage_eval('3*a_3*b_5-1/2*a_7', D)
-1/2*a_7 + 3*a_3*b_5
next()
Return a dictionary that can be used to interprete strings in the base ring of self.
EXAMPLES:
sage: next(D)
GenDict of Univariate Polynomial Ring in t over Rational Field
sage: sage_eval('t^2', next(D))
t^2
class sage.rings.polynomial.infinite_polynomial_ring.InfiniteGenDict(Gens)
A dictionary-like class that is suitable for usage in sage_eval.
The generators of an Infinite Polynomial Ring are not variables. Variables of an Infinite Polynomial Ring are
returned by indexing a generator. The purpose of this class is to return a variable of an Infinite Polynomial Ring,
given its string representation.
EXAMPLES:
class sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialGen(parent,
name)
Bases: sage.structure.sage_object.SageObject
This class provides the object which is responsible for returning variables in an infinite polynomial ring (imple-
mented in __getitem__()).
EXAMPLES:
class sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRingFactory
Bases: sage.structure.factory.UniqueFactory
A factory for creating infinite polynomial ring elements. It handles making sure that they are unique as well as
handling pickling. For more details, see UniqueFactory and infinite_polynomial_ring.
EXAMPLES:
sage: X is loads(dumps(X))
True
polynomial_ring()
Return the underlying finite polynomial ring.
Note: The ring returned can change over time as more variables are used.
Since the rings are cached, we create here a ring with variable names that do not occur in other doc tests,
so that we avoid side effects.
EXAMPLES:
tensor_with_ring(R)
Return the tensor product of self with another ring.
INPUT:
R - a ring.
OUTPUT:
An infinite polynomial ring that, mathematically, can be seen as the tensor product of self with R.
NOTE:
It is required that the underlying ring of self coerces into R. Hence, the tensor product is in fact merely an
extension of the base ring.
EXAMPLES:
The following tests against a bug that was fixed at trac ticket #10468:
class sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse(R,
names,
or-
der)
Bases: sage.rings.ring.CommutativeRing
Sparse implementation of Infinite Polynomial Rings.
An Infinite Polynomial Ring with generators 𝑥* , 𝑦* , ... over a field 𝐹 is a free commutative 𝐹 -algebra gen-
erated by 𝑥0 , 𝑥1 , 𝑥2 , ..., 𝑦0 , 𝑦1 , 𝑦2 , ..., ... and is equipped with a permutation action on the generators, namely
𝑥𝑃 𝑃
𝑛 = 𝑥𝑃 (𝑛) , 𝑦𝑛 = 𝑦𝑃 (𝑛) , ... for any permutation 𝑃 (note that variables of index zero are invariant under such
permutation).
It is known that any permutation invariant ideal in an Infinite Polynomial Ring is finitely generated modulo the
permutation action – see SymmetricIdeal for more details.
Usually, an instance of this class is created using InfinitePolynomialRing with the optional parame-
ter implementation='sparse'. This takes care of uniqueness of parent structures. However, a direct
construction is possible, in principle:
Nevertheless, since infinite polynomial rings are supposed to be unique parent structures, they do not evaluate
equal.
sage: Z == X False
The last parameter (‘lex’ in the above example) can also be ‘deglex’ or ‘degrevlex’; this would result in an
Infinite Polynomial Ring in degree lexicographic or degree reverse lexicographic order.
See infinite_polynomial_ring for more details.
characteristic()
Return the characteristic of the base field.
EXAMPLES:
construction()
Return the construction of self.
OUTPUT:
A pair F,R, where F is a construction functor and R is a ring, so that F(R) is self.
EXAMPLES:
gen(i=None)
Return the 𝑖𝑡ℎ ‘generator’ (see the description in ngens()) of this infinite polynomial ring.
EXAMPLES:
sage: X = InfinitePolynomialRing(QQ)
sage: x = X.gen()
sage: x[1]
x_1
sage: X.gen() is X.gen(0)
True
sage: XX = InfinitePolynomialRing(GF(5))
sage: XX.gen(0) is XX.gen()
True
gens_dict()
Return a dictionary-like object containing the infinitely many {var_name:variable} pairs.
EXAMPLES:
is_field(*args, **kwds)
Return False: Since Infinite Polynomial Rings must have at least one generator, they have infinitely
many variables and thus never are fields.
EXAMPLES:
is_integral_domain(*args, **kwds)
An infinite polynomial ring is an integral domain if and only if the base ring is. Arguments are passed to
is_integral_domain method of base ring.
EXAMPLES:
is_noetherian(*args, **kwds)
Return False, since polynomial rings in infinitely many variables are never Noetherian rings.
Note, however, that they are noetherian modules over the group ring of the symmetric group of the natural
numbers
EXAMPLES:
krull_dimension(*args, **kwds)
Return Infinity, since polynomial rings in infinitely many variables have infinite Krull dimension.
EXAMPLES:
ngens()
Return the number of generators for this ring.
Since there are countably infinitely many variables in this polynomial ring, by ‘generators’ we mean the
number of infinite families of variables. See infinite_polynomial_ring for more details.
EXAMPLES:
one()
order()
Return Infinity, since polynomial rings have infinitely many elements.
EXAMPLES:
tensor_with_ring(R)
Return the tensor product of self with another ring.
INPUT:
R - a ring.
OUTPUT:
An infinite polynomial ring that, mathematically, can be seen as the tensor product of self with R.
NOTE:
It is required that the underlying ring of self coerces into R. Hence, the tensor product is in fact merely an
extension of the base ring.
EXAMPLES:
The following tests against a bug that was fixed at trac ticket #10468:
varname_key(x)
Key for comparison of variable names.
INPUT:
x – a string of the form a+'_'+str(n), where a is the name of a generator, and n is an integer
RETURN:
a key used to sort the variables
THEORY:
The order is defined as follows:
x<y ⇐⇒ the string x.split('_')[0] is later in the list of generator names of
self than y.split('_')[0], or (x.split('_')[0]==y.split('_')[0] and int(x.
split('_')[1])<int(y.split('_')[1]))
EXAMPLES:
AUTHORS:
• Simon King <[email protected]>
• Mike Hansen <[email protected]>
An Infinite Polynomial Ring has generators 𝑥* , 𝑦* , ..., so that the variables are of the form
𝑥0 , 𝑥1 , 𝑥2 , ..., 𝑦0 , 𝑦1 , 𝑦2 , ..., ... (see infinite_polynomial_ring). Using the generators, we can create
elements as follows:
Any Infinite Polynomial Ring X is equipped with a monomial ordering. We only consider monomial orderings in
which:
X.gen(i)[m] > X.gen(j)[n] ⇐⇒ i<j, or i==j and m>n
Under this restriction, the monomial ordering can be lexicographic (default), degree lexicographic, or degree reverse
lexicographic. Here, the ordering is lexicographic, and elements can be compared as usual:
sage: X._order
'lex'
sage: a > b
True
Note that, when a method is called that is not directly implemented for ‘InfinitePolynomial’, it is tried to call this
method for the underlying classical polynomial. This holds, e.g., when applying the latex function:
sage: latex(c)
x_{3}^{3} + x_{3} y_{4} - 2 y_{4}^{4}
There is a permutation action on Infinite Polynomial Rings by permuting the indices of the variables:
sage: P = Permutation(((4,5),(2,3)))
sage: c^P
x_2^3 + x_2*y_5 - 2*y_5^4
Note that P(0)==0, and thus variables of index zero are invariant under the permutation action. More generally, if P
is any callable object that accepts non-negative integers as input and returns non-negative integers, then c^P means to
apply P to the variable indices occurring in c.
sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial(A, p)
Create an element of a Polynomial Ring with a Countably Infinite Number of Variables.
Usually, an InfinitePolynomial is obtained by using the generators of an Infinite Polynomial Ring (see
infinite_polynomial_ring) or by conversion.
INPUT:
• A – an Infinite Polynomial Ring.
• p – a classical polynomial that can be interpreted in A.
ASSUMPTIONS:
In the dense implementation, it must be ensured that the argument p coerces into A._P by a name preserving
conversion map.
In the sparse implementation, in the direct construction of an infinite polynomial, it is not tested whether the
argument p makes sense in A.
EXAMPLES:
Currently, P and X._P (the underlying polynomial ring of X) both have two variables:
sage: X._P
Multivariate Polynomial Ring in alpha_1, alpha_0 over Integer Ring
By default, a coercion from P to X._P would not be name preserving. However, this is taken care for; a name
preserving conversion is impossible, and by consequence an error is raised:
When extending the underlying polynomial ring, the construction of an infinite polynomial works:
sage: alpha[2]
alpha_2
sage: InfinitePolynomial(X, (alpha_1+alpha_2)^2)
alpha_2^2 + 2*alpha_2*alpha_1 + alpha_1^2
In the sparse implementation, it is not checked whether the polynomial really belongs to the parent:
sage: Y(a)
alpha_2^2 + alpha_1^2
class sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_dense(A,
p)
Bases: sage.rings.polynomial.infinite_polynomial_element.
InfinitePolynomial_sparse
Element of a dense Polynomial Ring with a Countably Infinite Number of Variables.
INPUT:
• A – an Infinite Polynomial Ring in dense implementation
• p – a classical polynomial that can be interpreted in A.
Of course, one should not directly invoke this class, but rather construct elements of A in the usual way.
This class inherits from InfinitePolynomial_sparse. See there for a description of the methods.
class sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse(A,
p)
Bases: sage.structure.element.RingElement
Element of a sparse Polynomial Ring with a Countably Infinite Number of Variables.
INPUT:
• A – an Infinite Polynomial Ring in sparse implementation
• p – a classical polynomial that can be interpreted in A.
Of course, one should not directly invoke this class, but rather construct elements of A in the usual way.
EXAMPLES:
sage: p.polynomial().parent()
Multivariate Polynomial Ring in b_100, b_0, c_4, c_0 over Univariate Polynomial
˓→Ring in a over Rational Field
coefficient(monomial)
Returns the coefficient of a monomial in this polynomial.
INPUT:
• A monomial (element of the parent of self) or
• a dictionary that describes a monomial (the keys are variables of the parent of self, the values are the
corresponding exponents)
EXAMPLES:
We can get the coefficient in front of monomials:
footprint()
Leading exponents sorted by index and generator.
OUTPUT:
D – a dictionary whose keys are the occurring variable indices.
D[s] is a list [i_1,...,i_n], where i_j gives the exponent of self.parent().gen(j)[s] in
the leading term of self.
EXAMPLES:
gcd(x)
computes the greatest common divisor
EXAMPLES:
sage: R.<x>=InfinitePolynomialRing(QQ)
sage: p1=x[0]+x[1]**2
sage: gcd(p1,p1+3)
1
sage: gcd(p1,p1)==p1
True
is_nilpotent()
Return True if self is nilpotent, i.e., some power of self is 0.
EXAMPLES:
is_unit()
Answer whether self is a unit.
EXAMPLES:
lc()
The coefficient of the leading term of self.
EXAMPLES:
lm()
The leading monomial of self.
EXAMPLES:
lt()
The leading term (= product of coefficient and monomial) of self.
EXAMPLES:
sage: X.<x,y> = InfinitePolynomialRing(QQ)
sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2
sage: p.lt()
3*x_10*x_1^2*y_1^3
max_index()
Return the maximal index of a variable occurring in self, or -1 if self is scalar.
EXAMPLES:
sage: X.<x,y> = InfinitePolynomialRing(QQ)
sage: p=x[1]^2+y[2]^2+x[1]*x[2]*y[3]+x[1]*y[4]
sage: p.max_index()
4
sage: x[0].max_index()
0
sage: X(10).max_index()
-1
polynomial()
Return the underlying polynomial.
EXAMPLES:
sage: X.<x,y> = InfinitePolynomialRing(GF(7))
sage: p=x[2]*y[1]+3*y[0]
sage: p
x_2*y_1 + 3*y_0
sage: p.polynomial()
x_2*y_1 + 3*y_0
sage: p.polynomial().parent()
Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 over Finite
˓→Field of size 7
sage: p.parent()
Infinite polynomial ring in x, y over Finite Field of size 7
The preceding is correct: If a permutation turns y[2]*x[1]^2 into a factor of the leading monomial
y[2]*x[3]^3 of p, then it interchanges the variable indices 1 and 2; this is not allowed in a symmetric
reduction. However, reduction by y[1]*x[2]^2 works, since one can change variable index 1 into 2
and 2 into 3:
sage: p.reduce([y[1]*x[2]^2])
y_3*y_1^2
The next example shows that tail reduction is not done, unless it is explicitly advised. The input can also
be a Symmetric Ideal:
sage: I = (y[3])*X
sage: p.reduce(I)
x_3^3*y_2 + y_3*y_1^2
sage: p.reduce(I, tailreduce=True)
x_3^3*y_2
sage: p=x[1]^2+y[2]^2+x[1]*x[2]*y[3]+x[1]*y[4]
sage: p.reduce(I, tailreduce=True, report=True)
:T[2]:>
>
x_1^2 + y_2^2
The output ‘:’ means that there was one reduction of the leading monomial. ‘T[2]’ means that a tail
reduction was performed on a polynomial with two terms. At ‘>’, one round of the reduction process is
finished (there could only be several non-trivial rounds if 𝐼 was generated by more than one polynomial).
ring()
The ring which self belongs to.
This is the same as self.parent().
EXAMPLES:
squeezed()
Reduce the variable indices occurring in self.
OUTPUT:
Apply a permutation to self that does not change the order of the variable indices of self but squeezes
them into the range 1,2,. . .
EXAMPLES:
stretch(k)
Stretch self by a given factor.
INPUT:
k – an integer.
OUTPUT:
Replace 𝑣𝑛 with 𝑣𝑛·𝑘 for all generators 𝑣* occurring in self.
EXAMPLES:
symmetric_cancellation_order(other)
Comparison of leading terms by Symmetric Cancellation Order, <𝑠𝑐 .
INPUT:
self, other – two Infinite Polynomials
ASSUMPTION:
Both Infinite Polynomials are non-zero.
OUTPUT:
(c, sigma, w), where
• c = -1,0,1, or None if the leading monomial of self is smaller, equal, greater, or incomparable with
respect to other in the monomial ordering of the Infinite Polynomial Ring
• sigma is a permutation witnessing self <𝑠𝑐 other (resp. self >𝑠𝑐 other) or is 1 if self.
lm()==other.lm()
• w is 1 or is a term so that w*self.lt()^sigma == other.lt() if 𝑐 ≤ 0, and w*other.
lt()^sigma == self.lt() if 𝑐 = 1
THEORY:
If the Symmetric Cancellation Order is a well-quasi-ordering then computation of Groebner bases always
terminates. This is the case, e.g., if the monomial order is lexicographic. For that reason, lexicographic
order is our default order.
EXAMPLES:
tail()
The tail of self (this is self minus its leading term).
EXAMPLES:
variables()
Return the variables occurring in self (tuple of elements of some polynomial ring).
EXAMPLES:
This module provides an implementation of ideals of polynomial rings in a countably infinite number of variables that
are invariant under variable permutation. Such ideals are called ‘Symmetric Ideals’ in the rest of this document. Our
implementation is based on the theory of M. Aschenbrenner and C. Hillar.
AUTHORS:
• Simon King <[email protected]>
EXAMPLES:
Here, we demonstrate that working in quotient rings of Infinite Polynomial Rings works, provided that one uses
symmetric Groebner bases.
sage: G = R*I.groebner_basis()
sage: G
(continues on next page)
sage: Q = R.quotient(G)
sage: p = x[3]*x[1]+x[2]^2+3
sage: Q(p)
-2*x_1 + 3
By the second generator of G, variable 𝑥𝑛 is equal to 𝑥1 for any positive integer 𝑛. By the first generator of G, 𝑥31 is
equal to 𝑥1 in Q. Indeed, we have
Note that even though the symmetric ideal can be generated by a single polynomial, its reduced symmetric
Groebner basis comprises four elements. Ideal membership in I can now be tested by commuting symmetric
reduction modulo J:
sage: I.reduce(J)
Symmetric Ideal (0) of Infinite polynomial ring in x, y over Rational Field
However, any element of J has symmetric reduction zero even after applying a permutation. This even holds
when the permutations involve higher variable indices than the ones occuring in J:
Since I is not a Groebner basis, it is no surprise that it can not detect ideal membership:
Note that we give no guarantee that the computation of a symmetric Groebner basis will terminate in any order
different from lexicographic.
When multiplying Symmetric Ideals or raising them to some integer power, the permutation action is taken into
account, so that the product is indeed the product of ideals in the mathematical sense.
sage: I=X*(x[1])
sage: I*I
Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x, y over
˓→Rational Field
sage: I^3
Symmetric Ideal (x_1^3, x_2*x_1^2, x_2^2*x_1, x_3*x_2*x_1) of Infinite polynomial
˓→ring in x, y over Rational Field
• algorithm – (string, default None) Determine the algorithm (see below for available algorithms).
• report – (object, default None) If not None, print information on the progress of computation.
• use_full_group – (bool, default False) If True then proceed as originally suggested by
[AB2008]. Our default method should be faster; see symmetrisation() for more details.
The computation of symmetric Groebner bases also involves the computation of classical Groebner bases,
i.e., of Groebner bases for ideals in polynomial rings with finitely many variables. For these computations,
Sage provides the following ALGORITHMS:
‘’ autoselect (default)
‘singular:groebner’ Singular’s groebner command
‘singular:std’ Singular’s std command
‘singular:stdhilb’ Singular’s stdhib command
‘singular:stdfglm’ Singular’s stdfglm command
‘singular:slimgb’ Singular’s slimgb command
‘libsingular:std’ libSingular’s std command
‘libsingular:slimgb’ libSingular’s slimgb command
‘toy:buchberger’ Sage’s toy/educational buchberger without strategy
‘toy:buchberger2’ Sage’s toy/educational buchberger with strategy
‘toy:d_basis’ Sage’s toy/educational d_basis algorithm
‘macaulay2:gb’ Macaulay2’s gb command (if available)
‘magma:GroebnerBasis’ Magma’s Groebnerbasis command (if available)
If only a system is given - e.g. ‘magma’ - the default algorithm is chosen for that system.
Note: The Singular and libSingular versions of the respective algorithms are identical, but the former
calls an external Singular process while the later calls a C function, i.e. the calling overhead is smaller.
EXAMPLES:
Note that a symmetric Groebner basis of a principal ideal is not necessarily formed by a single polynomial.
When using the algorithm originally suggested by Aschenbrenner and Hillar, the result is the same, but the
computation takes much longer:
sage: I2.groebner_basis(use_full_group=True)
[x_1*y_2 + y_2^2*y_1, x_2*y_1 + y_2*y_1^2]
Last, we demonstrate how the report on the progress of computations looks like:
The Aschenbrenner-Hillar algorithm is only guaranteed to work if the base ring is a field. So, we raise a
TypeError if this is not the case:
interreduced_basis()
A fully symmetrically reduced generating set (type Sequence) of self.
This does essentially the same as interreduction() with the option ‘tailreduce’, but it returns a
Sequence rather than a SymmetricIdeal.
EXAMPLES:
sage: I.interreduction(report=True)
Symmetric interreduction
[1/2] >
[2/2] :>
[1/2] >
[2/2] T[1]>
>
Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over
˓→Rational Field
[m/n] indicates that polynomial number m is considered and the total number of polyno-
mials under consideration is n. ‘-> 0’ is printed if a zero reduction occurred. The
rest of the report is as described in sage.rings.polynomial.symmetric_reduction.
SymmetricReductionStrategy.reduce().
Last, we demonstrate the use of the optional parameter RStrat:
sage: R = SymmetricReductionStrategy(X)
sage: R
Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational
˓→Field
sage: I.interreduction(RStrat=R)
Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over
˓→Rational Field
sage: R
Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational
˓→Field, modulo
x_1^2,
x_2 + x_1
sage: R = SymmetricReductionStrategy(X,[x[1]^2])
sage: I.interreduction(RStrat=R)
Symmetric Ideal (x_2 + x_1) of Infinite polynomial ring in x over Rational
˓→Field
is_maximal()
Answers whether self is a maximal ideal.
ASSUMPTION:
self is defined by a symmetric Groebner basis.
NOTE:
It is not checked whether self is in fact a symmetric Groebner basis. A wrong answer can result if this
assumption does not hold. A NotImplementedError is raised if the base ring is not a field, since
symmetric Groebner bases are not implemented in this setting.
EXAMPLES:
The preceding answer is wrong, since it is not the case that I is given by a symmetric Groebner basis:
sage: I = R*I.groebner_basis()
sage: I
Symmetric Ideal (y_1, x_1) of Infinite polynomial ring in x, y over Rational
˓→Field
sage: I.is_maximal()
True
normalisation()
Return an ideal that coincides with self, so that all generators have leading coefficient 1.
Possibly occurring zeroes are removed from the generator list.
EXAMPLES:
reduce(I, tailreduce=False)
Symmetric reduction of self by another Symmetric Ideal or list of Infinite Polynomials, or symmetric
reduction of a given Infinite Polynomial by self.
INPUT:
• I – an Infinite Polynomial, or a Symmetric Ideal or a list of Infinite Polynomials.
• tailreduce – (bool, default False) If True, the non-leading terms will be reduced as well.
OUTPUT:
Symmetric reduction of self with respect to I.
THEORY:
Reduction of an element 𝑝 of an Infinite Polynomial Ring 𝑋 by some other element 𝑞 means the following:
1. Let 𝑀 and 𝑁 be the leading terms of 𝑝 and 𝑞.
2. Test whether there is a permutation 𝑃 that does not does not diminish the variable indices occurring
in 𝑁 and preserves their order, so that there is some term 𝑇 ∈ 𝑋 with 𝑇 𝑁 𝑃 = 𝑀 . If there is no such
permutation, return 𝑝
3. Replace 𝑝 by 𝑝 − 𝑇 𝑞 𝑃 and continue with step 1.
EXAMPLES:
The preceding is correct, since any permutation that turns x[1]^2*y[2] into a factor of x[3]^2*y[2]
interchanges the variable indices 1 and 2 – which is not allowed. However, reduction by x[2]^2*y[1]
works, since one can change variable index 1 into 2 and 2 into 3:
sage: I.reduce([x[2]^2*y[1]])
Symmetric Ideal (y_3*y_1^2) of Infinite polynomial ring in x, y over Rational
˓→Field
The next example shows that tail reduction is not done, unless it is explicitly advised. The input can also
be a symmetric ideal:
sage: J = (y[2])*X
sage: I.reduce(J)
Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of Infinite polynomial ring in x, y
˓→over Rational Field
squeezed()
Reduce the variable indices occurring in self.
OUTPUT:
A Symmetric Ideal whose generators are the result of applying squeezed() to the generators of self.
NOTE:
The output describes the same Symmetric Ideal as self.
EXAMPLES:
symmetric_basis()
A symmetrised generating set (type Sequence) of self.
This does essentially the same as symmetrisation() with the option ‘tailreduce’, and it returns a
Sequence rather than a SymmetricIdeal.
EXAMPLES:
INPUT:
• N – (integer, default None) Apply permutations in 𝑆𝑦𝑚(𝑁 ). If it is not given then it will be re-
placed by the maximal variable index occurring in the generators of self.interreduction().
squeezed().
• tailreduce – (bool, default False) If True, perform tail reductions.
• report – (object, default None) If not None, report on the progress of computations.
• use_full_group (optional) – If True, apply all elements of 𝑆𝑦𝑚(𝑁 ) to the generators of self
(this is what [AB2008] originally suggests). The default is to apply all elementary transpositions to
the generators of self.squeezed(), interreduce, and repeat until the result stabilises, which is
often much faster than applying all of 𝑆𝑦𝑚(𝑁 ), and we are convinced that both methods yield the
same result.
OUTPUT:
A symmetrically interreduced symmetric ideal with respect to which any 𝑆𝑦𝑚(𝑁 )-translate of a generator
of self is symmetrically reducible, where by default N is the maximal variable index that occurs in the
generators of self.interreduction().squeezed().
NOTE:
If I is a symmetric ideal whose generators are monomials, then I.symmetrisation() is its reduced
Groebner basis. It should be noted that without symmetrisation, monomial generators, in general, do not
form a Groebner basis.
EXAMPLES:
sage: I.symmetrisation(N=3)
Symmetric Ideal (-2*x_1) of Infinite polynomial ring in x over Rational Field
sage: I.symmetrisation(N=3, use_full_group=True)
Symmetric Ideal (-2*x_1) of Infinite polynomial ring in x over Rational Field
When reducing one polynomial 𝑝 with respect to a list 𝐿 of other polynomials, there usually is a choice of order on
which the efficiency crucially depends. Also it helps to modify the polynomials on the list in order to simplify the
basic reduction steps.
The preparation of 𝐿 may be expensive. Hence, if the same list is used many times then it is reasonable to perform the
preparation only once. This is the background of SymmetricReductionStrategy.
Our current strategy is to keep the number of terms in the polynomials as small as possible. For this, we sort 𝐿 by
increasing number of terms. If several elements of 𝐿 allow for a reduction of 𝑝, we choose the one with the smallest
number of terms. Later on, it should be possible to implement further strategies for choice.
When adding a new polynomial 𝑞 to 𝐿, we first reduce 𝑞 with respect to 𝐿. Then, we test heuristically whether it is
possible to reduce the number of terms of the elements of 𝐿 by reduction modulo 𝑞. That way, we see best chances to
keep the number of terms in intermediate reduction steps relatively small.
EXAMPLES:
First, we create an infinite polynomial ring and one of its elements:
sage: X.<x,y> = InfinitePolynomialRing(QQ)
sage: p = y[1]*y[3]+y[1]^2*x[3]
We want to symmetrically reduce it by another polynomial. So, we put this other polynomial into a list and create a
Symmetric Reduction Strategy object:
sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy
sage: S = SymmetricReductionStrategy(X, [y[2]^2*x[1]])
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field,
˓→modulo
x_1*y_2^2
sage: S.reduce(p)
x_3*y_1^2 + y_3*y_1
The preceding is correct, since any permutation that turns y[2]^2*x[1] into a factor of y[1]^2*x[3] inter-
changes the variable indices 1 and 2 – which is not allowed in a symmetric reduction. However, reduction by
y[1]^2*x[2] works, since one can change variable index 1 into 2 and 2 into 3. So, we add this to S:
sage: S.add_generator(y[1]^2*x[2])
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field,
˓→modulo
x_2*y_1^2,
x_1*y_2^2
sage: S.reduce(p)
y_3*y_1
The next example shows that tail reduction is not done, unless it is explicitly advised:
sage: S.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1])
x_3 + 2*x_2*y_1^2 + 3*x_1*y_2^2
sage: S.tailreduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1])
x_3
However, it is possible to ask for tailreduction already when the Symmetric Reduction Strategy is created:
sage: S2 = SymmetricReductionStrategy(X, [y[2]^2*x[1],y[1]^2*x[2]], tailreduce=True)
sage: S2
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field,
˓→modulo (continues on next page)
class sage.rings.polynomial.symmetric_reduction.SymmetricReductionStrategy
Bases: object
A framework for efficient symmetric reduction of InfinitePolynomial, see
infinite_polynomial_element.
INPUT:
• Parent – an Infinite Polynomial Ring, see infinite_polynomial_element.
• L – (list, default the empty list) List of elements of Parent with respect to which will be reduced.
• good_input – (bool, default None) If this optional parameter is true, it is assumed that each element of
L is symmetrically reduced with respect to the previous elements of L.
EXAMPLES:
add_generator(p, good_input=None)
Add another polynomial to self.
INPUT:
• p – An element of the underlying infinite polynomial ring.
• good_input – (bool, default None) If True, it is assumed that p is reduced with respect to self.
Otherwise, this reduction will be done first (which may cost some time).
Note: Previously added polynomials may be modified. All input is prepared in view of an efficient
symmetric reduction.
EXAMPLES:
Note that the first added polynomial will be simplified when adding a suitable second polynomial:
sage: S.add_generator(x[2]+x[1])
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over
˓→Rational Field, modulo
y_3,
x_2 + x_1
By default, reduction is applied to any newly added polynomial. This can be avoided by specifying the
optional parameter ‘good_input’:
sage: S.add_generator(y[2]+y[1]*x[2])
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over
˓→Rational Field, modulo
y_3,
x_1*y_1 - y_2,
x_2 + x_1
sage: S.reduce(x[3]+x[2])
-2*x_1
sage: S.add_generator(x[3]+x[2], good_input=True)
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over
˓→Rational Field, modulo
y_3,
x_3 + x_2,
x_1*y_1 - y_2,
x_2 + x_1
In the previous example, x[3] + x[2] is added without being reduced to zero.
gens()
Return the list of Infinite Polynomials modulo which self reduces.
EXAMPLES:
y_2*y_1^2,
y_2^2*y_1
sage: S.gens()
[y_2*y_1^2, y_2^2*y_1]
EXAMPLES:
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over
˓→Rational Field, modulo
y_3 + y_2,
x_2 + y_1,
x_1*y_2 + y_4 - y_3*y_1
sage: S.reduce(x[3] + x[1]*y[3] + x[1]*y[1],report=True)
:::>
x_1*y_1 + y_4 - y_3*y_1 - y_1
Each ‘:’ indicates that one reduction of the leading monomial was performed. Eventually, the ‘>’ indicates
that the computation is finished.
reset()
Remove all polynomials from self.
EXAMPLES:
y_2*y_1^2,
y_2^2*y_1
sage: S.reset()
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational
˓→Field
setgens(L)
Define the list of Infinite Polynomials modulo which self reduces.
INPUT:
L – a list of elements of the underlying infinite polynomial ring.
Note: It is not tested if L is a good input. That method simply assigns a copy of L to the generators of
self.
EXAMPLES:
y_2*y_1^2,
y_2^2*y_1
sage: R.gens() is S.gens()
False
sage: R.gens() == S.gens()
True
tailreduce(p, report=None)
Symmetric reduction of an infinite polynomial, with forced tail reduction.
INPUT:
• p – an element of the underlying infinite polynomial ring.
• report – (object, default None) If not None, print information on the progress of the computation.
OUTPUT:
Reduction (including the non-leading elements) of p with respect to self.
EXAMPLES:
sage: S
Symmetric Reduction Strategy in Infinite polynomial ring in x, y over
˓→Rational Field, modulo
EIGHT
BOOLEAN POLYNOMIALS
are called boolean polynomials. Boolean polynomials arise naturally in cryptography, coding theory, formal logic, chip
design and other areas. This implementation is a thin wrapper around the PolyBoRi library by Michael Brickenstein
and Alexander Dreyer.
“Boolean polynomials can be modelled in a rather simple way, with both coefficients and degree per variable lying
in {0, 1}. The ring of Boolean polynomials is, however, not a polynomial ring, but rather the quotient ring of the
polynomial ring over the field with two elements modulo the field equations 𝑥2 = 𝑥 for each variable 𝑥. Therefore,
the usual polynomial data structures seem not to be appropriate for fast Groebner basis computations. We introduce a
specialised data structure for Boolean polynomials based on zero-suppressed binary decision diagrams (ZDDs), which
is capable of handling these polynomials more efficiently with respect to memory consumption and also computational
speed. Furthermore, we concentrate on high-level algorithmic aspects, taking into account the new data structures as
well as structural properties of Boolean polynomials.” - [BD07]
For details on the internal representation of polynomials see
http://polybori.sourceforge.net/zdd.html
AUTHORS:
• Michael Brickenstein: PolyBoRi author
• Alexander Dreyer: PolyBoRi author
• Burcin Erocal <[email protected]>: main Sage wrapper author
• Martin Albrecht <[email protected]>: some contributions to the Sage wrapper
• Simon King <[email protected]>: Adopt the new coercion model. Fix conversion from univari-
ate polynomial rings. Pickling of BooleanMonomialMonoid (via UniqueRepresentation) and
BooleanMonomial.
• Charles Bouillaguet <[email protected]>: minor changes to improve compatibility with MPoly-
nomial and make the variety() function work on ideals of BooleanPolynomial’s.
EXAMPLES:
Consider the ideal
581
Sage Reference Manual: Polynomials, Release 8.6
𝑅 = F2 [𝑎, 𝑏, 𝑐, 𝑑, 𝑒].
If one wants to solve this system over the algebraic closure of F2 then this Groebner basis was the one to consider. If
one wants solutions over F2 only then one adds the field polynomials to the ideal to force the solutions in F2 .
sage: J = I1 + sage.rings.ideal.FieldIdeal(P)
sage: for f in J.groebner_basis():
....: f
a + d + 1
b + 1
c + 1
d^2 + d
e
Note that d^2 + d is not representable in B == Q. Also note, that PolyBoRi cannot play out its strength in such
small examples, i.e. working in the polynomial ring might be faster for small examples like this.
PolyBoRi comes with a Python wrapper. However this wrapper does not match Sage’s style and is written using Boost.
Thus Sage’s wrapper is a reimplementation of Python bindings to PolyBoRi’s C++ library. This interface is written in
Cython like all of Sage’s C/C++ library interfaces. An interface in PolyBoRi style is also provided which is effectively
a reimplementation of the official Boost wrapper in Cython. This means that some functionality of the official wrapper
might be missing from this wrapper and this wrapper might have bugs not present in the official Python interface.
deg()
Get degree of boolean constant.
EXAMPLES:
has_constant_part()
This is true for 𝐵𝑜𝑜𝑙𝑒𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡(1).
EXAMPLES:
is_constant()
This is always true for in this case.
EXAMPLES:
is_one()
Check whether boolean constant is one.
EXAMPLES:
is_zero()
Check whether boolean constant is zero.
EXAMPLES:
variables()
Get variables (return always and empty tuple).
EXAMPLES:
class sage.rings.polynomial.pbori.BooleSet
Bases: object
Return a new set of boolean monomials. This data type is also implemented on the top of ZDDs and allows
to see polynomials from a different angle. Also, it makes high-level set operations possible, which are in most
cases faster than operations handling individual terms, because the complexity of the algorithms depends only
on the structure of the diagrams.
Objects of type BooleanPolynomial can easily be converted to the type BooleSet by using the member
function BooleanPolynomial.set().
INPUT:
• param - either a CCuddNavigator, a BooleSet or None.
• ring - a boolean polynomial ring.
EXAMPLES:
sage: from brial import BooleSet
sage: B.<a,b,c,d> = BooleanPolynomialRing(4)
sage: BS = BooleSet(a.set())
sage: BS
{{a}}
cartesian_product(rhs)
Return the Cartesian product of this set and the set rhs.
The Cartesian product of two sets X and Y is the set of all possible ordered pairs whose first component is
a member of X and whose second component is a member of Y.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set(); s
{{x1,x2}, {x2,x3}}
sage: g = x4 + 1
sage: t = g.set(); t
{{x4}, {}}
sage: s.cartesian_product(t)
{{x1,x2,x4}, {x1,x2}, {x2,x3,x4}, {x2,x3}}
change(ind)
Swaps the presence of x_i in each entry of the set.
EXAMPLES:
sage: P.<a,b,c> = BooleanPolynomialRing()
sage: f = a+b
sage: s = f.set(); s
{{a}, {b}}
sage: s.change(0)
(continues on next page)
diff(rhs)
Return the set theoretic difference of this set and the set rhs.
The difference of two sets 𝑋 and 𝑌 is defined as:
𝑋 𝑌 = {𝑥|𝑥 ∈ 𝑋 and 𝑥 ̸∈ 𝑌 }.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set(); s
{{x1,x2}, {x2,x3}}
sage: g = x2*x3 + 1
sage: t = g.set(); t
{{x2,x3}, {}}
sage: s.diff(t)
{{x1,x2}}
divide(rhs)
Divide each element of this set by the monomial rhs and return a new set containing the result.
EXAMPLES:
divisors_of(m)
Return those members which are divisors of m.
INPUT:
• m - a boolean monomial
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set()
sage: s.divisors_of((x1*x2*x4).lead())
{{x1,x2}}
empty()
Return True if this set is empty.
EXAMPLES:
sage: BS = B(0).set()
sage: BS.empty()
True
include_divisors()
Extend this set to include all divisors of the elements already in this set and return the result as a new set.
EXAMPLES:
sage: s.include_divisors()
{{a,d,e}, {a,d}, {a,e}, {a,f}, {a}, {b,d,e}, {b,d}, {b,e},
{b}, {c,d,e}, {c,d}, {c,e}, {c}, {d,e}, {d}, {e}, {f}, {}}
intersect(other)
Return the set theoretic intersection of this set and the set rhs.
The union of two sets 𝑋 and 𝑌 is defined as:
𝑋 ∩ 𝑌 = {𝑥|𝑥 ∈ 𝑋 and 𝑥 ∈ 𝑌 }.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set(); s
{{x1,x2}, {x2,x3}}
sage: g = x2*x3 + 1
sage: t = g.set(); t
{{x2,x3}, {}}
sage: s.intersect(t)
{{x2,x3}}
minimal_elements()
Return a new set containing a divisor of all elements of this set.
EXAMPLES:
multiples_of(m)
Return those members which are multiples of m.
INPUT:
• m - a boolean monomial
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set()
sage: s.multiples_of(x1.lm())
{{x1,x2}}
n_nodes()
Return the number of nodes in the ZDD.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set(); s
{{x1,x2}, {x2,x3}}
sage: s.n_nodes()
4
navigation()
Navigators provide an interface to diagram nodes, accessing their index as well as the corresponding then-
and else-branches.
You should be very careful and always keep a reference to the original object, when dealing with naviga-
tors, as navigators contain only a raw pointer as data. For the same reason, it is necessary to supply the
ring as argument, when constructing a set out of a navigator.
EXAMPLES:
sage: nav.value()
1
sage: BooleSet(nav_else,s.ring())
{{x2,x3,x4}, {x2,x4}, {x3}, {x4}, {}}
sage: nav_else.value()
2
ring()
Return the parent ring.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3*x4+x2*x4+x3+x4+1
sage: f.set().ring() is B
True
set()
Return self.
EXAMPLES:
size_double()
Return the size of this set as a floating point number.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set()
sage: s.size_double()
2.0
stable_hash()
A hash value which is stable across processes.
EXAMPLES:
Note: This function is part of the upstream PolyBoRi interface. In Sage all hashes are stable.
subset0(i)
Return a set of those elements in this set which do not contain the variable indexed by i.
INPUT:
• i - an index
EXAMPLES:
sage: BooleanPolynomialRing(5,'x')
Boolean PolynomialRing in x0, x1, x2, x3, x4
sage: B = BooleanPolynomialRing(5,'x')
(continues on next page)
subset1(i)
Return a set of those elements in this set which do contain the variable indexed by i and evaluate the
variable indexed by i to 1.
INPUT:
• i - an index
EXAMPLES:
sage: BooleanPolynomialRing(5,'x')
Boolean PolynomialRing in x0, x1, x2, x3, x4
sage: B = BooleanPolynomialRing(5,'x')
sage: B.inject_variables()
Defining x0, x1, x2, x3, x4
sage: f = x1*x2+x2*x3
sage: s = f.set(); s
{{x1,x2}, {x2,x3}}
sage: s.subset1(1)
{{x2}}
union(rhs)
Return the set theoretic union of this set and the set rhs.
The union of two sets 𝑋 and 𝑌 is defined as:
𝑋 ∪ 𝑌 = {𝑥|𝑥 ∈ 𝑋 or 𝑥 ∈ 𝑌 }.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2+x2*x3
sage: s = f.set(); s
{{x1,x2}, {x2,x3}}
sage: g = x2*x3 + 1
sage: t = g.set(); t
{{x2,x3}, {}}
sage: s.union(t)
{{x1,x2}, {x2,x3}, {}}
vars()
Return the variables in this set as a monomial.
EXAMPLES:
sage: B.<a,b,c,d,e,f> = BooleanPolynomialRing(order='lex')
sage: f = a + b*e + d*f + e + 1
sage: s = f.set()
sage: s
(continues on next page)
class sage.rings.polynomial.pbori.BooleSetIterator
Bases: object
Helper class to iterate over boolean sets.
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.polynomial.pbori.BooleanMonomial
Bases: sage.structure.element.MonoidElement
Construct a boolean monomial.
INPUT:
• parent - parent monoid this element lives in
EXAMPLES:
Note: Use the BooleanMonomialMonoid__call__() method and not this constructor to construct these
objects.
deg()
Return degree of this monomial.
EXAMPLES:
sage: M(x*x*y*z).deg()
3
degree(x=None)
Return the degree of this monomial in x, where x must be one of the generators of the polynomial ring.
INPUT:
• x - boolean multivariate polynomial (a generator of the polynomial ring). If x is not specified (or is
None), return the total degree of this monomial.
EXAMPLES:
divisors()
Return a set of boolean monomials with all divisors of this monomial.
EXAMPLES:
gcd(rhs)
Return the greatest common divisor of this boolean monomial and rhs.
INPUT:
• rhs - a boolean monomial
EXAMPLES:
index()
Return the variable index of the first variable in this monomial.
EXAMPLES:
iterindex()
Return an iterator over the indices of the variables in self.
EXAMPLES:
multiples(rhs)
Return a set of boolean monomials with all multiples of this monomial up to the bound rhs.
INPUT:
• rhs - a boolean monomial
EXAMPLES:
Note: The returned set always contains self even if the bound rhs is smaller than self.
navigation()
Navigators provide an interface to diagram nodes, accessing their index as well as the corresponding then-
and else-branches.
You should be very careful and always keep a reference to the original object, when dealing with naviga-
tors, as navigators contain only a raw pointer as data. For the same reason, it is necessary to supply the
ring as argument, when constructing a set out of a navigator.
EXAMPLES:
sage: nav.value()
1
reducible_by(rhs)
Return True if self is reducible by rhs.
INPUT:
• rhs - a boolean monomial
EXAMPLES:
ring()
Return the corresponding boolean ring.
EXAMPLES:
set()
Return a boolean set of variables in this monomials.
EXAMPLES:
stable_hash()
A hash value which is stable across processes.
EXAMPLES:
Note: This function is part of the upstream PolyBoRi interface. In Sage all hashes are stable.
variables()
Return a tuple of the variables in this monomial.
EXAMPLES:
class sage.rings.polynomial.pbori.BooleanMonomialIterator
Bases: object
An iterator over the variable indices of a monomial.
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.polynomial.pbori.BooleanMonomialMonoid(polring)
Bases: sage.structure.unique_representation.UniqueRepresentation, sage.
monoids.monoid.Monoid_class
Construct a boolean monomial monoid given a boolean polynomial ring.
This object provides a parent for boolean monomials.
INPUT:
• polring - the polynomial ring our monomials lie in
EXAMPLES:
sage: M.gens()
(x, y)
sage: type(M.gen(0))
<type 'sage.rings.polynomial.pbori.BooleanMonomial'>
Since trac ticket #9138, boolean monomial monoids are unique parents and are fit into the category framework:
sage: loads(dumps(M)) is M
True
sage: TestSuite(M).run()
gen(i=0)
Return the i-th generator of self.
INPUT:
• i - an integer
EXAMPLES:
gens()
Return the tuple of generators of this monoid.
EXAMPLES:
ngens()
Return the number of variables in this monoid.
EXAMPLES:
class sage.rings.polynomial.pbori.BooleanMonomialVariableIterator
Bases: object
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.polynomial.pbori.BooleanMulAction
Bases: sage.categories.action.Action
class sage.rings.polynomial.pbori.BooleanPolynomial
Bases: sage.rings.polynomial.multi_polynomial.MPolynomial
Construct a boolean polynomial object in the given boolean polynomial ring.
INPUT:
• parent - a boolean polynomial ring
Note: Do not use this method to construct boolean polynomials, but use the appropriate __call__ method in
the parent.
constant()
Return True if this element is constant.
EXAMPLES:
sage: B(1).constant()
True
constant_coefficient()
Return the constant coefficient of this boolean polynomial.
EXAMPLES:
deg()
Return the degree of self. This is usually equivalent to the total degree except for weighted term order-
ings which are not implemented yet.
EXAMPLES:
sage: P(1).degree()
0
degree(x=None)
Return the maximal degree of this polynomial in x, where x must be one of the generators for the parent
of this polynomial.
If x is not specified (or is None), return the total degree, which is the maximum degree of any monomial.
EXAMPLES:
sage: P(1).degree()
0
elength()
Return elimination length as used in the SlimGB algorithm.
EXAMPLES:
REFERENCES:
• Michael Brickenstein; SlimGB: Groebner Bases with Slim Polynomials http://www.mathematik.
uni-kl.de/~zca/Reports_on_ca/35/paper_35_full.ps.gz
first_term()
Return the first term with respect to the lexicographical term ordering.
EXAMPLES:
graded_part(deg)
Return graded part of this boolean polynomial of degree deg.
INPUT:
• deg - a degree
EXAMPLES:
sage: f.graded_part(0)
1
has_constant_part()
Return True if this boolean polynomial has a constant part, i.e. if 1 is a term.
EXAMPLES:
is_constant()
Check if self is constant.
EXAMPLES:
sage: P(0).is_constant()
True
sage: x.is_constant()
False
sage: (x*y).is_constant()
False
is_equal(right)
EXAMPLES:
sage: f.is_equal((f + 1) - 1)
True
is_homogeneous()
Return True if this element is a homogeneous polynomial.
EXAMPLES:
is_one()
Check if self is 1.
EXAMPLES:
sage: P.one().is_one()
True
sage: x.is_one()
False
sage: P(0).is_one()
False
is_pair()
Check if self has exactly two terms.
EXAMPLES:
sage: x.is_singleton_or_pair()
True
sage: P(1).is_singleton_or_pair()
True
sage: (x*y).is_singleton_or_pair()
True
sage: (x + y).is_singleton_or_pair()
True
sage: (x + 1).is_singleton_or_pair()
True
sage: (x + y + 1).is_singleton_or_pair()
False
is_singleton()
Check if self has at most one term.
EXAMPLES:
sage: x.is_singleton()
True
sage: P(1).is_singleton()
True
sage: (x*y).is_singleton()
True
sage: (x + y).is_singleton()
False
sage: (x + 1).is_singleton()
False
sage: (x + y + 1).is_singleton()
False
is_singleton_or_pair()
Check if self has at most two terms.
EXAMPLES:
sage: x.is_singleton_or_pair()
True
sage: P(1).is_singleton_or_pair()
True
sage: (x*y).is_singleton_or_pair()
True
sage: (x + y).is_singleton_or_pair()
True
sage: (x + 1).is_singleton_or_pair()
True
sage: (x + y + 1).is_singleton_or_pair()
False
is_unit()
Check if self is invertible in the parent ring.
sage: x.is_unit()
False
is_univariate()
Return True if self is a univariate polynomial, that is if self contains only one variable.
EXAMPLES:
is_zero()
Check if self is zero.
EXAMPLES:
sage: x.is_zero()
False
sage: P(1).is_zero()
False
lead()
Return the leading monomial of boolean polynomial, with respect to to the order of parent ring.
EXAMPLES:
lead_deg()
Return the total degree of the leading monomial of self.
EXAMPLES:
sage: P.<x,y,z> = BooleanPolynomialRing(3)
sage: p = x + y*z
sage: p.lead_deg()
1
sage: P(0).lead_deg()
0
lead_divisors()
Return a BooleSet of all divisors of the leading monomial.
EXAMPLES:
sage: B.<a,b,z> = BooleanPolynomialRing(3)
sage: f = a*b + z + 1
sage: f.lead_divisors()
{{a,b}, {a}, {b}, {}}
lex_lead()
Return the leading monomial of boolean polynomial, with respect to the lexicographical term ordering.
EXAMPLES:
sage: P.<x,y,z> = BooleanPolynomialRing(3)
sage: (x+y+y*z).lex_lead()
x
sage: P(0).lex_lead()
0
lex_lead_deg()
Return degree of leading monomial with respect to the lexicographical ordering.
EXAMPLES:
lm()
Return the leading monomial of this boolean polynomial, with respect to the order of parent ring.
EXAMPLES:
sage: P.<x,y,z> = BooleanPolynomialRing(3)
sage: (x+y+y*z).lm()
x
sage: P(0).lm()
0
lt()
Return the leading term of this boolean polynomial, with respect to the order of the parent ring.
Note that for boolean polynomials this is equivalent to returning leading monomials.
EXAMPLES:
sage: P.<x,y,z> = BooleanPolynomialRing(3)
sage: (x+y+y*z).lt()
x
map_every_x_to_x_plus_one()
Map every variable x_i in this polynomial to x_i + 1.
EXAMPLES:
sage: B.<a,b,z> = BooleanPolynomialRing(3)
sage: f = a*b + z + 1; f
a*b + z + 1
sage: f.map_every_x_to_x_plus_one()
(continues on next page)
monomial_coefficient(mon)
Return the coefficient of the monomial mon in self, where mon must have the same parent as self.
INPUT:
• mon - a monomial
EXAMPLES:
sage: f.monomial_coefficient(1)
1
sage: f.monomial_coefficient(0)
0
monomials()
Return a list of monomials appearing in self ordered largest to smallest.
EXAMPLES:
n_nodes()
Return the number of nodes in the ZDD implementing this polynomial.
EXAMPLES:
sage: B = BooleanPolynomialRing(5,'x')
sage: x0,x1,x2,x3,x4 = B.gens()
sage: f = x1*x2 + x2*x3 + 1
sage: f.n_nodes()
4
n_vars()
Return the number of variables used to form this boolean polynomial.
EXAMPLES:
navigation()
Navigators provide an interface to diagram nodes, accessing their index as well as the corresponding then-
and else-branches.
You should be very careful and always keep a reference to the original object, when dealing with naviga-
tors, as navigators contain only a raw pointer as data. For the same reason, it is necessary to supply the
ring as argument, when constructing a set out of a navigator.
EXAMPLES:
sage: nav.value()
1
sage: BooleSet(nav_else, B)
{{x2,x3,x4}, {x2,x4}, {x3}, {x4}, {}}
sage: nav_else.value()
2
nvariables()
Return the number of variables used to form this boolean polynomial.
EXAMPLES:
reduce(I)
Return the normal form of self w.r.t. I, i.e. return the remainder of self with respect to the polynomials
in I. If the polynomial set/list I is not a Groebner basis the result is not canonical.
INPUT:
• I - a list/set of polynomials in self.parent(). If I is an ideal, the generators are used.
EXAMPLES:
Note: If this function is called repeatedly with the same I then it is advised to use PolyBoRi’s
GroebnerStrategy object directly, since that will be faster. See the source code of this function
for details.
reducible_by(rhs)
Return True if this boolean polynomial is reducible by the polynomial rhs.
INPUT:
• rhs - a boolean polynomial
EXAMPLES:
ring()
Return the parent of this boolean polynomial.
EXAMPLES:
set()
Return a BooleSet with all monomials appearing in this polynomial.
EXAMPLES:
spoly(rhs)
Return the S-Polynomial of this boolean polynomial and the other boolean polynomial rhs.
EXAMPLES:
stable_hash()
A hash value which is stable across processes.
EXAMPLES:
Note: This function is part of the upstream PolyBoRi interface. In Sage all hashes are stable.
subs(in_dict=None, **kwds)
Fixes some given variables in a given boolean polynomial and returns the changed boolean polynomials.
The polynomial itself is not affected. The variable,value pairs for fixing are to be provided as dictionary
of the form {variable:value} or named parameters (see examples below).
INPUT:
• in_dict - (optional) dict with variable:value pairs
• **kwds - names parameters
EXAMPLES:
sage: f.subs(x=y)
y*z + y + z + 1
sage: f.subs({x:1},y=1)
0
sage: f.subs(y=1)
x + 1
sage: f.subs(y=1,z=1)
x + 1
sage: f.subs(z=1)
x*y + y
sage: f.subs({'x':1},y=1)
0
terms()
Return a list of monomials appearing in self ordered largest to smallest.
EXAMPLES:
sage: P.<a,b,c> = BooleanPolynomialRing(3,order='lex')
sage: f = a + c*b
sage: f.terms()
[a, b*c]
total_degree()
Return the total degree of self.
EXAMPLES:
sage: P.<x,y> = BooleanPolynomialRing(2)
sage: (x+y).total_degree()
1
sage: P(1).total_degree()
0
univariate_polynomial(R=None)
Return a univariate polynomial associated to this multivariate polynomial.
If this polynomial is not in at most one variable, then a ValueError exception is raised. This is checked
using the is_univariate() method. The new Polynomial is over GF(2) and in the variable x if no
ring R is provided.
sage: R.<x, y> = BooleanPolynomialRing() sage: f = x - y + x*y + 1 sage:
f.univariate_polynomial() Traceback (most recent call last): . . . ValueError: polynomial must
involve at most one variable sage: g = f.subs({x:0}); g y + 1 sage: g.univariate_polynomial () y
+ 1 sage: g.univariate_polynomial(GF(2)[‘foo’]) foo + 1
Here’s an example with a constant multivariate polynomial:
sage: g = R(1)
sage: h = g.univariate_polynomial(); h
1
sage: h.parent()
Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X)
variable(i=0)
Return the i-th variable occurring in self. The index i is the index in self.variables()
EXAMPLES:
variables()
Return a tuple of all variables appearing in self.
EXAMPLES:
sage: P.zero().variables()
()
sage: P.one().variables()
()
vars_as_monomial()
Return a boolean monomial with all the variables appearing in self.
EXAMPLES:
sage: P.zero().vars_as_monomial()
1
sage: P.one().vars_as_monomial()
1
zeros_in(s)
Return a set containing all elements of s where this boolean polynomial evaluates to zero.
If s is given as a BooleSet, then the return type is also a BooleSet. If s is a set/list/tuple of tuple this
function returns a tuple of tuples.
INPUT:
• s - candidate points for evaluation to zero
EXAMPLES:
sage: B.<a,b,c,d> = BooleanPolynomialRing(4)
sage: f = a*b + c + d + 1
This encodes the points (1,1,1,0), (1,1,0,0), (0,0,1,1) and (0,0,0,0). But of these only (1,1,0,0) evaluates to
zero.
sage: f.zeros_in(s)
{{a,b}}
class sage.rings.polynomial.pbori.BooleanPolynomialEntry
Bases: object
p
class sage.rings.polynomial.pbori.BooleanPolynomialIdeal(ring, gens=[], co-
erce=True)
Bases: sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal
Construct an ideal in the boolean polynomial ring.
INPUT:
• ring - the ring this ideal is defined in
• gens - a list of generators
• coerce - coerce all elements to the ring ring (default: True)
EXAMPLES:
dimension()
Return the dimension of self, which is always zero.
groebner_basis(algorithm=’polybori’, **kwds)
Return a Groebner basis of this ideal.
INPUT:
• algorithm - either "polybori" (built-in default) or "magma" (requires Magma).
• red_tail - tail reductions in intermediate polynomials, this options affects mainly heuristics. The
reducedness of the output polynomials can only be guaranteed by the option redsb (default: True)
• minsb - return a minimal Groebner basis (default: True)
• redsb - return a minimal Groebner basis and all tails are reduced (default: True)
• deg_bound - only compute Groebner basis up to a given degree bound (default: False)
• faugere - turn off or on the linear algebra (default: False)
• linear_algebra_in_last_block - this affects the last block of block orderings and degree
orderings. If it is set to True linear algebra takes affect in this block. (default: True)
• gauss_on_linear - perform Gaussian elimination on linear polynomials (default: True)
• selection_size - maximum number of polynomials for parallel reductions (default: 1000)
• heuristic - Turn off heuristic by setting heuristic=False (default: True)
• lazy - (default: True)
• invert - setting invert=True input and output get a transformation x+1 for each variable x,
which shouldn’t effect the calculated GB, but the algorithm.
• other_ordering_first - possible values are False or an ordering code. In practice, many
Boolean examples have very few solutions and a very easy Groebner basis. So, a complex walk algo-
rithm (which cannot be implemented using the data structures) seems unnecessary, as such Groebner
bases can be converted quite fast by the normal Buchberger algorithm from one ordering into another
ordering. (default: False)
• prot - show protocol (default: False)
• full_prot - show full protocol (default: False)
EXAMPLES:
interreduced_basis()
If this ideal is spanned by (f_1, ..., f_n) this method returns (g_1, ..., g_s) such that:
• <f_1,...,f_n> = <g_1,...,g_s>
• LT(g_i) != LT(g_j) for all i != j`
• LT(g_i) does not divide m for all monomials m of {g_1,...,g_{i-1},g_{i+1},...,g_s}
EXAMPLES:
sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True)
sage: F,s = sr.polynomial_system()
sage: I = F.ideal()
sage: I.interreduced_basis()
[k100 + 1, k101 + k001 + 1, k102, k103 + 1, x100 + k001 + 1, x101 + k001,
˓→x102, x103 + k001, w100 + 1, w101 + k001 + 1, w102 + 1, w103 + 1, s000 +
reduce(f )
Reduce an element modulo the reduced Groebner basis for this ideal. This returns 0 if and only if the
element is in this ideal. In any case, this reduction is unique up to monomial orders.
EXAMPLES:
sage: P = PolynomialRing(GF(2),10, 'x')
sage: B = BooleanPolynomialRing(10,'x')
sage: I = sage.rings.ideal.Cyclic(P)
sage: I = B.ideal([B(f) for f in I.gens()])
sage: gb = I.groebner_basis()
sage: I.reduce(gb[0])
0
sage: I.reduce(gb[0] + 1)
1
sage: I.reduce(gb[0]*gb[1])
0
(continues on next page)
variety(**kwds)
Return the variety associated to this boolean ideal.
EXAMPLES:
A Simple example:
class sage.rings.polynomial.pbori.BooleanPolynomialIterator
Bases: object
Iterator over the monomials of a boolean polynomial.
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.polynomial.pbori.BooleanPolynomialRing
Bases: sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base
Construct a boolean polynomial ring with the following parameters:
INPUT:
• n - number of variables (an integer > 1)
• names - names of ring variables, may be a string or list/tuple
• order - term order (default: lex)
EXAMPLES:
sage: R.term_order()
Lexicographic term order
sage: R = BooleanPolynomialRing(5,'x',order='deglex(3),deglex(2)')
sage: R.term_order()
Block term order with blocks:
(Degree lexicographic term order of length 3,
Degree lexicographic term order of length 2)
sage: R = BooleanPolynomialRing(3,'x',order='deglex')
sage: R.term_order()
Degree lexicographic term order
Now we call the clone method and generate a compatible, but ‘lex’ ordered, ring:
sage: C = B.clone(ordering=0)
sage: C(y*z) > C(x)
False
sage: Q = P.clone(names=['t'])
sage: Q
Boolean PolynomialRing in t, x1
sage: S = R.clone(blocks=[3])
sage: S(x2) > S(x3*x4)
True
cover_ring()
Return 𝑅 = F2 [𝑥1 , 𝑥2 , ..., 𝑥𝑛 ] if x_1,x_2,...,x_n is the ordered list of variable names of this ring.
R also has the same term ordering as this ring.
EXAMPLES:
defining_ideal()
Return 𝐼 =< 𝑥2𝑖 + 𝑥𝑖 >⊂ 𝑅 where R = self.cover_ring(), and 𝑥𝑖 any element in the set of
variables of this ring.
EXAMPLES:
gen(i=0)
Return the i-th generator of this boolean polynomial ring.
INPUT:
• i - an integer or a boolean monomial in one variable
EXAMPLES:
gens()
Return the tuple of variables in this ring.
EXAMPLES:
sage: P = BooleanPolynomialRing(10,'x')
sage: P.gens()
(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)
get_base_order_code()
EXAMPLES:
Note: This function which is part of the PolyBoRi upstream API works with a current global ring. This
notion is avoided in Sage.
get_order_code()
EXAMPLES:
Note: This function which is part of the PolyBoRi upstream API works with a current global ring. This
notion is avoided in Sage.
has_degree_order()
Return checks whether the order code corresponds to a degree ordering.
EXAMPLES:
id()
Return a unique identifier for this boolean polynomial ring.
EXAMPLES:
ideal(*gens, **kwds)
Create an ideal in this ring.
INPUT:
• gens - list or tuple of generators
• coerce - bool (default: True) automatically coerce the given polynomials to this ring to form the
ideal
EXAMPLES:
interpolation_polynomial(zeros, ones)
Return the lexicographically minimal boolean polynomial for the given sets of points.
Given two sets of points zeros - evaluating to zero - and ones - evaluating to one -, compute the
lexicographically minimal boolean polynomial satisfying these points.
INPUT:
• zeros - the set of interpolation points mapped to zero
• ones - the set of interpolation points mapped to one
EXAMPLES:
First we create a random-ish boolean polynomial.
Alternatively, we can work with PolyBoRi’s native BooleSet’s. This example is from the PolyBoRi
tutorial:
sage: B = BooleanPolynomialRing(4,"x0,x1,x2,x3")
sage: x = B.gen
sage: V=(x(0)+x(1)+x(2)+x(3)+1).set(); V
{{x0}, {x1}, {x2}, {x3}, {}}
sage: f=x(0)*x(1)+x(1)+x(2)+1
sage: z = f.zeros_in(V); z
{{x1}, {x2}}
sage: o = V.diff(z); o
{{x0}, {x3}, {}}
sage: B.interpolation_polynomial(z,o)
x1 + x2 + 1
n_variables()
Return the number of variables in this boolean polynomial ring.
EXAMPLES:
ngens()
Return the number of variables in this boolean polynomial ring.
EXAMPLES:
one()
EXAMPLES:
sage: P = BooleanPolynomialRing(2,'y')
sage: P.random_element()
y0*y1 + y0
sage: P = BooleanPolynomialRing(1,'y')
sage: P.random_element()
y
remove_var(order=None, *var)
Remove a variable or sequence of variables from this ring.
If order is not specified, then the subring inherits the term order of the original ring, if possible.
EXAMPLES:
sage: R.remove_var(y,z,x,w)
Finite Field of size 2
variable(i=0)
Return the i-th generator of this boolean polynomial ring.
INPUT:
• i - an integer or a boolean monomial in one variable
EXAMPLES:
zero()
EXAMPLES:
class sage.rings.polynomial.pbori.BooleanPolynomialVector
Bases: object
A vector of boolean polynomials.
EXAMPLES:
append(el)
Append the element el to this vector.
EXAMPLES:
sage: list(v)
[a*b + a + b*e + c*d + e*f, a*d + c*d + d*f + e + f, a*c + a*e + b*c + c*f +
˓→f, a*c + a*d + a*e + a*f + b*e, b*c + b*d + c*d + c + 1]
class sage.rings.polynomial.pbori.BooleanPolynomialVectorIterator
Bases: object
next()
x.next() -> the next value, or raise StopIteration
class sage.rings.polynomial.pbori.CCuddNavigator
Bases: object
constant()
else_branch()
terminal_one()
then_branch()
value()
class sage.rings.polynomial.pbori.FGLMStrategy
Bases: object
Strategy object for the FGLM algorithm to translate from one Groebner basis with respect to a term ordering A
to another Groebner basis with respect to a term ordering B.
main()
Execute the FGLM algorithm.
EXAMPLES:
class sage.rings.polynomial.pbori.GroebnerStrategy
Bases: object
A Groebner strategy is the main object to control the strategy for computing Groebner bases.
add_as_you_wish(p)
Add a new generator but let the strategy object decide whether to perform immediate interreduction.
INPUT:
• p - a polynomial
EXAMPLES:
Note that nothing happened immediatly but that the generator was indeed added:
sage: list(gbs)
[a + b]
sage: gbs.symmGB_F2()
sage: list(gbs)
[a + c, b + c]
add_generator(p)
Add a new generator.
INPUT:
• p - a polynomial
EXAMPLES:
add_generator_delayed(p)
Add a new generator but do not perform interreduction immediatly.
INPUT:
• p - a polynomial
EXAMPLES:
sage: list(gbs.all_generators())
[a + b, a + c]
all_generators()
EXAMPLES:
sage: list(gbs)
[a + b]
sage: list(gbs.all_generators())
[a + b, a + c]
all_spolys_in_next_degree()
clean_top_by_chain_criterion()
contains_one()
Return True if 1 is in the generating system.
EXAMPLES:
We construct an example which contains 1 in the ideal spanned by the generators but not in the set of
generators:
sage: B.<a,b,c,d,e,f> = BooleanPolynomialRing()
sage: from brial import GroebnerStrategy
sage: gb = GroebnerStrategy(B)
sage: gb.add_generator(a*c + a*f + d*f + d + f)
sage: gb.add_generator(b*c + b*e + c + d + 1)
sage: gb.add_generator(a*f + a + c + d + 1)
sage: gb.add_generator(a*d + a*e + b*e + c + f)
sage: gb.add_generator(b*d + c + d*f + e + f)
sage: gb.add_generator(a*b + b + c*e + e + 1)
sage: gb.add_generator(a + b + c*d + c*e + 1)
sage: gb.contains_one()
False
faugere_step_dense(v)
Reduces a vector of polynomials using linear algebra.
INPUT:
• v - a boolean polynomial vector
EXAMPLES:
sage: B.<a,b,c,d,e,f> = BooleanPolynomialRing()
sage: from brial import GroebnerStrategy
sage: gb = GroebnerStrategy(B)
sage: gb.add_generator(a*c + a*f + d*f + d + f)
sage: gb.add_generator(b*c + b*e + c + d + 1)
sage: gb.add_generator(a*f + a + c + d + 1)
sage: gb.add_generator(a*d + a*e + b*e + c + f)
sage: gb.add_generator(b*d + c + d*f + e + f)
sage: gb.add_generator(a*b + b + c*e + e + 1)
sage: gb.add_generator(a + b + c*d + c*e + 1)
implications(i)
Compute “useful” implied polynomials of i-th generator, and add them to the strategy, if it finds any.
INPUT:
• i - an index
ll_reduce_all()
Use the built-in ll-encoded BooleSet of polynomials with linear lexicographical leading term, which
coincides with leading term in current ordering, to reduce the tails of all polynomials in the strategy.
minimalize()
Return a vector of all polynomials with minimal leading terms.
minimalize_and_tail_reduce()
Return a vector of all polynomials with minimal leading terms and do tail reductions.
Note: Use that if strat contains a GB and you want a reduced GB.
next_spoly()
nf(p)
Compute the normal form of p with respect to the generating set.
INPUT:
• p - a boolean polynomial
EXAMPLES:
sage: G = GroebnerStrategy(B)
sage: _ = [G.add_generator(f) for f in gb]
sage: G.nf(gb[0])
0
sage: G.nf(gb[0] + 1)
1
sage: G.nf(gb[0]*gb[1])
0
sage: G.nf(gb[0]*B.gen(1))
0
Note: The result is only canonical if the generating set is a Groebner basis.
npairs()
reduction_strategy
select(m)
Return the index of the generator which can reduce the monomial m.
INPUT:
• m - a BooleanMonomial
EXAMPLES:
small_spolys_in_next_degree(f, n)
some_spolys_in_next_degree(n)
suggest_plugin_variable()
symmGB_F2()
Compute a Groebner basis for the generating system.
Note: This implementation is out of date, but it will revived at some point in time. Use the
groebner_basis() function instead.
top_sugar()
variable_has_value(v)
Computes, whether there exists some polynomial of the form 𝑣 + 𝑐 in the Strategy – where c is a constant
– in the list of generators.
INPUT:
• v - the index of a variable
class sage.rings.polynomial.pbori.MonomialConstruct
Bases: object
Implements PolyBoRi’s Monomial() constructor.
class sage.rings.polynomial.pbori.MonomialFactory
Bases: object
Implements PolyBoRi’s Monomial() constructor. If a ring is given is can be used as a Monomial factory for
the given ring.
EXAMPLES:
class sage.rings.polynomial.pbori.PolynomialConstruct
Bases: object
Implements PolyBoRi’s Polynomial() constructor.
lead(x)
Return the leading monomial of boolean polynomial x, with respect to the order of parent ring.
EXAMPLES:
class sage.rings.polynomial.pbori.PolynomialFactory
Bases: object
Implements PolyBoRi’s Polynomial() constructor and a polynomial factory for given rings.
lead(x)
Return the leading monomial of boolean polynomial x, with respect to the order of parent ring.
EXAMPLES:
class sage.rings.polynomial.pbori.ReductionStrategy
Bases: object
Functions and options for boolean polynomial reduction.
add_generator(p)
Add the new generator p to this strategy.
INPUT:
• p - a boolean polynomial.
EXAMPLES:
can_rewrite(p)
Return True if p can be reduced by the generators of this strategy.
EXAMPLES:
cheap_reductions(p)
Peform ‘cheap’ reductions on p.
INPUT:
• p - a boolean polynomial
EXAMPLES:
head_normal_form(p)
Compute the normal form of p with respect to the generators of this strategy but do not perform tail any
reductions.
INPUT:
• p – a polynomial
EXAMPLES:
nf(p)
Compute the normal form of p w.r.t. to the generators of this reduction strategy object.
EXAMPLES:
sage: red.nf(y*z + x)
y + z + 1
reduced_normal_form(p)
Compute the normal form of p with respect to the generators of this strategy and perform tail reductions.
INPUT:
• p - a polynomial
EXAMPLES:
sage: red.reduced_normal_form(y*z + x)
y + z + 1
Implements PolyBoRi’s Variable() constructor and a variable factory for given ring
sage.rings.polynomial.pbori.add_up_polynomials(v, init)
Add up all entries in the vector v.
INPUT:
• v - a vector of boolean polynomials
EXAMPLES:
sage.rings.polynomial.pbori.contained_vars(m)
sage.rings.polynomial.pbori.easy_linear_factors(p)
sage.rings.polynomial.pbori.gauss_on_polys(inp)
Perform Gaussian elimination on the input list of polynomials.
INPUT:
• inp - an iterable
EXAMPLES:
sage: e = gauss_on_polys(l)
sage: E,v = Sequence(e,B).coefficient_matrix()
sage: E
[1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 0]
[0 1 0 0 0 0 0 0 1 1 1 0 1 1 0 1 0 1]
[0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0]
[0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 1 1 0]
[0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 1]
[0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 1]
sage: A.echelon_form()
[1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 0]
[0 1 0 0 0 0 0 0 1 1 1 0 1 1 0 1 0 1]
[0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0]
[0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 1 1 0]
(continues on next page)
sage.rings.polynomial.pbori.get_var_mapping(ring, other)
Return a variable mapping between variables of other and ring. When other is a parent object, the mapping
defines images for all variables of other. If it is an element, only variables occurring in other are mapped.
Raises NameError if no such mapping is possible.
EXAMPLES:
sage.rings.polynomial.pbori.if_then_else(root, a, b)
The opposite of navigating down a ZDD using navigators is to construct new ZDDs in the same way, namely
giving their else- and then-branch as well as the index value of the new node.
INPUT:
• root - a variable
• a - the if branch, a BooleSet or a BoolePolynomial
• b - the else branch, a BooleSet or a BoolePolynomial
EXAMPLES:
sage: if_then_else(x1.lm().index(),f0,f1)
{{x1,x2,x3}, {x1,x3}, {x4}}
sage.rings.polynomial.pbori.interpolate(zero, one)
Interpolate a polynomial evaluating to zero on zero and to one on ones.
INPUT:
sage: B = BooleanPolynomialRing(4,"x0,x1,x2,x3")
sage: x = B.gen
sage: from brial.interpolate import *
sage: V=(x(0)+x(1)+x(2)+x(3)+1).set()
sage: V
{{x0}, {x1}, {x2}, {x3}, {}}
sage: f=x(0)*x(1)+x(1)+x(2)+1
sage: nf_lex_points(f,V)
x1 + x2 + 1
sage: z=f.zeros_in(V)
sage: z
{{x1}, {x2}}
sage: o=V.diff(z)
sage: o
{{x0}, {x3}, {}}
sage: interpolate(z,o)
x0*x1*x2 + x0*x1 + x0*x2 + x1*x2 + x1 + x2 + 1
sage.rings.polynomial.pbori.interpolate_smallest_lex(zero, one)
Interpolate the lexicographical smallest polynomial evaluating to zero on zero and to one on ones.
INPUT:
• zero - the set of zeros
• one - the set of ones
EXAMPLES:
Let V be a set of points in F𝑛2 and f a Boolean polynomial. V can be encoded as a BooleSet. Then we are
interested in the normal form of f against the vanishing ideal of V : I(V).
It turns out, that the computation of the normal form can be done by the computation of a minimal interpolation
polynomial, which takes the same values as f on V:
sage: B = BooleanPolynomialRing(4,"x0,x1,x2,x3")
sage: x = B.gen
sage: from brial.interpolate import *
sage: V=(x(0)+x(1)+x(2)+x(3)+1).set()
We take V = {e0,e1,e2,e3,0}, where ei describes the i-th unit vector. For our considerations it does not play any
role, if we suppose V to be embedded in F42 or a vector space of higher dimension:
sage: V
{{x0}, {x1}, {x2}, {x3}, {}}
sage: f=x(0)*x(1)+x(1)+x(2)+1
sage: nf_lex_points(f,V)
x1 + x2 + 1
In this case, the normal form of f w.r.t. the vanishing ideal of V consists of all terms of f with degree smaller or
equal to 1.
It can be easily seen, that this polynomial forms the same function on V as f. In fact, our computation is
equivalent to the direct call of the interpolation function interpolate_smallest_lex, which has two
arguments: the set of interpolation points mapped to zero and the set of interpolation points mapped to one:
sage: z=f.zeros_in(V)
sage: z
{{x1}, {x2}}
sage: o=V.diff(z)
sage: o
{{x0}, {x3}, {}}
sage: interpolate_smallest_lex(z,o)
x1 + x2 + 1
sage.rings.polynomial.pbori.ll_red_nf_noredsb(p, reductors)
Redude the polynomial p by the set of reductors with linear leading terms.
INPUT:
• p - a boolean polynomial
• reductors - a boolean set encoding a Groebner basis with linear leading terms.
EXAMPLES:
sage.rings.polynomial.pbori.ll_red_nf_noredsb_single_recursive_call(p, reduc-
tors)
Redude the polynomial p by the set of reductors with linear leading terms.
ll_red_nf_noredsb_single_recursive() call has the same specification as
ll_red_nf_noredsb(), but a different implementation: It is very sensitive to the ordering of vari-
ables, however it has the property, that it needs just one recursive call.
INPUT:
• p - a boolean polynomial
• reductors - a boolean set encoding a Groebner basis with linear leading terms.
EXAMPLES:
sage.rings.polynomial.pbori.ll_red_nf_redsb(p, reductors)
Redude the polynomial p by the set of reductors with linear leading terms. It is assumed that the set
reductors is a reduced Groebner basis.
INPUT:
• p - a boolean polynomial
• reductors - a boolean set encoding a reduced Groebner basis with linear leading terms.
EXAMPLES:
sage.rings.polynomial.pbori.map_every_x_to_x_plus_one(p)
Map every variable x_i in this polynomial to x_i + 1.
EXAMPLES:
sage.rings.polynomial.pbori.mod_mon_set(a_s, v_s)
sage.rings.polynomial.pbori.mod_var_set(a, v)
sage.rings.polynomial.pbori.mult_fact_sim_C(v, ring)
sage.rings.polynomial.pbori.nf3(s, p, m)
sage.rings.polynomial.pbori.parallel_reduce(inp, strat, average_steps, delay_f )
sage.rings.polynomial.pbori.random_set(variables, length)
Return a random set of monomials with length elements with each element in the variables variables.
EXAMPLES:
sage.rings.polynomial.pbori.recursively_insert(n, ind, m)
sage.rings.polynomial.pbori.red_tail(s, p)
Perform tail reduction on p using the generators of s.
INPUT:
• s - a reduction strategy
• p - a polynomial
EXAMPLES:
sage.rings.polynomial.pbori.set_random_seed(seed)
The the PolyBoRi random seed to seed
EXAMPLES:
sage: set_random_seed(1337)
sage: random_set((a*b*c*d).lm(),2)
{{b}, {c}}
sage: random_set((a*b*c*d).lm(),2)
{{a,c,d}, {c}}
sage.rings.polynomial.pbori.top_index(s)
Return the highest index in the parameter s.
INPUT:
• s - BooleSet, BooleMonomial, BoolePolynomial
EXAMPLES:
sage.rings.polynomial.pbori.unpickle_BooleanPolynomial(ring, string)
Unpickle boolean polynomials
EXAMPLES:
sage: T = TermOrder('deglex',2)+TermOrder('deglex',2)
sage: P.<a,b,c,d> = BooleanPolynomialRing(4,order=T)
sage: loads(dumps(a+b)) == a+b # indirect doctest
True
sage.rings.polynomial.pbori.unpickle_BooleanPolynomial0(ring, l)
Unpickle boolean polynomials
EXAMPLES:
sage: T = TermOrder('deglex',2)+TermOrder('deglex',2)
sage: P.<a,b,c,d> = BooleanPolynomialRing(4,order=T)
sage: loads(dumps(a+b)) == a+b # indirect doctest
True
sage: T = TermOrder('deglex',2)+TermOrder('deglex',2)
sage: P.<a,b,c,d> = BooleanPolynomialRing(4,order=T)
sage: loads(dumps(P)) == P # indirect doctest
True
sage.rings.polynomial.pbori.zeros(pol, s)
Return a BooleSet encoding on which points from s the polynomial pol evaluates to zero.
INPUT:
• pol - a boolean polynomial
This encodes the points (1,1,1,0), (1,1,0,0), (0,0,1,1) and (0,1,1,0). But of these only (1,1,0,0) evaluates to zero.:
NINE
NONCOMMUTATIVE POLYNOMIALS
This module provides specialized and optimized implementations for noncommutative multivariate polynomials over
many coefficient rings, via the shared library interface to SINGULAR. In particular, the following coefficient rings are
supported by this implementation:
• the rational numbers Q, and
• finite fields F𝑝 for 𝑝 prime
AUTHORS:
The PLURAL wrapper is due to
• Burcin Erocal (2008-11 and 2010-07): initial implementation and concept
• Michael Brickenstein (2008-11 and 2010-07): initial implementation and concept
• Oleksandr Motsak (2010-07): complete overall noncommutative functionality and first release
• Alexander Dreyer (2010-07): noncommutative ring functionality and documentation
• Simon King (2011-09): left and two-sided ideals; normal forms; pickling; documentation
The underlying libSINGULAR interface was implemented by
• Martin Albrecht (2007-01): initial implementation
• Joel Mohler (2008-01): misc improvements, polishing
• Martin Albrecht (2008-08): added Q(𝑎) and Z support
• Simon King (2009-04): improved coercion
• Martin Albrecht (2009-05): added Z/𝑛Z support, refactoring
• Martin Albrecht (2009-06): refactored the code to allow better re-use
EXAMPLES:
We show how to construct various noncommutative polynomial rings:
639
Sage Reference Manual: Polynomials, Release 8.6
sage: y*x + 7
-x*y + 7
sage: d = Matrix(3)
sage: d[0, 1] = 17
sage: P = QQ['x','y','z']
sage: c = c.change_ring(P)
sage: d = d.change_ring(P)
sage: R
Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-
˓→relations: {y*x: -2*x*y + 17}
sage: R.term_order()
Lexicographic term order
˓→x^2)
class sage.rings.polynomial.plural.ExteriorAlgebra_plural
Bases: sage.rings.polynomial.plural.NCPolynomialRing_plural
class sage.rings.polynomial.plural.G_AlgFactory
Bases: sage.structure.factory.UniqueFactory
A factory for the creation of g-algebras as unique parents.
create_key_and_extra_args(base_ring, c, d, names=None, order=None, category=None,
check=None)
Create a unique key for g-algebras.
INPUT:
• base_ring - a ring
• c,d - two matrices
• names - a tuple or list of names
• order - (optional) term order
• category - (optional) category
• check - optional bool
create_object(version, key, **extra_args)
Create a g-algebra to a given unique key.
INPUT:
• key - a 6-tuple, formed by a base ring, a tuple of names, two matrices over a polynomial ring over
the base ring with the given variable names, a term order, and a category
• extra_args - a dictionary, whose only relevant key is ‘check’.
class sage.rings.polynomial.plural.NCPolynomialRing_plural
Bases: sage.rings.ring.Ring
A non-commutative polynomial ring.
EXAMPLES:
Note that two variables commute if they are not part of the given relations:
free_algebra()
The free algebra of which this is the quotient.
EXAMPLES:
gen(n=0)
Returns the n-th generator of this noncommutative polynomial ring.
INPUT:
• n – an integer >= 0
EXAMPLES:
ideal(*gens, **kwds)
Create an ideal in this polynomial ring.
INPUT:
• *gens - list or tuple of generators (or several input arguments)
• coerce - bool (default: True); this must be a keyword argument. Only set it to False if you are
certain that each generator is already in the ring.
• side - string (either “left”, which is the default, or “twosided”) Must be a keyword argument. Defines
whether the ideal is a left ideal or a two-sided ideal. Right ideals are not implemented.
EXAMPLES:
sage: P.ideal([x + 2*y + 2*z-1, 2*x*y + 2*y*z-y, x^2 + 2*y^2 + 2*z^2-x], side=
˓→"twosided")
is_commutative()
Return False.
EXAMPLES:
is_field(*args, **kwargs)
Return False.
EXAMPLES:
monomial_all_divisors(t)
Return a list of all monomials that divide t.
Coefficients are ignored.
INPUT:
• t - a monomial
OUTPUT:
a list of monomials
EXAMPLES:
sage: P.monomial_all_divisors(x^2*z^3)
[x, x^2, z, x*z, x^2*z, z^2, x*z^2, x^2*z^2, z^3, x*z^3, x^2*z^3]
monomial_divides(a, b)
Return False if a does not divide b and True otherwise.
Coefficients are ignored.
INPUT:
• a – monomial
• b – monomial
EXAMPLES:
monomial_lcm(f, g)
LCM for monomials. Coefficients are ignored.
INPUT:
• f - monomial
• g - monomial
EXAMPLES:
sage: P.monomial_lcm(3/2*x*y,x)
x*y
monomial_pairwise_prime(g, h)
Return True if h and g are pairwise prime.
Both h and g are treated as monomials.
Coefficients are ignored.
INPUT:
• h - monomial
• g - monomial
EXAMPLES:
monomial_quotient(f, g, coeff=False)
Return f/g, where both f and g are treated as monomials.
Coefficients are ignored by default.
INPUT:
• f - monomial
• g - monomial
• coeff - divide coefficients as well (default: False)
EXAMPLES:
sage: P.monomial_quotient(3/2*x*y,x,coeff=True)
3/2*y
sage: P.monomial_quotient(2*x,3*x)
1
sage: P.monomial_quotient(2*x,3*x,coeff=True)
2/3
Warning: Assumes that the head term of f is a multiple of the head term of g and return the multipli-
cant m. If this rule is violated, funny things may happen.
monomial_reduce(f, G)
Try to find a g in G where g.lm() divides f. If found (flt,g) is returned, (0,0) otherwise, where
flt is f/g.lm().
It is assumed that G is iterable and contains only elements in this polynomial ring.
Coefficients are ignored.
INPUT:
• f - monomial
• G - list/set of mpolynomials
EXAMPLES:
sage: f = x*y^2
sage: G = [ 3/2*x^3 + y^2 + 1/2, 1/4*x*y + 2/7, 1/2 ]
sage: P.monomial_reduce(f,G)
(y, 1/4*x*y + 2/7)
ngens()
Returns the number of variables in this noncommutative polynomial ring.
EXAMPLES:
relations(add_commutative=False)
Return the relations of this g-algebra.
INPUT:
add_commutative (optional bool, default False)
OUTPUT:
The defining relations. There are some implicit relations: Two generators commute if they are not part of
any given relation. The implicit relations are not provided, unless add_commutative==True.
EXAMPLES:
term_order()
Return the term ordering of the noncommutative ring.
EXAMPLES:
sage: P = A.g_algebra(relations={y*x:-x*y})
sage: P.term_order()
Degree reverse lexicographic term order
class sage.rings.polynomial.plural.NCPolynomial_plural
Bases: sage.structure.element.RingElement
A noncommutative multivariate polynomial implemented using libSINGULAR.
coefficient(degrees)
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 in
degrees. 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 this element.
EXAMPLES:
sage: 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.
AUTHOR:
• Joel B. Mohler (2007-10-31)
constant_coefficient()
Return the constant coefficient of this multivariate polynomial.
EXAMPLES:
sage: A.<x,z,y> = FreeAlgebra(GF(389), 3)
sage: P = A.g_algebra(relations={y*x:-x*y + z}, order='lex')
sage: P.inject_variables()
Defining x, z, y
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
degree(x=None)
Return the maximal degree of this polynomial in x, where x must be one of the generators for the parent
of this polynomial.
INPUT:
• x - multivariate polynomial (a generator of the parent of self) If x is not specified (or is None), return
the total degree, which is the maximum degree of any monomial.
OUTPUT:
integer
EXAMPLES:
sage: A.<x,z,y> = FreeAlgebra(QQ, 3)
sage: R = A.g_algebra(relations={y*x:-x*y + z}, order='lex')
sage: R.inject_variables()
Defining x, z, y
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
degrees()
Returns a tuple with the maximal degree of each variable in this polynomial. The list of degrees is ordered
by the order of the generators.
EXAMPLES:
sage: A.<y0,y1,y2> = FreeAlgebra(QQ, 3)
sage: R = A.g_algebra(relations={y1*y0:-y0*y1 + y2}, order='lex')
sage: R.inject_variables()
Defining y0, y1, y2
sage: q = 3*y0*y1*y1*y2; q
3*y0*y1^2*y2
(continues on next page)
dict()
Return a dictionary representing self. This dictionary is in the same format as the generic MPolynomial:
The dictionary consists of ETuple:coefficient pairs.
EXAMPLES:
exponents(as_ETuples=True)
Return the exponents of the monomials appearing in this polynomial.
INPUT:
• as_ETuples - (default: True) if True returns the result as an list of ETuples otherwise returns a
list of tuples
EXAMPLES:
is_constant()
Return True if this polynomial is constant.
EXAMPLES:
is_homogeneous()
Return True if this polynomial is homogeneous.
EXAMPLES:
is_monomial()
Return True if this polynomial is a monomial.
A monomial is defined to be a product of generators with coefficient 1.
EXAMPLES:
is_zero()
Return True if this polynomial is zero.
EXAMPLES:
sage: x.is_zero()
False
sage: (x-x).is_zero()
True
lc()
Leading coefficient of this polynomial with respect to the term order of self.parent().
EXAMPLES:
lm()
Returns the lead monomial of self with respect to the term order of self.parent().
In Sage a monomial is a product of variables in some power without a coefficient.
EXAMPLES:
lt()
Leading term of this polynomial.
In Sage a term is a product of variables in some power and a coefficient.
EXAMPLES:
monomial_coefficient(mon)
Return the coefficient in the base ring of the monomial mon in self, where mon must have the same
parent as self.
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:
monomials()
Return the list of monomials in self
The returned list is decreasingly ordered by the term ordering of self.parent().
EXAMPLES:
sage: A.<x,z,y> = FreeAlgebra(GF(389), 3)
sage: P = A.g_algebra(relations={y*x:-x*y + z}, order='lex')
sage: P.inject_variables()
Defining x, z, y
sage: f = x + (3*2)*y*z^2 + (2+3)
sage: f.monomials()
[x, z^2*y, 1]
sage: f = P(3^2)
sage: f.monomials()
[1]
reduce(I)
EXAMPLES:
sage: A.<x,y,z> = FreeAlgebra(QQ, 3)
sage: H.<x,y,z> = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y})
sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False)
The result of reduction is not the normal form, if one reduces by a list of polynomials:
sage: (x*z).reduce(I.gens())
x*z
However, if the argument is an ideal, then a normal form (reduction with respect to a two-sided Groebner
basis) is returned:
sage: (x*z).reduce(I)
-x
total_degree()
Return the total degree of self, which is the maximum degree of all monomials in self.
EXAMPLES:
sage: A.<x,z,y> = FreeAlgebra(QQ, 3)
sage: R = A.g_algebra(relations={y*x:-x*y + z}, order='lex')
sage: R.inject_variables()
Defining x, z, y
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
(continues on next page)
sage: E.inject_variables()
Defining xbar, ybar, zbar
sage: x,y,z = (xbar,ybar,zbar)
sage: y*x
-x*y
sage: z*x
x*z
sage: x^2
0
sage: y^2
0
sage: z^2
z^2
sage: E.one()
1
sage.rings.polynomial.plural.new_CRing(rw, base_ring)
Construct MPolynomialRing_libsingular from ringWrap, assuming the ground field to be base_ring
EXAMPLES:
sage: len(L)
4
sage.rings.polynomial.plural.new_NRing(rw, base_ring)
Construct NCPolynomialRing_plural from ringWrap, assuming the ground field to be base_ring
EXAMPLES:
sage: A.<x,y,z> = FreeAlgebra(QQ, 3)
sage: H = A.g_algebra({y*x:x*y-1})
sage: H.inject_variables()
Defining x, y, z
sage: z*x
x*z
sage: z*y
y*z
sage: y*x
x*y - 1
sage: I = H.ideal([y^2, x^2, z^2-1])
sage: I._groebner_basis_libsingular()
[1]
[ 0 -1 0]
[ 0 0 0]
[ 0 0 0]
]
(continues on next page)
sage.rings.polynomial.plural.new_Ring(rw, base_ring)
Constructs a Sage ring out of low level RingWrap, which wraps a pointer to a Singular ring.
The constructed ring is either commutative or noncommutative depending on the Singular ring.
EXAMPLES:
sage: A.<x,y,z> = FreeAlgebra(QQ, 3)
sage: H = A.g_algebra({y*x:x*y-1})
sage: H.inject_variables()
Defining x, y, z
sage: z*x
x*z
sage: z*y
y*z
sage: y*x
x*y - 1
sage: I = H.ideal([y^2, x^2, z^2-1])
sage: I._groebner_basis_libsingular()
[1]
[ 0 -1 0]
[ 0 0 0]
[ 0 0 0]
]
sage: len(L)
6
sage.rings.polynomial.plural.unpickle_NCPolynomial_plural(R, d)
Auxiliary function to unpickle a non-commutative polynomial.
TEN
• Index
• Module Index
• Search Page
659
Sage Reference Manual: Polynomials, Release 8.6
[MF99] J.H. Mathews and K.D. Fink. Numerical Methods Using MATLAB. 3rd edition, Prentice-Hall, 1999.
[BF05] R.L. Burden and J.D. Faires. Numerical Analysis. 8th edition, Thomson Brooks/Cole, 2005.
[BFSS] A. Bostan, P. Flajolet, B. Salvy and E. Schost, Fast Computation of special resultants, Journal of Symbolic
Computation 41 (2006), 1-29
[ManWright1994] Yiu-Kwong Man and Francis J. Wright. Fast Polynomial Dispersion Computation and its Applica-
tion to Indefinite Summation. ISSAC 1994.
[BD89] R. J. Bradford and J. H. Davenport, Effective tests for cyclotomic polynomials, Symbolic and Algebraic
Computation (1989) pp. 244 – 251, doi:10.1007/3-540-51084-2_22
[CLO] D. Cox, J. Little, D. O’Shea. Using Algebraic Geometry. Springer, 2005.
[Can] J. Canny. Generalised characteristic polynomials. J. Symbolic Comput. Vol. 9, No. 3, 1990, 241–250.
[Mac] F.S. Macaulay. The algebraic theory of modular systems Cambridge university press, 1916.
[BFS04] Magali Bardet, Jean-Charles Faugère, and Bruno Salvy, On the complexity of Groebner basis computation of
semi-regular overdetermined algebraic equations. Proc. International Conference on Polynomial System Solving
(ICPSS), pp. 71-75, 2004.
[BPW06] J. Buchmann, A. Pychkine, R.-P. Weinmann Block Ciphers Sensitive to Groebner Basis Attacks in Topics
in Cryptology – CT RSA‘06; LNCS 3860; pp. 313–331; Springer Verlag 2006; pre-print available at http://eprint.
iacr.org/2005/200
[CBJ07] Gregory V. Bard, and Nicolas T. Courtois, and Chris Jefferson. Efficient Methods for Conversion and Solu-
tion of Sparse Systems of Low-Degree Multivariate Polynomials over GF(2) via SAT-Solvers. Cryptology ePrint
Archive: Report 2007/024. available at http://eprint.iacr.org/2007/024
[WpInvariantTheory] Wikipedia article Glossary_of_invariant_theory
[WpBinaryForm] Wikipedia article Invariant_of_a_binary_form
[WpTernaryCubic] Wikipedia article Ternary_cubic
[Salmon] G. Salmon: “A Treatise on the Analytic Geometry of Three Dimensions”, section on “Invariants and Co-
variants of Systems of Quadrics”.
[Salmon2] G. Salmon: A Treatise on Conic Sections, Section on “Invariants and Covariants of Systems of Conics”,
Art. 388 (a).
[BW93] Thomas Becker and Volker Weispfenning. Groebner Bases - A Computational Approach To Commutative
Algebra. Springer, New York 1993.
[Laz92] Daniel Lazard, Solving Zero-dimensional Algebraic Systems, in Journal of Symbolic Computation (1992)
vol. 13, pp. 117-131
661
Sage Reference Manual: Polynomials, Release 8.6
[Ore33] Oystein Ore. Theory of Non-Commutative Polynomials Annals of Mathematics, Second Series, Volume 34,
Issue 3 (Jul., 1933), 480-508.
[Ho72] E. Horowitz, “Algorithms for Rational Function Arithmetic Operations”, Annual ACM Symposium on Theory
of Computing, Proceedings of the Fourth Annual ACM Symposium on Theory of Computing, pp. 108–118, 1972
[AB2007] M. Aschenbrenner, C. Hillar, Finite generation of symmetric ideals. Trans. Amer. Math. Soc. 359 (2007),
no. 11, 5171–5192.
[AB2008] M. Aschenbrenner, C. Hillar, An Algorithm for Finding Symmetric Groebner Bases in Infinite Dimensional
Rings. Arxiv 0801.4439.
[BD07] Michael Brickenstein, Alexander Dreyer; PolyBoRi: A Groebner basis framework for Boolean polynomials;
pre-print available at http://www.itwm.fraunhofer.de/fileadmin/ITWM-Media/Zentral/Pdf/Berichte_ITWM/2007/
bericht122.pdf
662 Bibliography
PYTHON MODULE INDEX
r
sage.rings.fraction_field, 499
sage.rings.fraction_field_element, 505
sage.rings.fraction_field_FpT, 509
sage.rings.invariants.invariant_theory, 408
sage.rings.monomials, 408
sage.rings.polynomial.complex_roots, 212
sage.rings.polynomial.convolution, 239
sage.rings.polynomial.cyclotomic, 240
sage.rings.polynomial.flatten, 405
sage.rings.polynomial.hilbert, 404
sage.rings.polynomial.ideal, 215
sage.rings.polynomial.infinite_polynomial_element, 557
sage.rings.polynomial.infinite_polynomial_ring, 547
sage.rings.polynomial.laurent_polynomial, 524
sage.rings.polynomial.laurent_polynomial_ring, 517
sage.rings.polynomial.multi_polynomial, 269
sage.rings.polynomial.multi_polynomial_element, 293
sage.rings.polynomial.multi_polynomial_ideal, 307
sage.rings.polynomial.multi_polynomial_ideal_libsingular, 392
sage.rings.polynomial.multi_polynomial_libsingular, 366
sage.rings.polynomial.multi_polynomial_ring, 289
sage.rings.polynomial.multi_polynomial_ring_base, 260
sage.rings.polynomial.multi_polynomial_sequence, 351
sage.rings.polynomial.omega, 541
sage.rings.polynomial.padics.polynomial_padic, 170
sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense, 173
sage.rings.polynomial.padics.polynomial_padic_flat, 180
sage.rings.polynomial.pbori, 581
sage.rings.polynomial.plural, 639
sage.rings.polynomial.polydict, 394
sage.rings.polynomial.polynomial_compiled, 238
sage.rings.polynomial.polynomial_element, 30
sage.rings.polynomial.polynomial_element_generic, 110
sage.rings.polynomial.polynomial_fateman, 239
sage.rings.polynomial.polynomial_gf2x, 119
sage.rings.polynomial.polynomial_integer_dense_flint, 125
663
Sage Reference Manual: Polynomials, Release 8.6
sage.rings.polynomial.polynomial_integer_dense_ntl, 134
sage.rings.polynomial.polynomial_modn_dense_ntl, 157
sage.rings.polynomial.polynomial_number_field, 123
sage.rings.polynomial.polynomial_quotient_ring, 216
sage.rings.polynomial.polynomial_quotient_ring_element, 234
sage.rings.polynomial.polynomial_rational_flint, 139
sage.rings.polynomial.polynomial_real_mpfr_dense, 166
sage.rings.polynomial.polynomial_ring, 9
sage.rings.polynomial.polynomial_ring_constructor, 1
sage.rings.polynomial.polynomial_ring_homomorphism, 29
sage.rings.polynomial.polynomial_singular_interface, 169
sage.rings.polynomial.polynomial_zmod_flint, 150
sage.rings.polynomial.polynomial_zz_pex, 180
sage.rings.polynomial.real_roots, 184
sage.rings.polynomial.refine_root, 215
sage.rings.polynomial.skew_polynomial_element, 461
sage.rings.polynomial.skew_polynomial_ring, 491
sage.rings.polynomial.skew_polynomial_ring_constructor, 489
sage.rings.polynomial.symmetric_ideal, 565
sage.rings.polynomial.symmetric_reduction, 574
sage.rings.polynomial.term_order, 243
sage.rings.polynomial.toy_buchberger, 447
sage.rings.polynomial.toy_d_basis, 456
sage.rings.polynomial.toy_variety, 452
Symbols
_add_() (sage.rings.polynomial.polynomial_element.Polynomial method), 31
_add_() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 125
_add_() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
_add_() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 139
_add_() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 152
_lmul_() (sage.rings.polynomial.polynomial_element.Polynomial method), 31
_lmul_() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 126
_lmul_() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
_lmul_() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 139
_lmul_() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 153
_mul_() (sage.rings.polynomial.polynomial_element.Polynomial method), 32
_mul_() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 126
_mul_() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
_mul_() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 140
_mul_() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 153
_mul_trunc_() (sage.rings.polynomial.polynomial_element.Polynomial method), 32
_mul_trunc_() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 126
_mul_trunc_() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
_mul_trunc_() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 140
_mul_trunc_() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 154
_rmul_() (sage.rings.polynomial.polynomial_element.Polynomial method), 31
_rmul_() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 126
_rmul_() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
_rmul_() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 139
_rmul_() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 153
_sub_() (sage.rings.polynomial.polynomial_element.Polynomial method), 31
_sub_() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 126
_sub_() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
_sub_() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 139
_sub_() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 153
A
A_invariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 415
abc_pd (class in sage.rings.polynomial.polynomial_compiled), 239
adams_operator() (sage.rings.polynomial.polynomial_element.Polynomial method), 32
add_as_you_wish() (sage.rings.polynomial.pbori.GroebnerStrategy method), 623
665
Sage Reference Manual: Polynomials, Release 8.6
B
B_invariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 416
base_extend() (sage.rings.polynomial.polynomial_element.Polynomial method), 35
base_extend() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 20
base_field() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_field method), 221
base_ring() (sage.rings.fraction_field.FractionField_generic method), 502
base_ring() (sage.rings.polynomial.polynomial_element.Polynomial method), 35
base_ring() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 225
base_ring() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 464
basis (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal attribute), 311
basis_is_groebner() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr method), 327
bateman_bound() (in module sage.rings.polynomial.cyclotomic), 240
bernstein_down() (in module sage.rings.polynomial.real_roots), 184
bernstein_expand() (in module sage.rings.polynomial.real_roots), 185
bernstein_polynomial() (sage.rings.polynomial.real_roots.bernstein_polynomial_factory_ar method), 185
bernstein_polynomial() (sage.rings.polynomial.real_roots.bernstein_polynomial_factory_intlist method), 186
bernstein_polynomial() (sage.rings.polynomial.real_roots.bernstein_polynomial_factory_ratlist method), 187
bernstein_polynomial_factory (class in sage.rings.polynomial.real_roots), 185
bernstein_polynomial_factory_ar (class in sage.rings.polynomial.real_roots), 185
bernstein_polynomial_factory_intlist (class in sage.rings.polynomial.real_roots), 186
bernstein_polynomial_factory_ratlist (class in sage.rings.polynomial.real_roots), 186
666 Index
Sage Reference Manual: Polynomials, Release 8.6
C
C_invariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 416
can_convert_to_singular() (in module sage.rings.polynomial.polynomial_singular_interface), 169
can_rewrite() (sage.rings.polynomial.pbori.ReductionStrategy method), 629
cardinality() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 226
cartesian_product() (sage.rings.polynomial.pbori.BooleSet method), 585
CCuddNavigator (class in sage.rings.polynomial.pbori), 623
change() (sage.rings.polynomial.pbori.BooleSet method), 585
change_ring() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial method), 524
change_ring() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 520
change_ring() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 269
change_ring() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_element method), 294
change_ring() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 311
change_ring() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 261
change_ring() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 615
change_ring() (sage.rings.polynomial.polynomial_element.Polynomial method), 35
change_ring() (sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense method), 166
change_ring() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 20
change_var() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 20
change_var() (sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general method), 492
Index 667
Sage Reference Manual: Polynomials, Release 8.6
668 Index
Sage Reference Manual: Polynomials, Release 8.6
complete_primary_decomposition() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr
method), 328
completion() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 520
completion() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 261
completion() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 21
complex_embeddings() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_field method),
222
complex_roots() (in module sage.rings.polynomial.complex_roots), 212
complex_roots() (sage.rings.polynomial.polynomial_element.Polynomial method), 36
compose_power() (sage.rings.polynomial.polynomial_element.Polynomial method), 36
compose_trunc() (sage.rings.polynomial.polynomial_element.Polynomial method), 37
composed_op() (sage.rings.polynomial.polynomial_element.Polynomial method), 37
conjugate() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 465
connected_components() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method),
357
connection_graph() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method), 357
constant() (sage.rings.polynomial.pbori.BooleanPolynomial method), 596
constant() (sage.rings.polynomial.pbori.CCuddNavigator method), 623
constant_coefficient() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair method), 526
constant_coefficient() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 534
constant_coefficient() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 296
constant_coefficient() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 373
constant_coefficient() (sage.rings.polynomial.pbori.BooleanPolynomial method), 596
constant_coefficient() (sage.rings.polynomial.plural.NCPolynomial_plural method), 648
constant_coefficient() (sage.rings.polynomial.polynomial_element.Polynomial method), 39
constant_coefficient() (sage.rings.polynomial.polynomial_element.Polynomial_generic_dense method), 105
constant_coefficient() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 466
ConstantPolynomialSection (class in sage.rings.polynomial.polynomial_element), 30
ConstantSkewPolynomialSection (class in sage.rings.polynomial.skew_polynomial_element), 461
construction() (sage.rings.fraction_field.FractionField_generic method), 502
construction() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_dense method), 552
construction() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse method), 554
construction() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 520
construction() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 262
construction() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 228
construction() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 21
contained_vars() (in module sage.rings.polynomial.pbori), 631
contains_one() (sage.rings.polynomial.pbori.GroebnerStrategy method), 625
content() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 270
content() (sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic method), 170
content() (sage.rings.polynomial.polynomial_element.Polynomial method), 39
content() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 127
content() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 134
content_ideal() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 271
content_ideal() (sage.rings.polynomial.polynomial_element.Polynomial method), 39
context (class in sage.rings.polynomial.real_roots), 188
convolution() (in module sage.rings.polynomial.convolution), 240
covariant_conic() (sage.rings.invariants.invariant_theory.TernaryQuadratic method), 438
cover_ring() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 616
cover_ring() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 228
Index 669
Sage Reference Manual: Polynomials, Release 8.6
D
d_basis() (in module sage.rings.polynomial.toy_d_basis), 458
de_casteljau() (sage.rings.polynomial.real_roots.interval_bernstein_polynomial_float method), 194
de_casteljau() (sage.rings.polynomial.real_roots.interval_bernstein_polynomial_integer method), 196
de_casteljau_doublevec() (in module sage.rings.polynomial.real_roots), 188
de_casteljau_intvec() (in module sage.rings.polynomial.real_roots), 189
defining_ideal() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 616
deg() (sage.rings.polynomial.pbori.BooleanMonomial method), 591
deg() (sage.rings.polynomial.pbori.BooleanPolynomial method), 597
deg() (sage.rings.polynomial.pbori.BooleConstant method), 583
degree() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair method), 527
degree() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 534
degree() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 296
degree() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 374
degree() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 173
degree() (sage.rings.polynomial.pbori.BooleanMonomial method), 591
degree() (sage.rings.polynomial.pbori.BooleanPolynomial method), 597
degree() (sage.rings.polynomial.plural.NCPolynomial_plural method), 648
degree() (sage.rings.polynomial.polydict.PolyDict method), 399
degree() (sage.rings.polynomial.polynomial_element.Polynomial method), 40
degree() (sage.rings.polynomial.polynomial_element.Polynomial_generic_dense method), 105
degree() (sage.rings.polynomial.polynomial_element.Polynomial_generic_dense_inexact method), 107
degree() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse method), 114
degree() (sage.rings.polynomial.polynomial_gf2x.Polynomial_template method), 121
degree() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 127
degree() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 134
degree() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_n method), 157
degree() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ method), 160
degree() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 162
degree() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 228
degree() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 140
degree() (sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense method), 167
degree() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template method), 151
degree() (sage.rings.polynomial.polynomial_zz_pex.Polynomial_template method), 182
degree() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 466
degree() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial_generic_dense method), 485
degree_lowest_rational_function() (in module sage.rings.polynomial.multi_polynomial_element), 307
degree_of_semi_regularity() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 312
670 Index
Sage Reference Manual: Polynomials, Release 8.6
Index 671
Sage Reference Manual: Polynomials, Release 8.6
E
eadd() (sage.rings.polynomial.polydict.ETuple method), 395
eadd_p() (sage.rings.polynomial.polydict.ETuple method), 395
easy_linear_factors() (in module sage.rings.polynomial.pbori), 631
EisensteinD() (sage.rings.invariants.invariant_theory.BinaryQuartic method), 412
EisensteinE() (sage.rings.invariants.invariant_theory.BinaryQuartic method), 413
Element (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_mpair attribute), 523
Element (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_univariate attribute), 524
Element (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular attribute), 369
Element (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic attribute), 223
element() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_element method), 294
elength() (sage.rings.polynomial.pbori.BooleanPolynomial method), 597
elim_pol() (in module sage.rings.polynomial.toy_variety), 453
eliminate_linear_variables() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_gf2 method),
362
elimination_ideal() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr method), 331
else_branch() (sage.rings.polynomial.pbori.CCuddNavigator method), 623
emax() (sage.rings.polynomial.polydict.ETuple method), 396
emin() (sage.rings.polynomial.polydict.ETuple method), 396
empty() (sage.rings.polynomial.pbori.BooleSet method), 586
emul() (sage.rings.polynomial.polydict.ETuple method), 396
escalar_div() (sage.rings.polynomial.polydict.ETuple method), 396
esub() (sage.rings.polynomial.polydict.ETuple method), 397
ETuple (class in sage.rings.polynomial.polydict), 394
ETupleIter (class in sage.rings.polynomial.polydict), 398
euclidean_degree() (sage.rings.polynomial.polynomial_element.Polynomial method), 46
exponents() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair method), 528
exponents() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 535
exponents() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 298
exponents() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 375
exponents() (sage.rings.polynomial.plural.NCPolynomial_plural method), 649
exponents() (sage.rings.polynomial.polydict.PolyDict method), 399
exponents() (sage.rings.polynomial.polynomial_element.Polynomial method), 46
exponents() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse method), 115
exponents() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 467
672 Index
Sage Reference Manual: Polynomials, Release 8.6
F
F_covariant() (sage.rings.invariants.invariant_theory.TwoTernaryQuadratics method), 444
factor() (sage.rings.fraction_field_FpT.FpTElement method), 510
factor() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair method), 528
factor() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 535
factor() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 298
factor() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 375
factor() (sage.rings.polynomial.padics.polynomial_padic.Polynomial_padic method), 171
factor() (sage.rings.polynomial.polynomial_element.Polynomial method), 46
factor() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 128
factor() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 135
factor() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 154
factor_mod() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 174
factor_mod() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 128
factor_mod() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 135
factor_mod() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 142
factor_of_slope() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdv method), 110
factor_padic() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 129
factor_padic() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 136
factor_padic() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 143
faugere_step_dense() (sage.rings.polynomial.pbori.GroebnerStrategy method), 625
fcp() (sage.rings.polynomial.polynomial_quotient_ring_element.PolynomialQuotientRingElement method), 235
FGLMStrategy (class in sage.rings.polynomial.pbori), 623
field_extension() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_domain method), 220
field_extension() (sage.rings.polynomial.polynomial_quotient_ring_element.PolynomialQuotientRingElement
method), 236
find_roots() (sage.rings.polynomial.real_roots.ocean method), 202
first() (sage.rings.invariants.invariant_theory.TwoAlgebraicForms method), 439
first_hilbert_series() (in module sage.rings.polynomial.hilbert), 404
first_term() (sage.rings.polynomial.pbori.BooleanPolynomial method), 598
flattening_morphism() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 262
flattening_morphism() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 21
FlatteningMorphism (class in sage.rings.polynomial.flatten), 406
footprint() (sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse method), 560
form() (sage.rings.invariants.invariant_theory.AlgebraicForm method), 411
FormsBase (class in sage.rings.invariants.invariant_theory), 424
Fp_FpT_coerce (class in sage.rings.fraction_field_FpT), 514
FpT (class in sage.rings.fraction_field_FpT), 509
FpT_Fp_section (class in sage.rings.fraction_field_FpT), 512
FpT_iter (class in sage.rings.fraction_field_FpT), 513
FpT_Polyring_section (class in sage.rings.fraction_field_FpT), 513
FpTElement (class in sage.rings.fraction_field_FpT), 509
fraction_field() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 520
fraction_field() (sage.rings.polynomial.polynomial_ring.PolynomialRing_field method), 18
FractionField() (in module sage.rings.fraction_field), 499
Index 673
Sage Reference Manual: Polynomials, Release 8.6
G
G_AlgFactory (class in sage.rings.polynomial.plural), 641
g_covariant() (sage.rings.invariants.invariant_theory.BinaryQuartic method), 413
galois_group() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 144
gamma_covariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 421
gauss_on_polys() (in module sage.rings.polynomial.pbori), 631
gcd() (sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse method), 560
gcd() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 535
gcd() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 273
gcd() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 379
gcd() (sage.rings.polynomial.pbori.BooleanMonomial method), 592
gcd() (sage.rings.polynomial.polynomial_element.Polynomial method), 52
gcd() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse method), 115
gcd() (sage.rings.polynomial.polynomial_gf2x.Polynomial_template method), 121
gcd() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 129
gcd() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 136
gcd() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_p method), 159
gcd() (sage.rings.polynomial.polynomial_number_field.Polynomial_absolute_number_field_dense method), 124
gcd() (sage.rings.polynomial.polynomial_number_field.Polynomial_relative_number_field_dense method), 125
gcd() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 145
gcd() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template method), 151
gcd() (sage.rings.polynomial.polynomial_zz_pex.Polynomial_template method), 182
gen() (sage.rings.fraction_field.FractionField_generic method), 503
gen() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse method), 554
gen() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 520
gen() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular method), 369
gen() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 262
gen() (sage.rings.polynomial.pbori.BooleanMonomialMonoid method), 595
gen() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 617
gen() (sage.rings.polynomial.plural.NCPolynomialRing_plural method), 642
gen() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 229
gen() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 22
gen() (sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general method), 493
GenDictWithBasering (class in sage.rings.polynomial.infinite_polynomial_ring), 550
generic_pd (class in sage.rings.polynomial.polynomial_compiled), 239
generic_power_trunc() (in module sage.rings.polynomial.polynomial_element), 108
gens() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 313
gens() (sage.rings.polynomial.pbori.BooleanMonomialMonoid method), 595
gens() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 617
674 Index
Sage Reference Manual: Polynomials, Release 8.6
H
h_covariant() (sage.rings.invariants.invariant_theory.BinaryQuartic method), 414
Index 675
Sage Reference Manual: Polynomials, Release 8.6
I
i_covariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 421
id() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 618
ideal() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 521
ideal() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular method), 369
ideal() (sage.rings.polynomial.multi_polynomial_ring.MPolynomialRing_polydict_domain method), 293
ideal() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method), 358
ideal() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 618
ideal() (sage.rings.polynomial.plural.NCPolynomialRing_plural method), 642
Ideal_1poly_field (class in sage.rings.polynomial.ideal), 215
if_then_else() (in module sage.rings.polynomial.pbori), 632
implications() (sage.rings.polynomial.pbori.GroebnerStrategy method), 626
include_divisors() (sage.rings.polynomial.pbori.BooleSet method), 587
increase_precision() (sage.rings.polynomial.real_roots.ocean method), 203
index() (sage.rings.polynomial.pbori.BooleanMonomial method), 592
InfiniteGenDict (class in sage.rings.polynomial.infinite_polynomial_ring), 551
InfinitePolynomial() (in module sage.rings.polynomial.infinite_polynomial_element), 558
InfinitePolynomial_dense (class in sage.rings.polynomial.infinite_polynomial_element), 559
InfinitePolynomial_sparse (class in sage.rings.polynomial.infinite_polynomial_element), 559
InfinitePolynomialGen (class in sage.rings.polynomial.infinite_polynomial_ring), 551
InfinitePolynomialRing_dense (class in sage.rings.polynomial.infinite_polynomial_ring), 552
676 Index
Sage Reference Manual: Polynomials, Release 8.6
Index 677
Sage Reference Manual: Polynomials, Release 8.6
678 Index
Sage Reference Manual: Polynomials, Release 8.6
Index 679
Sage Reference Manual: Polynomials, Release 8.6
680 Index
Sage Reference Manual: Polynomials, Release 8.6
J
j_covariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 422
J_covariant() (sage.rings.invariants.invariant_theory.TernaryCubic method), 435
J_covariant() (sage.rings.invariants.invariant_theory.TwoQuaternaryQuadratics method), 441
J_covariant() (sage.rings.invariants.invariant_theory.TwoTernaryQuadratics method), 444
jacobian_ideal() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 278
K
karatsuba_threshold() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 23
kbase_libsingular() (in module sage.rings.polynomial.multi_polynomial_ideal_libsingular), 393
krull_dimension() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse method), 555
krull_dimension() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 522
krull_dimension() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 263
krull_dimension() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 230
krull_dimension() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 24
L
lagrange_polynomial() (sage.rings.polynomial.polynomial_ring.PolynomialRing_field method), 18
lagrange_polynomial() (sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general method), 495
latex() (sage.rings.polynomial.polydict.PolyDict method), 400
LaurentPolynomial (class in sage.rings.polynomial.laurent_polynomial), 524
LaurentPolynomial_mpair (class in sage.rings.polynomial.laurent_polynomial), 525
LaurentPolynomial_univariate (class in sage.rings.polynomial.laurent_polynomial), 533
LaurentPolynomialRing() (in module sage.rings.polynomial.laurent_polynomial_ring), 517
LaurentPolynomialRing_generic (class in sage.rings.polynomial.laurent_polynomial_ring), 519
LaurentPolynomialRing_mpair (class in sage.rings.polynomial.laurent_polynomial_ring), 523
LaurentPolynomialRing_univariate (class in sage.rings.polynomial.laurent_polynomial_ring), 524
LC() (in module sage.rings.polynomial.toy_d_basis), 457
lc() (sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse method), 561
lc() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 301
lc() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 382
Index 681
Sage Reference Manual: Polynomials, Release 8.6
682 Index
Sage Reference Manual: Polynomials, Release 8.6
M
macaulay2_str() (sage.rings.polynomial.term_order.TermOrder method), 254
macaulay_resultant() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 278
macaulay_resultant() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 263
MacMahonOmega() (in module sage.rings.polynomial.omega), 541
magma_str() (sage.rings.polynomial.term_order.TermOrder method), 254
main() (sage.rings.polynomial.pbori.FGLMStrategy method), 623
make_element() (in module sage.rings.fraction_field_element), 509
make_element() (in module sage.rings.polynomial.polynomial_gf2x), 123
make_element() (in module sage.rings.polynomial.polynomial_modn_dense_ntl), 164
make_element() (in module sage.rings.polynomial.polynomial_zmod_flint), 157
make_element() (in module sage.rings.polynomial.polynomial_zz_pex), 184
make_element_old() (in module sage.rings.fraction_field_element), 509
make_ETuple() (in module sage.rings.polynomial.polydict), 404
make_generic_polynomial() (in module sage.rings.polynomial.polynomial_element), 109
make_padic_poly() (in module sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense), 180
make_PolyDict() (in module sage.rings.polynomial.polydict), 404
make_PolynomialRealDense() (in module sage.rings.polynomial.polynomial_real_mpfr_dense), 169
map_coefficients() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 280
map_coefficients() (sage.rings.polynomial.polynomial_element.Polynomial method), 70
map_every_x_to_x_plus_one() (in module sage.rings.polynomial.pbori), 635
map_every_x_to_x_plus_one() (sage.rings.polynomial.pbori.BooleanPolynomial method), 604
matrix() (sage.rings.invariants.invariant_theory.QuadraticForm method), 432
Index 683
Sage Reference Manual: Polynomials, Release 8.6
684 Index
Sage Reference Manual: Polynomials, Release 8.6
Index 685
Sage Reference Manual: Polynomials, Release 8.6
N
n_forms() (sage.rings.invariants.invariant_theory.SeveralAlgebraicForms method), 434
n_nodes() (sage.rings.polynomial.pbori.BooleanPolynomial method), 605
n_nodes() (sage.rings.polynomial.pbori.BooleSet method), 588
n_variables() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 619
n_vars() (sage.rings.polynomial.pbori.BooleanPolynomial method), 606
name() (sage.rings.polynomial.term_order.TermOrder method), 255
navigation() (sage.rings.polynomial.pbori.BooleanMonomial method), 593
navigation() (sage.rings.polynomial.pbori.BooleanPolynomial method), 606
navigation() (sage.rings.polynomial.pbori.BooleSet method), 588
NCPolynomial_plural (class in sage.rings.polynomial.plural), 646
NCPolynomialIdeal (class in sage.rings.polynomial.multi_polynomial_ideal), 346
NCPolynomialRing_plural (class in sage.rings.polynomial.plural), 641
new_CRing() (in module sage.rings.polynomial.plural), 654
new_NRing() (in module sage.rings.polynomial.plural), 655
new_Ring() (in module sage.rings.polynomial.plural), 656
newton_polygon() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 175
newton_polygon() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdv method), 111
newton_polytope() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 281
newton_raphson() (sage.rings.polynomial.polynomial_element.Polynomial method), 73
newton_slopes() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 176
newton_slopes() (sage.rings.polynomial.polynomial_element.Polynomial method), 74
newton_slopes() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_cdv method), 111
next() (sage.rings.fraction_field_FpT.FpT_iter method), 514
next() (sage.rings.fraction_field_FpT.FpTElement method), 510
next() (sage.rings.polynomial.infinite_polynomial_ring.GenDictWithBasering method), 550
next() (sage.rings.polynomial.pbori.BooleanMonomialIterator method), 594
next() (sage.rings.polynomial.pbori.BooleanMonomialVariableIterator method), 596
next() (sage.rings.polynomial.pbori.BooleanPolynomialIterator method), 614
next() (sage.rings.polynomial.pbori.BooleanPolynomialVectorIterator method), 622
next() (sage.rings.polynomial.pbori.BooleSetIterator method), 591
next() (sage.rings.polynomial.polydict.ETupleIter method), 398
next_spoly() (sage.rings.polynomial.pbori.GroebnerStrategy method), 626
nf() (sage.rings.polynomial.pbori.GroebnerStrategy method), 626
nf() (sage.rings.polynomial.pbori.ReductionStrategy method), 630
nf3() (in module sage.rings.polynomial.pbori), 635
ngens() (sage.rings.fraction_field.FractionField_generic method), 503
ngens() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse method), 555
ngens() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 522
ngens() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular method), 372
ngens() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 266
ngens() (sage.rings.polynomial.pbori.BooleanMonomialMonoid method), 596
ngens() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 620
ngens() (sage.rings.polynomial.plural.NCPolynomialRing_plural method), 646
686 Index
Sage Reference Manual: Polynomials, Release 8.6
O
ocean (class in sage.rings.polynomial.real_roots), 202
Omega_ge() (in module sage.rings.polynomial.omega), 544
one() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse method), 555
one() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 620
operator_eval() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 477
ord() (sage.rings.polynomial.polynomial_element.Polynomial method), 79
Index 687
Sage Reference Manual: Polynomials, Release 8.6
P
p (sage.rings.polynomial.pbori.BooleanPolynomialEntry attribute), 611
padded_list() (sage.rings.polynomial.polynomial_element.Polynomial method), 79
padded_list() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial method), 477
parallel_reduce() (in module sage.rings.polynomial.pbori), 635
parameter() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 25
parameter() (sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general method), 496
part() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method), 360
partition() (in module sage.rings.polynomial.omega), 546
parts() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method), 360
Phi_invariant() (sage.rings.invariants.invariant_theory.TwoQuaternaryQuadratics method), 441
plot() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 320
plot() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr method), 337
plot() (sage.rings.polynomial.polynomial_element.Polynomial method), 79
polar_conic() (sage.rings.invariants.invariant_theory.TernaryCubic method), 437
poly_repr() (sage.rings.polynomial.polydict.PolyDict method), 401
PolyDict (class in sage.rings.polynomial.polydict), 398
polygen() (in module sage.rings.polynomial.polynomial_ring), 28
polygens() (in module sage.rings.polynomial.polynomial_ring), 29
Polynomial (class in sage.rings.polynomial.polynomial_element), 31
polynomial() (sage.rings.invariants.invariant_theory.AlgebraicForm method), 412
polynomial() (sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse method), 562
polynomial() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 282
polynomial() (sage.rings.polynomial.polynomial_element.Polynomial method), 80
Polynomial_absolute_number_field_dense (class in sage.rings.polynomial.polynomial_number_field), 124
polynomial_coefficient() (sage.rings.polynomial.polydict.PolyDict method), 402
polynomial_construction() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 539
polynomial_default_category() (in module sage.rings.polynomial.polynomial_ring_constructor), 7
Polynomial_dense_mod_n (class in sage.rings.polynomial.polynomial_modn_dense_ntl), 157
Polynomial_dense_mod_p (class in sage.rings.polynomial.polynomial_modn_dense_ntl), 159
Polynomial_dense_modn_ntl_ZZ (class in sage.rings.polynomial.polynomial_modn_dense_ntl), 160
Polynomial_dense_modn_ntl_zz (class in sage.rings.polynomial.polynomial_modn_dense_ntl), 162
Polynomial_generic_cdv (class in sage.rings.polynomial.polynomial_element_generic), 110
Polynomial_generic_cdvf (class in sage.rings.polynomial.polynomial_element_generic), 112
Polynomial_generic_cdvr (class in sage.rings.polynomial.polynomial_element_generic), 112
Polynomial_generic_dense (class in sage.rings.polynomial.polynomial_element), 105
Polynomial_generic_dense_cdv (class in sage.rings.polynomial.polynomial_element_generic), 113
Polynomial_generic_dense_cdvf (class in sage.rings.polynomial.polynomial_element_generic), 113
Polynomial_generic_dense_cdvr (class in sage.rings.polynomial.polynomial_element_generic), 113
Polynomial_generic_dense_field (class in sage.rings.polynomial.polynomial_element_generic), 113
Polynomial_generic_dense_inexact (class in sage.rings.polynomial.polynomial_element), 107
Polynomial_generic_domain (class in sage.rings.polynomial.polynomial_element_generic), 113
Polynomial_generic_field (class in sage.rings.polynomial.polynomial_element_generic), 113
Polynomial_generic_sparse (class in sage.rings.polynomial.polynomial_element_generic), 114
Polynomial_generic_sparse_cdv (class in sage.rings.polynomial.polynomial_element_generic), 118
Polynomial_generic_sparse_cdvf (class in sage.rings.polynomial.polynomial_element_generic), 118
Polynomial_generic_sparse_cdvr (class in sage.rings.polynomial.polynomial_element_generic), 118
688 Index
Sage Reference Manual: Polynomials, Release 8.6
Index 689
Sage Reference Manual: Polynomials, Release 8.6
Q
quadratic_form() (sage.rings.invariants.invariant_theory.InvariantTheoryFactory method), 427
QuadraticForm (class in sage.rings.invariants.invariant_theory), 431
quaternary_biquadratic() (sage.rings.invariants.invariant_theory.InvariantTheoryFactory method), 428
quaternary_quadratic() (sage.rings.invariants.invariant_theory.InvariantTheoryFactory method), 428
quo_rem() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair method), 531
quo_rem() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 539
quo_rem() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 304
quo_rem() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 387
quo_rem() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 177
quo_rem() (sage.rings.polynomial.polynomial_element.Polynomial_generic_dense method), 106
quo_rem() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_field method), 113
quo_rem() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse method), 116
quo_rem() (sage.rings.polynomial.polynomial_gf2x.Polynomial_template method), 122
quo_rem() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint method), 131
quo_rem() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method), 137
quo_rem() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_mod_n method), 158
quo_rem() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ method), 161
quo_rem() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 163
quo_rem() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 147
quo_rem() (sage.rings.polynomial.polynomial_real_mpfr_dense.PolynomialRealDense method), 167
quo_rem() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template method), 152
quo_rem() (sage.rings.polynomial.polynomial_zz_pex.Polynomial_template method), 183
690 Index
Sage Reference Manual: Polynomials, Release 8.6
R
R_invariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 417
radical() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal_singular_repr method), 340
radical() (sage.rings.polynomial.polynomial_element.Polynomial method), 81
random_element() (sage.rings.fraction_field.FractionField_generic method), 504
random_element() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 522
random_element() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 320
random_element() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 266
random_element() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 620
random_element() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 232
random_element() (sage.rings.polynomial.polynomial_ring.PolynomialRing_general method), 26
random_element() (sage.rings.polynomial.skew_polynomial_ring.SkewPolynomialRing_general method), 497
random_set() (in module sage.rings.polynomial.pbori), 635
rational_reconstruct() (sage.rings.polynomial.polynomial_element.Polynomial method), 82
rational_reconstruct() (sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint method), 154
rational_root_bounds() (in module sage.rings.polynomial.real_roots), 204
real_root_intervals() (sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint
method), 131
real_root_intervals() (sage.rings.polynomial.polynomial_integer_dense_ntl.Polynomial_integer_dense_ntl method),
137
real_root_intervals() (sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint method), 148
real_roots() (in module sage.rings.polynomial.real_roots), 205
real_roots() (sage.rings.polynomial.polynomial_element.Polynomial method), 85
reciprocal_transform() (sage.rings.polynomial.polynomial_element.Polynomial method), 85
recursively_insert() (in module sage.rings.polynomial.pbori), 635
red_tail() (in module sage.rings.polynomial.pbori), 635
reduce() (sage.rings.fraction_field_element.FractionFieldElement method), 507
reduce() (sage.rings.fraction_field_element.FractionFieldElement_1poly_field method), 508
reduce() (sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse method), 562
reduce() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 304
reduce() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 322
reduce() (sage.rings.polynomial.multi_polynomial_ideal.NCPolynomialIdeal method), 347
reduce() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method), 387
reduce() (sage.rings.polynomial.pbori.BooleanPolynomial method), 607
reduce() (sage.rings.polynomial.pbori.BooleanPolynomialIdeal method), 613
reduce() (sage.rings.polynomial.plural.NCPolynomial_plural method), 653
reduce() (sage.rings.polynomial.symmetric_ideal.SymmetricIdeal method), 572
reduce() (sage.rings.polynomial.symmetric_reduction.SymmetricReductionStrategy method), 577
reduced() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method), 360
reduced() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_gf2 method), 363
reduced_form() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 283
reduced_normal_form() (sage.rings.polynomial.pbori.ReductionStrategy method), 630
reducible_by() (sage.rings.polynomial.pbori.BooleanMonomial method), 593
reducible_by() (sage.rings.polynomial.pbori.BooleanPolynomial method), 607
reduction_strategy (sage.rings.polynomial.pbori.GroebnerStrategy attribute), 627
ReductionStrategy (class in sage.rings.polynomial.pbori), 628
refine() (sage.rings.polynomial.real_roots.island method), 199
Index 691
Sage Reference Manual: Polynomials, Release 8.6
692 Index
Sage Reference Manual: Polynomials, Release 8.6
S
S_class_group() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 223
S_invariant() (sage.rings.invariants.invariant_theory.TernaryCubic method), 435
S_units() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 224
sage.rings.fraction_field (module), 499
sage.rings.fraction_field_element (module), 505
sage.rings.fraction_field_FpT (module), 509
sage.rings.invariants.invariant_theory (module), 408
sage.rings.monomials (module), 408
sage.rings.polynomial.complex_roots (module), 212
sage.rings.polynomial.convolution (module), 239
sage.rings.polynomial.cyclotomic (module), 240
sage.rings.polynomial.flatten (module), 405
sage.rings.polynomial.hilbert (module), 404
sage.rings.polynomial.ideal (module), 215
sage.rings.polynomial.infinite_polynomial_element (module), 557
sage.rings.polynomial.infinite_polynomial_ring (module), 547
sage.rings.polynomial.laurent_polynomial (module), 524
sage.rings.polynomial.laurent_polynomial_ring (module), 517
sage.rings.polynomial.multi_polynomial (module), 269
sage.rings.polynomial.multi_polynomial_element (module), 293
sage.rings.polynomial.multi_polynomial_ideal (module), 307
sage.rings.polynomial.multi_polynomial_ideal_libsingular (module), 392
sage.rings.polynomial.multi_polynomial_libsingular (module), 366
Index 693
Sage Reference Manual: Polynomials, Release 8.6
694 Index
Sage Reference Manual: Polynomials, Release 8.6
Index 695
Sage Reference Manual: Polynomials, Release 8.6
696 Index
Sage Reference Manual: Polynomials, Release 8.6
T
T_covariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 417
T_covariant() (sage.rings.invariants.invariant_theory.TwoQuaternaryQuadratics method), 441
T_invariant() (sage.rings.invariants.invariant_theory.TernaryCubic method), 435
T_prime_covariant() (sage.rings.invariants.invariant_theory.TwoQuaternaryQuadratics method), 442
tail() (sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse method), 565
tailreduce() (sage.rings.polynomial.symmetric_reduction.SymmetricReductionStrategy method), 579
tau_covariant() (sage.rings.invariants.invariant_theory.BinaryQuintic method), 423
taylor_shift1_intvec() (in module sage.rings.polynomial.real_roots), 210
tensor_with_ring() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_dense method), 552
tensor_with_ring() (sage.rings.polynomial.infinite_polynomial_ring.InfinitePolynomialRing_sparse method), 556
term_lmult() (sage.rings.polynomial.polydict.PolyDict method), 403
term_order() (sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic method), 522
term_order() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 268
term_order() (sage.rings.polynomial.plural.NCPolynomialRing_plural method), 646
term_rmult() (sage.rings.polynomial.polydict.PolyDict method), 403
terminal_one() (sage.rings.polynomial.pbori.CCuddNavigator method), 623
TermOrder (class in sage.rings.polynomial.term_order), 248
TermOrder_from_pb_order() (in module sage.rings.polynomial.pbori), 630
termorder_from_singular() (in module sage.rings.polynomial.term_order), 260
terms() (sage.rings.polynomial.pbori.BooleanPolynomial method), 609
Index 697
Sage Reference Manual: Polynomials, Release 8.6
698 Index
Sage Reference Manual: Polynomials, Release 8.6
U
unary_pd (class in sage.rings.polynomial.polynomial_compiled), 239
UnflatteningMorphism (class in sage.rings.polynomial.flatten), 407
union() (sage.rings.polynomial.pbori.BooleSet method), 590
units() (sage.rings.polynomial.polynomial_quotient_ring.PolynomialQuotientRing_generic method), 233
univar_pd (class in sage.rings.polynomial.polynomial_compiled), 239
univariate_polynomial() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair method), 532
univariate_polynomial() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 306
univariate_polynomial() (sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular method),
391
univariate_polynomial() (sage.rings.polynomial.pbori.BooleanPolynomial method), 609
univariate_ring() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 268
universal_discriminant() (in module sage.rings.polynomial.polynomial_element), 109
universe() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_generic method), 361
unpickle_BooleanPolynomial() (in module sage.rings.polynomial.pbori), 637
unpickle_BooleanPolynomial0() (in module sage.rings.polynomial.pbori), 637
unpickle_BooleanPolynomialRing() (in module sage.rings.polynomial.pbori), 637
unpickle_FpT_element() (in module sage.rings.fraction_field_FpT), 516
unpickle_MPolynomial_libsingular() (in module sage.rings.polynomial.multi_polynomial_libsingular), 392
unpickle_MPolynomialRing_generic() (in module sage.rings.polynomial.multi_polynomial_ring_base), 269
unpickle_MPolynomialRing_generic_v1() (in module sage.rings.polynomial.multi_polynomial_ring_base), 269
unpickle_MPolynomialRing_libsingular() (in module sage.rings.polynomial.multi_polynomial_libsingular), 392
unpickle_NCPolynomial_plural() (in module sage.rings.polynomial.plural), 656
unpickle_PolynomialRing() (in module sage.rings.polynomial.polynomial_ring_constructor), 7
unweighted_degree() (sage.rings.polynomial.polydict.ETuple method), 398
update() (in module sage.rings.polynomial.toy_buchberger), 452
update() (in module sage.rings.polynomial.toy_d_basis), 459
usign() (sage.rings.polynomial.real_roots.bernstein_polynomial_factory method), 185
V
valuation() (sage.rings.fraction_field_element.FractionFieldElement method), 507
valuation() (sage.rings.fraction_field_FpT.FpTElement method), 512
valuation() (sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate method), 540
valuation() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 178
valuation() (sage.rings.polynomial.polydict.PolyDict method), 404
valuation() (sage.rings.polynomial.polynomial_element.Polynomial method), 102
valuation() (sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_sparse method), 118
valuation() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ method), 161
valuation() (sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_zz method), 164
valuation() (sage.rings.polynomial.skew_polynomial_element.SkewPolynomial_generic_dense method), 488
valuation_of_coefficient() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_
method), 179
value() (sage.rings.polynomial.pbori.CCuddNavigator method), 623
var_pd (class in sage.rings.polynomial.polynomial_compiled), 239
variable() (sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict method), 306
Index 699
Sage Reference Manual: Polynomials, Release 8.6
W
warp_map (class in sage.rings.polynomial.real_roots), 211
weighted_degree() (sage.rings.polynomial.multi_polynomial.MPolynomial method), 288
weights() (sage.rings.polynomial.term_order.TermOrder method), 260
weil_restriction() (sage.rings.polynomial.multi_polynomial_ideal.MPolynomialIdeal method), 323
weil_restriction() (sage.rings.polynomial.multi_polynomial_sequence.PolynomialSequence_gf2e method), 365
weyl_algebra() (sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base method), 269
weyl_algebra() (sage.rings.polynomial.polynomial_ring.PolynomialRing_commutative method), 12
wordsize_rational() (in module sage.rings.polynomial.real_roots), 211
X
xgcd() (sage.rings.polynomial.padics.polynomial_padic_capped_relative_dense.Polynomial_padic_capped_relative_dense
method), 179
xgcd() (sage.rings.polynomial.polynomial_element.Polynomial method), 103
xgcd() (sage.rings.polynomial.polynomial_gf2x.Polynomial_template method), 123
700 Index
Sage Reference Manual: Polynomials, Release 8.6
Z
zero() (sage.rings.polynomial.pbori.BooleanPolynomialRing method), 622
zeros() (in module sage.rings.polynomial.pbori), 637
zeros_in() (sage.rings.polynomial.pbori.BooleanPolynomial method), 611
ZZ_FpT_coerce (class in sage.rings.fraction_field_FpT), 515
Index 701