Topology

Simplicial complexes

A simplicial complex is a space built from points, edges, triangles and their higher analogues, glued along whole faces. It is given by its maximal simplices; everything else, from the face counts to the homology and the fundamental group, follows by counting and integer linear algebra.

Faces and the f-vector

simplicialComplex takes a list of simplices, each a list of vertices, and adds every face of each. The f-vector counts the faces in each dimension, and the Euler characteristic is its alternating sum. The boundary of a tetrahedron, four triangles on four vertices, is a sphere: 4−6+4=24 - 6 + 4 = 2.

import { simplicialComplex, simplicial } from "@ratmath/geo";

const S = simplicialComplex([[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]);
S.fVector;               // [4, 6, 4]
S.eulerCharacteristic;   // 2
String(S.chainComplex());   // "H0 = Z, H1 = 0, H2 = Z"

The boundary map sends a simplex [v0,…,vk][v_0, \dots, v_k] (vertices in increasing order) to ∑i(−1)i[v0,…,vi^,…,vk]\sum_i (-1)^i [v_0, \dots, \widehat{v_i}, \dots, v_k], the face without viv_i with sign (−1)i(-1)^i. These matrices go to @ratmath/structures for the homology, with coefficients in Z\mathbb Z, Q\mathbb Q or Z/p\mathbb Z/p.

Named complexes

simplicial.sphere(n) is the boundary of the (n+1)(n+1)-simplex. simplicial.torus() is Möbius and Császár's torus on 7 vertices, the smallest possible: every pair of vertices is an edge, (72)=21\binom72 = 21, and 7−21+14=07 - 21 + 14 = 0. simplicial.projectivePlane() is the 6-vertex projective plane (an icosahedron with opposite points identified), and simplicial.kleinBottle() a 12-vertex Klein bottle from a grid of squares.

const T = simplicial.torus();
T.fVector;                    // [7, 21, 14]
String(T.homology(1));        // "Z^2"
simplicial.projectivePlane().betti({ coefficients: "Z/2" });   // [1, 1, 1]
simplicial.sphere(3).fVector; // [5, 10, 10, 5]

Triangulated surfaces

A 2-dimensional complex is a surface when every edge lies in one or two triangles and the triangles around each vertex form a disk: the link of the vertex is a circle (or an arc, on the boundary). isSurface checks this, and classify() turns the triangles into glued polygons, one edge label per edge, so the classification agrees with the one from an edge word.

simplicial.kleinBottle().classify().name;   // "Klein bottle"
simplicialComplex([[1, 2, 3], [1, 2, 4], [1, 2, 5]]).surfaceCheck();
// { surface: false, reason: "edge [1,2] is in 3 triangles" }

Graphs, polyhedra and π₁

A graph is a 1-dimensional complex: χ=V−E\chi = V - E, and for a connected graph b1=E−V+1b_1 = E - V + 1 counts independent cycles. simplicial.fromGraph takes { vertices, edges } or a graph from @ratmath/discrete. A polyhedron's boundary, each face cut into triangles, is a sphere. The fundamental group comes from a spanning tree of the edges: the other edges generate, and each triangle gives a relation.

import { solids } from "@ratmath/geo";
simplicial.fromPolyhedron(solids.cube()).classify().name;   // "sphere"
String(simplicial.sphere(1).fundamentalGroup());             // "⟨e3 | ⟩": the circle, Z
String(simplicial.torus().fundamentalGroup().abelianInvariants());   // "Z^2"
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