# Chain Complexes Code

 When we looked at the delta complex we got a chain of 'face maps' between each dimension and the next lower one.

In homology we treat this as a chain of Abelian groups (more detail on the page here).

For implementation of co-chain see page here.

### FriCAS Implementation

In our FriCAS Implementation 'ChainComplex' represents, not the faces at each dimension, but the maps between them. Each map is represented by a (not necessarily square) matrix. These matrices may have a width or a height of zero.

Since the chain starts and ends with zero (trivial group) then:

• The first matrix has a height of zero. A matrix with a height of zero is shown with zeroes like this: [0 , 0 , 0] because it is hard to graphically depict a zero height matrix.
• The last matrix has a width of zero.

### Creating Chain Complexes

Here are two ways to construct a chain complex:

 Usually it is easier to construct a simplicial or delta complex first and then call chain function. Here we construct a simplicial complex then call chain function: ```(1) -> b1 := sphereSolid(2)\$SimplicialComplexFactory(Integer) (1) points 1..3 (1,2,3) Type: FiniteSimplicialComplex(Integer) (2) -> chain(b1) + 1 1 0 + + 1 + | | | | (2) [0 0 0],|- 1 0 1 |,|- 1|,[] | | | | + 0 - 1 - 1+ + 1 + Type: ChainComplex``` We could alternatively construct from a list of matrices.

### Example 1 - Solid 2D circle.

 ```(1) -> )expose DeltaComplex DeltaComplex is now explicitly exposed in frame frame1 (1) -> b1 := sphereSolid(2)\$SimplicialComplexFactory(Integer) (1) points 1..3 (1,2,3) Type: FiniteSimplicialComplex(Integer) (2) -> d1 := deltaComplex(b1) (2) 2D:[[1,- 2,3]] 1D:[[1,- 2],[1,- 3],[2,- 3]] 0D:[[0],[0],[0]] Type: DeltaComplex(Integer) (3) -> c1 := chain(d1) + 1 1 0 + + 1 + (3) [0 0 0],|- 1 0 1 |,|- 1|,[] + 0 - 1 - 1+ + 1 + Type: ChainComplex```

### Example2 - Solid 3D Sphere.

 ```(4) -> b2 := sphereSolid(3)\$SimplicialComplexFactory(Integer) (4) points 1..4 (1,2,3,4) Type: FiniteSimplicialComplex(Integer) (5) -> d2 := deltaComplex(b2) (5) 3D:[[1,- 2,3,- 4]] 2D:[[1,- 2,4],[1,- 3,5],[2,- 3,6],[4,- 5,6]] 1D:[[1,- 2],[1,- 3],[1,- 4],[2,- 3],[2,- 4],[3,- 4]] 0D:[[0],[0],[0],[0]] Type: DeltaComplex(Integer) (6) -> c2 := chain(d2) (6) + 1 1 0 0 + + 1 1 1 0 0 0 + |- 1 0 1 0 | + 1 + |- 1 0 0 1 1 0 | | 0 - 1 - 1 0 | |- 1| [0 0 0 0],| |,| |,| |,[] | 0 - 1 0 - 1 0 1 | | 1 0 0 1 | | 1 | + 0 0 - 1 0 - 1 - 1+ | 0 1 0 - 1| +- 1+ + 0 0 1 1 + Type: ChainComplex```

### Example 3 - Hollow 2D circle.

 ```(7) -> b3 := sphereSurface(2)\$SimplicialComplexFactory(Integer) (7) points 1..3 (1,2) -(1,3) (2,3) Type: FiniteSimplicialComplex(Integer) (8) -> d3 := deltaComplex(b3) (8) 1D:[[1,- 2],[- 1,3],[2,- 3]] 0D:[[0],[0],[0]] Type: DeltaComplex(Integer) (9) -> c3 := chain(d3) + 1 - 1 0 + ++ (9) [0 0 0],|- 1 0 1 |,|| + 0 1 - 1+ ++ Type: ChainComplex```

### Example 4 - Hollow 3D Sphere.

 ```(10) -> b4 := sphereSurface(3)\$SimplicialComplexFactory(Integer) (10) points 1..4 (1,2,3) -(1,2,4) (1,3,4) -(2,3,4) Type: FiniteSimplicialComplex(Integer) (11) -> d4 := deltaComplex(b4) (11) 2D:[[1,- 2,4],[- 1,3,- 5],[2,- 3,6],[- 4,5,- 6]] 1D:[[1,- 2],[1,- 3],[1,- 4],[2,- 3],[2,- 4],[3,- 4]] 0D:[[0],[0],[0],[0]] Type: DeltaComplex(Integer) (12) -> c4 := chain(d4) + 1 - 1 0 0 + + 1 1 1 0 0 0 + |- 1 0 1 0 | ++ |- 1 0 0 1 1 0 | | 0 1 - 1 0 | || (12) [0 0 0 0],| |,| |,|| | 0 - 1 0 - 1 0 1 | | 1 0 0 - 1| || + 0 0 - 1 0 - 1 - 1+ | 0 - 1 0 1 | ++ + 0 0 1 - 1+ Type: ChainComplex```

### Example 5 - Torus Surface.

 ```(13) -> b5 := torusSurface()\$SimplicialComplexFactory(Integer) (13) points 1..7 (1,2,3) (2,3,5) (2,4,5) (2,4,7) (1,2,6) (2,6,7) (3,4,6) (3,5,6) (3,4,7) (1,3,7) (1,4,5) (1,4,6) (5,6,7) (1,5,7) Type: FiniteSimplicialComplex(Integer) (14) -> d5 := deltaComplex(b5) (14) VCONCAT VCONCAT VCONCAT , 2D: [[1,- 2,7], [1,- 5,10], [2,- 6,15], [3,- 4,16], [3,- 5,17], [4,- 6,20], [7,- 9,13], [8,- 9,16], [8,- 11,18], [10,- 11,21], [12,- 14,17], [12,- 15,18], [13,- 14,19], [19,- 20,21]] , 1D: [[1,- 2], [1,- 3], [1,- 4], [1,- 5], [1,- 6], [1,- 7], [2,- 3], [2,- 4], [2,- 5], [2,- 6], [2,- 7], [3,- 4], [3,- 5], [3,- 6], [3,- 7], [4,- 5], [4,- 6], [4,- 7], [5,- 6], [5,- 7], [6,- 7]] , 0D:[[0],[0],[0],[0],[0],[0],[0]] Type: DeltaComplex(Integer) (15) -> c5 := chain(d5) (15) [0 0 0 0 0 0 0] , [[1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [- 1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,- 1,0,0,0,0,- 1,0,0,0,0,1,1,1,1,0,0,0,0,0,0], [0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,0,0,1,1,1,0,0,0], [0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,0,- 1,0,0,1,1,0], [0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,0,- 1,0,- 1,0,1], [0,0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,0,- 1,0,- 1,- 1]] , + 1 1 0 0 0 0 0 0 0 0 0 0 0 0 + |- 1 0 1 0 0 0 0 0 0 0 0 0 0 0 | | 0 0 0 1 1 0 0 0 0 0 0 0 0 0 | | 0 0 0 - 1 0 1 0 0 0 0 0 0 0 0 | | | ++ | 0 - 1 0 0 - 1 0 0 0 0 0 0 0 0 0 | || | 0 0 - 1 0 0 - 1 0 0 0 0 0 0 0 0 | || | 1 0 0 0 0 0 1 0 0 0 0 0 0 0 | || | 0 0 0 0 0 0 0 1 1 0 0 0 0 0 | || | 0 0 0 0 0 0 - 1 - 1 0 0 0 0 0 0 | || | 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | || | 0 0 0 0 0 0 0 0 - 1 - 1 0 0 0 0 |,|| | 0 0 0 0 0 0 0 0 0 0 1 1 0 0 | || | 0 0 0 0 0 0 1 0 0 0 0 0 1 0 | || | 0 0 0 0 0 0 0 0 0 0 - 1 0 - 1 0 | || | 0 0 1 0 0 0 0 0 0 0 0 - 1 0 0 | || | 0 0 0 1 0 0 0 1 0 0 0 0 0 0 | || | 0 0 0 0 1 0 0 0 0 0 1 0 0 0 | || | | ++ | 0 0 0 0 0 0 0 0 1 0 0 1 0 0 | | 0 0 0 0 0 0 0 0 0 0 0 0 1 1 | | 0 0 0 0 0 1 0 0 0 0 0 0 0 - 1| + 0 0 0 0 0 0 0 0 0 1 0 0 0 1 + Type: ChainComplex```

### Example 6 - Projective Plane.

 ```(16) -> b6 := projectiveSpace(2)\$SimplicialComplexFactory(Integer) (16) points 1..6 (1,2,3) (1,3,4) (1,2,6) (1,5,6) (1,4,5) (2,3,5) (2,4,5) (2,4,6) (3,4,6) (3,5,6) Type: FiniteSimplicialComplex(Integer) (17) -> d6 := deltaComplex(b6) (17) VCONCAT VCONCAT VCONCAT , 2D: [[1,- 2,6], [1,- 5,9], [2,- 3,10], [3,- 4,13], [4,- 5,15], [6,- 8,11], [7,- 8,13], [7,- 9,14], [10,- 12,14], [11,- 12,15]] , 1D: [[1,- 2], [1,- 3], [1,- 4], [1,- 5], [1,- 6], [2,- 3], [2,- 4], [2,- 5], [2,- 6], [3,- 4], [3,- 5], [3,- 6], [4,- 5], [4,- 6], [5,- 6]] , 0D:[[0],[0],[0],[0],[0],[0]] Type: DeltaComplex(Integer) (18) -> c6 := chain(d6) (18) [0 0 0 0 0 0] , + 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 + |- 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 | | 0 - 1 0 0 0 - 1 0 0 0 1 1 1 0 0 0 | | 0 0 - 1 0 0 0 - 1 0 0 - 1 0 0 1 1 0 | | 0 0 0 - 1 0 0 0 - 1 0 0 - 1 0 - 1 0 1 | + 0 0 0 0 - 1 0 0 0 - 1 0 0 - 1 0 - 1 - 1+ , + 1 1 0 0 0 0 0 0 0 0 + |- 1 0 1 0 0 0 0 0 0 0 | | 0 0 - 1 1 0 0 0 0 0 0 | | | ++ | 0 0 0 - 1 1 0 0 0 0 0 | || | 0 - 1 0 0 - 1 0 0 0 0 0 | || | 1 0 0 0 0 1 0 0 0 0 | || | 0 0 0 0 0 0 1 1 0 0 | || | 0 0 0 0 0 - 1 - 1 0 0 0 |,|| | 0 1 0 0 0 0 0 - 1 0 0 | || | 0 0 1 0 0 0 0 0 1 0 | || | 0 0 0 0 0 1 0 0 0 1 | || | 0 0 0 0 0 0 0 0 - 1 - 1| || | | ++ | 0 0 0 1 0 0 1 0 0 0 | | 0 0 0 0 0 0 0 1 1 0 | + 0 0 0 0 1 0 0 0 0 1 + Type: ChainComplex```

### Example 7 - Klein Bottle.

 ```(19) -> b7 := kleinBottle()\$SimplicialComplexFactory(Integer) (19) points 1..8 (3,4,8) (2,3,4) (2,4,6) (2,6,8) (2,5,8) (3,5,7) (2,3,7) (1,2,7) (1,2,5) (1,3,5) (4,5,8) (4,5,7) (4,6,7) (1,6,7) (1,3,6) (3,6,8) Type: FiniteSimplicialComplex(Integer) (20) -> d7 := deltaComplex(b7) (20) VCONCAT VCONCAT VCONCAT , 2D: [[1,- 3,8], [1,- 5,10], [2,- 3,13], [2,- 4,14], [4,- 5,23], [6,- 7,12], [6,- 10,15], [7,- 9,18], [8,- 11,22], [9,- 11,24], [12,- 16,20], [13,- 15,21], [14,- 16,24], [17,- 19,21], [17,- 20,22], [18,- 19,23]] , 1D: [[1,- 2], [1,- 3], [1,- 5], [1,- 6], [1,- 7], [2,- 3], [2,- 4], [2,- 5], [2,- 6], [2,- 7], [2,- 8], [3,- 4], [3,- 5], [3,- 6], [3,- 7], [3,- 8], [4,- 5], [4,- 6], [4,- 7], [4,- 8], [5,- 7], [5,- 8], [6,- 7], [6,- 8]] , 0D:[[0],[0],[0],[0],[0],[0],[0],[0]] Type: DeltaComplex(Integer) (21) -> c7 := chain(d7) (21) [0 0 0 0 0 0 0 0] , [[1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [- 1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,- 1,0,0,0,- 1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,0,1,1,1,1,0,0,0,0], [0,0,- 1,0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,0,0,1,1,0,0], [0,0,0,- 1,0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,0,0,0,1,1], [0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,- 1,0,- 1,0], [0,0,0,0,0,0,0,0,0,0,- 1,0,0,0,0,- 1,0,0,0,- 1,0,- 1,0,- 1]] , [[1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0], [- 1,0,- 1,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,- 1,1,0,0,0,0,0,0,0,0,0,0,0], [0,- 1,0,0,- 1,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,- 1,0,1,0,0,0,0,0,0,0,0], [1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,- 1,0,1,0,0,0,0,0,0], [0,1,0,0,0,0,- 1,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,- 1,- 1,0,0,0,0,0,0], [0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0], [0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0], [0,0,0,0,0,0,1,0,0,0,0,- 1,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,- 1,0,- 1,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0], [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1], [0,0,0,0,0,0,0,0,0,0,0,0,0,- 1,0,- 1], [0,0,0,0,0,0,0,0,0,0,1,0,0,0,- 1,0], [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0], [0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0], [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1], [0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0]] , ++ || || || || || || || || || || || || || || || || || || || || || || || || || || || || || ++ Type: ChainComplex```

## Next

To go on to implementation of co-chain see page here.