The same rules in different worlds
Here are four calculations from four different worlds.
- Clocks. A bus leaves Nairobi at 9 o'clock for a journey of 5 hours; it arrives at o'clock. On a 12-hour clock, adding 12 hours changes nothing.
- Shuffles. A card dealer in Macau cuts a deck, then riffles it. Doing the riffle first and the cut second usually gives a different order of the cards. Every shuffle can be undone by some other shuffle.
- Functions. "Add 3" followed by "double" is "", but "double" followed by "add 3" is "". The function does nothing at all.
- Matrices. A graphics programmer in São Paulo rotates an image by a quarter turn and then shears it. The combined effect is the product of two matrices — and again, the order matters.
In each world there is a way of combining two things into a third, the combination can be bracketed however we like, there is a do-nothing element, and sometimes things can be undone. These four features — closure, associativity, identity, inverses — are all we need to prove a surprising number of theorems. Prove them once, in the abstract, and they hold in every world at once. That economy is the point of abstract algebra.
Operation tables
A finite operation can be written as a table, like a multiplication table. Here are addition and multiplication of remainders modulo , that is, in (see modular arithmetic):
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 |
| 1 | 1 | 2 | 3 | 0 |
| 2 | 2 | 3 | 0 | 1 |
| 3 | 3 | 0 | 1 | 2 |
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 |
| 2 | 0 | 2 | 0 | 2 |
| 3 | 0 | 3 | 2 | 1 |
What can we read off?
- In the addition table the row of copies the header: is an identity. Every row contains a somewhere, so every element can be undone: , . Every row is a rearrangement of .
- In the multiplication table the identity is . The rows of and contain a (, so undoes itself), but the rows of and do not: and have no multiplicative partner. And : two non-zero things multiply to zero, which never happens with ordinary numbers.
- Both tables are symmetric about the diagonal: the operations are commutative. Tables for shuffles or matrices are not.
Associativity is the one law a table hides: to check we have to look up every triple. For elements that is checks — one reason to prove associativity once and for all, as we will.
Definitions
Definition— binary operation
A binary operation on a set is a function ; we write for . The definition includes closure: for all , the result must again lie in . The operation is associative if for all , and commutative if for all . An element is an identity if for all .
Definition— monoid, group
A monoid is a set with an associative binary operation and an identity element . If , then is an inverse of , and is invertible (or a unit). A group is a monoid in which every element is invertible. A monoid or group is abelian if its operation is commutative.
Because associativity lets us drop brackets, we usually write the operation as juxtaposition, , and the identity as (multiplicative notation); for abelian groups we often write , and instead (additive notation). The notation is a convenience: the identity of a monoid is whatever element behaves as one — the number , the number , the identity function, the empty string or the whole set.
Definition— ring, field
A ring is a set with two binary operations such that
- is an abelian group (the additive inverse of is written );
- is a monoid;
- multiplication distributes over addition on both sides: and .
The ring is commutative if its multiplication is. The units of are its invertible elements under multiplication; they form the set . A field is a commutative ring in which and every non-zero element is a unit.
Note
In this lesson every ring has a multiplicative identity . Some books allow "rings without " (for example the even integers ); when reading, check the convention.
Definition— homomorphism, isomorphism
A homomorphism is a function between two structures of the same kind that preserves the operations and the identities:
- a monoid homomorphism satisfies and ;
- a group homomorphism is a monoid homomorphism between groups (we will prove that alone already forces );
- a ring homomorphism satisfies , and .
An isomorphism is a bijective homomorphism; its inverse function is automatically a homomorphism. Isomorphic structures are "the same structure with the elements renamed".
Examples and non-examples
Example— Numbers
| Set and operation | Associative? | Identity | Every element invertible? | Structure |
|---|---|---|---|---|
| , | yes | no ( has no partner) | commutative monoid | |
| , | yes | yes, | abelian group | |
| , | yes | no, only | commutative monoid | |
| , | yes | yes, | abelian group | |
| , | no: | none | — | not a monoid |
| , | yes | no | commutative monoid | |
| , | yes | , since | no | commutative monoid |
| odd integers, | — | — | — | not even an operation |
The last row fails closure: is not odd. Subtraction fails associativity, and although , the number is not a two-sided identity because . The row is a reminder that an identity need not look like or in any familiar sense — it just has to do nothing.
Example— Remainders
On , the set of remainder classes modulo , both and are well defined (see congruences), and is a commutative ring. is an abelian group, the cyclic group of order . Under it is only a monoid; its units are the classes with . For these are ; for they are all of .
Example— Functions and permutations
For any set , the functions form a monoid under composition: and (see composition). Its identity is the identity function — neither nor . A function is invertible in this monoid exactly when it is a bijection, so the invertible elements form the symmetric group ; for it is written and has elements.
is not abelian. Let swap and , and swap and . Then but . It is the smallest non-abelian group.
Example— Strings
The words over an alphabet, such as "ka" and "ribu", form a monoid under concatenation: "ka" · "ribu" = "karibu". The identity is the empty word, and the monoid is not commutative. Only the empty word is invertible — concatenation can never make a word shorter.
Example— Matrices
The matrices with real entries form a ring under matrix addition and multiplication, with identity . It is not commutative, and it has zero divisors — non-zero elements whose product is zero:
Its units are the invertible matrices, those with non-zero determinant; they form the group (see linear algebra).
Example— Rings and fields
, , , , , the polynomials and the matrices are rings. , , and for prime are fields. , , and are not: in the number has no inverse, in the polynomial has none, and in the class has none (indeed ).
The first theorems
The theorems in this section use only the axioms, so they hold in every monoid, group or ring at once.
Theorem— Theorem 1 (uniqueness of the identity)
A binary operation has at most one identity element.
Proof
Suppose and are both identities. Compute in two ways. Since is an identity, . Since is an identity, . Hence .
∎
Notice that the proof did not use associativity. It also explains why it is safe to speak of the identity of a monoid.
Theorem— Theorem 2 (uniqueness of inverses)
In a monoid , if and , then . In particular, an element has at most one inverse.
Proof
Using the identity law, associativity and the two hypotheses,
∎
So we may write for the inverse of an invertible element . This time associativity was essential, and the misconceptions section shows that one-sided inverses on their own need not be unique.
Theorem— Corollary 3 (algebra in a group)
Let be a group and . Then
- and ;
- (cancellation) if then , and if then ;
- the equation has exactly one solution, . Consequently each row (and each column) of the operation table of a finite group contains every element exactly once.
Proof
(1) satisfies , so is an inverse of ; by Theorem 2 it is the inverse. Similarly and , so is the inverse of . Note the reversed order: to undo "put on socks, then shoes", take off the shoes first.
(2) Multiply on the left by : . The other case is symmetric.
(3) is a solution because ; if then by cancellation. In the row of in the table, the entry in column is ; existence and uniqueness of solutions say that each appears in exactly one column.
∎
Theorem— Theorem 4 (the units of a monoid form a group)
If is a monoid, its set of units is a group under the same operation. In particular, is a group, , is a group, and is a group.
Proof
We check that is closed and contains the identity and the inverses; associativity is inherited from . The identity is a unit, with inverse . If are units then so is , with inverse (the computation in Corollary 3(1) used only associativity). If is a unit then so is , with inverse . So every element of has an inverse lying in .
∎
Theorem— Theorem 5 (arithmetic in a ring)
In every ring, , and . If in , then .
Proof
The first three are proved from the ring axioms exactly as in the lesson on integers: for instance , and cancelling in the group leaves . If , then every satisfies .
∎
This is why a field must have , and why is excluded from the elements required to be invertible: if had an inverse , then , and the ring would collapse to a single point.
Theorem— Theorem 6 (fields have no zero divisors)
In a field, if then or .
Proof
If , multiply by : .
∎
Theorem— Theorem 7 (Z is not a field; Q is)
is a commutative ring but not a field; is a field.
Proof
The ring axioms for are the familiar laws of arithmetic. But has no inverse: for every integer , the number is even, so . In , every non-zero element can be written with integers , and satisfies .
∎
Passing from to is exactly the act of adjoining the missing inverses, as the construction of the number systems makes precise.
Theorem— Theorem 8 (when is Z/nZ a field?)
For an integer , the ring is a field if and only if is prime.
Proof
If , then has , so it is not a field; and is not prime.
If is composite, write with . The classes of and are non-zero in (neither nor is a multiple of ), but . By Theorem 6, is not a field.
If is prime, let be a non-zero class, represented by an integer not divisible by . The only positive divisors of are and , so . By Bézout's identity (see divisibility and Euclid's algorithm) there are integers with . Reducing modulo gives in , so is a unit. The other field axioms are inherited from , and because .
∎
The same argument shows, for every , that the class of is a unit in exactly when . The field is often written .
Theorem— Theorem 9 (group homomorphisms preserve identities and inverses)
Let and be groups and a function with for all . Then and for all .
Proof
, and cancelling in gives . Then and likewise , so is an inverse of ; by Theorem 2 it is the inverse.
∎
For monoids the first step fails — there may be no cancellation — and preserving must be demanded. The zero map , , satisfies but sends to .
Example— Homomorphisms everywhere
- Reduction modulo , , , is a ring homomorphism. The elements sent to — its kernel — are the multiples of .
- The exponential satisfies . It is a group isomorphism, with inverse : logarithm tables were, in effect, a way of turning multiplication into addition.
- The determinant is a group homomorphism, because .
- Length of a word is a monoid homomorphism from words under concatenation to : the length of a concatenation is the sum of the lengths.
Algebraic structures in Lean and Mathlib
Mathlib describes structures with type classes: Monoid M, Group G, CommRing R, Field K, and many more in a carefully layered hierarchy. A homomorphism of monoids is M →* N, of rings R →+* S. Writing [Group G] in a theorem means "for every group " — so a theorem proved once applies to every instance, just as in the human proofs above.
Uniqueness. The identity theorem is stated for an arbitrary operation op (no associativity assumed); the inverse theorem is the five-step calc of Theorem 2, one axiom per line. Mathlib's own name for it is left_inv_eq_right_inv.
/-- **An identity element is unique.** If `e` and `e'` are both two-sided identities for a
binary operation `op` on `S`, then `e = e'`. The proof is one line on paper: compute `op e e'`
in two ways — it is `e` because `e'` is an identity, and `e'` because `e` is one. No
associativity is needed. -/
theorem identity_unique {S : Type*} (op : S → S → S) {e e' : S}
(he : ∀ a, op e a = a ∧ op a e = a) (he' : ∀ a, op e' a = a ∧ op a e' = a) : e = e' :=
calc e = op e e' := ((he' e).2).symm
_ = e' := (he e').1/-- **Inverses are unique.** In a monoid, if `b` is a left inverse of `a` (`b * a = 1`) and `c`
is a right inverse (`a * c = 1`), then `b = c`. In particular an element has at most one
two-sided inverse. Each step of the `calc` is one monoid axiom; the key step is associativity. -/
theorem inverse_unique {M : Type*} [Monoid M] {a b c : M} (hb : b * a = 1) (hc : a * c = 1) :
b = c :=
calc b = b * 1 := (mul_one b).symm
_ = b * (a * c) := by rw [hc]
_ = (b * a) * c := (mul_assoc b a c).symm
_ = 1 * c := by rw [hb]
_ = c := one_mul c/-- The same fact, from Mathlib: `left_inv_eq_right_inv`. -/
theorem inverse_unique_library {M : Type*} [Monoid M] {a b c : M} (hb : b * a = 1)
(hc : a * c = 1) : b = c :=
left_inv_eq_right_inv hb hcExamples and non-examples. is not a group, the odd integers are not closed under addition, the functions from a type to itself form a monoid (built by hand: every axiom holds by rfl, "by definition"), is not abelian, and integer matrices have zero divisors.
/-- **`(ℕ, +)` is a monoid but not a group.** Not every natural number has an additive inverse:
there is no `b : ℕ` with `1 + b = 0`. (`omega` decides this linear fact about naturals.) -/
theorem nat_add_not_group : ¬ ∀ a : ℕ, ∃ b : ℕ, a + b = 0 := by
intro h
obtain ⟨b, hb⟩ := h 1
omega/-- **Closure can fail.** Addition is not a binary operation on the odd integers: `1` and `1`
are odd but `1 + 1 = 2` is not. -/
theorem odd_not_closed : ¬ ∀ a b : ℤ, Odd a → Odd b → Odd (a + b) := by
intro h
have h2 : Odd ((1 : ℤ) + 1) := h 1 1 odd_one odd_one
rw [Int.odd_iff] at h2
norm_num at h2/-- **The functions from a set to itself form a monoid under composition.** The product
`f * g` is `f ∘ g` ("`f` after `g`") and the identity element is the identity function `id` —
not `0` or `1`. All three axioms hold by `rfl`: composition is associative and `id` is neutral
*by definition*. (Mathlib's version is `Function.End α`.) -/
@[instance_reducible]
def endoMonoid (α : Type*) : Monoid (α → α) where
mul f g := f ∘ g
one := id
mul_assoc _ _ _ := rfl
one_mul _ := rfl
mul_one _ := rfl/-- **The symmetric group `S₃` is not commutative.** The bijections of `{0, 1, 2}` form a group
under composition (`Equiv.Perm (Fin 3)`, with `σ * τ = σ ∘ τ`), and the two transpositions
`(0 1)` and `(1 2)` do not commute. `decide` checks the finite computation. -/
theorem perm_not_comm :
∃ σ τ : Equiv.Perm (Fin 3), σ * τ ≠ τ * σ :=
⟨Equiv.swap 0 1, Equiv.swap 1 2, by decide⟩/-- **A non-commutative ring with zero divisors.** The `2 × 2` integer matrices form a ring in
which two non-zero matrices can multiply to `0`, and in which the order of multiplication
matters. Here `A = !![0, 1; 0, 0]` and `B = !![1, 0; 0, 0]`: `A * B = 0` but `B * A = A ≠ 0`. -/
theorem matrix_zero_divisors :
let A : Matrix (Fin 2) (Fin 2) ℤ := !![0, 1; 0, 0]
let B : Matrix (Fin 2) (Fin 2) ℤ := !![1, 0; 0, 0]
A ≠ 0 ∧ B ≠ 0 ∧ A * B = 0 ∧ B * A = A := by
intro A B
refine ⟨?_, ?_, ?_, ?_⟩
· intro h
have := congrFun (congrFun h 0) 1
simp [A] at this
· intro h
have := congrFun (congrFun h 0) 0
simp [B] at this
· ext i j
fin_cases i <;> fin_cases j <;> simp [A, B, Matrix.mul_apply, Fin.sum_univ_two]
· ext i j
fin_cases i <;> fin_cases j <;> simp [A, B, Matrix.mul_apply, Fin.sum_univ_two]Rings and fields. IsField R is Mathlib's proposition "the ring is a field". The characterisation of (Mathlib's ZMod n) follows the human proof of Theorem 8 case by case; for , ZMod 0 is itself, which is also covered. The direction "prime implies field" uses Mathlib's instance Field (ZMod p), which finds inverses by Bézout exactly as we did.
/-- **`ℤ` is a ring but not a field:** `2 ≠ 0` has no multiplicative inverse in `ℤ`.
(`IsField R` is Mathlib's proposition "`R` is a field": `0 ≠ 1`, commutativity, and inverses
for non-zero elements.) The final step, "no integer `b` has `2b = 1`", is decided by `omega`. -/
theorem int_not_field : ¬ IsField ℤ := by
intro h
obtain ⟨b, hb⟩ := h.mul_inv_cancel (two_ne_zero : (2 : ℤ) ≠ 0)
omega/-- **`ℚ` is a field.** Mathlib's `Field ℚ` instance (inverse `(a/b)⁻¹ = b/a`), turned into the
proposition `IsField ℚ` by `Field.toIsField`. -/
theorem rat_field : IsField ℚ := Field.toIsField ℚ/-- **`ℤ/nℤ` is a field if and only if `n` is prime.**
* If `n = p` is prime, Mathlib's instance `Field (ZMod p)` applies (it finds inverses with
Bézout's identity).
* If `n = 0`, `ZMod 0` is `ℤ`, which is not a field; if `n = 1`, `ZMod 1` has only one
element, and a field needs `0 ≠ 1`.
* If `n = m * b` with `2 ≤ m < n`, then `m` and `b` are non-zero in `ZMod n` but `m * b = 0`.
If `m` had an inverse `c`, then `b = (c * m) * b = c * (m * b) = 0`, a contradiction. -/
theorem zmod_isField_iff (n : ℕ) : IsField (ZMod n) ↔ n.Prime := by
constructor
· intro h
by_contra hn
rcases Nat.lt_or_ge n 2 with hlt | hge
· interval_cases n
· exact Int.not_isField h
· exact not_isField_of_subsingleton (ZMod 1) h
· simp only [Nat.prime_def_lt', not_and, not_forall, not_not] at hn
obtain ⟨m, hm2, hmn, hdvd⟩ := hn hge
obtain ⟨b, rfl⟩ := hdvd
have hb1 : 1 < b := by
by_contra hb
interval_cases b <;> omega
have hm0 : (m : ZMod (m * b)) ≠ 0 := by
rw [Ne, ZMod.natCast_eq_zero_iff]
intro hd
have := Nat.le_of_dvd (by omega) hd
omega
have hb0 : (b : ZMod (m * b)) ≠ 0 := by
rw [Ne, ZMod.natCast_eq_zero_iff]
intro hd
have := Nat.le_of_dvd (by omega) hd
nlinarith
have hprod : (m : ZMod (m * b)) * (b : ZMod (m * b)) = 0 := by
rw [← Nat.cast_mul, ZMod.natCast_self]
obtain ⟨c, hc⟩ := h.mul_inv_cancel hm0
apply hb0
calc (b : ZMod (m * b)) = (m * c) * b := by rw [hc, one_mul]
_ = c * (m * b) := by ring
_ = 0 := by rw [hprod, mul_zero]
· intro hp
have : Fact n.Prime := ⟨hp⟩
exact Field.toIsField (ZMod n)Homomorphisms. Theorem 9 in two steps, the second reusing inverse_unique; then the zero map showing that monoid homomorphisms must be required to preserve ; and reduction modulo as a ring homomorphism with kernel .
/-- **Between groups, preserving multiplication forces preserving the identity.** If
`f (a * b) = f a * f b` for all `a, b`, then `f 1 * f 1 = f (1 * 1) = f 1 = f 1 * 1`, and
cancelling `f 1` (possible in a group) leaves `f 1 = 1`. -/
theorem hom_map_one {G H : Type*} [Group G] [Group H] (f : G → H)
(hf : ∀ a b, f (a * b) = f a * f b) : f 1 = 1 := by
have h : f 1 * f 1 = f 1 * 1 :=
calc f 1 * f 1 = f (1 * 1) := (hf 1 1).symm
_ = f 1 := by rw [one_mul]
_ = f 1 * 1 := (mul_one (f 1)).symm
exact mul_left_cancel h/-- **Group homomorphisms preserve inverses.** `f a⁻¹ * f a = f (a⁻¹ * a) = f 1 = 1`, and
likewise `f a * f a⁻¹ = 1`; by the uniqueness of inverses (`inverse_unique`), `f a⁻¹` must be
*the* inverse `(f a)⁻¹`. Mathlib's version is `map_inv`. -/
theorem hom_map_inv {G H : Type*} [Group G] [Group H] (f : G → H)
(hf : ∀ a b, f (a * b) = f a * f b) (a : G) : f a⁻¹ = (f a)⁻¹ := by
have h1 : f a⁻¹ * f a = 1 := by rw [← hf, inv_mul_cancel, hom_map_one f hf]
have h2 : f a * (f a)⁻¹ = 1 := mul_inv_cancel (f a)
exact inverse_unique h1 h2/-- **For monoids, preserving `1` must be required separately.** The zero map on `(ℤ, ×)`
preserves products (`0 = 0 * 0`) but sends `1` to `0 ≠ 1`. Cancellation, which made
`hom_map_one` work for groups, is not available in the monoid `(ℤ, ×)` (one cannot cancel `0`). -/
theorem mul_hom_not_one : ∃ f : ℤ → ℤ, (∀ a b, f (a * b) = f a * f b) ∧ f 1 ≠ 1 :=
⟨fun _ => 0, fun _ _ => by simp, by simp⟩/-- **Reduction modulo `n` is a ring homomorphism** `ℤ →+* ℤ/nℤ`: it preserves `+`, `×`, `0`
and `1`. This is Mathlib's `Int.castRingHom`, given a lesson name. -/
def reduceMod (n : ℕ) : ℤ →+* ZMod n := Int.castRingHom (ZMod n)/-- The **kernel** of reduction mod `n` is the set of multiples of `n`: `a ↦ 0` exactly when
`n ∣ a`. This applies Mathlib's `ZMod.intCast_zmod_eq_zero_iff_dvd`. -/
theorem reduceMod_eq_zero_iff (n : ℕ) (a : ℤ) : reduceMod n a = 0 ↔ (n : ℤ) ∣ a :=
ZMod.intCast_zmod_eq_zero_iff_dvd a nNot formalised here: Corollary 3 and Theorem 4 (Mathlib has them as mul_inv_rev, mul_left_cancel and the group Mˣ of units of a monoid), the ring identities of Theorem 5 (zero_mul, neg_mul, neg_mul_neg, proved by hand in the integers lesson), and the isomorphism .
A census of all operations on three elements
A operation table has nine entries, each one of three elements, so there are binary operations on a three-element set. Which of them are associative? Which are monoids, which groups? Does any of them break Theorems 1 or 2? A computer can simply look at all of them.
"""A census of every binary operation on a three-element set, and of Z/nZ.
There are 3^9 = 19 683 binary operations on S = {0, 1, 2}: one for each way of
filling in a 3 x 3 operation table. The experiment checks every one of them for
associativity, identities and inverses, counts the monoids and groups, and
confirms on all of them the lesson's theorems that an identity is unique and
that inverses in a monoid are unique. Then it decides, for n = 2, ..., 40,
whether Z/nZ is a field by searching for inverses. Everything is exact and
exhaustive for these finite cases - evidence about small cases, not a proof
of the general theorems.
"""
import itertools
import math
S = (0, 1, 2)
def all_tables(size=3):
"""Yield every operation table on {0, ..., size-1} as a dict (a, b) -> a*b."""
elems = range(size)
pairs = [(a, b) for a in elems for b in elems]
for values in itertools.product(elems, repeat=len(pairs)):
yield dict(zip(pairs, values))
def is_associative(op, elems=S):
"""True if (ab)c = a(bc) for all a, b, c."""
return all(op[op[a, b], c] == op[a, op[b, c]]
for a in elems for b in elems for c in elems)
def identities(op, elems=S):
"""All two-sided identity elements e (ea = a = ae for every a)."""
return [e for e in elems
if all(op[e, a] == a and op[a, e] == a for a in elems)]
def inverses(op, a, e, elems=S):
"""All two-sided inverses of a with respect to the identity e."""
return [b for b in elems if op[a, b] == e and op[b, a] == e]
def is_commutative(op, elems=S):
"""True if ab = ba for all a, b."""
return all(op[a, b] == op[b, a] for a in elems for b in elems)
def census(size=3):
"""Count operations by kind, and record any failure of uniqueness."""
elems = tuple(range(size))
counts = {"tables": 0, "associative": 0, "with identity": 0,
"monoids": 0, "commutative monoids": 0, "groups": 0}
max_ids, max_invs = 0, 0
for op in all_tables(size):
counts["tables"] += 1
ids = identities(op, elems)
max_ids = max(max_ids, len(ids))
counts["with identity"] += bool(ids)
if not is_associative(op, elems):
continue
counts["associative"] += 1
if not ids:
continue
counts["monoids"] += 1
counts["commutative monoids"] += is_commutative(op, elems)
invs = [inverses(op, a, ids[0], elems) for a in elems]
max_invs = max(max_invs, max(len(i) for i in invs))
counts["groups"] += all(invs)
return counts, max_ids, max_invs
def units_mod(n):
"""The classes a in Z/nZ with some b such that ab = 1 (mod n)."""
return [a for a in range(n) if any(a * b % n == 1 % n for b in range(n))]
def is_field_mod(n):
"""Z/nZ is a field: 0 != 1 and every non-zero class has an inverse."""
return n > 1 and len(units_mod(n)) == n - 1
def is_prime(n):
"""Trial division."""
return n > 1 and all(n % d for d in range(2, math.isqrt(n) + 1))
def main():
counts, max_ids, max_invs = census()
print("All binary operations on S = {0, 1, 2}:")
for kind, number in counts.items():
print(f" {kind:<22}{number:>6}")
print(f" most identities in one table: {max_ids}")
print(f" most inverses of one element (monoid): {max_invs}")
print(" (Groups: S has 3 choices of identity, each giving a copy of Z/3.)")
print()
fields = [n for n in range(2, 41) if is_field_mod(n)]
primes = [n for n in range(2, 41) if is_prime(n)]
print("Z/nZ is a field for n in 2..40 exactly when n is in:")
print(" " + ", ".join(map(str, fields)))
print(f" same as the primes up to 40: {fields == primes}")
for n in (12, 13):
print(f" units of Z/{n}Z: {units_mod(n)}")
print()
print("Epistemic status: exact, exhaustive checks of finitely many cases.")
print("They agree with the theorems (an identity is unique, inverses in a")
print("monoid are unique, Z/nZ is a field iff n is prime) but prove them only")
print("for |S| = 3 and n <= 40; the proofs in the lesson cover every case.")
if __name__ == "__main__":
main()Only of the operations are associative (a known count), and only are groups. The groups are all "the same": once we choose which of the three elements is the identity, the table is forced to be that of — every group with three elements is isomorphic to . The search finds no operation with two identities and no monoid element with two inverses, as the theorems predict; but a search of one size proves nothing about other sizes, whereas the proofs above hold for every set at once.
Explore: units and non-commutativity
On the "multiply" tab, choose a number of hours and look for the classes that have a multiplicative partner — the units of . Which give a partner to every non-zero class? Compare with , and check your answer against Theorem 8.
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.
The ring of matrices is not commutative. First a shear, then a quarter turn — or the other way round: the two composites differ.
Matrix multiplication is not commutative
Apply A and then B, or B and then A, and compare the results.
- image of the grid
- image of the unit square
- image of the flag
- before the transformation
- after the first step
AB ≠ BA: the order matters.
BA means “apply A first, then B”: products of transformations are read from right to left.
det(AB) = det(BA) = det A · det B = 1 · 1 = 1 The area scale factor is the same in either order.
Exercises
1. Algebraic structures: monoids, groups and rings
Warm-upHumanWhich of these are groups? (Choose all that apply.)
2. Algebraic structures: monoids, groups and rings
Warm-upHumanThe operation on is associative and commutative. Which natural number is its identity element, i.e. satisfies for every ?
3. Algebraic structures: monoids, groups and rings
CoreHumanFind the inverse of in : the number with . (This is the key step in decoding an affine cipher.)
4. Algebraic structures: monoids, groups and rings
CoreHumanThe proof that inverses in a monoid are unique reads: if and then . Which equality uses associativity?
5. Algebraic structures: monoids, groups and rings
CoreHumanBetween groups, any with automatically satisfies . Which example shows that this fails for monoids, so that must be required separately?
6. Algebraic structures: monoids, groups and rings
CoreHumanis not a field. Find the smallest with , which exhibits as a zero divisor.
7. Algebraic structures: monoids, groups and rings
CoreFormalWhich Lean statement correctly formalises "in a monoid, a left inverse and a right inverse of the same element are equal"?
8. Algebraic structures: monoids, groups and rings
StretchComputationalWrite is_group(elements, op) that returns True exactly when op (a Python function of two arguments) is a group operation on the finite list elements: check closure, associativity, an identity, and inverses. Then test it on addition modulo 5, multiplication modulo 6, and multiplication modulo 12 on the units .
Common misconceptions
Misconception
"The identity element is always or ." It is whatever does nothing. For composition of functions it is the identity function; for concatenation of words it is the empty word; for on it is ; for on it is ; for intersection of subsets of it is itself.
Misconception
"Every operation is commutative, like addition." Composition of functions, multiplication of matrices, concatenation of words and composition of shuffles are not. Commutativity is an extra property that has to be checked, and many of the most important groups — symmetry groups, for , — lack it.
Misconception
Forgetting closure. "Addition on the odd integers" is not an operation at all, because is not odd. Likewise is not closed under addition (). Before asking whether an operation is associative, check that it lands back in the set.
Misconception
"A one-sided inverse is an inverse." In the monoid of functions , the successor has left inverses: any with satisfies , and can be anything, so there are infinitely many of them. But has no right inverse, since nothing is sent to . Theorem 2 says that if both a left and a right inverse exist, they coincide; one-sided inverses alone need be neither two-sided nor unique.
Misconception
"Checking associativity on a few examples is enough." Associativity is a statement about all triples. Exponentiation on positive integers satisfies , yet . One failure is enough to refute it; no finite number of successes proves it for an infinite set.
Misconception
"A homomorphism only has to preserve the operation." Between groups that is enough (Theorem 9). Between monoids and rings it is not: the zero map on preserves products but not , which is why preserving the identity is part of the definition.
Many ways of seeing
Geometry— Groups are symmetries
The rotations and reflections that map a square onto itself form a group under composition, the dihedral group with elements: four rotations (by , , , ) and four reflections. It is not abelian — a quarter turn followed by a reflection in the vertical axis is the reflection in one diagonal, while the opposite order gives the other diagonal. More generally the symmetries of any object — a tiling, a crystal, a molecule, a regular polyhedron — form a group, and Cayley's theorem says that conversely every group is a group of symmetries: is an injective homomorphism . Felix Klein's Erlangen programme (1872) turned this around and defined a geometry by its group of transformations: Euclidean geometry studies what is invariant under rigid motions, affine geometry what is invariant under and translations (see transformation geometry).
Topology— Loops form a group, but only up to deformation
In a space with a base point , two loops at can be combined by running through one and then the other. This concatenation is not associative on the nose — and spend different amounts of time on each loop — but the two can be continuously deformed into each other. Passing to loops up to deformation (homotopy) gives a genuine group, the fundamental group , whose identity is the constant loop and whose inverses run loops backwards. For the circle, , the integer being the winding number (see the fundamental group). Groups can also carry a topology: the circle under multiplication is a topological group, its operations being continuous maps, and splits into two connected pieces according to the sign of the determinant.
Number theory— Units modulo n and the finite fields
The units of form a group of order , Euler's totient — the number of in coprime to . Group theory then does number theory: Lagrange's theorem (the order of an element divides the order of a finite group) gives Euler's theorem whenever , and for prime, Fermat's little theorem (see congruences). Theorem 8 says that is a field; every finite field has prime-power order , and there is exactly one field of each such order up to isomorphism (see fields and Galois theory). Finite fields underlie error-correcting codes and much of modern cryptography.
Physics— Symmetries of physical law
In physics, the transformations that leave the laws of nature unchanged form groups: translations in space and time, the rotation group , and in special relativity the Lorentz group. Noether's theorem (Emmy Noether, 1918) states that, for a system whose equations come from a principle of least action, every continuous one-parameter group of symmetries yields a conserved quantity: invariance under time translation gives conservation of energy, under space translation conservation of momentum, and under rotation conservation of angular momentum (see classical mechanics). In quantum mechanics the electron's spin is described by the group of unitary matrices of determinant , and the classification of elementary particles is organised by groups such as . The mathematics of groups is exact; the identification of nature's symmetries is an empirical, and very successful, physical hypothesis.
Computation— Monoids make parallel computation possible
To add a billion numbers on a thousand processors, each processor adds its own million and then the partial sums are added. That this gives the right answer is precisely associativity; the identity is what an idle processor contributes. Programmers use the word "monoid" for exactly this pattern: summing, multiplying, taking maxima, concatenating strings and merging sorted lists are all monoid operations, and a "reduce" or "fold" can be split across machines because of the associative law. Floating-point addition on a computer is commutative but not associative — in standard double precision, while — which is why a parallel sum of floating-point numbers can depend on how the work was divided.
Category theory— A monoid is a category with one object
Given a monoid , build a category with a single object , one arrow for each element of , composition given by the monoid operation and identity arrow given by . The category axioms — associativity and identity laws — are exactly the monoid axioms. Conversely, the arrows from an object to itself in any category form a monoid. A monoid homomorphism is then exactly a functor between such one-object categories, and a group is a one-object category in which every arrow is invertible (a one-object groupoid). See categories and functors; the same idea, one level up, says that a monad is "a monoid in a category of endofunctors" (monads).
Wonder Trails
History and global context
- The rules of arithmetic. Brahmagupta's Brāhmasphuṭasiddhānta (628 CE, India) states rules for adding, subtracting and multiplying positive and negative numbers and zero — the ring laws of in words. Al-Khwārizmī's treatise on al-jabr wa-l-muqābala (Baghdad, around 820 CE) gave algebra its name, though its subject was solving equations rather than structures.
- Remainders and forms. Carl Friedrich Gauss's Disquisitiones Arithmeticae (1801) systematised arithmetic modulo and introduced a composition of binary quadratic forms — in hindsight, finite abelian groups.
- Permutations and groups. Joseph-Louis Lagrange (1770–71) studied how permuting the roots of a polynomial affects certain expressions in them. Évariste Galois, writing around 1830–32, used the word groupe for a set of permutations closed under composition and connected it to the solvability of equations; his work was published by Joseph Liouville in 1846. Arthur Cayley (1854) gave the first definition of an abstract finite group.
- Rings and fields. Richard Dedekind introduced the term Körper (field) in 1871, and David Hilbert's report on algebraic number theory (1897) the term Zahlring. Abraham Fraenkel gave an axiomatic definition of a ring in 1914. Emmy Noether's paper on ideals in rings (1921) and her school in Göttingen made the abstract, axiomatic approach central, and B. L. van der Waerden's Moderne Algebra (1930–31), based on lectures by Noether and Emil Artin, made it the standard way to teach algebra.
Further reading
- Michael Artin, Algebra (1991; 2nd ed. 2011) — groups through symmetry and linear algebra, with many geometric examples.
- Joseph A. Gallian, Contemporary Abstract Algebra (many editions) — a gentle first course with a wealth of examples.
- Charles C. Pinter, A Book of Abstract Algebra (1982; Dover reprint 2010) — short chapters with exercises that build the theory step by step.
- I. N. Herstein, Topics in Algebra (1964; 2nd ed. 1975) — a classic, concise and demanding.
- David S. Dummit and Richard M. Foote, Abstract Algebra (1991; 3rd ed. 2004) — a comprehensive reference for groups, rings, modules and fields.