# Polynomial Rings and Polynomials

## Creation of Polynomial Rings

Multivariate polynomial rings are created from a coefficient ring, the number of indeterminates, and a monomial order. If no order is specified, the monomial order is taken to be the lexicographical order (see Section [Representation and Monomial Orders](../../CommutativeAlgebra/GrobnerBases/order.md#dpoly-monomial-orders) for details).

### `PolynomialRing(R, n): Rng, RngIntElt -> RngMPol`

### `PolynomialAlgebra(R, n): Rng, RngIntElt -> RngMPol`

```magma
Global: BoolElt                    Default: false
```

Create a multivariate polynomial ring in $n>0$ indeterminates 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 lexicographical ordering on the monomials is used for this default construction (see Section [Representation and Monomial Orders](../../CommutativeAlgebra/GrobnerBases/order.md#dpoly-monomial-orders)). The angle bracket notation can be used to assign names to the indeterminates; e.g.: `P<x, y> := PolynomialRing(R, 2);` etc. By default, a *non-global* polynomial ring will be returned; if the parameter `Global` is set to `true`, then the unique global polynomial ring over $R$ with $n$ variables will be returned. This may be useful in some contexts, but a non-global result is returned by default since one often wishes to have several rings with the same numbers of variables but with different variable names (and create mappings between them, for example). Explicit coercion is always allowed between polynomial rings having the same number of variables (and suitable base rings), whether they are global or not, and the coercion maps the $i$-variable of one ring to the $i$-th variable of the other ring.

### `PolynomialRing(R, n, order): Rng, RngIntElt, MonStgElt, ... -> RngMPol`

### `PolynomialAlgebra(R, n, order): Rng, RngIntElt, MonStgElt, ... -> RngMPol`

Create a multivariate polynomial ring in $n>0$ indeterminates over the ring $R$ with the given order order on the monomials. See Section [Representation and Monomial Orders](../../CommutativeAlgebra/GrobnerBases/order.md#dpoly-monomial-orders) for details.

### `Example: Assign Names (ex-1b3506)`

We show the use of angle brackets for generator names.

```magma
> Z := IntegerRing();
> S := PolynomialRing(Z, 2);

```

If we define $S$ this way, we can only refer to the indeterminates by $S.1$ and $S.2$ (see below). So we could assign these generators to variables, say $x$ and $y$, as follows:

```magma
> x := S.1;
> y := S.2;

```

In this case it is easy to construct polynomials, but printing is slightly awkward:

```magma
> f := x^3*y +3*y^2;
> f;
$.1^3*$.2 + 3*$.2^2

```

To overcome that, it is possible to assign names to the indeterminates that are used in the printing routines, using the `AssignNames` function, before assigning to $x$ and $y$.

```magma
> AssignNames(~S, ["x", "y"]);
> x := S.1; y := S.2;
> f := x^3*y +3*y^2;
> f;
x^3*y + 3*y^2

```

Alternatively, we use the angle brackets to assign generator names that will be used in printing as well:

```magma
> S<x, y> := PolynomialRing(Z, 2);
> f := x^3*y +3*y^2;
> f;
x^3*y + 3*y^2

```

### `Example: Global (ex-a068bd)`

We demonstrate the difference between global and non-global rings. We first create the global multivariate polynomial ring over ${\mathbb{Q}}$ with 3 variables twice.

```magma
> Q := RationalField();
> P<x,y,z> := PolynomialRing(Q, 3: Global);
> PP := PolynomialRing(Q, 3: Global);
> P;
Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z
> PP;
Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z
> PP.1;
x

```

$PP$ is identical to $P$. We now create default (non-global) multivariate polynomial rings (which are also different to the global polynomial ring $P$). Explicit coercion is allowed, and maps the $i$-variable of one ring to the $i$-th variable of the other ring.

```magma
> P1<a,b,c> := PolynomialRing(Q, 3);
> P2<d,e,f> := PolynomialRing(Q, 3);
> P1;
Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: a, b, c
> P2;
Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: d, e, f
> a;
a
> d;
d
> P1 ! d;
a
> P ! e;
y

```

## Print Names

The `AssignNames` and `Name` functions can be used to associate names with the indeterminates of polynomial rings after creation.

### `AssignNames(~P, s): RngMPol, [ MonStgElt ])`

Procedure to change the name of the indeterminates of a polynomial ring $P$. The $i$-th indeterminate will be given the name of the $i$-th element of the sequence of strings $s$ (for $1\leq i\leq \#s$); the sequence may have length less than the number of indeterminates of $P$, in which case the remaining indeterminate names remain unchanged. 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 polynomial ring. 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): RngMPol, RngIntElt -> RngMPolElt`

Given a polynomial ring $P$, return the $i$-th indeterminate of $P$ (as an element of $P$).

## Graded Polynomial Rings

It is possible within Magma to assign weights to the variables of a multivariate polynomial ring. This means that monomials of the ring then have a *weighted degree* with respect to the weights of the variables. Such a multivariate polynomial ring is called *graded* or *weighted*. Since this subject is intimately related to ideals, it is covered in the chapter on ideals and Gröbner bases (see Subsection [Creation of Graded Polynomial Rings](../../CommutativeAlgebra/GrobnerBases/creation.md#gb-graded)).

## Creation of Polynomials

The easiest way to create polynomials in a given ring is to use the angle bracket construction to attach variables to the indeterminates, and then to use these variables to create polynomials (see the examples). Below we list other options.

### `P . i: RngMPol, RngInt -> RngMPolElt`

Return the $i$-th indeterminate for the polynomial ring $P$ in $n$ variables ($1\leq i\leq n$) as an element of $P$.

### `elt< R | a >: RngMPol, RngElt -> RngMPolElt`

### `R ! s: RngMPol, RngElt -> RngMPolElt`

### `R ! s: RngMPol, [ RngElt ] -> RngMPolElt`

### `elt< R | s >: RngMPol, [ RngElt ] -> RngMPolElt`

This element constructor can only be used for trivial purposes in multivariate polynomial rings: given a polynomial ring $P=R[x_1, \ldots, x_{n}]$ and an element $a$ that can be coerced into the coefficient ring $R$, the constant polynomial $a$ is returned; if $a$ is in $P$ already it will be returned unchanged.

### `MultivariatePolynomial(P, f, i): RngMPol, RngUPolElt, RngIntElt -> RngMPolElt`

### `MultivariatePolynomial(P, f, v): RngMPol, RngUPolElt, RngMPolElt -> RngMPolElt`

Given a multivariate polynomial ring $P=R[x_1, \ldots, x_n]$, as well as a polynomial $f$ in a univariate polynomial ring $R[x]$ over the same coefficient ring $R$, return an element $q$ of $P$ corresponding to $f$ in the indeterminate $v=x_i$; that is, $q\in P$ is defined by $q=\sum_j f_jx_i^j$ where $f=\sum_j f_jx^j$. The indeterminate $x_i$ can either be specified as a polynomial $v=x_i$ in $P$, or by simply providing the integer $i$ with $1\leq i\leq n$. The inverse operation is performed by the `UnivariatePolynomial` function.

### `One(P): RngMPol -> RngMPolElt`

### `Identity(P): RngMPol -> RngMPolElt`

### `Zero(P): RngMPol -> RngMPolElt`

### `Representative(P): RngMPol -> RngMPolElt`
