# Number field arithmetic

Number fields are provided in Nemo by Antic. This allows construction of absolute number fields and basic arithmetic computations therein.

Number fields are constructed using the `AnticNumberField`

function. However, for convenience we define

`number_field = AnticNumberField`

so that number fields can be constructed using `number_field`

rather than `AnticNumberField`

.

The types of number field elements in Nemo are given in the following table, along with the libraries that provide them and the associated types of the parent objects.

Library | Field | Element type | Parent type |
---|---|---|---|

Antic | $\mathbb{Q}[x]/(f)$ | `nf_elem` | `AnticNumberField` |

All the number field types belong to the `Field`

abstract type and the number field element types belong to the `FieldElem`

abstract type.

The Hecke.jl library radically expands on number field functionality, providing ideals, orders, class groups, relative extensions, class field theory, etc.

The basic number field element type used in Hecke is the Nemo/antic number field element type, making the two libraries tightly integrated.

https://thofma.github.io/Hecke.jl/stable/

## Number field functionality

The number fields in Nemo provide all of the AbstractAlgebra field functionality:

https://nemocas.github.io/AbstractAlgebra.jl/stable/field

Below, we document the additional functionality provided for number field elements.

### Constructors

In order to construct number field elements in Nemo, one must first construct the number field itself. This is accomplished with one of the following constructors.

`Nemo.number_field`

— Method```
number_field(f::QQPolyRingElem, s::VarName;
cached::Bool = true, check::Bool = true)
```

Return a tuple $R, x$ consisting of the parent object $R$ and generator $x$ of the number field $\mathbb{Q}[x]/(f)$ where $f$ is the supplied polynomial. The supplied string `s`

specifies how the generator of the number field should be printed. If `s`

is not specified, it defaults to `_a`

.

`Nemo.cyclotomic_field`

— Method`cyclotomic_field(n::Int, s::VarName = "z_$n", t = "_\$"; cached = true)`

Return a tuple $R, x$ consisting of the parent object $R$ and generator $x$ of the $n$-th cyclotomic field, $\mathbb{Q}(\zeta_n)$. The supplied string `s`

specifies how the generator of the number field should be printed. If provided, the string `t`

specifies how the generator of the polynomial ring from which the number field is constructed, should be printed. If it is not supplied, a default dollar sign will be used to represent the variable.

`Nemo.cyclotomic_real_subfield`

— Method`cyclotomic_real_subfield(n::Int, s::VarName = "(z_$n + 1/z_$n)", t = "\$"; cached = true)`

Return a tuple $R, x$ consisting of the parent object $R$ and generator $x$ of the totally real subfield of the $n$-th cyclotomic field, $\mathbb{Q}(\zeta_n)$. The supplied string `s`

specifies how the generator of the number field should be printed. If provided, the string `t`

specifies how the generator of the polynomial ring from which the number field is constructed, should be printed. If it is not supplied, a default dollar sign will be used to represent the variable.

Here are some examples of creating number fields and making use of the resulting parent objects to coerce various elements into those fields.

**Examples**

```
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")
L, b = cyclotomic_field(5, "b")
M, c = CyclotomicRealField(5, "c")
d = K(3)
f = L(b)
g = L(ZZ(11))
h = L(ZZ(11)//3)
k = M(x)
```

### Number field element constructors

`AbstractAlgebra.gen`

— Method`gen(a::AnticNumberField)`

Return the generator of the given number field, i.e., a symbolic root of the defining polynomial.

The easiest way of constructing number field elements is to use element arithmetic with the generator, to construct the desired element by its representation as a polynomial. See the following examples for how to do this.

**Examples**

```
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")
d = gen(K)
f = a^2 + 2a - 7
```

### Basic functionality

`AbstractAlgebra.mul_red!`

— Method`mul_red!(z::nf_elem, x::nf_elem, y::nf_elem, red::Bool)`

Multiply $x$ by $y$ and set the existing number field element $z$ to the result. Reduction modulo the defining polynomial is only performed if `red`

is set to `true`

. Note that $x$ and $y$ must be reduced. This function is provided for performance reasons as it saves allocating a new object for the result and eliminates associated garbage collection.

`AbstractAlgebra.Generic.reduce!`

— Method`reduce!(x::nf_elem)`

Reduce the given number field element by the defining polynomial, in-place. This only needs to be done after accumulating values computed by `mul_red!`

where reduction has not been performed. All standard Nemo number field functions automatically reduce their outputs.

The following coercion function is provided for a number field $R$.

`R(f::QQPolyRingElem)`

Coerce the given rational polynomial into the number field $R$, i.e. consider the polynomial to be the representation of a number field element and return it.

Conversely, if $R$ is the polynomial ring to which the generating polynomial of a number field belongs, then we can coerce number field elements into the ring $R$ using the following function.

`R(b::nf_elem)`

Coerce the given number field element into the polynomial ring $R$ of which the number field is a quotient.

**Examples**

```
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")
f = R(a^2 + 2a + 3)
g = K(x^2 + 2x + 1)
```

### Basic manipulation

`AbstractAlgebra.var`

— Method`var(a::AnticNumberField)`

Returns the identifier (as a symbol, not a string), that is used for printing the generator of the given number field.

`AbstractAlgebra.is_gen`

— Method`is_gen(a::nf_elem)`

Return `true`

if the given number field element is the generator of the number field, otherwise return `false`

.

`AbstractAlgebra.coeff`

— Method`coeff(x::nf_elem, n::Int)`

Return the $n$-th coefficient of the polynomial representation of the given number field element. Coefficients are numbered from $0$, starting with the constant coefficient.

`Base.denominator`

— Method`denominator(a::nf_elem)`

Return the denominator of the polynomial representation of the given number field element.

`AbstractAlgebra.degree`

— Method`degree(a::AnticNumberField)`

Return the degree of the given number field, i.e. the degree of its defining polynomial.

**Examples**

```
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")
d = a^2 + 2a - 7
m = gen(K)
c = coeff(d, 1)
is_gen(m)
q = degree(K)
r, s = signature(K)
v = var(R)
```

### Norm and trace

`LinearAlgebra.norm`

— Method`norm(a::nf_elem)`

Return the absolute norm of $a$. The result will be a rational number.

`LinearAlgebra.tr`

— Method`tr(a::nf_elem)`

Return the absolute trace of $a$. The result will be a rational number.

**Examples**

```
julia> R, x = polynomial_ring(QQ, "x")
(Univariate polynomial ring in x over QQ, x)
julia> K, a = number_field(x^3 + 3x + 1, "a")
(Number field of degree 3 over QQ, a)
julia> c = 3a^2 - a + 1
3*a^2 - a + 1
julia> d = norm(c)
113
julia> f = tr(c)
-15
```