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 number_field
function.
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)$ | AbsSimpleNumFieldElem | AbsSimpleNumField |
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
— Methodnumber_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
.
Examples
julia> R, x = polynomial_ring(QQ, "x");
julia> K, a = number_field(x^3 + 3x + 1, "a")
(Number field of degree 3 over QQ, a)
julia> K
Number field with defining polynomial x^3 + 3*x + 1
over rational field
Nemo.cyclotomic_field
— Methodcyclotomic_field(n::Int, s::VarName = "z_$n", t = "_\$"; cached::Bool = 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
— Methodcyclotomic_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
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> L, b = cyclotomic_field(5, "b")
(Cyclotomic field of order 5, b)
julia> M, c = cyclotomic_real_subfield(5, "c")
(Maximal real subfield of cyclotomic field of order 5, c)
julia> d = K(3)
3
julia> f = L(b)
b
julia> g = L(ZZ(11))
11
julia> h = L(ZZ(11)//3)
11//3
julia> k = M(x)
c
Number field element constructors
AbstractAlgebra.gen
— Methodgen(a::AbsSimpleNumField)
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
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> d = gen(K)
a
julia> f = a^2 + 2a - 7
a^2 + 2*a - 7
Basic functionality
AbstractAlgebra.mul_red!
— Methodmul_red!(z::AbsSimpleNumFieldElem, x::AbsSimpleNumFieldElem, y::AbsSimpleNumFieldElem, 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.reduce!
— Methodreduce!(x::AbsSimpleNumFieldElem)
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::AbsSimpleNumFieldElem)
Coerce the given number field element into the polynomial ring $R$ of which the number field is a quotient.
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> f = R(a^2 + 2a + 3)
x^2 + 2*x + 3
julia> g = K(x^2 + 2x + 1)
a^2 + 2*a + 1
Basic manipulation
AbstractAlgebra.var
— Methodvar(a::AbsSimpleNumField)
Returns the identifier (as a symbol, not a string), that is used for printing the generator of the given number field.
AbstractAlgebra.is_gen
— Methodis_gen(a::AbsSimpleNumFieldElem)
Return true
if the given number field element is the generator of the number field, otherwise return false
.
AbstractAlgebra.coeff
— Methodcoeff(x::AbsSimpleNumFieldElem, 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
— Methoddenominator(a::AbsSimpleNumFieldElem)
Return the denominator of the polynomial representation of the given number field element.
AbstractAlgebra.degree
— Methoddegree(a::AbsSimpleNumField)
Return the degree of the given number field, i.e. the degree of its defining polynomial.
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> d = a^2 + 2a - 7
a^2 + 2*a - 7
julia> m = gen(K)
a
julia> c = coeff(d, 1)
2
julia> is_gen(m)
true
julia> q = degree(K)
3
Norm and trace
LinearAlgebra.norm
— Methodnorm(a::AbsSimpleNumFieldElem)
Return the absolute norm of $a$. The result will be a rational number.
LinearAlgebra.tr
— Methodtr(a::AbsSimpleNumFieldElem)
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