# Structure Operations

In the lists below $K$ always denotes a number field.

## General Functions

Number fields form the Magma category `FldNum`. The notional power structures exist as parents of algebraic fields with no operations are allowed.

### `Category(K): FldNum -> Cat`

### `Type(K): FldNum -> Cat`

### `ExtendedType(K): FldNum -> Cat`

### `Parent(K): FldNum -> Pow`

### `AssignNames(~K, s): FldNum, [ MonStgElt ]`

Procedure to change the names of the generating elements in the number field $K$ to the contents of the sequence of strings $s$. The $i$-th sequence element will be the name used for the generator of the $(i-1)$-st subfield down from $K$ as determined by the creation of $K$, the first element being used as the name for the generator of $K$. In the case where $K$ is defined by more than one polynomial as an absolute extension, the $i$th sequence element will be the name used for the root of the $i$th polynomial used in the creation of $K$. This procedure only changes the names used in printing the elements of $K$. It does *not* assign to any identifiers the value of a generator in $K$; to do this, use an assignment statement, or use angle brackets when creating the field. Note that since this is a procedure that modifies $K$, it is necessary to have a reference `~K` to $K$ in the call to this function.

### `Name(K, i): FldNum, RngIntElt -> FldNumElt`

### `K . i: FldNum, RngIntElt -> FldNumElt`

Given a number field $K$, return the element which has the $i$-th name attached to it, that is, the generator of the $(i - 1)$-st subfield down from $K$ as determined by the creation of $K$. Here $i$ must be in the range $1\leq i\leq m$, where $m$ is the number of polynomials used in creating $K$. If $K$ was created using multiple polynomials as an absolute extension, `K.i` will be a root of the $i$th polynomial used in creating $K$.

## Related Structures

Each number field has other structures related to it in various ways.

### `GroundField(F): FldNum -> Fld`

### `BaseField(F): FldNum -> Fld`

### `CoefficientField(F): FldNum -> Fld`

### `CoefficientRing(F): FldNum -> Fld`

Given a number field $F$, return the number field over which $F$ was defined. For an absolute number field $F$, the function returns the rational field ${\mathbb{Q}}$.

### `AbsoluteField(F): FldNum -> FldNum`

Given a number field $F$, this returns an isomorphic number field $L$ defined as an absolute extension (i.e. over ${\mathbb{Q}}$). (For algorithm, see [[Trager, 1976](../../references.md#cite-trager-factorization)])

### `SimpleExtension(F): FldNum -> FldNum`

Given a number field $F$ or an order $O$, this returns an isomorphic field $L$ defined as an absolute simple extension. (For algorithm, see [[Trager, 1976](../../references.md#cite-trager-factorization)])

### `RelativeField(F, L): FldNum, FldNum -> FldNum`

### `RelativeField(Q, L): FldRat, FldNum -> FldNum`

Given number fields $L$ and $F$ such that Magma knows that $F$ is a subfield of $L$, return an isomorphic number field $M$ defined as an extension over $F$.

### `Components(F): FldNum -> [FldNum]`

Given a number field $F$ return the sequence of number fields each defined by a defining polynomial of $F$.

### `Example: Compositum (ex-e3e873)`

It is often desirable to build up a number field by adjoining several algebraic numbers to ${\mathbb{Q}}$. The following function returns a number field that is the composite field of two given number fields $K$ and $L$, provided that $K\cap L={\mathbb{Q}}$; if $K$ and $L$ have a common subfield larger than ${\mathbb{Q}}$ the function returns a field with the property that it contains a subfield isomorphic to $K$ as well as a subfield isomorphic to $L$.

```magma
> R<x> := PolynomialRing(Integers());
> Composite := function( K, L )
>     T<y> := PolynomialRing( K );
>     f := T!DefiningPolynomial( L );
>     ff := Factorization(f);
>     LKM := NumberField(ff[1][1]);
>     return AbsoluteField(LKM);
> end function;

```

To create, for example, the field ${\mathbb{Q}}(\sqrt{2}, \sqrt{3}, \sqrt{5})$, the above function should be applied twice:

```magma
> K := NumberField(x^2-3);
> L := NumberField(x^2-2);
> M := NumberField(x^2-5);
> KL := Composite(K, L);
> S<s> := PolynomialRing(BaseField(KL));
> KLM<w> := Composite(KL, M);
> KLM;
Number Field with defining polynomial s^8 - 40*s^6 + 352*s^4 - 960*s^2 + 576
over the Rational Field

```

Note, that the same field may be constructed with just one call to [`NumberField`](creation.md#function-fldnum-numberfield) followed by [`AbsoluteField`](#function-fldnum-absolutefield):

```magma
> KLM2 := AbsoluteField(NumberField([x^2-3, x^2-2, x^2-5]));
> KLM2;
Number Field with defining polynomial s^8 - 40*s^6 + 352*s^4 - 960*s^2 + 576
over the Rational Field

```

or by

```magma
> AbsoluteField(ext<Rationals() | [x^2-3, x^2-2, x^2-5]>);
Number Field with defining polynomial s^8 - 40*s^6 + 352*s^4 - 960*s^2 + 576
over the Rational Field

```

In general, however, the resulting polynomials of $KLM$ and $KLM2$ will differ. To see the difference between `SimpleExtension` and `AbsoluteField`, we will create `KLM2` again:

```magma
> KLM3 := NumberField([x^2-3, x^2-2, x^2-5]: Abs);
> AbsoluteField(KLM3);
Number Field with defining polynomials [ x^2 - 3, x^2 - 2,
    x^2 - 5] over the Rational Field
> SimpleExtension(KLM3);
Number Field with defining polynomial s^8 - 40*s^6 + 352*s^4 - 960*s^2 + 576
over the Rational Field

```

### `PrimeRing(F): FldNum -> RngRat`

### `PrimeField(F): FldNum -> RngRat`

### `Centre(F): FldNum -> FldNum`

### `Embed(F, L, a): FldNum, FldNum, FldNumElt`

```magma
Overwrite: BoolElt                    Default: false
```

Install the embedding of a simple number field $F$ in $L$ where the image of the primitive element of $F$ is the element $a$ of $L$. This embedding will be used in coercing from $F$ into $L$.

If the addition of this embedding causes an inconsistency with currently known embeddings then the embedding will not be added unless `Overwrite` is set to `true`.

### `Embed(F, L, a): FldNum, FldNum, [FldNumElt]`

```magma
Overwrite: BoolElt                    Default: false
```

Install the embedding of the non-simple number field $F$ in $L$ where the image of the generating elements of $F$ are in the sequence $a$ of elements of $L$. This embedding will be used in coercing from $F$ into $L$.

If the addition of this embedding causes an inconsistency with currently known embeddings then the embedding will not be added unless `Overwrite` is set to `true`.

### `EmbeddingMap(F, L): FldNum, FldNum -> Map`

Returns the embedding map of the number field $F$ in $L$ if an embedding is known.

### `Example: em (ex-909e79)`

Magma does not recognize two independently created number fields as equal since more than one embedding of a field in a larger field may be possible. To coerce between them, it is convenient to be able to embed them in each other.

```magma
> k := NumberField(x^2-2);
> l := NumberField(x^2-2);
> l!k.1;
>> l!k.1;
    ^
Runtime error in '!': Arguments are not compatible
LHS: FldNum
RHS: FldNumElt
> l eq k;
false
> Embed(k, l, l.1);
> l!k.1;
l.1
> Embed(l, k, k.1);
> k!l.1;
k.1

```

`Embed` is useful in specifying the embedding of a field in a larger field.

```magma
> l<a> := NumberField(x^3-2);
> L<b> := NumberField(x^6+108);
> Root(L!2, 3);
1/18*b^4
> Embed(l, L, $1);
> L!l.1;
1/18*b^4

```

Another embedding would be

```magma
> Roots(PolynomialRing(L)!DefiningPolynomial(l));
[
    <1/36*(-b^4 - 18*b), 1>,
    <1/36*(-b^4 + 18*b), 1>,
    <1/18*b^4, 1>
]
> Embed(l, L, $1[1][1] : Overwrite := true);
> L!l.1;
1/36*(-b^4 - 18*b)

```

### `MinkowskiSpace(F): FldNum -> Lat, Map`

The Minkowski vector space $V$ of the absolute number field $F$ as a real vector space, with inner product given by the $T_2$-norm ([`Length`](../NumberFieldsAndOrders/operation-element.md#function-rngord-length)) on $F$, and by the embedding $F \rightarrow V$.

### `Completion(K, P): FldNum, RngOrdIdl -> FldLoc, Map`

### `comp<K|P>: FldNum, RngOrdIdl -> FldLoc, Map`

```magma
Precision: RngIntElt                    Default: 20
```

For an absolute extension $K$ of ${\mathbb{Q}}$, compute the completion at a prime ideal $P$ which must be either a prime ideal of the maximal order or unramified. The result will be a local field or ring with default precision `Precision`.

The returned map is the canonical injection into the completion. It allows pointwise inverse operations.

### `Completion(K, P): FldNum, PlcNumElt -> FldLoc, Map`

```magma
Precision: RngIntElt                    Default: 20
```

For an absolute extension $K$ over ${\mathbb{Q}}$ and a (finite) place $P$, compute the completion at $P$. The precision and the map are as described for [`Completion`](#function-fldnum-completion1).

## Representing Fields as Vector Spaces

It is possible to express a number field as a vector space of any subfield using the intrinsics below. Such a construction also allows one to find properties of elements over these subfields.

### `Algebra(K, J): FldNum, Fld -> AlgAss, Map`

### `Algebra(K, J, S): FldNum, Fld, [FldNumElt] -> AlgAss, Map`

Returns the associative structure constant algebra which is isomorphic to the number field $K$ as an algebra over $J$. Also returns the isomorphism from $K$ to the algebra mapping $w^i$ to the $i + 1$st unit vector of the algebra where $w$ is a primitive element of $K$.

If a sequence $S$ is given it is taken to be a basis of $K$ over $J$ and the isomorphism will map the $i$th element of $S$ to the $i$th unit vector of the algebra.

### `VectorSpace(K, J): FldNum, Fld -> ModTupFld, Map`

### `KSpace(K, J): FldNum, Fld -> ModTupFld, Map`

### `VectorSpace(K, J, S): FldNum, Fld, [FldNumElt] -> ModTupFld, Map`

### `KSpace(K, J, S): FldNum, Fld, [FldNumElt] -> ModTupFld, Map`

The vector space isomorphic to the number field $K$ as a vector space over $J$ and the isomorphism from $K$ to the vector space. The isomorphism maps $w^i$ to the $i + 1$st unit vector of the vector space where $w$ is a primitive element of $K$.

If $S$ is given, the isomorphism will map the $i$th element of $S$ to the $i$th unit vector of the vector space.

### `Example: Vector Space Eg (ex-3f6dca)`

We use the `Algebra` of a relative number field to obtain the minimal polynomial of an element over a subfield which is not in its coefficient field tower.

```magma
> K := NumberField([x^2 - 2, x^2 - 3, x^2 - 7]);
> J := AbsoluteField(NumberField([x^2 - 2, x^2 - 7]));
> A, m := Algebra(K, J);
> A;
Associative Algebra of dimension 2 with base ring J
> m;
Mapping from: RngOrd: K to AlgAss: A
> m(K.1);
(1/10*(J.1^3 - 13*J.1)                      0)
> m(K.1^2);
(2 0)
> m(K.2);
(1/470*(83*J.1^3 + 125*J.1^2 - 1419*J.1 - 1735) 1/940*(-24*J.1^3 - 5*J.1^2 +
    382*J.1 + 295))
> m(K.2^2);
(3 0)
> m(K.3);
(1/10*(-J.1^3 + 23*J.1)                       0)
> m(K.3^2);
(7 0)
> A.1 @@ m;
1
> A.2 @@ m;
(($.1 - 1)*$.1 - $.1 - 1)*K.1 + ($.1 + 1)*$.1 + $.1 + 1
>
> r := 5*K.1 - 8*K.2 + K.3;
> m(r);
(1/235*(-238*J.1^3 - 500*J.1^2 + 4689*J.1 + 6940) 1/235*(48*J.1^3 + 10*J.1^2 -
    764*J.1 - 590))
> MinimalPolynomial($1);
$.1^2 + 1/5*(-4*J.1^3 + 42*J.1)*$.1 + 5*J.1^2 - 180
> Evaluate($1, r);
0
> K:Maximal;

  K
  |
  |
  $1
  |
  |
  $2
  |
  |
  Q

K  : $.1^2 - 2
$1 : $.1^2 - 3
$2 : x^2 - 7
> Parent($3);
Univariate Polynomial Ring over J
> J;
Number Field with defining polynomial $.1^4 - 18*$.1^2 + 25 over the Rational
Field

```

## Invariants

Some information describing a number field can be retrieved.

### `Characteristic(F): FldNum -> RngIntElt`

### `Degree(F): FldNum -> RngIntElt`

Given a number field $F$, return the degree $[F:G]$ of $F$ over its ground field $G$.

### `AbsoluteDegree(F): FldNum -> RngIntElt`

Given a number field $F$, return the absolute degree of $F$ over ${\mathbb{Q}}$.

### `Discriminant(F): FldNum -> RngIntElt`

### `Discriminant(F): FldNum -> RngOrdIdl`

Given an extension $F$ of ${\mathbb{Q}}$, return the discriminant of $F$. This discriminant is defined to be the discriminant of the defining polynomial, **not** as the discriminant of the maximal order.

The discriminant in a relative extension $F$ is the ideal in the base ring generated by the discriminant of the defining polynomial.

### `AbsoluteDiscriminant(K): FldNum -> FldRatElt`

Given a number field $K$, return the absolute value of the discriminant of $K$ regarded as an extension of ${\mathbb{Q}}$.

### `Regulator(K): FldNum -> FldComElt`

Given a number field $K$, return the regulator of $K$ as a real number. Note that this will trigger the computation of the maximal order and its unit group if they are not known yet. This only works in an absolute extension.

### `RegulatorLowerBound(K): FldNum -> FldComElt`

Given a number field $K$, return a lower bound on the regulator of $O$ or $K$. This only works in an absolute extension.

### `Signature(F): FldAlg -> RngIntElt, RngIntElt`

Given an absolute number field $F$, returns two integers, one being the number of real embeddings, the other the number of pairs of complex embeddings of $F$.

### `UnitRank(K): FldNum -> RngIntElt`

The unit rank of the number field $K$ (one less than the number of real embeddings plus number of pairs of complex embeddings).

### `DefiningPolynomial(F): FldNum -> RngUPolElt`

### `DefiningPolynomial(F): FldNum -> [RngUPolElt]`

Given a number field $F$, the polynomial defining $F$ as an extension of its ground field $G$ is returned.

For non simple extensions, this will return a list of polynomials.

### `Zeroes(F, n): FldNum, RngIntElt -> [ FldComElt ]`

Given an absolute number field $F$, and an integer $n$, return the zeroes of the defining polynomial of $F$ with a precision of exactly $n$ decimal digits. The function returns a sequence of length the degree of $F$; all of the real zeroes appear before the complex zeroes.

### `Example: zero (ex-e63cd9)`

The information provided by `Zeros` and `DefiningPolynomial` is illustrated below.

```magma
> L := NumberField(x^6+108);
> DefiningPolynomial(L);
x^6 + 108
> Zeros(L, 30);
[ 1.889881574842309747150815910899999999994 +
1.0911236359717214035600726141999999999977*i,
1.889881574842309747150815910899999999994 -
1.0911236359717214035600726141999999999977*i,  0.E-29 +
2.1822472719434428071201452283999999999955*i,  0.E-29 -
2.1822472719434428071201452283999999999955*i,
-1.889881574842309747150815910899999999994 +
1.0911236359717214035600726141999999999977*i,
-1.889881574842309747150815910899999999994 -
1.0911236359717214035600726141999999999977*i ]
> l := NumberField(x^3 - 2);
> DefiningPolynomial(l);
x^3 - 2
> Zeros(l, 30);
[ 1.259921049894873164767210607299999999994,
-0.629960524947436582383605303639109999999 +
1.0911236359717214035600726141999999999977*i,
-0.629960524947436582383605303639109999999 -
1.0911236359717214035600726141999999999977*i ]

```

## Basis Representation

The basis of a number field can be expressed using elements from any compatible ring.

### `Basis(F): FldNum -> [ FldNumElt ]`

### `Basis(F, R): FldNum, Rng -> [ RngElt ]`

Return the current basis for the number field $F$ over its ground ring as a sequence of elements of $F$ or as a sequence of elements of $R$.

### `IntegralBasis(F): FldNum -> [ FldNumElt ]`

### `IntegralBasis(F, R): FldNum, Rng -> [ RngElt ]`

An integral basis for the algebraic number field $F$ is returned as a sequence of elements of $F$ or $R$ if given. This is the same as the basis for the maximal order. Note that the maximal order will be determined (and stored) if necessary.

### `Example: Basis Ring (ex-49b3f2)`

The following illustrates how a basis can look different when expressed in a different ring.

```magma
> f := x^5 + 5*x^4 - 75*x^3 + 250*x^2 + 65625;
> N := NumberField(f);
> N;
Number Field with defining polynomial x^5 + 5*x^4 - 75*x^3 + 250*x^2 + 65625
over the Rational Field
> Basis(N);
[
    1,
    N.1,
    N.1^2,
    N.1^3,
    N.1^4
]
> IntegralBasis(N);
[
    1,
    1/5*N.1,
    1/25*N.1^2,
    1/125*N.1^3,
    1/625*N.1^4
]
> IntegralBasis(N, MaximalOrder(N));
[
    [1, 0, 0, 0, 0],
    [0, 1, 0, 0, 0],
    [0, 0, 1, 0, 0],
    [0, 0, 0, 1, 0],
    [0, 0, 0, 0, 1]
]

```

### `AbsoluteBasis(K): FldNum -> [FldNumElt]`

Returns an absolute basis for the number field $K$, i.e. a basis for $K$ as a ${\mathbb{Q}}$ vector space. The basis will consist of the products of the basis elements of the intermediate fields. The expansion is done depth-first.

### `Example: Bases (ex-0dc237)`

We continue our example of a field of degree 4. The functions `Basis` and `IntegralBasis` both return a sequence of elements, that can be accessed using the operators for enumerated sequences. Note that if, as in our example, $O$ is the maximal order of $K$, both functions produce the same output:

```magma
> R<x> := PolynomialRing(Integers());
> f := x^4 - 420*x^2 + 40000;
> K<y> := NumberField(f);
> O := MaximalOrder(K);
> I := IntegralBasis(K);
> B := Basis(O);
> I, B;
[
    1,
    1/2*y,
    1/40*(y^2 + 10*y),
    1/800*(y^3 + 180*y + 400)
]
[
    O.1,
    O.2,
    O.3,
    O.4
]
> Basis(O, K);
[
    1,
    1/2*y,
    1/40*(y^2 + 10*y),
    1/800*(y^3 + 180*y + 400)
]

```

## Ring Predicates

Number fields can be tested for having several properties that may hold for general rings.

### `F eq L: FldNum, FldNum -> BoolElt`

### `F eq L: FldRat, FldNum -> BoolElt`

### `F eq L: FldNum, FldRat -> BoolElt`

Returns `true` if and only if the number fields $F$ and $L$ are indentical. No two number fields which have been created independently of each other will be considered equal since it is possible that they can be embedded into a larger field in more than one way.

### `IsCommutative(R): Rng -> BoolElt`

### `IsUnitary(R): Rng -> BoolElt`

### `IsFinite(R): Rng -> BoolElt`

### `IsOrdered(R): Rng -> BoolElt`

### `IsField(R): Rng -> BoolElt`

### `IsNumberField(R): . -> BoolElt`

### `IsAlgebraicField(R): . -> BoolElt`

### `IsEuclideanDomain(F): FldNum -> BoolElt`

This is not a check for euclidean number fields. This function will always return `true`, as all number fields are euclidean domains.

### `IsSimple(F): FldNum -> BoolElt`

Checks if the number field $F$ is defined as a simple extension over the base ring.

### `IsPID(F): FldNum -> BoolElt`

### `IsUFD(F): FldNum -> BoolElt`

### `IsPrincipalIdealRing(F): FldNum -> BoolElt`

Always `true` for number fields.

### `IsDomain(R): FldNum -> BoolElt`

### `F ne L: FldNum, FldNum -> BoolElt`

### `K subset L: FldNum, FldNum -> BoolElt`

### `K subset L: FldRat, FldNum -> BoolElt`

### `HasComplexConjugate(K): FldNum -> BoolElt, Map`

This function returns `true` if there is an automorphism in the number field $K$ that acts like complex conjugation.

### `ComplexConjugate(x): FldNumElt -> FldNumElt`

For an element $x$ of a number field $K$ where [`HasComplexConjugate`](#function-fldnum-hascomplexconjugate) returns `true` (in particular this includes totally real fields, cyclotomic and quadratic fields and CM-extensions), the conjugate of $x$ is returned.

## Field Predicates

Here all the predicates that are specific to number fields are listed.

### `IsIsomorphic(F, L): FldNum, FldNum -> BoolElt, Map`

Given two number fields $F$ and $L$, this returns `true` as well as an isomorphism $F\rightarrow L$, if $F$ and $L$ are isomorphic, and it returns `false` otherwise.

### `IsSubfield(F, L): FldNum, FldNum -> BoolElt, Map`

### `IsSubfield(F, L): FldRat, FldNum -> BoolElt, Map`

Given two number fields $F$ and $L$, this returns `true` as well as an embedding $F\hookrightarrow L$, if $F$ is a subfield of $L$, and it returns `false` otherwise.

### `IsNormal(F): FldNum -> BoolElt`

Returns `true` if and only if the number field $F$ is a normal extension. At present this may only be applied if $F$ is an absolute extension or simple relative extension. In the relative case the result is obtained via Galois group computation.

### `IsAbelian(F): FldNum -> BoolElt`

Returns `true` if and only if the number field $F$ is a normal extension with abelian Galois group. At present this may only be applied if $F$ is an absolute extension or simple relative extension. In the relative case the result is obtained via Galois Group computation.

### `IsCyclic(F): FldNum -> BoolElt`

Returns `true` if and only if the number field $F$ is a normal extension with cyclic Galois group. At present this may only be applied if $F$ is an absolute extension or simple relative extension. In the relative case the result is obtained via Galois and automorphism group.

### `IsAbsoluteField(K): FldNum -> BoolElt`

Returns `true` iff the number field $K$ is a constructed as an absolute extension of ${\mathbb{Q}}$.
