Cycle spaces and cocycle spaces of a graph using Sagemath

The cube graph $\Gamma$

The cube graph

has incidence matrix

$B = \left(\begin{array}{rrrrrrrr} 1 & -1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & -1 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & -1 & 0 & 0 & 0 \\ 0 & 1 & 0 & -1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & -1 & 0 & 0 \\ 0 & 0 & 1 & -1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & -1 \\ 0 & 0 & 0 & 0 & 1 & -1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & -1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & -1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & -1 \end{array}\right).$

If $F$ is a field, the kernel of $B:C^1(\Gamma,F)\to C^0(\Gamma,F)$ is the cycle space. The cycle space has basis

$(1, 0, -1, 0, 1, 0, 0, 0, 0, -1, 1, -1), (0, 1, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0),$
$(0, 0, 0, 1, -1, 0, 0, 1, 0, 0, -1, 0), (0, 0, 0, 0, 0, 1, -1, 1, 0, 0, 0, -1),$

A cut is a partition of the vertex set of $\Gamma=(V,E)$ into two subsets, $V= S \cup T$. The cocycle of such a cut is the set $\{(u,v)\in E\ |\ u\in S,\ v \in T\}$ of edges that have one endpoint in $S$ and the other endpoint in $T$. The cocycle space has basis

$(1, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, -1), (0, 1, 0, 0, 0, -1, 0, 0, 0, -1, 0, -1),$
$(0, 0, 1, 0, 0, 0, 0, 0, -1, -1, 0, 0), (0, 0, 0, 1, 0, -1, 0, 0, 0, 0, -1, -1),$
$(0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1, 0), (0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1),$
$(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1).$

The Sagemath command below use functions from the file alg-graph-thry1.sage.

sage: Gamma = graphs.CubeGraph(3)
sage: eo = [1]*12
sage: incidence_matrix(Gamma, eo)
[ 1 -1  0  0  0  0  0  0]
[ 1  0 -1  0  0  0  0  0]
[ 1  0  0  0 -1  0  0  0]
[ 0  1  0 -1  0  0  0  0]
[ 0  1  0  0  0 -1  0  0]
[ 0  0  1 -1  0  0  0  0]
[ 0  0  1  0  0  0 -1  0]
[ 0  0  0  1  0  0  0 -1]
[ 0  0  0  0  1 -1  0  0]
[ 0  0  0  0  1  0 -1  0]
[ 0  0  0  0  0  1  0 -1]
[ 0  0  0  0  0  0  1 -1]
sage: cycle_space(Gamma, eo)
Vector space of degree 12 and dimension 5 over Rational Field
Basis matrix:
[ 1  0 -1  0 -1  0  0  0  0 -1 -1  1]
[ 0  1  1  0  0  0 -1  0  0  1  0  0]
[ 0  0  0  1  1  0  0 -1  0  0  1  0]
[ 0  0  0  0  0  1  1  1  0  0  0 -1]
[ 0  0  0  0  0  0  0  0  1 -1 -1  1]
sage: cocycle_space(Gamma, eo)
Vector space of degree 12 and dimension 7 over Rational Field
Basis matrix:
[ 1  0  0  0  0 -1  0  0  1  0  0 -1]
[ 0  1  0  0  0 -1  0  0  0 -1  0 -1]
[ 0  0  1  0  0  0  0  0 -1 -1  0  0]
[ 0  0  0  1  0 -1  0  0  0  0 -1 -1]
[ 0  0  0  0  1  0  0  0 -1  0 -1  0]
[ 0  0  0  0  0  0  1  0  0  1  0  1]
[ 0  0  0  0  0  0  0  1  0  0  1  1]