There are two different ways to create polynomial rings, corresponding
to the different internal representations (vector versus distributive
--- see the introductory section): PolynomialRing(S) and PolynomialRing(S, n). The latter should be used to create multivariate
polynomials; the former is recommended for univariate polynomials.
PolynomialAlgebra(P) : Rng -> RngUPol
Create a univariate polynomial ring over the ring S. The ring is regarded as an S-algebra via the usual identification of elements of S 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 indeterminates: P<x> := PolynomialRing(R).
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 a_0, ..., a_d coercible into the coefficient ring R, return the polynomial a_0 + a_1x_n + ... + a_dx_n^d 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 cannot be coerced into their coefficient rings, but the function Coefficient can be used for that.
- s is an element of P: it is returned unchanged;
- s is an element of a ring that can be coerced into the coefficient ring R of P: the constant polynomial s is returned;
- 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;
- 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.
> 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 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