Chain complexes and homology
Homology turns a space built from cells into a list of abelian groups. Once the cells and their boundaries are written down, everything is integer linear algebra: the Smith normal form of each boundary matrix gives the free part and the torsion.
Chain complexes
A cell complex has cells in dimension . The chain group has one generator per -cell, and the boundary map sends a cell to the signed sum of the cells on its boundary. The boundary of a boundary is empty, so , and the cycles contain the boundaries . The homology is the quotient
chainComplex takes the list . Each has one column per -cell holding its boundary, and one row per -cell. It checks and refuses a list that is not a chain complex.
import { chainComplex } from "@ratmath/structures";
// The torus: one vertex v, edges a, b, one face glued along a b a⁻¹ b⁻¹.
// ∂a = v − v = 0, ∂b = 0, ∂(face) = a + b − a − b = 0.
const T = chainComplex([[[0, 0]], [[0], [0]]]);
String(T); // "H0 = Z, H1 = Z^2, H2 = Z"
T.eulerCharacteristic; // 0 = 1 − 2 + 1
// The projective plane: face glued along a a, so ∂(face) = 2a.
const P = chainComplex([[[0]], [[2]]]);
String(P); // "H0 = Z, H1 = Z/2, H2 = 0"
Homology from the Smith normal form
Invertible integer row and column operations bring to the diagonal form with (see abelian groups). Then is free of rank , and inside it is spanned by for the invariant factors of . So
where the are those of . For the Klein bottle, glued along , and .
const K = chainComplex([[[0, 0]], [[0], [2]]]);
String(K.homology(1)); // "Z/2 × Z"
chainComplex([[[0, 0]], [[2, 6], [4, 8]]]).homology(1).toString(); // "Z/2 × Z/4": Smith form diag(2, 4)
Betti numbers, χ and other coefficients
The Betti number is the rank of , the number of copies of . Over a field the same recipe gives a vector space: over its dimension is , and over the ranks are counted mod , so torsion divisible by shows up twice (the universal coefficient theorem: , with the number of invariant factors of divisible by ). In every case the alternating sum of Betti numbers is the Euler characteristic , which needs no homology at all.
P.betti(); // [1, 0, 0]
P.betti({ coefficients: "Z/2" }); // [1, 1, 1]: the Z/2 in H1 is counted in H1 and in H2
String(P.homology(2, { coefficients: "Z/2" })); // "Z/2"
P.eulerCharacteristic; // 1
Glued polygons, simplicial complexes and their homology are in @ratmath/geo, which builds these boundary matrices for you.
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.