---
title: "Homology Computation"
canonical: "https://docs.magma-maths.org/v2.30-1/Topology/SimplicialHomology/homology-computation.html"
source: "https://docs.magma-maths.org/v2.30-1/Topology/SimplicialHomology/homology-computation.md"
part: "Topology"
chapter: "Simplicial Homology"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Topology", "source": "https://docs.magma-maths.org/v2.30-1/Topology/index-topology.md"}
  - {"title": "Simplicial Homology", "source": "https://docs.magma-maths.org/v2.30-1/Topology/SimplicialHomology/index-simplicial-homology.md"}
prev: {"title": "Simplicial Complexes", "source": "https://docs.magma-maths.org/v2.30-1/Topology/SimplicialHomology/simplicial-complexes.md"}
next: {"title": "Bibliography", "source": "https://docs.magma-maths.org/v2.30-1/Topology/SimplicialHomology/bibliography.md"}
intrinsics:
  - {"name": "Homology", "signature": "Homology(X): SmpCpx -> SeqEnum, SeqEnum"}
  - {"name": "Homology", "signature": "Homology(~X): SmpCpx"}
  - {"name": "Homology", "signature": "Homology(X, A): SmpCpx, Rng -> SeqEnum, SeqEnum"}
  - {"name": "Homology", "signature": "Homology(~X, A): SmpCpx, Rng"}
  - {"name": "HomologyGroup", "signature": "HomologyGroup(X, q): SmpCpx, RngIntElt -> ModRng"}
  - {"name": "HomologyGroup", "signature": "HomologyGroup(X, q, A): SmpCpx, RngIntElt, Rng -> ModRng"}
  - {"name": "BettiNumber", "signature": "BettiNumber(X, q): SmpCpx, RngIntElt -> RngIntElt"}
  - {"name": "BettiNumber", "signature": "BettiNumber(X, q, A): SmpCpx, RngIntElt, Rng -> RngIntElt"}
  - {"name": "TorsionCoefficients", "signature": "TorsionCoefficients(X, q): SmpCpx, RngIntElt -> SeqEnum[RngElt]"}
  - {"name": "TorsionCoefficients", "signature": "TorsionCoefficients(X, q, A): SmpCpx, RngIntElt, Rng -> SeqEnum[RngElt]"}
  - {"name": "EulerCharacteristic", "signature": "EulerCharacteristic(X): SmpCpx -> RngIntElt"}
  - {"name": "BoundaryMatrix", "signature": "BoundaryMatrix(X, q, A): SmpCpx, RngIntElt, Rng -> Mtrx"}
  - {"name": "ChainComplex", "signature": "ChainComplex(X, A): SmpCpx, Rng -> ModCpx"}
  - {"name": "HomologyGenerators", "signature": "HomologyGenerators(X): SmpCpx"}
  - {"name": "HomologyGenerators", "signature": "HomologyGenerators(X, A): SmpCpx, Rng"}
  - {"name": "HomologyGenerators", "signature": "HomologyGenerators(H, M, X): SeqEnum, SeqEnum, SmpCpx"}
examples:
  - "ex-a2198f"
  - "ex-dacb67"
  - "ex-1e8d54"
---

<a id="hom-comp"></a>
<a id="id1"></a>
# Homology Computation

The code computes exclusively reduced homology of the given simplicial complexes. If you want the non-reduced homology, just add a single free rank to dimension 0 and let it be generated by any single point in the complex.

<a id="function-homology-smpcpx"></a>
## `Homology(X): SmpCpx -> SeqEnum, SeqEnum`

<a id="procedure-homology-smpcpx-ref"></a>
## `Homology(~X): SmpCpx`

<a id="function-homology-smpcpx-rng"></a>
## `Homology(X, A): SmpCpx, Rng -> SeqEnum, SeqEnum`

<a id="procedure-homology-smpcpx-rng-ref"></a>
## `Homology(~X, A): SmpCpx, Rng`

Calculates the reduced homology of a simplicial complex `X` with coefficients in the ring $A$. The procedural form of this command caches the results of the calculation in the simplicial complex object. If no ring is given, then the function defaults to integer coefficients.

<a id="example-ex-a2198f"></a>
## `Example: Homology of a Simplicial Complex (ex-a2198f)`

The resulting modules are stored in falling dimension, always including the dimension $-1$ vanishing homology module at the very end.

```magma
> circ := Boundary(SimplicialComplex([{1,2,3}]));
> Homology(circ,Integers());
[
    Full Quotient RSpace of degree 1 over Integer Ring
    Column moduli:
    [ 0 ],

    Full Quotient RSpace of degree 0 over Integer Ring
    Column moduli:
    [ ],

    Full Quotient RSpace of degree 0 over Integer Ring
    Column moduli:
    [ ]
]
[
    Mapping from: RSpace of degree 3, dimension 1 over Integer Ring to Full
    Quotient RSpace of degree 1 over Integer Ring
    Column moduli:
    [ 0 ],
    Mapping from: RSpace of degree 3, dimension 2 over Integer Ring to Full
    Quotient RSpace of degree 0 over Integer Ring
    Column moduli:
    [ ],
    Mapping from: Full RSpace of degree 1 over Integer Ring to Full Quotient
    RSpace of degree 0 over Integer Ring
    Column moduli:
    [ ]
]
> lens3 := LensSpace(3);
> Homology(~lens3,Integers());
> Homology(lens3,Integers())[3];
Full Quotient RSpace of degree 1 over Integer Ring
Column moduli:
[ 3 ]
```

<a id="function-homologygroup-smpcpx-rngintelt"></a>
## `HomologyGroup(X, q): SmpCpx, RngIntElt -> ModRng`

<a id="function-homologygroup-smpcpx-rngintelt-rng"></a>
## `HomologyGroup(X, q, A): SmpCpx, RngIntElt, Rng -> ModRng`

Calculates and returns the $q$th homology group of $X$ with coefficients in $A$. If no ring is given, the function defaults to integer coefficients. If the homology is cached in $X$, the cached results are returned. This function will not compute the entire homology in order to return one homology group.

<a id="function-bettinumber-smpcpx-rngintelt"></a>
## `BettiNumber(X, q): SmpCpx, RngIntElt -> RngIntElt`

<a id="function-bettinumber-smpcpx-rngintelt-rng"></a>
## `BettiNumber(X, q, A): SmpCpx, RngIntElt, Rng -> RngIntElt`

Returns the $q$th Betti number, computed as the free rank of the $q$-dimensional homology group, with coefficients in $A$. If no ring is given, then the function will default to integer coefficients.

Note that the Betti number computations compensate for the homology computations being reduced. Thus, `BettiNumber(X,0) eq Rank(HomologyGroup(X,0)) + 1`.

<a id="function-torsioncoefficients-smpcpx-rngintelt"></a>
## `TorsionCoefficients(X, q): SmpCpx, RngIntElt -> SeqEnum[RngElt]`

<a id="function-torsioncoefficients-smpcpx-rngintelt-rng"></a>
## `TorsionCoefficients(X, q, A): SmpCpx, RngIntElt, Rng -> SeqEnum[RngElt]`

Returns the torsion coefficients of the $q$th homology group of $X$ with coefficients in $A$. If no ring is given, then the function will default to integer coefficients.

<a id="function-eulercharacteristic-smpcpx"></a>
## `EulerCharacteristic(X): SmpCpx -> RngIntElt`

Computes the Euler characteristic of the complex. If homology is cached, this is used for computation, and else the characteristic is computed using the ranks of the chain groups.

<a id="function-boundarymatrix-smpcpx-rngintelt-rng"></a>
## `BoundaryMatrix(X, q, A): SmpCpx, RngIntElt, Rng -> Mtrx`

Returns the $q$th boundary matrix of the corresponding chain complex to the simplicial complex $X$ with coefficients in $A$.

<a id="function-chaincomplex-smpcpx-rng"></a>
## `ChainComplex(X, A): SmpCpx, Rng -> ModCpx`

Constructs a reduced chain complex of free A-modules corresponding to the abstract simplicial complex $X$.

Note that the produced complex includes one extra rank 1 module on each end, with the zero map leading to it, to simulate the maps to and from the zero module that would end a chain complex constructed from a simplicial complex in ordinary cases.

<a id="example-ex-dacb67"></a>
## `Example: Chain Complex of a Simplicial Complex (ex-dacb67)`

```magma
> ChainComplex(SimplicialComplex([{1}]),Integers());
Chain complex with terms of degree 2 down to -1
Dimensions of terms: 1 1 1 1
> BoundaryMaps(ChainComplex(SimplicialComplex([{1}]),Integers()));
[*
    [0],

    [-1],

    [0]
*]
> ChainComplex(SimplicialComplex([{1,2,3}]),GF(3));
Chain complex with terms of degree 4 down to -1
Dimensions of terms: 1 1 3 3 1 1
> BoundaryMaps(ChainComplex(SimplicialComplex([{1,2,3}]),GF(3)));
[*
    [0],

    [1 2 2],

    [1 0 2]
    [0 1 2]
    [1 2 0],

    [2]
    [2]
    [2],

    [0]
*]
```

<a id="procedure-homologygenerators-smpcpx"></a>
## `HomologyGenerators(X): SmpCpx`

<a id="procedure-homologygenerators-smpcpx-rng"></a>
## `HomologyGenerators(X, A): SmpCpx, Rng`

<a id="procedure-homologygenerators-seqenum-seqenum-smpcpx"></a>
## `HomologyGenerators(H, M, X): SeqEnum, SeqEnum, SmpCpx`

Prints generators of the homology groups of the simplicial complex $X$ with coefficients in $A$ together with their order, in order of dimension. The latter calling form expects $H,M$ to be the result from `H,M := ChainComplex(A,smp);`. This function will recalculate homology each time unless the homology is already cached in the simplicial complex using `Homology(A, smp)`.

If no ring is given, the function defaults to integer coefficients.

<a id="example-ex-1e8d54"></a>
## `Example: Homology Generators (ex-1e8d54)`

This function gives a condensed form of the actual bases of the homology groups, as well as mappings back to an actual chain representative for each homology class.

```magma
> HomologyGenerators(threetorus,Integers());

*** dimension 2 ***
inf: { 21, 23, 27 } - { 4, 6, 16 } - { 20, 24, 26 } + { 20, 25, 26 } -
  { 14, 19, 25 } + { 12, 14, 25 } + { 3, 6, 11 } - { 10, 14, 19 } +
  { 19, 20, 27 } - { 3, 9, 11 } - { 10, 13, 20 } + { 10, 13, 19 } -
  { 10, 12, 14 } - { 12, 16, 19 } - { 11, 19, 20 } - { 13, 16, 20 } +
  { 21, 24, 25 } + { 24, 26, 27 } - { 20, 21, 24 } - { 19, 22, 26 } -
  { 3, 10, 16 } - { 4, 6, 10 } - { 22, 25, 26 } + { 11, 16, 20 } +
  { 4, 8, 16 } - { 5, 6, 9 } + { 4, 8, 10 } - { 11, 12, 19 } - { 3, 5, 9 } +
  { 11, 12, 25 } + { 8, 9, 10 } + { 20, 21, 27 } + { 3, 6, 16 } +
  { 10, 11, 25 } + { 19, 22, 24 } - { 9, 10, 11 } + { 3, 5, 10 } +
  { 10, 20, 25 } - { 8, 11, 16 } - { 19, 26, 27 } - { 19, 23, 24 } +
  { 10, 12, 16 } - { 19, 21, 23 } - { 6, 8, 9 } + { 13, 16, 19 } +
  { 19, 21, 25 } + { 23, 24, 27 } - { 22, 24, 25 } + { 5, 6, 10 } +
  { 6, 8, 11 }


*** dimension 1 ***
inf: -1*{ 10, 13 } + { 3, 5 } - { 8, 9 } - { 8, 16 } - { 19, 22 } +
  { 20, 26 } + { 9, 11 } - { 3, 16 } + { 5, 10 } + { 22, 26 } + { 11, 20 } +
  2*{ 10, 20 } + { 13, 19 } - 2*{ 10, 11 }

inf: { 3, 9 } - { 3, 5 } - { 9, 11 } - { 5, 10 } + { 10, 11 }

inf: -1*{ 26, 27 } - { 11, 19 } + 2*{ 19, 22 } - { 20, 26 } -
  2*{ 22,  26 } + { 11, 20 } + { 19, 21 } - { 21, 27 }

inf: { 10, 13 } + { 11, 19 } - { 11, 20 } - { 10, 20 } - { 13, 19 }

inf: -1*{ 11, 19 } + { 19, 22 } - { 20, 26 } - { 22, 26 } + { 11, 20 }

inf: { 11, 20 } + { 10, 20 } - { 10, 11 }
```

The six found generators are the generators of each of the contained torus homology groups.

Notice that each generator is printed out with a prefix. This gives the order of the generator - so that for instance torsion elements of homology may be recognized. Thus, we see with the projective plane:

```magma
> HomologyGenerators(SimplicialProjectivePlane(),Integers());

*** dimension 1 ***
  2: { 3, 6 } + { 2, 3 } - { 2, 6 }
```

We can further take this opportunity to verify the claims about `Cone` and `Suspension` with regard to the homology.

```magma
> HomologyGenerators(Cone(SimplicialProjectivePlane()),Integers());
Complex is acyclic.

> HomologyGenerators(Suspension(SimplicialProjectivePlane()),Integers());

*** dimension 2 ***
  2: { 1, 5, 7 } - { 1, 4, 7 } + { 1, 2, 5 } + { 1, 5, 8 } - { 2, 3, 8 } -
  { 3, 5, 7 } - { 1, 2, 8 } + { 5, 6, 8 } + { 1, 4, 5 } - { 4, 6, 8 } +
  { 3, 4, 7 } + { 2, 3, 5 } - { 4, 5, 6 } - { 3, 4, 8 }
```
