Let be a compact connected surface without boundary. A cellulation of is a finite graph embedded in such that every connected component of is homeomorphic to an open disc; these components are the faces . Each face is bounded by a closed walk in the graph. Loops and multiple edges are allowed.
The cellulation defines a chain complex over ,
where is the sum of the two endpoints of (zero for a loop) and is the sum, mod 2, of the edges in the boundary walk of (an edge traversed twice contributes zero). Every boundary walk is closed, so . The homology of this complex is the homology of the surface: it does not depend on the cellulation chosen. The Euler characteristic is
also independent of the cellulation. An orientable closed surface of genus (a sphere with handles) has .
Dual cellulation. Place a vertex inside each face ; for each edge draw a dual edge crossing once and joining the dual vertices of the two faces on either side of ; the dual faces are then discs around the original vertices. This is the dual cellulation , with , , . With these identifications the boundary maps of are the transposes of those of :
Hence the cocycles and coboundaries of in degree 1 are the cycles and boundaries of , and of is of (the combinatorial form of Poincaré duality with coefficients).
In the homological code of , -type logical operators are non-trivial cycles of and -type logical operators are non-trivial cycles of : on the square lattice of the toric code these are the loops on the lattice and on the dual lattice that wind around the torus (Kitaev; Bombin and Martin-Delgado). Cellular homology and its invariance are treated in Munkres.