# Creating Multivariate Rings

In this section, for the convenience of the reader, we recall from the chapters on rings and fields how to create multivariate polynomial rings and their elements, adding illustrating examples. At the same time, we introduce and illustrate a ring type for modelling multivariate polynomial rings with gradings.

## Types

OSCAR provides types for dense univariate and sparse multivariate polynomials. The univariate ring types belong to the abstract type `PolyRing{T}`

, their elements have abstract type `PolyRingElem{T}`

. The multivariate ring types belong to the abstract type `MPolyRing{T}`

, their elements have abstract type `MPolyRingElem{T}`

. Here, `T`

is the element type of the coefficient ring of the polynomial ring.

## Constructors

The basic constructor below allows one to build multivariate polynomial rings:

`polynomial_ring(C::Ring, V::Vector{String}; cached::Bool = true)`

Its return value is a tuple, say `R, vars`

, consisting of a polynomial ring `R`

with coefficient ring `C`

and a vector `vars`

of generators (variables) which print according to the strings in the vector `V`

.

Caching is used to ensure that a given ring constructed from given parameters is unique in the system. For example, there is only one ring of multivariate polynomials over $\mathbb{Z}$ with variables printing as x, y, z.

###### Examples

```
julia> R, (x, y, z) = polynomial_ring(ZZ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over ZZ, ZZMPolyRingElem[x, y, z])
julia> typeof(R)
ZZMPolyRing
julia> typeof(x)
ZZMPolyRingElem
julia> S, (a, b, c) = polynomial_ring(ZZ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over ZZ, ZZMPolyRingElem[x, y, z])
julia> T, _ = polynomial_ring(ZZ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over ZZ, ZZMPolyRingElem[x, y, z])
julia> R === S === T
true
```

```
julia> R1, x = polynomial_ring(QQ, ["x"])
(Multivariate polynomial ring in 1 variable over QQ, QQMPolyRingElem[x])
julia> typeof(x)
Vector{QQMPolyRingElem} (alias for Array{QQMPolyRingElem, 1})
julia> R2, (x,) = polynomial_ring(QQ, ["x"])
(Multivariate polynomial ring in 1 variable over QQ, QQMPolyRingElem[x])
julia> typeof(x)
QQMPolyRingElem
julia> R3, x = polynomial_ring(QQ, "x")
(Univariate polynomial ring in x over QQ, x)
julia> typeof(x)
QQPolyRingElem
```

```
julia> T, x = polynomial_ring(GF(3), ["x[1]", "x[2]"]);
julia> x
2-element Vector{FqMPolyRingElem}:
x[1]
x[2]
```

The constructor illustrated below allows for the convenient handling of variables with multi-indices:

```
julia> R, x, y, z = polynomial_ring(QQ, "x" => (1:3, 1:4), "y" => 1:2, "z" => (1:1, 1:1, 1:1));
julia> x
3×4 Matrix{QQMPolyRingElem}:
x[1, 1] x[1, 2] x[1, 3] x[1, 4]
x[2, 1] x[2, 2] x[2, 3] x[2, 4]
x[3, 1] x[3, 2] x[3, 3] x[3, 4]
julia> y
2-element Vector{QQMPolyRingElem}:
y[1]
y[2]
julia> z
1×1×1 Array{QQMPolyRingElem, 3}:
[:, :, 1] =
z[1, 1, 1]
```

## Coefficient Rings

Gröbner and standard bases are implemented for multivariate polynomial rings over the fields and rings below:

### The field of rational numbers $\mathbb{Q}$

```
julia> QQ
Rational field
```

### Finite fields $\mathbb{F_p}$, $p$ a prime

```
julia> GF(3)
Prime field of characteristic 3
julia> GF(ZZ(2)^127 - 1)
Prime field of characteristic 170141183460469231731687303715884105727
```

### Finite fields $\mathbb{F}_{p^n}$ with $p^n$ elements, $p$ a prime

```
julia> finite_field(2, 70, "a")
(Finite field of degree 70 and characteristic 2, a)
```

### Simple algebraic extensions of $\mathbb{Q}$ or $\mathbb{F}_p$

```
julia> T, t = polynomial_ring(QQ, "t")
(Univariate polynomial ring in t over QQ, t)
julia> K, a = number_field(t^2 + 1, "a")
(Number field of degree 2 over QQ, a)
julia> F = GF(3)
Prime field of characteristic 3
julia> T, t = polynomial_ring(F, "t")
(Univariate polynomial ring in t over GF(3), t)
julia> K, a = finite_field(t^2 + 1, "a")
(Finite field of degree 2 and characteristic 3, a)
```

### Purely transcendental extensions of $\mathbb{Q}$ or $\mathbb{F}_p$

```
julia> T, t = polynomial_ring(QQ, "t")
(Univariate polynomial ring in t over QQ, t)
julia> QT = fraction_field(T)
Fraction field
of univariate polynomial ring in t over QQ
julia> parent(t)
Univariate polynomial ring in t over QQ
julia> parent(1//t)
Fraction field
of univariate polynomial ring in t over QQ
julia> T, (s, t) = polynomial_ring(GF(3), ["s", "t"]);
julia> QT = fraction_field(T)
Fraction field
of multivariate polynomial ring in 2 variables over GF(3)
```

### The ring of integers $\mathbb{Z}$

```
julia> ZZ
Integer ring
```

## Gradings

Given a polynomial ring $R = C[x_1, \dots, x_n]$, we may endow $R$ with various gradings. The *standard $\mathbb Z$-grading* on $R$ is the decomposition $R=\bigoplus_{d\in \mathbb Z} R_d=\bigoplus_{d\geq 0} R_d$ by the usual degree of polynomials. More general $\mathbb Z$-gradings are obtained by assigning integer weights to the variables and considering the corresponding weighted degrees. Even more generally, we may consider multigradings: Given a finitely generated abelian group $G$, a *multigrading* on $R$ by $G$, or a *$G$-grading*, or simply a *grading*, corresponds to a semigroup homomorphism $\phi: \mathbb N^n \to G$: Given $\phi$, the *degree* of a monomial $x^\alpha$ is the image $\deg(x^\alpha):=\phi(\alpha)\in G$; the induced $G$-grading on $R$ is the decomposition $R = \bigoplus_{g\in G} R_g$ satisfying $R_g\cdot R_h\subset R_{g+h}$, where $R_g$ is the free $C$-module generated by the monomials of degree $g$. This grading is determined by assigning the *weights* $\deg(x_i)$ to the $x_i$. In other words, it is determined by the *weight vector* $W = (\deg(x_1), \dots, \deg(x_n))\in G^n.$

We refer to the textbooks [MS05] and [KR05] for details on multigradings. With respect to notation, we follow the former book.

Given a $G$-grading on $R$, we refer to $G$ as the *grading group* of $R$. Moreover, we then say that $R$ is *$G$-graded*, or simply that $R$ is *graded*. If $R$ is a polynomial ring over a field, we say that a $G$-grading on $R$ is *positive* if $G$ is free and each graded part $R_g$, $g\in G$, has finite dimension. We then also say that $R$ is *positively graded (by $G$)*. Note that the positivity condition can be equivalently expressed by asking that $G$ is free and that the degree zero part consists of the constants only (see Theorem 8.6 in [MS05]).

Given a `G`

-grading on `R`

in OSCAR, we say that `R`

is *$\mathbb Z^m$-graded* if `is_free(G) && number_of_generators(G) == rank(G) == m`

evaluates to `true`

. In this case, conversion routines allow one to switch back and forth between elements of `G`

and integer vectors of length `m`

. Specifically, if `R`

is *$\mathbb Z$-graded*, that is, `is_free(G) && number_of_generators(G) == rank(G) == 1`

evaluates to `true`

, elements of `G`

may be converted to integers and vice versa.

### Types

Multivariate rings with gradings are modeled by objects of type `MPolyDecRing{T, S} :< MPolyRing{T}`

, with elements of type `MPolyRingElem_dec{T, S} :< MPolyRingElem{T}`

. Here, `S`

is the element type of the multivariate ring, and `T`

is the element type of its coefficient ring as above.

The types `MPolyDecRing{T, S}`

and `MPolyRingElem_dec{T, S}`

are also meant to eventually model multivariate rings with filtrations and their elements.

The following function allows one, in particular, to distinguish between graded and filtered rings.

`is_graded`

— Method`is_graded(R::MPolyRing)`

Return `true`

if `R`

is graded, `false`

otherwise.

### Constructors for Graded Rings

There are two basic ways of creating multivariate rings with gradings: While the `grade`

function allows one to create a graded ring by assigning a grading to a polynomial ring already constructed, the `graded_polynomial_ring`

function is meant to create a graded polynomial ring all at once.

`grade`

— Method`grade(R::MPolyRing, W::Vector{FinGenAbGroupElem})`

Given a vector `W`

of `ngens(R)`

elements of a finitely presented group `G`

, say, create a `G`

-graded ring by assigning the entries of `W`

as weights to the variables of `R`

. Return the new ring as an object of type `MPolyDecRing`

, together with the vector of variables.

**Examples**

```
julia> R, (t, x, y) = polynomial_ring(QQ, ["t", "x", "y"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[t, x, y])
julia> typeof(R)
QQMPolyRing
julia> typeof(x)
QQMPolyRingElem
julia> G = abelian_group([0])
Z
julia> g = gen(G, 1)
Abelian group element [1]
julia> S, (t, x, y) = grade(R, [-g, g, g])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[t, x, y])
julia> typeof(S)
MPolyDecRing{QQFieldElem, QQMPolyRing}
julia> S isa MPolyRing
true
julia> typeof(x)
MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}
julia> R, x, y = polynomial_ring(QQ, "x" => 1:2, "y" => 1:3)
(Multivariate polynomial ring in 5 variables over QQ, QQMPolyRingElem[x[1], x[2]], QQMPolyRingElem[y[1], y[2], y[3]])
julia> G = abelian_group([0, 0])
Z^2
julia> g = gens(G)
2-element Vector{FinGenAbGroupElem}:
[1, 0]
[0, 1]
julia> W = [g[1], g[1], g[2], g[2], g[2]];
julia> S, _ = grade(R, W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], y[1], y[2], y[3]])
julia> typeof(x[1])
QQMPolyRingElem
julia> x = map(S, x)
2-element Vector{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}:
x[1]
x[2]
julia> y = map(S, y)
3-element Vector{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}:
y[1]
y[2]
y[3]
julia> typeof(x[1])
MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}
julia> R, x = polynomial_ring(QQ, "x" => 1:5)
(Multivariate polynomial ring in 5 variables over QQ, QQMPolyRingElem[x[1], x[2], x[3], x[4], x[5]])
julia> G = abelian_group([0, 0, 2, 2])
Finitely generated abelian group
with 4 generators and 4 relations and relation matrix
[0 0 0 0]
[0 0 0 0]
[0 0 2 0]
[0 0 0 2]
julia> g = gens(G);
julia> W = [g[1]+g[3]+g[4], g[2]+g[4], g[1]+g[3], g[2], g[1]+g[2]]
5-element Vector{FinGenAbGroupElem}:
[1, 0, 1, 1]
[0, 1, 0, 1]
[1, 0, 1, 0]
[0, 1, 0, 0]
[1, 1, 0, 0]
julia> S, x = grade(R, W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4], x[5]])
```

`grade`

— Method`grade(R::MPolyRing, W::AbstractVector{<:AbstractVector{<:IntegerUnion}})`

Given a vector `W`

of `ngens(R)`

integer vectors of the same size `m`

, say, create a free abelian group of type `FinGenAbGroup`

given by `m`

free generators, and convert the vectors in `W`

to elements of that group. Then create a $\mathbb Z^m$-graded ring by assigning the group elements as weights to the variables of `R`

, and return the new ring, together with the vector of variables.

`grade(R::MPolyRing, W::Union{ZZMatrix, AbstractMatrix{<:IntegerUnion}})`

As above, converting the columns of `W`

.

**Examples**

```
julia> R, x, y = polynomial_ring(QQ, "x" => 1:2, "y" => 1:3)
(Multivariate polynomial ring in 5 variables over QQ, QQMPolyRingElem[x[1], x[2]], QQMPolyRingElem[y[1], y[2], y[3]])
julia> W = [1 1 0 0 0; 0 0 1 1 1]
2×5 Matrix{Int64}:
1 1 0 0 0
0 0 1 1 1
julia> grade(R, W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], y[1], y[2], y[3]])
```

`grade`

— Method`grade(R::MPolyRing, W::AbstractVector{<:IntegerUnion})`

Given a vector `W`

of `ngens(R)`

integers, create a free abelian group of type `FinGenAbGroup`

given by one free generator, and convert the entries of `W`

to elements of that group. Then create a $\mathbb Z$-graded ring by assigning the group elements as weights to the variables of `R`

, and return the new ring, together with the vector of variables.

`grade(R::MPolyRing)`

As above, where the grading is the standard $\mathbb Z$-grading on `R`

.

**Examples**

```
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> W = [1, 2, 3];
julia> S, (x, y, z) = grade(R, W)
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> T, (x, y, z) = grade(R)
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
```

`graded_polynomial_ring`

— Method`graded_polynomial_ring(C::Ring, args...; weights, kwargs...)`

Create a multivariate `polynomial_ring`

with coefficient ring `C`

and variables as described by `args...`

(using the exact same syntax as `polynomial_ring`

), and `grade`

this ring according to the data provided by the keyword argument `weights`

. Return the graded ring as an object of type `MPolyDecRing`

, together with the variables.

If `weights`

is omitted the grading is the standard $\mathbb Z$-grading, i.e. all variables are graded with weight `1`

.

**Examples**

```
julia> W = [[1, 0], [0, 1], [1, 0], [4, 1]]
4-element Vector{Vector{Int64}}:
[1, 0]
[0, 1]
[1, 0]
[4, 1]
julia> R, x = graded_polynomial_ring(QQ, 4, :x; weights = W)
(Graded multivariate polynomial ring in 4 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x1, x2, x3, x4])
julia> S, (x, y, z) = graded_polynomial_ring(QQ, [:x, :y, :z]; weights = [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> T, x = graded_polynomial_ring(QQ, :x => 1:3)
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3]])
julia> T, x, y = graded_polynomial_ring(QQ, :x => 1:3, :y => (1:2, 1:2); weights=1:7)
(Graded multivariate polynomial ring in 7 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3]], MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[y[1, 1] y[1, 2]; y[2, 1] y[2, 2]])
```

## Tests on Graded Rings

`is_standard_graded`

— Method`is_standard_graded(R::MPolyDecRing)`

Return `true`

if `R`

is standard $\mathbb Z$-graded, `false`

otherwise.

**Examples**

```
julia> S, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]; weights = [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> is_standard_graded(S)
false
```

`is_z_graded`

— Method`is_z_graded(R::MPolyDecRing)`

Return `true`

if `R`

is $\mathbb Z$-graded, `false`

otherwise.

Writing `G = grading_group(R)`

, we say that `R`

is $\mathbb Z$-graded if `G`

is free abelian of rank `1`

, and `ngens(G) == 1`

.

**Examples**

```
julia> S, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]; weights = [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> is_z_graded(S)
true
```

`is_zm_graded`

— Method`is_zm_graded(R::MPolyDecRing)`

Return `true`

if `R`

is $\mathbb Z^m$-graded for some $m$, `false`

otherwise.

Writing `G = grading_group(R)`

, we say that `R`

is $\mathbb Z^m$-graded `G`

is free abelian of rank `m`

, and `ngens(G) == m`

.

**Examples**

```
julia> G = abelian_group([0, 0, 2, 2])
Finitely generated abelian group
with 4 generators and 4 relations and relation matrix
[0 0 0 0]
[0 0 0 0]
[0 0 2 0]
[0 0 0 2]
julia> W = [G[1]+G[3]+G[4], G[2]+G[4], G[1]+G[3], G[2], G[1]+G[2]];
julia> S, x = graded_polynomial_ring(QQ, "x" => 1:5; weights=W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4], x[5]])
julia> is_zm_graded(S)
false
julia> G = abelian_group(ZZMatrix([1 -1]));
julia> g = gen(G, 1)
Abelian group element [0, 1]
julia> W = [g, g, g, g];
julia> R, (w, x, y, z) = graded_polynomial_ring(QQ, ["w", "x", "y", "z"], W);
julia> is_free(G)
true
julia> is_zm_graded(R)
false
```

`is_positively_graded`

— Method`is_positively_graded(R::MPolyDecRing)`

Return `true`

if `R`

is positively graded, `false`

otherwise.

We say that `R`

is *positively graded* by a finitely generated abelian group $G$ if the coefficient ring of `R`

is a field, $G$ is free, and each graded part $R_g$, $g\in G$, has finite dimension.

**Examples**

```
julia> S, (t, x, y) = graded_polynomial_ring(QQ, ["t", "x", "y"]; weights = [-1, 1, 1])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[t, x, y])
julia> is_positively_graded(S)
false
julia> G = abelian_group([0, 2])
Finitely generated abelian group
with 2 generators and 2 relations and relation matrix
[0 0]
[0 2]
julia> W = [gen(G, 1)+gen(G, 2), gen(G, 1)]
2-element Vector{FinGenAbGroupElem}:
[1, 1]
[1, 0]
julia> S, (x, y) = graded_polynomial_ring(QQ, ["x", "y"]; weights = W)
(Graded multivariate polynomial ring in 2 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y])
julia> is_positively_graded(S)
false
```

## Data Associated to Multivariate Rings

Given a multivariate polynomial ring `R`

with coefficient ring `C`

,

`coefficient_ring(R)`

refers to`C`

,`gens(R)`

to the generators (variables) of`R`

,`number_of_generators(R)`

/`ngens(R)`

to the number of these generators, and`gen(R, i)`

as well as`R[i]`

to the`i`

-th such generator.

###### Examples

```
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> coefficient_ring(R)
Rational field
julia> gens(R)
3-element Vector{QQMPolyRingElem}:
x
y
z
julia> gen(R, 2)
y
julia> R[3]
z
julia> number_of_generators(R)
3
```

In the graded case, we additionally have:

`grading_group`

— Method`grading_group(R::MPolyDecRing)`

If `R`

is, say, `G`

-graded, then return `G`

.

**Examples**

```
julia> R, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"], [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> grading_group(R)
Z
```

`monomial_basis`

— Method`monomial_basis(R::MPolyDecRing, g::FinGenAbGroupElem)`

Given a polynomial ring `R`

over a field which is graded by a free group of type `FinGenAbGroup`

, and given an element `g`

of that group, return the monomials of degree `g`

in `R`

.

`monomial_basis(R::MPolyDecRing, W::Vector{<:IntegerUnion})`

Given a $\mathbb Z^m$-graded polynomial ring `R`

over a field and a vector `W`

of $m$ integers, convert `W`

into an element `g`

of the grading group of `R`

and proceed as above.

`monomial_basis(R::MPolyDecRing, d::IntegerUnion)`

Given a $\mathbb Z$-graded polynomial ring `R`

over a field and an integer `d`

, convert `d`

into an element `g`

of the grading group of `R`

and proceed as above.

If the component of the given degree is not finite dimensional, an error message will be thrown.

**Examples**

```
julia> T, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]);
julia> G = grading_group(T)
Z
julia> L = monomial_basis(T, 2)
6-element Vector{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}:
z^2
y*z
y^2
x*z
x*y
x^2
```

`homogeneous_component`

— Method`homogeneous_component(R::MPolyDecRing, g::FinGenAbGroupElem)`

Given a polynomial ring `R`

over a field which is graded by a free group of type `FinGenAbGroup`

, and given an element `g`

of that group, return the homogeneous component of `R`

of degree `g`

as a standard vector space. Additionally, return the map which sends an element of that vector space to the corresponding monomial in `R`

.

`homogeneous_component(R::MPolyDecRing, W::Vector{<:IntegerUnion})`

Given a $\mathbb Z^m$-graded polynomial ring `R`

over a field, and given a vector `W`

of $m$ integers, convert `W`

into an element `g`

of the grading group of `R`

and proceed as above.

`homogeneous_component(R::MPolyDecRing, d::IntegerUnion)`

Given a $\mathbb Z$-graded polynomial ring `R`

over a field, and given an integer `d`

, convert `d`

into an element `g`

of the grading group of `R`

proceed as above.

If the component is not finite dimensional, an error message will be thrown.

**Examples**

```
julia> W = [1 1 0 0 0; 0 0 1 1 1]
2×5 Matrix{Int64}:
1 1 0 0 0
0 0 1 1 1
julia> S, _ = graded_polynomial_ring(QQ, "x" => 1:2, "y" => 1:3; weights = W);
julia> G = grading_group(S)
Z^2
julia> L = homogeneous_component(S, [1, 1]);
julia> L[1]
S_[1 1] of dim 6
julia> FG = gens(L[1]);
julia> EMB = L[2]
Map defined by a julia-function with inverse
from S_[1 1] of dim 6
to graded multivariate polynomial ring in 5 variables over QQ
julia> for i in 1:length(FG) println(EMB(FG[i])) end
x[2]*y[3]
x[2]*y[2]
x[2]*y[1]
x[1]*y[3]
x[1]*y[2]
x[1]*y[1]
```

`forget_grading`

— Method`forget_grading(R::MPolyDecRing)`

Return the ungraded undecorated ring.

## Elements of Multivariate Rings

### Constructors

One way to create elements of a multivariate polynomial ring is to build up polynomials from the generators (variables) of the ring using basic arithmetic as shown below:

###### Examples

```
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> f = 3*x^2+y*z
3*x^2 + y*z
julia> typeof(f)
QQMPolyRingElem
julia> S, (x, y, z) = grade(R)
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> g = 3*x^2+y*z
3*x^2 + y*z
julia> typeof(g)
MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}
julia> g == S(f)
true
```

Alternatively, there is the following constructor:

`(R::MPolyRing{T})(c::Vector{T}, e::Vector{Vector{Int}}) where T <: RingElem`

Its return value is the element of `R`

whose nonzero coefficients are specified by the elements of `c`

, with exponent vectors given by the elements of `e`

.

###### Examples

```
julia> R, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"])
(Multivariate polynomial ring in 3 variables over QQ, QQMPolyRingElem[x, y, z])
julia> f = 3*x^2+y*z
3*x^2 + y*z
julia> g = R(QQ.([3, 1]), [[2, 0, 0], [0, 1, 1]])
3*x^2 + y*z
julia> f == g
true
```

An often more effective way to create polynomials is to use the `MPoly`

build context as indicated below:

```
julia> R, (x, y) = polynomial_ring(QQ, ["x", "y"])
(Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])
julia> B = MPolyBuildCtx(R)
Builder for an element of Multivariate polynomial ring in 2 variables over QQ
julia> for i = 1:5 push_term!(B, QQ(i), [i, i-1]) end
julia> finish(B)
5*x^5*y^4 + 4*x^4*y^3 + 3*x^3*y^2 + 2*x^2*y + x
```

### Special Elements

Given a multivariate polynomial ring `R`

, `zero(R)`

and `one(R)`

refer to the additive and multiplicative identity of `R`

, respectively. Relevant test calls on an element `f`

of `R`

are `iszero(f)`

and `isone(f)`

.

### Data Associated to Elements of Multivariate Rings

Given an element `f`

of a multivariate polynomial ring `R`

or a graded version of such a ring,

`parent(f)`

refers to`R`

, and`total_degree(f)`

to the total degree of`f`

.

Given a set of variables $x = \{x_1, \ldots, x_n\}$, the *total degree* of a monomial $x^\alpha=x_1^{\alpha_1}\cdots x_n^{\alpha_n}\in\text{Mon}_n(x)$ is the sum of the $\alpha_i$. The *total degree* of a polynomial `f`

is the maximum of the total degrees of its monomials. In particular, the notion of total degree ignores the weights given to the variables in the graded case.

For iterators which allow one to recover the monomials (terms, $\dots$) of `f`

we refer to the subsection Monomials, Terms, and More of the section on Gröbner/Standard Bases.

###### Examples

```
julia> R, (x, y) = polynomial_ring(GF(5), ["x", "y"])
(Multivariate polynomial ring in 2 variables over GF(5), FqMPolyRingElem[x, y])
julia> c = map(GF(5), [1, 2, 3])
3-element Vector{FqFieldElem}:
1
2
3
julia> e = [[3, 2], [1, 0], [0, 1]]
3-element Vector{Vector{Int64}}:
[3, 2]
[1, 0]
[0, 1]
julia> f = R(c, e)
x^3*y^2 + 2*x + 3*y
julia> parent(f)
Multivariate polynomial ring in 2 variables x, y
over prime field of characteristic 5
julia> total_degree(f)
5
```

Further functionality is available in the graded case:

`homogeneous_components`

— Method`homogeneous_components(f::MPolyDecRingElem{T, S}) where {T, S}`

Given an element `f`

of a graded multivariate ring, return the homogeneous components of `f`

.

**Examples**

```
julia> R, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"], [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> f = x^2+y+z
x^2 + y + z
julia> homogeneous_components(f)
Dict{FinGenAbGroupElem, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}} with 2 entries:
[2] => x^2 + y
[3] => z
julia> G = abelian_group([0, 0, 2, 2])
Finitely generated abelian group
with 4 generators and 4 relations and relation matrix
[0 0 0 0]
[0 0 0 0]
[0 0 2 0]
[0 0 0 2]
julia> W = [G[1]+G[3]+G[4], G[2]+G[4], G[1]+G[3], G[2], G[1]+G[2]];
julia> S, x = graded_polynomial_ring(QQ, "x" => 1:5; weights=W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4], x[5]])
julia> f = x[1]^2+x[3]^2+x[5]^2
x[1]^2 + x[3]^2 + x[5]^2
julia> homogeneous_components(f)
Dict{FinGenAbGroupElem, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}} with 2 entries:
[2, 2, 0, 0] => x[5]^2
[2, 0, 0, 0] => x[1]^2 + x[3]^2
```

`homogeneous_component`

— Method`homogeneous_component(f::MPolyDecRingElem, g::FinGenAbGroupElem)`

Given an element `f`

of a graded multivariate ring, and given an element `g`

of the grading group of that ring, return the homogeneous component of `f`

of degree `g`

.

`homogeneous_component(f::MPolyDecRingElem, g::Vector{<:IntegerUnion})`

Given an element `f`

of a $\mathbb Z^m$-graded multivariate ring `R`

, say, and given a vector `g`

of $m$ integers, convert `g`

into an element of the grading group of `R`

, and return the homogeneous component of `f`

whose degree is that element.

`homogeneous_component(f::MPolyDecRingElem, g::IntegerUnion)`

Given an element `f`

of a $\mathbb Z$-graded multivariate ring `R`

, say, and given an integer `g`

, convert `g`

into an element of the grading group of `R`

, and return the homogeneous component of `f`

whose degree is that element.

**Examples**

```
julia> G = abelian_group([0, 0, 2, 2])
Finitely generated abelian group
with 4 generators and 4 relations and relation matrix
[0 0 0 0]
[0 0 0 0]
[0 0 2 0]
[0 0 0 2]
julia> W = [G[1]+G[3]+G[4], G[2]+G[4], G[1]+G[3], G[2], G[1]+G[2]];
julia> S, x = graded_polynomial_ring(QQ, "x" => 1:5; weights=W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4], x[5]])
julia> f = x[1]^2+x[3]^2+x[5]^2
x[1]^2 + x[3]^2 + x[5]^2
julia> homogeneous_component(f, 2*G[1])
x[1]^2 + x[3]^2
julia> W = [[1, 0], [0, 1], [1, 0], [4, 1]]
4-element Vector{Vector{Int64}}:
[1, 0]
[0, 1]
[1, 0]
[4, 1]
julia> R, x = graded_polynomial_ring(QQ, :x => 1:4; weights=W)
(Graded multivariate polynomial ring in 4 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4]])
julia> f = x[1]^2*x[2]+x[4]
x[1]^2*x[2] + x[4]
julia> homogeneous_component(f, [2, 1])
x[1]^2*x[2]
julia> R, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"]; weights=[1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> f = x^2+y+z
x^2 + y + z
julia> homogeneous_component(f, 1)
0
julia> homogeneous_component(f, 2)
x^2 + y
julia> homogeneous_component(f, 3)
z
```

`is_homogeneous`

— Method`is_homogeneous(f::MPolyDecRingElem)`

Given an element `f`

of a graded multivariate ring, return `true`

if `f`

is homogeneous, `false`

otherwise.

**Examples**

```
julia> R, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"], [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> f = x^2+y*z
x^2 + y*z
julia> is_homogeneous(f)
false
julia> W = [1 2 1 0; 3 4 0 1]
2×4 Matrix{Int64}:
1 2 1 0
3 4 0 1
julia> S, (w, x, y, z) = graded_polynomial_ring(QQ, ["w", "x", "y", "z"], W)
(Graded multivariate polynomial ring in 4 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[w, x, y, z])
julia> F = w^3*y^3*z^3 + w^2*x*y^2*z^2 + w*x^2*y*z + x^3
w^3*y^3*z^3 + w^2*x*y^2*z^2 + w*x^2*y*z + x^3
julia> is_homogeneous(F)
true
```

`degree`

— Method`degree(f::MPolyDecRingElem)`

Given a homogeneous element `f`

of a graded multivariate ring, return the degree of `f`

.

`degree(::Type{Vector{Int}}, f::MPolyDecRingElem)`

Given a homogeneous element `f`

of a $\mathbb Z^m$-graded multivariate ring, return the degree of `f`

, converted to a vector of integer numbers.

`degree(::Type{Int}, f::MPolyDecRingElem)`

Given a homogeneous element `f`

of a $\mathbb Z$-graded multivariate ring, return the degree of `f`

, converted to an integer number.

**Examples**

```
julia> G = abelian_group([0, 0, 2, 2])
Finitely generated abelian group
with 4 generators and 4 relations and relation matrix
[0 0 0 0]
[0 0 0 0]
[0 0 2 0]
[0 0 0 2]
julia> W = [G[1]+G[3]+G[4], G[2]+G[4], G[1]+G[3], G[2], G[1]+G[2]];
julia> S, x = graded_polynomial_ring(QQ, "x" => 1:5; weights=W)
(Graded multivariate polynomial ring in 5 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4], x[5]])
julia> f = x[2]^2+2*x[4]^2
x[2]^2 + 2*x[4]^2
julia> degree(f)
Abelian group element [0, 2, 0, 0]
julia> W = [[1, 0], [0, 1], [1, 0], [4, 1]]
4-element Vector{Vector{Int64}}:
[1, 0]
[0, 1]
[1, 0]
[4, 1]
julia> R, x = graded_polynomial_ring(QQ, ["x[1]", "x[2]", "x[3]", "x[4]"], W)
(Graded multivariate polynomial ring in 4 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x[1], x[2], x[3], x[4]])
julia> f = x[1]^4*x[2]+x[4]
x[1]^4*x[2] + x[4]
julia> degree(f)
[4 1]
julia> degree(Vector{Int}, f)
2-element Vector{Int64}:
4
1
julia> R, (x, y, z) = graded_polynomial_ring(QQ, ["x", "y", "z"], [1, 2, 3])
(Graded multivariate polynomial ring in 3 variables over QQ, MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}[x, y, z])
julia> f = x^6+y^3+z^2
x^6 + y^3 + z^2
julia> degree(f)
[6]
julia> typeof(degree(f))
FinGenAbGroupElem
julia> degree(Int, f)
6
julia> typeof(degree(Int, f))
Int64
```

`forget_grading`

— Method`forget_grading(f::MPolyDecRingElem)`

Return the element in the underlying ungraded ring.

## Homomorphisms From Multivariate Rings

If $R$ is a multivariate polynomial ring, and $S$ is any ring, then a ring homomorphism $R \to S$ is determined by specifying its restriction to the coefficient ring of $R$, and by assigning an image to each variable of $R$. In OSCAR, such homomorphisms are created by using the following constructor:

`hom`

— Method```
hom(R::MPolyRing, S::NCRing, coeff_map, images::Vector; check::Bool = true)
hom(R::MPolyRing, S::NCRing, images::Vector; check::Bool = true)
```

Given a homomorphism `coeff_map`

from `C`

to `S`

, where `C`

is the coefficient ring of `R`

, and given a vector `images`

of `nvars(R)`

elements of `S`

, return the homomorphism `R`

$\to$ `S`

whose restriction to `C`

is `coeff_map`

, and which sends the `i`

-th variable of `R`

to the `i`

-th entry of `images`

.

If no coefficient map is entered, invoke a canonical homomorphism of `C`

to `S`

, if such a homomorphism exists, and throw an error, otherwise.

In case `check = true`

(default), the function checks the conditions below:

- If
`S`

is graded, the assigned images must be homogeneous with respect to the given grading. - If
`S`

is noncommutative, the assigned images must pairwise commute.

**Examples**

```
julia> K, a = finite_field(2, 2, "a");
julia> R, (x, y) = polynomial_ring(K, ["x", "y"]);
julia> F = hom(R, R, z -> z^2, [y, x])
Ring homomorphism
from multivariate polynomial ring in 2 variables over GF(2, 2)
to multivariate polynomial ring in 2 variables over GF(2, 2)
defined by
x -> y
y -> x
with map on coefficients
#1
julia> F(a * y)
(a + 1)*x
julia> Qi, i = quadratic_field(-1)
(Imaginary quadratic field defined by x^2 + 1, sqrt(-1))
julia> S, (x, y) = polynomial_ring(Qi, ["x", "y"]);
julia> G = hom(S, S, hom(Qi, Qi, -i), [x^2, y^2])
Ring homomorphism
from multivariate polynomial ring in 2 variables over Qi
to multivariate polynomial ring in 2 variables over Qi
defined by
x -> x^2
y -> y^2
with map on coefficients
Map: Qi -> Qi
julia> G(x+i*y)
x^2 - sqrt(-1)*y^2
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]);
julia> f = 3*x^2+2*x+1;
julia> S, (x, y) = polynomial_ring(GF(2), ["x", "y"]);
julia> H = hom(R, S, gens(S))
Ring homomorphism
from multivariate polynomial ring in 2 variables over ZZ
to multivariate polynomial ring in 2 variables over GF(2)
defined by
x -> x
y -> y
julia> H(f)
x^2 + 1
```

Given a ring homomorphism `F`

from `R`

to `S`

as above, `domain(F)`

and `codomain(F)`

refer to `R`

and `S`

, respectively.

The OSCAR homomorphism type `AffAlgHom`

models ring homomorphisms `R`

$\to$ `S`

such that the type of both `R`

and `S`

is a subtype of `Union{MPolyRing{T}, MPolyQuoRing{U}}`

, where `T <: FieldElem`

and `U <: MPolyRingElem{T}`

. Functionality for these homomorphism is discussed in the section on affine algebras.