Six is two times three — and something else
Fermat claimed in 1640 that an odd prime is a sum of two squares exactly when it leaves remainder on division by : , , but and are not sums of two squares. In the Gaussian integers the statement becomes a statement about factorisation: , so the primes split in while those stay prime. Since has unique factorisation, this can be proved by arithmetic in .
The method seems to promise a proof of much more. In 1847 Gabriel Lamé announced to the Paris Academy a proof of Fermat's Last Theorem, factoring
in . Joseph Liouville immediately asked whether has unique factorisation; Ernst Kummer had already shown that for it does not. The simplest failure is in :
and , , are all irreducible (proved below, and in Lean). Kummer's response was to invent "ideal numbers" — the missing common factors — and Dedekind turned them into ideals. With ideals, factorisation is unique again; the class group measures how far ideals are from being numbers, and the unit group measures the other ambiguity in factorisation.
Algebraic number theory studies number fields — finite extensions of — through their rings of integers. This lesson assumes elementary number theory (quadratic residues), field extensions and commutative algebra (integral extensions, Noetherian rings, localisation).
Ideal numbers
In , the numbers and "ought" to have a common factor with — but no element has norm (the norm of is ), so no such element exists. Kummer and Dedekind replace the missing gcd by the set of all its "multiples", which does exist:
These ideals are prime, not principal, and
So both factorisations of are regroupings of the single ideal factorisation , exactly as regroups in . The non-principal ideals are the ghosts of the missing numbers. Since is principal, the ghost has order in the class group, which here is : every non-principal ideal of becomes principal when multiplied by .
Geometrically, a ring of integers is a lattice: is the lattice spanned by and in , and its non-zero ideals are sublattices of finite index (the index is the norm of the ideal).
Definitions
Definition— number field, algebraic integers, ring of integers
A number field is a field with . An element is an algebraic integer if it is a root of a monic polynomial with coefficients in . The algebraic integers of form a subring , the ring of integers (Proposition 1). For , : a rational root of a monic integer polynomial is an integer.
Definition— embeddings, norm, trace
A number field of degree has exactly field embeddings ; of them are real () and the others come in complex-conjugate pairs, so . The norm and trace of are and — the determinant and trace of multiplication by on the -vector space . Both are rational, the norm is multiplicative, and both are integers when . For , and .
Definition— integral basis and discriminant
An integral basis is a -basis of (one exists: , Proposition 3). The discriminant of is , a non-zero integer independent of the choice of integral basis. Its sign is , and the primes that ramify in are exactly those dividing .
Definition— Dedekind domain; fractional ideals; class group
A Dedekind domain is a Noetherian, integrally closed domain in which every non-zero prime ideal is maximal. For a domain with fraction field , a fractional ideal is a non-zero -submodule with for some non-zero ; products are defined as for ideals. The principal fractional ideals are , . The ideal class group of a number field is the group of fractional ideals of modulo the principal ones (a group by Theorem 4), and the class number is .
Definition— norm of an ideal; splitting of primes
The norm of a non-zero ideal is ; it is multiplicative, and . For a rational prime , write (Theorem 4). The exponent is the ramification index and the residue degree; comparing norms gives . In a quadratic field there are three possibilities: splits ( with ), is inert ( is prime), or ramifies ().
Definition— units
The unit group consists of the elements with inverses in , equivalently those of norm . Its torsion subgroup is the finite cyclic group of roots of unity in .
Examples
Example— Quadratic fields
For squarefree and (Theorem 2):
| units | ||||
|---|---|---|---|---|
| , | the six roots of unity | |||
| , | ||||
| , |
The golden ratio is an algebraic integer () although its coordinates are halves: is not the whole ring of integers of .
Example— Factorisations in the Gaussian integers
is Euclidean for the norm , hence a PID and a UFD, with . Its primes lie over rational primes as follows: ramifies; splits, e.g. and ; is inert, e.g. and stay prime. Fermat's two-squares theorem is exactly the statement that splits.
Example— Factorisations in ℤ[√−5]
Using the Dedekind–Kummer theorem (Theorem 5) with :
- : , so with — ramified.
- : , so — ramified, with a principal prime.
- : , so — split into non-principal primes (no element has norm ).
- : , so splits, and here the primes are principal: .
- : is not a square mod , so is inert.
The first experiment shows the pattern: an odd prime splits when and is inert when ; among the split primes, the factors are principal exactly for .
Example— Cyclotomic fields
For a prime and , has degree (the cyclotomic polynomial is irreducible by Eisenstein's criterion applied to ), , , ring of integers and discriminant (both formalised in Mathlib). The prime is totally ramified: . A prime splits into primes, where is the order of modulo . Kummer proved Fermat's Last Theorem for exponent whenever does not divide the class number of (a regular prime); exactly for (Montgomery and Uchida, 1971), and is the first irregular prime.
The main theorems
Theorem— Proposition 1 (integrality)
For in a field the following are equivalent: (a) is an algebraic integer; (b) is a finitely generated -module; (c) lies in a subring of that is a finitely generated -module. Consequently the algebraic integers of form a ring. Moreover, an algebraic number is an algebraic integer exactly when its minimal polynomial over has integer coefficients.
Proof
(a ⇒ b) If with , every power of is a -combination of . (b ⇒ c) is clear. (c ⇒ a) Let be a subring containing . Then with , so ; multiplying by the adjugate gives for all , and since , — a monic integer equation for . If are algebraic integers, is generated by the finitely many with below the degrees of their equations, and contains and , which are therefore integral by (c). For the last statement: if is integral with monic integer equation , its minimal polynomial divides ; the roots of are roots of , hence algebraic integers, so the coefficients of (symmetric functions of the roots) are algebraic integers and rational, hence integers. The converse is the definition.
∎
Theorem— Theorem 2 (rings of integers of quadratic fields)
Let be squarefree and . Then
Proof
Let with and (rationals are integral only if integers). Its minimal polynomial is , so by Proposition 1, iff and . Then , so . Writing in lowest terms, with , so , and because is squarefree: . The condition is now . Squares are or mod . If or , then forces both even, i.e. . If , the condition is , i.e. : with . In both cases the ring is with or , and , which is or .
∎
Theorem— Proposition 3 (rings of integers are Dedekind domains)
is a free -module of rank , and it is a Dedekind domain. For every non-zero ideal , is finite.
Proof
Every non-zero ideal meets . If , then ; the second factor lies in and is an algebraic integer (a product of conjugates of ), hence in . So .
Freeness (sketch). Choose a -basis of inside (multiply any basis by integers) and let (the trace form is non-degenerate in characteristic zero). If with , then , and Cramer's rule gives . So , and a subgroup of a free abelian group of rank containing a free subgroup of rank is free of rank .
Dedekind. is Noetherian, since every ideal is a subgroup of , hence finitely generated. It is integrally closed in : an element of integral over is integral over (transitivity of integrality, via Proposition 1(c)), so lies in . If with , then is a quotient of , so it is finite. Finally, for a non-zero prime , is a finite integral domain, hence a field (multiplication by a non-zero element is injective, hence surjective), so is maximal.
∎
Theorem— Theorem 4 (unique factorisation of ideals)
Let be a Dedekind domain. Every non-zero proper ideal of is a product of non-zero prime ideals, uniquely up to order. The fractional ideals form a free abelian group on the non-zero primes, and for ideals, if and only if divides ("to contain is to divide").
Proof
Let be the fraction field. For a non-zero prime put , an -module containing .
Lemma A: every non-zero ideal contains a product of non-zero primes. If not, since is Noetherian there is a maximal counterexample . It is not prime (a prime contains itself) and not , so there are with . The ideals and are strictly larger, so contain products of primes, and their product, contained in , does too — a contradiction.
Lemma B: for every non-zero ideal , . First, : pick and, by Lemma A, primes with and minimal. Since is prime, it contains some , say , and then because non-zero primes are maximal. By minimality (for read this product as , and note is not a unit), so there is . Then , i.e. , but . Now let and suppose . For write with ; the determinant trick gives , so is integral over , hence because is integrally closed. Thus , a contradiction.
Lemma C: . Indeed , the first inclusion is strict by Lemma B, and is maximal.
Existence. Suppose some non-zero proper ideal has no factorisation, and let be a maximal one. Choose a maximal ideal . Then . If then , which factors; otherwise factors by maximality, , and then . Either way a contradiction.
Uniqueness. If , then the prime contains some , hence equals it; multiplying by (Lemma C) cancels it, and induction finishes.
Group and divisibility. A fractional ideal has , so is a quotient of products of primes, each invertible by Lemma C. If then is an ideal with ; the converse is clear.
∎
The hypothesis "integrally closed" is used exactly once, in Lemma B, and it is necessary: in the non-integrally-closed ring , the ideal satisfies but , so is not invertible and factorisation is not unique; passing to repairs this.
Theorem— Theorem 5 (Dedekind–Kummer)
Suppose , let be the minimal polynomial of , and let be prime. If in with distinct monic irreducible , and are any monic lifts, then
with the distinct primes. In particular, for a quadratic field and an odd prime , splits if and is inert if ; the ramified primes are those dividing .
Proof
Reduction of coefficients gives . The primes of containing correspond to the primes of this ring, i.e. to the ideals ; explicitly, is the kernel of , , which is , with residue field of degree , so . Next, , and with , so . Hence , i.e. divides (Theorem 4). Comparing norms, and , so the two ideals are equal. For a quadratic field with (or , whose minimal polynomial has discriminant ), has two distinct roots, no roots or a double root according as its discriminant is a non-zero square, a non-square or zero modulo .
∎
(The theorem holds more generally when does not divide the index ; Mathlib proves this form.) So in : splits iff is a non-zero square mod , and by quadratic reciprocity this depends only on — the residues found by the first experiment.
Theorem— Theorem 6 (UFD ⇔ PID for Dedekind domains)
A Dedekind domain is a unique factorisation domain if and only if it is a principal ideal domain. Hence has unique factorisation of elements if and only if .
Proof
A PID is a UFD (standard). Conversely let be a Dedekind UFD and a non-zero prime ideal. Pick ; is not a unit, so it factors into irreducibles, and since is prime one irreducible factor lies in . In a UFD irreducibles are prime, so is a non-zero prime ideal; being non-zero it is maximal, and forces . So every non-zero prime is principal, and by Theorem 4 so is every non-zero ideal, a product of primes.
∎
In the element is irreducible but not prime (formalised below), so is not a UFD and .
Theorem— Theorem 7 (Minkowski's bound; finiteness of the class group)
Every ideal class of a number field of degree contains an integral ideal of norm at most
Since there are only finitely many ideals of bounded norm, the class group is finite. Moreover for .
Proof sketch. The embeddings map to a lattice in of covolume , and an ideal to a sublattice of covolume . Minkowski's convex body theorem — a convex, centrally symmetric region of volume greater than times the covolume contains a non-zero lattice point — applied to a suitably scaled region yields with (using the AM–GM inequality). Given a class, choose in the inverse class with integral; then is an integral ideal in the original class with norm . An ideal of norm contains , and is finite, so there are finitely many such ideals. Since (every class contains an ideal of norm ), for . Full proofs: Neukirch, Chapter I, §5–6; Marcus, Chapter 5.
Example— Computing class groups with the Minkowski bound
- : , so every class contains the ideal : .
- : : . (Mathlib proves exactly this, as
IsCyclotomicExtension.Rat.three_pid.) - : : .
- : , so every class contains an ideal of norm or . The only ideal of norm is (since ), which is not principal because has no solution. So , and .
Theorem— Theorem 8 (Dirichlet's unit theorem)
: there are fundamental units , , such that every unit is uniquely with and .
Proof for quadratic fields. If is imaginary quadratic (, , ), a unit has norm , and is a positive definite quadratic form, so there are finitely many units: they are roots of unity, except for and . If is real (), view . For , a unit with has conjugate , so ; then and are bounded, which bounds the coordinates of in the lattice , so there are finitely many such units. If there is at least one unit (below), let be the smallest. Any unit satisfies for some , and is a unit in , hence equal to . So the units are . That a unit exists is the solvability of Pell's equation in positive integers (Lagrange, 1768; proved in Mathlib as Pell.exists_of_not_isSquare); for , is a unit of infinite order (formalised below).
The general case (sketch): the logarithmic embedding (one coordinate per real embedding and per pair of complex ones, the latter doubled) is a homomorphism into the hyperplane (because ). Its kernel is finite — algebraic integers all of whose conjugates have absolute value are roots of unity (Kronecker) — and its image is discrete, because a bounded region contains finitely many algebraic integers with bounded conjugates. The hard step is that the image spans the hyperplane, again by Minkowski's theorem. See Neukirch, Chapter I, §7. Mathlib formalises the full theorem (below).
Explore: units on hyperbolas, roots of unity on circles
Units of . A unit has norm , so the points lie on the two hyperbolas below. Multiplying by the fundamental unit sends , hopping between the hyperbolas: , with norms alternating . On the logarithmic scale these powers are evenly spaced — a rank-one lattice, as Dirichlet's theorem says. The points , , … also give the best rational approximations , , to .
The units a + b√2 of ℤ[√2] (a, b ≥ 0)
Every unit is ±(1 + √2)ⁿ: the powers alternate between norm +1 and norm −1 and approach the asymptote b = a/√2.
- a² − 2b² = 1
- a² − 2b² = −1
- b = a/√2
- a² − 2b² = 1: y = 0
- a² − 2b² = −1: y = 1
- b = a/√2: y = 0.7071
Cyclotomic integers. The -th roots of unity are the vertices of a regular -gon; is the ring of integer combinations of them. Change : for you get (class number ), for the ring (class number , also proved in Mathlib), and Kummer's theory says what happens for larger primes: the class number of is .
The fifth roots of unity
ℤ[ζ₅] has ζ = e^{2πi/5} as a generator; its four embeddings into ℂ send ζ to the four non-trivial vertices.
Drag the points, or focus one with Tab and use the arrow keys (hold Shift for small steps).
Solutions of wⁿ = c for n = 5:
- w₀ = 1
- w₁ = 0.309 + 0.951i
- w₂ = −0.809 + 0.588i
- w₃ = −0.809 − 0.588i
- w₄ = 0.309 − 0.951i
All roots lie on the circle of radius |c|^(1/n) ≈ 1.
Neighbouring roots are 72° apart: 360° ÷ 5.
w₀ is the principal root, at the angle (arg c)/n; the others follow by equal turns.
Because c = 1, these are the roots of unity of order 5.
The roots add up to 0, so the regular polygon is balanced around the origin.
Algebraic number theory in Lean and Mathlib
We first prove, from scratch, everything about used in the lesson, working in Mathlib's Zsqrtd (-5) (written ℤ√(-5)), whose norm is multiplicative. The norm, the fact that the ring is a domain (needed to talk about unique factorisation at all), and the key arithmetic fact that nothing has norm :
/-- **The norm on `ℤ[√−5]`.** `N(a + b√−5) = (a + b√−5)(a − b√−5) = a² + 5b²`. In Mathlib the norm
of `z : ℤ√d` is `z.re * z.re - d * z.im * z.im`, multiplicative by `Zsqrtd.norm_mul`. -/
theorem norm_sqrt_neg_five (z : ℤ√(-5)) : z.norm = z.re ^ 2 + 5 * z.im ^ 2 := by
rw [Zsqrtd.norm_def]
ring/-- **`ℤ[√−5]` is an integral domain.** If `xy = 0` then `N(x) N(y) = N(xy) = 0`, so `N(x) = 0` or
`N(y) = 0`; and `N(a + b√−5) = a² + 5b² = 0` forces `a = b = 0` (Mathlib: `Zsqrtd.norm_eq_zero`,
since `−5` is not a square). -/
instance isDomain_sqrt_neg_five : IsDomain (ℤ√(-5)) := by
have hns : ∀ n : ℤ, (-5 : ℤ) ≠ n * n := fun n h => by nlinarith [mul_self_nonneg n]
have : NoZeroDivisors (ℤ√(-5)) :=
⟨fun {x y} hxy => by
have h := congrArg Zsqrtd.norm hxy
rw [Zsqrtd.norm_mul, Zsqrtd.norm_zero, mul_eq_zero] at h
rcases h with h | h
· exact Or.inl ((Zsqrtd.norm_eq_zero hns x).mp h)
· exact Or.inr ((Zsqrtd.norm_eq_zero hns y).mp h)⟩
exact NoZeroDivisors.to_isDomain _/-- **No element of `ℤ[√−5]` has norm `2`.** If `a² + 5b² = 2` then `b = 0` (otherwise the left
side is at least `5`), and `a² = 2` has no integer solution. -/
theorem norm_ne_two (z : ℤ√(-5)) : z.norm ≠ 2 := by
rw [norm_sqrt_neg_five]
intro h
have hb : z.im = 0 := by nlinarith [sq_nonneg z.re, sq_nonneg z.im]
rw [hb] at h
have ha : z.re ^ 2 = 2 := by linarith
have h1 : z.re ≤ 1 := by nlinarith [sq_nonneg (z.re - 2)]
have h2 : -1 ≤ z.re := by nlinarith [sq_nonneg (z.re + 2)]
interval_cases z.re <;> norm_num at haThen is irreducible but not prime, so is not a UFD:
/-- **`2` is irreducible in `ℤ[√−5]`.** It is not a unit, since `N(2) = 4 ≠ 1`. If `2 = xy` then
`N(x) N(y) = 4` with both norms non-negative; `N(x) = 2` is impossible, so `N(x) = 1` or
`N(y) = 1`, and an element of norm `1` is a unit (Mathlib: `Zsqrtd.norm_eq_one_iff'`). -/
theorem two_irreducible : Irreducible (2 : ℤ√(-5)) := by
have hd : (-5 : ℤ) ≤ 0 := by norm_num
have hnorm2 : (2 : ℤ√(-5)).norm = 4 := by
rw [norm_sqrt_neg_five]; simp
refine ⟨fun hu => ?_, fun x y hxy => ?_⟩
· have := (Zsqrtd.norm_eq_one_iff' hd 2).mpr hu
rw [hnorm2] at this
norm_num at this
· have h := congrArg Zsqrtd.norm hxy
rw [Zsqrtd.norm_mul, hnorm2] at h
have hx0 := Zsqrtd.norm_nonneg hd x
have hy0 := Zsqrtd.norm_nonneg hd y
have hx2 := norm_ne_two x
have hypos : 0 < y.norm := by
rcases hy0.lt_or_eq with h' | h'
· exact h'
· rw [← h'] at h; norm_num at h
have hxle : x.norm ≤ 4 := by nlinarith
have hxpos : 0 < x.norm := by
rcases hx0.lt_or_eq with h' | h'
· exact h'
· rw [← h'] at h; norm_num at h
interval_cases hn : x.norm
· exact Or.inl ((Zsqrtd.norm_eq_one_iff' hd x).mp hn)
· exact absurd rfl hx2
· omega
· right
exact (Zsqrtd.norm_eq_one_iff' hd y).mp (by omega)/-- **…but `2` is not prime in `ℤ[√−5]`.** `2` divides `(1 + √−5)(1 − √−5) = 6 = 2 · 3`, yet it
divides neither factor: `1 ± √−5 = 2(a + b√−5)` would give `1 = 2a`. -/
theorem two_not_prime : ¬ Prime (2 : ℤ√(-5)) := by
intro hp
have hdvd : (2 : ℤ√(-5)) ∣ ⟨1, 1⟩ * ⟨1, -1⟩ :=
⟨3, by ext <;> simp [Zsqrtd.re_mul, Zsqrtd.im_mul]⟩
rcases hp.dvd_or_dvd hdvd with ⟨c, hc⟩ | ⟨c, hc⟩
· have := congrArg Zsqrtd.re hc
simp [Zsqrtd.re_mul] at this
omega
· have := congrArg Zsqrtd.re hc
simp [Zsqrtd.re_mul] at this
omega/-- **`ℤ[√−5]` is not a unique factorisation domain.** In a UFD every irreducible element is
prime, but `2` is irreducible and not prime. Concretely, `6 = 2 · 3 = (1 + √−5)(1 − √−5)` are
two factorisations into irreducibles that do not match up to units. (The *ideals* still factor
uniquely: `(6) = 𝔭₂² 𝔭₃ 𝔭₃'` — see the lesson.) -/
theorem not_ufd : ¬ UniqueFactorizationMonoid (ℤ√(-5)) := by
intro h
exact two_not_prime (UniqueFactorizationMonoid.irreducible_iff_prime.mp two_irreducible)The two cases of Dirichlet's unit theorem for quadratic rings: finitely many units for , infinitely many for :
/-- **The units of `ℤ[√−5]` are `±1`** — the imaginary quadratic case of Dirichlet's unit theorem
(rank `r₁ + r₂ − 1 = 0 + 1 − 1 = 0`). A unit has norm `1`, and `a² + 5b² = 1` forces `b = 0` and
`a = ±1`. -/
theorem units_sqrt_neg_five (z : ℤ√(-5)) : IsUnit z ↔ z = 1 ∨ z = -1 := by
have hd : (-5 : ℤ) ≤ 0 := by norm_num
constructor
· intro hu
have h := (Zsqrtd.norm_eq_one_iff' hd z).mpr hu
rw [norm_sqrt_neg_five] at h
have hb : z.im = 0 := by nlinarith [sq_nonneg z.re, sq_nonneg z.im]
rw [hb] at h
have ha : z.re ^ 2 = 1 := by linarith
have h1 : z.re ≤ 1 := by nlinarith [sq_nonneg (z.re - 1)]
have h2 : -1 ≤ z.re := by nlinarith [sq_nonneg (z.re + 1)]
interval_cases hre : z.re
· right; ext <;> simp [hre, hb]
· norm_num at ha
· left; ext <;> simp [hre, hb]
· rintro (rfl | rfl)
· exact isUnit_one
· exact isUnit_one.neg/-- **`1 + √2` is a unit of `ℤ[√2]`**: `(1 + √2)(−1 + √2) = 2 − 1 = 1`. Units of `ℤ[√2]` are the
elements of norm `a² − 2b² = ±1`, i.e. solutions of Pell-type equations. -/
theorem one_add_sqrt_two_unit : IsUnit (⟨1, 1⟩ : ℤ√2) :=
IsUnit.of_mul_eq_one ⟨-1, 1⟩ (by ext <;> simp [Zsqrtd.re_mul, Zsqrtd.im_mul])/-- **`1 + √2` has infinite order**, so `ℤ[√2]` has infinitely many units — the real quadratic
case of Dirichlet's unit theorem (rank `r₁ + r₂ − 1 = 2 + 0 − 1 = 1`). Proof: multiplying
`a + b√2` by `1 + √2` gives `(a + 2b) + (a + b)√2`, so by induction every power
`(1 + √2)ⁿ⁺¹` has both coordinates at least `1`; but `1 = 1 + 0√2`. -/
theorem one_add_sqrt_two_infinite_order (n : ℕ) : (⟨1, 1⟩ : ℤ√2) ^ (n + 1) ≠ 1 := by
have key : ∀ m : ℕ, 1 ≤ ((⟨1, 1⟩ : ℤ√2) ^ (m + 1)).re ∧ 1 ≤ ((⟨1, 1⟩ : ℤ√2) ^ (m + 1)).im := by
intro m
induction m with
| zero => simp
| succ m ih =>
rw [pow_succ, Zsqrtd.re_mul, Zsqrtd.im_mul]
obtain ⟨h1, h2⟩ := ih
constructor <;> simp <;> omega
intro h
have := (key n).2
rw [h] at this
simp at thisMathlib's number field library proves the general theory. Proposition 3 and Theorem 4:
/-- **The ring of integers of a number field is a Dedekind domain**: Noetherian, integrally closed
and of dimension one. Mathlib: an instance in `Mathlib.NumberTheory.NumberField.Basic`, proved
from the fact that `𝓞 K` is the integral closure of the Dedekind domain `ℤ` in `K`. -/
theorem ring_of_integers_dedekind (K : Type*) [Field K] [NumberField K] :
IsDedekindDomain (𝓞 K) :=
inferInstance/-- **Unique factorisation of ideals.** In a Dedekind domain the non-zero ideals form a unique
factorisation monoid: every non-zero ideal is a product of prime ideals, uniquely up to order.
Mathlib: `Ideal.uniqueFactorizationMonoid`. -/
theorem ideals_factor_uniquely (K : Type*) [Field K] [NumberField K] :
UniqueFactorizationMonoid (Ideal (𝓞 K)) :=
inferInstanceTheorem 7 and Theorem 6 (in the form "class number one ⇔ PID"):
/-- **The class group of a number field is finite.** Mathlib proves it by showing that every
ideal class contains an ideal of bounded norm (`ClassGroup.fintypeOfAdmissibleOfFinite`); the
lesson's proof uses the Minkowski bound instead (Mathlib:
`NumberField.exists_ideal_in_class_of_norm_le`). -/
theorem class_group_finite (K : Type*) [Field K] [NumberField K] :
Finite (ClassGroup (𝓞 K)) :=
inferInstance/-- **Class number one ⇔ principal ideal domain** (and, for Dedekind domains, ⇔ unique
factorisation domain, as proved in the lesson). Mathlib: `NumberField.classNumber_eq_one_iff`. -/
theorem class_number_one_iff (K : Type*) [Field K] [NumberField K] :
classNumber K = 1 ↔ IsPrincipalIdealRing (𝓞 K) :=
classNumber_eq_one_iffTheorem 8, with the rank:
/-- **Dirichlet's unit theorem.** There are units `ε₁, …, ε_r` (a fundamental system) such that
every unit of `𝓞 K` is uniquely `ζ ε₁^{n₁} ⋯ ε_r^{n_r}` with `ζ` a root of unity and `nᵢ ∈ ℤ`;
here `r = r₁ + r₂ − 1` is one less than the number of infinite places. Mathlib:
`NumberField.Units.exist_unique_eq_mul_prod`. -/
theorem dirichlet_unit_theorem (K : Type*) [Field K] [NumberField K] (x : (𝓞 K)ˣ) :
∃! ζe : Units.torsion K × (Fin (Units.rank K) → ℤ),
x = ζe.1 * ∏ i, (Units.fundSystem K i) ^ (ζe.2 i) :=
Units.exist_unique_eq_mul_prod K x/-- **The rank of the unit group is `r₁ + r₂ − 1`.** Mathlib defines `Units.rank K` as the number of
infinite places minus one, and counts the infinite places as `r₁ + r₂`
(`InfinitePlace.card_eq_nrRealPlaces_add_nrComplexPlaces`). -/
theorem unit_rank (K : Type*) [Field K] [NumberField K] :
Units.rank K = InfinitePlace.nrRealPlaces K + InfinitePlace.nrComplexPlaces K - 1 := by
rw [Units.rank, InfinitePlace.card_eq_nrRealPlaces_add_nrComplexPlaces]Cyclotomic integers, and Fermat's two-squares theorem (the splitting of in ):
/-- **The ring of integers of `ℚ(ζ_p)` is `ℤ[ζ_p]`.** For a prime `p` and a primitive `p`-th root of
unity `ζ`, the integral closure of `ℤ` in `ℚ(ζ)` is generated by `ζ`. Mathlib:
`IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime` (proved via the
Eisenstein criterion for the minimal polynomial of `ζ − 1`). -/
theorem cyclotomic_integers {p : ℕ} [Fact p.Prime] {K : Type*} [Field K] [CharZero K]
[IsCyclotomicExtension {p} ℚ K] {ζ : K} (hζ : IsPrimitiveRoot ζ p) :
IsIntegralClosure (Algebra.adjoin ℤ ({ζ} : Set K)) ℤ K :=
IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime hζ/-- **Fermat's two-squares theorem**: a prime `p` with `p mod 4 ≠ 3` is a sum of two squares.
In the lesson's language: such a `p` splits in `ℤ[i]` as `(a + bi)(a − bi)`. Mathlib:
`Nat.Prime.sq_add_sq` (proved via the Gaussian integers, a Euclidean domain). -/
theorem sum_of_two_squares {p : ℕ} [Fact p.Prime] (hp : p % 4 ≠ 3) :
∃ a b : ℕ, a ^ 2 + b ^ 2 = p :=
Nat.Prime.sq_add_sq hpWhat is and is not formalised. Proved here: all the arithmetic of in the lesson (domain, irreducibility and non-primality of , not a UFD, units ) and the infinitude of the units of . From Mathlib: rings of integers are Dedekind, unique factorisation of ideals, finiteness of the class group, PID, Dirichlet's unit theorem with rank , , and the two-squares theorem. Not formalised here: Theorem 2 (Mathlib does not yet have a packaged computation of the rings of integers of all quadratic fields), the computation (we prove via "not a UFD", but not ), and the Dedekind–Kummer theorem, which Mathlib proves as KummerDedekind.normalizedFactors_ideal_map_eq_normalizedFactors_min_poly_mk_map but which we do not restate.
Splitting primes and counting classes
The first experiment factors every prime below in , , and by Theorem 5, checks the answer against the Kronecker symbol , and then looks at the split primes of : the prime factors are principal exactly when , which happens for — the class group made visible. About half the primes split in each field, an instance of the Chebotarev density theorem.
"""How rational primes split in quadratic fields, and the class group at work.
For K = Q(sqrt d) the ring of integers is Z[w] with w = sqrt d (d = 2, 3 mod 4)
or w = (1 + sqrt d)/2 (d = 1 mod 4), and the Dedekind-Kummer theorem says
that p splits, is inert or ramifies according as the minimal polynomial of w
has two, no or one (double) root modulo p. We compute this for every prime
p < 200 in four fields and compare with the prediction from the Kronecker
symbol (D/p) of the discriminant D. Then, in Q(sqrt -5), whose class number
is 2, we ask which split primes have *principal* prime factors: exactly those
with p = a^2 + 5b^2. They turn out to be the primes p = 1, 9 (mod 20), while
p = 3, 7 (mod 20) split into non-principal ideals - the class group made
visible. Exact and exhaustive for p < 200; the general statements are
theorems (Dedekind-Kummer; genus theory), not consequences of the check.
"""
import math
def is_prime(n):
"""Trial division primality test."""
return n >= 2 and all(n % q for q in range(2, math.isqrt(n) + 1))
def discriminant(d):
"""Discriminant of Q(sqrt d) for squarefree d != 0, 1."""
return d if d % 4 == 1 else 4 * d
def min_poly(d):
"""Coefficients (b, c) of x^2 + b x + c, the minimal polynomial of w."""
if d % 4 == 1:
return (-1, (1 - d) // 4)
return (0, -d)
def roots_mod_p(d, p):
"""Distinct roots modulo p of the minimal polynomial of w."""
b, c = min_poly(d)
return [x for x in range(p) if (x * x + b * x + c) % p == 0]
def splitting_type(d, p):
"""'split', 'inert' or 'ramified', by Dedekind-Kummer."""
b, c = min_poly(d)
roots = roots_mod_p(d, p)
if len(roots) == 2:
return "split"
if not roots:
return "inert"
# one distinct root: check it is a double root (discriminant = 0 mod p)
return "ramified" if (b * b - 4 * c) % p == 0 else "split"
def kronecker(a, p):
"""Kronecker symbol (a/p) for a prime p."""
if p == 2:
if a % 2 == 0:
return 0
return 1 if a % 8 in (1, 7) else -1
r = pow(a % p, (p - 1) // 2, p)
return 0 if a % p == 0 else (1 if r == 1 else -1)
PREDICTION = {1: "split", -1: "inert", 0: "ramified"}
def norm_form_represents(p, d):
"""True if p = a^2 + |d| b^2 for integers a, b (d < 0)."""
return any(math.isqrt(p + d * b * b) ** 2 == p + d * b * b
for b in range(math.isqrt(p // -d) + 1))
def main():
primes = [p for p in range(2, 200) if is_prime(p)]
print(f"Primes p < 200 ({len(primes)} primes), factored in O_K:")
print(f"{'field':<10}{'D':>5} split inert ramified agrees with (D/p)")
for d, name in [(-1, "Q(i)"), (-5, "Q(sqrt-5)"), (2, "Q(sqrt2)"),
(5, "Q(sqrt5)")]:
D = discriminant(d)
types = [splitting_type(d, p) for p in primes]
agree = all(t == PREDICTION[kronecker(D, p)]
for t, p in zip(types, primes))
counts = [types.count(t) for t in ("split", "inert", "ramified")]
print(f"{name:<10}{D:>5} {counts[0]:>5} {counts[1]:>5} "
f"{counts[2]:>8} {agree}")
split = [p for p in primes if splitting_type(-5, p) == "split"]
principal = [p for p in split if norm_form_represents(p, -5)]
other = [p for p in split if p not in principal]
print("Q(sqrt-5), class number 2: split primes p = P P'.")
print(f" P principal (p = a^2+5b^2): {principal[:9]} ...")
print(f" P not principal: {other[:9]} ...")
print(" residues mod 20, principal:",
sorted({p % 20 for p in principal}),
" not principal:", sorted({p % 20 for p in other}))
print()
print("Epistemic status: exact and exhaustive for primes below 200. The")
print("agreement with (D/p) is the Dedekind-Kummer theorem; the residues")
print("mod 20 illustrate genus theory. Neither is proved by this check.")
if __name__ == "__main__":
main()The second experiment computes class numbers of imaginary quadratic fields in two independent ways — counting Gauss's reduced binary quadratic forms, and Dirichlet's analytic class number formula — finds the nine discriminants with class number one, and computes fundamental units of real quadratic rings from continued fractions. Notice how erratically the units grow: the unit theorem says one generator exists, not how big it is.
"""Class numbers of imaginary quadratic fields and units of real ones.
Gauss's reduced binary quadratic forms count ideal classes: for a negative
fundamental discriminant D, the class number h(D) of Q(sqrt D) equals the
number of reduced primitive forms a x^2 + b xy + c y^2 with b^2 - 4ac = D,
|b| <= a <= c (and b >= 0 if |b| = a or a = c). We compute h(D) this way for
every fundamental discriminant -200 <= D < 0, and check each value against
Dirichlet's analytic class number formula
h(D) = -(w / (2|D|)) * sum_{a=1}^{|D|-1} chi_D(a) * a,
where chi_D is the Kronecker symbol and w is the number of roots of unity.
Then, for real quadratic rings Z[sqrt d], we find the fundamental unit by the
continued fraction of sqrt d (the smallest solution of x^2 - d y^2 = +-1),
showing how wildly its size varies - Dirichlet's unit theorem promises one
fundamental unit but says nothing about how large it is. Exact integer
arithmetic, exhaustive in the stated range.
"""
import math
def is_squarefree(n):
"""True if no square of a prime divides n (n != 0)."""
n = abs(n)
return all(n % (q * q) for q in range(2, math.isqrt(n) + 1))
def is_fundamental(D):
"""Fundamental discriminant test for D != 0, 1."""
if D % 4 == 1:
return is_squarefree(D)
if D % 4 == 0:
m = D // 4
return m % 4 in (2, 3) and is_squarefree(m)
return False
def reduced_forms(D):
"""Reduced primitive positive definite forms (a, b, c) of discriminant D < 0."""
forms = []
a = 1
while 3 * a * a <= -D:
for b in range(-a + 1, a + 1):
if (b * b - D) % (4 * a):
continue
c = (b * b - D) // (4 * a)
if c < a or (c == a and b < 0):
continue
if math.gcd(math.gcd(a, b), c) == 1:
forms.append((a, b, c))
a += 1
return forms
def class_number(D):
"""h(D) as the number of reduced primitive forms."""
return len(reduced_forms(D))
def kronecker(D, n):
"""Kronecker symbol (D/n) for n >= 1."""
result, m, p = 1, n, 2
while m > 1:
if m % p:
p += 1
continue
m //= p
if p == 2:
factor = 0 if D % 2 == 0 else (1 if D % 8 in (1, 7) else -1)
else:
r = pow(D % p, (p - 1) // 2, p)
factor = 0 if D % p == 0 else (1 if r == 1 else -1)
result *= factor
return result
def class_number_formula(D):
"""Dirichlet's formula h = -(w / 2|D|) sum chi_D(a) a, as an exact integer."""
w = {-3: 6, -4: 4}.get(D, 2)
s = sum(kronecker(D, a) * a for a in range(1, -D))
value = -w * s
if value % (2 * -D):
raise ArithmeticError("formula did not give an integer")
return value // (2 * -D)
def fundamental_unit(d):
"""Smallest x + y sqrt d (x, y > 0) with x^2 - d y^2 = +-1, d not a square."""
a0 = math.isqrt(d)
m, q, a = 0, 1, a0
h_prev, h = 1, a0
k_prev, k = 0, 1
while h * h - d * k * k not in (1, -1):
m = q * a - m
q = (d - m * m) // q
a = (a0 + m) // q
h_prev, h = h, a * h + h_prev
k_prev, k = k, a * k + k_prev
return h, k, h * h - d * k * k
def main():
discs = [D for D in range(-200, 0) if is_fundamental(D)]
hs = {D: class_number(D) for D in discs}
agree = all(hs[D] == class_number_formula(D) for D in discs)
print(f"Fundamental discriminants -200 <= D < 0: {len(discs)} fields")
print(" h(D) by reduced forms equals Dirichlet's formula for all:",
agree)
print(" h(D) for the first fields:")
first = sorted(discs, reverse=True)[:20]
for start in (0, 10):
print(" " + " ".join(f"{D}:{hs[D]}" for D in first[start:start + 10]))
print(" class number 1:", [D for D in sorted(discs, reverse=True)
if hs[D] == 1])
print(" forms of D = -20 (Q(sqrt-5)):", reduced_forms(-20))
print(f" largest h in range: {max(hs.values())}")
print("Fundamental units of Z[sqrt d] (x + y sqrt d, norm x^2 - d y^2):")
for d in (2, 3, 7, 19, 31, 43, 46, 94):
x, y, nrm = fundamental_unit(d)
print(f" d = {d:>2}: {x} + {y} sqrt{d} (norm {nrm:+d})")
print()
print("Epistemic status: exact integer computations, exhaustive for the")
print("stated discriminants. That -163 is the last D with h(D) = 1 is the")
print("Baker-Heegner-Stark theorem; the computation only covers |D| <= 200.")
if __name__ == "__main__":
main()Exercises
1. Algebraic number theory
Warm-upHumanWhat is the discriminant of the quadratic field ?
2. Algebraic number theory
Warm-upHumanWhich ring is the ring of integers of ?
3. Algebraic number theory
CoreHumanList the primes that are inert (remain prime) in the Gaussian integers . Enter them as a set, for example {2, 5}.
4. Algebraic number theory
CoreHumanIn the proof that a Dedekind UFD is a PID, we find an irreducible with for a non-zero prime and conclude . Which property is used for this last step?
5. Algebraic number theory
CoreHumanUsing the Minkowski bound for , what is the class number ?
6. Algebraic number theory
StretchHumanIn , let . One checks that although . Which hypothesis of Theorem 4 fails, and where does the proof break?
7. Algebraic number theory
CoreHumanWhat is the rank of the unit group for ? (The minimal polynomial has one real root and two complex conjugate roots.)
8. Algebraic number theory
CoreFormalWhich pair of Lean facts about ℤ√(-5) (Mathlib's ) is exactly what the lesson uses to prove ¬ UniqueFactorizationMonoid (ℤ√(-5))?
9. Algebraic number theory
StretchComputationalWrite inert_primes(d, bound) returning the sorted list of primes that are inert in ( squarefree). Use Dedekind–Kummer: with () or (), is inert exactly when the minimal polynomial of has no root modulo .
Common misconceptions
Misconception
"Every ring of integers has unique factorisation, like ." It fails already in : with all four factors irreducible and no two associate. What survives is unique factorisation of ideals (Theorem 4): , and both element factorisations are regroupings of it. Element factorisation is unique exactly when every ideal is principal, (Theorem 6).
Misconception
"The ring of integers of is ." Only when . For the element is a root of , an integer polynomial: the golden ratio and are algebraic integers. Working in the too-small ring even destroys unique factorisation of ideals, because it is not integrally closed.
Misconception
"A prime number stays prime in any ring of integers" — or the opposite, "every prime splits." All three behaviours occur, governed by the reduction of a minimal polynomial (Theorem 5): in , ramifies, splits and stays prime. Whether splits in depends only on modulo , by quadratic reciprocity.
Misconception
"Units are just ." That is true for and for imaginary quadratic fields other than and , but real quadratic fields have infinitely many units, , and the fundamental unit can be enormous: for it is . In general the unit group has rank .
Viewpoints
Geometry— The geometry of numbers
Minkowski's insight (Geometrie der Zahlen, 1896) was that embedded by is a lattice in , and that arithmetic questions become questions about lattice points in convex bodies. His convex body theorem proves the finiteness of the class group (Theorem 7), the inequality for , and — applied to the logarithmic embedding — Dirichlet's unit theorem, where the units form a lattice of covolume related to the regulator in the hyperplane . The same technique gives Lagrange's four-squares theorem (via a lattice in ) and Fermat's two-squares theorem (a lattice of covolume in must contain a non-zero point in the disc of area ). The picture in the intuition section — an ideal as a sublattice of index — is this viewpoint in miniature.
Topology— Primes as points, extensions as coverings (an analogy)
Think of as a curve whose points are the non-zero primes (see algebraic geometry). A finite extension gives a map that behaves like a branched covering of degree : over most points there are "sheets", and the finitely many ramified primes (those dividing the relative discriminant) are the branch points. For Galois extensions the Galois group acts on the fibres like deck transformations, and the decomposition group and Frobenius element of a prime mirror the local monodromy around a point. The analogy predicts true theorems: the Hilbert class field of — its maximal unramified abelian extension — has Galois group isomorphic to , as the maximal abelian unramified cover of a space has deck group , the abelianised fundamental group; and Minkowski's theorem that every extension of ramifies somewhere says " is simply connected". This is an analogy, not an identity — étale fundamental groups (Grothendieck) make it precise.
Analysis— Dedekind zeta functions and the class number formula
The Dedekind zeta function () encodes the splitting of all primes at once — its Euler product is Theorem 4 read analytically. It continues meromorphically to with a simple pole at whose residue is given by the analytic class number formula:
where is the regulator (the covolume of the unit lattice) and . So the class number and the units, the two measures of failure of unique factorisation, appear together in an analytic invariant. For a quadratic field , which turns the formula into Dirichlet's finite sum used in the second experiment. This is the bridge to analytic number theory; Siegel's theorem for imaginary quadratic fields comes from it.
Algebra— Galois theory of primes
If is Galois with group , then permutes the primes above transitively, so and are the same for all of them and . For unramified there is a well-defined Frobenius conjugacy class , the elements acting as on a residue field. For abelian , is an element, and for cyclotomic fields it is simply in — this is why the splitting of in depends on the order of mod , and why quadratic reciprocity follows from the inclusion . Class field theory (Takagi, Artin) describes all abelian extensions of in terms of ideals of ; the Chebotarev density theorem says each conjugacy class occurs as for a proportion of primes — half of all primes split in each quadratic field, as the first experiment shows. Non-abelian generalisations are the subject of the Langlands programme.
Wonder Trail
Clock arithmetic is the arithmetic of — the residue rings of this lesson generalise it, and the Dedekind–Kummer theorem reduces the factorisation of primes to factoring polynomials on a "clock" .
Wonder Trail · Optional · never gradedClock arithmeticIt's 9 o'clock. What time will it be in 5 hours — and in 29 hours? Can a clock teach us a whole new kind of arithmetic?Follow the trailHistory and global context
- Brahmagupta (Brāhmasphuṭasiddhānta, 628) found the composition identity — multiplicativity of the norm in — and used it to generate solutions of . Jayadeva and Bhāskara II (Bījagaṇita, 1150) developed the cyclic chakravāla method, solving with , .
- Fermat stated the two-squares theorem (1640) and posed Pell's equation as a challenge (1657); Euler proved the two-squares theorem (1749) and used numbers in work on ; Lagrange proved that Pell's equation always has a non-trivial solution (1768) and began the theory of binary quadratic forms.
- Gauss (Disquisitiones Arithmeticae, 1801) developed composition of forms and class numbers — a class group before groups had a name — and conjectured that only finitely many imaginary quadratic fields have class number one; he introduced for biquadratic reciprocity (1832). Dirichlet proved the unit theorem (1846) and his class number formula (1839).
- Kummer found the failure of unique factorisation in cyclotomic integers and introduced ideal numbers (1844–47), proving Fermat's Last Theorem for regular primes. Dedekind replaced ideal numbers by ideals in his supplements to Dirichlet's lectures (1871), proving Theorem 4; Kronecker developed a parallel theory of divisors. Hilbert's Zahlbericht (1897) unified the subject, and Minkowski (1896) brought in the geometry of numbers.
- Teiji Takagi (1920) and Emil Artin (1927) established class field theory. Kurt Heegner (1952), Alan Baker and Harold Stark (1966–67) proved that exactly nine imaginary quadratic fields have class number one (), settling Gauss's problem. Andrew Wiles's proof of Fermat's Last Theorem (1995) used far more than Kummer's methods, but ideals, class groups and Galois actions on primes remain its language.
Further reading
- Daniel A. Marcus, Number Fields (1977; 2nd ed. 2018) — the friendliest first course, with excellent exercises on quadratic and cyclotomic fields.
- Jürgen Neukirch, Algebraic Number Theory (1999) — the standard graduate text: Dedekind domains, Minkowski theory, units, local fields and class field theory.
- Kenneth Ireland and Michael Rosen, A Classical Introduction to Modern Number Theory (2nd ed., 1990) — Gaussian and Eisenstein integers, cyclotomy, and Fermat's Last Theorem for small exponents.
- Ian Stewart and David Tall, Algebraic Number Theory and Fermat's Last Theorem (4th ed., 2015) — from Kummer's ideals to an outline of Wiles's proof.
- Pierre Samuel, Algebraic Theory of Numbers (1970) — short and elegant.
- David A. Cox, Primes of the Form (1989) — forms, class field theory and complex multiplication, starting from exactly the question of which are .