# Creation Functions

The following describes how number fields may be created. It also shows some ways of creating elements of these rings and homomorphisms from these rings into an arbitrary ring.

## Creation of Number Fields

Algebraic Number Fields can be created in a various ways, most of which involve polynomials. The fields can be created as absolute extensions, i.e. an extension of **Q** by one or more irreducible polynomial(s), or as a relative extension which is an extension of an algebraic field by one or more polynomial(s) irreducible over that field.

### `NumberField(f): RngUPolElt -> FldNum`

```magma
Check            : BoolElt                    Default: true
DoLinearExtension: BoolElt                    Default: false
Global           : BoolElt                    Default: false
```

Given an irreducible polynomial $f$ of degree $n\geq 1$ over $K = {\mathbb{Q}}$ or some number field $K$, create the number field $L=K(\alpha)$ obtained by adjoining a root $\alpha$ of $f$ to $K$.

The polynomial $f$ is allowed to have either integer coefficients, coefficients in an order of $K$, coefficients from the rational field or some algebraic field $K$. The field $K$ will be referred to as [`CoefficientField`](operation.md#function-fldnum-coefficientfield). If the polynomial is defined over a field and the coefficients have denominators greater than $1$, an equivalent polynomial $df(x)$ is used to define $L$, where $d$ is the least common multiple of the denominators of the coefficients of $f$.

If the optional parameter `Check` is set to `false` then the polynomial is not checked for irreducibility. This is useful when building relative extensions where factoring can be time consuming.

If `DoLinearExtension` is `true` and the degree of $f$ is $1$ a trivial extension is returned. This is an object of type `FldNum` but of degree $1$. Otherwise (or by default), the coefficient field of $f$ is returned. (This is important in situations where the number of extensions matters.) Furthermore, a degree $1$ extension of ${\mathbb{Q}}$ is a field isomorphic to ${\mathbb{Q}}$, but regarded by Magma as a number field (while ${\mathbb{Q}}$ itself is not, since `FldRat` is not a subtype of `FldNum`). This then supports all of the number field functions (including for instance fractional ideals) while the `Rationals()` do not. On the other hand, arithmetic will be slower.

If `Global` is `true`, then Magma checks if this polynomial is the defining polynomial of some other field created using `Global := true`. In this case, the old field will be returned.

The angle bracket notation may be used to assign the root $\alpha$ to an identifier e.g. `L<y> := NumberField(f)` where $y$ will be a root of $f$.

### `RationalsAsNumberField() -> FldNum`

### `QNF() -> FldNum`

This creates a number field isomorphic to ${\mathbb{Q}}$. It is equivalent to `NumberField(x-1 : DoLinearExtension)`, where $x$ is `PolynomialRing(Rationals()).1`.

The result is a field isomorphic to ${\mathbb{Q}}$, but regarded by Magma as a number field (while ${\mathbb{Q}}$ itself is not, since `FldRat` is not a subtype of `FldNum`). It therefore supports all of the number field functions, while the `Rationals()` do not. On the other hand, arithmetic will be slower.

Coercion can be used to convert to and from the `Rationals()`.

### `NumberField(s): [ RngUPolElt ] -> FldNum`

```magma
Check            : BoolElt                    Default: true
DoLinearExtension: BoolElt                    Default: false
Abs              : BoolElt                    Default: false
```

Let $K$ be a possibly trivial algebraic extension of ${\mathbb{Q}}$. $K$ will be referred to as the [`CoefficientField`](operation.md#function-fldnum-coefficientfield).

Given a sequence $s$ of nonconstant polynomials $s_1, \ldots, s_m$, that are irreducible over $K$, create the number field $L=K(\alpha_1, \ldots, \alpha_m)$ obtained by adjoining a root $\alpha_i$ of each $s_i$ to $K$. The polynomials $s_i$ are allowed to have coefficients in an order of $K$ (or ${\mathbb{Z}}$) or in $K$ or a suitable field of fractions, but if in the latter cases denominators occur in the coefficients of $s_i$, an integral polynomial is used instead of $s_i$, as in the case of the definition of a number field by a single polynomial.

If $m>1$ and `Abs` is `false`, a tower of extension fields

$$
L_0=K\subset L_1=K(\alpha_m) \subset L_{2}=K(\alpha_{m-1}, \alpha_{m})\subset \cdots \subset L_m = K(\alpha_1, \ldots, \alpha_m)=L
$$

is created, and $L$ is a relative extension by $s_1$ over its ground field $L_{m-1}=K(\alpha_2, \ldots, \alpha_m)$. Thus, this construction has the same effect as $m$ applications of the [`ext< F | s1, ..., sn >`](#constructor-fldnum-ext) constructor. The angle bracket notation may be used to assign the $m$ generators $\alpha_i$ to identifiers: `L<a_1, ..., a_m> := NumberField([ s_1, ..., s_m ])`; thus the first generator $a_1$, which corresponds to `L.1`, generates $L$ over its ground field.

Note that it is important to ensure that in each of the above steps the polynomial $s_i$ is irreducible over $L_{i-1}$; by default Magma will check that this is the case. If the optional parameter `Check` is set to `false` then this checking will not be done.

If the optional parameter `Abs` is changed to `true`, then a non-simple extension will be returned. This is a extension of the coefficient field of the $f_i$ but such that the base field of $L$ will be $K$. The $i$th generator will be a root of the $i$th polynomial in this case, but all of the generators will have $L$ as parent. In this case, a sparse representation of number field elements will be used (based on multivariate polynomial rings). As a consequence, costs for arithmetic operations will (mainly) depend on the number of non-zero coefficients of the elements involved rather than the field degree. This allows to define and work in fields of degree $<10^6$. However, for general elements this representation is slower than the dense (default) representation.

If the optional parameter `DoLinearExtension` is set to `true`, linear polynomials will not be removed from the list.

### `ext< F | s1, ..., sn >: FldNum, RngUPolElt, ..., RngUPolElt -> FldNum`

### `ext<F | s>: FldNum, [RngUPolElt] -> FldNum`

### `ext< Q | s1, ..., sn >: FldRat, RngUPolElt, ..., RngUPolElt -> FldNum`

### `ext< Q | s >: FldRat, [RngUPolElt] -> FldNum`

```magma
Check            : BoolElt                    Default: true
Global           : BoolElt                    Default: false
Abs              : BoolElt                    Default: false
DoLinearExtension: BoolElt                    Default: false
```

Construct the number field defined by extending the number field $F$ by the polynomials $s_i$ or the polynomials in the sequence $s$. Similar as for [`NumberField`](#function-fldnum-numberfield)`(S)` described above, $F$ may be ${\mathbb{Q}}$. A tower of fields similar to that of [`NumberField`](#function-fldnum-numberfield-seq) is created and the same restrictions as for that function apply to the polynomials that can be used in the constructor.

### `Example: Creation (ex-30ee5b)`

To create the number field ${\mathbb{Q}}(\alpha)$, where $\alpha$ is a zero of the integer polynomial $x^4 - 420x^2 + 40000$, one may proceed as follows:

```magma
> R<x> := PolynomialRing(Integers());
> f := x^4 - 420*x^2 + 40000;
> K<y> := NumberField(f);
> Degree(K);
> K;
Number Field with defining polynomial x^4 - 420*x^2 + 40000 over the Rational
Field
> y^4 - 420*y^2;
-40000

```

By assigning the generating element to $y$, we can from here on specify elements in the field as polynomials in $y$. The elements will always be printed as polynomials in ${\mathbb{Q}}[y]/f$:

```magma
> z := y^5/11;
> z;
1/11*(420*y^3 - 40000*y)

```

$K$ can be further extended by the use of either [`ext< F | s1, ..., sn >`](#constructor-fldnum-ext) or [`NumberField`](#function-fldnum-numberfield).

```magma
> R<y> := PolynomialRing(K);
> f := y^2 + y + 1;
> L := ext<K | f>;
> L;
Number Field with defining polynomial y^2 + y + 1 over K

```

This is equivalent to

```magma
> KL := NumberField([x^2 + x + 1, x^4 - 420*x^2 + 40000]);
> KL;
Number Field with defining polynomial $.1^2 + $.1 + 1 over its ground field

```

but different to

```magma
> LK := NumberField([x^4 - 420*x^2 + 40000, x^2 + x + 1]);
> LK;
Number Field with defining polynomial $.1^4 - 420*$.1^2 + 40000 over its ground
field

```

To illustrate the use of `Global`:

```magma
> K1 := NumberField(x^3-2 : Global);
> K2 := NumberField(x^3-2 : Global);
> L1 := NumberField(x^3-2);
> L2 := NumberField(x^3-2);
> K1 eq K2;
true
> K1 eq L1;
false
> L1 eq L2;
false;
> K1!K2.1;
K1.1;
> K2!K1.1;
K1.1
>> L1!L2.1;
     ^
Runtime error in '!': Arguments are not compatible
LHS: FldNum
RHS: FldNumElt

```

A typical application of `DoLinearExtension` is as follows. To construct a Kummer extension of degree $p$, one has to start with a field containing the $p$-th roots of unity. In most situation this will be a field extension of degree $p-1$, but what happens if $\zeta_p$ is already in the base field?

```magma
> AdjoinRoot := function(K, p: DoLinearExtension := false)
>   f := CyclotomicPolynomial(p);
>   f := Polynomial(K, f);
>   f := Factorisation(f)[1][1];
>   return ext<K|f : DoLinearExtension := DoLinearExtension>;
> end function;
> K := NumberField(x^2+x+1);
> E1 := AdjoinRoot(K, 3);
> E1;
Number Field with defining polynomial x^2 + x + 1 over the
Rational Field
> E2 := AdjoinRoot(K, 3 : DoLinearExtension);
> E2;
Number Field with defining polynomial ext<K|>.1 - K.1 over
K
> Norm(E1.1);
1
> Norm(E2.1);
K.1
> Norm($1);
1

```

### `RadicalExtension(F, d, a): Rng, RngIntElt, RngElt -> FldNum`

```magma
Check: BoolElt                    Default: true
```

Let $F$ be a number field. Let $a$ be an integral element of $F$ chosen such that $a$ is not an $n$-th power for any $n$ dividing $d$. Returns the number field obtained by adjoining the $d$-th root of $a$ to $F$.

### `SplittingField(F): FldNum -> FldNum, SeqEnum`

### `NormalClosure(F): FldNum -> FldNum, SeqEnum`

```magma
Abs: BoolElt                    Default: true
Opt: BoolElt                    Default: true
```

Given a number field $F$, this computes the splitting field of its defining polynomial. The roots of the defining polynomial in the splitting field are also returned.

If `Abs` is `true`, the resulting field will be an absolute extension, otherwise a tower is returned.

If `Opt` is `true`, an attempt of using [`OptimizedRepresentation`](../NumberFieldsAndOrders/creation.md#function-rngord-optimizedrepresentation) is done. If successful, the resulting field will have a much nicer representation. On the other hand, computing the intermediate maximal orders can be extremely time consuming.

### `SplittingField(f): RngUPolElt -> FldNum`

Given an irreducible polynomial $f$ over ${\mathbb{Z}}$, return its splitting field.

### `SplittingField(L): [RngUPolElt] -> FldNum, [FldNumElt]`

```magma
Abs: BoolElt                    Default: false
Opt: BoolElt                    Default: false
```

Given a sequence $L$ of polynomials over a number field or the rational numbers, compute a common splitting field, ie. a field $K$ such that every polynomial in $L$ splits into linear factors over $K$. The roots of the polynomials are returned as the second return value.

If the optional parameter `Abs` is `true`, then a primitive element for the splitting field is computed and the field returned will be generated by this primitive element over ${\mathbb{Q}}$. If in addition `Opt` is also `true`, then an optimized representation of $K$ is computed as well.

### `sub< F | e₁, ..., eₙ >: FldAlg, FldAlgElt, ..., FldAlgElt -> FldAlg, Map`

### `sub< F | S >: FldAlg, SeqEnum -> FldAlg, Map`

Given a number field $F$ with coefficient field $G$ and $n$ elements $e_i\in F$, return the number field $H=G(e_1, \ldots, e_n)$ generated by the $e_i$ (over $G$), as well as the embedding homomorphism from $H$ to $F$.

### `MergeFields(F, L): FldNum, FldNum -> SeqEnum`

### `CompositeFields(F, L): FldNum, FldNum -> SeqEnum`

Let $F$ and $L$ be absolute number fields. Returns a sequence of fields $[M_1, \ldots, M_r]$ such that each field $M_i$ contains both a root of the generating polynomial of $F$ and a root of the generating polynomial of $L$.

In detail: Suppose that $F$ is the smaller field (wrt. the degree). As a first step we factorise the defining polynomial of $L$ over $F$. For each factor obtained, an extension of $F$ is constructed and then transformed into an absolute extension. The sequence of extension fields is returned to the user.

### `Compositum(K, L): FldNum, FldNum -> FldNum`

For absolute number fields $K$ and $L$, at least one of which must be normal, find a smallest common over field. Note that in contrast to [`CompositeFields`](#function-fldnum-compositefields) above the result here is essentially unique since one field was normal.

### `quo< FldNum : R | f >: RngUPol, RngUPolElt -> FldNum`

```magma
Check: BoolElt                    Default: true
```

Given a ring of polynomials $R$ in one variable over a number field $K$, create the number field $K(\alpha)$ obtained by adjoining a root $\alpha$ of $f$ to $K$. Here the coefficient ring $K$ of $R$ is allowed to be the rational field ${\mathbb{Q}}$. The polynomial $f$ is allowed to have coefficients in $K$, but if coefficients occur in $f$ which require denominator greater than $1$ when expressed on the basis of $K$, the polynomial will be replaced by an equivalent one requiring no such denominators: $\tilde f(x)=df(x)$, where $d$ is a common denominator. The parameter `Check` determines whether the polynomial is checked for irreducibility. The angle bracket notation may be used to assign the root $\alpha$ to an identifier: `K<y> := quo< FldNum ``:`` R | f >`. If the category `FldNum` is not specified, `quo< R | f >` creates the quotient ring $R/f$ as a generic ring (not as a number field), in which only elementary arithmetic is possible.

### `Example: Composite Fields (ex-180416)`

To illustrate the use of `CompositeFields` we will use this function to compute the normal closure of ${\mathbb{Q}}(\alpha)$ where $\alpha$ is a zero of the integer polynomial $x^3 - 2$:

```magma
> K := RadicalExtension(Rationals(), 3, 2);
> l := CompositeFields(K, K);
> l;
[
    Number Field with defining polynomial $.1^3 - 2 over the Rational
    Field,
    Number Field with defining polynomial $.1^6 + 108 over the Rational
    Field
]

```

The second element of $l$ corresponds to the smallest field $L_2$ containing two distinct roots of $x^3-2$. Since the degree of $K$ is $3$, $L_2$ is the splitting field of $f$ and therefore the normal closure of $K$.

### `OptimizedRepresentation(F): FldNum -> FldNum, Map`

### `OptimisedRepresentation(F): FldNum -> FldNum, Map`

Given a number field $F$ with ground field ${\mathbb{Q}}$, this function will attempt to find an isomorphic field $L$ with a better defining polynomial than the one used to define $F$. If such a polynomial is found then $L$ is returned along with a map from $F$ into $L$; otherwise $F$ will be returned. For more details, please refer to [`OptimizedRepresentation`](../NumberFieldsAndOrders/creation.md#function-rngord-optimizedrepresentation) in Chapter [Number Fields and Orders](../NumberFieldsAndOrders/index-number-fields-and-orders.md#rngord-main).

### `Example: Opt Rep (ex-91bae8)`

Some results of `OptimizedRepresentation` are shown.

```magma
> R<x> := PolynomialRing(Rationals());
> K := NumberField(x^4-420*x^2+40000);
> L := OptimizedRepresentation(K);
> L ne K;
true
> L;
Number Field with defining polynomial x^4 - 4*x^3 -
    17*x^2 + 42*x + 59 over the Rational Field
> L eq OptimizedRepresentation(L);

```

### `IntegralModel(F): FldNum -> FldNum, Map`

Given a number field $F$ with ground field ${\mathbb{Q}}$, return an isomorphic field $L$ whose defining polynomial is monic with integer coefficients, together with an isomorphism from $F$ to $L$. The transformation uses a substitution $y = dx$ for a positive integer $d$ chosen so that the roots become algebraic integers. If the defining polynomial is already integral, returns $F$ and the identity map.

### `Example: Integral Model (ex-67a832)`

```magma
> R<x> := PolynomialRing(Rationals());
> K := NumberField(x^3 - 2*x + 1/2);
> L, m := IntegralModel(K);
> L;
Number Field with defining polynomial x^3 - 8*x + 4 over the Rational Field
> m(K.1);
1/2*L.1
> Inverse(m)(L.1);
2*K.1

```

## Maximal Orders

The maximal order ${\cal O}_K$ is the ring of integers of an algebraic field consisting of all integral elements of the field; that is, elements which are roots of monic integer polynomials. It may also be called the number ring of a number field. It is arguably the single most important invariant of a number field, in fact in number theory when one talks about units, ideals, etc. of number fields, it is typically implied that the maximal order is the underlying ring.

Maximal orders and orders in general are explained in detail in Chapter [Number Fields and Orders](../NumberFieldsAndOrders/index-number-fields-and-orders.md#rngord-main), here we only give a very brief overview.

There are a number of algorithms which Magma uses whilst computing maximal orders. The main ones are the Round–$2$ and the Round–$4$ methods ([[Baier, 1996](../../references.md#cite-bai1), [Cohen, 1993](../../references.md#cite-cohen1), [Pohst, 1993](../../references.md#cite-pohst2), [Pohst and Zassenhaus, 1989](../../references.md#cite-pohst1)] for absolute extensions and [[Cohen, 2000](../../references.md#cite-cohen2), [Friedrichs, 1997](../../references.md#cite-fr1), [Pauli, 2001](../../references.md#cite-pauli-r4)] for relative extensions).

### `MaximalOrder(F): FldNum -> RngOrd`

### `IntegerRing(F): FldNum -> RngOrd`

### `Integers(F): FldNum -> RngOrd`

### `RingOfIntegers(F): FldNum -> RngOrd`

```magma
Al     : MonStgElt                       Default: "Auto"
verbose: MaximalOrder                    Default: Verbose : 5
```

Create the ring of integers of the algebraic number field $F$. An integral basis for $F$ can be found as the basis of the maximal order.

For information on the parameters, see Section [Maximal Orders](../NumberFieldsAndOrders/creation.md#rngord-max-ord).

## Creation of Elements

Since number fields are though of as quotients of (multivariate) polynomial rings, elements in those fields are represented as (multivariate) polynomials in the generator(s) of the field.

### `F ! a: FldNum, RngElt -> FldNumElt`

### `elt< F | a >: FldNum, RngElt -> FldNumElt`

Coerce $a$ into the number field $F$. Here $a$ may be an integer or a rational field element, or an element from a subfield of $F$, or from an order in such or any other field related to $F$ through chains of subfields, optimised representation, absolute fields, etc.

### `F ! [a₀, a₁, ..., aₘ₋₁]: FldNum, [RngElt] -> FldNumElt`

### `elt< F | [ a₀, a₁, ..., aₘ₋₁ ] >: FldNum, SeqEnum[RngElt] -> FldNumElt`

### `elt< F | a₀, a₁, ..., aₘ₋₁>: FldNum, RngElt, ..., RngElt -> FldNumElt`

Given the number field, $F$ of degree $m$ over its ground field $G$ and a sequence $[a_0, \ldots, a_{m-1}]$ of elements of $G$, construct the element $a_0\alpha_0 + a_1\alpha_1 + \cdots a_{m-1}\alpha_{m-1}$ of $F$ where the $\alpha_i$ are the basis elements of $F$. In case $F$ was generated by a root of a single polynomial, we will always have $\alpha_i = {\tt F.1}^i$. If $F$ was defined using multiple polynomials and the `Abs` parameter, the basis will consist of products of powers of the generators.

### `Random(F, m): FldNum, RngIntElt -> FldNumElt`

A random element of the number field $F$. The maximal size of the coefficients is determined by the integer $m$.

### `Example: Elements (ex-543b5e)`

```magma
> R<x> := PolynomialRing(Integers());
> K<y> := NumberField(x^4-420*x^2+40000);
> y^6;
136400*y^2 - 16800000
> K![-16800000, 0, 136400, 0];
136400*y^2 - 16800000
> K := NumberField([x^3-2, x^2-5]:Abs);
> Basis(K);
[
    1,
    K.1,
    K.1^2,
    K.2,
    K.1*K.2,
    K.1^2*K.2
]
> K![1,2,3,4,5,6];
6*K.1^2*K.2 + 3*K.1^2 + 5*K.1*K.2 + 2*K.1 + 4*K.2 + 1

```

### `One(K): FldNum -> FldNumElt`

### `Identity(K): FldNum -> FldNumElt`

### `Zero(K): FldNum -> FldNumElt`

### `Representative(K): FldNum -> FldNumElt`

## Creation of Homomorphisms

To specify homomorphisms from number fields, it is necessary to specify the image of the generating elements, and possible to specify a map on the coefficient field.

### `hom< F -> R | r >: FldNum, Rng, RngElt -> Map`

### `hom< F -> R | h, r >: FldNum, Rng, Map, RngElt -> Map`

### `hom< F -> R | r >: FldNum, Rng, [RngElt] -> Map`

### `hom< F -> R | h, r >: FldNum, Rng, Map, [RngElt] -> Map`

Given an algebraic number field $F$, defined as an extension of the coefficient field $G$, as well as some ring $R$, build the homomorphism $\phi$ obtained by sending the defining primitive element $\alpha$ of $F$ to the element $r\in R$.

In case the field $F$ was defined using multiple polynomials, instead of an image for the primitive element, one has to give images for each of the generators.

It is possible (if $G={\mathbb{Q}}$) and sometimes necessary (if $G\neq {\mathbb{Q}}$) to specify a homomorphism $\phi$ on $F$ by specifying its action on $G$ by providing a homomorphism $h$ with $G$ as its domain and $R$ its codomain together with the image of $\alpha$. If $R$ does not cover $G$ then the homomorphism $h$ from $G$ into $R$ is necessary to ensure that the ground field can be mapped into $R$.

### `Example: Homomorphisms (ex-4d9b55)`

We show a way to embed the field ${\mathbb{Q}}(\sqrt{2})$ in ${\mathbb{Q}}(\sqrt{2}+\sqrt{3})$. The application of the homomorphism suggests how the image could have been chosen.

```magma
> R<x> := PolynomialRing(Integers());
> K<y> := NumberField(x^2-2);
> KL<w> := NumberField(x^4-10*x^2+1);
> H := hom< K -> KL | (9*w-w^3)/2 >;
> H(y);
1/2*(-w^3 + 9*w)
> H(y)^2;
2

```
