---
title: "Calculating Cohomology"
canonical: "https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/cohomology-groups.html"
source: "https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/cohomology-groups.md"
part: "Finite Groups"
chapter: "Cohomology and Extensions"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Finite Groups", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/index-finite-groups.md"}
  - {"title": "Cohomology and Extensions", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/index-cohomology-and-extensions.md"}
prev: {"title": "Accessing Properties of the Cohomology Module", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/structure-invar.md"}
next: {"title": "Cocycles", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/cocycles.md"}
intrinsics:
  - {"name": "CohomologyGroup", "signature": "CohomologyGroup(CM, n): ModCoho, RngIntElt -> ModTupRng"}
  - {"name": "CohomologicalDimension", "signature": "CohomologicalDimension(CM, n): ModCoho, RngIntElt -> RngIntElt"}
  - {"name": "CohomologicalDimension", "signature": "CohomologicalDimension(M, n): ModGrp, RngIntElt -> RngIntElt"}
  - {"name": "CohomologicalDimensions", "signature": "CohomologicalDimensions(M, n): ModGrp, RngIntElt -> RngIntElt"}
  - {"name": "CohomologicalDimension", "signature": "CohomologicalDimension(G, M, n): GrpPerm, ModRng, RngIntElt -> RngIntElt"}
  - {"name": "H1Dimension", "signature": "H1Dimension(F, f, M): GrpFP, Map, ModGrp -> RngIntElt"}
  - {"name": "H1Dimension", "signature": "H1Dimension(G, f, K): GrpFP, Map, Rng -> RngIntElt"}
  - {"name": "H1DimensionSymmetricSquare", "signature": "H1DimensionSymmetricSquare(G, f, K): GrpFP, Map, Rng -> RngIntElt"}
  - {"name": "H1DimensionExteriorSquare", "signature": "H1DimensionExteriorSquare(G, f, K): GrpFP, Map, Rng -> RngIntElt"}
examples:
  - "ex-68b620"
  - "ex-0db52b"
  - "ex-096719"
  - "ex-46f77b"
  - "ex-023d07"
---

# Calculating Cohomology

<a id="function-cohomologygroup-modcoho-rngintelt"></a>
## `CohomologyGroup(CM, n): ModCoho, RngIntElt -> ModTupRng`

Given a cohomology module ${\rm CM}$ for the group $G$ acting on the module $M$ and a non-negative integer $n$ taking one of the values $0$, $1$, or $2$, this function returns the cohomology group $H^n(G,M)$. For modules defined over the ring of integers only, $n$ may also be equal to 3. (In this case, $H^3(G,M)$ is computed as $H^2(G, M \otimes_Z Q/Z)$.) If the group used to define ${\rm CM}$ was a finitely presented group, then $n$ may only be equal to $0$ or $1$. Note that ${\rm CM}$ must be a module returned by invoking `CohomologyModule`.

<a id="example-ex-68b620"></a>
## `Example: Cohomology for a Cyclic Group of Order 4 (ex-68b620)`

Following on from example [Cohomology Module for a Cyclic Group](https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/creation.md#example-ex-0c0fe6) above:

```magma
> G:=CyclicGroup(4);
> mats := [ Matrix(Integers(),2,2,[1,2,1,3]) ];
> invar := [2,4];
> CM := CohomologyModule(G,invar,mats);
> CohomologyGroup(CM,0);
Full Quotient RSpace of degree 1 over Integer Ring
Column moduli:
[ 2 ]
> CohomologyGroup(CM,1);
Full Quotient RSpace of degree 1 over Integer Ring
Column moduli:
[ 2 ]
> CohomologyGroup(CM,2);
Full Quotient RSpace of degree 1 over Integer Ring
Column moduli:
[ 2 ]
```

<a id="example-ex-0db52b"></a>
## `Example: Cohomology of an Infinite FP-Group (ex-0db52b)`

Following on from example [Cohomology Module for an Infinite Group](https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/creation.md#example-ex-e9e40a) above:

```magma
> G := Group<x,y | x^2,y^3,(x*y)^7 >;
> L := LowIndexSubgroups(G, <7,7>);
> Q := CosetImage(G,L[1]);
> PM := PermutationModule(Q, Integers());
> cons := Constituents(PM);
> mats := ActionGenerators(cons[2]);
> M := GModule(G,mats);
> CM := CohomologyModule(G,M);
> CohomologyGroup(CM,0);
Full Quotient RSpace of degree 0 over Integer Ring
Column moduli:
[ ]
> CohomologyGroup(CM,1);
Full Quotient RSpace of degree 1 over Integer Ring
Column moduli:
[ 7 ]
> CohomologyGroup(CM,2);
Runtime error: Second cohomology groups are not implemented for GrpFP
```

<a id="function-cohomologicaldimension-modcoho-rngintelt"></a>
## `CohomologicalDimension(CM, n): ModCoho, RngIntElt -> RngIntElt`

Given a cohomology module ${\rm CM}$ for the group $G$ acting on the module $M$ defined over a finite field $K$ and a non-negative integer $n$ taking one of the values $0$, $1$, or $2$, this function returns the dimension of $H^n(G,M)$ over $K$. Note that this function may only be applied to the module returned by a call to `CohomologyModule(G, M)`, where $M$ is a module over a finite field $K$. When $n = 2$, this function is faster and may be applied to much larger examples than `CohomologyGroup(CM, n)` but, unlike that function, it does not enable the user to compute with explicit extensions and two-cocycles.

Note that there are some alternative functions for performing these calculations described in other manual chapters.

<a id="function-cohomologicaldimension-modgrp-n"></a>
## `CohomologicalDimension(M, n): ModGrp, RngIntElt -> RngIntElt`

For $K[G]$-module $M$ (with $K$ a finite field and $G$ a finite group), compute and return the $K$-dimension of the cohomology group $H^n(G,M)$ for $n \ge 0$. For $n=0$ and 1, this is carried out by using the function `CohomologicalDimension(CM,n)` just described. For $n \ge 2$, it is done recursively using projective covers and dimension shifting to reduce to the case $n=1$. See Section [Projective Indecomposable Modules](https://docs.magma-maths.org/v2.30-1/RepresentationTheory/ModulesOverAnAlgebraAndGroupRepresentations/projective-indecomposable-modules.md#projective-indecomposable-modules) in Chapter [Modules over an Algebra and Group Representations](https://docs.magma-maths.org/v2.30-1/RepresentationTheory/ModulesOverAnAlgebraAndGroupRepresentations/index-modules-over-an-algebra-and-group-representations.md#chapmodalg) for further details and examples.

<a id="function-cohomologicaldimensions-modgrp-n"></a>
## `CohomologicalDimensions(M, n): ModGrp, RngIntElt -> RngIntElt`

For $K[G]$-module $M$ (with $K$ a finite field and $G$ a finite group), compute and return the sequence of $K$-dimensions of the cohomology groups $H^k(G,M)$ for $1 \le k \le n$. On account of the recursive method used, this is quicker than computing them all individually.

<a id="function-cohomologicaldimension-grpperm-modrng-rngintelt"></a>
## `CohomologicalDimension(G, M, n): GrpPerm, ModRng, RngIntElt -> RngIntElt`

Given the permutation group $G$, the $K[G]$-module $M$, and an integer $n$ (equal to 1 or 2), return the dimension of the $n$-th cohomology group of $G$ acting on $M$. *Note that* $K$ *must be a finite field of prime order*. This function invokes Derek Holt’s original C cohomology code (see [[Hol85b](https://docs.magma-maths.org/v2.30-1/references.md#cite-holt-cohom)]). In some cases it will be faster than the function that uses the cohomology module data structure.

<a id="function-h1dimension-grpfp-map-modgrp"></a>
## `H1Dimension(F, f, M): GrpFP, Map, ModGrp -> RngIntElt`

This function returns the dimension of the first cohomology group of the $F$-module $M_F$, where $F$ is a finitely presented group, $f$ is an epimorphism from $F$ onto a finite group $G$ and $M$ is a $G$-module that has been lifted to $M_F$. Again, this function is generally much faster, since it uses sparse matrices.

<a id="function-h1dimension-grpfp-map-rng"></a>
## `H1Dimension(G, f, K): GrpFP, Map, Rng -> RngIntElt`

This function is equivalent to `CohomologicalDimension(G, M, 1)` where `M := PermutationModule(P, K)` and $P$ is defined by the images of generators of G under the map $f$, but is generally much faster, since it uses sparse matrices and avoids the explicit construction of the permutation module.

<a id="function-h1dimensionsymmetricsquare-grpfp-map-rng"></a>
## `H1DimensionSymmetricSquare(G, f, K): GrpFP, Map, Rng -> RngIntElt`

<a id="function-h1dimensionexteriorsquare-grpfp-map-rng"></a>
## `H1DimensionExteriorSquare(G, f, K): GrpFP, Map, Rng -> RngIntElt`

These functions are equivalent to `CohomologicalDimension(G, M, 1)` where $M$ is the symmetric square or exterior square, respectively, of `PermutationModule(P, R)`, and $P$ is defined by the images of generators of G under the map $f$. But the functions are generally much faster, since they use sparse matrices and avoid the explicit construction of the modules.

<a id="example-ex-096719"></a>
## `Example: Cohomology of A8 (ex-096719)`

We examine the first and second cohomology groups of the group $A_8$.

```magma
> G := Alt(8);
> M := PermutationModule(G, GF(3));
```

We first calculate the dimensions of $H^1(G,M)$ and $H^2(G,M)$ using the old functions.

```magma
> time CohomologicalDimension(G, M, 1);
0
Time: 0.020
> time CohomologicalDimension(G, M, 2);
1
Time: 0.020
```

We now recalculate the dimensions of $H^1(G,M)$ and $H^2(G,M)$ using the new functions.

```magma
> X := CohomologyModule(G, M);
> time CohomologicalDimension(X, 1);
0
Time: 0.020
> time CohomologicalDimension(X, 2);
1
Time: 0.920
> X := CohomologyModule(G, M);
> time C:=CohomologyGroup(X, 2);
Time: 4.070
> C;
Full Vector space of degree 1 over GF(3)
```

<a id="example-ex-46f77b"></a>
## `Example: Cohomology of ASL(3, 5) (ex-46f77b)`

We do a similar comparison with Example [Cohomology Module for ASL(3, 5)](https://docs.magma-maths.org/v2.30-1/FiniteGroups/CohomologyAndExtensions/creation.md#example-ex-233494) above.

```magma
> G := ASL(3,5);
> N := pCore(G,5);
> M := GModule(G,N);
> CM := CohomologyModule(G,M);
> time [CohomologyGroup(CM,i) : i in [0..2]];
[
    Full Vector space of degree 0 over GF(5),

    Full Vector space of degree 1 over GF(5),

    Full Vector space of degree 1 over GF(5)
]
Time: 46.940
> CM := CohomologyModule(G,M);
> time [CohomologicalDimension(CM,i) : i in [0..2]];
[ 0, 1, 1 ]
Time: 0.320
```

<a id="example-ex-023d07"></a>
## `Example: Cohomology Where the Old Method Fails (ex-023d07)`

In the case of $\Omega^-(8,3)$ acting on its natural module, the new function succeeds, but the old function does not.

```magma
> G := OmegaMinus(8, 3);
> M := GModule(G);
> X := CohomologyModule(G, M);
> time CohomologicalDimension(X, 2);
2
Time: 290.280
> phi, P := PermutationRepresentation(G);
> MM := GModule(P, [ActionGenerator(M, i): i in [1..Ngens(G)]] );
> time CohomologicalDimension(P, MM, 2);

Out of space.

>> time CohomologicalDimension(P, MM, 2);
                              ^
Runtime error in 'CohomologicalDimension': Cohomology failed
```
