Computing Homology

MATH 348 Topology

Computing boundary matrices of a simplicial complex

The following function computes the boundary matrix for a given simplicial complex in the specified dimension. The simplicial complex must be supplied as a MeshRegion.

boundaryMatrix[complex_,dimension_]:=Module[
(* local variables *)
{simplices, faces,matrix, row, col},

(* get lists of simplices of the appropriate dimensions *)
simplices=MeshCells[complex,dimension];
faces=Table[If[dimension==1,{face[[1]]},Sort[face[[1]]]],{face,MeshCells[complex,dimension-1]}];

(* initialize a zero matrix *)
matrix=Table[0,Length[faces],Length[simplices]];

(* set entries in the matrix *)
col=1;
Do[
Do[
row=Position[faces,Sort[r]][[1,1]];
matrix[[row,col]]=1,
{r,Subsets[simp[[1]],{dimension}]}];
col+=1
,
{simp, simplices}];

(* return the matrix *)
matrix
]

Worksheet example

Here is the simplicial complex from the worksheet.

complex=MeshRegion[{{0,0},{1.9,-0.1},{1.7,1.5},{0.2,1.6},{-2,0.5},{1,-1.3},{4,0.7},{0.7,2.8}}, {Triangle[{1,2,6}],Triangle[{1,4,5}],Triangle[{1,5,6}],Triangle[{2,6,7}],Triangle[{2,3,7}],Triangle[{3,7,8}],Triangle[{3,4,8}],Triangle[{4,5,8}]}]

HighlightMesh[complex,Labeled[0,"Index"]]

Compute the boundary matrices:

b1=boundaryMatrix[complex,1];
MatrixForm[b1]

MatrixRank[b1, Modulus->2]

b2=boundaryMatrix[complex,2];
MatrixForm[b2]

MatrixRank[b2,Modulus->2]

Sphere example

sphere=ConvexHullMesh[SpherePoints[50]]

Compute the boundary matrix (Subscript[δ, 1]) and the Betti number (Subscript[β, 0]):

b1=boundaryMatrix[sphere,1];

MatrixRank[b1,Modulus->2]

number of vertices = 50 = nullity((Subscript[δ, 0]))
rank((Subscript[δ, 1]))=49
Therefore, (Subscript[β, 0])=50-49=1. This indicates that the sphere has one connected component.

Compute the boundary matrix (Subscript[δ, 2]) and the Betti number (Subscript[β, 1]):

b2=boundaryMatrix[sphere,2];

MatrixRank[b2,Modulus->2]

How many columns in matrix (Subscript[δ, 1])?

Length[b1[[1]]]

144-49

So nullity((Subscript[δ, 1]))=95.
Therefore, (Subscript[β, 1])=dim((Subscript[H, 1]))=95-95=0. This indicates that the sphere has no 1-dimensional holes.

Compute the Betti number (Subscript[β, 2]):

How many columns in matrix (Subscript[δ, 2])?

Length[b2[[1]]]

So nullity((Subscript[δ, 2]))=1.
There are no 3-simplices in the simplicial complex, so (Subscript[δ, 3]) is the zero map, and rank((Subscript[δ, 3]))=0.
Therefore, (Subscript[β, 2])=dim((Subscript[H, 2]))=1-0=1. This indicates that the sphere has one enclosed void.

Torus example

torus=TriangulateMesh[DiscretizeRegion[Torus[]]]

Compute the boundary matrix (Subscript[δ, 1]) and the Betti number (Subscript[β, 0]):

b1=boundaryMatrix[torus,1];
MatrixRank[b1,Modulus->2]

Length[MeshCells[torus,0]]

number of vertices = 1290 = nullity((Subscript[δ, 0]))
rank((Subscript[δ, 1]))=1289
Therefore, (Subscript[β, 0])=1290-1289=1. This indicates that the torus has one connected component.

Compute the boundary matrix (Subscript[δ, 2]) and the Betti number (Subscript[β, 1]):

b2=boundaryMatrix[torus,2];
MatrixRank[b2,Modulus->2]

We also need the nullity of (Subscript[δ, 1]):

Length[b1[[1]]]-MatrixRank[b1,Modulus->2]

So nullity((Subscript[δ, 1]))=2581.
Therefore, (Subscript[β, 1])=dim((Subscript[H, 1]))=2851-2579=2. This indicates that the torus has two 1-dimensional holes.

Compute the Betti number (Subscript[β, 2]):

We need the nullity of (Subscript[δ, 2]):

Length[b2[[1]]]-MatrixRank[b2,Modulus->2]

So nullity((Subscript[δ, 2]))=1.
There are no 3-simplices in the simplicial complex, so (Subscript[δ, 3]) is the zero map, and rank((Subscript[δ, 3]))=0.
Therefore, (Subscript[β, 2])=dim((Subscript[H, 2]))=1-0=1. This indicates that the torus has one enclosed void.