There are two different ways to create polynomial rings, corresponding to the different internal representations (vector versus distributive --- see the introductory section): PolynomialRing(R) and PolynomialRing(R, n). The latter should be used to create multivariate polynomials; the former should be used for univariate polynomials.
Global: BoolElt Default: true
Create a univariate polynomial ring over the ring R. The ring is regarded as an R-algebra via the usual identification of elements of R and the constant polynomials. The polynomials are stored in vector form, which allows fast arithmetic. It is not recommended to use this function recursively to build multivariate polynomial rings. The angle bracket notation can be used to assign names to the indeterminate, e.g.: P<x> := PolynomialRing(R).By default, the unique global univariate polynomial ring over R will be returned; if the parameter Global is set to false, then a non-global univariate polynomial ring over R will be returned (to which a separate name for the indeterminate can be assigned).
> Q := RationalField(); > P<x> := PolynomialRing(Q); > PP := PolynomialRing(Q); > P; Univariate Polynomial Ring in x over Rational Field > PP; Univariate Polynomial Ring in x over Rational Field > PP.1; xPP is identical to P. We now create non-global univariate polynomial rings (which are also different to the global polynomial ring P). Note that elements of all the rings are mathematically equal by automatic coercion.
> Pa<a> := PolynomialRing(Q: Global := false); > Pb<b> := PolynomialRing(Q: Global := false); > Pa; Univariate Polynomial Ring in a over Rational Field > Pb; Univariate Polynomial Ring in b over Rational Field > a; a > b; b > P; Univariate Polynomial Ring in x over Rational Field > x; x > x eq a; // Automatic coercion true > x + a; 2*x
The AssignNames and Name functions can be used to associate a name with the indeterminate of a polynomial ring after creation.
Procedure to change the name of the indeterminate of a polynomial ring P. The indeterminate will be given the name of the string in the sequence s.This procedure only changes the name used in printing the elements of P. It does not assign to identifiers corresponding to the strings the indeterminates in P; to do this, use an assignment statement, or use angle brackets when creating the field.
Note that since this is a procedure that modifies P, it is necessary to have a reference ~P to P in the call to this function.
Given a polynomial ring P, return the i-th indeterminate of P (as an element of P).
The easiest way to create polynomials in a given ring is to use the angle bracket construction to attach names to the indeterminates, and to use these names to express polynomials (see the examples). Below we list other options.
Return the indeterminate for the polynomial ring P, as an element of P.
Given a polynomial ring P=R[x] and elements a0, ..., ad coercible into the coefficient ring R, return the polynomial a0 + a1xn + ... + adxnd as an element of P.
Coerce the element s into the polynomial ring P = R[x]. The following possibilities for s exist.Note that constant polynomials may be coerced into their coefficient rings.
- (a)
- s is an element of P: it is returned unchanged;
- (b)
- s is an element of a ring that can be coerced into the coefficient ring R of P: the constant polynomial s is returned;
- (c)
- s=∑j sjyj is an element of a univariate polynomial ring whose coefficient ring elements sj can be coerced into R: the polynomial ∑j rjxj is returned, where rj is the result of coercing sj into R;
- (c)
- s is a sequence: if s is empty then the zero element of P is returned, and if it is non-empty but the elements of the sequence can be coerced into R then the polynomial ∑j s[j]xnj - 1 is returned.
Given a sequence Q of elements from a ring R, create the polynomial over R whose coefficients are given by Q. This is equivalent to PolynomialRing(Universe(Q))!Q.
Given a ring R and sequence Q of elements from a ring S, create the polynomial over R whose coefficients are given by the elements of Q, coerced into S. This is equivalent to PolynomialRing(R)!ChangeUniverse(Q, R).
Given a ring R and a polynomial f over a ring S, create the polynomial over R obtained from f by coercing its coefficients into S. This is equivalent to PolynomialRing(R)!f.
> P<x> := PolynomialRing(Integers()); > f := x^3+3*x+1; > f; x^3 + 3*x + 1Alternative ways to create polynomials are given by the element constructor (rarely used) and the ! operator:
> P<x> := PolynomialAlgebra(Integers()); > f := elt< P | 2, 3, 0, 1 >; > f; x^3 + 3*x + 2 > P ! [ 2, 3, 0, 1 ]; x^3 + 3*x + 2Note that it is important to realize that a sequence is coerced into a polynomial ring by coercing its entries into the coefficient ring, and it is not attempted first to coerce the sequence as a whole into the coefficient ring:
> Q := RationalField(); > Q ! [1, 2]; 1/2 > P<x> := PolynomialRing(Q); > P ! [1,2]; 2*x + 1 > P ! Q ! [1,2]; 1/2 > P ! [ [1,2], [2,3] ]; 2/3*x + 1/2