Number fields

Rings of integers

In Q(5)\mathbb{Q}(\sqrt5) the number (1+5)/2(1+\sqrt5)/2 is a root of x2−x−1x^2 - x - 1: it has a denominator, yet it behaves like a whole number. The algebraic integers of a number field form a ring, a lattice of rank nn inside the field, and finding a basis of it is the first step of everything else: discriminants, prime ideals, class groups, units.

A field and its integers

A number field is K=Q(α)K = \mathbb{Q}(\alpha) for a root α\alpha of an irreducible polynomial; here it is a NumberField from @ratmath/algebraic (re-exported), or just the coefficients of the polynomial, constant first. An element of KK is an algebraic integer when it is a root of a monic polynomial with whole coefficients. They form the ring OK\mathcal{O}_K, and OK\mathcal{O}_K has a basis ω1=1,ω2,…,ωn\omega_1 = 1, \omega_2, \dots, \omega_n over Z\mathbb{Z}: an integral basis.

import { NumberField, ringOfIntegers } from "@ratmath/numtheory";

const K = new NumberField([-8n, -2n, -1n, 1n]);   // α³ − α² − 2α − 8 = 0, Dedekind's field
const O = ringOfIntegers(K);
O.basis;            // 1, α, (1/2)α + (1/2)α²
O.discriminant;     // -503n
O.index;            // 2n: Z[α] has index 2 in the ring of integers
O.signature;        // [1, 1]: one real embedding, one pair of complex ones

O.contains(K.gen.mul(K.gen).add(K.gen).div(K.of(2n)));   // true: (α² + α)/2 is an integer
O.coordinates(K.gen.mul(K.gen));                         // 0, -1, 2: α² = −ω₂ + 2ω₃
String(O.element([0, 0, 1]));                            // "(1/2)α + (1/2)α²"

The quadratic case is the familiar one: Z[d]\mathbb{Z}[\sqrt d] when d≡2,3(mod4)d \equiv 2, 3 \pmod 4, and Z[(1+d)/2]\mathbb{Z}[(1+\sqrt d)/2] when d≡1(mod4)d \equiv 1 \pmod 4.

ringOfIntegers(NumberField.quadratic(5)).basis;     // 1, 1/2 + (1/2)√5
ringOfIntegers(NumberField.quadratic(-5)).basis;    // 1, √(-5)
ringOfIntegers([-19n, 0n, 0n, 1n]).basis;           // 1, α, 1/3 + (1/3)α + (1/3)α²   (α³ = 19)

The discriminant

The discriminant of the field is dK=det⁡(Tr⁡(ωiωj))d_K = \det\big(\operatorname{Tr}(\omega_i\omega_j)\big), the squared volume of the lattice OK\mathcal{O}_K. It does not depend on the basis. For the lattice Z[α]\mathbb{Z}[\alpha] the same determinant is the discriminant of the polynomial, and the two differ by the square of the index:

disc⁡(f)=[OK:Z[α]]2⋅dK. \operatorname{disc}(f) = [\mathcal{O}_K : \mathbb{Z}[\alpha]]^2 \cdot d_K.

So only primes whose square divides disc⁡(f)\operatorname{disc}(f) can divide the index. For Dedekind's field, disc⁡(f)=−2012=−22⋅503\operatorname{disc}(f) = -2012 = -2^2 \cdot 503, and the index is 2.

O.polyDiscriminant;     // -2012n
O.traceMatrix;          // [[3, 1, 3], [1, 5, 18], [3, 18, 29]], with determinant −503
fieldDiscriminant([1n, 1n, 1n, 1n, 1n]);    // 125n: the fifth roots of unity
fieldDiscriminant([-2n, 0n, 0n, 0n, 1n]);   // -2048n: Q(⁴√2)
O.ramifiedPrimes;       // [503n]: the primes dividing the discriminant

How the basis is found: Round 2

Start with the order O=Z[θ]\mathcal{O} = \mathbb{Z}[\theta], where θ\theta is α\alpha scaled to be integral, and enlarge it one prime at a time. For a prime pp, let IpI_p be the radical of pOp\mathcal{O}: the elements with some power in pOp\mathcal{O}. The theorem of Pohst and Zassenhaus says that

O′={x∈K:xIp⊆Ip} \mathcal{O}' = \{ x \in K : x I_p \subseteq I_p \}

is an order containing O\mathcal{O}, and that O′=O\mathcal{O}' = \mathcal{O} exactly when O\mathcal{O} is already maximal at pp. Both steps are linear algebra over Fp\mathbb{F}_p. The radical is the kernel of x↦xpkx \mapsto x^{p^k} on O/pO\mathcal{O}/p\mathcal{O} once pk≥np^k \ge n (or of the trace form when p>np > n), and O′\mathcal{O}' comes from the kernel of the map sending xx to multiplication by xx on Ip/pIpI_p/pI_p. Repeat until nothing grows, for each pp with p2∣disc⁡(f)p^2 \mid \operatorname{disc}(f).

O.steps;
// [{ p: 2n, exponent: 2, indexExponent: 1, rounds: 1, note: "the order grows by index 2 in 1 round" }]

ringOfIntegers([-19n, 0n, 0n, 1n]).steps.map((s) => s.note);
// ["the order grows by index 3 in 1 round", "already maximal at 19"]

The polynomial need not be monic or have whole coefficients: the generator is rescaled inside, and O.scale says by how much. The discriminant of the polynomial has to be factored, which is the one step that can be slow for large coefficients.

Why Dedekind's field is famous

One might hope that OK=Z[β]\mathcal{O}_K = \mathbb{Z}[\beta] for a well-chosen β\beta, as in quadratic fields. In Dedekind's field no β\beta works. The prime 2 splits into three different prime ideals of norm 2 (see Prime ideals); if OK\mathcal{O}_K were Z[β]\mathbb{Z}[\beta], those primes would correspond to three different linear factors of a cubic modulo 2, and there are only two linear polynomials modulo 2. So every Z[β]\mathbb{Z}[\beta] has even index.

Next: how primes factor in OK\mathcal{O}_K, in Prime ideals; then Class groups and Units.

Try itEdit the code and run it with @ratmath/numtheory and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs