Creation Functions#

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: Creation (ex-2d4846)#

We demonstrate the difference between global and non-global rings. We first create the global univariate polynomial ring over \({\mathbb{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

Run in calculator

\(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

Run in calculator

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.

P . 1: RngUPol, RngInt -> RngPolElt#

Return the indeterminate for the polynomial ring \(P\), as an element of \(P\).

elt< P | a₀, ..., a_d >: RngUPol, RngElt, ..., RngElt -> RngUPolElt#

Given a polynomial ring \(P=R[x]\) and elements \(a_0, \ldots, a_d\) coercible into the coefficient ring \(R\), return the polynomial \(a_0+a_1x_n+\cdots+a_dx_n^d\) 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=\sum_j s_jy^j\) is an element of a univariate polynomial ring whose coefficient ring elements \(s_j\) can be coerced into \(R\): the polynomial \(\sum_j r_jx^j\) is returned, where \(r_j\) is the result of coercing \(s_j\) 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 \(\sum_j s[j]x_n^{j-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.

One(P): RngUPol -> RngUPolElt#
Identity(P): RngUPol -> RngUPolElt#
Zero(P): RngUPol -> RngUPolElt#
Representative(P): RngUPol -> RngUPolElt#
Example: Polynomials (ex-365cfe)#

The easiest way to create the polynomial \(x^3+3x+1\) (over the integers) is as follows.

> P<x> := PolynomialRing(Integers());
> f := x^3+3*x+1;
> f;
x^3 + 3*x + 1

Run in calculator

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

Run in calculator

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

Run in calculator