Topology

Surfaces from polygons

Textbooks draw a torus as a square with opposite sides glued, and write it as the word aba−1b−1aba^{-1}b^{-1} read around the boundary. surface takes such words, works out which corners the gluing identifies, and from the resulting cells computes homology, orientability and which surface it is.

Edge words and cells

Each polygon is a word in edge labels, read around its boundary: a means the edge is traversed along its arrow, a^-1 (or a', or a⁻¹) against it. Edges with the same label are glued, so each label appears twice, or once for an edge left on the boundary. Gluing aa to aa also glues the tail of one copy to the tail of the other, and the head to the head; following those identifications gives the vertices. A square glued as aba−1b−1aba^{-1}b^{-1} has all four corners become one point, so the torus has one vertex, two edges and one face, and χ=1−2+1=0\chi = 1 - 2 + 1 = 0.

import { surface } from "@ratmath/geo";

const T = surface("a b a^-1 b^-1");
T.cells;                    // [1, 2, 1]: V, E, F
T.eulerCharacteristic;      // 0
String(T.chainComplex());   // "H0 = Z, H1 = Z^2, H2 = Z"
String(surface("a a").homology(1));          // "Z/2": the projective plane
String(surface("a b a^-1 b").homology(1));   // "Z/2 × Z": the Klein bottle

The boundary maps are read off the word: ∂1\partial_1 sends an edge to head minus tail, and ∂2\partial_2 sends a face to the sum of its edges with their exponents. For the Klein bottle that is a+b−a+b=2ba + b - a + b = 2b, which is where the Z/2\mathbb Z/2 comes from. The homology itself is computed by @ratmath/structures.

Orientability and classification

A surface is orientable when the polygons can be given directions so that every glued pair of edges is traversed in opposite directions. Within one polygon that means each label appears once as aa and once as a−1a^{-1}; across polygons it is a two-colouring problem. The classification theorem says that a closed connected surface is decided by orientability and χ\chi: the sphere (χ=2\chi = 2), a connected sum of gg tori (χ=2−2g\chi = 2 - 2g), or a connected sum of kk projective planes (χ=2−k\chi = 2 - k). Each boundary circle lowers χ\chi by one more.

surface("a a b b").classify().name;               // "Klein bottle": the same as a b a^-1 b
surface("a b a c").classify().name;               // "Möbius band": b and c stay on the boundary
surface("a b a^-1 b^-1 c d c^-1 d^-1").classify();
// { eulerCharacteristic: -2, orientable: true, genus: 2, name: "connected sum of 2 tori", normalForm: "a1 b1 a1^-1 b1^-1 a2 b2 a2^-1 b2^-1", … }

import { classifySurface } from "@ratmath/geo";
classifySurface({ euler: 10 - 36 + 24, orientable: true }).name; // "connected sum of 2 tori"

Connected sums and several polygons

A surface may be several polygons, glued along shared labels. singleFace() merges them along shared edges into one polygon, which changes the cells but not the surface. The connected sum of two closed surfaces is their two words side by side (cut a small disk from each at a vertex and join along the cut), so torus # projective plane is aba−1b−1ccaba^{-1}b^{-1}cc: with χ=−1\chi = -1 and not orientable, it is the connected sum of three projective planes.

surface(["a b c", "c^-1 b^-1 a^-1"]).classify().name;           // "sphere", from two triangles
surface("a b a^-1 b^-1").connectedSum("a a").classify().name;   // "connected sum of 3 projective planes"

The fundamental group

Contract a spanning tree of the edges to a point. The remaining edges are loops, and each polygon becomes a relation among them (van Kampen's theorem for a 2-complex). So fundamentalGroup() returns a presentation, with one relator per polygon. Its abelianisation is H1H_1, which is a good check.

String(surface("a b a^-1 b^-1").fundamentalGroup());    // "⟨a, b | aba⁻¹b⁻¹⟩", which is Z²
surface("a a").fundamentalGroup().order();               // 2
String(surface("a b a^-1 b").fundamentalGroup().abelianInvariants());   // "Z/2 × Z" = H1
Try itEdit the code and run it with @ratmath/geo and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs