# Creation Functions

This section describes the main ways to construct number fields and orders, as well as creation of elements and homomorphisms.

## Creation of Algebraic Fields

A field may be created as an *absolute extension* (absolute field), i.e. an extension of $Q$ by an irreducible polynomial, or as a *relative extension* (relative field), i.e. an extension of another field $K$ by an irreducible polynomial over $K$. See also Section [Creation of Structures](../QuadraticFields/creation.md#fldquad-creation) for quadratic fields and Section [Creation Functions](../CyclotomicFields/creation.md#fldcyc-creation) for cyclotomic fields (these are the special subtypes of number fields in Magma). Some other constructions (which involve nontrivial computations) are the composite formed by two or more given fields, and the splitting field of a given polynomial or 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$. For details see [`NumberField`](../NumberFields/creation.md#function-fldnum-numberfield) in Section [Creation of Number Fields](../NumberFields/creation.md#fldnum-creation).

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}}$. 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$. For details see [`NumberField`](../NumberFields/creation.md#function-fldnum-numberfield-seq) in Section [Creation of Number Fields](../NumberFields/creation.md#fldnum-creation).

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

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

### `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
```

Create the algebraic field defined by extending $F$ by the polynomials $s_i$ or the polynomials in the sequence $s$. Similar as for `NumberField(S)` described above, $F$ may be ${\mathbb{Q}}$ or a field of fractions. If $F$ is a field of fractions a field of fractions will be returned otherwise a number field will be returned. A tower of fields similar to that of [`NumberField`](../NumberFields/creation.md#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.

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

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

Let $F$ be an algebraic 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 algebraic field obtained by adjoining the $d$-th root of $a$ to $F$.

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

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

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

Given an algebraic field $F$, return 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`](#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 -> FldAlg`

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, i.e. 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 an algebraic field $F$ with ground field $G$ and $n$ elements $e_i\in F$, return the algebraic 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): FldAlg, FldAlg -> SeqEnum`

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

Let $F$ and $L$ be absolute algebraic 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): FldAlg, FldAlg -> FldAlg`

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-rngord-compositefields) above the result here is essentially unique since one field was normal.

### `Compositum(K, A): FldAlg, FldAb -> FldAlg`

For a normal number field $K$ and abelian extension $A$ of some subfield of $K$, find a smallest common over field. Note that in contrast to [`CompositeFields`](#function-rngord-compositefields) above the result here is essentially unique since $K$ is normal.

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

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

### `OptimizedRepresentation(F, d): FldAlg, RngIntElt -> FldAlg, Map`

### `OptimisedRepresentation(F, d): FldAlg, RngIntElt -> FldAlg, Map`

Given an algebraic field $F$ with ground field ${\mathbb{Q}}$, this function will attempt to find an isomorphic field $L$ with a better defining polynomial (in the sense defined below) than the one used to define $F$. If such a polynomial is found then $L$ is returned as well as a map from $F$ into $L$; otherwise $F$ will be returned. If the argument $d$ is not specified, a polynomial $g$ with integer coefficients is defined to be better than $f$ if it is monic, irreducible, defines a number field isomorphic to $F$ and its discriminant is smaller (in absolute value) than that of $f$. If a second argument $d$ is specified, then $g$ is defined to be better if in addition to the previous requirements $d$ is not an index divisor, that is, if $d$ does not divide the index (defined in the Invariants sub–section) $[O_L : E_L]$ of the equation order $E_L$ of $L$ in the maximal order $O_L$, (which are defined in the next sub–section).

Note however, that as a first step this function will determine the maximal order of $F$ which may take some time if the field is large.

### `Example: Opt Rep Ord (ex-509ba1)`

Some results of `OptimizedRepresentation` are shown. Note that `OptimizedRepresentation` is a random algorithm, and may return different results for the same input.

```magma
> _<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);
true
> f := DefiningPolynomial(K);
// f is an element of Q[x], so Discriminant(f) is in Q not Z
> Z := IntegerRing();
> Factorization(Z !  Discriminant(f));
[ <2, 18>, <5, 8>, <41, 2> ]
> g := DefiningPolynomial(L);
> g;
x^4 - 4*x^3 - 17*x^2 + 42*x + 59;
> Factorization(Z ! Discriminant(g));
[ <2, 4>, <3, 4>, <5, 2>, <41, 2> ]
> OL := MaximalOrder(L);
> EL := EquationOrder(L);
> Index(OL, EL);
36
> OptimizedRepresentation(L, 2) eq L;
true

```

As we see from this computation, the prime $5$ (as well as $41$) divides the discriminant of $g$ twice. This means that, potentially, 5 would still divide the index of the equation order in the maximal order $O_L$ of $L$. However, in fact $E_L$ has only index $36$ in $O_L$.

The optimized representation of $L$ such that $2$ does not divide the index of $E_L$ in $O_L$ is $L$ so $2$ does divide the index seemingly contrary to the description above. However, if a more optimal representation cannot be found then the field is returned which is what happens here.

## Creation of Orders and Fields from Orders

The maximal order ${\cal O}_K$ of an algebraic field and the equation order of a number field can be obtained from the field. Other orders of a field are unitary subrings of finite index in the ring of integers; they contain a subset of the integral elements in the field. The equation order ${\cal E}_K={\mathbb{Z}}[\alpha]$ of $K={\mathbb{Q}}(\alpha)\cong {\mathbb{Q}}[X]/f(X)$, where $K$ is a number field defined by a monic integral polynomial, has the same basis as $K$, a power basis. Obviously ${\cal E}_K\subset{\cal O}_K$ since the minimal polynomial of $\alpha$ is integral and monic. Once an order is created in Magma further orders can be created from it.

### `EquationOrder(f): RngUPolElt -> RngOrd`

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

Given an irreducible non-constant monic integral polynomial $f\in R[X]$, return the equation order $E={\mathbb{R}}[X]/f(X)$ corresponding to $f$. If the optional parameter `Check` is set to `false` then the polynomial will not be checked for irreducibility.

### `EquationOrder(S): [RngUPolElt] -> RngOrd`

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

The equation order of [`NumberField`](../NumberFields/creation.md#function-fldnum-numberfield-seq)`(S)`.

### `EquationOrder(K): FldNum -> RngOrd`

Return the equation order corresponding to the polynomial with which the number field $K$ was defined. The field $K$ must have been defined by a monic integral polynomial. Thus this function returns the extension of the equation order of the ground field of $K$ by the defining polynomial of $K$.

### `SubOrder(O): RngOrd -> RngOrd`

Provided the order $O$ is not an equation order, $O$ is a transformation of some order $O'$. This function returns $O'$.

### `EquationOrder(O): RngOrd -> RngOrd`

A suborder of the order $O$ which is defined by a polynomial. e.g. $R[x] / f$ where $R$ is a polynomial ring over the coefficient ring of $O$ and $f$ is in $R$. It will also be the final order of `SubOrder(SubOrder(... SubOrder(O)))`. The order $O$ must have a monic defining polynomial for the equation order to exist.

### `Integers(O): RngOrd -> RngOrd`

### `RingOfIntegers(O): RngOrd -> RngOrd`

### `IntegerRing(O): RngOrd -> RngOrd`

Returns the ring of integers in the order $O$, ie. $O$ itself.

### `Example: Orders (ex-4c8125)`

Once a number field $K={\mathbb{Q}}(\alpha)$ has been created, one can obtain the equation order $E={\mathbb{Z}}[\alpha]$ and the ring of integers $O_K$ simply as follows.

```magma
> R<x> := PolynomialRing(Integers());
> K := NumberField(x^4-420*x^2+40000);
> E := EquationOrder(K);
> O := MaximalOrder(K);
> Index(O, E);
64000

```

Note that entirely different things happen here: for the equation order nothing has to be computed, but the determination of the maximal order involves the complicated Round 2 (or 4) algorithm. In our particular example above, $E$ is a subring of index $2^9\cdot 5^3$ in $O$ (see also the example for orders and ideals in the subsection [Orders and Ideals](#rngord-orders-ideals) where a maximal order is created).

### `sub< O | a₁, ..., aᵣ >: RngOrd, RngOrdElt, ..., RngOrdElt -> RngOrd`

Create the suborder of the order $O$ generated (as an algebra over ${\mathbb{Z}}$) by the elements $a_1, \ldots, a_r\in O$, that is, create ${\mathbb{Z}}[a_1, \ldots, a_r]$. If the algebra does not have full rank as a sub-module of $O$, an error results. Note, however, that it is currently *not* required that $1$ is in the sub-ring.

### `ext< O | a₁, ..., aᵣ >: RngOrd, RngOrdElt, ..., RngOrdElt -> RngOrd`

Given an order $O$, and elements $a_1, \ldots, a_r$ lying in the maximal order of $O$, create the order $O[a_1, \ldots, a_r]$. Note that using this constructor $O$ can only be extended to be as large as the maximal order. This does not cause the maximal order to get computed. See also [`Order`](#function-rngord-order-seq) for a different version that allows parameters to improve efficiency.

### `ext< Z | f >: RngInt, RngUPolElt -> RngOrd`

### `ext< O | f >: RngOrd, RngUPolElt -> RngOrd`

Given an order $O$ and a polynomial $f$ of degree $n$ with coefficients in $O$, create the extension $E$ of $O$ by a root of $f$ which forms a free module of rank $n$ over $O$ : $E\cong O[\alpha]$; it is necessary for $f$ to be irreducible over $O$.

### `FieldOfFractions(O): RngOrd -> FldOrd`

Return the field containing all fractions of elements of $O$. The angle bracket notation can be used to assign names to the basis elements of $F$ and assign these elements to variables, e.g. `F<x, y> := FieldOfFractions(MaximalOrder(x^2 + 3))`.

### `Order(F): FldOrd -> RngOrd`

The order of which $F$ was created as its field of fractions. This function is an inverse to `FieldOfFractions`.

### `NumberField(O): RngOrd -> FldNum`

The number field of an order is recursively defined by:

1. the number field of **Z** is **Q**

2. the number field of $O$ is the number field of the coefficient ring of $O$, (i.e. the order over which $O$ is defined), with an element $\alpha$ adjoined where $\alpha$ is a root of the defining polynomial of $O$.

### `NumberField(F): FldOrd -> FldNum`

The number field of `Order(F)` for a field of fractions $F$.

### `Example: fractions (ex-94a3f9)`

The following illustrates the relationship between the bases of an order, its field of fractions and its number field.

```magma
> R<x> := PolynomialRing(Integers());
> f := x^5 + 5*x^4 - 75*x^3 + 250*x^2 + 65625;
> M := MaximalOrder(f);
> M;
Maximal Order of Equation Order with defining polynomial x^5 + 5*x^4 - 75*x^3 +
    250*x^2 + 65625 over its ground order
> Basis(FieldOfFractions(M));
[
    M.1,
    M.2,
    M.3,
    M.4,
    M.5
]
> Basis(NumberField(M));
[
    1,
    $.1,
    $.1^2,
    $.1^3,
    $.1^4
]
> Basis(M);
[
    M.1,
    M.2,
    M.3,
    M.4,
    M.5
]
> M.1 eq 1;
true
> M.2 eq NumberField(M).1;
false
> E := EquationOrder(M);
> NumberField(M) eq NumberField(E);
true
> Basis(FieldOfFractions(E), NumberField(M));
[
    1,
    $.1,
    $.1^2,
    $.1^3,
    $.1^4
]
> M!Basis(FieldOfFractions(E))[1];
[1, 0, 0, 0, 0]
> M!Basis(FieldOfFractions(E))[2];
[0, 5, 0, 0, 0]
> M!NumberField(M).1;
[0, 5, 0, 0, 0]

```

### `OptimizedRepresentation(O): RngOrd -> BoolElt, RngOrd, Map`

### `OptimisedRepresentation(O): RngOrd -> BoolElt, RngOrd, Map`

### `OptimizedRepresentation(O, d): RngOrd, RngIntElt -> BoolElt, RngOrd, Map`

### `OptimisedRepresentation(O, d): RngOrd, RngIntElt -> BoolElt, RngOrd, Map`

Given an order $O$ with ground ring ${\mathbb{Z}}$, this function will attempt to find an isomorphic order $OO$ with discriminant the same as O with a better defining polynomial than the one used to define $O$. If such a polynomial is found then $OO$ is returned; otherwise only `false` is returned. If the argument $d$ is not specified, a polynomial $g$ with integer coefficients is defined to be better than $f$ if it is monic, irreducible, defines an order isomorphic to $O$ and its discriminant is smaller in absolute value than that of $f$. If a second argument $d$ is specified, then $g$ is defined to be better if in addition to the previous requirements $d$ is not an index divisor, that is, if $d$ does not divide the index (defined in the Invariants sub–section) $[OO : E_{OO}]$ of the equation order $E_{OO}$ of $OO$ in $OO$.

### `O + P: RngOrd, RngOrd -> RngOrd`

Add two orders $O$ and $P$ having the same equation order. Computes the smallest common over order.

### `O meet P: RngOrd, RngOrd -> RngOrd`

The intersection of two orders $O$ and $P$ having the same equation order.

### `AsExtensionOf(O, P): RngOrd, RngOrd -> RngOrd`

Return the order $O$ as a transformation of the order $P$ where $O$ and $P$ have the same coefficient ring.

### `Order(O, T, d): RngOrd, AlgMatElt, RngIntElt -> RngOrd`

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

Let $O$ be an absolute order with basis $b_1, \ldots, n_n$, $T=(T_{i,j})\in{\operatorname{GL}}(n, {\mathbb{Q}}) \cap {\operatorname{Mat}}(n, {\mathbb{Z}})$ and $d\in \rm N$. This function creates the order with basis $(1/d\sum_{j=1}^n T_{i,j}b_j)_{i\leq i\leq n}$. The parameter `Check` can be set to `false` when the order is large to avoid checking that the result actually is an order. Note that this can result in a non-order being constructed which may cause errors later.

### `Order(O, M): RngOrd, ModDed -> RngOrd`

### `Order(O, M): RngOrd, PMat -> RngOrd`

```magma
NFBasis: BoolElt                    Default: true
```

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

Let $O$ be an order with (pseudo) basis $b_1, \ldots, b_n$ and $M=\sum_{i=1}^n A_i\alpha_i \subseteq k^n$ be an $o_k$-module where $o_k$ is the coefficient ring of $O$. This function creates the order $\sum_{i=1}^n A_i c_i$ where $c_i := \sum_{j=1}^n\alpha_{i,j}b_j$. If the parameter `Check` is set to `false`, then it will not be checked that the result actually is an order (potentially expensive). Note that this can result in a non-order being constructed which may cause errors later. If the parameter `NFBasis` is set to `false` then the `PseudoGenerators` of the module $M$ will be used rather than the `PseudoBasis`, however these pseudo generators must also be a pseudo basis.

### `Order([ e₁, ... eₙ ]): [FldAlgElt] -> RngOrd`

```magma
Verify : BoolElt                    Default: true
IsBasis: BoolElt                    Default: false
```

Given $n$ elements $e_1, \ldots, e_n$ in an algebraic extension field $F$ over ${\mathbb{Q}}$ create the minimal order $O$ of $F$ which contains all the $e_i$. If `Verify` is `true`, it is verified that the $e_i$ are integral algebraic numbers. This can be a lengthy process if the field is of large degree.

Setting `IsBasis` to `true` assumes that the given elements actually form a basis for the new order, thus it avoids testing for multiplicative closure. Without this parameter the order returned will have a canonical basis chosen with no direct relation to the input. Note that setting `IsBasis` to `true` can result in a non-order being constructed if the elements in the sequence are not a basis which may cause errors later. By default, products of the generators will be added until the module is closed under multiplication.

If `IsBasis` is set to `true` to specify the basis of the resulting order rather than avoid the expense of the multiplicative closure computation, it can be checked that the result $O$ is an order using `Order(SubOrder(O), Matrix(CoefficientRing(O), M*d), d) where d is Denominator(M) where M is BasisMatrix(O);`. If $O$ is not an order this will cause an error.

## 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.

There are a number of algorithms which Magma uses whilst computing maximal orders. Each maximal order is a sum of $p$-maximal orders. The main algorithm used for $p$-maximal orders is a mixture of the Round–$2$ and 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 a variant of the Round–$2$ for relative extensions ([[Cohen, 2000](../../references.md#cite-cohen2), [Friedrichs, 1997](../../references.md#cite-fr1)]).

However if the field is a radical (pure) extension, there is another algorithm available which is used to calculate each $p$-maximal order. In this case we can compute a pseudo basis for the $p$-maximal orders knowing only the valuation of the constant coefficient of the defining polynomial at $p$ [[Sutherland, 2012](../../references.md#cite-suth-max-kummer)].

It is possible to compute the maximal order of an absolute extension of ${\mathbb{Z}}$ or ${\mathbb{Q}}$ defined by one monic, integral polynomial using the Montes Algorithm [[Stainsby, 2018](../../references.md#cite-2015arxiv150601904s)]. The Montes algorithm can be selected using `Al := "Montes"` when the input is a field or an order. For more on the Montes Algorithm see Section [The Montes Algorithm](montes.md#montes-fld-num).

The Round–$2$ and Round–$4$ algorithms can be selected by setting the parameter `Al` to `"Round2"` and `"Round4"` respectively. Another option for this parameter and for computation of $p$-maximal orders is the `"Pauli"` method. This method is only available for equation orders in simple relative extensions. It uses the factorization of the defining polynomial over the completion of the order.

Alternatively, if the discriminant of the maximal order is already known, the parameters `Discriminant` or `Ramification` can be used. If the input is an order $O$ and the `Discriminant` or `Ramification` parameters are supplied an algorithm which can compute the maximal order given the discriminant of the maximal order will be used. `Discriminant` must be an integer if $O$ is an absolute order and must be an ideal of the coefficient ring of $O$ if $O$ is a relative order. `Ramification` must contain integers if $O$ is an absolute order and must contain ideals of the coefficient ring of $O$ if $O$ is a relative order. The ramification sequence is taken to contain prime factors of the discriminant. Only one of these parameters can be specified, and in this case `Al` cannot be specified. This algorithm is based on [[Buchmann and Lenstra jr, 1994](../../references.md#cite-buchman-lenstra)], Theorems 1.2 and 7.6.

### `MaximalOrder(O): RngOrd -> RngOrd`

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

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

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

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

```magma
Al          : MonStgElt                       Default: "Auto"
Discriminant: Any                             Default: 
Ramification: SeqEnum                         Default: 
verbose     : MaximalOrder                    Default: Verbose : 5
```

Return the maximal order or ring of integers of the number field $F$. When the input is an order $O$ or a field of fractions of an order $O$ return the order containing $O$ which is the largest order in the number field of $O$.

An integral basis for $F$ can be found as the basis of the maximal order.

For information on the parameters, see the introduction to this section above, [Maximal Orders](#rngord-max-ord).

### `MaximalOrder(f): RngUPolElt -> RngOrd`

```magma
Check       : BoolElt                         Default: true
Al          : MonStgElt                       Default: "Auto"
Discriminant: Any                             Default: 
Ramification: SeqEnum                         Default: 
verbose     : MaximalOrder                    Default: Verbose : 5
```

This is equivalent to `MaximalOrder(NumberField(f))`.

The `Check` parameter if set to `false` will prevent checking of the polynomial for irreducibility.

For information on the other parameters, see the introduction to this section above.

### `Example: Max Order (ex-474b81)`

The following shows the advantage of the `Ramification` parameter to the `MaximalOrder` function.

```magma
> R<t> := PolynomialRing(Integers());
> f1 := t^14 - 63*t^12 - 9555*t^11 + 118671*t^10 - 708246*t^9 - 17922660*t^8 +
> 859373823*t^7 + 2085856500*t^6 - 117366985106*t^5 - 335941176396*t^4 +
> 4638317668005*t^3 + 17926524826973*t^2 + 7429846568445*t+ 91264986397629;
> d1 := [2, 3, 5, 7, 59];
> time MaximalOrder(f1:Ramification := d1);
Maximal Order of Equation Order with defining polynomial x^14 - 63*x^12 -
    9555*x^11 + 118671*x^10 - 708246*x^9 - 17922660*x^8 + 859373823*x^7 +
    2085856500*x^6 - 117366985106*x^5 - 335941176396*x^4 + 4638317668005*x^3 +
    17926524826973*x^2 + 7429846568445*x + 91264986397629 over Z
Time: 0.230
> time MaximalOrder(f1);
Maximal Order of Equation Order with defining polynomial x^14 - 63*x^12 -
    9555*x^11 + 118671*x^10 - 708246*x^9 - 17922660*x^8 + 859373823*x^7 +
    2085856500*x^6 - 117366985106*x^5 - 335941176396*x^4 + 4638317668005*x^3 +
    17926524826973*x^2 + 7429846568445*x + 91264986397629 over Z
Time: 0.590
> f2 := t^14 - 129864*t^12 - 517832*t^11 + 6567239322*t^10 + 33352434192*t^9 -
> 166594899026864*t^8 - 752915315481312*t^7 + 2275891736459084940*t^6 +
> 7743078094604088768*t^5 - 16633213695413438344032*t^4 -
> 39871919309692447523616*t^3 + 60126791399546070679893112*t^2 +
> 77844118533852728698751040*t - 83173498199506854751458701376;
> d2 := [2,3,7,4145023];
>
> time MaximalOrder(f2:Ramification := d2);
Maximal Order of Equation Order with defining polynomial x^14 - 129864*x^12 -
    517832*x^11 + 6567239322*x^10 + 33352434192*x^9 - 166594899026864*x^8 -
    752915315481312*x^7 + 2275891736459084940*x^6 + 7743078094604088768*x^5 -
    16633213695413438344032*x^4 - 39871919309692447523616*x^3 +
    60126791399546070679893112*x^2 + 77844118533852728698751040*x -
    83173498199506854751458701376 over Z
Time: 0.730
> time MaximalOrder(f2);
Maximal Order of Equation Order with defining polynomial x^14 - 129864*x^12 -
    517832*x^11 + 6567239322*x^10 + 33352434192*x^9 - 166594899026864*x^8 -
    752915315481312*x^7 + 2275891736459084940*x^6 + 7743078094604088768*x^5 -
    16633213695413438344032*x^4 - 39871919309692447523616*x^3 +
    60126791399546070679893112*x^2 + 77844118533852728698751040*x -
    83173498199506854751458701376 over Z
Time: 0.840
> f13 := t^15 - 114*t^14 + 282185319*t^13 + 1247857228852*t^12 -
> 35114805704965233*t^11 - 141524337796433387826*t^10 +
> 2604584980442264028744009*t^9 + 14153948932132918272984150384*t^8 -
> 178273077248353369941327628479552*t^7 - 1142953506821390914419260564494304768
> *t^6 + 15975069142211276963134599495014990639616*t^5 +
> 33516684438303088018217308253251277376159744*t^4 -
> 617589777108203716232396372453619309554471256064*t^3 -
> 397561412445066919545461762354884631501806174863360*t^2 +
> 2266657182908547570648245464215192357802047101628186624*t
> - 1302222456532760256406916223259306960561657428777814196224;
> d13 := [2, 3, 3377890562461, 7623585272461];
> time MaximalOrder(f13: Ramification := d13);
Maximal Order of Equation Order with defining polynomial x^15 - 114*x^14 +
    282185319*x^13 + 1247857228852*x^12 - 35114805704965233*x^11 -
    141524337796433387826*x^10 + 2604584980442264028744009*x^9 +
    14153948932132918272984150384*x^8 - 178273077248353369941327628479552*x^7 -
    1142953506821390914419260564494304768*x^6 +
    15975069142211276963134599495014990639616*x^5 +
    33516684438303088018217308253251277376159744*x^4 -
    617589777108203716232396372453619309554471256064*x^3 -
    397561412445066919545461762354884631501806174863360*x^2 +
    2266657182908547570648245464215192357802047101628186624*x -
    1302222456532760256406916223259306960561657428777814196224 over Z
Time: 0.270

```

The following call will not terminate, because the discriminant of the polynomial has a 257-digit composite factor which cannot be factored.

```magma
> time MaximalOrder(f13);

```

### Orders and Ideals

Orders may be created using ideals of another order. Ideals are discussed in Section [Ideals and Quotients](ideal.md#rngord-ideal). The following intrinsics form part of the computation of maximal orders as discussed above in Section [Maximal Orders](#rngord-max-ord).

#### `pMaximalOrder(O, p): RngOrd, RngIntElt -> RngOrd`

#### `pMaximalOrder(O, p): RngOrd, RngOrdIdl -> RngOrd`

```magma
Al: MonStgElt                    Default: "Auto"
```

The $p$-maximal overorder of $O$ (see also the example below). This is the largest overorder $P$ such that the index $(P:O)$ is a power of $p$, a prime in the coefficient ring of $O$. The options for the `Al` parameter are the same as those for [`MaximalOrder`](#function-rngord-maxord).

If $O$ is a kummer extension then specific code is used to calculate each $p$-maximal order, rather than the Round $2$ or Round $4$ methods. In this case we know $1$ or $2$ elements which generate the $p$-maximal order and can easily write the order down.

#### `pRadical(O, p): RngOrd, RngIntElt -> RngOrdIdl`

#### `pRadical(O, p): RngOrd, RngOrdIdl -> RngOrdIdl`

Returns the $p$-radical of an order $O$ for a prime $p$ in the coefficient ring of $O$, defined as the ideal consisting of elements of $O$ for which some power lies in the ideal $pO$.

It is possible to call this function for $p$ not prime (so long as $p$ is greater than the degree of $O$ if it is an integer). In this case the $p$-trace-radical will be computed, i.e.

$$
\{ x\in F \mid {\operatorname{Tr}}(xO)\subseteq p{\mathbb{Z}}\}.
$$

If $p$ is square free and all divisors are larger than the field degree, this is the intersection of the radicals for all $l$ dividing $p$. In particular together with `MultiplicatorRing` this can sometime be used to compute maximal orders without factoring the discriminant [[Buchmann and Lenstra jr, 1994](../../references.md#cite-buchman-lenstra), [Friedrichs, 2000](../../references.md#cite-fr2)] or at least “good” approximations.

#### `MultiplicatorRing(I): RngOrdFracIdl -> Rng`

Returns the multiplicator ring $M$ of the ideal $I$ of the order $O$, that is, the subring of elements of the field of fractions $K$ of $O$ multiplying $I$ into itself: $M=\{ x \in F : xI\subset I\}$.

#### `Example: Round2 (ex-638433)`

To illustrate how the Round 2 algorithm for the determination of the ring of integers works, we present an implementation of it in the Magma language. The key functions are `MultiplicatorRing` and `pRadical`, called by the following function `pMaximalOverOrder`;

```magma
> pMaximalOverOrder := function(ord, p)
>        ovr := MultiplicatorRing(pRadical(ord, p));
>        print "index is", Index(ovr, ord);
>        return (Index(ovr, ord) eq 1) select ovr else $$(ovr, p);
> end function;

```

which finds the largest overorder in which the given order has $p$-power index. This function is now simply applied to the equation order, for each prime dividing the discriminant:

```magma
> Round2 := function(E, K)
>        // E should be some order of a number field K
>        d := Discriminant(E);
>        fact := Factorization(Abs(d));
>        print fact;
>        M := E;
>        for x in fact do
>             M := M+pMaximalOverOrder(E, x[1]);
>        end for;
>        print "index of equation order in maximal order is:", Index(M, E);
>        return M;
> end function;

```

In our running example, this produces the following output:

```magma
> R<x> := PolynomialRing(Integers());
> K := NumberField(x^4-420*x^2+40000);
> E := EquationOrder(K);
> Round2(E, K);
[ <2, 18>, <5, 8>, <41, 2> ]
index is 2
index is 4
index is 8
index is 4
index is 2
index is 1
index is 5
index is 25
index is 1
index is 1
index of equation order in maximal order is: 64000
Transformation of E
Transformation Matrix:
[800   0   0   0]
[  0 400   0   0]
[  0 200  20   0]
[400 180   0   1]
Denominator: 800

```

## Creation of Elements

Elements of algebraic fields and of orders are displayed quite differently. Algebraic field elements are always printed as a linear combination with rational coefficients of the basis elements of the field. For number fields which have a power basis this is also a polynomial in the primitive element of the field with rational coefficients; that is, an element of $G[x]/f$, where $f$ was the defining polynomial of the field over the ground field $G$. Since in general $G$ will be an algebraic field itself, elements in relative extensions, i.e. $G$ strictly bigger than ${\mathbb{Q}}$, will be printed as linear combinations with linear combinations as coefficients and for number fields this will look like multivariate polynomials. In fact they are recursively defined univariate polynomials. Elements of orders are displayed as sequences of integer coefficients, referring to the basis of the order. To convert this ${\mathbb{Z}}$-basis representation to a polynomial expression in the primitive element of an associated number field, the element should be coerced into the number field (using `!`). To print the element as a linear combination of the basis elements, coerce the element into the field of fractions.

### `F ! a: FldAlg, RngElt -> FldAlgElt`

### `elt< F | a >: FldAlg, RngElt -> FldAlgElt`

Coerce $a$ into the 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.

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

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

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

Given the algebraic 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$.

### `O ! a: RngOrd, RngElt -> RngOrdElt`

### `elt< O | a >: RngOrd, RngElt -> RngOrdElt`

Coerce $a$ into the order $O$. Here $a$ is allowed to be an integer, or an integral element of an associated algebraic field of $O$, or an element of a quotient order.

### `O ! [a₀, a₁, ..., aₘ₋₁]: RngOrd, [ RngElt ] -> RngOrdElt`

### `elt< O | [ a₀, a₁, ..., aₘ₋₁ ] >: RngOrd, SeqEnum[RngElt] -> RngOrdElt`

### `elt< O | a₀, a₁, ..., aₘ₋₁ >: RngOrd, RngElt, ..., RngElt -> RngOrdElt`

Given the order $O$ of degree $m$ and elements $a_0, a_{1}, \ldots, a_{m-1}$ in the ground order of $O$, construct the element $a_0\alpha_0 + a_1  \alpha_1 + \cdots + a_{m-1} \alpha_{m-1}$ of $O$, where $\alpha_0, \ldots, \alpha_{m-1}$ is the basis for the order.

### `Random(F, m): FldAlg, RngIntElt -> FldAlgElt`

### `Random(O, m): RngOrd, RngIntElt -> RngOrdElt`

A random element of the algebraic field $F$ or order $O$. The maximal size of the coefficients is determined by $m$.

### `Random(I, m): RngOrdFracIdl, RngIntElt -> FldOrdElt`

A random element of the ideal $I$ as an element of the field of fractions of the associated order. The maximal size of the coefficients with respect to the ideal basis is determined by $m$.

### `Example: Elements (ex-759e86)`

Here are three ways of creating the same integral element in $K$ as an element of the maximal order and its field of fractions.

```magma
> R<x> := PolynomialRing(Integers());
> K<y> := NumberField(x^4-420*x^2+40000);
> O := MaximalOrder(K);
> e := O ! (y^2/40 + y/4);
> // Coordinates of e with respect to Basis(O):
> v := Eltseq(e);
> v;
[ 0, 1, 1, 0 ]
> // The same coordinates build the element directly,
> // both in O and in its field of fractions:
> f := elt< O | v >;
> f eq e;
true
> F<a, b, c, d> := FieldOfFractions(O);
> g := F ! v;
> g eq e;
true
> g;
b + c

```

These constructions would have failed if the element was not in $O$.

### `One(K): FldAlg -> FldAlgElt`

### `One(O): RngOrd -> RngOrdElt`

### `Identity(K): FldAlg -> FldAlgElt`

### `Identity(O): RngOrd -> RngOrdElt`

### `Zero(K): FldAlg -> FldAlgElt`

### `Zero(O): RngOrd -> RngOrdElt`

### `Representative(K): FldAlg -> FldAlgElt`

### `Representative(O): RngOrd -> RngOrdElt`

## Creation of Homomorphisms

To specify homomorphisms from algebraic fields or orders in algebraic fields, it is necessary to specify the image of the generating elements, and possible to specify a map on the ground field.

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

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

Given an algebraic field $F$, defined as an extension of the ground 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$.

If $F$ is a field of fractions then $r$ will be the image of the primitive element of the field of fractions of the equation order of `Order(F)`.

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$.

### `hom< O -> R | r >: RngOrd, Rng, RngElt -> Map`

### `hom< O -> R | h, r >: RngOrd, Rng, Map, RngElt -> Map`

Given an order $O$, a ring $R$ and an element $r\in R$, construct a homomorphism $\phi$ by sending the primitive element of the equation order of $O$ to $r$.

To be more precise: Let $K$ be the field of fractions of $O$, $k$ be the base field of $K$ i.e. the field of fractions of the base ring of $O$, and $N$ := `NumberField(O)`. As a $k$–algebra $K$ is generated by $x := K!N.1$, so $x$ is zero of `DefiningPolynomial(O)`. The element $r$ given in the map construction will be the image of $x$.

When $O$ is an equation order e.g. if $O$ was defined using a monic integral polynomial $x$ will be `O.2`.

As in the field case it is possible to specify a map on the coefficient ring of $O$ (ring over which $O$ is defined) with codomain $R$. This is necessary if $R$ does not cover the coefficient ring of $O$.

### `Example: Homomorphisms (ex-d59686)`

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

```

Homomorphisms can be created between any order or algebraic field and any ring.

```magma
> f := x^4 + 5*x^3 - 25*x^2 + 125*x + 625;
> M := MaximalOrder(f);
> F<a, b, c, d> := FieldOfFractions(M);
> FF := FiniteField(5, 3);
> F;
Field of Fractions of M
> FF;
Finite field of size 5^3
> h := hom< F -> FF | Coercion(Rationals(), FF), 3*FF.1>;
> h;
Mapping from: FldOrd: F to FldFin: FF
> h(a); h(b);
1

>> h(a); h(b);
          ^
Runtime error in map application: Application of map failed
> h(5*b); h(5*5*c); h(5*5*5*d);
FF.1^94
FF.1^64
FF.1^34

```

This unexpected behaviour occurs because when the basis of $F$ is expressed with respect to the power basis of the number field they have denominator divisible by $5$. A more well–behaved example is shown below.

```magma
> FF := FiniteField(11, 5);
> h := hom< F -> FF | Coercion(Rationals(), FF), 7*FF.1>;
> h(a);
1
> h(b); h(c); h(d);
FF.1^48316
FF.1^96632
FF.1^144948
> 7*FF.1;
FF.1^112736
> 5*h(b);
FF.1^112736
> PrimitiveElement(F);
5/1*b

```

### `hom< O -> R | b₁, ..., bₙ >: RngFunOrd, Rng, RngElt, ..., RngElt -> Map`

### `hom< O -> R | m, b₁, ..., bₙ >: RngFunOrd, Rng, Map, RngElt, ..., RngElt -> Map`

Return the map from the order $O$ of an algebraic number field to the ring $R$ mapping the basis elements to $b_1, .., b_n$. If given, the map $m$ should be from the coefficient ring of $O$ to $R$ and will be used to map the coefficients of the basis elements. If not given the coefficient ring of $O$ should by covered by $R$.

### `IsRingHomomorphism(m): Map -> BoolElt`

Return whether the vector space homomorphism $m$ is a homomorphism of rings.
