When factorisation stops being unique
Every whole number greater than factors into primes in essentially one way. Polynomials over a field behave the same way: over , and there is no other factorisation into irreducibles. The reason is the same in both cases: division with remainder, which gives Euclid's algorithm, then Bézout's identity, then Euclid's lemma ( or ), and finally uniqueness.
Mathematicians soon found they wanted to factor other kinds of numbers. In his Algebra (1770), Leonhard Euler solved in integers by factoring and arguing as if unique factorisation held for numbers . (It does, but Euler did not prove it.) In 1847 Gabriel Lamé announced a proof of Fermat's Last Theorem that factored over the complex -th roots of unity, and it rested on the same unproved assumption. Joseph Liouville pointed out the gap at once. Ernst Kummer had already discovered that unique factorisation fails for some of these number systems. The simplest failure is in the numbers , :
where none of the four factors can be broken down further, and is not a unit multiple of either .
Kummer's response was to invent "ideal numbers" that restore uniqueness, and Richard Dedekind turned them into the ideals of this lesson. We define rings and their ideals, find their units and zero divisors, and prove the chain
with examples showing that neither arrow reverses and that is not even a UFD.
Two operations, and the multiples of a number
A group has one operation (see groups). Numbers, polynomials, matrices and functions have two, addition and multiplication, linked by the distributive law. A ring is the structure they share.
The ring axioms say nothing about division, and the interesting questions are about it. Which elements can be inverted? Can a product of non-zero elements be zero? Is there a division algorithm? Does factorisation into "atoms" exist, and is it unique?
The key new notion is the set of all multiples of an element. In the multiples of form . This set is closed under addition, and it absorbs multiplication: any integer times a multiple of is again a multiple of . Divisibility is containment: exactly when . A gcd is a generator of a sum: . Sets of this kind are called ideals. In the set of all combinations is an ideal, but it consists of the multiples of no single element: it behaves like a "gcd of and " that does not exist as a number. Kummer's ideal numbers were exactly such missing gcds.
Rings, ideals and the factorisation hierarchy
Convention. In this lesson (and the following ones) a ring has a multiplicative identity , and ring homomorphisms preserve it. Some books (for example in analysis) allow rings without ; then is a ring. Commutativity is not assumed unless stated. Integral domains and fields are commutative and have .
Definition— ring
A ring is a set with two operations and such that is an abelian group with identity , multiplication is associative with identity , and the distributive laws and hold. is commutative if for all . A subring is a subset containing and closed under , and .
Definition— units, zero divisors, domains and fields
A unit is an element with some such that ; the units form a group . A zero divisor is a non-zero with or for some non-zero . An integral domain is a commutative ring with and no zero divisors. A field is a commutative ring with in which every non-zero element is a unit. (A division ring drops commutativity.)
Definition— ring homomorphism, kernel
A ring homomorphism satisfies , and . Its kernel is .
Definition— ideal
A left ideal of is an additive subgroup with for all , ; a two-sided ideal also has . In a commutative ring the notions coincide and we just say ideal. The ideal generated by in a commutative ring is . An ideal is principal if it equals for one element .
Definition— prime and maximal ideals
In a commutative ring , an ideal is prime if implies or , and an ideal is maximal if there is no ideal strictly between and . (In quotients we prove that is a domain and a field exactly in these cases.)
Definition— divisibility, irreducible and prime elements
Let be an integral domain. Then if for some ; and are associates if for a unit . A non-zero non-unit is irreducible if forces or to be a unit, and prime if forces or .
Definition— Euclidean domain, PID, UFD
An integral domain is
- a Euclidean domain if there is a function such that for all and all there are with and either or ;
- a principal ideal domain (PID) if every ideal is principal;
- a unique factorisation domain (UFD) if every non-zero non-unit is a product of irreducibles, uniquely up to the order of the factors and replacing factors by associates.
A gallery of rings
Example— Numbers
are commutative rings. , , are fields; is a domain whose only units are . The Gaussian integers and are subrings of , hence domains. Each has a multiplicative norm : so and . If then , so units have norm . The units of are therefore , and those of are .
Example— Remainders
In , a residue is a unit iff . Otherwise, if , it is a zero divisor: with , we have . In the units are , and the other seven non-zero residues are zero divisors. Some elements are nilpotent ( in ) and some are idempotent (). So is a domain iff it is a field iff is prime. The field is also written .
Example— Polynomials
For a commutative ring , is the ring of polynomials with coefficients in . If is a domain, then for non-zero , because the leading coefficients multiply. So is a domain and its units are the units of (constants). For a field , behaves remarkably like : there is long division, and its irreducible elements play the role of primes (see polynomials). Over a non-domain strange things happen: in , , so the non-constant polynomial is a unit.
Example— Non-commutative rings
The matrix ring () is not commutative and has zero divisors and nilpotents: . Its two-sided ideals are only and , although it has many left ideals. The quaternions with form a division ring that is not a field, since .
Example— Products and functions
with componentwise operations is a commutative ring with zero divisors: . The continuous functions form a commutative ring. It has zero divisors (two non-zero functions with disjoint supports multiply to ), and for each the functions vanishing at form a maximal ideal.
Example— Ideals, subrings and generators
- The ideals of are the . Every ideal of is an additive subgroup, and these are the (see groups, Theorem 1). Similarly the ideals of are the for divisors of .
- is a subring of but not an ideal: . In the other direction, is an ideal of but not a subring (it does not contain ). A proper ideal never contains a unit.
- In : , the polynomials with constant term , is a prime ideal but not maximal, since . The ideal , the polynomials with even constant term, is maximal and not principal (Theorem 12).
- In , is maximal for prime, and is prime but not maximal. In , is prime and is maximal.
Units, zero divisors and ideals
Theorem— Proposition 1 (first consequences of the axioms)
In every ring: (a) and ; (b) if then ; (c) is a group under multiplication; (d) a unit is not a zero divisor.
Proof
(a) ; subtract . Then . (b) . (c) is a unit, , and is a unit with inverse . (d) If is a unit and , then ; similarly if .
∎
Theorem— Theorem 2 (finite domains are fields)
Every finite integral domain is a field.
Proof
Let in the finite domain . The map , , is injective: gives , so , since there are no zero divisors. An injective map from a finite set to itself is surjective, so for some .
∎
The same argument shows that in a finite commutative ring every non-zero element is either a unit or a zero divisor: if is not injective, then with . (Wedderburn's little theorem, 1905, says more: a finite division ring is commutative, hence a field.) The first experiment checks the unit/zero-divisor dichotomy in every with .
Theorem— Proposition 3 (kernels, units in ideals, fields)
Let and be rings.
- If is a ring homomorphism, then is a two-sided ideal of and is a subring of .
- An ideal containing a unit is all of .
- A commutative ring with is a field iff its only ideals are and .
- Every ring homomorphism from a field to a non-zero ring is injective.
Proof
(1) is an additive subgroup. If then and . The image contains and is closed under the operations. (2) If is a unit, then and for all . (3) If is a field and , then contains a non-zero element, which is a unit, so by (2). Conversely, if the only ideals are and and , then , so is a unit. (4) is an ideal of the field and does not contain , since . So by (3).
∎
Conversely, every two-sided ideal is the kernel of some homomorphism, namely the quotient map . That construction belongs to quotient rings. Together they give the key result: the kernels of ring homomorphisms are exactly the two-sided ideals, just as the kernels of group homomorphisms are exactly the normal subgroups.
Theorem— Proposition 4 (divisibility is containment)
In an integral domain : (a) ; (b) are associates; (c) is a unit; (d) a non-zero is prime iff is a prime ideal.
Proof
(a) . (b) If with , write and . Then , so , and since is a domain: is a unit. (If then .) The converse is clear. (c) is the case of (b). (d) This is a restatement: , and iff is not a unit.
∎
Theorem— Proposition 5 (prime implies irreducible)
In an integral domain every prime element is irreducible.
Proof
Let be prime and . Then , so (say) : . Then , so , and because . Hence is a unit.
∎
The converse fails in general, and it is exactly what fails in (Theorem 11). In a UFD the converse holds. If is irreducible and , factor , and into irreducibles. By uniqueness, is associate to an irreducible factor of or of .
Euclidean domain ⇒ PID ⇒ UFD
Theorem— Theorem 6 (three Euclidean domains)
with , for a field with , and with are Euclidean domains.
Proof
For this is the division algorithm, and for it is polynomial long division: if , subtract to lower the degree of , and repeat. This uses that the leading coefficient of is invertible, which is why must be a field.
For , let with , and compute the exact quotient . Choose integers with and , and set , . Then and, with extended to (still multiplicative),
∎
Theorem— Theorem 7 (Euclidean domains are PIDs)
Every ideal of a Euclidean domain is principal.
Proof
Let be an ideal. If then . Otherwise choose with least, by well-ordering of . For write with or . Then , so minimality forces . Hence , and .
∎
Theorem— Theorem 8 (arithmetic in a PID)
Let be a PID. (a) Any have a gcd , with , and for some (Bézout). (b) Every irreducible element is prime (Euclid's lemma). (c) Every non-zero prime ideal is maximal.
Proof
(a) is principal, say . Since , is a common divisor. Since , , so every common divisor of and divides .
(b) Let be irreducible, and . Write . Then , so or is a unit. If were a unit, would contain , giving . So is a unit, , and . Multiplying by gives , a sum of two multiples of , so .
(c) Let be prime, and . By Proposition 4(d) and Proposition 5, is irreducible. From with not a unit, is a unit, so .
∎
Theorem— Theorem 9 (PIDs are UFDs)
Every principal ideal domain is a unique factorisation domain.
Proof
Chains stabilise. Let be ideals. Their union is an ideal (any two elements lie in a common ), so . Then for some , and for all .
Existence. Suppose a non-zero non-unit is not a product of irreducibles. Then is not irreducible, so with neither factor a unit. If both and were products of irreducibles, so would be; say is not. Moreover : equality would make a unit, by Proposition 4(b). Repeating with gives a strictly increasing chain , which contradicts the first step.
Uniqueness. Suppose with all irreducible and a unit. We use induction on . If , the right side is a unit, so it has no irreducible factors and . If : is prime by Theorem 8(b), so it divides some . Since is irreducible and is not a unit, with a unit. Cancel (we are in a domain) and apply the induction hypothesis to .
∎
So , and have unique factorisation. In the prime splits, while stays prime. Which primes split is the question behind Fermat's theorem on sums of two squares, treated in number theory.
Where the hierarchy breaks
Theorem— Theorem 10 (the norm on ℤ[√−5])
In , is multiplicative, only for , the units are , and no element has norm or .
Proof
, and complex conjugation is multiplicative, so . A sum of non-negative terms is only if , and it is only if and . If , then (else the sum is at least ), and is impossible.
∎
Theorem— Theorem 11 (ℤ[√−5] is not a UFD, and not a PID)
In : (a) , , and are irreducible, and is associate to neither , so are two genuinely different factorisations; (b) is irreducible but not prime; (c) the ideal is not principal.
Proof
(a) The norms are . A factorisation into non-units would need to be a proper divisor of greater than , that is or , which is impossible by Theorem 10. The units are , and .
(b) . But requires even, so divides neither factor.
(c) Let . It is closed under addition, and under multiplication by , since and . So is an ideal. It contains and but not , so . If , then and , so divides . Thus , since no norm is , and is a unit — contradicting . (Alternatively: a PID is a UFD, and (a) shows is not.)
∎
Ideals restore uniqueness here. With , and , one checks that , , and . So both factorisations of refine to the same factorisation into prime ideals, . Dedekind proved that in the ring of integers of any number field, every non-zero ideal factors uniquely into prime ideals (see algebraic number theory).
Theorem— Theorem 12 (neither implication reverses)
(a) is a UFD but not a PID: the ideal is not principal. (b) is a PID but not a Euclidean domain (for any function ).
Proof
(a) That is a UFD is Gauss's lemma: if is a UFD, so is (Dummit and Foote, §9.3). Suppose . Since , degrees give , so . Since , . But every element of has even constant term, and is such an element, so is even. Contradiction.
(b) We only sketch this; full proofs are in Dummit and Foote, §8.1–8.2. The ring is not Euclidean (Motzkin, 1949): in a Euclidean domain that is not a field, an element of least size among non-zero non-units has the property that every element is congruent modulo to or a unit, and in this ring (whose units are ) no such exists. It is a PID because it has a weaker "Dedekind–Hasse" norm property, and because the class number of is .
∎
Rings in Lean and Mathlib
Mathlib's Ring, CommRing, IsDomain and Field classes match the lesson's conventions: rings have a , and ring homomorphisms R →+* S preserve it. Ideal R is defined as a submodule of over itself, which is exactly "an additive subgroup that absorbs multiplication". Prime p and Irreducible p are the lesson's definitions. IsPrincipalIdealRing R, EuclideanDomain R and UniqueFactorizationMonoid R are the three layers of the hierarchy.
Units and zero divisors (Proposition 1(d), the example and Theorem 2):
/-- A unit is never a zero divisor: if `u` is a unit and `u * a = 0` then `a = 0`, because
`a = u⁻¹ * (u * a) = u⁻¹ * 0 = 0`. (This works in every ring, commutative or not.) -/
theorem unit_mul_eq_zero {R : Type*} [Ring R] {u a : R} (hu : IsUnit u) (h : u * a = 0) :
a = 0 := by
obtain ⟨v, rfl⟩ := hu
calc a = (↑v⁻¹ * ↑v) * a := by simp
_ = ↑v⁻¹ * (↑v * a) := mul_assoc _ _ _
_ = 0 := by rw [h, mul_zero]/-- `ℤ/6ℤ` is not an integral domain: `2 · 3 = 0` although neither factor is `0`.
`decide` computes in `ZMod 6`. -/
theorem zmod_six_zero_divisors : (2 : ZMod 6) * 3 = 0 ∧ (2 : ZMod 6) ≠ 0 ∧ (3 : ZMod 6) ≠ 0 := by
decide/-- In a finite integral domain every non-zero `a` has an inverse. Multiplication by `a` is
injective (cancellation: `a * x = a * y` and `a ≠ 0` give `x = y`); an injective map from a
finite set to itself is surjective; so some `b` has `a * b = 1`. -/
theorem finite_domain_inverse {R : Type*} [CommRing R] [IsDomain R] [Finite R] (a : R)
(ha : a ≠ 0) : ∃ b : R, a * b = 1 := by
have inj : Function.Injective (fun x : R => a * x) := fun x y h => mul_left_cancel₀ ha h
exact Finite.injective_iff_surjective.mp inj 1/-- Every finite integral domain is a field. Mathlib's `Finite.isDomain_to_isField` proves this
even without commutativity — that stronger statement includes Wedderburn's little theorem that
finite division rings are commutative. -/
theorem finite_domain_is_field (R : Type*) [CommRing R] [IsDomain R] [Finite R] : IsField R :=
Finite.isDomain_to_isField RKernels and ideals (Proposition 3). The kernel is built by hand and then identified with Mathlib's RingHom.ker:
/-- The kernel of a ring homomorphism, built by hand as an ideal: it contains `0`, is closed
under addition, and absorbs multiplication, since `f (r * x) = f r * 0 = 0`. -/
def kerIdeal {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) : Ideal R where
carrier := {x | f x = 0}
zero_mem' := by simp
add_mem' {x y} hx hy := by simp_all
smul_mem' r x hx := by simp_all/-- The hand-built kernel is Mathlib's `RingHom.ker f`: both are `{x | f x = 0}`. -/
theorem kerIdeal_eq {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S) :
kerIdeal f = RingHom.ker f := by
ext x
simp [kerIdeal, RingHom.mem_ker]/-- An ideal that contains a unit `u` is the whole ring: it contains `u⁻¹ * u = 1`, and then
`r = r * 1` for every `r`. -/
theorem eq_top_of_unit_mem {R : Type*} [CommRing R] (I : Ideal R) {u : R} (hu : IsUnit u)
(h : u ∈ I) : I = ⊤ := by
rw [Ideal.eq_top_iff_one]
obtain ⟨v, rfl⟩ := hu
have : (↑v⁻¹ * ↑v : R) ∈ I := I.mul_mem_left _ h
simpa using this/-- A field has exactly two ideals, `0` and the whole field: a non-zero ideal contains a non-zero
element, which is a unit. -/
theorem field_ideals {K : Type*} [Field K] (I : Ideal K) : I = ⊥ ∨ I = ⊤ := by
by_cases h : I = ⊥
· exact Or.inl h
· obtain ⟨x, hx, hx0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot h
exact Or.inr (eq_top_of_unit_mem I (IsUnit.mk0 x hx0) hx)Prime and irreducible elements: Proposition 5, and Theorem 8(b), which is the heart of "PID ⇒ UFD". The Lean proof follows the human one line by line, using Ideal.mem_span_pair for the Bézout step:
/-- In an integral domain every prime element is irreducible. If `p = a * b`, then `p ∣ a` or
`p ∣ b`; say `a = p * c`. Then `p = p * c * b`, and cancelling `p ≠ 0` gives `1 = c * b`, so `b`
is a unit. -/
theorem prime_irreducible {R : Type*} [CommRing R] [IsDomain R] {p : R} (hp : Prime p) :
Irreducible p := by
refine ⟨hp.not_isUnit, fun a b hab => ?_⟩
rcases hp.dvd_or_dvd ⟨1, by rw [← hab, mul_one]⟩ with ⟨c, hc⟩ | ⟨c, hc⟩
· right
have h : p * 1 = p * (c * b) := by
calc p * 1 = a * b := by rw [mul_one, hab]
_ = p * (c * b) := by rw [hc, mul_assoc]
exact IsUnit.of_mul_eq_one_right c (mul_left_cancel₀ hp.ne_zero h).symm
· left
have h : p * 1 = p * (c * a) := by
calc p * 1 = a * b := by rw [mul_one, hab]
_ = p * (c * a) := by rw [hc, mul_comm a, mul_assoc]
exact IsUnit.of_mul_eq_one_right c (mul_left_cancel₀ hp.ne_zero h).symm/-- **Euclid's lemma in a principal ideal domain**: irreducible elements are prime. Let `p` be
irreducible with `p ∣ a * b` and `p ∤ a`. The ideal `(p, a)` is principal, say `(d)`. From
`p = d * x`, either `x` is a unit — then `(d) = (p)` contains `a`, so `p ∣ a`, impossible — or `d`
is a unit, so `(p, a)` is everything: `1 = r * p + s * a`. Then `b = r * p * b + s * (a * b)` is
divisible by `p`. -/
theorem pid_irreducible_prime {R : Type*} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
{p : R} (hp : Irreducible p) : Prime p := by
refine ⟨hp.ne_zero, hp.not_isUnit, fun a b hab => ?_⟩
by_cases hpa : p ∣ a
· exact Or.inl hpa
right
obtain ⟨d, hd⟩ := (IsPrincipalIdealRing.principal (Ideal.span {p, a})).principal
have hd' : Ideal.span {p, a} = Ideal.span {d} := hd
have hpd : p ∈ Ideal.span {d} := by rw [← hd']; exact Ideal.subset_span (by simp)
have had : a ∈ Ideal.span {d} := by rw [← hd']; exact Ideal.subset_span (by simp)
obtain ⟨x, hx⟩ := Ideal.mem_span_singleton'.mp hpd
have hpdx : p = d * x := by rw [← hx, mul_comm]
rcases hp.isUnit_or_isUnit hpdx with hdu | hxu
· -- `d` is a unit, so `1 ∈ (p, a)`.
have h1 : (1 : R) ∈ Ideal.span {p, a} := by
rw [hd', eq_top_of_unit_mem _ hdu (Ideal.mem_span_singleton_self d)]
exact Submodule.mem_top
obtain ⟨r, s, hrs⟩ := Ideal.mem_span_pair.mp h1
obtain ⟨c, hc⟩ := hab
exact ⟨r * b + s * c, by
calc b = (r * p + s * a) * b := by rw [hrs, one_mul]
_ = p * (r * b + s * c) := by rw [add_mul, mul_assoc s, hc]; ring⟩
· -- `x` is a unit, so `d` divides `p` and `p` divides `d ∣ a`: contradiction.
exfalso
apply hpa
obtain ⟨y, hy⟩ := Ideal.mem_span_singleton'.mp had
obtain ⟨u, rfl⟩ := hxu
exact ⟨y * ↑u⁻¹, by rw [← hy, ← hx]; linear_combination (-(y * d)) * Units.mul_inv u⟩The hierarchy itself (Theorems 6, 7 and 9) is in Mathlib as instances, so these proofs are just inferInstance. The real content is in the cited library proofs:
/-- Every Euclidean domain is a principal ideal domain: a non-zero ideal is generated by any of
its elements of least size. This is Mathlib's instance `EuclideanDomain.instIsPrincipalIdealRing`. -/
theorem ed_is_pid (R : Type*) [EuclideanDomain R] : IsPrincipalIdealRing R :=
inferInstance/-- Every principal ideal domain is a unique factorisation domain. Mathlib's instance
`PrincipalIdealRing.to_uniqueFactorizationMonoid` combines Euclid's lemma (`pid_irreducible_prime`
above) with the ascending chain condition on principal ideals. -/
theorem pid_is_ufd (R : Type*) [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] :
UniqueFactorizationMonoid R :=
inferInstance/-- For a field `K`, the polynomial ring `K[X]` is Euclidean (divide with remainder, measuring
size by degree), hence a principal ideal domain. Mathlib: `Polynomial.instEuclideanDomain`. -/
theorem polynomial_pid (K : Type*) [Field K] : IsPrincipalIdealRing K[X] :=
inferInstance/-- The Gaussian integers `ℤ[i]` are Euclidean for the norm `a² + b²` (round the exact quotient
in `ℚ(i)` to the nearest lattice point), hence a principal ideal domain. Mathlib: the
`EuclideanDomain` instance on `GaussianInt`. -/
theorem gaussian_pid : IsPrincipalIdealRing GaussianInt :=
inferInstance/-- `ℤ[X]` is a unique factorisation domain (Gauss's lemma: `R[X]` is a UFD when `R` is).
Mathlib: `Polynomial.uniqueFactorizationMonoid`. -/
theorem int_poly_ufd : UniqueFactorizationMonoid ℤ[X] :=
inferInstanceTheorem 12(a), proved here: is not principal in . The proof compares degrees, then the coefficient of , then constant terms, exactly as in the lesson:
/-- `ℤ[X]` is **not** a principal ideal domain: the ideal `(2, X)` is not principal. If
`(2, X) = (f)`, then `f ∣ 2` forces `f` to be a constant `c`; `f ∣ X` forces `c ∣ 1`; but every
element `2g + Xh` of `(2, X)` has an even constant term, so `c` is even. -/
theorem int_poly_not_pid : ¬ IsPrincipalIdealRing ℤ[X] := by
intro h
obtain ⟨f, hf⟩ := (h.principal (Ideal.span {(2 : ℤ[X]), X})).principal
have hfs : Ideal.span {(2 : ℤ[X]), X} = Ideal.span {f} := hf
have h2 : (2 : ℤ[X]) ∈ Ideal.span {f} := by rw [← hfs]; exact Ideal.subset_span (by simp)
have hX : (X : ℤ[X]) ∈ Ideal.span {f} := by rw [← hfs]; exact Ideal.subset_span (by simp)
have hf' : f ∈ Ideal.span {(2 : ℤ[X]), X} := by rw [hfs]; exact Ideal.mem_span_singleton_self f
-- The constant term of `f` is even.
obtain ⟨a, b, hab⟩ := Ideal.mem_span_pair.mp hf'
have heven : f.coeff 0 = 2 * a.coeff 0 := by
rw [← hab]
simp [mul_comm]
-- `f` is constant, because it divides `2`.
obtain ⟨g, hg⟩ := Ideal.mem_span_singleton'.mp h2
have hf0 : f ≠ 0 := by rintro rfl; simp at hg
have hg0 : g ≠ 0 := by rintro rfl; simp at hg
have hdeg : f.natDegree = 0 := by
have := congrArg natDegree hg
rw [natDegree_mul hg0 hf0] at this
have h2deg : (2 : ℤ[X]).natDegree = 0 := natDegree_ofNat 2
omega
rw [eq_C_of_natDegree_eq_zero hdeg] at hX
-- `C c ∣ X` gives `c * q₁ = 1`, so `c ∣ 1`; but `c` is even.
obtain ⟨q, hq⟩ := Ideal.mem_span_singleton'.mp hX
have h1 := congrArg (fun p : ℤ[X] => p.coeff 1) hq
simp only [coeff_mul_C, coeff_X_one] at h1
rw [heven] at h1
have h21 : (2 : ℤ) ∣ 1 := ⟨q.coeff 1 * a.coeff 0, by rw [← h1]; ring⟩
omegaFinally , which Mathlib writes ℤ√(-5), with elements ⟨x, y⟩ meaning . Mathlib provides the multiplicative norm but no domain instance for negative , so we prove one ourselves from the norm. We then prove Theorems 10 and 11(a, b) and conclude that is not a UFD:
/-- The norm on `ℤ[√−5]` is `N(x + y√−5) = (x + y√−5)(x − y√−5) = x² + 5y²`. It is
multiplicative (Mathlib's `Zsqrtd.norm_mul`). -/
theorem norm_formula (z : ℤ√(-5)) : z.norm = z.re ^ 2 + 5 * z.im ^ 2 := by
rw [Zsqrtd.norm_def]
ring/-- Only `0` has norm `0`: `x² + 5y² = 0` forces `x = y = 0`. -/
theorem norm_eq_zero (z : ℤ√(-5)) (h : z.norm = 0) : z = 0 := by
rw [norm_formula] at h
have hre : z.re ^ 2 = 0 := by nlinarith [sq_nonneg z.re, sq_nonneg z.im]
have him : z.im ^ 2 = 0 := by nlinarith [sq_nonneg z.re, sq_nonneg z.im]
ext
· simpa using hre
· simpa using him/-- `ℤ[√−5]` is an integral domain: if `a * b = 0` then `N(a) N(b) = N(a * b) = 0`, so one of
the norms is `0`, and only `0` has norm `0`. (Mathlib provides this instance for `ℤ[√d]` with
`d` a positive non-square; here `d = −5`.) -/
instance isDomain : IsDomain (ℤ√(-5)) :=
@NoZeroDivisors.to_isDomain _ _ _ ⟨fun {a b} h => by
have hn := congrArg Zsqrtd.norm h
rw [Zsqrtd.norm_mul, Zsqrtd.norm_zero] at hn
rcases mul_eq_zero.mp hn with ha | hb
· exact Or.inl (norm_eq_zero a ha)
· exact Or.inr (norm_eq_zero b hb)⟩/-- No element of `ℤ[√−5]` has norm `2`: `x² + 5y² = 2` forces `y = 0` and then `x² = 2`. -/
theorem norm_ne_two (z : ℤ√(-5)) : z.norm ≠ 2 := by
rw [norm_formula]
intro h
have him : z.im = 0 := by nlinarith [sq_nonneg z.re, sq_nonneg z.im]
rw [him] at h
have hle : z.re ≤ 1 := by nlinarith
have hge : -1 ≤ z.re := by nlinarith
interval_cases z.re <;> simp at h/-- Two factorisations of `6`: `2 · 3 = (1 + √−5)(1 − √−5)`. -/
theorem two_mul_three : (2 : ℤ√(-5)) * 3 = ⟨1, 1⟩ * ⟨1, -1⟩ := by
decide/-- `2` is irreducible in `ℤ[√−5]`. It is not a unit (its norm is `4`, units have norm `1`). If
`2 = a * b` then `N(a) N(b) = 4`; neither norm is `2` (`norm_ne_two`), so one of them is `1`, and
that factor is a unit. -/
theorem two_irreducible : Irreducible (2 : ℤ√(-5)) := by
have hunit : ∀ z : ℤ√(-5), z.norm = 1 → IsUnit z :=
fun z hz => (Zsqrtd.norm_eq_one_iff' (by norm_num) z).mp hz
refine ⟨fun h => ?_, fun a b hab => ?_⟩
· have := (Zsqrtd.norm_eq_one_iff' (by norm_num) 2).mpr h
rw [norm_formula] at this
norm_num at this
· have hn := congrArg Zsqrtd.norm hab
rw [Zsqrtd.norm_mul, norm_formula 2] at hn
norm_num at hn
have ha0 := Zsqrtd.norm_nonneg (by norm_num) a
have hb0 := Zsqrtd.norm_nonneg (by norm_num) b
have ha2 := norm_ne_two a
have hb2 := norm_ne_two b
have hapos : 0 < a.norm := by
rcases ha0.lt_or_eq with h | h
· exact h
· rw [← h] at hn; simp at hn
have hbpos : 0 < b.norm := by
rcases hb0.lt_or_eq with h | h
· exact h
· rw [← h] at hn; simp at hn
have hale : a.norm ≤ 4 := by
have := mul_le_mul_of_nonneg_left (show (1 : ℤ) ≤ b.norm by omega) ha0
linarith
interval_cases hna : a.norm
· exact Or.inl (hunit a hna)
· exact absurd rfl ha2
· omega
· exact Or.inr (hunit b (by omega))/-- `2` is not prime in `ℤ[√−5]`: it divides `(1 + √−5)(1 − √−5) = 6` but neither factor, since
`2 * c` always has even real part while `1 ± √−5` has real part `1`. -/
theorem two_not_prime : ¬ Prime (2 : ℤ√(-5)) := by
intro hp
rcases hp.dvd_or_dvd ⟨3, two_mul_three.symm⟩ with ⟨c, hc⟩ | ⟨c, hc⟩
· have := congrArg Zsqrtd.re hc
simp at this
omega
· have := congrArg Zsqrtd.re hc
simp at this
omega/-- **`ℤ[√−5]` is not a unique factorisation domain.** In a UFD every irreducible element is
prime, but `2` is irreducible (`two_irreducible`) and not prime (`two_not_prime`). -/
theorem not_ufd : ¬ UniqueFactorizationMonoid (ℤ√(-5)) := fun h =>
two_not_prime (h.irreducible_iff_prime.mp two_irreducible)What is and is not formalised. Proved independently here: Proposition 1(d), Theorem 2, Proposition 3(2, 3) and the kernel ideal, Proposition 5, Theorem 8(b), Theorem 12(a) (non-principality of ), and Theorems 10 and 11(a, b) — that is a domain but not a UFD. Cited from Mathlib: Theorems 6, 7 and 9, Gauss's lemma for , and the finite-domain theorem in its non-commutative (Wedderburn) form. Not formalised: Theorem 11(c) and the ideal factorisation of , and Theorem 12(b). As far as we know, Mathlib does not contain the fact that is a non-Euclidean PID.
Census and factorisation by computer
The first program sorts every residue of into units, zero divisors and , counts nilpotents, idempotents and ideals, and checks the general statements of the lesson for every .
"""Units, zero divisors, nilpotents and ideals in the rings Z/nZ.
For each n the program sorts the residues 0, ..., n - 1 into units (elements
with a multiplicative inverse) and zero divisors (non-zero a with ab = 0 for
some non-zero b), finds the nilpotent elements (a^k = 0) and the idempotents
(e^2 = e), and lists all ideals by brute force. It confirms, for every n up to
60, that each non-zero residue is exactly one of unit or zero divisor, that the
units number phi(n) = #{a : gcd(a, n) = 1}, that the ideals correspond to the
divisors of n, and that Z/nZ is a domain exactly when it is a field, exactly
when n is prime. Exact and exhaustive for these n only.
"""
from math import gcd
def units(n):
"""Residues a in Z/nZ with some b such that a * b = 1 (mod n)."""
return [a for a in range(n) if any(a * b % n == 1 % n for b in range(n))]
def zero_divisors(n):
"""Non-zero residues a with a * b = 0 (mod n) for some non-zero b."""
return [a for a in range(1, n) if any(a * b % n == 0 for b in range(1, n))]
def nilpotents(n):
"""Residues a with a^k = 0 (mod n) for some k >= 1 (k = n suffices)."""
return [a for a in range(n) if pow(a, n, n) == 0]
def idempotents(n):
"""Residues e with e * e = e (mod n)."""
return [e for e in range(n) if e * e % n == e]
def ideals(n):
"""All ideals of Z/nZ, found by brute force as sorted tuples.
An ideal is an additive subgroup closed under multiplication by every
residue. Every subset generated by one element is checked, and the ideal
generated by a set is the one generated by the gcd, so this is complete;
the test file also checks completeness against all subsets for small n.
"""
found = set()
for a in range(n):
ideal = tuple(sorted({a * r % n for r in range(n)}))
found.add(ideal)
return sorted(found, key=len)
def is_ideal(subset, n):
"""True when subset is non-empty, closed under +, and absorbs products."""
s = set(subset)
return bool(s) and all((x + y) % n in s and x * r % n in s
for x in s for y in s for r in range(n))
def is_prime(n):
"""Trial division."""
return n >= 2 and all(n % p for p in range(2, int(n ** 0.5) + 1))
def main():
print(" n units zero divisors ideals idempotents non-zero nilpotents")
for n in (2, 4, 6, 7, 8, 9, 10, 12, 15, 30):
u, z = units(n), zero_divisors(n)
nil = [a for a in nilpotents(n) if a]
print(f"{n:>2} {len(u):>5} {len(z):>13} {len(ideals(n)):>6} "
f"{len(idempotents(n)):>11} {nil}")
split = phi = divisors = domain = True
for n in range(2, 61):
u, z = set(units(n)), set(zero_divisors(n))
split &= u.isdisjoint(z) and u | z == set(range(1, n))
phi &= len(u) == sum(gcd(a, n) == 1 for a in range(n))
divisors &= len(ideals(n)) == sum(n % d == 0 for d in range(1, n + 1))
domain &= (not z) == (len(u) == n - 1) == is_prime(n)
print("For every n from 2 to 60:")
print(f" each non-zero residue is a unit or a zero divisor, not both: {split}")
print(f" number of units = phi(n) = #{{a : gcd(a, n) = 1}}: {phi}")
print(f" number of ideals = number of divisors of n: {divisors}")
print(f" no zero divisors <=> every non-zero a a unit <=> n prime: {domain}")
print()
print("Epistemic status: exact, exhaustive checks for n <= 60. In a finite")
print("commutative ring every non-zero element is a unit or a zero divisor,")
print("and Z/nZ is a field exactly when n is prime: those are theorems, proved")
print("in the lesson; the table is evidence and illustration, not proof.")
if __name__ == "__main__":
main()Notice the patterns. Nilpotents appear exactly when has a repeated prime factor. There are idempotents, where is the number of distinct prime factors; this reflects the Chinese remainder theorem of the next lesson. The table is exact evidence for these . The statements that hold for all are the theorems proved above.
The norm makes factorisation in and a finite search. A factor of has norm dividing , and there are finitely many elements of each norm. The second program lists every factorisation into irreducibles of the integers in both rings.
"""Factorisation by norms in Z[i] and Z[sqrt(-5)].
An element x + y*sqrt(d) (d = -1 or -5) has norm N = x^2 - d*y^2, and the norm is
multiplicative, so a factor of z has a norm dividing N(z). That makes an exact
search possible: list the elements of each smaller norm and test divisibility.
The program finds every factorisation of 2, ..., 30 into irreducibles (up to
order and units) in both rings, shows that Euclidean division by 2 fails in
Z[sqrt(-5)] (every remainder has norm at least 6 > N(2) = 4), and checks that
rounding the exact quotient always works in Z[i] on a box of examples.
"""
from fractions import Fraction
from functools import lru_cache
from itertools import product
def norm(z, d):
"""N(x + y sqrt(d)) = x^2 - d y^2 (positive for d < 0, z != 0)."""
x, y = z
return x * x - d * y * y
def mul(z, w, d):
"""(a + b r)(c + e r) with r^2 = d."""
return (z[0] * w[0] + d * z[1] * w[1], z[0] * w[1] + z[1] * w[0])
def divide(z, w, d):
"""Return z / w if it lies in Z[sqrt(d)], else None (uses z * conj(w))."""
n = norm(w, d)
x, y = mul(z, (w[0], -w[1]), d)
if x % n or y % n:
return None
return (x // n, y // n)
def of_norm(n, d):
"""All elements of norm n (finitely many, since d < 0)."""
bound = int(n ** 0.5) + 1
return [(x, y) for x in range(-bound, bound + 1)
for y in range(-bound, bound + 1) if norm((x, y), d) == n]
def units(d):
"""The units: the elements of norm 1."""
return of_norm(1, d)
def canonical(z, d):
"""A fixed representative of z up to multiplication by units."""
return max(mul(z, u, d) for u in units(d))
def proper_divisors(z, d):
"""Divisors a of z with 1 < N(a) < N(z), one per associate class."""
n = norm(z, d)
found = set()
for m in range(2, n):
if n % m == 0:
for a in of_norm(m, d):
if divide(z, a, d) is not None:
found.add(canonical(a, d))
return sorted(found)
def is_irreducible(z, d):
"""Not zero, not a unit, and no factor of intermediate norm."""
return norm(z, d) > 1 and not proper_divisors(z, d)
@lru_cache(maxsize=None)
def factorisations(z, d):
"""All factorisations of z into irreducibles, as sorted tuples of
canonical representatives (so order and units are ignored)."""
if is_irreducible(z, d):
return frozenset({(canonical(z, d),)})
result = set()
for a in proper_divisors(z, d):
if is_irreducible(a, d):
for rest in factorisations(divide(z, a, d), d):
result.add(tuple(sorted(rest + (a,))))
return frozenset(result)
def show(z, d):
"""Format x + y*sqrt(d) compactly, e.g. 1+r or 2 or -r."""
x, y = z
if y == 0:
return str(x)
r = "i" if d == -1 else "r"
coef = "" if abs(y) == 1 else str(abs(y))
if x == 0:
return f"{'-' if y < 0 else ''}{coef}{r}"
return f"{x}{'-' if y < 0 else '+'}{coef}{r}"
def best_remainder(a, b, d, box=6):
"""Least N(a - q b) over q = (s, t) with |s|, |t| <= box."""
return min(norm((a[0] - p[0], a[1] - p[1]), d)
for p in (mul(q, b, d) for q in product(range(-box, box + 1),
repeat=2)))
def gaussian_rounding_works(limit=6):
"""Check N(a - q b) < N(b) with q = a/b rounded, for a, b in a box."""
rng = range(-limit, limit + 1)
for a in product(rng, repeat=2):
for b in product(rng, repeat=2):
if b == (0, 0):
continue
n = norm(b, -1)
x, y = mul(a, (b[0], -b[1]), -1)
q = (round(Fraction(x, n)), round(Fraction(y, n)))
r = (a[0] - mul(q, b, -1)[0], a[1] - mul(q, b, -1)[1])
if norm(r, -1) >= n:
return False
return True
def main():
for d, name in ((-1, "Z[i]"), (-5, "Z[sqrt(-5)] (r = sqrt(-5))")):
print(f"{name}: integers 2..30 with more than one factorisation")
several = []
for n in range(2, 31):
facs = factorisations((n, 0), d)
if len(facs) > 1:
several.append(n)
first, second = sorted(facs, key=len)[:2]
shown = " = ".join(" ".join(f"({show(p, d)})" for p in f)
for f in (first, second))
print(f" {n:>2}: {len(facs)} ways, e.g. {shown}")
if not several:
print(" none: every factorisation is unique up to order and units")
print("Irreducible but not prime in Z[sqrt(-5)]: 2 divides (1+r)(1-r) = 6,")
print(f" 2 irreducible: {is_irreducible((2, 0), -5)}; 2 divides 1+r: "
f"{divide((1, 1), (2, 0), -5) is not None}")
print(f"Euclid fails in Z[sqrt(-5)]: least N((1+r) - 2q) = "
f"{best_remainder((1, 1), (2, 0), -5)} >= N(2) = 4")
print(f"Z[i]: rounding a/b gives N(remainder) < N(b) for all a, b with")
print(f" coordinates in -6..6: {gaussian_rounding_works()}")
print()
print("Epistemic status: exact searches, justified by the multiplicative")
print("norm, for the integers 2..30 only. They illustrate, but do not prove,")
print("that Z[i] is a UFD (proved via its Euclidean algorithm) and exhibit a")
print("genuine counterexample to unique factorisation in Z[sqrt(-5)].")
if __name__ == "__main__":
main()In every factorisation is unique, as Theorem 9 guarantees. In ten of the integers up to factor in more than one way, and factors in five different ways. The searches are exact, and the failure of Euclidean division by is a proved counterexample: has norm at least for all integers , because odd numbers have odd squares.
Explore: units and zero divisors on a clock
Switch the clock to the multiplication tab and search for multiplicative partners. For a prime number of hours, every non-zero residue has a partner, so is a field. For , only do. Each of the others times some non-zero residue lands on , so those are zero divisors. Try , , and , and predict which residues will have partners before you look: exactly those coprime to .
The clock laboratory
On a clock with k hours, counting wraps around. Explore adding and multiplying.
9 + 5 = 14 ≡ 2 (mod 12)
14 hours forward on a 12-hour clock lands on 2: the remainder when 14 is divided by 12.
Exercises
1. Rings, ideals and fields
Warm-upHumanHow many units does the ring have?
2. Rings, ideals and fields
Warm-upHumanWhich of these rings are integral domains? (Select all that apply.)
3. Rings, ideals and fields
CoreHumanWhich of these subsets of are ideals? (Select all that apply.)
4. Rings, ideals and fields
CoreHumanis a principal ideal domain. Which polynomial generates the ideal ?
5. Rings, ideals and fields
CoreHumanIn the proof that a Euclidean domain is a PID, we take a non-zero ideal , choose of least size , and divide any as with or . Why must ?
6. Rings, ideals and fields
CoreHumanIn the element is irreducible. Which of these products show that is not prime — that is, divides the product but divides neither factor? (Select all that apply.)
7. Rings, ideals and fields
CoreHumanHow many Gaussian integers have norm ?
8. Rings, ideals and fields
CoreFormalWhich Lean statement formalises “every finite integral domain is a field”?
9. Rings, ideals and fields
StretchComputationalWrite classify(n) returning a pair (units, zero_divisors) of sorted lists for the ring (): units are the with for some , and zero_divisors the non-zero with for some non-zero . Then check that together they contain every non-zero residue exactly once.
Common misconceptions
Misconception
"Every ring is commutative and has a ." Matrix rings and the quaternions are not commutative, and some authors do not require a (then is a ring and homomorphisms need not preserve ). State your conventions. In this lesson rings have , homomorphisms preserve it, and commutativity is assumed only when said.
Misconception
"Ideals are subrings" (or the reverse). A subring contains ; a proper ideal never does, since an ideal containing a unit is everything. is a subring that is not an ideal, and is an ideal that is not a subring. Ideals are the kernels of homomorphisms; subrings are their images.
Misconception
"Irreducible and prime mean the same thing." In , in and in every UFD they coincide. In general, prime implies irreducible (Proposition 5) but not conversely: is irreducible in and divides without dividing either factor.
Misconception
"A domain in which every element factors into irreducibles has unique factorisation." Existence and uniqueness are separate. In every non-zero non-unit does factor into irreducibles (induct on the norm), but not uniquely. Uniqueness needs Euclid's lemma, that is, irreducibles must be prime.
Misconception
"Every PID is Euclidean" and "every UFD is a PID". is a PID that is not Euclidean, and and are UFDs that are not PIDs. The hierarchy is strict.
Misconception
" is always a field" or "a ring without zero divisors is a field". has zero divisors. has none and is not a field. Finiteness is what turns "no zero divisors" into "every non-zero element is a unit" (Theorem 2).
Many ways of seeing
Geometry— Ideals are shapes
In the polynomial ring , an ideal cuts out a shape, the variety . Bigger ideals give smaller shapes: is the circle, is the two points , and is the single point . Hilbert's Nullstellensatz (1893) makes the dictionary exact. The maximal ideals of are exactly the ideals of points. Prime ideals correspond to irreducible varieties, and iff and have the same radical. Ring theory becomes geometry: this is the starting point of commutative algebra and algebraic geometry. Unique factorisation also has a geometric meaning: in a UFD, every hypersurface is cut out by a single equation.
Topology— The space of primes
Grothendieck made every commutative ring into a space. Its points are the prime ideals, forming . Its closed sets are the sets ; this is the Zariski topology. has a closed point for each prime , and one generic point , whose closure is the whole space. Its proper closed sets are the finite sets of primes. The space is connected, and that is the topological form of the fact that has no idempotents other than and . In general is disconnected iff with both factors non-zero. This explains the idempotents counted by the first experiment: is a finite discrete set with one point for each prime dividing .
Number theory— Ideal numbers and the class group
For a number field , its ring of integers need not be a UFD. It is always a Dedekind domain: non-zero ideals factor uniquely into prime ideals. The failure of unique factorisation of elements is measured by the class group, the group of ideals modulo principal ideals. It is finite, and its order is the class number. For the class number is : the non-principal ideal has principal. By the Baker–Heegner–Stark theorem (1952–1967), the imaginary quadratic fields with class number are exactly for . Kummer proved Fermat's Last Theorem for every prime that does not divide the class number of (the regular primes). See algebraic number theory.
Analysis— Rings of functions
Analysts meet rings of functions everywhere. For a compact Hausdorff space , the maximal ideals of are exactly the ideals of points (Gelfand–Kolmogorov, 1939). So can be recovered from the ring. For commutative C*-algebras, Gelfand duality makes this an equivalence between compact Hausdorff spaces and rings with extra analytic structure. Locally, the ring of convergent power series (germs of holomorphic functions at ) is a PID with essentially one prime, . Every non-zero germ is times a unit, where is its order of vanishing, so it is a discrete valuation ring. In several variables the ring of germs is still a UFD (a consequence of the Weierstrass preparation theorem), but no longer a PID.
Category theory— The category of rings
Rings and homomorphisms form a category , with commutative rings forming . is initial: every ring receives exactly one homomorphism from , determined by . The zero ring is terminal. Kernels in the categorical sense are subtle, because is not additive; ideals are best seen as the kernel pairs of homomorphisms, and quotients as coequalisers (limits and colimits). is a contravariant functor: a homomorphism pulls prime ideals back to prime ideals, giving a continuous map . The category of Grothendieck's affine schemes is equivalent to — algebra read backwards as geometry.
Wonder Trails
Rings grow out of clock arithmetic and the search for inverses. These optional trails start there.
Wonder Trail · Optional · never gradedInverses and structureEvery integer can be added to another integer to get . So why can almost no integer be multiplied by another integer to get ?Follow the trail 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
- Division and Euclid's lemma. Euclid's Elements (Book VII, c. 300 BCE) contains the Euclidean algorithm and the lemma that a prime dividing a product divides a factor (VII.30). Unique factorisation of integers was first stated and proved explicitly by Carl Friedrich Gauss in the Disquisitiones Arithmeticae (1801).
- Arithmetic with . Brahmagupta (628 CE) discovered the composition identity , which is the multiplicativity of the norm on . Bhāskara II (12th century) used it in the chakravāla method for . In Baghdad, al-Samawʾal (12th century) developed the arithmetic of polynomials, including long division.
- New integers. Euler (1770) worked with numbers and , assuming unique factorisation. Gauss (1832) introduced the Gaussian integers to state biquadratic reciprocity and proved that they factor uniquely.
- Failure and repair. Lamé's 1847 attempt on Fermat's Last Theorem assumed unique factorisation in cyclotomic integers, and Liouville objected at once. Ernst Kummer had found failures in 1844 and introduced "ideal complex numbers" (1847), which let him prove the theorem for regular primes. Richard Dedekind (1871) replaced ideal numbers by ideals, sets of actual numbers, and proved unique factorisation of ideals. Leopold Kronecker developed a parallel theory of divisors.
- Abstraction. David Hilbert's Zahlbericht (1897) used the word Zahlring. Abraham Fraenkel gave axioms for rings in 1914. Emmy Noether's Idealtheorie in Ringbereichen (1921) founded modern ring theory, with chain conditions (Noetherian rings) like the one in the proof of Theorem 9. Wolfgang Krull, Emil Artin, B. L. van der Waerden's Moderne Algebra (1930–31) and later Alexander Grothendieck's schemes (1960s) shaped the subject as it is taught today.
Further reading
- David S. Dummit and Richard M. Foote, Abstract Algebra (3rd edition, 2004), chapters 7–9 — rings, ideals, EDs, PIDs and UFDs, including .
- Michael Artin, Algebra (2nd edition, 2011), the chapters on rings and factorisation, including quadratic integers and ideal factorisation.
- Kenneth Ireland and Michael Rosen, A Classical Introduction to Modern Number Theory (2nd edition, 1990), chapter 1 — unique factorisation in , , and .
- Ian Stewart and David Tall, Algebraic Number Theory and Fermat's Last Theorem (4th edition, 2015) — the story of Kummer, ideals and class groups.
- M. F. Atiyah and I. G. Macdonald, Introduction to Commutative Algebra (1969) — the next step: localisation, Noetherian rings, Spec.