Skip to content
The Lumenary
First-year graduateGraduate 140 min

Modules

Linear algebra over a ring — where bases can fail to exist, and one theorem classifies both finite abelian groups and Jordan normal forms.

Formally verified · 11 LeanComputationally tested · 2 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

One theorem, two classical classifications

Two classification problems look unrelated.

  • Finite abelian groups. Every finite abelian group is a product of cyclic groups, for instance Z/2×Z/6\Z/2 \times \Z/6 or Z/12\Z/12 — but which products are isomorphic? (Answer: Z/12≅Z/4×Z/3\Z/12 \cong \Z/4 \times \Z/3, while Z/2×Z/6\Z/2 \times \Z/6 is not cyclic.)
  • Matrices up to similarity. A complex square matrix is similar to a Jordan normal form, unique up to the order of the blocks. Why blocks, and why unique?

Both are the same theorem. An abelian group is a module over the ring Z\Z; a vector space VV with a linear operator TT is a module over the polynomial ring k[x]k[x], where xx acts as TT. Both Z\Z and k[x]k[x] are principal ideal domains, and the structure theorem for finitely generated modules over a PID says that every such module is a direct sum of cyclic modules R/(d)R/(d), in an essentially unique way. For R=ZR = \Z this is the classification of finitely generated abelian groups; for R=C[x]R = \C[x], the cyclic pieces C[x]/((x−λ)e)\C[x]/((x - \lambda)^e) are exactly the Jordan blocks.

Modules are the language in which much of modern algebra is written: ideals of a ring, representations of groups and quivers, homology groups of spaces, sections of vector bundles. This lesson builds the basic theory — exact sequences, free and projective modules, tensor products — and proves the structure theorem in full. It assumes quotient rings and the isomorphism theorems, PIDs and UFDs and advanced linear algebra.

IntuitionH

Vector spaces whose scalars cannot always be divided

A module is a vector space in which the scalars come from a ring instead of a field. Everything that uses only addition and multiplication by scalars survives: submodules, quotients, homomorphisms, kernels, images, direct sums, the isomorphism theorems. Everything that uses division by scalars can fail:

  • Bases. In Z/2\Z/2 regarded as a Z\Z-module, 2⋅1ˉ=02 \cdot \bar 1 = 0 is a non-trivial relation, so no non-empty subset is linearly independent: Z/2\Z/2 has no basis. Elements killed by non-zero scalars are called torsion, and torsion is the first obstruction to freeness.
  • Extending independent sets. In Z\Z, the set {2}\{2\} is linearly independent and cannot be enlarged, yet it is not a basis. The set {2,3}\{2, 3\} generates Z\Z minimally, yet contains no basis.
  • Complements. The submodule 2Z⊆Z2\Z \subseteq \Z has no complement: Z\Z is not 2Z⊕C2\Z \oplus C for any CC, because any two non-zero submodules of Z\Z intersect.

So short exact sequences 0→A→B→C→00 \to A \to B \to C \to 0 need not split, and the central questions of module theory are about the ways in which they fail to. Free modules (those with a basis) behave like vector spaces; projective modules are the ones that behave well when mapped out of; the tensor product turns bilinear maps into linear ones but can destroy injectivity. Over a PID the damage is controlled: torsion is the only obstruction, and it is completely described by the structure theorem.

DefinitionsH

Definitions

Throughout, rings have a 11, and modules are left modules on which 11 acts as the identity. From the section on PIDs onwards, RR is commutative.

Definition— module, homomorphism, submodule, quotient

A (left) module over a ring RR is an abelian group (M,+)(M, +) with a map R×M→MR \times M \to M, (r,m)↦rm(r, m) \mapsto rm, such that for all r,s∈Rr, s \in R and m,n∈Mm, n \in M:

r(m+n)=rm+rn,(r+s)m=rm+sm,(rs)m=r(sm),1m=m.r(m + n) = rm + rn, \qquad (r + s)m = rm + sm, \qquad (rs)m = r(sm), \qquad 1m = m.

Equivalently, a ring homomorphism R→End⁡(M)R \to \operatorname{End}(M) into the endomorphism ring of the abelian group MM. A homomorphism (RR-linear map) f:M→Nf : M \to N is additive with f(rm)=rf(m)f(rm) = r f(m); they form an abelian group HomR(M,N)\Hom_R(M, N). A submodule is a subgroup closed under the action; for a submodule N⊆MN \subseteq M the quotient M/NM/N is a module with r(m+N)=rm+Nr(m + N) = rm + N.

Definition— kernel, image, cokernel; exact sequence

For f:M→Nf : M \to N: ker⁡f={m:f(m)=0}\ker f = \{m : f(m) = 0\}, im⁡f=f(M)\operatorname{im} f = f(M) and coker⁡f=N/im⁡f\operatorname{coker} f = N / \operatorname{im} f. A sequence A→fB→gCA \xrightarrow{f} B \xrightarrow{g} C is exact at BB if im⁡f=ker⁡g\operatorname{im} f = \ker g. A short exact sequence is 0→A→fB→gC→00 \to A \xrightarrow{f} B \xrightarrow{g} C \to 0 exact at AA, BB and CC: ff injective, gg surjective, im⁡f=ker⁡g\operatorname{im} f = \ker g, so C≅B/f(A)C \cong B / f(A). It splits if gg has a section s:C→Bs : C \to B (gs=idCgs = \mathrm{id}_C), equivalently ff has a retraction; then B≅A⊕CB \cong A \oplus C.

Definition— free module, rank, torsion

A family (ei)i∈I(e_i)_{i \in I} in MM is a basis if every m∈Mm \in M is uniquely a finite combination ∑riei\sum r_i e_i. A module with a basis is free; it is isomorphic to R(I)=⨁i∈IRR^{(I)} = \bigoplus_{i \in I} R. Universal property: for any module NN and any elements (ni)i∈I(n_i)_{i \in I} of NN there is a unique homomorphism R(I)→NR^{(I)} \to N with ei↦nie_i \mapsto n_i. For commutative R≠0R \neq 0, Rm≅RnR^m \cong R^n implies m=nm = n (tensor with R/mR/\mathfrak{m} for a maximal ideal m\mathfrak{m}), and nn is the rank. If RR is a domain, m∈Mm \in M is torsion if rm=0rm = 0 for some r≠0r \neq 0; the torsion elements form the torsion submodule T(M)T(M), and MM is torsion-free if T(M)=0T(M) = 0.

Definition— projective and injective modules

A module PP is projective if HomR(P,−)\Hom_R(P, -) carries surjections to surjections: for every surjection g:M→Ng : M \to N and every f:P→Nf : P \to N there is h:P→Mh : P \to M with g∘h=fg \circ h = f. Dually, II is injective if HomR(−,I)\Hom_R(-, I) carries injections to surjections: every homomorphism A→IA \to I extends along any injection A↪BA \hookrightarrow B.

PP
MM
NN
00
hh
ff
gg
PP is projective: every ff lifts through every surjection gg, so that g∘h=fg \circ h = f (the lift is usually not unique).

Definition— tensor product

Let RR be commutative and M,NM, N modules. A tensor product is a module M⊗RNM \otimes_R N with an RR-bilinear map ⊗:M×N→M⊗RN\otimes : M \times N \to M \otimes_R N, (m,n)↦m⊗n(m, n) \mapsto m \otimes n, such that every bilinear map β:M×N→P\beta : M \times N \to P factors as β(m,n)=β~(m⊗n)\beta(m, n) = \tilde\beta(m \otimes n) for a unique homomorphism β~:M⊗RN→P\tilde\beta : M \otimes_R N \to P. It exists (take the free module on M×NM \times N modulo the bilinearity relations) and is unique up to unique isomorphism. Its elements are finite sums ∑mi⊗ni\sum m_i \otimes n_i, but not every element is a single pure tensor m⊗nm \otimes n. For f:M→M′f : M \to M' we write f⊗N:M⊗N→M′⊗Nf \otimes N : M \otimes N \to M' \otimes N, m⊗n↦f(m)⊗nm \otimes n \mapsto f(m) \otimes n.

Definition— principal ideal domain

A commutative domain RR is a PID if every ideal is (a)=Ra(a) = Ra for some aa. Examples: Z\Z, k[x]k[x] for a field kk, the Gaussian integers Z[i]\Z[i]. A PID is a UFD; any two elements have a gcd gg, and (a,b)=(g)(a, b) = (g), so g=xa+ybg = xa + yb for some x,y∈Rx, y \in R (Bézout).

Worked examplesH

Examples and non-examples

Example— Abelian groups, vector spaces, ideals

A Z\Z-module is exactly an abelian group (nm=m+⋯+mnm = m + \cdots + m is forced), and Z\Z-linear maps are group homomorphisms. A module over a field kk is a vector space. Every ring is a module over itself; its submodules are its left ideals, and R/IR/I is a module. If R→SR \to S is a ring homomorphism, every SS-module is an RR-module by restriction of scalars: so Z/n\Z/n-modules are abelian groups killed by nn.

Example— Modules over k[x] are vector spaces with an operator

A k[x]k[x]-module is a kk-vector space VV together with the linear map T:v↦xvT : v \mapsto xv; conversely (V,T)(V, T) becomes a k[x]k[x]-module by p(x)⋅v=p(T)vp(x) \cdot v = p(T)v. Under this dictionary:

  • submodules are TT-invariant subspaces;
  • homomorphisms (V,T)→(W,S)(V, T) \to (W, S) are linear maps φ\varphi with φT=Sφ\varphi T = S \varphi, and (kn,A)≅(kn,B)(k^n, A) \cong (k^n, B) exactly when AA and BB are similar;
  • the cyclic module k[x]/(f)k[x]/(f), for monic f=xn+an−1xn−1+⋯+a0f = x^n + a_{n-1}x^{n-1} + \cdots + a_0, has basis 1,x,…,xn−11, x, \dots, x^{n-1}, in which xx acts by the companion matrix of ff.

So classifying finitely generated k[x]k[x]-modules that are finite-dimensional over kk means classifying square matrices up to similarity.

Example— Modules without bases

  • Z/n\Z/n (n≥2n \geq 2) is not a free Z\Z-module: every element is torsion. (Formalised below.)
  • Q\Q is a torsion-free Z\Z-module that is not free. Any two elements are linearly dependent, since (rq)pq−(ps)rs=0(rq)\tfrac{p}{q} - (ps)\tfrac{r}{s} = 0, so a basis would have one element xx; but x/2∉Zxx/2 \notin \Z x.
  • The ideal (x,y)(x, y) of k[x,y]k[x, y] is not free: two elements f,gf, g always satisfy g⋅f−f⋅g=0g \cdot f - f \cdot g = 0, so a basis would be a single generator, and (x,y)(x, y) is not principal.

Example— Projective but not free

Let R=Z/6R = \Z/6. By the Chinese remainder theorem, R≅Z/2×Z/3R \cong \Z/2 \times \Z/3 as rings, so R=P⊕QR = P \oplus Q as RR-modules with P=3R≅Z/2P = 3R \cong \Z/2 and Q=2R≅Z/3Q = 2R \cong \Z/3. Each summand of a free module is projective (Proposition 1 below), but PP is not free: it has 22 elements, while a non-zero free RR-module has at least 66. Over a PID this cannot happen for finitely generated modules (Theorem 2), and the number theorist's viewpoint below describes a deeper example, a non-principal ideal of Z[−5]\Z[\sqrt{-5}].

Example— Injective modules

Over a PID, a module is injective exactly when it is divisible (rM=MrM = M for all r≠0r \neq 0) — a consequence of Baer's criterion (Baer, 1940): II is injective if every homomorphism from an ideal J⊆RJ \subseteq R to II extends to RR. So Q\Q and Q/Z\Q/\Z are injective Z\Z-modules, while Z\Z is not (2Z→Z2\Z \to \Z, 2↦12 \mapsto 1, does not extend to Z\Z). Every module embeds in an injective one; for abelian groups, ⨁Q/Z\bigoplus \Q/\Z suffices. Injective modules supply the resolutions used to compute Ext\mathrm{Ext} in homological algebra.

Example— Tensor products

  • Rm⊗RRn≅RmnR^m \otimes_R R^n \cong R^{mn}, with basis ei⊗eje_i \otimes e_j; so for vector spaces the tensor product is the familiar one.
  • R/I⊗RM≅M/IMR/I \otimes_R M \cong M/IM, by right exactness (Theorem 7) applied to I⊗M→R⊗M→R/I⊗M→0I \otimes M \to R \otimes M \to R/I \otimes M \to 0.
  • Z/m⊗ZZ/n≅Z/gcd⁡(m,n)\Z/m \otimes_\Z \Z/n \cong \Z/\gcd(m, n): by the previous item it is (Z/n)/m(Z/n)=Z/(m,n)(\Z/n)/m(\Z/n) = \Z/(m, n). So Z/2⊗Z/3=0\Z/2 \otimes \Z/3 = 0 and Z/12⊗Z/18≅Z/6\Z/12 \otimes \Z/18 \cong \Z/6.
  • Q⊗ZZ/n=0\Q \otimes_\Z \Z/n = 0: q⊗a=qn⊗na=qn⊗0=0q \otimes a = \tfrac{q}{n} \otimes na = \tfrac{q}{n} \otimes 0 = 0. Tensoring can kill a module entirely.
ProofH

The structure theory

Theorem— Proposition 1 (projective modules)

For a module PP the following are equivalent:

  1. PP is projective;
  2. every short exact sequence 0→A→B→gP→00 \to A \to B \xrightarrow{g} P \to 0 splits;
  3. PP is a direct summand of a free module.

In particular, free modules are projective.

Proof

Free modules are projective. Let FF have basis (ei)(e_i), g:M→Ng : M \to N surjective and f:F→Nf : F \to N. Choose mi∈Mm_i \in M with g(mi)=f(ei)g(m_i) = f(e_i) and let h:F→Mh : F \to M be the homomorphism with h(ei)=mih(e_i) = m_i (universal property). Then ghgh and ff agree on the basis, so gh=fgh = f.

(1 ⇒ 2) Lift idP\mathrm{id}_P along the surjection gg: there is s:P→Bs : P \to B with gs=idPgs = \mathrm{id}_P.

(2 ⇒ 3) Let FF be the free module on the set PP and F→PF \to P the surjection sending the basis vector epe_p to pp. The sequence 0→K→F→P→00 \to K \to F \to P \to 0 splits, so F≅K⊕PF \cong K \oplus P.

(3 ⇒ 1) Let F=P⊕QF = P \oplus Q be free, with inclusion ι\iota and projection π\pi onto PP. Given g:M↠Ng : M \twoheadrightarrow N and f:P→Nf : P \to N, lift fπ:F→Nf \pi : F \to N to h′:F→Mh' : F \to M (free modules are projective) and put h=h′ιh = h' \iota; then gh=fπι=fg h = f \pi \iota = f.

∎

The functor HomR(P,−)\Hom_R(P, -) is always left exact: it sends 0→A→B→C0 \to A \to B \to C exact to 0→Hom(P,A)→Hom(P,B)→Hom(P,C)0 \to \Hom(P, A) \to \Hom(P, B) \to \Hom(P, C) exact. Projectivity says exactly that it also preserves surjectivity, so PP is projective iff HomR(P,−)\Hom_R(P, -) is exact.

Theorem— Theorem 2 (submodules of free modules over a PID)

Let RR be a PID and NN a submodule of RnR^n. Then NN is free of rank at most nn.

Proof

Induction on nn. For n=0n = 0 there is nothing to prove. For n=1n = 1, NN is an ideal (a)(a): if a=0a = 0 it is free of rank 00, and otherwise r↦rar \mapsto ra is an isomorphism R→(a)R \to (a) because RR is a domain. For n≥2n \geq 2, let π:Rn→R\pi : R^n \to R be the last coordinate, with kernel Rn−1R^{n-1}. Then

0→N∩Rn−1→N→ π π(N)→00 \to N \cap R^{n-1} \to N \xrightarrow{\ \pi\ } \pi(N) \to 0

is exact. By induction N∩Rn−1N \cap R^{n-1} is free of rank at most n−1n - 1, and π(N)⊆R\pi(N) \subseteq R is free of rank at most 11 by the case n=1n = 1. A free module is projective, so the sequence splits (Proposition 1) and N≅(N∩Rn−1)⊕π(N)N \cong (N \cap R^{n-1}) \oplus \pi(N) is free of rank at most nn.

∎

(The same holds for submodules of free modules of any rank, by a transfinite version of this induction; see Lang, Algebra, III §7. It fails over non-PIDs: 2Z/4⊆Z/42\Z/4 \subseteq \Z/4, (x,y)⊆k[x,y](x, y) \subseteq k[x, y].)

Theorem— Theorem 3 (Smith normal form)

Let RR be a PID and AA an m×nm \times n matrix over RR. There are invertible matrices P∈GLm(R)P \in GL_m(R) and Q∈GLn(R)Q \in GL_n(R) such that

PAQ=(D000),D=diag⁡(d1,…,dr),d1∣d2∣⋯∣dr,di≠0.PAQ = \begin{pmatrix} D & 0 \\ 0 & 0 \end{pmatrix}, \qquad D = \operatorname{diag}(d_1, \dots, d_r), \qquad d_1 \mid d_2 \mid \cdots \mid d_r, \quad d_i \neq 0.

Proof

Since RR is a UFD, every non-zero a∈Ra \in R has a length ℓ(a)\ell(a), the number of prime factors counted with multiplicity; units have length 00, and if g∣ag \mid a but gg is not an associate of aa then ℓ(g)<ℓ(a)\ell(g) < \ell(a). Call two matrices equivalent if one is PAQPAQ for invertible P,QP, Q. We induct on m+nm + n; the case A=0A = 0 is trivial.

Among all matrices equivalent to AA with non-zero (1,1)(1,1) entry (there are some: permute a non-zero entry to the corner), choose BB whose (1,1)(1,1) entry bb has minimal length.

Step 1: bb divides every entry of the first column and the first row. Suppose b∤c=Bi1b \nmid c = B_{i1}. Let g=gcd⁡(b,c)=xb+ycg = \gcd(b, c) = xb + yc, and write b=gub = gu, c=gvc = gv, so that xu+yv=1xu + yv = 1. The matrix (xy−vu)\left(\begin{smallmatrix} x & y \\ -v & u \end{smallmatrix}\right) has determinant 11; applying it to rows 11 and ii is an invertible row operation that puts xb+yc=gxb + yc = g in the corner. Since b∤cb \nmid c, gg is a proper divisor of bb, so ℓ(g)<ℓ(b)\ell(g) < \ell(b), contradicting minimality. Columns are handled by the same argument applied to BTB^{\mathsf T}.

Step 2: clear. Subtracting multiples of row 11 and column 11 gives an equivalent matrix (b00B′)\left(\begin{smallmatrix} b & 0 \\ 0 & B' \end{smallmatrix}\right).

Step 3: bb divides every entry of B′B'. If b∤Bij′b \nmid B'_{ij}, add row ii to row 11: the first row now contains an entry not divisible by bb, and Step 1 gives a contradiction.

By induction B′B' is equivalent to diag⁡(d2,…,dr,0,… )\operatorname{diag}(d_2, \dots, d_r, 0, \dots) with d2∣d3∣⋯d_2 \mid d_3 \mid \cdots. Equivalent matrices generate the same ideal of entries (each entry of PB′QPB'Q is a combination of entries of B′B', and conversely), so bb divides d2d_2. Put d1=bd_1 = b.

∎

Over a Euclidean domain such as Z\Z or k[x]k[x] the same steps become an algorithm: divide with remainder instead of using Bézout, and the norm of the corner entry decreases. For a 1×21 \times 2 matrix (a b)(a \ b) the algorithm is Euclid's algorithm, and the Smith form is (gcd⁡(a,b)  0)(\gcd(a, b) \ \ 0). The first experiment below implements it.

Theorem— Theorem 4 (structure theorem for finitely generated modules over a PID)

Let RR be a PID and MM a finitely generated RR-module. Then

M  ≅  Rs⊕R/(d1)⊕⋯⊕R/(dk),d1∣d2∣⋯∣dk,M \;\cong\; R^s \oplus R/(d_1) \oplus \cdots \oplus R/(d_k), \qquad d_1 \mid d_2 \mid \cdots \mid d_k,

with the did_i non-zero non-units (the invariant factors). Equivalently, by the Chinese remainder theorem, M≅Rs⊕⨁jR/(pjej)M \cong R^s \oplus \bigoplus_j R/(p_j^{e_j}) with pjp_j prime and ej≥1e_j \geq 1 (the elementary divisors pjejp_j^{e_j}). The rank ss, the ideals (di)(d_i) and the multiset of ideals (pjej)(p_j^{e_j}) are uniquely determined by MM.

Proof

Existence. Choose generators m1,…,mnm_1, \dots, m_n and let φ:Rn→M\varphi : R^n \to M send ei↦mie_i \mapsto m_i. By Theorem 2, K=ker⁡φK = \ker \varphi is free with a basis of r≤nr \leq n elements; writing them as columns gives an n×rn \times r matrix AA with M≅coker⁡(A:Rr→Rn)M \cong \operatorname{coker}(A : R^r \to R^n). If PAQ=D′PAQ = D' is the Smith form, then PP and QQ are changes of basis in RnR^n and RrR^r, so coker⁡A≅coker⁡D′≅R/(d1)⊕⋯⊕R/(dr)⊕Rn−r\operatorname{coker} A \cong \operatorname{coker} D' \cong R/(d_1) \oplus \cdots \oplus R/(d_r) \oplus R^{n - r}. Summands with did_i a unit are 00; drop them. For the elementary divisors, write d=u p1a1⋯ptatd = u\, p_1^{a_1} \cdots p_t^{a_t}; the ideals (piai)(p_i^{a_i}) are pairwise comaximal, so R/(d)≅∏iR/(piai)R/(d) \cong \prod_i R/(p_i^{a_i}).

Uniqueness. The torsion submodule is T(M)≅⨁R/(di)T(M) \cong \bigoplus R/(d_i) and M/T(M)≅RsM / T(M) \cong R^s, so ss is the rank of the free module M/T(M)M/T(M), which is well defined. For a prime pp, the pp-primary part Tp={m:pam=0 for some a}T_p = \{m : p^a m = 0 \text{ for some } a\} is the sum of the elementary divisor summands R/(pe)R/(p^{e}) at pp. For N=⨁j=1tR/(pej)N = \bigoplus_{j=1}^{t} R/(p^{e_j}), the quotient paN/pa+1Np^a N / p^{a+1} N is a vector space over the field R/(p)R/(p) of dimension

dim⁡R/(p)(paN/pa+1N)=#{ j:ej>a },\dim_{R/(p)} \bigl(p^a N / p^{a+1} N\bigr) = \#\{\, j : e_j > a \,\},

because paR/peR / pa+1R/peR≅paR/pa+1R≅R/(p)p^a R / p^{e} R \,\big/\, p^{a+1} R / p^e R \cong p^a R / p^{a+1} R \cong R/(p) when a<ea < e, and it is 00 when a≥ea \geq e. These dimensions depend only on MM, and they determine the multiset of exponents eje_j. The invariant factors are recovered from the elementary divisors: dkd_k is the product of the largest power of each prime, dk−1d_{k-1} of the next largest, and so on.

∎

Theorem— Corollary 5 (finitely generated abelian groups)

Every finitely generated abelian group is isomorphic to Zs⊕Z/d1⊕⋯⊕Z/dk\Z^s \oplus \Z/d_1 \oplus \cdots \oplus \Z/d_k with 1<d1∣d2∣⋯∣dk1 < d_1 \mid d_2 \mid \cdots \mid d_k, for unique s,d1,…,dks, d_1, \dots, d_k. The number of abelian groups of order n=∏papn = \prod p^{a_p}, up to isomorphism, is ∏pp(ap)\prod_p \mathrm{p}(a_p), where p(a)\mathrm{p}(a) is the number of partitions of aa.

Proof

Take R=ZR = \Z. A finite group has s=0s = 0, and its elementary divisors at pp are pe1,…,petp^{e_1}, \dots, p^{e_t} with e1+⋯+et=ape_1 + \cdots + e_t = a_p, that is, a partition of apa_p; by uniqueness, distinct choices of partitions give non-isomorphic groups.

∎

For example, there are p(3) p(2)=3⋅2=6\mathrm{p}(3)\,\mathrm{p}(2) = 3 \cdot 2 = 6 abelian groups of order 72=23⋅3272 = 2^3 \cdot 3^2.

Theorem— Corollary 6 (Jordan normal form)

Let kk be algebraically closed, VV a finite-dimensional kk-vector space and T:V→VT : V \to V linear. Then VV has a basis in which TT is block diagonal with Jordan blocks Je(λ)J_e(\lambda), and the multiset of blocks is unique. More generally, over any field kk, TT has a unique rational canonical form: block diagonal with the companion matrices of its invariant factors d1∣⋯∣dkd_1 \mid \cdots \mid d_k, where dkd_k is the minimal polynomial and d1⋯dkd_1 \cdots d_k the characteristic polynomial.

Proof

VV is a finitely generated k[x]k[x]-module, and it is torsion: VV is finite-dimensional, so 1,T,T2,…,Tn21, T, T^2, \dots, T^{n^2} are linearly dependent in End⁡(V)\operatorname{End}(V) and some non-zero polynomial kills VV. Hence V≅⨁jk[x]/(pjej)V \cong \bigoplus_j k[x]/(p_j^{e_j}) by Theorem 4. Over an algebraically closed field the primes of k[x]k[x] are the x−λx - \lambda. On k[x]/((x−λ)e)k[x]/((x - \lambda)^e) take the basis vi=(x−λ)e−iv_i = (x - \lambda)^{e - i}, i=1,…,ei = 1, \dots, e: then (T−λ)v1=0(T - \lambda)v_1 = 0 and (T−λ)vi=vi−1(T - \lambda) v_i = v_{i-1}, so TT acts by the Jordan block Je(λ)J_e(\lambda) (with 11's above the diagonal). Uniqueness of the blocks is uniqueness of the elementary divisors, because similar matrices give isomorphic modules. The rational canonical form uses the invariant factor decomposition and the companion matrix basis of k[x]/(di)k[x]/(d_i). The minimal polynomial generates the annihilator of VV, which is (dk)(d_k); the characteristic polynomial of a companion matrix of dd is dd, so that of TT is d1⋯dkd_1 \cdots d_k.

∎

The proof explains a classical fact: the characteristic polynomial does not determine a matrix up to similarity, but the list of invariant factors does. The two nilpotent 4×44 \times 4 matrices with Jordan blocks of sizes (2,2)(2, 2) and (3,1)(3, 1) both have characteristic polynomial x4x^4, but invariant factors x2,x2x^2, x^2 and x,x3x, x^3; the second experiment computes this.

Now tensor products. We use one lemma about Hom\Hom.

Theorem— Lemma (exactness can be tested by Hom)

A sequence A→fB→gC→0A \xrightarrow{f} B \xrightarrow{g} C \to 0 is exact if and only if for every module PP the sequence

0→Hom(C,P)→ g∗ Hom(B,P)→ f∗ Hom(A,P)0 \to \Hom(C, P) \xrightarrow{\ g^*\ } \Hom(B, P) \xrightarrow{\ f^*\ } \Hom(A, P)

is exact, where g∗(φ)=φgg^*(\varphi) = \varphi g and f∗(ψ)=ψff^*(\psi) = \psi f.

Proof

(⇒) If gg is surjective then φg=0\varphi g = 0 forces φ=0\varphi = 0. Clearly f∗g∗=(gf)∗=0f^* g^* = (gf)^* = 0. If ψf=0\psi f = 0, then ψ\psi vanishes on im⁡f=ker⁡g\operatorname{im} f = \ker g, so it factors through B/ker⁡g≅CB / \ker g \cong C: ψ=φg\psi = \varphi g.

(⇐) gg is surjective: the projection π:C→C/im⁡g\pi : C \to C/\operatorname{im} g satisfies g∗(π)=πg=0g^*(\pi) = \pi g = 0, so π=0\pi = 0. gf=0gf = 0: take P=CP = C; f∗(g∗(idC))=gf=0f^*(g^*(\mathrm{id}_C)) = gf = 0. ker⁡g⊆im⁡f\ker g \subseteq \operatorname{im} f: take P=B/im⁡fP = B / \operatorname{im} f and the projection π\pi; then f∗(π)=0f^*(\pi) = 0, so π=φg\pi = \varphi g for some φ\varphi, and every b∈ker⁡gb \in \ker g has π(b)=φ(g(b))=0\pi(b) = \varphi(g(b)) = 0, that is, b∈im⁡fb \in \operatorname{im} f.

∎

Theorem— Theorem 7 (tensor–hom adjunction; right exactness)

Let RR be commutative. For all modules M,N,PM, N, P there is an isomorphism, natural in all three variables,

HomR(M⊗RN,P)  ≅  HomR(M,HomR(N,P)),φ↦(m↦(n↦φ(m⊗n))).\Hom_R(M \otimes_R N, P) \;\cong\; \Hom_R\bigl(M, \Hom_R(N, P)\bigr), \qquad \varphi \mapsto \bigl(m \mapsto (n \mapsto \varphi(m \otimes n))\bigr).

Consequently, if M′→M→M′′→0M' \to M \to M'' \to 0 is exact, so is M′⊗N→M⊗N→M′′⊗N→0M' \otimes N \to M \otimes N \to M'' \otimes N \to 0: the functor −⊗RN- \otimes_R N is right exact. It is not exact in general: 0→Z→2Z→Z/2→00 \to \Z \xrightarrow{2} \Z \to \Z/2 \to 0 is exact, but after −⊗ZZ/2- \otimes_\Z \Z/2 the first map becomes the zero map Z/2→Z/2\Z/2 \to \Z/2.

Proof

Both sides are the set of bilinear maps M×N→PM \times N \to P: the left by the universal property of ⊗\otimes, the right because a bilinear map is the same as a linear map from MM to linear maps N→PN \to P. Naturality is a direct check.

For right exactness, fix PP and write H=Hom(N,P)H = \Hom(N, P). Since M′→M→M′′→0M' \to M \to M'' \to 0 is exact, the lemma (⇒) gives exactness of 0→Hom(M′′,H)→Hom(M,H)→Hom(M′,H)0 \to \Hom(M'', H) \to \Hom(M, H) \to \Hom(M', H). By the natural isomorphism, this is the sequence 0→Hom(M′′⊗N,P)→Hom(M⊗N,P)→Hom(M′⊗N,P)0 \to \Hom(M'' \otimes N, P) \to \Hom(M \otimes N, P) \to \Hom(M' \otimes N, P). As this holds for every PP, the lemma (⇐) gives exactness of M′⊗N→M⊗N→M′′⊗N→0M' \otimes N \to M \otimes N \to M'' \otimes N \to 0.

For the counterexample, Z⊗Z/2≅Z/2\Z \otimes \Z/2 \cong \Z/2 via n⊗a↦nan \otimes a \mapsto na, and (2⊗id)(n⊗a)=2n⊗a=n⊗2a=0(2 \otimes \mathrm{id})(n \otimes a) = 2n \otimes a = n \otimes 2a = 0.

∎

A module NN for which −⊗RN- \otimes_R N is exact is called flat. Free modules are flat (tensoring with R(I)R^{(I)} is a direct sum of copies of the identity functor), hence so are projective modules (direct summands); Q\Q is a flat Z\Z-module that is not projective; Z/2\Z/2 is not flat. The derived functors TornR(−,N)\mathrm{Tor}_n^R(-, N) measure the failure of exactness: there, the kernel Z/2\Z/2 of the zero map above reappears as Tor1Z(Z/2,Z/2)\mathrm{Tor}_1^\Z(\Z/2, \Z/2). The adjunction also explains right exactness conceptually: −⊗N- \otimes N is a left adjoint, and left adjoints preserve all colimits, in particular cokernels (see adjunctions).

Explore

Explore: modules over ℝ[x] in the plane

A 2×22 \times 2 real matrix AA makes R2\R^2 into an R[x]\R[x]-module, with xx acting by AA. Its one-dimensional submodules are exactly the invariant lines, which the widget draws dashed (the real eigenvectors). Try the presets and read the module structure off the picture:

  • Scaling diag⁡(2,0.5)\operatorname{diag}(2, 0.5): two invariant lines, and R2≅R[x]/(x−2)⊕R[x]/(x−0.5)\R^2 \cong \R[x]/(x - 2) \oplus \R[x]/(x - 0.5) — a direct sum of two simple modules.
  • Shear (1101)\left(\begin{smallmatrix} 1 & 1 \\ 0 & 1 \end{smallmatrix}\right): a single invariant line. The module is R[x]/((x−1)2)\R[x]/((x - 1)^2): it has a submodule (the line) with no complementary submodule — indecomposable but not simple, exactly like 2Z⊆Z2\Z \subseteq \Z.
  • Rotation by 90∘90^\circ: no invariant line at all, so the module R[x]/(x2+1)\R[x]/(x^2 + 1) is simple although it has dimension 22. Over C\C the polynomial x2+1x^2 + 1 factors and the module splits into two lines: the structure theorem depends on which polynomials are prime.

An ℝ[x]-module structure on the plane

The dashed invariant lines are the one-dimensional submodules.

Your own matrix
λ = 1Ae₁Ae₂
  • image of the grid
  • image of the unit square
  • image of the flag
  • before the transformation
  • invariant line
Entries of the matrix A
A =

The columns of A are the images of e₁ = (1, 0) and e₂ = (0, 1): Ae₁ = (1, 0), Ae₂ = (1, 1)

det A = ad − bc = 1

The unit square (area 1) becomes a parallelogram of area |det A| = 1. Since det A > 0, orientation is preserved.

Invariant lines (real eigenvectors)

λ = 1, v = (1, 0)

Only one invariant line, with eigenvalue 1: there is no second eigenvector direction.

The Smith normal form of a 1×21 \times 2 integer matrix (a  b)(a \ \ b) is (gcd⁡(a,b)  0)(\gcd(a, b) \ \ 0), and the column operations that compute it are the steps of Euclid's algorithm. So Z/(a,b)≅Z/gcd⁡(a,b)\Z / (a, b) \cong \Z/\gcd(a, b): below, each square cut from the rectangle is one column operation.

Smith normal form of a 1 × 2 matrix

Euclid's algorithm as column operations: Z/(36, 15) ≅ Z/3.

36 × 15

Step 1 of 4

A 36 by 15 rectangle. Press “Next step” to cut off the biggest squares that fit.

  1. …
Formal mathematicsF

Modules in Lean and Mathlib

Mathlib's Module R M is exactly the definition above (for a semiring R and an additive commutative monoid M), and exactness of a pair of maps is Function.Exact f g, meaning range f = ker g pointwise. First, the short exact sequence of the counterexample is exact in the middle:

int_two_exactLean 4Proved here from basic factsFormally verified
/-- **The short exact sequence `0 → ℤ --2·--> ℤ → ℤ/2 → 0` is exact in the middle**: the image
of multiplication by `2` is exactly the kernel of reduction mod `2`. (Exactness at the ends says
that `2·` is injective and reduction is surjective; both are immediate.) The proof is the
arithmetic fact that an integer reduces to `0` in `ℤ/2` exactly when it is even. -/
theorem int_two_exact :
    Function.Exact (fun n : ℤ => 2 * n) (fun n : ℤ => (n : ZMod 2)) := by
  intro n
  constructor
  · intro h
    have h2 : (2 : ℤ) ∣ n := (ZMod.intCast_zmod_eq_zero_iff_dvd n 2).mp h
    obtain ⟨m, hm⟩ := h2
    exact ⟨m, hm.symm⟩
  · rintro ⟨m, rfl⟩
    push_cast
    have : (2 : ZMod 2) = 0 := rfl
    rw [this, zero_mul]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor

Next, the first failure of the vector-space analogy, proved from linear independence of a basis:

zmod_two_not_freeLean 4Proved here from basic factsFormally verified
/-- **`ℤ/2` is a `ℤ`-module with no basis.** Human proof: suppose `b` were a basis. Since
`ℤ/2 ≠ 0` the basis is non-empty; pick a basis vector `b i`. Then `2 • b i = 0` in `ℤ/2`, a
non-trivial linear relation (the coefficient `2 ≠ 0` in `ℤ`), contradicting linear independence.
So modules, unlike vector spaces, can fail to be free: torsion is the obstruction. -/
theorem zmod_two_not_free : ¬ Module.Free ℤ (ZMod 2) := by
  intro hfree
  let b := Module.Free.chooseBasis ℤ (ZMod 2)
  have hne : Nonempty (Module.Free.ChooseBasisIndex ℤ (ZMod 2)) := by
    by_contra hempty
    rw [not_nonempty_iff] at hempty
    have h1 : (1 : ZMod 2) = 0 := by
      rw [← b.sum_repr (1 : ZMod 2)]
      simp
    exact one_ne_zero h1
  obtain ⟨i⟩ := hne
  have h2 : (2 : ℤ) • b i = 0 := by
    have : ∀ x : ZMod 2, (2 : ℤ) • x = 0 := by decide
    exact this _
  -- a basis vector is never killed by a non-zero scalar
  have key : (2 : ℤ) = 0 := by
    have hli := b.linearIndependent
    rw [LinearIndependent] at hli
    have := hli (a₁ := Finsupp.single i 2) (a₂ := 0)
    simp only [Finsupp.linearCombination_single, map_zero] at this
    have h := this h2
    simpa using congrArg (fun f => f i) h
  exact two_ne_zero key
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor

The key step of Proposition 1, proved by the same argument as in the text — choose preimages of the images of basis vectors and extend linearly with Finsupp.linearCombination — followed by Mathlib's versions, "free ⇒ projective" and the lifting property:

free_liftingLean 4Proved here from basic factsFormally verified
/-- **Maps out of a free module lift along surjections.** Let `g : M → N` be surjective and
`f : R^(ι) → N` a homomorphism from the free module on `ι`. For each basis vector `eᵢ`, choose
`mᵢ ∈ M` with `g mᵢ = f eᵢ` (surjectivity); the universal property of the free module gives a
unique `h` with `h eᵢ = mᵢ`, and `g ∘ h = f` because both agree on the basis. This is exactly why
free modules are projective. -/
theorem free_lifting {R : Type*} [Ring R] {ι M N : Type*} [AddCommGroup M] [Module R M]
    [AddCommGroup N] [Module R N] (g : M →ₗ[R] N) (hg : Function.Surjective g)
    (f : (ι →₀ R) →ₗ[R] N) : ∃ h : (ι →₀ R) →ₗ[R] M, g ∘ₗ h = f := by
  choose m hm using fun i : ι => hg (f (Finsupp.single i 1))
  refine ⟨Finsupp.linearCombination R m, ?_⟩
  ext i
  simp [hm]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor
projective_of_freeLean 4Applies a library theoremFormally verified
/-- **Free modules are projective.** This is Mathlib's instance `Module.Projective.of_free`,
whose proof is the lifting argument of `free_lifting`. -/
theorem projective_of_free {R P : Type*} [Ring R] [AddCommGroup P] [Module R P]
    [Module.Free R P] : Module.Projective R P :=
  Module.Projective.of_free
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor
projective_liftingLean 4Applies a library theoremFormally verified
/-- **The lifting property of projective modules**: every map from a projective module to the
target of a surjection lifts through it — equivalently, `Hom(P, −)` carries surjections to
surjections. Mathlib: `Module.projective_lifting_property`. -/
theorem projective_lifting {R P M N : Type*} [Ring R] [AddCommGroup P] [Module R P]
    [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] [Module.Projective R P]
    (g : M →ₗ[R] N) (f : P →ₗ[R] N) (hg : Function.Surjective g) :
    ∃ h : P →ₗ[R] M, g ∘ₗ h = f :=
  Module.projective_lifting_property g f hg
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor

Theorem 2 and the structure theorem (in its elementary-divisor form) with the corollary for abelian groups are in Mathlib:

submodule_free_pidLean 4Applies a library theoremFormally verified
/-- **Over a PID, submodules of finite free modules are free** (of rank at most the rank of the
ambient module). Mathlib: `Submodule.basisOfPid`, which produces a basis of the submodule indexed
by `Fin n`; the proof is the induction on the rank given in the lesson. -/
theorem submodule_free_pid {R M : Type*} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
    [AddCommGroup M] [Module R M] {ι : Type*} [Finite ι] (b : Module.Basis ι R M)
    (N : Submodule R M) : ∃ n : ℕ, Nonempty (Module.Basis (Fin n) R N) :=
  ⟨(Submodule.basisOfPid b N).1, ⟨(Submodule.basisOfPid b N).2⟩⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor
structure_theoremLean 4Applies a library theoremFormally verified
/-- **Structure theorem for finitely generated modules over a PID** (elementary divisor form):
`M ≅ Rⁿ ⊕ ⨁ᵢ R/(pᵢ^eᵢ)` with each `pᵢ` irreducible (prime). Mathlib:
`Module.equiv_free_prod_directSum`. Grouping the prime powers gives the invariant factor form
`R/(d₁) ⊕ ⋯ ⊕ R/(dₖ)` with `d₁ ∣ ⋯ ∣ dₖ` used in the lesson. -/
theorem structure_theorem {R : Type u} {M : Type v} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
    [AddCommGroup M] [Module R M] [Module.Finite R M] :
    ∃ (n : ℕ) (ι : Type u) (_ : Fintype ι) (p : ι → R) (_ : ∀ i, Irreducible (p i)) (e : ι → ℕ),
      Nonempty (M ≃ₗ[R] (Fin n →₀ R) × DirectSum ι (fun i => R ⧸ R ∙ p i ^ e i)) :=
  Module.equiv_free_prod_directSum R M
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor
abelian_groupsLean 4Applies a library theoremFormally verified
/-- **Corollary: finitely generated abelian groups.** Taking `R = ℤ`:
`G ≅ ℤⁿ ⊕ ⨁ᵢ ℤ/pᵢ^eᵢ` with the `pᵢ` prime. Mathlib: `AddCommGroup.equiv_free_prod_directSum_zmod`. -/
theorem abelian_groups (G : Type*) [AddCommGroup G] [AddGroup.FG G] :
    ∃ (n : ℕ) (ι : Type) (_ : Fintype ι) (p : ι → ℕ) (_ : ∀ i, Nat.Prime (p i)) (e : ι → ℕ),
      Nonempty (G ≃+ (Fin n →₀ ℤ) × DirectSum ι (fun i => ZMod (p i ^ e i))) :=
  AddCommGroup.equiv_free_prod_directSum_zmod G
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor

Finally, tensor products: the tensor–hom correspondence, right exactness, and the counterexample to left exactness, proved by computing on the pure tensor 1⊗11 \otimes 1 and the isomorphism Z⊗Z/2≅Z/2\Z \otimes \Z/2 \cong \Z/2:

tensor_homLean 4Applies a library theoremFormally verified
/-- **The tensor–hom adjunction** (one variable at a time): bilinear maps `M × N → P`, that is
linear maps `M → Hom(N, P)`, are the same as linear maps `M ⊗ N → P`, naturally. Mathlib:
`TensorProduct.lift.equiv`. -/
noncomputable def tensor_hom (R M N P : Type*) [CommRing R] [AddCommGroup M] [Module R M]
    [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] :
    (M →ₗ[R] N →ₗ[R] P) ≃ₗ[R] (M ⊗[R] N →ₗ[R] P) :=
  TensorProduct.lift.equiv (RingHom.id R) M N P
Axioms used: propext, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor
tensor_right_exactLean 4Applies a library theoremFormally verified
/-- **Tensoring is right exact**: if `M → N → P → 0` is exact then so is
`M ⊗ Q → N ⊗ Q → P ⊗ Q → 0`. Mathlib: `rTensor_exact` (exactness in the middle) and
`LinearMap.rTensor_surjective` (at the right). The lesson derives it from the tensor–hom
adjunction. -/
theorem tensor_right_exact {R M N P : Type*} (Q : Type*) [CommRing R] [AddCommGroup M] [Module R M]
    [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P] [AddCommGroup Q] [Module R Q]
    {f : M →ₗ[R] N} {g : N →ₗ[R] P} (hfg : Function.Exact f g) (hg : Function.Surjective g) :
    Function.Exact (f.rTensor Q) (g.rTensor Q) ∧ Function.Surjective (g.rTensor Q) :=
  ⟨rTensor_exact Q hfg hg, LinearMap.rTensor_surjective Q hg⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor
tensor_not_left_exactLean 4Proved here from basic factsFormally verified
/-- **…but not exact.** Multiplication by `2` on `ℤ` is injective, yet after tensoring with
`ℤ/2` it becomes the zero map on `ℤ ⊗ ℤ/2 ≅ ℤ/2 ≠ 0`, so it is no longer injective.
Human proof: on a pure tensor, `(2a) ⊗ b = a ⊗ 2b = a ⊗ 0 = 0`; and `1 ⊗ 1 ≠ 0` because
`n ⊗ b ↦ n • b` is a well-defined map `ℤ ⊗ ℤ/2 → ℤ/2` sending it to `1`. -/
theorem tensor_not_left_exact :
    Function.Injective (2 • LinearMap.id : ℤ →ₗ[ℤ] ℤ) ∧
      ¬ Function.Injective ((2 • LinearMap.id : ℤ →ₗ[ℤ] ℤ).rTensor (ZMod 2)) := by
  constructor
  · intro a b h
    have h' : 2 * a = 2 * b := by simpa [two_smul, two_mul] using h
    omega
  · intro hinj
    -- the element `1 ⊗ 1` is sent to `2 ⊗ 1 = 1 ⊗ 2 = 0`
    have himg : ((2 • LinearMap.id : ℤ →ₗ[ℤ] ℤ).rTensor (ZMod 2)) ((1 : ℤ) ⊗ₜ (1 : ZMod 2)) = 0 := by
      rw [LinearMap.rTensor_tmul]
      simp only [LinearMap.smul_apply, LinearMap.id_apply]
      rw [TensorProduct.smul_tmul]
      have : (2 : ℕ) • (1 : ZMod 2) = 0 := by decide
      rw [this, TensorProduct.tmul_zero]
    have hzero : (1 : ℤ) ⊗ₜ[ℤ] (1 : ZMod 2) = 0 :=
      hinj (himg.trans (map_zero _).symm)
    -- but `1 ⊗ 1` maps to `1 ≠ 0` under `ℤ ⊗ ℤ/2 ≅ ℤ/2`
    have := congrArg (TensorProduct.lid ℤ (ZMod 2)) hzero
    rw [TensorProduct.lid_tmul, map_zero, one_smul] at this
    exact one_ne_zero this
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Modules.leanTry it in the Lean web editor

What is and is not formalised. Proved here: exactness of 0→Z→Z→Z/2→00 \to \Z \to \Z \to \Z/2 \to 0 in the middle, that Z/2\Z/2 is not free, the lifting property of free modules, and the failure of left exactness of −⊗Z/2- \otimes \Z/2. From Mathlib: free ⇒ projective, the lifting property, Theorem 2, the structure theorem, the classification of finitely generated abelian groups, the tensor–hom correspondence and right exactness. Not formalised in this module: the Smith normal form proof (Mathlib has Submodule.smithNormalForm for submodules of free modules over a PID), the uniqueness argument of Theorem 4, the lemma testing exactness by Hom\Hom, and the Jordan normal form as a corollary.

ComputationC

Smith normal forms, computed

The first experiment implements the Smith normal form over Z\Z, reads off the abelian group presented by a relation matrix, and checks two theorems on many matrices: the divisibility chain, and the determinantal divisor identity d1d2⋯dk=d_1 d_2 \cdots d_k = (gcd of the k×kk \times k minors). The right-hand side is unchanged by invertible row and column operations, so the identity shows that the did_i depend only on the matrix. It then counts abelian groups of order n≤100n \leq 100 in two independent ways — chains of invariant factors, and products of partition numbers — confirming Corollary 5 in that range.

Smith normal form and the classification of abelian groupsPythonExact computationExhaustive finite checkComputationally tested
"""Smith normal form over the integers: classifying abelian groups by matrices.

A finitely generated abelian group given by generators and relations is
Z^m / (column span of an integer relation matrix A). Row and column operations
over Z (invertible over Z) bring A to diagonal form diag(d1, d2, ...) with
d1 | d2 | ..., and then the group is Z/d1 + Z/d2 + ... + Z^(free rank).
This experiment implements the reduction, checks the divisibility chain and
the determinantal-divisor identity d1 d2 ... dk = gcd of k x k minors (which
proves the d_i do not depend on the choices made), and compares two ways of
counting abelian groups of order n: invariant-factor chains versus products
of partition numbers (elementary divisors). Exact integer arithmetic.
"""

from itertools import combinations
from math import gcd, prod
import random

def smith_diagonal(matrix):
    """Invariant factors d1 | d2 | ... (with zeros last) of an integer matrix."""
    a = [list(row) for row in matrix]
    m, n = len(a), len(a[0]) if a else 0
    diag = []
    for t in range(min(m, n)):
        entries = [(abs(a[i][j]), i, j) for i in range(t, m)
                   for j in range(t, n) if a[i][j]]
        if not entries:
            break
        while True:
            _, i, j = min(entries)
            a[t], a[i] = a[i], a[t]
            for row in a:
                row[t], row[j] = row[j], row[t]
            done = True
            for i in range(t + 1, m):           # clear column t
                q = a[i][t] // a[t][t]
                a[i] = [x - q * y for x, y in zip(a[i], a[t])]
                done &= a[i][t] == 0
            for j in range(t + 1, n):           # clear row t
                q = a[t][j] // a[t][t]
                for row in a:
                    row[j] -= q * row[t]
                done &= a[t][j] == 0
            bad = [(i, j) for i in range(t + 1, m) for j in range(t + 1, n)
                   if a[i][j] % a[t][t]]
            if done and bad:                    # pivot must divide the rest
                i = bad[0][0]
                a[t] = [x + y for x, y in zip(a[t], a[i])]
                done = False
            if done:
                break
            entries = [(abs(a[i][j]), i, j) for i in range(t, m)
                       for j in range(t, n) if a[i][j]]
        diag.append(abs(a[t][t]))
    return diag + [0] * (min(m, n) - len(diag))

def cokernel(matrix):
    """(free rank, torsion orders > 1) of Z^m / column span of the matrix."""
    m = len(matrix)
    diag = smith_diagonal(matrix)
    nonzero = [d for d in diag if d]
    return m - len(nonzero), [d for d in nonzero if d > 1]

def det(mat):
    """Integer determinant by Laplace expansion (small matrices only)."""
    if len(mat) == 1:
        return mat[0][0]
    return sum((-1) ** j * mat[0][j] * det([r[:j] + r[j + 1:] for r in mat[1:]])
               for j in range(len(mat)))

def determinantal_divisor(matrix, k):
    """gcd of all k x k minors of the matrix."""
    rows, cols = range(len(matrix)), range(len(matrix[0]))
    g = 0
    for r in combinations(rows, k):
        for c in combinations(cols, k):
            g = gcd(g, det([[matrix[i][j] for j in c] for i in r]))
    return g

def chain_ok(diag):
    """d1 | d2 | ... among the non-zero entries, zeros only at the end."""
    nz = [d for d in diag if d]
    tail_zero = all(d == 0 for d in diag[len(nz):])
    return tail_zero and all(b % a == 0 for a, b in zip(nz, nz[1:]))

def identity_ok(matrix):
    """d1 ... dk equals the k-th determinantal divisor for every k."""
    diag = smith_diagonal(matrix)
    return all(prod(diag[:k]) == determinantal_divisor(matrix, k)
               for k in range(1, len(diag) + 1))

def partitions(n):
    """Number of partitions of n."""
    p = [1] + [0] * n
    for part in range(1, n + 1):
        for total in range(part, n + 1):
            p[total] += p[total - part]
    return p[n]

def groups_by_elementary_divisors(n):
    """Abelian groups of order n: product of p(e) over prime powers p^e || n."""
    count, q = 1, 2
    while n > 1:
        e = 0
        while n % q == 0:
            n, e = n // q, e + 1
        count *= partitions(e)
        q += 1
    return count

def groups_by_invariant_factors(n, prev=1):
    """Chains d1 | d2 | ... | dk with d1 >= 2, prev | d1 and product n."""
    if n == 1:
        return 1
    return sum(groups_by_invariant_factors(n // d, d) for d in range(2, n + 1)
               if n % d == 0 and d % prev == 0)

def main():
    examples = [("Z^2 / <(2,0), (0,3)>", [[2, 0], [0, 3]]),
                ("Z^2 / <(4,6), (6,4)>", [[4, 6], [6, 4]]),
                ("Z^3 / <(2,4,6), (4,8,12)>", [[2, 4], [4, 8], [6, 12]]),
                ("Z^3 / <(1,1,1), (0,2,4), (0,0,6)>",
                 [[1, 0, 0], [1, 2, 0], [1, 4, 6]])]
    print("Presented abelian groups (relations are the columns):")
    for name, mat in examples:
        free, tors = cokernel(mat)
        parts = [f"Z/{d}" for d in tors] + ["Z"] * free
        print(f"  {name:34} = {' + '.join(parts) or '0'}")
    small = [[[a, b], [c, d]] for a in range(-3, 4) for b in range(-3, 4)
             for c in range(-3, 4) for d in range(-3, 4)]
    ok2 = sum(chain_ok(smith_diagonal(m)) and identity_ok(m) for m in small)
    rng = random.Random(2024)
    big = [[[rng.randint(-9, 9) for _ in range(3)] for _ in range(3)]
           for _ in range(300)]
    ok3 = sum(chain_ok(smith_diagonal(m)) and identity_ok(m) for m in big)
    print("Divisibility chain and minor identity d1...dk = gcd of k x k minors:")
    print(f"  all {len(small)} 2x2 matrices, entries in [-3, 3]: hold for {ok2}")
    print(f"  300 random 3x3 matrices, entries in [-9, 9]: hold for {ok3}")
    agree = all(groups_by_elementary_divisors(n) == groups_by_invariant_factors(n)
                for n in range(1, 101))
    print("Abelian groups of order n, two ways, agree for n <= 100:", agree)
    print("  n = 8, 16, 72, 64:", [groups_by_elementary_divisors(n)
                                  for n in (8, 16, 72, 64)])
    print()
    print("Epistemic status: exact integer arithmetic, exhaustive over the "
          "finite range\nstated and seeded-random elsewhere. The minor identity "
          "shows that the d_i\ndepend only on the matrix, not on the "
          "operations chosen. Finite checks are\nevidence; the structure "
          "theorem is proved in the lesson for every PID.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The second experiment applies the same theory over Q[x]\Q[x]: the invariant factors of the module (Qn,A)(\Q^n, A) are quotients of gcds of minors of xI−AxI - A, and their prime-power factors predict the Jordan blocks, which it compares with an independent Jordan form computation.

Jordan blocks from invariant factors over Q[x]PythonSymbolic computationExact computationComputationally tested
"""Jordan normal form from the structure theorem over Q[x].

A square matrix A makes Q^n into a Q[x]-module (x acts by A), presented by
the matrix xI - A. Its invariant factors d1 | d2 | ... | dn are quotients of
determinantal divisors: D_k = monic gcd of the k x k minors of xI - A, and
d_k = D_k / D_(k-1). Each power (x - c)^e in the d_k is a Jordan block of
size e for the eigenvalue c. We compute the blocks this way and compare them
with sympy's independent jordan_form; an irreducible factor such as x^2 + 1
shows a module with no Jordan form over Q. Exact symbolic computation.
"""

from itertools import combinations

import sympy as sp

X = sp.Symbol("x")

def invariant_factors(rows):
    """Invariant factors d_1 | ... | d_n of the Q[x]-module Q^n, x acting by A."""
    a = sp.Matrix(rows)
    n = a.shape[0]
    m = X * sp.eye(n) - a
    divisors = [sp.Integer(1)]
    for k in range(1, n + 1):
        g = sp.Integer(0)
        for r in combinations(range(n), k):
            for c in combinations(range(n), k):
                g = sp.gcd(g, m.extract(list(r), list(c)).det())
        divisors.append(sp.Poly(g, X).monic().as_expr())
    return [sp.factor(sp.cancel(divisors[k] / divisors[k - 1]))
            for k in range(1, n + 1)]

def predicted_blocks(factors):
    """Sorted (eigenvalue, size) pairs from linear prime powers; None if a
    factor does not split into linear factors over Q."""
    blocks = []
    for d in factors:
        for p, e in sp.factor_list(d, X)[1]:
            if sp.degree(p, X) != 1:
                return None
            blocks.append((sp.solve(p, X)[0], e))
    return sorted(blocks)

def sympy_blocks(rows):
    """Sorted (eigenvalue, size) pairs read off sympy's Jordan form."""
    _, j = sp.Matrix(rows).jordan_form()
    n, blocks, i = j.shape[0], [], 0
    while i < n:
        size = 1
        while i + size < n and j[i + size - 1, i + size] == 1:
            size += 1
        blocks.append((j[i, i], size))
        i += size
    return sorted(blocks)

def main():
    examples = {
        "A (4x4, eigenvalues 1, 2, 4)": [[5, 4, 2, 1], [0, 1, -1, -1],
                                         [-1, -1, 3, 0], [1, 1, -1, 2]],
        "N1 (nilpotent)": [[0, 1, 0, 0], [0, 0, 0, 0],
                           [0, 0, 0, 1], [0, 0, 0, 0]],
        "N2 (nilpotent)": [[0, 1, 0, 0], [0, 0, 1, 0],
                           [0, 0, 0, 0], [0, 0, 0, 0]],
        "R (rotation by 90 degrees)": [[0, -1], [1, 0]],
    }
    for name, rows in examples.items():
        factors = invariant_factors(rows)
        shown = ", ".join(str(f) for f in factors if f != 1)
        print(f"{name}:")
        print(f"  invariant factors (non-unit): {shown}")
        pred = predicted_blocks(factors)
        if pred is None:
            print("  a factor is irreducible of degree > 1: no Jordan form "
                  "over Q")
        else:
            agree = pred == sympy_blocks(rows)
            print(f"  blocks (eigenvalue, size): {pred}; sympy agrees: {agree}")
    print("N1 and N2 have the same characteristic polynomial x**4 but are "
          "not similar.")
    print()
    print("Epistemic status: exact symbolic computation for four matrices; "
          "it checks the\nrecipe 'Jordan blocks = prime powers in the "
          "invariant factors' on examples.\nThe recipe is a theorem: the "
          "structure theorem over the PID Q[x], in the lesson.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Exercises

Exercises

1. Modules

Warm-upHuman

Which of these Z\mathbb{Z}-modules are free? (Choose all that apply.)

Choose all that apply

2. Modules

Warm-upHuman

How many abelian groups of order 7272 are there, up to isomorphism?

3. Modules

CoreHuman

Which group is Z2/⟨(4,6),(6,4)⟩\mathbb{Z}^2 / \langle (4, 6), (6, 4) \rangle (the quotient by the subgroup generated by these two vectors)?

Choose one

4. Modules

CoreHuman

A linear map TT on C6\mathbb{C}^6 has characteristic polynomial (x−2)6(x - 2)^6, minimal polynomial (x−2)3(x - 2)^3, and dim⁡ker⁡(T−2)=3\dim \ker(T - 2) = 3. What are the sizes of its Jordan blocks?

Choose one

5. Modules

CoreHuman

In the proof that a submodule N⊆RnN \subseteq R^n over a PID is free, why does the sequence 0→N∩Rn−1→N→π(N)→00 \to N \cap R^{n-1} \to N \to \pi(N) \to 0 split?

Choose one

6. Modules

StretchHuman

Over which of these rings RR does some submodule of a free RR-module (of finite rank) fail to be free? (Choose all that apply.)

Choose all that apply

7. Modules

CoreHuman

How many elements does Z/12⊗ZZ/18\mathbb{Z}/12 \otimes_{\mathbb{Z}} \mathbb{Z}/18 have?

8. Modules

CoreFormal

Which Lean statement expresses that tensoring with Z/2\mathbb{Z}/2 does not preserve injectivity (as proved in tensor_not_left_exact)?

Choose one

9. Modules

StretchComputational

Write invariant_factors(orders): given positive integers n1,…,nkn_1, \dots, n_k, return the invariant factors of Z/n1⊕⋯⊕Z/nk\mathbb{Z}/n_1 \oplus \cdots \oplus \mathbb{Z}/n_k as a list [d1,d2,… ][d_1, d_2, \dots] with 1<d1∣d2∣⋯1 < d_1 \mid d_2 \mid \cdots (empty for the zero group). For example Z/4⊕Z/6≅Z/2⊕Z/12\mathbb{Z}/4 \oplus \mathbb{Z}/6 \cong \mathbb{Z}/2 \oplus \mathbb{Z}/12, so invariant_factors([4, 6]) == [2, 12].

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

"Modules behave like vector spaces." Many familiar facts fail: Z/2\Z/2 is a Z\Z-module with no basis; the independent set {2}⊆Z\{2\} \subseteq \Z does not extend to a basis; the generating set {2,3}\{2, 3\} of Z\Z contains no basis; the submodule 2Z⊆Z2\Z \subseteq \Z has no complement; and over non-noetherian rings a finitely generated module can have submodules that are not finitely generated. What survives is everything that does not divide by scalars.

Misconception

"Tensoring preserves injective maps." It preserves surjections and cokernels (right exactness) but not injections: multiplication by 22 on Z\Z is injective, and becomes the zero map on Z⊗Z/2≅Z/2\Z \otimes \Z/2 \cong \Z/2. Modules that do preserve injections under tensoring are the flat ones; Tor1\mathrm{Tor}_1 measures the failure.

Misconception

"Projective means free" and "torsion-free means free". Both are true for finitely generated modules over a PID, and both fail in general: Z/2\Z/2 is a projective, non-free Z/6\Z/6-module; Q\Q is a torsion-free, non-free Z\Z-module (it is not finitely generated); and a non-principal ideal of a Dedekind domain is a finitely generated, torsion-free, projective module that is not free. Over local rings projective modules are free (Kaplansky), and over polynomial rings k[x1,…,xn]k[x_1, \dots, x_n] finitely generated projective modules are free (Quillen and Suslin, 1976) — deep theorems, not formalities.

Misconception

"The characteristic polynomial determines a matrix up to similarity." It is the product of the invariant factors, and different lists of invariant factors can have the same product: the nilpotent matrices with Jordan blocks (2,2)(2, 2) and (3,1)(3, 1) both have characteristic polynomial x4x^4. The complete invariant is the list d1∣⋯∣dkd_1 \mid \cdots \mid d_k.

ViewpointsH

Viewpoints

Geometry— Projective modules are vector bundles

For a compact Hausdorff space XX, let C(X)C(X) be the ring of continuous real functions. The Serre–Swan theorem (Serre 1955 for algebraic varieties, Swan 1962 in this form) says that E↦Γ(X,E)E \mapsto \Gamma(X, E), sending a vector bundle to its module of continuous sections, is an equivalence between real vector bundles on XX and finitely generated projective C(X)C(X)-modules. Free modules correspond to trivial bundles, and "direct summand of a free module" is the statement that every bundle is a summand of a trivial one. On the circle, the Möbius line bundle gives a projective C(S1)C(S^1)-module PP that is not free, while P⊕P≅C(S1)2P \oplus P \cong C(S^1)^2 because the sum of two Möbius bundles is trivial. In algebraic geometry, finitely generated modules over k[x1,…,xn]k[x_1, \dots, x_n] are coherent sheaves on affine space and projective ones are vector bundles; the Quillen–Suslin theorem says they are all trivial (see vector bundles and algebraic geometry).

Topology— Betti numbers, torsion and barcodes

The integral homology groups Hn(X;Z)H_n(X; \Z) of a finite cell complex are finitely generated Z\Z-modules, and the structure theorem splits each into a free part Zbn\Z^{b_n} — the Betti number bnb_n — and a torsion part, Poincaré's torsion coefficients. The real projective plane has H1(RP2;Z)≅Z/2H_1(\R P^2; \Z) \cong \Z/2: a loop that is not a boundary, although twice it is. In topological data analysis, a filtration of a space X0⊆X1⊆⋯X_0 \subseteq X_1 \subseteq \cdots gives homology groups Hn(Xi;k)H_n(X_i; k) linked by maps, which together form a graded module over k[t]k[t] (tt moves one step along the filtration). Zomorodian and Carlsson (2005) observed that the structure theorem for graded modules over the PID k[t]k[t] decomposes it into shifted copies Σak[t]\Sigma^a k[t] and Σak[t]/(tb)\Sigma^a k[t]/(t^{b}) of k[t]k[t] and k[t]/(tb)k[t]/(t^b): the barcode of features born at time aa and living forever or for bb steps. The same decomposition, in quiver language, is the classification of representations of a line in quivers and path algebras.

Number theory— Ideals of number rings: projective but not free

In the ring of integers OK\mathcal{O}_K of a number field — a Dedekind domain, but usually not a PID — every non-zero ideal II is a projective module of rank 11, and II is free exactly when it is principal. So the ideal class group Cl(K)\mathrm{Cl}(K) measures how far projective modules are from being free. In Z[−5]\Z[\sqrt{-5}] the ideal I=(2,1+−5)I = (2, 1 + \sqrt{-5}) is not principal (no element has norm 22, as a2+5b2=2a^2 + 5b^2 = 2 has no integer solutions), but I2=(2)I^2 = (2); it is projective and not free. Steinitz (1911) showed that every finitely generated torsion-free OK\mathcal{O}_K-module is isomorphic to OKn−1⊕J\mathcal{O}_K^{n-1} \oplus J for an ideal JJ whose class in Cl(K)\mathrm{Cl}(K) is an invariant. Over Z\Z itself, the structure theorem is the arithmetic statement that relation matrices can be diagonalised, which reduces linear systems of Diophantine equations to congruences (see algebraic number theory).

Category theory— R-Mod as an abelian category; tensor as a left adjoint

R-ModR\text{-}\cat{Mod} is the model abelian category (see abelian categories). Projective objects are those PP for which Hom(P,−)\Hom(P, -) is exact; there are enough projectives (free modules surject onto everything) and enough injectives, which makes derived functors possible. The tensor–hom isomorphism says −⊗RN⊣HomR(N,−)- \otimes_R N \dashv \Hom_R(N, -), so tensoring preserves colimits and Hom(N,−)\Hom(N, -) preserves limits — right and left exactness are shadows of adjointness. The Eilenberg–Watts theorem (1960) says every right exact functor R-Mod→S-ModR\text{-}\cat{Mod} \to S\text{-}\cat{Mod} that preserves direct sums is B⊗R−B \otimes_R - for an (S,R)(S, R)-bimodule BB; and Morita theory shows that R-ModR\text{-}\cat{Mod} and Mn(R)-ModM_n(R)\text{-}\cat{Mod} are equivalent, so the category remembers less than the ring.

History & global context

History and global context

  • Solving systems of linear equations by elimination is ancient: chapter 8 (fangcheng) of the Chinese Nine Chapters on the Mathematical Art (compiled by about the 1st century CE) reduces rectangular arrays of coefficients by column operations. The remainder problem of the Sunzi Suanjing (around the 3rd–5th century) is the earliest known instance of the Chinese remainder theorem, which in module language is Z/mn≅Z/m⊕Z/n\Z/mn \cong \Z/m \oplus \Z/n for coprime m,nm, n.
  • Henry John Stephen Smith (1861) diagonalised integer matrices by invertible row and column operations, in his work on systems of linear Diophantine equations. Karl Weierstrass (1868) introduced elementary divisors of matrix pencils, and Camille Jordan's Traité des substitutions (1870) gave the canonical form now named after him. Leopold Kronecker (1870) proved the decomposition of finite abelian groups, and Ferdinand Georg Frobenius and Ludwig Stickelberger (1879) gave the full structure theorem for finitely generated abelian groups.
  • Richard Dedekind introduced the word Modul (for additive subgroups of number fields) and ideals in the 1870s. Emmy Noether and her school in the 1920s made modules over rings the unifying language, and B. L. van der Waerden's Moderne Algebra (1930–31) spread it; the structure theorem over a PID took its modern form there.
  • Hassler Whitney (1938) defined tensor products of abelian groups; Reinhold Baer (1940) introduced injective modules; Henri Cartan and Samuel Eilenberg's Homological Algebra (1956) introduced projective modules and made exactness central.
  • Jean-Pierre Serre (1955) related projective modules to vector bundles and asked whether projective modules over polynomial rings are free; Daniel Quillen and Andrei Suslin answered yes, independently, in 1976. Richard Swan (1962) proved the topological version of the correspondence.
Further reading

Further reading

  • David S. Dummit and Richard M. Foote, Abstract Algebra (3rd ed., 2004) — Chapters 10–12: modules, tensor products, the structure theorem, rational and Jordan forms.
  • Serge Lang, Algebra (revised 3rd ed., 2002) — Chapters III and XVI: modules and tensor products.
  • Paolo Aluffi, Algebra: Chapter 0 (2009) — Chapters III, VI and VIII: modules with a categorical outlook, Smith normal form.
  • M. F. Atiyah and I. G. Macdonald, Introduction to Commutative Algebra (1969) — Chapter 2: modules, exactness, tensor products, flatness.
  • Nathan Jacobson, Basic Algebra I (2nd ed., 1985) — Chapter 3: modules over a PID with full proofs.
  • T. Y. Lam, Lectures on Modules and Rings (1999) — projective, injective and flat modules in depth.