Creation Functions

Contents

Creation of Structures

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.

PolynomialAlgebra(R) : Rng -> RngUPol
PolynomialRing(R) : Rng -> RngUPol
    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).

Example RngPol_Creation (H24E1)

We demonstrate the difference between global and non-global rings. We first create the global univariate polynomial ring over {Q} twice.
> 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;
x
PP 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

Print Options

The AssignNames and Name functions can be used to associate a name with the indeterminate of a polynomial ring after creation.

AssignNames(~P, s) : RngUPol, [ MonStgElt ]) ->
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.

Name(P, i) : RngUPol, RngIntElt -> RngUPolElt
Given a polynomial ring P, return the i-th indeterminate of P (as an element of P).

Creation of Elements

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.

One(P) : RngUPol -> RngUPolElt
Identity(P) : RngUPol -> RngUPolElt
Zero(P) : RngUPol -> RngUPolElt
Representative(P) : RngUPol -> RngUPolElt
P . 1 : RngUPol, RngInt -> RngPolElt
Return the indeterminate for the polynomial ring P, as an element of P.
elt< P | a0, ..., ad > : RngUPol, RngElt, ..., RngElt -> RngUPolElt
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.
P ! s : RngUPol, RngElt -> RngPolElt
P ! s : RngUPol, [ RngElt ] -> RngPolElt
elt< P | s > : RngUPol, [ RngElt ] -> RngUPolElt
Coerce the element s into the polynomial ring P = R[x]. The following possibilities for s exist.
(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.

Note that constant polynomials may be coerced into their coefficient rings.

Polynomial(Q) : [ RngElt ] -> RngUPolElt
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.
Polynomial(R, Q) : Rng, [ RngElt] -> RngUPolElt
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).
Polynomial(R, f) : Rng, RngUPolElt -> RngUPolElt
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.

Example RngPol_Polynomials (H24E2)

The easiest way to create the polynomial x3 + 3x + 1 (over the integers) is as follows.
> P<x> := PolynomialRing(Integers());
> f := x^3+3*x+1;
> f;
x^3 + 3*x + 1
Alternative 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 + 2
Note 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
V2.28, 13 July 2023